summaryrefslogtreecommitdiff
path: root/portability/pipe2.c
diff options
context:
space:
mode:
Diffstat (limited to 'portability/pipe2.c')
-rw-r--r--portability/pipe2.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/portability/pipe2.c b/portability/pipe2.c
new file mode 100644
index 0000000..e39834f
--- /dev/null
+++ b/portability/pipe2.c
@@ -0,0 +1,22 @@
+#include <fcntl.h>
+#include <unistd.h>
+
+int pipe2(int pipefd[2], int flags)
+{
+ int r;
+
+ if ((r = pipe(pipefd)) < 0)
+ return r;
+
+ if (flags & O_CLOEXEC) {
+ (void) fcntl(pipefd[0], F_SETFD, FD_CLOEXEC);
+ (void) fcntl(pipefd[1], F_SETFD, FD_CLOEXEC);
+ }
+
+ if (flags & O_NONBLOCK) {
+ (void) fcntl(pipefd[0], F_SETFL, O_NONBLOCK);
+ (void) fcntl(pipefd[1], F_SETFL, O_NONBLOCK);
+ }
+
+ return 0;
+}