Changeset 777832e in mainline
- Timestamp:
- 2018-06-21T12:27:09Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 296890f3
- Parents:
- 7d7bc09
- git-author:
- Jiri Svoboda <jiri@…> (2018-06-20 19:26:46)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-06-21 12:27:09)
- Location:
- uspace
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
r7d7bc09 r777832e 194 194 test/qsort.c \ 195 195 test/sprintf.c \ 196 test/stdio.c \ 196 197 test/stdlib.c \ 197 198 test/str.c -
uspace/lib/c/generic/stdio.c
r7d7bc09 r777832e 1 1 /* 2 * Copyright (c) 201 7Jiri Svoboda2 * Copyright (c) 2018 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 35 35 #include <errno.h> 36 36 #include <stdio.h> 37 #include <str_error.h> 37 38 #include <vfs/vfs.h> 39 40 /** Get stream position. 41 * 42 * @param stream Stream 43 * @param pos Place to store position 44 * 45 * @return Zero on success, non-zero on failure 46 */ 47 int fgetpos(FILE *stream, fpos_t *pos) 48 { 49 off64_t p; 50 51 p = ftell64(stream); 52 if (p < 0) 53 return -1; 54 55 pos->pos = p; 56 return 0; 57 } 58 59 /** Get stream position. 60 * 61 * @param stream Stream 62 * @param pos Position 63 * 64 * @return Zero on sucess, non-zero on failure 65 */ 66 int fsetpos(FILE *stream, const fpos_t *pos) 67 { 68 int rc; 69 70 rc = fseek64(stream, pos->pos, SEEK_SET); 71 if (rc < 0) 72 return -1; 73 74 return 0; 75 } 38 76 39 77 /** Rename file or directory (C standard) */ … … 65 103 } 66 104 105 /** Print error message and string representation of @c errno. 106 * 107 * @param s Error message 108 */ 109 void perror(const char *s) 110 { 111 if (s != NULL && *s != '\0') 112 fprintf(stderr, "%s: %s\n", s, str_error(errno)); 113 else 114 fprintf(stderr, "%s\n", str_error(errno)); 115 } 116 67 117 /** @} 68 118 */ -
uspace/lib/c/include/stdio.h
r7d7bc09 r777832e 1 1 /* 2 2 * Copyright (c) 2005 Martin Decky 3 * Copyright (c) 2018 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 36 37 #define LIBC_STDIO_H_ 37 38 39 #include <offset.h> 38 40 #include <stdarg.h> 39 41 #include <io/verify.h> … … 59 61 #define BUFSIZ 4096 60 62 63 /** Max number of files that is guaranteed to be able to open at the same time */ 64 #define FOPEN_MAX VFS_MAX_OPEN_FILES 65 61 66 /** Recommended size of fixed-size array for holding file names. */ 62 67 #define FILENAME_MAX 4096 … … 65 70 struct _IO_FILE; 66 71 typedef struct _IO_FILE FILE; 72 73 /** File position */ 74 typedef struct { 75 off64_t pos; 76 } fpos_t; 67 77 68 78 extern FILE *stdin; … … 124 134 extern size_t fwrite(const void *, size_t, size_t, FILE *); 125 135 136 extern int fgetpos(FILE *, fpos_t *); 137 extern int fsetpos(FILE *, const fpos_t *); 138 126 139 extern int fseek(FILE *, long, int); 127 140 extern void rewind(FILE *); … … 132 145 extern int ferror(FILE *); 133 146 extern void clearerr(FILE *); 147 148 extern void perror(const char *); 134 149 135 150 extern void setvbuf(FILE *, void *, int, size_t); -
uspace/lib/c/include/vfs/vfs.h
r7d7bc09 r777832e 45 45 #include <offset.h> 46 46 47 #define MAX_OPEN_FILES 12847 #define VFS_MAX_OPEN_FILES 128 48 48 49 49 enum vfs_change_state_type { -
uspace/lib/posix/include/posix/stdio.h
r7d7bc09 r777832e 59 59 FILE *__restrict__ stream); 60 60 61 /* Error Messages */62 extern void perror(const char *s);63 64 /* File Positioning */65 typedef struct {66 off64_t offset;67 } fpos_t;68 69 extern int fsetpos(FILE *stream, const fpos_t *pos);70 extern int fgetpos(FILE *__restrict__ stream, fpos_t *__restrict__ pos);71 61 extern int fseeko(FILE *stream, off_t offset, int whence); 72 62 extern off_t ftello(FILE *stream); -
uspace/lib/posix/src/internal/common.h
r7d7bc09 r777832e 66 66 } 67 67 68 extern aoff64_t posix_pos[ MAX_OPEN_FILES];68 extern aoff64_t posix_pos[VFS_MAX_OPEN_FILES]; 69 69 70 70 #endif /* LIBPOSIX_COMMON_H_ */ -
uspace/lib/posix/src/stdio.c
r7d7bc09 r777832e 169 169 170 170 /** 171 * Write error messages to standard error.172 *173 * @param s Error message.174 */175 void perror(const char *s)176 {177 if (s == NULL || s[0] == '\0') {178 fprintf(stderr, "%s\n", strerror(errno));179 } else {180 fprintf(stderr, "%s: %s\n", s, strerror(errno));181 }182 }183 184 /** Restores stream a to position previously saved with fgetpos().185 *186 * @param stream Stream to restore187 * @param pos Position to restore188 * @return Zero on success, non-zero (with errno set) on failure189 */190 int fsetpos(FILE *stream, const fpos_t *pos)191 {192 return fseek64(stream, pos->offset, SEEK_SET);193 }194 195 /** Saves the stream's position for later use by fsetpos().196 *197 * @param stream Stream to save198 * @param pos Place to store the position199 * @return Zero on success, non-zero (with errno set) on failure200 */201 int fgetpos(FILE *restrict stream, fpos_t *restrict pos)202 {203 off64_t ret = ftell64(stream);204 if (ret != -1) {205 pos->offset = ret;206 return 0;207 } else {208 return -1;209 }210 }211 212 /**213 171 * Reposition a file-position indicator in a stream. 214 172 * -
uspace/lib/posix/src/unistd.c
r7d7bc09 r777832e 51 51 52 52 // FIXME: replace with a hash table 53 aoff64_t posix_pos[ MAX_OPEN_FILES];53 aoff64_t posix_pos[VFS_MAX_OPEN_FILES]; 54 54 55 55 /* Array of environment variable strings (NAME=VALUE). */ -
uspace/srv/vfs/vfs_file.c
r7d7bc09 r777832e 71 71 fibril_mutex_lock(&vfs_data->lock); 72 72 if (!vfs_data->files) { 73 vfs_data->files = malloc( MAX_OPEN_FILES * sizeof(vfs_file_t *));73 vfs_data->files = malloc(VFS_MAX_OPEN_FILES * sizeof(vfs_file_t *)); 74 74 if (!vfs_data->files) { 75 75 fibril_mutex_unlock(&vfs_data->lock); 76 76 return false; 77 77 } 78 memset(vfs_data->files, 0, MAX_OPEN_FILES * sizeof(vfs_file_t *));78 memset(vfs_data->files, 0, VFS_MAX_OPEN_FILES * sizeof(vfs_file_t *)); 79 79 } 80 80 fibril_mutex_unlock(&vfs_data->lock); … … 90 90 return; 91 91 92 for (i = 0; i < MAX_OPEN_FILES; i++) {92 for (i = 0; i < VFS_MAX_OPEN_FILES; i++) { 93 93 if (vfs_data->files[i]) 94 94 (void) _vfs_fd_free(vfs_data, i); … … 199 199 unsigned int i; 200 200 if (desc) 201 i = MAX_OPEN_FILES - 1;201 i = VFS_MAX_OPEN_FILES - 1; 202 202 else 203 203 i = 0; … … 233 233 i--; 234 234 } else { 235 if (i == MAX_OPEN_FILES - 1)235 if (i == VFS_MAX_OPEN_FILES - 1) 236 236 break; 237 237 … … 261 261 static errno_t _vfs_fd_free_locked(vfs_client_data_t *vfs_data, int fd) 262 262 { 263 if ((fd < 0) || (fd >= MAX_OPEN_FILES) || !vfs_data->files[fd]) {263 if ((fd < 0) || (fd >= VFS_MAX_OPEN_FILES) || !vfs_data->files[fd]) { 264 264 return EBADF; 265 265 } … … 311 311 312 312 fibril_mutex_lock(&VFS_DATA->lock); 313 if ((fd < 0) || (fd >= MAX_OPEN_FILES)) {313 if ((fd < 0) || (fd >= VFS_MAX_OPEN_FILES)) { 314 314 fibril_mutex_unlock(&VFS_DATA->lock); 315 315 return EBADF; … … 342 342 343 343 fibril_mutex_lock(&vfs_data->lock); 344 if ((fd >= 0) && (fd < MAX_OPEN_FILES)) {344 if ((fd >= 0) && (fd < VFS_MAX_OPEN_FILES)) { 345 345 vfs_file_t *file = vfs_data->files[fd]; 346 346 if (file != NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.