diff options
author | lvqcl <lvqcl.mail@gmail.com> | 2018-08-25 10:23:39 +0300 |
---|---|---|
committer | Erik de Castro Lopo <erikd@mega-nerd.com> | 2018-08-25 18:55:30 +1000 |
commit | edfbe3cf194768af2f4c3cfd5cb5a6a273f63964 (patch) | |
tree | cf27f168aa05a39f987f26800d333ddcd2c5fc33 /src/share/grabbag | |
parent | cdb030cd3749b4547399a049ce3cae5e974ccd48 (diff) | |
download | flac-edfbe3cf194768af2f4c3cfd5cb5a6a273f63964.tar.gz |
Move CreateFile_utf8 function to a more logical place
Diffstat (limited to 'src/share/grabbag')
-rw-r--r-- | src/share/grabbag/file.c | 51 | ||||
-rw-r--r-- | src/share/grabbag/grabbag_static.vcxproj | 4 |
2 files changed, 12 insertions, 43 deletions
diff --git a/src/share/grabbag/file.c b/src/share/grabbag/file.c index a7b2b62e..2c67bebf 100644 --- a/src/share/grabbag/file.c +++ b/src/share/grabbag/file.c @@ -41,7 +41,13 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> /* for strrchr() */ +#if defined _WIN32 && !defined __CYGWIN__ +// for GetFileInformationByHandle() etc +#include <windows.h> +#include <winbase.h> +#endif #include "share/grabbag.h" +#include "share/compat.h" void grabbag__file_copy_metadata(const char *srcpath, const char *destpath) @@ -123,8 +129,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 = grabbag__CreateFile_utf8(f1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - h2 = grabbag__CreateFile_utf8(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); @@ -180,44 +186,3 @@ FILE *grabbag__file_get_binary_stdout(void) return stdout; } - -#if defined _WIN32 && !defined __CYGWIN__ - -/* convert UTF-8 back to WCHAR. Caller is responsible for freeing memory */ -static wchar_t *wchar_from_utf8(const char *str) -{ - wchar_t *widestr; - int len; - - if (!str) - return NULL; - if ((len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0)) == 0) - return NULL; - if ((widestr = (wchar_t *)malloc(len*sizeof(wchar_t))) == NULL) - return NULL; - if (MultiByteToWideChar(CP_UTF8, 0, str, -1, widestr, len) == 0) { - free(widestr); - widestr = NULL; - } - - return widestr; -} - -HANDLE WINAPI grabbag__CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) -{ - if (!flac_internal_get_utf8_filenames()) { - return CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); - } else { - 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; - } -} - -#endif diff --git a/src/share/grabbag/grabbag_static.vcxproj b/src/share/grabbag/grabbag_static.vcxproj index 8e7b6fde..8ae6a28f 100644 --- a/src/share/grabbag/grabbag_static.vcxproj +++ b/src/share/grabbag/grabbag_static.vcxproj @@ -154,6 +154,10 @@ <Project>{4cefbc89-c215-11db-8314-0800200c9a66}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
+ <ProjectReference Include="..\win_utf8_io\win_utf8_io_static.vcxproj">
+ <Project>{4cefbe02-c215-11db-8314-0800200c9a66}</Project>
+ <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
+ </ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
|