getlogin, getlogin_r - get login name
#include <unistd.h> char *getlogin(void); int getlogin_r(char *name, size_t namesize);
The getlogin() function returns a pointer to a string giving a user name associated with the calling process, which is the login name associated with the calling process. If getlogin() returns a non-null pointer, then that pointer points to the name that the user logged in under, even if there are several login names with the same user ID.The getlogin() interface need not be reentrant.
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.
Upon successful completion, getlogin() returns a pointer to the login name or a null pointer if the user's login name cannot be found. Otherwise it returns a null pointer and sets errno to indicate the error.The return value may point to static data whose content is overwritten by each call.
If successful, the getlogin_r() function returns zero. Otherwise, an error number is returned to indicate the error.
The getlogin() function may fail if:
- [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.
- [ENXIO]
- The calling process has no controlling terminal.
The getlogin_r() function may fail if:
- [ERANGE]
- The value of namesize is smaller than the length of the string to be returned including the terminating null character.
None.
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(.Fngetuid) returns the name associated with the real user ID of the process.
None.
getpwnam(), getpwuid(), geteuid(), getuid(), <limits.h>, <unistd.h>.
getlogin() derived from System V Release 2.0.getlogin_r() derived from the POSIX Threads Extension (1003.1c-1995).