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

Ramiro Polla ramiro.polla
Wed Oct 21 03:29:56 CEST 2009


2009/10/20 M?ns Rullg?rd <mans at mansr.com>:
> 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?

Yes for characters > 127 IIRC. It is assumed the person compiling
knows what he's doing (as is Karl's case), but it should be documented
better in ./configure --help.

>> +#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.

Hmm, hadn't I removed the fallback? I think we should just return
error if we can't convert to wchar.

>> +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.

Applied separately.



More information about the ffmpeg-devel mailing list