Debian Codegraph @

upstream/mageia-cauldron/man3/getpwent.3

raw
1 '\" t
2 .\" Copyright 1993, David Metcalfe <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH getpwent 3 2026-02-08 "Linux man-pages 6.17"
8 .SH NAME
9 getpwent, setpwent, endpwent \- get password file entry
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <sys/types.h>
16 .B #include <pwd.h>
17 .P
18 .B struct passwd *getpwent(void);
19 .B void setpwent(void);
20 .B void endpwent(void);
21 .fi
22 .P
23 .RS -4
24 Feature Test Macro Requirements for glibc (see
25 .BR feature_test_macros (7)):
26 .RE
27 .P
28 .BR getpwent (),
29 .BR setpwent (),
30 .BR endpwent ():
31 .nf
32 _XOPEN_SOURCE >= 500
33 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
34 || /* glibc >= 2.19: */ _DEFAULT_SOURCE
35 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
36 .fi
37 .SH DESCRIPTION
38 The
39 .BR getpwent ()
40 function returns a pointer to a structure containing
41 the broken-out fields of a record from the password database
42 (e.g., the local password file
43 .IR /etc/passwd ,
44 NIS, and LDAP).
45 The first time
46 .BR getpwent ()
47 is called,
48 it returns the first entry;
49 thereafter,
50 it returns successive entries.
51 .P
52 The
53 .BR setpwent ()
54 function rewinds to the beginning
55 of the password database.
56 .P
57 The
58 .BR endpwent ()
59 function is used to close the password database
60 after all processing has been performed.
61 .P
62 The
63 .I passwd
64 structure is defined in
65 .I <pwd.h>
66 as follows:
67 .P
68 .in +4n
69 .EX
70 struct passwd {
71 char *pw_name; /* username */
72 char *pw_passwd; /* user password */
73 uid_t pw_uid; /* user ID */
74 gid_t pw_gid; /* group ID */
75 char *pw_gecos; /* user information */
76 char *pw_dir; /* home directory */
77 char *pw_shell; /* shell program */
78 };
79 .EE
80 .in
81 .P
82 For more information about the fields of this structure, see
83 .BR passwd (5).
84 .SH RETURN VALUE
85 The
86 .BR getpwent ()
87 function returns a pointer to a
88 .I passwd
89 structure, or NULL if
90 there are no more entries or an error occurred.
91 If an error occurs,
92 .I errno
93 is set to indicate the error.
94 If one wants to check
95 .I errno
96 after the call, it should be set to zero before the call.
97 .P
98 The return value may point to a static area, and may be overwritten
99 by subsequent calls to
100 .BR getpwent (),
101 .BR getpwnam (3),
102 or
103 .BR getpwuid (3).
104 (Do not pass the returned pointer to
105 .BR free (3).)
106 .SH ERRORS
107 .TP
108 .B EINTR
109 A signal was caught;
110 see
111 .BR signal (7).
112 .TP
113 .B EIO
114 I/O error.
115 .TP
116 .B EMFILE
117 The per-process limit on the number of open file descriptors has been reached.
118 .TP
119 .B ENFILE
120 The system-wide limit on the total number of open files has been reached.
121 .TP
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
128 .TP
129 .B ERANGE
130 Insufficient buffer space supplied.
131 .SH FILES
132 .TP
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).
138 .TS
139 allbox;
140 lb lb lbx
141 l l l.
142 Interface Attribute Value
143 T{
144 .na
145 .nh
146 .BR getpwent ()
147 T} Thread safety T{
148 .na
149 .nh
150 MT-Unsafe race:pwent
151 race:pwentbuf locale
152 T}
153 T{
154 .na
155 .nh
156 .BR setpwent (),
157 .BR endpwent ()
158 T} Thread safety T{
159 .na
160 .nh
161 MT-Unsafe race:pwent locale
162 T}
163 .TE
164 .P
165 In the above table,
166 .I pwent
167 in
168 .I race:pwent
169 signifies that if any of the functions
170 .BR setpwent (),
171 .BR getpwent (),
172 or
173 .BR endpwent ()
174 are used in parallel in different threads of a program,
175 then data races could occur.
176 .SH VERSIONS
177 The
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)