Mercurial > hg > octave-jordi > gnulib-hg
annotate m4/linkat.m4 @ 17908:074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
* m4/linkat.m4: Guess no for Darwin, yes otherwise.
author | Kevin Cernekee <cernekee@google.com> |
---|---|
date | Wed, 11 Feb 2015 15:22:55 -0800 |
parents | ab58d4870664 |
children | 301a9d4b8f5a |
rev | line source |
---|---|
15025
5cec5df6b606
linkat: Move AC_LIBOBJ invocations to module description.
Bruno Haible <bruno@clisp.org>
parents:
14803
diff
changeset
|
1 # serial 6 |
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 ])], |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
38 [gl_cv_func_linkat_nofollow=yes |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
39 LINKAT_SYMLINK_NOTSUP=0], |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
40 [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
|
41 LINKAT_SYMLINK_NOTSUP=1], |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
42 [case "$host_os" in |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
43 darwin*) |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
44 gl_cv_func_linkat_nofollow="guessing no" |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
45 LINKAT_SYMLINK_NOTSUP=1 ;; |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
46 *) |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
47 gl_cv_func_linkat_nofollow="guessing yes" |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
48 LINKAT_SYMLINK_NOTSUP=0 ;; |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
49 esac]) |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
50 |
17787
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
51 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
|
52 |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
53 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
|
54 [gl_cv_func_linkat_slash], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
55 [rm -rf conftest.a conftest.b conftest.c conftest.d |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
56 AC_RUN_IFELSE( |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
57 [AC_LANG_PROGRAM( |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
58 [[#include <unistd.h> |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
59 #include <fcntl.h> |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
60 #include <errno.h> |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
61 #include <stdio.h> |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
62 ]], |
13918
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
63 [[int result; |
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
64 int fd; |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
65 /* Create a regular file. */ |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
66 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
|
67 if (fd < 0) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
68 return 1; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
69 if (write (fd, "hello", 5) < 5) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
70 return 2; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
71 if (close (fd) < 0) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
72 return 3; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
73 /* 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
|
74 device. */ |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
75 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
|
76 AT_SYMLINK_FOLLOW) < 0) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
77 return 0; |
13918
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
78 result = 0; |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
79 /* Test whether a trailing "/" is treated like "/.". */ |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
80 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
|
81 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
|
82 result |= 4; |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
83 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
|
84 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
|
85 result |= 8; |
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
86 return result; |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
87 ]])], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
88 [gl_cv_func_linkat_slash=yes], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
89 [gl_cv_func_linkat_slash=no], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
90 [# Guess yes on glibc systems, no otherwise. |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
91 case "$host_os" in |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
92 *-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
|
93 *) gl_cv_func_linkat_slash="guessing no";; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
94 esac |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
95 ]) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
96 rm -rf conftest.a conftest.b conftest.c conftest.d]) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
97 case "$gl_cv_func_linkat_slash" in |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
98 *yes) gl_linkat_slash_bug=0 ;; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
99 *) gl_linkat_slash_bug=1 ;; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
100 esac |
17787
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
101 |
17908
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
102 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
|
103 *yes) linkat_nofollow=yes ;; |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
104 *) linkat_nofollow=no ;; |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
105 esac |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
106 |
074ad7ba0d73
linkat_nofollow: Add fallback case for cross compiling
Kevin Cernekee <cernekee@google.com>
parents:
17848
diff
changeset
|
107 if test "$linkat_nofollow" != yes \ |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
108 || test $gl_linkat_slash_bug = 1; then |
12120 | 109 REPLACE_LINKAT=1 |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
110 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
|
111 [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
|
112 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
|
113 [Define to 1 if linkat can create hardlinks to symlinks]) |
12120 | 114 fi |
12068 | 115 fi |
116 ]) |