declare smobs in alloc.c
[bpt/emacs.git] / m4 / getgroups.m4
CommitLineData
73dcdb9f
PE
1# serial 18
2
3dnl From Jim Meyering.
4dnl A wrapper around AC_FUNC_GETGROUPS.
5
ba318903 6# Copyright (C) 1996-1997, 1999-2004, 2008-2014 Free Software Foundation, Inc.
73dcdb9f
PE
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# http://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 Ultrix 4.3, 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*) 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 return getgroups (-1, list) != -1;]])],
91 [gl_cv_func_getgroups_works=yes],
92 [gl_cv_func_getgroups_works=no],
93 [case "$host_os" in
94 # Guess yes on glibc systems.
95 *-gnu*) gl_cv_func_getgroups_works="guessing yes" ;;
96 # If we don't know, assume the worst.
97 *) gl_cv_func_getgroups_works="guessing no" ;;
98 esac
99 ])])
100 case "$gl_cv_func_getgroups_works" in
101 *yes) ;;
102 *) REPLACE_GETGROUPS=1 ;;
103 esac
104 fi
105 fi
106 test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS"
107])