#ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #include int cloexec_pipe(int pipefds[2]) { #ifdef O_CLOEXEC return pipe2(pipefds, O_CLOEXEC); #else int ret; ret = pipe(pipefds); if (!ret) { fcntl(pipefds[0], F_SETFD, FD_CLOEXEC); fcntl(pipefds[1], F_SETFD, FD_CLOEXEC); } return ret; #endif }