diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-18 18:55:44 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-18 18:55:44 +0000 |
commit | 3534b428629be185e096be99e3bd5fdfe32d5544 (patch) | |
tree | 210ef3198ed66bc7f7b7bf6a85e4579f455e5a36 /src/libstddjb/pipe_internal.c | |
download | skalibs-3534b428629be185e096be99e3bd5fdfe32d5544.tar.xz |
initial commit with rc for skalibs-2.0.0.0
Diffstat (limited to 'src/libstddjb/pipe_internal.c')
-rw-r--r-- | src/libstddjb/pipe_internal.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/libstddjb/pipe_internal.c b/src/libstddjb/pipe_internal.c new file mode 100644 index 0000000..d5354de --- /dev/null +++ b/src/libstddjb/pipe_internal.c @@ -0,0 +1,45 @@ +/* ISC license. */ + +#include <skalibs/sysdeps.h> + +#ifdef SKALIBS_HASPIPE2 + +#define _NETBSD_SOURCE +#define _GNU_SOURCE + +#include <unistd.h> +#include <fcntl.h> +#include <skalibs/djbunix.h> + +int pipe_internal (int *p, unsigned int flags) +{ + return pipe2(p, ((flags & DJBUNIX_FLAG_COE) ? O_CLOEXEC : 0) | ((flags & DJBUNIX_FLAG_NB) ? O_NONBLOCK : 0)) ; +} + +#else + +#include <unistd.h> +#include <errno.h> +#include <skalibs/djbunix.h> + +int pipe_internal (int *p, unsigned int flags) +{ + 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 |