Changes in uspace/lib/c/generic/stdio.c [bfe90b6:5a6cc679] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/stdio.c
rbfe90b6 r5a6cc679 1 1 /* 2 * Copyright (c) 201 8Jiri Svoboda2 * Copyright (c) 2017 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 34 34 35 35 #include <errno.h> 36 #include <stdbool.h>37 36 #include <stdio.h> 38 #include <str.h>39 #include <str_error.h>40 #include <tmpfile.h>41 37 #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 Stream49 * @param pos Place to store position50 *51 * @return Zero on success, non-zero on failure52 */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 Stream68 * @param pos Position69 *70 * @return Zero on sucess, non-zero on failure71 */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 }82 38 83 39 /** Rename file or directory (C standard) */ … … 88 44 rc = vfs_rename_path(old_path, new_path); 89 45 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 */94 46 errno = rc; 95 47 return -1; … … 106 58 rc = vfs_unlink_path(path); 107 59 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 */112 60 errno = rc; 113 61 return -1; … … 117 65 } 118 66 119 /** Create a temporary file.120 *121 * @return Open stream descriptor or @c NULL on error. In that case122 * errno is set (UN*X). Note that ISO C leaves the value of errno123 * 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 message165 */166 void perror(const char *s)167 {168 if (s != NULL && *s != '\0')169 fprintf(stderr, "%s: %s\n", s, str_error(errno));170 else171 fprintf(stderr, "%s\n", str_error(errno));172 }173 174 175 67 /** @} 176 68 */
Note:
See TracChangeset
for help on using the changeset viewer.