README: Update links
[man-pages.git] / man3 / getpwent.3
blob5c213db9a015e7ff40fa44bbe08db8b81bb32bbf
1 '\" t
2 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .\" References consulted:
7 .\"     Linux libc source code
8 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
9 .\"     386BSD man pages
10 .\"
11 .\" Modified Sat Jul 24 19:22:14 1993 by Rik Faith (faith@cs.unc.edu)
12 .\" Modified Mon May 27 21:37:47 1996 by Martin Schulze (joey@linux.de)
13 .\"
14 .TH getpwent 3 (date) "Linux man-pages (unreleased)"
15 .SH NAME
16 getpwent, setpwent, endpwent \- get password file entry
17 .SH LIBRARY
18 Standard C library
19 .RI ( libc ", " \-lc )
20 .SH SYNOPSIS
21 .nf
22 .B #include <sys/types.h>
23 .B #include <pwd.h>
25 .B struct passwd *getpwent(void);
26 .B void setpwent(void);
27 .B void endpwent(void);
28 .fi
30 .RS -4
31 Feature Test Macro Requirements for glibc (see
32 .BR feature_test_macros (7)):
33 .RE
35 .BR getpwent (),
36 .BR setpwent (),
37 .BR endpwent ():
38 .nf
39     _XOPEN_SOURCE >= 500
40 .\"    || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
41         || /* glibc >= 2.19: */ _DEFAULT_SOURCE
42         || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
43 .fi
44 .SH DESCRIPTION
45 The
46 .BR getpwent ()
47 function returns a pointer to a structure containing
48 the broken-out fields of a record from the password database
49 (e.g., the local password file
50 .IR /etc/passwd ,
51 NIS, and LDAP).
52 The first time
53 .BR getpwent ()
54 is called, it returns the first entry; thereafter, it returns successive
55 entries.
57 The
58 .BR setpwent ()
59 function rewinds to the beginning
60 of the password database.
62 The
63 .BR endpwent ()
64 function is used to close the password database
65 after all processing has been performed.
67 The \fIpasswd\fP structure is defined in \fI<pwd.h>\fP as follows:
69 .in +4n
70 .EX
71 struct passwd {
72     char   *pw_name;       /* username */
73     char   *pw_passwd;     /* user password */
74     uid_t   pw_uid;        /* user ID */
75     gid_t   pw_gid;        /* group ID */
76     char   *pw_gecos;      /* user information */
77     char   *pw_dir;        /* home directory */
78     char   *pw_shell;      /* shell program */
80 .EE
81 .in
83 For more information about the fields of this structure, see
84 .BR passwd (5).
85 .SH RETURN VALUE
86 The
87 .BR getpwent ()
88 function returns a pointer to a
89 .I passwd
90 structure, or NULL if
91 there are no more entries or an error occurred.
92 If an error occurs,
93 .I errno
94 is set to indicate the error.
95 If one wants to check
96 .I errno
97 after the call, it should be set to zero before the call.
99 The return value may point to a static area, and may be overwritten
100 by subsequent calls to
101 .BR getpwent (),
102 .BR getpwnam (3),
104 .BR getpwuid (3).
105 (Do not pass the returned pointer to
106 .BR free (3).)
107 .SH ERRORS
109 .B EINTR
110 A signal was caught; see
111 .BR signal (7).
113 .B EIO
114 I/O error.
116 .B EMFILE
117 The per-process limit on the number of open file descriptors has been reached.
119 .B ENFILE
120 The system-wide limit on the total number of open files has been reached.
122 .B ENOMEM
123 .\" not in POSIX
124 Insufficient memory to allocate
125 .I passwd
126 structure.
127 .\" to allocate the passwd structure, or to allocate buffers
129 .B ERANGE
130 Insufficient buffer space supplied.
131 .SH FILES
133 .I /etc/passwd
134 local password database file
135 .SH ATTRIBUTES
136 For an explanation of the terms used in this section, see
137 .BR attributes (7).
139 allbox;
140 lb lb lbx
141 l l l.
142 Interface       Attribute       Value
146 .BR getpwent ()
147 T}      Thread safety   T{
150 MT-Unsafe race:pwent
151 race:pwentbuf locale
156 .BR setpwent (),
157 .BR endpwent ()
158 T}      Thread safety   T{
161 MT-Unsafe race:pwent locale
165 In the above table,
166 .I pwent
168 .I race:pwent
169 signifies that if any of the functions
170 .BR setpwent (),
171 .BR getpwent (),
173 .BR endpwent ()
174 are used in parallel in different threads of a program,
175 then data races could occur.
176 .SH VERSIONS
178 .I pw_gecos
179 field is not specified in POSIX, but is present on most implementations.
180 .SH STANDARDS
181 POSIX.1-2008.
182 .SH HISTORY
183 POSIX.1-2001, SVr4, 4.3BSD.
184 .SH SEE ALSO
185 .BR fgetpwent (3),
186 .BR getpw (3),
187 .BR getpwent_r (3),
188 .BR getpwnam (3),
189 .BR getpwuid (3),
190 .BR putpwent (3),
191 .BR passwd (5)