Fix last ChangeLog entry.
[gnulib.git] / m4 / getgroups.m4
blobbd746cdf88f32ef916d50aa1f5bd1ebff2e34d9a
1 # serial 24
3 dnl From Jim Meyering.
4 dnl A wrapper around AC_FUNC_GETGROUPS.
6 # Copyright (C) 1996-1997, 1999-2004, 2008-2021 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.
23   ac_save_LIBS=$LIBS
24   if test $ac_cv_func_getgroups = no; then
25     AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd])
26   fi
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],
32       [AC_RUN_IFELSE(
33          [AC_LANG_PROGRAM(
34             [AC_INCLUDES_DEFAULT],
35             [[/* On NeXTstep 3.2, getgroups (0, 0) always fails.  */
36               return getgroups (0, 0) == -1;]])
37          ],
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" ;;
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
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
68   AC_FUNC_GETGROUPS
69   if test $ac_cv_func_getgroups != yes; then
70     HAVE_GETGROUPS=0
71   else
72     if test "$ac_cv_type_getgroups" != gid_t \
73        || { case "$ac_cv_func_getgroups_works" in
74               *yes) false;;
75               *) true;;
76             esac
77           }; then
78       REPLACE_GETGROUPS=1
79       AC_DEFINE([GETGROUPS_ZERO_BUG], [1], [Define this to 1 if
80         getgroups(0,NULL) does not return the number of groups.])
81     else
82       dnl Detect Mac OS X and FreeBSD bug; POSIX requires getgroups(-1,ptr)
83       dnl to fail.
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;
90             free (list);
91             return result;]])],
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* | 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" ;;
101            esac
102           ])])
103       case "$gl_cv_func_getgroups_works" in
104         *yes) ;;
105         *) REPLACE_GETGROUPS=1 ;;
106       esac
107     fi
108   fi
109   test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS"