mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 05:09:12 +00:00
LibCore: Add syscall wrapper for getgrnam()
This commit is contained in:
parent
cd5063555e
commit
c4bd46023b
Notes:
sideshowbarker
2024-07-17 22:56:43 +09:00
Author: https://github.com/kennethmyhra
Commit: c4bd46023b
Pull-request: https://github.com/SerenityOS/serenity/pull/11101
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/bgianfo ✅
Reviewed-by: https://github.com/creator1creeper1 ✅
Reviewed-by: https://github.com/kleinesfilmroellchen ✅
2 changed files with 20 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue