getpwnam_r() — Search user database for a name

Standards

Standards / Extensions C or C++ Dependencies

Single UNIX Specification, Version 2
Single UNIX Specification, Version 3

both OS/390 V2R8

Format

#define _XOPEN_SOURCE 500
#include <sys/types.h>
#include <pwd.h>

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

General description

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. A NULL pointer is returned at the location pointed to by result on error or if the requested entry is not found.

Returned value

If successful, getpwnam_r() returns 0.

If unsuccessful, getpwnam_r() sets errno to one of the following values:
Error Code
Description
EINVAL
One of the input arguments was not valid. Arguments pwd, buffer, and result must not be NULL. Argument bufsize must not be 0.
ERANGE
Insufficient storage was supplied in buffer and bufsize to contain the data to be referenced by the resulting passwd structure.

Related information