pipe_internal.c (719B)
1 /* ISC license. */ 2 3 #include <skalibs/sysdeps.h> 4 5 #ifdef SKALIBS_HASPIPE2 6 7 #include <skalibs/nonposix.h> 8 #include <unistd.h> 9 10 #include <skalibs/djbunix.h> 11 12 int pipe_internal (int *p, unsigned int flags) 13 { 14 return pipe2(p, flags) ; 15 } 16 17 #else 18 19 #include <unistd.h> 20 21 #include <skalibs/fcntl.h> 22 #include <skalibs/djbunix.h> 23 24 int pipe_internal (int *p, unsigned int flags) 25 { 26 int pi[2] ; 27 if (pipe(pi) < 0) return -1 ; 28 if (flags & O_CLOEXEC) 29 if ((coe(pi[0]) < 0) || (coe(pi[1]) < 0)) goto err ; 30 if (flags & O_NONBLOCK) 31 if ((ndelay_on(pi[0]) < 0) || (ndelay_on(pi[1]) < 0)) goto err ; 32 p[0] = pi[0] ; p[1] = pi[1] ; 33 return 0 ; 34 err: 35 { 36 fd_close(pi[1]) ; 37 fd_close(pi[0]) ; 38 } 39 return -1 ; 40 } 41 42 #endif