diff options
author | Brent Cook <busterb@gmail.com> | 2017-01-16 09:56:20 -0600 |
---|---|---|
committer | Brent Cook <busterb@gmail.com> | 2017-01-16 10:59:15 -0600 |
commit | f21bd20c7e1d073db7a5e6b37928caae492eb1c5 (patch) | |
tree | 4652e8e2db4de4bb89525d021fbbb7454d887cec | |
parent | 51a53876b623f751e076fa66cdf2b99df06b2028 (diff) | |
download | portable-f21bd20c7e1d073db7a5e6b37928caae492eb1c5.tar.gz portable-f21bd20c7e1d073db7a5e6b37928caae492eb1c5.tar.bz2 portable-f21bd20c7e1d073db7a5e6b37928caae492eb1c5.zip |
add open(2) shim to handle O_BINARY and O_CLOEXEC
-rw-r--r-- | crypto/compat/posix_win.c | 23 | ||||
-rw-r--r-- | crypto/crypto_win.list | 1 | ||||
-rw-r--r-- | include/compat/fcntl.h | 6 | ||||
-rw-r--r-- | m4/check-libc.m4 | 1 |
4 files changed, 31 insertions, 0 deletions
diff --git a/crypto/compat/posix_win.c b/crypto/compat/posix_win.c index 05a20bb..331f88e 100644 --- a/crypto/compat/posix_win.c +++ b/crypto/compat/posix_win.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <ws2tcpip.h> | 12 | #include <ws2tcpip.h> |
13 | 13 | ||
14 | #include <errno.h> | 14 | #include <errno.h> |
15 | #include <fcntl.h> | ||
15 | #include <stdint.h> | 16 | #include <stdint.h> |
16 | #include <stdio.h> | 17 | #include <stdio.h> |
17 | #include <stdlib.h> | 18 | #include <stdlib.h> |
@@ -39,6 +40,28 @@ posix_fopen(const char *path, const char *mode) | |||
39 | return fopen(path, mode); | 40 | return fopen(path, mode); |
40 | } | 41 | } |
41 | 42 | ||
43 | int | ||
44 | posix_open(const char *path, ...) | ||
45 | { | ||
46 | va_list ap; | ||
47 | mode_t mode = 0; | ||
48 | int flags; | ||
49 | |||
50 | va_start(ap, path); | ||
51 | flags = va_arg(ap, int); | ||
52 | if (flags & O_CREAT) | ||
53 | mode = va_arg(ap, int); | ||
54 | va_end(ap); | ||
55 | |||
56 | flags |= O_BINARY; | ||
57 | if (flags & O_CLOEXEC) { | ||
58 | flags &= ~O_CLOEXEC; | ||
59 | flags |= O_NOINHERIT; | ||
60 | } | ||
61 | flags &= ~O_NONBLOCK; | ||
62 | return open(path, flags, mode); | ||
63 | } | ||
64 | |||
42 | char * | 65 | char * |
43 | posix_fgets(char *s, int size, FILE *stream) | 66 | posix_fgets(char *s, int size, FILE *stream) |
44 | { | 67 | { |
diff --git a/crypto/crypto_win.list b/crypto/crypto_win.list index 6f89a43..37c02a5 100644 --- a/crypto/crypto_win.list +++ b/crypto/crypto_win.list | |||
@@ -7,6 +7,7 @@ posix_close | |||
7 | posix_connect | 7 | posix_connect |
8 | posix_fgets | 8 | posix_fgets |
9 | posix_fopen | 9 | posix_fopen |
10 | posix_open | ||
10 | posix_read | 11 | posix_read |
11 | posix_rename | 12 | posix_rename |
12 | posix_write | 13 | posix_write |
diff --git a/include/compat/fcntl.h b/include/compat/fcntl.h index 99c2d58..edc468a 100644 --- a/include/compat/fcntl.h +++ b/include/compat/fcntl.h | |||
@@ -29,4 +29,10 @@ | |||
29 | #define FD_CLOEXEC 1 | 29 | #define FD_CLOEXEC 1 |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | int posix_open(const char *path, ...); | ||
33 | |||
34 | #ifndef NO_REDEF_POSIX_FUNCTIONS | ||
35 | #define open(path, ...) posix_open(path, __VA_ARGS__) | ||
36 | #endif | ||
37 | |||
32 | #endif | 38 | #endif |
diff --git a/m4/check-libc.m4 b/m4/check-libc.m4 index 54efc37..3c0ed31 100644 --- a/m4/check-libc.m4 +++ b/m4/check-libc.m4 | |||
@@ -201,6 +201,7 @@ if test "x$HOST_OS" = "xwin" ; then | |||
201 | echo posix_perror >> $crypto_p_sym | 201 | echo posix_perror >> $crypto_p_sym |
202 | echo posix_fopen >> $crypto_p_sym | 202 | echo posix_fopen >> $crypto_p_sym |
203 | echo posix_fgets >> $crypto_p_sym | 203 | echo posix_fgets >> $crypto_p_sym |
204 | echo posix_open >> $crypto_p_sym | ||
204 | echo posix_rename >> $crypto_p_sym | 205 | echo posix_rename >> $crypto_p_sym |
205 | echo posix_connect >> $crypto_p_sym | 206 | echo posix_connect >> $crypto_p_sym |
206 | echo posix_close >> $crypto_p_sym | 207 | echo posix_close >> $crypto_p_sym |