Mercurial > hg > octave-jordi > gnulib-hg
annotate m4/linkat.m4 @ 17848:ab58d4870664
version-etc: new year
* doc/gnulib.texi:
* lib/version-etc.c (COPYRIGHT_YEAR): Update copyright date.
* all files: Run 'make update-copyright'.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Thu, 01 Jan 2015 01:38:23 +0000 |
parents | 6eb23dad34b3 |
children | 074ad7ba0d73 |
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 |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
41 LINKAT_SYMLINK_NOTSUP=1]) |
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
42 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
|
43 |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
44 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
|
45 [gl_cv_func_linkat_slash], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
46 [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
|
47 AC_RUN_IFELSE( |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
48 [AC_LANG_PROGRAM( |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
49 [[#include <unistd.h> |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
50 #include <fcntl.h> |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
51 #include <errno.h> |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
52 #include <stdio.h> |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
53 ]], |
13918
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
54 [[int result; |
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
55 int fd; |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
56 /* Create a regular file. */ |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
57 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
|
58 if (fd < 0) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
59 return 1; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
60 if (write (fd, "hello", 5) < 5) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
61 return 2; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
62 if (close (fd) < 0) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
63 return 3; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
64 /* 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
|
65 device. */ |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
66 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
|
67 AT_SYMLINK_FOLLOW) < 0) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
68 return 0; |
13918
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
69 result = 0; |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
70 /* Test whether a trailing "/" is treated like "/.". */ |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
71 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
|
72 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
|
73 result |= 4; |
13514
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.d/", |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
75 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
|
76 result |= 8; |
d5a74c6ec06b
Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents:
13514
diff
changeset
|
77 return result; |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
78 ]])], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
79 [gl_cv_func_linkat_slash=yes], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
80 [gl_cv_func_linkat_slash=no], |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
81 [# Guess yes on glibc systems, no otherwise. |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
82 case "$host_os" in |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
83 *-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
|
84 *) gl_cv_func_linkat_slash="guessing no";; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
85 esac |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
86 ]) |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
87 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
|
88 case "$gl_cv_func_linkat_slash" in |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
89 *yes) gl_linkat_slash_bug=0 ;; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
90 *) gl_linkat_slash_bug=1 ;; |
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
91 esac |
17787
461b92d0b2eb
linkat: wrap to handle symlinks on OS X 10.10
Pádraig Brady <P@draigBrady.com>
parents:
17587
diff
changeset
|
92 |
17788
6eb23dad34b3
linkat: don't unconditionally replace on GNU/Linux
Pádraig Brady <P@draigBrady.com>
parents:
17787
diff
changeset
|
93 if test "$gl_cv_func_linkat_nofollow" != yes \ |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
94 || test $gl_linkat_slash_bug = 1; then |
12120 | 95 REPLACE_LINKAT=1 |
13514
6154fce586b6
linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
96 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
|
97 [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
|
98 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
|
99 [Define to 1 if linkat can create hardlinks to symlinks]) |
12120 | 100 fi |
12068 | 101 fi |
102 ]) |