]> Savannah Git Hosting - gnulib.git/commitdiff
canonicalize-lgpl: Work around // handling in realpath() of musl 1.2.2.
authorBruno Haible <bruno@clisp.org>
Sun, 17 Jan 2021 21:07:14 +0000 (22:07 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 17 Jan 2021 21:07:14 +0000 (22:07 +0100)
Reported by Natanael Copa <ncopa@alpinelinux.org> in
<https://lists.gnu.org/archive/html/bug-gettext/2021-01/msg00021.html>.

* m4/canonicalize.m4 (gl_FUNC_REALPATH_WORKS): Add a test whether // is
the same as /, on Linux only.
* lib/canonicalize-lgpl.c: Correct indentation of preprocessor
directives.
* doc/posix-functions/realpath.texi: Mention the musl 1.2.2 bug.

ChangeLog
doc/posix-functions/realpath.texi
lib/canonicalize-lgpl.c
m4/canonicalize.m4

index dad3119bfbdbcde5ea3d7e7dbb0b62c6c1022357..357006678984cf0aa1e9b6c2e0e24f65a3e793df 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2021-01-17  Bruno Haible  <bruno@clisp.org>
+
+       canonicalize-lgpl: Work around // handling in realpath() of musl 1.2.2.
+       Reported by Natanael Copa <ncopa@alpinelinux.org> in
+       <https://lists.gnu.org/archive/html/bug-gettext/2021-01/msg00021.html>.
+       * m4/canonicalize.m4 (gl_FUNC_REALPATH_WORKS): Add a test whether // is
+       the same as /, on Linux only.
+       * lib/canonicalize-lgpl.c: Correct indentation of preprocessor
+       directives.
+       * doc/posix-functions/realpath.texi: Mention the musl 1.2.2 bug.
+
 2021-01-17  Bruno Haible  <bruno@clisp.org>
 
        canonicalize[-lgpl] tests: Add more tests.
index 02837e710fb334a81df390736a6aa83f542f709c..a5b7c1d1ae39f355cba4b7d080374ca5041322b9 100644 (file)
@@ -22,14 +22,14 @@ Solaris 10.
 @item
 This function fails to detect trailing slashes on non-directories on
 some platforms:
-glibc 2.3.5, Mac OS X 10.13.
+glibc 2.3.5, Mac OS X 10.13, OpenBSD 6.0.
 @item
 This function fails to recognize non-directories followed @samp{..} on
 some platforms:
 cygwin.
 @item
 This function misbehaves on consecutive slashes on some platforms:
-AIX 7.
+musl libc 1.2.2, AIX 7.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 698f9ede25570ef2775d3c772ff510336425b796..bf63355da9160c55d5c42ee7cab2ce35e4bfb4f8 100644 (file)
@@ -141,11 +141,11 @@ suffix_requires_dir_check (char const *end)
    macOS 10.13 <https://bugs.gnu.org/30350>, and should also work on
    platforms like AIX 7.2 that need at least "/.".  */
 
-#if defined _LIBC || defined LSTAT_FOLLOWS_SLASHED_SYMLINK
+# if defined _LIBC || defined LSTAT_FOLLOWS_SLASHED_SYMLINK
 static char const dir_suffix[] = "/";
-#else
+# else
 static char const dir_suffix[] = "/./";
-#endif
+# endif
 
 /* Return true if DIR is a searchable dir, false (setting errno) otherwise.
    DIREND points to the NUL byte at the end of the DIR string.
@@ -187,13 +187,13 @@ get_path_max (void)
    to pacify GCC is known; even an explicit #pragma does not pacify GCC.
    When the GCC bug is fixed this workaround should be limited to the
    broken GCC versions.  */
-#if __GNUC_PREREQ (10, 1)
-# if defined GCC_LINT || defined lint
+# if __GNUC_PREREQ (10, 1)
+#  if defined GCC_LINT || defined lint
 __attribute__ ((__noinline__))
-# elif __OPTIMIZE__ && !__NO_INLINE__
-#  define GCC_BOGUS_WRETURN_LOCAL_ADDR
+#  elif __OPTIMIZE__ && !__NO_INLINE__
+#   define GCC_BOGUS_WRETURN_LOCAL_ADDR
+#  endif
 # endif
-#endif
 static char *
 realpath_stk (const char *name, char *resolved,
               struct scratch_buffer *rname_buf)
@@ -439,7 +439,8 @@ __realpath (const char *name, char *resolved)
 }
 libc_hidden_def (__realpath)
 versioned_symbol (libc, __realpath, realpath, GLIBC_2_3);
-#endif /* !FUNC_REALPATH_WORKS || defined _LIBC */
+
+#endif /* defined _LIBC || !FUNC_REALPATH_WORKS */
 
 
 #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3)
index 475fa15d6bdf5a95412b89c987bf02680bd0308f..6821c70e6f6336af8f7bcd65f4410e9eec264f02 100644 (file)
@@ -1,4 +1,4 @@
-# canonicalize.m4 serial 35
+# canonicalize.m4 serial 36
 
 dnl Copyright (C) 2003-2007, 2009-2021 Free Software Foundation, Inc.
 
@@ -91,6 +91,7 @@ AC_DEFUN([gl_FUNC_REALPATH_WORKS],
         #include <string.h>
       ]], [[
         int result = 0;
+        /* This test fails on Solaris 10.  */
         {
           char *name = realpath ("conftest.a", NULL);
           if (!(name && *name == '/'))
@@ -103,12 +104,14 @@ AC_DEFUN([gl_FUNC_REALPATH_WORKS],
             result |= 2;
           free (name);
         }
+        /* This test fails on Mac OS X 10.13, OpenBSD 6.0.  */
         {
           char *name = realpath ("conftest.a/", NULL);
           if (name != NULL)
             result |= 4;
           free (name);
         }
+        /* This test fails on AIX 7, Solaris 10.  */
         {
           char *name1 = realpath (".", NULL);
           char *name2 = realpath ("conftest.d//./..", NULL);
@@ -117,16 +120,31 @@ AC_DEFUN([gl_FUNC_REALPATH_WORKS],
           free (name1);
           free (name2);
         }
+        #ifdef __linux__
+        /* On Linux, // is the same as /. See also double-slash-root.m4.
+           realpath() should respect this.
+           This test fails on musl libc 1.2.2.  */
+        {
+          char *name = realpath ("//", NULL);
+          if (! name || strcmp (name, "/"))
+            result |= 16;
+          free (name);
+        }
+        #endif
         return result;
       ]])
      ],
      [gl_cv_func_realpath_works=yes],
-     [gl_cv_func_realpath_works=no],
+     [case $? in
+        16) gl_cv_func_realpath_works=nearly ;;
+        *)  gl_cv_func_realpath_works=no ;;
+      esac
+     ],
      [case "$host_os" in
                        # Guess yes on glibc systems.
         *-gnu* | gnu*) gl_cv_func_realpath_works="guessing yes" ;;
-                       # Guess yes on musl systems.
-        *-musl*)       gl_cv_func_realpath_works="guessing yes" ;;
+                       # Guess 'nearly' on musl systems.
+        *-musl*)       gl_cv_func_realpath_works="guessing nearly" ;;
                        # Guess no on native Windows.
         mingw*)        gl_cv_func_realpath_works="guessing no" ;;
                        # If we don't know, obey --enable-cross-guesses.
@@ -137,9 +155,12 @@ AC_DEFUN([gl_FUNC_REALPATH_WORKS],
   ])
   case "$gl_cv_func_realpath_works" in
     *yes)
-      AC_DEFINE([FUNC_REALPATH_WORKS], [1], [Define to 1 if realpath()
-        can malloc memory, always gives an absolute path, and handles
-        trailing slash correctly.])
+      AC_DEFINE([FUNC_REALPATH_WORKS], [1],
+        [Define to 1 if realpath() can malloc memory, always gives an absolute path, and handles leading slashes and a trailing slash correctly.])
+      ;;
+    *nearly)
+      AC_DEFINE([FUNC_REALPATH_NEARLY_WORKS], [1],
+        [Define to 1 if realpath() can malloc memory, always gives an absolute path, and handles a trailing slash correctly.])
       ;;
   esac
 ])