gtpc2m3u | C/C++ Language Support User's Guide |
This function accesses the group structure containing an entry from the group database with the specified name.
Format
#include <grp.h> struct group *getgrnam(const char *name);
Normal Return
If successful, the getgrnam function returns a pointer to a group structure containing an entry from the group database with the specified name. The return value is a pointer to static data that is overwritten by each call.
This group structure, defined in the grp.h header file, contains the following members:
Error Return
If unsuccessful, the getgrnam function returns a NULL pointer and sets errno to one of the following:
Programming Considerations
Examples
The following example provides the members of a group.
#include <grp.h> #include <stdio.h> int main(void) { char grpname[] = "users", **curr; struct group *grp; 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); } return 0; }
Output
The following members of group users: tpfuser1 tpfuser2 tpfuser3
Related Information