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