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(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE ||
25       _BSD_SOURCE || _SVID_SOURCE || _POSIX_SOURCE
26

DESCRIPTION

28       The getgrnam() function returns a pointer to a structure containing the
29       broken-out  fields of the record in the group database (e.g., the local
30       group file /etc/group, NIS, and LDAP) that matches the group name name.
31
32       The getgrgid() function returns a pointer to a structure containing the
33       broken-out  fields of the record in the group database that matches the
34       group ID gid.
35
36       The getgrnam_r() and getgrgid_r() functions obtain  the  same  informa‐
37       tion,  but  store the retrieved group structure in the space pointed to
38       by grp.  This group structure contains pointers to strings,  and  these
39       strings  are stored in the buffer buf of size buflen.  A pointer to the
40       result (in case of success) or NULL (in case no entry was found  or  an
41       error occurred) is stored in *result.
42
43       The group structure is defined in <grp.h> as follows:
44
45           struct group {
46               char   *gr_name;       /* group name */
47               char   *gr_passwd;     /* group password */
48               gid_t   gr_gid;        /* group ID */
49               char  **gr_mem;        /* group members */
50           };
51
52       The  maximum needed size for buf can be found using sysconf(3) with the
53       argument _SC_GETGR_R_SIZE_MAX.
54

RETURN VALUE

56       The getgrnam() and getgrgid() functions return a  pointer  to  a  group
57       structure,  or  NULL  if  the  matching  entry is not found or an error
58       occurs.  If an error occurs, errno is set appropriately.  If one  wants
59       to  check  errno  after  the  call, it should be set to zero before the
60       call.
61
62       The return value may point to a static area, and may be overwritten  by
63       subsequent  calls  to  getgrent(3), getgrgid(), or getgrnam().  (Do not
64       pass the returned pointer to free(3).)
65
66       On success, getgrnam_r() and getgrgid_r() return zero, and set  *result
67       to  grp.  If no matching group record was found, these functions return
68       0 and store NULL in *result.  In case of  error,  an  error  number  is
69       returned, and NULL is stored in *result.
70

ERRORS

72       0 or ENOENT or ESRCH or EBADF or EPERM or ...
73              The given name or gid was not found.
74
75       EINTR  A signal was caught.
76
77       EIO    I/O error.
78
79       EMFILE The  maximum  number (OPEN_MAX) of files was open already in the
80              calling process.
81
82       ENFILE The maximum number of files was open already in the system.
83
84       ENOMEM Insufficient memory to allocate group structure.
85
86       ERANGE Insufficient buffer space supplied.
87

FILES

89       /etc/group
90              local group database file
91

CONFORMING TO

93       SVr4, 4.3BSD, POSIX.1-2001.
94

NOTES

96       The formulation given above under "RETURN VALUE" is from  POSIX.1-2001.
97       It  does  not  call  "not  found" an error, hence does not specify what
98       value errno might have in this situation.  But that makes it impossible
99       to  recognize  errors.   One  might argue that according to POSIX errno
100       should be left unchanged if an entry is not found.  Experiments on var‐
101       ious  Unix-like  systems  shows  that lots of different values occur in
102       this situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and  proba‐
103       bly others.
104

SEE ALSO

106       endgrent(3),   fgetgrent(3),   getgrent(3),  getpwnam(3),  setgrent(3),
107       group(5)
108

COLOPHON

110       This page is part of release 3.22 of the Linux  man-pages  project.   A
111       description  of  the project, and information about reporting bugs, can
112       be found at http://www.kernel.org/doc/man-pages/.
113
114
115
116                                  2009-03-30                       GETGRNAM(3)
Impressum