From: Eric Blake Date: Fri, 11 Sep 2009 20:57:01 +0000 (-0600) Subject: canonicalize: avoid resolvepath X-Git-Tag: v0.1~5475 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=b472b51e158594a679f8e49eea49cf14d1c3be9a;p=gnulib.git canonicalize: avoid resolvepath Back when canonicalize merely provided canonicalize_file_name, resolvepath was more efficient than implementing a complete realpath. But since resolvepath can't implement other modes for canonicalize_filename_mode, using it is now just bulk on Solaris. * m4/canonicalize.m4 (gl_FUNC_CANONICALIZE_FILENAME_MODE): Delete unnecessary checks. * lib/canonicalize.c (includes): Simplify. (canonicalize_file_name): Drop resolvepath implementation. * modules/canonicalize (Depends-on): Drop filenamecat. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index b078c1ba2..6ee35f04e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2009-09-17 Eric Blake + canonicalize: avoid resolvepath + * m4/canonicalize.m4 (gl_FUNC_CANONICALIZE_FILENAME_MODE): Delete + unnecessary checks. + * lib/canonicalize.c (includes): Simplify. + (canonicalize_file_name): Drop resolvepath implementation. + * modules/canonicalize (Depends-on): Drop filenamecat. + canonicalize: don't lose errno * lib/canonicalize.c (canonicalize_filename_mode): Protect errno over calls to free. diff --git a/lib/canonicalize.c b/lib/canonicalize.c index 402a8ff17..403093055 100644 --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -18,23 +18,14 @@ #include "canonicalize.h" +#include #include #include - -#if HAVE_SYS_PARAM_H -# include -#endif - #include - #include -#include -#include - #include "areadlink.h" #include "file-set.h" -#include "filenamecat.h" #include "hash-triple.h" #include "pathmax.h" #include "xalloc.h" @@ -49,68 +40,7 @@ char * canonicalize_file_name (const char *name) { -# if HAVE_RESOLVEPATH - - char *resolved, *extra_buf = NULL; - size_t resolved_size; - ssize_t resolved_len; - - if (name == NULL) - { - errno = EINVAL; - return NULL; - } - - if (name[0] == '\0') - { - errno = ENOENT; - return NULL; - } - - /* All known hosts with resolvepath (e.g. Solaris 7) don't turn - relative names into absolute ones, so prepend the working - directory if the file name is not absolute. */ - if (name[0] != '/') - { - char *wd; - - if (!(wd = xgetcwd ())) - return NULL; - - extra_buf = file_name_concat (wd, name, NULL); - name = extra_buf; - free (wd); - } - - resolved_size = strlen (name); - while (1) - { - resolved_size = 2 * resolved_size + 1; - resolved = xmalloc (resolved_size); - resolved_len = resolvepath (name, resolved, resolved_size); - if (resolved_len < 0) - { - free (resolved); - free (extra_buf); - return NULL; - } - if (resolved_len < resolved_size) - break; - free (resolved); - } - - free (extra_buf); - - /* NUL-terminate the resulting name. */ - resolved[resolved_len] = '\0'; - - return resolved; - -# else - return canonicalize_filename_mode (name, CAN_EXISTING); - -# endif /* !HAVE_RESOLVEPATH */ } #endif /* !HAVE_CANONICALIZE_FILE_NAME */ @@ -138,7 +68,8 @@ seen_triple (Hash_table **ht, char const *filename, struct stat const *st) return false; } -/* Return the canonical absolute name of file NAME. A canonical name +/* Return the canonical absolute name of file NAME, while treating + missing elements according to CAN_MODE. A canonical name does not contain any `.', `..' components nor any repeated file name separators ('/') or symlinks. Whether components must exist or not depends on canonicalize mode. The result is malloc'd. */ diff --git a/m4/canonicalize.m4 b/m4/canonicalize.m4 index 0a42a41ef..1258b3b4a 100644 --- a/m4/canonicalize.m4 +++ b/m4/canonicalize.m4 @@ -1,4 +1,4 @@ -#serial 13 +# canonicalize.m4 serial 14 # Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 Free Software # Foundation, Inc. @@ -14,6 +14,5 @@ AC_DEFUN([gl_FUNC_CANONICALIZE_FILENAME_MODE], AC_LIBOBJ([canonicalize]) AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) - AC_CHECK_HEADERS_ONCE([sys/param.h]) - AC_CHECK_FUNCS_ONCE([canonicalize_file_name resolvepath]) + AC_CHECK_FUNCS_ONCE([canonicalize_file_name]) ]) diff --git a/modules/canonicalize b/modules/canonicalize index a7e61a67a..ec94c7670 100644 --- a/modules/canonicalize +++ b/modules/canonicalize @@ -11,7 +11,6 @@ areadlink-with-size errno extensions file-set -filenamecat hash-triple lstat memmove