diff options
author | Josiah Worcester <josiahw@gmail.com> | 2015-02-07 15:40:46 -0600 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2015-02-13 01:46:51 -0500 |
commit | 7c5f0a5212127b70486159af80e24fd96262ec88 (patch) | |
tree | 767c31af77ff639f324a0fe2e8dcd422f467e937 /src/passwd/getgrent.c | |
parent | 4e8a3561652ebcda6a126b3162fc545573889dc4 (diff) | |
download | musl-7c5f0a5212127b70486159af80e24fd96262ec88.tar.gz musl-7c5f0a5212127b70486159af80e24fd96262ec88.tar.bz2 musl-7c5f0a5212127b70486159af80e24fd96262ec88.tar.xz musl-7c5f0a5212127b70486159af80e24fd96262ec88.zip |
refactor group file access code
this allows getgrnam and getgrgid to share code with the _r versions
in preparation for alternate backend support.
Diffstat (limited to 'src/passwd/getgrent.c')
-rw-r--r-- | src/passwd/getgrent.c | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/src/passwd/getgrent.c b/src/passwd/getgrent.c index 429a3e58..835b9ab5 100644 --- a/src/passwd/getgrent.c +++ b/src/passwd/getgrent.c @@ -1,6 +1,8 @@ #include "pwf.h" static FILE *f; +static char *line, **mem; +static struct group gr; void setgrent() { @@ -12,34 +14,26 @@ weak_alias(setgrent, endgrent); struct group *getgrent() { - static char *line, **mem; - static struct group gr; + struct group *res; size_t size=0, nmem=0; if (!f) f = fopen("/etc/group", "rbe"); if (!f) return 0; - return __getgrent_a(f, &gr, &line, &size, &mem, &nmem); + __getgrent_a(f, &gr, &line, &size, &mem, &nmem, &res); + return res; } struct group *getgrgid(gid_t gid) { - struct group *gr; - int errno_saved; - setgrent(); - while ((gr=getgrent()) && gr->gr_gid != gid); - errno_saved = errno; - endgrent(); - errno = errno_saved; - return gr; + struct group *res; + size_t size=0, nmem=0; + __getgr_a(0, gid, &gr, &line, &size, &mem, &nmem, &res); + return res; } struct group *getgrnam(const char *name) { - struct group *gr; - int errno_saved; - setgrent(); - while ((gr=getgrent()) && strcmp(gr->gr_name, name)); - errno_saved = errno; - endgrent(); - errno = errno_saved; - return gr; + struct group *res; + size_t size=0, nmem=0; + __getgr_a(name, 0, &gr, &line, &size, &mem, &nmem, &res); + return res; } |