Changes: Ready for 5.13
[man-pages.git] / man3 / getgrent.3
blob83571c03894f4f6613e02294d1e705bc35fa846f
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\" Modified Sat Jul 24 19:29:54 1993 by Rik Faith (faith@cs.unc.edu)
30 .TH GETGRENT 3  2021-03-22 "" "Linux Programmer's Manual"
31 .SH NAME
32 getgrent, setgrent, endgrent \- get group file entry
33 .SH SYNOPSIS
34 .nf
35 .B #include <sys/types.h>
36 .B #include <grp.h>
37 .PP
38 .B struct group *getgrent(void);
39 .PP
40 .B void setgrent(void);
41 .B void endgrent(void);
42 .fi
43 .PP
44 .RS -4
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
47 .RE
48 .PP
49 .BR setgrent ():
50 .nf
51     _XOPEN_SOURCE >= 500
52 .\"    || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
53         || /* Glibc since 2.19: */ _DEFAULT_SOURCE
54         || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
55 .fi
56 .PP
57 .BR getgrent (),
58 .BR endgrent ():
59 .nf
60     Since glibc 2.22:
61         _XOPEN_SOURCE >= 500 || _DEFAULT_SOURCE
62 .\"        || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
63     Glibc 2.21 and earlier
64         _XOPEN_SOURCE >= 500
65 .\"        || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
66             || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
67             || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
68 .fi
69 .SH DESCRIPTION
70 The
71 .BR getgrent ()
72 function returns a pointer to a structure containing
73 the broken-out fields of a record in the group database
74 (e.g., the local group file
75 .IR /etc/group ,
76 NIS, and LDAP).
77 The first time
78 .BR getgrent ()
79 is called,
80 it returns the first entry; thereafter, it returns successive entries.
81 .PP
82 The
83 .BR setgrent ()
84 function rewinds to the beginning
85 of the group database, to allow repeated scans.
86 .PP
87 The
88 .BR endgrent ()
89 function is used to close the group database
90 after all processing has been performed.
91 .PP
92 The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows:
93 .PP
94 .in +4n
95 .EX
96 struct group {
97     char   *gr_name;        /* group name */
98     char   *gr_passwd;      /* group password */
99     gid_t   gr_gid;         /* group ID */
100     char  **gr_mem;         /* NULL\-terminated array of pointers
101                                to names of group members */
106 For more information about the fields of this structure, see
107 .BR group (5).
108 .SH RETURN VALUE
110 .BR getgrent ()
111 function returns a pointer to a
112 .I group
113 structure,
114 or NULL if there are no more entries or an error occurs.
116 Upon error,
117 .I errno
118 may be set.
119 If one wants to check
120 .I errno
121 after the call, it should be set to zero before the call.
123 The return value may point to a static area, and may be overwritten
124 by subsequent calls to
125 .BR getgrent (),
126 .BR getgrgid (3),
128 .BR getgrnam (3).
129 (Do not pass the returned pointer to
130 .BR free (3).)
131 .SH ERRORS
133 .B EAGAIN
134 The service was temporarily unavailable; try again later.
135 For NSS backends in glibc this indicates a temporary error talking to the backend.
136 The error may correct itself, retrying later is suggested.
138 .B EINTR
139 A signal was caught; see
140 .BR signal (7).
142 .B EIO
143 I/O error.
145 .B EMFILE
146 The per-process limit on the number of open file descriptors has been reached.
148 .B ENFILE
149 The system-wide limit on the total number of open files has been reached.
151 .\" not in POSIX
152 .B ENOENT
153 A necessary input file cannot be found.
154 For NSS backends in glibc this indicates the backend is not correctly configured.
156 .B ENOMEM
157 .\" not in POSIX
158 Insufficient memory to allocate
159 .I group
160 structure.
162 .B ERANGE
163 Insufficient buffer space supplied.
164 .SH FILES
166 .I /etc/group
167 local group database file
168 .SH ATTRIBUTES
169 For an explanation of the terms used in this section, see
170 .BR attributes (7).
171 .ad l
174 allbox;
175 lb lb lbx
176 l l l.
177 Interface       Attribute       Value
179 .BR getgrent ()
180 T}      Thread safety   T{
181 MT-Unsafe race:grent
182 race:grentbuf locale
185 .BR setgrent (),
186 .BR endgrent ()
187 T}      Thread safety   T{
188 MT-Unsafe race:grent locale
193 .sp 1
195 In the above table,
196 .I grent
198 .I race:grent
199 signifies that if any of the functions
200 .BR setgrent (),
201 .BR getgrent (),
203 .BR endgrent ()
204 are used in parallel in different threads of a program,
205 then data races could occur.
206 .SH CONFORMING TO
207 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
208 .SH SEE ALSO
209 .BR fgetgrent (3),
210 .BR getgrent_r (3),
211 .BR getgrgid (3),
212 .BR getgrnam (3),
213 .BR getgrouplist (3),
214 .BR putgrent (3),
215 .BR group (5)