From 982ac34437f10f9613484d589dfec90e6395bcc8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 28 Nov 2021 09:12:29 +0100 Subject: [PATCH] LibCore: Add syscall wrappers for sendfd() and recvfd() --- Userland/Libraries/LibCore/System.cpp | 16 ++++++++++++++++ Userland/Libraries/LibCore/System.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 4289b22ed5..8e241749cc 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \ @@ -49,6 +50,21 @@ ErrorOr> pipe2(int flags) return Error::from_syscall("pipe2"sv, -errno); return fds; } + +ErrorOr sendfd(int sockfd, int fd) +{ + if (::sendfd(sockfd, fd) < 0) + return Error::from_syscall("sendfd"sv, -errno); + return {}; +} + +ErrorOr recvfd(int sockfd, int options) +{ + auto fd = ::recvfd(sockfd, options); + if (fd < 0) + return Error::from_syscall("recvfd"sv, -errno); + return fd; +} #endif ErrorOr sigaction(int signal, struct sigaction const* action, struct sigaction* old_action) diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 24b68b37c1..2f4d61ea42 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -16,6 +16,8 @@ namespace Core::System { 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); #endif ErrorOr sigaction(int signal, struct sigaction const* action, struct sigaction* old_action);