| 31 | #include "libavutil/wchar_filename.h" |
| 32 | |
| 33 | static inline FILE *fopen_utf8(const char *path_utf8, const char *mode) |
| 34 | { |
| 35 | wchar_t *path_w, *mode_w; |
| 36 | FILE *f; |
| 37 | |
| 38 | /* convert UTF-8 to wide chars */ |
| 39 | if (get_extended_win32_path(path_utf8, &path_w)) /* This sets errno on error. */ |
| 40 | return NULL; |
| 41 | if (!path_w) |
| 42 | goto fallback; |
| 43 | |
| 44 | if (utf8towchar(mode, &mode_w)) |
| 45 | return NULL; |
| 46 | if (!mode_w) { |
| 47 | /* If failing to interpret the mode string as utf8, it is an invalid |
| 48 | * parameter. */ |
| 49 | av_freep(&path_w); |
| 50 | errno = EINVAL; |
| 51 | return NULL; |
| 52 | } |
| 53 | |
| 54 | f = _wfopen(path_w, mode_w); |
| 55 | av_freep(&path_w); |
| 56 | av_freep(&mode_w); |
| 57 | |
| 58 | return f; |
| 59 | fallback: |
| 60 | /* path may be in CP_ACP */ |
| 61 | return fopen(path_utf8, mode); |
| 62 | } |
| 63 | |
| 64 | #else |
| 65 |
no test coverage detected