getgrgid()

QNX SDP8.0C Library ReferenceAPIDeveloper

Get information about the group with a given ID

Synopsis:

#include <sys/types.h>
#include <grp.h>

struct group* getgrgid( gid_t gid );

Arguments:

gid
The ID of the group you want to get information about.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The getgrgid() function lets a process gain more knowledge about group gid. This function uses a static buffer that's overwritten by each call.

Note:
The getgrent(), getgrgid(), and getgrnam() functions share the same static buffer.

Returns:

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.

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>

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

Classification:

POSIX 1003.1

Safety:
Cancellation pointYes
Signal handlerNo
ThreadNo
Page updated: