diff options
author | Kirill Gavrilov <gavr.mail@gmail.com> | 2011-04-20 14:36:44 +0300 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2011-04-24 00:05:38 +0300 |
commit | b1ac139d89b9fc55b70ad3411af2f75fe8b17805 (patch) | |
tree | 28ae1bc6fca572e2bb811962f3d381c2fb7af935 /libavformat | |
parent | 9261e6cf3fe579fa02a96761c8e81a77bb3d8b2e (diff) | |
download | ffmpeg-b1ac139d89b9fc55b70ad3411af2f75fe8b17805.tar.gz |
Handle unicode file names on windows
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ö <martin@martin.st>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/os_support.c | 28 | ||||
-rw-r--r-- | libavformat/os_support.h | 5 | ||||
-rw-r--r-- | libavformat/version.h | 2 |
3 files changed, 34 insertions, 1 deletions
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 <windows.h> + +#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 <fcntl.h> #include <unistd.h> diff --git a/libavformat/os_support.h b/libavformat/os_support.h index dc01e6413c..521e9978a2 100644 --- a/libavformat/os_support.h +++ b/libavformat/os_support.h @@ -45,6 +45,11 @@ static inline int is_dos_path(const char *path) return 0; } +#if defined(_WIN32) && !defined(__MINGW32CE__) +int ff_win32_open(const char *filename, int oflag, int pmode); +#define open ff_win32_open +#endif + #if CONFIG_NETWORK #if !HAVE_SOCKLEN_T typedef int socklen_t; diff --git a/libavformat/version.h b/libavformat/version.h index 9041f92626..22b5dc9791 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -25,7 +25,7 @@ #define LIBAVFORMAT_VERSION_MAJOR 53 #define LIBAVFORMAT_VERSION_MINOR 0 -#define LIBAVFORMAT_VERSION_MICRO 2 +#define LIBAVFORMAT_VERSION_MICRO 3 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ |