* m4/acl.m4 (gl_ACL_GET_FILE): Fix logic error.
[gnulib.git] / m4 / acl.m4
1 # acl.m4 - check for access control list (ACL) primitives
2
3 # Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
7
8 # Written by Paul Eggert and Jim Meyering.
9
10 AC_DEFUN([AC_FUNC_ACL],
11 [
12   AC_LIBOBJ([acl])
13
14   dnl Prerequisites of lib/acl.c.
15   AC_CHECK_HEADERS(sys/acl.h)
16   AC_CHECK_FUNCS(acl)
17   ac_save_LIBS="$LIBS"
18     AC_SEARCH_LIBS(acl_get_file, acl,
19                    [test "$ac_cv_search_acl_get_file" = "none required" ||
20                     LIB_ACL=$ac_cv_search_acl_get_file])
21     AC_SUBST(LIB_ACL)
22     AC_CHECK_HEADERS(acl/libacl.h)
23     AC_CHECK_FUNCS(acl_get_file acl_get_fd acl_set_file acl_set_fd \
24                    acl_free acl_from_mode acl_from_text acl_to_text \
25                    acl_delete_def_file acl_entries acl_extended_file)
26     if test "$ac_cv_header_sys_acl_h" = yes; then
27       use_acl=1
28       if test "$ac_cv_func_acl_get_file" = yes; then
29         # If we detect the acl_get_file bug, disable ACL support altogether.
30         gl_ACL_GET_FILE( , [use_acl=0])
31       fi
32     else
33       use_acl=0
34     fi
35   LIBS="$ac_save_LIBS"
36   AC_DEFINE_UNQUOTED(USE_ACL, $use_acl,
37                      [Define if you want access control list support.])
38 ])
39
40 # gl_ACL_GET_FILE(IF-WORKS, IF-NOT)
41 # -------------------------------------
42 # If `acl_get_file' works (does not have a particular bug),
43 # run IF-WORKS, otherwise, IF-NOT.
44 # This tests for a Darwin 8.7.0 bug, whereby acl_get_file returns NULL,
45 # but sets errno = ENOENT for an existing file or directory.
46 AC_DEFUN([gl_ACL_GET_FILE],
47 [
48   AC_CACHE_CHECK([for working acl_get_file], gl_cv_func_working_acl_get_file,
49     [AC_RUN_IFELSE(
50        [AC_LANG_PROGRAM(
51           [[#include <sys/types.h>
52            #include <sys/acl.h>
53            #include <errno.h>
54           ]],
55           [[return !! (!acl_get_file (".", ACL_TYPE_ACCESS)
56                        && errno == ENOENT);]])],
57        [gl_cv_func_working_acl_get_file=yes],
58        [gl_cv_func_working_acl_get_file=no],
59        [gl_cv_func_working_acl_get_file=cross-compiling])])
60
61   AS_IF([test $gl_cv_func_working_acl_get_file = yes], [$1], [$2])
62 ])