diff options
Diffstat (limited to 'include/stdio.h')
| -rw-r--r-- | include/stdio.h | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/include/stdio.h b/include/stdio.h index db369c9..76bd9da 100644 --- a/include/stdio.h +++ b/include/stdio.h | |||
| @@ -15,35 +15,16 @@ int asprintf(char **str, const char *fmt, ...); | |||
| 15 | #endif | 15 | #endif |
| 16 | 16 | ||
| 17 | #ifdef _WIN32 | 17 | #ifdef _WIN32 |
| 18 | #include <errno.h> | ||
| 19 | #include <string.h> | ||
| 20 | 18 | ||
| 21 | static inline void | 19 | void posix_perror(const char *s); |
| 22 | posix_perror(const char *s) | 20 | FILE * posix_fopen(const char *path, const char *mode); |
| 23 | { | 21 | int posix_rename(const char *oldpath, const char *newpath); |
| 24 | fprintf(stderr, "%s: %s\n", s, strerror(errno)); | ||
| 25 | } | ||
| 26 | 22 | ||
| 23 | #ifndef NO_REDEF_POSIX_FUNCTIONS | ||
| 27 | #define perror(errnum) posix_perror(errnum) | 24 | #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) | 25 | #define fopen(path, mode) posix_fopen(path, mode) |
| 26 | #define rename(oldpath, newpath) posix_rename(oldpath, newpath) | ||
| 27 | #endif | ||
| 47 | 28 | ||
| 48 | #endif | 29 | #endif |
| 49 | 30 | ||
