Skip to content

Commit 33d1ba0

Browse files
committed
xrCore: implement getting uesrname and machinename on linux
1 parent 46ba394 commit 33d1ba0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/xrCore/xrCore.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include <mmsystem.h>
88
#include <objbase.h>
99
#pragma comment(lib, "winmm.lib")
10+
#elif defined(LINUX)
11+
#include <sys/types.h>
12+
#include <pwd.h>
13+
#include <unistd.h>
1014
#endif
1115
#include "xrCore.h"
1216
#include "Threading/ThreadPool.hpp"
@@ -237,6 +241,20 @@ void xrCore::Initialize(pcstr _ApplicationName, pcstr commandLine, LogCallback c
237241

238242
DWORD sz_comp = sizeof(CompName);
239243
GetComputerName(CompName, &sz_comp);
244+
#elif defined(LINUX)
245+
uid_t uid = geteuid();
246+
struct passwd *pw = getpwuid(uid);
247+
if(pw)
248+
{
249+
strcpy(UserName, pw->pw_gecos);
250+
char* pos = strchr(UserName, ','); // pw_gecos return string
251+
if(NULL != pos)
252+
*pos = 0;
253+
if(0 == UserName[0])
254+
strcpy(UserName, pw->pw_name);
255+
}
256+
257+
gethostname(CompName, sizeof(CompName));
240258
#endif
241259

242260
Memory._initialize();

0 commit comments

Comments
 (0)