@matheusbsbs / matheus-bagliano / commits / 20c6788ace
Fork 0

msvc: opendir: do not start the search

compat/mingw.c's readdir expects to be the one that starts the search, and if it isn't, then the first entry will be missing or incorrect. Fix this by removing the call to _findfirst, and initializing dd_handle to INVALID_HANDLE_VALUE. At the same time, make sure we use FindClose instead of _findclose, which is symmetric to readdir's FindFirstFile. Take into account that the find-handle might already be closed by readdir. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Erik Faye-Lund committed Nov 23, 2010 at 19:38 UTC 20c6788aced1237489824db3b25285afed0ad169
1 file changed +3 -7
compat/msvc.c
+3 -7
@@ -16,17 +16,13 @@ DIR *opendir(const char *name)
16 p->dd_name[len] = '/';
17 p->dd_name[len+1] = '*';
18
19 - p->dd_handle = _findfirst(p->dd_name, &p->dd_dta);
20 -
21 - if (p->dd_handle == -1) {
22 - free(p);
23 - return NULL;
24 - }
19 + p->dd_handle = (long)INVALID_HANDLE_VALUE;
20 return p;
21 }
22 int closedir(DIR *dir)
23 {
29 - _findclose(dir->dd_handle);
24 + if (dir->dd_handle != (long)INVALID_HANDLE_VALUE)
25 + FindClose((HANDLE)dir->dd_handle);
26 free(dir);
27 return 0;
28 }