initial check-in, version 0.5.0
[musl] / src / passwd / getpwent.c
1 #include "pwf.h"
2
3 static FILE *f;
4
5 void setpwent()
6 {
7         if (f) fclose(f);
8         f = 0;
9 }
10
11 weak_alias(setpwent, endpwent);
12
13 struct passwd *getpwent()
14 {
15         static char *line;
16         static struct passwd pw;
17         size_t size=0;
18         if (!f) f = fopen("/etc/passwd", "rb");
19         if (!f) return 0;
20         return __getpwent_a(f, &pw, &line, &size);
21 }
22
23 struct passwd *getpwuid(uid_t uid)
24 {
25         struct passwd *pw;
26         setpwent();
27         while ((pw=getpwent()) && pw->pw_uid != uid);
28         endpwent();
29         return pw;
30 }
31
32 struct passwd *getpwnam(const char *name)
33 {
34         struct passwd *pw;
35         setpwent();
36         while ((pw=getpwent()) && strcmp(pw->pw_name, name));
37         endpwent();
38         return pw;
39 }