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)
int gid;
struct group *getgrnam (name)
char *name;
void setgrent ( )
struct group *fgetgrent (f)
FILE *f;
void endgrent ( )
DESCRIPTION
getgrent, getgrgid, and getgrnam each return pointers to an
object 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 numerical 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
numerical 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
Page 1 (last mod. 1/14/87)
getgrent(3C) getgrent(3C)
file to allow repeated searches. endgrent may be called to
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.
FILES
/etc/group
SEE ALSO
getlogin(3C), getpwent(3C), group(4).
DIAGNOSTICS
A NULL pointer is returned on EOF or error.
WARNING
The above routines use <stdio.h>. This causes them to
increase the size of programs not otherwise using standard
I/O 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.
Page 2 (last mod. 1/14/87)