Don't check for fcntl.h, and don't test for HAVE_FCNTL_H.
[gnulib.git] / m4 / chown.m4
1 #serial 14
2 # Determine whether we need the chown wrapper.
3
4 dnl Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free
5 dnl Software Foundation, Inc.
6
7 dnl This file is free software; the Free Software Foundation
8 dnl gives unlimited permission to copy and/or distribute it,
9 dnl with or without modifications, as long as this notice is preserved.
10
11 # chown should accept arguments of -1 for uid and gid, and it should
12 # dereference symlinks.  If it doesn't, arrange to use the replacement
13 # function.
14
15 # From Jim Meyering.
16
17 AC_DEFUN([gl_FUNC_CHOWN],
18 [
19   AC_REQUIRE([AC_TYPE_UID_T])
20   AC_REQUIRE([AC_FUNC_CHOWN])
21   AC_REQUIRE([gl_FUNC_CHOWN_FOLLOWS_SYMLINK])
22
23   if test $ac_cv_func_chown_works = no; then
24     AC_DEFINE(CHOWN_FAILS_TO_HONOR_ID_OF_NEGATIVE_ONE, 1,
25       [Define if chown is not POSIX compliant regarding IDs of -1.])
26   fi
27
28   # If chown has either of the above problems, then we need the wrapper.
29   if test $ac_cv_func_chown_works$gl_cv_func_chown_follows_symlink = yesyes; then
30     : # no wrapper needed
31   else
32     AC_LIBOBJ(chown)
33     AC_DEFINE(chown, rpl_chown,
34       [Define to rpl_chown if the replacement function should be used.])
35     gl_PREREQ_CHOWN
36   fi
37 ])
38
39 # Determine whether chown follows symlinks (it should).
40 AC_DEFUN([gl_FUNC_CHOWN_FOLLOWS_SYMLINK],
41 [
42   AC_CACHE_CHECK(
43     [whether chown(2) dereferences symlinks],
44     gl_cv_func_chown_follows_symlink,
45     [
46       AC_RUN_IFELSE([AC_LANG_SOURCE([[
47 #ifdef HAVE_UNISTD_H
48 # include <unistd.h>
49 #endif
50 #include <stdlib.h>
51 #include <errno.h>
52
53         int
54         main ()
55         {
56           char const *dangling_symlink = "conftest.dangle";
57
58           unlink (dangling_symlink);
59           if (symlink ("conftest.no-such", dangling_symlink))
60             abort ();
61
62           /* Exit successfully on a conforming system,
63              i.e., where chown must fail with ENOENT.  */
64           exit ( ! (chown (dangling_symlink, getuid (), getgid ()) != 0
65                     && errno == ENOENT));
66         }
67         ]])],
68         [gl_cv_func_chown_follows_symlink=yes],
69         [gl_cv_func_chown_follows_symlink=no],
70         [gl_cv_func_chown_follows_symlink=yes]
71       )
72     ]
73   )
74
75   if test $gl_cv_func_chown_follows_symlink = no; then
76     AC_DEFINE(CHOWN_MODIFIES_SYMLINK, 1,
77       [Define if chown modifies symlinks.])
78   fi
79 ])
80
81 # Prerequisites of lib/chown.c.
82 AC_DEFUN([gl_PREREQ_CHOWN],
83 [
84   AC_CHECK_HEADERS_ONCE(unistd.h)
85   AC_CHECK_FUNC([fchown], , [AC_LIBOBJ(fchown-stub)])
86 ])