summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore/System.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibCore/System.cpp')
-rw-r--r--Userland/Libraries/LibCore/System.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp
index 500b39b39f..55801d6e91 100644
--- a/Userland/Libraries/LibCore/System.cpp
+++ b/Userland/Libraries/LibCore/System.cpp
@@ -342,4 +342,22 @@ ErrorOr<struct passwd> getpwnam(StringView name)
return Error::from_string_literal("getpwnam: Unknown username"sv);
}
+ErrorOr<struct group> getgrnam(StringView name)
+{
+ ::setgrent();
+ if (errno)
+ return Error::from_syscall("getgrnam"sv, -errno);
+
+ while (auto* gr = ::getgrent()) {
+ if (errno)
+ return Error::from_syscall("getgrnam"sv, -errno);
+ if (gr->gr_name == name)
+ return *gr;
+ }
+ if (errno)
+ return Error::from_syscall("getgrnam"sv, -errno);
+ else
+ return Error::from_string_literal("getgrnam: Unknown username"sv);
+}
+
}