Skip to content

Commit 20c6788

Browse files
kusmagitster
authored andcommitted
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>
1 parent 17194c1 commit 20c6788

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

compat/msvc.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@ DIR *opendir(const char *name)
1616
p->dd_name[len] = '/';
1717
p->dd_name[len+1] = '*';
1818

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;
2520
return p;
2621
}
2722
int closedir(DIR *dir)
2823
{
29-
_findclose(dir->dd_handle);
24+
if (dir->dd_handle != (long)INVALID_HANDLE_VALUE)
25+
FindClose((HANDLE)dir->dd_handle);
3026
free(dir);
3127
return 0;
3228
}

0 commit comments

Comments
 (0)