Previous: Lookup Group, Up: Group Database
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.
The
fgetgrent
function reads the next entry from stream. It returns a pointer to the entry. The structure is statically allocated and is overwritten on subsequent calls tofgetgrent
. 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.
This function is similar to
fgetgrent
in that it reads the next user entry from stream. But the result is returned in the structure pointed to by result_buf. The first buflen bytes of the additional buffer pointed to by buffer are used to contain additional information, normally strings which are pointed to by the elements of the result structure.This stream must correspond to a file in the same format as the standard group database file.
If the function returns zero result points to the structure with the wanted data (normally this is in result_buf). If errors occurred the return value is non-zero and result contains a null pointer.
The way to scan all the entries in the group database is with
setgrent
, getgrent
, and endgrent
.
This function initializes a stream for reading from the group data base. You use this stream by calling
getgrent
orgetgrent_r
.
The
getgrent
function reads the next entry from the stream initialized bysetgrent
. It returns a pointer to the entry. The structure is statically allocated and is overwritten on subsequent calls togetgrent
. You must copy the contents of the structure if you wish to save the information.
This function is similar to
getgrent
in that it returns the next entry from the stream initialized bysetgrent
. Likefgetgrent_r
, it places the result in user-supplied buffers pointed to result_buf and buffer.If the function returns zero result contains a pointer to the data (normally equal to result_buf). If errors occurred the return value is non-zero and result contains a null pointer.