From c37a02341b61f00f0097a93d566ab61859f15a10 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 23 Nov 2021 11:10:19 +0100 Subject: [PATCH] LibCore: Add Core::System wrappers for fstat() and fcntl() --- Userland/Libraries/LibCore/System.cpp | 22 ++++++++++++++++++++++ Userland/Libraries/LibCore/System.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 5d0e465bb2..611817c135 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -6,6 +6,8 @@ #include #include +#include +#include #define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \ if ((rc) < 0) { \ @@ -44,4 +46,24 @@ ErrorOr sigaction(int signal, struct sigaction const* action, struct sigac return {}; } +ErrorOr fstat(int fd) +{ + struct stat st = {}; + if (::fstat(fd, &st) < 0) + return Error::from_syscall("fstat"sv, -errno); + return st; +} + +ErrorOr fcntl(int fd, int command, ...) +{ + va_list ap; + va_start(ap, command); + u32 extra_arg = va_arg(ap, u32); + int rc = ::fcntl(fd, command, extra_arg); + va_end(ap); + if (rc < 0) + return Error::from_syscall("fcntl"sv, -errno); + return rc; +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 638fed1c9d..9af82b2233 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -8,6 +8,7 @@ #include #include +#include namespace Core::System { @@ -17,5 +18,7 @@ ErrorOr unveil(StringView path, StringView permissions); #endif ErrorOr sigaction(int signal, struct sigaction const* action, struct sigaction* old_action); +ErrorOr fstat(int fd); +ErrorOr fcntl(int fd, int command, ...); }