Chapter Contents

Previous

Next
getgrgid

getgrgid



Access Group Database by ID

Portability: POSIX.1 conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

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

struct group *getgrgid(gid_t gid);


DESCRIPTION

getgrgid provides information about a group and its members. gid is the group ID. getgrgid returns a pointer to a group structure defined in <grp.h> that contains an entry from the group database. group contains the following members:
gr_name name of the group
gr_gid numerical group ID
gr_mem null-terminated vector of pointers to the member names.


RETURN VALUE

getgrgid returns a pointer to a group structure if successful. getgrgid returns a NULL pointer if unsuccessful.

Note:    The pointer returned by getgrgid may be a static data area that can be rewritten by the next call to getgrgid or getgrnam .  [cautionend]


EXAMPLE

The following code fragment illustrates the use of getgrgid to obtain a group name:

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

.
.
.
struct stat info; 
struct group *grp;

.
.
.
if ((grp = getgrgid(info.st_gid)) == NULL)
   perror("getgrgid() error");
 else
    printf("The group name is %s\n", grp->  gr_name);

.
.
.


RELATED FUNCTIONS

getgrnam , getgroups , getpwuid


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.