mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:47:34 +00:00
LibCore: Add syscall wrappers for getpwuid() and getgrgid()
This commit is contained in:
parent
1e4117f1e1
commit
7008f74214
2 changed files with 22 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue