For C/C++ there seems to be no portable function to get the user name in Linux/Posix and Windows. What would be the least cumbersome and yet robust portable code to achieve this ?
In Linux the USER environment variable seems always to be defined, whereas Windows seems to define the USERNAME variable. Relying on getenv one could avoid including windows.h and minimize preprocessor statements:
char * user_name = getenv("USER");
if (!user_name) {
user_name = getenv("USERNAME");
}
But is this approach halfway robust ? Or am I ignorant to another solution ? And I was also ignorant towards iOS ...