Get information about the group with a given name
#include <sys/types.h> #include <grp.h> struct group* getgrnam( const char* name );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The getgrnam() function lets a process gain more knowledge about the group named name. 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 name, or NULL on error or failure to find an entry with a matching name.
/* * Print the name of all users in the group given in * argv[1] */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <grp.h> int main( int argc, char** argv ) { struct group* g; char** p; if( ( g = getgrnam( argv[1] ) ) == NULL ) { fprintf( stderr, "getgrnam: %s failed\n", argv[1] ); 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 |