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