1ENDPWENT(P) POSIX Programmer's Manual ENDPWENT(P)
2
3
4
6 endpwent, getpwent, setpwent - user database functions
7
9 #include <pwd.h>
10
11 void endpwent(void);
12 struct passwd *getpwent(void);
13 void setpwent(void);
14
15
17 These functions shall retrieve information about users.
18
19 The getpwent() function shall return a pointer to a structure contain‐
20 ing the broken-out fields of an entry in the user database. Each entry
21 in the user database contains a passwd structure. When first called,
22 getpwent() shall return a pointer to a passwd structure containing the
23 first entry in the user database. Thereafter, it shall return a pointer
24 to a passwd structure containing the next entry in the user database.
25 Successive calls can be used to search the entire user database.
26
27 If an end-of-file or an error is encountered on reading, getpwent()
28 shall return a null pointer.
29
30 An implementation that provides extended security controls may impose
31 further implementation-defined restrictions on accessing the user data‐
32 base. In particular, the system may deny the existence of some or all
33 of the user database entries associated with users other than the call‐
34 er.
35
36 The setpwent() function effectively rewinds the user database to allow
37 repeated searches.
38
39 The endpwent() function may be called to close the user database when
40 processing is complete.
41
42 These functions need not be reentrant. A function that is not required
43 to be reentrant is not required to be thread-safe.
44
46 The getpwent() function shall return a null pointer on end-of-file or
47 error.
48
50 The getpwent(), setpwent(), and endpwent() functions may fail if:
51
52 EIO An I/O error has occurred.
53
54
55 In addition, getpwent() and setpwent() may fail if:
56
57 EMFILE {OPEN_MAX} file descriptors are currently open in the calling
58 process.
59
60 ENFILE The maximum allowable number of files is currently open in the
61 system.
62
63
64 The return value may point to a static area which is overwritten by a
65 subsequent call to getpwuid(), getpwnam(), or getpwent().
66
67 The following sections are informative.
68
70 Searching the User Database
71 The following example uses the getpwent() function to get successive
72 entries in the user database, returning a pointer to a passwd structure
73 that contains information about each user. The call to endpwent()
74 closes the user database and cleans up.
75
76
77 #include <pwd.h>
78 ...
79 struct passwd *p;
80 ...
81 while ((p = getpwent ()) != NULL) {
82 ...
83 }
84
85
86 endpwent();
87 ...
88
90 These functions are provided due to their historical usage. Applica‐
91 tions should avoid dependencies on fields in the password database,
92 whether the database is a single file, or where in the file system name
93 space the database resides. Applications should use getpwuid() whenever
94 possible because it avoids these dependencies.
95
97 None.
98
100 None.
101
103 endgrent() , getlogin() , getpwnam() , getpwuid() , the Base Defini‐
104 tions volume of IEEE Std 1003.1-2001, <pwd.h>
105
107 Portions of this text are reprinted and reproduced in electronic form
108 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
109 -- Portable Operating System Interface (POSIX), The Open Group Base
110 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
111 Electrical and Electronics Engineers, Inc and The Open Group. In the
112 event of any discrepancy between this version and the original IEEE and
113 The Open Group Standard, the original IEEE and The Open Group Standard
114 is the referee document. The original Standard can be obtained online
115 at http://www.opengroup.org/unix/online.html .
116
117
118
119IEEE/The Open Group 2003 ENDPWENT(P)