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 2003-11-15 "GNU" "Linux Programmer's Manual"
25 getpwent_r, fgetpwent_r \- get passwd file entry reentrantly
28 .B "#define _GNU_SOURCE"
32 .BI "int getpwent_r(struct passwd *" pwbuf ", char *" buf ,
34 .BI " size_t " buflen ", struct passwd **" pwbufp );
36 .BI "int fgetpwent_r(FILE *" fp ", struct passwd *" pwbuf ", char *" buf ,
38 .BI " size_t " buflen ", struct passwd **" pwbufp );
44 are the reentrant versions of
48 The former reads the next passwd entry from the stream initialized by
50 The latter reads the next passwd entry from the stream
54 The \fIpasswd\fP structure is defined in
61 char *pw_name; /* user name */
62 char *pw_passwd; /* user password */
63 uid_t pw_uid; /* user ID */
64 gid_t pw_gid; /* group ID */
65 char *pw_gecos; /* real name */
66 char *pw_dir; /* home directory */
67 char *pw_shell; /* shell program */
72 The non-reentrant functions return a pointer to static storage,
73 where this static storage contains further pointers to user
74 name, password, gecos field, home directory and shell.
75 The reentrant functions described here return all of that in
76 caller-provided buffers. First of all there is the buffer
78 that can hold a struct passwd. And next the buffer
82 that can hold additional strings.
83 The result of these functions, the struct passwd read from the stream,
84 is stored in the provided buffer
86 and a pointer to this struct passwd is returned in
89 On success, these functions return 0 and
91 is a pointer to the struct passwd.
92 On error, these functions return an error value and
101 Insufficient buffer space supplied. Try again with larger buffer.
112 struct passwd pw, *pwp;
118 i = getpwent_r(&pw, buf, BUFLEN, &pwp);
121 printf("%s (%d)\etHOME %s\etSHELL %s\en", pwp->pw_name,
122 pwp->pw_uid, pwp->pw_dir, pwp->pw_shell);
128 .\" perhaps add error checking - should use strerror_r
129 .\" #include <errno.h>
130 .\" #include <stdlib.h>
134 .\" printf("getpwent_r: %s", strerror(i));
138 These functions are GNU extensions, done in a style resembling
139 the POSIX version of functions like
141 Other systems use prototype
146 getpwent_r(struct passwd *pwd, char *buf, int buflen);
155 getpwent_r(struct passwd *pwd, char *buf, int buflen,
162 is not really reentrant since it shares the reading position
163 in the stream with all other threads.
172 .BR feature_test_macros (7)