mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-12-03 17:42:55 +00:00
backends: add portable variant of getcwd
This commit is contained in:
parent
e87bcfb906
commit
24888cc3c1
1 changed files with 29 additions and 2 deletions
|
@ -145,6 +145,31 @@ static void SetExecutablePath(char* exePath)
|
|||
#endif
|
||||
}
|
||||
|
||||
qboolean Sys_GetCwd(char *buf, size_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
WCHAR wpath[PATH_MAX];
|
||||
DWORD len;
|
||||
|
||||
if (_wgetcwd(wpath, PATH_MAX) == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
len = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, buf, size, NULL, NULL);
|
||||
if (len <= 0 || len == size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
if (getcwd(buf, size) == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return Q_strlcat(buf, "/", size) == 1;
|
||||
}
|
||||
|
||||
|
||||
const char *Sys_GetBinaryDir(void)
|
||||
{
|
||||
static char exeDir[PATH_MAX] = {0};
|
||||
|
@ -156,8 +181,10 @@ const char *Sys_GetBinaryDir(void)
|
|||
SetExecutablePath(exeDir);
|
||||
|
||||
if (exeDir[0] == '\0') {
|
||||
getcwd(exeDir, sizeof(exeDir));
|
||||
strcat(exeDir, "/");
|
||||
if (Sys_GetCwd(exeDir, sizeof(exeDir)) == false)
|
||||
{
|
||||
Q_strlcpy(exeDir, "./", sizeof(exeDir));
|
||||
}
|
||||
Com_Printf("Couldn't determine executable path. Using %s instead.\n", exeDir);
|
||||
} else {
|
||||
// cut off executable name
|
||||
|
|
Loading…
Reference in a new issue