X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fcanonicalize-lgpl.c;h=fa310fb59554ffdf1d64a6ffa0273a105cf61e40;hb=e9b552cf52b6200633c335b19a2f703f72f8683a;hp=fbde01bbc5d01fc4d374dcde2584bf51538febfb;hpb=4e793c35b62f5ea945b7d33ce36c78fc4d645b3a;p=gnulib.git diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index fbde01bbc..fa310fb59 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -67,6 +67,10 @@ # endif #endif +#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT +# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 +#endif + #if !FUNC_REALPATH_WORKS || defined _LIBC /* Return the canonical absolute name of file NAME. A canonical name does not contain any `.', `..' components nor any repeated path @@ -141,6 +145,8 @@ __realpath (const char *name, char *resolved) { rpath[0] = '/'; dest = rpath + 1; + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && name[1] == '/') + *dest++ = '/'; } for (start = end = name; *start; start = end) @@ -169,6 +175,9 @@ __realpath (const char *name, char *resolved) /* Back up to previous component, ignore if at root already. */ if (dest > rpath + 1) while ((--dest)[-1] != '/'); + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 + && *dest == '/') + dest++; } else { @@ -276,11 +285,21 @@ __realpath (const char *name, char *resolved) name = end = memcpy (extra_buf, buf, n); if (buf[0] == '/') - dest = rpath + 1; /* It's an absolute symlink */ + { + dest = rpath + 1; /* It's an absolute symlink */ + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && buf[1] == '/') + *dest++ = '/'; + } else - /* Back up to previous component, ignore if at root already: */ - if (dest > rpath + 1) - while ((--dest)[-1] != '/'); + { + /* Back up to previous component, ignore if at root + already: */ + if (dest > rpath + 1) + while ((--dest)[-1] != '/'); + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 + && *dest == '/') + dest++; + } } else if (!S_ISDIR (st.st_mode) && *end != '\0') { @@ -291,6 +310,8 @@ __realpath (const char *name, char *resolved) } if (dest > rpath + 1 && dest[-1] == '/') --dest; + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 && *dest == '/') + dest++; *dest = '\0'; if (extra_buf)