4 dnl A wrapper around AC_FUNC_GETGROUPS.
6 # Copyright (C) 1996-1997, 1999-2004, 2008-2013 Free Software Foundation, Inc.
8 # This file is free software; the Free Software Foundation
9 # gives unlimited permission to copy and/or distribute it,
10 # with or without modifications, as long as this notice is preserved.
12 m4_version_prereq([2.70], [] ,[
14 # This is taken from the following Autoconf patch:
15 # http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
16 AC_DEFUN([AC_FUNC_GETGROUPS],
18 AC_REQUIRE([AC_TYPE_GETGROUPS])dnl
19 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
20 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
21 AC_CHECK_FUNC([getgroups])
23 # If we don't yet have getgroups, see if it's in -lbsd.
24 # This is reported to be necessary on an ITOS 3000WS running SEIUX 3.1.
26 if test $ac_cv_func_getgroups = no; then
27 AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd])
30 # Run the program to test the functionality of the system-supplied
31 # getgroups function only if there is such a function.
32 if test $ac_cv_func_getgroups = yes; then
33 AC_CACHE_CHECK([for working getgroups], [ac_cv_func_getgroups_works],
36 [AC_INCLUDES_DEFAULT],
37 [[/* On Ultrix 4.3, getgroups (0, 0) always fails. */
38 return getgroups (0, 0) == -1;]])
40 [ac_cv_func_getgroups_works=yes],
41 [ac_cv_func_getgroups_works=no],
42 [case "$host_os" in # ((
43 # Guess yes on glibc systems.
44 *-gnu*) ac_cv_func_getgroups_works="guessing yes" ;;
45 # If we don't know, assume the worst.
46 *) ac_cv_func_getgroups_works="guessing no" ;;
51 ac_cv_func_getgroups_works=no
53 case "$ac_cv_func_getgroups_works" in
55 AC_DEFINE([HAVE_GETGROUPS], [1],
56 [Define to 1 if your system has a working `getgroups' function.])
64 AC_DEFUN([gl_FUNC_GETGROUPS],
66 AC_REQUIRE([AC_TYPE_GETGROUPS])
67 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
68 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
71 if test $ac_cv_func_getgroups != yes; then
74 if test "$ac_cv_type_getgroups" != gid_t \
75 || { case "$ac_cv_func_getgroups_works" in
81 AC_DEFINE([GETGROUPS_ZERO_BUG], [1], [Define this to 1 if
82 getgroups(0,NULL) does not return the number of groups.])
84 dnl Detect FreeBSD bug; POSIX requires getgroups(-1,ptr) to fail.
85 AC_CACHE_CHECK([whether getgroups handles negative values],
86 [gl_cv_func_getgroups_works],
87 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
88 [[int size = getgroups (0, 0);
89 gid_t *list = malloc (size * sizeof *list);
90 return getgroups (-1, list) != -1;]])],
91 [gl_cv_func_getgroups_works=yes],
92 [gl_cv_func_getgroups_works=no],
94 # Guess yes on glibc systems.
95 *-gnu*) gl_cv_func_getgroups_works="guessing yes" ;;
96 # If we don't know, assume the worst.
97 *) gl_cv_func_getgroups_works="guessing no" ;;
100 case "$gl_cv_func_getgroups_works" in
102 *) REPLACE_GETGROUPS=1 ;;
106 test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS"