X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fpasswd%2Fgetpwent_a.c;h=d1b4b53ce2008234ea37a4e5cfe5e78f5456142f;hb=eb2e298cdc814493a6ced8c05cf0d0f5cccc8b63;hp=1bd7f4fcc4ba1b2851707cb8f8c4617943b027fc;hpb=4948a24df21c1e80bedc1f302547c9cb26e4dbfe;p=musl diff --git a/src/passwd/getpwent_a.c b/src/passwd/getpwent_a.c index 1bd7f4fc..d1b4b53c 100644 --- a/src/passwd/getpwent_a.c +++ b/src/passwd/getpwent_a.c @@ -1,14 +1,23 @@ #include "pwf.h" #include -struct passwd *__getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size) +static unsigned atou(char **s) +{ + unsigned x; + for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0'); + return x; +} + +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 = ferror(f) ? errno : 0; free(*line); *line = 0; pw = 0; @@ -23,11 +32,11 @@ struct passwd *__getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *siz *s++ = 0; pw->pw_passwd = s; if (!(s = strchr(s, ':'))) continue; - *s++ = 0; pw->pw_uid = atoi(s); - if (!(s = strchr(s, ':'))) continue; + *s++ = 0; pw->pw_uid = atou(&s); + if (*s != ':') continue; - *s++ = 0; pw->pw_gid = atoi(s); - if (!(s = strchr(s, ':'))) continue; + *s++ = 0; pw->pw_gid = atou(&s); + if (*s != ':') continue; *s++ = 0; pw->pw_gecos = s; if (!(s = strchr(s, ':'))) continue; @@ -39,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; }