Skip to content

Commit 8f2a99e

Browse files
committed
xrCore: replaced _findfirst/ _findnext to glob for Linux
1 parent 319423a commit 8f2a99e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/xrCore/LocatorAPI.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "xrCore/Threading/Lock.hpp"
2121
#if defined(LINUX)
2222
#include "xrstring.h"
23+
#include <glob.h>
2324
#endif
2425

2526
const u32 BIG_FILE_READER_WINDOW_SIZE = 1024 * 1024;
@@ -606,14 +607,33 @@ bool CLocatorAPI::Recurse(pcstr path)
606607
xr_strcpy(scanPath, sizeof scanPath, path);
607608
xr_strcat(scanPath, "*.*");
608609
_finddata_t findData;
610+
#ifdef WINDOWS
609611
intptr_t handle = _findfirst(scanPath, &findData);
610612
if (handle == -1)
611613
return false;
614+
#elif defined(LINUX)
615+
glob_t globbuf;
616+
617+
globbuf.gl_offs = 256;
618+
int result = glob(scanPath, GLOB_NOSORT, NULL, &globbuf);
619+
620+
if(0 != result)
621+
return false;
622+
623+
intptr_t handle = globbuf.gl_pathc - 1;
624+
#endif
625+
612626
rec_files.reserve(256);
613627
size_t oldSize = rec_files.size();
614628
intptr_t done = handle;
615629
while (done != -1)
616630
{
631+
#if defined(LINUX)
632+
xr_strcpy(findData.name, sizeof globbuf.gl_pathv[handle - done], globbuf.gl_pathv[handle - done]);
633+
struct stat fi;
634+
stat(findData.name, &fi);
635+
findData.size = fi.st_size;
636+
#endif
617637
string1024 fullPath;
618638
bool ignore = false;
619639
if (m_Flags.test(flNeedCheck))
@@ -628,9 +648,17 @@ bool CLocatorAPI::Recurse(pcstr path)
628648
}
629649
if (!ignore)
630650
rec_files.push_back(findData);
651+
#ifdef WINDOWS
631652
done = _findnext(handle, &findData);
653+
#elif defined(LINUX)
654+
done--;
655+
#endif
632656
}
657+
#ifdef WINDOWS
633658
_findclose(handle);
659+
#elif defined(LINUX)
660+
globfree(&globbuf);
661+
#endif
634662
size_t newSize = rec_files.size();
635663
if (newSize > oldSize)
636664
{
@@ -642,6 +670,7 @@ bool CLocatorAPI::Recurse(pcstr path)
642670
// insert self
643671
if (path && path[0] != 0)
644672
Register(path, 0xffffffff, 0, 0, 0, 0, 0);
673+
645674
return true;
646675
}
647676

0 commit comments

Comments
 (0)