sys/stat.h: fix typo in statx member name stx_dio_offset_align
[musl.git] / src / passwd / getpwent_a.c
blobd1b4b53ce2008234ea37a4e5cfe5e78f5456142f
1 #include "pwf.h"
2 #include <pthread.h>
4 static unsigned atou(char **s)
6 unsigned x;
7 for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0');
8 return x;
11 int __getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size, struct passwd **res)
13 ssize_t l;
14 char *s;
15 int rv = 0;
16 int cs;
17 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
18 for (;;) {
19 if ((l=getline(line, size, f)) < 0) {
20 rv = ferror(f) ? errno : 0;
21 free(*line);
22 *line = 0;
23 pw = 0;
24 break;
26 line[0][l-1] = 0;
28 s = line[0];
29 pw->pw_name = s++;
30 if (!(s = strchr(s, ':'))) continue;
32 *s++ = 0; pw->pw_passwd = s;
33 if (!(s = strchr(s, ':'))) continue;
35 *s++ = 0; pw->pw_uid = atou(&s);
36 if (*s != ':') continue;
38 *s++ = 0; pw->pw_gid = atou(&s);
39 if (*s != ':') continue;
41 *s++ = 0; pw->pw_gecos = s;
42 if (!(s = strchr(s, ':'))) continue;
44 *s++ = 0; pw->pw_dir = s;
45 if (!(s = strchr(s, ':'))) continue;
47 *s++ = 0; pw->pw_shell = s;
48 break;
50 pthread_setcancelstate(cs, 0);
51 *res = pw;
52 if (rv) errno = rv;
53 return rv;