change uid_t, gid_t, and id_t to unsigned types
[musl] / src / passwd / getpwent_a.c
1 #include "pwf.h"
2 #include <pthread.h>
3
4 static unsigned atou(char **s)
5 {
6         unsigned x;
7         for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0');
8         return x;
9 }
10
11 struct passwd *__getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size)
12 {
13         ssize_t l;
14         char *s;
15         int cs;
16         pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
17         for (;;) {
18                 if ((l=getline(line, size, f)) < 0) {
19                         free(*line);
20                         *line = 0;
21                         pw = 0;
22                         break;
23                 }
24                 line[0][l-1] = 0;
25
26                 s = line[0];
27                 pw->pw_name = s++;
28                 if (!(s = strchr(s, ':'))) continue;
29
30                 *s++ = 0; pw->pw_passwd = s;
31                 if (!(s = strchr(s, ':'))) continue;
32
33                 *s++ = 0; pw->pw_uid = atou(&s);
34                 if (*s != ':') continue;
35
36                 *s++ = 0; pw->pw_gid = atou(&s);
37                 if (*s != ':') continue;
38
39                 *s++ = 0; pw->pw_gecos = s;
40                 if (!(s = strchr(s, ':'))) continue;
41
42                 *s++ = 0; pw->pw_dir = s;
43                 if (!(s = strchr(s, ':'))) continue;
44
45                 *s++ = 0; pw->pw_shell = s;
46                 break;
47         }
48         pthread_setcancelstate(cs, 0);
49         return pw;
50 }