summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-23 10:48:22 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-23 11:33:36 +0100
commitacc2eccede491e0c34d718e348d76c13c190347c (patch)
treeb9113dbf448be3912e51cfd4447ac043b846c118
parent2828d58a1025f80fc1c7af7c3433a8111412606e (diff)
downloadserenity-acc2eccede491e0c34d718e348d76c13c190347c.zip
LibSystem: Add wrapper for fstat()
-rw-r--r--Userland/Libraries/LibSystem/Wrappers.cpp23
-rw-r--r--Userland/Libraries/LibSystem/Wrappers.h2
2 files changed, 17 insertions, 8 deletions
diff --git a/Userland/Libraries/LibSystem/Wrappers.cpp b/Userland/Libraries/LibSystem/Wrappers.cpp
index bf8207a6e9..0cade18695 100644
--- a/Userland/Libraries/LibSystem/Wrappers.cpp
+++ b/Userland/Libraries/LibSystem/Wrappers.cpp
@@ -7,11 +7,11 @@
#include <LibSystem/Wrappers.h>
#include <LibSystem/syscall.h>
-#define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc) \
- if ((rc) < 0) { \
- return Error::from_syscall(syscall_name, rc); \
- } \
- return {};
+#define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \
+ if ((rc) < 0) { \
+ return Error::from_syscall(syscall_name, rc); \
+ } \
+ return success_value;
namespace System {
@@ -22,7 +22,7 @@ ErrorOr<void> pledge(StringView promises, StringView execpromises)
{ execpromises.characters_without_null_termination(), execpromises.length() },
};
int rc = syscall(SC_pledge, &params);
- HANDLE_SYSCALL_RETURN_VALUE("pledge"sv, rc);
+ HANDLE_SYSCALL_RETURN_VALUE("pledge"sv, rc, {});
}
ErrorOr<void> unveil(StringView path, StringView permissions)
@@ -32,13 +32,20 @@ ErrorOr<void> unveil(StringView path, StringView permissions)
{ permissions.characters_without_null_termination(), permissions.length() },
};
int rc = syscall(SC_unveil, &params);
- HANDLE_SYSCALL_RETURN_VALUE("unveil"sv, rc);
+ HANDLE_SYSCALL_RETURN_VALUE("unveil"sv, rc, {});
}
ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action)
{
int rc = syscall(SC_sigaction, signal, action, old_action);
- HANDLE_SYSCALL_RETURN_VALUE("sigaction"sv, rc);
+ HANDLE_SYSCALL_RETURN_VALUE("sigaction"sv, rc, {});
+}
+
+ErrorOr<struct stat> fstat(int fd)
+{
+ struct stat st;
+ int rc = syscall(SC_fstat, fd, &st);
+ HANDLE_SYSCALL_RETURN_VALUE("fstat"sv, rc, st);
}
}
diff --git a/Userland/Libraries/LibSystem/Wrappers.h b/Userland/Libraries/LibSystem/Wrappers.h
index 0eca7977ce..751d598334 100644
--- a/Userland/Libraries/LibSystem/Wrappers.h
+++ b/Userland/Libraries/LibSystem/Wrappers.h
@@ -8,11 +8,13 @@
#include <AK/Error.h>
#include <signal.h>
+#include <sys/stat.h>
namespace System {
ErrorOr<void> pledge(StringView promises, StringView execpromises);
ErrorOr<void> unveil(StringView path, StringView permissions);
ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action);
+ErrorOr<struct stat> fstat(int fd);
}