<p dir="ltr">We're not trying to implement a clean version but something that works in compat for VLC. I think VLC assumes UTF-8 throughout the app so we should just use that. </p>
<div class="gmail_extra"><br><div class="gmail_quote">On Sep 15, 2016 18:25, "Rémi Denis-Courmont" <<a href="mailto:remi@remlab.net">remi@remlab.net</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Le torstaina 15. syyskuuta 2016, 11.10.27 EEST Steve Lhomme a écrit :<br>
> --<br>
> replaces <a href="https://patches.videolan.org/patch/14469/" rel="noreferrer" target="_blank">https://patches.videolan.org/<wbr>patch/14469/</a><br>
> * support non ASCII chars in pathes<br>
> * use resolved_path if provided<br>
><br>
> replaces <a href="https://patches.videolan.org/patch/14471/" rel="noreferrer" target="_blank">https://patches.videolan.org/<wbr>patch/14471/</a><br>
> * fix leak<br>
> ---<br>
>  compat/realpath.c    | 67<br>
> ++++++++++++++++++++++++++++++<wbr>++++++++++++++++++++++ <a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a>         |<br>
>  3 +++<br>
>  include/vlc_fixups.h |  4 ++++<br>
>  3 files changed, 74 insertions(+)<br>
>  create mode 100644 compat/realpath.c<br>
><br>
> diff --git a/compat/realpath.c b/compat/realpath.c<br>
> new file mode 100644<br>
> index 0000000..a8edce5<br>
> --- /dev/null<br>
> +++ b/compat/realpath.c<br>
> @@ -0,0 +1,67 @@<br>
> +/****************************<wbr>******************************<wbr>****************<br>
> *** + * realpath.c: POSIX realpath replacement<br>
> +<br>
> ******************************<wbr>******************************<wbr>***************<br>
> ** + * Copyright © 2016 VLC authors and VideoLAN<br>
> + *<br>
> + * This program is free software; you can redistribute it and/or modify it<br>
> + * under the terms of the GNU Lesser General Public License as published by<br>
> + * the Free Software Foundation; either version 2.1 of the License, or + *<br>
> (at your option) any later version.<br>
> + *<br>
> + * This program is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
> + * GNU Lesser General Public License for more details.<br>
> + *<br>
> + * You should have received a copy of the GNU Lesser General Public License<br>
> + * along with this program; if not, write to the Free Software Foundation,<br>
> + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. +<br>
> ******************************<wbr>******************************<wbr>***************<br>
> **/ +<br>
> +#ifdef HAVE_CONFIG_H<br>
> +# include <config.h><br>
> +#endif<br>
> +<br>
> +#include <stdlib.h><br>
> +#ifdef _WIN32<br>
> +#include <windows.h><br>
> +#endif<br>
> +<br>
> +char *realpath(const char * restrict relpath, char * restrict<br>
> resolved_path) +{<br>
> +#ifdef _WIN32<br>
> +    int len = MultiByteToWideChar( CP_UTF8, 0, relpath, -1, NULL, 0 );<br>
> +    if (len == 0)<br>
> +        return NULL;<br>
> +<br>
> +    wchar_t *wrelpath = (wchar_t *)malloc(len * sizeof (wchar_t));<br>
> +    if (wrelpath == NULL)<br>
> +        return NULL;<br>
> +<br>
> +    MultiByteToWideChar( CP_UTF8, 0, relpath, -1, wrelpath, len );<br>
> +<br>
> +    wchar_t *wfullpath = _wfullpath( NULL, wrelpath, _MAX_PATH );<br>
> +    free(wrelpath);<br>
> +    if (wfullpath != NULL)<br>
> +    {<br>
> +        size_t len = WideCharToMultiByte( CP_UTF8, 0, wfullpath, -1, NULL,<br>
> 0, NULL, NULL ); +        if (len != 0)<br>
> +        {<br>
> +            if (resolved_path != NULL)<br>
> +                len = len >= _MAX_PATH ? _MAX_PATH : len;<br>
> +            else<br>
> +                resolved_path = (char *)malloc(len);<br>
> +<br>
> +            if (resolved_path != NULL)<br>
> +                WideCharToMultiByte( CP_UTF8, 0, wfullpath, -1,<br>
> resolved_path, len, NULL, NULL );<br>
> +            free(wfullpath);<br>
> +            return resolved_path;<br>
> +        }<br>
> +        free(wfullpath);<br>
> +    }<br>
<br>
Is the function call supposed to return an UTF-8 string? I would have expected<br>
ANSI here.<br>
<br>
> +#else<br>
> +    (void)resolved_path;<br>
> +    (void)relpath;<br>
<br>
Missing errno.<br>
<br>
> +#endif<br>
> +    return NULL;<br>
> +}<br>
> diff --git a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> index 59f116e..cec9e56 100644<br>
> --- a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> +++ b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> @@ -604,6 +604,9 @@ AC_CHECK_FUNCS(fdatasync,,<br>
>    [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])<br>
>  ])<br>
><br>
> +dnl for tests<br>
> +VLC_REPLACE_DECL([realpath], [#include <stdlib.h>])<br>
> +<br>
>  dnl mingw64 implements those as static inline, not functions with C linkage<br>
> VLC_REPLACE_DECL([asprintf], [#include <stdio.h>])<br>
>  VLC_REPLACE_DECL([vasprintf], [#include <stdio.h>])<br>
> diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h<br>
> index a14764f..2992796 100644<br>
> --- a/include/vlc_fixups.h<br>
> +++ b/include/vlc_fixups.h<br>
> @@ -473,6 +473,10 @@ void freeaddrinfo (struct addrinfo *res);<br>
>  #define nanf(tagp) NAN<br>
>  #endif<br>
><br>
> +#ifndef HAVE_REALPATH<br>
> +char *realpath(const char * restrict pathname, char * restrict<br>
> resolved_path); +#endif<br>
> +<br>
>  #ifdef _WIN32<br>
>  FILE *vlc_win32_tmpfile(void);<br>
>  #endif<br>
<br>
<br>
--<br>
Rémi Denis-Courmont<br>
Nonsponsored VLC developer<br>
<a href="http://www.remlab.net/CV.pdf" rel="noreferrer" target="_blank">http://www.remlab.net/CV.pdf</a><br>
<br>
______________________________<wbr>_________________<br>
vlc-devel mailing list<br>
To unsubscribe or modify your subscription options:<br>
<a href="https://mailman.videolan.org/listinfo/vlc-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/<wbr>listinfo/vlc-devel</a><br>
</blockquote></div></div>