re-mark 1.29b-2 as not yet uploaded (merge madness!)
[debian/tar] / m4 / fchownat.m4
1 # fchownat.m4 serial 1
2 dnl Copyright (C) 2004-2015 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 # Written by Jim Meyering.
8
9 # If we have the fchownat function, and it has the bug (in glibc-2.4)
10 # that it dereferences symlinks even with AT_SYMLINK_NOFOLLOW, then
11 # use the replacement function.
12 # Also if the fchownat function, like chown, has the trailing slash bug,
13 # use the replacement function.
14 # Also use the replacement function if fchownat is simply not available.
15 AC_DEFUN([gl_FUNC_FCHOWNAT],
16 [
17   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
18   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
19   AC_REQUIRE([gl_FUNC_CHOWN])
20   AC_CHECK_FUNC([fchownat],
21     [gl_FUNC_FCHOWNAT_DEREF_BUG(
22        [REPLACE_FCHOWNAT=1
23         AC_DEFINE([FCHOWNAT_NOFOLLOW_BUG], [1],
24                   [Define to 1 if your platform has fchownat, but it cannot
25                    perform lchown tasks.])
26        ])
27      gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG(
28        [REPLACE_FCHOWNAT=1
29         AC_DEFINE([FCHOWNAT_EMPTY_FILENAME_BUG], [1],
30                   [Define to 1 if your platform has fchownat, but it does
31                    not reject an empty file name.])
32        ])
33      if test $REPLACE_CHOWN = 1; then
34        REPLACE_FCHOWNAT=1
35      fi],
36     [HAVE_FCHOWNAT=0])
37 ])
38
39 # gl_FUNC_FCHOWNAT_DEREF_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
40 AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG],
41 [
42   dnl Persuade glibc's <unistd.h> to declare fchownat().
43   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
44
45   AC_CACHE_CHECK([whether fchownat works with AT_SYMLINK_NOFOLLOW],
46     gl_cv_func_fchownat_nofollow_works,
47     [
48      gl_dangle=conftest.dangle
49      # Remove any remnants of a previous test.
50      rm -f $gl_dangle
51      # Arrange for deletion of the temporary file this test creates.
52      ac_clean_files="$ac_clean_files $gl_dangle"
53      ln -s conftest.no-such $gl_dangle
54      AC_RUN_IFELSE(
55        [AC_LANG_SOURCE(
56           [[
57 #include <fcntl.h>
58 #include <unistd.h>
59 #include <stdlib.h>
60 #include <errno.h>
61 #include <sys/types.h>
62 int
63 main ()
64 {
65   return (fchownat (AT_FDCWD, "$gl_dangle", -1, getgid (),
66                     AT_SYMLINK_NOFOLLOW) != 0
67           && errno == ENOENT);
68 }
69           ]])],
70     [gl_cv_func_fchownat_nofollow_works=yes],
71     [gl_cv_func_fchownat_nofollow_works=no],
72     [gl_cv_func_fchownat_nofollow_works=no],
73     )
74   ])
75   AS_IF([test $gl_cv_func_fchownat_nofollow_works = no], [$1], [$2])
76 ])
77
78 # gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
79 AC_DEFUN([gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG],
80 [
81   dnl Persuade glibc's <unistd.h> to declare fchownat().
82   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
83
84   AC_CACHE_CHECK([whether fchownat works with an empty file name],
85     [gl_cv_func_fchownat_empty_filename_works],
86     [AC_RUN_IFELSE(
87        [AC_LANG_PROGRAM(
88           [[#include <unistd.h>
89             #include <fcntl.h>
90           ]],
91           [[int fd;
92             int ret;
93             if (mkdir ("conftestdir", 0700) < 0)
94               return 2;
95             fd = open ("conftestdir", O_RDONLY);
96             if (fd < 0)
97               return 3;
98             ret = fchownat (fd, "", -1, -1, 0);
99             close (fd);
100             rmdir ("conftestdir");
101             return ret == 0;
102           ]])],
103        [gl_cv_func_fchownat_empty_filename_works=yes],
104        [gl_cv_func_fchownat_empty_filename_works=no],
105        [gl_cv_func_fchownat_empty_filename_works="guessing no"])
106     ])
107   AS_IF([test "$gl_cv_func_fchownat_empty_filename_works" != yes], [$1], [$2])
108 ])