GETGRENT(S) UNIX System V GETGRENT(S)
Name
getgrent, getgrgid, getgrnam, setgrent, endgrent, fgetgrent
- get group file entry
Syntax
#include <grp.h>
struct group *getgrent ( )
struct group *getgrgid (gid)
int gid;
struct group *getgrnam (name)
char *name;
void setgrent ( )
void endgrent ( )
struct group *fgetgrent (f)
FILE *f;
Description
The getgrent, getgrgid, and getgrnam functions 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 */
};
The getgrent function when first called returns a pointer to
the first group structure in the file; thereafter, it
returns a pointer to the next group structure in the file;
so, 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 and returns a
pointer to the particular structure in which it was found.
getgrnam searches from the beginning of the file until a
group name matching name is found and returns a pointer to
the particular structure in which it 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
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(S), getpwent(S), group(F)
Diagnostics
A NULL pointer is returned on EOF or error.
Warning
The above routines use <stdio.h>, which causes them to
increase the size of programs, not otherwise using standard
I/O, more than might be expected.
Note
All information is contained in a static area, so it must be
copied if it is to be saved.
Standards Conformance
endgrent, fgetgrent, getgrent, and setgrent are conformant
with:
AT&T SVID Issue 2, Select Code 307-127;
and The X/Open Portability Guide II of January 1987.
getgrgid and getgrnam are conformant with:
AT&T SVID Issue 2, Select Code 307-127;
The X/Open Portability Guide II of January 1987;
IEEE POSIX Std 1003.1-1988 with C Standard Language-
Dependent System Support;
and NIST FIPS 151-1.
(printed 6/20/89)