diff options
-rw-r--r-- | include/stdio.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/stdio.h b/include/stdio.h index ab17883..db369c9 100644 --- a/include/stdio.h +++ b/include/stdio.h | |||
@@ -25,6 +25,26 @@ posix_perror(const char *s) | |||
25 | } | 25 | } |
26 | 26 | ||
27 | #define perror(errnum) posix_perror(errnum) | 27 | #define perror(errnum) posix_perror(errnum) |
28 | |||
29 | static inline FILE * | ||
30 | posix_fopen(const char *path, const char *mode) | ||
31 | { | ||
32 | char *bin_mode = mode; | ||
33 | if (strchr(mode, 'b') == NULL) { | ||
34 | bin_mode = NULL; | ||
35 | if (asprintf(&bin_mode, "%sb", mode) == -1) | ||
36 | return NULL; | ||
37 | fprintf(stderr, "opening bin file %s\n", bin_mode); | ||
38 | } | ||
39 | |||
40 | FILE *f = fopen(path, bin_mode); | ||
41 | if (bin_mode != mode) | ||
42 | free(bin_mode); | ||
43 | return f; | ||
44 | } | ||
45 | |||
46 | #define fopen(path, mode) posix_fopen(path, mode) | ||
47 | |||
28 | #endif | 48 | #endif |
29 | 49 | ||
30 | #endif | 50 | #endif |