xref: /netbsd-src/external/gpl3/autoconf/dist/lib/autoconf/functions.m4 (revision 4080c3a3f03649e48cc6b6ecb30c480200bd51cc)
1# This file is part of Autoconf.			-*- Autoconf -*-
2# Checking for functions.
3# Copyright (C) 2000-2012 Free Software Foundation, Inc.
4
5# This file is part of Autoconf.  This program is free
6# software; you can redistribute it and/or modify it under the
7# terms of the GNU General Public License as published by the
8# Free Software Foundation, either version 3 of the License, or
9# (at your option) 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# Under Section 7 of GPL version 3, you are granted additional
17# permissions described in the Autoconf Configure Script Exception,
18# version 3.0, as published by the Free Software Foundation.
19#
20# You should have received a copy of the GNU General Public License
21# and a copy of the Autoconf Configure Script Exception along with
22# this program; see the files COPYINGv3 and COPYING.EXCEPTION
23# respectively.  If not, see <http://www.gnu.org/licenses/>.
24
25# Written by David MacKenzie, with help from
26# Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
27# Roland McGrath, Noah Friedman, david d zuhn, and many others.
28
29
30# Table of contents
31#
32# 1. Generic tests for functions.
33# 2. Functions to check with AC_CHECK_FUNCS
34# 3. Tests for specific functions.
35
36
37## -------------------------------- ##
38## 1. Generic tests for functions.  ##
39## -------------------------------- ##
40
41# _AC_CHECK_FUNC_BODY
42# -------------------
43# Shell function body for AC_CHECK_FUNC.
44m4_define([_AC_CHECK_FUNC_BODY],
45[  AS_LINENO_PUSH([$[]1])
46  AC_CACHE_CHECK([for $[]2], [$[]3],
47  [AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY($[]2)],
48		  [AS_VAR_SET([$[]3], [yes])],
49		  [AS_VAR_SET([$[]3], [no])])])
50  AS_LINENO_POP
51])# _AC_CHECK_FUNC_BODY
52
53
54# AC_CHECK_FUNC(FUNCTION, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
55# -----------------------------------------------------------------
56# Check whether FUNCTION links in the current language.  Set the cache
57# variable ac_cv_func_FUNCTION accordingly, then execute
58# ACTION-IF-FOUND or ACTION-IF-NOT-FOUND.
59AC_DEFUN([AC_CHECK_FUNC],
60[AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_func],
61  [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_func],
62    [LINENO FUNC VAR],
63    [Tests whether FUNC exists, setting the cache variable VAR accordingly])],
64  [_$0_BODY])]dnl
65[AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$1])]dnl
66[ac_fn_[]_AC_LANG_ABBREV[]_check_func "$LINENO" "$1" "ac_var"
67AS_VAR_IF([ac_var], [yes], [$2], [$3])
68AS_VAR_POPDEF([ac_var])])# AC_CHECK_FUNC
69
70
71# _AH_CHECK_FUNC(FUNCTION)
72# ------------------------
73# Prepare the autoheader snippet for FUNCTION.
74m4_define([_AH_CHECK_FUNC],
75[AH_TEMPLATE(AS_TR_CPP([HAVE_$1]),
76  [Define to 1 if you have the `$1' function.])])
77
78
79# AC_CHECK_FUNCS(FUNCTION..., [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
80# ---------------------------------------------------------------------
81# Check for each whitespace-separated FUNCTION, and perform
82# ACTION-IF-FOUND or ACTION-IF-NOT-FOUND for each function.
83# Additionally, make the preprocessor definition HAVE_FUNCTION
84# available for each found function.  Either ACTION may include
85# `break' to stop the search.
86AC_DEFUN([AC_CHECK_FUNCS],
87[m4_map_args_w([$1], [_AH_CHECK_FUNC(], [)])]dnl
88[AS_FOR([AC_func], [ac_func], [$1],
89[AC_CHECK_FUNC(AC_func,
90	       [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_]AC_func)) $2],
91	       [$3])dnl])
92])# AC_CHECK_FUNCS
93
94
95# _AC_CHECK_FUNC_ONCE(FUNCTION)
96# -----------------------------
97# Check for a single FUNCTION once.
98m4_define([_AC_CHECK_FUNC_ONCE],
99[_AH_CHECK_FUNC([$1])AC_DEFUN([_AC_Func_$1],
100  [m4_divert_text([INIT_PREPARE], [AS_VAR_APPEND([ac_func_list], [" $1"])])
101_AC_FUNCS_EXPANSION])AC_REQUIRE([_AC_Func_$1])])
102
103# AC_CHECK_FUNCS_ONCE(FUNCTION...)
104# --------------------------------
105# Add each whitespace-separated name in FUNCTION to the list of functions
106# to check once.
107AC_DEFUN([AC_CHECK_FUNCS_ONCE],
108[m4_map_args_w([$1], [_AC_CHECK_FUNC_ONCE(], [)])])
109
110m4_define([_AC_FUNCS_EXPANSION],
111[
112  m4_divert_text([DEFAULTS], [ac_func_list=])
113  AC_CHECK_FUNCS([$ac_func_list])
114  m4_define([_AC_FUNCS_EXPANSION], [])
115])
116
117
118# _AC_REPLACE_FUNC(FUNCTION)
119# --------------------------
120# If FUNCTION exists, define HAVE_FUNCTION; else add FUNCTION.c
121# to the list of library objects.  FUNCTION must be literal.
122m4_define([_AC_REPLACE_FUNC],
123[AC_CHECK_FUNC([$1],
124  [_AH_CHECK_FUNC([$1])AC_DEFINE(AS_TR_CPP([HAVE_$1]))],
125  [_AC_LIBOBJ([$1])AC_LIBSOURCE([$1.c])])])
126
127# AC_REPLACE_FUNCS(FUNCTION...)
128# -----------------------------
129# For each FUNCTION in the whitespace separated list, perform the
130# equivalent of AC_CHECK_FUNC, then call AC_LIBOBJ if the function
131# was not found.
132AC_DEFUN([AC_REPLACE_FUNCS],
133[_$0(m4_flatten([$1]))])
134
135m4_define([_AC_REPLACE_FUNCS],
136[AS_LITERAL_IF([$1],
137[m4_map_args_w([$1], [_AC_REPLACE_FUNC(], [)
138])],
139[AC_CHECK_FUNCS([$1],
140  [_AH_CHECK_FUNC([$ac_func])],
141  [_AC_LIBOBJ([$ac_func])])])])
142
143
144# AC_TRY_LINK_FUNC(FUNC, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
145# ------------------------------------------------------------
146# Try to link a program that calls FUNC, handling GCC builtins.  If
147# the link succeeds, execute ACTION-IF-FOUND; otherwise, execute
148# ACTION-IF-NOT-FOUND.
149AC_DEFUN([AC_TRY_LINK_FUNC],
150[AC_LINK_IFELSE([AC_LANG_CALL([], [$1])], [$2], [$3])])
151
152
153# AU::AC_FUNC_CHECK
154# -----------------
155AU_ALIAS([AC_FUNC_CHECK], [AC_CHECK_FUNC])
156
157
158# AU::AC_HAVE_FUNCS
159# -----------------
160AU_ALIAS([AC_HAVE_FUNCS], [AC_CHECK_FUNCS])
161
162
163
164
165## ------------------------------------------- ##
166## 2. Functions to check with AC_CHECK_FUNCS.  ##
167## ------------------------------------------- ##
168
169AN_FUNCTION([__argz_count],            [AC_CHECK_FUNCS])
170AN_FUNCTION([__argz_next],             [AC_CHECK_FUNCS])
171AN_FUNCTION([__argz_stringify],        [AC_CHECK_FUNCS])
172AN_FUNCTION([__fpending],              [AC_CHECK_FUNCS])
173AN_FUNCTION([acl],                     [AC_CHECK_FUNCS])
174AN_FUNCTION([alarm],                   [AC_CHECK_FUNCS])
175AN_FUNCTION([atexit],                  [AC_CHECK_FUNCS])
176AN_FUNCTION([btowc],                   [AC_CHECK_FUNCS])
177AN_FUNCTION([bzero],                   [AC_CHECK_FUNCS])
178AN_FUNCTION([clock_gettime],           [AC_CHECK_FUNCS])
179AN_FUNCTION([doprnt],                  [AC_CHECK_FUNCS])
180AN_FUNCTION([dup2],                    [AC_CHECK_FUNCS])
181AN_FUNCTION([endgrent],                [AC_CHECK_FUNCS])
182AN_FUNCTION([endpwent],                [AC_CHECK_FUNCS])
183AN_FUNCTION([euidaccess],              [AC_CHECK_FUNCS])
184AN_FUNCTION([fchdir],                  [AC_CHECK_FUNCS])
185AN_FUNCTION([fdatasync],               [AC_CHECK_FUNCS])
186AN_FUNCTION([fesetround],              [AC_CHECK_FUNCS])
187AN_FUNCTION([floor],                   [AC_CHECK_FUNCS])
188AN_FUNCTION([fs_stat_dev],             [AC_CHECK_FUNCS])
189AN_FUNCTION([ftime],                   [AC_CHECK_FUNCS])
190AN_FUNCTION([ftruncate],               [AC_CHECK_FUNCS])
191AN_FUNCTION([getcwd],                  [AC_CHECK_FUNCS])
192AN_FUNCTION([getdelim],                [AC_CHECK_FUNCS])
193AN_FUNCTION([gethostbyaddr],           [AC_CHECK_FUNCS])
194AN_FUNCTION([gethostbyname],           [AC_CHECK_FUNCS])
195AN_FUNCTION([gethostname],             [AC_CHECK_FUNCS])
196AN_FUNCTION([gethrtime],               [AC_CHECK_FUNCS])
197AN_FUNCTION([getmntent],               [AC_CHECK_FUNCS])
198AN_FUNCTION([getmntinfo],              [AC_CHECK_FUNCS])
199AN_FUNCTION([getpagesize],             [AC_CHECK_FUNCS])
200AN_FUNCTION([getpass],                 [AC_CHECK_FUNCS])
201AN_FUNCTION([getspnam],                [AC_CHECK_FUNCS])
202AN_FUNCTION([gettimeofday],            [AC_CHECK_FUNCS])
203AN_FUNCTION([getusershell],            [AC_CHECK_FUNCS])
204AN_FUNCTION([hasmntopt],               [AC_CHECK_FUNCS])
205AN_FUNCTION([inet_ntoa],               [AC_CHECK_FUNCS])
206AN_FUNCTION([isascii],                 [AC_CHECK_FUNCS])
207AN_FUNCTION([iswprint],                [AC_CHECK_FUNCS])
208AN_FUNCTION([lchown],                  [AC_CHECK_FUNCS])
209AN_FUNCTION([listmntent],              [AC_CHECK_FUNCS])
210AN_FUNCTION([localeconv],              [AC_CHECK_FUNCS])
211AN_FUNCTION([localtime_r],             [AC_CHECK_FUNCS])
212AN_FUNCTION([mblen],                   [AC_CHECK_FUNCS])
213AN_FUNCTION([mbrlen],                  [AC_CHECK_FUNCS])
214AN_FUNCTION([memchr],                  [AC_CHECK_FUNCS])
215AN_FUNCTION([memmove],                 [AC_CHECK_FUNCS])
216AN_FUNCTION([mempcpy],                 [AC_CHECK_FUNCS])
217AN_FUNCTION([memset],                  [AC_CHECK_FUNCS])
218AN_FUNCTION([mkdir],                   [AC_CHECK_FUNCS])
219AN_FUNCTION([mkfifo],                  [AC_CHECK_FUNCS])
220AN_FUNCTION([modf],                    [AC_CHECK_FUNCS])
221AN_FUNCTION([munmap],                  [AC_CHECK_FUNCS])
222AN_FUNCTION([next_dev],                [AC_CHECK_FUNCS])
223AN_FUNCTION([nl_langinfo],             [AC_CHECK_FUNCS])
224AN_FUNCTION([pathconf],                [AC_CHECK_FUNCS])
225AN_FUNCTION([pow],                     [AC_CHECK_FUNCS])
226AN_FUNCTION([pstat_getdynamic],        [AC_CHECK_FUNCS])
227AN_FUNCTION([putenv],                  [AC_CHECK_FUNCS])
228AN_FUNCTION([re_comp],                 [AC_CHECK_FUNCS])
229AN_FUNCTION([realpath],                [AC_CHECK_FUNCS])
230AN_FUNCTION([regcmp],                  [AC_CHECK_FUNCS])
231AN_FUNCTION([regcomp],                 [AC_CHECK_FUNCS])
232AN_FUNCTION([resolvepath],             [AC_CHECK_FUNCS])
233AN_FUNCTION([rint],                    [AC_CHECK_FUNCS])
234AN_FUNCTION([rmdir],                   [AC_CHECK_FUNCS])
235AN_FUNCTION([rpmatch],                 [AC_CHECK_FUNCS])
236AN_FUNCTION([select],                  [AC_CHECK_FUNCS])
237AN_FUNCTION([setenv],                  [AC_CHECK_FUNCS])
238AN_FUNCTION([sethostname],             [AC_CHECK_FUNCS])
239AN_FUNCTION([setlocale],               [AC_CHECK_FUNCS])
240AN_FUNCTION([socket],                  [AC_CHECK_FUNCS])
241AN_FUNCTION([sqrt],                    [AC_CHECK_FUNCS])
242AN_FUNCTION([stime],                   [AC_CHECK_FUNCS])
243AN_FUNCTION([stpcpy],                  [AC_CHECK_FUNCS])
244AN_FUNCTION([strcasecmp],              [AC_CHECK_FUNCS])
245AN_FUNCTION([strchr],                  [AC_CHECK_FUNCS])
246AN_FUNCTION([strcspn],                 [AC_CHECK_FUNCS])
247AN_FUNCTION([strdup],                  [AC_CHECK_FUNCS])
248AN_FUNCTION([strerror],                [AC_CHECK_FUNCS])
249AN_FUNCTION([strncasecmp],             [AC_CHECK_FUNCS])
250AN_FUNCTION([strndup],                 [AC_CHECK_FUNCS])
251AN_FUNCTION([strpbrk],                 [AC_CHECK_FUNCS])
252AN_FUNCTION([strrchr],                 [AC_CHECK_FUNCS])
253AN_FUNCTION([strspn],                  [AC_CHECK_FUNCS])
254AN_FUNCTION([strstr],                  [AC_CHECK_FUNCS])
255AN_FUNCTION([strtol],                  [AC_CHECK_FUNCS])
256AN_FUNCTION([strtoul],                 [AC_CHECK_FUNCS])
257AN_FUNCTION([strtoull],                [AC_CHECK_FUNCS])
258AN_FUNCTION([strtoumax],               [AC_CHECK_FUNCS])
259AN_FUNCTION([strverscmp],              [AC_CHECK_FUNCS])
260AN_FUNCTION([sysinfo],                 [AC_CHECK_FUNCS])
261AN_FUNCTION([tzset],                   [AC_CHECK_FUNCS])
262AN_FUNCTION([uname],                   [AC_CHECK_FUNCS])
263AN_FUNCTION([utime],                   [AC_CHECK_FUNCS])
264AN_FUNCTION([utmpname],                [AC_CHECK_FUNCS])
265AN_FUNCTION([utmpxname],               [AC_CHECK_FUNCS])
266AN_FUNCTION([wcwidth],                 [AC_CHECK_FUNCS])
267
268
269AN_FUNCTION([dcgettext],    [AM_GNU_GETTEXT])
270AN_FUNCTION([getwd],        [warn: getwd is deprecated, use getcwd instead])
271
272
273## --------------------------------- ##
274## 3. Tests for specific functions.  ##
275## --------------------------------- ##
276
277
278# The macros are sorted:
279#
280# 1. AC_FUNC_* macros are sorted by alphabetical order.
281#
282# 2. Helping macros such as _AC_LIBOBJ_* are before the macro that
283#    uses it.
284#
285# 3. Obsolete macros are right after the modern macro.
286
287
288
289# _AC_LIBOBJ_ALLOCA
290# -----------------
291# Set up the LIBOBJ replacement of `alloca'.  Well, not exactly
292# AC_LIBOBJ since we actually set the output variable `ALLOCA'.
293# Nevertheless, for Automake, AC_LIBSOURCES it.
294m4_define([_AC_LIBOBJ_ALLOCA],
295[# The SVR3 libPW and SVR4 libucb both contain incompatible functions
296# that cause trouble.  Some versions do not even contain alloca or
297# contain a buggy version.  If you still want to use their alloca,
298# use ar to extract alloca.o from them instead of compiling alloca.c.
299AC_LIBSOURCES(alloca.c)
300AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl
301AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using `alloca.c'.])
302
303AC_CACHE_CHECK(whether `alloca.c' needs Cray hooks, ac_cv_os_cray,
304[AC_EGREP_CPP(webecray,
305[#if defined CRAY && ! defined CRAY2
306webecray
307#else
308wenotbecray
309#endif
310], ac_cv_os_cray=yes, ac_cv_os_cray=no)])
311if test $ac_cv_os_cray = yes; then
312  for ac_func in _getb67 GETB67 getb67; do
313    AC_CHECK_FUNC($ac_func,
314		  [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func,
315				      [Define to one of `_getb67', `GETB67',
316				       `getb67' for Cray-2 and Cray-YMP
317				       systems. This function is required for
318				       `alloca.c' support on those systems.])
319    break])
320  done
321fi
322
323AC_CACHE_CHECK([stack direction for C alloca],
324	       [ac_cv_c_stack_direction],
325[AC_RUN_IFELSE([AC_LANG_SOURCE(
326[AC_INCLUDES_DEFAULT
327int
328find_stack_direction (int *addr, int depth)
329{
330  int dir, dummy = 0;
331  if (! addr)
332    addr = &dummy;
333  *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
334  dir = depth ? find_stack_direction (addr, depth - 1) : 0;
335  return dir + dummy;
336}
337
338int
339main (int argc, char **argv)
340{
341  return find_stack_direction (0, argc + !argv + 20) < 0;
342}])],
343	       [ac_cv_c_stack_direction=1],
344	       [ac_cv_c_stack_direction=-1],
345	       [ac_cv_c_stack_direction=0])])
346AH_VERBATIM([STACK_DIRECTION],
347[/* If using the C implementation of alloca, define if you know the
348   direction of stack growth for your system; otherwise it will be
349   automatically deduced at runtime.
350	STACK_DIRECTION > 0 => grows toward higher addresses
351	STACK_DIRECTION < 0 => grows toward lower addresses
352	STACK_DIRECTION = 0 => direction of growth unknown */
353@%:@undef STACK_DIRECTION])dnl
354AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
355])# _AC_LIBOBJ_ALLOCA
356
357
358# AC_FUNC_ALLOCA
359# --------------
360AN_FUNCTION([alloca], [AC_FUNC_ALLOCA])
361AN_HEADER([alloca.h], [AC_FUNC_ALLOCA])
362AC_DEFUN([AC_FUNC_ALLOCA],
363[AC_REQUIRE([AC_TYPE_SIZE_T])]dnl
364[# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
365# for constant arguments.  Useless!
366AC_CACHE_CHECK([for working alloca.h], ac_cv_working_alloca_h,
367[AC_LINK_IFELSE(
368       [AC_LANG_PROGRAM([[@%:@include <alloca.h>]],
369			[[char *p = (char *) alloca (2 * sizeof (int));
370			  if (p) return 0;]])],
371		[ac_cv_working_alloca_h=yes],
372		[ac_cv_working_alloca_h=no])])
373if test $ac_cv_working_alloca_h = yes; then
374  AC_DEFINE(HAVE_ALLOCA_H, 1,
375	    [Define to 1 if you have <alloca.h> and it should be used
376	     (not on Ultrix).])
377fi
378
379AC_CACHE_CHECK([for alloca], ac_cv_func_alloca_works,
380[AC_LINK_IFELSE([AC_LANG_PROGRAM(
381[[#ifdef __GNUC__
382# define alloca __builtin_alloca
383#else
384# ifdef _MSC_VER
385#  include <malloc.h>
386#  define alloca _alloca
387# elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
388#   include <stdlib.h>
389# else
390#  ifdef HAVE_ALLOCA_H
391#   include <alloca.h>
392#  else
393#   ifdef _AIX
394 #pragma alloca
395#   else
396#    ifndef alloca /* predefined by HP cc +Olibcalls */
397void *alloca (size_t);
398#    endif
399#   endif
400#  endif
401# endif
402#endif
403]],                               [[char *p = (char *) alloca (1);
404				    if (p) return 0;]])],
405		[ac_cv_func_alloca_works=yes],
406		[ac_cv_func_alloca_works=no])])
407
408if test $ac_cv_func_alloca_works = yes; then
409  AC_DEFINE(HAVE_ALLOCA, 1,
410	    [Define to 1 if you have `alloca', as a function or macro.])
411else
412  _AC_LIBOBJ_ALLOCA
413fi
414])# AC_FUNC_ALLOCA
415
416
417# AU::AC_ALLOCA
418# -------------
419AU_ALIAS([AC_ALLOCA], [AC_FUNC_ALLOCA])
420
421
422# AC_FUNC_CHOWN
423# -------------
424# Determine whether chown accepts arguments of -1 for uid and gid.
425AN_FUNCTION([chown], [AC_FUNC_CHOWN])
426AC_DEFUN([AC_FUNC_CHOWN],
427[AC_REQUIRE([AC_TYPE_UID_T])dnl
428AC_CHECK_HEADERS(unistd.h)
429AC_CACHE_CHECK([for working chown], ac_cv_func_chown_works,
430[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
431#include <fcntl.h>
432],
433[[  char *f = "conftest.chown";
434  struct stat before, after;
435
436  if (creat (f, 0600) < 0)
437    return 1;
438  if (stat (f, &before) < 0)
439    return 1;
440  if (chown (f, (uid_t) -1, (gid_t) -1) == -1)
441    return 1;
442  if (stat (f, &after) < 0)
443    return 1;
444  return ! (before.st_uid == after.st_uid && before.st_gid == after.st_gid);
445]])],
446	       [ac_cv_func_chown_works=yes],
447	       [ac_cv_func_chown_works=no],
448	       [ac_cv_func_chown_works=no])
449rm -f conftest.chown
450])
451if test $ac_cv_func_chown_works = yes; then
452  AC_DEFINE(HAVE_CHOWN, 1,
453	    [Define to 1 if your system has a working `chown' function.])
454fi
455])# AC_FUNC_CHOWN
456
457
458# AC_FUNC_CLOSEDIR_VOID
459# ---------------------
460# Check whether closedir returns void, and #define CLOSEDIR_VOID in
461# that case.
462AC_DEFUN([AC_FUNC_CLOSEDIR_VOID],
463[AC_REQUIRE([AC_HEADER_DIRENT])dnl
464AC_CACHE_CHECK([whether closedir returns void],
465	       [ac_cv_func_closedir_void],
466[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
467#include <$ac_header_dirent>
468#ifndef __cplusplus
469int closedir ();
470#endif
471],
472				[[return closedir (opendir (".")) != 0;]])],
473	       [ac_cv_func_closedir_void=no],
474	       [ac_cv_func_closedir_void=yes],
475	       [ac_cv_func_closedir_void=yes])])
476if test $ac_cv_func_closedir_void = yes; then
477  AC_DEFINE(CLOSEDIR_VOID, 1,
478	    [Define to 1 if the `closedir' function returns void instead
479	     of `int'.])
480fi
481])
482
483
484# AC_FUNC_ERROR_AT_LINE
485# ---------------------
486AN_FUNCTION([error],         [AC_FUNC_ERROR_AT_LINE])
487AN_FUNCTION([error_at_line], [AC_FUNC_ERROR_AT_LINE])
488AC_DEFUN([AC_FUNC_ERROR_AT_LINE],
489[AC_LIBSOURCES([error.h, error.c])dnl
490AC_CACHE_CHECK([for error_at_line], ac_cv_lib_error_at_line,
491[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <error.h>],
492				 [error_at_line (0, 0, "", 0, "an error occurred");])],
493		[ac_cv_lib_error_at_line=yes],
494		[ac_cv_lib_error_at_line=no])])
495if test $ac_cv_lib_error_at_line = no; then
496  AC_LIBOBJ(error)
497fi
498])
499
500
501# AU::AM_FUNC_ERROR_AT_LINE
502# -------------------------
503AU_ALIAS([AM_FUNC_ERROR_AT_LINE], [AC_FUNC_ERROR_AT_LINE])
504
505
506# _AC_FUNC_FNMATCH_IF(STANDARD = GNU | POSIX, CACHE_VAR, IF-TRUE, IF-FALSE)
507# -------------------------------------------------------------------------
508# If a STANDARD compliant fnmatch is found, run IF-TRUE, otherwise
509# IF-FALSE.  Use CACHE_VAR.
510AC_DEFUN([_AC_FUNC_FNMATCH_IF],
511[AC_CACHE_CHECK(
512   [for working $1 fnmatch],
513   [$2],
514  [# Some versions of Solaris, SCO, and the GNU C Library
515   # have a broken or incompatible fnmatch.
516   # So we run a test program.  If we are cross-compiling, take no chance.
517   # Thanks to John Oleynick, Franc,ois Pinard, and Paul Eggert for this test.
518   AC_RUN_IFELSE(
519      [AC_LANG_PROGRAM(
520	 [#include <fnmatch.h>
521#	   define y(a, b, c) (fnmatch (a, b, c) == 0)
522#	   define n(a, b, c) (fnmatch (a, b, c) == FNM_NOMATCH)
523	 ],
524	 [return
525	   (!(y ("a*", "abc", 0)
526	      && n ("d*/*1", "d/s/1", FNM_PATHNAME)
527	      && y ("a\\\\bc", "abc", 0)
528	      && n ("a\\\\bc", "abc", FNM_NOESCAPE)
529	      && y ("*x", ".x", 0)
530	      && n ("*x", ".x", FNM_PERIOD)
531	      && m4_if([$1], [GNU],
532		   [y ("xxXX", "xXxX", FNM_CASEFOLD)
533		    && y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)
534		    && n ("d*/*1", "d/s/1", FNM_FILE_NAME)
535		    && y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)
536		    && y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)
537		    && y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)],
538		   1)));])],
539      [$2=yes],
540      [$2=no],
541      [$2=cross])])
542AS_IF([test $$2 = yes], [$3], [$4])
543])# _AC_FUNC_FNMATCH_IF
544
545
546# AC_FUNC_FNMATCH
547# ---------------
548AC_DEFUN([AC_FUNC_FNMATCH],
549[_AC_FUNC_FNMATCH_IF([POSIX], [ac_cv_func_fnmatch_works],
550		     [AC_DEFINE([HAVE_FNMATCH], 1,
551		     [Define to 1 if your system has a working POSIX `fnmatch'
552		      function.])])
553])# AC_FUNC_FNMATCH
554
555
556# _AC_LIBOBJ_FNMATCH
557# ------------------
558# Prepare the replacement of fnmatch.
559AC_DEFUN([_AC_LIBOBJ_FNMATCH],
560[AC_REQUIRE([AC_C_CONST])dnl
561AC_REQUIRE([AC_FUNC_ALLOCA])dnl
562AC_REQUIRE([AC_TYPE_MBSTATE_T])dnl
563AC_CHECK_DECLS([getenv])
564AC_CHECK_FUNCS([btowc mbsrtowcs mempcpy wmempcpy])
565AC_CHECK_HEADERS([wchar.h wctype.h])
566AC_LIBOBJ([fnmatch])
567AC_CONFIG_LINKS([$ac_config_libobj_dir/fnmatch.h:$ac_config_libobj_dir/fnmatch_.h])
568AC_DEFINE(fnmatch, rpl_fnmatch,
569	  [Define to rpl_fnmatch if the replacement function should be used.])
570])# _AC_LIBOBJ_FNMATCH
571
572
573# AC_REPLACE_FNMATCH
574# ------------------
575AC_DEFUN([AC_REPLACE_FNMATCH],
576[_AC_FUNC_FNMATCH_IF([POSIX], [ac_cv_func_fnmatch_works],
577		     [rm -f "$ac_config_libobj_dir/fnmatch.h"],
578		     [_AC_LIBOBJ_FNMATCH])
579])# AC_REPLACE_FNMATCH
580
581
582# AC_FUNC_FNMATCH_GNU
583# -------------------
584AC_DEFUN([AC_FUNC_FNMATCH_GNU],
585[AC_REQUIRE([AC_GNU_SOURCE])
586_AC_FUNC_FNMATCH_IF([GNU], [ac_cv_func_fnmatch_gnu],
587		    [rm -f "$ac_config_libobj_dir/fnmatch.h"],
588		    [_AC_LIBOBJ_FNMATCH])
589])# AC_FUNC_FNMATCH_GNU
590
591
592# AU::AM_FUNC_FNMATCH
593# AU::fp_FUNC_FNMATCH
594# -------------------
595AU_ALIAS([AM_FUNC_FNMATCH], [AC_FUNC_FNMATCH])
596AU_ALIAS([fp_FUNC_FNMATCH], [AC_FUNC_FNMATCH])
597
598
599# AC_FUNC_FSEEKO
600# --------------
601AN_FUNCTION([ftello], [AC_FUNC_FSEEKO])
602AN_FUNCTION([fseeko], [AC_FUNC_FSEEKO])
603AC_DEFUN([AC_FUNC_FSEEKO],
604[_AC_SYS_LARGEFILE_MACRO_VALUE(_LARGEFILE_SOURCE, 1,
605   [ac_cv_sys_largefile_source],
606   [Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2).],
607   [[#include <sys/types.h> /* for off_t */
608     #include <stdio.h>]],
609   [[int (*fp) (FILE *, off_t, int) = fseeko;
610     return fseeko (stdin, 0, 0) && fp (stdin, 0, 0);]])
611
612# We used to try defining _XOPEN_SOURCE=500 too, to work around a bug
613# in glibc 2.1.3, but that breaks too many other things.
614# If you want fseeko and ftello with glibc, upgrade to a fixed glibc.
615if test $ac_cv_sys_largefile_source != unknown; then
616  AC_DEFINE(HAVE_FSEEKO, 1,
617    [Define to 1 if fseeko (and presumably ftello) exists and is declared.])
618fi
619])# AC_FUNC_FSEEKO
620
621
622# AC_FUNC_GETGROUPS
623# -----------------
624# Try to find `getgroups', and check that it works.
625# When cross-compiling, assume getgroups is broken.
626AN_FUNCTION([getgroups], [AC_FUNC_GETGROUPS])
627AC_DEFUN([AC_FUNC_GETGROUPS],
628[AC_REQUIRE([AC_TYPE_GETGROUPS])dnl
629AC_REQUIRE([AC_TYPE_SIZE_T])dnl
630AC_CHECK_FUNC(getgroups)
631
632# If we don't yet have getgroups, see if it's in -lbsd.
633# This is reported to be necessary on an ITOS 3000WS running SEIUX 3.1.
634ac_save_LIBS=$LIBS
635if test $ac_cv_func_getgroups = no; then
636  AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd])
637fi
638
639# Run the program to test the functionality of the system-supplied
640# getgroups function only if there is such a function.
641if test $ac_cv_func_getgroups = yes; then
642  AC_CACHE_CHECK([for working getgroups], ac_cv_func_getgroups_works,
643   [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
644      [[/* On Ultrix 4.3, getgroups (0, 0) always fails.  */
645       return getgroups (0, 0) == -1;]])],
646		  [ac_cv_func_getgroups_works=yes],
647		  [ac_cv_func_getgroups_works=no],
648		  [ac_cv_func_getgroups_works=no])
649   ])
650else
651  ac_cv_func_getgroups_works=no
652fi
653if test $ac_cv_func_getgroups_works = yes; then
654  AC_DEFINE(HAVE_GETGROUPS, 1,
655	    [Define to 1 if your system has a working `getgroups' function.])
656fi
657LIBS=$ac_save_LIBS
658])# AC_FUNC_GETGROUPS
659
660
661# _AC_LIBOBJ_GETLOADAVG
662# ---------------------
663# Set up the AC_LIBOBJ replacement of `getloadavg'.
664m4_define([_AC_LIBOBJ_GETLOADAVG],
665[AC_LIBOBJ(getloadavg)
666AC_DEFINE(C_GETLOADAVG, 1, [Define to 1 if using `getloadavg.c'.])
667# Figure out what our getloadavg.c needs.
668ac_have_func=no
669AC_CHECK_HEADER(sys/dg_sys_info.h,
670[ac_have_func=yes
671 AC_DEFINE(DGUX, 1, [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
672 AC_CHECK_LIB(dgc, dg_sys_info)])
673
674AC_CHECK_HEADER(locale.h)
675AC_CHECK_FUNCS(setlocale)
676
677# We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
678# uses stabs), but it is still SVR4.  We cannot check for <elf.h> because
679# Irix 4.0.5F has the header but not the library.
680if test $ac_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes \
681    && test "$ac_cv_lib_kvm_kvm_open" = yes; then
682  ac_have_func=yes
683  AC_DEFINE(SVR4, 1, [Define to 1 on System V Release 4.])
684fi
685
686if test $ac_have_func = no; then
687  AC_CHECK_HEADER(inq_stats/cpustats.h,
688  [ac_have_func=yes
689   AC_DEFINE(UMAX, 1, [Define to 1 for Encore UMAX.])
690   AC_DEFINE(UMAX4_3, 1,
691	     [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
692	      instead of <sys/cpustats.h>.])])
693fi
694
695if test $ac_have_func = no; then
696  AC_CHECK_HEADER(sys/cpustats.h,
697  [ac_have_func=yes; AC_DEFINE(UMAX)])
698fi
699
700if test $ac_have_func = no; then
701  AC_CHECK_HEADERS(mach/mach.h)
702fi
703
704AC_CHECK_HEADERS(nlist.h,
705[AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
706		  [AC_DEFINE(NLIST_NAME_UNION, 1,
707			     [Define to 1 if your `struct nlist' has an
708			      `n_un' member.  Obsolete, depend on
709			      `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [],
710		  [@%:@include <nlist.h>])
711])dnl
712])# _AC_LIBOBJ_GETLOADAVG
713
714
715# AC_FUNC_GETLOADAVG
716# ------------------
717AC_DEFUN([AC_FUNC_GETLOADAVG],
718[ac_have_func=no # yes means we've found a way to get the load average.
719
720# Make sure getloadavg.c is where it belongs, at configure-time.
721test -f "$srcdir/$ac_config_libobj_dir/getloadavg.c" ||
722  AC_MSG_ERROR([$srcdir/$ac_config_libobj_dir/getloadavg.c is missing])
723
724ac_save_LIBS=$LIBS
725
726# Check for getloadavg, but be sure not to touch the cache variable.
727(AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && ac_have_func=yes
728
729# On HPUX9, an unprivileged user can get load averages through this function.
730AC_CHECK_FUNCS(pstat_getdynamic)
731
732# Solaris has libkstat which does not require root.
733AC_CHECK_LIB(kstat, kstat_open)
734test $ac_cv_lib_kstat_kstat_open = yes && ac_have_func=yes
735
736# Some systems with -lutil have (and need) -lkvm as well, some do not.
737# On Solaris, -lkvm requires nlist from -lelf, so check that first
738# to get the right answer into the cache.
739# For kstat on solaris, we need libelf to force the definition of SVR4 below.
740if test $ac_have_func = no; then
741  AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
742fi
743if test $ac_have_func = no; then
744  AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
745  # Check for the 4.4BSD definition of getloadavg.
746  AC_CHECK_LIB(util, getloadavg,
747    [LIBS="-lutil $LIBS" ac_have_func=yes ac_cv_func_getloadavg_setgid=yes])
748fi
749
750if test $ac_have_func = no; then
751  # There is a commonly available library for RS/6000 AIX.
752  # Since it is not a standard part of AIX, it might be installed locally.
753  ac_getloadavg_LIBS=$LIBS
754  LIBS="-L/usr/local/lib $LIBS"
755  AC_CHECK_LIB(getloadavg, getloadavg,
756	       [LIBS="-lgetloadavg $LIBS"], [LIBS=$ac_getloadavg_LIBS])
757fi
758
759# Make sure it is really in the library, if we think we found it,
760# otherwise set up the replacement function.
761AC_CHECK_FUNCS(getloadavg, [],
762	       [_AC_LIBOBJ_GETLOADAVG])
763
764# Some definitions of getloadavg require that the program be installed setgid.
765AC_CACHE_CHECK(whether getloadavg requires setgid,
766	       ac_cv_func_getloadavg_setgid,
767[AC_EGREP_CPP([Yowza Am I SETGID yet],
768[#include "$srcdir/$ac_config_libobj_dir/getloadavg.c"
769#ifdef LDAV_PRIVILEGED
770Yowza Am I SETGID yet
771@%:@endif],
772	      ac_cv_func_getloadavg_setgid=yes,
773	      ac_cv_func_getloadavg_setgid=no)])
774if test $ac_cv_func_getloadavg_setgid = yes; then
775  NEED_SETGID=true
776  AC_DEFINE(GETLOADAVG_PRIVILEGED, 1,
777	    [Define to 1 if the `getloadavg' function needs to be run setuid
778	     or setgid.])
779else
780  NEED_SETGID=false
781fi
782AC_SUBST(NEED_SETGID)dnl
783
784if test $ac_cv_func_getloadavg_setgid = yes; then
785  AC_CACHE_CHECK(group of /dev/kmem, ac_cv_group_kmem,
786[ # On Solaris, /dev/kmem is a symlink.  Get info on the real file.
787  ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
788  # If we got an error (system does not support symlinks), try without -L.
789  test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
790  ac_cv_group_kmem=`AS_ECHO(["$ac_ls_output"]) \
791    | sed -ne ['s/[	 ][	 ]*/ /g;
792	       s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\)  *.*/\1/;
793	       / /s/.* //;p;']`
794])
795  AC_SUBST(KMEM_GROUP, $ac_cv_group_kmem)dnl
796fi
797if test "x$ac_save_LIBS" = x; then
798  GETLOADAVG_LIBS=$LIBS
799else
800  GETLOADAVG_LIBS=`AS_ECHO(["$LIBS"]) | sed "s|$ac_save_LIBS||"`
801fi
802LIBS=$ac_save_LIBS
803
804AC_SUBST(GETLOADAVG_LIBS)dnl
805])# AC_FUNC_GETLOADAVG
806
807
808# AU::AC_GETLOADAVG
809# -----------------
810AU_ALIAS([AC_GETLOADAVG], [AC_FUNC_GETLOADAVG])
811
812
813# AC_FUNC_GETMNTENT
814# -----------------
815AN_FUNCTION([getmntent], [AC_FUNC_GETMNTENT])
816AC_DEFUN([AC_FUNC_GETMNTENT],
817[# getmntent is in the standard C library on UNICOS, in -lsun on Irix 4,
818# -lseq on Dynix/PTX, -lgen on Unixware.
819AC_SEARCH_LIBS(getmntent, [sun seq gen],
820	       [ac_cv_func_getmntent=yes
821		AC_DEFINE([HAVE_GETMNTENT], 1,
822			  [Define to 1 if you have the `getmntent' function.])],
823	       [ac_cv_func_getmntent=no])
824])
825
826
827# AC_FUNC_GETPGRP
828# ---------------
829# Figure out whether getpgrp requires zero arguments.
830AC_DEFUN([AC_FUNC_GETPGRP],
831[AC_CACHE_CHECK(whether getpgrp requires zero arguments,
832 ac_cv_func_getpgrp_void,
833[# Use it with a single arg.
834AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [getpgrp (0);])],
835		  [ac_cv_func_getpgrp_void=no],
836		  [ac_cv_func_getpgrp_void=yes])
837])
838if test $ac_cv_func_getpgrp_void = yes; then
839  AC_DEFINE(GETPGRP_VOID, 1,
840	    [Define to 1 if the `getpgrp' function requires zero arguments.])
841fi
842])# AC_FUNC_GETPGRP
843
844
845# AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
846# -------------------------------------
847# When cross-compiling, be pessimistic so we will end up using the
848# replacement version of lstat that checks for trailing slashes and
849# calls lstat a second time when necessary.
850AN_FUNCTION([lstat], [AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
851AC_DEFUN([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
852[AC_CACHE_CHECK(
853       [whether lstat correctly handles trailing slash],
854       [ac_cv_func_lstat_dereferences_slashed_symlink],
855[rm -f conftest.sym conftest.file
856echo >conftest.file
857if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then
858  AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
859    [struct stat sbuf;
860     /* Linux will dereference the symlink and fail, as required by POSIX.
861	That is better in the sense that it means we will not
862	have to compile and use the lstat wrapper.  */
863     return lstat ("conftest.sym/", &sbuf) == 0;])],
864		[ac_cv_func_lstat_dereferences_slashed_symlink=yes],
865		[ac_cv_func_lstat_dereferences_slashed_symlink=no],
866		[ac_cv_func_lstat_dereferences_slashed_symlink=no])
867else
868  # If the `ln -s' command failed, then we probably don't even
869  # have an lstat function.
870  ac_cv_func_lstat_dereferences_slashed_symlink=no
871fi
872rm -f conftest.sym conftest.file
873])
874
875test $ac_cv_func_lstat_dereferences_slashed_symlink = yes &&
876  AC_DEFINE_UNQUOTED([LSTAT_FOLLOWS_SLASHED_SYMLINK], [1],
877		     [Define to 1 if `lstat' dereferences a symlink specified
878		      with a trailing slash.])
879
880if test "x$ac_cv_func_lstat_dereferences_slashed_symlink" = xno; then
881  AC_LIBOBJ([lstat])
882fi
883])
884
885
886# _AC_FUNC_MALLOC_IF(IF-WORKS, IF-NOT)
887# ------------------------------------
888# If `malloc (0)' properly handled, run IF-WORKS, otherwise, IF-NOT.
889AC_DEFUN([_AC_FUNC_MALLOC_IF],
890[AC_REQUIRE([AC_HEADER_STDC])dnl
891AC_CHECK_HEADERS(stdlib.h)
892AC_CACHE_CHECK([for GNU libc compatible malloc], ac_cv_func_malloc_0_nonnull,
893[AC_RUN_IFELSE(
894[AC_LANG_PROGRAM(
895[[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
896# include <stdlib.h>
897#else
898char *malloc ();
899#endif
900]],
901		 [return ! malloc (0);])],
902	       [ac_cv_func_malloc_0_nonnull=yes],
903	       [ac_cv_func_malloc_0_nonnull=no],
904	       [ac_cv_func_malloc_0_nonnull=no])])
905AS_IF([test $ac_cv_func_malloc_0_nonnull = yes], [$1], [$2])
906])# _AC_FUNC_MALLOC_IF
907
908
909# AC_FUNC_MALLOC
910# --------------
911# Report whether `malloc (0)' properly handled, and replace malloc if
912# needed.
913AN_FUNCTION([malloc], [AC_FUNC_MALLOC])
914AC_DEFUN([AC_FUNC_MALLOC],
915[_AC_FUNC_MALLOC_IF(
916  [AC_DEFINE([HAVE_MALLOC], 1,
917	     [Define to 1 if your system has a GNU libc compatible `malloc'
918	      function, and to 0 otherwise.])],
919  [AC_DEFINE([HAVE_MALLOC], 0)
920   AC_LIBOBJ(malloc)
921   AC_DEFINE([malloc], [rpl_malloc],
922      [Define to rpl_malloc if the replacement function should be used.])])
923])# AC_FUNC_MALLOC
924
925
926# AC_FUNC_MBRTOWC
927# ---------------
928AN_FUNCTION([mbrtowc], [AC_FUNC_MBRTOWC])
929AC_DEFUN([AC_FUNC_MBRTOWC],
930[
931  AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
932    ac_cv_func_mbrtowc,
933    [AC_LINK_IFELSE(
934       [AC_LANG_PROGRAM(
935	    [[@%:@include <wchar.h>]],
936	    [[wchar_t wc;
937	      char const s[] = "";
938	      size_t n = 1;
939	      mbstate_t state;
940	      return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
941       ac_cv_func_mbrtowc=yes,
942       ac_cv_func_mbrtowc=no)])
943  if test $ac_cv_func_mbrtowc = yes; then
944    AC_DEFINE([HAVE_MBRTOWC], 1,
945      [Define to 1 if mbrtowc and mbstate_t are properly declared.])
946  fi
947])
948
949
950# AC_FUNC_MEMCMP
951# --------------
952AC_DEFUN([AC_FUNC_MEMCMP],
953[AC_CACHE_CHECK([for working memcmp], ac_cv_func_memcmp_working,
954[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[
955  /* Some versions of memcmp are not 8-bit clean.  */
956  char c0 = '\100', c1 = '\200', c2 = '\201';
957  if (memcmp(&c0, &c2, 1) >= 0 || memcmp(&c1, &c2, 1) >= 0)
958    return 1;
959
960  /* The Next x86 OpenStep bug shows up only when comparing 16 bytes
961     or more and with at least one buffer not starting on a 4-byte boundary.
962     William Lewis provided this test program.   */
963  {
964    char foo[21];
965    char bar[21];
966    int i;
967    for (i = 0; i < 4; i++)
968      {
969	char *a = foo + i;
970	char *b = bar + i;
971	strcpy (a, "--------01111111");
972	strcpy (b, "--------10000000");
973	if (memcmp (a, b, 16) >= 0)
974	  return 1;
975      }
976    return 0;
977  }
978]])],
979	       [ac_cv_func_memcmp_working=yes],
980	       [ac_cv_func_memcmp_working=no],
981	       [ac_cv_func_memcmp_working=no])])
982test $ac_cv_func_memcmp_working = no && AC_LIBOBJ([memcmp])
983])# AC_FUNC_MEMCMP
984
985
986# AC_FUNC_MKTIME
987# --------------
988AN_FUNCTION([mktime], [AC_FUNC_MKTIME])
989AC_DEFUN([AC_FUNC_MKTIME],
990[AC_REQUIRE([AC_HEADER_TIME])dnl
991AC_CHECK_HEADERS_ONCE(sys/time.h unistd.h)
992AC_CHECK_FUNCS_ONCE(alarm)
993AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
994[AC_RUN_IFELSE([AC_LANG_SOURCE(
995[[/* Test program from Paul Eggert and Tony Leneis.  */
996#ifdef TIME_WITH_SYS_TIME
997# include <sys/time.h>
998# include <time.h>
999#else
1000# ifdef HAVE_SYS_TIME_H
1001#  include <sys/time.h>
1002# else
1003#  include <time.h>
1004# endif
1005#endif
1006
1007#include <limits.h>
1008#include <stdlib.h>
1009
1010#ifdef HAVE_UNISTD_H
1011# include <unistd.h>
1012#endif
1013
1014#ifndef HAVE_ALARM
1015# define alarm(X) /* empty */
1016#endif
1017
1018/* Work around redefinition to rpl_putenv by other config tests.  */
1019#undef putenv
1020
1021static time_t time_t_max;
1022static time_t time_t_min;
1023
1024/* Values we'll use to set the TZ environment variable.  */
1025static const char *tz_strings[] = {
1026  (const char *) 0, "TZ=GMT0", "TZ=JST-9",
1027  "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
1028};
1029#define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
1030
1031/* Return 0 if mktime fails to convert a date in the spring-forward gap.
1032   Based on a problem report from Andreas Jaeger.  */
1033static int
1034spring_forward_gap ()
1035{
1036  /* glibc (up to about 1998-10-07) failed this test. */
1037  struct tm tm;
1038
1039  /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
1040     instead of "TZ=America/Vancouver" in order to detect the bug even
1041     on systems that don't support the Olson extension, or don't have the
1042     full zoneinfo tables installed.  */
1043  putenv ((char*) "TZ=PST8PDT,M4.1.0,M10.5.0");
1044
1045  tm.tm_year = 98;
1046  tm.tm_mon = 3;
1047  tm.tm_mday = 5;
1048  tm.tm_hour = 2;
1049  tm.tm_min = 0;
1050  tm.tm_sec = 0;
1051  tm.tm_isdst = -1;
1052  return mktime (&tm) != (time_t) -1;
1053}
1054
1055static int
1056mktime_test1 (time_t now)
1057{
1058  struct tm *lt;
1059  return ! (lt = localtime (&now)) || mktime (lt) == now;
1060}
1061
1062static int
1063mktime_test (time_t now)
1064{
1065  return (mktime_test1 (now)
1066	  && mktime_test1 ((time_t) (time_t_max - now))
1067	  && mktime_test1 ((time_t) (time_t_min + now)));
1068}
1069
1070static int
1071irix_6_4_bug ()
1072{
1073  /* Based on code from Ariel Faigon.  */
1074  struct tm tm;
1075  tm.tm_year = 96;
1076  tm.tm_mon = 3;
1077  tm.tm_mday = 0;
1078  tm.tm_hour = 0;
1079  tm.tm_min = 0;
1080  tm.tm_sec = 0;
1081  tm.tm_isdst = -1;
1082  mktime (&tm);
1083  return tm.tm_mon == 2 && tm.tm_mday == 31;
1084}
1085
1086static int
1087bigtime_test (int j)
1088{
1089  struct tm tm;
1090  time_t now;
1091  tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
1092  now = mktime (&tm);
1093  if (now != (time_t) -1)
1094    {
1095      struct tm *lt = localtime (&now);
1096      if (! (lt
1097	     && lt->tm_year == tm.tm_year
1098	     && lt->tm_mon == tm.tm_mon
1099	     && lt->tm_mday == tm.tm_mday
1100	     && lt->tm_hour == tm.tm_hour
1101	     && lt->tm_min == tm.tm_min
1102	     && lt->tm_sec == tm.tm_sec
1103	     && lt->tm_yday == tm.tm_yday
1104	     && lt->tm_wday == tm.tm_wday
1105	     && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
1106		  == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
1107	return 0;
1108    }
1109  return 1;
1110}
1111
1112static int
1113year_2050_test ()
1114{
1115  /* The correct answer for 2050-02-01 00:00:00 in Pacific time,
1116     ignoring leap seconds.  */
1117  unsigned long int answer = 2527315200UL;
1118
1119  struct tm tm;
1120  time_t t;
1121  tm.tm_year = 2050 - 1900;
1122  tm.tm_mon = 2 - 1;
1123  tm.tm_mday = 1;
1124  tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
1125  tm.tm_isdst = -1;
1126
1127  /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
1128     instead of "TZ=America/Vancouver" in order to detect the bug even
1129     on systems that don't support the Olson extension, or don't have the
1130     full zoneinfo tables installed.  */
1131  putenv ((char*) "TZ=PST8PDT,M4.1.0,M10.5.0");
1132
1133  t = mktime (&tm);
1134
1135  /* Check that the result is either a failure, or close enough
1136     to the correct answer that we can assume the discrepancy is
1137     due to leap seconds.  */
1138  return (t == (time_t) -1
1139	  || (0 < t && answer - 120 <= t && t <= answer + 120));
1140}
1141
1142int
1143main ()
1144{
1145  time_t t, delta;
1146  int i, j;
1147
1148  /* This test makes some buggy mktime implementations loop.
1149     Give up after 60 seconds; a mktime slower than that
1150     isn't worth using anyway.  */
1151  alarm (60);
1152
1153  for (;;)
1154    {
1155      t = (time_t_max << 1) + 1;
1156      if (t <= time_t_max)
1157	break;
1158      time_t_max = t;
1159    }
1160  time_t_min = - ((time_t) ~ (time_t) 0 == (time_t) -1) - time_t_max;
1161
1162  delta = time_t_max / 997; /* a suitable prime number */
1163  for (i = 0; i < N_STRINGS; i++)
1164    {
1165      if (tz_strings[i])
1166	putenv ((char*) tz_strings[i]);
1167
1168      for (t = 0; t <= time_t_max - delta; t += delta)
1169	if (! mktime_test (t))
1170	  return 1;
1171      if (! (mktime_test ((time_t) 1)
1172	     && mktime_test ((time_t) (60 * 60))
1173	     && mktime_test ((time_t) (60 * 60 * 24))))
1174	return 1;
1175
1176      for (j = 1; ; j <<= 1)
1177	if (! bigtime_test (j))
1178	  return 1;
1179	else if (INT_MAX / 2 < j)
1180	  break;
1181      if (! bigtime_test (INT_MAX))
1182	return 1;
1183    }
1184  return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ());
1185}]])],
1186	       [ac_cv_func_working_mktime=yes],
1187	       [ac_cv_func_working_mktime=no],
1188	       [ac_cv_func_working_mktime=no])])
1189if test $ac_cv_func_working_mktime = no; then
1190  AC_LIBOBJ([mktime])
1191fi
1192])# AC_FUNC_MKTIME
1193
1194
1195# AU::AM_FUNC_MKTIME
1196# ------------------
1197AU_ALIAS([AM_FUNC_MKTIME], [AC_FUNC_MKTIME])
1198
1199
1200# AC_FUNC_MMAP
1201# ------------
1202AN_FUNCTION([mmap], [AC_FUNC_MMAP])
1203AC_DEFUN([AC_FUNC_MMAP],
1204[AC_CHECK_HEADERS_ONCE([stdlib.h unistd.h sys/param.h])
1205AC_CHECK_FUNCS([getpagesize])
1206AC_CACHE_CHECK([for working mmap], [ac_cv_func_mmap_fixed_mapped],
1207[AC_RUN_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT]
1208[[/* malloc might have been renamed as rpl_malloc. */
1209#undef malloc
1210
1211/* Thanks to Mike Haertel and Jim Avera for this test.
1212   Here is a matrix of mmap possibilities:
1213	mmap private not fixed
1214	mmap private fixed at somewhere currently unmapped
1215	mmap private fixed at somewhere already mapped
1216	mmap shared not fixed
1217	mmap shared fixed at somewhere currently unmapped
1218	mmap shared fixed at somewhere already mapped
1219   For private mappings, we should verify that changes cannot be read()
1220   back from the file, nor mmap's back from the file at a different
1221   address.  (There have been systems where private was not correctly
1222   implemented like the infamous i386 svr4.0, and systems where the
1223   VM page cache was not coherent with the file system buffer cache
1224   like early versions of FreeBSD and possibly contemporary NetBSD.)
1225   For shared mappings, we should conversely verify that changes get
1226   propagated back to all the places they're supposed to be.
1227
1228   Grep wants private fixed already mapped.
1229   The main things grep needs to know about mmap are:
1230   * does it exist and is it safe to write into the mmap'd area
1231   * how to use it (BSD variants)  */
1232
1233#include <fcntl.h>
1234#include <sys/mman.h>
1235
1236#if !defined STDC_HEADERS && !defined HAVE_STDLIB_H
1237char *malloc ();
1238#endif
1239
1240/* This mess was copied from the GNU getpagesize.h.  */
1241#ifndef HAVE_GETPAGESIZE
1242# ifdef _SC_PAGESIZE
1243#  define getpagesize() sysconf(_SC_PAGESIZE)
1244# else /* no _SC_PAGESIZE */
1245#  ifdef HAVE_SYS_PARAM_H
1246#   include <sys/param.h>
1247#   ifdef EXEC_PAGESIZE
1248#    define getpagesize() EXEC_PAGESIZE
1249#   else /* no EXEC_PAGESIZE */
1250#    ifdef NBPG
1251#     define getpagesize() NBPG * CLSIZE
1252#     ifndef CLSIZE
1253#      define CLSIZE 1
1254#     endif /* no CLSIZE */
1255#    else /* no NBPG */
1256#     ifdef NBPC
1257#      define getpagesize() NBPC
1258#     else /* no NBPC */
1259#      ifdef PAGESIZE
1260#       define getpagesize() PAGESIZE
1261#      endif /* PAGESIZE */
1262#     endif /* no NBPC */
1263#    endif /* no NBPG */
1264#   endif /* no EXEC_PAGESIZE */
1265#  else /* no HAVE_SYS_PARAM_H */
1266#   define getpagesize() 8192	/* punt totally */
1267#  endif /* no HAVE_SYS_PARAM_H */
1268# endif /* no _SC_PAGESIZE */
1269
1270#endif /* no HAVE_GETPAGESIZE */
1271
1272int
1273main ()
1274{
1275  char *data, *data2, *data3;
1276  const char *cdata2;
1277  int i, pagesize;
1278  int fd, fd2;
1279
1280  pagesize = getpagesize ();
1281
1282  /* First, make a file with some known garbage in it. */
1283  data = (char *) malloc (pagesize);
1284  if (!data)
1285    return 1;
1286  for (i = 0; i < pagesize; ++i)
1287    *(data + i) = rand ();
1288  umask (0);
1289  fd = creat ("conftest.mmap", 0600);
1290  if (fd < 0)
1291    return 2;
1292  if (write (fd, data, pagesize) != pagesize)
1293    return 3;
1294  close (fd);
1295
1296  /* Next, check that the tail of a page is zero-filled.  File must have
1297     non-zero length, otherwise we risk SIGBUS for entire page.  */
1298  fd2 = open ("conftest.txt", O_RDWR | O_CREAT | O_TRUNC, 0600);
1299  if (fd2 < 0)
1300    return 4;
1301  cdata2 = "";
1302  if (write (fd2, cdata2, 1) != 1)
1303    return 5;
1304  data2 = (char *) mmap (0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd2, 0L);
1305  if (data2 == MAP_FAILED)
1306    return 6;
1307  for (i = 0; i < pagesize; ++i)
1308    if (*(data2 + i))
1309      return 7;
1310  close (fd2);
1311  if (munmap (data2, pagesize))
1312    return 8;
1313
1314  /* Next, try to mmap the file at a fixed address which already has
1315     something else allocated at it.  If we can, also make sure that
1316     we see the same garbage.  */
1317  fd = open ("conftest.mmap", O_RDWR);
1318  if (fd < 0)
1319    return 9;
1320  if (data2 != mmap (data2, pagesize, PROT_READ | PROT_WRITE,
1321		     MAP_PRIVATE | MAP_FIXED, fd, 0L))
1322    return 10;
1323  for (i = 0; i < pagesize; ++i)
1324    if (*(data + i) != *(data2 + i))
1325      return 11;
1326
1327  /* Finally, make sure that changes to the mapped area do not
1328     percolate back to the file as seen by read().  (This is a bug on
1329     some variants of i386 svr4.0.)  */
1330  for (i = 0; i < pagesize; ++i)
1331    *(data2 + i) = *(data2 + i) + 1;
1332  data3 = (char *) malloc (pagesize);
1333  if (!data3)
1334    return 12;
1335  if (read (fd, data3, pagesize) != pagesize)
1336    return 13;
1337  for (i = 0; i < pagesize; ++i)
1338    if (*(data + i) != *(data3 + i))
1339      return 14;
1340  close (fd);
1341  return 0;
1342}]])],
1343	       [ac_cv_func_mmap_fixed_mapped=yes],
1344	       [ac_cv_func_mmap_fixed_mapped=no],
1345	       [ac_cv_func_mmap_fixed_mapped=no])])
1346if test $ac_cv_func_mmap_fixed_mapped = yes; then
1347  AC_DEFINE([HAVE_MMAP], [1],
1348	    [Define to 1 if you have a working `mmap' system call.])
1349fi
1350rm -f conftest.mmap conftest.txt
1351])# AC_FUNC_MMAP
1352
1353
1354# AU::AC_MMAP
1355# -----------
1356AU_ALIAS([AC_MMAP], [AC_FUNC_MMAP])
1357
1358
1359# AC_FUNC_OBSTACK
1360# ---------------
1361# Ensure obstack support.  Yeah, this is not exactly a `FUNC' check.
1362AN_FUNCTION([obstack_init], [AC_FUNC_OBSTACK])
1363AN_IDENTIFIER([obstack],    [AC_FUNC_OBSTACK])
1364AC_DEFUN([AC_FUNC_OBSTACK],
1365[AC_LIBSOURCES([obstack.h, obstack.c])dnl
1366AC_CACHE_CHECK([for obstacks], ac_cv_func_obstack,
1367[AC_LINK_IFELSE(
1368    [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
1369		      [@%:@include "obstack.h"]],
1370		     [[struct obstack mem;
1371		       @%:@define obstack_chunk_alloc malloc
1372		       @%:@define obstack_chunk_free free
1373		       obstack_init (&mem);
1374		       obstack_free (&mem, 0);]])],
1375		[ac_cv_func_obstack=yes],
1376		[ac_cv_func_obstack=no])])
1377if test $ac_cv_func_obstack = yes; then
1378  AC_DEFINE(HAVE_OBSTACK, 1, [Define to 1 if libc includes obstacks.])
1379else
1380  AC_LIBOBJ(obstack)
1381fi
1382])# AC_FUNC_OBSTACK
1383
1384
1385# AU::AM_FUNC_OBSTACK
1386# -------------------
1387AU_ALIAS([AM_FUNC_OBSTACK], [AC_FUNC_OBSTACK])
1388
1389
1390
1391# _AC_FUNC_REALLOC_IF(IF-WORKS, IF-NOT)
1392# -------------------------------------
1393# If `realloc (0, 0)' is properly handled, run IF-WORKS, otherwise, IF-NOT.
1394AC_DEFUN([_AC_FUNC_REALLOC_IF],
1395[AC_REQUIRE([AC_HEADER_STDC])dnl
1396AC_CHECK_HEADERS(stdlib.h)
1397AC_CACHE_CHECK([for GNU libc compatible realloc], ac_cv_func_realloc_0_nonnull,
1398[AC_RUN_IFELSE(
1399[AC_LANG_PROGRAM(
1400[[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
1401# include <stdlib.h>
1402#else
1403char *realloc ();
1404#endif
1405]],
1406		 [return ! realloc (0, 0);])],
1407	       [ac_cv_func_realloc_0_nonnull=yes],
1408	       [ac_cv_func_realloc_0_nonnull=no],
1409	       [ac_cv_func_realloc_0_nonnull=no])])
1410AS_IF([test $ac_cv_func_realloc_0_nonnull = yes], [$1], [$2])
1411])# AC_FUNC_REALLOC
1412
1413
1414# AC_FUNC_REALLOC
1415# ---------------
1416# Report whether `realloc (0, 0)' is properly handled, and replace realloc if
1417# needed.
1418AN_FUNCTION([realloc], [AC_FUNC_REALLOC])
1419AC_DEFUN([AC_FUNC_REALLOC],
1420[_AC_FUNC_REALLOC_IF(
1421  [AC_DEFINE([HAVE_REALLOC], 1,
1422	     [Define to 1 if your system has a GNU libc compatible `realloc'
1423	      function, and to 0 otherwise.])],
1424  [AC_DEFINE([HAVE_REALLOC], 0)
1425   AC_LIBOBJ([realloc])
1426   AC_DEFINE([realloc], [rpl_realloc],
1427      [Define to rpl_realloc if the replacement function should be used.])])
1428])# AC_FUNC_REALLOC
1429
1430
1431# AC_FUNC_SELECT_ARGTYPES
1432# -----------------------
1433# Determine the correct type to be passed to each of the `select'
1434# function's arguments, and define those types in `SELECT_TYPE_ARG1',
1435# `SELECT_TYPE_ARG234', and `SELECT_TYPE_ARG5'.
1436AC_DEFUN([AC_FUNC_SELECT_ARGTYPES],
1437[AC_CHECK_HEADERS(sys/select.h sys/socket.h)
1438AC_CACHE_CHECK([types of arguments for select],
1439[ac_cv_func_select_args],
1440[for ac_arg234 in 'fd_set *' 'int *' 'void *'; do
1441 for ac_arg1 in 'int' 'size_t' 'unsigned long int' 'unsigned int'; do
1442  for ac_arg5 in 'struct timeval *' 'const struct timeval *'; do
1443   AC_COMPILE_IFELSE(
1444       [AC_LANG_PROGRAM(
1445[AC_INCLUDES_DEFAULT
1446#ifdef HAVE_SYS_SELECT_H
1447# include <sys/select.h>
1448#endif
1449#ifdef HAVE_SYS_SOCKET_H
1450# include <sys/socket.h>
1451#endif
1452],
1453			[extern int select ($ac_arg1,
1454					    $ac_arg234, $ac_arg234, $ac_arg234,
1455					    $ac_arg5);])],
1456	      [ac_cv_func_select_args="$ac_arg1,$ac_arg234,$ac_arg5"; break 3])
1457  done
1458 done
1459done
1460# Provide a safe default value.
1461: "${ac_cv_func_select_args=int,int *,struct timeval *}"
1462])
1463ac_save_IFS=$IFS; IFS=','
1464set dummy `echo "$ac_cv_func_select_args" | sed 's/\*/\*/g'`
1465IFS=$ac_save_IFS
1466shift
1467AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG1, $[1],
1468		   [Define to the type of arg 1 for `select'.])
1469AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG234, ($[2]),
1470		   [Define to the type of args 2, 3 and 4 for `select'.])
1471AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG5, ($[3]),
1472		   [Define to the type of arg 5 for `select'.])
1473rm -f conftest*
1474])# AC_FUNC_SELECT_ARGTYPES
1475
1476
1477# AC_FUNC_SETPGRP
1478# ---------------
1479AC_DEFUN([AC_FUNC_SETPGRP],
1480[AC_CACHE_CHECK(whether setpgrp takes no argument, ac_cv_func_setpgrp_void,
1481[AC_RUN_IFELSE(
1482[AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1483[/* If this system has a BSD-style setpgrp which takes arguments,
1484  setpgrp(1, 1) will fail with ESRCH and return -1, in that case
1485  exit successfully. */
1486  return setpgrp (1,1) != -1;])],
1487	       [ac_cv_func_setpgrp_void=no],
1488	       [ac_cv_func_setpgrp_void=yes],
1489	       [AC_MSG_ERROR([cannot check setpgrp when cross compiling])])])
1490if test $ac_cv_func_setpgrp_void = yes; then
1491  AC_DEFINE(SETPGRP_VOID, 1,
1492	    [Define to 1 if the `setpgrp' function takes no argument.])
1493fi
1494])# AC_FUNC_SETPGRP
1495
1496
1497# _AC_FUNC_STAT(STAT | LSTAT)
1498# ---------------------------
1499# Determine whether stat or lstat have the bug that it succeeds when
1500# given the zero-length file name argument.  The stat and lstat from
1501# SunOS4.1.4 and the Hurd (as of 1998-11-01) do this.
1502#
1503# If it does, then define HAVE_STAT_EMPTY_STRING_BUG (or
1504# HAVE_LSTAT_EMPTY_STRING_BUG) and arrange to compile the wrapper
1505# function.
1506m4_define([_AC_FUNC_STAT],
1507[AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])dnl
1508AC_CACHE_CHECK([whether $1 accepts an empty string],
1509	       [ac_cv_func_$1_empty_string_bug],
1510[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1511[[struct stat sbuf;
1512  return $1 ("", &sbuf) == 0;]])],
1513	    [ac_cv_func_$1_empty_string_bug=no],
1514	    [ac_cv_func_$1_empty_string_bug=yes],
1515	    [ac_cv_func_$1_empty_string_bug=yes])])
1516if test $ac_cv_func_$1_empty_string_bug = yes; then
1517  AC_LIBOBJ([$1])
1518  AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1_EMPTY_STRING_BUG]), 1,
1519		     [Define to 1 if `$1' has the bug that it succeeds when
1520		      given the zero-length file name argument.])
1521fi
1522])# _AC_FUNC_STAT
1523
1524
1525# AC_FUNC_STAT & AC_FUNC_LSTAT
1526# ----------------------------
1527AC_DEFUN([AC_FUNC_STAT],  [_AC_FUNC_STAT(stat)])
1528AC_DEFUN([AC_FUNC_LSTAT], [_AC_FUNC_STAT(lstat)])
1529
1530
1531# _AC_LIBOBJ_STRTOD
1532# -----------------
1533m4_define([_AC_LIBOBJ_STRTOD],
1534[AC_LIBOBJ(strtod)
1535AC_CHECK_FUNC(pow)
1536if test $ac_cv_func_pow = no; then
1537  AC_CHECK_LIB(m, pow,
1538	       [POW_LIB=-lm],
1539	       [AC_MSG_WARN([cannot find library containing definition of pow])])
1540fi
1541])# _AC_LIBOBJ_STRTOD
1542
1543
1544# AC_FUNC_STRTOD
1545# --------------
1546AN_FUNCTION([strtod], [AC_FUNC_STRTOD])
1547AC_DEFUN([AC_FUNC_STRTOD],
1548[AC_SUBST(POW_LIB)dnl
1549AC_CACHE_CHECK(for working strtod, ac_cv_func_strtod,
1550[AC_RUN_IFELSE([AC_LANG_SOURCE([[
1551]AC_INCLUDES_DEFAULT[
1552#ifndef strtod
1553double strtod ();
1554#endif
1555int
1556main()
1557{
1558  {
1559    /* Some versions of Linux strtod mis-parse strings with leading '+'.  */
1560    char *string = " +69";
1561    char *term;
1562    double value;
1563    value = strtod (string, &term);
1564    if (value != 69 || term != (string + 4))
1565      return 1;
1566  }
1567
1568  {
1569    /* Under Solaris 2.4, strtod returns the wrong value for the
1570       terminating character under some conditions.  */
1571    char *string = "NaN";
1572    char *term;
1573    strtod (string, &term);
1574    if (term != string && *(term - 1) == 0)
1575      return 1;
1576  }
1577  return 0;
1578}
1579]])],
1580	       ac_cv_func_strtod=yes,
1581	       ac_cv_func_strtod=no,
1582	       ac_cv_func_strtod=no)])
1583if test $ac_cv_func_strtod = no; then
1584  _AC_LIBOBJ_STRTOD
1585fi
1586])
1587
1588
1589# AC_FUNC_STRTOLD
1590# ---------------
1591AC_DEFUN([AC_FUNC_STRTOLD],
1592[
1593  AC_CACHE_CHECK([whether strtold conforms to C99],
1594    [ac_cv_func_strtold],
1595    [AC_COMPILE_IFELSE(
1596       [AC_LANG_PROGRAM(
1597	  [[/* On HP-UX before 11.23, strtold returns a struct instead of
1598		long double.  Reject implementations like that, by requiring
1599		compatibility with the C99 prototype.  */
1600#	     include <stdlib.h>
1601	     static long double (*p) (char const *, char **) = strtold;
1602	     static long double
1603	     test (char const *nptr, char **endptr)
1604	     {
1605	       long double r;
1606	       r = strtold (nptr, endptr);
1607	       return r;
1608	     }]],
1609	   [[return test ("1.0", NULL) != 1 || p ("1.0", NULL) != 1;]])],
1610       [ac_cv_func_strtold=yes],
1611       [ac_cv_func_strtold=no])])
1612  if test $ac_cv_func_strtold = yes; then
1613    AC_DEFINE([HAVE_STRTOLD], 1,
1614      [Define to 1 if strtold exists and conforms to C99.])
1615  fi
1616])# AC_FUNC_STRTOLD
1617
1618
1619# AU::AM_FUNC_STRTOD
1620# ------------------
1621AU_ALIAS([AM_FUNC_STRTOD], [AC_FUNC_STRTOD])
1622
1623
1624# AC_FUNC_STRERROR_R
1625# ------------------
1626AN_FUNCTION([strerror_r], [AC_FUNC_STRERROR_R])
1627AC_DEFUN([AC_FUNC_STRERROR_R],
1628[AC_CHECK_DECLS([strerror_r])
1629AC_CHECK_FUNCS([strerror_r])
1630AC_CACHE_CHECK([whether strerror_r returns char *],
1631	       ac_cv_func_strerror_r_char_p,
1632   [
1633    ac_cv_func_strerror_r_char_p=no
1634    if test $ac_cv_have_decl_strerror_r = yes; then
1635      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1636	[[
1637	  char buf[100];
1638	  char x = *strerror_r (0, buf, sizeof buf);
1639	  char *p = strerror_r (0, buf, sizeof buf);
1640	  return !p || x;
1641	]])],
1642			ac_cv_func_strerror_r_char_p=yes)
1643    else
1644      # strerror_r is not declared.  Choose between
1645      # systems that have relatively inaccessible declarations for the
1646      # function.  BeOS and DEC UNIX 4.0 fall in this category, but the
1647      # former has a strerror_r that returns char*, while the latter
1648      # has a strerror_r that returns `int'.
1649      # This test should segfault on the DEC system.
1650      AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
1651	extern char *strerror_r ();],
1652	[[char buf[100];
1653	  char x = *strerror_r (0, buf, sizeof buf);
1654	  return ! isalpha (x);]])],
1655		    ac_cv_func_strerror_r_char_p=yes, , :)
1656    fi
1657  ])
1658if test $ac_cv_func_strerror_r_char_p = yes; then
1659  AC_DEFINE([STRERROR_R_CHAR_P], 1,
1660	    [Define to 1 if strerror_r returns char *.])
1661fi
1662])# AC_FUNC_STRERROR_R
1663
1664
1665# AC_FUNC_STRFTIME
1666# ----------------
1667AC_DEFUN([AC_FUNC_STRFTIME],
1668[AC_CHECK_FUNCS(strftime, [],
1669[# strftime is in -lintl on SCO UNIX.
1670AC_CHECK_LIB(intl, strftime,
1671	     [AC_DEFINE(HAVE_STRFTIME)
1672LIBS="-lintl $LIBS"])])dnl
1673])# AC_FUNC_STRFTIME
1674
1675
1676# AC_FUNC_STRNLEN
1677# ---------------
1678AN_FUNCTION([strnlen], [AC_FUNC_STRNLEN])
1679AC_DEFUN([AC_FUNC_STRNLEN],
1680[AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])dnl
1681AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1682AC_CACHE_CHECK([for working strnlen], ac_cv_func_strnlen_working,
1683[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[
1684#define S "foobar"
1685#define S_LEN (sizeof S - 1)
1686
1687  /* At least one implementation is buggy: that of AIX 4.3 would
1688     give strnlen (S, 1) == 3.  */
1689
1690  int i;
1691  for (i = 0; i < S_LEN + 1; ++i)
1692    {
1693      int expected = i <= S_LEN ? i : S_LEN;
1694      if (strnlen (S, i) != expected)
1695	return 1;
1696    }
1697  return 0;
1698]])],
1699	       [ac_cv_func_strnlen_working=yes],
1700	       [ac_cv_func_strnlen_working=no],
1701	       [# Guess no on AIX systems, yes otherwise.
1702		case "$host_os" in
1703		  aix*) ac_cv_func_strnlen_working=no;;
1704		  *)    ac_cv_func_strnlen_working=yes;;
1705		esac])])
1706test $ac_cv_func_strnlen_working = no && AC_LIBOBJ([strnlen])
1707])# AC_FUNC_STRNLEN
1708
1709
1710# AC_FUNC_SETVBUF_REVERSED
1711# ------------------------
1712AC_DEFUN([AC_FUNC_SETVBUF_REVERSED],
1713[AC_DIAGNOSE([obsolete],
1714[The macro `$0' is obsolete.  Remove it and all references to SETVBUF_REVERSED.])dnl
1715AC_CACHE_VAL([ac_cv_func_setvbuf_reversed], [ac_cv_func_setvbuf_reversed=no])
1716])# AC_FUNC_SETVBUF_REVERSED
1717
1718
1719# AU::AC_SETVBUF_REVERSED
1720# -----------------------
1721AU_ALIAS([AC_SETVBUF_REVERSED], [AC_FUNC_SETVBUF_REVERSED])
1722
1723
1724# AC_FUNC_STRCOLL
1725# ---------------
1726AN_FUNCTION([strcoll], [AC_FUNC_STRCOLL])
1727AC_DEFUN([AC_FUNC_STRCOLL],
1728[AC_CACHE_CHECK(for working strcoll, ac_cv_func_strcoll_works,
1729[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1730  [[return (strcoll ("abc", "def") >= 0 ||
1731	 strcoll ("ABC", "DEF") >= 0 ||
1732	 strcoll ("123", "456") >= 0)]])],
1733	       ac_cv_func_strcoll_works=yes,
1734	       ac_cv_func_strcoll_works=no,
1735	       ac_cv_func_strcoll_works=no)])
1736if test $ac_cv_func_strcoll_works = yes; then
1737  AC_DEFINE(HAVE_STRCOLL, 1,
1738	    [Define to 1 if you have the `strcoll' function and it is properly
1739	     defined.])
1740fi
1741])# AC_FUNC_STRCOLL
1742
1743
1744# AU::AC_STRCOLL
1745# --------------
1746AU_ALIAS([AC_STRCOLL], [AC_FUNC_STRCOLL])
1747
1748
1749# AC_FUNC_UTIME_NULL
1750# ------------------
1751AC_DEFUN([AC_FUNC_UTIME_NULL],
1752[AC_CHECK_HEADERS_ONCE(utime.h)
1753AC_CACHE_CHECK(whether utime accepts a null argument, ac_cv_func_utime_null,
1754[rm -f conftest.data; >conftest.data
1755# Sequent interprets utime(file, 0) to mean use start of epoch.  Wrong.
1756AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
1757	       #ifdef HAVE_UTIME_H
1758	       # include <utime.h>
1759	       #endif],
1760[[struct stat s, t;
1761  return ! (stat ("conftest.data", &s) == 0
1762	    && utime ("conftest.data", 0) == 0
1763	    && stat ("conftest.data", &t) == 0
1764	    && t.st_mtime >= s.st_mtime
1765	    && t.st_mtime - s.st_mtime < 120);]])],
1766	      ac_cv_func_utime_null=yes,
1767	      ac_cv_func_utime_null=no,
1768	      ac_cv_func_utime_null='guessing yes')])
1769if test "x$ac_cv_func_utime_null" != xno; then
1770  ac_cv_func_utime_null=yes
1771  AC_DEFINE(HAVE_UTIME_NULL, 1,
1772	    [Define to 1 if `utime(file, NULL)' sets file's timestamp to the
1773	     present.])
1774fi
1775rm -f conftest.data
1776])# AC_FUNC_UTIME_NULL
1777
1778
1779# AU::AC_UTIME_NULL
1780# -----------------
1781AU_ALIAS([AC_UTIME_NULL], [AC_FUNC_UTIME_NULL])
1782
1783
1784# AC_FUNC_FORK
1785# ------------
1786AN_FUNCTION([fork],  [AC_FUNC_FORK])
1787AN_FUNCTION([vfork], [AC_FUNC_FORK])
1788AC_DEFUN([AC_FUNC_FORK],
1789[AC_REQUIRE([AC_TYPE_PID_T])dnl
1790AC_CHECK_HEADERS(vfork.h)
1791AC_CHECK_FUNCS(fork vfork)
1792if test "x$ac_cv_func_fork" = xyes; then
1793  _AC_FUNC_FORK
1794else
1795  ac_cv_func_fork_works=$ac_cv_func_fork
1796fi
1797if test "x$ac_cv_func_fork_works" = xcross; then
1798  case $host in
1799    *-*-amigaos* | *-*-msdosdjgpp*)
1800      # Override, as these systems have only a dummy fork() stub
1801      ac_cv_func_fork_works=no
1802      ;;
1803    *)
1804      ac_cv_func_fork_works=yes
1805      ;;
1806  esac
1807  AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
1808fi
1809ac_cv_func_vfork_works=$ac_cv_func_vfork
1810if test "x$ac_cv_func_vfork" = xyes; then
1811  _AC_FUNC_VFORK
1812fi;
1813if test "x$ac_cv_func_fork_works" = xcross; then
1814  ac_cv_func_vfork_works=$ac_cv_func_vfork
1815  AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
1816fi
1817
1818if test "x$ac_cv_func_vfork_works" = xyes; then
1819  AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
1820else
1821  AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
1822fi
1823if test "x$ac_cv_func_fork_works" = xyes; then
1824  AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
1825fi
1826])# AC_FUNC_FORK
1827
1828
1829# _AC_FUNC_FORK
1830# -------------
1831AC_DEFUN([_AC_FUNC_FORK],
1832  [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
1833    [AC_RUN_IFELSE(
1834      [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1835	[
1836	  /* By Ruediger Kuhlmann. */
1837	  return fork () < 0;
1838	])],
1839      [ac_cv_func_fork_works=yes],
1840      [ac_cv_func_fork_works=no],
1841      [ac_cv_func_fork_works=cross])])]
1842)# _AC_FUNC_FORK
1843
1844
1845# _AC_FUNC_VFORK
1846# --------------
1847AC_DEFUN([_AC_FUNC_VFORK],
1848[AC_CACHE_CHECK(for working vfork, ac_cv_func_vfork_works,
1849[AC_RUN_IFELSE([AC_LANG_SOURCE([[/* Thanks to Paul Eggert for this test.  */
1850]AC_INCLUDES_DEFAULT[
1851#include <sys/wait.h>
1852#ifdef HAVE_VFORK_H
1853# include <vfork.h>
1854#endif
1855/* On some sparc systems, changes by the child to local and incoming
1856   argument registers are propagated back to the parent.  The compiler
1857   is told about this with #include <vfork.h>, but some compilers
1858   (e.g. gcc -O) don't grok <vfork.h>.  Test for this by using a
1859   static variable whose address is put into a register that is
1860   clobbered by the vfork.  */
1861static void
1862#ifdef __cplusplus
1863sparc_address_test (int arg)
1864# else
1865sparc_address_test (arg) int arg;
1866#endif
1867{
1868  static pid_t child;
1869  if (!child) {
1870    child = vfork ();
1871    if (child < 0) {
1872      perror ("vfork");
1873      _exit(2);
1874    }
1875    if (!child) {
1876      arg = getpid();
1877      write(-1, "", 0);
1878      _exit (arg);
1879    }
1880  }
1881}
1882
1883int
1884main ()
1885{
1886  pid_t parent = getpid ();
1887  pid_t child;
1888
1889  sparc_address_test (0);
1890
1891  child = vfork ();
1892
1893  if (child == 0) {
1894    /* Here is another test for sparc vfork register problems.  This
1895       test uses lots of local variables, at least as many local
1896       variables as main has allocated so far including compiler
1897       temporaries.  4 locals are enough for gcc 1.40.3 on a Solaris
1898       4.1.3 sparc, but we use 8 to be safe.  A buggy compiler should
1899       reuse the register of parent for one of the local variables,
1900       since it will think that parent can't possibly be used any more
1901       in this routine.  Assigning to the local variable will thus
1902       munge parent in the parent process.  */
1903    pid_t
1904      p = getpid(), p1 = getpid(), p2 = getpid(), p3 = getpid(),
1905      p4 = getpid(), p5 = getpid(), p6 = getpid(), p7 = getpid();
1906    /* Convince the compiler that p..p7 are live; otherwise, it might
1907       use the same hardware register for all 8 local variables.  */
1908    if (p != p1 || p != p2 || p != p3 || p != p4
1909	|| p != p5 || p != p6 || p != p7)
1910      _exit(1);
1911
1912    /* On some systems (e.g. IRIX 3.3), vfork doesn't separate parent
1913       from child file descriptors.  If the child closes a descriptor
1914       before it execs or exits, this munges the parent's descriptor
1915       as well.  Test for this by closing stdout in the child.  */
1916    _exit(close(fileno(stdout)) != 0);
1917  } else {
1918    int status;
1919    struct stat st;
1920
1921    while (wait(&status) != child)
1922      ;
1923    return (
1924	 /* Was there some problem with vforking?  */
1925	 child < 0
1926
1927	 /* Did the child fail?  (This shouldn't happen.)  */
1928	 || status
1929
1930	 /* Did the vfork/compiler bug occur?  */
1931	 || parent != getpid()
1932
1933	 /* Did the file descriptor bug occur?  */
1934	 || fstat(fileno(stdout), &st) != 0
1935	 );
1936  }
1937}]])],
1938	    [ac_cv_func_vfork_works=yes],
1939	    [ac_cv_func_vfork_works=no],
1940	    [ac_cv_func_vfork_works=cross])])
1941])# _AC_FUNC_VFORK
1942
1943
1944# AU::AC_FUNC_VFORK
1945# -----------------
1946AU_ALIAS([AC_FUNC_VFORK], [AC_FUNC_FORK])
1947
1948# AU::AC_VFORK
1949# ------------
1950AU_ALIAS([AC_VFORK], [AC_FUNC_FORK])
1951
1952
1953# AC_FUNC_VPRINTF
1954# ---------------
1955# Why the heck is that _doprnt does not define HAVE__DOPRNT???
1956# That the logical name!
1957AC_DEFUN([AC_FUNC_VPRINTF],
1958[AC_CHECK_FUNCS(vprintf, []
1959[AC_CHECK_FUNC(_doprnt,
1960	       [AC_DEFINE(HAVE_DOPRNT, 1,
1961			  [Define to 1 if you don't have `vprintf' but do have
1962			  `_doprnt.'])])])
1963])
1964
1965
1966# AU::AC_VPRINTF
1967# --------------
1968AU_ALIAS([AC_VPRINTF], [AC_FUNC_VPRINTF])
1969
1970
1971# AC_FUNC_WAIT3
1972# -------------
1973# Don't bother too hard maintaining this macro, as it's obsoleted.
1974# We don't AU define it, since we don't have any alternative to propose,
1975# any invocation should be removed, and the code adjusted.
1976AN_FUNCTION([wait3], [AC_FUNC_WAIT3])
1977AC_DEFUN([AC_FUNC_WAIT3],
1978[AC_DIAGNOSE([obsolete],
1979[$0: `wait3' has been removed from POSIX.
1980Remove this `AC_FUNC_WAIT3' and adjust your code to use `waitpid' instead.])dnl
1981AC_CACHE_CHECK([for wait3 that fills in rusage],
1982	       [ac_cv_func_wait3_rusage],
1983[AC_RUN_IFELSE([AC_LANG_SOURCE(
1984[AC_INCLUDES_DEFAULT[
1985#include <sys/time.h>
1986#include <sys/resource.h>
1987#include <sys/wait.h>
1988/* HP-UX has wait3 but does not fill in rusage at all.  */
1989int
1990main ()
1991{
1992  struct rusage r;
1993  int i;
1994  /* Use a field that we can force nonzero --
1995     voluntary context switches.
1996     For systems like NeXT and OSF/1 that don't set it,
1997     also use the system CPU time.  And page faults (I/O) for Linux.  */
1998  r.ru_nvcsw = 0;
1999  r.ru_stime.tv_sec = 0;
2000  r.ru_stime.tv_usec = 0;
2001  r.ru_majflt = r.ru_minflt = 0;
2002  switch (fork ())
2003    {
2004    case 0: /* Child.  */
2005      sleep(1); /* Give up the CPU.  */
2006      _exit(0);
2007      break;
2008    case -1: /* What can we do?  */
2009      _exit(0);
2010      break;
2011    default: /* Parent.  */
2012      wait3(&i, 0, &r);
2013      /* Avoid "text file busy" from rm on fast HP-UX machines.  */
2014      sleep(2);
2015      return (r.ru_nvcsw == 0 && r.ru_majflt == 0 && r.ru_minflt == 0
2016	      && r.ru_stime.tv_sec == 0 && r.ru_stime.tv_usec == 0);
2017    }
2018}]])],
2019	       [ac_cv_func_wait3_rusage=yes],
2020	       [ac_cv_func_wait3_rusage=no],
2021	       [ac_cv_func_wait3_rusage=no])])
2022if test $ac_cv_func_wait3_rusage = yes; then
2023  AC_DEFINE(HAVE_WAIT3, 1,
2024	    [Define to 1 if you have the `wait3' system call.
2025	     Deprecated, you should no longer depend upon `wait3'.])
2026fi
2027])# AC_FUNC_WAIT3
2028
2029
2030# AU::AC_WAIT3
2031# ------------
2032AU_ALIAS([AC_WAIT3], [AC_FUNC_WAIT3])
2033