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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       getgrgid, getgrgid_r - get group database entry for a group ID
13

SYNOPSIS

15       #include <grp.h>
16
17       struct group *getgrgid(gid_t gid);
18
19
20       int getgrgid_r(gid_t gid, struct group *grp, char *buffer,
21              size_t bufsize, struct group **result);
22
23

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

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

APPLICATION USAGE

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

RATIONALE

107       None.
108

FUTURE DIRECTIONS

110       None.
111

SEE ALSO

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