[Previous]
[Contents]
[Next]

getgrnam()

get information about the group with a given name

Synopsis:

#include <sys/types.h>
#include <grp.h>
struct group *getgrnam( const char *name );

Description:

The getgrnam() function allows a process to gain more knowledge about the group named name. This function uses a static buffer that is overwritten by each call.

Returns:

A pointer to an object of type struct group containing an entry from the group database with a matching name. Upon error or failure to find an entry with a matching name, a NULL pointer is returned.

Examples:

/*
 * 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>

void main( int argc, char **argv )
  {
    struct group *g;
    char     **p;

    if( ( g = getgrnam( argv[1] ) ) == NULL ) {
       fprintf( stderr, "getgrnam: %s failed\n",
            argv[1] );
       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 );
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

getgrent(), getgrgid()


[Previous]
[Contents]
[Next]