Changes in uspace/lib/c/generic/stdio.c [5a6cc679:bfe90b6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/stdio.c
r5a6cc679 rbfe90b6 1 1 /* 2 * Copyright (c) 201 7Jiri Svoboda2 * Copyright (c) 2018 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 34 34 35 35 #include <errno.h> 36 #include <stdbool.h> 36 37 #include <stdio.h> 38 #include <str.h> 39 #include <str_error.h> 40 #include <tmpfile.h> 37 41 #include <vfs/vfs.h> 42 43 /** Static buffer for tmpnam function */ 44 static char tmpnam_buf[L_tmpnam]; 45 46 /** Get stream position. 47 * 48 * @param stream Stream 49 * @param pos Place to store position 50 * 51 * @return Zero on success, non-zero on failure 52 */ 53 int fgetpos(FILE *stream, fpos_t *pos) 54 { 55 off64_t p; 56 57 p = ftell64(stream); 58 if (p < 0) 59 return -1; 60 61 pos->pos = p; 62 return 0; 63 } 64 65 /** Get stream position. 66 * 67 * @param stream Stream 68 * @param pos Position 69 * 70 * @return Zero on sucess, non-zero on failure 71 */ 72 int fsetpos(FILE *stream, const fpos_t *pos) 73 { 74 int rc; 75 76 rc = fseek64(stream, pos->pos, SEEK_SET); 77 if (rc < 0) 78 return -1; 79 80 return 0; 81 } 38 82 39 83 /** Rename file or directory (C standard) */ … … 44 88 rc = vfs_rename_path(old_path, new_path); 45 89 if (rc != EOK) { 90 /* 91 * Note that ISO C leaves the value of errno undefined, 92 * whereas according to UN*X standards, it is set. 93 */ 46 94 errno = rc; 47 95 return -1; … … 58 106 rc = vfs_unlink_path(path); 59 107 if (rc != EOK) { 108 /* 109 * Note that ISO C leaves the value of errno undefined, 110 * whereas according to UN*X standards, it is set. 111 */ 60 112 errno = rc; 61 113 return -1; … … 65 117 } 66 118 119 /** Create a temporary file. 120 * 121 * @return Open stream descriptor or @c NULL on error. In that case 122 * errno is set (UN*X). Note that ISO C leaves the value of errno 123 * undefined. 124 */ 125 FILE *tmpfile(void) 126 { 127 int file; 128 FILE *stream; 129 130 file = __tmpfile(); 131 if (file < 0) { 132 printf("file is < 0\n"); 133 errno = EEXIST; 134 return NULL; 135 } 136 137 stream = fdopen(file, "w+"); 138 if (stream == NULL) { 139 printf("stream = NULL\n"); 140 vfs_put(file); 141 errno = EACCES; 142 return NULL; 143 } 144 145 return stream; 146 } 147 148 /** Create name for a temporary file. 149 * 150 * @param s Pointer to array of at least L_tmpnam bytes or @c NULL. 151 * @return The pointer @a s or pointer to internal static buffer on success, 152 * @c NULL on error. 153 */ 154 char *tmpnam(char *s) 155 { 156 char *p; 157 158 p = (s != NULL) ? s : tmpnam_buf; 159 return __tmpnam(p); 160 } 161 162 /** Print error message and string representation of @c errno. 163 * 164 * @param s Error message 165 */ 166 void perror(const char *s) 167 { 168 if (s != NULL && *s != '\0') 169 fprintf(stderr, "%s: %s\n", s, str_error(errno)); 170 else 171 fprintf(stderr, "%s\n", str_error(errno)); 172 } 173 174 67 175 /** @} 68 176 */
Note:
See TracChangeset
for help on using the changeset viewer.