2 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" References consulted:
7 .\" Linux libc source code
8 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
11 .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
12 .\" Modified 2003-11-15 by aeb
14 .TH getgrnam 3 (date) "Linux man-pages (unreleased)"
16 getgrnam, getgrnam_r, getgrgid, getgrgid_r \- get group file entry
19 .RI ( libc ", " \-lc )
22 .B #include <sys/types.h>
25 .BI "struct group *getgrnam(const char *" name );
26 .BI "struct group *getgrgid(gid_t " gid );
28 .BI "int getgrnam_r(const char *restrict " name \
29 ", struct group *restrict " grp ,
30 .BI " char " buf "[restrict ." buflen "], size_t " buflen ,
31 .BI " struct group **restrict " result );
32 .BI "int getgrgid_r(gid_t " gid ", struct group *restrict " grp ,
33 .BI " char " buf "[restrict ." buflen "], size_t " buflen ,
34 .BI " struct group **restrict " result );
38 Feature Test Macro Requirements for glibc (see
39 .BR feature_test_macros (7)):
46 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
51 function returns a pointer to a structure containing
52 the broken-out fields of the record in the group database
53 (e.g., the local group file
56 that matches the group name
61 function returns a pointer to a structure containing
62 the broken-out fields of the record in the group database
63 that matches the group ID
66 The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows:
71 char *gr_name; /* group name */
72 char *gr_passwd; /* group password */
73 gid_t gr_gid; /* group ID */
74 char **gr_mem; /* NULL\-terminated array of pointers
75 to names of group members */
80 For more information about the fields of this structure, see
87 functions obtain the same information as
91 but store the retrieved
94 in the space pointed to by
96 The string fields pointed to by the members of the
98 structure are stored in the buffer
102 A pointer to the result (in case of success) or NULL (in case no entry
103 was found or an error occurred) is stored in
110 sysconf(_SC_GETGR_R_SIZE_MAX)
114 returns either \-1, without changing
116 or an initial suggested size for
118 (If this size is too small,
121 in which case the caller can retry with a larger buffer.)
127 functions return a pointer to a
129 structure, or NULL if the matching entry
130 is not found or an error occurs.
133 is set to indicate the error.
134 If one wants to check
136 after the call, it should be set to zero before the call.
138 The return value may point to a static area, and may be overwritten
139 by subsequent calls to
144 (Do not pass the returned pointer to
155 If no matching group record was found,
156 these functions return 0 and store NULL in
158 In case of error, an error number is returned, and NULL is stored in
162 .BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ..."
170 A signal was caught; see
177 The per-process limit on the number of open file descriptors has been reached.
180 The system-wide limit on the total number of open files has been reached.
184 Insufficient memory to allocate
187 .\" to allocate the group structure, or to allocate buffers
190 Insufficient buffer space supplied.
194 local group database file
196 For an explanation of the terms used in this section, see
202 Interface Attribute Value
210 MT-Unsafe race:grnam locale
219 MT-Unsafe race:grgid locale
226 T} Thread safety MT-Safe locale
230 The formulation given above under "RETURN VALUE" is from POSIX.1.
231 .\" POSIX.1-2001, POSIX.1-2008
232 It does not call "not found" an error, hence does not specify what value
234 might have in this situation.
235 But that makes it impossible to recognize
237 One might argue that according to POSIX
239 should be left unchanged if an entry is not found.
240 Experiments on various
241 UNIX-like systems show that lots of different values occur in this
242 situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM, and probably others.
244 .\" AIX 5.1 - gives ESRCH
245 .\" OSF1 4.0g - gives EWOULDBLOCK
246 .\" libc, glibc up to glibc 2.6, Irix 6.5 - give ENOENT
247 .\" since glibc 2.7 - give 0
248 .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM
249 .\" SunOS 5.8 - gives EBADF
250 .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0
254 POSIX.1-2001, SVr4, 4.3BSD.