X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fcanonicalize-lgpl.c;h=6cbd2e08a0842c79edb41fb6761d7185b2659bca;hb=8866a241ddbf4a459347b7147e325f539e4c07fe;hp=0888501fa34a46177d04c89d68836b58238c198f;hpb=86627bb14a123f183bd094e582e4cd9f2aca489a;p=gnulib.git diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index 0888501fa..6cbd2e08a 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -1,5 +1,5 @@ /* Return the canonical absolute name of a given file. - Copyright (C) 1996-2012 Free Software Foundation, Inc. + Copyright (C) 1996-2013 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software: you can redistribute it and/or modify @@ -16,16 +16,16 @@ along with this program. If not, see . */ #ifndef _LIBC +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the name == NULL test below. */ +# define _GL_ARG_NONNULL(params) + # define _GL_USE_STDLIB_ALLOC 1 # include #endif #if !HAVE_CANONICALIZE_FILE_NAME || !FUNC_REALPATH_WORKS || defined _LIBC -/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc - optimizes away the name == NULL test below. */ -#define _GL_ARG_NONNULL(params) - /* Specification. */ #include @@ -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)