getlogin(3C)
NAME
getlogin, getlogin_r − get login name
SYNOPSIS
#include <stdlib.h>
char ∗getlogin(void);
char ∗getlogin_r(char ∗name, int namelen);
MT-LEVEL
See the NOTES section of this page.
DESCRIPTION
getlogin() returns a pointer to the login name as found in /var/adm/utmp. It may be used in conjunction with getpwnam() to locate the correct password file entry when the same user id is shared by several login names.
If getlogin() is called within a process that is not attached to a terminal, it returns a null pointer. The correct procedure for determining the login name is to call cuserid(), or to call getlogin() and if it fails to call getpwuid().
getlogin_r() has the same functionality as getlogin() except that a buffer name with length namelen has to be supplied by the caller to store the result. name must be at least LOGNAME_MAX bytes in size (defined in limits.h).
RETURN VALUES
Returns a null pointer if the login name is not found.
ERRORS
getlogin_r() will fail if the following is true:
ERANGE The size of the buffer is smaller than the result to be returned.
FILES
/var/adm/utmp
SEE ALSO
cuserid(3S), getgrnam(3C), getpwnam(3C), utmp(4)
NOTES
The getlogin_r() interface is as proposed in the POSIX.4a Draft #6 document, and is subject to change to be compliant to the standard when it is accepted.
When compiling multi-thread applications, the _REENTRANT flag must be defined on the compile line. This flag should only be used in multi-thread applications.
The return values point to static data whose content is overwritten by each call.
getlogin() is unsafe in multi-thread applications. getlogin_r() should be used instead.
SunOS 5.4 — Last change: 22 Jan 1993