getgrent(3C) getgrent(3C)NAME getgrent, getgrgid, getgrnam, setgrent, endgrent, fgetgrent - obtain group file entry from a group file SYNOPSIS #include <grp.h> struct group *getgrent() struct group *getgrgid(gid) gid_t gid; struct group *getgrnam(name) char *name; void setgrent() struct group *fgetgrent(f) FILE *f; void endgrent() DESCRIPTION getgrent, getgrgid, and getgrnam return pointers to an ob- ject with the following structure containing the broken-out fields of a line in the /etc/group file. Each line contains a group structure, defined in the <grp.h> header file: struct group { char *gr_name; /* the name of the group */ char *gr_passwd; /* the encrypted group password */ int gr_gid; /* the numeric group ID */ char **gr_mem; /* vector of pointers to member names */ }; When first called, getgrent returns a pointer to the first group structure in the file. Thereafter, it returns a pointer to the next group structure in the file; therefore, successive calls may be used to search the entire file. getgrgid searches from the beginning of the file until a numeric group ID matching gid is found; it returns a pointer to the particular structure in which the match was found. getgrnam searches from the beginning of the file until a group name matching name is found; it returns a pointer to the particular structure in which the match was found. If an end-of-file or an error is encountered on reading, these functions return a NULL pointer. A call to setgrent has the effect of rewinding the group file to allow repeated searches. endgrent may be called to April, 1990 1
getgrent(3C) getgrent(3C)close the group file when processing is complete. fgetgrent returns a pointer to the next group structure in the stream f, which matches the format of /etc/group. RETURN VALUE If an end-of-file or an error is encountered, a NULL pointer is returned. FILES /etc/group SEE ALSO getlogin(3C), getpwent(3C), group(4). WARNINGS The routines use <stdio.h>. Therefore, the size of programs not otherwise using standard I/O is increased more than might be expected. BUGS All information is contained in a static area, so it must be copied if it is to be saved. 2 April, 1990