Commit 5705b4d7 authored by Erik de Castro Lopo's avatar Erik de Castro Lopo

Huge Windows utf8 I/O patch.

Patch from Janne Hyvärinen <cse@sci.fi>.
parent 9b8fdafe
This diff is collapsed.
......@@ -172,6 +172,87 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release (UTF8)|Win32"
OutputDirectory="..\..\..\..\objs\release\bin"
IntermediateDirectory="Release"
ConfigurationType="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="..\..\..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;FLAC__NO_DLL;FLAC__STRINGS_IN_UTF8"
RuntimeLibrary="0"
BufferSecurityCheck="false"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
CompileAs="0"
DisableSpecificWarnings="4267;4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="..\..\..\..\objs\release\lib\libogg_static.lib"
LinkIncremental="1"
IgnoreDefaultLibraryNames="uuid.lib"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
LinkTimeCodeGeneration="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
......
......@@ -172,6 +172,87 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release (UTF8)|Win32"
OutputDirectory="..\..\..\..\objs\release\bin"
IntermediateDirectory="Release"
ConfigurationType="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="..\..\..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;FLAC__NO_DLL;FLAC__STRINGS_IN_UTF8"
RuntimeLibrary="0"
BufferSecurityCheck="false"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
CompileAs="0"
DisableSpecificWarnings="4267;4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="..\..\..\..\objs\release\lib\libogg_static.lib"
LinkIncremental="1"
IgnoreDefaultLibraryNames="uuid.lib"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
LinkTimeCodeGeneration="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
......
......@@ -172,6 +172,87 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release (UTF8)|Win32"
OutputDirectory="..\..\..\..\objs\release\bin"
IntermediateDirectory="Release"
ConfigurationType="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="..\..\..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;FLAC__NO_DLL;FLAC__STRINGS_IN_UTF8"
RuntimeLibrary="0"
BufferSecurityCheck="false"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
CompileAs="0"
DisableSpecificWarnings="4267;4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="..\..\..\..\objs\release\lib\libogg_static.lib"
LinkIncremental="1"
IgnoreDefaultLibraryNames="uuid.lib"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
LinkTimeCodeGeneration="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
......
......@@ -172,6 +172,87 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release (UTF8)|Win32"
OutputDirectory="..\..\..\..\objs\release\bin"
IntermediateDirectory="Release"
ConfigurationType="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="..\..\..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;FLAC__NO_DLL;FLAC__STRINGS_IN_UTF8"
RuntimeLibrary="0"
BufferSecurityCheck="false"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
CompileAs="0"
DisableSpecificWarnings="4267;4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="..\..\..\..\objs\release\lib\libogg_static.lib"
LinkIncremental="1"
IgnoreDefaultLibraryNames="uuid.lib"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
LinkTimeCodeGeneration="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
......
......@@ -141,6 +141,44 @@
# endif
#endif /* defined _MSC_VER */
#ifdef FLAC__STRINGS_IN_UTF8 /* all char* strings are in UTF-8 format. Added to support Unicode files on Windows */
#include "share/utf8_io.h"
#define flac_printf printf_utf8
#define flac_fprintf fprintf_utf8
#define flac_vfprintf vfprintf_utf8
#define flac_fopen fopen_utf8
#define flac_stat _stat64_utf8
#define flac_chmod chmod_utf8
#define flac_utime utime_utf8
#define flac_unlink unlink_utf8
#define flac_rename rename_utf8
#else
#define flac_printf printf
#define flac_fprintf fprintf
#define flac_vfprintf vfprintf
#define flac_fopen fopen
#ifdef _WIN32
#define flac_stat _stat64
#else
#define flac_stat stat
#endif
#define flac_chmod chmod
#define flac_utime utime
#define flac_unlink unlink
#define flac_rename rename
#endif
#ifdef _WIN32
#define _flac_stat _stat64 /* stat struct */
#define flac_fstat _fstat64
#else
#define _flac_stat stat /* stat struct */
#define flac_fstat fstat
#endif
/* FLAC needs to compile and work correctly on systems with a norrmal ISO C99
* snprintf as well as Microsoft Visual Studio which has an non-standards
......
#ifdef FLAC__STRINGS_IN_UTF8
#ifndef flac__utf8_io_h
#define flac__utf8_io_h
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <sys/stat.h>
#include <stdarg.h>
int get_utf8_argv(int *argc, char ***argv);
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 stat_utf8(const char *path, struct stat *buffer);
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);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
#endif
......@@ -217,7 +217,7 @@ FLAC__bool dump_stats(const subframe_stats_t *stats, const char *filename)
const double s1 = stats->stddev, s2 = s1*2, s3 = s1*3, s4 = s1*4, s5 = s1*5, s6 = s1*6;
const double p = stats->buckets[stats->peak_index].count;
outfile = fopen(filename, "w");
outfile = flac_fopen(filename, "w");
if(0 == outfile) {
fprintf(stderr, "ERROR opening %s: %s\n", filename, strerror(errno));
......
......@@ -244,7 +244,7 @@ FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__
d->fout = grabbag__file_get_binary_stdout();
}
else {
if(0 == (d->fout = fopen(outfilename, "wb"))) {
if(0 == (d->fout = flac_fopen(outfilename, "wb"))) {
flac__utils_printf(stderr, 1, "%s: ERROR: can't open output file %s: %s\n", d->inbasefilename, outfilename, strerror(errno));
DecoderSession_destroy(d, /*error_occurred=*/true);
return false;
......@@ -263,7 +263,7 @@ void DecoderSession_destroy(DecoderSession *d, FLAC__bool error_occurred)
if(0 != d->fout && d->fout != stdout) {
fclose(d->fout);
if(error_occurred)
unlink(d->outfilename);
flac_unlink(d->outfilename);
}
}
......@@ -926,7 +926,7 @@ FLAC__bool fixup_iff_headers(DecoderSession *d)
d->format==FORMAT_WAVE64? "Wave64" :
d->format==FORMAT_RF64? "RF64" :
"AIFF";
FILE *f = fopen(d->outfilename, "r+b"); /* stream is positioned at beginning of file */
FILE *f = flac_fopen(d->outfilename, "r+b"); /* stream is positioned at beginning of file */
if(0 == f) {
flac__utils_printf(stderr, 1, "ERROR, couldn't open file %s while fixing up %s chunk size: %s\n", d->outfilename, fmt_desc, strerror(errno));
......
......@@ -1665,7 +1665,7 @@ int EncoderSession_finish_error(EncoderSession *e)
print_verify_error(e);
else if(e->outputfile_opened)
/* only want to delete the file if we opened it; otherwise it could be an existing file and our overwrite failed */
unlink(e->outfilename);
flac_unlink(e->outfilename);
EncoderSession_destroy(e);
......@@ -2562,7 +2562,7 @@ FLAC__bool parse_cuesheet(FLAC__StreamMetadata **cuesheet, const char *cuesheet_
return false;
}
if(0 == (f = fopen(cuesheet_filename, "r"))) {
if(0 == (f = flac_fopen(cuesheet_filename, "r"))) {
flac__utils_printf(stderr, 1, "%s: ERROR opening cuesheet \"%s\" for reading: %s\n", inbasefilename, cuesheet_filename, strerror(errno));
return false;
}
......@@ -2800,9 +2800,9 @@ FLAC__bool read_sane_extended(FILE *f, FLAC__uint32 *val, const char *fn)
FLAC__bool fskip_ahead(FILE *f, FLAC__uint64 offset)
{
static unsigned char dump[8192];
struct stat stb;
struct _flac_stat stb;
if(fstat(fileno(f), &stb) == 0 && (stb.st_mode & S_IFMT) == S_IFREG)
if(flac_fstat(fileno(f), &stb) == 0 && (stb.st_mode & S_IFMT) == S_IFREG)
{
if(fseeko(f, offset, SEEK_CUR) == 0)
return true;
......
......@@ -172,6 +172,87 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release (UTF8)|Win32"
OutputDirectory="..\..\objs\release\bin"
IntermediateDirectory="Release"
ConfigurationType="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
WholeProgramOptimization="true"
AdditionalIncludeDirectories=".;..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;FLAC__HAS_OGG;FLAC__NO_DLL;FLAC__STRINGS_IN_UTF8"
RuntimeLibrary="0"
BufferSecurityCheck="false"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
CompileAs="0"
DisableSpecificWarnings="4267;4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="..\..\objs\release\lib\libogg_static.lib"
LinkIncremental="1"
IgnoreDefaultLibraryNames="uuid.lib"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
LinkTimeCodeGeneration="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
......
......@@ -702,7 +702,7 @@ void flac__foreign_metadata_delete(foreign_metadata_t *fm)
FLAC__bool flac__foreign_metadata_read_from_aiff(foreign_metadata_t *fm, const char *filename, const char **error)
{
FLAC__bool ok;
FILE *f = fopen(filename, "rb");
FILE *f = flac_fopen(filename, "rb");
if(!f) {
if(error) *error = "can't open AIFF file for reading (000)";
return false;
......@@ -715,7 +715,7 @@ FLAC__bool flac__foreign_metadata_read_from_aiff(foreign_metadata_t *fm, const c
FLAC__bool flac__foreign_metadata_read_from_wave(foreign_metadata_t *fm, const char *filename, const char **error)
{
FLAC__bool ok;
FILE *f = fopen(filename, "rb");
FILE *f = flac_fopen(filename, "rb");
if(!f) {
if(error) *error = "can't open WAVE file for reading (000)";
return false;
......@@ -728,7 +728,7 @@ FLAC__bool flac__foreign_metadata_read_from_wave(foreign_metadata_t *fm, const c
FLAC__bool flac__foreign_metadata_read_from_wave64(foreign_metadata_t *fm, const char *filename, const char **error)
{
FLAC__bool ok;
FILE *f = fopen(filename, "rb");
FILE *f = flac_fopen(filename, "rb");
if(!f) {
if(error) *error = "can't open Wave64 file for reading (000)";
return false;
......@@ -752,12 +752,12 @@ FLAC__bool flac__foreign_metadata_write_to_flac(foreign_metadata_t *fm, const ch
FLAC__metadata_simple_iterator_delete(it);
return false;
}
if(0 == (fin = fopen(infilename, "rb"))) {
if(0 == (fin = flac_fopen(infilename, "rb"