mirror of
https://github.com/RGBCube/serenity
synced 2025-07-17 05:07:37 +00:00
LibCore: Add syscall wrapper for getpwnam()
This commit is contained in:
parent
c8080fc2ca
commit
cd5063555e
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
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
@ -45,5 +46,6 @@ ErrorOr<struct termios> tcgetattr(int fd);
|
||||||
ErrorOr<void> tcsetattr(int fd, int optional_actions, struct termios const&);
|
ErrorOr<void> tcsetattr(int fd, int optional_actions, struct termios const&);
|
||||||
ErrorOr<void> chmod(StringView pathname, mode_t mode);
|
ErrorOr<void> chmod(StringView pathname, mode_t mode);
|
||||||
ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid);
|
ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid);
|
||||||
|
ErrorOr<struct passwd> getpwnam(StringView name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue