* admin/update_autogen (commit): Prepend "# " to commit message.
[emacs.git] / m4 / getgroups.m4
blob8989a5ce430dabbf692e2fa1ac2ad09596f972f0
1 # serial 18
3 dnl From Jim Meyering.
4 dnl A wrapper around AC_FUNC_GETGROUPS.
6 # Copyright (C) 1996-1997, 1999-2004, 2008-2015 Free Software
7 # Foundation, Inc.
9 # This file is free software; the Free Software Foundation
10 # gives unlimited permission to copy and/or distribute it,
11 # with or without modifications, as long as this notice is preserved.
13 m4_version_prereq([2.70], [] ,[
15 # This is taken from the following Autoconf patch:
16 # http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
17 AC_DEFUN([AC_FUNC_GETGROUPS],
19   AC_REQUIRE([AC_TYPE_GETGROUPS])dnl
20   AC_REQUIRE([AC_TYPE_SIZE_T])dnl
21   AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
22   AC_CHECK_FUNC([getgroups])
24   # If we don't yet have getgroups, see if it's in -lbsd.
25   # This is reported to be necessary on an ITOS 3000WS running SEIUX 3.1.
26   ac_save_LIBS=$LIBS
27   if test $ac_cv_func_getgroups = no; then
28     AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd])
29   fi
31   # Run the program to test the functionality of the system-supplied
32   # getgroups function only if there is such a function.
33   if test $ac_cv_func_getgroups = yes; then
34     AC_CACHE_CHECK([for working getgroups], [ac_cv_func_getgroups_works],
35       [AC_RUN_IFELSE(
36          [AC_LANG_PROGRAM(
37             [AC_INCLUDES_DEFAULT],
38             [[/* On Ultrix 4.3, getgroups (0, 0) always fails.  */
39               return getgroups (0, 0) == -1;]])
40          ],
41          [ac_cv_func_getgroups_works=yes],
42          [ac_cv_func_getgroups_works=no],
43          [case "$host_os" in # ((
44                     # Guess yes on glibc systems.
45             *-gnu*) ac_cv_func_getgroups_works="guessing yes" ;;
46                     # If we don't know, assume the worst.
47             *)      ac_cv_func_getgroups_works="guessing no" ;;
48           esac
49          ])
50       ])
51   else
52     ac_cv_func_getgroups_works=no
53   fi
54   case "$ac_cv_func_getgroups_works" in
55     *yes)
56       AC_DEFINE([HAVE_GETGROUPS], [1],
57         [Define to 1 if your system has a working `getgroups' function.])
58       ;;
59   esac
60   LIBS=$ac_save_LIBS
61 ])# AC_FUNC_GETGROUPS
65 AC_DEFUN([gl_FUNC_GETGROUPS],
67   AC_REQUIRE([AC_TYPE_GETGROUPS])
68   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
69   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
71   AC_FUNC_GETGROUPS
72   if test $ac_cv_func_getgroups != yes; then
73     HAVE_GETGROUPS=0
74   else
75     if test "$ac_cv_type_getgroups" != gid_t \
76        || { case "$ac_cv_func_getgroups_works" in
77               *yes) false;;
78               *) true;;
79             esac
80           }; then
81       REPLACE_GETGROUPS=1
82       AC_DEFINE([GETGROUPS_ZERO_BUG], [1], [Define this to 1 if
83         getgroups(0,NULL) does not return the number of groups.])
84     else
85       dnl Detect FreeBSD bug; POSIX requires getgroups(-1,ptr) to fail.
86       AC_CACHE_CHECK([whether getgroups handles negative values],
87         [gl_cv_func_getgroups_works],
88         [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
89           [[int size = getgroups (0, 0);
90             gid_t *list = malloc (size * sizeof *list);
91             return getgroups (-1, list) != -1;]])],
92           [gl_cv_func_getgroups_works=yes],
93           [gl_cv_func_getgroups_works=no],
94           [case "$host_os" in
95                      # Guess yes on glibc systems.
96              *-gnu*) gl_cv_func_getgroups_works="guessing yes" ;;
97                      # If we don't know, assume the worst.
98              *)      gl_cv_func_getgroups_works="guessing no" ;;
99            esac
100           ])])
101       case "$gl_cv_func_getgroups_works" in
102         *yes) ;;
103         *) REPLACE_GETGROUPS=1 ;;
104       esac
105     fi
106   fi
107   test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS"