You can use the functions listed in this section to determine the login name of the user who is running a process, and the name of the user who logged in the current session. See also the function getuid
and friends (see Reading Persona).
The getlogin
function is declared in `unistd.h', while cuserid
and L_cuserid
are declared in `stdio.h'.
getlogin
function returns a pointer to a string containing the name of the user logged in on the controlling terminal of the process, or a null pointer if this information cannot be determined. The string is statically allocated and might be overwritten on subsequent calls to this function or to cuserid
.
cuserid
function returns a pointer to a string containing a user name associated with the effective ID of the process. If string is not a null pointer, it should be an array that can hold at least L_cuserid
characters; the string is returned in this array. Otherwise, a pointer to a string in a static area is returned. This string is statically allocated and might be overwritten on subsequent calls to this function or to getlogin
.
These functions let your program identify positively the user who is running or the user who logged in this session. (These can differ when setuid programs are involved; See Process Persona.) The user cannot do anything to fool these functions.
For most purposes, it is more useful to use the environment variable LOGNAME
to find out who the user is. This is more flexible precisely because the user can set LOGNAME
arbitrarily. See Standard Environment.