endpwent() — User database functions

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <pwd.h>

void endpwent(void),
struct passwd *getpwent(void);
void setpwent(void);

General description

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

The setpwent() function effectively rewinds the user database to allow repeated searches.

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

Returned value

When first called, getpwent() returns a pointer to the next passwd structure in the user database. Upon subsequent calls it returns a pointer to a passwd 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 for endpwent() and setpwent(). For getpwent(), if unsuccessful, getpwemt() sets errno to one of the following values:
Error Code
Description
EMVSSAF2ERR
The system authorization facility (SAF) or RACF Get GMAP service had an error.
EMVSSAFEXTRERR
The SAF or RACF RACROUTE EXTRACT service had an error.

Related information