diff options
author | Andreas Kling <kling@serenityos.org> | 2022-01-01 18:26:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-02 18:08:02 +0100 |
commit | 431bd069f0cc66abec8b27b94289955310db8679 (patch) | |
tree | 13e3ba8066eff6e3f54046154039f9d67113e364 /Userland/Libraries/LibCore/System.cpp | |
parent | 7008f74214aefc088eb15f0ff7656b31e70c0cbd (diff) | |
download | serenity-431bd069f0cc66abec8b27b94289955310db8679.zip |
LibCore: Add Core::System wrappers for getspent() and getspnam()
Diffstat (limited to 'Userland/Libraries/LibCore/System.cpp')
-rw-r--r-- | Userland/Libraries/LibCore/System.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 17ff8023af..3cddacc95e 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -107,6 +107,31 @@ ErrorOr<long> ptrace(int request, pid_t tid, void* address, void* data) } #endif +#ifndef AK_OS_BSD_GENERIC +ErrorOr<Optional<struct spwd>> getspent() +{ + errno = 0; + if (auto* spwd = ::getspent()) + return *spwd; + if (errno) + return Error::from_syscall("getspent"sv, -errno); + return Optional<struct spwd> {}; +} + +ErrorOr<Optional<struct spwd>> getspnam(StringView name) +{ + errno = 0; + ::setspent(); + while (auto* spwd = ::getspent()) { + if (spwd->sp_namp == name) + return *spwd; + } + if (errno) + return Error::from_syscall("getspnam"sv, -errno); + return Optional<struct spwd> {}; +} +#endif + #ifndef AK_OS_MACOS ErrorOr<int> accept4(int sockfd, sockaddr* address, socklen_t* address_length, int flags) { |