sys_info: add username
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
9fb899849d
commit
8844c4059d
@ -118,6 +118,11 @@ namespace stdex
|
||||
///
|
||||
bool elevated;
|
||||
|
||||
///
|
||||
/// Currently signed in user
|
||||
///
|
||||
sstring username;
|
||||
|
||||
sys_info_t() :
|
||||
os_platform(platform_id::unknown),
|
||||
#ifdef _WIN32
|
||||
@ -225,6 +230,27 @@ namespace stdex
|
||||
// TODO: Set admin.
|
||||
elevated = geteuid() == 0;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
{
|
||||
TCHAR szStackBuffer[0x100];
|
||||
ULONG ulSize = _countof(szStackBuffer);
|
||||
if (GetUserNameEx(NameFormat, szStackBuffer, &ulSize))
|
||||
username.assign(szStackBuffer, ulSize);
|
||||
if (GetLastError() == ERROR_MORE_DATA) {
|
||||
// Allocate buffer on heap and retry.
|
||||
username.resize(ulSize - 1);
|
||||
if (!GetUserNameEx(NameFormat, &username[0], &ulSize))
|
||||
username.clear();
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
struct passwd *pw = getpwuid(geteuid());
|
||||
if (pw && pw->pw_name)
|
||||
username = pw->pw_name;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user