1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
29 .\" Modified 2003-11-15 by aeb
31 .TH GETGRNAM 3 2003-11-15 "" "Linux Programmer's Manual"
33 getgrnam, getgrnam_r, getgrgid, getgrgid_r \- get group file entry
36 .B #include <sys/types.h>
39 .BI "struct group *getgrnam(const char *" name );
41 .BI "struct group *getgrgid(gid_t " gid );
43 .BI "int getgrnam_r(const char *" name ", struct group *" gbuf ,
45 .BI " char *" buf ", size_t " buflen ", struct group **" gbufp );
47 .BI "int getgrgid_r(gid_t " gid ", struct group *" gbuf ,
49 .BI " char *" buf ", size_t " buflen ", struct group **" gbufp );
54 function returns a pointer to a structure containing
55 the broken-out fields of the record in the group database
56 (e.g., the local group file
59 that matches the group name
64 function returns a pointer to a structure containing
65 the broken-out fields of the record in the group database
66 that matches the group ID
73 functions obtain the same information, but store the retrieved
76 in the space pointed to by
80 structure contains pointers to strings, and these strings
81 are stored in the buffer
85 A pointer to the result (in case of success) or NULL (in case no entry
86 was found or an error occurred) is stored in
89 The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows:
94 char *gr_name; /* group name */
95 char *gr_passwd; /* group password */
96 gid_t gr_gid; /* group ID */
97 char **gr_mem; /* group members */
102 The maximum needed size for
106 with the _SC_GETGR_R_SIZE_MAX parameter.
108 The \fBgetgrnam\fP() and \fBgetgrgid\fP() functions return a pointer to a
110 structure, or NULL if the matching entry
111 is not found or an error occurs.
114 is set appropriately.
115 If one wants to check
117 after the call, it should be set to zero before the call.
119 The return value may point to static area, and may be overwritten
120 by subsequent calls to
126 The \fBgetgrnam_r\fP() and \fBgetgrgid_r\fP() functions return
127 zero on success. In case of error, an error number is returned.
130 .BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ... "
144 The maximum number (OPEN_MAX) of files was open already in the calling process.
147 The maximum number of files was open already in the system.
151 Insufficient memory to allocate group structure.
152 .\" to allocate the group structure, or to allocate buffers
155 Insufficient buffer space supplied.
159 local group database file
161 SVID 3, 4.3BSD, POSIX 1003.1-2003
163 The formulation given above under "RETURN VALUE" is from POSIX 1003.1-2001.
164 It does not call "not found" an error, hence does not specify what value
166 might have in this situation. But that makes it impossible to recognize
167 errors. One might argue that according to POSIX
169 should be left unchanged if an entry is not found. Experiments on various
170 Unix-like systems shows that lots of different values occur in this
171 situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and probably others.
173 .\" AIX 5.1 - gives ESRCH
174 .\" OSF1 4.0g - gives EWOULDBLOCK
175 .\" libc, glibc, Irix 6.5 - give ENOENT
176 .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM
177 .\" SunOS 5.8 - gives EBADF
178 .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0