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 getpwnam(StringView name) return Error::from_string_literal("getpwnam: Unknown username"sv); } +ErrorOr 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); +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index f6f5db9a0b..0905fbb294 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include #include @@ -47,5 +48,6 @@ ErrorOr tcsetattr(int fd, int optional_actions, struct termios const&); ErrorOr chmod(StringView pathname, mode_t mode); ErrorOr chown(StringView pathname, uid_t uid, gid_t gid); ErrorOr getpwnam(StringView name); +ErrorOr getgrnam(StringView name); }