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