GETLOGIN(3) BSD GETLOGIN(3)
NAME
getlogin, getlogin_r - get log-in name
SYNOPSIS
char *getlogin()
int getlogin_r (name, namelen)
char *name;
int namelen;
DESCRIPTION
getlogin returns a pointer to the log-in name as found in /etc/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, or if there is no entry in /etc/utmp for the process' terminal,
getlogin returns a NULL pointer (0). A reasonable procedure for
determining the log-in name is to first call getlogin and, if it fails,
to call getpwuid(getuid()).
getlogin_r is the reentrant version of the getlogin function and can be
used in a multiple-thread environment. It places the login name in a
user-supplied buffer and returns a non-zero value if it fails.
FILES
/etc/utmp
WARNINGS
/etc/utmp can be an unreliable source of login information. /etc/utmp is
written by the most recently executed /bin/login, which is not
necessarily the same as the current login.
SEE ALSO
getuid(2), getpwent(3), utmp(5), ttyslot(3)
DIAGNOSTICS
Returns a NULL pointer (0) if name is not found.
BUGS
The return values point to static data whose content is overwritten by
each call.