canonicalize: avoid resolvepath
authorEric Blake <ebb9@byu.net>
Fri, 11 Sep 2009 20:57:01 +0000 (14:57 -0600)
committerEric Blake <ebb9@byu.net>
Fri, 18 Sep 2009 01:16:17 +0000 (19:16 -0600)
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>
ChangeLog
lib/canonicalize.c
m4/canonicalize.m4
modules/canonicalize

index b078c1b..6ee35f0 100644 (file)
--- 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.
index 402a8ff..4030930 100644 (file)
 
 #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"
 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.  */
index 0a42a41..1258b3b 100644 (file)
@@ -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])
 ])
index a7e61a6..ec94c76 100644 (file)
@@ -11,7 +11,6 @@ areadlink-with-size
 errno
 extensions
 file-set
-filenamecat
 hash-triple
 lstat
 memmove