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
11

NAME

13       endpwent, getpwent, setpwent — user database functions
14

SYNOPSIS

16       #include <pwd.h>
17
18       void endpwent(void);
19       struct passwd *getpwent(void);
20       void setpwent(void);
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 thread-safe.
49

RETURN VALUE

51       The  getpwent()  function shall return a null pointer on end-of-file or
52       error.
53
54       The application shall not modify the  structure  to  which  the  return
55       value  points,  nor any storage areas pointed to by pointers within the
56       structure. The returned pointer, and  pointers  within  the  structure,
57       might  be  invalidated  or  the structure or the storage areas might be
58       overwritten by a subsequent call to getpwuid(),  getpwnam(),  or  getp‐
59       went().
60

ERRORS

62       These functions may fail if:
63
64       EIO    An I/O error has occurred.
65
66       In addition, getpwent() and setpwent() may fail if:
67
68       EMFILE All  file  descriptors  available  to  the process are currently
69              open.
70
71       ENFILE The maximum allowable number of files is currently open  in  the
72              system.
73
74       The following sections are informative.
75

EXAMPLES

77   Searching the User Database
78       The  following  example  uses the getpwent() function to get successive
79       entries in the user database, returning a pointer to a passwd structure
80       that  contains  information  about  each  user.  The call to endpwent()
81       closes the user database and cleans up.
82
83           #include <pwd.h>
84           #include <stdio.h>
85
86           void printname(uid_t uid)
87           {
88               struct passwd *pwd;
89
90               setpwent();
91               while((pwd = getpwent()) != NULL) {
92                   if (pwd->pw_uid == uid) {
93                       printf("name=%s\n",pwd->pw_name);
94                       break;
95                   }
96               }
97               endpwent();
98           }
99

APPLICATION USAGE

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

RATIONALE

108       None.
109

FUTURE DIRECTIONS

111       None.
112

SEE ALSO

114       endgrent(), getlogin(), getpwnam(), getpwuid()
115
116       The Base Definitions volume of POSIX.1‐2008, <pwd.h>
117
119       Portions of this text are reprinted and reproduced in  electronic  form
120       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
121       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
122       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
123       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
124       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
125       event of any discrepancy between this version and the original IEEE and
126       The  Open Group Standard, the original IEEE and The Open Group Standard
127       is the referee document. The original Standard can be  obtained  online
128       at http://www.unix.org/online.html .
129
130       Any  typographical  or  formatting  errors that appear in this page are
131       most likely to have been introduced during the conversion of the source
132       files  to  man page format. To report such errors, see https://www.ker
133       nel.org/doc/man-pages/reporting_bugs.html .
134
135
136
137IEEE/The Open Group                  2013                         ENDPWENT(3P)
Impressum