diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2024-04-16 12:57:52 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2024-04-16 12:57:52 +0000 |
commit | 825b80eaa311b0aec4c00614f38f3eb63949d5a7 (patch) | |
tree | 624f702487d9acdd3cc85060cfe2edc388cf7096 /src/libstddjb/open2.c | |
parent | bfc53cfde4fdda343647678fcd21b38a44f2de08 (diff) | |
download | skalibs-825b80eaa311b0aec4c00614f38f3eb63949d5a7.tar.xz |
Tentative support for old MacOS with no O_CLOEXEC
Also add a prototype for gol, not finished yet.
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libstddjb/open2.c')
-rw-r--r-- | src/libstddjb/open2.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/libstddjb/open2.c b/src/libstddjb/open2.c index 1d2682e..0f23183 100644 --- a/src/libstddjb/open2.c +++ b/src/libstddjb/open2.c @@ -1,14 +1,38 @@ /* ISC license. */ +#include <skalibs/sysdeps.h> #include <skalibs/nonposix.h> + #include <sys/stat.h> -#include <fcntl.h> #include <errno.h> +#include <skalibs/fcntl.h> +#include <skalibs/djbunix.h> + +#ifdef SKALIBS_HASOCLOEXEC + int open2 (char const *s, unsigned int flags) { int r ; do r = open(s, flags) ; - while ((r == -1) && (errno == EINTR)) ; + while (r == -1 && errno == EINTR) ; return r ; } + +#else + +int open2 (char const *s, unsigned int flags) +{ + int fd ; + do fd = open(s, flags & ~O_CLOEXEC) ; + while (fd == -1 && errno == EINTR) ; + if (fd == -1) return -1 ; + if (flags & O_CLOEXEC && coe(fd) == -1) + { + fd_close(fd) ; + return -1 ; + } + return fd ; +} + +#endif |