Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
lavf/os_support.h: Fix for unicode filenames on windows.
Fixes #819 #5256 #5281

Signed-off-by: Matt Oliver <protogonoi@gmail.com>
  • Loading branch information
Sibras committed Jun 13, 2016
1 parent be37a66 commit 37787f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libavformat/file.c
Expand Up @@ -148,7 +148,11 @@ static int file_check(URLContext *h, int mask)
ret |= AVIO_FLAG_WRITE;
#else
struct stat st;
# ifndef _WIN32
ret = stat(filename, &st);
# else
ret = win32_stat(filename, &st);
# endif
if (ret < 0)
return AVERROR(errno);

Expand Down
24 changes: 24 additions & 0 deletions libavformat/os_support.h
Expand Up @@ -182,6 +182,29 @@ DEF_FS_FUNCTION(unlink, _wunlink, _unlink)
DEF_FS_FUNCTION(mkdir, _wmkdir, _mkdir)
DEF_FS_FUNCTION(rmdir, _wrmdir , _rmdir)

#define DEF_FS_FUNCTION2(name, wfunc, afunc, partype) \
static inline int win32_##name(const char *filename_utf8, partype par) \
{ \
wchar_t *filename_w; \
int ret; \
\
if (utf8towchar(filename_utf8, &filename_w)) \
return -1; \
if (!filename_w) \
goto fallback; \
\
ret = wfunc(filename_w, par); \
av_free(filename_w); \
return ret; \
\
fallback: \
/* filename may be be in CP_ACP */ \
return afunc(filename_utf8, par); \
}

DEF_FS_FUNCTION2(access, _waccess, _access, int)
DEF_FS_FUNCTION2(stat, _wstat64, _stat64, struct stat*)

static inline int win32_rename(const char *src_utf8, const char *dest_utf8)
{
wchar_t *src_w, *dest_w;
Expand Down Expand Up @@ -231,6 +254,7 @@ static inline int win32_rename(const char *src_utf8, const char *dest_utf8)
#define rename win32_rename
#define rmdir win32_rmdir
#define unlink win32_unlink
#define access win32_access

#endif

Expand Down

1 comment on commit 37787f2

@rboy1
Copy link

@rboy1 rboy1 commented on 37787f2 Jun 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is causing a failure to cross compile for x86 Windows in Ubuntu14.04:
In file included from ./libavformat/internal.h:28:0, from libavdevice/decklink_enc.cpp:29: ./libavformat/os_support.h: In function 'int win32_stat(const char*, _stati64*)': ./libavformat/os_support.h:196:32: error: cannot convert '_stati64*' to '_stat64*' for argument '2' to 'int _wstat64(const wchar_t*, _stat64*)' ret = wfunc(filename_w, par); \ ^ ./libavformat/os_support.h:206:1: note: in expansion of macro 'DEF_FS_FUNCTION2' DEF_FS_FUNCTION2(stat, _wstat64, _stat64, struct stat*) ^ ./libavformat/os_support.h:202:36: error: cannot convert '_stati64*' to '_stat64*' for argument '2' to 'int _stat64(const char*, _stat64*)' return afunc(filename_utf8, par);

Please sign in to comment.