annotate m4/link-follow.m4 @ 40203:30d91797009f

autoupdate
author Karl Berry <karl@freefriends.org>
date Fri, 01 Mar 2019 08:42:42 -0800
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19479
4bc5b8cefed7 Add cross-compilation results for GNU/Hurd.
Samuel Thibault <samuel.thibault@gnu.org>
parents: 18626
diff changeset
1 # serial 20
6939
c34c3fd8f414 Commentary sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6275
diff changeset
2 dnl Run a program to determine whether link(2) follows symlinks.
1999
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
3 dnl Set LINK_FOLLOWS_SYMLINKS accordingly.
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
4
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
5 # Copyright (C) 1999-2001, 2004-2006, 2009-2019 Free Software Foundation, Inc.
5611
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5016
diff changeset
6 # This file is free software; the Free Software Foundation
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5016
diff changeset
7 # gives unlimited permission to copy and/or distribute it,
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5016
diff changeset
8 # with or without modifications, as long as this notice is preserved.
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5016
diff changeset
9
11948
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
10 dnl This macro can be used to emulate POSIX linkat. If
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
11 dnl LINK_FOLLOWS_SYMLINKS is 0, link matches linkat(,0), and
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
12 dnl linkat(,AT_SYMLINK_FOLLOW) requires a readlink. If it is 1,
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
13 dnl link matches linkat(,AT_SYMLINK_FOLLOW), and there is no way
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
14 dnl to do linkat(,0) on symlinks (on all other file types,
14050
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
15 dnl link() is sufficient). If it is -1, use a Solaris specific
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
16 dnl runtime test. If it is -2, use a generic runtime test.
11948
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
17 AC_DEFUN([gl_FUNC_LINK_FOLLOWS_SYMLINK],
1999
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
18 [dnl
16826
31a7d8d65261 link-follow: Avoid guessing wrong when cross-compiling to glibc/Linux.
Bruno Haible <bruno@clisp.org>
parents: 16234
diff changeset
19 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
11948
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
20 AC_CHECK_FUNCS_ONCE([readlink])
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
21 dnl Mingw lacks link, although gnulib provides a good replacement.
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
22 dnl However, it also lacks symlink, so there's nothing to test in
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
23 dnl the first place, and no reason to need to distinguish between
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
24 dnl linkat variants. So, we set LINK_FOLLOWS_SYMLINKS to 0.
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
25 gl_link_follows_symlinks=0 # assume GNU behavior
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
26 if test $ac_cv_func_readlink = yes; then
14050
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
27 dnl Solaris has an __xpg4 variable in libc, and it determines the
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
28 dnl behaviour of link(): It dereferences a symlink if and only if
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
29 dnl __xpg4 != 0.
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
30 AC_CACHE_CHECK([for __xpg4], [gl_cv_have___xpg4],
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
31 [AC_LINK_IFELSE(
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
32 [AC_LANG_PROGRAM(
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
33 [[extern int __xpg4;]],
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
34 [[return __xpg4;]])],
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
35 [gl_cv_have___xpg4=yes],
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
36 [gl_cv_have___xpg4=no])
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
37 ])
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
38 if test $gl_cv_have___xpg4 = yes; then
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
39 gl_link_follows_symlinks=-1
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
40 else
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
41 AC_CACHE_CHECK([whether link(2) dereferences a symlink],
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
42 [gl_cv_func_link_follows_symlink],
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
43 [
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
44 # Create a regular file.
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
45 echo > conftest.file
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
46 AC_RUN_IFELSE(
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
47 [AC_LANG_SOURCE([[
1999
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
48 # include <sys/types.h>
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
49 # include <sys/stat.h>
6275
fd0ccce602e4 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5611
diff changeset
50 # include <unistd.h>
7356
0af37e82a5e3 * fsusage.m4 (gl_STATFS_TRUNCATES): Avoid unused variable.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents: 6939
diff changeset
51 # include <stdlib.h>
1999
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
52
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
53 # define SAME_INODE(Stat_buf_1, Stat_buf_2) \
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
54 ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
55 && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
1999
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
56
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
57 int
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
58 main ()
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
59 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
60 const char *file = "conftest.file";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
61 const char *sym = "conftest.sym";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
62 const char *hard = "conftest.hard";
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
63 struct stat sb_file, sb_hard;
1999
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
64
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
65 /* Create a symlink to the regular file. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
66 if (symlink (file, sym))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
67 return 2;
1999
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
68
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
69 /* Create a hard link to that symlink. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
70 if (link (sym, hard))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
71 return 3;
1999
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
72
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
73 if (lstat (hard, &sb_hard))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
74 return 4;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
75 if (lstat (file, &sb_file))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
76 return 5;
1999
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
77
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
78 /* If the dev/inode of hard and file are the same, then
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
79 the link call followed the symlink. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
80 return SAME_INODE (sb_hard, sb_file) ? 1 : 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12051
diff changeset
81 }
14050
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
82 ]])],
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
83 [gl_cv_func_link_follows_symlink=no], dnl GNU behavior
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
84 [gl_cv_func_link_follows_symlink=yes], dnl Followed link/compile failed
16826
31a7d8d65261 link-follow: Avoid guessing wrong when cross-compiling to glibc/Linux.
Bruno Haible <bruno@clisp.org>
parents: 16234
diff changeset
85 [dnl We're cross compiling.
16935
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16826
diff changeset
86 dnl The past results are "yes" on Mac OS X, FreeBSD, NetBSD,
16826
31a7d8d65261 link-follow: Avoid guessing wrong when cross-compiling to glibc/Linux.
Bruno Haible <bruno@clisp.org>
parents: 16234
diff changeset
87 dnl OpenBSD, Minix, AIX, HP-UX, OSF/1, and "no" on Linux, Cygwin.
31a7d8d65261 link-follow: Avoid guessing wrong when cross-compiling to glibc/Linux.
Bruno Haible <bruno@clisp.org>
parents: 16234
diff changeset
88 case "$host_os" in
19479
4bc5b8cefed7 Add cross-compilation results for GNU/Hurd.
Samuel Thibault <samuel.thibault@gnu.org>
parents: 18626
diff changeset
89 # On glibc/Linux we know the result.
4bc5b8cefed7 Add cross-compilation results for GNU/Hurd.
Samuel Thibault <samuel.thibault@gnu.org>
parents: 18626
diff changeset
90 linux*-gnu* | gnu*) gl_cv_func_link_follows_symlink="guessing no" ;;
4bc5b8cefed7 Add cross-compilation results for GNU/Hurd.
Samuel Thibault <samuel.thibault@gnu.org>
parents: 18626
diff changeset
91 # Otherwise, we don't know.
4bc5b8cefed7 Add cross-compilation results for GNU/Hurd.
Samuel Thibault <samuel.thibault@gnu.org>
parents: 18626
diff changeset
92 *) gl_cv_func_link_follows_symlink=unknown ;;
16826
31a7d8d65261 link-follow: Avoid guessing wrong when cross-compiling to glibc/Linux.
Bruno Haible <bruno@clisp.org>
parents: 16234
diff changeset
93 esac
31a7d8d65261 link-follow: Avoid guessing wrong when cross-compiling to glibc/Linux.
Bruno Haible <bruno@clisp.org>
parents: 16234
diff changeset
94 ])
14050
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
95 rm -f conftest.file conftest.sym conftest.hard
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
96 ])
16826
31a7d8d65261 link-follow: Avoid guessing wrong when cross-compiling to glibc/Linux.
Bruno Haible <bruno@clisp.org>
parents: 16234
diff changeset
97 case "$gl_cv_func_link_follows_symlink" in
31a7d8d65261 link-follow: Avoid guessing wrong when cross-compiling to glibc/Linux.
Bruno Haible <bruno@clisp.org>
parents: 16234
diff changeset
98 *yes) gl_link_follows_symlinks=1 ;;
31a7d8d65261 link-follow: Avoid guessing wrong when cross-compiling to glibc/Linux.
Bruno Haible <bruno@clisp.org>
parents: 16234
diff changeset
99 *no) ;; # already defaulted to 0
14050
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
100 *) gl_link_follows_symlinks=-2 ;;
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
101 esac
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
102 fi
2004
882288b6539c define LINK_FOLLOWS_SYMLINKS
Jim Meyering <jim@meyering.net>
parents: 2002
diff changeset
103 fi
11948
325a0b28c47e link-follow: accomodate mingw and cross-compilation
Eric Blake <ebb9@byu.net>
parents: 11929
diff changeset
104 AC_DEFINE_UNQUOTED([LINK_FOLLOWS_SYMLINKS], [$gl_link_follows_symlinks],
16234
f9b906545e2f Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
105 [Define to 1 if 'link(2)' dereferences symbolic links, 0 if it
14050
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
106 creates hard links to symlinks, -1 if it depends on the variable __xpg4,
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
107 and -2 if unknown.])
1999
5c262d8ca0d3 (jm_AC_FUNC_LINK_FOLLOWS_SYMLINK): New file/macro.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
108 ])