getgrnam -- Access Group Database by Name

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


Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.