- do not use POSIX directory functions in common code.

For Windows these need to redirect to Unicode system functions to properly handle paths not representable in 8 bit encodings.
This commit is contained in:
Christoph Oelckers 2022-08-17 09:55:47 +02:00
commit 8d3c1adf05
7 changed files with 76 additions and 22 deletions

View file

@ -171,9 +171,24 @@ unsigned int I_MakeRNGSeed()
return static_cast<unsigned int>(arc4random());
}
FString I_GetCWD()
{
char curdir[PATH_MAX];
if (!getcwd(curdir, countof(curdir)))
{
return "";
}
return curdir;
}
bool I_ChDir(const char* path)
{
return chdir(path) == 0;
}
void I_OpenShellFolder(const char* folder)
{
char curdir[256];
char curdir[PATH_MAX];
if (!getcwd (curdir, countof(curdir)))
{
Printf ("Current path too long\n");

View file

@ -69,6 +69,8 @@ inline int I_GetNumaNodeCount() { return 1; }
inline int I_GetNumaNodeThreadCount(int numaNode) { return std::max<int>(std::thread::hardware_concurrency(), 1); }
inline void I_SetThreadNumaNode(std::thread &thread, int numaNode) { }
FString I_GetCWD();
bool I_ChDir(const char* path);
void I_OpenShellFolder(const char*);
#endif

View file

@ -410,6 +410,21 @@ FString I_GetFromClipboard (bool use_primary_selection)
return "";
}
FString I_GetCWD()
{
char curdir[PATH_MAX];
if (!getcwd(curdir, countof(curdir)))
{
return "";
}
return curdir;
}
bool I_ChDir(const char* path)
{
return chdir(path) == 0;
}
// Return a random seed, preferably one with lots of entropy.
unsigned int I_MakeRNGSeed()
{
@ -434,7 +449,7 @@ unsigned int I_MakeRNGSeed()
void I_OpenShellFolder(const char* folder)
{
char curdir[256];
char curdir[PATH_MAX];
if (!getcwd (curdir, countof(curdir)))
{
Printf ("Current path too long\n");

View file

@ -961,6 +961,25 @@ void I_SetThreadNumaNode(std::thread &thread, int numaNode)
}
}
FString I_GetCWD()
{
auto len = GetCurrentDirectoryW(0, nullptr);
TArray<wchar_t> curdir(len + 1, true);
if (!GetCurrentDirectoryW(len + 1, curdir.Data()))
{
return "";
}
FString returnv(curdir.Data());
FixPathSeperator(returnv);
return returnv;
}
bool I_ChDir(const char* path)
{
return SetCurrentDirectoryW(WideString(path).c_str());
}
void I_OpenShellFolder(const char* infolder)
{
auto len = GetCurrentDirectoryW(0, nullptr);

View file

@ -80,5 +80,7 @@ int I_GetNumaNodeThreadCount(int numaNode);
void I_SetThreadNumaNode(std::thread &thread, int numaNode);
void I_OpenShellFolder(const char*);
FString I_GetCWD();
bool I_ChDir(const char* path);
#endif