Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

getlogin - get login name

&pagelevel(4)&pagelevel

Syntax

#include <unistd.h>

Optional
#include <stdlib.h> (End)

char *getlogin(void);

Description

getlogin() returns a pointer to a string with the user name of the calling process (which
corresponds to the login name of the calling process). If getlogin() returns a non-null
pointer, then that pointer points to the name that the user logged in under, even if there are
several login names with the same user ID.

getlogin() is not thread-safe. Use the reentrant function getlogin_r() when needed.

Return val.

Pointer to the login name


The function is always successful.

Null pointer

if unsuccessful, e.g. if getlogin() is called from within a process for which
the login name cannot be found. errno is set to indicate the error.

Notes

The return value usually points to static data whose content is overwritten by each call.
Portable applications should therefore save the login name elsewhere if it is required after
a subsequent call to the same function.

Three names associated with the current process can be determined:
getpwuid(geteuid()) returns the name associated with the effective user ID of the
process; getlogin() returns the name associated with the current login activity; and
getpwuid(getuid()) returns the name associated with the real user ID of the process.

See also

getlogin_r(), getpwnam(), getpwuid(), geteuid(), getuid(), limits.h,
unistd.h.