get information about the group with a given ID
#include <sys/types.h> #include <grp.h> struct group *getgrgid( gid_t gid );
The getgrgid() function allows a process to gain more knowledge about group gid. This function uses a static buffer that is overwritten by each call.
A pointer to an object of type struct group containing an entry from the group database with a matching gid. Upon error or failure to find an entry with a matching gid, a NULL pointer is returned.
/* * print a list of all users in your group */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <grp.h> void main() { struct group *g; char **p; if( ( g = getgrgid( getgid() ) ) == NULL ) { fprintf( stderr, "getgrgid: NULL pointer\n" ); exit( EXIT_FAILURE ); } printf( "group name:%s\n", g->gr_name ); for( p = g->gr_mem; *p != NULL; p++ ) { printf( "\t%s\n", *p ); } exit( EXIT_SUCCESS ); }
POSIX 1003.1
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |