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

NAME

6       getgroups - get supplementary group IDs
7

SYNOPSIS

9       #include <unistd.h>
10
11       int getgroups(int gidsetsize, gid_t grouplist[]);
12
13

DESCRIPTION

15       The  getgroups()  function  shall  fill in the array grouplist with the
16       current supplementary group IDs of the calling process. It is implemen‐
17       tation-defined  whether getgroups() also returns the effective group ID
18       in the grouplist array.
19
20       The gidsetsize argument specifies the number of elements in  the  array
21       grouplist.  The actual number of group IDs stored in the array shall be
22       returned. The values of array entries  with  indices  greater  than  or
23       equal to the value returned are undefined.
24
25       If  gidsetsize  is  0, getgroups() shall return the number of group IDs
26       that it would otherwise return without modifying the array  pointed  to
27       by grouplist.
28
29       If  the  effective group ID of the process is returned with the supple‐
30       mentary group IDs, the value returned shall always be greater  than  or
31       equal to one and less than or equal to the value of {NGROUPS_MAX}+1.
32

RETURN VALUE

34       Upon successful completion, the number of supplementary group IDs shall
35       be returned. A return value of -1 indicates failure and errno shall  be
36       set to indicate the error.
37

ERRORS

39       The getgroups() function shall fail if:
40
41       EINVAL The  gidsetsize argument is non-zero and less than the number of
42              group IDs that would have been returned.
43
44
45       The following sections are informative.
46

EXAMPLES

48   Getting the Supplementary Group IDs of the Calling Process
49       The following example places the current supplementary group IDs of the
50       calling process into the group array.
51
52
53              #include <sys/types.h>
54              #include <unistd.h>
55              ...
56              gid_t *group;
57              int nogroups;
58              long ngroups_max;
59
60
61              ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1;
62              group = (gid_t *)malloc(ngroups_max *sizeof(gid_t));
63
64
65              ngroups = getgroups(ngroups_max, group);
66

APPLICATION USAGE

68       None.
69

RATIONALE

71       The  related  function setgroups() is a privileged operation and there‐
72       fore is not covered by this volume of IEEE Std 1003.1-2001.
73
74       As implied by the definition of  supplementary  groups,  the  effective
75       group  ID  may appear in the array returned by getgroups() or it may be
76       returned only by getegid(). Duplication may exist, but the  application
77       needs  to  call getegid() to be sure of getting all of the information.
78       Various implementation variations and  administrative  sequences  cause
79       the  set  of  groups  appearing in the result of getgroups() to vary in
80       order and as to whether the effective group ID is included,  even  when
81       the  set  of  groups  is the same (in the mathematical sense of "set").
82       (The history of a process and its parents could affect the  details  of
83       the result.)
84
85       Application writers should note that {NGROUPS_MAX} is not necessarily a
86       constant on all implementations.
87

FUTURE DIRECTIONS

89       None.
90

SEE ALSO

92       getegid()   ,   setgid()   ,   the   Base   Definitions    volume    of
93       IEEE Std 1003.1-2001, <sys/types.h>, <unistd.h>
94
96       Portions  of  this text are reprinted and reproduced in electronic form
97       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
98       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
99       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
100       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
101       event of any discrepancy between this version and the original IEEE and
102       The  Open Group Standard, the original IEEE and The Open Group Standard
103       is the referee document. The original Standard can be  obtained  online
104       at http://www.opengroup.org/unix/online.html .
105
106
107
108IEEE/The Open Group                  2003                         GETGROUPS(P)
Impressum