Consider this typical for Linux function (it returns the current process username):
char* currentUserName(void) {
struct passwd *p = getpwuid(getuid());
return (p? p->pw_name : NULL);
}
How to get it in Unicode (let's say wchar_t
)? To be honest, I don't know what is the encoding of pw_name
even (system? Which one - File System? Always UTF-8?).
Is there a way to get the username as wchar_t
string? Maybe some function similar to Windows's GetUserNameW()
(where W
is for wide-chars) - to do it without to link with iconv library...
Maybe I can use mbstowcs()
but which locale will be used? I plan to call this function from systemd service, so I have not idea what LC_CTYPE/LANG is there...