1GETGROUPS(3P) POSIX Programmer's Manual GETGROUPS(3P)
2
3
4
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
12 getgroups - get supplementary group IDs
13
15 #include <unistd.h>
16
17 int getgroups(int gidsetsize, gid_t grouplist[]);
18
19
21 The getgroups() function shall fill in the array grouplist with the
22 current supplementary group IDs of the calling process. It is implemen‐
23 tation-defined whether getgroups() also returns the effective group ID
24 in the grouplist array.
25
26 The gidsetsize argument specifies the number of elements in the array
27 grouplist. The actual number of group IDs stored in the array shall be
28 returned. The values of array entries with indices greater than or
29 equal to the value returned are undefined.
30
31 If gidsetsize is 0, getgroups() shall return the number of group IDs
32 that it would otherwise return without modifying the array pointed to
33 by grouplist.
34
35 If the effective group ID of the process is returned with the supple‐
36 mentary group IDs, the value returned shall always be greater than or
37 equal to one and less than or equal to the value of {NGROUPS_MAX}+1.
38
40 Upon successful completion, the number of supplementary group IDs shall
41 be returned. A return value of -1 indicates failure and errno shall be
42 set to indicate the error.
43
45 The getgroups() function shall fail if:
46
47 EINVAL The gidsetsize argument is non-zero and less than the number of
48 group IDs that would have been returned.
49
50
51 The following sections are informative.
52
54 Getting the Supplementary Group IDs of the Calling Process
55 The following example places the current supplementary group IDs of the
56 calling process into the group array.
57
58
59 #include <sys/types.h>
60 #include <unistd.h>
61 ...
62 gid_t *group;
63 int nogroups;
64 long ngroups_max;
65
66
67 ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1;
68 group = (gid_t *)malloc(ngroups_max *sizeof(gid_t));
69
70
71 ngroups = getgroups(ngroups_max, group);
72
74 None.
75
77 The related function setgroups() is a privileged operation and there‐
78 fore is not covered by this volume of IEEE Std 1003.1-2001.
79
80 As implied by the definition of supplementary groups, the effective
81 group ID may appear in the array returned by getgroups() or it may be
82 returned only by getegid(). Duplication may exist, but the application
83 needs to call getegid() to be sure of getting all of the information.
84 Various implementation variations and administrative sequences cause
85 the set of groups appearing in the result of getgroups() to vary in
86 order and as to whether the effective group ID is included, even when
87 the set of groups is the same (in the mathematical sense of "set").
88 (The history of a process and its parents could affect the details of
89 the result.)
90
91 Application writers should note that {NGROUPS_MAX} is not necessarily a
92 constant on all implementations.
93
95 None.
96
98 getegid(), setgid(), the Base Definitions volume of
99 IEEE Std 1003.1-2001, <sys/types.h>, <unistd.h>
100
102 Portions of this text are reprinted and reproduced in electronic form
103 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
104 -- Portable Operating System Interface (POSIX), The Open Group Base
105 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
106 Electrical and Electronics Engineers, Inc and The Open Group. In the
107 event of any discrepancy between this version and the original IEEE and
108 The Open Group Standard, the original IEEE and The Open Group Standard
109 is the referee document. The original Standard can be obtained online
110 at http://www.opengroup.org/unix/online.html .
111
112
113
114IEEE/The Open Group 2003 GETGROUPS(3P)