1# serial 21 2 3dnl From Jim Meyering. 4dnl A wrapper around AC_FUNC_GETGROUPS. 5 6# Copyright (C) 1996-1997, 1999-2004, 2008-2019 Free Software Foundation, Inc. 7# 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. 11 12m4_version_prereq([2.70], [] ,[ 13 14# This is taken from the following Autoconf patch: 15# https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9 16AC_DEFUN([AC_FUNC_GETGROUPS], 17[ 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]) 22 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. 25 ac_save_LIBS=$LIBS 26 if test $ac_cv_func_getgroups = no; then 27 AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd]) 28 fi 29 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], 34 [AC_RUN_IFELSE( 35 [AC_LANG_PROGRAM( 36 [AC_INCLUDES_DEFAULT], 37 [[/* On NeXTstep 3.2, getgroups (0, 0) always fails. */ 38 return getgroups (0, 0) == -1;]]) 39 ], 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* | 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" ;; 47 esac 48 ]) 49 ]) 50 else 51 ac_cv_func_getgroups_works=no 52 fi 53 case "$ac_cv_func_getgroups_works" in 54 *yes) 55 AC_DEFINE([HAVE_GETGROUPS], [1], 56 [Define to 1 if your system has a working `getgroups' function.]) 57 ;; 58 esac 59 LIBS=$ac_save_LIBS 60])# AC_FUNC_GETGROUPS 61 62]) 63 64AC_DEFUN([gl_FUNC_GETGROUPS], 65[ 66 AC_REQUIRE([AC_TYPE_GETGROUPS]) 67 AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) 68 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 69 70 AC_FUNC_GETGROUPS 71 if test $ac_cv_func_getgroups != yes; then 72 HAVE_GETGROUPS=0 73 else 74 if test "$ac_cv_type_getgroups" != gid_t \ 75 || { case "$ac_cv_func_getgroups_works" in 76 *yes) false;; 77 *) true;; 78 esac 79 }; then 80 REPLACE_GETGROUPS=1 81 AC_DEFINE([GETGROUPS_ZERO_BUG], [1], [Define this to 1 if 82 getgroups(0,NULL) does not return the number of groups.]) 83 else 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 int result = getgroups (-1, list) != -1; 91 free (list); 92 return result;]])], 93 [gl_cv_func_getgroups_works=yes], 94 [gl_cv_func_getgroups_works=no], 95 [case "$host_os" in 96 # Guess yes on glibc systems. 97 *-gnu* | gnu*) gl_cv_func_getgroups_works="guessing yes" ;; 98 # If we don't know, assume the worst. 99 *) gl_cv_func_getgroups_works="guessing no" ;; 100 esac 101 ])]) 102 case "$gl_cv_func_getgroups_works" in 103 *yes) ;; 104 *) REPLACE_GETGROUPS=1 ;; 105 esac 106 fi 107 fi 108 test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS" 109]) 110