From: Piotr Caban piotr@codeweavers.com
--- dlls/msvcrt/dir.c | 45 ++++++++++++++++++++++---------------- dlls/ucrtbase/tests/file.c | 13 +++++++++++ 2 files changed, 39 insertions(+), 19 deletions(-)
diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c index 1ba14308f85..257f49d5351 100644 --- a/dlls/msvcrt/dir.c +++ b/dlls/msvcrt/dir.c @@ -387,25 +387,6 @@ intptr_t CDECL _findfirst(const char * fspec, struct _finddata_t* ft) return (intptr_t)hfind; }
-/********************************************************************* - * _findfirst32 (MSVCRT.@) - */ -intptr_t CDECL _findfirst32(const char * fspec, struct _finddata32_t* ft) -{ - WIN32_FIND_DATAA find_data; - HANDLE hfind; - - hfind = FindFirstFileA(fspec, &find_data); - if (hfind == INVALID_HANDLE_VALUE) - { - msvcrt_set_errno(GetLastError()); - return -1; - } - msvcrt_fttofd32(&find_data, ft); - TRACE(":got handle %p\n", hfind); - return (intptr_t)hfind; -} - /********************************************************************* * _wfindfirst (MSVCRT.@) * @@ -448,6 +429,32 @@ intptr_t CDECL _wfindfirst32(const wchar_t * fspec, struct _wfinddata32_t* ft) return (intptr_t)hfind; }
+static int finddata32_wtoa(const struct _wfinddata32_t *wfd, struct _finddata32_t *fd) +{ + fd->attrib = wfd->attrib; + fd->time_create = wfd->time_create; + fd->time_access = wfd->time_access; + fd->time_write = wfd->time_write; + fd->size = wfd->size; + return convert_wcs_to_acp_utf8(wfd->name, fd->name, ARRAY_SIZE(fd->name)); +} + +/********************************************************************* + * _findfirst32 (MSVCRT.@) + */ +intptr_t CDECL _findfirst32(const char *fspec, struct _finddata32_t *ft) +{ + struct _wfinddata32_t wft; + wchar_t *fspecW = NULL; + intptr_t ret; + + if (fspec && !(fspecW = wstrdupa_utf8(fspec))) return -1; + ret = _wfindfirst32(fspecW, &wft); + free(fspecW); + if (!finddata32_wtoa(&wft, ft)) return -1; + return ret; +} + /********************************************************************* * _findfirsti64 (MSVCRT.@) * diff --git a/dlls/ucrtbase/tests/file.c b/dlls/ucrtbase/tests/file.c index 248fdc92dd3..73aa5da0659 100644 --- a/dlls/ucrtbase/tests/file.c +++ b/dlls/ucrtbase/tests/file.c @@ -239,7 +239,9 @@ static void test_utf8(void) const WCHAR dirW[] = L"dir\x0119\x015b\x0107";
char file2[32], buf[256], *p, *q; + struct _finddata32_t fdata32; struct _stat64 stat; + intptr_t hfind; FILE *f; int ret;
@@ -317,6 +319,17 @@ static void test_utf8(void) ok(!memcmp(buf, file, sizeof(file) - 1), "buf = %s\n", debugstr_a(buf)); ok(buf[ARRAY_SIZE(file) - 1] == 'b', "buf = %s\n", debugstr_a(buf));
+ strcpy(buf, file); + strcat(buf, "*"); + fdata32.name[0] = 'x'; + hfind = _findfirst32(buf, &fdata32); + ok(hfind != -1, "_findfirst32 returned %Id, errno %d\n", hfind, errno); + todo_wine_if(!is_lossless_convertion(dir)) + ok(!memcmp(file, fdata32.name, sizeof(file) - 1), "fdata32.name = %s\n", debugstr_a(fdata32.name)); + + ret = _findclose(hfind); + ok(!ret, "_findclose returned %d, errno %d\n", ret, errno); + ret = remove(file2); ok(!ret, "remove returned %d, errno %d\n", ret, errno);