Mercurial > hg > octave-jordi > gnulib-hg
annotate m4/linkat.m4 @ 18079:4c948fd76734 default tip master
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Mon, 24 Aug 2015 06:09:19 -0700 |
parents | bbdce0795bb7 |
children |
rev | line source |
---|---|
18030
bbdce0795bb7
linkat: fix invalid definition of LINKAT_SYMLINK_NOTSUP on OS X
Jim Meyering <meyering@fb.com>
parents:
17995
diff
changeset
|
1 # serial 7 |
12068 | 2 # See if we need to provide linkat replacement. |
3 | |
17848 | 4 dnl Copyright (C) 2009-2015 Free Software Foundation, Inc. |
12068 | 5 dnl This file is free software; the Free Software Foundation |
6 dnl gives unlimited permission to copy and/or distribute it, | |
7 dnl with or without modifications, as long as this notice is preserved. | |
8 | |
9 # Written by Eric Blake. | |
10 | |
11 AC_DEFUN([gl_FUNC_LINKAT], | |
12 [ | |
13 AC_REQUIRE([gl_FUNC_OPENAT]) | |
14 AC_REQUIRE([gl_FUNC_LINK_FOLLOWS_SYMLINK]) | |
15 AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) | |
16 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) | |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
17 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
12068 | 18 AC_CHECK_FUNCS_ONCE([linkat symlink]) |
19 AC_CHECK_HEADERS_ONCE([sys/param.h]) | |
20 if test $ac_cv_func_linkat = no; then | |
21 HAVE_LINKAT=0 | |
12120 | 22 else |
17787
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
23 dnl OS X Yosemite has linkat() but it's not sufficient |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
24 dnl to our needs since it doesn't support creating |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
25 dnl hardlinks to symlinks. Therefore check for that |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
26 dnl capability before considering using the system version. |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
27 AC_CACHE_CHECK([whether linkat() can link symlinks], |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
28 [gl_cv_func_linkat_nofollow], |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
29 [rm -rf conftest.l1 conftest.l2 |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
30 ln -s target conftest.l1 |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
31 AC_RUN_IFELSE([AC_LANG_PROGRAM( |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
32 [[#include <fcntl.h> |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
33 #include <unistd.h> |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
34 ]], |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
35 [return linkat (AT_FDCWD, "conftest.l1", AT_FDCWD, |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
36 "conftest.l2", 0); |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
37 ])], |
18030
bbdce0795bb7
linkat: fix invalid definition of LINKAT_SYMLINK_NOTSUP on OS X
Jim Meyering <meyering@fb.com>
parents:
17995
diff
changeset
|
38 [gl_cv_func_linkat_nofollow=yes], |
bbdce0795bb7
linkat: fix invalid definition of LINKAT_SYMLINK_NOTSUP on OS X
Jim Meyering <meyering@fb.com>
parents:
17995
diff
changeset
|
39 [gl_cv_func_linkat_nofollow=no], |
17908
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
40 [case "$host_os" in |
18030
bbdce0795bb7
linkat: fix invalid definition of LINKAT_SYMLINK_NOTSUP on OS X
Jim Meyering <meyering@fb.com>
parents:
17995
diff
changeset
|
41 darwin*) gl_cv_func_linkat_nofollow="guessing no" ;; |
bbdce0795bb7
linkat: fix invalid definition of LINKAT_SYMLINK_NOTSUP on OS X
Jim Meyering <meyering@fb.com>
parents:
17995
diff
changeset
|
42 *) gl_cv_func_linkat_nofollow="guessing yes" ;; |
17908
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
43 esac]) |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
44 |
17787
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
45 rm -rf conftest.l1 conftest.l2]) |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
46 |
18030
bbdce0795bb7
linkat: fix invalid definition of LINKAT_SYMLINK_NOTSUP on OS X
Jim Meyering <meyering@fb.com>
parents:
17995
diff
changeset
|
47 case $gl_cv_func_linkat_nofollow in |
bbdce0795bb7
linkat: fix invalid definition of LINKAT_SYMLINK_NOTSUP on OS X
Jim Meyering <meyering@fb.com>
parents:
17995
diff
changeset
|
48 *no) LINKAT_SYMLINK_NOTSUP=1 ;; |
bbdce0795bb7
linkat: fix invalid definition of LINKAT_SYMLINK_NOTSUP on OS X
Jim Meyering <meyering@fb.com>
parents:
17995
diff
changeset
|
49 *yes) LINKAT_SYMLINK_NOTSUP=0 ;; |
bbdce0795bb7
linkat: fix invalid definition of LINKAT_SYMLINK_NOTSUP on OS X
Jim Meyering <meyering@fb.com>
parents:
17995
diff
changeset
|
50 esac |
bbdce0795bb7
linkat: fix invalid definition of LINKAT_SYMLINK_NOTSUP on OS X
Jim Meyering <meyering@fb.com>
parents:
17995
diff
changeset
|
51 |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
52 AC_CACHE_CHECK([whether linkat handles trailing slash correctly], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
53 [gl_cv_func_linkat_slash], |
17995
301a9d4b8f5a
linkat: avoid OS X 10.10 trailing slash with symlink bug
Pádraig Brady <P@draigBrady.com>
parents:
17908
diff
changeset
|
54 [rm -rf conftest.a conftest.b conftest.c conftest.d conftest.e conftest.s |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
55 AC_RUN_IFELSE( |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
56 [AC_LANG_PROGRAM( |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
57 [[#include <unistd.h> |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
58 #include <fcntl.h> |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
59 #include <errno.h> |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
60 #include <stdio.h> |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
61 ]], |
13918
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
62 [[int result; |
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
63 int fd; |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
64 /* Create a regular file. */ |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
65 fd = open ("conftest.a", O_CREAT | O_EXCL | O_WRONLY, 0600); |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
66 if (fd < 0) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
67 return 1; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
68 if (write (fd, "hello", 5) < 5) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
69 return 2; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
70 if (close (fd) < 0) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
71 return 3; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
72 /* Test whether hard links are supported on the current |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
73 device. */ |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
74 if (linkat (AT_FDCWD, "conftest.a", AT_FDCWD, "conftest.b", |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
75 AT_SYMLINK_FOLLOW) < 0) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
76 return 0; |
13918
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
77 result = 0; |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
78 /* Test whether a trailing "/" is treated like "/.". */ |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
79 if (linkat (AT_FDCWD, "conftest.a/", AT_FDCWD, "conftest.c", |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
80 AT_SYMLINK_FOLLOW) == 0) |
13918
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
81 result |= 4; |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
82 if (linkat (AT_FDCWD, "conftest.a", AT_FDCWD, "conftest.d/", |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
83 AT_SYMLINK_FOLLOW) == 0) |
13918
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
84 result |= 8; |
17995
301a9d4b8f5a
linkat: avoid OS X 10.10 trailing slash with symlink bug
Pádraig Brady <P@draigBrady.com>
parents:
17908
diff
changeset
|
85 |
301a9d4b8f5a
linkat: avoid OS X 10.10 trailing slash with symlink bug
Pádraig Brady <P@draigBrady.com>
parents:
17908
diff
changeset
|
86 /* On OS X 10.10 a trailing "/" will cause the second path to be |
301a9d4b8f5a
linkat: avoid OS X 10.10 trailing slash with symlink bug
Pádraig Brady <P@draigBrady.com>
parents:
17908
diff
changeset
|
87 dereferenced, and thus will succeed on a dangling symlink. */ |
301a9d4b8f5a
linkat: avoid OS X 10.10 trailing slash with symlink bug
Pádraig Brady <P@draigBrady.com>
parents:
17908
diff
changeset
|
88 if (symlink ("conftest.e", "conftest.s") == 0) |
301a9d4b8f5a
linkat: avoid OS X 10.10 trailing slash with symlink bug
Pádraig Brady <P@draigBrady.com>
parents:
17908
diff
changeset
|
89 { |
301a9d4b8f5a
linkat: avoid OS X 10.10 trailing slash with symlink bug
Pádraig Brady <P@draigBrady.com>
parents:
17908
diff
changeset
|
90 if (linkat (AT_FDCWD, "conftest.a", AT_FDCWD, "conftest.s/", |
301a9d4b8f5a
linkat: avoid OS X 10.10 trailing slash with symlink bug
Pádraig Brady <P@draigBrady.com>
parents:
17908
diff
changeset
|
91 AT_SYMLINK_FOLLOW) == 0) |
301a9d4b8f5a
linkat: avoid OS X 10.10 trailing slash with symlink bug
Pádraig Brady <P@draigBrady.com>
parents:
17908
diff
changeset
|
92 result |= 16; |
301a9d4b8f5a
linkat: avoid OS X 10.10 trailing slash with symlink bug
Pádraig Brady <P@draigBrady.com>
parents:
17908
diff
changeset
|
93 } |
301a9d4b8f5a
linkat: avoid OS X 10.10 trailing slash with symlink bug
Pádraig Brady <P@draigBrady.com>
parents:
17908
diff
changeset
|
94 |
13918
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
95 return result; |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
96 ]])], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
97 [gl_cv_func_linkat_slash=yes], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
98 [gl_cv_func_linkat_slash=no], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
99 [# Guess yes on glibc systems, no otherwise. |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
100 case "$host_os" in |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
101 *-gnu*) gl_cv_func_linkat_slash="guessing yes";; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
102 *) gl_cv_func_linkat_slash="guessing no";; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
103 esac |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
104 ]) |
17995
301a9d4b8f5a
linkat: avoid OS X 10.10 trailing slash with symlink bug
Pádraig Brady <P@draigBrady.com>
parents:
17908
diff
changeset
|
105 rm -rf conftest.a conftest.b conftest.c conftest.d conftest.e conftest.s]) |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
106 case "$gl_cv_func_linkat_slash" in |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
107 *yes) gl_linkat_slash_bug=0 ;; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
108 *) gl_linkat_slash_bug=1 ;; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
109 esac |
17787
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
110 |
17908
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
111 case "$gl_cv_func_linkat_nofollow" in |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
112 *yes) linkat_nofollow=yes ;; |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
113 *) linkat_nofollow=no ;; |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
114 esac |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
115 |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
116 if test "$linkat_nofollow" != yes \ |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
117 || test $gl_linkat_slash_bug = 1; then |
12120 | 118 REPLACE_LINKAT=1 |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
119 AC_DEFINE_UNQUOTED([LINKAT_TRAILING_SLASH_BUG], [$gl_linkat_slash_bug], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
120 [Define to 1 if linkat fails to recognize a trailing slash.]) |
17787
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
121 AC_DEFINE_UNQUOTED([LINKAT_SYMLINK_NOTSUP], [$LINKAT_SYMLINK_NOTSUP], |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
122 [Define to 1 if linkat can create hardlinks to symlinks]) |
12120 | 123 fi |
12068 | 124 fi |
125 ]) |