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
friends (see Reading Persona). How this information is collected by
the system and how to control/add/remove information from the background
storage is described in User Accounting Database.
getlogin function is declared in unistd.h, while
L_cuserid are declared in stdio.h.
Preliminary: | MT-Unsafe race:getlogin race:utent sig:ALRM timer locale | AS-Unsafe dlopen plugin heap lock | AC-Unsafe corrupt lock fd mem | See POSIX Safety Concepts.
getloginfunction 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
Preliminary: | MT-Safe locale | AS-Unsafe dlopen plugin heap lock | AC-Unsafe corrupt lock fd mem | See POSIX Safety Concepts.
cuseridfunction 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_cuseridcharacters; 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
The use of this function is deprecated since it is marked to be withdrawn in XPG4.2 and has already been removed from newer revisions of POSIX.1.
An integer constant that indicates how long an array you might need to store a user name.
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
See Standard Environment.