Go to the first, previous, next, last section, table of contents.


Looking Up One User

You can search the system user database for information about a specific user using getpwuid or getpwnam. These functions are declared in `pwd.h'.

Function: struct passwd * getpwuid (uid_t uid)
This function returns a pointer to a statically-allocated structure containing information about the user whose user ID is uid. This structure may be overwritten on subsequent calls to getpwuid.

A null pointer value indicates there is no user in the data base with user ID uid.

Function: int getpwuid_r (uid_t uid, struct passwd *result_buf, char *buffer, size_t buflen, struct passwd **result)
This function is similar to getpwuid in that is returns information about the user whose user ID is uid. But the result is not placed in a static buffer. Instead the user supplied structure pointed to by result_buf is filled with the information. The first buflen bytes of the additional buffer pointed to by buffer are used to contain additional information, normally strings which are pointed to by the elements of the result structure.

If the return value is 0 the pointer returned in result points to the record which contains the wanted data (i.e., result contains the value result_buf). In case the return value is non null there is no user in the data base with user ID uid or the buffer buffer is too small to contain all the needed information. In the later case the global errno variable is set to ERANGE.

Function: struct passwd * getpwnam (const char *name)
This function returns a pointer to a statically-allocated structure containing information about the user whose user name is name. This structure may be overwritten on subsequent calls to getpwnam.

A null pointer value indicates there is no user named name.

Function: int getpwnam_r (const char *name, struct passwd *result_buf, char *buffer, size_t buflen, struct passwd **result)
This function is similar to getpwnam in that is returns information about the user whose user name is name. But the result is not placed in a static buffer. Instead the user supplied structure pointed to by result_buf is filled with the information. The first buflen bytes of the additional buffer pointed to by buffer are used to contain additional information, normally strings which are pointed to by the elements of the result structure.

If the return value is 0 the pointer returned in result points to the record which contains the wanted data (i.e., result contains the value result_buf). In case the return value is non null there is no user in the data base with user name name or the buffer buffer is too small to contain all the needed information. In the later case the global errno variable is set to ERANGE.


Go to the first, previous, next, last section, table of contents.