mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
LibCore: Add convenience templates for System::{unveil,pledge}
These convenience templates allow the following to be written as before: TRY(Core::System::pledge("promises...")); TRY(Core::System::pledge("promises...", "execpromises...")); TRY(Core::System::unveil("path", "permissions")); TRY(Core::System::unveil(nullptr, nullptr)); Other uses must now append sv to any literal string passed to pledge and unveil.
This commit is contained in:
parent
a4c251f858
commit
828060e631
Notes:
sideshowbarker
2024-07-17 09:27:22 +09:00
Author: https://github.com/sin-ack Commit: https://github.com/SerenityOS/serenity/commit/828060e631 Pull-request: https://github.com/SerenityOS/serenity/pull/14555 Reviewed-by: https://github.com/Dexesttp ✅ Reviewed-by: https://github.com/kleinesfilmroellchen
@ -55,6 +55,29 @@ inline ErrorOr<void> unveil(StringView, StringView)
|
||||
inline ErrorOr<void> pledge(StringView, StringView = {}) { return {}; }
|
||||
#endif
|
||||
|
||||
template<size_t N>
|
||||
ALWAYS_INLINE ErrorOr<void> pledge(char const (&promises)[N])
|
||||
{
|
||||
return pledge(StringView { promises, N - 1 });
|
||||
}
|
||||
|
||||
template<size_t NPromises, size_t NExecPromises>
|
||||
ALWAYS_INLINE ErrorOr<void> pledge(char const (&promises)[NPromises], char const (&execpromises)[NExecPromises])
|
||||
{
|
||||
return pledge(StringView { promises, NPromises - 1 }, StringView { execpromises, NExecPromises - 1 });
|
||||
}
|
||||
|
||||
template<size_t NPath, size_t NPermissions>
|
||||
ALWAYS_INLINE ErrorOr<void> unveil(char const (&path)[NPath], char const (&permissions)[NPermissions])
|
||||
{
|
||||
return unveil(StringView { path, NPath - 1 }, StringView { permissions, NPermissions - 1 });
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ErrorOr<void> unveil(std::nullptr_t, std::nullptr_t)
|
||||
{
|
||||
return unveil(StringView {}, StringView {});
|
||||
}
|
||||
|
||||
#ifndef AK_OS_BSD_GENERIC
|
||||
ErrorOr<Optional<struct spwd>> getspent();
|
||||
ErrorOr<Optional<struct spwd>> getspnam(StringView name);
|
||||
|
Loading…
Reference in New Issue
Block a user