[Previous] [Contents] [Next]

getpwnam_r()

Get information about the user with a given name

Synopsis:

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

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

Library:

libc

Description:

The getpwnam_r() function is a reentrant version of getpwnam(). It gets information about the user with the given name.

If _POSIX_THREAD_SAFE_FUNCTIONS is defined, the getpwnam_r() function updates the passwd structure pointed to by pwd and stores a pointer to that structure at the location pointed by result. The structure contains an entry from the user database with the given 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 by calling sysconf() with the argument _SC_GETPW_R_SIZE_MAX.

A NULL pointer is stored at the location pointed by result on error or if the requested entry isn't found.

Returns:

Zero for success, or an error number.

Errors:

ERANGE
Insufficient storage was supplied via buffer and bufsize to contain the resulting passwd structure.

The getpwnam_r() function uses the following functions, and as a result errno can be set to a valid error for any of these calls:

Classification:

POSIX 1003.1

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

See also:

getlogin(), getpwent(), getpwnam(), getpwuid(), getpwuid_r()


[Previous] [Contents] [Next]