c14fb8f284b969903b9d0ea5d271f024f803b5bd
[gnulib.git] / m4 / euidaccess.m4
1 # euidaccess.m4 serial 4
2 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License.  As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 AC_DEFUN([gl_FUNC_NONREENTRANT_EUIDACCESS],
10 [
11   AC_REQUIRE([gl_FUNC_EUIDACCESS])
12   AC_DEFINE([PREFER_NONREENTRANT_EUIDACCESS], 1,
13     [Define this if you prefer euidaccess to return the correct result
14      even if this would make it nonreentrant.  Define this only if your
15      entire application is safe even if the uid or gid might temporarily
16      change.  If your application uses signal handlers or threads it
17      is probably not safe.])
18 ])
19
20 AC_DEFUN([gl_FUNC_EUIDACCESS],
21 [
22   dnl Persuade glibc <unistd.h> to declare euidaccess().
23   AC_REQUIRE([AC_GNU_SOURCE])
24
25   AC_CHECK_DECLS_ONCE([euidaccess])
26   AC_REPLACE_FUNCS(euidaccess)
27   if test $ac_cv_func_euidaccess = no; then
28     gl_PREREQ_EUIDACCESS
29   fi
30 ])
31
32 # Prerequisites of lib/euidaccess.c.
33 AC_DEFUN([gl_PREREQ_EUIDACCESS], [
34   AC_CHECK_HEADERS_ONCE(libgen.h)
35   AC_CHECK_DECLS_ONCE(setregid)
36   AC_REQUIRE([AC_FUNC_GETGROUPS])
37   AC_REQUIRE([AC_HEADER_STAT])
38
39   # Solaris 9 needs -lgen to get the eaccess function.
40   # Save and restore LIBS so -lgen isn't added to it.  Otherwise, *all*
41   # programs in the package would end up linked with that potentially-shared
42   # library, inducing unnecessary run-time overhead.
43   gl_saved_libs=$LIBS
44     AC_SEARCH_LIBS(eaccess, [gen],
45                    [test "$ac_cv_search_eaccess" = "none required" ||
46                     LIB_EACCESS=$ac_cv_search_eaccess])
47     AC_SUBST(LIB_EACCESS)
48     AC_CHECK_FUNCS(eaccess)
49   LIBS=$gl_saved_libs
50 ])
51