diff options
author | Vladimir Azarov <avm@intermediate-node.net> | 2024-10-01 15:47:05 +0200 |
---|---|---|
committer | Vladimir Azarov <avm@intermediate-node.net> | 2024-10-01 15:47:05 +0200 |
commit | 4abab5ad6c8465a7528ccdd5f49367da05f78bbd (patch) | |
tree | ebf009bf1376a5a223a915bc27cbbd791a1316bc /src/unistd/pipe2.c |
Initial version
Diffstat (limited to 'src/unistd/pipe2.c')
-rw-r--r-- | src/unistd/pipe2.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/unistd/pipe2.c b/src/unistd/pipe2.c new file mode 100644 index 0000000..a096990 --- /dev/null +++ b/src/unistd/pipe2.c @@ -0,0 +1,23 @@ +#include <unistd.h> +#include <errno.h> +#include <fcntl.h> +#include "syscall.h" + +int pipe2(int fd[2], int flag) +{ + if (!flag) return pipe(fd); + int ret = __syscall(SYS_pipe2, fd, flag); + if (ret != -ENOSYS) return __syscall_ret(ret); + if (flag & ~(O_CLOEXEC|O_NONBLOCK)) return __syscall_ret(-EINVAL); + ret = pipe(fd); + if (ret) return ret; + if (flag & O_CLOEXEC) { + __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC); + __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC); + } + if (flag & O_NONBLOCK) { + __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK); + __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK); + } + return 0; +} |