all file IO should be binary, auto-append the flag

This commit is contained in:
Brent Cook 2015-06-05 03:31:28 -05:00 committed by Brent Cook
parent 8eec2f485a
commit b239fc25fc

View File

@ -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