1
0
Fork 0
mirror of https://github.com/halpz/re3.git synced 2024-12-25 18:05:27 +00:00

satisfy mr.casepath

This commit is contained in:
erorcun 2020-10-23 01:56:32 +03:00
parent 1cdc647324
commit 1587815fca

View file

@ -26,28 +26,21 @@ void GetLocalTime_CP(SYSTEMTIME *out) {
// Compatible with Linux/POSIX and MinGW on Windows // Compatible with Linux/POSIX and MinGW on Windows
#ifndef _WIN32 #ifndef _WIN32
HANDLE FindFirstFile(const char* pathname, WIN32_FIND_DATA* firstfile) { 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... // Case-sensitivity and backslashes...
char *realFolder = casepath(folder); // Will be freed at the bottom
char *extension = nil; char *realFolder = casepath(folder);
if (realFolder) { if (realFolder) {
realFolder[strlen(realFolder)] = '*'; folder = 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, "*");
} }
strncpy(firstfile->folder, folder, sizeof(firstfile->folder)); strncpy(firstfile->folder, folder, sizeof(firstfile->folder));
@ -57,8 +50,11 @@ HANDLE FindFirstFile(const char* pathname, WIN32_FIND_DATA* firstfile) {
else else
firstfile->extension[0] = '\0'; firstfile->extension[0] = '\0';
if (realFolder)
free(realFolder);
HANDLE d; HANDLE d;
if ((d = (HANDLE)opendir(folder)) == NULL || !FindNextFile(d, firstfile)) if ((d = (HANDLE)opendir(firstfile->folder)) == NULL || !FindNextFile(d, firstfile))
return NULL; return NULL;
return d; return d;