.
[gnulib.git] / m4 / chown.m4
1 #serial 1
2
3 dnl From Jim Meyering.
4 dnl If you use this macro in a package, you should
5 dnl add the following two lines to acconfig.h:
6 dnl  /* Define to rpl_chown if the replacement function should be used.  */
7 dnl  #undef chown
8 dnl
9
10 AC_DEFUN(jm_FUNC_CHOWN,
11 [AC_REQUIRE([AC_TYPE_UID_T])dnl
12  test -z "$ac_cv_header_unistd_h" \
13    && AC_CHECK_HEADERS(unistd.h)
14  AC_CACHE_CHECK([for working chown], jm_cv_func_working_chown,
15   [AC_TRY_RUN([
16 #   include <sys/types.h>
17 #   include <fcntl.h>
18 #   ifdef HAVE_UNISTD_H
19 #    include <unistd.h>
20 #   endif
21
22     int
23     main ()
24     {
25       char *f = "conftestchown";
26       if (creat (f, 0600) < 0)
27         exit (1);
28       exit (chown (f, (gid_t) -1, (uid_t) -1) == -1 ? 1 : 0);
29     }
30               ],
31              jm_cv_func_working_chown=yes,
32              jm_cv_func_working_chown=no,
33              dnl When crosscompiling, assume chown is broken.
34              jm_cv_func_working_chown=no)
35   ])
36   if test $jm_cv_func_working_chown = no; then
37     LIBOBJS="$LIBOBJS chown.o"
38     AC_DEFINE_UNQUOTED(chown, rpl_chown)
39   fi
40 ])