From ee46cee31f95b893a89fa6a0bf59396a966296ba Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Tue, 21 Dec 2021 06:16:46 +0330 Subject: [PATCH] LibCore: Make Core::System::pipe2() available on Lagom Note that this drops the flags on the floor if not on linux or serenity. --- Userland/Libraries/LibCore/System.cpp | 21 +++++++++++++-------- Userland/Libraries/LibCore/System.h | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index eec0e07971..d87ff035ae 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -45,14 +45,6 @@ ErrorOr unveil(StringView path, StringView permissions) HANDLE_SYSCALL_RETURN_VALUE("unveil"sv, rc, {}); } -ErrorOr> pipe2(int flags) -{ - Array fds; - if (::pipe2(fds.data(), flags) < 0) - return Error::from_syscall("pipe2"sv, -errno); - return fds; -} - ErrorOr sendfd(int sockfd, int fd) { if (::sendfd(sockfd, fd) < 0) @@ -709,4 +701,17 @@ ErrorOr socketpair(int domain, int type, int protocol, int sv[2]) return {}; } +ErrorOr> pipe2([[maybe_unused]] int flags) +{ + Array fds; +#if defined(__unix__) + if (::pipe2(fds.data(), flags) < 0) + return Error::from_syscall("pipe2"sv, -errno); +#else + if (::pipe(fds.data()) < 0) + return Error::from_syscall("pipe2"sv, -errno); +#endif + return fds; +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 5c5a277a90..addd51ddcd 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -27,7 +27,6 @@ namespace Core::System { #ifdef __serenity__ ErrorOr pledge(StringView promises, StringView execpromises = {}); ErrorOr unveil(StringView path, StringView permissions); -ErrorOr> pipe2(int flags); ErrorOr sendfd(int sockfd, int fd); ErrorOr recvfd(int sockfd, int options); ErrorOr ptrace_peekbuf(pid_t tid, void const* tracee_addr, Bytes destination_buf); @@ -85,6 +84,7 @@ ErrorOr mkstemp(Span pattern); ErrorOr fchmod(int fd, mode_t mode); ErrorOr rename(StringView old_path, StringView new_path); ErrorOr utime(StringView path, Optional); +ErrorOr> pipe2(int flags); ErrorOr socket(int domain, int type, int protocol); ErrorOr bind(int sockfd, struct sockaddr const*, socklen_t);