about summary refs log tree commit diff
path: root/src/passwd/getpwent_a.c
diff options
context:
space:
mode:
authorJosiah Worcester <josiahw@gmail.com>2015-02-10 18:32:55 -0600
committerRich Felker <dalias@aerifal.cx>2015-02-10 22:57:02 -0500
commit700e08993c3f6a808773d56424aa7e633da13e2e (patch)
tree752558943d55b652eb61469e818ac1dceaad6238 /src/passwd/getpwent_a.c
parent74e334dcd177b585c64ddafa732a3dc9e3f6b5ec (diff)
downloadmusl-700e08993c3f6a808773d56424aa7e633da13e2e.tar.gz
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_a.c')
-rw-r--r--src/passwd/getpwent_a.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/passwd/getpwent_a.c b/src/passwd/getpwent_a.c
index 34842a07..4d84f0d5 100644
--- a/src/passwd/getpwent_a.c
+++ b/src/passwd/getpwent_a.c
@@ -8,14 +8,16 @@ static unsigned atou(char **s)
 	return x;
 }
 
-struct passwd *__getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size)
+int __getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size, struct passwd **res)
 {
 	ssize_t l;
 	char *s;
+	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;
 			pw = 0;
@@ -46,5 +48,7 @@ struct passwd *__getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *siz
 		break;
 	}
 	pthread_setcancelstate(cs, 0);
-	return pw;
+	*res = pw;
+	if (rv) errno = rv;
+	return rv;
 }