History

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()

Michael Niedermayer committed 13 years ago

Commit 85cabf11 parent d0ac6074 files · +45 −1Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavutil/avutil.h +7 −0
  3. libavutil/file_open.c +34 −0
  4. libavutil/version.h +1 −1
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2012-10-22 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2013-11-04 - xxxxxxx - lavu 52.50.100 - avutil.h
19+ Add av_fopen_utf8()
20+
1821 2013-08-xx - xxxxxxx - lavu 52.17.0 - avframe.h
1922 Add AVFrame.flags and AV_FRAME_FLAG_CORRUPT.
2023
libavutil/avutil.h+7−0
@@ -312,6 +312,13 @@ unsigned av_int_list_length_for_size(unsigned elsize, · 311 unmodified lines
312312 #define av_int_list_length(list, term) \
313313 av_int_list_length_for_size(sizeof(*(list)), list, term)
314314
315+/**
316+ * Open a file using a UTF-8 filename.
317+ * The API of this function matches POSIX fopen(), errors are returned through
318+ * errno.
319+ */
320+FILE *av_fopen_utf8(const char *path, const char *mode);
321+
315322 /**
316323 * @}
317324 * @}
libavutil/file_open.c+34−0
@@ -93,3 +93,37 @@ int avpriv_open(const char *filename, int flags, ...) · 92 unmodified lines
9393
9494 return fd;
9595 }
96+
97+FILE *av_fopen_utf8(const char *path, const char *mode)
98+{
99+ int fd;
100+ int access;
101+ const char *m = mode;
102+
103+ switch (*m++) {
104+ case 'r': access = O_RDONLY; break;
105+ case 'w': access = O_CREAT|O_WRONLY|O_TRUNC; break;
106+ case 'a': access = O_CREAT|O_WRONLY|O_APPEND; break;
107+ default :
108+ errno = EINVAL;
109+ return NULL;
110+ }
111+ while (*m) {
112+ if (*m == '+') {
113+ access &= ~(O_RDONLY | O_WRONLY);
114+ access |= O_RDWR;
115+ } else if (*m == 'b') {
116+#ifdef O_BINARY
117+ access |= O_BINARY;
118+#endif
119+ } else if (*m) {
120+ errno = EINVAL;
121+ return NULL;
122+ }
123+ m++;
124+ }
125+ fd = avpriv_open(path, access, 0666);
126+ if (fd == -1)
127+ return NULL;
128+ return fdopen(fd, mode);
129+}
libavutil/version.h+1−1
@@ -75,7 +75,7 @@ · 74 unmodified lines
7575 */
7676
7777 #define LIBAVUTIL_VERSION_MAJOR 52
78−#define LIBAVUTIL_VERSION_MINOR 49
78+#define LIBAVUTIL_VERSION_MINOR 50
7979 #define LIBAVUTIL_VERSION_MICRO 100
8080
8181 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t