From bba09a3cd039256767de1dc00108b218acf4f69a Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 13 Jul 2023 12:01:16 +0300 Subject: [PATCH] LibC: add getpwname() and getpwuid() --- libc/pwd.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/libc/pwd.cpp b/libc/pwd.cpp index 79b9f183..20e3a71d 100644 --- a/libc/pwd.cpp +++ b/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) {