40 lines
844 B
C++
40 lines
844 B
C++
#include "ehs/system/User.h"
|
|
#include "ehs/Log.h"
|
|
|
|
#include <unistd.h>
|
|
#include <cstring>
|
|
#include <cerrno>
|
|
|
|
namespace ehs
|
|
{
|
|
void User::GetId(UInt_32* const real, UInt_32* const effective, UInt_32* const saved)
|
|
{
|
|
if (getresuid(real, effective, saved) == -1)
|
|
EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
|
|
}
|
|
|
|
Str_8 User::GetName()
|
|
{
|
|
SInt_64 max = sysconf(_SC_LOGIN_NAME_MAX);
|
|
if (max == -1)
|
|
{
|
|
EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
|
|
return {};
|
|
}
|
|
|
|
Char_8* name = new Char_8[max];
|
|
|
|
if (getlogin_r(name, max) == -1)
|
|
{
|
|
delete[] name;
|
|
EHS_LOG_INT(LogType::ERR, 1, strerror(errno));
|
|
return {};
|
|
}
|
|
|
|
Str_8 result(name);
|
|
|
|
delete[] name;
|
|
|
|
return result;
|
|
}
|
|
} |