forked from Bananymous/banan-os
LibC: add getpwname() and getpwuid()
This commit is contained in:
parent
985df3532b
commit
bba09a3cd0
23
libc/pwd.cpp
23
libc/pwd.cpp
|
@ -100,10 +100,25 @@ struct passwd* getpwent(void)
|
|||
return &s_pwent_struct;
|
||||
}
|
||||
|
||||
struct passwd* getpwnam(const char* name);
|
||||
int getpwnam_r(const char* name, struct passwd* pwd, char* buffer, size_t bufsize, struct passwd** result);
|
||||
struct passwd* getpwuid(uid_t uid);
|
||||
int getpwuid_r(uid_t uid, struct passwd* pwd, char* buffer, size_t bufsize, struct passwd** result);
|
||||
struct passwd* getpwnam(const char* name)
|
||||
{
|
||||
passwd* pwd;
|
||||
setpwent();
|
||||
while (pwd = getpwent())
|
||||
if (strcmp(pwd->pw_name, name) == 0)
|
||||
return pwd;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
struct passwd* getpwuid(uid_t uid)
|
||||
{
|
||||
passwd* pwd;
|
||||
setpwent();
|
||||
while (pwd = getpwent())
|
||||
if (pwd->pw_uid == uid)
|
||||
return pwd;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void setpwent(void)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue