1# This file is part of Autoconf.                       -*- Autoconf -*-
2# Checking for functions.
3# Copyright 2000, 2001
4# Free Software Foundation, Inc.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2, or (at your option)
9# any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19# 02111-1307, USA.
20#
21# As a special exception, the Free Software Foundation gives unlimited
22# permission to copy, distribute and modify the configure scripts that
23# are the output of Autoconf.  You need not follow the terms of the GNU
24# General Public License when using or distributing such scripts, even
25# though portions of the text of Autoconf appear in them.  The GNU
26# General Public License (GPL) does govern all other use of the material
27# that constitutes the Autoconf program.
28#
29# Certain portions of the Autoconf source text are designed to be copied
30# (in certain cases, depending on the input) into the output of
31# Autoconf.  We call these the "data" portions.  The rest of the Autoconf
32# source text consists of comments plus executable code that decides which
33# of the data portions to output in any given case.  We call these
34# comments and executable code the "non-data" portions.  Autoconf never
35# copies any of the non-data portions into its output.
36#
37# This special exception to the GPL applies to versions of Autoconf
38# released by the Free Software Foundation.  When you make and
39# distribute a modified version of Autoconf, you may extend this special
40# exception to the GPL to apply to your modified version as well, *unless*
41# your modified version has the potential to copy into its output some
42# of the text that was the non-data portion of the version that you started
43# with.  (In other words, unless your change moves or copies text from
44# the non-data portions to the data portions.)  If your modification has
45# such potential, you must delete any notice of this special exception
46# to the GPL from your modified version.
47#
48# Written by David MacKenzie, with help from
49# Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
50# Roland McGrath, Noah Friedman, david d zuhn, and many others.
51
52
53# Table of contents
54#
55# 1. Generic tests for functions.
56# 2. Tests for specific functions.
57
58
59## -------------------------------- ##
60## 1. Generic tests for functions.  ##
61## -------------------------------- ##
62
63
64# AC_CHECK_FUNC(FUNCTION, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
65# -----------------------------------------------------------------
66AC_DEFUN([AC_CHECK_FUNC],
67[AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$1])dnl
68AC_CACHE_CHECK([for $1], ac_var,
69[AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY([$1])],
70                [AS_VAR_SET(ac_var, yes)],
71                [AS_VAR_SET(ac_var, no)])])
72AS_IF([test AS_VAR_GET(ac_var) = yes], [$2], [$3])dnl
73AS_VAR_POPDEF([ac_var])dnl
74])# AC_CHECK_FUNC
75
76
77# AC_CHECK_FUNCS(FUNCTION..., [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
78# ---------------------------------------------------------------------
79AC_DEFUN([AC_CHECK_FUNCS],
80[AC_FOREACH([AC_Func], [$1],
81  [AH_TEMPLATE(AS_TR_CPP(HAVE_[]AC_Func),
82               [Define if you have the `]AC_Func[' function.])])dnl
83for ac_func in $1
84do
85AC_CHECK_FUNC($ac_func,
86              [AC_DEFINE_UNQUOTED([AS_TR_CPP([HAVE_$ac_func])]) $2],
87              [$3])dnl
88done
89])
90
91
92# AC_REPLACE_FUNCS(FUNCTION...)
93# -----------------------------
94AC_DEFUN([AC_REPLACE_FUNCS],
95[AC_FOREACH([AC_Func], [$1], [AC_LIBSOURCE(AC_Func.c)])dnl
96AC_CHECK_FUNCS([$1], , [_AC_LIBOBJ($ac_func)])
97])
98
99
100# AU::AC_FUNC_CHECK
101# -----------------
102AU_ALIAS([AC_FUNC_CHECK], [AC_CHECK_FUNC])
103
104
105# AU::AC_HAVE_FUNCS
106# -----------------
107AU_ALIAS([AC_HAVE_FUNCS], [AC_CHECK_FUNCS])
108
109
110
111
112## --------------------------------- ##
113## 2. Tests for specific functions.  ##
114## --------------------------------- ##
115
116
117# The macros are sorted:
118#
119# 1. AC_FUNC_* macros are sorted by alphabetical order.
120#
121# 2. Helping macros such as _AC_LIBOBJ_* are before the macro that
122#    uses it.
123#
124# 3. Obsolete macros are right after the modern macro.
125
126
127
128# _AC_LIBOBJ_ALLOCA
129# -----------------
130# Set up the LIBOBJ replacement of `alloca'.  Well, not exactly
131# AC_LIBOBJ since we actually set the output variable `ALLOCA'.
132# Nevertheless, for Automake, AC_LIBSOURCES it.
133m4_define([_AC_LIBOBJ_ALLOCA],
134[# The SVR3 libPW and SVR4 libucb both contain incompatible functions
135# that cause trouble.  Some versions do not even contain alloca or
136# contain a buggy version.  If you still want to use their alloca,
137# use ar to extract alloca.o from them instead of compiling alloca.c.
138AC_LIBSOURCES(alloca.c)
139AC_SUBST(ALLOCA, alloca.$ac_objext)dnl
140AC_DEFINE(C_ALLOCA, 1, [Define if using `alloca.c'.])
141
142AC_CACHE_CHECK(whether `alloca.c' needs Cray hooks, ac_cv_os_cray,
143[AC_EGREP_CPP(webecray,
144[#if defined(CRAY) && ! defined(CRAY2)
145webecray
146#else
147wenotbecray
148#endif
149], ac_cv_os_cray=yes, ac_cv_os_cray=no)])
150if test $ac_cv_os_cray = yes; then
151  for ac_func in _getb67 GETB67 getb67; do
152    AC_CHECK_FUNC($ac_func,
153  		  [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func,
154  				      [Define to one of `_getb67', `GETB67',
155  				       `getb67' for Cray-2 and Cray-YMP
156                                       systems. This function is required for
157                                       `alloca.c' support on those systems.])
158    break])
159  done
160fi
161
162AC_CACHE_CHECK([stack direction for C alloca],
163               [ac_cv_c_stack_direction],
164[AC_RUN_IFELSE([AC_LANG_SOURCE(
165[int
166find_stack_direction ()
167{
168  static char *addr = 0;
169  auto char dummy;
170  if (addr == 0)
171    {
172      addr = &dummy;
173      return find_stack_direction ();
174    }
175  else
176    return (&dummy > addr) ? 1 : -1;
177}
178
179int
180main ()
181{
182  exit (find_stack_direction () < 0);
183}])],
184               [ac_cv_c_stack_direction=1],
185               [ac_cv_c_stack_direction=-1],
186               [ac_cv_c_stack_direction=0])])
187AH_VERBATIM([STACK_DIRECTION],
188[/* If using the C implementation of alloca, define if you know the
189   direction of stack growth for your system; otherwise it will be
190   automatically deduced at run-time.
191        STACK_DIRECTION > 0 => grows toward higher addresses
192        STACK_DIRECTION < 0 => grows toward lower addresses
193        STACK_DIRECTION = 0 => direction of growth unknown */
194@%:@undef STACK_DIRECTION])dnl
195AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
196])# _AC_LIBOBJ_ALLOCA
197
198
199# AC_FUNC_ALLOCA
200# --------------
201AC_DEFUN([AC_FUNC_ALLOCA],
202[# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
203# for constant arguments.  Useless!
204AC_CACHE_CHECK([for working alloca.h], ac_cv_working_alloca_h,
205[AC_TRY_LINK([@%:@include <alloca.h>],
206  [char *p = (char *) alloca (2 * sizeof (int));],
207  ac_cv_working_alloca_h=yes, ac_cv_working_alloca_h=no)])
208if test $ac_cv_working_alloca_h = yes; then
209  AC_DEFINE(HAVE_ALLOCA_H, 1,
210            [Define if you have <alloca.h> and it should be used
211             (not on Ultrix).])
212fi
213
214AC_CACHE_CHECK([for alloca], ac_cv_func_alloca_works,
215[AC_TRY_LINK(
216[#ifdef __GNUC__
217# define alloca __builtin_alloca
218#else
219# ifdef _MSC_VER
220#  include <malloc.h>
221#  define alloca _alloca
222# else
223#  if HAVE_ALLOCA_H
224#   include <alloca.h>
225#  else
226#   ifdef _AIX
227 #pragma alloca
228#   else
229#    ifndef alloca /* predefined by HP cc +Olibcalls */
230char *alloca ();
231#    endif
232#   endif
233#  endif
234# endif
235#endif
236], [char *p = (char *) alloca (1);],
237  ac_cv_func_alloca_works=yes, ac_cv_func_alloca_works=no)])
238
239if test $ac_cv_func_alloca_works = yes; then
240  AC_DEFINE(HAVE_ALLOCA, 1,
241            [Define if you have `alloca', as a function or macro.])
242else
243  _AC_LIBOBJ_ALLOCA
244fi
245])# AC_FUNC_ALLOCA
246
247
248# AU::AC_ALLOCA
249# -------------
250AU_ALIAS([AC_ALLOCA], [AC_FUNC_ALLOCA])
251
252
253# AC_FUNC_CHOWN
254# -------------
255# Determine whether chown accepts arguments of -1 for uid and gid.
256AC_DEFUN([AC_FUNC_CHOWN],
257[AC_REQUIRE([AC_TYPE_UID_T])dnl
258AC_CHECK_HEADERS(unistd.h)
259AC_CACHE_CHECK([for working chown], ac_cv_func_chown_works,
260[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
261#include <fcntl.h>
262],
263[[  char *f = "conftest.chown";
264  struct stat before, after;
265
266  if (creat (f, 0600) < 0)
267    exit (1);
268  if (stat (f, &before) < 0)
269    exit (1);
270  if (chown (f, (uid_t) -1, (gid_t) -1) == -1)
271    exit (1);
272  if (stat (f, &after) < 0)
273    exit (1);
274  exit ((before.st_uid == after.st_uid
275         && before.st_gid == after.st_gid) ? 0 : 1);
276]])],
277               [ac_cv_func_chown_works=yes],
278               [ac_cv_func_chown_works=no],
279               [ac_cv_func_chown_works=no])
280rm -f conftest.chown
281])
282if test $ac_cv_func_chown_works = yes; then
283  AC_DEFINE(HAVE_CHOWN, 1,
284            [Define if your system has a working `chown' function.])
285fi
286])# AC_FUNC_CHOWN
287
288
289# AC_FUNC_CLOSEDIR_VOID
290# ---------------------
291# Check whether closedir returns void, and #define CLOSEDIR_VOID in
292# that case.
293AC_DEFUN([AC_FUNC_CLOSEDIR_VOID],
294[AC_REQUIRE([AC_HEADER_DIRENT])dnl
295AC_CACHE_CHECK([whether closedir returns void],
296               [ac_cv_func_closedir_void],
297[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
298#include <$ac_header_dirent>
299#ifndef __cplusplus
300int closedir ();
301#endif
302],
303                                [[exit (closedir (opendir (".")) != 0);]])],
304               [ac_cv_func_closedir_void=no],
305               [ac_cv_func_closedir_void=yes],
306               [ac_cv_func_closedir_void=yes])])
307if test $ac_cv_func_closedir_void = yes; then
308  AC_DEFINE(CLOSEDIR_VOID, 1,
309            [Define if the `closedir' function returns void instead of `int'.])
310fi
311])
312
313
314# AC_FUNC_ERROR_AT_LINE
315# ---------------------
316AC_DEFUN([AC_FUNC_ERROR_AT_LINE],
317[AC_LIBSOURCES([error.h, error.c])dnl
318AC_CACHE_CHECK([for error_at_line], ac_cv_lib_error_at_line,
319[AC_TRY_LINK([],[error_at_line (0, 0, "", 0, "");],
320             [ac_cv_lib_error_at_line=yes],
321             [ac_cv_lib_error_at_line=no])])
322if test $ac_cv_lib_error_at_line = no; then
323  AC_LIBOBJ(error)
324fi
325])
326
327
328# AU::AM_FUNC_ERROR_AT_LINE
329# -------------------------
330AU_ALIAS([AM_FUNC_ERROR_AT_LINE], [AC_FUNC_ERROR_AT_LINE])
331
332
333# AC_FUNC_FNMATCH
334# ---------------
335# We look for fnmatch.h to avoid that the test fails in C++.
336AC_DEFUN([AC_FUNC_FNMATCH],
337[AC_CACHE_CHECK([for working GNU-style fnmatch],
338                [ac_cv_func_fnmatch_works],
339# Some versions of Solaris, SCO, and the GNU C Library
340# have a broken or incompatible fnmatch.
341# So we run a test program.  If we are cross-compiling, take no chance.
342# Thanks to John Oleynick, Franc,ois Pinard, and Paul Eggert for this test.
343[AC_RUN_IFELSE([AC_LANG_PROGRAM([@%:@include <fnmatch.h>],
344 [exit (fnmatch ("a*", "abc", 0) != 0
345	|| fnmatch ("d*/*1", "d/s/1", FNM_FILE_NAME) != FNM_NOMATCH
346	|| fnmatch ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR) != 0
347	|| fnmatch ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR) != 0
348	|| fnmatch ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR) != 0);])],
349               [ac_cv_func_fnmatch_works=yes],
350               [ac_cv_func_fnmatch_works=no],
351               [ac_cv_func_fnmatch_works=no])])
352if test $ac_cv_func_fnmatch_works = yes; then
353  AC_DEFINE(HAVE_FNMATCH, 1,
354            [Define if your system has a working `fnmatch' function.])
355fi
356])# AC_FUNC_FNMATCH
357
358
359# AU::AM_FUNC_FNMATCH
360# AU::fp_FUNC_FNMATCH
361# -------------------
362AU_ALIAS([AM_FUNC_FNMATCH], [AC_FUNC_FNMATCH])
363AU_ALIAS([fp_FUNC_FNMATCH], [AC_FUNC_FNMATCH])
364
365
366# AC_FUNC_FSEEKO
367# --------------
368AC_DEFUN([AC_FUNC_FSEEKO],
369[_AC_SYS_LARGEFILE_MACRO_VALUE(_LARGEFILE_SOURCE, 1,
370   [ac_cv_sys_largefile_source],
371   [Define to make fseeko visible on some hosts (e.g. glibc 2.2).],
372   [@%:@include <stdio.h>], [return !fseeko;])
373
374# We used to try defining _XOPEN_SOURCE=500 too, to work around a bug
375# in glibc 2.1.3, but that breaks too many other things.
376# If you want fseeko and ftello with glibc, upgrade to a fixed glibc.
377AC_CACHE_CHECK([for fseeko], [ac_cv_func_fseeko],
378               [AC_TRY_LINK([@%:@include <stdio.h>],
379                            [return fseeko && fseeko (stdin, 0, 0);],
380                            [ac_cv_func_fseeko=yes],
381                            [ac_cv_func_fseeko=no])])
382if test $ac_cv_func_fseeko = yes; then
383  AC_DEFINE(HAVE_FSEEKO, 1,
384    [Define if fseeko (and presumably ftello) exists and is declared.])
385fi
386])# AC_FUNC_FSEEKO
387
388
389# AC_FUNC_GETGROUPS
390# -----------------
391# Try to find `getgroups', and check that it works.
392# When crosscompiling, assume getgroups is broken.
393AC_DEFUN([AC_FUNC_GETGROUPS],
394[AC_REQUIRE([AC_TYPE_GETGROUPS])dnl
395AC_REQUIRE([AC_TYPE_SIZE_T])dnl
396AC_CHECK_FUNC(getgroups)
397
398# If we don't yet have getgroups, see if it's in -lbsd.
399# This is reported to be necessary on an ITOS 3000WS running SEIUX 3.1.
400ac_save_LIBS=$LIBS
401if test $ac_cv_func_getgroups = no; then
402  AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd])
403fi
404
405# Run the program to test the functionality of the system-supplied
406# getgroups function only if there is such a function.
407if test $ac_cv_func_getgroups = yes; then
408  AC_CACHE_CHECK([for working getgroups], ac_cv_func_getgroups_works,
409   [AC_RUN_IFELSE([AC_LANG_PROGRAM([],
410      [[/* On Ultrix 4.3, getgroups (0, 0) always fails.  */
411       exit (getgroups (0, 0) == -1 ? 1 : 0);]])],
412                  [ac_cv_func_getgroups_works=yes],
413                  [ac_cv_func_getgroups_works=no],
414                  [ac_cv_func_getgroups_works=no])
415   ])
416  if test $ac_cv_func_getgroups_works = yes; then
417    AC_DEFINE(HAVE_GETGROUPS, 1,
418              [Define if your system has a working `getgroups' function.])
419  fi
420fi
421LIBS=$ac_save_LIBS
422])# AC_FUNC_GETGROUPS
423
424
425# _AC_LIBOBJ_GETLOADAVG
426# ---------------------
427# Set up the AC_LIBOBJ replacement of `getloadavg'.
428m4_define([_AC_LIBOBJ_GETLOADAVG],
429[AC_LIBOBJ(getloadavg)
430AC_DEFINE(C_GETLOADAVG, 1, [Define if using `getloadavg.c'.])
431# Figure out what our getloadavg.c needs.
432ac_have_func=no
433AC_CHECK_HEADER(sys/dg_sys_info.h,
434[ac_have_func=yes
435 AC_DEFINE(DGUX, 1, [Define for DGUX with <sys/dg_sys_info.h>.])
436 AC_CHECK_LIB(dgc, dg_sys_info)])
437
438AC_CHECK_HEADER(locale.h)
439AC_CHECK_FUNCS(setlocale)
440
441# We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
442# uses stabs), but it is still SVR4.  We cannot check for <elf.h> because
443# Irix 4.0.5F has the header but not the library.
444if test $ac_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes; then
445  ac_have_func=yes
446  AC_DEFINE(SVR4, 1, [Define on System V Release 4.])
447fi
448
449if test $ac_have_func = no; then
450  AC_CHECK_HEADER(inq_stats/cpustats.h,
451  [ac_have_func=yes
452   AC_DEFINE(UMAX, 1, [Define for Encore UMAX.])
453   AC_DEFINE(UMAX4_3, 1,
454             [Define for Encore UMAX 4.3 that has <inq_status/cpustats.h>
455              instead of <sys/cpustats.h>.])])
456fi
457
458if test $ac_have_func = no; then
459  AC_CHECK_HEADER(sys/cpustats.h,
460  [ac_have_func=yes; AC_DEFINE(UMAX)])
461fi
462
463if test $ac_have_func = no; then
464  AC_CHECK_HEADERS(mach/mach.h)
465fi
466
467AC_CHECK_HEADERS(nlist.h,
468[AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
469                  [AC_DEFINE(NLIST_NAME_UNION, 1,
470                             [Define if your `struct nlist' has an
471                              `n_un' member.  Obsolete, depend on
472                              `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [],
473                  [@%:@include <nlist.h>])
474])dnl
475])# _AC_LIBOBJ_GETLOADAVG
476
477
478# AC_FUNC_GETLOADAVG
479# ------------------
480AC_DEFUN([AC_FUNC_GETLOADAVG],
481[ac_have_func=no # yes means we've found a way to get the load average.
482
483ac_save_LIBS=$LIBS
484
485# Check for getloadavg, but be sure not to touch the cache variable.
486(AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && ac_have_func=yes
487
488# On HPUX9, an unprivileged user can get load averages through this function.
489AC_CHECK_FUNCS(pstat_getdynamic)
490
491# Solaris has libkstat which does not require root.
492AC_CHECK_LIB(kstat, kstat_open)
493test $ac_cv_lib_kstat_kstat_open = yes && ac_have_func=yes
494
495# Some systems with -lutil have (and need) -lkvm as well, some do not.
496# On Solaris, -lkvm requires nlist from -lelf, so check that first
497# to get the right answer into the cache.
498# For kstat on solaris, we need libelf to force the definition of SVR4 below.
499if test $ac_have_func = no; then
500  AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
501fi
502if test $ac_have_func = no; then
503  AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
504  # Check for the 4.4BSD definition of getloadavg.
505  AC_CHECK_LIB(util, getloadavg,
506    [LIBS="-lutil $LIBS" ac_have_func=yes ac_cv_func_getloadavg_setgid=yes])
507fi
508
509if test $ac_have_func = no; then
510  # There is a commonly available library for RS/6000 AIX.
511  # Since it is not a standard part of AIX, it might be installed locally.
512  ac_getloadavg_LIBS=$LIBS
513  LIBS="-L/usr/local/lib $LIBS"
514  AC_CHECK_LIB(getloadavg, getloadavg,
515               [LIBS="-lgetloadavg $LIBS"], [LIBS=$ac_getloadavg_LIBS])
516fi
517
518# Make sure it is really in the library, if we think we found it,
519# otherwise set up the replacement function.
520AC_CHECK_FUNCS(getloadavg, [],
521               [_AC_LIBOBJ_GETLOADAVG])
522
523# Some definitions of getloadavg require that the program be installed setgid.
524dnl FIXME: Don't hardwire the path of getloadavg.c in the top-level directory.
525AC_CACHE_CHECK(whether getloadavg requires setgid,
526               ac_cv_func_getloadavg_setgid,
527[AC_EGREP_CPP([Yowza Am I SETGID yet],
528[#include "$srcdir/getloadavg.c"
529#ifdef LDAV_PRIVILEGED
530Yowza Am I SETGID yet
531@%:@endif],
532              ac_cv_func_getloadavg_setgid=yes,
533              ac_cv_func_getloadavg_setgid=no)])
534if test $ac_cv_func_getloadavg_setgid = yes; then
535  NEED_SETGID=true
536  AC_DEFINE(GETLOADAVG_PRIVILEGED, 1,
537            [Define if the `getloadavg' function needs to be run setuid
538             or setgid.])
539else
540  NEED_SETGID=false
541fi
542AC_SUBST(NEED_SETGID)dnl
543
544if test $ac_cv_func_getloadavg_setgid = yes; then
545  AC_CACHE_CHECK(group of /dev/kmem, ac_cv_group_kmem,
546[ # On Solaris, /dev/kmem is a symlink.  Get info on the real file.
547  ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
548  # If we got an error (system does not support symlinks), try without -L.
549  test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
550  ac_cv_group_kmem=`echo $ac_ls_output \
551    | sed -ne ['s/[ 	][ 	]*/ /g;
552	       s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\)  *.*/\1/;
553	       / /s/.* //;p;']`
554])
555  AC_SUBST(KMEM_GROUP, $ac_cv_group_kmem)dnl
556fi
557if test "x$ac_save_LIBS" = x; then
558  GETLOADAVG_LIBS=$LIBS
559else
560  GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$ac_save_LIBS!!"`
561fi
562LIBS=$ac_save_LIBS
563
564AC_SUBST(GETLOADAVG_LIBS)dnl
565])# AC_FUNC_GETLOADAVG
566
567
568# AU::AC_GETLOADAVG
569# -----------------
570AU_ALIAS([AC_GETLOADAVG], [AC_FUNC_GETLOADAVG])
571
572
573# AC_FUNC_GETMNTENT
574# -----------------
575AC_DEFUN([AC_FUNC_GETMNTENT],
576[# getmntent is in -lsun on Irix 4, -lseq on Dynix/PTX, -lgen on Unixware.
577AC_CHECK_LIB(sun, getmntent, LIBS="-lsun $LIBS",
578  [AC_CHECK_LIB(seq, getmntent, LIBS="-lseq $LIBS",
579    [AC_CHECK_LIB(gen, getmntent, LIBS="-lgen $LIBS")])])
580AC_CHECK_FUNC(getmntent,
581              [AC_DEFINE(HAVE_GETMNTENT, 1,
582                         [Define if you have the `getmntent' function.])])])
583
584
585# _AC_FUNC_GETPGRP_TEST
586# ---------------------
587# A program that exits with success iff `getpgrp' seems to ignore its
588# argument.
589m4_define([_AC_FUNC_GETPGRP_TEST],
590[AC_LANG_SOURCE([AC_INCLUDES_DEFAULT]
591[[
592/*
593 * If this system has a BSD-style getpgrp(),
594 * which takes a pid argument, exit unsuccessfully.
595 *
596 * Snarfed from Chet Ramey's bash pgrp.c test program
597 */
598
599int     pid;
600int     pg1, pg2, pg3, pg4;
601int     ng, np, s, child;
602
603int
604main ()
605{
606  pid = getpid ();
607  pg1 = getpgrp (0);
608  pg2 = getpgrp ();
609  pg3 = getpgrp (pid);
610  pg4 = getpgrp (1);
611
612  /* If all of these values are the same, it's pretty sure that we're
613     on a system that ignores getpgrp's first argument.  */
614  if (pg2 == pg4 && pg1 == pg3 && pg2 == pg3)
615    exit (0);
616
617  child = fork ();
618  if (child < 0)
619    exit(1);
620  else if (child == 0)
621    {
622      np = getpid ();
623      /*  If this is Sys V, this will not work; pgrp will be set to np
624	 because setpgrp just changes a pgrp to be the same as the
625	 pid.  */
626      setpgrp (np, pg1);
627      ng = getpgrp (0);        /* Same result for Sys V and BSD */
628      if (ng == pg1)
629  	exit (1);
630      else
631  	exit (0);
632    }
633  else
634    {
635      wait (&s);
636      exit (s>>8);
637    }
638}]])
639])# _AC_FUNC_GETPGRP_TEST
640
641
642# AC_FUNC_GETPGRP
643# ---------------
644# Figure out whether getpgrp takes an argument or not.  Try first using
645# prototypes (AC_COMPILE), and if the compiler is of no help, try a runtime
646# test.
647AC_DEFUN([AC_FUNC_GETPGRP],
648[AC_CACHE_CHECK(whether getpgrp takes no argument, ac_cv_func_getpgrp_void,
649[# Use it with a single arg.
650AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [getpgrp (0);])],
651                  [ac_func_getpgrp_1=yes],
652                  [ac_func_getpgrp_1=no])
653# Use it with no arg.
654AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [getpgrp ();])],
655                  [ac_func_getpgrp_0=yes],
656                  [ac_func_getpgrp_0=no])
657# If both static checks agree, we are done.
658case $ac_func_getpgrp_0:$ac_func_getpgrp_1 in
659  yes:no) ac_cv_func_getpgrp_void=yes;;
660  no:yes) ac_cv_func_getpgrp_void=false;;
661  *) AC_RUN_IFELSE([_AC_FUNC_GETPGRP_TEST],
662                   [ac_cv_func_getpgrp_void=yes],
663                   [ac_cv_func_getpgrp_void=no],
664                   [AC_MSG_ERROR([cannot check getpgrp if cross compiling])]);;
665esac # $ac_func_getpgrp_0:$ac_func_getpgrp_1
666])
667if test $ac_cv_func_getpgrp_void = yes; then
668  AC_DEFINE(GETPGRP_VOID, 1,
669            [Define if the `getpgrp' function takes no argument.])
670fi
671])# AC_FUNC_GETPGRP
672
673
674# AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
675# -------------------------------------
676# When crosscompiling, be pessimistic so we will end up using the
677# replacement version of lstat that checkes for trailing slashes and
678# calls lstat a second time when necessary.
679AC_DEFUN([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
680[AC_CACHE_CHECK(
681       [whether lstat dereferences a symlink specified with a trailing slash],
682       [ac_cv_func_lstat_dereferences_slashed_symlink],
683[rm -f conftest.sym conftest.file
684echo >conftest.file
685if ln -s conftest.file conftest.sym; then
686  AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
687    [struct stat sbuf;
688     /* Linux will dereference the symlink and fail.
689        That is better in the sense that it means we will not
690        have to compile and use the lstat wrapper.  */
691     exit (lstat ("conftest.sym/", &sbuf) ? 0 : 1);])],
692                [ac_cv_func_lstat_dereferences_slashed_symlink=yes],
693                [ac_cv_func_lstat_dereferences_slashed_symlink=no],
694                [ac_cv_func_lstat_dereferences_slashed_symlink=no])
695else
696  # If the `ln -s' command failed, then we probably don't even
697  # have an lstat function.
698  ac_cv_func_lstat_dereferences_slashed_symlink=no
699fi
700rm -f conftest.sym conftest.file
701])
702
703test $ac_cv_func_lstat_dereferences_slashed_symlink = yes &&
704  AC_DEFINE_UNQUOTED(LSTAT_FOLLOWS_SLASHED_SYMLINK, 1,
705                     [Define if `lstat' dereferences a symlink specified
706                      with a trailing slash.])
707
708if test $ac_cv_func_lstat_dereferences_slashed_symlink = no; then
709  AC_LIBOBJ(lstat)
710fi
711])
712
713
714# AC_FUNC_MALLOC
715# --------------
716# Is `malloc (0)' properly handled?
717AC_DEFUN([AC_FUNC_MALLOC],
718[AC_REQUIRE([AC_HEADER_STDC])dnl
719AC_CHECK_HEADERS(stdlib.h)
720AC_CACHE_CHECK([for working malloc], ac_cv_func_malloc_works,
721[AC_RUN_IFELSE(
722[AC_LANG_PROGRAM(
723[[#if STDC_HEADERS || HAVE_STDLIB_H
724# include <stdlib.h>
725#else
726char *malloc ();
727#endif
728]],
729                 [exit (malloc (0) ? 0 : 1);])],
730               [ac_cv_func_malloc_works=yes],
731               [ac_cv_func_malloc_works=no],
732               [ac_cv_func_malloc_works=no])])
733if test $ac_cv_func_malloc_works = yes; then
734  AC_DEFINE(HAVE_MALLOC, 1,
735            [Define if your system has a working `malloc' function.])
736fi
737])# AC_FUNC_MALLOC
738
739
740# AC_FUNC_MEMCMP
741# --------------
742AC_DEFUN([AC_FUNC_MEMCMP],
743[AC_CACHE_CHECK([for working memcmp], ac_cv_func_memcmp_working,
744[AC_RUN_IFELSE([AC_LANG_PROGRAM([], [[
745  /* Some versions of memcmp are not 8-bit clean.  */
746  char c0 = 0x40, c1 = 0x80, c2 = 0x81;
747  if (memcmp(&c0, &c2, 1) >= 0 || memcmp(&c1, &c2, 1) >= 0)
748    exit (1);
749
750  /* The Next x86 OpenStep bug shows up only when comparing 16 bytes
751     or more and with at least one buffer not starting on a 4-byte boundary.
752     William Lewis provided this test program.   */
753  {
754    char foo[21];
755    char bar[21];
756    int i;
757    for (i = 0; i < 4; i++)
758      {
759        char *a = foo + i;
760        char *b = bar + i;
761        strcpy (a, "--------01111111");
762        strcpy (b, "--------10000000");
763        if (memcmp (a, b, 16) >= 0)
764          exit (1);
765      }
766    exit (0);
767  }
768]])],
769               [ac_cv_func_memcmp_working=yes],
770               [ac_cv_func_memcmp_working=no],
771               [ac_cv_func_memcmp_working=no])])
772test $ac_cv_func_memcmp_working = no && AC_LIBOBJ([memcmp])
773])# AC_FUNC_MEMCMP
774
775
776# AC_FUNC_MKTIME
777# --------------
778AC_DEFUN([AC_FUNC_MKTIME],
779[AC_REQUIRE([AC_HEADER_TIME])dnl
780AC_CHECK_HEADERS(sys/time.h unistd.h)
781AC_CHECK_FUNCS(alarm)
782AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
783[AC_RUN_IFELSE([AC_LANG_SOURCE(
784[[/* Test program from Paul Eggert and Tony Leneis.  */
785#if TIME_WITH_SYS_TIME
786# include <sys/time.h>
787# include <time.h>
788#else
789# if HAVE_SYS_TIME_H
790#  include <sys/time.h>
791# else
792#  include <time.h>
793# endif
794#endif
795
796#if HAVE_UNISTD_H
797# include <unistd.h>
798#endif
799
800#if !HAVE_ALARM
801# define alarm(X) /* empty */
802#endif
803
804/* Work around redefinition to rpl_putenv by other config tests.  */
805#undef putenv
806
807static time_t time_t_max;
808
809/* Values we'll use to set the TZ environment variable.  */
810static const char *const tz_strings[] = {
811  (const char *) 0, "TZ=GMT0", "TZ=JST-9",
812  "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
813};
814#define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
815
816/* Fail if mktime fails to convert a date in the spring-forward gap.
817   Based on a problem report from Andreas Jaeger.  */
818static void
819spring_forward_gap ()
820{
821  /* glibc (up to about 1998-10-07) failed this test. */
822  struct tm tm;
823
824  /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
825     instead of "TZ=America/Vancouver" in order to detect the bug even
826     on systems that don't support the Olson extension, or don't have the
827     full zoneinfo tables installed.  */
828  putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
829
830  tm.tm_year = 98;
831  tm.tm_mon = 3;
832  tm.tm_mday = 5;
833  tm.tm_hour = 2;
834  tm.tm_min = 0;
835  tm.tm_sec = 0;
836  tm.tm_isdst = -1;
837  if (mktime (&tm) == (time_t)-1)
838    exit (1);
839}
840
841static void
842mktime_test (now)
843     time_t now;
844{
845  struct tm *lt;
846  if ((lt = localtime (&now)) && mktime (lt) != now)
847    exit (1);
848  now = time_t_max - now;
849  if ((lt = localtime (&now)) && mktime (lt) != now)
850    exit (1);
851}
852
853static void
854irix_6_4_bug ()
855{
856  /* Based on code from Ariel Faigon.  */
857  struct tm tm;
858  tm.tm_year = 96;
859  tm.tm_mon = 3;
860  tm.tm_mday = 0;
861  tm.tm_hour = 0;
862  tm.tm_min = 0;
863  tm.tm_sec = 0;
864  tm.tm_isdst = -1;
865  mktime (&tm);
866  if (tm.tm_mon != 2 || tm.tm_mday != 31)
867    exit (1);
868}
869
870static void
871bigtime_test (j)
872     int j;
873{
874  struct tm tm;
875  time_t now;
876  tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
877  now = mktime (&tm);
878  if (now != (time_t) -1)
879    {
880      struct tm *lt = localtime (&now);
881      if (! (lt
882	     && lt->tm_year == tm.tm_year
883	     && lt->tm_mon == tm.tm_mon
884	     && lt->tm_mday == tm.tm_mday
885	     && lt->tm_hour == tm.tm_hour
886	     && lt->tm_min == tm.tm_min
887	     && lt->tm_sec == tm.tm_sec
888	     && lt->tm_yday == tm.tm_yday
889	     && lt->tm_wday == tm.tm_wday
890	     && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
891		  == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
892	exit (1);
893    }
894}
895
896int
897main ()
898{
899  time_t t, delta;
900  int i, j;
901
902  /* This test makes some buggy mktime implementations loop.
903     Give up after 60 seconds; a mktime slower than that
904     isn't worth using anyway.  */
905  alarm (60);
906
907  for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
908    continue;
909  time_t_max--;
910  delta = time_t_max / 997; /* a suitable prime number */
911  for (i = 0; i < N_STRINGS; i++)
912    {
913      if (tz_strings[i])
914	putenv (tz_strings[i]);
915
916      for (t = 0; t <= time_t_max - delta; t += delta)
917	mktime_test (t);
918      mktime_test ((time_t) 60 * 60);
919      mktime_test ((time_t) 60 * 60 * 24);
920
921      for (j = 1; 0 < j; j *= 2)
922        bigtime_test (j);
923      bigtime_test (j - 1);
924    }
925  irix_6_4_bug ();
926  spring_forward_gap ();
927  exit (0);
928}]])],
929               [ac_cv_func_working_mktime=yes],
930               [ac_cv_func_working_mktime=no],
931               [ac_cv_func_working_mktime=no])])
932if test $ac_cv_func_working_mktime = no; then
933  AC_LIBOBJ([mktime])
934fi
935])# AC_FUNC_MKTIME
936
937
938# AU::AM_FUNC_MKTIME
939# ------------------
940AU_ALIAS([AM_FUNC_MKTIME], [AC_FUNC_MKTIME])
941
942
943# AC_FUNC_MMAP
944# ------------
945AC_DEFUN([AC_FUNC_MMAP],
946[AC_CHECK_HEADERS(stdlib.h unistd.h)
947AC_CHECK_FUNCS(getpagesize)
948AC_CACHE_CHECK(for working mmap, ac_cv_func_mmap_fixed_mapped,
949[AC_RUN_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT]
950[[/* Thanks to Mike Haertel and Jim Avera for this test.
951   Here is a matrix of mmap possibilities:
952	mmap private not fixed
953	mmap private fixed at somewhere currently unmapped
954	mmap private fixed at somewhere already mapped
955	mmap shared not fixed
956	mmap shared fixed at somewhere currently unmapped
957	mmap shared fixed at somewhere already mapped
958   For private mappings, we should verify that changes cannot be read()
959   back from the file, nor mmap's back from the file at a different
960   address.  (There have been systems where private was not correctly
961   implemented like the infamous i386 svr4.0, and systems where the
962   VM page cache was not coherent with the file system buffer cache
963   like early versions of FreeBSD and possibly contemporary NetBSD.)
964   For shared mappings, we should conversely verify that changes get
965   propogated back to all the places they're supposed to be.
966
967   Grep wants private fixed already mapped.
968   The main things grep needs to know about mmap are:
969   * does it exist and is it safe to write into the mmap'd area
970   * how to use it (BSD variants)  */
971
972#include <fcntl.h>
973#include <sys/mman.h>
974
975#if !STDC_HEADERS && !HAVE_STDLIB_H
976char *malloc ();
977#endif
978
979/* This mess was copied from the GNU getpagesize.h.  */
980#if !HAVE_GETPAGESIZE
981/* Assume that all systems that can run configure have sys/param.h.  */
982# if !HAVE_SYS_PARAM_H
983#  define HAVE_SYS_PARAM_H 1
984# endif
985
986# ifdef _SC_PAGESIZE
987#  define getpagesize() sysconf(_SC_PAGESIZE)
988# else /* no _SC_PAGESIZE */
989#  if HAVE_SYS_PARAM_H
990#   include <sys/param.h>
991#   ifdef EXEC_PAGESIZE
992#    define getpagesize() EXEC_PAGESIZE
993#   else /* no EXEC_PAGESIZE */
994#    ifdef NBPG
995#     define getpagesize() NBPG * CLSIZE
996#     ifndef CLSIZE
997#      define CLSIZE 1
998#     endif /* no CLSIZE */
999#    else /* no NBPG */
1000#     ifdef NBPC
1001#      define getpagesize() NBPC
1002#     else /* no NBPC */
1003#      ifdef PAGESIZE
1004#       define getpagesize() PAGESIZE
1005#      endif /* PAGESIZE */
1006#     endif /* no NBPC */
1007#    endif /* no NBPG */
1008#   endif /* no EXEC_PAGESIZE */
1009#  else /* no HAVE_SYS_PARAM_H */
1010#   define getpagesize() 8192	/* punt totally */
1011#  endif /* no HAVE_SYS_PARAM_H */
1012# endif /* no _SC_PAGESIZE */
1013
1014#endif /* no HAVE_GETPAGESIZE */
1015
1016int
1017main ()
1018{
1019  char *data, *data2, *data3;
1020  int i, pagesize;
1021  int fd;
1022
1023  pagesize = getpagesize ();
1024
1025  /* First, make a file with some known garbage in it. */
1026  data = (char *) malloc (pagesize);
1027  if (!data)
1028    exit (1);
1029  for (i = 0; i < pagesize; ++i)
1030    *(data + i) = rand ();
1031  umask (0);
1032  fd = creat ("conftest.mmap", 0600);
1033  if (fd < 0)
1034    exit (1);
1035  if (write (fd, data, pagesize) != pagesize)
1036    exit (1);
1037  close (fd);
1038
1039  /* Next, try to mmap the file at a fixed address which already has
1040     something else allocated at it.  If we can, also make sure that
1041     we see the same garbage.  */
1042  fd = open ("conftest.mmap", O_RDWR);
1043  if (fd < 0)
1044    exit (1);
1045  data2 = (char *) malloc (2 * pagesize);
1046  if (!data2)
1047    exit (1);
1048  data2 += (pagesize - ((int) data2 & (pagesize - 1))) & (pagesize - 1);
1049  if (data2 != mmap (data2, pagesize, PROT_READ | PROT_WRITE,
1050                     MAP_PRIVATE | MAP_FIXED, fd, 0L))
1051    exit (1);
1052  for (i = 0; i < pagesize; ++i)
1053    if (*(data + i) != *(data2 + i))
1054      exit (1);
1055
1056  /* Finally, make sure that changes to the mapped area do not
1057     percolate back to the file as seen by read().  (This is a bug on
1058     some variants of i386 svr4.0.)  */
1059  for (i = 0; i < pagesize; ++i)
1060    *(data2 + i) = *(data2 + i) + 1;
1061  data3 = (char *) malloc (pagesize);
1062  if (!data3)
1063    exit (1);
1064  if (read (fd, data3, pagesize) != pagesize)
1065    exit (1);
1066  for (i = 0; i < pagesize; ++i)
1067    if (*(data + i) != *(data3 + i))
1068      exit (1);
1069  close (fd);
1070  exit (0);
1071}]])],
1072               [ac_cv_func_mmap_fixed_mapped=yes],
1073               [ac_cv_func_mmap_fixed_mapped=no],
1074               [ac_cv_func_mmap_fixed_mapped=no])])
1075if test $ac_cv_func_mmap_fixed_mapped = yes; then
1076  AC_DEFINE(HAVE_MMAP, 1,
1077            [Define if you have a working `mmap' system call.])
1078fi
1079rm -f conftest.mmap
1080])# AC_FUNC_MMAP
1081
1082
1083# AU::AC_MMAP
1084# -----------
1085AU_ALIAS([AC_MMAP], [AC_FUNC_MMAP])
1086
1087
1088# AC_FUNC_OBSTACK
1089# ---------------
1090# Ensure obstack support.  Yeah, this is not exactly a `FUNC' check.
1091AC_DEFUN([AC_FUNC_OBSTACK],
1092[AC_LIBSOURCES([obstack.h, obstack.c])dnl
1093AC_CACHE_CHECK([for obstacks], ac_cv_func_obstack,
1094[AC_TRY_LINK([@%:@include "obstack.h"],
1095             [struct obstack *mem; obstack_free(mem,(char *) 0)],
1096             [ac_cv_func_obstack=yes],
1097             [ac_cv_func_obstack=no])])
1098if test $ac_cv_func_obstack = yes; then
1099  AC_DEFINE(HAVE_OBSTACK, 1, [Define if libc includes obstacks.])
1100else
1101  AC_LIBOBJ(obstack)
1102fi
1103])# AC_FUNC_OBSTACK
1104
1105
1106# AU::AM_FUNC_OBSTACK
1107# -------------------
1108AU_ALIAS([AM_FUNC_OBSTACK], [AC_FUNC_OBSTACK])
1109
1110
1111# AC_FUNC_SELECT_ARGTYPES
1112# -----------------------
1113# Determine the correct type to be passed to each of the `select'
1114# function's arguments, and define those types in `SELECT_TYPE_ARG1',
1115# `SELECT_TYPE_ARG234', and `SELECT_TYPE_ARG5'.
1116AC_DEFUN([AC_FUNC_SELECT_ARGTYPES],
1117[AC_CHECK_HEADERS(sys/select.h sys/socket.h)
1118AC_CACHE_CHECK([types of arguments for select],
1119[ac_cv_func_select_args],
1120[for ac_arg234 in 'fd_set *' 'int *' 'void *'; do
1121 for ac_arg1 in 'int' 'size_t' 'unsigned long' 'unsigned'; do
1122  for ac_arg5 in 'struct timeval *' 'const struct timeval *'; do
1123   AC_COMPILE_IFELSE(
1124       [AC_LANG_PROGRAM(
1125[AC_INCLUDES_DEFAULT
1126#if HAVE_SYS_SELECT_H
1127# include <sys/select.h>
1128#endif
1129#if HAVE_SYS_SOCKET_H
1130# include <sys/socket.h>
1131#endif
1132],
1133                        [extern int select ($ac_arg1,
1134                                            $ac_arg234, $ac_arg234, $ac_arg234,
1135                                            $ac_arg5);])],
1136              [ac_cv_func_select_args="$ac_arg1,$ac_arg234,$ac_arg5"; break 3])
1137  done
1138 done
1139done
1140# Provide a safe default value.
1141: ${ac_cv_func_select_args='int,int *,struct timeval *'}
1142])
1143ac_save_IFS=$IFS; IFS=','
1144set dummy `echo "$ac_cv_func_select_args" | sed 's/\*/\*/g'`
1145IFS=$ac_save_IFS
1146shift
1147AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG1, $[1],
1148                   [Define to the type of arg 1 for `select'.])
1149AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG234, ($[2]),
1150                   [Define to the type of args 2, 3 and 4 for `select'.])
1151AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG5, ($[3]),
1152                   [Define to the type of arg 5 for `select'.])
1153rm -f conftest*
1154])# AC_FUNC_SELECT_ARGTYPES
1155
1156
1157# AC_FUNC_SETPGRP
1158# ---------------
1159AC_DEFUN([AC_FUNC_SETPGRP],
1160[AC_CACHE_CHECK(whether setpgrp takes no argument, ac_cv_func_setpgrp_void,
1161[AC_RUN_IFELSE(
1162[AC_LANG_PROGRAM(
1163[#if HAVE_UNISTD_H
1164# include <unistd.h>
1165#endif
1166],
1167[/* If this system has a BSD-style setpgrp, which takes arguments, exit
1168   successfully.  */
1169  exit (setpgrp (1,1) == -1);])],
1170               [ac_cv_func_setpgrp_void=no],
1171               [ac_cv_func_setpgrp_void=yes],
1172               [AC_MSG_ERROR([cannot check setpgrp if cross compiling])])])
1173if test $ac_cv_func_setpgrp_void = yes; then
1174  AC_DEFINE(SETPGRP_VOID, 1,
1175            [Define if the `setpgrp' function takes no argument.])
1176fi
1177])# AC_FUNC_SETPGRP
1178
1179
1180# _AC_FUNC_STAT(STAT | LSTAT)
1181# ---------------------------
1182# Determine whether stat or lstat have the bug that it succeeds when
1183# given the zero-length file name argument.  The stat and lstat from
1184# SunOS4.1.4 and the Hurd (as of 1998-11-01) do this.
1185#
1186# If it does, then define HAVE_STAT_EMPTY_STRING_BUG (or
1187# HAVE_LSTAT_EMPTY_STRING_BUG) and arrange to compile the wrapper
1188# function.
1189m4_define([_AC_FUNC_STAT],
1190[AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])dnl
1191AC_CACHE_CHECK([whether $1 accepts an empty string],
1192               [ac_cv_func_$1_empty_string_bug],
1193[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1194[[struct stat sbuf;
1195  exit ($1 ("", &sbuf) ? 1 : 0);]])],
1196            [ac_cv_func_$1_empty_string_bug=yes],
1197            [ac_cv_func_$1_empty_string_bug=no],
1198            [ac_cv_func_$1_empty_string_bug=yes])])
1199if test $ac_cv_func_$1_empty_string_bug = yes; then
1200  AC_LIBOBJ([$1])
1201  AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1_EMPTY_STRING_BUG]), 1,
1202                     [Define if `$1' has the bug that it succeeds when
1203                      given the zero-length file name argument.])
1204fi
1205])# _AC_FUNC_STAT
1206
1207
1208# AC_FUNC_STAT & AC_FUNC_LSTAT
1209# ----------------------------
1210AC_DEFUN([AC_FUNC_STAT],  [_AC_FUNC_STAT(stat)])
1211AC_DEFUN([AC_FUNC_LSTAT], [_AC_FUNC_STAT(lstat)])
1212
1213
1214# _AC_LIBOBJ_STRTOD
1215# -----------------
1216m4_define([_AC_LIBOBJ_STRTOD],
1217[AC_LIBOBJ(strtod)
1218AC_CHECK_FUNC(pow)
1219if test $ac_cv_func_pow = no; then
1220  AC_CHECK_LIB(m, pow,
1221               [POW_LIB=-lm],
1222               [AC_MSG_WARN([can't find library containing definition of pow])])
1223fi
1224])# _AC_LIBOBJ_STRTOD
1225
1226
1227# AC_FUNC_STRTOD
1228# --------------
1229AC_DEFUN([AC_FUNC_STRTOD],
1230[AC_CACHE_CHECK(for working strtod, ac_cv_func_strtod,
1231[AC_RUN_IFELSE([AC_LANG_SOURCE([[
1232double strtod ();
1233int
1234main()
1235{
1236  {
1237    /* Some versions of Linux strtod mis-parse strings with leading '+'.  */
1238    char *string = " +69";
1239    char *term;
1240    double value;
1241    value = strtod (string, &term);
1242    if (value != 69 || term != (string + 4))
1243      exit (1);
1244  }
1245
1246  {
1247    /* Under Solaris 2.4, strtod returns the wrong value for the
1248       terminating character under some conditions.  */
1249    char *string = "NaN";
1250    char *term;
1251    strtod (string, &term);
1252    if (term != string && *(term - 1) == 0)
1253      exit (1);
1254  }
1255  exit (0);
1256}
1257]])],
1258               ac_cv_func_strtod=yes,
1259               ac_cv_func_strtod=no,
1260               ac_cv_func_strtod=no)])
1261if test $ac_cv_func_strtod = no; then
1262  _AC_LIBOBJ_STRTOD
1263fi
1264])
1265
1266
1267# AU::AM_FUNC_STRTOD
1268# ------------------
1269AU_ALIAS([AM_FUNC_STRTOD], [AC_FUNC_STRTOD])
1270
1271
1272# AC_FUNC_STRERROR_R
1273# ------------------
1274AC_DEFUN([AC_FUNC_STRERROR_R],
1275[AC_CHECK_DECLS([strerror_r])
1276AC_CHECK_FUNCS([strerror_r])
1277if test $ac_cv_func_strerror_r = yes; then
1278  AC_CACHE_CHECK([for working strerror_r],
1279                 ac_cv_func_strerror_r_works,
1280   [
1281    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1282     [[
1283       char buf[100];
1284       char x = *strerror_r (0, buf, sizeof buf);
1285     ]])],
1286                      ac_cv_func_strerror_r_works=yes,
1287                      ac_cv_func_strerror_r_works=no)
1288    if test $ac_cv_func_strerror_r_works = no; then
1289      # strerror_r seems not to work, but now we have to choose between
1290      # systems that have relatively inaccessible declarations for the
1291      # function.  BeOS and DEC UNIX 4.0 fall in this category, but the
1292      # former has a strerror_r that returns char*, while the latter
1293      # has a strerror_r that returns `int'.
1294      # This test should segfault on the DEC system.
1295      AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
1296	extern char *strerror_r ();],
1297	[[char buf[100];
1298	  char x = *strerror_r (0, buf, sizeof buf);
1299	  exit (!isalpha (x));]])],
1300                    ac_cv_func_strerror_r_works=yes,
1301                    ac_cv_func_strerror_r_works=no,
1302                    ac_cv_func_strerror_r_works=no)
1303    fi
1304  ])
1305  if test $ac_cv_func_strerror_r_works = yes; then
1306    AC_DEFINE_UNQUOTED([HAVE_WORKING_STRERROR_R], 1,
1307                       [Define to 1 if `strerror_r' returns a string.])
1308  fi
1309fi
1310])# AC_FUNC_STRERROR_R
1311
1312
1313# AC_FUNC_STRFTIME
1314# ----------------
1315AC_DEFUN([AC_FUNC_STRFTIME],
1316[AC_CHECK_FUNCS(strftime, [],
1317[# strftime is in -lintl on SCO UNIX.
1318AC_CHECK_LIB(intl, strftime,
1319             [AC_DEFINE(HAVE_STRFTIME)
1320LIBS="-lintl $LIBS"])])dnl
1321])# AC_FUNC_STRFTIME
1322
1323
1324# AC_FUNC_SETVBUF_REVERSED
1325# ------------------------
1326AC_DEFUN([AC_FUNC_SETVBUF_REVERSED],
1327[AC_CACHE_CHECK(whether setvbuf arguments are reversed,
1328  ac_cv_func_setvbuf_reversed,
1329[AC_TRY_RUN([#include <stdio.h>
1330/* If setvbuf has the reversed format, exit 0. */
1331int
1332main ()
1333{
1334  /* This call has the arguments reversed.
1335     A reversed system may check and see that the address of main
1336     is not _IOLBF, _IONBF, or _IOFBF, and return nonzero.  */
1337  if (setvbuf(stdout, _IOLBF, (char *) main, BUFSIZ) != 0)
1338    exit(1);
1339  putc('\r', stdout);
1340  exit(0);			/* Non-reversed systems segv here.  */
1341}], ac_cv_func_setvbuf_reversed=yes, ac_cv_func_setvbuf_reversed=no)
1342rm -f core core.* *.core])
1343if test $ac_cv_func_setvbuf_reversed = yes; then
1344  AC_DEFINE(SETVBUF_REVERSED, 1,
1345            [Define if the `setvbuf' function takes the buffering type as
1346             its second argument and the buffer pointer as the third, as on
1347             System V before release 3.])
1348fi
1349])# AC_FUNC_SETVBUF_REVERSED
1350
1351
1352# AU::AC_SETVBUF_REVERSED
1353# -----------------------
1354AU_ALIAS([AC_SETVBUF_REVERSED], [AC_FUNC_SETVBUF_REVERSED])
1355
1356
1357# AC_FUNC_STRCOLL
1358# ---------------
1359AC_DEFUN([AC_FUNC_STRCOLL],
1360[AC_CACHE_CHECK(for working strcoll, ac_cv_func_strcoll_works,
1361[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1362  [[exit (strcoll ("abc", "def") >= 0 ||
1363	 strcoll ("ABC", "DEF") >= 0 ||
1364	 strcoll ("123", "456") >= 0)]])],
1365               ac_cv_func_strcoll_works=yes,
1366               ac_cv_func_strcoll_works=no,
1367               ac_cv_func_strcoll_works=no)])
1368if test $ac_cv_func_strcoll_works = yes; then
1369  AC_DEFINE(HAVE_STRCOLL, 1,
1370            [Define if you have the `strcoll' function and it is properly
1371             defined.])
1372fi
1373])# AC_FUNC_STRCOLL
1374
1375
1376# AU::AC_STRCOLL
1377# --------------
1378AU_ALIAS([AC_STRCOLL], [AC_FUNC_STRCOLL])
1379
1380
1381# AC_FUNC_UTIME_NULL
1382# ------------------
1383AC_DEFUN([AC_FUNC_UTIME_NULL],
1384[AC_CACHE_CHECK(whether utime accepts a null argument, ac_cv_func_utime_null,
1385[rm -f conftest.data; >conftest.data
1386# Sequent interprets utime(file, 0) to mean use start of epoch.  Wrong.
1387AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1388[[struct stat s, t;
1389  exit (!(stat ("conftest.data", &s) == 0
1390          && utime ("conftest.data", (long *)0) == 0
1391          && stat ("conftest.data", &t) == 0
1392          && t.st_mtime >= s.st_mtime
1393          && t.st_mtime - s.st_mtime < 120));]])],
1394              ac_cv_func_utime_null=yes,
1395              ac_cv_func_utime_null=no,
1396              ac_cv_func_utime_null=no)
1397rm -f core core.* *.core])
1398if test $ac_cv_func_utime_null = yes; then
1399  AC_DEFINE(HAVE_UTIME_NULL, 1,
1400            [Define if `utime(file, NULL)' sets file's timestamp to the
1401             present.])
1402fi
1403rm -f conftest.data
1404])# AC_FUNC_UTIME_NULL
1405
1406
1407# AU::AC_UTIME_NULL
1408# -----------------
1409AU_ALIAS([AC_UTIME_NULL], [AC_FUNC_UTIME_NULL])
1410
1411
1412# AC_FUNC_FORK
1413# -------------
1414AC_DEFUN([AC_FUNC_FORK],
1415[AC_REQUIRE([AC_TYPE_PID_T])dnl
1416AC_CHECK_HEADERS(unistd.h vfork.h)
1417AC_CHECK_FUNCS(fork vfork)
1418ac_cv_func_fork_works=$ac_cv_func_fork
1419if test "x$ac_cv_func_fork" = xyes; then
1420  _AC_FUNC_FORK
1421fi
1422if test "x$ac_cv_func_fork_works" = xcross; then
1423  case $host in
1424    *-*-amigaos* | *-*-msdosdjgpp*)
1425      # Override, as these systems have only a dummy fork() stub
1426      ac_cv_func_fork_works=no
1427      ;;
1428    *)
1429      ac_cv_func_fork_works=yes
1430      ;;
1431  esac
1432  AC_MSG_WARN(CROSS: Result $ac_cv_func_fork_works guessed due to cross-compiling.)
1433fi
1434ac_cv_func_vfork_works=$ac_cv_func_vfork
1435if test "x$ac_cv_func_vfork" = xyes; then
1436  _AC_FUNC_VFORK
1437fi;
1438if test "x$ac_cv_func_fork_works" = xcross; then
1439  ac_cv_func_vfork_works=ac_cv_func_vfork
1440  AC_MSG_WARN(CROSS: Result $ac_cv_func_vfork_works guessed due to cross-compiling.)
1441fi
1442
1443if test "x$ac_cv_func_vfork_works" = xyes; then
1444  AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define if `vfork' works.])
1445else
1446  AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
1447fi
1448if test "x$ac_cv_func_fork_works" = xyes; then
1449  AC_DEFINE(HAVE_WORKING_FORK, 1, [Define if `fork' works.])
1450fi
1451])# AC_FUNC_FORK
1452
1453
1454# _AC_FUNC_FORK
1455# -------------
1456AC_DEFUN([_AC_FUNC_FORK],
1457  [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
1458    [AC_RUN_IFELSE([/* By R�diger Kuhlmann. */
1459      #include <sys/types.h>
1460      #if HAVE_UNISTD_H
1461      # include <unistd.h>
1462      #endif
1463      /* Some systems only have a dummy stub for fork() */
1464      int main ()
1465      {
1466        if (fork() < 0)
1467          exit (1);
1468        exit (0);
1469      }],
1470    [ac_cv_func_fork_works=yes],
1471    [ac_cv_func_fork_works=no],
1472    [ac_cv_func_fork_works=cross])])]
1473)# _AC_FUNC_FORK
1474
1475
1476# _AC_FUNC_VFORK
1477# -------------
1478AC_DEFUN([_AC_FUNC_VFORK],
1479[AC_CACHE_CHECK(for working vfork, ac_cv_func_vfork_works,
1480[AC_TRY_RUN([/* Thanks to Paul Eggert for this test.  */
1481#include <stdio.h>
1482#include <sys/types.h>
1483#include <sys/stat.h>
1484#if HAVE_UNISTD_H
1485# include <unistd.h>
1486#endif
1487#if HAVE_VFORK_H
1488# include <vfork.h>
1489#endif
1490/* On some sparc systems, changes by the child to local and incoming
1491   argument registers are propagated back to the parent.  The compiler
1492   is told about this with #include <vfork.h>, but some compilers
1493   (e.g. gcc -O) don't grok <vfork.h>.  Test for this by using a
1494   static variable whose address is put into a register that is
1495   clobbered by the vfork.  */
1496static
1497#ifdef __cplusplus
1498sparc_address_test (int arg)
1499# else
1500sparc_address_test (arg) int arg;
1501#endif
1502{
1503  static pid_t child;
1504  if (!child) {
1505    child = vfork ();
1506    if (child < 0) {
1507      perror ("vfork");
1508      _exit(2);
1509    }
1510    if (!child) {
1511      arg = getpid();
1512      write(-1, "", 0);
1513      _exit (arg);
1514    }
1515  }
1516}
1517
1518int
1519main ()
1520{
1521  pid_t parent = getpid ();
1522  pid_t child;
1523
1524  sparc_address_test ();
1525
1526  child = vfork ();
1527
1528  if (child == 0) {
1529    /* Here is another test for sparc vfork register problems.  This
1530       test uses lots of local variables, at least as many local
1531       variables as main has allocated so far including compiler
1532       temporaries.  4 locals are enough for gcc 1.40.3 on a Solaris
1533       4.1.3 sparc, but we use 8 to be safe.  A buggy compiler should
1534       reuse the register of parent for one of the local variables,
1535       since it will think that parent can't possibly be used any more
1536       in this routine.  Assigning to the local variable will thus
1537       munge parent in the parent process.  */
1538    pid_t
1539      p = getpid(), p1 = getpid(), p2 = getpid(), p3 = getpid(),
1540      p4 = getpid(), p5 = getpid(), p6 = getpid(), p7 = getpid();
1541    /* Convince the compiler that p..p7 are live; otherwise, it might
1542       use the same hardware register for all 8 local variables.  */
1543    if (p != p1 || p != p2 || p != p3 || p != p4
1544	|| p != p5 || p != p6 || p != p7)
1545      _exit(1);
1546
1547    /* On some systems (e.g. IRIX 3.3), vfork doesn't separate parent
1548       from child file descriptors.  If the child closes a descriptor
1549       before it execs or exits, this munges the parent's descriptor
1550       as well.  Test for this by closing stdout in the child.  */
1551    _exit(close(fileno(stdout)) != 0);
1552  } else {
1553    int status;
1554    struct stat st;
1555
1556    while (wait(&status) != child)
1557      ;
1558    exit(
1559	 /* Was there some problem with vforking?  */
1560	 child < 0
1561
1562	 /* Did the child fail?  (This shouldn't happen.)  */
1563	 || status
1564
1565	 /* Did the vfork/compiler bug occur?  */
1566	 || parent != getpid()
1567
1568	 /* Did the file descriptor bug occur?  */
1569	 || fstat(fileno(stdout), &st) != 0
1570	 );
1571  }
1572}],
1573            [ac_cv_func_vfork_works=yes],
1574            [ac_cv_func_vfork_works=no],
1575            [ac_cv_func_vfork_works=cross])])
1576])# _AC_FUNC_VFORK
1577
1578
1579# AU::AC_FUNC_VFORK
1580# ------------
1581AU_ALIAS([AC_FUNC_VFORK], [AC_FUNC_FORK])
1582
1583# AU::AC_VFORK
1584# ------------
1585AU_ALIAS([AC_VFORK], [AC_FUNC_FORK])
1586
1587
1588# AC_FUNC_VPRINTF
1589# ---------------
1590# Why the heck is that _doprnt does not define HAVE__DOPRNT???
1591# That the logical name!
1592AC_DEFUN([AC_FUNC_VPRINTF],
1593[AC_CHECK_FUNCS(vprintf, []
1594[AC_CHECK_FUNC(_doprnt,
1595               [AC_DEFINE(HAVE_DOPRNT, 1,
1596                          [Define if you don't have `vprintf' but do have
1597                          `_doprnt.'])])])
1598])
1599
1600
1601# AU::AC_VPRINTF
1602# --------------
1603AU_ALIAS([AC_VPRINTF], [AC_FUNC_VPRINTF])
1604
1605
1606# AC_FUNC_WAIT3
1607# -------------
1608# Don't bother too hard maintaining this macro, as it's obsoleted.
1609# We don't AU define it, since we don't have any alternative to propose,
1610# any invocation should be removed, and the code adjusted.
1611AC_DEFUN([AC_FUNC_WAIT3],
1612[AC_DIAGNOSE([obsolete],
1613[$0: `wait3' is being removed from the Open Group standards.
1614Remove this `AC_FUNC_WAIT3' and adjust your code to use `waitpid' instead.])dnl
1615AC_CACHE_CHECK([for wait3 that fills in rusage],
1616               [ac_cv_func_wait3_rusage],
1617[AC_RUN_IFELSE([AC_LANG_SOURCE(
1618[[#include <sys/types.h>
1619#include <sys/time.h>
1620#include <sys/resource.h>
1621#include <stdio.h>
1622/* HP-UX has wait3 but does not fill in rusage at all.  */
1623int
1624main ()
1625{
1626  struct rusage r;
1627  int i;
1628  /* Use a field that we can force nonzero --
1629     voluntary context switches.
1630     For systems like NeXT and OSF/1 that don't set it,
1631     also use the system CPU time.  And page faults (I/O) for Linux.  */
1632  r.ru_nvcsw = 0;
1633  r.ru_stime.tv_sec = 0;
1634  r.ru_stime.tv_usec = 0;
1635  r.ru_majflt = r.ru_minflt = 0;
1636  switch (fork ())
1637    {
1638    case 0: /* Child.  */
1639      sleep(1); /* Give up the CPU.  */
1640      _exit(0);
1641      break;
1642    case -1: /* What can we do?  */
1643      _exit(0);
1644      break;
1645    default: /* Parent.  */
1646      wait3(&i, 0, &r);
1647      /* Avoid "text file busy" from rm on fast HP-UX machines.  */
1648      sleep(2);
1649      exit (r.ru_nvcsw == 0 && r.ru_majflt == 0 && r.ru_minflt == 0
1650	    && r.ru_stime.tv_sec == 0 && r.ru_stime.tv_usec == 0);
1651    }
1652}]])],
1653               [ac_cv_func_wait3_rusage=yes],
1654               [ac_cv_func_wait3_rusage=no],
1655               [ac_cv_func_wait3_rusage=no])])
1656if test $ac_cv_func_wait3_rusage = yes; then
1657  AC_DEFINE(HAVE_WAIT3, 1,
1658            [Define if you have the `wait3' system call.
1659             Deprecated, you should no longer depend upon `wait3'.])
1660fi
1661])# AC_FUNC_WAIT3
1662
1663
1664# AU::AC_WAIT3
1665# ------------
1666AU_ALIAS([AC_WAIT3], [AC_FUNC_WAIT3])
1667