[FFmpeg-devel] Unicode filenames support on Windows regression

Nicolas George nicolas.george at normalesup.org
Tue Apr 17 20:26:43 CEST 2012


Le nonidi 29 germinal, an CCXX, Kirill Gavrilov a écrit :
> I tried to prepare the patch that follows semantic of definitions' hell
> adopted in FFmpeg.

Can you elaborate on that?

> From e72b1680d0965ba433e9ac084bbe6361ad25b2fa Mon Sep 17 00:00:00 2001
> From: Kirill Gavrilov <kirill at sview.ru>
> Date: Tue, 17 Apr 2012 22:02:44 +0400
> Subject: [PATCH] Fix Unicode filenames support on Windows regression

Git log messages should look like that:

os_support: implement Unicode stat for windows

(possibly a blank line and a few more lines of explanations)

> 
> Signed-off-by: Kirill Gavrilov <kirill at sview.ru>
> ---
>  libavformat/os_support.c |   27 ++++++++++++++++++++++++++-
>  libavformat/os_support.h |   23 +++++++++++++++++++++++
>  2 files changed, 49 insertions(+), 1 deletions(-)
> 
> diff --git a/libavformat/os_support.c b/libavformat/os_support.c
> index 913ca53..a14628a 100644
> --- a/libavformat/os_support.c
> +++ b/libavformat/os_support.c
> @@ -28,10 +28,13 @@
>  #include "os_support.h"
>  
>  #if defined(_WIN32) && !defined(__MINGW32CE__)
> +
> +#undef open
> +#undef stat
> +#undef fstat

Why fstat?

>  #include <windows.h>
>  #include <share.h>
>  
> -#undef open

Was it necessary to move it?

>  int ff_win32_open(const char *filename_utf8, int oflag, int pmode)
>  {
>      int fd;
> @@ -54,6 +57,28 @@ int ff_win32_open(const char *filename_utf8, int oflag, int pmode)
>  
>      return fd;
>  }
> +
> +int ff_win32_stat(const char *filename_utf8, struct ff_win32_stat *buffer)
> +{
> +    int result;
> +    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);
> +
> +    result = _wstati64(filename_w, (struct _stati64* )buffer);
> +    av_freep(&filename_w);
> +    if (result == 0)
> +        return 0;
> +
> +    /* filename maybe be in CP_ACP */
> +    return _stati64(filename_utf8, (struct _stati64* )buffer);
> +}
>  #endif
>  
>  #if CONFIG_NETWORK
> diff --git a/libavformat/os_support.h b/libavformat/os_support.h
> index 159d4d7..a15de5a 100644
> --- a/libavformat/os_support.h
> +++ b/libavformat/os_support.h
> @@ -29,6 +29,9 @@
>  
>  #include "config.h"
>  
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +
>  #if defined(__MINGW32__) && !defined(__MINGW32CE__)
>  #  include <fcntl.h>
>  #  ifdef lseek
> @@ -51,6 +54,26 @@ static inline int is_dos_path(const char *path)
>  #if defined(_WIN32) && !defined(__MINGW32CE__)
>  int ff_win32_open(const char *filename, int oflag, int pmode);
>  #define open ff_win32_open
> +
> +/* Redeclared _stati64 */
> +struct ff_win32_stat {
> +    _dev_t st_dev;
> +    _ino_t st_ino;
> +    unsigned short st_mode;
> +    short st_nlink;
> +    short st_uid;
> +    short st_gid;
> +    _dev_t st_rdev;
> +    __int64 st_size;
> +    time_t st_atime;
> +    time_t st_mtime;
> +    time_t st_ctime;
> +};

Duplicating a system data structure definition does not look like a good
idea at all.

Of course, I see the nature of your problem: if #define stat overrides the
stat function, it will override the structure name too.

I do not have a really good idea on how to deal with that problem.

> +
> +int ff_win32_stat(const char *filename_utf8, struct ff_win32_stat *buffer);
> +#undef stat
> +#define stat ff_win32_stat
> +
>  #endif
>  
>  #if CONFIG_NETWORK

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120417/e6100fa2/attachment.asc>


More information about the ffmpeg-devel mailing list