4 dnl A wrapper around AC_FUNC_GETGROUPS.
6 # Copyright (C) 1996-1997, 1999-2004, 2008-2020 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 # This is taken from the following Autoconf patch:
13 # https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
14 AC_DEFUN([AC_FUNC_GETGROUPS],
16 AC_REQUIRE([AC_TYPE_GETGROUPS])dnl
17 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
18 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
19 AC_CHECK_FUNC([getgroups])
21 # If we don't yet have getgroups, see if it's in -lbsd.
22 # This is reported to be necessary on an ITOS 3000WS running SEIUX 3.1.
24 if test $ac_cv_func_getgroups = no; then
25 AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd])
28 # Run the program to test the functionality of the system-supplied
29 # getgroups function only if there is such a function.
30 if test $ac_cv_func_getgroups = yes; then
31 AC_CACHE_CHECK([for working getgroups], [ac_cv_func_getgroups_works],
34 [AC_INCLUDES_DEFAULT],
35 [[/* On NeXTstep 3.2, getgroups (0, 0) always fails. */
36 return getgroups (0, 0) == -1;]])
38 [ac_cv_func_getgroups_works=yes],
39 [ac_cv_func_getgroups_works=no],
40 [case "$host_os" in # ((
41 # Guess yes on glibc systems.
42 *-gnu* | gnu*) ac_cv_func_getgroups_works="guessing yes" ;;
43 # Guess yes on musl systems.
44 *-musl*) ac_cv_func_getgroups_works="guessing yes" ;;
45 # If we don't know, obey --enable-cross-guesses.
46 *) ac_cv_func_getgroups_works="$gl_cross_guess_normal" ;;
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.])
62 AC_DEFUN([gl_FUNC_GETGROUPS],
64 AC_REQUIRE([AC_TYPE_GETGROUPS])
65 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
66 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
69 if test $ac_cv_func_getgroups != yes; then
72 if test "$ac_cv_type_getgroups" != gid_t \
73 || { case "$ac_cv_func_getgroups_works" in
79 AC_DEFINE([GETGROUPS_ZERO_BUG], [1], [Define this to 1 if
80 getgroups(0,NULL) does not return the number of groups.])
82 dnl Detect Mac OS X and FreeBSD bug; POSIX requires getgroups(-1,ptr)
84 AC_CACHE_CHECK([whether getgroups handles negative values],
85 [gl_cv_func_getgroups_works],
86 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
87 [[int size = getgroups (0, 0);
88 gid_t *list = malloc (size * sizeof *list);
89 int result = getgroups (-1, list) != -1;
92 [gl_cv_func_getgroups_works=yes],
93 [gl_cv_func_getgroups_works=no],
95 # Guess yes on glibc systems.
96 *-gnu* | gnu*) gl_cv_func_getgroups_works="guessing yes" ;;
97 # Guess yes on musl systems.
98 *-musl*) gl_cv_func_getgroups_works="guessing yes" ;;
99 # If we don't know, obey --enable-cross-guesses.
100 *) gl_cv_func_getgroups_works="$gl_cross_guess_normal" ;;
103 case "$gl_cv_func_getgroups_works" in
105 *) REPLACE_GETGROUPS=1 ;;
109 test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS"