diff options
| author | Brent Cook <busterb@gmail.com> | 2015-06-05 03:31:28 -0500 |
|---|---|---|
| committer | Brent Cook <bcook@openbsd.org> | 2015-06-05 04:50:17 -0500 |
| commit | b239fc25fcde7ec6f305fff290bc762d14397d15 (patch) | |
| tree | 249acdd157a32f349ef2680b3156d6d65d1a0438 /include | |
| parent | 8eec2f485a9aa4adda7fec46b15771b29c3ac9ee (diff) | |
| download | portable-b239fc25fcde7ec6f305fff290bc762d14397d15.tar.gz portable-b239fc25fcde7ec6f305fff290bc762d14397d15.tar.bz2 portable-b239fc25fcde7ec6f305fff290bc762d14397d15.zip | |
all file IO should be binary, auto-append the flag
Diffstat (limited to 'include')
| -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 |
