about summary refs log tree commit diff
path: root/src/passwd/getgrent_a.c
diff options
context:
space:
mode:
authorJosiah Worcester <josiahw@gmail.com>2015-02-07 15:40:46 -0600
committerRich Felker <dalias@aerifal.cx>2015-02-13 01:46:51 -0500
commit7c5f0a5212127b70486159af80e24fd96262ec88 (patch)
tree767c31af77ff639f324a0fe2e8dcd422f467e937 /src/passwd/getgrent_a.c
parent4e8a3561652ebcda6a126b3162fc545573889dc4 (diff)
downloadmusl-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/getgrent_a.c')
-rw-r--r--src/passwd/getgrent_a.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/passwd/getgrent_a.c b/src/passwd/getgrent_a.c
index 2cb85215..bafc9ed2 100644
--- a/src/passwd/getgrent_a.c
+++ b/src/passwd/getgrent_a.c
@@ -8,15 +8,17 @@ static unsigned atou(char **s)
 	return x;
 }
 
-struct group *__getgrent_a(FILE *f, struct group *gr, char **line, size_t *size, char ***mem, size_t *nmem)
+int __getgrent_a(FILE *f, struct group *gr, char **line, size_t *size, char ***mem, size_t *nmem, struct group **res)
 {
 	ssize_t l;
 	char *s, *mems;
 	size_t i;
+	int rv = 0;
 	int cs;
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
 	for (;;) {
 		if ((l=getline(line, size, f)) < 0) {
+			rv = errno;
 			free(*line);
 			*line = 0;
 			gr = 0;
@@ -43,6 +45,7 @@ struct group *__getgrent_a(FILE *f, struct group *gr, char **line, size_t *size,
 	free(*mem);
 	*mem = calloc(sizeof(char *), *nmem+1);
 	if (!*mem) {
+		rv = errno;
 		free(*line);
 		*line = 0;
 		return 0;
@@ -58,5 +61,7 @@ struct group *__getgrent_a(FILE *f, struct group *gr, char **line, size_t *size,
 	gr->gr_mem = *mem;
 end:
 	pthread_setcancelstate(cs, 0);
-	return gr;
+	*res = gr;
+	if(rv) errno = rv;
+	return rv;
 }