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 2017-09-15 "GNU" "Linux Programmer's Manual"
26 getpwent_r, fgetpwent_r \- get passwd file entry reentrantly
31 .BI "int getpwent_r(struct passwd *" pwbuf ", char *" buf ,
32 .BI " size_t " buflen ", struct passwd **" pwbufp );
34 .BI "int fgetpwent_r(FILE *" stream ", struct passwd *" pwbuf ", char *" buf ,
35 .BI " size_t " buflen ", struct passwd **" pwbufp );
39 Feature Test Macro Requirements for glibc (see
40 .BR feature_test_macros (7)):
46 Glibc 2.19 and earlier:
47 _BSD_SOURCE || _SVID_SOURCE
52 Glibc 2.19 and earlier:
59 are the reentrant versions of
63 The former reads the next passwd entry from the stream initialized by
65 The latter reads the next passwd entry from
68 The \fIpasswd\fP structure is defined in
75 char *pw_name; /* username */
76 char *pw_passwd; /* user password */
77 uid_t pw_uid; /* user ID */
78 gid_t pw_gid; /* group ID */
79 char *pw_gecos; /* user information */
80 char *pw_dir; /* home directory */
81 char *pw_shell; /* shell program */
86 For more information about the fields of this structure, see
89 The nonreentrant functions return a pointer to static storage,
90 where this static storage contains further pointers to user
91 name, password, gecos field, home directory and shell.
92 The reentrant functions described here return all of that in
93 caller-provided buffers.
94 First of all there is the buffer
96 that can hold a \fIstruct passwd\fP.
101 that can hold additional strings.
102 The result of these functions, the \fIstruct passwd\fP read from the stream,
103 is stored in the provided buffer
105 and a pointer to this \fIstruct passwd\fP is returned in
108 On success, these functions return 0 and
110 is a pointer to the \fIstruct passwd\fP.
111 On error, these functions return an error value and
120 Insufficient buffer space supplied.
121 Try again with larger buffer.
123 For an explanation of the terms used in this section, see
129 Interface Attribute Value
132 T} Thread safety MT-Unsafe race:pwent locale
135 T} Thread safety MT-Safe
142 signifies that if any of the functions
148 are used in parallel in different threads of a program,
149 then data races could occur.
151 These functions are GNU extensions, done in a style resembling
152 the POSIX version of functions like
154 Other systems use the prototype
159 getpwent_r(struct passwd *pwd, char *buf, int buflen);
168 getpwent_r(struct passwd *pwd, char *buf, int buflen,
175 is not really reentrant since it shares the reading position
176 in the stream with all other threads.
187 struct passwd pw, *pwp;
193 i = getpwent_r(&pw, buf, BUFLEN, &pwp);
196 printf("%s (%d)\etHOME %s\etSHELL %s\en", pwp\->pw_name,
197 pwp\->pw_uid, pwp\->pw_dir, pwp\->pw_shell);
203 .\" perhaps add error checking - should use strerror_r
204 .\" #include <errno.h>
205 .\" #include <stdlib.h>
209 .\" printf("getpwent_r: %s", strerror(i));
210 .\" exit(EXIT_SUCCESS);