Chapter Contents

Previous

Next
getgrnam

getgrnam



Access Group Database by Name

Portability: POSIX.1 conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

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

struct group *getgrnam(const char *name);


DESCRIPTION

getgrnam returns a pointer to a group structure defined in <grp.h> that contains an entry from the group database. name is the entry. 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

getgrnam returns a pointer to a group structure if successful. Note that the pointer returned by getgrnam may be a static data area that can be rewritten by the next call to getgrgid or getgrnam . getgrnam returns a NULL pointer if unsuccessful.


EXAMPLE

The following code fragment illustrates the use of getgrnam to obtain a list of group members:

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

.
.
.
struct group *grp;
char grpname[]="BILLING";
char  **gmem;
.
.
.
if ((grp = getgrnam(grpname)) == NULL)
   perror("getgrnam() error");
else {
   printf("These are the members of group %s:\n", grpname);
   for (gmem=grp->gr_mem; *gmem != NULL; gmem++)
      printf(" %s\n", *gmem);
}


.
.
.


RELATED FUNCTIONS

getgrgid , getpwnam


Chapter Contents

Previous

Next

Top of Page

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