Gets the login name. Format #include <unistd.h> char *getlogin (void); int *getlogin_r (char *name, size_t namesize);
1 – Description
The getlogin function returns the login name of the user associated with the current session. 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. The getlogin_r function is the reentrant version of getlogin. Upon successful completion, getlogin_r returns 0 and puts the name associated by the login activity with the controlling terminal of the current process in the character array pointed to by name. The array is namesize characters long and should have space for the name and the terminating null character. The maximum size of the login name is LOGIN_NAME_MAX. If getlogin_r is successful, name points to the name the user used at login, even if there are several login names with the same user ID.
2 – Return Values
x Upon successful completion, getlogin returns a pointer to a null-terminated string in a static buffer. 0 Indicates successful completion of getlogin_r. NULL Indicates an error; errno is set.