1 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
3 .\" SPDX-License-Identifier: GPL-2.0-or-later
5 .TH getgrent_r 3 (date) "Linux man-pages (unreleased)"
7 getgrent_r, fgetgrent_r \- get group file entry reentrantly
10 .RI ( libc ", " \-lc )
15 .BI "int getgrent_r(struct group *restrict " gbuf ,
16 .BI " char *restrict " buf ", size_t " buflen ,
17 .BI " struct group **restrict " gbufp );
18 .BI "int fgetgrent_r(FILE *restrict " stream ", struct group *restrict " gbuf ,
19 .BI " char *restrict " buf ", size_t " buflen ,
20 .BI " struct group **restrict " gbufp );
24 Feature Test Macro Requirements for glibc (see
25 .BR feature_test_macros (7)):
32 .\" FIXME . The FTM requirements seem inconsistent here. File a glibc bug?
38 Glibc 2.19 and earlier:
46 are the reentrant versions of
50 The former reads the next group entry from the stream initialized by
52 The latter reads the next group entry from
55 The \fIgroup\fP structure is defined in
62 char *gr_name; /* group name */
63 char *gr_passwd; /* group password */
64 gid_t gr_gid; /* group ID */
65 char **gr_mem; /* NULL\-terminated array of pointers
66 to names of group members */
71 For more information about the fields of this structure, see
74 The nonreentrant functions return a pointer to static storage,
75 where this static storage contains further pointers to group
76 name, password, and members.
77 The reentrant functions described here return all of that in
78 caller-provided buffers.
79 First of all there is the buffer
81 that can hold a \fIstruct group\fP.
86 that can hold additional strings.
87 The result of these functions, the \fIstruct group\fP read from the stream,
88 is stored in the provided buffer
90 and a pointer to this \fIstruct group\fP is returned in
93 On success, these functions return 0 and
95 is a pointer to the \fIstruct group\fP.
96 On error, these functions return an error value and
105 Insufficient buffer space supplied.
106 Try again with larger buffer.
108 For an explanation of the terms used in this section, see
116 Interface Attribute Value
120 MT-Unsafe race:grent locale
135 signifies that if any of the functions
141 are used in parallel in different threads of a program,
142 then data races could occur.
144 These functions are GNU extensions, done in a style resembling
145 the POSIX version of functions like
147 Other systems use the prototype
151 struct group *getgrent_r(struct group *grp, char *buf,
160 int getgrent_r(struct group *grp, char *buf, int buflen,
167 is not really reentrant since it shares the reading position
168 in the stream with all other threads.
170 .\" SRC BEGIN (getgrent_r.c)
189 i = getgrent_r(&grp, buf, sizeof(buf), &grpp);
192 printf("%s (%jd):", grpp\->gr_name, (intmax_t) grpp\->gr_gid);
193 for (size_t j = 0; ; j++) {
194 if (grpp\->gr_mem[j] == NULL)
196 printf(" %s", grpp\->gr_mem[j]);
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);