bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

link-follow and mingw


From: Eric Blake
Subject: link-follow and mingw
Date: Fri, 04 Sep 2009 11:58:02 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This is a pre-requisite to linkat, and implementing POSIX 2008 ln(1) -L
and -P options.  It will make it possible to decide whether linkat should
call plain link, readlink/link, or error out with ENOSYS (on the few
remaining systems where link() doesn't allow hardlinks to symlinks), as
well as being more accommodating to cross-compilation.  It also simplifies
the decision for mingw and any other platform that lacks symlinks.  I'm
going ahead and pushing it, even though it causes a slight semantic change
(at least coreutils will need to change an #ifdef to an #if, once it picks
up the latest gnulib, now that the variable is tri-stated).

Unfortunately, I don't have linkat working yet - if both paths are
absolute, or both fds point to the same location (which may require some
fstats or even stat(".") in the case of AT_FDCWD), or only one of the two
paths is relative, then the existing framework is easy enough to copy.
But if both paths are relative, and the fds point to different
directories, it requires chdir to one directory (preferably the one closer
to /), getcwd to determine the name, then retrying with the use of an
absolute name (and hoping not to hit ENAMETOOLONG errors).

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkqhVSoACgkQ84KuGfSFAYCpDQCePp1M7hiMYPwW+tu0CEv05oyQ
3qkAnR2Qv2wKacJqnn7iHLN5iGqplHI8
=ZjnD
-----END PGP SIGNATURE-----
>From 1149a55ddf28c24bb4be20778cfe8d00733cdd06 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Fri, 4 Sep 2009 11:49:02 -0600
Subject: [PATCH] link-follow: accomodate mingw and cross-compilation

* m4/link-follow.m4 (gl_AC_FUNC_LINK_FOLLOWS_SYMLINK): Rename...
(gl_FUNC_LINK_FOLLOWS_SYMLINK): ...to this.  Change
cross-compilation results to -1, to make linkat easier to
implement when cross-compiling.  Trivially support mingw.
* modules/link-follow (configure.ac): Call new name.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog           |    9 +++++++++
 m4/link-follow.m4   |   50 ++++++++++++++++++++++++++++++++++----------------
 modules/link-follow |    2 +-
 3 files changed, 44 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 58a4b35..41c104e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-09-04  Eric Blake  <address@hidden>
+
+       link-follow: accomodate mingw and cross-compilation
+       * m4/link-follow.m4 (gl_AC_FUNC_LINK_FOLLOWS_SYMLINK): Rename...
+       (gl_FUNC_LINK_FOLLOWS_SYMLINK): ...to this.  Change
+       cross-compilation results to -1, to make linkat easier to
+       implement when cross-compiling.  Trivially support mingw.
+       * modules/link-follow (configure.ac): Call new name.
+
 2009-09-03  Eric Blake  <address@hidden>

        faccessat: compile replacement
diff --git a/m4/link-follow.m4 b/m4/link-follow.m4
index 0c1ea36..eb98c3b 100644
--- a/m4/link-follow.m4
+++ b/m4/link-follow.m4
@@ -1,4 +1,4 @@
-# serial 12
+# serial 13
 dnl Run a program to determine whether link(2) follows symlinks.
 dnl Set LINK_FOLLOWS_SYMLINKS accordingly.

@@ -7,14 +7,27 @@ dnl Set LINK_FOLLOWS_SYMLINKS accordingly.
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.

-AC_DEFUN([gl_AC_FUNC_LINK_FOLLOWS_SYMLINK],
+dnl This macro can be used to emulate POSIX linkat.  If
+dnl LINK_FOLLOWS_SYMLINKS is 0, link matches linkat(,0), and
+dnl linkat(,AT_SYMLINK_FOLLOW) requires a readlink. If it is 1,
+dnl link matches linkat(,AT_SYMLINK_FOLLOW), and there is no way
+dnl to do linkat(,0) on symlinks (on all other file types,
+dnl link() is sufficient).  If it is -1, use a runtime test.
+AC_DEFUN([gl_FUNC_LINK_FOLLOWS_SYMLINK],
 [dnl
-  AC_CACHE_CHECK([whether link(2) dereferences a symlink],
-                gl_ac_cv_func_link_follows_symlink,
-  [
-    # Create a regular file.
-    echo > conftest.file
-    AC_RUN_IFELSE([AC_LANG_SOURCE([[
+  AC_CHECK_FUNCS_ONCE([readlink])
+  dnl Mingw lacks link, although gnulib provides a good replacement.
+  dnl However, it also lacks symlink, so there's nothing to test in
+  dnl the first place, and no reason to need to distinguish between
+  dnl linkat variants.  So, we set LINK_FOLLOWS_SYMLINKS to 0.
+  gl_link_follows_symlinks=0 # assume GNU behavior
+  if test $ac_cv_func_readlink = yes; then
+    AC_CACHE_CHECK([whether link(2) dereferences a symlink],
+                   gl_cv_func_link_follows_symlink,
+    [
+      # Create a regular file.
+      echo > conftest.file
+      AC_RUN_IFELSE([AC_LANG_SOURCE([[
 #       include <sys/types.h>
 #       include <sys/stat.h>
 #       include <unistd.h>
@@ -50,13 +63,18 @@ AC_DEFUN([gl_AC_FUNC_LINK_FOLLOWS_SYMLINK],
          return SAME_INODE (sb_hard, sb_file) ? 0 : 1;
        }
       ]])],
-      [gl_ac_cv_func_link_follows_symlink=yes],
-      [gl_ac_cv_func_link_follows_symlink=no],
-      [gl_ac_cv_func_link_follows_symlink=yes] dnl We're cross compiling.
-    )
-  ])
-  if test $gl_ac_cv_func_link_follows_symlink = yes; then
-    AC_DEFINE([LINK_FOLLOWS_SYMLINKS], [1],
-      [Define if `link(2)' dereferences symbolic links.])
+       [gl_cv_func_link_follows_symlink=yes],
+       [gl_cv_func_link_follows_symlink=no],
+       [gl_cv_func_link_follows_symlink=unknown] dnl We're cross compiling.
+      )
+    ])
+    case $gl_cv_func_link_follows_symlink in
+      yes) ;;
+      no) gl_link_follows_symlinks=1 ;;
+      *) gl_link_follows_symlinks=-1 ;;
+    esac
   fi
+  AC_DEFINE_UNQUOTED([LINK_FOLLOWS_SYMLINKS], [$gl_link_follows_symlinks],
+    [Define to 1 if `link(2)' dereferences symbolic links, 0 if it
+     creates hard links to symlinks, and -1 if unknown.])
 ])
diff --git a/modules/link-follow b/modules/link-follow
index 15a19f4..c7fd48a 100644
--- a/modules/link-follow
+++ b/modules/link-follow
@@ -7,7 +7,7 @@ m4/link-follow.m4
 Depends-on:

 configure.ac:
-gl_AC_FUNC_LINK_FOLLOWS_SYMLINK
+gl_FUNC_LINK_FOLLOWS_SYMLINK

 Makefile.am:

-- 
1.6.3.3.334.g916e1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]