Changes in / [9ec25a6:b670523] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/stdio.c
r9ec25a6 rb670523 35 35 #define POSIX_INTERNAL 36 36 37 #include <assert.h>38 #include "errno.h"39 37 #include "common.h" 40 38 #include "stdio.h" 41 #include "string.h"42 /* not the best of solutions, but freopen will eventually43 need to be implemented in libc anyway */44 #include "../c/generic/private/stdio.h"45 39 46 40 FILE *posix_freopen(const char *restrict filename, … … 48 42 FILE *restrict stream) 49 43 { 50 assert(mode != NULL); 51 assert(stream != NULL); 52 53 if (filename == NULL) { 54 // TODO 55 56 /* print error to stderr as well, to avoid hard to find problems 57 with buggy apps that expect this to work */ 58 fprintf(stderr, "ERROR: Application wants to use freopen() to change mode of opened stream.\n" 59 " libposix does not support that yet, the application may function improperly.\n"); 60 errno = ENOTSUP; 61 return NULL; 62 } 63 64 FILE* copy = malloc(sizeof(FILE)); 65 if (copy == NULL) { 66 errno = ENOMEM; 67 return NULL; 68 } 69 memcpy(copy, stream, sizeof(FILE)); 70 fclose(copy); /* copy is now freed */ 71 72 copy = fopen(filename, mode); /* open new stream */ 73 if (copy == NULL) { 74 /* fopen() sets errno */ 75 return NULL; 76 } 77 78 /* move the new stream to the original location */ 79 memcpy(stream, copy, sizeof (FILE)); 80 free(copy); 81 82 /* update references in the file list */ 83 stream->link.next->prev = &stream->link; 84 stream->link.prev->next = &stream->link; 85 86 return stream; 44 // TODO 45 not_implemented(); 87 46 } 88 47
Note:
See TracChangeset
for help on using the changeset viewer.