tzfile.5, tzselect.8: sync from tzdb upstream
[man-pages.git] / man3 / getgrnam.3
blob51ec2d028b83d80a0904eb9df22fe5979cf4fcab
1 '\" t
2 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .\" References consulted:
7 .\"     Linux libc source code
8 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
9 .\"     386BSD man pages
10 .\"
11 .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
12 .\" Modified 2003-11-15 by aeb
13 .\"
14 .TH getgrnam 3 (date) "Linux man-pages (unreleased)"
15 .SH NAME
16 getgrnam, getgrnam_r, getgrgid, getgrgid_r \- get group file entry
17 .SH LIBRARY
18 Standard C library
19 .RI ( libc ", " \-lc )
20 .SH SYNOPSIS
21 .nf
22 .B #include <sys/types.h>
23 .B #include <grp.h>
24 .PP
25 .BI "struct group *getgrnam(const char *" name );
26 .BI "struct group *getgrgid(gid_t " gid );
27 .PP
28 .BI "int getgrnam_r(const char *restrict " name \
29 ", struct group *restrict " grp ,
30 .BI "               char " buf "[restrict ." buflen "], size_t " buflen ,
31 .BI "               struct group **restrict " result );
32 .BI "int getgrgid_r(gid_t " gid ", struct group *restrict " grp ,
33 .BI "               char " buf "[restrict ." buflen "], size_t " buflen ,
34 .BI "               struct group **restrict " result );
35 .fi
36 .PP
37 .RS -4
38 Feature Test Macro Requirements for glibc (see
39 .BR feature_test_macros (7)):
40 .RE
41 .PP
42 .BR getgrnam_r (),
43 .BR getgrgid_r ():
44 .nf
45     _POSIX_C_SOURCE
46         || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
47 .fi
48 .SH DESCRIPTION
49 The
50 .BR getgrnam ()
51 function returns a pointer to a structure containing
52 the broken-out fields of the record in the group database
53 (e.g., the local group file
54 .IR /etc/group ,
55 NIS, and LDAP)
56 that matches the group name
57 .IR name .
58 .PP
59 The
60 .BR getgrgid ()
61 function returns a pointer to a structure containing
62 the broken-out fields of the record in the group database
63 that matches the group ID
64 .IR gid .
65 .PP
66 The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows:
67 .PP
68 .in +4n
69 .EX
70 struct group {
71     char   *gr_name;        /* group name */
72     char   *gr_passwd;      /* group password */
73     gid_t   gr_gid;         /* group ID */
74     char  **gr_mem;         /* NULL\-terminated array of pointers
75                                to names of group members */
77 .EE
78 .in
79 .PP
80 For more information about the fields of this structure, see
81 .BR group (5).
82 .PP
83 The
84 .BR getgrnam_r ()
85 and
86 .BR getgrgid_r ()
87 functions obtain the same information as
88 .BR getgrnam ()
89 and
90 .BR getgrgid (),
91 but store the retrieved
92 .I group
93 structure
94 in the space pointed to by
95 .IR grp .
96 The string fields pointed to by the members of the
97 .I group
98 structure are stored in the buffer
99 .I buf
100 of size
101 .IR buflen .
102 A pointer to the result (in case of success) or NULL (in case no entry
103 was found or an error occurred) is stored in
104 .IR *result .
106 The call
108 .in +4n
110 sysconf(_SC_GETGR_R_SIZE_MAX)
114 returns either \-1, without changing
115 .IR errno ,
116 or an initial suggested size for
117 .IR buf .
118 (If this size is too small,
119 the call fails with
120 .BR ERANGE ,
121 in which case the caller can retry with a larger buffer.)
122 .SH RETURN VALUE
124 .BR getgrnam ()
126 .BR getgrgid ()
127 functions return a pointer to a
128 .I group
129 structure, or NULL if the matching entry
130 is not found or an error occurs.
131 If an error occurs,
132 .I errno
133 is set to indicate the error.
134 If one wants to check
135 .I errno
136 after the call, it should be set to zero before the call.
138 The return value may point to a static area, and may be overwritten
139 by subsequent calls to
140 .BR getgrent (3),
141 .BR getgrgid (),
143 .BR getgrnam ().
144 (Do not pass the returned pointer to
145 .BR free (3).)
147 On success,
148 .BR getgrnam_r ()
150 .BR getgrgid_r ()
151 return zero, and set
152 .I *result
154 .IR grp .
155 If no matching group record was found,
156 these functions return 0 and store NULL in
157 .IR *result .
158 In case of error, an error number is returned, and NULL is stored in
159 .IR *result .
160 .SH ERRORS
162 .BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ..."
163 The given
164 .I name
166 .I gid
167 was not found.
169 .B EINTR
170 A signal was caught; see
171 .BR signal (7).
173 .B EIO
174 I/O error.
176 .B EMFILE
177 The per-process limit on the number of open file descriptors has been reached.
179 .B ENFILE
180 The system-wide limit on the total number of open files has been reached.
182 .B ENOMEM
183 .\" not in POSIX
184 Insufficient memory to allocate
185 .I group
186 structure.
187 .\" to allocate the group structure, or to allocate buffers
189 .B ERANGE
190 Insufficient buffer space supplied.
191 .SH FILES
193 .I /etc/group
194 local group database file
195 .SH ATTRIBUTES
196 For an explanation of the terms used in this section, see
197 .BR attributes (7).
198 .ad l
201 allbox;
202 lb lb lbx
203 l l l.
204 Interface       Attribute       Value
206 .BR getgrnam ()
207 T}      Thread safety   T{
208 MT-Unsafe race:grnam locale
211 .BR getgrgid ()
212 T}      Thread safety   T{
213 MT-Unsafe race:grgid locale
216 .BR getgrnam_r (),
217 .BR getgrgid_r ()
218 T}      Thread safety   MT-Safe locale
222 .sp 1
223 .SH STANDARDS
224 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
225 .SH NOTES
226 The formulation given above under "RETURN VALUE" is from POSIX.1.
227 .\" POSIX.1-2001, POSIX.1-2008
228 It does not call "not found" an error, hence does not specify what value
229 .I errno
230 might have in this situation.
231 But that makes it impossible to recognize
232 errors.
233 One might argue that according to POSIX
234 .I errno
235 should be left unchanged if an entry is not found.
236 Experiments on various
237 UNIX-like systems show that lots of different values occur in this
238 situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM, and probably others.
239 .\" more precisely:
240 .\" AIX 5.1 - gives ESRCH
241 .\" OSF1 4.0g - gives EWOULDBLOCK
242 .\" libc, glibc up to glibc 2.6, Irix 6.5 - give ENOENT
243 .\" since glibc 2.7 - give 0
244 .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM
245 .\" SunOS 5.8 - gives EBADF
246 .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0
247 .SH SEE ALSO
248 .BR endgrent (3),
249 .BR fgetgrent (3),
250 .BR getgrent (3),
251 .BR getpwnam (3),
252 .BR setgrent (3),
253 .BR group (5)