Browse Source

avutil: add av_fopen_utf8()

fopen() on windows uses UTF-16, we use UTF-8 everywhere, this
function bridges the gap by using avpriv_open()

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Michael Niedermayer 11 years ago
parent
commit
85cabf1ca9
4 changed files with 45 additions and 1 deletions
  1. 3 0
      doc/APIchanges
  2. 7 0
      libavutil/avutil.h
  3. 34 0
      libavutil/file_open.c
  4. 1 1
      libavutil/version.h

+ 3 - 0
doc/APIchanges

@@ -15,6 +15,9 @@ libavutil:     2012-10-22
 
 API changes, most recent first:
 
+2013-11-04 - xxxxxxx - lavu 52.50.100 - avutil.h
+  Add av_fopen_utf8()
+
 2013-08-xx - xxxxxxx - lavu 52.17.0 - avframe.h
   Add AVFrame.flags and AV_FRAME_FLAG_CORRUPT.
 

+ 7 - 0
libavutil/avutil.h

@@ -312,6 +312,13 @@ unsigned av_int_list_length_for_size(unsigned elsize,
 #define av_int_list_length(list, term) \
     av_int_list_length_for_size(sizeof(*(list)), list, term)
 
+/**
+ * Open a file using a UTF-8 filename.
+ * The API of this function matches POSIX fopen(), errors are returned through
+ * errno.
+ */
+FILE *av_fopen_utf8(const char *path, const char *mode);
+
 /**
  * @}
  * @}

+ 34 - 0
libavutil/file_open.c

@@ -93,3 +93,37 @@ int avpriv_open(const char *filename, int flags, ...)
 
     return fd;
 }
+
+FILE *av_fopen_utf8(const char *path, const char *mode)
+{
+    int fd;
+    int access;
+    const char *m = mode;
+
+    switch (*m++) {
+    case 'r': access = O_RDONLY; break;
+    case 'w': access = O_CREAT|O_WRONLY|O_TRUNC; break;
+    case 'a': access = O_CREAT|O_WRONLY|O_APPEND; break;
+    default :
+        errno = EINVAL;
+        return NULL;
+    }
+    while (*m) {
+        if (*m == '+') {
+            access &= ~(O_RDONLY | O_WRONLY);
+            access |= O_RDWR;
+        } else if (*m == 'b') {
+#ifdef O_BINARY
+            access |= O_BINARY;
+#endif
+        } else if (*m) {
+            errno = EINVAL;
+            return NULL;
+        }
+        m++;
+    }
+    fd = avpriv_open(path, access, 0666);
+    if (fd == -1)
+        return NULL;
+    return fdopen(fd, mode);
+}

+ 1 - 1
libavutil/version.h

@@ -75,7 +75,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  52
-#define LIBAVUTIL_VERSION_MINOR  49
+#define LIBAVUTIL_VERSION_MINOR  50
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \