#include <stdlib.h>
char *getlogin(void);
char *getlogin_r(char *name, int namelen);
cc [ flag... ] file ... -D_POSIX_PTHREAD_SEMANTICS [ library... ]
int getlogin_r(char *name, size_t namesize);
See the NOTES section of this page.
If getlogin() is called within a process that is not attached to a terminal, it returns a null pointer. The correct procedure for determining the login name is to call cuserid(), or to call getlogin() and if it fails to call getpwuid().
getlogin_r() has the same functionality as getlogin() except that the caller must supply a buffer name with length namelen to store the result. The name buffer must be at least LOGNAME_MAX bytes in size (defined in <limits.h>). The POSIX version of getlogin_r() takes a namesize parameter of type size_t.
getlogin_r() will fail if the following is true:
The POSIX getlogin_r() returns zero if successful, or the error number upon failure.
The return values point to static data whose content is overwritten by each call.
getlogin() is unsafe in multi-thread applications. getlogin_r() should be used instead.
Solaris 2.4 and earlier releases provided a getlogin_r() as specified in POSIX.1c Draft 6. The final POSIX.1c standard changed the interface as described above. Support for the Draft 6 interface is provided for compatibility only and may not be supported in future releases. New applications and libraries should use the POSIX standard interface.