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/getgr_a.c | |
parent | 4e8a3561652ebcda6a126b3162fc545573889dc4 (diff) | |
download | musl-7c5f0a5212127b70486159af80e24fd96262ec88.tar.gz 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/getgr_a.c')
-rw-r--r-- | src/passwd/getgr_a.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/passwd/getgr_a.c b/src/passwd/getgr_a.c new file mode 100644 index 00000000..805e28c9 --- /dev/null +++ b/src/passwd/getgr_a.c @@ -0,0 +1,32 @@ +#include <pthread.h> +#include "pwf.h" + +int __getgr_a(const char *name, gid_t gid, struct group *gr, char **buf, size_t *size, char ***mem, size_t *nmem, struct group **res) +{ + FILE *f; + int rv = 0; + int cs; + + *res = 0; + + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); + + f = fopen("/etc/group", "rbe"); + if (!f) { + rv = errno; + goto done; + } + + while (!(rv = __getgrent_a(f, gr, buf, size, mem, nmem, res)) && *res) { + if (name && !strcmp(name, (*res)->gr_name) + || !name && (*res)->gr_gid == gid) { + break; + } + } + fclose(f); + +done: + pthread_setcancelstate(cs, 0); + if (rv) errno = rv; + return rv; +} |