1 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
3 .\" This is free documentation; you can redistribute it and/or
4 .\" modify it under the terms of the GNU General Public License as
5 .\" published by the Free Software Foundation; either version 2 of
6 .\" the License, or (at your option) any later version.
8 .\" The GNU General Public License's references to "object code"
9 .\" and "executables" are to be interpreted as the output of any
10 .\" document formatting or typesetting system, including
11 .\" intermediate and printed output.
13 .\" This manual is distributed in the hope that it will be useful,
14 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
15 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 .\" GNU General Public License for more details.
18 .\" You should have received a copy of the GNU General Public
19 .\" License along with this manual; if not, write to the Free
20 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
23 .TH GETPWENT_R 3 2007-07-26 "GNU" "Linux Programmer's Manual"
25 getpwent_r, fgetpwent_r \- get passwd file entry reentrantly
30 .BI "int getpwent_r(struct passwd *" pwbuf ", char *" buf ,
32 .BI " size_t " buflen ", struct passwd **" pwbufp );
34 .BI "int fgetpwent_r(FILE *" fp ", struct passwd *" pwbuf ", char *" buf ,
36 .BI " size_t " buflen ", struct passwd **" pwbufp );
40 Feature Test Macro Requirements for glibc (see
41 .BR feature_test_macros (7)):
45 _BSD_SOURCE || _SVID_SOURCE
54 are the reentrant versions of
58 The former reads the next passwd entry from the stream initialized by
60 The latter reads the next passwd entry from the stream
63 The \fIpasswd\fP structure is defined in
70 char *pw_name; /* username */
71 char *pw_passwd; /* user password */
72 uid_t pw_uid; /* user ID */
73 gid_t pw_gid; /* group ID */
74 char *pw_gecos; /* real name */
75 char *pw_dir; /* home directory */
76 char *pw_shell; /* shell program */
81 The nonreentrant functions return a pointer to static storage,
82 where this static storage contains further pointers to user
83 name, password, gecos field, home directory and shell.
84 The reentrant functions described here return all of that in
85 caller-provided buffers.
86 First of all there is the buffer
88 that can hold a \fIstruct passwd\fP.
93 that can hold additional strings.
94 The result of these functions, the \fIstruct passwd\fP read from the stream,
95 is stored in the provided buffer
97 and a pointer to this \fIstruct passwd\fP is returned in
100 On success, these functions return 0 and
102 is a pointer to the \fIstruct passwd\fP.
103 On error, these functions return an error value and
112 Insufficient buffer space supplied.
113 Try again with larger buffer.
115 These functions are GNU extensions, done in a style resembling
116 the POSIX version of functions like
118 Other systems use prototype
123 getpwent_r(struct passwd *pwd, char *buf, int buflen);
132 getpwent_r(struct passwd *pwd, char *buf, int buflen,
139 is not really reentrant since it shares the reading position
140 in the stream with all other threads.
151 struct passwd pw, *pwp;
157 i = getpwent_r(&pw, buf, BUFLEN, &pwp);
160 printf("%s (%d)\etHOME %s\etSHELL %s\en", pwp\->pw_name,
161 pwp\->pw_uid, pwp\->pw_dir, pwp\->pw_shell);
167 .\" perhaps add error checking - should use strerror_r
168 .\" #include <errno.h>
169 .\" #include <stdlib.h>
173 .\" printf("getpwent_r: %s", strerror(i));
174 .\" exit(EXIT_SUCCESS);