Unverified Commit bdf3369e authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Add Windows UTF8 support

parent 802597c5
......@@ -16,14 +16,16 @@ noinst_HEADERS = src/arch.h \
src/picture.h \
src/resample_sse.h \
src/speex_resampler.h \
src/stack_alloc.h
src/stack_alloc.h \
src/unicode_support.h
libopusenc_la_SOURCES = \
src/ogg_packer.c \
src/opus_header.c \
src/opusenc.c \
src/picture.c \
src/resample.c
src/resample.c \
src/unicode_support.c
libopusenc_la_LIBADD = $(DEPS_LIBS) $(lrintf_lib)
libopusenc_la_LDFLAGS = -no-undefined \
-version-info @OP_LT_CURRENT@:@OP_LT_REVISION@:@OP_LT_AGE@
......
......@@ -42,6 +42,7 @@
#include "speex_resampler.h"
#include "picture.h"
#include "ogg_packer.h"
#include "unicode_support.h"
/* Bump this when we change the ABI. */
#define OPE_ABI_VERSION 0
......@@ -234,7 +235,7 @@ OggOpusEnc *ope_encoder_create_file(const char *path, OggOpusComments *comments,
if (enc == NULL || (error && *error)) {
return NULL;
}
obj->file = fopen(path, "wb");
obj->file = _ope_fopen(path, "wb");
if (!obj->file) {
if (error) *error = OPE_CANNOT_OPEN;
ope_encoder_destroy(enc);
......@@ -695,7 +696,7 @@ int ope_encoder_continue_new_file(OggOpusEnc *enc, const char *path, OggOpusComm
int ret;
struct StdioObject *obj;
if (!(obj = malloc(sizeof(*obj)))) return OPE_ALLOC_FAIL;
obj->file = fopen(path, "wb");
obj->file = _ope_fopen(path, "wb");
if (!obj->file) {
free(obj);
/* By trying to open the file first, we can recover if we can't open it. */
......
......@@ -33,6 +33,7 @@
#include <stdlib.h>
#include <string.h>
#include "picture.h"
#include "unicode_support.h"
static const char BASE64_TABLE[64]={
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
......@@ -262,7 +263,7 @@ char *_ope_parse_picture_specification(const char *filename, int picture_type, c
}
if (description == NULL) description = "";
picture_file=fopen(filename,"rb");
picture_file=_ope_fopen(filename,"rb");
/*Buffer size: 8 static 4-byte fields plus 2 dynamic fields, plus the
file/URL data.
We reserve at least 10 bytes for the media type, in case we still need to
......
/* Copyright (c) 2004-2012 LoRd_MuldeR <mulder2@gmx.de>
File: unicode_support.c
This file was originally part of a patch included with LameXP,
released under the same license as the original audio tools.
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.
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.
*/
#include "unicode_support.h"
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
#include <windows.h>
#include <io.h>
static UINT g_old_output_cp = ((UINT)-1);
static wchar_t *utf8_to_utf16(const char *input)
{
wchar_t *Buffer;
int BuffSize = 0, Result = 0;
BuffSize = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
Buffer = (wchar_t*) malloc(sizeof(wchar_t) * BuffSize);
if(Buffer)
{
Result = MultiByteToWideChar(CP_UTF8, 0, input, -1, Buffer, BuffSize);
}
return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
}
FILE *_ope_fopen(const char *filename_utf8, const char *mode_utf8)
{
FILE *ret = NULL;
wchar_t *filename_utf16 = utf8_to_utf16(filename_utf8);
wchar_t *mode_utf16 = utf8_to_utf16(mode_utf8);
if(filename_utf16 && mode_utf16)
{
ret = _wfopen(filename_utf16, mode_utf16);
}
if(filename_utf16) free(filename_utf16);
if(mode_utf16) free(mode_utf16);
return ret;
}
#else
#include <stdio.h>
FILE *_ope_fopen(const char *filename_utf8, const char *mode_utf8) {
return fopen(filename_utf8, mode_utf8);
}
#endif
/* Copyright (c) 2004-2012 LoRd_MuldeR <mulder2@gmx.de>
File: unicode_support.h
This file was originally part of a patch included with LameXP,
released under the same license as the original audio tools.
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.
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.
*/
#ifndef UNICODE_SUPPORT_H_INCLUDED
#define UNICODE_SUPPORT_H_INCLUDED
#include <stdio.h>
#define WIN_UNICODE 1
FILE *_ope_fopen(const char *filename_utf8, const char *mode_utf8);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment