diff options
author | erorcun <erorcunerorcun@hotmail.com.tr> | 2020-10-23 00:56:32 +0200 |
---|---|---|
committer | erorcun <erorcunerorcun@hotmail.com.tr> | 2020-10-23 03:25:55 +0200 |
commit | 1587815fca2c8b45bdefedd61c351c6e9115f28b (patch) | |
tree | f34ddb7ef89433a5d17953b25d273761bdcbcf00 /src/skel/crossplatform.cpp | |
parent | Fix argument type (diff) | |
download | re3-1587815fca2c8b45bdefedd61c351c6e9115f28b.tar re3-1587815fca2c8b45bdefedd61c351c6e9115f28b.tar.gz re3-1587815fca2c8b45bdefedd61c351c6e9115f28b.tar.bz2 re3-1587815fca2c8b45bdefedd61c351c6e9115f28b.tar.lz re3-1587815fca2c8b45bdefedd61c351c6e9115f28b.tar.xz re3-1587815fca2c8b45bdefedd61c351c6e9115f28b.tar.zst re3-1587815fca2c8b45bdefedd61c351c6e9115f28b.zip |
Diffstat (limited to '')
-rw-r--r-- | src/skel/crossplatform.cpp | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/skel/crossplatform.cpp b/src/skel/crossplatform.cpp index e9320c05..4b7d3d9a 100644 --- a/src/skel/crossplatform.cpp +++ b/src/skel/crossplatform.cpp @@ -26,28 +26,21 @@ void GetLocalTime_CP(SYSTEMTIME *out) { // Compatible with Linux/POSIX and MinGW on Windows #ifndef _WIN32 HANDLE FindFirstFile(const char* pathname, WIN32_FIND_DATA* firstfile) { - char pathCopy[32]; + char pathCopy[MAX_PATH]; + strcpy(pathCopy, pathname); - strncpy(pathCopy, pathname, 32); - char* folder = strtok(pathCopy, "*"); + char *folder = strtok(pathCopy, "*"); + char *extension = strtok(NULL, "*"); + // because strtok doesn't return NULL for last delimiter + if (extension - folder == strlen(pathname)) + extension = nil; + // Case-sensitivity and backslashes... - char *realFolder = casepath(folder); - char *extension = nil; + // Will be freed at the bottom + char *realFolder = casepath(folder); if (realFolder) { - realFolder[strlen(realFolder)] = '*'; - extension = strtok(NULL, "*"); - if (extension) { - strcat(realFolder, extension); - } - - strncpy(pathCopy, realFolder, 32); - free(realFolder); - folder = strtok(pathCopy, "*"); - } else { - // Wildcard (*) - if (strlen(folder) + 1 != strlen(pathname)) - extension = strtok(NULL, "*"); + folder = realFolder; } strncpy(firstfile->folder, folder, sizeof(firstfile->folder)); @@ -57,8 +50,11 @@ HANDLE FindFirstFile(const char* pathname, WIN32_FIND_DATA* firstfile) { else firstfile->extension[0] = '\0'; + if (realFolder) + free(realFolder); + HANDLE d; - if ((d = (HANDLE)opendir(folder)) == NULL || !FindNextFile(d, firstfile)) + if ((d = (HANDLE)opendir(firstfile->folder)) == NULL || !FindNextFile(d, firstfile)) return NULL; return d; |