From 4abab5ad6c8465a7528ccdd5f49367da05f78bbd Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Tue, 1 Oct 2024 15:47:05 +0200 Subject: Initial version --- src/unistd/pipe2.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/unistd/pipe2.c (limited to 'src/unistd/pipe2.c') 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 +#include +#include +#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; +} -- cgit v1.2.3