X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fcanonicalize-lgpl.c;h=7aa2d92cfdc71a03d841a8c83d4c000733fc16b4;hb=82781cc8ba8aa1831f3fce91ce14b8538f5319f0;hp=c71721eaa4160c635050c7bd13f0876dfc7156f0;hpb=441aa3044f43e5572f58c354f01e6bc070acd5c7;p=gnulib.git diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index c71721eaa..7aa2d92cf 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-2009 Free Software Foundation, Inc. + Copyright (C) 1996-2012 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,11 +16,16 @@ along with this program. If not, see . */ #ifndef _LIBC +# 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 @@ -39,7 +44,7 @@ # include #else # define SHLIB_COMPAT(lib, introduced, obsoleted) 0 -# define versioned_symbol(lib, local, symbol, version) +# define versioned_symbol(lib, local, symbol, version) extern int dummy # define compat_symbol(lib, local, symbol, version) # define weak_alias(local, symbol) # define __canonicalize_file_name canonicalize_file_name @@ -47,6 +52,12 @@ # include "pathmax.h" # include "malloca.h" # if HAVE_GETCWD +# if IN_RELOCWRAPPER + /* When building the relocatable program wrapper, use the system's getcwd + function, not the gnulib override, otherwise we would get a link error. + */ +# undef getcwd +# endif # ifdef VMS /* We want the directory in Unix syntax, not in VMS syntax. */ # define __getcwd(buf, max) getcwd (buf, max, 0) @@ -73,10 +84,10 @@ #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 + does not contain any ".", ".." components nor any repeated path separators ('/') or symlinks. All path components must exist. If RESOLVED is null, the result is malloc'd; otherwise, if the - canonical name is PATH_MAX chars or more, returns null with `errno' + canonical name is PATH_MAX chars or more, returns null with 'errno' set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the name in RESOLVED. If the name cannot be resolved and RESOLVED is non-NULL, it contains the path of the first component @@ -114,7 +125,7 @@ __realpath (const char *name, char *resolved) #else path_max = pathconf (name, _PC_PATH_MAX); if (path_max <= 0) - path_max = 1024; + path_max = 8192; #endif if (resolved == NULL) @@ -145,8 +156,12 @@ __realpath (const char *name, char *resolved) { rpath[0] = '/'; dest = rpath + 1; - if (DOUBLE_SLASH_IS_DISTINCT_ROOT && name[1] == '/') - *dest++ = '/'; + if (DOUBLE_SLASH_IS_DISTINCT_ROOT) + { + if (name[1] == '/' && name[2] != '/') + *dest++ = '/'; + *dest = '\0'; + } } for (start = end = name; *start; start = end) @@ -176,7 +191,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 @@ -287,8 +302,12 @@ __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] == '/') - *dest++ = '/'; + if (DOUBLE_SLASH_IS_DISTINCT_ROOT) + { + if (buf[1] == '/' && buf[2] != '/') + *dest++ = '/'; + *dest = '\0'; + } } else { @@ -297,7 +316,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++; } } @@ -310,7 +329,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';