mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 21:59:07 +00:00
LibCore: Add syscall wrapper for getpwnam()
This commit is contained in:
parent
c8080fc2ca
commit
cd5063555e
Notes:
sideshowbarker
2024-07-17 22:56:47 +09:00
Author: https://github.com/kennethmyhra
Commit: cd5063555e
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
|
@ -324,4 +324,22 @@ ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid)
|
|||
#endif
|
||||
}
|
||||
|
||||
ErrorOr<struct passwd> getpwnam(StringView name)
|
||||
{
|
||||
::setpwent();
|
||||
if (errno)
|
||||
return Error::from_syscall("getpwnam"sv, -errno);
|
||||
|
||||
while (auto* pw = ::getpwent()) {
|
||||
if (errno)
|
||||
return Error::from_syscall("getpwnam"sv, -errno);
|
||||
if (pw->pw_name == name)
|
||||
return *pw;
|
||||
}
|
||||
if (errno)
|
||||
return Error::from_syscall("getpwnam"sv, -errno);
|
||||
else
|
||||
return Error::from_string_literal("getpwnam: Unknown username"sv);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue