Merge commit '12319ff4e84ca616a671216d991dd6eaf1c39c47' into stable
[gnulib.git] / m4 / euidaccess.m4
1 # euidaccess.m4 serial 12
2 dnl Copyright (C) 2002-2010 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 AC_DEFUN([gl_FUNC_NONREENTRANT_EUIDACCESS],
8 [
9   AC_REQUIRE([gl_FUNC_EUIDACCESS])
10   AC_DEFINE([PREFER_NONREENTRANT_EUIDACCESS], [1],
11     [Define this if you prefer euidaccess to return the correct result
12      even if this would make it nonreentrant.  Define this only if your
13      entire application is safe even if the uid or gid might temporarily
14      change.  If your application uses signal handlers or threads it
15      is probably not safe.])
16 ])
17
18 AC_DEFUN([gl_FUNC_EUIDACCESS],
19 [
20   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
21
22   dnl Persuade glibc <unistd.h> to declare euidaccess().
23   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
24
25   AC_REPLACE_FUNCS([euidaccess])
26   if test $ac_cv_func_euidaccess = no; then
27     HAVE_EUIDACCESS=0
28     gl_PREREQ_EUIDACCESS
29   fi
30 ])
31
32 # Prerequisites of lib/euidaccess.c.
33 AC_DEFUN([gl_PREREQ_EUIDACCESS], [
34   dnl Prefer POSIX faccessat over non-standard euidaccess.
35   AC_CHECK_FUNCS_ONCE([faccessat])
36   dnl Try various other non-standard fallbacks.
37   AC_CHECK_HEADERS_ONCE([libgen.h])
38   AC_CHECK_DECLS_ONCE([setregid])
39   AC_REQUIRE([AC_FUNC_GETGROUPS])
40
41   # Solaris 9 needs -lgen to get the eaccess function.
42   # Save and restore LIBS so -lgen isn't added to it.  Otherwise, *all*
43   # programs in the package would end up linked with that potentially-shared
44   # library, inducing unnecessary run-time overhead.
45   LIB_EACCESS=
46   AC_SUBST([LIB_EACCESS])
47   gl_saved_libs=$LIBS
48     AC_SEARCH_LIBS([eaccess], [gen],
49                    [test "$ac_cv_search_eaccess" = "none required" ||
50                     LIB_EACCESS=$ac_cv_search_eaccess])
51     AC_CHECK_FUNCS([eaccess])
52   LIBS=$gl_saved_libs
53 ])