[FFmpeg-devel] Support for Unicode filenames on Windows: try #2

Måns Rullgård mans
Wed Oct 21 03:07:30 CEST 2009


Karl Blomster <kalle at agigen.se> writes:

> Karl Blomster wrote:
>> Anyway, winutf8_try2.diff is my patch (probably full of bad and
>> wrong things).
>> ramiro_winutf8_4.diff is Ramiro's old patch, attached for reference
>> (it no longer applies, but the needed changes are pretty minor).
>
> Patch was broken (missing winmain.c/winmain.h), but Ramiro suggested
> on IRC that I only submit the lavf part for now and save the
> ffmpeg/ffplay commandline support for later. Simpler patch attached.

Won't this break the command line tools?

> Index: libavformat/os_support.c
> ===================================================================
> --- libavformat/os_support.c	(revision 20336)
> +++ libavformat/os_support.c	(working copy)
> @@ -30,6 +30,36 @@
>  #include <sys/time.h>
>  #include "os_support.h"
>
> +#ifdef CONFIG_WIN_UNICODE

#if

> +#define WIN32_LEAN_AND_MEAN
> +#include <windows.h>
> +#include <wchar.h>
> +
> +static wchar_t *dup_char_to_wchar(const char *s)
> +{
> +    wchar_t *w;
> +    int l;
> +    if (!(l = MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,s,-1,0,0)))
> +        return NULL;
> +    if (!(w = av_malloc(l*sizeof(wchar_t))))
> +        return NULL;
> +    if (MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,s,-1,w,l) <= 0)
> +        av_freep(&w);
> +    return w;
> +}
> +
> +int ff_winutf8_open(const char *fname, int oflags, int pmode)
> +{
> +    wchar_t *wfname = dup_char_to_wchar(fname);
> +    if (wfname) {
> +        int ret = _wopen(wfname, oflags, pmode);
> +        av_free(wfname);
> +        return ret;
> +    }
> +    return _open(fname, oflags, pmode); /* very likely to fail, but at least it's worth trying */

I don't like that way of thinking.

> +}
> +#endif /* CONFIG_WIN_UNICODE */
> +
>  #if CONFIG_NETWORK
>  #if !HAVE_POLL_H
>  #if HAVE_WINSOCK2_H
> Index: libavformat/os_support.h
> ===================================================================
> --- libavformat/os_support.h	(revision 20336)
> +++ libavformat/os_support.h	(working copy)
> @@ -32,7 +32,11 @@
>  #if defined(__MINGW32__) && !defined(__MINGW32CE__)
>  #  include <fcntl.h>
>  #  define lseek(f,p,w) _lseeki64((f), (p), (w))
> -#endif
> +#  ifdef CONFIG_WIN_UNICODE

#if

> +#    define open(fn,of,pm) ff_winutf8_open((fn), (of), (pm))

Unnecessary () around args.

> +int ff_winutf8_open(const char *fname, int oflags, int pmode);
> +#  endif /* CONFIG_WIN_UNICODE */
> +#endif /* defined(__MINGW32__) && !defined(__MINGW32CE__) */

Adding that comment is cosmetic and doesn't belong in this patch.

>  static inline int is_dos_path(const char *path)
>  {

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list