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 /crypto | |
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
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/compat/posix_win.c | 23 | ||||
-rw-r--r-- | crypto/crypto_win.list | 1 |
2 files changed, 24 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 |