2009-09-23 Eric Blake <ebb9@byu.net>
+ fchdir: another mingw fix
+ * modules/fchdir (Depends-on): Drop canonicalize-lgpl.
+ * lib/fchdir.c (get_name): New helper method; skips canonicalize
+ on mingw (where it has not yet been ported), and make it optional
+ elsewhere.
+ (_gl_register_fd): Use it.
+
same-inode: make SAME_INODE tri-state, to port to mingw
* NEWS: Mention this change.
* lib/same-inode.h (same-inode.h): Recognize mingw limitation of
# define REPLACE_OPEN_DIRECTORY 0
#endif
+#ifndef HAVE_CANONICALIZE_FILE_NAME
+# if GNULIB_CANONICALIZE || GNULIB_CANONICALIZE_LGPL
+# define HAVE_CANONICALIZE_FILE_NAME 1
+# else
+# define HAVE_CANONICALIZE_FILE_NAME 0
+# endif
+#endif
+
/* This replacement assumes that a directory is not renamed while opened
through a file descriptor.
return true;
}
+/* Return the canonical name of DIR in malloc'd storage. */
+static char *
+get_name (char const *dir)
+{
+ char *result;
+ if (REPLACE_OPEN_DIRECTORY || !HAVE_CANONICALIZE_FILE_NAME)
+ {
+ /* The function canonicalize_file_name has not yet been ported
+ to mingw, with all its drive letter and backslash quirks.
+ Fortunately, getcwd is reliable in this case, but we ensure
+ we can get back to where we started before using it. Treat
+ "." as a special case, as it is frequently encountered. */
+ char *cwd = getcwd (NULL, 0);
+ int saved_errno;
+ if (dir[0] == '.' && dir[1] == '\0')
+ return cwd;
+ if (chdir (cwd))
+ return NULL;
+ result = chdir (dir) ? NULL : getcwd (NULL, 0);
+ saved_errno = errno;
+ chdir (cwd);
+ free (cwd);
+ errno = saved_errno;
+ }
+ else
+ {
+ /* Avoid changing the directory. */
+ result = canonicalize_file_name (dir);
+ }
+ return result;
+}
+
/* Hook into the gnulib replacements for open() and close() to keep track
of the open file descriptors. */
|| (fstat (fd, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)))
{
if (!ensure_dirs_slot (fd)
- || (dirs[fd].name = canonicalize_file_name (filename)) == NULL)
+ || (dirs[fd].name = get_name (filename)) == NULL)
{
int saved_errno = errno;
close (fd);