diff options
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 |