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 2017-09-15 "GNU" "Linux Programmer's Manual"
26 getgrent_r, fgetgrent_r \- get group file entry reentrantly
31 .BI "int getgrent_r(struct group *" gbuf ", char *" buf ,
32 .BI " size_t " buflen ", struct group **" gbufp );
34 .BI "int fgetgrent_r(FILE *" stream ", struct group *" gbuf ", char *" buf ,
35 .BI " size_t " buflen ", struct group **" gbufp );
39 Feature Test Macro Requirements for glibc (see
40 .BR feature_test_macros (7)):
45 .\" FIXME . The FTM requirements seem inconsistent here. File a glibc bug?
50 Glibc 2.19 and earlier:
57 are the reentrant versions of
61 The former reads the next group entry from the stream initialized by
63 The latter reads the next group entry from
66 The \fIgroup\fP structure is defined in
73 char *gr_name; /* group name */
74 char *gr_passwd; /* group password */
75 gid_t gr_gid; /* group ID */
76 char **gr_mem; /* NULL-terminated array of pointers
77 to names of group members */
82 For more information about the fields of this structure, see
85 The nonreentrant functions return a pointer to static storage,
86 where this static storage contains further pointers to group
87 name, password and members.
88 The reentrant functions described here return all of that in
89 caller-provided buffers.
90 First of all there is the buffer
92 that can hold a \fIstruct group\fP.
97 that can hold additional strings.
98 The result of these functions, the \fIstruct group\fP read from the stream,
99 is stored in the provided buffer
101 and a pointer to this \fIstruct group\fP is returned in
104 On success, these functions return 0 and
106 is a pointer to the \fIstruct group\fP.
107 On error, these functions return an error value and
116 Insufficient buffer space supplied.
117 Try again with larger buffer.
119 For an explanation of the terms used in this section, see
125 Interface Attribute Value
128 T} Thread safety MT-Unsafe race:grent locale
131 T} Thread safety MT-Safe
138 signifies that if any of the functions
144 are used in parallel in different threads of a program,
145 then data races could occur.
147 These functions are GNU extensions, done in a style resembling
148 the POSIX version of functions like
150 Other systems use the prototype
154 struct group *getgrent_r(struct group *grp, char *buf,
163 int getgrent_r(struct group *grp, char *buf, int buflen,
170 is not really reentrant since it shares the reading position
171 in the stream with all other threads.
183 struct group grp, *grpp;
189 i = getgrent_r(&grp, buf, BUFLEN, &grpp);
192 printf("%s (%d):", grpp\->gr_name, grpp\->gr_gid);
194 if (grpp\->gr_mem[i] == NULL)
196 printf(" %s", grpp\->gr_mem[i]);
204 .\" perhaps add error checking - should use strerror_r
205 .\" #include <errno.h>
206 .\" #include <stdlib.h>
210 .\" printf("getgrent_r: %s", strerror(i));
211 .\" exit(EXIT_FAILURE);