|
|
#include <grp.h>struct group *getgrent ()
struct group *getgrgid (gid) gid_t gid;
struct group *getgrnam (name) char *name;
void setgrent ()
void endgrent ()
struct group *fgetgrent (f) FILE *f;
The getgrent, getgrgid, and getgrnam routines 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 the getgrent routine is first called, it returns a pointer to the first group structure in the /etc/group file. Thereafter, it returns a pointer to the next group structure in the /etc/group file. Thus, successive calls to getgrent may be used to search the entire file.
The getgrgid routine searches from the beginning of the /etc/group file until a numerical group ID matching the argument gid is found. getgrgid returns a pointer to the group structure in which the argument gid was found.
Like getgrgid, the getgrnam routine searches from the beginning of the /etc/group file until a group whose name matches the argument name is found. getgrnam returns a pointer to the particular group structure in which the argument name was found.
The setgrent routine resets the file pointer to the beginning of the group file to allow repeated searches. The endgrent routine closes the group file when processing is complete.
The fgetgrent routine returns a pointer to the next group structure which matches the format of /etc/group in the stream argument f.
The endgrent, getgrgid and getgrnam functions may fail if:
These routines are also included in libsocket. The libsocket version provides the same functionality described here, in addition to providing the NIS support. Link with libsocket using cc ... -lsocket to get the additional NIS (Network Information Service) functionality.
getgrgid and getgrnam conform with:
AT&T SVID Issue 2
;
X/Open Portability Guide, Issue 3, 1989
;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1)
;
and
NIST FIPS 151-1
. getgrgid and getgrnam conform with:
X/Open Portability Guide, Issue 3, 1989
;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1)
;
and
NIST FIPS 151-1
.