From 700e08993c3f6a808773d56424aa7e633da13e2e Mon Sep 17 00:00:00 2001 From: Josiah Worcester Date: Tue, 10 Feb 2015 18:32:55 -0600 Subject: refactor passwd file access code this allows getpwnam and getpwuid to share code with the _r versions in preparation for alternate backend support. --- src/passwd/getpwent_a.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/passwd/getpwent_a.c') 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; } -- cgit v1.2.1