get the supplementary group IDs of the calling process
#include <sys/types.h> #include <unistd.h> int getgroups( int gidsetsize, gid_t grouplist[] );
The getgroups() function fills the array grouplist with the supplementary group IDs of the calling process. The gidsetsize argument specifies how many elements are in the supplied array. The values of array entries with indices greater than or equal to the returned value are undefined.
The number of supplementary groups IDs. This value is zero if NGROUPS_MAX is zero. A value of -1 indicates an error, and errno is set.
/* * print the supplementary group IDs of * the calling process. */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> void main() { int gidsize; gid_t *grouplist; int i; gidsize = getgroups( 0, NULL ); grouplist = malloc( gidsize * sizeof( gid_t ) ); getgroups( gidsize, grouplist ); for( i = 0; i < gidsize; i++ ) printf( "%d\n", ( int ) grouplist[i] ); exit( 0 ); }
POSIX 1003.1
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes, but modifies errno |
Thread | Yes |