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);