1ENDPWENT(3P)               POSIX Programmer's Manual              ENDPWENT(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       endpwent, getpwent, setpwent - user database functions
13

SYNOPSIS

15       #include <pwd.h>
16
17       void endpwent(void);
18       struct passwd *getpwent(void);
19       void setpwent(void);
20
21

DESCRIPTION

23       These functions shall retrieve information about users.
24
25       The getpwent() function shall return a pointer to a structure  contain‐
26       ing  the broken-out fields of an entry in the user database. Each entry
27       in the user database contains a passwd structure.  When  first  called,
28       getpwent()  shall return a pointer to a passwd structure containing the
29       first entry in the user database. Thereafter, it shall return a pointer
30       to  a  passwd structure containing the next entry in the user database.
31       Successive calls can be used to search the entire user database.
32
33       If an end-of-file or an error is  encountered  on  reading,  getpwent()
34       shall return a null pointer.
35
36       An  implementation  that provides extended security controls may impose
37       further implementation-defined restrictions on accessing the user data‐
38       base.  In  particular, the system may deny the existence of some or all
39       of the user database entries associated with users other than the call‐
40       er.
41
42       The  setpwent() function effectively rewinds the user database to allow
43       repeated searches.
44
45       The endpwent() function may be called to close the user  database  when
46       processing is complete.
47
48       These  functions need not be reentrant. A function that is not required
49       to be reentrant is not required to be thread-safe.
50

RETURN VALUE

52       The getpwent() function shall return a null pointer on  end-of-file  or
53       error.
54

ERRORS

56       The getpwent(), setpwent(), and endpwent() functions may fail if:
57
58       EIO    An I/O error has occurred.
59
60
61       In addition, getpwent() and setpwent() may fail if:
62
63       EMFILE {OPEN_MAX}  file  descriptors  are currently open in the calling
64              process.
65
66       ENFILE The maximum allowable number of files is currently open  in  the
67              system.
68
69
70       The  return  value may point to a static area which is overwritten by a
71       subsequent call to getpwuid(), getpwnam(), or getpwent().
72
73       The following sections are informative.
74

EXAMPLES

76   Searching the User Database
77       The following example uses the getpwent() function  to  get  successive
78       entries in the user database, returning a pointer to a passwd structure
79       that contains information about each  user.   The  call  to  endpwent()
80       closes the user database and cleans up.
81
82
83              #include <pwd.h>
84              ...
85              struct passwd *p;
86              ...
87              while ((p = getpwent ()) != NULL) {
88              ...
89              }
90
91
92              endpwent();
93              ...
94

APPLICATION USAGE

96       These  functions  are  provided due to their historical usage. Applica‐
97       tions should avoid dependencies on fields  in  the  password  database,
98       whether the database is a single file, or where in the file system name
99       space the database resides. Applications should use getpwuid() whenever
100       possible because it avoids these dependencies.
101

RATIONALE

103       None.
104

FUTURE DIRECTIONS

106       None.
107

SEE ALSO

109       endgrent(),  getlogin(),  getpwnam(),  getpwuid(), the Base Definitions
110       volume of IEEE Std 1003.1-2001, <pwd.h>
111
113       Portions of this text are reprinted and reproduced in  electronic  form
114       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
115       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
116       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
117       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
118       event of any discrepancy between this version and the original IEEE and
119       The Open Group Standard, the original IEEE and The Open Group  Standard
120       is  the  referee document. The original Standard can be obtained online
121       at http://www.opengroup.org/unix/online.html .
122
123
124
125IEEE/The Open Group                  2003                         ENDPWENT(3P)
Impressum