summaryrefslogtreecommitdiffstats
path: root/src/skel/crossplatform.cpp
diff options
context:
space:
mode:
authorerorcun <erorcunerorcun@hotmail.com.tr>2020-10-23 03:37:01 +0200
committererorcun <erorcunerorcun@hotmail.com.tr>2020-10-23 03:37:01 +0200
commit067200dd7eae890d6b0bfa98fc90fa80ca494a74 (patch)
tree754161f3d9f7bc525ed6b9a9f59e6a18a041b525 /src/skel/crossplatform.cpp
parentmr.casepath (diff)
downloadre3-067200dd7eae890d6b0bfa98fc90fa80ca494a74.tar
re3-067200dd7eae890d6b0bfa98fc90fa80ca494a74.tar.gz
re3-067200dd7eae890d6b0bfa98fc90fa80ca494a74.tar.bz2
re3-067200dd7eae890d6b0bfa98fc90fa80ca494a74.tar.lz
re3-067200dd7eae890d6b0bfa98fc90fa80ca494a74.tar.xz
re3-067200dd7eae890d6b0bfa98fc90fa80ca494a74.tar.zst
re3-067200dd7eae890d6b0bfa98fc90fa80ca494a74.zip
Diffstat (limited to 'src/skel/crossplatform.cpp')
-rw-r--r--src/skel/crossplatform.cpp37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/skel/crossplatform.cpp b/src/skel/crossplatform.cpp
index 65cfde45..f2f9d5ee 100644
--- a/src/skel/crossplatform.cpp
+++ b/src/skel/crossplatform.cpp
@@ -26,31 +26,23 @@ 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 constructedPath[32];
-
- strncpy(pathCopy, pathname, 32);
- char* folder = strtok(pathCopy, "*");
+ char pathCopy[MAX_PATH];
+ strcpy(pathCopy, pathname);
+
+ 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...
+ // Will be freed at the bottom
char *realFolder = casepath(folder);
- char *extension = nil;
if (realFolder) {
- sprintf(constructedPath, "%s*", realFolder);
- extension = strtok(NULL, "*");
- if (extension) {
- strcat(constructedPath, extension);
- }
-
- free(realFolder);
- folder = strtok(constructedPath, "*");
- extension = strtok(NULL, "*");
- } else {
- // Wildcard (*)
- if (strlen(folder) + 1 != strlen(pathname))
- extension = strtok(NULL, "*");
+ folder = realFolder;
}
-
+
strncpy(firstfile->folder, folder, sizeof(firstfile->folder));
if (extension)
@@ -58,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;