:man| Alphabetical   Categories   About us 
 
GETPWNAM (3) | C library functions | Unix Manual Pages | :man

NAME

getpwnam, getpwuid - get password file entry

CONTENTS

Synopsis
Description
Errors
Files
Notes

SYNOPSIS



#include <pwd.h>

#include <sys/types.h>



"struct passwd *getpwnam(const char *"name);



"struct passwd *getpwuid(uid_t "uid);

DESCRIPTION

The getpwnam() function returns a pointer to a structure containing the broken out fields of a line from /etc/passwd for the entry that matches the user name name.

The getpwuid() function returns a pointer to a structure containing the broken out fields of a line from /etc/passwd for the entry that matches the user uid uid.

The passwd structure is defined in <pwd.h> as follows:



struct passwd {
char *pw_name; /* user name */
char *pw_passwd;/* user password */
uid_t pw_uid; /* user id */
gid_t pw_gid; /* group id */
char *pw_gecos; /* real name */
char *pw_dir; /* home directory */
char *pw_shell; /* shell program */
};


"RETURN VALUE"

The getpwnam() and getpwuid() functions return a pointer to the passwd structure, or NULL if the matching entry is not found or an error occurs. If an error occurs, errno is set appropriately.

The return value may point to static area, and may be overwritten by subsequent calls.

ERRORS

0" or "ENOENT" or "ESRCH" or "EBADF" or "EPERM" or ... "
The given name or gid was not found.
ENOMEM Insufficient memory to allocate passwd structure.
EIO I/O error.
EINTR A signal was caught.
EMFILE The maximum number (OPEN_MAX) of files was open already in the calling process.
ENFILE The maximum number of files was open already in the system.

FILES

/etc/passwd
password database file

"CONFORMING TO"

SVID 3, POSIX, BSD 4.3

NOTES

The formulation given above under "RETURN VALUE" is from POSIX 1003.1-2001. It does not call "not found" an error, hence does not specify what value errno might have in this situation. But that makes it impossible to recognize errors. One might argue that according to POSIX errno should be left unchanged if an entry is not found. Experiments on various Unix-like systems shows that lots of different values occur in this situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and probably others.

"SEE ALSO"

fgetpwent(3), getgrnam(3), getpwent(3), setpwent(3), endpwent(3), getpw(3), putpwent(3), passwd(5)

 
Created by Blin Media, 2008-2013