<p dir="ltr">Hello,</p>
<p dir="ltr">Le 30 sept. 2016 03:49, Steve Lhomme <robux4@videolabs.io> a écrit :<br>
><br>
> --<br>
> replaces https://patches.videolan.org/patch/14469/<br>
> * support non ASCII chars in pathes<br>
> * use resolved_path if provided<br>
><br>
> replaces https://patches.videolan.org/patch/14471/<br>
> * fix leak<br>
> ---<br>
> compat/realpath.c    | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
> configure.ac         |  2 ++<br>
> include/vlc_fixups.h |  4 ++++<br>
> 3 files changed, 73 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>
> +/*****************************************************************************<br>
> + * realpath.c: POSIX realpath replacement<br>
> + *****************************************************************************<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>
> + *****************************************************************************/<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 resolved_path)<br>
> +{<br>
> +#ifdef _WIN32<br>
> +    int len = MultiByteToWideChar( CP_UTF8, 0, relpath, -1, NULL, 0 );<br>
> +    if (len == 0)<br>
> +        return NULL;</p>
<p dir="ltr">Set errno on error?</p>
<p dir="ltr">> +<br>
> +    wchar_t *wrelpath = (wchar_t *)malloc(len * sizeof (wchar_t));</p>
<p dir="ltr">Useless cast - t'is not C++.</p>
<p dir="ltr">> +    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, 0, NULL, NULL );<br>
> +        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, resolved_path, len, NULL, NULL );<br>
> +            free(wfullpath);<br>
> +            return resolved_path;<br>
> +        }<br>
> +        free(wfullpath);<br>
> +    }<br>
> +#else<br>
> +    (void)resolved_path;<br>
> +    (void)relpath;</p>
<p dir="ltr">Either set errno or use #error.</p>
<p dir="ltr">> +#endif<br>
> +    return NULL;<br>
> +}<br>
> diff --git a/configure.ac b/configure.ac<br>
> index 671c8a1..85b14d1 100644<br>
> --- a/configure.ac<br>
> +++ b/configure.ac<br>
> @@ -604,6 +604,8 @@ AC_CHECK_FUNC(fdatasync,,<br>
>    [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])<br>
> ])<br>
><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 7a76ef4..690daae 100644<br>
> --- a/include/vlc_fixups.h<br>
> +++ b/include/vlc_fixups.h<br>
> @@ -481,6 +481,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 resolved_path);<br>
> +#endif<br>
> +<br>
> #ifdef _WIN32<br>
> FILE *vlc_win32_tmpfile(void);<br>
> #endif<br>
> -- <br>
> 2.8.2<br>
><br>
> _______________________________________________<br>
> vlc-devel mailing list<br>
> To unsubscribe or modify your subscription options:<br>
> https://mailman.videolan.org/listinfo/vlc-devel<br></p>