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