getgrent(3)
NAME
getgrent, getgrgid, getgrnam, setgrent, endgrent − get group file entry
SYNTAX
#include <grp.h>
struct group *getgrent()
struct group *getgrgid(gid)
int gid;
struct group *getgrnam(name)
char *name;
int setgrent()
int endgrent()
struct group *fgetgrent(f)
FILE *f;
DESCRIPTION
The getgrent, getgrgid and getgrnam subroutines each return pointers to an object with the following structure containing the broken-out fields of a line in the group file.
struct group { /* see getgrent(3) */
char *gr_name;
char *gr_passwd;
int gr_gid;
char **gr_mem;
};
The members of this structure are:
gr_name Contains the name of the group.
gr_passwd Contains the encrypted password of the group.
gr_gid Contains the numerical group-ID.
gr_mem Contains the null-terminated vector of pointers to the individual member names.
The getgrent subroutine simply reads the next line while getgrgid and getgrnam search until a matching gid or name is found (or until EOF is encountered). Each routine picks up where the others leave off so successive calls may be used to search the entire file.
A call to setgrent has the effect of rewinding the group file to allow repeated searches. The endgrent subroutine may be called to close the group file when processing is complete.
The fgetgrent subroutine returns a pointer to the next group structure in the stream f, which matches the format of /etc/group.
RESTRICTIONS
All information is contained in a static area so it must be copied if it is to be saved.
DIAGNOSTICS
A null pointer (0) is returned on EOF or error.
FILES
/etc/group