diff options
24 files changed, 183 insertions, 312 deletions
diff --git a/include/FLAC++/export.h b/include/FLAC++/export.h index 2d7a8c97..f9b09bc4 100644 --- a/include/FLAC++/export.h +++ b/include/FLAC++/export.h @@ -84,9 +84,9 @@ /* These \#defines will mirror the libtool-based library version number, see * http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning */ -#define FLACPP_API_VERSION_CURRENT 9 +#define FLACPP_API_VERSION_CURRENT 10 #define FLACPP_API_VERSION_REVISION 0 -#define FLACPP_API_VERSION_AGE 3 +#define FLACPP_API_VERSION_AGE 0 /* \} */ diff --git a/include/FLAC/export.h b/include/FLAC/export.h index 40f8cea8..70b200db 100644 --- a/include/FLAC/export.h +++ b/include/FLAC/export.h @@ -84,9 +84,9 @@ /** These \#defines will mirror the libtool-based library version number, see * http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning */ -#define FLAC_API_VERSION_CURRENT 11 +#define FLAC_API_VERSION_CURRENT 12 #define FLAC_API_VERSION_REVISION 0 /**< see above */ -#define FLAC_API_VERSION_AGE 3 /**< see above */ +#define FLAC_API_VERSION_AGE 0 /**< see above */ #ifdef __cplusplus extern "C" { diff --git a/include/FLAC/stream_decoder.h b/include/FLAC/stream_decoder.h index 67be1a24..533ad192 100644 --- a/include/FLAC/stream_decoder.h +++ b/include/FLAC/stream_decoder.h @@ -1280,11 +1280,14 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE( /** Initialize the decoder instance to decode native FLAC files. * * This flavor of initialization sets up the decoder to decode from a plain - * native FLAC file. If POSIX fopen() semantics are not sufficient, (for - * example, with Unicode filenames on Windows), you must use - * FLAC__stream_decoder_init_FILE(), or FLAC__stream_decoder_init_stream() + * native FLAC file. If POSIX fopen() semantics are not sufficient, you must + * use FLAC__stream_decoder_init_FILE(), or FLAC__stream_decoder_init_stream() * and provide callbacks for the I/O. * + * On Windows, filename must be a UTF-8 encoded filename, which libFLAC + * internally translates to a appropriate representation to use with + * _wfopen + * * This function should be called after FLAC__stream_decoder_new() and * FLAC__stream_decoder_set_*() but before any of the * FLAC__stream_decoder_process_*() functions. Will set and return the @@ -1322,11 +1325,14 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file( /** Initialize the decoder instance to decode Ogg FLAC files. * * This flavor of initialization sets up the decoder to decode from a plain - * Ogg FLAC file. If POSIX fopen() semantics are not sufficient, (for - * example, with Unicode filenames on Windows), you must use + * Ogg FLAC file. If POSIX fopen() semantics are not sufficient, you must use * FLAC__stream_decoder_init_ogg_FILE(), or FLAC__stream_decoder_init_ogg_stream() * and provide callbacks for the I/O. * + * On Windows, filename must be a UTF-8 encoded filename, which libFLAC + * internally translates to a appropriate representation to use with + * _wfopen + * * This function should be called after FLAC__stream_decoder_new() and * FLAC__stream_decoder_set_*() but before any of the * FLAC__stream_decoder_process_*() functions. Will set and return the diff --git a/include/FLAC/stream_encoder.h b/include/FLAC/stream_encoder.h index 03c116aa..de66de54 100644 --- a/include/FLAC/stream_encoder.h +++ b/include/FLAC/stream_encoder.h @@ -1657,11 +1657,14 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__ /** Initialize the encoder instance to encode native FLAC files. * * This flavor of initialization sets up the encoder to encode to a plain - * FLAC file. If POSIX fopen() semantics are not sufficient (for example, - * with Unicode filenames on Windows), you must use + * FLAC file. If POSIX fopen() semantics are not sufficient you must use * FLAC__stream_encoder_init_FILE(), or FLAC__stream_encoder_init_stream() * and provide callbacks for the I/O. * + * On Windows, filename must be a UTF-8 encoded filename, which libFLAC + * internally translates to a appropriate representation to use with + * _wfopen + * * This function should be called after FLAC__stream_encoder_new() and * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() * or FLAC__stream_encoder_process_interleaved(). @@ -1689,11 +1692,14 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__Stre /** Initialize the encoder instance to encode Ogg FLAC files. * * This flavor of initialization sets up the encoder to encode to a plain - * Ogg FLAC file. If POSIX fopen() semantics are not sufficient (for example, - * with Unicode filenames on Windows), you must use + * Ogg FLAC file. If POSIX fopen() semantics are not sufficient, you must use * FLAC__stream_encoder_init_ogg_FILE(), or FLAC__stream_encoder_init_ogg_stream() * and provide callbacks for the I/O. * + * On Windows, filename must be a UTF-8 encoded filename, which libFLAC + * internally translates to a appropriate representation to use with + * _wfopen + * * This function should be called after FLAC__stream_encoder_new() and * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() * or FLAC__stream_encoder_process_interleaved(). diff --git a/include/share/compat.h b/include/share/compat.h index f72c209b..e9e522a7 100644 --- a/include/share/compat.h +++ b/include/share/compat.h @@ -147,14 +147,12 @@ #define flac_printf printf_utf8 #define flac_fprintf fprintf_utf8 #define flac_vfprintf vfprintf_utf8 - -#include "share/windows_unicode_filenames.h" -#define flac_fopen flac_internal_fopen_utf8 -#define flac_chmod flac_internal_chmod_utf8 -#define flac_utime flac_internal_utime_utf8 -#define flac_unlink flac_internal_unlink_utf8 -#define flac_rename flac_internal_rename_utf8 -#define flac_stat flac_internal_stat64_utf8 +#define flac_fopen fopen_utf8 +#define flac_chmod chmod_utf8 +#define flac_utime utime_utf8 +#define flac_unlink unlink_utf8 +#define flac_rename rename_utf8 +#define flac_stat stat64_utf8 #else diff --git a/include/share/win_utf8_io.h b/include/share/win_utf8_io.h index 6031b898..3f2a48cc 100644 --- a/include/share/win_utf8_io.h +++ b/include/share/win_utf8_io.h @@ -36,6 +36,9 @@ #include <stdio.h> #include <stdarg.h> +#include <sys/stat.h> +#include <sys/utime.h> +#include "FLAC/ordinals.h" #ifdef __cplusplus extern "C" { @@ -50,6 +53,13 @@ int printf_utf8(const char *format, ...); int fprintf_utf8(FILE *stream, const char *format, ...); int vfprintf_utf8(FILE *stream, const char *format, va_list argptr); +FILE* fopen_utf8(const char *filename, const char *mode); +int stat64_utf8(const char *path, struct __stat64 *buffer); +int chmod_utf8(const char *filename, int pmode); +int utime_utf8(const char *filename, struct utimbuf *times); +int unlink_utf8(const char *filename); +int rename_utf8(const char *oldname, const char *newname); + #include <windows.h> HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); diff --git a/include/share/windows_unicode_filenames.h b/include/share/windows_unicode_filenames.h deleted file mode 100644 index 94cbeb6c..00000000 --- a/include/share/windows_unicode_filenames.h +++ /dev/null @@ -1,66 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef _WIN32 - -#ifndef flac__windows_unicode_filenames_h -#define flac__windows_unicode_filenames_h - -#include <stdio.h> -#include <sys/stat.h> -#include <sys/utime.h> -#include "FLAC/ordinals.h" - -/***** FIXME: KLUDGE: export these syms for flac.exe, metaflac.exe, etc. *****/ -#include "FLAC/export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -FLAC_API void flac_internal_set_utf8_filenames(FLAC__bool flag); -FLAC_API FLAC__bool flac_internal_get_utf8_filenames(void); -#define flac_set_utf8_filenames flac_internal_set_utf8_filenames -#define flac_get_utf8_filenames flac_internal_get_utf8_filenames - -FLAC_API FILE* flac_internal_fopen_utf8(const char *filename, const char *mode); -FLAC_API int flac_internal_stat64_utf8(const char *path, struct __stat64 *buffer); -FLAC_API int flac_internal_chmod_utf8(const char *filename, int pmode); -FLAC_API int flac_internal_utime_utf8(const char *filename, struct utimbuf *times); -FLAC_API int flac_internal_unlink_utf8(const char *filename); -FLAC_API int flac_internal_rename_utf8(const char *oldname, const char *newname); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif -#endif diff --git a/src/libFLAC++/CMakeLists.txt b/src/libFLAC++/CMakeLists.txt index 5098bb9f..81d466a4 100644 --- a/src/libFLAC++/CMakeLists.txt +++ b/src/libFLAC++/CMakeLists.txt @@ -15,8 +15,8 @@ target_include_directories(FLAC++ INTERFACE target_link_libraries(FLAC++ PUBLIC FLAC) if(BUILD_SHARED_LIBS) set_target_properties(FLAC++ PROPERTIES - VERSION 6.3.0 - SOVERSION 6) + VERSION 10.0.0 + SOVERSION 10) if(NOT WIN32) set_target_properties(FLAC++ PROPERTIES CXX_VISIBILITY_PRESET hidden) endif() diff --git a/src/libFLAC++/Makefile.am b/src/libFLAC++/Makefile.am index 4a6919ef..c67a9d04 100644 --- a/src/libFLAC++/Makefile.am +++ b/src/libFLAC++/Makefile.am @@ -56,7 +56,7 @@ libFLAC___sources = \ stream_encoder.cpp # see 'http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning' for numbering convention -libFLAC___la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-info 9:0:3 +libFLAC___la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-info 10:0:0 libFLAC___la_LIBADD = ../libFLAC/libFLAC.la libFLAC___la_SOURCES = $(libFLAC___sources) diff --git a/src/libFLAC/CMakeLists.txt b/src/libFLAC/CMakeLists.txt index 56a63452..3ba57398 100644 --- a/src/libFLAC/CMakeLists.txt +++ b/src/libFLAC/CMakeLists.txt @@ -91,8 +91,8 @@ add_library(FLAC stream_encoder_intrin_avx2.c stream_encoder_framing.c window.c - $<$<BOOL:${WIN32}>:../../include/share/windows_unicode_filenames.h> - $<$<BOOL:${WIN32}>:windows_unicode_filenames.c> + $<$<BOOL:${WIN32}>:../../include/share/win_utf8_io.h> + $<$<BOOL:${WIN32}>:../share/win_utf8_io/win_utf8_io.c> $<$<BOOL:${OGG_FOUND}>:ogg_decoder_aspect.c> $<$<BOOL:${OGG_FOUND}>:ogg_encoder_aspect.c> $<$<BOOL:${OGG_FOUND}>:ogg_helper.c> @@ -117,8 +117,8 @@ if(TARGET Ogg::ogg) endif() if(BUILD_SHARED_LIBS) set_target_properties(FLAC PROPERTIES - VERSION 8.3.0 - SOVERSION 8) + VERSION 12.0.0 + SOVERSION 12) if(NOT WIN32) set_target_properties(FLAC PROPERTIES C_VISIBILITY_PRESET hidden) endif() diff --git a/src/libFLAC/Makefile.am b/src/libFLAC/Makefile.am index da561f2a..c0e42a5b 100644 --- a/src/libFLAC/Makefile.am +++ b/src/libFLAC/Makefile.am @@ -88,7 +88,7 @@ EXTRA_DIST = \ deduplication/lpc_compute_autocorrelation_intrin_neon.c if OS_IS_WINDOWS -windows_unicode_compat = windows_unicode_filenames.c +windows_unicode_compat = ../share/win_utf8_io/win_utf8_io.c endif if FLaC__HAS_OGG @@ -100,7 +100,7 @@ extra_ogg_sources = \ endif # see 'http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning' for numbering convention -libFLAC_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-info 11:0:3 $(LOCAL_EXTRA_LDFLAGS) +libFLAC_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-info 12:0:0 $(LOCAL_EXTRA_LDFLAGS) libFLAC_sources = \ bitmath.c \ diff --git a/src/libFLAC/Makefile.lite b/src/libFLAC/Makefile.lite index 9e96f9f1..6f95092e 100644 --- a/src/libFLAC/Makefile.lite +++ b/src/libFLAC/Makefile.lite @@ -42,7 +42,7 @@ else endif ifeq ($(findstring Windows,$(OS)),Windows) - WIN_UNICODE_COMPAT = windows_unicode_filenames.c + WIN_UNICODE_COMPAT = ../share/win_utf8_io/win_utf8_io.c endif LIB_NAME = libFLAC diff --git a/src/libFLAC/libFLAC_dynamic.vcproj b/src/libFLAC/libFLAC_dynamic.vcproj index 0bd5f084..7d042cf6 100644 --- a/src/libFLAC/libFLAC_dynamic.vcproj +++ b/src/libFLAC/libFLAC_dynamic.vcproj @@ -406,7 +406,7 @@ >
</File>
<File
- RelativePath=".\windows_unicode_filenames.c"
+ RelativePath="..\share\win_utf8_io\win_utf8_io.c"
>
</File>
</Filter>
@@ -474,7 +474,7 @@ >
</File>
<File
- RelativePath="..\..\include\share\windows_unicode_filenames.h"
+ RelativePath="..\..\include\share\win_utf8_io.h"
>
</File>
</Filter>
diff --git a/src/libFLAC/libFLAC_dynamic.vcxproj b/src/libFLAC/libFLAC_dynamic.vcxproj index 97f7b750..7bc51026 100644 --- a/src/libFLAC/libFLAC_dynamic.vcxproj +++ b/src/libFLAC/libFLAC_dynamic.vcxproj @@ -190,7 +190,7 @@ <ClInclude Include="..\..\include\share\macros.h" />
<ClInclude Include="..\..\include\share\private.h" />
<ClInclude Include="..\..\include\share\safe_str.h" />
- <ClInclude Include="..\..\include\share\windows_unicode_filenames.h" />
+ <ClInclude Include="..\..\include\share\win_utf8_io.h" />
<ClInclude Include="ia32\nasm.h" />
<ClInclude Include="include\private\all.h" />
<ClInclude Include="include\private\bitmath.h" />
@@ -256,7 +256,7 @@ <ClCompile Include="stream_encoder_intrin_sse2.c" />
<ClCompile Include="stream_encoder_intrin_ssse3.c" />
<ClCompile Include="window.c" />
- <ClCompile Include="windows_unicode_filenames.c" />
+ <ClCompile Include="..\share\win_utf8_io\win_utf8_io.c" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="ia32\cpu_asm.nasm">
diff --git a/src/libFLAC/libFLAC_dynamic.vcxproj.filters b/src/libFLAC/libFLAC_dynamic.vcxproj.filters index af105da4..eed190a2 100644 --- a/src/libFLAC/libFLAC_dynamic.vcxproj.filters +++ b/src/libFLAC/libFLAC_dynamic.vcxproj.filters @@ -131,7 +131,7 @@ <ClInclude Include="..\..\include\share\safe_str.h">
<Filter>Public Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\..\include\share\windows_unicode_filenames.h">
+ <ClInclude Include="..\..\include\share\win_utf8_io.h">
<Filter>Public Header Files</Filter>
</ClInclude>
</ItemGroup>
@@ -223,7 +223,7 @@ <ClCompile Include="window.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="windows_unicode_filenames.c">
+ <ClCompile Include="..\share\win_utf8_io\win_utf8_io.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
diff --git a/src/libFLAC/libFLAC_static.vcproj b/src/libFLAC/libFLAC_static.vcproj index 38e597be..db90a4f7 100644 --- a/src/libFLAC/libFLAC_static.vcproj +++ b/src/libFLAC/libFLAC_static.vcproj @@ -321,7 +321,7 @@ >
</File>
<File
- RelativePath="..\..\include\share\windows_unicode_filenames.h"
+ RelativePath="..\..\include\share\win_utf8_io.h"
>
</File>
</Filter>
@@ -447,7 +447,7 @@ >
</File>
<File
- RelativePath=".\windows_unicode_filenames.c"
+ RelativePath="..\share\win_utf8_io\win_utf8_io.c"
>
</File>
</Filter>
diff --git a/src/libFLAC/libFLAC_static.vcxproj b/src/libFLAC/libFLAC_static.vcxproj index 063c3e73..2d6df967 100644 --- a/src/libFLAC/libFLAC_static.vcxproj +++ b/src/libFLAC/libFLAC_static.vcxproj @@ -150,7 +150,7 @@ <ClInclude Include="..\..\include\share\macros.h" />
<ClInclude Include="..\..\include\share\private.h" />
<ClInclude Include="..\..\include\share\safe_str.h" />
- <ClInclude Include="..\..\include\share\windows_unicode_filenames.h" />
+ <ClInclude Include="..\..\include\share\win_utf8_io.h" />
<ClInclude Include="ia32\nasm.h" />
<ClInclude Include="include\private\all.h" />
<ClInclude Include="include\private\bitmath.h" />
@@ -216,7 +216,7 @@ <ClCompile Include="stream_encoder_intrin_sse2.c" />
<ClCompile Include="stream_encoder_intrin_ssse3.c" />
<ClCompile Include="window.c" />
- <ClCompile Include="windows_unicode_filenames.c" />
+ <ClCompile Include="..\share\win_utf8_io\win_utf8_io.c" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="ia32\cpu_asm.nasm">
diff --git a/src/libFLAC/libFLAC_static.vcxproj.filters b/src/libFLAC/libFLAC_static.vcxproj.filters index 492e2e80..b49b8497 100644 --- a/src/libFLAC/libFLAC_static.vcxproj.filters +++ b/src/libFLAC/libFLAC_static.vcxproj.filters @@ -131,7 +131,7 @@ <ClInclude Include="..\..\include\share\safe_str.h">
<Filter>Public Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\..\include\share\windows_unicode_filenames.h">
+ <ClInclude Include="..\..\include\share\win_utf8_io.h">
<Filter>Public Header Files</Filter>
</ClInclude>
</ItemGroup>
@@ -223,7 +223,7 @@ <ClCompile Include="window.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="windows_unicode_filenames.c">
+ <ClCompile Include="..\share\win_utf8_io\win_utf8_io.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
diff --git a/src/libFLAC/windows_unicode_filenames.c b/src/libFLAC/windows_unicode_filenames.c deleted file mode 100644 index bf3bfe16..00000000 --- a/src/libFLAC/windows_unicode_filenames.c +++ /dev/null @@ -1,187 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <io.h> -#include <windows.h> -#include "share/windows_unicode_filenames.h" - -/*** FIXME: KLUDGE: export these syms for flac.exe, metaflac.exe, etc. ***/ - -/* 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; -} - - -static FLAC__bool utf8_filenames = false; - - -FLAC_API void flac_internal_set_utf8_filenames(FLAC__bool flag) -{ - utf8_filenames = flag ? true : false; -} - -FLAC_API FLAC__bool flac_internal_get_utf8_filenames(void) -{ - return utf8_filenames; -} - -/* file functions */ - -FLAC_API FILE* flac_internal_fopen_utf8(const char *filename, const char *mode) -{ - if (!utf8_filenames) { - return fopen(filename, mode); - } else { - wchar_t *wname = NULL; - wchar_t *wmode = NULL; - FILE *f = NULL; - - do { - if (!(wname = wchar_from_utf8(filename))) break; - if (!(wmode = wchar_from_utf8(mode))) break; - f = _wfopen(wname, wmode); - } while(0); - - free(wname); - free(wmode); - - return f; - } -} - -FLAC_API int flac_internal_stat64_utf8(const char *path, struct __stat64 *buffer) -{ - if (!utf8_filenames) { - return _stat64(path, buffer); - } else { - wchar_t *wpath; - int ret; - - if (!(wpath = wchar_from_utf8(path))) return -1; - ret = _wstat64(wpath, buffer); - free(wpath); - - return ret; - } -} - -FLAC_API int flac_internal_chmod_utf8(const char *filename, int pmode) -{ - if (!utf8_filenames) { - return _chmod(filename, pmode); - } else { - wchar_t *wname; - int ret; - - if (!(wname = wchar_from_utf8(filename))) return -1; - ret = _wchmod(wname, pmode); - free(wname); - - return ret; - } -} - -FLAC_API int flac_internal_utime_utf8(const char *filename, struct utimbuf *times) -{ - if (!utf8_filenames) { - return utime(filename, times); - } else { - wchar_t *wname; - struct __utimbuf64 ut; - int ret; - - if (!(wname = wchar_from_utf8(filename))) return -1; - ut.actime = times->actime; - ut.modtime = times->modtime; - ret = _wutime64(wname, &ut); - free(wname); - - return ret; - } -} - -FLAC_API int flac_internal_unlink_utf8(const char *filename) -{ - if (!utf8_filenames) { - return _unlink(filename); - } else { - wchar_t *wname; - int ret; - - if (!(wname = wchar_from_utf8(filename))) return -1; - ret = _wunlink(wname); - free(wname); - - return ret; - } -} - -FLAC_API int flac_internal_rename_utf8(const char *oldname, const char *newname) -{ - if (!utf8_filenames) { - return rename(oldname, newname); - } else { - wchar_t *wold = NULL; - wchar_t *wnew = NULL; - int ret = -1; - - do { - if (!(wold = wchar_from_utf8(oldname))) break; - if (!(wnew = wchar_from_utf8(newname))) break; - ret = _wrename(wold, wnew); - } while(0); - - free(wold); - free(wnew); - - return ret; - } -} diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c index bbb6a74a..3b0b4aab 100644 --- a/src/share/win_utf8_io/win_utf8_io.c +++ b/src/share/win_utf8_io/win_utf8_io.c @@ -33,9 +33,9 @@ # include <config.h> #endif +#include <io.h> #include <windows.h> #include "share/win_utf8_io.h" -#include "share/windows_unicode_filenames.h" #define UTF8_BUFFER_SIZE 32768 @@ -137,7 +137,6 @@ int get_utf8_argv(int *argc, char ***argv) FreeLibrary(handle); /* do not free it when wargv or wenv are still in use */ if (ret == 0) { - flac_set_utf8_filenames(true); *argc = wargc; *argv = utf8argv; } else { @@ -152,19 +151,15 @@ int get_utf8_argv(int *argc, char ***argv) /* similar to CreateFileW but accepts UTF-8 encoded lpFileName */ HANDLE WINAPI 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); - } + wchar_t *wname; + HANDLE handle = INVALID_HANDLE_VALUE; - return handle; + if ((wname = wchar_from_utf8(lpFileName)) != NULL) { + handle = CreateFileW(wname, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); + free(wname); } + + return handle; } /* return number of characters in the UTF-8 string */ @@ -269,3 +264,92 @@ int vfprintf_utf8(FILE *stream, const char *format, va_list argptr) return ret; } + +/* file functions */ + +FILE* fopen_utf8(const char *filename, const char *mode) +{ + wchar_t *wname = NULL; + wchar_t *wmode = NULL; + FILE *f = NULL; + + do { + if (!(wname = wchar_from_utf8(filename))) break; + if (!(wmode = wchar_from_utf8(mode))) break; + f = _wfopen(wname, wmode); + } while(0); + + free(wname); + free(wmode); + + return f; +} + +int stat64_utf8(const char *path, struct __stat64 *buffer) +{ + wchar_t *wpath; + int ret; + + if (!(wpath = wchar_from_utf8(path))) return -1; + ret = _wstat64(wpath, buffer); + free(wpath); + + return ret; +} + +int chmod_utf8(const char *filename, int pmode) +{ + wchar_t *wname; + int ret; + + if (!(wname = wchar_from_utf8(filename))) return -1; + ret = _wchmod(wname, pmode); + free(wname); + + return ret; +} + +int utime_utf8(const char *filename, struct utimbuf *times) +{ + wchar_t *wname; + struct __utimbuf64 ut; + int ret; + + if (!(wname = wchar_from_utf8(filename))) return -1; + ut.actime = times->actime; + ut.modtime = times->modtime; + ret = _wutime64(wname, &ut); + free(wname); + + return ret; +} + +int unlink_utf8(const char *filename) +{ + wchar_t *wname; + int ret; + + if (!(wname = wchar_from_utf8(filename))) return -1; + ret = _wunlink(wname); + free(wname); + + return ret; +} + +int rename_utf8(const char *oldname, const char *newname) +{ + wchar_t *wold = NULL; + wchar_t *wnew = NULL; + int ret = -1; + + do { + if (!(wold = wchar_from_utf8(oldname))) break; + if (!(wnew = wchar_from_utf8(newname))) break; + ret = _wrename(wold, wnew); + } while(0); + + free(wold); + free(wnew); + + return ret; +} diff --git a/src/test_grabbag/cuesheet/Makefile.am b/src/test_grabbag/cuesheet/Makefile.am index 6b88be4b..f9f252e5 100644 --- a/src/test_grabbag/cuesheet/Makefile.am +++ b/src/test_grabbag/cuesheet/Makefile.am @@ -27,9 +27,15 @@ AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include check_PROGRAMS = test_cuesheet test_cuesheet_SOURCES = \ main.c + +if OS_IS_WINDOWS +win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la +endif + test_cuesheet_LDADD = \ $(top_builddir)/src/share/grabbag/libgrabbag.la \ $(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \ - $(top_builddir)/src/libFLAC/libFLAC.la + $(top_builddir)/src/libFLAC/libFLAC.la \ + $(win_utf8_lib) CLEANFILES = test_cuesheet.exe diff --git a/src/test_grabbag/cuesheet/Makefile.lite b/src/test_grabbag/cuesheet/Makefile.lite index e66d10b6..8c7cab81 100644 --- a/src/test_grabbag/cuesheet/Makefile.lite +++ b/src/test_grabbag/cuesheet/Makefile.lite @@ -32,7 +32,11 @@ INCLUDES = -I./include -I$(topdir)/include ifeq ($(OS),Darwin) EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libreplaygain_analysis.a $(libdir)/libFLAC.a $(OGG_EXPLICIT_LIBS) -lm else - LIBS = -lgrabbag -lreplaygain_analysis -lFLAC $(OGG_LIBS) -lm +ifeq ($(findstring Windows,$(OS)),Windows) + LIBS = -lgrabbag -lreplaygain_analysis -lFLAC -lwin_utf8_io $(OGG_LIBS) -lm +else + LIBS = -lgrabbag -lreplaygain_analysis -lFLAC -lgrabbag $(OGG_LIBS) -lm +endif endif SRCS_C = \ diff --git a/src/test_seeking/Makefile.am b/src/test_seeking/Makefile.am index a42d78d5..5cd4c090 100644 --- a/src/test_seeking/Makefile.am +++ b/src/test_seeking/Makefile.am @@ -28,8 +28,14 @@ AM_CFLAGS = @OGG_CFLAGS@ AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include check_PROGRAMS = test_seeking + +if OS_IS_WINDOWS +win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la +endif + test_seeking_LDADD = \ - $(top_builddir)/src/libFLAC/libFLAC.la + $(top_builddir)/src/libFLAC/libFLAC.la \ + $(win_utf8_lib) test_seeking_SOURCES = \ main.c diff --git a/src/test_seeking/Makefile.lite b/src/test_seeking/Makefile.lite index 4c64540c..101fecaa 100644 --- a/src/test_seeking/Makefile.lite +++ b/src/test_seeking/Makefile.lite @@ -32,8 +32,12 @@ INCLUDES = -I../libFLAC/include -I$(topdir)/include ifeq ($(OS),Darwin) EXPLICIT_LIBS = $(libdir)/libFLAC.a $(OGG_EXPLICIT_LIBS) -lm else +ifeq ($(findstring Windows,$(OS)),Windows) + LIBS = -lFLAC -lwin_utf8_io $(OGG_LIBS) -lm +else LIBS = -lFLAC $(OGG_LIBS) -lm endif +endif SRCS_C = \ main.c |