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 2010-10-21 "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 *" fp ", 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 the stream
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; /* group members */
80 For more information about the fields of this structure, see
83 The nonreentrant functions return a pointer to static storage,
84 where this static storage contains further pointers to group
85 name, password and members.
86 The reentrant functions described here return all of that in
87 caller-provided buffers.
88 First of all there is the buffer
90 that can hold a \fIstruct group\fP.
95 that can hold additional strings.
96 The result of these functions, the \fIstruct group\fP read from the stream,
97 is stored in the provided buffer
99 and a pointer to this \fIstruct group\fP is returned in
102 On success, these functions return 0 and
104 is a pointer to the \fIstruct group\fP.
105 On error, these functions return an error value and
114 Insufficient buffer space supplied.
115 Try again with larger buffer.
117 These functions are GNU extensions, done in a style resembling
118 the POSIX version of functions like
120 Other systems use prototype
124 struct group *getgrent_r(struct group *grp, char *buf,
133 int getgrent_r(struct group *grp, char *buf, int buflen,
140 is not really reentrant since it shares the reading position
141 in the stream with all other threads.
153 struct group grp, *grpp;
159 i = getgrent_r(&grp, buf, BUFLEN, &grpp);
162 printf("%s (%d):", grpp\->gr_name, grpp\->gr_gid);
164 if (grpp\->gr_mem[i] == NULL)
166 printf(" %s", grpp\->gr_mem[i]);
174 .\" perhaps add error checking - should use strerror_r
175 .\" #include <errno.h>
176 .\" #include <stdlib.h>
180 .\" printf("getgrent_r: %s", strerror(i));
181 .\" exit(EXIT_FAILURE);
191 This page is part of release 3.67 of the Linux
194 A description of the project,
195 information about reporting bugs,
196 and the latest version of this page,
198 \%http://www.kernel.org/doc/man\-pages/.