open3.c (677B)
1 /* ISC license. */ 2 3 #include <skalibs/sysdeps.h> 4 #include <skalibs/nonposix.h> 5 6 #include <sys/stat.h> 7 #include <errno.h> 8 9 #include <skalibs/fcntl.h> 10 #include <skalibs/djbunix.h> 11 12 #ifdef SKALIBS_HASOCLOEXEC 13 14 int open3 (char const *s, unsigned int flags, unsigned int mode) 15 { 16 int r ; 17 do r = open(s, flags, mode) ; 18 while (r == -1 && errno == EINTR) ; 19 return r ; 20 } 21 22 #else 23 24 int open3 (char const *s, unsigned int flags, unsigned int mode) 25 { 26 int fd ; 27 do fd = open(s, flags & ~O_CLOEXEC, mode) ; 28 while (fd == -1 && errno == EINTR) ; 29 if (fd == -1) return -1 ; 30 if (flags & O_CLOEXEC && coe(fd) == -1) 31 { 32 fd_close(fd) ; 33 return -1 ; 34 } 35 return fd ; 36 } 37 38 #endif