Hello!!

What is the best way to get the username of the logged in user? I used getlogin() and it worked fine with these distros :

Solaris 8
Suse 9

It also worked perfectly at cygwin. However, Mandrake 10, returns a ENOENT error message. What's more, I found this page :

http://jamesthornton.com/linux/man/getlogin.3.html

which says :

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.
and this page :

http://linux-documentation.com/en/pa...Logged-In.html

says:

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.
Can anyone inform me about the best way (portable and secure) to find the login name of the user?

Thank you!