#include <sys/types.h> #include <unistd.h> int getgroups(int listSize, gid_t *groupList);
getgroups
stores the supplementary group IDs of the calling
process in an array.
listSize
groupList
Note:
groupList
is declared as gid_t *groupList
so that NULL may be passed to groupList
when listSize
is 0
. This could not be done if groupList
was declared as
an array.
getgroups
returns the number of supplementary group IDs
in groupList
. This value is always less than or
equal to the value
of NGROUPS_MAX
defined in <limits.h>
. If listSize
is 0
,
getgroups
returns the total number of supplementary group IDs
and does not store the group IDs in an array. getgroups
returns a -1
if unsuccessful.
getgroups
to determine supplementary group IDs.
Note:
You must specify the posix
option when compiling this example.
#include <sys/types.h> #include <unistd.h> #include <stdio.h> #include <limits.h> main() { gid_t groupIDs[NGROUPS_MAX]; int i, count; if ((count = getgroups(NGROUPS_MAX, groupIDs)) == -1) perror("getgroups error"); else for (i = 0; i < count; i++) printf("Group ID %d = %dn", i + 1, (int) groupIDs[i]); }
getgroupsbyname
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.