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