From b239fc25fcde7ec6f305fff290bc762d14397d15 Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Fri, 5 Jun 2015 03:31:28 -0500 Subject: all file IO should be binary, auto-append the flag --- include/stdio.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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) } #define perror(errnum) posix_perror(errnum) + +static inline FILE * +posix_fopen(const char *path, const char *mode) +{ + char *bin_mode = mode; + if (strchr(mode, 'b') == NULL) { + bin_mode = NULL; + if (asprintf(&bin_mode, "%sb", mode) == -1) + return NULL; + fprintf(stderr, "opening bin file %s\n", bin_mode); + } + + FILE *f = fopen(path, bin_mode); + if (bin_mode != mode) + free(bin_mode); + return f; +} + +#define fopen(path, mode) posix_fopen(path, mode) + #endif #endif -- cgit v1.2.3-55-g6feb