aboutsummaryrefslogtreecommitdiff
path: root/include/stdio.h
diff options
context:
space:
mode:
authorBrent Cook <busterb@gmail.com>2015-06-05 04:31:56 -0500
committerBrent Cook <bcook@openbsd.org>2015-06-05 04:50:18 -0500
commitb4a6a615134b59435efbecdd8c5b5407b6af8e8f (patch)
tree7e1b645be3b352fab0021da3b0e43e78a423347a /include/stdio.h
parent1d27b22e82ce00d27d0886c8488e4cbed1cb618e (diff)
downloadportable-b4a6a615134b59435efbecdd8c5b5407b6af8e8f.tar.gz
portable-b4a6a615134b59435efbecdd8c5b5407b6af8e8f.tar.bz2
portable-b4a6a615134b59435efbecdd8c5b5407b6af8e8f.zip
refactor win32 shims into posix_win.c
this also adds a rename shim that allows overwrites
Diffstat (limited to 'include/stdio.h')
-rw-r--r--include/stdio.h31
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
21static inline void 19void posix_perror(const char *s);
22posix_perror(const char *s) 20FILE * posix_fopen(const char *path, const char *mode);
23{ 21int 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
29static inline FILE *
30posix_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