What is the best way to get the username of the logged in user? I used getlogin() and it worked fine with these distros :
It also worked perfectly at cygwin. However, Mandrake 10, returns a ENOENT error message. What's more, I found this page :
which says :
and this page :Unfortunately, it is often rather easy to fool getlogin(). Sometimes it does not work at all, because some program messed up the utmp file. Often, it gives only the first 8 characters of the login name. The user currently logged in on the controlling tty of our program need not be the user who started it. Avoid getlogin() for security-related purposes.
Can anyone inform me about the best way (portable and secure) to find the login name of the user?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 Process Persona.) The user cannot do anything to fool these functions.