add open(2) shim to handle O_BINARY and O_CLOEXEC

This commit is contained in:
Brent Cook 2017-01-16 09:56:20 -06:00
parent 51a53876b6
commit f21bd20c7e
4 changed files with 31 additions and 0 deletions

View File

@ -12,6 +12,7 @@
#include <ws2tcpip.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -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)
{

View File

@ -7,6 +7,7 @@ posix_close
posix_connect
posix_fgets
posix_fopen
posix_open
posix_read
posix_rename
posix_write

View File

@ -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

View File

@ -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