canonicalize-lgpl: fix // handling
[gnulib.git] / lib / canonicalize-lgpl.c
index 2fd79dc..a61bef9 100644 (file)
@@ -156,7 +156,7 @@ __realpath (const char *name, char *resolved)
     {
       rpath[0] = '/';
       dest = rpath + 1;
-      if (DOUBLE_SLASH_IS_DISTINCT_ROOT && name[1] == '/')
+      if (DOUBLE_SLASH_IS_DISTINCT_ROOT && name[1] == '/' && name[2] != '/')
         *dest++ = '/';
     }
 
@@ -187,7 +187,7 @@ __realpath (const char *name, char *resolved)
           if (dest > rpath + 1)
             while ((--dest)[-1] != '/');
           if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1
-              && *dest == '/')
+              && *dest == '/' && dest[1] != '/')
             dest++;
         }
       else
@@ -298,7 +298,8 @@ __realpath (const char *name, char *resolved)
               if (buf[0] == '/')
                 {
                   dest = rpath + 1;     /* It's an absolute symlink */
-                  if (DOUBLE_SLASH_IS_DISTINCT_ROOT && buf[1] == '/')
+                  if (DOUBLE_SLASH_IS_DISTINCT_ROOT
+                      && buf[1] == '/' && buf[2] != '/')
                     *dest++ = '/';
                 }
               else
@@ -308,7 +309,7 @@ __realpath (const char *name, char *resolved)
                   if (dest > rpath + 1)
                     while ((--dest)[-1] != '/');
                   if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1
-                      && *dest == '/')
+                      && *dest == '/' && dest[1] != '/')
                     dest++;
                 }
             }
@@ -321,7 +322,8 @@ __realpath (const char *name, char *resolved)
     }
   if (dest > rpath + 1 && dest[-1] == '/')
     --dest;
-  if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 && *dest == '/')
+  if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1
+      && *dest == '/' && dest[1] != '/')
     dest++;
   *dest = '\0';