Provide an alternative to pipe2() on non-Linux systems

This commit is contained in:
Indrek Juhkam 2015-12-04 19:38:24 +02:00
parent 93a0b60b6e
commit 767fb175b1
1 changed files with 9 additions and 1 deletions

View File

@ -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));
}