Fixed pattern detection if path is already a directory.
@@ -833,9 +833,8 @@ static BOOL FindDataFromStat(const char* path, const struct stat* fileStat,
HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
{
- LPSTR p;
- size_t index;
- size_t length;
+ int oldErrno;
+ BOOL isDir = FALSE;
struct stat fileStat;
WIN32_FILE_SEARCH* pFileSearch;
ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
@@ -847,6 +846,25 @@ HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
return INVALID_HANDLE_VALUE;
}
+ oldErrno = errno;
+
+ if (stat(lpFileName, &fileStat) >= 0)
+ {
+ isDir = (S_ISDIR(fileStat.st_mode) != 0);
+ }
+
+ errno = oldErrno;
+
+ if (isDir)
+ {
+ pFileSearch->lpPath = _strdup(lpFileName);
+ pFileSearch->lpPattern = _strdup("*");
+ }
+ else
+ {
+ LPSTR p;
+ size_t index;
+ size_t length;
/* Separate lpFileName into path and pattern components */
p = strrchr(lpFileName, '/');
@@ -895,6 +913,7 @@ HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
FindClose(pFileSearch);
return INVALID_HANDLE_VALUE; /* not a directory */
}
+ }
/* Open directory for reading */
pFileSearch->pDir = opendir(pFileSearch->lpPath);
