Updated: April 19, 2023 |
Get information about the group with a given ID
#include <sys/types.h> #include <grp.h> struct group* getgrgid( gid_t gid );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The getgrgid() function lets a process gain more knowledge about group gid. This function uses a static buffer that's overwritten by each call.
A pointer to an object of type struct group containing an entry from the group database with a matching gid. On 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> int main( void ) { struct group* g; char** p; if( ( g = getgrgid( getgid() ) ) == NULL ) { fprintf( stderr, "getgrgid: NULL pointer\n" ); return( EXIT_FAILURE ); } printf( "group name:%s\n", g->gr_name ); for( p = g->gr_mem; *p != NULL; p++ ) { printf( "\t%s\n", *p ); } return( EXIT_SUCCESS ); }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | No |