From 767fb175b10685fe96fabc692b8d06cac5bcd365 Mon Sep 17 00:00:00 2001 From: Indrek Juhkam Date: Fri, 4 Dec 2015 19:38:24 +0200 Subject: [PATCH] Provide an alternative to pipe2() on non-Linux systems --- src/pipe.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pipe.h b/src/pipe.h index 11168d9..d374d7b 100644 --- a/src/pipe.h +++ b/src/pipe.h @@ -42,8 +42,16 @@ public: Pipe() { // construct the pipe +#ifdef _GNU_SOURCE if (pipe2(_fds, O_CLOEXEC) == 0) return; - +#else + if ( + pipe(_fds) == 0 && + fcntl(_fds[0], F_SETFD, FD_CLOEXEC) == 0 && + fcntl(_fds[1], F_SETFD, FD_CLOEXEC) == 0 + ) return; +#endif + // something went wrong throw std::runtime_error(strerror(errno)); }