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

 NAME

getpwuid, getpwuid_r - search user database for a user ID

 SYNOPSIS



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

struct passwd *getpwuid(uid_t uid);
int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer,
    size_t bufsize, struct passwd **result);

 DESCRIPTION

The getpwuid() function searches the user database for an entry with a matching uid.

The getpwuid() interface need not be reentrant.

The getpwuid_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 uid. 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 getpwuid(). If getpwuid() returns a null pointer and errno is set to non-zero, an error occurred.

 RETURN VALUE

The getpwuid() 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 getpwuid_r() function returns zero. Otherwise, an error number is returned to indicate the error.

 ERRORS

The getpwuid() function may fail if:
[EIO]
An I/O error has occurred.
[EINTR]
A signal was caught during getpwuid().
[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 getpwuid_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

getpwnam(), geteuid(), getuid(), getlogin(), <limits.h>, <pwd.h>, <sys/types.h>.

DERIVATION

getpwuid() derived from System V Release 2.0.

getpwuid_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 ]