]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/getgrnam.3
truncate.2: wfix
[thirdparty/man-pages.git] / man3 / getgrnam.3
CommitLineData
fea681da
MK
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
7.\"
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.
c13182ef 12.\"
fea681da
MK
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
19.\" professionally.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
24.\"
25.\" References consulted:
26.\" Linux libc source code
27.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28.\" 386BSD man pages
29.\"
30.\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
31.\" Modified 2003-11-15 by aeb
32.\"
29b41e74 33.TH GETGRNAM 3 2015-12-28 "" "Linux Programmer's Manual"
fea681da
MK
34.SH NAME
35getgrnam, getgrnam_r, getgrgid, getgrgid_r \- get group file entry
36.SH SYNOPSIS
37.nf
38.B #include <sys/types.h>
39.B #include <grp.h>
40.sp
41.BI "struct group *getgrnam(const char *" name );
42.sp
43.BI "struct group *getgrgid(gid_t " gid );
44.sp
3b11a494 45.BI "int getgrnam_r(const char *" name ", struct group *" grp ,
fea681da 46.br
3b11a494 47.BI " char *" buf ", size_t " buflen ", struct group **" result );
fea681da 48.sp
3b11a494 49.BI "int getgrgid_r(gid_t " gid ", struct group *" grp ,
fea681da 50.br
3b11a494 51.BI " char *" buf ", size_t " buflen ", struct group **" result );
fea681da 52.fi
0f200f07
MK
53.sp
54.in -4n
55Feature Test Macro Requirements for glibc (see
56.BR feature_test_macros (7)):
57.ad l
58.in
59.sp
60.BR getgrnam_r (),
61.BR getgrgid_r ():
47bec168 62.RS 4
0f200f07
MK
63_POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
64_SVID_SOURCE || _POSIX_SOURCE
47bec168 65.RE
0f200f07 66.ad b
fea681da
MK
67.SH DESCRIPTION
68The
63aa9df0 69.BR getgrnam ()
fea681da 70function returns a pointer to a structure containing
f936cf26 71the broken-out fields of the record in the group database
c13182ef 72(e.g., the local group file
f2738b39
MK
73.IR /etc/group ,
74NIS, and LDAP)
f936cf26 75that matches the group name
fea681da
MK
76.IR name .
77.PP
78The
63aa9df0 79.BR getgrgid ()
fea681da 80function returns a pointer to a structure containing
f2738b39 81the broken-out fields of the record in the group database
f936cf26 82that matches the group ID
fea681da
MK
83.IR gid .
84.PP
b39f3e05
MK
85The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows:
86.sp
87.in +4n
88.nf
89struct group {
5e333b1b
MK
90 char *gr_name; /* group name */
91 char *gr_passwd; /* group password */
92 gid_t gr_gid; /* group ID */
b7800b44
MK
93 char **gr_mem; /* NULL-terminated array of pointers
94 to names of group members */
b39f3e05
MK
95};
96.fi
97.in
98.PP
99For more information about the fields of this structure, see
100.BR group (5).
101.PP
fea681da 102The
63aa9df0 103.BR getgrnam_r ()
fea681da 104and
63aa9df0 105.BR getgrgid_r ()
b39f3e05
MK
106functions obtain the same information as
107.BR getgrnam ()
108and
109.BR getgrgid (),
110but store the retrieved
f2738b39
MK
111.I group
112structure
fea681da 113in the space pointed to by
3b11a494 114.IR grp .
b39f3e05 115The string fields pointed to by the members of the
f2738b39 116.I group
b39f3e05 117structure are stored in the buffer
fea681da
MK
118.I buf
119of size
120.IR buflen .
121A pointer to the result (in case of success) or NULL (in case no entry
122was found or an error occurred) is stored in
3b11a494 123.IR *result .
fea681da 124.PP
f7bae7f8
MK
125The call
126
127 sysconf(_SC_GETGR_R_SIZE_MAX)
128
129returns either \-1, without changing
130.IR errno ,
131or an initial suggested size for
132.IR buf .
133(If this size is too small,
134the call fails with
135.BR ERANGE ,
136in which case the caller can retry with a larger buffer.)
47297adb 137.SH RETURN VALUE
60a90ecd
MK
138The
139.BR getgrnam ()
140and
141.BR getgrgid ()
142functions return a pointer to a
f2738b39
MK
143.I group
144structure, or NULL if the matching entry
145is not found or an error occurs.
146If an error occurs,
fea681da 147.I errno
f2738b39
MK
148is set appropriately.
149If one wants to check
fea681da
MK
150.I errno
151after the call, it should be set to zero before the call.
152.LP
c34a8ff7 153The return value may point to a static area, and may be overwritten
fea681da 154by subsequent calls to
91fe9d5c 155.BR getgrent (3),
63aa9df0 156.BR getgrgid (),
fea681da 157or
63aa9df0 158.BR getgrnam ().
48e4cfa0
MK
159(Do not pass the returned pointer to
160.BR free (3).)
fea681da 161.LP
2ac1e1d3 162On success,
60a90ecd
MK
163.BR getgrnam_r ()
164and
165.BR getgrgid_r ()
b006e083 166return zero, and set
3b11a494 167.IR *result
b006e083 168to
3b11a494 169.IR grp .
b006e083
MK
170If no matching group record was found,
171these functions return 0 and store NULL in
3b11a494 172.IR *result .
b006e083 173In case of error, an error number is returned, and NULL is stored in
3b11a494 174.IR *result .
fea681da
MK
175.SH ERRORS
176.TP
177.BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ... "
178The given
179.I name
180or
181.I gid
182was not found.
183.TP
184.B EINTR
185A signal was caught.
186.TP
187.B EIO
188I/O error.
189.TP
190.B EMFILE
26c32fab 191The per-process limit on the number of open file descriptors has been reached.
fea681da
MK
192.TP
193.B ENFILE
e258766b 194The system-wide limit on the total number of open files has been reached.
fea681da
MK
195.TP
196.B ENOMEM
f2738b39 197.\" not in POSIX
b2133414
MK
198Insufficient memory to allocate
199.I group
200structure.
fea681da
MK
201.\" to allocate the group structure, or to allocate buffers
202.TP
203.B ERANGE
204Insufficient buffer space supplied.
205.SH FILES
206.TP
207.I /etc/group
f2738b39 208local group database file
8c3438a6 209.SH ATTRIBUTES
9209a9c2
MK
210For an explanation of the terms used in this section, see
211.BR attributes (7).
212.TS
213allbox;
ab10d107 214lb lb lb
9209a9c2
MK
215l l l.
216Interface Attribute Value
217T{
ab10d107
MS
218.BR getgrnam ()
219T} Thread safety MT-Unsafe race:grnam locale
220T{
8c3438a6 221.BR getgrgid ()
ab10d107 222T} Thread safety MT-Unsafe race:grgid locale
9209a9c2
MK
223T{
224.BR getgrnam_r (),
ab10d107 225.br
8c3438a6 226.BR getgrgid_r ()
ab10d107 227T} Thread safety MT-Safe locale
9209a9c2 228.TE
47297adb 229.SH CONFORMING TO
f3ee8d98 230POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
fea681da 231.SH NOTES
6497bbd9
MK
232The formulation given above under "RETURN VALUE" is from POSIX.1.
233.\" POSIX.1-2001, POSIX.1-2008
fea681da
MK
234It does not call "not found" an error, hence does not specify what value
235.I errno
c13182ef
MK
236might have in this situation.
237But that makes it impossible to recognize
238errors.
239One might argue that according to POSIX
fea681da 240.I errno
c13182ef
MK
241should be left unchanged if an entry is not found.
242Experiments on various
6497bbd9 243UNIX-like systems show that lots of different values occur in this
a797afac 244situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM, and probably others.
fea681da
MK
245.\" more precisely:
246.\" AIX 5.1 - gives ESRCH
247.\" OSF1 4.0g - gives EWOULDBLOCK
db85058b
MK
248.\" libc, glibc up to version 2.6, Irix 6.5 - give ENOENT
249.\" glibc since version 2.7 - give 0
fea681da
MK
250.\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM
251.\" SunOS 5.8 - gives EBADF
252.\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0
47297adb 253.SH SEE ALSO
fea681da
MK
254.BR endgrent (3),
255.BR fgetgrent (3),
256.BR getgrent (3),
257.BR getpwnam (3),
258.BR setgrent (3),
259.BR group (5)