diff options
Diffstat (limited to 'src/pipeutils.c')
-rw-r--r-- | src/pipeutils.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/pipeutils.c b/src/pipeutils.c index 200fb6d..9202910 100644 --- a/src/pipeutils.c +++ b/src/pipeutils.c @@ -19,19 +19,40 @@ #include "common.h" -#ifndef _WIN32 +#ifdef WINDOWS + +/* Create non-blocking set of pipe fds. + + Not supported on Windows! Always fails. */ +int +pipeutils_create_nonblocking(int pipefds[2]) +{ + return -1; +} + +#else /* Create non-blocking set of pipe fds. */ int pipeutils_create_nonblocking(int pipefds[2]) { - int r = pipe(pipefds); - if (r == -1) { + int flags; + +#if defined(__linux__) && !defined(MISSING_PIPE2) + if (!pipe2(pipefds, O_NONBLOCK)) { + return 0; + } else if (errno != ENOSYS) { + perror("pipe2 O_NONBLOCK"); + return -1; + } +#endif + + if (pipe(pipefds)) { perror("pipe"); return -1; } - int flags = fcntl(pipefds[0], F_GETFL); + flags = fcntl(pipefds[0], F_GETFL); if (flags == -1) { perror("fcntl"); close(pipefds[0]); @@ -39,8 +60,7 @@ pipeutils_create_nonblocking(int pipefds[2]) return -1; } - r = fcntl(pipefds[0], F_SETFL, flags | O_NONBLOCK); - if (r == -1) { + if (fcntl(pipefds[0], F_SETFL, flags | O_NONBLOCK)) { perror("fcntl"); close(pipefds[0]); close(pipefds[1]); @@ -55,8 +75,7 @@ pipeutils_create_nonblocking(int pipefds[2]) return -1; } - r = fcntl(pipefds[1], F_SETFL, flags | O_NONBLOCK); - if (r == -1) { + if (fcntl(pipefds[1], F_SETFL, flags | O_NONBLOCK)) { perror("fcntl"); close(pipefds[0]); close(pipefds[1]); @@ -66,17 +85,6 @@ pipeutils_create_nonblocking(int pipefds[2]) return 0; } -#else /* _WIN32 */ - -/* Create non-blocking set of pipe fds. - - Not supported on Windows! Always fails. */ -int -pipeutils_create_nonblocking(int pipefds[2]) -{ - return -1; -} - #endif /* Signal on write-end of pipe. */ |