Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

getpwnam - get user name

&pagelevel(4)&pagelevel

Syntax

#include <pwd.h>

Optional
#include <sys/types.h> (End)

struct passwd *getpwnam(const char *name); 

Description

getpwnam() searches the user catalog for an entry in which the pw_name component matches name (see also pwd.h and the manual "POSIX Basics" [1 (Related publications)]).

getpwnam() is not thread-safe. Use the reentrant function getpwnam_r() when needed.

Return val.

Pointer to a structure of type passwd (see pwd.h



if successful.

 

Null pointer

if an error occurs when reading or no matching entry was found. errno is set to indicate the error.

Errors

getpwnam() fails if:

 

EINVAL

name is too long.

 

EFAULT

An error occurs when creating the passwd structure, or an invalid name string is specified.

 

ENOENT

The user is not recognized.

Notes

The return value may point to a static area which may be overwritten by a subsequent call to cuserid, getpwnam or getpwuid.

Applications wishing to check for error situations should set errno to 0 before calling getpwnam(). If errno is set to non-zero on return, an error occurred.

The three names associated with the current process can be determined as follows:
getpwuid(geteuid()) returns the name associated with the effective user ID of the process; getlogin() returns the name associated with the current login activity; and getpwuid(getuid()) returns the name associated with the real user ID of the process.

See also

geteuid(), getlogin(), getpwnam_r(), getpwuid(), getuid(), limits.h, pwd.h, sys/types.h, and the manual "POSIX Basics" [1 (Related publications)].