[Previous]
[Contents]
[Next]

getgrgid()

get information about the group with a given ID

Synopsis:

#include <sys/types.h>
#include <grp.h>
struct group *getgrgid( gid_t gid );

Description:

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.

Returns:

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.

Examples:

/*
 * 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 );
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

getgrent(), getgrnam()


[Previous]
[Contents]
[Next]