]>
Commit | Line | Data |
---|---|---|
a1eaacb1 | 1 | '\" t |
fea681da MK |
2 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
3 | .\" | |
5fbde956 | 4 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da MK |
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 | .\" | |
4c1c5274 | 14 | .TH getgrnam 3 (date) "Linux man-pages (unreleased)" |
fea681da MK |
15 | .SH NAME |
16 | getgrnam, getgrnam_r, getgrgid, getgrgid_r \- get group file entry | |
42009080 AC |
17 | .SH LIBRARY |
18 | Standard C library | |
19 | .RI ( libc ", " \-lc ) | |
fea681da MK |
20 | .SH SYNOPSIS |
21 | .nf | |
22 | .B #include <sys/types.h> | |
23 | .B #include <grp.h> | |
68e4db0a | 24 | .PP |
fea681da | 25 | .BI "struct group *getgrnam(const char *" name ); |
fea681da | 26 | .BI "struct group *getgrgid(gid_t " gid ); |
68e4db0a | 27 | .PP |
2bebee6f AC |
28 | .BI "int getgrnam_r(const char *restrict " name \ |
29 | ", struct group *restrict " grp , | |
1eed67e7 | 30 | .BI " char " buf "[restrict ." buflen "], size_t " buflen , |
2bebee6f AC |
31 | .BI " struct group **restrict " result ); |
32 | .BI "int getgrgid_r(gid_t " gid ", struct group *restrict " grp , | |
1eed67e7 | 33 | .BI " char " buf "[restrict ." buflen "], size_t " buflen , |
2bebee6f | 34 | .BI " struct group **restrict " result ); |
fea681da | 35 | .fi |
68e4db0a | 36 | .PP |
d39ad78f | 37 | .RS -4 |
0f200f07 MK |
38 | Feature Test Macro Requirements for glibc (see |
39 | .BR feature_test_macros (7)): | |
d39ad78f | 40 | .RE |
68e4db0a | 41 | .PP |
0f200f07 MK |
42 | .BR getgrnam_r (), |
43 | .BR getgrgid_r (): | |
9d2adbae MK |
44 | .nf |
45 | _POSIX_C_SOURCE | |
75c018a1 | 46 | || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE |
9d2adbae | 47 | .fi |
fea681da MK |
48 | .SH DESCRIPTION |
49 | The | |
63aa9df0 | 50 | .BR getgrnam () |
fea681da | 51 | function returns a pointer to a structure containing |
f936cf26 | 52 | the broken-out fields of the record in the group database |
c13182ef | 53 | (e.g., the local group file |
f2738b39 MK |
54 | .IR /etc/group , |
55 | NIS, and LDAP) | |
f936cf26 | 56 | that matches the group name |
fea681da MK |
57 | .IR name . |
58 | .PP | |
59 | The | |
63aa9df0 | 60 | .BR getgrgid () |
fea681da | 61 | function returns a pointer to a structure containing |
f2738b39 | 62 | the broken-out fields of the record in the group database |
f936cf26 | 63 | that matches the group ID |
fea681da MK |
64 | .IR gid . |
65 | .PP | |
b39f3e05 | 66 | The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows: |
51f5698d | 67 | .PP |
b39f3e05 | 68 | .in +4n |
b8302363 | 69 | .EX |
b39f3e05 | 70 | struct group { |
5e333b1b MK |
71 | char *gr_name; /* group name */ |
72 | char *gr_passwd; /* group password */ | |
73 | gid_t gr_gid; /* group ID */ | |
d064d41a | 74 | char **gr_mem; /* NULL\-terminated array of pointers |
b7800b44 | 75 | to names of group members */ |
b39f3e05 | 76 | }; |
b8302363 | 77 | .EE |
b39f3e05 MK |
78 | .in |
79 | .PP | |
80 | For more information about the fields of this structure, see | |
81 | .BR group (5). | |
82 | .PP | |
fea681da | 83 | The |
63aa9df0 | 84 | .BR getgrnam_r () |
fea681da | 85 | and |
63aa9df0 | 86 | .BR getgrgid_r () |
b39f3e05 MK |
87 | functions obtain the same information as |
88 | .BR getgrnam () | |
89 | and | |
90 | .BR getgrgid (), | |
91 | but store the retrieved | |
f2738b39 MK |
92 | .I group |
93 | structure | |
fea681da | 94 | in the space pointed to by |
3b11a494 | 95 | .IR grp . |
b39f3e05 | 96 | The string fields pointed to by the members of the |
f2738b39 | 97 | .I group |
b39f3e05 | 98 | structure are stored in the buffer |
fea681da MK |
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 | |
3b11a494 | 104 | .IR *result . |
fea681da | 105 | .PP |
f7bae7f8 | 106 | The call |
847e0d88 | 107 | .PP |
1ae6b2c7 AC |
108 | .in +4n |
109 | .EX | |
110 | sysconf(_SC_GETGR_R_SIZE_MAX) | |
111 | .EE | |
112 | .in | |
847e0d88 | 113 | .PP |
f7bae7f8 MK |
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.) | |
47297adb | 122 | .SH RETURN VALUE |
60a90ecd MK |
123 | The |
124 | .BR getgrnam () | |
125 | and | |
126 | .BR getgrgid () | |
127 | functions return a pointer to a | |
f2738b39 MK |
128 | .I group |
129 | structure, or NULL if the matching entry | |
130 | is not found or an error occurs. | |
131 | If an error occurs, | |
fea681da | 132 | .I errno |
f6a4078b | 133 | is set to indicate the error. |
f2738b39 | 134 | If one wants to check |
fea681da MK |
135 | .I errno |
136 | after the call, it should be set to zero before the call. | |
dd3568a1 | 137 | .PP |
c34a8ff7 | 138 | The return value may point to a static area, and may be overwritten |
fea681da | 139 | by subsequent calls to |
91fe9d5c | 140 | .BR getgrent (3), |
63aa9df0 | 141 | .BR getgrgid (), |
fea681da | 142 | or |
63aa9df0 | 143 | .BR getgrnam (). |
48e4cfa0 MK |
144 | (Do not pass the returned pointer to |
145 | .BR free (3).) | |
dd3568a1 | 146 | .PP |
2ac1e1d3 | 147 | On success, |
60a90ecd MK |
148 | .BR getgrnam_r () |
149 | and | |
150 | .BR getgrgid_r () | |
b006e083 | 151 | return zero, and set |
1ae6b2c7 | 152 | .I *result |
b006e083 | 153 | to |
3b11a494 | 154 | .IR grp . |
b006e083 MK |
155 | If no matching group record was found, |
156 | these functions return 0 and store NULL in | |
3b11a494 | 157 | .IR *result . |
b006e083 | 158 | In case of error, an error number is returned, and NULL is stored in |
3b11a494 | 159 | .IR *result . |
fea681da MK |
160 | .SH ERRORS |
161 | .TP | |
be1db87e | 162 | .BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ..." |
fea681da MK |
163 | The given |
164 | .I name | |
165 | or | |
166 | .I gid | |
167 | was not found. | |
168 | .TP | |
169 | .B EINTR | |
bb14af39 MK |
170 | A signal was caught; see |
171 | .BR signal (7). | |
fea681da MK |
172 | .TP |
173 | .B EIO | |
174 | I/O error. | |
175 | .TP | |
176 | .B EMFILE | |
26c32fab | 177 | The per-process limit on the number of open file descriptors has been reached. |
fea681da MK |
178 | .TP |
179 | .B ENFILE | |
e258766b | 180 | The system-wide limit on the total number of open files has been reached. |
fea681da MK |
181 | .TP |
182 | .B ENOMEM | |
f2738b39 | 183 | .\" not in POSIX |
b2133414 MK |
184 | Insufficient memory to allocate |
185 | .I group | |
186 | structure. | |
fea681da MK |
187 | .\" to allocate the group structure, or to allocate buffers |
188 | .TP | |
189 | .B ERANGE | |
190 | Insufficient buffer space supplied. | |
191 | .SH FILES | |
192 | .TP | |
193 | .I /etc/group | |
f2738b39 | 194 | local group database file |
8c3438a6 | 195 | .SH ATTRIBUTES |
9209a9c2 MK |
196 | For an explanation of the terms used in this section, see |
197 | .BR attributes (7). | |
198 | .TS | |
199 | allbox; | |
b32feea5 | 200 | lb lb lbx |
9209a9c2 MK |
201 | l l l. |
202 | Interface Attribute Value | |
203 | T{ | |
9e54434e BR |
204 | .na |
205 | .nh | |
ab10d107 | 206 | .BR getgrnam () |
b32feea5 | 207 | T} Thread safety T{ |
9e54434e BR |
208 | .na |
209 | .nh | |
b32feea5 MK |
210 | MT-Unsafe race:grnam locale |
211 | T} | |
ab10d107 | 212 | T{ |
9e54434e BR |
213 | .na |
214 | .nh | |
8c3438a6 | 215 | .BR getgrgid () |
b32feea5 | 216 | T} Thread safety T{ |
9e54434e BR |
217 | .na |
218 | .nh | |
b32feea5 MK |
219 | MT-Unsafe race:grgid locale |
220 | T} | |
9209a9c2 | 221 | T{ |
9e54434e BR |
222 | .na |
223 | .nh | |
9209a9c2 | 224 | .BR getgrnam_r (), |
8c3438a6 | 225 | .BR getgrgid_r () |
ab10d107 | 226 | T} Thread safety MT-Safe locale |
9209a9c2 | 227 | .TE |
c466875e | 228 | .sp 1 |
4131356c | 229 | .SH VERSIONS |
6497bbd9 MK |
230 | The formulation given above under "RETURN VALUE" is from POSIX.1. |
231 | .\" POSIX.1-2001, POSIX.1-2008 | |
fea681da MK |
232 | It does not call "not found" an error, hence does not specify what value |
233 | .I errno | |
c13182ef MK |
234 | might have in this situation. |
235 | But that makes it impossible to recognize | |
236 | errors. | |
237 | One might argue that according to POSIX | |
fea681da | 238 | .I errno |
c13182ef MK |
239 | should be left unchanged if an entry is not found. |
240 | Experiments on various | |
6497bbd9 | 241 | UNIX-like systems show that lots of different values occur in this |
a797afac | 242 | situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM, and probably others. |
fea681da MK |
243 | .\" more precisely: |
244 | .\" AIX 5.1 - gives ESRCH | |
245 | .\" OSF1 4.0g - gives EWOULDBLOCK | |
b324e17d AC |
246 | .\" libc, glibc up to glibc 2.6, Irix 6.5 - give ENOENT |
247 | .\" since glibc 2.7 - give 0 | |
fea681da MK |
248 | .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM |
249 | .\" SunOS 5.8 - gives EBADF | |
250 | .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0 | |
4131356c AC |
251 | .SH STANDARDS |
252 | POSIX.1-2008. | |
253 | .SH HISTORY | |
254 | POSIX.1-2001, SVr4, 4.3BSD. | |
47297adb | 255 | .SH SEE ALSO |
fea681da MK |
256 | .BR endgrent (3), |
257 | .BR fgetgrent (3), | |
258 | .BR getgrent (3), | |
259 | .BR getpwnam (3), | |
260 | .BR setgrent (3), | |
261 | .BR group (5) |