From: Daniel Lehman dlehman25@gmail.com
--- dlls/msvcp140/tests/msvcp140.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/dlls/msvcp140/tests/msvcp140.c b/dlls/msvcp140/tests/msvcp140.c index 9c18afd76fc..2abe5643e82 100644 --- a/dlls/msvcp140/tests/msvcp140.c +++ b/dlls/msvcp140/tests/msvcp140.c @@ -269,6 +269,7 @@ typedef enum { static FILE* (__cdecl *p__Fiopen_wchar)(const wchar_t*, int, int); static FILE* (__cdecl *p__Fiopen)(const char*, int, int);
+static unsigned int (__cdecl *p____lc_codepage_func)(void); static char* (__cdecl *p_setlocale)(int, const char*); static int (__cdecl *p_fclose)(FILE*); static int (__cdecl *p__unlink)(const char*); @@ -392,6 +393,7 @@ static BOOL init(void) pCreateSymbolicLinkW = (void*)GetProcAddress(hdll, "CreateSymbolicLinkW");
hdll = GetModuleHandleA("ucrtbase.dll"); + p____lc_codepage_func = (void*)GetProcAddress(hdll, "___lc_codepage_func"); p_setlocale = (void*)GetProcAddress(hdll, "setlocale"); p_fclose = (void*)GetProcAddress(hdll, "fclose"); p__unlink = (void*)GetProcAddress(hdll, "_unlink"); @@ -1717,6 +1719,7 @@ static void test__Fiopen(void) { "Arabic.utf8", "t\xd8\xaa\xda\x86.txt", TRUE }, { "Japanese.utf8", "t\xe3\x82\xaf\xe3\x83\xa4.txt", TRUE }, { "Chinese.utf8", "t\xe4\xb8\x82\xe9\xbd\xab.txt", TRUE }, + { "Japanese", "t\xb8\xd5.txt" }, };
for(i=0; i<ARRAY_SIZE(tests); i++) { @@ -1725,9 +1728,9 @@ static void test__Fiopen(void) continue; }
- ok(MultiByteToWideChar(CP_UTF8, 0, tests[i].path, -1, wpath, MAX_PATH), - "MultiByteToWideChar failed on %s with locale %s: %lx\n", - debugstr_a(tests[i].path), tests[i].loc, GetLastError()); + if(!MultiByteToWideChar(p____lc_codepage_func() == CP_UTF8 ? CP_UTF8 : CP_ACP, + MB_PRECOMPOSED | MB_ERR_INVALID_CHARS, tests[i].path, -1, wpath, MAX_PATH)) + continue;
f = p__Fiopen(tests[i].path, OPENMODE_out, SH_DENYNO); ok(!!f, "failed to create %s with locale %s\n", tests[i].path, tests[i].loc);
From: Daniel Lehman dlehman25@gmail.com
--- dlls/msvcp140/tests/msvcp140.c | 14 +++++------ dlls/msvcrt/file.c | 43 +++++++++++++++++++++++++++------- dlls/ucrtbase/tests/file.c | 14 +++++------ 3 files changed, 47 insertions(+), 24 deletions(-)
diff --git a/dlls/msvcp140/tests/msvcp140.c b/dlls/msvcp140/tests/msvcp140.c index 2abe5643e82..bdde764c39e 100644 --- a/dlls/msvcp140/tests/msvcp140.c +++ b/dlls/msvcp140/tests/msvcp140.c @@ -1711,14 +1711,13 @@ static void test__Fiopen(void) static const struct { const char *loc; const char *path; - int is_todo; } tests[] = { - { "German.utf8", "t\xc3\xa4\xc3\x8f\xc3\xb6\xc3\x9f.txt", TRUE }, - { "Polish.utf8", "t\xc4\x99\xc5\x9b\xc4\x87.txt", TRUE }, - { "Turkish.utf8", "t\xc3\x87\xc4\x9e\xc4\xb1\xc4\xb0\xc5\x9e.txt", TRUE }, - { "Arabic.utf8", "t\xd8\xaa\xda\x86.txt", TRUE }, - { "Japanese.utf8", "t\xe3\x82\xaf\xe3\x83\xa4.txt", TRUE }, - { "Chinese.utf8", "t\xe4\xb8\x82\xe9\xbd\xab.txt", TRUE }, + { "German.utf8", "t\xc3\xa4\xc3\x8f\xc3\xb6\xc3\x9f.txt" }, + { "Polish.utf8", "t\xc4\x99\xc5\x9b\xc4\x87.txt" }, + { "Turkish.utf8", "t\xc3\x87\xc4\x9e\xc4\xb1\xc4\xb0\xc5\x9e.txt" }, + { "Arabic.utf8", "t\xd8\xaa\xda\x86.txt" }, + { "Japanese.utf8", "t\xe3\x82\xaf\xe3\x83\xa4.txt" }, + { "Chinese.utf8", "t\xe4\xb8\x82\xe9\xbd\xab.txt" }, { "Japanese", "t\xb8\xd5.txt" }, };
@@ -1737,7 +1736,6 @@ static void test__Fiopen(void) p_fclose(f);
f = p__Fiopen_wchar(wpath, OPENMODE_in, SH_DENYNO); - todo_wine_if(tests[i].is_todo && GetACP() != CP_UTF8) ok(!!f, "failed to open %s with locale %s\n", wine_dbgstr_w(wpath), tests[i].loc); if(f) p_fclose(f);
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 422e7712660..6d31d40712e 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -34,6 +34,7 @@ #include <sys/utime.h> #include <time.h> #include <limits.h> +#include <locale.h>
#include "windef.h" #include "winbase.h" @@ -547,6 +548,22 @@ static inline FILE* msvcrt_get_file(int i) return &ret->file; }
+/* INTERNAL: Create a wide string from an ascii string */ +wchar_t *msvcrt_wstrdupa_utf8(const char *str) +{ + const unsigned int len = strlen(str) + 1 ; + wchar_t *wstr = malloc(len* sizeof (wchar_t)); + if (!wstr) + return NULL; +#if _MSVCR_VER >= 140 + MultiByteToWideChar(___lc_codepage_func() == CP_UTF8 ? CP_UTF8 : CP_ACP, + MB_PRECOMPOSED,str,len,wstr,len); +#else + MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,str,len,wstr,len); +#endif + return wstr; +} + /* INTERNAL: free a file entry fd */ static void msvcrt_free_fd(int fd) { @@ -1101,12 +1118,22 @@ int CDECL _wchmod(const wchar_t *path, int flags) */ int CDECL _unlink(const char *path) { - TRACE("%s\n", debugstr_a(path)); - if(DeleteFileA(path)) - return 0; - TRACE("failed (%ld)\n", GetLastError()); - msvcrt_set_errno(GetLastError()); - return -1; + wchar_t *pathW; + BOOL ret; + + TRACE("%s\n", debugstr_a(path)); + + if(!(pathW = msvcrt_wstrdupa_utf8(path))) + return -1; + + ret = DeleteFileW(pathW); + free(pathW); + if(ret) + return 0; + + TRACE("failed (%ld)\n", GetLastError()); + msvcrt_set_errno(GetLastError()); + return -1; }
/********************************************************************* @@ -4354,12 +4381,12 @@ FILE * CDECL _fsopen(const char *path, const char *mode, int share) FILE *ret; wchar_t *pathW = NULL, *modeW = NULL;
- if (path && !(pathW = msvcrt_wstrdupa(path))) { + if (path && !(pathW = msvcrt_wstrdupa_utf8(path))) { _invalid_parameter(NULL, NULL, NULL, 0, 0); *_errno() = EINVAL; return NULL; } - if (mode && !(modeW = msvcrt_wstrdupa(mode))) + if (mode && !(modeW = msvcrt_wstrdupa_utf8(mode))) { free(pathW); _invalid_parameter(NULL, NULL, NULL, 0, 0); diff --git a/dlls/ucrtbase/tests/file.c b/dlls/ucrtbase/tests/file.c index 99372a391e3..667de4461c2 100644 --- a/dlls/ucrtbase/tests/file.c +++ b/dlls/ucrtbase/tests/file.c @@ -177,14 +177,13 @@ static void test_fopen(void) static const struct { const char *loc; const char *path; - int is_todo; } tests[] = { - { "German.utf8", "t\xc3\xa4\xc3\x8f\xc3\xb6\xc3\x9f.txt", TRUE }, - { "Polish.utf8", "t\xc4\x99\xc5\x9b\xc4\x87.txt", TRUE }, - { "Turkish.utf8", "t\xc3\x87\xc4\x9e\xc4\xb1\xc4\xb0\xc5\x9e.txt", TRUE }, - { "Arabic.utf8", "t\xd8\xaa\xda\x86.txt", TRUE }, - { "Japanese.utf8", "t\xe3\x82\xaf\xe3\x83\xa4.txt", TRUE }, - { "Chinese.utf8", "t\xe4\xb8\x82\xe9\xbd\xab.txt", TRUE }, + { "German.utf8", "t\xc3\xa4\xc3\x8f\xc3\xb6\xc3\x9f.txt" }, + { "Polish.utf8", "t\xc4\x99\xc5\x9b\xc4\x87.txt" }, + { "Turkish.utf8", "t\xc3\x87\xc4\x9e\xc4\xb1\xc4\xb0\xc5\x9e.txt" }, + { "Arabic.utf8", "t\xd8\xaa\xda\x86.txt" }, + { "Japanese.utf8", "t\xe3\x82\xaf\xe3\x83\xa4.txt" }, + { "Chinese.utf8", "t\xe4\xb8\x82\xe9\xbd\xab.txt" }, { "Japanese", "t\xb8\xd5.txt" },
}; @@ -205,7 +204,6 @@ static void test_fopen(void) fclose(f);
f = _wfsopen(wpath, L"r", SH_DENYNO); - todo_wine_if(tests[i].is_todo && GetACP() != CP_UTF8) ok(!!f, "failed to open %s with locale %s\n", debugstr_a(tests[i].path), tests[i].loc); if(f) fclose(f);
This merge request was closed by Daniel Lehman.