From b1ac139d89b9fc55b70ad3411af2f75fe8b17805 Mon Sep 17 00:00:00 2001 From: Kirill Gavrilov Date: Wed, 20 Apr 2011 14:36:44 +0300 Subject: Handle unicode file names on windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All file names should be in UTF-8 within libavformat. This is handled by mapping the open() function to an internal one in os_support.h for windows. fopen() could be overridden in the same way, but if that would be used from ffmpeg.c, it would add a dependency on an ff prefixed internal lavf function. Signed-off-by: Martin Storsjö --- libavformat/os_support.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'libavformat/os_support.c') diff --git a/libavformat/os_support.c b/libavformat/os_support.c index 5a3a1bbfe0..05577b7553 100644 --- a/libavformat/os_support.c +++ b/libavformat/os_support.c @@ -28,6 +28,34 @@ #include "avformat.h" #include "os_support.h" +#if defined(_WIN32) && !defined(__MINGW32CE__) +#include + +#undef open +int ff_win32_open(const char *filename_utf8, int oflag, int pmode) +{ + int fd; + int num_chars; + wchar_t *filename_w; + + /* convert UTF-8 to wide chars */ + num_chars = MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, NULL, 0); + if (num_chars <= 0) + return -1; + filename_w = av_mallocz(sizeof(wchar_t) * num_chars); + MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, filename_w, num_chars); + + fd = _wopen(filename_w, oflag, pmode); + av_freep(&filename_w); + + /* filename maybe be in CP_ACP */ + if (fd == -1 && !(oflag & O_CREAT)) + return open(filename_utf8, oflag, pmode); + + return fd; +} +#endif + #if CONFIG_NETWORK #include #include -- cgit v1.2.3