Go to the previous, next section.

Scanning the List of All Groups

This section explains how a program can read the list of all groups in the system, one group at a time. The functions described here are declared in `grp.h'.

You can use the fgetgrent function to read group entries from a particular file.

Function: struct group * fgetgrent (FILE *stream)

The fgetgrent function reads the next entry from stream. It returns a pointer to the entry. The structure is statically allocated and is rewritten on subsequent calls to fgetgrent. You must copy the contents of the structure if you wish to save the information.

The stream must correspond to a file in the same format as the standard group database file.

The way to scan all the entries in the group database is with setgrent, getgrent, and endgrent.

Function: void setgrent (void)

This function initializes a stream for reading from the group data base. You use this stream by calling getgrent.

Function: struct group * getgrent (void)

The getgrent function reads the next entry from the stream initialized by setgrent. It returns a pointer to the entry. The structure is statically allocated and is rewritten on subsequent calls to getgrent. You must copy the contents of the structure if you wish to save the information.

Function: void endgrent (void)

This function closes the internal stream used by getgrent.

Go to the previous, next section.