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 @@ #include #include +#include #include #include #include @@ -39,6 +40,28 @@ posix_fopen(const char *path, const char *mode) return fopen(path, mode); } +int +posix_open(const char *path, ...) +{ + va_list ap; + mode_t mode = 0; + int flags; + + va_start(ap, path); + flags = va_arg(ap, int); + if (flags & O_CREAT) + mode = va_arg(ap, int); + va_end(ap); + + flags |= O_BINARY; + if (flags & O_CLOEXEC) { + flags &= ~O_CLOEXEC; + flags |= O_NOINHERIT; + } + flags &= ~O_NONBLOCK; + return open(path, flags, mode); +} + char * posix_fgets(char *s, int size, FILE *stream) { 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 posix_connect posix_fgets posix_fopen +posix_open posix_read posix_rename 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 @@ #define FD_CLOEXEC 1 #endif +int posix_open(const char *path, ...); + +#ifndef NO_REDEF_POSIX_FUNCTIONS +#define open(path, ...) posix_open(path, __VA_ARGS__) +#endif + #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 echo posix_perror >> $crypto_p_sym echo posix_fopen >> $crypto_p_sym echo posix_fgets >> $crypto_p_sym + echo posix_open >> $crypto_p_sym echo posix_rename >> $crypto_p_sym echo posix_connect >> $crypto_p_sym echo posix_close >> $crypto_p_sym