~ubuntu-branches/ubuntu/lucid/autoconf/lucid

« back to all changes in this revision

Viewing changes to lib/autoconf/functions.m4

  • Committer: Bazaar Package Importer
  • Author(s): Ben Pfaff
  • Date: 2002-03-27 21:52:33 UTC
  • Revision ID: james.westby@ubuntu.com-20020327215233-r3gmxall0x27s306
Tags: upstream-2.53
ImportĀ upstreamĀ versionĀ 2.53

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file is part of Autoconf.                       -*- Autoconf -*-
 
2
# Checking for functions.
 
3
# Copyright 2000, 2001
 
4
# Free Software Foundation, Inc.
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2, or (at your option)
 
9
# any later version.
 
10
#
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program; if not, write to the Free Software
 
18
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
# 02111-1307, USA.
 
20
#
 
21
# As a special exception, the Free Software Foundation gives unlimited
 
22
# permission to copy, distribute and modify the configure scripts that
 
23
# are the output of Autoconf.  You need not follow the terms of the GNU
 
24
# General Public License when using or distributing such scripts, even
 
25
# though portions of the text of Autoconf appear in them.  The GNU
 
26
# General Public License (GPL) does govern all other use of the material
 
27
# that constitutes the Autoconf program.
 
28
#
 
29
# Certain portions of the Autoconf source text are designed to be copied
 
30
# (in certain cases, depending on the input) into the output of
 
31
# Autoconf.  We call these the "data" portions.  The rest of the Autoconf
 
32
# source text consists of comments plus executable code that decides which
 
33
# of the data portions to output in any given case.  We call these
 
34
# comments and executable code the "non-data" portions.  Autoconf never
 
35
# copies any of the non-data portions into its output.
 
36
#
 
37
# This special exception to the GPL applies to versions of Autoconf
 
38
# released by the Free Software Foundation.  When you make and
 
39
# distribute a modified version of Autoconf, you may extend this special
 
40
# exception to the GPL to apply to your modified version as well, *unless*
 
41
# your modified version has the potential to copy into its output some
 
42
# of the text that was the non-data portion of the version that you started
 
43
# with.  (In other words, unless your change moves or copies text from
 
44
# the non-data portions to the data portions.)  If your modification has
 
45
# such potential, you must delete any notice of this special exception
 
46
# to the GPL from your modified version.
 
47
#
 
48
# Written by David MacKenzie, with help from
 
49
# Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
 
50
# Roland McGrath, Noah Friedman, david d zuhn, and many others.
 
51
 
 
52
 
 
53
# Table of contents
 
54
#
 
55
# 1. Generic tests for functions.
 
56
# 2. Tests for specific functions.
 
57
 
 
58
 
 
59
## -------------------------------- ##
 
60
## 1. Generic tests for functions.  ##
 
61
## -------------------------------- ##
 
62
 
 
63
 
 
64
# AC_CHECK_FUNC(FUNCTION, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
 
65
# -----------------------------------------------------------------
 
66
AC_DEFUN([AC_CHECK_FUNC],
 
67
[AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$1])dnl
 
68
AC_CACHE_CHECK([for $1], ac_var,
 
69
[AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY([$1])],
 
70
                [AS_VAR_SET(ac_var, yes)],
 
71
                [AS_VAR_SET(ac_var, no)])])
 
72
AS_IF([test AS_VAR_GET(ac_var) = yes], [$2], [$3])dnl
 
73
AS_VAR_POPDEF([ac_var])dnl
 
74
])# AC_CHECK_FUNC
 
75
 
 
76
 
 
77
# AC_CHECK_FUNCS(FUNCTION..., [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
 
78
# ---------------------------------------------------------------------
 
79
AC_DEFUN([AC_CHECK_FUNCS],
 
80
[AC_FOREACH([AC_Func], [$1],
 
81
  [AH_TEMPLATE(AS_TR_CPP(HAVE_[]AC_Func),
 
82
               [Define to 1 if you have the `]AC_Func[' function.])])dnl
 
83
for ac_func in $1
 
84
do
 
85
AC_CHECK_FUNC($ac_func,
 
86
              [AC_DEFINE_UNQUOTED([AS_TR_CPP([HAVE_$ac_func])]) $2],
 
87
              [$3])dnl
 
88
done
 
89
])
 
90
 
 
91
 
 
92
# AC_REPLACE_FUNCS(FUNCTION...)
 
93
# -----------------------------
 
94
AC_DEFUN([AC_REPLACE_FUNCS],
 
95
[AC_FOREACH([AC_Func], [$1], [AC_LIBSOURCE(AC_Func.c)])dnl
 
96
AC_CHECK_FUNCS([$1], , [_AC_LIBOBJ($ac_func)])
 
97
])
 
98
 
 
99
 
 
100
# AC_TRY_LINK_FUNC(FUNC, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
 
101
# ------------------------------------------------------------
 
102
# Try to link a program that calls FUNC, handling GCC builtins.  If
 
103
# the link succeeds, execute ACTION-IF-FOUND; otherwise, execute
 
104
# ACTION-IF-NOT-FOUND.
 
105
AC_DEFUN([AC_TRY_LINK_FUNC],
 
106
[AC_LINK_IFELSE([AC_LANG_CALL([], [$1])], [$2], [$3])])
 
107
 
 
108
 
 
109
# AU::AC_FUNC_CHECK
 
110
# -----------------
 
111
AU_ALIAS([AC_FUNC_CHECK], [AC_CHECK_FUNC])
 
112
 
 
113
 
 
114
# AU::AC_HAVE_FUNCS
 
115
# -----------------
 
116
AU_ALIAS([AC_HAVE_FUNCS], [AC_CHECK_FUNCS])
 
117
 
 
118
 
 
119
 
 
120
 
 
121
## --------------------------------- ##
 
122
## 2. Tests for specific functions.  ##
 
123
## --------------------------------- ##
 
124
 
 
125
 
 
126
# The macros are sorted:
 
127
#
 
128
# 1. AC_FUNC_* macros are sorted by alphabetical order.
 
129
#
 
130
# 2. Helping macros such as _AC_LIBOBJ_* are before the macro that
 
131
#    uses it.
 
132
#
 
133
# 3. Obsolete macros are right after the modern macro.
 
134
 
 
135
 
 
136
 
 
137
# _AC_LIBOBJ_ALLOCA
 
138
# -----------------
 
139
# Set up the LIBOBJ replacement of `alloca'.  Well, not exactly
 
140
# AC_LIBOBJ since we actually set the output variable `ALLOCA'.
 
141
# Nevertheless, for Automake, AC_LIBSOURCES it.
 
142
m4_define([_AC_LIBOBJ_ALLOCA],
 
143
[# The SVR3 libPW and SVR4 libucb both contain incompatible functions
 
144
# that cause trouble.  Some versions do not even contain alloca or
 
145
# contain a buggy version.  If you still want to use their alloca,
 
146
# use ar to extract alloca.o from them instead of compiling alloca.c.
 
147
AC_LIBSOURCES(alloca.c)
 
148
AC_SUBST(ALLOCA, alloca.$ac_objext)dnl
 
149
AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using `alloca.c'.])
 
150
 
 
151
AC_CACHE_CHECK(whether `alloca.c' needs Cray hooks, ac_cv_os_cray,
 
152
[AC_EGREP_CPP(webecray,
 
153
[#if defined(CRAY) && ! defined(CRAY2)
 
154
webecray
 
155
#else
 
156
wenotbecray
 
157
#endif
 
158
], ac_cv_os_cray=yes, ac_cv_os_cray=no)])
 
159
if test $ac_cv_os_cray = yes; then
 
160
  for ac_func in _getb67 GETB67 getb67; do
 
161
    AC_CHECK_FUNC($ac_func,
 
162
                  [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func,
 
163
                                      [Define to one of `_getb67', `GETB67',
 
164
                                       `getb67' for Cray-2 and Cray-YMP
 
165
                                       systems. This function is required for
 
166
                                       `alloca.c' support on those systems.])
 
167
    break])
 
168
  done
 
169
fi
 
170
 
 
171
AC_CACHE_CHECK([stack direction for C alloca],
 
172
               [ac_cv_c_stack_direction],
 
173
[AC_RUN_IFELSE([AC_LANG_SOURCE(
 
174
[int
 
175
find_stack_direction ()
 
176
{
 
177
  static char *addr = 0;
 
178
  auto char dummy;
 
179
  if (addr == 0)
 
180
    {
 
181
      addr = &dummy;
 
182
      return find_stack_direction ();
 
183
    }
 
184
  else
 
185
    return (&dummy > addr) ? 1 : -1;
 
186
}
 
187
 
 
188
int
 
189
main ()
 
190
{
 
191
  exit (find_stack_direction () < 0);
 
192
}])],
 
193
               [ac_cv_c_stack_direction=1],
 
194
               [ac_cv_c_stack_direction=-1],
 
195
               [ac_cv_c_stack_direction=0])])
 
196
AH_VERBATIM([STACK_DIRECTION],
 
197
[/* If using the C implementation of alloca, define if you know the
 
198
   direction of stack growth for your system; otherwise it will be
 
199
   automatically deduced at run-time.
 
200
        STACK_DIRECTION > 0 => grows toward higher addresses
 
201
        STACK_DIRECTION < 0 => grows toward lower addresses
 
202
        STACK_DIRECTION = 0 => direction of growth unknown */
 
203
@%:@undef STACK_DIRECTION])dnl
 
204
AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
 
205
])# _AC_LIBOBJ_ALLOCA
 
206
 
 
207
 
 
208
# AC_FUNC_ALLOCA
 
209
# --------------
 
210
AC_DEFUN([AC_FUNC_ALLOCA],
 
211
[# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
 
212
# for constant arguments.  Useless!
 
213
AC_CACHE_CHECK([for working alloca.h], ac_cv_working_alloca_h,
 
214
[AC_LINK_IFELSE(
 
215
       [AC_LANG_PROGRAM([[@%:@include <alloca.h>]],
 
216
                        [[char *p = (char *) alloca (2 * sizeof (int));]])],
 
217
                [ac_cv_working_alloca_h=yes],
 
218
                [ac_cv_working_alloca_h=no])])
 
219
if test $ac_cv_working_alloca_h = yes; then
 
220
  AC_DEFINE(HAVE_ALLOCA_H, 1,
 
221
            [Define to 1 if you have <alloca.h> and it should be used
 
222
             (not on Ultrix).])
 
223
fi
 
224
 
 
225
AC_CACHE_CHECK([for alloca], ac_cv_func_alloca_works,
 
226
[AC_LINK_IFELSE([AC_LANG_PROGRAM(
 
227
[[#ifdef __GNUC__
 
228
# define alloca __builtin_alloca
 
229
#else
 
230
# ifdef _MSC_VER
 
231
#  include <malloc.h>
 
232
#  define alloca _alloca
 
233
# else
 
234
#  if HAVE_ALLOCA_H
 
235
#   include <alloca.h>
 
236
#  else
 
237
#   ifdef _AIX
 
238
 #pragma alloca
 
239
#   else
 
240
#    ifndef alloca /* predefined by HP cc +Olibcalls */
 
241
char *alloca ();
 
242
#    endif
 
243
#   endif
 
244
#  endif
 
245
# endif
 
246
#endif
 
247
]],                               [[char *p = (char *) alloca (1);]])],
 
248
                [ac_cv_func_alloca_works=yes],
 
249
                [ac_cv_func_alloca_works=no])])
 
250
 
 
251
if test $ac_cv_func_alloca_works = yes; then
 
252
  AC_DEFINE(HAVE_ALLOCA, 1,
 
253
            [Define to 1 if you have `alloca', as a function or macro.])
 
254
else
 
255
  _AC_LIBOBJ_ALLOCA
 
256
fi
 
257
])# AC_FUNC_ALLOCA
 
258
 
 
259
 
 
260
# AU::AC_ALLOCA
 
261
# -------------
 
262
AU_ALIAS([AC_ALLOCA], [AC_FUNC_ALLOCA])
 
263
 
 
264
 
 
265
# AC_FUNC_CHOWN
 
266
# -------------
 
267
# Determine whether chown accepts arguments of -1 for uid and gid.
 
268
AC_DEFUN([AC_FUNC_CHOWN],
 
269
[AC_REQUIRE([AC_TYPE_UID_T])dnl
 
270
AC_CHECK_HEADERS(unistd.h)
 
271
AC_CACHE_CHECK([for working chown], ac_cv_func_chown_works,
 
272
[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
 
273
#include <fcntl.h>
 
274
],
 
275
[[  char *f = "conftest.chown";
 
276
  struct stat before, after;
 
277
 
 
278
  if (creat (f, 0600) < 0)
 
279
    exit (1);
 
280
  if (stat (f, &before) < 0)
 
281
    exit (1);
 
282
  if (chown (f, (uid_t) -1, (gid_t) -1) == -1)
 
283
    exit (1);
 
284
  if (stat (f, &after) < 0)
 
285
    exit (1);
 
286
  exit ((before.st_uid == after.st_uid
 
287
         && before.st_gid == after.st_gid) ? 0 : 1);
 
288
]])],
 
289
               [ac_cv_func_chown_works=yes],
 
290
               [ac_cv_func_chown_works=no],
 
291
               [ac_cv_func_chown_works=no])
 
292
rm -f conftest.chown
 
293
])
 
294
if test $ac_cv_func_chown_works = yes; then
 
295
  AC_DEFINE(HAVE_CHOWN, 1,
 
296
            [Define to 1 if your system has a working `chown' function.])
 
297
fi
 
298
])# AC_FUNC_CHOWN
 
299
 
 
300
 
 
301
# AC_FUNC_CLOSEDIR_VOID
 
302
# ---------------------
 
303
# Check whether closedir returns void, and #define CLOSEDIR_VOID in
 
304
# that case.
 
305
AC_DEFUN([AC_FUNC_CLOSEDIR_VOID],
 
306
[AC_REQUIRE([AC_HEADER_DIRENT])dnl
 
307
AC_CACHE_CHECK([whether closedir returns void],
 
308
               [ac_cv_func_closedir_void],
 
309
[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
 
310
#include <$ac_header_dirent>
 
311
#ifndef __cplusplus
 
312
int closedir ();
 
313
#endif
 
314
],
 
315
                                [[exit (closedir (opendir (".")) != 0);]])],
 
316
               [ac_cv_func_closedir_void=no],
 
317
               [ac_cv_func_closedir_void=yes],
 
318
               [ac_cv_func_closedir_void=yes])])
 
319
if test $ac_cv_func_closedir_void = yes; then
 
320
  AC_DEFINE(CLOSEDIR_VOID, 1,
 
321
            [Define to 1 if the `closedir' function returns void instead
 
322
             of `int'.])
 
323
fi
 
324
])
 
325
 
 
326
 
 
327
# AC_FUNC_ERROR_AT_LINE
 
328
# ---------------------
 
329
AC_DEFUN([AC_FUNC_ERROR_AT_LINE],
 
330
[AC_LIBSOURCES([error.h, error.c])dnl
 
331
AC_CACHE_CHECK([for error_at_line], ac_cv_lib_error_at_line,
 
332
[AC_LINK_IFELSE([AC_LANG_PROGRAM([],[error_at_line (0, 0, "", 0, "");])],
 
333
                [ac_cv_lib_error_at_line=yes],
 
334
                [ac_cv_lib_error_at_line=no])])
 
335
if test $ac_cv_lib_error_at_line = no; then
 
336
  AC_LIBOBJ(error)
 
337
fi
 
338
])
 
339
 
 
340
 
 
341
# AU::AM_FUNC_ERROR_AT_LINE
 
342
# -------------------------
 
343
AU_ALIAS([AM_FUNC_ERROR_AT_LINE], [AC_FUNC_ERROR_AT_LINE])
 
344
 
 
345
 
 
346
# AC_FUNC_FNMATCH
 
347
# ---------------
 
348
# We look for fnmatch.h to avoid that the test fails in C++.
 
349
AC_DEFUN([AC_FUNC_FNMATCH],
 
350
[AC_CACHE_CHECK([for working GNU-style fnmatch],
 
351
                [ac_cv_func_fnmatch_works],
 
352
# Some versions of Solaris, SCO, and the GNU C Library
 
353
# have a broken or incompatible fnmatch.
 
354
# So we run a test program.  If we are cross-compiling, take no chance.
 
355
# Thanks to John Oleynick, Franc,ois Pinard, and Paul Eggert for this test.
 
356
[AC_RUN_IFELSE([AC_LANG_PROGRAM([@%:@include <fnmatch.h>],
 
357
 [exit (fnmatch ("a*", "abc", 0) != 0
 
358
        || fnmatch ("d*/*1", "d/s/1", FNM_FILE_NAME) != FNM_NOMATCH
 
359
        || fnmatch ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR) != 0
 
360
        || fnmatch ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR) != 0
 
361
        || fnmatch ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR) != 0);])],
 
362
               [ac_cv_func_fnmatch_works=yes],
 
363
               [ac_cv_func_fnmatch_works=no],
 
364
               [ac_cv_func_fnmatch_works=no])])
 
365
if test $ac_cv_func_fnmatch_works = yes; then
 
366
  AC_DEFINE(HAVE_FNMATCH, 1,
 
367
            [Define to 1 if your system has a working `fnmatch' function.])
 
368
fi
 
369
])# AC_FUNC_FNMATCH
 
370
 
 
371
 
 
372
# AU::AM_FUNC_FNMATCH
 
373
# AU::fp_FUNC_FNMATCH
 
374
# -------------------
 
375
AU_ALIAS([AM_FUNC_FNMATCH], [AC_FUNC_FNMATCH])
 
376
AU_ALIAS([fp_FUNC_FNMATCH], [AC_FUNC_FNMATCH])
 
377
 
 
378
 
 
379
# AC_FUNC_FSEEKO
 
380
# --------------
 
381
AC_DEFUN([AC_FUNC_FSEEKO],
 
382
[_AC_SYS_LARGEFILE_MACRO_VALUE(_LARGEFILE_SOURCE, 1,
 
383
   [ac_cv_sys_largefile_source],
 
384
   [Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2).],
 
385
   [@%:@include <stdio.h>], [return !fseeko;])
 
386
 
 
387
# We used to try defining _XOPEN_SOURCE=500 too, to work around a bug
 
388
# in glibc 2.1.3, but that breaks too many other things.
 
389
# If you want fseeko and ftello with glibc, upgrade to a fixed glibc.
 
390
AC_CACHE_CHECK([for fseeko], [ac_cv_func_fseeko],
 
391
[AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <stdio.h>],
 
392
                                 [[return fseeko && fseeko (stdin, 0, 0);]])],
 
393
                [ac_cv_func_fseeko=yes],
 
394
                [ac_cv_func_fseeko=no])])
 
395
if test $ac_cv_func_fseeko = yes; then
 
396
  AC_DEFINE(HAVE_FSEEKO, 1,
 
397
    [Define to 1 if fseeko (and presumably ftello) exists and is declared.])
 
398
fi
 
399
])# AC_FUNC_FSEEKO
 
400
 
 
401
 
 
402
# AC_FUNC_GETGROUPS
 
403
# -----------------
 
404
# Try to find `getgroups', and check that it works.
 
405
# When crosscompiling, assume getgroups is broken.
 
406
AC_DEFUN([AC_FUNC_GETGROUPS],
 
407
[AC_REQUIRE([AC_TYPE_GETGROUPS])dnl
 
408
AC_REQUIRE([AC_TYPE_SIZE_T])dnl
 
409
AC_CHECK_FUNC(getgroups)
 
410
 
 
411
# If we don't yet have getgroups, see if it's in -lbsd.
 
412
# This is reported to be necessary on an ITOS 3000WS running SEIUX 3.1.
 
413
ac_save_LIBS=$LIBS
 
414
if test $ac_cv_func_getgroups = no; then
 
415
  AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd])
 
416
fi
 
417
 
 
418
# Run the program to test the functionality of the system-supplied
 
419
# getgroups function only if there is such a function.
 
420
if test $ac_cv_func_getgroups = yes; then
 
421
  AC_CACHE_CHECK([for working getgroups], ac_cv_func_getgroups_works,
 
422
   [AC_RUN_IFELSE([AC_LANG_PROGRAM([],
 
423
      [[/* On Ultrix 4.3, getgroups (0, 0) always fails.  */
 
424
       exit (getgroups (0, 0) == -1 ? 1 : 0);]])],
 
425
                  [ac_cv_func_getgroups_works=yes],
 
426
                  [ac_cv_func_getgroups_works=no],
 
427
                  [ac_cv_func_getgroups_works=no])
 
428
   ])
 
429
  if test $ac_cv_func_getgroups_works = yes; then
 
430
    AC_DEFINE(HAVE_GETGROUPS, 1,
 
431
              [Define to 1 if your system has a working `getgroups' function.])
 
432
  fi
 
433
fi
 
434
LIBS=$ac_save_LIBS
 
435
])# AC_FUNC_GETGROUPS
 
436
 
 
437
 
 
438
# _AC_LIBOBJ_GETLOADAVG
 
439
# ---------------------
 
440
# Set up the AC_LIBOBJ replacement of `getloadavg'.
 
441
m4_define([_AC_LIBOBJ_GETLOADAVG],
 
442
[AC_LIBOBJ(getloadavg)
 
443
AC_DEFINE(C_GETLOADAVG, 1, [Define to 1 if using `getloadavg.c'.])
 
444
# Figure out what our getloadavg.c needs.
 
445
ac_have_func=no
 
446
AC_CHECK_HEADER(sys/dg_sys_info.h,
 
447
[ac_have_func=yes
 
448
 AC_DEFINE(DGUX, 1, [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
 
449
 AC_CHECK_LIB(dgc, dg_sys_info)])
 
450
 
 
451
AC_CHECK_HEADER(locale.h)
 
452
AC_CHECK_FUNCS(setlocale)
 
453
 
 
454
# We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
 
455
# uses stabs), but it is still SVR4.  We cannot check for <elf.h> because
 
456
# Irix 4.0.5F has the header but not the library.
 
457
if test $ac_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes; then
 
458
  ac_have_func=yes
 
459
  AC_DEFINE(SVR4, 1, [Define to 1 on System V Release 4.])
 
460
fi
 
461
 
 
462
if test $ac_have_func = no; then
 
463
  AC_CHECK_HEADER(inq_stats/cpustats.h,
 
464
  [ac_have_func=yes
 
465
   AC_DEFINE(UMAX, 1, [Define to 1 for Encore UMAX.])
 
466
   AC_DEFINE(UMAX4_3, 1,
 
467
             [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
 
468
              instead of <sys/cpustats.h>.])])
 
469
fi
 
470
 
 
471
if test $ac_have_func = no; then
 
472
  AC_CHECK_HEADER(sys/cpustats.h,
 
473
  [ac_have_func=yes; AC_DEFINE(UMAX)])
 
474
fi
 
475
 
 
476
if test $ac_have_func = no; then
 
477
  AC_CHECK_HEADERS(mach/mach.h)
 
478
fi
 
479
 
 
480
AC_CHECK_HEADERS(nlist.h,
 
481
[AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
 
482
                  [AC_DEFINE(NLIST_NAME_UNION, 1,
 
483
                             [Define to 1 if your `struct nlist' has an
 
484
                              `n_un' member.  Obsolete, depend on
 
485
                              `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [],
 
486
                  [@%:@include <nlist.h>])
 
487
])dnl
 
488
])# _AC_LIBOBJ_GETLOADAVG
 
489
 
 
490
 
 
491
# AC_FUNC_GETLOADAVG
 
492
# ------------------
 
493
AC_DEFUN([AC_FUNC_GETLOADAVG],
 
494
[ac_have_func=no # yes means we've found a way to get the load average.
 
495
 
 
496
ac_save_LIBS=$LIBS
 
497
 
 
498
# Check for getloadavg, but be sure not to touch the cache variable.
 
499
(AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && ac_have_func=yes
 
500
 
 
501
# On HPUX9, an unprivileged user can get load averages through this function.
 
502
AC_CHECK_FUNCS(pstat_getdynamic)
 
503
 
 
504
# Solaris has libkstat which does not require root.
 
505
AC_CHECK_LIB(kstat, kstat_open)
 
506
test $ac_cv_lib_kstat_kstat_open = yes && ac_have_func=yes
 
507
 
 
508
# Some systems with -lutil have (and need) -lkvm as well, some do not.
 
509
# On Solaris, -lkvm requires nlist from -lelf, so check that first
 
510
# to get the right answer into the cache.
 
511
# For kstat on solaris, we need libelf to force the definition of SVR4 below.
 
512
if test $ac_have_func = no; then
 
513
  AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
 
514
fi
 
515
if test $ac_have_func = no; then
 
516
  AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
 
517
  # Check for the 4.4BSD definition of getloadavg.
 
518
  AC_CHECK_LIB(util, getloadavg,
 
519
    [LIBS="-lutil $LIBS" ac_have_func=yes ac_cv_func_getloadavg_setgid=yes])
 
520
fi
 
521
 
 
522
if test $ac_have_func = no; then
 
523
  # There is a commonly available library for RS/6000 AIX.
 
524
  # Since it is not a standard part of AIX, it might be installed locally.
 
525
  ac_getloadavg_LIBS=$LIBS
 
526
  LIBS="-L/usr/local/lib $LIBS"
 
527
  AC_CHECK_LIB(getloadavg, getloadavg,
 
528
               [LIBS="-lgetloadavg $LIBS"], [LIBS=$ac_getloadavg_LIBS])
 
529
fi
 
530
 
 
531
# Make sure it is really in the library, if we think we found it,
 
532
# otherwise set up the replacement function.
 
533
AC_CHECK_FUNCS(getloadavg, [],
 
534
               [_AC_LIBOBJ_GETLOADAVG])
 
535
 
 
536
# Some definitions of getloadavg require that the program be installed setgid.
 
537
dnl FIXME: Don't hardwire the path of getloadavg.c in the top-level directory.
 
538
AC_CACHE_CHECK(whether getloadavg requires setgid,
 
539
               ac_cv_func_getloadavg_setgid,
 
540
[AC_EGREP_CPP([Yowza Am I SETGID yet],
 
541
[#include "$srcdir/getloadavg.c"
 
542
#ifdef LDAV_PRIVILEGED
 
543
Yowza Am I SETGID yet
 
544
@%:@endif],
 
545
              ac_cv_func_getloadavg_setgid=yes,
 
546
              ac_cv_func_getloadavg_setgid=no)])
 
547
if test $ac_cv_func_getloadavg_setgid = yes; then
 
548
  NEED_SETGID=true
 
549
  AC_DEFINE(GETLOADAVG_PRIVILEGED, 1,
 
550
            [Define to 1 if the `getloadavg' function needs to be run setuid
 
551
             or setgid.])
 
552
else
 
553
  NEED_SETGID=false
 
554
fi
 
555
AC_SUBST(NEED_SETGID)dnl
 
556
 
 
557
if test $ac_cv_func_getloadavg_setgid = yes; then
 
558
  AC_CACHE_CHECK(group of /dev/kmem, ac_cv_group_kmem,
 
559
[ # On Solaris, /dev/kmem is a symlink.  Get info on the real file.
 
560
  ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
 
561
  # If we got an error (system does not support symlinks), try without -L.
 
562
  test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
 
563
  ac_cv_group_kmem=`echo $ac_ls_output \
 
564
    | sed -ne ['s/[     ][      ]*/ /g;
 
565
               s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\)  *.*/\1/;
 
566
               / /s/.* //;p;']`
 
567
])
 
568
  AC_SUBST(KMEM_GROUP, $ac_cv_group_kmem)dnl
 
569
fi
 
570
if test "x$ac_save_LIBS" = x; then
 
571
  GETLOADAVG_LIBS=$LIBS
 
572
else
 
573
  GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$ac_save_LIBS!!"`
 
574
fi
 
575
LIBS=$ac_save_LIBS
 
576
 
 
577
AC_SUBST(GETLOADAVG_LIBS)dnl
 
578
])# AC_FUNC_GETLOADAVG
 
579
 
 
580
 
 
581
# AU::AC_GETLOADAVG
 
582
# -----------------
 
583
AU_ALIAS([AC_GETLOADAVG], [AC_FUNC_GETLOADAVG])
 
584
 
 
585
 
 
586
# AC_FUNC_GETMNTENT
 
587
# -----------------
 
588
AC_DEFUN([AC_FUNC_GETMNTENT],
 
589
[# getmntent is in -lsun on Irix 4, -lseq on Dynix/PTX, -lgen on Unixware.
 
590
AC_CHECK_LIB(sun, getmntent, LIBS="-lsun $LIBS",
 
591
  [AC_CHECK_LIB(seq, getmntent, LIBS="-lseq $LIBS",
 
592
    [AC_CHECK_LIB(gen, getmntent, LIBS="-lgen $LIBS")])])
 
593
AC_CHECK_FUNCS(getmntent)
 
594
])
 
595
 
 
596
 
 
597
# AC_FUNC_GETPGRP
 
598
# ---------------
 
599
# Figure out whether getpgrp requires zero arguments.
 
600
AC_DEFUN([AC_FUNC_GETPGRP],
 
601
[AC_CACHE_CHECK(whether getpgrp requires zero arguments,
 
602
 ac_cv_func_getpgrp_void,
 
603
[# Use it with a single arg.
 
604
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [getpgrp (0);])],
 
605
                  [ac_cv_func_getpgrp_void=no],
 
606
                  [ac_cv_func_getpgrp_void=yes])
 
607
])
 
608
if test $ac_cv_func_getpgrp_void = yes; then
 
609
  AC_DEFINE(GETPGRP_VOID, 1,
 
610
            [Define to 1 if the `getpgrp' function requires zero arguments.])
 
611
fi
 
612
])# AC_FUNC_GETPGRP
 
613
 
 
614
 
 
615
# AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
 
616
# -------------------------------------
 
617
# When crosscompiling, be pessimistic so we will end up using the
 
618
# replacement version of lstat that checkes for trailing slashes and
 
619
# calls lstat a second time when necessary.
 
620
AC_DEFUN([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
 
621
[AC_CACHE_CHECK(
 
622
       [whether lstat dereferences a symlink specified with a trailing slash],
 
623
       [ac_cv_func_lstat_dereferences_slashed_symlink],
 
624
[rm -f conftest.sym conftest.file
 
625
echo >conftest.file
 
626
if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then
 
627
  AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
 
628
    [struct stat sbuf;
 
629
     /* Linux will dereference the symlink and fail.
 
630
        That is better in the sense that it means we will not
 
631
        have to compile and use the lstat wrapper.  */
 
632
     exit (lstat ("conftest.sym/", &sbuf) ? 0 : 1);])],
 
633
                [ac_cv_func_lstat_dereferences_slashed_symlink=yes],
 
634
                [ac_cv_func_lstat_dereferences_slashed_symlink=no],
 
635
                [ac_cv_func_lstat_dereferences_slashed_symlink=no])
 
636
else
 
637
  # If the `ln -s' command failed, then we probably don't even
 
638
  # have an lstat function.
 
639
  ac_cv_func_lstat_dereferences_slashed_symlink=no
 
640
fi
 
641
rm -f conftest.sym conftest.file
 
642
])
 
643
 
 
644
test $ac_cv_func_lstat_dereferences_slashed_symlink = yes &&
 
645
  AC_DEFINE_UNQUOTED(LSTAT_FOLLOWS_SLASHED_SYMLINK, 1,
 
646
                     [Define to 1 if `lstat' dereferences a symlink specified
 
647
                      with a trailing slash.])
 
648
 
 
649
if test $ac_cv_func_lstat_dereferences_slashed_symlink = no; then
 
650
  AC_LIBOBJ(lstat)
 
651
fi
 
652
])
 
653
 
 
654
 
 
655
# AC_FUNC_MALLOC
 
656
# --------------
 
657
# Is `malloc (0)' properly handled?
 
658
AC_DEFUN([AC_FUNC_MALLOC],
 
659
[AC_REQUIRE([AC_HEADER_STDC])dnl
 
660
AC_CHECK_HEADERS(stdlib.h)
 
661
AC_CACHE_CHECK([for working malloc], ac_cv_func_malloc_works,
 
662
[AC_RUN_IFELSE(
 
663
[AC_LANG_PROGRAM(
 
664
[[#if STDC_HEADERS || HAVE_STDLIB_H
 
665
# include <stdlib.h>
 
666
#else
 
667
char *malloc ();
 
668
#endif
 
669
]],
 
670
                 [exit (malloc (0) ? 0 : 1);])],
 
671
               [ac_cv_func_malloc_works=yes],
 
672
               [ac_cv_func_malloc_works=no],
 
673
               [ac_cv_func_malloc_works=no])])
 
674
if test $ac_cv_func_malloc_works = yes; then
 
675
  AC_DEFINE(HAVE_MALLOC, 1,
 
676
            [Define to 1 if your system has a working `malloc' function.])
 
677
fi
 
678
])# AC_FUNC_MALLOC
 
679
 
 
680
 
 
681
# AC_FUNC_MEMCMP
 
682
# --------------
 
683
AC_DEFUN([AC_FUNC_MEMCMP],
 
684
[AC_CACHE_CHECK([for working memcmp], ac_cv_func_memcmp_working,
 
685
[AC_RUN_IFELSE([AC_LANG_PROGRAM([], [[
 
686
  /* Some versions of memcmp are not 8-bit clean.  */
 
687
  char c0 = 0x40, c1 = 0x80, c2 = 0x81;
 
688
  if (memcmp(&c0, &c2, 1) >= 0 || memcmp(&c1, &c2, 1) >= 0)
 
689
    exit (1);
 
690
 
 
691
  /* The Next x86 OpenStep bug shows up only when comparing 16 bytes
 
692
     or more and with at least one buffer not starting on a 4-byte boundary.
 
693
     William Lewis provided this test program.   */
 
694
  {
 
695
    char foo[21];
 
696
    char bar[21];
 
697
    int i;
 
698
    for (i = 0; i < 4; i++)
 
699
      {
 
700
        char *a = foo + i;
 
701
        char *b = bar + i;
 
702
        strcpy (a, "--------01111111");
 
703
        strcpy (b, "--------10000000");
 
704
        if (memcmp (a, b, 16) >= 0)
 
705
          exit (1);
 
706
      }
 
707
    exit (0);
 
708
  }
 
709
]])],
 
710
               [ac_cv_func_memcmp_working=yes],
 
711
               [ac_cv_func_memcmp_working=no],
 
712
               [ac_cv_func_memcmp_working=no])])
 
713
test $ac_cv_func_memcmp_working = no && AC_LIBOBJ([memcmp])
 
714
])# AC_FUNC_MEMCMP
 
715
 
 
716
 
 
717
# AC_FUNC_MKTIME
 
718
# --------------
 
719
AC_DEFUN([AC_FUNC_MKTIME],
 
720
[AC_REQUIRE([AC_HEADER_TIME])dnl
 
721
AC_CHECK_HEADERS(sys/time.h unistd.h)
 
722
AC_CHECK_FUNCS(alarm)
 
723
AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
 
724
[AC_RUN_IFELSE([AC_LANG_SOURCE(
 
725
[[/* Test program from Paul Eggert and Tony Leneis.  */
 
726
#if TIME_WITH_SYS_TIME
 
727
# include <sys/time.h>
 
728
# include <time.h>
 
729
#else
 
730
# if HAVE_SYS_TIME_H
 
731
#  include <sys/time.h>
 
732
# else
 
733
#  include <time.h>
 
734
# endif
 
735
#endif
 
736
 
 
737
#if HAVE_UNISTD_H
 
738
# include <unistd.h>
 
739
#endif
 
740
 
 
741
#if !HAVE_ALARM
 
742
# define alarm(X) /* empty */
 
743
#endif
 
744
 
 
745
/* Work around redefinition to rpl_putenv by other config tests.  */
 
746
#undef putenv
 
747
 
 
748
static time_t time_t_max;
 
749
 
 
750
/* Values we'll use to set the TZ environment variable.  */
 
751
static const char *const tz_strings[] = {
 
752
  (const char *) 0, "TZ=GMT0", "TZ=JST-9",
 
753
  "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
 
754
};
 
755
#define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
 
756
 
 
757
/* Fail if mktime fails to convert a date in the spring-forward gap.
 
758
   Based on a problem report from Andreas Jaeger.  */
 
759
static void
 
760
spring_forward_gap ()
 
761
{
 
762
  /* glibc (up to about 1998-10-07) failed this test. */
 
763
  struct tm tm;
 
764
 
 
765
  /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
 
766
     instead of "TZ=America/Vancouver" in order to detect the bug even
 
767
     on systems that don't support the Olson extension, or don't have the
 
768
     full zoneinfo tables installed.  */
 
769
  putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
 
770
 
 
771
  tm.tm_year = 98;
 
772
  tm.tm_mon = 3;
 
773
  tm.tm_mday = 5;
 
774
  tm.tm_hour = 2;
 
775
  tm.tm_min = 0;
 
776
  tm.tm_sec = 0;
 
777
  tm.tm_isdst = -1;
 
778
  if (mktime (&tm) == (time_t)-1)
 
779
    exit (1);
 
780
}
 
781
 
 
782
static void
 
783
mktime_test (now)
 
784
     time_t now;
 
785
{
 
786
  struct tm *lt;
 
787
  if ((lt = localtime (&now)) && mktime (lt) != now)
 
788
    exit (1);
 
789
  now = time_t_max - now;
 
790
  if ((lt = localtime (&now)) && mktime (lt) != now)
 
791
    exit (1);
 
792
}
 
793
 
 
794
static void
 
795
irix_6_4_bug ()
 
796
{
 
797
  /* Based on code from Ariel Faigon.  */
 
798
  struct tm tm;
 
799
  tm.tm_year = 96;
 
800
  tm.tm_mon = 3;
 
801
  tm.tm_mday = 0;
 
802
  tm.tm_hour = 0;
 
803
  tm.tm_min = 0;
 
804
  tm.tm_sec = 0;
 
805
  tm.tm_isdst = -1;
 
806
  mktime (&tm);
 
807
  if (tm.tm_mon != 2 || tm.tm_mday != 31)
 
808
    exit (1);
 
809
}
 
810
 
 
811
static void
 
812
bigtime_test (j)
 
813
     int j;
 
814
{
 
815
  struct tm tm;
 
816
  time_t now;
 
817
  tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
 
818
  now = mktime (&tm);
 
819
  if (now != (time_t) -1)
 
820
    {
 
821
      struct tm *lt = localtime (&now);
 
822
      if (! (lt
 
823
             && lt->tm_year == tm.tm_year
 
824
             && lt->tm_mon == tm.tm_mon
 
825
             && lt->tm_mday == tm.tm_mday
 
826
             && lt->tm_hour == tm.tm_hour
 
827
             && lt->tm_min == tm.tm_min
 
828
             && lt->tm_sec == tm.tm_sec
 
829
             && lt->tm_yday == tm.tm_yday
 
830
             && lt->tm_wday == tm.tm_wday
 
831
             && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
 
832
                  == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
 
833
        exit (1);
 
834
    }
 
835
}
 
836
 
 
837
int
 
838
main ()
 
839
{
 
840
  time_t t, delta;
 
841
  int i, j;
 
842
 
 
843
  /* This test makes some buggy mktime implementations loop.
 
844
     Give up after 60 seconds; a mktime slower than that
 
845
     isn't worth using anyway.  */
 
846
  alarm (60);
 
847
 
 
848
  for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
 
849
    continue;
 
850
  time_t_max--;
 
851
  delta = time_t_max / 997; /* a suitable prime number */
 
852
  for (i = 0; i < N_STRINGS; i++)
 
853
    {
 
854
      if (tz_strings[i])
 
855
        putenv (tz_strings[i]);
 
856
 
 
857
      for (t = 0; t <= time_t_max - delta; t += delta)
 
858
        mktime_test (t);
 
859
      mktime_test ((time_t) 60 * 60);
 
860
      mktime_test ((time_t) 60 * 60 * 24);
 
861
 
 
862
      for (j = 1; 0 < j; j *= 2)
 
863
        bigtime_test (j);
 
864
      bigtime_test (j - 1);
 
865
    }
 
866
  irix_6_4_bug ();
 
867
  spring_forward_gap ();
 
868
  exit (0);
 
869
}]])],
 
870
               [ac_cv_func_working_mktime=yes],
 
871
               [ac_cv_func_working_mktime=no],
 
872
               [ac_cv_func_working_mktime=no])])
 
873
if test $ac_cv_func_working_mktime = no; then
 
874
  AC_LIBOBJ([mktime])
 
875
fi
 
876
])# AC_FUNC_MKTIME
 
877
 
 
878
 
 
879
# AU::AM_FUNC_MKTIME
 
880
# ------------------
 
881
AU_ALIAS([AM_FUNC_MKTIME], [AC_FUNC_MKTIME])
 
882
 
 
883
 
 
884
# AC_FUNC_MMAP
 
885
# ------------
 
886
AC_DEFUN([AC_FUNC_MMAP],
 
887
[AC_CHECK_HEADERS(stdlib.h unistd.h)
 
888
AC_CHECK_FUNCS(getpagesize)
 
889
AC_CACHE_CHECK(for working mmap, ac_cv_func_mmap_fixed_mapped,
 
890
[AC_RUN_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT]
 
891
[[/* malloc might have been renamed as rpl_malloc. */
 
892
#undef malloc
 
893
 
 
894
/* Thanks to Mike Haertel and Jim Avera for this test.
 
895
   Here is a matrix of mmap possibilities:
 
896
        mmap private not fixed
 
897
        mmap private fixed at somewhere currently unmapped
 
898
        mmap private fixed at somewhere already mapped
 
899
        mmap shared not fixed
 
900
        mmap shared fixed at somewhere currently unmapped
 
901
        mmap shared fixed at somewhere already mapped
 
902
   For private mappings, we should verify that changes cannot be read()
 
903
   back from the file, nor mmap's back from the file at a different
 
904
   address.  (There have been systems where private was not correctly
 
905
   implemented like the infamous i386 svr4.0, and systems where the
 
906
   VM page cache was not coherent with the file system buffer cache
 
907
   like early versions of FreeBSD and possibly contemporary NetBSD.)
 
908
   For shared mappings, we should conversely verify that changes get
 
909
   propagated back to all the places they're supposed to be.
 
910
 
 
911
   Grep wants private fixed already mapped.
 
912
   The main things grep needs to know about mmap are:
 
913
   * does it exist and is it safe to write into the mmap'd area
 
914
   * how to use it (BSD variants)  */
 
915
 
 
916
#include <fcntl.h>
 
917
#include <sys/mman.h>
 
918
 
 
919
#if !STDC_HEADERS && !HAVE_STDLIB_H
 
920
char *malloc ();
 
921
#endif
 
922
 
 
923
/* This mess was copied from the GNU getpagesize.h.  */
 
924
#if !HAVE_GETPAGESIZE
 
925
/* Assume that all systems that can run configure have sys/param.h.  */
 
926
# if !HAVE_SYS_PARAM_H
 
927
#  define HAVE_SYS_PARAM_H 1
 
928
# endif
 
929
 
 
930
# ifdef _SC_PAGESIZE
 
931
#  define getpagesize() sysconf(_SC_PAGESIZE)
 
932
# else /* no _SC_PAGESIZE */
 
933
#  if HAVE_SYS_PARAM_H
 
934
#   include <sys/param.h>
 
935
#   ifdef EXEC_PAGESIZE
 
936
#    define getpagesize() EXEC_PAGESIZE
 
937
#   else /* no EXEC_PAGESIZE */
 
938
#    ifdef NBPG
 
939
#     define getpagesize() NBPG * CLSIZE
 
940
#     ifndef CLSIZE
 
941
#      define CLSIZE 1
 
942
#     endif /* no CLSIZE */
 
943
#    else /* no NBPG */
 
944
#     ifdef NBPC
 
945
#      define getpagesize() NBPC
 
946
#     else /* no NBPC */
 
947
#      ifdef PAGESIZE
 
948
#       define getpagesize() PAGESIZE
 
949
#      endif /* PAGESIZE */
 
950
#     endif /* no NBPC */
 
951
#    endif /* no NBPG */
 
952
#   endif /* no EXEC_PAGESIZE */
 
953
#  else /* no HAVE_SYS_PARAM_H */
 
954
#   define getpagesize() 8192   /* punt totally */
 
955
#  endif /* no HAVE_SYS_PARAM_H */
 
956
# endif /* no _SC_PAGESIZE */
 
957
 
 
958
#endif /* no HAVE_GETPAGESIZE */
 
959
 
 
960
int
 
961
main ()
 
962
{
 
963
  char *data, *data2, *data3;
 
964
  int i, pagesize;
 
965
  int fd;
 
966
 
 
967
  pagesize = getpagesize ();
 
968
 
 
969
  /* First, make a file with some known garbage in it. */
 
970
  data = (char *) malloc (pagesize);
 
971
  if (!data)
 
972
    exit (1);
 
973
  for (i = 0; i < pagesize; ++i)
 
974
    *(data + i) = rand ();
 
975
  umask (0);
 
976
  fd = creat ("conftest.mmap", 0600);
 
977
  if (fd < 0)
 
978
    exit (1);
 
979
  if (write (fd, data, pagesize) != pagesize)
 
980
    exit (1);
 
981
  close (fd);
 
982
 
 
983
  /* Next, try to mmap the file at a fixed address which already has
 
984
     something else allocated at it.  If we can, also make sure that
 
985
     we see the same garbage.  */
 
986
  fd = open ("conftest.mmap", O_RDWR);
 
987
  if (fd < 0)
 
988
    exit (1);
 
989
  data2 = (char *) malloc (2 * pagesize);
 
990
  if (!data2)
 
991
    exit (1);
 
992
  data2 += (pagesize - ((int) data2 & (pagesize - 1))) & (pagesize - 1);
 
993
  if (data2 != mmap (data2, pagesize, PROT_READ | PROT_WRITE,
 
994
                     MAP_PRIVATE | MAP_FIXED, fd, 0L))
 
995
    exit (1);
 
996
  for (i = 0; i < pagesize; ++i)
 
997
    if (*(data + i) != *(data2 + i))
 
998
      exit (1);
 
999
 
 
1000
  /* Finally, make sure that changes to the mapped area do not
 
1001
     percolate back to the file as seen by read().  (This is a bug on
 
1002
     some variants of i386 svr4.0.)  */
 
1003
  for (i = 0; i < pagesize; ++i)
 
1004
    *(data2 + i) = *(data2 + i) + 1;
 
1005
  data3 = (char *) malloc (pagesize);
 
1006
  if (!data3)
 
1007
    exit (1);
 
1008
  if (read (fd, data3, pagesize) != pagesize)
 
1009
    exit (1);
 
1010
  for (i = 0; i < pagesize; ++i)
 
1011
    if (*(data + i) != *(data3 + i))
 
1012
      exit (1);
 
1013
  close (fd);
 
1014
  exit (0);
 
1015
}]])],
 
1016
               [ac_cv_func_mmap_fixed_mapped=yes],
 
1017
               [ac_cv_func_mmap_fixed_mapped=no],
 
1018
               [ac_cv_func_mmap_fixed_mapped=no])])
 
1019
if test $ac_cv_func_mmap_fixed_mapped = yes; then
 
1020
  AC_DEFINE(HAVE_MMAP, 1,
 
1021
            [Define to 1 if you have a working `mmap' system call.])
 
1022
fi
 
1023
rm -f conftest.mmap
 
1024
])# AC_FUNC_MMAP
 
1025
 
 
1026
 
 
1027
# AU::AC_MMAP
 
1028
# -----------
 
1029
AU_ALIAS([AC_MMAP], [AC_FUNC_MMAP])
 
1030
 
 
1031
 
 
1032
# AC_FUNC_OBSTACK
 
1033
# ---------------
 
1034
# Ensure obstack support.  Yeah, this is not exactly a `FUNC' check.
 
1035
AC_DEFUN([AC_FUNC_OBSTACK],
 
1036
[AC_LIBSOURCES([obstack.h, obstack.c])dnl
 
1037
AC_CACHE_CHECK([for obstacks], ac_cv_func_obstack,
 
1038
[AC_LINK_IFELSE(
 
1039
    [AC_LANG_PROGRAM([[@%:@include "obstack.h"]],
 
1040
                     [[struct obstack *mem; obstack_free(mem,(char *) 0)]])],
 
1041
                [ac_cv_func_obstack=yes],
 
1042
                [ac_cv_func_obstack=no])])
 
1043
if test $ac_cv_func_obstack = yes; then
 
1044
  AC_DEFINE(HAVE_OBSTACK, 1, [Define to 1 if libc includes obstacks.])
 
1045
else
 
1046
  AC_LIBOBJ(obstack)
 
1047
fi
 
1048
])# AC_FUNC_OBSTACK
 
1049
 
 
1050
 
 
1051
# AU::AM_FUNC_OBSTACK
 
1052
# -------------------
 
1053
AU_ALIAS([AM_FUNC_OBSTACK], [AC_FUNC_OBSTACK])
 
1054
 
 
1055
 
 
1056
# AC_FUNC_SELECT_ARGTYPES
 
1057
# -----------------------
 
1058
# Determine the correct type to be passed to each of the `select'
 
1059
# function's arguments, and define those types in `SELECT_TYPE_ARG1',
 
1060
# `SELECT_TYPE_ARG234', and `SELECT_TYPE_ARG5'.
 
1061
AC_DEFUN([AC_FUNC_SELECT_ARGTYPES],
 
1062
[AC_CHECK_HEADERS(sys/select.h sys/socket.h)
 
1063
AC_CACHE_CHECK([types of arguments for select],
 
1064
[ac_cv_func_select_args],
 
1065
[for ac_arg234 in 'fd_set *' 'int *' 'void *'; do
 
1066
 for ac_arg1 in 'int' 'size_t' 'unsigned long' 'unsigned'; do
 
1067
  for ac_arg5 in 'struct timeval *' 'const struct timeval *'; do
 
1068
   AC_COMPILE_IFELSE(
 
1069
       [AC_LANG_PROGRAM(
 
1070
[AC_INCLUDES_DEFAULT
 
1071
#if HAVE_SYS_SELECT_H
 
1072
# include <sys/select.h>
 
1073
#endif
 
1074
#if HAVE_SYS_SOCKET_H
 
1075
# include <sys/socket.h>
 
1076
#endif
 
1077
],
 
1078
                        [extern int select ($ac_arg1,
 
1079
                                            $ac_arg234, $ac_arg234, $ac_arg234,
 
1080
                                            $ac_arg5);])],
 
1081
              [ac_cv_func_select_args="$ac_arg1,$ac_arg234,$ac_arg5"; break 3])
 
1082
  done
 
1083
 done
 
1084
done
 
1085
# Provide a safe default value.
 
1086
: ${ac_cv_func_select_args='int,int *,struct timeval *'}
 
1087
])
 
1088
ac_save_IFS=$IFS; IFS=','
 
1089
set dummy `echo "$ac_cv_func_select_args" | sed 's/\*/\*/g'`
 
1090
IFS=$ac_save_IFS
 
1091
shift
 
1092
AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG1, $[1],
 
1093
                   [Define to the type of arg 1 for `select'.])
 
1094
AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG234, ($[2]),
 
1095
                   [Define to the type of args 2, 3 and 4 for `select'.])
 
1096
AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG5, ($[3]),
 
1097
                   [Define to the type of arg 5 for `select'.])
 
1098
rm -f conftest*
 
1099
])# AC_FUNC_SELECT_ARGTYPES
 
1100
 
 
1101
 
 
1102
# AC_FUNC_SETPGRP
 
1103
# ---------------
 
1104
AC_DEFUN([AC_FUNC_SETPGRP],
 
1105
[AC_CACHE_CHECK(whether setpgrp takes no argument, ac_cv_func_setpgrp_void,
 
1106
[AC_RUN_IFELSE(
 
1107
[AC_LANG_PROGRAM(
 
1108
[#if HAVE_UNISTD_H
 
1109
# include <unistd.h>
 
1110
#endif
 
1111
],
 
1112
[/* If this system has a BSD-style setpgrp which takes arguments,
 
1113
  setpgrp(1, 1) will fail with ESRCH and return -1, in that case
 
1114
  exit successfully. */
 
1115
  exit (setpgrp (1,1) == -1 ? 0 : 1);])],
 
1116
               [ac_cv_func_setpgrp_void=no],
 
1117
               [ac_cv_func_setpgrp_void=yes],
 
1118
               [AC_MSG_ERROR([cannot check setpgrp when cross compiling])])])
 
1119
if test $ac_cv_func_setpgrp_void = yes; then
 
1120
  AC_DEFINE(SETPGRP_VOID, 1,
 
1121
            [Define to 1 if the `setpgrp' function takes no argument.])
 
1122
fi
 
1123
])# AC_FUNC_SETPGRP
 
1124
 
 
1125
 
 
1126
# _AC_FUNC_STAT(STAT | LSTAT)
 
1127
# ---------------------------
 
1128
# Determine whether stat or lstat have the bug that it succeeds when
 
1129
# given the zero-length file name argument.  The stat and lstat from
 
1130
# SunOS4.1.4 and the Hurd (as of 1998-11-01) do this.
 
1131
#
 
1132
# If it does, then define HAVE_STAT_EMPTY_STRING_BUG (or
 
1133
# HAVE_LSTAT_EMPTY_STRING_BUG) and arrange to compile the wrapper
 
1134
# function.
 
1135
m4_define([_AC_FUNC_STAT],
 
1136
[AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])dnl
 
1137
AC_CACHE_CHECK([whether $1 accepts an empty string],
 
1138
               [ac_cv_func_$1_empty_string_bug],
 
1139
[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
 
1140
[[struct stat sbuf;
 
1141
  exit ($1 ("", &sbuf) ? 1 : 0);]])],
 
1142
            [ac_cv_func_$1_empty_string_bug=yes],
 
1143
            [ac_cv_func_$1_empty_string_bug=no],
 
1144
            [ac_cv_func_$1_empty_string_bug=yes])])
 
1145
if test $ac_cv_func_$1_empty_string_bug = yes; then
 
1146
  AC_LIBOBJ([$1])
 
1147
  AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1_EMPTY_STRING_BUG]), 1,
 
1148
                     [Define to 1 if `$1' has the bug that it succeeds when
 
1149
                      given the zero-length file name argument.])
 
1150
fi
 
1151
])# _AC_FUNC_STAT
 
1152
 
 
1153
 
 
1154
# AC_FUNC_STAT & AC_FUNC_LSTAT
 
1155
# ----------------------------
 
1156
AC_DEFUN([AC_FUNC_STAT],  [_AC_FUNC_STAT(stat)])
 
1157
AC_DEFUN([AC_FUNC_LSTAT], [_AC_FUNC_STAT(lstat)])
 
1158
 
 
1159
 
 
1160
# _AC_LIBOBJ_STRTOD
 
1161
# -----------------
 
1162
m4_define([_AC_LIBOBJ_STRTOD],
 
1163
[AC_LIBOBJ(strtod)
 
1164
AC_CHECK_FUNC(pow)
 
1165
if test $ac_cv_func_pow = no; then
 
1166
  AC_CHECK_LIB(m, pow,
 
1167
               [POW_LIB=-lm],
 
1168
               [AC_MSG_WARN([cannot find library containing definition of pow])])
 
1169
fi
 
1170
])# _AC_LIBOBJ_STRTOD
 
1171
 
 
1172
 
 
1173
# AC_FUNC_STRTOD
 
1174
# --------------
 
1175
AC_DEFUN([AC_FUNC_STRTOD],
 
1176
[AC_SUBST(POW_LIB)dnl
 
1177
AC_CACHE_CHECK(for working strtod, ac_cv_func_strtod,
 
1178
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
 
1179
double strtod ();
 
1180
int
 
1181
main()
 
1182
{
 
1183
  {
 
1184
    /* Some versions of Linux strtod mis-parse strings with leading '+'.  */
 
1185
    char *string = " +69";
 
1186
    char *term;
 
1187
    double value;
 
1188
    value = strtod (string, &term);
 
1189
    if (value != 69 || term != (string + 4))
 
1190
      exit (1);
 
1191
  }
 
1192
 
 
1193
  {
 
1194
    /* Under Solaris 2.4, strtod returns the wrong value for the
 
1195
       terminating character under some conditions.  */
 
1196
    char *string = "NaN";
 
1197
    char *term;
 
1198
    strtod (string, &term);
 
1199
    if (term != string && *(term - 1) == 0)
 
1200
      exit (1);
 
1201
  }
 
1202
  exit (0);
 
1203
}
 
1204
]])],
 
1205
               ac_cv_func_strtod=yes,
 
1206
               ac_cv_func_strtod=no,
 
1207
               ac_cv_func_strtod=no)])
 
1208
if test $ac_cv_func_strtod = no; then
 
1209
  _AC_LIBOBJ_STRTOD
 
1210
fi
 
1211
])
 
1212
 
 
1213
 
 
1214
# AU::AM_FUNC_STRTOD
 
1215
# ------------------
 
1216
AU_ALIAS([AM_FUNC_STRTOD], [AC_FUNC_STRTOD])
 
1217
 
 
1218
 
 
1219
# AC_FUNC_STRERROR_R
 
1220
# ------------------
 
1221
AC_DEFUN([AC_FUNC_STRERROR_R],
 
1222
[AC_CHECK_DECLS([strerror_r])
 
1223
AC_CHECK_FUNCS([strerror_r])
 
1224
AC_CACHE_CHECK([whether strerror_r returns char *],
 
1225
               ac_cv_func_strerror_r_char_p,
 
1226
   [
 
1227
    ac_cv_func_strerror_r_char_p=no
 
1228
    if test $ac_cv_have_decl_strerror_r = yes; then
 
1229
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
 
1230
        [[
 
1231
          char buf[100];
 
1232
          char x = *strerror_r (0, buf, sizeof buf);
 
1233
          char *p = strerror_r (0, buf, sizeof buf);
 
1234
        ]])],
 
1235
                        ac_cv_func_strerror_r_char_p=yes)
 
1236
    else
 
1237
      # strerror_r is not declared.  Choose between
 
1238
      # systems that have relatively inaccessible declarations for the
 
1239
      # function.  BeOS and DEC UNIX 4.0 fall in this category, but the
 
1240
      # former has a strerror_r that returns char*, while the latter
 
1241
      # has a strerror_r that returns `int'.
 
1242
      # This test should segfault on the DEC system.
 
1243
      AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
 
1244
        extern char *strerror_r ();],
 
1245
        [[char buf[100];
 
1246
          char x = *strerror_r (0, buf, sizeof buf);
 
1247
          exit (!isalpha (x));]])],
 
1248
                    ac_cv_func_strerror_r_char_p=yes, , :)
 
1249
    fi
 
1250
  ])
 
1251
if test $ac_cv_func_strerror_r_char_p = yes; then
 
1252
  AC_DEFINE([STRERROR_R_CHAR_P], 1,
 
1253
            [Define to 1 if strerror_r returns char *.])
 
1254
fi
 
1255
])# AC_FUNC_STRERROR_R
 
1256
 
 
1257
 
 
1258
# AC_FUNC_STRFTIME
 
1259
# ----------------
 
1260
AC_DEFUN([AC_FUNC_STRFTIME],
 
1261
[AC_CHECK_FUNCS(strftime, [],
 
1262
[# strftime is in -lintl on SCO UNIX.
 
1263
AC_CHECK_LIB(intl, strftime,
 
1264
             [AC_DEFINE(HAVE_STRFTIME)
 
1265
LIBS="-lintl $LIBS"])])dnl
 
1266
])# AC_FUNC_STRFTIME
 
1267
 
 
1268
 
 
1269
# AC_FUNC_STRNLEN
 
1270
# --------------
 
1271
AC_DEFUN([AC_FUNC_STRNLEN],
 
1272
[AC_CACHE_CHECK([for working strnlen], ac_cv_func_strnlen_working,
 
1273
[AC_RUN_IFELSE([AC_LANG_PROGRAM([], [[
 
1274
#define S "foobar"
 
1275
#define S_LEN (sizeof S - 1)
 
1276
 
 
1277
  /* At least one implementation is buggy: that of AIX 4.3 would
 
1278
     give strnlen (S, 1) == 3.  */
 
1279
 
 
1280
  int i;
 
1281
  for (i = 0; i < S_LEN + 1; ++i)
 
1282
    {
 
1283
      int expected = i <= S_LEN ? i : S_LEN;
 
1284
      if (strnlen (S, i) != expected)
 
1285
        exit (1);
 
1286
    }
 
1287
  exit (0);
 
1288
]])],
 
1289
               [ac_cv_func_strnlen_working=yes],
 
1290
               [ac_cv_func_strnlen_working=no],
 
1291
               [ac_cv_func_strnlen_working=no])])
 
1292
test $ac_cv_func_strnlen_working = no && AC_LIBOBJ([strnlen])
 
1293
])# AC_FUNC_STRNLEN
 
1294
 
 
1295
 
 
1296
# AC_FUNC_SETVBUF_REVERSED
 
1297
# ------------------------
 
1298
AC_DEFUN([AC_FUNC_SETVBUF_REVERSED],
 
1299
[AC_CACHE_CHECK(whether setvbuf arguments are reversed,
 
1300
  ac_cv_func_setvbuf_reversed,
 
1301
[AC_TRY_RUN([#include <stdio.h>
 
1302
/* If setvbuf has the reversed format, exit 0. */
 
1303
int
 
1304
main ()
 
1305
{
 
1306
  /* This call has the arguments reversed.
 
1307
     A reversed system may check and see that the address of main
 
1308
     is not _IOLBF, _IONBF, or _IOFBF, and return nonzero.  */
 
1309
  if (setvbuf(stdout, _IOLBF, (char *) main, BUFSIZ) != 0)
 
1310
    exit(1);
 
1311
  putc('\r', stdout);
 
1312
  exit(0);                      /* Non-reversed systems segv here.  */
 
1313
}], ac_cv_func_setvbuf_reversed=yes, ac_cv_func_setvbuf_reversed=no)
 
1314
rm -f core core.* *.core])
 
1315
if test $ac_cv_func_setvbuf_reversed = yes; then
 
1316
  AC_DEFINE(SETVBUF_REVERSED, 1,
 
1317
            [Define to 1 if the `setvbuf' function takes the buffering type as
 
1318
             its second argument and the buffer pointer as the third, as on
 
1319
             System V before release 3.])
 
1320
fi
 
1321
])# AC_FUNC_SETVBUF_REVERSED
 
1322
 
 
1323
 
 
1324
# AU::AC_SETVBUF_REVERSED
 
1325
# -----------------------
 
1326
AU_ALIAS([AC_SETVBUF_REVERSED], [AC_FUNC_SETVBUF_REVERSED])
 
1327
 
 
1328
 
 
1329
# AC_FUNC_STRCOLL
 
1330
# ---------------
 
1331
AC_DEFUN([AC_FUNC_STRCOLL],
 
1332
[AC_CACHE_CHECK(for working strcoll, ac_cv_func_strcoll_works,
 
1333
[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
 
1334
  [[exit (strcoll ("abc", "def") >= 0 ||
 
1335
         strcoll ("ABC", "DEF") >= 0 ||
 
1336
         strcoll ("123", "456") >= 0)]])],
 
1337
               ac_cv_func_strcoll_works=yes,
 
1338
               ac_cv_func_strcoll_works=no,
 
1339
               ac_cv_func_strcoll_works=no)])
 
1340
if test $ac_cv_func_strcoll_works = yes; then
 
1341
  AC_DEFINE(HAVE_STRCOLL, 1,
 
1342
            [Define to 1 if you have the `strcoll' function and it is properly
 
1343
             defined.])
 
1344
fi
 
1345
])# AC_FUNC_STRCOLL
 
1346
 
 
1347
 
 
1348
# AU::AC_STRCOLL
 
1349
# --------------
 
1350
AU_ALIAS([AC_STRCOLL], [AC_FUNC_STRCOLL])
 
1351
 
 
1352
 
 
1353
# AC_FUNC_UTIME_NULL
 
1354
# ------------------
 
1355
AC_DEFUN([AC_FUNC_UTIME_NULL],
 
1356
[AC_CACHE_CHECK(whether utime accepts a null argument, ac_cv_func_utime_null,
 
1357
[rm -f conftest.data; >conftest.data
 
1358
# Sequent interprets utime(file, 0) to mean use start of epoch.  Wrong.
 
1359
AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
 
1360
[[struct stat s, t;
 
1361
  exit (!(stat ("conftest.data", &s) == 0
 
1362
          && utime ("conftest.data", (long *)0) == 0
 
1363
          && stat ("conftest.data", &t) == 0
 
1364
          && t.st_mtime >= s.st_mtime
 
1365
          && t.st_mtime - s.st_mtime < 120));]])],
 
1366
              ac_cv_func_utime_null=yes,
 
1367
              ac_cv_func_utime_null=no,
 
1368
              ac_cv_func_utime_null=no)
 
1369
rm -f core core.* *.core])
 
1370
if test $ac_cv_func_utime_null = yes; then
 
1371
  AC_DEFINE(HAVE_UTIME_NULL, 1,
 
1372
            [Define to 1 if `utime(file, NULL)' sets file's timestamp to the
 
1373
             present.])
 
1374
fi
 
1375
rm -f conftest.data
 
1376
])# AC_FUNC_UTIME_NULL
 
1377
 
 
1378
 
 
1379
# AU::AC_UTIME_NULL
 
1380
# -----------------
 
1381
AU_ALIAS([AC_UTIME_NULL], [AC_FUNC_UTIME_NULL])
 
1382
 
 
1383
 
 
1384
# AC_FUNC_FORK
 
1385
# -------------
 
1386
AC_DEFUN([AC_FUNC_FORK],
 
1387
[AC_REQUIRE([AC_TYPE_PID_T])dnl
 
1388
AC_CHECK_HEADERS(unistd.h vfork.h)
 
1389
AC_CHECK_FUNCS(fork vfork)
 
1390
ac_cv_func_fork_works=$ac_cv_func_fork
 
1391
if test "x$ac_cv_func_fork" = xyes; then
 
1392
  _AC_FUNC_FORK
 
1393
fi
 
1394
if test "x$ac_cv_func_fork_works" = xcross; then
 
1395
  case $host in
 
1396
    *-*-amigaos* | *-*-msdosdjgpp*)
 
1397
      # Override, as these systems have only a dummy fork() stub
 
1398
      ac_cv_func_fork_works=no
 
1399
      ;;
 
1400
    *)
 
1401
      ac_cv_func_fork_works=yes
 
1402
      ;;
 
1403
  esac
 
1404
  AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
 
1405
fi
 
1406
ac_cv_func_vfork_works=$ac_cv_func_vfork
 
1407
if test "x$ac_cv_func_vfork" = xyes; then
 
1408
  _AC_FUNC_VFORK
 
1409
fi;
 
1410
if test "x$ac_cv_func_fork_works" = xcross; then
 
1411
  ac_cv_func_vfork_works=ac_cv_func_vfork
 
1412
  AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
 
1413
fi
 
1414
 
 
1415
if test "x$ac_cv_func_vfork_works" = xyes; then
 
1416
  AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
 
1417
else
 
1418
  AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
 
1419
fi
 
1420
if test "x$ac_cv_func_fork_works" = xyes; then
 
1421
  AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
 
1422
fi
 
1423
])# AC_FUNC_FORK
 
1424
 
 
1425
 
 
1426
# _AC_FUNC_FORK
 
1427
# -------------
 
1428
AC_DEFUN([_AC_FUNC_FORK],
 
1429
  [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
 
1430
    [AC_RUN_IFELSE([/* By Ruediger Kuhlmann. */
 
1431
      #include <sys/types.h>
 
1432
      #if HAVE_UNISTD_H
 
1433
      # include <unistd.h>
 
1434
      #endif
 
1435
      /* Some systems only have a dummy stub for fork() */
 
1436
      int main ()
 
1437
      {
 
1438
        if (fork() < 0)
 
1439
          exit (1);
 
1440
        exit (0);
 
1441
      }],
 
1442
    [ac_cv_func_fork_works=yes],
 
1443
    [ac_cv_func_fork_works=no],
 
1444
    [ac_cv_func_fork_works=cross])])]
 
1445
)# _AC_FUNC_FORK
 
1446
 
 
1447
 
 
1448
# _AC_FUNC_VFORK
 
1449
# -------------
 
1450
AC_DEFUN([_AC_FUNC_VFORK],
 
1451
[AC_CACHE_CHECK(for working vfork, ac_cv_func_vfork_works,
 
1452
[AC_TRY_RUN([/* Thanks to Paul Eggert for this test.  */
 
1453
#include <stdio.h>
 
1454
#include <sys/types.h>
 
1455
#include <sys/stat.h>
 
1456
#if HAVE_UNISTD_H
 
1457
# include <unistd.h>
 
1458
#endif
 
1459
#if HAVE_VFORK_H
 
1460
# include <vfork.h>
 
1461
#endif
 
1462
/* On some sparc systems, changes by the child to local and incoming
 
1463
   argument registers are propagated back to the parent.  The compiler
 
1464
   is told about this with #include <vfork.h>, but some compilers
 
1465
   (e.g. gcc -O) don't grok <vfork.h>.  Test for this by using a
 
1466
   static variable whose address is put into a register that is
 
1467
   clobbered by the vfork.  */
 
1468
static
 
1469
#ifdef __cplusplus
 
1470
sparc_address_test (int arg)
 
1471
# else
 
1472
sparc_address_test (arg) int arg;
 
1473
#endif
 
1474
{
 
1475
  static pid_t child;
 
1476
  if (!child) {
 
1477
    child = vfork ();
 
1478
    if (child < 0) {
 
1479
      perror ("vfork");
 
1480
      _exit(2);
 
1481
    }
 
1482
    if (!child) {
 
1483
      arg = getpid();
 
1484
      write(-1, "", 0);
 
1485
      _exit (arg);
 
1486
    }
 
1487
  }
 
1488
}
 
1489
 
 
1490
int
 
1491
main ()
 
1492
{
 
1493
  pid_t parent = getpid ();
 
1494
  pid_t child;
 
1495
 
 
1496
  sparc_address_test ();
 
1497
 
 
1498
  child = vfork ();
 
1499
 
 
1500
  if (child == 0) {
 
1501
    /* Here is another test for sparc vfork register problems.  This
 
1502
       test uses lots of local variables, at least as many local
 
1503
       variables as main has allocated so far including compiler
 
1504
       temporaries.  4 locals are enough for gcc 1.40.3 on a Solaris
 
1505
       4.1.3 sparc, but we use 8 to be safe.  A buggy compiler should
 
1506
       reuse the register of parent for one of the local variables,
 
1507
       since it will think that parent can't possibly be used any more
 
1508
       in this routine.  Assigning to the local variable will thus
 
1509
       munge parent in the parent process.  */
 
1510
    pid_t
 
1511
      p = getpid(), p1 = getpid(), p2 = getpid(), p3 = getpid(),
 
1512
      p4 = getpid(), p5 = getpid(), p6 = getpid(), p7 = getpid();
 
1513
    /* Convince the compiler that p..p7 are live; otherwise, it might
 
1514
       use the same hardware register for all 8 local variables.  */
 
1515
    if (p != p1 || p != p2 || p != p3 || p != p4
 
1516
        || p != p5 || p != p6 || p != p7)
 
1517
      _exit(1);
 
1518
 
 
1519
    /* On some systems (e.g. IRIX 3.3), vfork doesn't separate parent
 
1520
       from child file descriptors.  If the child closes a descriptor
 
1521
       before it execs or exits, this munges the parent's descriptor
 
1522
       as well.  Test for this by closing stdout in the child.  */
 
1523
    _exit(close(fileno(stdout)) != 0);
 
1524
  } else {
 
1525
    int status;
 
1526
    struct stat st;
 
1527
 
 
1528
    while (wait(&status) != child)
 
1529
      ;
 
1530
    exit(
 
1531
         /* Was there some problem with vforking?  */
 
1532
         child < 0
 
1533
 
 
1534
         /* Did the child fail?  (This shouldn't happen.)  */
 
1535
         || status
 
1536
 
 
1537
         /* Did the vfork/compiler bug occur?  */
 
1538
         || parent != getpid()
 
1539
 
 
1540
         /* Did the file descriptor bug occur?  */
 
1541
         || fstat(fileno(stdout), &st) != 0
 
1542
         );
 
1543
  }
 
1544
}],
 
1545
            [ac_cv_func_vfork_works=yes],
 
1546
            [ac_cv_func_vfork_works=no],
 
1547
            [ac_cv_func_vfork_works=cross])])
 
1548
])# _AC_FUNC_VFORK
 
1549
 
 
1550
 
 
1551
# AU::AC_FUNC_VFORK
 
1552
# ------------
 
1553
AU_ALIAS([AC_FUNC_VFORK], [AC_FUNC_FORK])
 
1554
 
 
1555
# AU::AC_VFORK
 
1556
# ------------
 
1557
AU_ALIAS([AC_VFORK], [AC_FUNC_FORK])
 
1558
 
 
1559
 
 
1560
# AC_FUNC_VPRINTF
 
1561
# ---------------
 
1562
# Why the heck is that _doprnt does not define HAVE__DOPRNT???
 
1563
# That the logical name!
 
1564
AC_DEFUN([AC_FUNC_VPRINTF],
 
1565
[AC_CHECK_FUNCS(vprintf, []
 
1566
[AC_CHECK_FUNC(_doprnt,
 
1567
               [AC_DEFINE(HAVE_DOPRNT, 1,
 
1568
                          [Define to 1 if you don't have `vprintf' but do have
 
1569
                          `_doprnt.'])])])
 
1570
])
 
1571
 
 
1572
 
 
1573
# AU::AC_VPRINTF
 
1574
# --------------
 
1575
AU_ALIAS([AC_VPRINTF], [AC_FUNC_VPRINTF])
 
1576
 
 
1577
 
 
1578
# AC_FUNC_WAIT3
 
1579
# -------------
 
1580
# Don't bother too hard maintaining this macro, as it's obsoleted.
 
1581
# We don't AU define it, since we don't have any alternative to propose,
 
1582
# any invocation should be removed, and the code adjusted.
 
1583
AC_DEFUN([AC_FUNC_WAIT3],
 
1584
[AC_DIAGNOSE([obsolete],
 
1585
[$0: `wait3' is being removed from the Open Group standards.
 
1586
Remove this `AC_FUNC_WAIT3' and adjust your code to use `waitpid' instead.])dnl
 
1587
AC_CACHE_CHECK([for wait3 that fills in rusage],
 
1588
               [ac_cv_func_wait3_rusage],
 
1589
[AC_RUN_IFELSE([AC_LANG_SOURCE(
 
1590
[[#include <sys/types.h>
 
1591
#include <sys/time.h>
 
1592
#include <sys/resource.h>
 
1593
#include <stdio.h>
 
1594
/* HP-UX has wait3 but does not fill in rusage at all.  */
 
1595
int
 
1596
main ()
 
1597
{
 
1598
  struct rusage r;
 
1599
  int i;
 
1600
  /* Use a field that we can force nonzero --
 
1601
     voluntary context switches.
 
1602
     For systems like NeXT and OSF/1 that don't set it,
 
1603
     also use the system CPU time.  And page faults (I/O) for Linux.  */
 
1604
  r.ru_nvcsw = 0;
 
1605
  r.ru_stime.tv_sec = 0;
 
1606
  r.ru_stime.tv_usec = 0;
 
1607
  r.ru_majflt = r.ru_minflt = 0;
 
1608
  switch (fork ())
 
1609
    {
 
1610
    case 0: /* Child.  */
 
1611
      sleep(1); /* Give up the CPU.  */
 
1612
      _exit(0);
 
1613
      break;
 
1614
    case -1: /* What can we do?  */
 
1615
      _exit(0);
 
1616
      break;
 
1617
    default: /* Parent.  */
 
1618
      wait3(&i, 0, &r);
 
1619
      /* Avoid "text file busy" from rm on fast HP-UX machines.  */
 
1620
      sleep(2);
 
1621
      exit (r.ru_nvcsw == 0 && r.ru_majflt == 0 && r.ru_minflt == 0
 
1622
            && r.ru_stime.tv_sec == 0 && r.ru_stime.tv_usec == 0);
 
1623
    }
 
1624
}]])],
 
1625
               [ac_cv_func_wait3_rusage=yes],
 
1626
               [ac_cv_func_wait3_rusage=no],
 
1627
               [ac_cv_func_wait3_rusage=no])])
 
1628
if test $ac_cv_func_wait3_rusage = yes; then
 
1629
  AC_DEFINE(HAVE_WAIT3, 1,
 
1630
            [Define to 1 if you have the `wait3' system call.
 
1631
             Deprecated, you should no longer depend upon `wait3'.])
 
1632
fi
 
1633
])# AC_FUNC_WAIT3
 
1634
 
 
1635
 
 
1636
# AU::AC_WAIT3
 
1637
# ------------
 
1638
AU_ALIAS([AC_WAIT3], [AC_FUNC_WAIT3])