]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/getpwent_r.3
fuse.4: fuse_entry_out: rework discussion of uniqueness of nodeid + generation
[thirdparty/man-pages.git] / man3 / getpwent_r.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
2.\"
1dd72f9c 3.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
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.
8.\"
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.
13.\"
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.
18.\"
19.\" You should have received a copy of the GNU General Public
c715f741
MK
20.\" License along with this manual; if not, see
21.\" <http://www.gnu.org/licenses/>.
6a8d8745 22.\" %%%LICENSE_END
fea681da 23.\"
97986708 24.TH GETPWENT_R 3 2016-03-15 "GNU" "Linux Programmer's Manual"
fea681da
MK
25.SH NAME
26getpwent_r, fgetpwent_r \- get passwd file entry reentrantly
27.SH SYNOPSIS
28.nf
fea681da
MK
29.B #include <pwd.h>
30.sp
31.BI "int getpwent_r(struct passwd *" pwbuf ", char *" buf ,
32.br
33.BI " size_t " buflen ", struct passwd **" pwbufp );
34.sp
495604c3 35.BI "int fgetpwent_r(FILE *" stream ", struct passwd *" pwbuf ", char *" buf ,
fea681da
MK
36.br
37.BI " size_t " buflen ", struct passwd **" pwbufp );
cc4615cc
MK
38.fi
39.sp
40.in -4n
41Feature Test Macro Requirements for glibc (see
42.BR feature_test_macros (7)):
43.in
44.sp
45.BR getpwent_r (),
51c612fb
MK
46 Since glibc 2.19:
47 _DEFAULT_SOURCE
48 Glibc 2.19 and earlier:
49 _BSD_SOURCE || _SVID_SOURCE
cc4615cc
MK
50.br
51.BR fgetpwent_r ():
51c612fb
MK
52 Since glibc 2.19:
53 _DEFAULT_SOURCE
54 Glibc 2.19 and earlier:
55 _SVID_SOURCE
fea681da
MK
56.SH DESCRIPTION
57The functions
63aa9df0 58.BR getpwent_r ()
fea681da 59and
63aa9df0 60.BR fgetpwent_r ()
fea681da
MK
61are the reentrant versions of
62.BR getpwent (3)
63and
64.BR fgetpwent (3).
65The former reads the next passwd entry from the stream initialized by
66.BR setpwent (3).
ef3d4efe 67The latter reads the next passwd entry from
495604c3 68.IR stream .
fea681da
MK
69.PP
70The \fIpasswd\fP structure is defined in
71.I <pwd.h>
72as follows:
73.sp
bd191423 74.in +4n
fea681da
MK
75.nf
76struct passwd {
18701562 77 char *pw_name; /* username */
cf0a9ace
MK
78 char *pw_passwd; /* user password */
79 uid_t pw_uid; /* user ID */
80 gid_t pw_gid; /* group ID */
97724acd 81 char *pw_gecos; /* user information */
cf0a9ace
MK
82 char *pw_dir; /* home directory */
83 char *pw_shell; /* shell program */
fea681da
MK
84};
85.fi
bd191423 86.in
7f12f117
MK
87.PP
88For more information about the fields of this structure, see
89.BR passwd (5).
90
54d75d6c 91The nonreentrant functions return a pointer to static storage,
fea681da
MK
92where this static storage contains further pointers to user
93name, password, gecos field, home directory and shell.
94The reentrant functions described here return all of that in
c13182ef
MK
95caller-provided buffers.
96First of all there is the buffer
fea681da 97.I pwbuf
0c2ec4f1 98that can hold a \fIstruct passwd\fP.
c13182ef 99And next the buffer
fea681da
MK
100.I buf
101of size
102.I buflen
103that can hold additional strings.
0c2ec4f1 104The result of these functions, the \fIstruct passwd\fP read from the stream,
fea681da 105is stored in the provided buffer
bd9b2a9c 106.IR *pwbuf ,
0c2ec4f1 107and a pointer to this \fIstruct passwd\fP is returned in
bd9b2a9c 108.IR *pwbufp .
47297adb 109.SH RETURN VALUE
fea681da 110On success, these functions return 0 and
bd9b2a9c 111.I *pwbufp
0c2ec4f1 112is a pointer to the \fIstruct passwd\fP.
fea681da 113On error, these functions return an error value and
bd9b2a9c 114.I *pwbufp
fea681da
MK
115is NULL.
116.SH ERRORS
117.TP
118.B ENOENT
119No more entries.
120.TP
121.B ERANGE
c13182ef
MK
122Insufficient buffer space supplied.
123Try again with larger buffer.
98a731cd
ZL
124.SH ATTRIBUTES
125For an explanation of the terms used in this section, see
126.BR attributes (7).
127.TS
128allbox;
129lb lb lbw27
130l l l.
131Interface Attribute Value
132T{
133.BR getpwent_r ()
134T} Thread safety MT-Unsafe race:pwent locale
135T{
136.BR fgetpwent_r ()
137T} Thread safety MT-Safe
138.TE
139
140In the above table,
141.I pwent
142in
143.I race:pwent
144signifies that if any of the functions
145.BR setpwent (),
146.BR getpwent (),
147.BR endpwent (),
148or
149.BR getpwent_r ()
150are used in parallel in different threads of a program,
151then data races could occur.
47297adb 152.SH CONFORMING TO
2b2581ee
MK
153These functions are GNU extensions, done in a style resembling
154the POSIX version of functions like
155.BR getpwnam_r (3).
b5606b27 156Other systems use the prototype
2b2581ee
MK
157.sp
158.nf
088a639b 159.in +4n
2b2581ee
MK
160struct passwd *
161getpwent_r(struct passwd *pwd, char *buf, int buflen);
162.in
163.fi
164.sp
165or, better,
166.sp
167.nf
088a639b 168.in +4n
2b2581ee
MK
169int
170getpwent_r(struct passwd *pwd, char *buf, int buflen,
171 FILE **pw_fp);
172.in
173.fi
174.SH NOTES
175The function
176.BR getpwent_r ()
177is not really reentrant since it shares the reading position
178in the stream with all other threads.
fea681da
MK
179.SH EXAMPLE
180.nf
181#define _GNU_SOURCE
182#include <pwd.h>
183#include <stdio.h>
184#define BUFLEN 4096
185
c13182ef
MK
186int
187main(void)
cf0a9ace
MK
188{
189 struct passwd pw, *pwp;
190 char buf[BUFLEN];
191 int i;
fea681da 192
cf0a9ace
MK
193 setpwent();
194 while (1) {
195 i = getpwent_r(&pw, buf, BUFLEN, &pwp);
196 if (i)
197 break;
31a6818e 198 printf("%s (%d)\etHOME %s\etSHELL %s\en", pwp\->pw_name,
29059a65 199 pwp\->pw_uid, pwp\->pw_dir, pwp\->pw_shell);
cf0a9ace
MK
200 }
201 endpwent();
5bc8c34c 202 exit(EXIT_SUCCESS);
fea681da
MK
203}
204.fi
205.\" perhaps add error checking - should use strerror_r
206.\" #include <errno.h>
207.\" #include <stdlib.h>
208.\" if (i) {
209.\" if (i == ENOENT)
210.\" break;
211.\" printf("getpwent_r: %s", strerror(i));
4c44ffe5 212.\" exit(EXIT_SUCCESS);
fea681da 213.\" }
47297adb 214.SH SEE ALSO
fea681da
MK
215.BR fgetpwent (3),
216.BR getpw (3),
217.BR getpwent (3),
218.BR getpwnam (3),
219.BR getpwuid (3),
220.BR putpwent (3),
cc4615cc 221.BR passwd (5)