1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" References consulted:
26 .\" Linux libc source code
27 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
30 .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
31 .\" Modified 2003-11-15 by aeb
33 .TH GETGRNAM 3 2015-08-08 "" "Linux Programmer's Manual"
35 getgrnam, getgrnam_r, getgrgid, getgrgid_r \- get group file entry
38 .B #include <sys/types.h>
41 .BI "struct group *getgrnam(const char *" name );
43 .BI "struct group *getgrgid(gid_t " gid );
45 .BI "int getgrnam_r(const char *" name ", struct group *" grp ,
47 .BI " char *" buf ", size_t " buflen ", struct group **" result );
49 .BI "int getgrgid_r(gid_t " gid ", struct group *" grp ,
51 .BI " char *" buf ", size_t " buflen ", struct group **" result );
55 Feature Test Macro Requirements for glibc (see
56 .BR feature_test_macros (7)):
63 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
64 _SVID_SOURCE || _POSIX_SOURCE
70 function returns a pointer to a structure containing
71 the broken-out fields of the record in the group database
72 (e.g., the local group file
75 that matches the group name
80 function returns a pointer to a structure containing
81 the broken-out fields of the record in the group database
82 that matches the group ID
85 The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows:
90 char *gr_name; /* group name */
91 char *gr_passwd; /* group password */
92 gid_t gr_gid; /* group ID */
93 char **gr_mem; /* NULL-terminated array of pointers
94 to names of group members */
99 For more information about the fields of this structure, see
106 functions obtain the same information as
110 but store the retrieved
113 in the space pointed to by
115 The string fields pointed to by the members of the
117 structure are stored in the buffer
121 A pointer to the result (in case of success) or NULL (in case no entry
122 was found or an error occurred) is stored in
127 sysconf(_SC_GETGR_R_SIZE_MAX)
129 returns either \-1, without changing
131 or an initial suggested size for
133 (If this size is too small,
136 in which case the caller can retry with a larger buffer.)
142 functions return a pointer to a
144 structure, or NULL if the matching entry
145 is not found or an error occurs.
148 is set appropriately.
149 If one wants to check
151 after the call, it should be set to zero before the call.
153 The return value may point to a static area, and may be overwritten
154 by subsequent calls to
159 (Do not pass the returned pointer to
170 If no matching group record was found,
171 these functions return 0 and store NULL in
173 In case of error, an error number is returned, and NULL is stored in
177 .BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ... "
193 of files was open already in the calling process.
196 The maximum number of files was open already in the system.
200 Insufficient memory to allocate
203 .\" to allocate the group structure, or to allocate buffers
206 Insufficient buffer space supplied.
210 local group database file
212 For an explanation of the terms used in this section, see
218 Interface Attribute Value
221 T} Thread safety MT-Unsafe race:grnam locale
224 T} Thread safety MT-Unsafe race:grgid locale
229 T} Thread safety MT-Safe locale
232 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
234 The formulation given above under "RETURN VALUE" is from POSIX.1.
235 .\" POSIX.1-2001, POSIX.1-2008
236 It does not call "not found" an error, hence does not specify what value
238 might have in this situation.
239 But that makes it impossible to recognize
241 One might argue that according to POSIX
243 should be left unchanged if an entry is not found.
244 Experiments on various
245 UNIX-like systems show that lots of different values occur in this
246 situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM, and probably others.
248 .\" AIX 5.1 - gives ESRCH
249 .\" OSF1 4.0g - gives EWOULDBLOCK
250 .\" libc, glibc up to version 2.6, Irix 6.5 - give ENOENT
251 .\" glibc since version 2.7 - give 0
252 .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM
253 .\" SunOS 5.8 - gives EBADF
254 .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0