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 2015-01-22 "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 ,
33 .BI " size_t " buflen ", struct group **" gbufp );
35 .BI "int fgetgrent_r(FILE *" stream ", struct group *" gbuf ", char *" buf ,
37 .BI " size_t " buflen ", struct group **" gbufp );
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
47 .\" FIXME . The FTM requirements seem inconsistent here. File a glibc bug?
56 are the reentrant versions of
60 The former reads the next group entry from the stream initialized by
62 The latter reads the next group entry from
65 The \fIgroup\fP structure is defined in
72 char *gr_name; /* group name */
73 char *gr_passwd; /* group password */
74 gid_t gr_gid; /* group ID */
75 char **gr_mem; /* NULL-terminated array of pointers
76 to names of group members */
81 For more information about the fields of this structure, see
84 The nonreentrant functions return a pointer to static storage,
85 where this static storage contains further pointers to group
86 name, password and members.
87 The reentrant functions described here return all of that in
88 caller-provided buffers.
89 First of all there is the buffer
91 that can hold a \fIstruct group\fP.
96 that can hold additional strings.
97 The result of these functions, the \fIstruct group\fP read from the stream,
98 is stored in the provided buffer
100 and a pointer to this \fIstruct group\fP is returned in
103 On success, these functions return 0 and
105 is a pointer to the \fIstruct group\fP.
106 On error, these functions return an error value and
115 Insufficient buffer space supplied.
116 Try again with larger buffer.
118 These functions are GNU extensions, done in a style resembling
119 the POSIX version of functions like
121 Other systems use the prototype
125 struct group *getgrent_r(struct group *grp, char *buf,
134 int getgrent_r(struct group *grp, char *buf, int buflen,
141 is not really reentrant since it shares the reading position
142 in the stream with all other threads.
154 struct group grp, *grpp;
160 i = getgrent_r(&grp, buf, BUFLEN, &grpp);
163 printf("%s (%d):", grpp\->gr_name, grpp\->gr_gid);
165 if (grpp\->gr_mem[i] == NULL)
167 printf(" %s", grpp\->gr_mem[i]);
175 .\" perhaps add error checking - should use strerror_r
176 .\" #include <errno.h>
177 .\" #include <stdlib.h>
181 .\" printf("getgrent_r: %s", strerror(i));
182 .\" exit(EXIT_FAILURE);
192 This page is part of release 3.79 of the Linux
195 A description of the project,
196 information about reporting bugs,
197 and the latest version of this page,
199 \%http://www.kernel.org/doc/man\-pages/.