OLD | NEW |
(Empty) | |
| 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 int __getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size, struct p
asswd **res) |
| 12 { |
| 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; |
| 25 } |
| 26 line[0][l-1] = 0; |
| 27 |
| 28 s = line[0]; |
| 29 pw->pw_name = s++; |
| 30 if (!(s = strchr(s, ':'))) continue; |
| 31 |
| 32 *s++ = 0; pw->pw_passwd = s; |
| 33 if (!(s = strchr(s, ':'))) continue; |
| 34 |
| 35 *s++ = 0; pw->pw_uid = atou(&s); |
| 36 if (*s != ':') continue; |
| 37 |
| 38 *s++ = 0; pw->pw_gid = atou(&s); |
| 39 if (*s != ':') continue; |
| 40 |
| 41 *s++ = 0; pw->pw_gecos = s; |
| 42 if (!(s = strchr(s, ':'))) continue; |
| 43 |
| 44 *s++ = 0; pw->pw_dir = s; |
| 45 if (!(s = strchr(s, ':'))) continue; |
| 46 |
| 47 *s++ = 0; pw->pw_shell = s; |
| 48 break; |
| 49 } |
| 50 pthread_setcancelstate(cs, 0); |
| 51 *res = pw; |
| 52 if (rv) errno = rv; |
| 53 return rv; |
| 54 } |
OLD | NEW |