From: Eli Zaretskii Date: Mon, 10 Dec 2012 22:52:22 +0000 (-0800) Subject: canonicalize, canonicalize-lgpl: Microsoft Windows prefix fixes X-Git-Tag: v0.1~326 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=b15e506db41611193303d635df8e5f739431a131;p=gnulib.git canonicalize, canonicalize-lgpl: Microsoft Windows prefix fixes * lib/canonicalize.c (canonicalize_filename_mode): * lib/canonicalize-lgpl.c (__realpath): Recompute prefix_len after fetching the current directory. Don't overrun the beginning of rpath if there's no slashes after the MS-Windows drive letter. --- diff --git a/ChangeLog b/ChangeLog index 413e435eb..a49fc077e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-12-10 Eli Zaretskii + + canonicalize, canonicalize-lgpl: Microsoft Windows prefix fixes + * lib/canonicalize.c (canonicalize_filename_mode): + * lib/canonicalize-lgpl.c (__realpath): Recompute prefix_len after + fetching the current directory. Don't overrun the beginning of + rpath if there's no slashes after the MS-Windows drive letter. + 2012-12-08 Stefano Lattarini maint.mk: avoid extra forks diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index 0888501fa..6d26fa6ee 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -157,6 +157,8 @@ __realpath (const char *name, char *resolved) goto error; } dest = strchr (rpath, '\0'); + start = name; + prefix_len = FILE_SYSTEM_PREFIX_LEN (rpath); } else { @@ -173,9 +175,10 @@ __realpath (const char *name, char *resolved) *dest++ = '/'; *dest = '\0'; } + start = name + prefix_len; } - for (start = end = name + prefix_len; *start; start = end) + for (end = start; *start; start = end) { #ifdef _LIBC struct stat64 st; @@ -200,7 +203,7 @@ __realpath (const char *name, char *resolved) { /* Back up to previous component, ignore if at root already. */ if (dest > rpath + prefix_len + 1) - for (--dest; !ISSLASH (dest[-1]); --dest) + for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest) continue; if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 && !prefix_len @@ -334,7 +337,7 @@ __realpath (const char *name, char *resolved) /* Back up to previous component, ignore if at root already: */ if (dest > rpath + prefix_len + 1) - for (--dest; !ISSLASH (dest[-1]); --dest) + for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest) continue; if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len) diff --git a/lib/canonicalize.c b/lib/canonicalize.c index 33ad29f07..176e55f0f 100644 --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -150,6 +150,8 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) { rname_limit = dest; } + start = name; + prefix_len = FILE_SYSTEM_PREFIX_LEN (rname); } else { @@ -168,9 +170,10 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) *dest++ = '/'; *dest = '\0'; } + start = name + prefix_len; } - for (start = name + prefix_len; *start; start = end) + for ( ; *start; start = end) { /* Skip sequence of multiple file name separators. */ while (ISSLASH (*start)) @@ -188,7 +191,7 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) { /* Back up to previous component, ignore if at root already. */ if (dest > rname + prefix_len + 1) - for (--dest; !ISSLASH (dest[-1]); --dest) + for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest) continue; if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 && !prefix_len && ISSLASH (*dest) && !ISSLASH (dest[1])) @@ -308,7 +311,7 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) /* Back up to previous component, ignore if at root already: */ if (dest > rname + prefix_len + 1) - for (--dest; !ISSLASH (dest[-1]); --dest) + for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest) continue; if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len)