Mercurial > hg > octave-nkf > gnulib-hg
changeset 12012:556a7580132e
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 <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Fri, 11 Sep 2009 14:57:01 -0600 |
parents | d8660f7d216a |
children | 284fbf719a2a |
files | ChangeLog lib/canonicalize.c m4/canonicalize.m4 modules/canonicalize |
diffstat | 4 files changed, 12 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2009-09-17 Eric Blake <ebb9@byu.net> + 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.
--- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -18,23 +18,14 @@ #include "canonicalize.h" +#include <errno.h> #include <stdlib.h> #include <string.h> - -#if HAVE_SYS_PARAM_H -# include <sys/param.h> -#endif - #include <sys/stat.h> - #include <unistd.h> -#include <errno.h> -#include <stddef.h> - #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 @@ 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. */
--- 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_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]) ])