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 2015-01-22 "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)):
46 _BSD_SOURCE || _SVID_SOURCE
55 are the reentrant versions of
59 The former reads the next passwd entry from the stream initialized by
61 The latter reads the next passwd entry from
64 The \fIpasswd\fP structure is defined in
71 char *pw_name; /* username */
72 char *pw_passwd; /* user password */
73 uid_t pw_uid; /* user ID */
74 gid_t pw_gid; /* group ID */
75 char *pw_gecos; /* user information */
76 char *pw_dir; /* home directory */
77 char *pw_shell; /* shell program */
82 For more information about the fields of this structure, see
85 The nonreentrant functions return a pointer to static storage,
86 where this static storage contains further pointers to user
87 name, password, gecos field, home directory and shell.
88 The reentrant functions described here return all of that in
89 caller-provided buffers.
90 First of all there is the buffer
92 that can hold a \fIstruct passwd\fP.
97 that can hold additional strings.
98 The result of these functions, the \fIstruct passwd\fP read from the stream,
99 is stored in the provided buffer
101 and a pointer to this \fIstruct passwd\fP is returned in
104 On success, these functions return 0 and
106 is a pointer to the \fIstruct passwd\fP.
107 On error, these functions return an error value and
116 Insufficient buffer space supplied.
117 Try again with larger buffer.
119 These functions are GNU extensions, done in a style resembling
120 the POSIX version of functions like
122 Other systems use the prototype
127 getpwent_r(struct passwd *pwd, char *buf, int buflen);
136 getpwent_r(struct passwd *pwd, char *buf, int buflen,
143 is not really reentrant since it shares the reading position
144 in the stream with all other threads.
155 struct passwd pw, *pwp;
161 i = getpwent_r(&pw, buf, BUFLEN, &pwp);
164 printf("%s (%d)\etHOME %s\etSHELL %s\en", pwp\->pw_name,
165 pwp\->pw_uid, pwp\->pw_dir, pwp\->pw_shell);
171 .\" perhaps add error checking - should use strerror_r
172 .\" #include <errno.h>
173 .\" #include <stdlib.h>
177 .\" printf("getpwent_r: %s", strerror(i));
178 .\" exit(EXIT_SUCCESS);
189 This page is part of release 3.79 of the Linux
192 A description of the project,
193 information about reporting bugs,
194 and the latest version of this page,
196 \%http://www.kernel.org/doc/man\-pages/.