4 dnl A wrapper around AC_FUNC_GETGROUPS.
6 # Copyright (C) 1996-1997, 1999-2004, 2008-2017 Free Software
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.
27 if test $ac_cv_func_getgroups = no; then
28 AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd])
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],
37 [AC_INCLUDES_DEFAULT],
38 [[/* On Ultrix 4.3, getgroups (0, 0) always fails. */
39 return getgroups (0, 0) == -1;]])
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" ;;
52 ac_cv_func_getgroups_works=no
54 case "$ac_cv_func_getgroups_works" in
56 AC_DEFINE([HAVE_GETGROUPS], [1],
57 [Define to 1 if your system has a working `getgroups' function.])
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
72 if test $ac_cv_func_getgroups != yes; then
75 if test "$ac_cv_type_getgroups" != gid_t \
76 || { case "$ac_cv_func_getgroups_works" in
82 AC_DEFINE([GETGROUPS_ZERO_BUG], [1], [Define this to 1 if
83 getgroups(0,NULL) does not return the number of groups.])
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 int result = getgroups (-1, list) != -1;
94 [gl_cv_func_getgroups_works=yes],
95 [gl_cv_func_getgroups_works=no],
97 # Guess yes on glibc systems.
98 *-gnu*) gl_cv_func_getgroups_works="guessing yes" ;;
99 # If we don't know, assume the worst.
100 *) gl_cv_func_getgroups_works="guessing no" ;;
103 case "$gl_cv_func_getgroups_works" in
105 *) REPLACE_GETGROUPS=1 ;;
109 test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS"