1getgrent(3) Library Functions Manual getgrent(3)
2
3
4
6 getgrent, setgrent, endgrent - get group file entry
7
9 Standard C library (libc, -lc)
10
12 #include <sys/types.h>
13 #include <grp.h>
14
15 struct group *getgrent(void);
16
17 void setgrent(void);
18 void endgrent(void);
19
20 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21
22 setgrent():
23 _XOPEN_SOURCE >= 500
24 || /* glibc >= 2.19: */ _DEFAULT_SOURCE
25 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
26
27 getgrent(), endgrent():
28 Since glibc 2.22:
29 _XOPEN_SOURCE >= 500 || _DEFAULT_SOURCE
30 glibc 2.21 and earlier
31 _XOPEN_SOURCE >= 500
32 || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
33 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
34
36 The getgrent() function returns a pointer to a structure containing the
37 broken-out fields of a record in the group database (e.g., the local
38 group file /etc/group, NIS, and LDAP). The first time getgrent() is
39 called, it returns the first entry; thereafter, it returns successive
40 entries.
41
42 The setgrent() function rewinds to the beginning of the group database,
43 to allow repeated scans.
44
45 The endgrent() function is used to close the group database after all
46 processing has been performed.
47
48 The group structure is defined in <grp.h> as follows:
49
50 struct group {
51 char *gr_name; /* group name */
52 char *gr_passwd; /* group password */
53 gid_t gr_gid; /* group ID */
54 char **gr_mem; /* NULL-terminated array of pointers
55 to names of group members */
56 };
57
58 For more information about the fields of this structure, see group(5).
59
61 The getgrent() function returns a pointer to a group structure, or NULL
62 if there are no more entries or an error occurs.
63
64 Upon error, errno may be set. If one wants to check errno after the
65 call, it should be set to zero before the call.
66
67 The return value may point to a static area, and may be overwritten by
68 subsequent calls to getgrent(), getgrgid(3), or getgrnam(3). (Do not
69 pass the returned pointer to free(3).)
70
72 EAGAIN The service was temporarily unavailable; try again later. For
73 NSS backends in glibc this indicates a temporary error talking
74 to the backend. The error may correct itself, retrying later is
75 suggested.
76
77 EINTR A signal was caught; see signal(7).
78
79 EIO I/O error.
80
81 EMFILE The per-process limit on the number of open file descriptors has
82 been reached.
83
84 ENFILE The system-wide limit on the total number of open files has been
85 reached.
86
87 ENOENT A necessary input file cannot be found. For NSS backends in
88 glibc this indicates the backend is not correctly configured.
89
90 ENOMEM Insufficient memory to allocate group structure.
91
92 ERANGE Insufficient buffer space supplied.
93
95 /etc/group
96 local group database file
97
99 For an explanation of the terms used in this section, see at‐
100 tributes(7).
101
102 ┌────────────┬───────────────┬─────────────────────────────────────────┐
103 │Interface │ Attribute │ Value │
104 ├────────────┼───────────────┼─────────────────────────────────────────┤
105 │getgrent() │ Thread safety │ MT-Unsafe race:grent race:grentbuf │
106 │ │ │ locale │
107 ├────────────┼───────────────┼─────────────────────────────────────────┤
108 │setgrent(), │ Thread safety │ MT-Unsafe race:grent locale │
109 │endgrent() │ │ │
110 └────────────┴───────────────┴─────────────────────────────────────────┘
111
112 In the above table, grent in race:grent signifies that if any of the
113 functions setgrent(), getgrent(), or endgrent() are used in parallel in
114 different threads of a program, then data races could occur.
115
117 POSIX.1-2008.
118
120 POSIX.1-2001, SVr4, 4.3BSD.
121
123 fgetgrent(3), getgrent_r(3), getgrgid(3), getgrnam(3), getgrouplist(3),
124 putgrent(3), group(5)
125
126
127
128Linux man-pages 6.04 2023-03-30 getgrent(3)