]> git.cworth.org Git - tar/blob - m4/openat.m4
Imported Upstream version 1.21
[tar] / m4 / openat.m4
1 #serial 16
2 # See if we need to use our replacement for Solaris' openat et al functions.
3
4 dnl Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
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 Jim Meyering.
10
11 AC_DEFUN([gl_FUNC_OPENAT],
12 [
13   AC_LIBOBJ([openat-proc])
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15   AC_CHECK_FUNCS_ONCE([lchmod])
16   AC_CHECK_FUNCS_ONCE([fdopendir])
17   AC_REPLACE_FUNCS([fchmodat mkdirat openat])
18   AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
19   case $ac_cv_func_openat+$ac_cv_func_lstat_dereferences_slashed_symlink in
20   yes+yes) ;;
21   yes+*) AC_LIBOBJ([fstatat]);;
22   *)
23     AC_DEFINE([__OPENAT_PREFIX], [[rpl_]],
24       [Define to rpl_ if the openat replacement function should be used.])
25     gl_PREREQ_OPENAT;;
26   esac
27   gl_FUNC_FCHOWNAT
28 ])
29
30 # gl_FUNC_FCHOWNAT_DEREF_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
31 AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG],
32 [
33   AC_CACHE_CHECK([whether fchownat works with AT_SYMLINK_NOFOLLOW],
34     gl_cv_func_fchownat_nofollow_works,
35     [
36      gl_dangle=conftest.dangle
37      # Remove any remnants of a previous test.
38      rm -f $gl_dangle
39      # Arrange for deletion of the temporary file this test creates.
40      ac_clean_files="$ac_clean_files $gl_dangle"
41      ln -s conftest.no-such $gl_dangle
42      AC_RUN_IFELSE(
43        [AC_LANG_SOURCE(
44           [[
45 #include <fcntl.h>
46 #include <unistd.h>
47 #include <stdlib.h>
48 #include <errno.h>
49 #include <sys/types.h>
50 int
51 main ()
52 {
53   return (fchownat (AT_FDCWD, "$gl_dangle", -1, getgid (),
54                     AT_SYMLINK_NOFOLLOW) != 0
55           && errno == ENOENT);
56 }
57           ]])],
58     [gl_cv_func_fchownat_nofollow_works=yes],
59     [gl_cv_func_fchownat_nofollow_works=no],
60     [gl_cv_func_fchownat_nofollow_works=no],
61     )
62   ])
63   AS_IF([test $gl_cv_func_fchownat_nofollow_works = no], [$1], [$2])
64 ])
65
66 # If we have the fchownat function, and it has the bug (in glibc-2.4)
67 # that it dereferences symlinks even with AT_SYMLINK_NOFOLLOW, then
68 # use the replacement function.
69 # Also use the replacement function if fchownat is simply not available.
70 AC_DEFUN([gl_FUNC_FCHOWNAT],
71 [
72   # Assume we'll use the replacement function.
73   # The only case in which we won't is when we have fchownat, and it works.
74   use_replacement_fchownat=yes
75
76   AC_CHECK_FUNC([fchownat], [have_fchownat=yes], [have_fchownat=no])
77   if test $have_fchownat = yes; then
78     gl_FUNC_FCHOWNAT_DEREF_BUG([], [use_replacement_fchownat=no])
79   fi
80
81   if test $use_replacement_fchownat = yes; then
82     AC_LIBOBJ(fchownat)
83     AC_DEFINE(fchownat, rpl_fchownat,
84       [Define to rpl_fchownat if the replacement function should be used.])
85   fi
86 ])
87
88 AC_DEFUN([gl_PREREQ_OPENAT],
89 [
90   :
91 ])