2 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
6 .TH getpwent_r 3 (date) "Linux man-pages (unreleased)"
8 getpwent_r, fgetpwent_r \- get passwd file entry reentrantly
11 .RI ( libc ", " \-lc )
16 .BI "int getpwent_r(struct passwd *restrict " pwbuf ,
17 .BI " char " buf "[restrict ." buflen "], size_t " buflen ,
18 .BI " struct passwd **restrict " pwbufp );
19 .BI "int fgetpwent_r(FILE *restrict " stream \
20 ", struct passwd *restrict " pwbuf ,
21 .BI " char " buf "[restrict ." buflen "], size_t " buflen ,
22 .BI " struct passwd **restrict " pwbufp );
26 Feature Test Macro Requirements for glibc (see
27 .BR feature_test_macros (7)):
34 glibc 2.19 and earlier:
35 _BSD_SOURCE || _SVID_SOURCE
42 glibc 2.19 and earlier:
50 are the reentrant versions of
54 The former reads the next passwd entry from the stream initialized by
56 The latter reads the next passwd entry from
59 The \fIpasswd\fP structure is defined in
66 char *pw_name; /* username */
67 char *pw_passwd; /* user password */
68 uid_t pw_uid; /* user ID */
69 gid_t pw_gid; /* group ID */
70 char *pw_gecos; /* user information */
71 char *pw_dir; /* home directory */
72 char *pw_shell; /* shell program */
77 For more information about the fields of this structure, see
80 The nonreentrant functions return a pointer to static storage,
81 where this static storage contains further pointers to user
82 name, password, gecos field, home directory and shell.
83 The reentrant functions described here return all of that in
84 caller-provided buffers.
85 First of all there is the buffer
87 that can hold a \fIstruct passwd\fP.
92 that can hold additional strings.
93 The result of these functions, the \fIstruct passwd\fP read from the stream,
94 is stored in the provided buffer
96 and a pointer to this \fIstruct passwd\fP is returned in
99 On success, these functions return 0 and
101 is a pointer to the \fIstruct passwd\fP.
102 On error, these functions return an error value and
111 Insufficient buffer space supplied.
112 Try again with larger buffer.
114 For an explanation of the terms used in this section, see
120 Interface Attribute Value
128 MT-Unsafe race:pwent locale
134 T} Thread safety MT-Safe
141 signifies that if any of the functions
147 are used in parallel in different threads of a program,
148 then data races could occur.
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 These functions are done in a style resembling
172 the POSIX version of functions like
177 is not really reentrant since it shares the reading position
178 in the stream with all other threads.
180 .\" SRC BEGIN (getpwent_r.c)
200 i = getpwent_r(&pw, buf, sizeof(buf), &pwp);
203 printf("%s (%jd)\etHOME %s\etSHELL %s\en", pwp\->pw_name,
204 (intmax_t) pwp\->pw_uid, pwp\->pw_dir, pwp\->pw_shell);
210 .\" perhaps add error checking - should use strerror_r
211 .\" #include <errno.h>
212 .\" #include <stdlib.h>
216 .\" printf("getpwent_r: %s", strerror(i));
217 .\" exit(EXIT_SUCCESS);