summaryrefslogtreecommitdiff
path: root/src/passwd/getpwent_a.c
blob: aaf84edde708416302b51eb376f0876ea9382a44 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "pwf.h"

struct passwd *__getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size)
{
	ssize_t l;
	char *s;
	for (;;) {
		if ((l=getline(line, size, f)) < 0) {
			free(*line);
			*line = 0;
			return 0;
		}
		line[0][l-1] = 0;

		s = line[0];
		pw->pw_name = s++;
		if (!(s = strchr(s, ':'))) continue;

		*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_gid = atoi(s);
		if (!(s = strchr(s, ':'))) continue;

		*s++ = 0; pw->pw_gecos = s;
		if (!(s = strchr(s, ':'))) continue;

		*s++ = 0; pw->pw_dir = s;
		if (!(s = strchr(s, ':'))) continue;

		*s++ = 0; pw->pw_shell = s;
		return pw;
	}
}