Alexandre Julliard : kernel32: Close the directory handle in FindNextFile as soon as we reach the end of the directory .

Alexandre Julliard julliard at wine.codeweavers.com
Fri Oct 27 05:49:25 CDT 2006


Module: wine
Branch: master
Commit: 5e0823056898524321458a88e0d6937007d0b0bf
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=5e0823056898524321458a88e0d6937007d0b0bf

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Oct 27 12:27:33 2006 +0200

kernel32: Close the directory handle in FindNextFile as soon as we reach the end of the directory.

---

 dlls/kernel32/file.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/dlls/kernel32/file.c b/dlls/kernel32/file.c
index b5e58e0..15dd719 100644
--- a/dlls/kernel32/file.c
+++ b/dlls/kernel32/file.c
@@ -1546,6 +1546,7 @@ HANDLE WINAPI FindFirstFileExW( LPCWSTR
                                 LPVOID data, FINDEX_SEARCH_OPS search_op,
                                 LPVOID filter, DWORD flags)
 {
+    static const WCHAR wildcardsW[] = { '*','?',0 };
     WCHAR *mask, *p;
     FIND_FIRST_INFO *info = NULL;
     UNICODE_STRING nt_name;
@@ -1637,6 +1638,12 @@ HANDLE WINAPI FindFirstFileExW( LPCWSTR
         SetLastError( ERROR_FILE_NOT_FOUND );
         return INVALID_HANDLE_VALUE;
     }
+    if (!strpbrkW( info->mask.Buffer, wildcardsW ))
+    {
+        /* we can't find two files with the same name */
+        CloseHandle( info->handle );
+        info->handle = 0;
+    }
     return (HANDLE)info;
 
 error:
@@ -1671,7 +1678,8 @@ BOOL WINAPI FindNextFileW( HANDLE handle
 
     RtlEnterCriticalSection( &info->cs );
 
-    for (;;)
+    if (!info->handle) SetLastError( ERROR_NO_MORE_FILES );
+    else for (;;)
     {
         if (info->data_pos >= info->data_len)  /* need to read some more data */
         {
@@ -1682,6 +1690,11 @@ BOOL WINAPI FindNextFileW( HANDLE handle
             if (io.u.Status)
             {
                 SetLastError( RtlNtStatusToDosError( io.u.Status ) );
+                if (io.u.Status == STATUS_NO_MORE_FILES)
+                {
+                    CloseHandle( info->handle );
+                    info->handle = 0;
+                }
                 break;
             }
             info->data_len = io.Information;




More information about the wine-cvs mailing list