1 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 .\" GNU General Public License for more details.
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
24 .TH GETPWENT_R 3 2021-03-22 "GNU" "Linux Programmer's Manual"
26 getpwent_r, fgetpwent_r \- get passwd file entry reentrantly
31 .BI "int getpwent_r(struct passwd *restrict " pwbuf ,
32 .BI " char *restrict " buf ", size_t " buflen ,
33 .BI " struct passwd **restrict " pwbufp );
34 .BI "int fgetpwent_r(FILE *restrict " stream \
35 ", struct passwd *restrict " pwbuf ,
36 .BI " char *restrict " buf ", size_t " buflen ,
37 .BI " struct passwd **restrict " pwbufp );
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
49 Glibc 2.19 and earlier:
50 _BSD_SOURCE || _SVID_SOURCE
57 Glibc 2.19 and earlier:
65 are the reentrant versions of
69 The former reads the next passwd entry from the stream initialized by
71 The latter reads the next passwd entry from
74 The \fIpasswd\fP structure is defined in
81 char *pw_name; /* username */
82 char *pw_passwd; /* user password */
83 uid_t pw_uid; /* user ID */
84 gid_t pw_gid; /* group ID */
85 char *pw_gecos; /* user information */
86 char *pw_dir; /* home directory */
87 char *pw_shell; /* shell program */
92 For more information about the fields of this structure, see
95 The nonreentrant functions return a pointer to static storage,
96 where this static storage contains further pointers to user
97 name, password, gecos field, home directory and shell.
98 The reentrant functions described here return all of that in
99 caller-provided buffers.
100 First of all there is the buffer
102 that can hold a \fIstruct passwd\fP.
107 that can hold additional strings.
108 The result of these functions, the \fIstruct passwd\fP read from the stream,
109 is stored in the provided buffer
111 and a pointer to this \fIstruct passwd\fP is returned in
114 On success, these functions return 0 and
116 is a pointer to the \fIstruct passwd\fP.
117 On error, these functions return an error value and
126 Insufficient buffer space supplied.
127 Try again with larger buffer.
129 For an explanation of the terms used in this section, see
137 Interface Attribute Value
141 MT-Unsafe race:pwent locale
145 T} Thread safety MT-Safe
154 signifies that if any of the functions
160 are used in parallel in different threads of a program,
161 then data races could occur.
163 These functions are GNU extensions, done in a style resembling
164 the POSIX version of functions like
166 Other systems use the prototype
171 getpwent_r(struct passwd *pwd, char *buf, int buflen);
180 getpwent_r(struct passwd *pwd, char *buf, int buflen,
187 is not really reentrant since it shares the reading position
188 in the stream with all other threads.
207 i = getpwent_r(&pw, buf, sizeof(buf), &pwp);
210 printf("%s (%jd)\etHOME %s\etSHELL %s\en", pwp\->pw_name,
211 (intmax_t) pwp\->pw_uid, pwp\->pw_dir, pwp\->pw_shell);
217 .\" perhaps add error checking - should use strerror_r
218 .\" #include <errno.h>
219 .\" #include <stdlib.h>
223 .\" printf("getpwent_r: %s", strerror(i));
224 .\" exit(EXIT_SUCCESS);