summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibCore/System.cpp20
-rw-r--r--Userland/Libraries/LibCore/System.h2
2 files changed, 22 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;
diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h
index 1353108885..318cdde735 100644
--- a/Userland/Libraries/LibCore/System.h
+++ b/Userland/Libraries/LibCore/System.h
@@ -70,6 +70,8 @@ ErrorOr<void> lchown(StringView pathname, uid_t uid, gid_t gid);
ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid);
ErrorOr<Optional<struct passwd>> getpwnam(StringView name);
ErrorOr<Optional<struct group>> getgrnam(StringView name);
+ErrorOr<Optional<struct passwd>> getpwuid(uid_t);
+ErrorOr<Optional<struct group>> getgrgid(gid_t);
ErrorOr<void> clock_settime(clockid_t clock_id, struct timespec* ts);
ErrorOr<pid_t> posix_spawnp(StringView const path, posix_spawn_file_actions_t* const file_actions, posix_spawnattr_t* const attr, char* const arguments[], char* const envp[]);
ErrorOr<pid_t> waitpid(pid_t waitee, int* wstatus, int options);