endgrent() — Group database entry functions

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <grp.h>

void endgrent(void),
struct group *getgrent (void);
void setgrent(void);

General description

The getgrent() function returns a pointer to the broken-out fields of a line in the group database, mapped by the group structure defined in the <grp.h> header file. Repeated calls to getgrent() return a pointer to the next group structure in the database, until End Of File (EOF), at which point a NULL pointer is returned. setgrent() interrupts this sequential search and rewinds the user database to the beginning, such that the next getgrent() returns a pointer to the first group structure. Use of setgrent() is optional after an End Of File (EOF), as the next getgrent() after end of file again returns a pointer to the first group structure. endgrent() is optionally used to close the user database when searching is complete.

The setgrent() function effectively rewinds the group database to allow repeated searches.

The endgrent() function may be called to close the group database when processing is complete.

Returned value

When first called, getgrent() returns a pointer to the next group structure in the group database. Upon subsequent calls it returns a pointer to a group structure, or it returns a NULL pointer on either End Of File (EOF) or an error. The return value may point to static data that is overwritten by each call.

There are no documented errno values.

Related information