GETPWENT(3C)
NAME
getpwent, getpwuid, getpwnam, setpwent, endpwent − get password file entry
SYNOPSIS
#include <pwd.h>
struct passwd ∗getpwent ( );
struct passwd ∗getpwuid (uid)
int uid;
struct passwd ∗getpwnam (name)
char ∗name;
int setpwent ( );
int endpwent ( );
DESCRIPTION
Getpwent, getpwuid and getpwnam each returns a pointer to an object with the following structure containing the broken-out fields of a line in the password file.
struct passwd {
char *pw_name;
char *pw_passwd;
int pw_uid;
int pw_gid;
char *pw_age;
char *pw_comment;
char *pw_gecos;
char *pw_dir;
char *pw_shell;
};
The pw_comment field is unused; the others have meanings described in passwd(5).
Getpwent reads the next line in the file, so successive calls can be used to search the entire file. Getpwuid and getpwnam search from the beginning of the file until a matching uid or name is found, or EOF is encountered.
A call to setpwent has the effect of rewinding the password file to allow repeated searches. Endpwent may be called to close the password file when processing is complete.
FILES
/etc/passwd
SEE ALSO
getlogin(3C), getgrent(3C), passwd(5).
DIAGNOSTICS
Null pointer (0) returned on EOF or error.
BUGS
All information is contained in a static area so it must be copied if it is to be saved.