Handle special handle value from FindFirstFileA in FindNextFileA (#52)

This commit is contained in:
Luke Street 2023-10-08 13:08:53 -04:00 committed by GitHub
parent 97a5af2055
commit c9d634876d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -50,6 +50,7 @@ typedef unsigned char BYTE;
#define ERROR_PATH_NOT_FOUND 3 #define ERROR_PATH_NOT_FOUND 3
#define ERROR_ACCESS_DENIED 5 #define ERROR_ACCESS_DENIED 5
#define ERROR_INVALID_HANDLE 6 #define ERROR_INVALID_HANDLE 6
#define ERROR_NO_MORE_FILES 18
#define ERROR_READ_FAULT 30 #define ERROR_READ_FAULT 30
#define ERROR_HANDLE_EOF 38 #define ERROR_HANDLE_EOF 38
#define ERROR_NOT_SUPPORTED 50 #define ERROR_NOT_SUPPORTED 50

View File

@ -707,12 +707,12 @@ namespace kernel32 {
return (void *) 1; return (void *) 1;
} }
FindFirstFileHandle *handle = new FindFirstFileHandle(); auto *handle = new FindFirstFileHandle();
if (!std::filesystem::exists(path.parent_path())) { if (!std::filesystem::exists(path.parent_path())) {
wibo::lastError = 3; // ERROR_PATH_NOT_FOUND wibo::lastError = ERROR_PATH_NOT_FOUND;
delete handle; delete handle;
return (void *) 0xFFFFFFFF; return INVALID_HANDLE_VALUE;
} }
std::filesystem::directory_iterator it(path.parent_path()); std::filesystem::directory_iterator it(path.parent_path());
@ -720,9 +720,9 @@ namespace kernel32 {
handle->pattern = path.filename().string(); handle->pattern = path.filename().string();
if (!findNextFile(handle)) { if (!findNextFile(handle)) {
wibo::lastError = 2; // ERROR_FILE_NOT_FOUND wibo::lastError = ERROR_FILE_NOT_FOUND;
delete handle; delete handle;
return (void *) 0xFFFFFFFF; return INVALID_HANDLE_VALUE;
} }
setFindFileDataFromPath(lpFindFileData, *handle->it++); setFindFileDataFromPath(lpFindFileData, *handle->it++);
@ -752,8 +752,15 @@ namespace kernel32 {
} }
int WIN_FUNC FindNextFileA(void *hFindFile, WIN32_FIND_DATA<char> *lpFindFileData) { int WIN_FUNC FindNextFileA(void *hFindFile, WIN32_FIND_DATA<char> *lpFindFileData) {
FindFirstFileHandle *handle = (FindFirstFileHandle *) hFindFile; // Special value from FindFirstFileA
if (hFindFile == (void *) 1) {
wibo::lastError = ERROR_NO_MORE_FILES;
return 0;
}
auto *handle = (FindFirstFileHandle *) hFindFile;
if (!findNextFile(handle)) { if (!findNextFile(handle)) {
wibo::lastError = ERROR_NO_MORE_FILES;
return 0; return 0;
} }