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

LibCore: Reset errno before using LibC pwd functions

We should not expect LibC functions to clear `errno` on success,
so if we want to use it for error checking after a call, we need
to clear it before the call.
This commit is contained in:
Andreas Kling 2022-01-01 16:05:21 +01:00
parent ad6694d0db
commit f95fc91e4f

View file

@ -404,6 +404,8 @@ ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid)
ErrorOr<Optional<struct passwd>> getpwnam(StringView name)
{
errno = 0;
::setpwent();
if (errno)
return Error::from_syscall("getpwnam"sv, -errno);
@ -422,6 +424,8 @@ ErrorOr<Optional<struct passwd>> getpwnam(StringView name)
ErrorOr<Optional<struct group>> getgrnam(StringView name)
{
errno = 0;
::setgrent();
if (errno)
return Error::from_syscall("getgrnam"sv, -errno);