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 the Persona of a Process). How this information is collected by
the system and how to control/add/remove information from the background
storage is described in The 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.
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
Preliminary: | MT-Unsafe race:cuserid/!string locale | AS-Unsafe dlopen plugin heap lock | AC-Unsafe corrupt lock fd mem | See POSIX Safety Concepts.
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
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
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 The Persona of a Process.) 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 Variables.