Browse code

Merge commit '9326d64ed1baadd7af60df6bbcc59cf1fefede48'

* commit '9326d64ed1baadd7af60df6bbcc59cf1fefede48':
Share the utf8 to wchar conversion routine between lavf and lavu

Conflicts:
libavformat/os_support.h
libavutil/file_open.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2014/11/27 19:10:26
Showing 3 changed files
... ...
@@ -144,24 +144,7 @@ int ff_poll(struct pollfd *fds, nfds_t numfds, int timeout);
144 144
 #elif defined(_WIN32)
145 145
 #include <stdio.h>
146 146
 #include <windows.h>
147
-#include "libavutil/mem.h"
148
-
149
-static inline int utf8towchar(const char *filename_utf8, wchar_t **filename_w)
150
-{
151
-    int num_chars;
152
-    num_chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename_utf8, -1, NULL, 0);
153
-    if (num_chars <= 0) {
154
-        *filename_w = NULL;
155
-        return 0;
156
-    }
157
-    *filename_w = (wchar_t *)av_mallocz(sizeof(wchar_t) * num_chars);
158
-    if (!*filename_w) {
159
-        errno = ENOMEM;
160
-        return -1;
161
-    }
162
-    MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, *filename_w, num_chars);
163
-    return 0;
164
-}
147
+#include "libavutil/wchar_filename.h"
165 148
 
166 149
 #define DEF_FS_FUNCTION(name, wfunc, afunc)               \
167 150
 static inline int win32_##name(const char *filename_utf8) \
... ...
@@ -37,23 +37,18 @@
37 37
 #include <windows.h>
38 38
 #include <share.h>
39 39
 #include <errno.h>
40
+#include "wchar_filename.h"
40 41
 
41 42
 static int win32_open(const char *filename_utf8, int oflag, int pmode)
42 43
 {
43 44
     int fd;
44
-    int num_chars;
45 45
     wchar_t *filename_w;
46 46
 
47 47
     /* convert UTF-8 to wide chars */
48
-    num_chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename_utf8, -1, NULL, 0);
49
-    if (num_chars <= 0)
50
-        goto fallback;
51
-    filename_w = av_mallocz_array(num_chars, sizeof(wchar_t));
52
-    if (!filename_w) {
53
-        errno = ENOMEM;
48
+    if (utf8towchar(filename_utf8, &filename_w))
54 49
         return -1;
55
-    }
56
-    MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, filename_w, num_chars);
50
+    if (!filename_w)
51
+        goto fallback;
57 52
 
58 53
     fd = _wsopen(filename_w, oflag, SH_DENYNO, pmode);
59 54
     av_freep(&filename_w);
60 55
new file mode 100644
... ...
@@ -0,0 +1,44 @@
0
+/*
1
+ * This file is part of FFmpeg.
2
+ *
3
+ * FFmpeg is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU Lesser General Public
5
+ * License as published by the Free Software Foundation; either
6
+ * version 2.1 of the License, or (at your option) any later version.
7
+ *
8
+ * FFmpeg is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
+ * Lesser General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Lesser General Public
14
+ * License along with FFmpeg; if not, write to the Free Software
15
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+#ifndef AVUTIL_WCHAR_FILENAME_H
19
+#define AVUTIL_WCHAR_FILENAME_H
20
+
21
+#if defined(_WIN32) && !defined(__MINGW32CE__)
22
+#include <windows.h>
23
+#include "mem.h"
24
+
25
+static inline int utf8towchar(const char *filename_utf8, wchar_t **filename_w)
26
+{
27
+    int num_chars;
28
+    num_chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename_utf8, -1, NULL, 0);
29
+    if (num_chars <= 0) {
30
+        *filename_w = NULL;
31
+        return 0;
32
+    }
33
+    *filename_w = (wchar_t *)av_mallocz_array(num_chars, sizeof(wchar_t));
34
+    if (!*filename_w) {
35
+        errno = ENOMEM;
36
+        return -1;
37
+    }
38
+    MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, *filename_w, num_chars);
39
+    return 0;
40
+}
41
+#endif
42
+
43
+#endif /* AVUTIL_WCHAR_FILENAME_H */