mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 03:57:15 +02:00
AK+LibSystem+LibMain: Add Error::from_syscall() for syscall failures
This creates an error that contains the name of the syscall that failed. This allows error handlers to print out the name of the call if they want to. :^)
This commit is contained in:
Notes:
sideshowbarker
2024-07-18 00:52:47 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/4e530135d55
@@ -7,6 +7,12 @@
|
||||
#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 {};
|
||||
|
||||
namespace System {
|
||||
|
||||
ErrorOr<void> pledge(StringView promises, StringView execpromises)
|
||||
@@ -16,9 +22,7 @@ ErrorOr<void> pledge(StringView promises, StringView execpromises)
|
||||
{ execpromises.characters_without_null_termination(), execpromises.length() },
|
||||
};
|
||||
int rc = syscall(SC_pledge, ¶ms);
|
||||
if (rc < 0)
|
||||
return Error::from_errno(-rc);
|
||||
return {};
|
||||
HANDLE_SYSCALL_RETURN_VALUE("pledge"sv, rc);
|
||||
}
|
||||
|
||||
ErrorOr<void> unveil(StringView path, StringView permissions)
|
||||
@@ -28,9 +32,7 @@ ErrorOr<void> unveil(StringView path, StringView permissions)
|
||||
{ permissions.characters_without_null_termination(), permissions.length() },
|
||||
};
|
||||
int rc = syscall(SC_unveil, ¶ms);
|
||||
if (rc < 0)
|
||||
return Error::from_errno(-rc);
|
||||
return {};
|
||||
HANDLE_SYSCALL_RETURN_VALUE("unveil"sv, rc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user