]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/os_support.c
asv1: use av_fast_padded_malloc()
[ffmpeg] / libavformat / os_support.c
index 5a3a1bbfe014a5930be4539fa88c1123d0991194..889a005eebbdd36201b7a528aa5654adb40bdfd8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Various utilities for ffmpeg system
+ * various OS-feature replacement utilities
  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
  * copyright (c) 2002 Francois Revol
  *
 
 /* needed by inet_aton() */
 #define _SVID_SOURCE
-#define _DARWIN_C_SOURCE
 
 #include "config.h"
 #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>
@@ -44,7 +71,6 @@
 
 #if !HAVE_INET_ATON
 #include <stdlib.h>
-#include <strings.h>
 
 int ff_inet_aton (const char * str, struct in_addr * add)
 {