[FFmpeg-cvslog] file: Move win32 utf8->wchar open wrapper to libavutil

Martin Storsjö git at videolan.org
Fri Aug 9 08:00:08 CEST 2013


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Thu Aug  8 11:29:57 2013 +0300| [dfc6b5c81491abf7effb97b23af17ccf7adcd132] | committer: Martin Storsjö

file: Move win32 utf8->wchar open wrapper to libavutil

When libavformat was changed to use the new avpriv_open function
in 51eb213d001, this silently bypassed the existing wrapper for
win32. Move the win32 wrapper into libavutil/file.c to make sure
it gets called everywhere (not just in the libavformat case).

This makes sure that non-ascii file names gets opened properly
(where file names internally are stored as utf8, but they get
converted to wchar_t and opened with _wsopen).

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=dfc6b5c81491abf7effb97b23af17ccf7adcd132
---

 libavformat/os_support.c |   40 ----------------------------------------
 libavformat/os_support.h |    5 -----
 libavutil/file.c         |   39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 45 deletions(-)

diff --git a/libavformat/os_support.c b/libavformat/os_support.c
index 2d8a903..4ae5ac1 100644
--- a/libavformat/os_support.c
+++ b/libavformat/os_support.c
@@ -27,46 +27,6 @@
 #include "avformat.h"
 #include "os_support.h"
 
-#if defined(_WIN32) && !defined(__MINGW32CE__)
-#undef open
-#undef lseek
-#undef stat
-#undef fstat
-#include <fcntl.h>
-#include <io.h>
-#include <windows.h>
-#include <share.h>
-#include <errno.h>
-
-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, MB_ERR_INVALID_CHARS, filename_utf8, -1, NULL, 0);
-    if (num_chars <= 0)
-        goto fallback;
-    filename_w = av_mallocz(sizeof(wchar_t) * num_chars);
-    if (!filename_w) {
-        errno = ENOMEM;
-        return -1;
-    }
-    MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, filename_w, num_chars);
-
-    fd = _wsopen(filename_w, oflag, SH_DENYNO, pmode);
-    av_freep(&filename_w);
-
-    if (fd != -1 || (oflag & O_CREAT))
-        return fd;
-
-fallback:
-    /* filename may be be in CP_ACP */
-    return _sopen(filename_utf8, oflag, SH_DENYNO, pmode);
-}
-#endif
-
 #if CONFIG_NETWORK
 #include <fcntl.h>
 #if !HAVE_POLL_H
diff --git a/libavformat/os_support.h b/libavformat/os_support.h
index 39d4cb6..ae8cef7 100644
--- a/libavformat/os_support.h
+++ b/libavformat/os_support.h
@@ -77,11 +77,6 @@ static inline int is_dos_path(const char *path)
 #endif
 #endif
 
-#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/libavutil/file.c b/libavutil/file.c
index 9ce0dc5..cf76a8a 100644
--- a/libavutil/file.c
+++ b/libavutil/file.c
@@ -36,6 +36,45 @@
 #include <windows.h>
 #endif
 
+#if defined(_WIN32) && !defined(__MINGW32CE__)
+#undef open
+#undef lseek
+#undef stat
+#undef fstat
+#include <windows.h>
+#include <share.h>
+#include <errno.h>
+
+static int 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, MB_ERR_INVALID_CHARS, filename_utf8, -1, NULL, 0);
+    if (num_chars <= 0)
+        goto fallback;
+    filename_w = av_mallocz(sizeof(wchar_t) * num_chars);
+    if (!filename_w) {
+        errno = ENOMEM;
+        return -1;
+    }
+    MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, filename_w, num_chars);
+
+    fd = _wsopen(filename_w, oflag, SH_DENYNO, pmode);
+    av_freep(&filename_w);
+
+    if (fd != -1 || (oflag & O_CREAT))
+        return fd;
+
+fallback:
+    /* filename may be be in CP_ACP */
+    return _sopen(filename_utf8, oflag, SH_DENYNO, pmode);
+}
+#define open win32_open
+#endif
+
 int avpriv_open(const char *filename, int flags, ...)
 {
     int fd;



More information about the ffmpeg-cvslog mailing list