Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
#define _POSIX_SOURCE
#include <grp.h>
struct group *getgrnam(const char *name);
Accesses the group structure containing an entry from the group database with the specified name.
If successful, getgrnam() returns a pointer to a group structure. The return value may point to static data that is overwritten by each call.
If unsuccessful or if the requested entry is not found, getgrnam() returns a NULL pointer.
There are no documented errno values.
⁄* CELEBG09
This example provides the members of a group.
*⁄
#define _POSIX_SOURCE
#include <sys⁄types.h>
#include <grp.h>
#include <stdio.h>
main() {
struct group *grp;
char grpname[]="USERS", **curr;
if ((grp = getgrnam(grpname)) == NULL)
perror("getgrnam() error");
else {
printf("The following are members of group %s:\n", grpname);
for (curr=grp->gr_mem; (*curr) != NULL; curr++)
printf(" %s\n", *curr);
}
}
The following are members of group USERS:
MVSUSR1
MVSUSR2
MVSUSR3
MVSUSR4
MVSUSR5
MVSUSR6
MVSUSR7
MVSUSR8
MVSUSR9