Get the supplementary group IDs of the calling process
#include <unistd.h> int getgroups( int gidsetsize, gid_t grouplist[] );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The getgroups() function fills the array grouplist with the supplementary group IDs of the calling process. The maximum number of group IDs is given by sysconf(_SC_NGROUPS_MAX). The values of array entries with indices greater than or equal to the returned value are undefined.
If gidsetsize is 0, the function returns the number of group IDs, without modifying the grouplist array.
The number of supplementary groups IDs, or -1 if an error occurred (errno is set).
/* * Print the supplementary group IDs of * the calling process. */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main( void ) { 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] ); return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |