mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:37:35 +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:
parent
ad6694d0db
commit
f95fc91e4f
1 changed files with 4 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue