]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/getpwent_r.3
Added/updated glibc feature test macro requirements
[thirdparty/man-pages.git] / man3 / getpwent_r.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
2.\"
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.
7.\"
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.
12.\"
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.
17.\"
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,
21.\" USA.
22.\"
cc4615cc 23.TH GETPWENT_R 3 2007-07-26 "GNU" "Linux Programmer's Manual"
fea681da
MK
24.SH NAME
25getpwent_r, fgetpwent_r \- get passwd file entry reentrantly
26.SH SYNOPSIS
27.nf
fea681da
MK
28.B #include <pwd.h>
29.sp
30.BI "int getpwent_r(struct passwd *" pwbuf ", char *" buf ,
31.br
32.BI " size_t " buflen ", struct passwd **" pwbufp );
33.sp
34.BI "int fgetpwent_r(FILE *" fp ", struct passwd *" pwbuf ", char *" buf ,
35.br
36.BI " size_t " buflen ", struct passwd **" pwbufp );
cc4615cc
MK
37.fi
38.sp
39.in -4n
40Feature Test Macro Requirements for glibc (see
41.BR feature_test_macros (7)):
42.in
43.sp
44.BR getpwent_r (),
45_BSD_SOURCE || _SVID_SOURCE
46.br
47.BR fgetpwent_r ():
48_SVID_SOURCE
fea681da
MK
49.SH DESCRIPTION
50The functions
63aa9df0 51.BR getpwent_r ()
fea681da 52and
63aa9df0 53.BR fgetpwent_r ()
fea681da
MK
54are the reentrant versions of
55.BR getpwent (3)
56and
57.BR fgetpwent (3).
58The former reads the next passwd entry from the stream initialized by
59.BR setpwent (3).
60The latter reads the next passwd entry from the stream
61.I fp
62given as parameter.
63.PP
64The \fIpasswd\fP structure is defined in
65.I <pwd.h>
66as follows:
67.sp
68.RS
69.nf
70struct passwd {
cf0a9ace
MK
71 char *pw_name; /* user name */
72 char *pw_passwd; /* user password */
73 uid_t pw_uid; /* user ID */
74 gid_t pw_gid; /* group ID */
75 char *pw_gecos; /* real name */
76 char *pw_dir; /* home directory */
77 char *pw_shell; /* shell program */
fea681da
MK
78};
79.fi
80.RE
81.sp
82The non-reentrant functions return a pointer to static storage,
83where this static storage contains further pointers to user
84name, password, gecos field, home directory and shell.
85The reentrant functions described here return all of that in
c13182ef
MK
86caller-provided buffers.
87First of all there is the buffer
fea681da 88.I pwbuf
0c2ec4f1 89that can hold a \fIstruct passwd\fP.
c13182ef 90And next the buffer
fea681da
MK
91.I buf
92of size
93.I buflen
94that can hold additional strings.
0c2ec4f1 95The result of these functions, the \fIstruct passwd\fP read from the stream,
fea681da
MK
96is stored in the provided buffer
97.RI * pwbuf ,
0c2ec4f1 98and a pointer to this \fIstruct passwd\fP is returned in
fea681da
MK
99.RI * pwbufp .
100.SH "RETURN VALUE"
101On success, these functions return 0 and
102.RI * pwbufp
0c2ec4f1 103is a pointer to the \fIstruct passwd\fP.
fea681da
MK
104On error, these functions return an error value and
105.RI * pwbufp
106is NULL.
107.SH ERRORS
108.TP
109.B ENOENT
110No more entries.
111.TP
112.B ERANGE
c13182ef
MK
113Insufficient buffer space supplied.
114Try again with larger buffer.
2b2581ee
MK
115.SH "CONFORMING TO"
116These functions are GNU extensions, done in a style resembling
117the POSIX version of functions like
118.BR getpwnam_r (3).
119Other systems use prototype
120.sp
121.nf
122.in +4
123struct passwd *
124getpwent_r(struct passwd *pwd, char *buf, int buflen);
125.in
126.fi
127.sp
128or, better,
129.sp
130.nf
131.in +4
132int
133getpwent_r(struct passwd *pwd, char *buf, int buflen,
134 FILE **pw_fp);
135.in
136.fi
137.SH NOTES
138The function
139.BR getpwent_r ()
140is not really reentrant since it shares the reading position
141in the stream with all other threads.
fea681da
MK
142.SH EXAMPLE
143.nf
144#define _GNU_SOURCE
145#include <pwd.h>
146#include <stdio.h>
147#define BUFLEN 4096
148
c13182ef
MK
149int
150main(void)
cf0a9ace
MK
151{
152 struct passwd pw, *pwp;
153 char buf[BUFLEN];
154 int i;
fea681da 155
cf0a9ace
MK
156 setpwent();
157 while (1) {
158 i = getpwent_r(&pw, buf, BUFLEN, &pwp);
159 if (i)
160 break;
29059a65
MK
161 printf("%s (%d)\etHOME %s\etSHELL %s\en", pwp\->pw_name,
162 pwp\->pw_uid, pwp\->pw_dir, pwp\->pw_shell);
cf0a9ace
MK
163 }
164 endpwent();
5bc8c34c 165 exit(EXIT_SUCCESS);
fea681da
MK
166}
167.fi
168.\" perhaps add error checking - should use strerror_r
169.\" #include <errno.h>
170.\" #include <stdlib.h>
171.\" if (i) {
172.\" if (i == ENOENT)
173.\" break;
174.\" printf("getpwent_r: %s", strerror(i));
4c44ffe5 175.\" exit(EXIT_SUCCESS);
fea681da 176.\" }
fea681da
MK
177.SH "SEE ALSO"
178.BR fgetpwent (3),
179.BR getpw (3),
180.BR getpwent (3),
181.BR getpwnam (3),
182.BR getpwuid (3),
183.BR putpwent (3),
cc4615cc 184.BR passwd (5)