1 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 .\" GNU General Public License for more details.
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
24 .TH GETGRENT_R 3 2021-03-22 "GNU" "Linux Programmer's Manual"
26 getgrent_r, fgetgrent_r \- get group file entry reentrantly
31 .BI "int getgrent_r(struct group *restrict " gbuf ,
32 .BI " char *restrict " buf ", size_t " buflen ,
33 .BI " struct group **restrict " gbufp );
34 .BI "int fgetgrent_r(FILE *restrict " stream ", struct group *restrict " gbuf ,
35 .BI " char *restrict " buf ", size_t " buflen ,
36 .BI " struct group **restrict " gbufp );
40 Feature Test Macro Requirements for glibc (see
41 .BR feature_test_macros (7)):
48 .\" FIXME . The FTM requirements seem inconsistent here. File a glibc bug?
53 Glibc 2.19 and earlier:
60 are the reentrant versions of
64 The former reads the next group entry from the stream initialized by
66 The latter reads the next group entry from
69 The \fIgroup\fP structure is defined in
76 char *gr_name; /* group name */
77 char *gr_passwd; /* group password */
78 gid_t gr_gid; /* group ID */
79 char **gr_mem; /* NULL\-terminated array of pointers
80 to names of group members */
85 For more information about the fields of this structure, see
88 The nonreentrant functions return a pointer to static storage,
89 where this static storage contains further pointers to group
90 name, password, and members.
91 The reentrant functions described here return all of that in
92 caller-provided buffers.
93 First of all there is the buffer
95 that can hold a \fIstruct group\fP.
100 that can hold additional strings.
101 The result of these functions, the \fIstruct group\fP read from the stream,
102 is stored in the provided buffer
104 and a pointer to this \fIstruct group\fP is returned in
107 On success, these functions return 0 and
109 is a pointer to the \fIstruct group\fP.
110 On error, these functions return an error value and
119 Insufficient buffer space supplied.
120 Try again with larger buffer.
122 For an explanation of the terms used in this section, see
130 Interface Attribute Value
134 MT-Unsafe race:grent locale
149 signifies that if any of the functions
155 are used in parallel in different threads of a program,
156 then data races could occur.
158 These functions are GNU extensions, done in a style resembling
159 the POSIX version of functions like
161 Other systems use the prototype
165 struct group *getgrent_r(struct group *grp, char *buf,
174 int getgrent_r(struct group *grp, char *buf, int buflen,
181 is not really reentrant since it shares the reading position
182 in the stream with all other threads.
202 i = getgrent_r(&grp, buf, sizeof(buf), &grpp);
205 printf("%s (%jd):", grpp\->gr_name, (intmax_t) grpp\->gr_gid);
206 for (int j = 0; ; j++) {
207 if (grpp\->gr_mem[j] == NULL)
209 printf(" %s", grpp\->gr_mem[j]);
217 .\" perhaps add error checking - should use strerror_r
218 .\" #include <errno.h>
219 .\" #include <stdlib.h>
223 .\" printf("getgrent_r: %s", strerror(i));
224 .\" exit(EXIT_FAILURE);