The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

getpwnam, getpwnam_r - search user database for a name

 SYNOPSIS



#include <sys/types.h>
#include <pwd.h>

struct passwd *getpwnam(const char *name);
int getpwnam_r(const char *nam, struct passwd *pwd, char *buffer,
    size_t bufsize, struct passwd **result);

 DESCRIPTION

The getpwnam() function searches the user database for an entry with a matching name.

The getpwnam() interface need not be reentrant.

The getpwnam_r() function updates the passwd structure pointed to by pwd and stores a pointer to that structure at the location pointed to by result. The structure will contain an entry from the user database with a matching name. Storage referenced by the structure is allocated from the memory provided with the buffer parameter, which is bufsize characters in size. The maximum size needed for this buffer can be determined with the {_SC_GETPW_R_SIZE_MAX} sysconf() parameter. A NULL pointer is returned at the location pointed to by result on error or if the requested entry is not found.

Applications wishing to check for error situations should set errno to 0 before calling getpwnam(). If getpwnam() returns a null pointer and errno is non-zero, an error occurred.

 RETURN VALUE

The getpwnam() function returns a pointer to a struct passwd with the structure as defined in <pwd.h> with a matching entry if found. A null pointer is returned if the requested entry is not found, or an error occurs. On error, errno is set to indicate the error.

The return value may point to a static area which is overwritten by a subsequent call to getpwent(), getpwnam() or getpwuid().

If successful, the getpwnam_r() function returns zero. Otherwise, an error number is returned to indicate the error.

 ERRORS

The getpwnam() function may fail if:
[EIO]
An I/O error has occurred.
[EINTR]
A signal was caught during getpwnam().
[EMFILE]
{OPEN_MAX} file descriptors are currently open in the calling process.
[ENFILE]
The maximum allowable number of files is currently open in the system.

The getpwnam_r() function may fail if:

[ERANGE]
Insufficient storage was supplied via buffer and bufsize to contain the data to be referenced by the resulting passwd structure.

 EXAMPLES

None.

 APPLICATION USAGE

Three names associated with the current process can be determined: 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.

 FUTURE DIRECTIONS

None.

 SEE ALSO

getpwuid(), <limits.h>, <pwd.h>, <sys/types.h>.

DERIVATION

getpwnam() derived from System V Release 2.0.

getpwnam_r() derived from the POSIX Threads Extension (1003.1c-1995).


UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]