解决LINUX下无HOME环境变量引起的崩溃问题

This commit is contained in:
luoliangyi 2023-02-08 11:32:28 +08:00
parent c3d2e52890
commit 8e4e48b970
1 changed files with 6 additions and 3 deletions

View File

@ -311,7 +311,8 @@ HGResult HGAPI HGBase_GetConfigPath(HGChar* configPath, HGUInt maxLen)
strcat(cfgPath, "\\Cfg\\");
#else
char cfgPath[512] = { 0 };
strcpy(cfgPath, getenv("HOME"));
struct passwd* pw = getpwuid(getuid());
strcpy(cfgPath, pw->pw_dir);
if (cfgPath[strlen(cfgPath) - 1] != '/')
strcat(cfgPath, "/");
@ -375,7 +376,8 @@ HGResult HGAPI HGBase_GetLogFilePath(HGChar* logFilePath, HGUInt maxLen)
strcat(logPath, "\\Log\\");
#else
char logPath[512] = { 0 };
strcpy(logPath, getenv("HOME"));
struct passwd* pw = getpwuid(getuid());
strcpy(logPath, pw->pw_dir);
if (logPath[strlen(logPath) - 1] != '/')
strcat(logPath, "/");
@ -408,7 +410,8 @@ HGResult HGAPI HGBase_GetDocumentsPath(HGChar* documentsPath, HGUInt maxLen)
strcat(docPath, "\\");
#else
char docPath[512] = { 0 };
strcpy(docPath, getenv("HOME"));
struct passwd* pw = getpwuid(getuid());
strcpy(docPath, pw->pw_dir);
if (docPath[strlen(docPath) - 1] != '/')
strcat(docPath, "/");
strcat(docPath, "Documents/");