1GETGRNAM(3) Linux Programmer's Manual GETGRNAM(3)
2
3
4
6 getgrnam, getgrnam_r, getgrgid, getgrgid_r - get group file entry
7
9 #include <sys/types.h>
10 #include <grp.h>
11
12 struct group *getgrnam(const char *name);
13
14 struct group *getgrgid(gid_t gid);
15
16 int getgrnam_r(const char *name, struct group *grp,
17 char *buf, size_t buflen, struct group **result);
18
19 int getgrgid_r(gid_t gid, struct group *grp,
20 char *buf, size_t buflen, struct group **result);
21
22 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
23
24 getgrnam_r(), getgrgid_r():
25 _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
26 _SVID_SOURCE || _POSIX_SOURCE
27
29 The getgrnam() function returns a pointer to a structure containing the
30 broken-out fields of the record in the group database (e.g., the local
31 group file /etc/group, NIS, and LDAP) that matches the group name name.
32
33 The getgrgid() function returns a pointer to a structure containing the
34 broken-out fields of the record in the group database that matches the
35 group ID gid.
36
37 The group structure is defined in <grp.h> as follows:
38
39 struct group {
40 char *gr_name; /* group name */
41 char *gr_passwd; /* group password */
42 gid_t gr_gid; /* group ID */
43 char **gr_mem; /* group members */
44 };
45
46 For more information about the fields of this structure, see group(5).
47
48 The getgrnam_r() and getgrgid_r() functions obtain the same information
49 as getgrnam() and getgrgid(), but store the retrieved group structure
50 in the space pointed to by grp. The string fields pointed to by the
51 members of the group structure are stored in the buffer buf of size
52 buflen. A pointer to the result (in case of success) or NULL (in case
53 no entry was found or an error occurred) is stored in *result.
54
55 The call
56
57 sysconf(_SC_GETGR_R_SIZE_MAX)
58
59 returns either -1, without changing errno, or an initial suggested size
60 for buf. (If this size is too small, the call fails with ERANGE, in
61 which case the caller can retry with a larger buffer.)
62
64 The getgrnam() and getgrgid() functions return a pointer to a group
65 structure, or NULL if the matching entry is not found or an error
66 occurs. If an error occurs, errno is set appropriately. If one wants
67 to check errno after the call, it should be set to zero before the
68 call.
69
70 The return value may point to a static area, and may be overwritten by
71 subsequent calls to getgrent(3), getgrgid(), or getgrnam(). (Do not
72 pass the returned pointer to free(3).)
73
74 On success, getgrnam_r() and getgrgid_r() return zero, and set *result
75 to grp. If no matching group record was found, these functions return
76 0 and store NULL in *result. In case of error, an error number is
77 returned, and NULL is stored in *result.
78
80 0 or ENOENT or ESRCH or EBADF or EPERM or ...
81 The given name or gid was not found.
82
83 EINTR A signal was caught.
84
85 EIO I/O error.
86
87 EMFILE The maximum number (OPEN_MAX) of files was open already in the
88 calling process.
89
90 ENFILE The maximum number of files was open already in the system.
91
92 ENOMEM Insufficient memory to allocate group structure.
93
94 ERANGE Insufficient buffer space supplied.
95
97 /etc/group
98 local group database file
99
101 Multithreading (see pthreads(7))
102 The getgrnam() and getgrgid() functions are not thread-safe.
103
104 The getgrnam_r() and getgrgid_r() functions are thread-safe.
105
107 SVr4, 4.3BSD, POSIX.1-2001.
108
110 The formulation given above under "RETURN VALUE" is from POSIX.1-2001.
111 It does not call "not found" an error, hence does not specify what
112 value errno might have in this situation. But that makes it impossible
113 to recognize errors. One might argue that according to POSIX errno
114 should be left unchanged if an entry is not found. Experiments on var‐
115 ious UNIX-like systems shows that lots of different values occur in
116 this situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and proba‐
117 bly others.
118
120 endgrent(3), fgetgrent(3), getgrent(3), getpwnam(3), setgrent(3),
121 group(5)
122
124 This page is part of release 3.53 of the Linux man-pages project. A
125 description of the project, and information about reporting bugs, can
126 be found at http://www.kernel.org/doc/man-pages/.
127
128
129
130 2013-07-22 GETGRNAM(3)