Changeset 80bee81 in mainline for uspace/lib/posix/source/stdio.c
- Timestamp:
- 2015-09-21T22:40:52Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a955fcc
- Parents:
- 7db5cfd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/source/stdio.c
r7db5cfd r80bee81 55 55 #include "libc/sys/stat.h" 56 56 57 58 /* not the best of solutions, but freopen and ungetc will eventually59 * need to be implemented in libc anyway60 */61 #include "../../c/generic/private/stdio.h"62 63 57 /** Clears the stream's error and end-of-file indicators. 64 58 * … … 67 61 void posix_clearerr(FILE *stream) 68 62 { 69 stream->error = 0; 70 stream->eof = 0; 63 clearerr(stream); 71 64 } 72 65 … … 221 214 const char *restrict mode, FILE *restrict stream) 222 215 { 223 assert(mode != NULL); 224 assert(stream != NULL); 225 226 if (filename == NULL) { 227 /* POSIX allows this to be imlementation-defined. HelenOS currently 228 * does not support changing the mode. */ 229 // FIXME: handle mode change once it is supported 230 return stream; 231 } 232 233 /* Open a new stream. */ 234 FILE* new = fopen(filename, mode); 235 if (new == NULL) { 236 fclose(stream); 237 /* errno was set by fopen() */ 238 return NULL; 239 } 240 241 /* Close the original stream without freeing it (ignoring errors). */ 242 if (stream->buf != NULL) { 243 fflush(stream); 244 } 245 if (stream->sess != NULL) { 246 async_hangup(stream->sess); 247 } 248 if (stream->fd >= 0) { 249 close(stream->fd); 250 } 251 list_remove(&stream->link); 252 253 /* Move the new stream to the original location. */ 254 memcpy(stream, new, sizeof (FILE)); 255 free(new); 256 257 /* Update references in the file list. */ 258 stream->link.next->prev = &stream->link; 259 stream->link.prev->next = &stream->link; 260 261 return stream; 216 return freopen(filename, mode, stream); 262 217 } 263 218
Note:
See TracChangeset
for help on using the changeset viewer.