getlogin_r() — Get login 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 <unistd.h>

int getlogin_r(char *name, size_t namesize);

General description

The getlogin_r() function puts the name associated by the login activity with the control terminal of the current process in the character array pointed to by name. The array is namesize characters long and should have space for the name and the terminating NULL character. The maximum size of the login name is LOGIN_NAME_MAX.

If getlogin_r() is successful, name points to the name the user used at login, even if there are several login names with the same user ID.

Returned value

If successful, getlogin_r() returns 0.

If unsuccessful, getlogin_r() sets errno to one of the following values:
Error Code
Description
ERANGE
The value of namesize is smaller than the length of the string to be returned including the terminating NULL character.

Related information