1 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
3 .\" SPDX-License-Identifier: GPL-2.0-or-later
5 .TH getpwent_r 3 (date) "Linux man-pages (unreleased)"
7 getpwent_r, fgetpwent_r \- get passwd file entry reentrantly
10 .RI ( libc ", " \-lc )
15 .BI "int getpwent_r(struct passwd *restrict " pwbuf ,
16 .BI " char *restrict " buf ", size_t " buflen ,
17 .BI " struct passwd **restrict " pwbufp );
18 .BI "int fgetpwent_r(FILE *restrict " stream \
19 ", struct passwd *restrict " pwbuf ,
20 .BI " char *restrict " buf ", size_t " buflen ,
21 .BI " struct passwd **restrict " pwbufp );
25 Feature Test Macro Requirements for glibc (see
26 .BR feature_test_macros (7)):
33 Glibc 2.19 and earlier:
34 _BSD_SOURCE || _SVID_SOURCE
41 Glibc 2.19 and earlier:
49 are the reentrant versions of
53 The former reads the next passwd entry from the stream initialized by
55 The latter reads the next passwd entry from
58 The \fIpasswd\fP structure is defined in
65 char *pw_name; /* username */
66 char *pw_passwd; /* user password */
67 uid_t pw_uid; /* user ID */
68 gid_t pw_gid; /* group ID */
69 char *pw_gecos; /* user information */
70 char *pw_dir; /* home directory */
71 char *pw_shell; /* shell program */
76 For more information about the fields of this structure, see
79 The nonreentrant functions return a pointer to static storage,
80 where this static storage contains further pointers to user
81 name, password, gecos field, home directory and shell.
82 The reentrant functions described here return all of that in
83 caller-provided buffers.
84 First of all there is the buffer
86 that can hold a \fIstruct passwd\fP.
91 that can hold additional strings.
92 The result of these functions, the \fIstruct passwd\fP read from the stream,
93 is stored in the provided buffer
95 and a pointer to this \fIstruct passwd\fP is returned in
98 On success, these functions return 0 and
100 is a pointer to the \fIstruct passwd\fP.
101 On error, these functions return an error value and
110 Insufficient buffer space supplied.
111 Try again with larger buffer.
113 For an explanation of the terms used in this section, see
121 Interface Attribute Value
125 MT-Unsafe race:pwent locale
129 T} Thread safety MT-Safe
138 signifies that if any of the functions
144 are used in parallel in different threads of a program,
145 then data races could occur.
147 These functions are GNU extensions, done in a style resembling
148 the POSIX version of functions like
150 Other systems use the prototype
155 getpwent_r(struct passwd *pwd, char *buf, int buflen);
164 getpwent_r(struct passwd *pwd, char *buf, int buflen,
171 is not really reentrant since it shares the reading position
172 in the stream with all other threads.
174 .\" SRC BEGIN (getpwent_r.c)
194 i = getpwent_r(&pw, buf, sizeof(buf), &pwp);
197 printf("%s (%jd)\etHOME %s\etSHELL %s\en", pwp\->pw_name,
198 (intmax_t) pwp\->pw_uid, pwp\->pw_dir, pwp\->pw_shell);
204 .\" perhaps add error checking - should use strerror_r
205 .\" #include <errno.h>
206 .\" #include <stdlib.h>
210 .\" printf("getpwent_r: %s", strerror(i));
211 .\" exit(EXIT_SUCCESS);