add open(2) shim to handle O_BINARY and O_CLOEXEC
This commit is contained in:
parent
51a53876b6
commit
f21bd20c7e
@ -12,6 +12,7 @@
|
|||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -39,6 +40,28 @@ posix_fopen(const char *path, const char *mode)
|
|||||||
return fopen(path, 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 *
|
char *
|
||||||
posix_fgets(char *s, int size, FILE *stream)
|
posix_fgets(char *s, int size, FILE *stream)
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,7 @@ posix_close
|
|||||||
posix_connect
|
posix_connect
|
||||||
posix_fgets
|
posix_fgets
|
||||||
posix_fopen
|
posix_fopen
|
||||||
|
posix_open
|
||||||
posix_read
|
posix_read
|
||||||
posix_rename
|
posix_rename
|
||||||
posix_write
|
posix_write
|
||||||
|
@ -29,4 +29,10 @@
|
|||||||
#define FD_CLOEXEC 1
|
#define FD_CLOEXEC 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int posix_open(const char *path, ...);
|
||||||
|
|
||||||
|
#ifndef NO_REDEF_POSIX_FUNCTIONS
|
||||||
|
#define open(path, ...) posix_open(path, __VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -201,6 +201,7 @@ if test "x$HOST_OS" = "xwin" ; then
|
|||||||
echo posix_perror >> $crypto_p_sym
|
echo posix_perror >> $crypto_p_sym
|
||||||
echo posix_fopen >> $crypto_p_sym
|
echo posix_fopen >> $crypto_p_sym
|
||||||
echo posix_fgets >> $crypto_p_sym
|
echo posix_fgets >> $crypto_p_sym
|
||||||
|
echo posix_open >> $crypto_p_sym
|
||||||
echo posix_rename >> $crypto_p_sym
|
echo posix_rename >> $crypto_p_sym
|
||||||
echo posix_connect >> $crypto_p_sym
|
echo posix_connect >> $crypto_p_sym
|
||||||
echo posix_close >> $crypto_p_sym
|
echo posix_close >> $crypto_p_sym
|
||||||
|
Loading…
x
Reference in New Issue
Block a user