From 52fab8ba7e2a728e884a06fa80f9e0a0d4938e05 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Sun, 21 Apr 2013 17:53:02 +1000 Subject: [PATCH] Win utf8 treatment for CreateFile. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch from Janne Hyvärinen . --- include/share/win_utf8_io.h | 3 ++- src/share/grabbag/file.c | 4 ++-- src/share/win_utf8_io/win_utf8_io.c | 13 +++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/share/win_utf8_io.h b/include/share/win_utf8_io.h index c0419b2a..9e2cd4e4 100644 --- a/include/share/win_utf8_io.h +++ b/include/share/win_utf8_io.h @@ -10,7 +10,7 @@ extern "C" { #include #include #include - +#include int get_utf8_argv(int *argc, char ***argv); @@ -28,6 +28,7 @@ int rename_utf8(const char *oldname, const char *newname); size_t strlen_utf8(const char *str); int win_get_console_width(void); int print_console(FILE *stream, const wchar_t *text, uint32_t len); +HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/share/grabbag/file.c b/src/share/grabbag/file.c index dd2880cb..a3706f1d 100644 --- a/src/share/grabbag/file.c +++ b/src/share/grabbag/file.c @@ -127,8 +127,8 @@ FLAC__bool grabbag__file_are_same(const char *f1, const char *f2) BY_HANDLE_FILE_INFORMATION info1, info2; HANDLE h1, h2; BOOL ok = 1; - h1 = CreateFile(f1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - h2 = CreateFile(f2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + h1 = CreateFile_utf8(f1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + h2 = CreateFile_utf8(f2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(h1 == INVALID_HANDLE_VALUE || h2 == INVALID_HANDLE_VALUE) ok = 0; ok &= GetFileInformationByHandle(h1, &info1); diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c index b32db3c7..d8736e16 100644 --- a/src/share/win_utf8_io/win_utf8_io.c +++ b/src/share/win_utf8_io/win_utf8_io.c @@ -307,3 +307,16 @@ int rename_utf8(const char *oldname, const char *newname) return ret; } + +HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) +{ + wchar_t *wname; + HANDLE handle = INVALID_HANDLE_VALUE; + + if ((wname = wchar_from_utf8(lpFileName)) != NULL) { + handle = CreateFileW(wname, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); + free(wname); + } + + return handle; +}