Debian Codegraph @

m4/getgroups.m4

raw
1 # getgroups.m4
2 # serial 25
3 dnl Copyright (C) 1996-1997, 1999-2004, 2008-2026 Free Software Foundation,
4 dnl Inc.
5 dnl This file is free software; the Free Software Foundation
6 dnl gives unlimited permission to copy and/or distribute it,
7 dnl with or without modifications, as long as this notice is preserved.
8 dnl This file is offered as-is, without any warranty.
9
10 dnl From Jim Meyering.
11 dnl A wrapper around AC_FUNC_GETGROUPS.
12
13 # This is taken from the following Autoconf patch:
14 # https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
15 AC_DEFUN([AC_FUNC_GETGROUPS],
16 [
17 AC_REQUIRE([AC_TYPE_GETGROUPS])dnl
18 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
19 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
20 AC_CHECK_FUNC([getgroups])
21
22 # If we don't yet have getgroups, see if it's in -lbsd.
23 # This is reported to be necessary on an ITOS 3000WS running SEIUX 3.1.
24 gl_saved_LIBS=$LIBS
25 if test $ac_cv_func_getgroups = no; then
26 AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd])
27 fi
28
29 # Run the program to test the functionality of the system-supplied
30 # getgroups function only if there is such a function.
31 if test $ac_cv_func_getgroups = yes; then
32 AC_CACHE_CHECK([for working getgroups], [ac_cv_func_getgroups_works],
33 [AC_RUN_IFELSE(
34 [AC_LANG_PROGRAM(
35 [AC_INCLUDES_DEFAULT],
36 [[/* On NeXTstep 3.2, getgroups (0, 0) always fails. */
37 return getgroups (0, 0) == -1;]])
38 ],
39 [ac_cv_func_getgroups_works=yes],
40 [ac_cv_func_getgroups_works=no],
41 [case "$host_os" in # ((
42 # Guess yes on glibc systems.
43 *-gnu* | gnu*) ac_cv_func_getgroups_works="guessing yes" ;;
44 # Guess yes on musl systems.
45 *-musl*) ac_cv_func_getgroups_works="guessing yes" ;;
46 # If we don't know, obey --enable-cross-guesses.
47 *) ac_cv_func_getgroups_works="$gl_cross_guess_normal" ;;
48 esac
49 ])
50 ])
51 else
52 ac_cv_func_getgroups_works=no
53 fi
54 case "$ac_cv_func_getgroups_works" in
55 *yes)
56 AC_DEFINE([HAVE_GETGROUPS], [1],
57 [Define to 1 if your system has a working `getgroups' function.])
58 ;;
59 esac
60 LIBS=$gl_saved_LIBS
61 ])# AC_FUNC_GETGROUPS
62
63 AC_DEFUN([gl_FUNC_GETGROUPS],
64 [
65 AC_REQUIRE([AC_TYPE_GETGROUPS])
66 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
67 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
68
69 AC_FUNC_GETGROUPS
70 if test $ac_cv_func_getgroups != yes; then
71 HAVE_GETGROUPS=0
72 else
73 if test "$ac_cv_type_getgroups" != gid_t \
74 || { case "$ac_cv_func_getgroups_works" in
75 *yes) false;;
76 *) true;;
77 esac
78 }; then
79 REPLACE_GETGROUPS=1
80 AC_DEFINE([GETGROUPS_ZERO_BUG], [1], [Define this to 1 if
81 getgroups(0,NULL) does not return the number of groups.])
82 else
83 dnl Detect Mac OS X and FreeBSD bug; POSIX requires getgroups(-1,ptr)
84 dnl 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 # Guess yes on musl systems.
99 *-musl*) gl_cv_func_getgroups_works="guessing yes" ;;
100 # If we don't know, obey --enable-cross-guesses.
101 *) gl_cv_func_getgroups_works="$gl_cross_guess_normal" ;;
102 esac
103 ])])
104 case "$gl_cv_func_getgroups_works" in
105 *yes) ;;
106 *) REPLACE_GETGROUPS=1 ;;
107 esac
108 fi
109 fi
110 test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS"
111 ])