1GETGRNAM(3)                Linux Programmer's Manual               GETGRNAM(3)
2
3
4

NAME

6       getgrnam, getgrnam_r, getgrgid, getgrgid_r - get group file entry
7

SYNOPSIS

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
26               || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
27

DESCRIPTION

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;         /* NULL-terminated array of pointers
44                                          to names of group members */
45           };
46
47       For more information about the fields of this structure, see group(5).
48
49       The getgrnam_r() and getgrgid_r() functions obtain the same information
50       as getgrnam() and getgrgid(), but store the retrieved  group  structure
51       in  the  space  pointed to by grp.  The string fields pointed to by the
52       members of the group structure are stored in the buffer buf of size bu‐
53       flen.  A pointer to the result (in case of success) or NULL (in case no
54       entry was found or an error occurred) is stored in *result.
55
56       The call
57
58           sysconf(_SC_GETGR_R_SIZE_MAX)
59
60       returns either -1, without changing errno, or an initial suggested size
61       for  buf.   (If  this size is too small, the call fails with ERANGE, in
62       which case the caller can retry with a larger buffer.)
63

RETURN VALUE

65       The getgrnam() and getgrgid() functions return a  pointer  to  a  group
66       structure,  or  NULL if the matching entry is not found or an error oc‐
67       curs.  If an error occurs, errno is set appropriately.  If one wants to
68       check errno after the call, it should be set to zero before the 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 re‐
77       turned, and NULL is stored in *result.
78

ERRORS

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; see signal(7).
84
85       EIO    I/O error.
86
87       EMFILE The per-process limit on the number of open file descriptors has
88              been reached.
89
90       ENFILE The system-wide limit on the total number of open files has been
91              reached.
92
93       ENOMEM Insufficient memory to allocate group structure.
94
95       ERANGE Insufficient buffer space supplied.
96

FILES

98       /etc/group
99              local group database file
100

ATTRIBUTES

102       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
103       tributes(7).
104
105       ┌──────────────┬───────────────┬─────────────────────────────┐
106Interface     Attribute     Value                       
107       ├──────────────┼───────────────┼─────────────────────────────┤
108getgrnam()    │ Thread safety │ MT-Unsafe race:grnam locale │
109       ├──────────────┼───────────────┼─────────────────────────────┤
110getgrgid()    │ Thread safety │ MT-Unsafe race:grgid locale │
111       ├──────────────┼───────────────┼─────────────────────────────┤
112getgrnam_r(), │ Thread safety │ MT-Safe locale              │
113getgrgid_r()  │               │                             │
114       └──────────────┴───────────────┴─────────────────────────────┘

CONFORMING TO

116       POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
117

NOTES

119       The  formulation  given above under "RETURN VALUE" is from POSIX.1.  It
120       does not call "not found" an error, hence does not specify  what  value
121       errno  might  have  in this situation.  But that makes it impossible to
122       recognize errors.  One might argue that according to POSIX errno should
123       be  left  unchanged  if  an entry is not found.  Experiments on various
124       UNIX-like systems show that lots of different values occur in this sit‐
125       uation:  0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM, and probably oth‐
126       ers.
127

SEE ALSO

129       endgrent(3),  fgetgrent(3),  getgrent(3),   getpwnam(3),   setgrent(3),
130       group(5)
131

COLOPHON

133       This  page  is  part of release 5.10 of the Linux man-pages project.  A
134       description of the project, information about reporting bugs,  and  the
135       latest     version     of     this    page,    can    be    found    at
136       https://www.kernel.org/doc/man-pages/.
137
138
139
140                                  2017-09-15                       GETGRNAM(3)
Impressum