1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" References consulted:
6 .\" Linux libc source code
7 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
10 .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
11 .\" Modified 2003-11-15 by aeb
13 .TH GETGRNAM 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
15 getgrnam, getgrnam_r, getgrgid, getgrgid_r \- get group file entry
18 .RI ( libc ", " \-lc )
21 .B #include <sys/types.h>
24 .BI "struct group *getgrnam(const char *" name );
25 .BI "struct group *getgrgid(gid_t " gid );
27 .BI "int getgrnam_r(const char *restrict " name \
28 ", struct group *restrict " grp ,
29 .BI " char *restrict " buf ", size_t " buflen ,
30 .BI " struct group **restrict " result );
31 .BI "int getgrgid_r(gid_t " gid ", struct group *restrict " grp ,
32 .BI " char *restrict " buf ", size_t " buflen ,
33 .BI " struct group **restrict " result );
37 Feature Test Macro Requirements for glibc (see
38 .BR feature_test_macros (7)):
45 || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
50 function returns a pointer to a structure containing
51 the broken-out fields of the record in the group database
52 (e.g., the local group file
55 that matches the group name
60 function returns a pointer to a structure containing
61 the broken-out fields of the record in the group database
62 that matches the group ID
65 The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows:
70 char *gr_name; /* group name */
71 char *gr_passwd; /* group password */
72 gid_t gr_gid; /* group ID */
73 char **gr_mem; /* NULL\-terminated array of pointers
74 to names of group members */
79 For more information about the fields of this structure, see
86 functions obtain the same information as
90 but store the retrieved
93 in the space pointed to by
95 The string fields pointed to by the members of the
97 structure are stored in the buffer
101 A pointer to the result (in case of success) or NULL (in case no entry
102 was found or an error occurred) is stored in
109 sysconf(_SC_GETGR_R_SIZE_MAX)
113 returns either \-1, without changing
115 or an initial suggested size for
117 (If this size is too small,
120 in which case the caller can retry with a larger buffer.)
126 functions return a pointer to a
128 structure, or NULL if the matching entry
129 is not found or an error occurs.
132 is set to indicate the error.
133 If one wants to check
135 after the call, it should be set to zero before the call.
137 The return value may point to a static area, and may be overwritten
138 by subsequent calls to
143 (Do not pass the returned pointer to
154 If no matching group record was found,
155 these functions return 0 and store NULL in
157 In case of error, an error number is returned, and NULL is stored in
161 .BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ..."
169 A signal was caught; see
176 The per-process limit on the number of open file descriptors has been reached.
179 The system-wide limit on the total number of open files has been reached.
183 Insufficient memory to allocate
186 .\" to allocate the group structure, or to allocate buffers
189 Insufficient buffer space supplied.
193 local group database file
195 For an explanation of the terms used in this section, see
203 Interface Attribute Value
207 MT-Unsafe race:grnam locale
212 MT-Unsafe race:grgid locale
217 T} Thread safety MT-Safe locale
223 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
225 The formulation given above under "RETURN VALUE" is from POSIX.1.
226 .\" POSIX.1-2001, POSIX.1-2008
227 It does not call "not found" an error, hence does not specify what value
229 might have in this situation.
230 But that makes it impossible to recognize
232 One might argue that according to POSIX
234 should be left unchanged if an entry is not found.
235 Experiments on various
236 UNIX-like systems show that lots of different values occur in this
237 situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM, and probably others.
239 .\" AIX 5.1 - gives ESRCH
240 .\" OSF1 4.0g - gives EWOULDBLOCK
241 .\" libc, glibc up to version 2.6, Irix 6.5 - give ENOENT
242 .\" glibc since version 2.7 - give 0
243 .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM
244 .\" SunOS 5.8 - gives EBADF
245 .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0