|
|
char *getlogin(void);char *getlogin_r(char *name, size_t namelen);
getlogin() may be used in conjunction with the getpwnam routine to locate the correct password file entry when the same user ID is shared by several login names.
The correct procedure for determining the login name is to call the cuserid(S) or the getlogin() routine. If both fail, one should call the getpwuid routine.
getlogin_r(S) puts the name associated by the login activity with the control terminal of the current process in the character string pointed to by name. As the same user ID may be shared by several login names, use getlogin_r() with getpwnam(S)(see getpwent(S)) to ensure that the correct user database entry is found. If successful, getlogin_r() returns name which points to the name the user logged in under, even if there are several login names with the same user ID.
getlogin_r() returns a pointer to a string containing the user's login name, or NULL if the user's login name cannot be found. This is a pointer to the string passed in by name. If an error is detected, getlogin_r() returns NULL and sets errno.
getlogin_r() returns NULL and sets errno to ERANGE when namelen is smaller than the length of the string.
The getlogin() function may fail if:
X/Open Portability Guide, Issue 3, 1989
;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1)
;
and
NIST FIPS 151-1
.