1GETGRGID(P)                POSIX Programmer's Manual               GETGRGID(P)
2
3
4

NAME

6       getgrgid, getgrgid_r - get group database entry for a group ID
7

SYNOPSIS

9       #include <grp.h>
10
11       struct group *getgrgid(gid_t gid);
12
13
14       int getgrgid_r(gid_t gid, struct group *grp, char *buffer,
15              size_t bufsize, struct group **result);
16
17

DESCRIPTION

19       The  getgrgid()  function  shall search the group database for an entry
20       with a matching gid.
21
22       The getgrgid() function need not be reentrant. A function that  is  not
23       required to be reentrant is not required to be thread-safe.
24
25       The  getgrgid_r()  function shall update the group structure pointed to
26       by grp and store a pointer to that structure at the location pointed to
27       by result. The structure shall contain an entry from the group database
28       with a matching gid. Storage referenced by the group structure is allo‐
29       cated from the memory provided with the buffer parameter, which is buf‐
30       size bytes in size. The maximum size needed  for  this  buffer  can  be
31       determined  with the {_SC_GETGR_R_SIZE_MAX} sysconf() parameter. A NULL
32       pointer shall be returned at the location pointed to by result on error
33       or if the requested entry is not found.
34

RETURN VALUE

36       Upon  successful  completion,  getgrgid()  shall  return a pointer to a
37       struct group with the structure defined  in  <grp.h>  with  a  matching
38       entry  if  one  is  found.  The getgrgid() function shall return a null
39       pointer if either the requested  entry  was  not  found,  or  an  error
40       occurred. On error, errno shall be set to indicate the error.
41
42       The  return  value may point to a static area which is overwritten by a
43       subsequent call to getgrent(), getgrgid(), or getgrnam().
44
45       If successful, the getgrgid_r() function shall return zero;  otherwise,
46       an error number shall be returned to indicate the error.
47

ERRORS

49       The getgrgid() and getgrgid_r() functions may fail if:
50
51       EIO    An I/O error has occurred.
52
53       EINTR  A signal was caught during getgrgid().
54
55       EMFILE {OPEN_MAX}  file  descriptors  are currently open in the calling
56              process.
57
58       ENFILE The maximum allowable number of files is currently open  in  the
59              system.
60
61
62       The getgrgid_r() function may fail if:
63
64       ERANGE Insufficient storage was supplied via buffer and bufsize to con‐
65              tain the data to be referenced by the resulting group structure.
66
67
68       The following sections are informative.
69

EXAMPLES

71   Finding an Entry in the Group Database
72       The following example uses getgrgid() to search the group database  for
73       a  group ID that was previously stored in a stat structure, then prints
74       out the group name if it is found.  If the group is not found, the pro‐
75       gram prints the numeric value of the group for the entry.
76
77
78              #include <sys/types.h>
79              #include <grp.h>
80              #include <stdio.h>
81              ...
82              struct stat statbuf;
83              struct group *grp;
84              ...
85              if ((grp = getgrgid(statbuf.st_gid)) != NULL)
86                  printf(" %-8.8s", grp->gr_name);
87              else
88                  printf(" %-8d", statbuf.st_gid);
89              ...
90

APPLICATION USAGE

92       Applications  wishing to check for error situations should set errno to
93       0 before calling getgrgid(). If  errno  is  set  on  return,  an  error
94       occurred.
95
96       The  getgrgid_r()  function is thread-safe and shall return values in a
97       user-supplied buffer instead of possibly using a static data area  that
98       may be overwritten by each call.
99

RATIONALE

101       None.
102

FUTURE DIRECTIONS

104       None.
105

SEE ALSO

107       endgrent()   ,   getgrnam()   ,   the   Base   Definitions   volume  of
108       IEEE Std 1003.1-2001, <grp.h>, <limits.h>, <sys/types.h>
109
111       Portions of this text are reprinted and reproduced in  electronic  form
112       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
113       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
114       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
115       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
116       event of any discrepancy between this version and the original IEEE and
117       The Open Group Standard, the original IEEE and The Open Group  Standard
118       is  the  referee document. The original Standard can be obtained online
119       at http://www.opengroup.org/unix/online.html .
120
121
122
123IEEE/The Open Group                  2003                          GETGRGID(P)
Impressum