From: Piotr Caban piotr@codeweavers.com
--- dlls/msvcrt/dir.c | 47 ++++++++++++++++++++++---------------- dlls/ucrtbase/tests/file.c | 11 +++++++++ 2 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c index 0448a2a8523..f5d95f1217e 100644 --- a/dlls/msvcrt/dir.c +++ b/dlls/msvcrt/dir.c @@ -457,45 +457,52 @@ intptr_t CDECL _findfirsti64(const char * fspec, struct _finddatai64_t* ft) }
/********************************************************************* - * _findfirst64 (MSVCRT.@) + * _wfindfirst64 (MSVCRT.@) * - * 64-bit version of _findfirst. + * Unicode version of _findfirst64. */ -intptr_t CDECL _findfirst64(const char * fspec, struct _finddata64_t* ft) +intptr_t CDECL _wfindfirst64(const wchar_t * fspec, struct _wfinddata64_t* ft) { - WIN32_FIND_DATAA find_data; + WIN32_FIND_DATAW find_data; HANDLE hfind;
- hfind = FindFirstFileA(fspec, &find_data); + hfind = FindFirstFileW(fspec, &find_data); if (hfind == INVALID_HANDLE_VALUE) { msvcrt_set_errno(GetLastError()); return -1; } - msvcrt_fttofd64(&find_data,ft); + msvcrt_wfttofd64(&find_data,ft); TRACE(":got handle %p\n",hfind); return (intptr_t)hfind; }
+static int finddata64_wtoa(const struct _wfinddata64_t *wfd, struct _finddata64_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)); +} + /********************************************************************* - * _wfindfirst64 (MSVCRT.@) + * _findfirst64 (MSVCRT.@) * - * Unicode version of _findfirst64. + * 64-bit version of _findfirst. */ -intptr_t CDECL _wfindfirst64(const wchar_t * fspec, struct _wfinddata64_t* ft) +intptr_t CDECL _findfirst64(const char *fspec, struct _finddata64_t *ft) { - WIN32_FIND_DATAW find_data; - HANDLE hfind; + struct _wfinddata64_t wft; + wchar_t *fspecW = NULL; + intptr_t ret;
- hfind = FindFirstFileW(fspec, &find_data); - if (hfind == INVALID_HANDLE_VALUE) - { - msvcrt_set_errno(GetLastError()); - return -1; - } - msvcrt_wfttofd64(&find_data,ft); - TRACE(":got handle %p\n",hfind); - return (intptr_t)hfind; + if (fspec && !(fspecW = wstrdupa_utf8(fspec))) return -1; + ret = _wfindfirst64(fspecW, &wft); + free(fspecW); + if (!finddata64_wtoa(&wft, ft)) return -1; + return ret; }
/********************************************************************* diff --git a/dlls/ucrtbase/tests/file.c b/dlls/ucrtbase/tests/file.c index 1e2a141260a..f050a0e47e6 100644 --- a/dlls/ucrtbase/tests/file.c +++ b/dlls/ucrtbase/tests/file.c @@ -240,6 +240,7 @@ static void test_utf8(void)
char file2[32], buf[256], *p, *q; struct _finddata32_t fdata32; + struct _finddata64_t fdata64; struct _stat64 stat; intptr_t hfind; FILE *f; @@ -336,6 +337,16 @@ static void test_utf8(void) ok(!ret, "_findclose returned %d, errno %d\n", ret, errno);
+ strcpy(buf, file); + strcat(buf, "*"); + fdata64.name[0] = 'x'; + hfind = _findfirst64(buf, &fdata64); + ok(hfind != -1, "_findfirst64 returned %Id, errno %d\n", hfind, errno); + todo_wine_if(!is_lossless_convertion(dir)) + ok(!memcmp(file, fdata64.name, sizeof(file) - 1), "fdata64.name = %s\n", debugstr_a(fdata64.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);