maint: update copyright year
[autoconf.git] / lib / autoconf / functions.m4
blob55419681e5c26e26e4c0da5c4d92fba0635c4e2b
1 # This file is part of Autoconf.                        -*- Autoconf -*-
2 # Checking for functions.
3 # Copyright (C) 2000-2011 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])AC_DEFINE(AS_TR_CPP([HAVE_$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 ()
330   static char *addr = 0;
331   auto char dummy;
332   if (addr == 0)
333     {
334       addr = &dummy;
335       return find_stack_direction ();
336     }
337   else
338     return (&dummy > addr) ? 1 : -1;
342 main ()
344   return find_stack_direction () < 0;
345 }])],
346                [ac_cv_c_stack_direction=1],
347                [ac_cv_c_stack_direction=-1],
348                [ac_cv_c_stack_direction=0])])
349 AH_VERBATIM([STACK_DIRECTION],
350 [/* If using the C implementation of alloca, define if you know the
351    direction of stack growth for your system; otherwise it will be
352    automatically deduced at runtime.
353         STACK_DIRECTION > 0 => grows toward higher addresses
354         STACK_DIRECTION < 0 => grows toward lower addresses
355         STACK_DIRECTION = 0 => direction of growth unknown */
356 @%:@undef STACK_DIRECTION])dnl
357 AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
358 ])# _AC_LIBOBJ_ALLOCA
361 # AC_FUNC_ALLOCA
362 # --------------
363 AN_FUNCTION([alloca], [AC_FUNC_ALLOCA])
364 AN_HEADER([alloca.h], [AC_FUNC_ALLOCA])
365 AC_DEFUN([AC_FUNC_ALLOCA],
366 [AC_REQUIRE([AC_TYPE_SIZE_T])]dnl
367 [# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
368 # for constant arguments.  Useless!
369 AC_CACHE_CHECK([for working alloca.h], ac_cv_working_alloca_h,
370 [AC_LINK_IFELSE(
371        [AC_LANG_PROGRAM([[@%:@include <alloca.h>]],
372                         [[char *p = (char *) alloca (2 * sizeof (int));
373                           if (p) return 0;]])],
374                 [ac_cv_working_alloca_h=yes],
375                 [ac_cv_working_alloca_h=no])])
376 if test $ac_cv_working_alloca_h = yes; then
377   AC_DEFINE(HAVE_ALLOCA_H, 1,
378             [Define to 1 if you have <alloca.h> and it should be used
379              (not on Ultrix).])
382 AC_CACHE_CHECK([for alloca], ac_cv_func_alloca_works,
383 [AC_LINK_IFELSE([AC_LANG_PROGRAM(
384 [[#ifdef __GNUC__
385 # define alloca __builtin_alloca
386 #else
387 # ifdef _MSC_VER
388 #  include <malloc.h>
389 #  define alloca _alloca
390 # else
391 #  ifdef HAVE_ALLOCA_H
392 #   include <alloca.h>
393 #  else
394 #   ifdef _AIX
395  #pragma alloca
396 #   else
397 #    ifndef alloca /* predefined by HP cc +Olibcalls */
398 void *alloca (size_t);
399 #    endif
400 #   endif
401 #  endif
402 # endif
403 #endif
404 ]],                               [[char *p = (char *) alloca (1);
405                                     if (p) return 0;]])],
406                 [ac_cv_func_alloca_works=yes],
407                 [ac_cv_func_alloca_works=no])])
409 if test $ac_cv_func_alloca_works = yes; then
410   AC_DEFINE(HAVE_ALLOCA, 1,
411             [Define to 1 if you have `alloca', as a function or macro.])
412 else
413   _AC_LIBOBJ_ALLOCA
415 ])# AC_FUNC_ALLOCA
418 # AU::AC_ALLOCA
419 # -------------
420 AU_ALIAS([AC_ALLOCA], [AC_FUNC_ALLOCA])
423 # AC_FUNC_CHOWN
424 # -------------
425 # Determine whether chown accepts arguments of -1 for uid and gid.
426 AN_FUNCTION([chown], [AC_FUNC_CHOWN])
427 AC_DEFUN([AC_FUNC_CHOWN],
428 [AC_REQUIRE([AC_TYPE_UID_T])dnl
429 AC_CHECK_HEADERS(unistd.h)
430 AC_CACHE_CHECK([for working chown], ac_cv_func_chown_works,
431 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
432 #include <fcntl.h>
434 [[  char *f = "conftest.chown";
435   struct stat before, after;
437   if (creat (f, 0600) < 0)
438     return 1;
439   if (stat (f, &before) < 0)
440     return 1;
441   if (chown (f, (uid_t) -1, (gid_t) -1) == -1)
442     return 1;
443   if (stat (f, &after) < 0)
444     return 1;
445   return ! (before.st_uid == after.st_uid && before.st_gid == after.st_gid);
446 ]])],
447                [ac_cv_func_chown_works=yes],
448                [ac_cv_func_chown_works=no],
449                [ac_cv_func_chown_works=no])
450 rm -f conftest.chown
452 if test $ac_cv_func_chown_works = yes; then
453   AC_DEFINE(HAVE_CHOWN, 1,
454             [Define to 1 if your system has a working `chown' function.])
456 ])# AC_FUNC_CHOWN
459 # AC_FUNC_CLOSEDIR_VOID
460 # ---------------------
461 # Check whether closedir returns void, and #define CLOSEDIR_VOID in
462 # that case.
463 AC_DEFUN([AC_FUNC_CLOSEDIR_VOID],
464 [AC_REQUIRE([AC_HEADER_DIRENT])dnl
465 AC_CACHE_CHECK([whether closedir returns void],
466                [ac_cv_func_closedir_void],
467 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
468 #include <$ac_header_dirent>
469 #ifndef __cplusplus
470 int closedir ();
471 #endif
473                                 [[return closedir (opendir (".")) != 0;]])],
474                [ac_cv_func_closedir_void=no],
475                [ac_cv_func_closedir_void=yes],
476                [ac_cv_func_closedir_void=yes])])
477 if test $ac_cv_func_closedir_void = yes; then
478   AC_DEFINE(CLOSEDIR_VOID, 1,
479             [Define to 1 if the `closedir' function returns void instead
480              of `int'.])
485 # AC_FUNC_ERROR_AT_LINE
486 # ---------------------
487 AN_FUNCTION([error],         [AC_FUNC_ERROR_AT_LINE])
488 AN_FUNCTION([error_at_line], [AC_FUNC_ERROR_AT_LINE])
489 AC_DEFUN([AC_FUNC_ERROR_AT_LINE],
490 [AC_LIBSOURCES([error.h, error.c])dnl
491 AC_CACHE_CHECK([for error_at_line], ac_cv_lib_error_at_line,
492 [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <error.h>],
493                                  [error_at_line (0, 0, "", 0, "an error occurred");])],
494                 [ac_cv_lib_error_at_line=yes],
495                 [ac_cv_lib_error_at_line=no])])
496 if test $ac_cv_lib_error_at_line = no; then
497   AC_LIBOBJ(error)
502 # AU::AM_FUNC_ERROR_AT_LINE
503 # -------------------------
504 AU_ALIAS([AM_FUNC_ERROR_AT_LINE], [AC_FUNC_ERROR_AT_LINE])
507 # _AC_FUNC_FNMATCH_IF(STANDARD = GNU | POSIX, CACHE_VAR, IF-TRUE, IF-FALSE)
508 # -------------------------------------------------------------------------
509 # If a STANDARD compliant fnmatch is found, run IF-TRUE, otherwise
510 # IF-FALSE.  Use CACHE_VAR.
511 AC_DEFUN([_AC_FUNC_FNMATCH_IF],
512 [AC_CACHE_CHECK(
513    [for working $1 fnmatch],
514    [$2],
515   [# Some versions of Solaris, SCO, and the GNU C Library
516    # have a broken or incompatible fnmatch.
517    # So we run a test program.  If we are cross-compiling, take no chance.
518    # Thanks to John Oleynick, Franc,ois Pinard, and Paul Eggert for this test.
519    AC_RUN_IFELSE(
520       [AC_LANG_PROGRAM(
521          [#include <fnmatch.h>
522 #          define y(a, b, c) (fnmatch (a, b, c) == 0)
523 #          define n(a, b, c) (fnmatch (a, b, c) == FNM_NOMATCH)
524          ],
525          [return
526            (!(y ("a*", "abc", 0)
527               && n ("d*/*1", "d/s/1", FNM_PATHNAME)
528               && y ("a\\\\bc", "abc", 0)
529               && n ("a\\\\bc", "abc", FNM_NOESCAPE)
530               && y ("*x", ".x", 0)
531               && n ("*x", ".x", FNM_PERIOD)
532               && m4_if([$1], [GNU],
533                    [y ("xxXX", "xXxX", FNM_CASEFOLD)
534                     && y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)
535                     && n ("d*/*1", "d/s/1", FNM_FILE_NAME)
536                     && y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)
537                     && y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)
538                     && y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)],
539                    1)));])],
540       [$2=yes],
541       [$2=no],
542       [$2=cross])])
543 AS_IF([test $$2 = yes], [$3], [$4])
544 ])# _AC_FUNC_FNMATCH_IF
547 # AC_FUNC_FNMATCH
548 # ---------------
549 AC_DEFUN([AC_FUNC_FNMATCH],
550 [_AC_FUNC_FNMATCH_IF([POSIX], [ac_cv_func_fnmatch_works],
551                      [AC_DEFINE([HAVE_FNMATCH], 1,
552                      [Define to 1 if your system has a working POSIX `fnmatch'
553                       function.])])
554 ])# AC_FUNC_FNMATCH
557 # _AC_LIBOBJ_FNMATCH
558 # ------------------
559 # Prepare the replacement of fnmatch.
560 AC_DEFUN([_AC_LIBOBJ_FNMATCH],
561 [AC_REQUIRE([AC_C_CONST])dnl
562 AC_REQUIRE([AC_FUNC_ALLOCA])dnl
563 AC_REQUIRE([AC_TYPE_MBSTATE_T])dnl
564 AC_CHECK_DECLS([getenv])
565 AC_CHECK_FUNCS([btowc mbsrtowcs mempcpy wmempcpy])
566 AC_CHECK_HEADERS([wchar.h wctype.h])
567 AC_LIBOBJ([fnmatch])
568 AC_CONFIG_LINKS([$ac_config_libobj_dir/fnmatch.h:$ac_config_libobj_dir/fnmatch_.h])
569 AC_DEFINE(fnmatch, rpl_fnmatch,
570           [Define to rpl_fnmatch if the replacement function should be used.])
571 ])# _AC_LIBOBJ_FNMATCH
574 # AC_REPLACE_FNMATCH
575 # ------------------
576 AC_DEFUN([AC_REPLACE_FNMATCH],
577 [_AC_FUNC_FNMATCH_IF([POSIX], [ac_cv_func_fnmatch_works],
578                      [rm -f "$ac_config_libobj_dir/fnmatch.h"],
579                      [_AC_LIBOBJ_FNMATCH])
580 ])# AC_REPLACE_FNMATCH
583 # AC_FUNC_FNMATCH_GNU
584 # -------------------
585 AC_DEFUN([AC_FUNC_FNMATCH_GNU],
586 [AC_REQUIRE([AC_GNU_SOURCE])
587 _AC_FUNC_FNMATCH_IF([GNU], [ac_cv_func_fnmatch_gnu],
588                     [rm -f "$ac_config_libobj_dir/fnmatch.h"],
589                     [_AC_LIBOBJ_FNMATCH])
590 ])# AC_FUNC_FNMATCH_GNU
593 # AU::AM_FUNC_FNMATCH
594 # AU::fp_FUNC_FNMATCH
595 # -------------------
596 AU_ALIAS([AM_FUNC_FNMATCH], [AC_FUNC_FNMATCH])
597 AU_ALIAS([fp_FUNC_FNMATCH], [AC_FUNC_FNMATCH])
600 # AC_FUNC_FSEEKO
601 # --------------
602 AN_FUNCTION([ftello], [AC_FUNC_FSEEKO])
603 AN_FUNCTION([fseeko], [AC_FUNC_FSEEKO])
604 AC_DEFUN([AC_FUNC_FSEEKO],
605 [_AC_SYS_LARGEFILE_MACRO_VALUE(_LARGEFILE_SOURCE, 1,
606    [ac_cv_sys_largefile_source],
607    [Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2).],
608    [[#include <sys/types.h> /* for off_t */
609      #include <stdio.h>]],
610    [[int (*fp) (FILE *, off_t, int) = fseeko;
611      return fseeko (stdin, 0, 0) && fp (stdin, 0, 0);]])
613 # We used to try defining _XOPEN_SOURCE=500 too, to work around a bug
614 # in glibc 2.1.3, but that breaks too many other things.
615 # If you want fseeko and ftello with glibc, upgrade to a fixed glibc.
616 if test $ac_cv_sys_largefile_source != unknown; then
617   AC_DEFINE(HAVE_FSEEKO, 1,
618     [Define to 1 if fseeko (and presumably ftello) exists and is declared.])
620 ])# AC_FUNC_FSEEKO
623 # AC_FUNC_GETGROUPS
624 # -----------------
625 # Try to find `getgroups', and check that it works.
626 # When cross-compiling, assume getgroups is broken.
627 AN_FUNCTION([getgroups], [AC_FUNC_GETGROUPS])
628 AC_DEFUN([AC_FUNC_GETGROUPS],
629 [AC_REQUIRE([AC_TYPE_GETGROUPS])dnl
630 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
631 AC_CHECK_FUNC(getgroups)
633 # If we don't yet have getgroups, see if it's in -lbsd.
634 # This is reported to be necessary on an ITOS 3000WS running SEIUX 3.1.
635 ac_save_LIBS=$LIBS
636 if test $ac_cv_func_getgroups = no; then
637   AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd])
640 # Run the program to test the functionality of the system-supplied
641 # getgroups function only if there is such a function.
642 if test $ac_cv_func_getgroups = yes; then
643   AC_CACHE_CHECK([for working getgroups], ac_cv_func_getgroups_works,
644    [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
645       [[/* On Ultrix 4.3, getgroups (0, 0) always fails.  */
646        return getgroups (0, 0) == -1;]])],
647                   [ac_cv_func_getgroups_works=yes],
648                   [ac_cv_func_getgroups_works=no],
649                   [ac_cv_func_getgroups_works=no])
650    ])
651 else
652   ac_cv_func_getgroups_works=no
654 if test $ac_cv_func_getgroups_works = yes; then
655   AC_DEFINE(HAVE_GETGROUPS, 1,
656             [Define to 1 if your system has a working `getgroups' function.])
658 LIBS=$ac_save_LIBS
659 ])# AC_FUNC_GETGROUPS
662 # _AC_LIBOBJ_GETLOADAVG
663 # ---------------------
664 # Set up the AC_LIBOBJ replacement of `getloadavg'.
665 m4_define([_AC_LIBOBJ_GETLOADAVG],
666 [AC_LIBOBJ(getloadavg)
667 AC_DEFINE(C_GETLOADAVG, 1, [Define to 1 if using `getloadavg.c'.])
668 # Figure out what our getloadavg.c needs.
669 ac_have_func=no
670 AC_CHECK_HEADER(sys/dg_sys_info.h,
671 [ac_have_func=yes
672  AC_DEFINE(DGUX, 1, [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
673  AC_CHECK_LIB(dgc, dg_sys_info)])
675 AC_CHECK_HEADER(locale.h)
676 AC_CHECK_FUNCS(setlocale)
678 # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
679 # uses stabs), but it is still SVR4.  We cannot check for <elf.h> because
680 # Irix 4.0.5F has the header but not the library.
681 if test $ac_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes \
682     && test "$ac_cv_lib_kvm_kvm_open" = yes; then
683   ac_have_func=yes
684   AC_DEFINE(SVR4, 1, [Define to 1 on System V Release 4.])
687 if test $ac_have_func = no; then
688   AC_CHECK_HEADER(inq_stats/cpustats.h,
689   [ac_have_func=yes
690    AC_DEFINE(UMAX, 1, [Define to 1 for Encore UMAX.])
691    AC_DEFINE(UMAX4_3, 1,
692              [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
693               instead of <sys/cpustats.h>.])])
696 if test $ac_have_func = no; then
697   AC_CHECK_HEADER(sys/cpustats.h,
698   [ac_have_func=yes; AC_DEFINE(UMAX)])
701 if test $ac_have_func = no; then
702   AC_CHECK_HEADERS(mach/mach.h)
705 AC_CHECK_HEADERS(nlist.h,
706 [AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
707                   [AC_DEFINE(NLIST_NAME_UNION, 1,
708                              [Define to 1 if your `struct nlist' has an
709                               `n_un' member.  Obsolete, depend on
710                               `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [],
711                   [@%:@include <nlist.h>])
712 ])dnl
713 ])# _AC_LIBOBJ_GETLOADAVG
716 # AC_FUNC_GETLOADAVG
717 # ------------------
718 AC_DEFUN([AC_FUNC_GETLOADAVG],
719 [ac_have_func=no # yes means we've found a way to get the load average.
721 # Make sure getloadavg.c is where it belongs, at configure-time.
722 test -f "$srcdir/$ac_config_libobj_dir/getloadavg.c" ||
723   AC_MSG_ERROR([$srcdir/$ac_config_libobj_dir/getloadavg.c is missing])
725 ac_save_LIBS=$LIBS
727 # Check for getloadavg, but be sure not to touch the cache variable.
728 (AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && ac_have_func=yes
730 # On HPUX9, an unprivileged user can get load averages through this function.
731 AC_CHECK_FUNCS(pstat_getdynamic)
733 # Solaris has libkstat which does not require root.
734 AC_CHECK_LIB(kstat, kstat_open)
735 test $ac_cv_lib_kstat_kstat_open = yes && ac_have_func=yes
737 # Some systems with -lutil have (and need) -lkvm as well, some do not.
738 # On Solaris, -lkvm requires nlist from -lelf, so check that first
739 # to get the right answer into the cache.
740 # For kstat on solaris, we need libelf to force the definition of SVR4 below.
741 if test $ac_have_func = no; then
742   AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
744 if test $ac_have_func = no; then
745   AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
746   # Check for the 4.4BSD definition of getloadavg.
747   AC_CHECK_LIB(util, getloadavg,
748     [LIBS="-lutil $LIBS" ac_have_func=yes ac_cv_func_getloadavg_setgid=yes])
751 if test $ac_have_func = no; then
752   # There is a commonly available library for RS/6000 AIX.
753   # Since it is not a standard part of AIX, it might be installed locally.
754   ac_getloadavg_LIBS=$LIBS
755   LIBS="-L/usr/local/lib $LIBS"
756   AC_CHECK_LIB(getloadavg, getloadavg,
757                [LIBS="-lgetloadavg $LIBS"], [LIBS=$ac_getloadavg_LIBS])
760 # Make sure it is really in the library, if we think we found it,
761 # otherwise set up the replacement function.
762 AC_CHECK_FUNCS(getloadavg, [],
763                [_AC_LIBOBJ_GETLOADAVG])
765 # Some definitions of getloadavg require that the program be installed setgid.
766 AC_CACHE_CHECK(whether getloadavg requires setgid,
767                ac_cv_func_getloadavg_setgid,
768 [AC_EGREP_CPP([Yowza Am I SETGID yet],
769 [#include "$srcdir/$ac_config_libobj_dir/getloadavg.c"
770 #ifdef LDAV_PRIVILEGED
771 Yowza Am I SETGID yet
772 @%:@endif],
773               ac_cv_func_getloadavg_setgid=yes,
774               ac_cv_func_getloadavg_setgid=no)])
775 if test $ac_cv_func_getloadavg_setgid = yes; then
776   NEED_SETGID=true
777   AC_DEFINE(GETLOADAVG_PRIVILEGED, 1,
778             [Define to 1 if the `getloadavg' function needs to be run setuid
779              or setgid.])
780 else
781   NEED_SETGID=false
783 AC_SUBST(NEED_SETGID)dnl
785 if test $ac_cv_func_getloadavg_setgid = yes; then
786   AC_CACHE_CHECK(group of /dev/kmem, ac_cv_group_kmem,
787 [ # On Solaris, /dev/kmem is a symlink.  Get info on the real file.
788   ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
789   # If we got an error (system does not support symlinks), try without -L.
790   test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
791   ac_cv_group_kmem=`AS_ECHO(["$ac_ls_output"]) \
792     | sed -ne ['s/[      ][      ]*/ /g;
793                s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\)  *.*/\1/;
794                / /s/.* //;p;']`
796   AC_SUBST(KMEM_GROUP, $ac_cv_group_kmem)dnl
798 if test "x$ac_save_LIBS" = x; then
799   GETLOADAVG_LIBS=$LIBS
800 else
801   GETLOADAVG_LIBS=`AS_ECHO(["$LIBS"]) | sed "s|$ac_save_LIBS||"`
803 LIBS=$ac_save_LIBS
805 AC_SUBST(GETLOADAVG_LIBS)dnl
806 ])# AC_FUNC_GETLOADAVG
809 # AU::AC_GETLOADAVG
810 # -----------------
811 AU_ALIAS([AC_GETLOADAVG], [AC_FUNC_GETLOADAVG])
814 # AC_FUNC_GETMNTENT
815 # -----------------
816 AN_FUNCTION([getmntent], [AC_FUNC_GETMNTENT])
817 AC_DEFUN([AC_FUNC_GETMNTENT],
818 [# getmntent is in the standard C library on UNICOS, in -lsun on Irix 4,
819 # -lseq on Dynix/PTX, -lgen on Unixware.
820 AC_SEARCH_LIBS(getmntent, [sun seq gen],
821                [ac_cv_func_getmntent=yes
822                 AC_DEFINE([HAVE_GETMNTENT], 1,
823                           [Define to 1 if you have the `getmntent' function.])],
824                [ac_cv_func_getmntent=no])
828 # AC_FUNC_GETPGRP
829 # ---------------
830 # Figure out whether getpgrp requires zero arguments.
831 AC_DEFUN([AC_FUNC_GETPGRP],
832 [AC_CACHE_CHECK(whether getpgrp requires zero arguments,
833  ac_cv_func_getpgrp_void,
834 [# Use it with a single arg.
835 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [getpgrp (0);])],
836                   [ac_cv_func_getpgrp_void=no],
837                   [ac_cv_func_getpgrp_void=yes])
839 if test $ac_cv_func_getpgrp_void = yes; then
840   AC_DEFINE(GETPGRP_VOID, 1,
841             [Define to 1 if the `getpgrp' function requires zero arguments.])
843 ])# AC_FUNC_GETPGRP
846 # AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
847 # -------------------------------------
848 # When cross-compiling, be pessimistic so we will end up using the
849 # replacement version of lstat that checks for trailing slashes and
850 # calls lstat a second time when necessary.
851 AN_FUNCTION([lstat], [AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
852 AC_DEFUN([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
853 [AC_CACHE_CHECK(
854        [whether lstat correctly handles trailing slash],
855        [ac_cv_func_lstat_dereferences_slashed_symlink],
856 [rm -f conftest.sym conftest.file
857 echo >conftest.file
858 if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then
859   AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
860     [struct stat sbuf;
861      /* Linux will dereference the symlink and fail, as required by POSIX.
862         That is better in the sense that it means we will not
863         have to compile and use the lstat wrapper.  */
864      return lstat ("conftest.sym/", &sbuf) == 0;])],
865                 [ac_cv_func_lstat_dereferences_slashed_symlink=yes],
866                 [ac_cv_func_lstat_dereferences_slashed_symlink=no],
867                 [ac_cv_func_lstat_dereferences_slashed_symlink=no])
868 else
869   # If the `ln -s' command failed, then we probably don't even
870   # have an lstat function.
871   ac_cv_func_lstat_dereferences_slashed_symlink=no
873 rm -f conftest.sym conftest.file
876 test $ac_cv_func_lstat_dereferences_slashed_symlink = yes &&
877   AC_DEFINE_UNQUOTED([LSTAT_FOLLOWS_SLASHED_SYMLINK], [1],
878                      [Define to 1 if `lstat' dereferences a symlink specified
879                       with a trailing slash.])
881 if test "x$ac_cv_func_lstat_dereferences_slashed_symlink" = xno; then
882   AC_LIBOBJ([lstat])
887 # _AC_FUNC_MALLOC_IF(IF-WORKS, IF-NOT)
888 # ------------------------------------
889 # If `malloc (0)' properly handled, run IF-WORKS, otherwise, IF-NOT.
890 AC_DEFUN([_AC_FUNC_MALLOC_IF],
891 [AC_REQUIRE([AC_HEADER_STDC])dnl
892 AC_CHECK_HEADERS(stdlib.h)
893 AC_CACHE_CHECK([for GNU libc compatible malloc], ac_cv_func_malloc_0_nonnull,
894 [AC_RUN_IFELSE(
895 [AC_LANG_PROGRAM(
896 [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
897 # include <stdlib.h>
898 #else
899 char *malloc ();
900 #endif
902                  [return ! malloc (0);])],
903                [ac_cv_func_malloc_0_nonnull=yes],
904                [ac_cv_func_malloc_0_nonnull=no],
905                [ac_cv_func_malloc_0_nonnull=no])])
906 AS_IF([test $ac_cv_func_malloc_0_nonnull = yes], [$1], [$2])
907 ])# _AC_FUNC_MALLOC_IF
910 # AC_FUNC_MALLOC
911 # --------------
912 # Report whether `malloc (0)' properly handled, and replace malloc if
913 # needed.
914 AN_FUNCTION([malloc], [AC_FUNC_MALLOC])
915 AC_DEFUN([AC_FUNC_MALLOC],
916 [_AC_FUNC_MALLOC_IF(
917   [AC_DEFINE([HAVE_MALLOC], 1,
918              [Define to 1 if your system has a GNU libc compatible `malloc'
919               function, and to 0 otherwise.])],
920   [AC_DEFINE([HAVE_MALLOC], 0)
921    AC_LIBOBJ(malloc)
922    AC_DEFINE([malloc], [rpl_malloc],
923       [Define to rpl_malloc if the replacement function should be used.])])
924 ])# AC_FUNC_MALLOC
927 # AC_FUNC_MBRTOWC
928 # ---------------
929 AN_FUNCTION([mbrtowc], [AC_FUNC_MBRTOWC])
930 AC_DEFUN([AC_FUNC_MBRTOWC],
932   AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
933     ac_cv_func_mbrtowc,
934     [AC_LINK_IFELSE(
935        [AC_LANG_PROGRAM(
936             [[@%:@include <wchar.h>]],
937             [[wchar_t wc;
938               char const s[] = "";
939               size_t n = 1;
940               mbstate_t state;
941               return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
942        ac_cv_func_mbrtowc=yes,
943        ac_cv_func_mbrtowc=no)])
944   if test $ac_cv_func_mbrtowc = yes; then
945     AC_DEFINE([HAVE_MBRTOWC], 1,
946       [Define to 1 if mbrtowc and mbstate_t are properly declared.])
947   fi
951 # AC_FUNC_MEMCMP
952 # --------------
953 AC_DEFUN([AC_FUNC_MEMCMP],
954 [AC_CACHE_CHECK([for working memcmp], ac_cv_func_memcmp_working,
955 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[
956   /* Some versions of memcmp are not 8-bit clean.  */
957   char c0 = '\100', c1 = '\200', c2 = '\201';
958   if (memcmp(&c0, &c2, 1) >= 0 || memcmp(&c1, &c2, 1) >= 0)
959     return 1;
961   /* The Next x86 OpenStep bug shows up only when comparing 16 bytes
962      or more and with at least one buffer not starting on a 4-byte boundary.
963      William Lewis provided this test program.   */
964   {
965     char foo[21];
966     char bar[21];
967     int i;
968     for (i = 0; i < 4; i++)
969       {
970         char *a = foo + i;
971         char *b = bar + i;
972         strcpy (a, "--------01111111");
973         strcpy (b, "--------10000000");
974         if (memcmp (a, b, 16) >= 0)
975           return 1;
976       }
977     return 0;
978   }
979 ]])],
980                [ac_cv_func_memcmp_working=yes],
981                [ac_cv_func_memcmp_working=no],
982                [ac_cv_func_memcmp_working=no])])
983 test $ac_cv_func_memcmp_working = no && AC_LIBOBJ([memcmp])
984 ])# AC_FUNC_MEMCMP
987 # AC_FUNC_MKTIME
988 # --------------
989 AN_FUNCTION([mktime], [AC_FUNC_MKTIME])
990 AC_DEFUN([AC_FUNC_MKTIME],
991 [AC_REQUIRE([AC_HEADER_TIME])dnl
992 AC_CHECK_HEADERS_ONCE(sys/time.h unistd.h)
993 AC_CHECK_FUNCS_ONCE(alarm)
994 AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
995 [AC_RUN_IFELSE([AC_LANG_SOURCE(
996 [[/* Test program from Paul Eggert and Tony Leneis.  */
997 #ifdef TIME_WITH_SYS_TIME
998 # include <sys/time.h>
999 # include <time.h>
1000 #else
1001 # ifdef HAVE_SYS_TIME_H
1002 #  include <sys/time.h>
1003 # else
1004 #  include <time.h>
1005 # endif
1006 #endif
1008 #include <limits.h>
1009 #include <stdlib.h>
1011 #ifdef HAVE_UNISTD_H
1012 # include <unistd.h>
1013 #endif
1015 #ifndef HAVE_ALARM
1016 # define alarm(X) /* empty */
1017 #endif
1019 /* Work around redefinition to rpl_putenv by other config tests.  */
1020 #undef putenv
1022 static time_t time_t_max;
1023 static time_t time_t_min;
1025 /* Values we'll use to set the TZ environment variable.  */
1026 static const char *tz_strings[] = {
1027   (const char *) 0, "TZ=GMT0", "TZ=JST-9",
1028   "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
1030 #define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
1032 /* Return 0 if mktime fails to convert a date in the spring-forward gap.
1033    Based on a problem report from Andreas Jaeger.  */
1034 static int
1035 spring_forward_gap ()
1037   /* glibc (up to about 1998-10-07) failed this test. */
1038   struct tm tm;
1040   /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
1041      instead of "TZ=America/Vancouver" in order to detect the bug even
1042      on systems that don't support the Olson extension, or don't have the
1043      full zoneinfo tables installed.  */
1044   putenv ((char*) "TZ=PST8PDT,M4.1.0,M10.5.0");
1046   tm.tm_year = 98;
1047   tm.tm_mon = 3;
1048   tm.tm_mday = 5;
1049   tm.tm_hour = 2;
1050   tm.tm_min = 0;
1051   tm.tm_sec = 0;
1052   tm.tm_isdst = -1;
1053   return mktime (&tm) != (time_t) -1;
1056 static int
1057 mktime_test1 (time_t now)
1059   struct tm *lt;
1060   return ! (lt = localtime (&now)) || mktime (lt) == now;
1063 static int
1064 mktime_test (time_t now)
1066   return (mktime_test1 (now)
1067           && mktime_test1 ((time_t) (time_t_max - now))
1068           && mktime_test1 ((time_t) (time_t_min + now)));
1071 static int
1072 irix_6_4_bug ()
1074   /* Based on code from Ariel Faigon.  */
1075   struct tm tm;
1076   tm.tm_year = 96;
1077   tm.tm_mon = 3;
1078   tm.tm_mday = 0;
1079   tm.tm_hour = 0;
1080   tm.tm_min = 0;
1081   tm.tm_sec = 0;
1082   tm.tm_isdst = -1;
1083   mktime (&tm);
1084   return tm.tm_mon == 2 && tm.tm_mday == 31;
1087 static int
1088 bigtime_test (int j)
1090   struct tm tm;
1091   time_t now;
1092   tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
1093   now = mktime (&tm);
1094   if (now != (time_t) -1)
1095     {
1096       struct tm *lt = localtime (&now);
1097       if (! (lt
1098              && lt->tm_year == tm.tm_year
1099              && lt->tm_mon == tm.tm_mon
1100              && lt->tm_mday == tm.tm_mday
1101              && lt->tm_hour == tm.tm_hour
1102              && lt->tm_min == tm.tm_min
1103              && lt->tm_sec == tm.tm_sec
1104              && lt->tm_yday == tm.tm_yday
1105              && lt->tm_wday == tm.tm_wday
1106              && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
1107                   == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
1108         return 0;
1109     }
1110   return 1;
1113 static int
1114 year_2050_test ()
1116   /* The correct answer for 2050-02-01 00:00:00 in Pacific time,
1117      ignoring leap seconds.  */
1118   unsigned long int answer = 2527315200UL;
1120   struct tm tm;
1121   time_t t;
1122   tm.tm_year = 2050 - 1900;
1123   tm.tm_mon = 2 - 1;
1124   tm.tm_mday = 1;
1125   tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
1126   tm.tm_isdst = -1;
1128   /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
1129      instead of "TZ=America/Vancouver" in order to detect the bug even
1130      on systems that don't support the Olson extension, or don't have the
1131      full zoneinfo tables installed.  */
1132   putenv ((char*) "TZ=PST8PDT,M4.1.0,M10.5.0");
1134   t = mktime (&tm);
1136   /* Check that the result is either a failure, or close enough
1137      to the correct answer that we can assume the discrepancy is
1138      due to leap seconds.  */
1139   return (t == (time_t) -1
1140           || (0 < t && answer - 120 <= t && t <= answer + 120));
1144 main ()
1146   time_t t, delta;
1147   int i, j;
1149   /* This test makes some buggy mktime implementations loop.
1150      Give up after 60 seconds; a mktime slower than that
1151      isn't worth using anyway.  */
1152   alarm (60);
1154   for (;;)
1155     {
1156       t = (time_t_max << 1) + 1;
1157       if (t <= time_t_max)
1158         break;
1159       time_t_max = t;
1160     }
1161   time_t_min = - ((time_t) ~ (time_t) 0 == (time_t) -1) - time_t_max;
1163   delta = time_t_max / 997; /* a suitable prime number */
1164   for (i = 0; i < N_STRINGS; i++)
1165     {
1166       if (tz_strings[i])
1167         putenv ((char*) tz_strings[i]);
1169       for (t = 0; t <= time_t_max - delta; t += delta)
1170         if (! mktime_test (t))
1171           return 1;
1172       if (! (mktime_test ((time_t) 1)
1173              && mktime_test ((time_t) (60 * 60))
1174              && mktime_test ((time_t) (60 * 60 * 24))))
1175         return 1;
1177       for (j = 1; ; j <<= 1)
1178         if (! bigtime_test (j))
1179           return 1;
1180         else if (INT_MAX / 2 < j)
1181           break;
1182       if (! bigtime_test (INT_MAX))
1183         return 1;
1184     }
1185   return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ());
1186 }]])],
1187                [ac_cv_func_working_mktime=yes],
1188                [ac_cv_func_working_mktime=no],
1189                [ac_cv_func_working_mktime=no])])
1190 if test $ac_cv_func_working_mktime = no; then
1191   AC_LIBOBJ([mktime])
1193 ])# AC_FUNC_MKTIME
1196 # AU::AM_FUNC_MKTIME
1197 # ------------------
1198 AU_ALIAS([AM_FUNC_MKTIME], [AC_FUNC_MKTIME])
1201 # AC_FUNC_MMAP
1202 # ------------
1203 AN_FUNCTION([mmap], [AC_FUNC_MMAP])
1204 AC_DEFUN([AC_FUNC_MMAP],
1205 [AC_CHECK_HEADERS_ONCE([stdlib.h unistd.h sys/param.h])
1206 AC_CHECK_FUNCS([getpagesize])
1207 AC_CACHE_CHECK([for working mmap], [ac_cv_func_mmap_fixed_mapped],
1208 [AC_RUN_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT]
1209 [[/* malloc might have been renamed as rpl_malloc. */
1210 #undef malloc
1212 /* Thanks to Mike Haertel and Jim Avera for this test.
1213    Here is a matrix of mmap possibilities:
1214         mmap private not fixed
1215         mmap private fixed at somewhere currently unmapped
1216         mmap private fixed at somewhere already mapped
1217         mmap shared not fixed
1218         mmap shared fixed at somewhere currently unmapped
1219         mmap shared fixed at somewhere already mapped
1220    For private mappings, we should verify that changes cannot be read()
1221    back from the file, nor mmap's back from the file at a different
1222    address.  (There have been systems where private was not correctly
1223    implemented like the infamous i386 svr4.0, and systems where the
1224    VM page cache was not coherent with the file system buffer cache
1225    like early versions of FreeBSD and possibly contemporary NetBSD.)
1226    For shared mappings, we should conversely verify that changes get
1227    propagated back to all the places they're supposed to be.
1229    Grep wants private fixed already mapped.
1230    The main things grep needs to know about mmap are:
1231    * does it exist and is it safe to write into the mmap'd area
1232    * how to use it (BSD variants)  */
1234 #include <fcntl.h>
1235 #include <sys/mman.h>
1237 #if !defined STDC_HEADERS && !defined HAVE_STDLIB_H
1238 char *malloc ();
1239 #endif
1241 /* This mess was copied from the GNU getpagesize.h.  */
1242 #ifndef HAVE_GETPAGESIZE
1243 # ifdef _SC_PAGESIZE
1244 #  define getpagesize() sysconf(_SC_PAGESIZE)
1245 # else /* no _SC_PAGESIZE */
1246 #  ifdef HAVE_SYS_PARAM_H
1247 #   include <sys/param.h>
1248 #   ifdef EXEC_PAGESIZE
1249 #    define getpagesize() EXEC_PAGESIZE
1250 #   else /* no EXEC_PAGESIZE */
1251 #    ifdef NBPG
1252 #     define getpagesize() NBPG * CLSIZE
1253 #     ifndef CLSIZE
1254 #      define CLSIZE 1
1255 #     endif /* no CLSIZE */
1256 #    else /* no NBPG */
1257 #     ifdef NBPC
1258 #      define getpagesize() NBPC
1259 #     else /* no NBPC */
1260 #      ifdef PAGESIZE
1261 #       define getpagesize() PAGESIZE
1262 #      endif /* PAGESIZE */
1263 #     endif /* no NBPC */
1264 #    endif /* no NBPG */
1265 #   endif /* no EXEC_PAGESIZE */
1266 #  else /* no HAVE_SYS_PARAM_H */
1267 #   define getpagesize() 8192   /* punt totally */
1268 #  endif /* no HAVE_SYS_PARAM_H */
1269 # endif /* no _SC_PAGESIZE */
1271 #endif /* no HAVE_GETPAGESIZE */
1274 main ()
1276   char *data, *data2, *data3;
1277   const char *cdata2;
1278   int i, pagesize;
1279   int fd, fd2;
1281   pagesize = getpagesize ();
1283   /* First, make a file with some known garbage in it. */
1284   data = (char *) malloc (pagesize);
1285   if (!data)
1286     return 1;
1287   for (i = 0; i < pagesize; ++i)
1288     *(data + i) = rand ();
1289   umask (0);
1290   fd = creat ("conftest.mmap", 0600);
1291   if (fd < 0)
1292     return 2;
1293   if (write (fd, data, pagesize) != pagesize)
1294     return 3;
1295   close (fd);
1297   /* Next, check that the tail of a page is zero-filled.  File must have
1298      non-zero length, otherwise we risk SIGBUS for entire page.  */
1299   fd2 = open ("conftest.txt", O_RDWR | O_CREAT | O_TRUNC, 0600);
1300   if (fd2 < 0)
1301     return 4;
1302   cdata2 = "";
1303   if (write (fd2, cdata2, 1) != 1)
1304     return 5;
1305   data2 = (char *) mmap (0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd2, 0L);
1306   if (data2 == MAP_FAILED)
1307     return 6;
1308   for (i = 0; i < pagesize; ++i)
1309     if (*(data2 + i))
1310       return 7;
1311   close (fd2);
1312   if (munmap (data2, pagesize))
1313     return 8;
1315   /* Next, try to mmap the file at a fixed address which already has
1316      something else allocated at it.  If we can, also make sure that
1317      we see the same garbage.  */
1318   fd = open ("conftest.mmap", O_RDWR);
1319   if (fd < 0)
1320     return 9;
1321   if (data2 != mmap (data2, pagesize, PROT_READ | PROT_WRITE,
1322                      MAP_PRIVATE | MAP_FIXED, fd, 0L))
1323     return 10;
1324   for (i = 0; i < pagesize; ++i)
1325     if (*(data + i) != *(data2 + i))
1326       return 11;
1328   /* Finally, make sure that changes to the mapped area do not
1329      percolate back to the file as seen by read().  (This is a bug on
1330      some variants of i386 svr4.0.)  */
1331   for (i = 0; i < pagesize; ++i)
1332     *(data2 + i) = *(data2 + i) + 1;
1333   data3 = (char *) malloc (pagesize);
1334   if (!data3)
1335     return 12;
1336   if (read (fd, data3, pagesize) != pagesize)
1337     return 13;
1338   for (i = 0; i < pagesize; ++i)
1339     if (*(data + i) != *(data3 + i))
1340       return 14;
1341   close (fd);
1342   return 0;
1343 }]])],
1344                [ac_cv_func_mmap_fixed_mapped=yes],
1345                [ac_cv_func_mmap_fixed_mapped=no],
1346                [ac_cv_func_mmap_fixed_mapped=no])])
1347 if test $ac_cv_func_mmap_fixed_mapped = yes; then
1348   AC_DEFINE([HAVE_MMAP], [1],
1349             [Define to 1 if you have a working `mmap' system call.])
1351 rm -f conftest.mmap conftest.txt
1352 ])# AC_FUNC_MMAP
1355 # AU::AC_MMAP
1356 # -----------
1357 AU_ALIAS([AC_MMAP], [AC_FUNC_MMAP])
1360 # AC_FUNC_OBSTACK
1361 # ---------------
1362 # Ensure obstack support.  Yeah, this is not exactly a `FUNC' check.
1363 AN_FUNCTION([obstack_init], [AC_FUNC_OBSTACK])
1364 AN_IDENTIFIER([obstack],    [AC_FUNC_OBSTACK])
1365 AC_DEFUN([AC_FUNC_OBSTACK],
1366 [AC_LIBSOURCES([obstack.h, obstack.c])dnl
1367 AC_CACHE_CHECK([for obstacks], ac_cv_func_obstack,
1368 [AC_LINK_IFELSE(
1369     [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
1370                       [@%:@include "obstack.h"]],
1371                      [[struct obstack mem;
1372                        @%:@define obstack_chunk_alloc malloc
1373                        @%:@define obstack_chunk_free free
1374                        obstack_init (&mem);
1375                        obstack_free (&mem, 0);]])],
1376                 [ac_cv_func_obstack=yes],
1377                 [ac_cv_func_obstack=no])])
1378 if test $ac_cv_func_obstack = yes; then
1379   AC_DEFINE(HAVE_OBSTACK, 1, [Define to 1 if libc includes obstacks.])
1380 else
1381   AC_LIBOBJ(obstack)
1383 ])# AC_FUNC_OBSTACK
1386 # AU::AM_FUNC_OBSTACK
1387 # -------------------
1388 AU_ALIAS([AM_FUNC_OBSTACK], [AC_FUNC_OBSTACK])
1392 # _AC_FUNC_REALLOC_IF(IF-WORKS, IF-NOT)
1393 # -------------------------------------
1394 # If `realloc (0, 0)' is properly handled, run IF-WORKS, otherwise, IF-NOT.
1395 AC_DEFUN([_AC_FUNC_REALLOC_IF],
1396 [AC_REQUIRE([AC_HEADER_STDC])dnl
1397 AC_CHECK_HEADERS(stdlib.h)
1398 AC_CACHE_CHECK([for GNU libc compatible realloc], ac_cv_func_realloc_0_nonnull,
1399 [AC_RUN_IFELSE(
1400 [AC_LANG_PROGRAM(
1401 [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
1402 # include <stdlib.h>
1403 #else
1404 char *realloc ();
1405 #endif
1407                  [return ! realloc (0, 0);])],
1408                [ac_cv_func_realloc_0_nonnull=yes],
1409                [ac_cv_func_realloc_0_nonnull=no],
1410                [ac_cv_func_realloc_0_nonnull=no])])
1411 AS_IF([test $ac_cv_func_realloc_0_nonnull = yes], [$1], [$2])
1412 ])# AC_FUNC_REALLOC
1415 # AC_FUNC_REALLOC
1416 # ---------------
1417 # Report whether `realloc (0, 0)' is properly handled, and replace realloc if
1418 # needed.
1419 AN_FUNCTION([realloc], [AC_FUNC_REALLOC])
1420 AC_DEFUN([AC_FUNC_REALLOC],
1421 [_AC_FUNC_REALLOC_IF(
1422   [AC_DEFINE([HAVE_REALLOC], 1,
1423              [Define to 1 if your system has a GNU libc compatible `realloc'
1424               function, and to 0 otherwise.])],
1425   [AC_DEFINE([HAVE_REALLOC], 0)
1426    AC_LIBOBJ([realloc])
1427    AC_DEFINE([realloc], [rpl_realloc],
1428       [Define to rpl_realloc if the replacement function should be used.])])
1429 ])# AC_FUNC_REALLOC
1432 # AC_FUNC_SELECT_ARGTYPES
1433 # -----------------------
1434 # Determine the correct type to be passed to each of the `select'
1435 # function's arguments, and define those types in `SELECT_TYPE_ARG1',
1436 # `SELECT_TYPE_ARG234', and `SELECT_TYPE_ARG5'.
1437 AC_DEFUN([AC_FUNC_SELECT_ARGTYPES],
1438 [AC_CHECK_HEADERS(sys/select.h sys/socket.h)
1439 AC_CACHE_CHECK([types of arguments for select],
1440 [ac_cv_func_select_args],
1441 [for ac_arg234 in 'fd_set *' 'int *' 'void *'; do
1442  for ac_arg1 in 'int' 'size_t' 'unsigned long int' 'unsigned int'; do
1443   for ac_arg5 in 'struct timeval *' 'const struct timeval *'; do
1444    AC_COMPILE_IFELSE(
1445        [AC_LANG_PROGRAM(
1446 [AC_INCLUDES_DEFAULT
1447 #ifdef HAVE_SYS_SELECT_H
1448 # include <sys/select.h>
1449 #endif
1450 #ifdef HAVE_SYS_SOCKET_H
1451 # include <sys/socket.h>
1452 #endif
1454                         [extern int select ($ac_arg1,
1455                                             $ac_arg234, $ac_arg234, $ac_arg234,
1456                                             $ac_arg5);])],
1457               [ac_cv_func_select_args="$ac_arg1,$ac_arg234,$ac_arg5"; break 3])
1458   done
1459  done
1460 done
1461 # Provide a safe default value.
1462 : "${ac_cv_func_select_args=int,int *,struct timeval *}"
1464 ac_save_IFS=$IFS; IFS=','
1465 set dummy `echo "$ac_cv_func_select_args" | sed 's/\*/\*/g'`
1466 IFS=$ac_save_IFS
1467 shift
1468 AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG1, $[1],
1469                    [Define to the type of arg 1 for `select'.])
1470 AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG234, ($[2]),
1471                    [Define to the type of args 2, 3 and 4 for `select'.])
1472 AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG5, ($[3]),
1473                    [Define to the type of arg 5 for `select'.])
1474 rm -f conftest*
1475 ])# AC_FUNC_SELECT_ARGTYPES
1478 # AC_FUNC_SETPGRP
1479 # ---------------
1480 AC_DEFUN([AC_FUNC_SETPGRP],
1481 [AC_CACHE_CHECK(whether setpgrp takes no argument, ac_cv_func_setpgrp_void,
1482 [AC_RUN_IFELSE(
1483 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1484 [/* If this system has a BSD-style setpgrp which takes arguments,
1485   setpgrp(1, 1) will fail with ESRCH and return -1, in that case
1486   exit successfully. */
1487   return setpgrp (1,1) != -1;])],
1488                [ac_cv_func_setpgrp_void=no],
1489                [ac_cv_func_setpgrp_void=yes],
1490                [AC_MSG_ERROR([cannot check setpgrp when cross compiling])])])
1491 if test $ac_cv_func_setpgrp_void = yes; then
1492   AC_DEFINE(SETPGRP_VOID, 1,
1493             [Define to 1 if the `setpgrp' function takes no argument.])
1495 ])# AC_FUNC_SETPGRP
1498 # _AC_FUNC_STAT(STAT | LSTAT)
1499 # ---------------------------
1500 # Determine whether stat or lstat have the bug that it succeeds when
1501 # given the zero-length file name argument.  The stat and lstat from
1502 # SunOS4.1.4 and the Hurd (as of 1998-11-01) do this.
1504 # If it does, then define HAVE_STAT_EMPTY_STRING_BUG (or
1505 # HAVE_LSTAT_EMPTY_STRING_BUG) and arrange to compile the wrapper
1506 # function.
1507 m4_define([_AC_FUNC_STAT],
1508 [AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])dnl
1509 AC_CACHE_CHECK([whether $1 accepts an empty string],
1510                [ac_cv_func_$1_empty_string_bug],
1511 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1512 [[struct stat sbuf;
1513   return $1 ("", &sbuf) == 0;]])],
1514             [ac_cv_func_$1_empty_string_bug=no],
1515             [ac_cv_func_$1_empty_string_bug=yes],
1516             [ac_cv_func_$1_empty_string_bug=yes])])
1517 if test $ac_cv_func_$1_empty_string_bug = yes; then
1518   AC_LIBOBJ([$1])
1519   AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1_EMPTY_STRING_BUG]), 1,
1520                      [Define to 1 if `$1' has the bug that it succeeds when
1521                       given the zero-length file name argument.])
1523 ])# _AC_FUNC_STAT
1526 # AC_FUNC_STAT & AC_FUNC_LSTAT
1527 # ----------------------------
1528 AC_DEFUN([AC_FUNC_STAT],  [_AC_FUNC_STAT(stat)])
1529 AC_DEFUN([AC_FUNC_LSTAT], [_AC_FUNC_STAT(lstat)])
1532 # _AC_LIBOBJ_STRTOD
1533 # -----------------
1534 m4_define([_AC_LIBOBJ_STRTOD],
1535 [AC_LIBOBJ(strtod)
1536 AC_CHECK_FUNC(pow)
1537 if test $ac_cv_func_pow = no; then
1538   AC_CHECK_LIB(m, pow,
1539                [POW_LIB=-lm],
1540                [AC_MSG_WARN([cannot find library containing definition of pow])])
1542 ])# _AC_LIBOBJ_STRTOD
1545 # AC_FUNC_STRTOD
1546 # --------------
1547 AN_FUNCTION([strtod], [AC_FUNC_STRTOD])
1548 AC_DEFUN([AC_FUNC_STRTOD],
1549 [AC_SUBST(POW_LIB)dnl
1550 AC_CACHE_CHECK(for working strtod, ac_cv_func_strtod,
1551 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
1552 ]AC_INCLUDES_DEFAULT[
1553 #ifndef strtod
1554 double strtod ();
1555 #endif
1557 main()
1559   {
1560     /* Some versions of Linux strtod mis-parse strings with leading '+'.  */
1561     char *string = " +69";
1562     char *term;
1563     double value;
1564     value = strtod (string, &term);
1565     if (value != 69 || term != (string + 4))
1566       return 1;
1567   }
1569   {
1570     /* Under Solaris 2.4, strtod returns the wrong value for the
1571        terminating character under some conditions.  */
1572     char *string = "NaN";
1573     char *term;
1574     strtod (string, &term);
1575     if (term != string && *(term - 1) == 0)
1576       return 1;
1577   }
1578   return 0;
1580 ]])],
1581                ac_cv_func_strtod=yes,
1582                ac_cv_func_strtod=no,
1583                ac_cv_func_strtod=no)])
1584 if test $ac_cv_func_strtod = no; then
1585   _AC_LIBOBJ_STRTOD
1590 # AC_FUNC_STRTOLD
1591 # ---------------
1592 AC_DEFUN([AC_FUNC_STRTOLD],
1594   AC_CACHE_CHECK([whether strtold conforms to C99],
1595     [ac_cv_func_strtold],
1596     [AC_COMPILE_IFELSE(
1597        [AC_LANG_PROGRAM(
1598           [[/* On HP-UX before 11.23, strtold returns a struct instead of
1599                 long double.  Reject implementations like that, by requiring
1600                 compatibility with the C99 prototype.  */
1601 #            include <stdlib.h>
1602              static long double (*p) (char const *, char **) = strtold;
1603              static long double
1604              test (char const *nptr, char **endptr)
1605              {
1606                long double r;
1607                r = strtold (nptr, endptr);
1608                return r;
1609              }]],
1610            [[return test ("1.0", NULL) != 1 || p ("1.0", NULL) != 1;]])],
1611        [ac_cv_func_strtold=yes],
1612        [ac_cv_func_strtold=no])])
1613   if test $ac_cv_func_strtold = yes; then
1614     AC_DEFINE([HAVE_STRTOLD], 1,
1615       [Define to 1 if strtold exists and conforms to C99.])
1616   fi
1617 ])# AC_FUNC_STRTOLD
1620 # AU::AM_FUNC_STRTOD
1621 # ------------------
1622 AU_ALIAS([AM_FUNC_STRTOD], [AC_FUNC_STRTOD])
1625 # AC_FUNC_STRERROR_R
1626 # ------------------
1627 AN_FUNCTION([strerror_r], [AC_FUNC_STRERROR_R])
1628 AC_DEFUN([AC_FUNC_STRERROR_R],
1629 [AC_CHECK_DECLS([strerror_r])
1630 AC_CHECK_FUNCS([strerror_r])
1631 AC_CACHE_CHECK([whether strerror_r returns char *],
1632                ac_cv_func_strerror_r_char_p,
1633    [
1634     ac_cv_func_strerror_r_char_p=no
1635     if test $ac_cv_have_decl_strerror_r = yes; then
1636       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1637         [[
1638           char buf[100];
1639           char x = *strerror_r (0, buf, sizeof buf);
1640           char *p = strerror_r (0, buf, sizeof buf);
1641           return !p || x;
1642         ]])],
1643                         ac_cv_func_strerror_r_char_p=yes)
1644     else
1645       # strerror_r is not declared.  Choose between
1646       # systems that have relatively inaccessible declarations for the
1647       # function.  BeOS and DEC UNIX 4.0 fall in this category, but the
1648       # former has a strerror_r that returns char*, while the latter
1649       # has a strerror_r that returns `int'.
1650       # This test should segfault on the DEC system.
1651       AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
1652         extern char *strerror_r ();],
1653         [[char buf[100];
1654           char x = *strerror_r (0, buf, sizeof buf);
1655           return ! isalpha (x);]])],
1656                     ac_cv_func_strerror_r_char_p=yes, , :)
1657     fi
1658   ])
1659 if test $ac_cv_func_strerror_r_char_p = yes; then
1660   AC_DEFINE([STRERROR_R_CHAR_P], 1,
1661             [Define to 1 if strerror_r returns char *.])
1663 ])# AC_FUNC_STRERROR_R
1666 # AC_FUNC_STRFTIME
1667 # ----------------
1668 AC_DEFUN([AC_FUNC_STRFTIME],
1669 [AC_CHECK_FUNCS(strftime, [],
1670 [# strftime is in -lintl on SCO UNIX.
1671 AC_CHECK_LIB(intl, strftime,
1672              [AC_DEFINE(HAVE_STRFTIME)
1673 LIBS="-lintl $LIBS"])])dnl
1674 ])# AC_FUNC_STRFTIME
1677 # AC_FUNC_STRNLEN
1678 # ---------------
1679 AN_FUNCTION([strnlen], [AC_FUNC_STRNLEN])
1680 AC_DEFUN([AC_FUNC_STRNLEN],
1681 [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])dnl
1682 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1683 AC_CACHE_CHECK([for working strnlen], ac_cv_func_strnlen_working,
1684 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[
1685 #define S "foobar"
1686 #define S_LEN (sizeof S - 1)
1688   /* At least one implementation is buggy: that of AIX 4.3 would
1689      give strnlen (S, 1) == 3.  */
1691   int i;
1692   for (i = 0; i < S_LEN + 1; ++i)
1693     {
1694       int expected = i <= S_LEN ? i : S_LEN;
1695       if (strnlen (S, i) != expected)
1696         return 1;
1697     }
1698   return 0;
1699 ]])],
1700                [ac_cv_func_strnlen_working=yes],
1701                [ac_cv_func_strnlen_working=no],
1702                [# Guess no on AIX systems, yes otherwise.
1703                 case "$host_os" in
1704                   aix*) ac_cv_func_strnlen_working=no;;
1705                   *)    ac_cv_func_strnlen_working=yes;;
1706                 esac])])
1707 test $ac_cv_func_strnlen_working = no && AC_LIBOBJ([strnlen])
1708 ])# AC_FUNC_STRNLEN
1711 # AC_FUNC_SETVBUF_REVERSED
1712 # ------------------------
1713 AC_DEFUN([AC_FUNC_SETVBUF_REVERSED],
1714 [AC_DIAGNOSE([obsolete],
1715 [The macro `$0' is obsolete.  Remove it and all references to SETVBUF_REVERSED.])dnl
1716 AC_CACHE_VAL([ac_cv_func_setvbuf_reversed], [ac_cv_func_setvbuf_reversed=no])
1717 ])# AC_FUNC_SETVBUF_REVERSED
1720 # AU::AC_SETVBUF_REVERSED
1721 # -----------------------
1722 AU_ALIAS([AC_SETVBUF_REVERSED], [AC_FUNC_SETVBUF_REVERSED])
1725 # AC_FUNC_STRCOLL
1726 # ---------------
1727 AN_FUNCTION([strcoll], [AC_FUNC_STRCOLL])
1728 AC_DEFUN([AC_FUNC_STRCOLL],
1729 [AC_CACHE_CHECK(for working strcoll, ac_cv_func_strcoll_works,
1730 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1731   [[return (strcoll ("abc", "def") >= 0 ||
1732          strcoll ("ABC", "DEF") >= 0 ||
1733          strcoll ("123", "456") >= 0)]])],
1734                ac_cv_func_strcoll_works=yes,
1735                ac_cv_func_strcoll_works=no,
1736                ac_cv_func_strcoll_works=no)])
1737 if test $ac_cv_func_strcoll_works = yes; then
1738   AC_DEFINE(HAVE_STRCOLL, 1,
1739             [Define to 1 if you have the `strcoll' function and it is properly
1740              defined.])
1742 ])# AC_FUNC_STRCOLL
1745 # AU::AC_STRCOLL
1746 # --------------
1747 AU_ALIAS([AC_STRCOLL], [AC_FUNC_STRCOLL])
1750 # AC_FUNC_UTIME_NULL
1751 # ------------------
1752 AC_DEFUN([AC_FUNC_UTIME_NULL],
1753 [AC_CHECK_HEADERS_ONCE(utime.h)
1754 AC_CACHE_CHECK(whether utime accepts a null argument, ac_cv_func_utime_null,
1755 [rm -f conftest.data; >conftest.data
1756 # Sequent interprets utime(file, 0) to mean use start of epoch.  Wrong.
1757 AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
1758                #ifdef HAVE_UTIME_H
1759                # include <utime.h>
1760                #endif],
1761 [[struct stat s, t;
1762   return ! (stat ("conftest.data", &s) == 0
1763             && utime ("conftest.data", 0) == 0
1764             && stat ("conftest.data", &t) == 0
1765             && t.st_mtime >= s.st_mtime
1766             && t.st_mtime - s.st_mtime < 120);]])],
1767               ac_cv_func_utime_null=yes,
1768               ac_cv_func_utime_null=no,
1769               ac_cv_func_utime_null='guessing yes')])
1770 if test "x$ac_cv_func_utime_null" != xno; then
1771   ac_cv_func_utime_null=yes
1772   AC_DEFINE(HAVE_UTIME_NULL, 1,
1773             [Define to 1 if `utime(file, NULL)' sets file's timestamp to the
1774              present.])
1776 rm -f conftest.data
1777 ])# AC_FUNC_UTIME_NULL
1780 # AU::AC_UTIME_NULL
1781 # -----------------
1782 AU_ALIAS([AC_UTIME_NULL], [AC_FUNC_UTIME_NULL])
1785 # AC_FUNC_FORK
1786 # ------------
1787 AN_FUNCTION([fork],  [AC_FUNC_FORK])
1788 AN_FUNCTION([vfork], [AC_FUNC_FORK])
1789 AC_DEFUN([AC_FUNC_FORK],
1790 [AC_REQUIRE([AC_TYPE_PID_T])dnl
1791 AC_CHECK_HEADERS(vfork.h)
1792 AC_CHECK_FUNCS(fork vfork)
1793 if test "x$ac_cv_func_fork" = xyes; then
1794   _AC_FUNC_FORK
1795 else
1796   ac_cv_func_fork_works=$ac_cv_func_fork
1798 if test "x$ac_cv_func_fork_works" = xcross; then
1799   case $host in
1800     *-*-amigaos* | *-*-msdosdjgpp*)
1801       # Override, as these systems have only a dummy fork() stub
1802       ac_cv_func_fork_works=no
1803       ;;
1804     *)
1805       ac_cv_func_fork_works=yes
1806       ;;
1807   esac
1808   AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
1810 ac_cv_func_vfork_works=$ac_cv_func_vfork
1811 if test "x$ac_cv_func_vfork" = xyes; then
1812   _AC_FUNC_VFORK
1814 if test "x$ac_cv_func_fork_works" = xcross; then
1815   ac_cv_func_vfork_works=$ac_cv_func_vfork
1816   AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
1819 if test "x$ac_cv_func_vfork_works" = xyes; then
1820   AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
1821 else
1822   AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
1824 if test "x$ac_cv_func_fork_works" = xyes; then
1825   AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
1827 ])# AC_FUNC_FORK
1830 # _AC_FUNC_FORK
1831 # -------------
1832 AC_DEFUN([_AC_FUNC_FORK],
1833   [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
1834     [AC_RUN_IFELSE(
1835       [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1836         [
1837           /* By Ruediger Kuhlmann. */
1838           return fork () < 0;
1839         ])],
1840       [ac_cv_func_fork_works=yes],
1841       [ac_cv_func_fork_works=no],
1842       [ac_cv_func_fork_works=cross])])]
1843 )# _AC_FUNC_FORK
1846 # _AC_FUNC_VFORK
1847 # --------------
1848 AC_DEFUN([_AC_FUNC_VFORK],
1849 [AC_CACHE_CHECK(for working vfork, ac_cv_func_vfork_works,
1850 [AC_RUN_IFELSE([AC_LANG_SOURCE([[/* Thanks to Paul Eggert for this test.  */
1851 ]AC_INCLUDES_DEFAULT[
1852 #include <sys/wait.h>
1853 #ifdef HAVE_VFORK_H
1854 # include <vfork.h>
1855 #endif
1856 /* On some sparc systems, changes by the child to local and incoming
1857    argument registers are propagated back to the parent.  The compiler
1858    is told about this with #include <vfork.h>, but some compilers
1859    (e.g. gcc -O) don't grok <vfork.h>.  Test for this by using a
1860    static variable whose address is put into a register that is
1861    clobbered by the vfork.  */
1862 static void
1863 #ifdef __cplusplus
1864 sparc_address_test (int arg)
1865 # else
1866 sparc_address_test (arg) int arg;
1867 #endif
1869   static pid_t child;
1870   if (!child) {
1871     child = vfork ();
1872     if (child < 0) {
1873       perror ("vfork");
1874       _exit(2);
1875     }
1876     if (!child) {
1877       arg = getpid();
1878       write(-1, "", 0);
1879       _exit (arg);
1880     }
1881   }
1885 main ()
1887   pid_t parent = getpid ();
1888   pid_t child;
1890   sparc_address_test (0);
1892   child = vfork ();
1894   if (child == 0) {
1895     /* Here is another test for sparc vfork register problems.  This
1896        test uses lots of local variables, at least as many local
1897        variables as main has allocated so far including compiler
1898        temporaries.  4 locals are enough for gcc 1.40.3 on a Solaris
1899        4.1.3 sparc, but we use 8 to be safe.  A buggy compiler should
1900        reuse the register of parent for one of the local variables,
1901        since it will think that parent can't possibly be used any more
1902        in this routine.  Assigning to the local variable will thus
1903        munge parent in the parent process.  */
1904     pid_t
1905       p = getpid(), p1 = getpid(), p2 = getpid(), p3 = getpid(),
1906       p4 = getpid(), p5 = getpid(), p6 = getpid(), p7 = getpid();
1907     /* Convince the compiler that p..p7 are live; otherwise, it might
1908        use the same hardware register for all 8 local variables.  */
1909     if (p != p1 || p != p2 || p != p3 || p != p4
1910         || p != p5 || p != p6 || p != p7)
1911       _exit(1);
1913     /* On some systems (e.g. IRIX 3.3), vfork doesn't separate parent
1914        from child file descriptors.  If the child closes a descriptor
1915        before it execs or exits, this munges the parent's descriptor
1916        as well.  Test for this by closing stdout in the child.  */
1917     _exit(close(fileno(stdout)) != 0);
1918   } else {
1919     int status;
1920     struct stat st;
1922     while (wait(&status) != child)
1923       ;
1924     return (
1925          /* Was there some problem with vforking?  */
1926          child < 0
1928          /* Did the child fail?  (This shouldn't happen.)  */
1929          || status
1931          /* Did the vfork/compiler bug occur?  */
1932          || parent != getpid()
1934          /* Did the file descriptor bug occur?  */
1935          || fstat(fileno(stdout), &st) != 0
1936          );
1937   }
1938 }]])],
1939             [ac_cv_func_vfork_works=yes],
1940             [ac_cv_func_vfork_works=no],
1941             [ac_cv_func_vfork_works=cross])])
1942 ])# _AC_FUNC_VFORK
1945 # AU::AC_FUNC_VFORK
1946 # -----------------
1947 AU_ALIAS([AC_FUNC_VFORK], [AC_FUNC_FORK])
1949 # AU::AC_VFORK
1950 # ------------
1951 AU_ALIAS([AC_VFORK], [AC_FUNC_FORK])
1954 # AC_FUNC_VPRINTF
1955 # ---------------
1956 # Why the heck is that _doprnt does not define HAVE__DOPRNT???
1957 # That the logical name!
1958 AC_DEFUN([AC_FUNC_VPRINTF],
1959 [AC_CHECK_FUNCS(vprintf, []
1960 [AC_CHECK_FUNC(_doprnt,
1961                [AC_DEFINE(HAVE_DOPRNT, 1,
1962                           [Define to 1 if you don't have `vprintf' but do have
1963                           `_doprnt.'])])])
1967 # AU::AC_VPRINTF
1968 # --------------
1969 AU_ALIAS([AC_VPRINTF], [AC_FUNC_VPRINTF])
1972 # AC_FUNC_WAIT3
1973 # -------------
1974 # Don't bother too hard maintaining this macro, as it's obsoleted.
1975 # We don't AU define it, since we don't have any alternative to propose,
1976 # any invocation should be removed, and the code adjusted.
1977 AN_FUNCTION([wait3], [AC_FUNC_WAIT3])
1978 AC_DEFUN([AC_FUNC_WAIT3],
1979 [AC_DIAGNOSE([obsolete],
1980 [$0: `wait3' has been removed from POSIX.
1981 Remove this `AC_FUNC_WAIT3' and adjust your code to use `waitpid' instead.])dnl
1982 AC_CACHE_CHECK([for wait3 that fills in rusage],
1983                [ac_cv_func_wait3_rusage],
1984 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1985 [AC_INCLUDES_DEFAULT[
1986 #include <sys/time.h>
1987 #include <sys/resource.h>
1988 #include <sys/wait.h>
1989 /* HP-UX has wait3 but does not fill in rusage at all.  */
1991 main ()
1993   struct rusage r;
1994   int i;
1995   /* Use a field that we can force nonzero --
1996      voluntary context switches.
1997      For systems like NeXT and OSF/1 that don't set it,
1998      also use the system CPU time.  And page faults (I/O) for Linux.  */
1999   r.ru_nvcsw = 0;
2000   r.ru_stime.tv_sec = 0;
2001   r.ru_stime.tv_usec = 0;
2002   r.ru_majflt = r.ru_minflt = 0;
2003   switch (fork ())
2004     {
2005     case 0: /* Child.  */
2006       sleep(1); /* Give up the CPU.  */
2007       _exit(0);
2008       break;
2009     case -1: /* What can we do?  */
2010       _exit(0);
2011       break;
2012     default: /* Parent.  */
2013       wait3(&i, 0, &r);
2014       /* Avoid "text file busy" from rm on fast HP-UX machines.  */
2015       sleep(2);
2016       return (r.ru_nvcsw == 0 && r.ru_majflt == 0 && r.ru_minflt == 0
2017               && r.ru_stime.tv_sec == 0 && r.ru_stime.tv_usec == 0);
2018     }
2019 }]])],
2020                [ac_cv_func_wait3_rusage=yes],
2021                [ac_cv_func_wait3_rusage=no],
2022                [ac_cv_func_wait3_rusage=no])])
2023 if test $ac_cv_func_wait3_rusage = yes; then
2024   AC_DEFINE(HAVE_WAIT3, 1,
2025             [Define to 1 if you have the `wait3' system call.
2026              Deprecated, you should no longer depend upon `wait3'.])
2028 ])# AC_FUNC_WAIT3
2031 # AU::AC_WAIT3
2032 # ------------
2033 AU_ALIAS([AC_WAIT3], [AC_FUNC_WAIT3])