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 2016-03-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 ,
33 .BI " size_t " buflen ", struct passwd **" pwbufp );
35 .BI "int fgetpwent_r(FILE *" stream ", struct passwd *" pwbuf ", char *" buf ,
37 .BI " size_t " buflen ", struct passwd **" pwbufp );
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
48 Glibc 2.19 and earlier:
49 _BSD_SOURCE || _SVID_SOURCE
54 Glibc 2.19 and earlier:
61 are the reentrant versions of
65 The former reads the next passwd entry from the stream initialized by
67 The latter reads the next passwd entry from
70 The \fIpasswd\fP structure is defined in
77 char *pw_name; /* username */
78 char *pw_passwd; /* user password */
79 uid_t pw_uid; /* user ID */
80 gid_t pw_gid; /* group ID */
81 char *pw_gecos; /* user information */
82 char *pw_dir; /* home directory */
83 char *pw_shell; /* shell program */
88 For more information about the fields of this structure, see
91 The nonreentrant functions return a pointer to static storage,
92 where this static storage contains further pointers to user
93 name, password, gecos field, home directory and shell.
94 The reentrant functions described here return all of that in
95 caller-provided buffers.
96 First of all there is the buffer
98 that can hold a \fIstruct passwd\fP.
103 that can hold additional strings.
104 The result of these functions, the \fIstruct passwd\fP read from the stream,
105 is stored in the provided buffer
107 and a pointer to this \fIstruct passwd\fP is returned in
110 On success, these functions return 0 and
112 is a pointer to the \fIstruct passwd\fP.
113 On error, these functions return an error value and
122 Insufficient buffer space supplied.
123 Try again with larger buffer.
125 For an explanation of the terms used in this section, see
131 Interface Attribute Value
134 T} Thread safety MT-Unsafe race:pwent locale
137 T} Thread safety MT-Safe
144 signifies that if any of the functions
150 are used in parallel in different threads of a program,
151 then data races could occur.
153 These functions are GNU extensions, done in a style resembling
154 the POSIX version of functions like
156 Other systems use the prototype
161 getpwent_r(struct passwd *pwd, char *buf, int buflen);
170 getpwent_r(struct passwd *pwd, char *buf, int buflen,
177 is not really reentrant since it shares the reading position
178 in the stream with all other threads.
189 struct passwd pw, *pwp;
195 i = getpwent_r(&pw, buf, BUFLEN, &pwp);
198 printf("%s (%d)\etHOME %s\etSHELL %s\en", pwp\->pw_name,
199 pwp\->pw_uid, pwp\->pw_dir, pwp\->pw_shell);
205 .\" perhaps add error checking - should use strerror_r
206 .\" #include <errno.h>
207 .\" #include <stdlib.h>
211 .\" printf("getpwent_r: %s", strerror(i));
212 .\" exit(EXIT_SUCCESS);