1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:47:45 +00:00

LibCore+chown: Return ErrorOr<Optional<...>> for getgrnam and getpwnam

This patch returns an empty Optional<...> instead of an Error for
Core::System::getgrname and Core::System::getpwnam if we can't find a
matching group or user entry.

It also updates the 'chown' utility to support this new behavior.
This commit is contained in:
Kenneth Myhra 2021-12-23 09:41:00 +01:00 committed by Andreas Kling
parent ab324c1dae
commit 7772309169
3 changed files with 16 additions and 8 deletions

View file

@ -393,7 +393,7 @@ ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid)
#endif
}
ErrorOr<struct passwd> getpwnam(StringView name)
ErrorOr<Optional<struct passwd>> getpwnam(StringView name)
{
::setpwent();
if (errno)
@ -408,10 +408,10 @@ ErrorOr<struct passwd> getpwnam(StringView name)
if (errno)
return Error::from_syscall("getpwnam"sv, -errno);
else
return Error::from_string_literal("getpwnam: Unknown username"sv);
return Optional<struct passwd> {};
}
ErrorOr<struct group> getgrnam(StringView name)
ErrorOr<Optional<struct group>> getgrnam(StringView name)
{
::setgrent();
if (errno)
@ -426,7 +426,7 @@ ErrorOr<struct group> getgrnam(StringView name)
if (errno)
return Error::from_syscall("getgrnam"sv, -errno);
else
return Error::from_string_literal("getgrnam: Unknown username"sv);
return Optional<struct group> {};
}
ErrorOr<void> clock_settime(clockid_t clock_id, struct timespec* ts)