Import selfpipe code from skalibs 1.2.5

[andersk@mit.edu: Move code to new third/libstddjb directory]
This commit is contained in:
Quentin Smith
2012-02-26 15:58:37 -05:00
committed by Keith Winstein
parent 9a3ab83783
commit 77f3a9073f
24 changed files with 697 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
/* ISC license. */
#include "sysdeps.h"
#ifdef HASPIPE2
# define _GNU_SOURCE
# include <fcntl.h>
#else
# include <errno.h>
#endif
#include <unistd.h>
#include "djbunix.h"
int pipe_internal (int *p, unsigned int flags)
{
#ifdef HASPIPE2
return pipe2(p, ((flags & DJBUNIX_FLAG_COE) ? O_CLOEXEC : 0) | ((flags & DJBUNIX_FLAG_NB) ? O_NONBLOCK : 0)) ;
#else
int pi[2] ;
if (pipe(pi) < 0) return -1 ;
if (flags & DJBUNIX_FLAG_COE)
if ((coe(pi[0]) < 0) || (coe(pi[1]) < 0)) goto err ;
if (flags & DJBUNIX_FLAG_NB)
if ((ndelay_on(pi[0]) < 0) || (ndelay_on(pi[1]) < 0)) goto err ;
p[0] = pi[0] ; p[1] = pi[1] ;
return 0 ;
err:
{
register int e = errno ;
fd_close(pi[1]) ;
fd_close(pi[0]) ;
errno = e ;
}
return -1 ;
#endif
}