man.bsd.lv manual page server

Manual Page Search Parameters
GETPWENT(3) Library Functions Manual GETPWENT(3)

getpwent, getpwuid, getpwnam, setpwent, endpwent - get password file entry

#include <pwd.h>

struct passwd *getpwent();

struct passwd *getpwuid(uid) int uid;

struct passwd *getpwnam(name) char *name;

int setpwent();

int endpwent();

Getpwent, getpwuid and getpwnam each return a pointer to an object with the following structure containing the broken-out fields of a line in the password file.

struct	passwd { /* see getpwent(3) */
	char	*pw_name;
	char	*pw_passwd;
	int	pw_uid;
	int	pw_gid;
	int	pw_quota;
	char	*pw_comment;
	char	*pw_gecos;
	char	*pw_dir;
	char	*pw_shell;
};

The fields pw_quota and pw_comment are unused; the others have meanings described in passwd(5).

Getpwent reads the next line (opening the file if necessary); setpwent rewinds the file; endpwent closes it.

Getpwuid and getpwnam search from the beginning until a matching uid or name is found (or until EOF is encountered).

/etc/passwd

getlogin(3), getgrent(3), passwd(5)

Null pointer (0) returned on EOF or error.

All information is contained in a static area so it must be copied if it is to be saved.

UNIX-7