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, ...); }