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
53       buflen.   A pointer to the result (in case of success) or NULL (in case
54       no 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
67       occurs.  If an error occurs, errno is set appropriately.  If one  wants
68       to  check  errno  after  the  call, it should be set to zero before the
69       call.
70
71       The return value may point to a static area, and may be overwritten  by
72       subsequent  calls  to  getgrent(3), getgrgid(), or getgrnam().  (Do not
73       pass the returned pointer to free(3).)
74
75       On success, getgrnam_r() and getgrgid_r() return zero, and set  *result
76       to  grp.  If no matching group record was found, these functions return
77       0 and store NULL in *result.  In case of  error,  an  error  number  is
78       returned, and NULL is stored in *result.
79

ERRORS

81       0 or ENOENT or ESRCH or EBADF or EPERM or ...
82              The given name or gid was not found.
83
84       EINTR  A signal was caught; see signal(7).
85
86       EIO    I/O error.
87
88       EMFILE The per-process limit on the number of open file descriptors has
89              been reached.
90
91       ENFILE The system-wide limit on the total number of open files has been
92              reached.
93
94       ENOMEM Insufficient memory to allocate group structure.
95
96       ERANGE Insufficient buffer space supplied.
97

FILES

99       /etc/group
100              local group database file
101

ATTRIBUTES

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

CONFORMING TO

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

NOTES

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

SEE ALSO

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

COLOPHON

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