2 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
6 .TH getgrent_r 3 (date) "Linux man-pages (unreleased)"
8 getgrent_r, fgetgrent_r \- get group file entry reentrantly
11 .RI ( libc ", " \-lc )
16 .BI "int getgrent_r(struct group *restrict " gbuf ,
17 .BI " char " buf "[restrict ." buflen "], size_t " buflen ,
18 .BI " struct group **restrict " gbufp );
19 .BI "int fgetgrent_r(FILE *restrict " stream ", struct group *restrict " gbuf ,
20 .BI " char " buf "[restrict ." buflen "], size_t " buflen ,
21 .BI " struct group **restrict " gbufp );
25 Feature Test Macro Requirements for glibc (see
26 .BR feature_test_macros (7)):
33 .\" FIXME . The FTM requirements seem inconsistent here. File a glibc bug?
39 glibc 2.19 and earlier:
47 are the reentrant versions of
51 The former reads the next group entry from the stream initialized by
53 The latter reads the next group entry from
56 The \fIgroup\fP structure is defined in
63 char *gr_name; /* group name */
64 char *gr_passwd; /* group password */
65 gid_t gr_gid; /* group ID */
66 char **gr_mem; /* NULL\-terminated array of pointers
67 to names of group members */
72 For more information about the fields of this structure, see
75 The nonreentrant functions return a pointer to static storage,
76 where this static storage contains further pointers to group
77 name, password, and members.
78 The reentrant functions described here return all of that in
79 caller-provided buffers.
80 First of all there is the buffer
82 that can hold a \fIstruct group\fP.
87 that can hold additional strings.
88 The result of these functions, the \fIstruct group\fP read from the stream,
89 is stored in the provided buffer
91 and a pointer to this \fIstruct group\fP is returned in
94 On success, these functions return 0 and
96 is a pointer to the \fIstruct group\fP.
97 On error, these functions return an error value and
106 Insufficient buffer space supplied.
107 Try again with larger buffer.
109 For an explanation of the terms used in this section, see
115 Interface Attribute Value
123 MT-Unsafe race:grent locale
140 signifies that if any of the functions
146 are used in parallel in different threads of a program,
147 then data races could occur.
149 Other systems use the prototype
153 struct group *getgrent_r(struct group *grp, char *buf,
162 int getgrent_r(struct group *grp, char *buf, int buflen,
169 These functions are done in a style resembling
170 the POSIX version of functions like
175 is not really reentrant since it shares the reading position
176 in the stream with all other threads.
178 .\" SRC BEGIN (getgrent_r.c)
197 i = getgrent_r(&grp, buf, sizeof(buf), &grpp);
200 printf("%s (%jd):", grpp\->gr_name, (intmax_t) grpp\->gr_gid);
201 for (size_t j = 0; ; j++) {
202 if (grpp\->gr_mem[j] == NULL)
204 printf(" %s", grpp\->gr_mem[j]);
212 .\" perhaps add error checking - should use strerror_r
213 .\" #include <errno.h>
214 .\" #include <stdlib.h>
218 .\" printf("getgrent_r: %s", strerror(i));
219 .\" exit(EXIT_FAILURE);