1getpwent(3)                Library Functions Manual                getpwent(3)
2
3
4

NAME

6       getpwent, setpwent, endpwent - get password file entry
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/types.h>
13       #include <pwd.h>
14
15       struct passwd *getpwent(void);
16       void setpwent(void);
17       void endpwent(void);
18
19   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21       getpwent(), setpwent(), endpwent():
22           _XOPEN_SOURCE >= 500
23               || /* glibc >= 2.19: */ _DEFAULT_SOURCE
24               || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
25

DESCRIPTION

27       The getpwent() function returns a pointer to a structure containing the
28       broken-out fields of a record from the password database (e.g., the lo‐
29       cal  password  file  /etc/passwd, NIS, and LDAP).  The first time getp‐
30       went() is called, it returns the first entry;  thereafter,  it  returns
31       successive entries.
32
33       The  setpwent() function rewinds to the beginning of the password data‐
34       base.
35
36       The endpwent() function is used to close the  password  database  after
37       all processing has been performed.
38
39       The passwd structure is defined in <pwd.h> as follows:
40
41           struct passwd {
42               char   *pw_name;       /* username */
43               char   *pw_passwd;     /* user password */
44               uid_t   pw_uid;        /* user ID */
45               gid_t   pw_gid;        /* group ID */
46               char   *pw_gecos;      /* user information */
47               char   *pw_dir;        /* home directory */
48               char   *pw_shell;      /* shell program */
49           };
50
51       For more information about the fields of this structure, see passwd(5).
52

RETURN VALUE

54       The  getpwent()  function  returns  a pointer to a passwd structure, or
55       NULL if there are no more entries or an error occurred.   If  an  error
56       occurs,  errno is set to indicate the error.  If one wants to check er‐
57       rno after the call, it should be set to zero before the call.
58
59       The return value may point to a static area, and may be overwritten  by
60       subsequent  calls  to getpwent(), getpwnam(3), or getpwuid(3).  (Do not
61       pass the returned pointer to free(3).)
62

ERRORS

64       EINTR  A signal was caught; see signal(7).
65
66       EIO    I/O error.
67
68       EMFILE The per-process limit on the number of open file descriptors has
69              been reached.
70
71       ENFILE The system-wide limit on the total number of open files has been
72              reached.
73
74       ENOMEM Insufficient memory to allocate passwd structure.
75
76       ERANGE Insufficient buffer space supplied.
77

FILES

79       /etc/passwd
80              local password database file
81

ATTRIBUTES

83       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
84       tributes(7).
85
86       ┌────────────┬───────────────┬─────────────────────────────────────────┐
87Interface   Attribute     Value                                   
88       ├────────────┼───────────────┼─────────────────────────────────────────┤
89getpwent()  │ Thread safety │ MT-Unsafe race:pwent race:pwentbuf      │
90       │            │               │ locale                                  │
91       ├────────────┼───────────────┼─────────────────────────────────────────┤
92setpwent(), │ Thread safety │ MT-Unsafe race:pwent locale             │
93endpwent()  │               │                                         │
94       └────────────┴───────────────┴─────────────────────────────────────────┘
95       In  the  above  table, pwent in race:pwent signifies that if any of the
96       functions setpwent(), getpwent(), or endpwent() are used in parallel in
97       different threads of a program, then data races could occur.
98

VERSIONS

100       The  pw_gecos  field  is not specified in POSIX, but is present on most
101       implementations.
102

STANDARDS

104       POSIX.1-2008.
105

HISTORY

107       POSIX.1-2001, SVr4, 4.3BSD.
108

SEE ALSO

110       fgetpwent(3), getpw(3), getpwent_r(3), getpwnam(3), getpwuid(3),  putp‐
111       went(3), passwd(5)
112
113
114
115Linux man-pages 6.04              2023-03-30                       getpwent(3)
Impressum