summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore/System.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-01-01 17:53:57 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-02 18:08:02 +0100
commit7008f74214aefc088eb15f0ff7656b31e70c0cbd (patch)
tree5de2d370e1a0ddc74d8f89fd253695d2e3fa0329 /Userland/Libraries/LibCore/System.cpp
parent1e4117f1e1830723ae5d15cc7876370de14bf645 (diff)
downloadserenity-7008f74214aefc088eb15f0ff7656b31e70c0cbd.zip
LibCore: Add syscall wrappers for getpwuid() and getgrgid()
Diffstat (limited to 'Userland/Libraries/LibCore/System.cpp')
-rw-r--r--Userland/Libraries/LibCore/System.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp
index 37cca47260..17ff8023af 100644
--- a/Userland/Libraries/LibCore/System.cpp
+++ b/Userland/Libraries/LibCore/System.cpp
@@ -403,6 +403,26 @@ ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid)
#endif
}
+ErrorOr<Optional<struct passwd>> getpwuid(uid_t uid)
+{
+ errno = 0;
+ if (auto* pwd = ::getpwuid(uid))
+ return *pwd;
+ if (errno)
+ return Error::from_syscall("getpwuid"sv, -errno);
+ return Optional<struct passwd> {};
+}
+
+ErrorOr<Optional<struct group>> getgrgid(gid_t gid)
+{
+ errno = 0;
+ if (auto* grp = ::getgrgid(gid))
+ return *grp;
+ if (errno)
+ return Error::from_syscall("getgrgid"sv, -errno);
+ return Optional<struct group> {};
+}
+
ErrorOr<Optional<struct passwd>> getpwnam(StringView name)
{
errno = 0;