From 30d0bde4babc9f1e64afd84970e2f2895bb11373 Mon Sep 17 00:00:00 2001 From: David PHAM-VAN Date: Fri, 31 Mar 2017 15:33:28 -0700 Subject: [PATCH] Fix FindFirstFile return values --- winpr/libwinpr/file/generic.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/winpr/libwinpr/file/generic.c b/winpr/libwinpr/file/generic.c index a5cfc517b..17623685d 100644 --- a/winpr/libwinpr/file/generic.c +++ b/winpr/libwinpr/file/generic.c @@ -475,7 +475,7 @@ BOOL WINAPI GetFileAttributesExA(LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfo WIN32_FIND_DATAA findFileData; HANDLE hFind; - if (!(hFind = FindFirstFileA(lpFileName, &findFileData) == INVALID_HANDLE_VALUE)) + if ((hFind = FindFirstFileA(lpFileName, &findFileData) != INVALID_HANDLE_VALUE)) FindClose(hFind); fd->dwFileAttributes = findFileData.dwFileAttributes; @@ -925,7 +925,8 @@ BOOL FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData) fullpath = (char*)malloc(pathlen + namelen + 2); if (fullpath == NULL) { - return INVALID_HANDLE_VALUE; + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; } memcpy(fullpath, pFileSearch->lpPath, pathlen); fullpath[pathlen] = '/'; @@ -935,7 +936,8 @@ BOOL FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData) if (lstat(fullpath, &fileStat) != 0) { free(fullpath); - return INVALID_HANDLE_VALUE; + SetLastError(map_posix_err(errno)); + return FALSE; } free(fullpath); @@ -991,7 +993,7 @@ BOOL FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData) if (!fd) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return INVALID_HANDLE_VALUE; + return FALSE; } if (FindNextFileA(hFindFile, fd))