diff options
author | Josiah Worcester <josiahw@gmail.com> | 2015-02-10 18:32:55 -0600 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2015-02-10 22:57:02 -0500 |
commit | 700e08993c3f6a808773d56424aa7e633da13e2e (patch) | |
tree | 752558943d55b652eb61469e818ac1dceaad6238 /src/passwd/getpwent.c | |
parent | 74e334dcd177b585c64ddafa732a3dc9e3f6b5ec (diff) | |
download | musl-700e08993c3f6a808773d56424aa7e633da13e2e.tar.gz musl-700e08993c3f6a808773d56424aa7e633da13e2e.tar.bz2 musl-700e08993c3f6a808773d56424aa7e633da13e2e.tar.xz musl-700e08993c3f6a808773d56424aa7e633da13e2e.zip |
refactor passwd file access code
this allows getpwnam and getpwuid to share code with the _r versions
in preparation for alternate backend support.
Diffstat (limited to 'src/passwd/getpwent.c')
-rw-r--r-- | src/passwd/getpwent.c | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/src/passwd/getpwent.c b/src/passwd/getpwent.c index c655135e..f2bd516e 100644 --- a/src/passwd/getpwent.c +++ b/src/passwd/getpwent.c @@ -1,6 +1,9 @@ #include "pwf.h" static FILE *f; +static char *line; +static struct passwd pw; +static size_t size; void setpwent() { @@ -12,34 +15,23 @@ weak_alias(setpwent, endpwent); struct passwd *getpwent() { - static char *line; - static struct passwd pw; - size_t size=0; + struct passwd *res; if (!f) f = fopen("/etc/passwd", "rbe"); if (!f) return 0; - return __getpwent_a(f, &pw, &line, &size); + __getpwent_a(f, &pw, &line, &size, &res); + return res; } struct passwd *getpwuid(uid_t uid) { - struct passwd *pw; - int errno_saved; - setpwent(); - while ((pw=getpwent()) && pw->pw_uid != uid); - errno_saved = errno; - endpwent(); - errno = errno_saved; - return pw; + struct passwd *res; + __getpw_a(0, uid, &pw, &line, &size, &res); + return res; } struct passwd *getpwnam(const char *name) { - struct passwd *pw; - int errno_saved; - setpwent(); - while ((pw=getpwent()) && strcmp(pw->pw_name, name)); - errno_saved = errno; - endpwent(); - errno = errno_saved; - return pw; + struct passwd *res; + __getpw_a(name, 0, &pw, &line, &size, &res); + return res; } |