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.
#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 */
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. */
-#serial 13
+# canonicalize.m4 serial 14
# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 Free Software
# Foundation, Inc.
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])
])