blob: 2e09aea77fcebfe129a2ee218c6dd59727d52d04 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/* some musl versions incorrectly mark fgetpwent() as a GNU extension */
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <pwd.h>
#include <string.h>
int getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) {
struct passwd *pwd;
if (pwbufp == NULL || pwbuf == NULL)
return ERANGE;
if (buflen < 1)
return ERANGE;
if (buf != NULL)
*buf = '\0';
if ((pwd = getpwent()) == NULL) {
*pwbufp = NULL;
return ENOENT;
}
memcpy(pwbuf, pwd, sizeof(*pwd));
*pwbufp = pwbuf;
return 0;
}
int fgetpwent_r(FILE *filp, struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) {
struct passwd *pwd;
if (pwbufp == NULL || pwbuf == NULL)
return ERANGE;
if (buflen < 1)
return ERANGE;
if (buf != NULL)
*buf = '\0';
if ((pwd = fgetpwent(filp)) == NULL) {
*pwbufp = NULL;
return ENOENT;
}
memcpy(pwbuf, pwd, sizeof(*pwd));
*pwbufp = pwbuf;
return 0;
}
|