summaryrefslogtreecommitdiff
path: root/libavformat/os_support.c
diff options
context:
space:
mode:
authorKirill Gavrilov <gavr.mail@gmail.com>2011-04-20 14:36:44 +0300
committerMartin Storsjö <martin@martin.st>2011-04-24 00:05:38 +0300
commitb1ac139d89b9fc55b70ad3411af2f75fe8b17805 (patch)
tree28ae1bc6fca572e2bb811962f3d381c2fb7af935 /libavformat/os_support.c
parent9261e6cf3fe579fa02a96761c8e81a77bb3d8b2e (diff)
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/os_support.c')
-rw-r--r--libavformat/os_support.c28
1 files changed, 28 insertions, 0 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>