|
|
#include <pwd.h>struct passwd *getpwent ()
struct passwd *getpwuid (uid) uid_t uid;
struct passwd *getpwnam (name) const char *name;
void setpwent ()
void endpwent ()
struct passwd *fgetpwent (f) FILE *f;
The getpwent, getpwuid, and getpwnam routines each returns a pointer to an object with a structure containing the broken-out fields of a line in the /etc/passwd file, a passwd structure declared in the <pwd.h> header file. Refer to this header file for a listing of the passwd structure. Because the elements vary by the type of standards compliance that you are using, it is not included here. Because this structure is in <pwd.h>, it does not need to be redeclared. The meanings of the fields in the passwd structure are described in passwd(FP).
When the getpwent routine is first called, it returns a pointer to the first passwd structure in the /etc/passwd file. Thereafter, it returns a pointer to the next passwd structure in the file. So successive calls to getpwent can be used to search the entire file.
The getpwuid routine searches from the beginning of the /etc/passwd file until a numerical user ID matching the argument uid is found. getpwuid returns a pointer to the particular passwd structure in which the argument uid was found.
Like getpwuid, the getpwnam routine searches from the beginning of the /etc/passwd file until a login name matching the argument name is found. getpwnam returns a pointer to the particular passwd structure in which the argument name was found.
The setpwent routine resets the file pointer to the beginning of the password file, /etc/passwd, to allow repeated searches. The endpwent routine closes the password file, /etc/passwd, when processing is complete.
The fgetpwent routine returns a pointer to the next passwd structure which matches the format of /etc/passwd in the stream argument f.
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.
getpwnam and getpwuid conforms 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
.
The fgetpwent routine has been withdrawn from XPG3.