xref: /netbsd-src/external/gpl3/autoconf/dist/lib/autoconf/types.m4 (revision d874e91932377fc40d53f102e48fc3ee6f4fe9de)
1# This file is part of Autoconf.			-*- Autoconf -*-
2# Type related macros: existence, sizeof, and structure members.
3#
4# Copyright (C) 2000-2002, 2004-2012 Free Software Foundation, Inc.
5
6# This file is part of Autoconf.  This program is free
7# software; you can redistribute it and/or modify it under the
8# terms of the GNU General Public License as published by the
9# Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# Under Section 7 of GPL version 3, you are granted additional
18# permissions described in the Autoconf Configure Script Exception,
19# version 3.0, as published by the Free Software Foundation.
20#
21# You should have received a copy of the GNU General Public License
22# and a copy of the Autoconf Configure Script Exception along with
23# this program; see the files COPYINGv3 and COPYING.EXCEPTION
24# respectively.  If not, see <http://www.gnu.org/licenses/>.
25
26# Written by David MacKenzie, with help from
27# Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
28# Roland McGrath, Noah Friedman, david d zuhn, and many others.
29
30
31## ---------------- ##
32## Type existence.  ##
33## ---------------- ##
34
35# ---------------- #
36# General checks.  #
37# ---------------- #
38
39# Up to 2.13 included, Autoconf used to provide the macro
40#
41#    AC_CHECK_TYPE(TYPE, DEFAULT)
42#
43# Since, it provides another version which fits better with the other
44# AC_CHECK_ families:
45#
46#    AC_CHECK_TYPE(TYPE,
47#		   [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
48#		   [INCLUDES = DEFAULT-INCLUDES])
49#
50# In order to provide backward compatibility, the new scheme is
51# implemented as _AC_CHECK_TYPE_NEW, the old scheme as _AC_CHECK_TYPE_OLD,
52# and AC_CHECK_TYPE branches to one or the other, depending upon its
53# arguments.
54
55
56# _AC_CHECK_TYPE_NEW_BODY
57# -----------------------
58# Shell function body for _AC_CHECK_TYPE_NEW.  This macro implements the
59# former task of AC_CHECK_TYPE, with one big difference though: AC_CHECK_TYPE
60# used to grep in the headers, which, BTW, led to many problems until the
61# extended regular expression was correct and did not give false positives.
62# It turned out there are even portability issues with egrep...
63#
64# The most obvious way to check for a TYPE is just to compile a variable
65# definition:
66#
67#	  TYPE my_var;
68#
69# (TYPE being the second parameter to the shell function, hence $[]2 in m4).
70# Unfortunately this does not work for const qualified types in C++, where
71# you need an initializer.  So you think of
72#
73#	  TYPE my_var = (TYPE) 0;
74#
75# Unfortunately, again, this is not valid for some C++ classes.
76#
77# Then you look for another scheme.  For instance you think of declaring
78# a function which uses a parameter of type TYPE:
79#
80#	  int foo (TYPE param);
81#
82# but of course you soon realize this does not make it with K&R
83# compilers.  And by no means do you want to use this:
84#
85#	  int foo (param)
86#	    TYPE param
87#	  { ; }
88#
89# since C++ would complain loudly.
90#
91# Don't even think of using a function return type, since K&R cries
92# there too.  So you start thinking of declaring a *pointer* to this TYPE:
93#
94#	  TYPE *p;
95#
96# but you know fairly well that this is legal in C for aggregates which
97# are unknown (TYPE = struct does-not-exist).
98#
99# Then you think of using sizeof to make sure the TYPE is really
100# defined:
101#
102#	  sizeof (TYPE);
103#
104# That is great, but has one drawback: it succeeds when TYPE happens
105# to be a variable: you'd get the size of the variable's type.
106# Obviously, we must not accept a variable in place of a type name.
107#
108# So, to filter out the last possibility, we will require that this fail:
109#
110#	  sizeof ((TYPE));
111#
112# This evokes a syntax error when TYPE is a type, but succeeds if TYPE
113# is actually a variable.
114#
115# Also note that we use
116#
117#	  if (sizeof (TYPE))
118#
119# to `read' sizeof (to avoid warnings), while not depending on its type
120# (not necessarily size_t etc.).
121#
122# C++ disallows defining types inside `sizeof ()', but that's OK,
123# since we don't want to consider unnamed structs to be types for C++,
124# precisely because they don't work in cases like that.
125m4_define([_AC_CHECK_TYPE_NEW_BODY],
126[  AS_LINENO_PUSH([$[]1])
127  AC_CACHE_CHECK([for $[]2], [$[]3],
128  [AS_VAR_SET([$[]3], [no])
129  AC_COMPILE_IFELSE(
130    [AC_LANG_PROGRAM([$[]4],
131       [if (sizeof ($[]2))
132	 return 0;])],
133    [AC_COMPILE_IFELSE(
134       [AC_LANG_PROGRAM([$[]4],
135	  [if (sizeof (($[]2)))
136	    return 0;])],
137       [],
138       [AS_VAR_SET([$[]3], [yes])])])])
139  AS_LINENO_POP
140])dnl
141
142# _AC_CHECK_TYPE_NEW(TYPE,
143#		     [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
144#		     [INCLUDES = DEFAULT-INCLUDES])
145# ------------------------------------------------------------
146# Check whether the type TYPE is supported by the system, maybe via the
147# the provided includes.
148AC_DEFUN([_AC_CHECK_TYPE_NEW],
149[AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_type],
150  [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_type],
151    [LINENO TYPE VAR INCLUDES],
152    [Tests whether TYPE exists after having included INCLUDES, setting
153     cache variable VAR accordingly.])],
154    [$0_BODY])]dnl
155[AS_VAR_PUSHDEF([ac_Type], [ac_cv_type_$1])]dnl
156[ac_fn_[]_AC_LANG_ABBREV[]_check_type "$LINENO" "$1" "ac_Type" ]dnl
157["AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])"
158AS_VAR_IF([ac_Type], [yes], [$2], [$3])
159AS_VAR_POPDEF([ac_Type])dnl
160])# _AC_CHECK_TYPE_NEW
161
162
163# _AC_CHECK_TYPES(TYPE)
164# ---------------------
165# Helper to AC_CHECK_TYPES, which generates two of the four arguments
166# to _AC_CHECK_TYPE_NEW that are based on TYPE.
167m4_define([_AC_CHECK_TYPES],
168[[$1], [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1]), [1],
169  [Define to 1 if the system has the type `$1'.])]])
170
171
172# AC_CHECK_TYPES(TYPES,
173#		 [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
174#		 [INCLUDES = DEFAULT-INCLUDES])
175# --------------------------------------------------------
176# TYPES is an m4 list.  There are no ambiguities here, we mean the newer
177# AC_CHECK_TYPE.
178AC_DEFUN([AC_CHECK_TYPES],
179[m4_map_args_sep([_AC_CHECK_TYPE_NEW(_$0(], [)[
180$2], [$3], [$4])], [], $1)])
181
182
183# _AC_CHECK_TYPE_OLD(TYPE, DEFAULT)
184# ---------------------------------
185# FIXME: This is an extremely badly chosen name, since this
186# macro actually performs an AC_REPLACE_TYPE.  Some day we
187# have to clean this up.
188m4_define([_AC_CHECK_TYPE_OLD],
189[_AC_CHECK_TYPE_NEW([$1],,
190   [AC_DEFINE_UNQUOTED([$1], [$2],
191		       [Define to `$2' if <sys/types.h> does not define.])])dnl
192])# _AC_CHECK_TYPE_OLD
193
194
195# _AC_CHECK_TYPE_REPLACEMENT_TYPE_P(STRING)
196# -----------------------------------------
197# Return `1' if STRING seems to be a builtin C/C++ type, i.e., if it
198# starts with `_Bool', `bool', `char', `double', `float', `int',
199# `long', `short', `signed', or `unsigned' followed by characters
200# that are defining types.
201# Because many people have used `off_t' and `size_t' too, they are added
202# for better common-use backward compatibility.
203m4_define([_AC_CHECK_TYPE_REPLACEMENT_TYPE_P],
204[m4_bmatch([$1],
205	  [^\(_Bool\|bool\|char\|double\|float\|int\|long\|short\|\(un\)?signed\|[_a-zA-Z][_a-zA-Z0-9]*_t\)[][_a-zA-Z0-9() *]*$],
206	  1, 0)dnl
207])# _AC_CHECK_TYPE_REPLACEMENT_TYPE_P
208
209
210# _AC_CHECK_TYPE_MAYBE_TYPE_P(STRING)
211# -----------------------------------
212# Return `1' if STRING looks like a C/C++ type.
213m4_define([_AC_CHECK_TYPE_MAYBE_TYPE_P],
214[m4_bmatch([$1], [^[_a-zA-Z0-9 ]+\([_a-zA-Z0-9() *]\|\[\|\]\)*$],
215	  1, 0)dnl
216])# _AC_CHECK_TYPE_MAYBE_TYPE_P
217
218
219# AC_CHECK_TYPE(TYPE, DEFAULT)
220#  or
221# AC_CHECK_TYPE(TYPE,
222#		[ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
223#		[INCLUDES = DEFAULT-INCLUDES])
224# -------------------------------------------------------
225#
226# Dispatch respectively to _AC_CHECK_TYPE_OLD or _AC_CHECK_TYPE_NEW.
227# 1. More than two arguments	     => NEW
228# 2. $2 seems to be replacement type => OLD
229#    See _AC_CHECK_TYPE_REPLACEMENT_TYPE_P for `replacement type'.
230# 3. $2 seems to be a type	     => NEW plus a warning
231# 4. default			     => NEW
232AC_DEFUN([AC_CHECK_TYPE],
233[m4_cond([$#], [3],
234  [_AC_CHECK_TYPE_NEW],
235	 [$#], [4],
236  [_AC_CHECK_TYPE_NEW],
237	 [_AC_CHECK_TYPE_REPLACEMENT_TYPE_P([$2])], [1],
238  [_AC_CHECK_TYPE_OLD],
239	 [_AC_CHECK_TYPE_MAYBE_TYPE_P([$2])], [1],
240  [AC_DIAGNOSE([syntax],
241	       [$0: assuming `$2' is not a type])_AC_CHECK_TYPE_NEW],
242  [_AC_CHECK_TYPE_NEW])($@)])# AC_CHECK_TYPE
243
244
245
246# ---------------------------- #
247# Types that must be checked.  #
248# ---------------------------- #
249
250AN_IDENTIFIER([ptrdiff_t], [AC_CHECK_TYPES])
251
252
253# ----------------- #
254# Specific checks.  #
255# ----------------- #
256
257# AC_TYPE_GETGROUPS
258# -----------------
259AC_DEFUN([AC_TYPE_GETGROUPS],
260[AC_REQUIRE([AC_TYPE_UID_T])dnl
261AC_CACHE_CHECK(type of array argument to getgroups, ac_cv_type_getgroups,
262[AC_RUN_IFELSE([AC_LANG_SOURCE(
263[[/* Thanks to Mike Rendell for this test.  */
264]AC_INCLUDES_DEFAULT[
265#define NGID 256
266#undef MAX
267#define MAX(x, y) ((x) > (y) ? (x) : (y))
268
269int
270main ()
271{
272  gid_t gidset[NGID];
273  int i, n;
274  union { gid_t gval; long int lval; }  val;
275
276  val.lval = -1;
277  for (i = 0; i < NGID; i++)
278    gidset[i] = val.gval;
279  n = getgroups (sizeof (gidset) / MAX (sizeof (int), sizeof (gid_t)) - 1,
280		 gidset);
281  /* Exit non-zero if getgroups seems to require an array of ints.  This
282     happens when gid_t is short int but getgroups modifies an array
283     of ints.  */
284  return n > 0 && gidset[n] != val.gval;
285}]])],
286	       [ac_cv_type_getgroups=gid_t],
287	       [ac_cv_type_getgroups=int],
288	       [ac_cv_type_getgroups=cross])
289if test $ac_cv_type_getgroups = cross; then
290  dnl When we can't run the test program (we are cross compiling), presume
291  dnl that <unistd.h> has either an accurate prototype for getgroups or none.
292  dnl Old systems without prototypes probably use int.
293  AC_EGREP_HEADER([getgroups.*int.*gid_t], unistd.h,
294		  ac_cv_type_getgroups=gid_t, ac_cv_type_getgroups=int)
295fi])
296AC_DEFINE_UNQUOTED(GETGROUPS_T, $ac_cv_type_getgroups,
297		   [Define to the type of elements in the array set by
298		    `getgroups'. Usually this is either `int' or `gid_t'.])
299])# AC_TYPE_GETGROUPS
300
301
302# AU::AM_TYPE_PTRDIFF_T
303# ---------------------
304AU_DEFUN([AM_TYPE_PTRDIFF_T],
305[AC_CHECK_TYPES(ptrdiff_t)])
306
307
308# AC_TYPE_INTMAX_T
309# ----------------
310AC_DEFUN([AC_TYPE_INTMAX_T],
311[
312  AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
313  AC_CHECK_TYPE([intmax_t],
314    [AC_DEFINE([HAVE_INTMAX_T], 1,
315       [Define to 1 if the system has the type `intmax_t'.])],
316    [test $ac_cv_type_long_long_int = yes \
317       && ac_type='long long int' \
318       || ac_type='long int'
319     AC_DEFINE_UNQUOTED([intmax_t], [$ac_type],
320       [Define to the widest signed integer type
321	if <stdint.h> and <inttypes.h> do not define.])])
322])
323
324
325# AC_TYPE_UINTMAX_T
326# -----------------
327AC_DEFUN([AC_TYPE_UINTMAX_T],
328[
329  AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
330  AC_CHECK_TYPE([uintmax_t],
331    [AC_DEFINE([HAVE_UINTMAX_T], 1,
332       [Define to 1 if the system has the type `uintmax_t'.])],
333    [test $ac_cv_type_unsigned_long_long_int = yes \
334       && ac_type='unsigned long long int' \
335       || ac_type='unsigned long int'
336     AC_DEFINE_UNQUOTED([uintmax_t], [$ac_type],
337       [Define to the widest unsigned integer type
338	if <stdint.h> and <inttypes.h> do not define.])])
339])
340
341
342# AC_TYPE_INTPTR_T
343# ----------------
344AC_DEFUN([AC_TYPE_INTPTR_T],
345[
346  AC_CHECK_TYPE([intptr_t],
347    [AC_DEFINE([HAVE_INTPTR_T], 1,
348       [Define to 1 if the system has the type `intptr_t'.])],
349    [for ac_type in 'int' 'long int' 'long long int'; do
350       AC_COMPILE_IFELSE(
351	 [AC_LANG_BOOL_COMPILE_TRY(
352	    [AC_INCLUDES_DEFAULT],
353	    [[sizeof (void *) <= sizeof ($ac_type)]])],
354	 [AC_DEFINE_UNQUOTED([intptr_t], [$ac_type],
355	    [Define to the type of a signed integer type wide enough to
356	     hold a pointer, if such a type exists, and if the system
357	     does not define it.])
358	  ac_type=])
359       test -z "$ac_type" && break
360     done])
361])
362
363
364# AC_TYPE_UINTPTR_T
365# -----------------
366AC_DEFUN([AC_TYPE_UINTPTR_T],
367[
368  AC_CHECK_TYPE([uintptr_t],
369    [AC_DEFINE([HAVE_UINTPTR_T], 1,
370       [Define to 1 if the system has the type `uintptr_t'.])],
371    [for ac_type in 'unsigned int' 'unsigned long int' \
372	'unsigned long long int'; do
373       AC_COMPILE_IFELSE(
374	 [AC_LANG_BOOL_COMPILE_TRY(
375	    [AC_INCLUDES_DEFAULT],
376	    [[sizeof (void *) <= sizeof ($ac_type)]])],
377	 [AC_DEFINE_UNQUOTED([uintptr_t], [$ac_type],
378	    [Define to the type of an unsigned integer type wide enough to
379	     hold a pointer, if such a type exists, and if the system
380	     does not define it.])
381	  ac_type=])
382       test -z "$ac_type" && break
383     done])
384])
385
386
387# AC_TYPE_LONG_DOUBLE
388# -------------------
389AC_DEFUN([AC_TYPE_LONG_DOUBLE],
390[
391  AC_CACHE_CHECK([for long double], [ac_cv_type_long_double],
392    [if test "$GCC" = yes; then
393       ac_cv_type_long_double=yes
394     else
395       AC_COMPILE_IFELSE(
396	 [AC_LANG_BOOL_COMPILE_TRY(
397	    [[/* The Stardent Vistra knows sizeof (long double), but does
398		 not support it.  */
399	      long double foo = 0.0L;]],
400	    [[/* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
401	      sizeof (double) <= sizeof (long double)]])],
402	 [ac_cv_type_long_double=yes],
403	 [ac_cv_type_long_double=no])
404     fi])
405  if test $ac_cv_type_long_double = yes; then
406    AC_DEFINE([HAVE_LONG_DOUBLE], 1,
407      [Define to 1 if the system has the type `long double'.])
408  fi
409])
410
411
412# AC_TYPE_LONG_DOUBLE_WIDER
413# -------------------------
414AC_DEFUN([AC_TYPE_LONG_DOUBLE_WIDER],
415[
416  AC_CACHE_CHECK(
417    [for long double with more range or precision than double],
418    [ac_cv_type_long_double_wider],
419    [AC_COMPILE_IFELSE(
420       [AC_LANG_BOOL_COMPILE_TRY(
421	  [[#include <float.h>
422	    long double const a[] =
423	      {
424		 0.0L, DBL_MIN, DBL_MAX, DBL_EPSILON,
425		 LDBL_MIN, LDBL_MAX, LDBL_EPSILON
426	      };
427	    long double
428	    f (long double x)
429	    {
430	       return ((x + (unsigned long int) 10) * (-1 / x) + a[0]
431			+ (x ? f (x) : 'c'));
432	    }
433	  ]],
434	  [[(0 < ((DBL_MAX_EXP < LDBL_MAX_EXP)
435		   + (DBL_MANT_DIG < LDBL_MANT_DIG)
436		   - (LDBL_MAX_EXP < DBL_MAX_EXP)
437		   - (LDBL_MANT_DIG < DBL_MANT_DIG)))
438	    && (int) LDBL_EPSILON == 0
439	  ]])],
440       ac_cv_type_long_double_wider=yes,
441       ac_cv_type_long_double_wider=no)])
442  if test $ac_cv_type_long_double_wider = yes; then
443    AC_DEFINE([HAVE_LONG_DOUBLE_WIDER], 1,
444      [Define to 1 if the type `long double' works and has more range or
445       precision than `double'.])
446  fi
447])# AC_TYPE_LONG_DOUBLE_WIDER
448
449
450# AC_C_LONG_DOUBLE
451# ----------------
452AU_DEFUN([AC_C_LONG_DOUBLE],
453  [
454    AC_TYPE_LONG_DOUBLE_WIDER
455    ac_cv_c_long_double=$ac_cv_type_long_double_wider
456    if test $ac_cv_c_long_double = yes; then
457      AC_DEFINE([HAVE_LONG_DOUBLE], 1,
458	[Define to 1 if the type `long double' works and has more range or
459	 precision than `double'.])
460    fi
461  ],
462  [The macro `AC_C_LONG_DOUBLE' is obsolete.
463You should use `AC_TYPE_LONG_DOUBLE' or `AC_TYPE_LONG_DOUBLE_WIDER' instead.]
464)
465
466
467# _AC_TYPE_LONG_LONG_SNIPPET
468# --------------------------
469# Expands to a C program that can be used to test for simultaneous support
470# of 'long long' and 'unsigned long long'. We don't want to say that
471# 'long long' is available if 'unsigned long long' is not, or vice versa,
472# because too many programs rely on the symmetry between signed and unsigned
473# integer types (excluding 'bool').
474AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET],
475[
476  AC_LANG_PROGRAM(
477    [[/* For now, do not test the preprocessor; as of 2007 there are too many
478	 implementations with broken preprocessors.  Perhaps this can
479	 be revisited in 2012.  In the meantime, code should not expect
480	 #if to work with literals wider than 32 bits.  */
481      /* Test literals.  */
482      long long int ll = 9223372036854775807ll;
483      long long int nll = -9223372036854775807LL;
484      unsigned long long int ull = 18446744073709551615ULL;
485      /* Test constant expressions.   */
486      typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
487		     ? 1 : -1)];
488      typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
489		     ? 1 : -1)];
490      int i = 63;]],
491    [[/* Test availability of runtime routines for shift and division.  */
492      long long int llmax = 9223372036854775807ll;
493      unsigned long long int ullmax = 18446744073709551615ull;
494      return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
495	      | (llmax / ll) | (llmax % ll)
496	      | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
497	      | (ullmax / ull) | (ullmax % ull));]])
498])
499
500
501# AC_TYPE_LONG_LONG_INT
502# ---------------------
503AC_DEFUN([AC_TYPE_LONG_LONG_INT],
504[
505  AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
506  AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int],
507     [ac_cv_type_long_long_int=yes
508      if test "x${ac_cv_prog_cc_c99-no}" = xno; then
509	ac_cv_type_long_long_int=$ac_cv_type_unsigned_long_long_int
510	if test $ac_cv_type_long_long_int = yes; then
511	  dnl Catch a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004.
512	  dnl If cross compiling, assume the bug is not important, since
513	  dnl nobody cross compiles for this platform as far as we know.
514	  AC_RUN_IFELSE(
515	    [AC_LANG_PROGRAM(
516	       [[@%:@include <limits.h>
517		 @%:@ifndef LLONG_MAX
518		 @%:@ define HALF \
519			  (1LL << (sizeof (long long int) * CHAR_BIT - 2))
520		 @%:@ define LLONG_MAX (HALF - 1 + HALF)
521		 @%:@endif]],
522	       [[long long int n = 1;
523		 int i;
524		 for (i = 0; ; i++)
525		   {
526		     long long int m = n << i;
527		     if (m >> i != n)
528		       return 1;
529		     if (LLONG_MAX / 2 < m)
530		       break;
531		   }
532		 return 0;]])],
533	    [],
534	    [ac_cv_type_long_long_int=no],
535	    [:])
536	fi
537      fi])
538  if test $ac_cv_type_long_long_int = yes; then
539    AC_DEFINE([HAVE_LONG_LONG_INT], [1],
540      [Define to 1 if the system has the type `long long int'.])
541  fi
542])
543
544
545# AC_TYPE_UNSIGNED_LONG_LONG_INT
546# ------------------------------
547AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
548[
549  AC_CACHE_CHECK([for unsigned long long int],
550    [ac_cv_type_unsigned_long_long_int],
551    [ac_cv_type_unsigned_long_long_int=yes
552     if test "x${ac_cv_prog_cc_c99-no}" = xno; then
553       AC_LINK_IFELSE(
554	 [_AC_TYPE_LONG_LONG_SNIPPET],
555	 [],
556	 [ac_cv_type_unsigned_long_long_int=no])
557     fi])
558  if test $ac_cv_type_unsigned_long_long_int = yes; then
559    AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], [1],
560      [Define to 1 if the system has the type `unsigned long long int'.])
561  fi
562])
563
564
565# AC_TYPE_MBSTATE_T
566# -----------------
567AC_DEFUN([AC_TYPE_MBSTATE_T],
568  [AC_CACHE_CHECK([for mbstate_t], ac_cv_type_mbstate_t,
569     [AC_COMPILE_IFELSE(
570	[AC_LANG_PROGRAM(
571	   [AC_INCLUDES_DEFAULT
572#	    include <wchar.h>],
573	   [mbstate_t x; return sizeof x;])],
574	[ac_cv_type_mbstate_t=yes],
575	[ac_cv_type_mbstate_t=no])])
576   if test $ac_cv_type_mbstate_t = yes; then
577     AC_DEFINE([HAVE_MBSTATE_T], 1,
578	       [Define to 1 if <wchar.h> declares mbstate_t.])
579   else
580     AC_DEFINE([mbstate_t], int,
581	       [Define to a type if <wchar.h> does not define.])
582   fi])
583
584
585# AC_TYPE_UID_T
586# -------------
587# FIXME: Rewrite using AC_CHECK_TYPE.
588AN_IDENTIFIER([gid_t], [AC_TYPE_UID_T])
589AN_IDENTIFIER([uid_t], [AC_TYPE_UID_T])
590AC_DEFUN([AC_TYPE_UID_T],
591[AC_CACHE_CHECK(for uid_t in sys/types.h, ac_cv_type_uid_t,
592[AC_EGREP_HEADER(uid_t, sys/types.h,
593  ac_cv_type_uid_t=yes, ac_cv_type_uid_t=no)])
594if test $ac_cv_type_uid_t = no; then
595  AC_DEFINE(uid_t, int, [Define to `int' if <sys/types.h> doesn't define.])
596  AC_DEFINE(gid_t, int, [Define to `int' if <sys/types.h> doesn't define.])
597fi
598])
599
600
601AN_IDENTIFIER([size_t], [AC_TYPE_SIZE_T])
602AC_DEFUN([AC_TYPE_SIZE_T], [AC_CHECK_TYPE(size_t, unsigned int)])
603
604AN_IDENTIFIER([ssize_t], [AC_TYPE_SSIZE_T])
605AC_DEFUN([AC_TYPE_SSIZE_T], [AC_CHECK_TYPE(ssize_t, int)])
606
607AN_IDENTIFIER([pid_t], [AC_TYPE_PID_T])
608AC_DEFUN([AC_TYPE_PID_T],  [AC_CHECK_TYPE(pid_t,  int)])
609
610AN_IDENTIFIER([off_t], [AC_TYPE_OFF_T])
611AC_DEFUN([AC_TYPE_OFF_T],  [AC_CHECK_TYPE(off_t,  long int)])
612
613AN_IDENTIFIER([mode_t], [AC_TYPE_MODE_T])
614AC_DEFUN([AC_TYPE_MODE_T], [AC_CHECK_TYPE(mode_t, int)])
615
616AN_IDENTIFIER([int8_t], [AC_TYPE_INT8_T])
617AN_IDENTIFIER([int16_t], [AC_TYPE_INT16_T])
618AN_IDENTIFIER([int32_t], [AC_TYPE_INT32_T])
619AN_IDENTIFIER([int64_t], [AC_TYPE_INT64_T])
620AN_IDENTIFIER([uint8_t], [AC_TYPE_UINT8_T])
621AN_IDENTIFIER([uint16_t], [AC_TYPE_UINT16_T])
622AN_IDENTIFIER([uint32_t], [AC_TYPE_UINT32_T])
623AN_IDENTIFIER([uint64_t], [AC_TYPE_UINT64_T])
624AC_DEFUN([AC_TYPE_INT8_T], [_AC_TYPE_INT(8)])
625AC_DEFUN([AC_TYPE_INT16_T], [_AC_TYPE_INT(16)])
626AC_DEFUN([AC_TYPE_INT32_T], [_AC_TYPE_INT(32)])
627AC_DEFUN([AC_TYPE_INT64_T], [_AC_TYPE_INT(64)])
628AC_DEFUN([AC_TYPE_UINT8_T], [_AC_TYPE_UNSIGNED_INT(8)])
629AC_DEFUN([AC_TYPE_UINT16_T], [_AC_TYPE_UNSIGNED_INT(16)])
630AC_DEFUN([AC_TYPE_UINT32_T], [_AC_TYPE_UNSIGNED_INT(32)])
631AC_DEFUN([AC_TYPE_UINT64_T], [_AC_TYPE_UNSIGNED_INT(64)])
632
633# _AC_TYPE_INT_BODY
634# -----------------
635# Shell function body for _AC_TYPE_INT.
636m4_define([_AC_TYPE_INT_BODY],
637[  AS_LINENO_PUSH([$[]1])
638  AC_CACHE_CHECK([for int$[]2_t], [$[]3],
639    [AS_VAR_SET([$[]3], [no])
640     # Order is important - never check a type that is potentially smaller
641     # than half of the expected target width.
642     for ac_type in int$[]2_t 'int' 'long int' \
643	 'long long int' 'short int' 'signed char'; do
644       AC_COMPILE_IFELSE(
645	 [AC_LANG_BOOL_COMPILE_TRY(
646	    [AC_INCLUDES_DEFAULT
647	     enum { N = $[]2 / 2 - 1 };],
648	    [0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1)])],
649	 [AC_COMPILE_IFELSE(
650	    [AC_LANG_BOOL_COMPILE_TRY(
651	       [AC_INCLUDES_DEFAULT
652	        enum { N = $[]2 / 2 - 1 };],
653	       [($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1)
654		 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 2)])],
655	    [],
656	    [AS_CASE([$ac_type], [int$[]2_t],
657	       [AS_VAR_SET([$[]3], [yes])],
658	       [AS_VAR_SET([$[]3], [$ac_type])])])])
659       AS_VAR_IF([$[]3], [no], [], [break])
660     done])
661  AS_LINENO_POP
662])# _AC_TYPE_INT_BODY
663
664# _AC_TYPE_INT(NBITS)
665# -------------------
666# Set a variable ac_cv_c_intNBITS_t to `yes' if intNBITS_t is available,
667# `no' if it is not and no replacement types could be found, and a C type
668# if it is not available but a replacement signed integer type of width
669# exactly NBITS bits was found.  In the third case, intNBITS_t is AC_DEFINEd
670# to type, as well.
671AC_DEFUN([_AC_TYPE_INT],
672[AC_REQUIRE_SHELL_FN([ac_fn_c_find_intX_t],
673  [AS_FUNCTION_DESCRIBE([ac_fn_c_find_intX_t], [LINENO BITS VAR],
674    [Finds a signed integer type with width BITS, setting cache variable VAR
675     accordingly.])],
676    [$0_BODY])]dnl
677[ac_fn_c_find_intX_t "$LINENO" "$1" "ac_cv_c_int$1_t"
678case $ac_cv_c_int$1_t in #(
679  no|yes) ;; #(
680  *)
681    AC_DEFINE_UNQUOTED([int$1_t], [$ac_cv_c_int$1_t],
682      [Define to the type of a signed integer type of width exactly $1 bits
683       if such a type exists and the standard includes do not define it.]);;
684esac
685])# _AC_TYPE_INT
686
687# _AC_TYPE_UNSIGNED_INT_BODY
688# --------------------------
689# Shell function body for _AC_TYPE_UNSIGNED_INT.
690m4_define([_AC_TYPE_UNSIGNED_INT_BODY],
691[  AS_LINENO_PUSH([$[]1])
692  AC_CACHE_CHECK([for uint$[]2_t], $[]3,
693    [AS_VAR_SET([$[]3], [no])
694     # Order is important - never check a type that is potentially smaller
695     # than half of the expected target width.
696     for ac_type in uint$[]2_t 'unsigned int' 'unsigned long int' \
697	 'unsigned long long int' 'unsigned short int' 'unsigned char'; do
698       AC_COMPILE_IFELSE(
699	 [AC_LANG_BOOL_COMPILE_TRY(
700	    [AC_INCLUDES_DEFAULT],
701	    [(($ac_type) -1 >> ($[]2 / 2 - 1)) >> ($[]2 / 2 - 1) == 3])],
702	 [AS_CASE([$ac_type], [uint$[]2_t],
703	    [AS_VAR_SET([$[]3], [yes])],
704	    [AS_VAR_SET([$[]3], [$ac_type])])])
705       AS_VAR_IF([$[]3], [no], [], [break])
706     done])
707  AS_LINENO_POP
708])# _AC_TYPE_UNSIGNED_INT_BODY
709
710
711# _AC_TYPE_UNSIGNED_INT(NBITS)
712# ----------------------------
713# Set a variable ac_cv_c_uintNBITS_t to `yes' if uintNBITS_t is available,
714# `no' if it is not and no replacement types could be found, and a C type
715# if it is not available but a replacement unsigned integer type of width
716# exactly NBITS bits was found.  In the third case, uintNBITS_t is AC_DEFINEd
717# to type, as well.
718AC_DEFUN([_AC_TYPE_UNSIGNED_INT],
719[AC_REQUIRE_SHELL_FN([ac_fn_c_find_uintX_t],
720  [AS_FUNCTION_DESCRIBE([ac_fn_c_find_uintX_t], [LINENO BITS VAR],
721    [Finds an unsigned integer type with width BITS, setting cache variable VAR
722     accordingly.])],
723  [$0_BODY])]dnl
724[ac_fn_c_find_uintX_t "$LINENO" "$1" "ac_cv_c_uint$1_t"
725case $ac_cv_c_uint$1_t in #(
726  no|yes) ;; #(
727  *)
728    m4_bmatch([$1], [^\(8\|32\|64\)$],
729      [AC_DEFINE([_UINT$1_T], 1,
730	 [Define for Solaris 2.5.1 so the uint$1_t typedef from
731	  <sys/synch.h>, <pthread.h>, or <semaphore.h> is not used.
732	  If the typedef were allowed, the #define below would cause a
733	  syntax error.])])
734    AC_DEFINE_UNQUOTED([uint$1_t], [$ac_cv_c_uint$1_t],
735      [Define to the type of an unsigned integer type of width exactly $1 bits
736       if such a type exists and the standard includes do not define it.]);;
737  esac
738])# _AC_TYPE_UNSIGNED_INT
739
740# AC_TYPE_SIGNAL
741# --------------
742# Note that identifiers starting with SIG are reserved by ANSI C.
743# C89 requires signal handlers to return void; only K&R returned int;
744# modern code does not need to worry about using this macro (not to
745# mention that sigaction is better than signal).
746AU_DEFUN([AC_TYPE_SIGNAL],
747[AC_CACHE_CHECK([return type of signal handlers], ac_cv_type_signal,
748[AC_COMPILE_IFELSE(
749[AC_LANG_PROGRAM([#include <sys/types.h>
750#include <signal.h>
751],
752		 [return *(signal (0, 0)) (0) == 1;])],
753		   [ac_cv_type_signal=int],
754		   [ac_cv_type_signal=void])])
755AC_DEFINE_UNQUOTED(RETSIGTYPE, $ac_cv_type_signal,
756		   [Define as the return type of signal handlers
757		    (`int' or `void').])
758], [your code may safely assume C89 semantics that RETSIGTYPE is void.
759Remove this warning and the `AC_CACHE_CHECK' when you adjust the code.])
760
761
762## ------------------------ ##
763## Checking size of types.  ##
764## ------------------------ ##
765
766# ---------------- #
767# Generic checks.  #
768# ---------------- #
769
770
771# AC_CHECK_SIZEOF(TYPE, [IGNORED], [INCLUDES = DEFAULT-INCLUDES])
772# ---------------------------------------------------------------
773AC_DEFUN([AC_CHECK_SIZEOF],
774[AS_LITERAL_IF(m4_translit([[$1]], [*], [p]), [],
775	       [m4_fatal([$0: requires literal arguments])])]dnl
776[# The cast to long int works around a bug in the HP C Compiler
777# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
778# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
779# This bug is HP SR number 8606223364.
780_AC_CACHE_CHECK_INT([size of $1], [AS_TR_SH([ac_cv_sizeof_$1])],
781  [(long int) (sizeof ($1))],
782  [AC_INCLUDES_DEFAULT([$3])],
783  [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
784     AC_MSG_FAILURE([cannot compute sizeof ($1)], 77)
785   else
786     AS_TR_SH([ac_cv_sizeof_$1])=0
787   fi])
788
789AC_DEFINE_UNQUOTED(AS_TR_CPP(sizeof_$1), $AS_TR_SH([ac_cv_sizeof_$1]),
790		   [The size of `$1', as computed by sizeof.])
791])# AC_CHECK_SIZEOF
792
793
794# AC_CHECK_ALIGNOF(TYPE, [INCLUDES = DEFAULT-INCLUDES])
795# -----------------------------------------------------
796# TYPE can include braces and semicolon, which AS_TR_CPP and AS_TR_SH
797# (correctly) recognize as potential shell metacharacters.  So we
798# have to flatten problematic characters ourselves to guarantee that
799# AC_DEFINE_UNQUOTED will see a literal.
800AC_DEFUN([AC_CHECK_ALIGNOF],
801[m4_if(m4_index(m4_translit([[$1]], [`\"], [$]), [$]), [-1], [],
802       [m4_fatal([$0: requires literal arguments])])]dnl
803[_$0([$1], [$2], m4_translit([[$1]], [{;}], [___]))])
804
805m4_define([_AC_CHECK_ALIGNOF],
806[# The cast to long int works around a bug in the HP C Compiler,
807# see AC_CHECK_SIZEOF for more information.
808_AC_CACHE_CHECK_INT([alignment of $1], [AS_TR_SH([ac_cv_alignof_$3])],
809  [(long int) offsetof (ac__type_alignof_, y)],
810  [AC_INCLUDES_DEFAULT([$2])
811#ifndef offsetof
812# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
813#endif
814typedef struct { char x; $1 y; } ac__type_alignof_;],
815  [if test "$AS_TR_SH([ac_cv_type_$3])" = yes; then
816     AC_MSG_FAILURE([cannot compute alignment of $1], 77)
817   else
818     AS_TR_SH([ac_cv_alignof_$3])=0
819   fi])
820
821AC_DEFINE_UNQUOTED(AS_TR_CPP(alignof_$3), $AS_TR_SH([ac_cv_alignof_$3]),
822		   [The normal alignment of `$1', in bytes.])
823])# AC_CHECK_ALIGNOF
824
825
826# AU::AC_INT_16_BITS
827# ------------------
828# What a great name :)
829AU_DEFUN([AC_INT_16_BITS],
830[AC_CHECK_SIZEOF([int])
831test $ac_cv_sizeof_int = 2 &&
832  AC_DEFINE(INT_16_BITS, 1,
833	    [Define to 1 if `sizeof (int)' = 2.  Obsolete, use `SIZEOF_INT'.])
834], [your code should no longer depend upon `INT_16_BITS', but upon
835`SIZEOF_INT == 2'.  Remove this warning and the `AC_DEFINE' when you
836adjust the code.])
837
838
839# AU::AC_LONG_64_BITS
840# -------------------
841AU_DEFUN([AC_LONG_64_BITS],
842[AC_CHECK_SIZEOF([long int])
843test $ac_cv_sizeof_long_int = 8 &&
844  AC_DEFINE(LONG_64_BITS, 1,
845	    [Define to 1 if `sizeof (long int)' = 8.  Obsolete, use
846	     `SIZEOF_LONG_INT'.])
847], [your code should no longer depend upon `LONG_64_BITS', but upon
848`SIZEOF_LONG_INT == 8'.  Remove this warning and the `AC_DEFINE' when
849you adjust the code.])
850
851
852
853## -------------------------- ##
854## Generic structure checks.  ##
855## -------------------------- ##
856
857
858# ---------------- #
859# Generic checks.  #
860# ---------------- #
861
862# _AC_CHECK_MEMBER_BODY
863# ---------------------
864# Shell function body for AC_CHECK_MEMBER.
865m4_define([_AC_CHECK_MEMBER_BODY],
866[  AS_LINENO_PUSH([$[]1])
867  AC_CACHE_CHECK([for $[]2.$[]3], [$[]4],
868  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$[]5],
869[static $[]2 ac_aggr;
870if (ac_aggr.$[]3)
871return 0;])],
872		[AS_VAR_SET([$[]4], [yes])],
873  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$[]5],
874[static $[]2 ac_aggr;
875if (sizeof ac_aggr.$[]3)
876return 0;])],
877		[AS_VAR_SET([$[]4], [yes])],
878		[AS_VAR_SET([$[]4], [no])])])])
879  AS_LINENO_POP
880])dnl
881
882# AC_CHECK_MEMBER(AGGREGATE.MEMBER,
883#		  [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
884#		  [INCLUDES = DEFAULT-INCLUDES])
885# ---------------------------------------------------------
886# AGGREGATE.MEMBER is for instance `struct passwd.pw_gecos', shell
887# variables are not a valid argument.
888AC_DEFUN([AC_CHECK_MEMBER],
889[AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_member],
890  [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_member],
891    [LINENO AGGR MEMBER VAR INCLUDES],
892    [Tries to find if the field MEMBER exists in type AGGR, after including
893     INCLUDES, setting cache variable VAR accordingly.])],
894    [_$0_BODY])]dnl
895[AS_LITERAL_IF([$1], [], [m4_fatal([$0: requires literal arguments])])]dnl
896[m4_if(m4_index([$1], [.]), [-1],
897  [m4_fatal([$0: Did not see any dot in `$1'])])]dnl
898[AS_VAR_PUSHDEF([ac_Member], [ac_cv_member_$1])]dnl
899[ac_fn_[]_AC_LANG_ABBREV[]_check_member "$LINENO" ]dnl
900[m4_bpatsubst([$1], [^\([^.]*\)\.\(.*\)], ["\1" "\2"]) "ac_Member" ]dnl
901["AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])"
902AS_VAR_IF([ac_Member], [yes], [$2], [$3])
903AS_VAR_POPDEF([ac_Member])dnl
904])# AC_CHECK_MEMBER
905
906
907# _AC_CHECK_MEMBERS(AGGREGATE.MEMBER)
908# -----------------------------------
909# Helper to AC_CHECK_MEMBERS, which generates two of the four
910# arguments to AC_CHECK_MEMBER that are based on AGGREGATE and MEMBER.
911m4_define([_AC_CHECK_MEMBERS],
912[[$1], [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1]), [1],
913  [Define to 1 if `]m4_bpatsubst([$1],
914    [^\([^.]*\)\.\(.*\)], [[\2' is a member of `\1]])['.])]])
915
916# AC_CHECK_MEMBERS([AGGREGATE.MEMBER, ...],
917#		   [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
918#		   [INCLUDES = DEFAULT-INCLUDES])
919# ----------------------------------------------------------
920# The first argument is an m4 list.
921AC_DEFUN([AC_CHECK_MEMBERS],
922[m4_map_args_sep([AC_CHECK_MEMBER(_$0(], [)[
923$2], [$3], [$4])], [], $1)])
924
925
926
927# ------------------------------------------------------- #
928# Members that ought to be tested with AC_CHECK_MEMBERS.  #
929# ------------------------------------------------------- #
930
931AN_IDENTIFIER([st_blksize], [AC_CHECK_MEMBERS([struct stat.st_blksize])])
932AN_IDENTIFIER([st_rdev],    [AC_CHECK_MEMBERS([struct stat.st_rdev])])
933
934
935# Alphabetic order, please.
936
937# _AC_STRUCT_DIRENT(MEMBER)
938# -------------------------
939AC_DEFUN([_AC_STRUCT_DIRENT],
940[
941  AC_REQUIRE([AC_HEADER_DIRENT])
942  AC_CHECK_MEMBERS([struct dirent.$1], [], [],
943    [[
944#include <sys/types.h>
945#ifdef HAVE_DIRENT_H
946# include <dirent.h>
947#else
948# define dirent direct
949# ifdef HAVE_SYS_NDIR_H
950#  include <sys/ndir.h>
951# endif
952# ifdef HAVE_SYS_DIR_H
953#  include <sys/dir.h>
954# endif
955# ifdef HAVE_NDIR_H
956#  include <ndir.h>
957# endif
958#endif
959    ]])
960])
961
962# AC_STRUCT_DIRENT_D_INO
963# ----------------------
964AC_DEFUN([AC_STRUCT_DIRENT_D_INO], [_AC_STRUCT_DIRENT([d_ino])])
965
966# AC_STRUCT_DIRENT_D_TYPE
967# -----------------------
968AC_DEFUN([AC_STRUCT_DIRENT_D_TYPE], [_AC_STRUCT_DIRENT([d_type])])
969
970
971# AC_STRUCT_ST_BLKSIZE
972# --------------------
973AU_DEFUN([AC_STRUCT_ST_BLKSIZE],
974[AC_CHECK_MEMBERS([struct stat.st_blksize],
975		 [AC_DEFINE(HAVE_ST_BLKSIZE, 1,
976			    [Define to 1 if your `struct stat' has
977			     `st_blksize'.  Deprecated, use
978			     `HAVE_STRUCT_STAT_ST_BLKSIZE' instead.])])
979], [your code should no longer depend upon `HAVE_ST_BLKSIZE', but
980`HAVE_STRUCT_STAT_ST_BLKSIZE'.  Remove this warning and
981the `AC_DEFINE' when you adjust the code.])# AC_STRUCT_ST_BLKSIZE
982
983
984# AC_STRUCT_ST_BLOCKS
985# -------------------
986# If `struct stat' contains an `st_blocks' member, define
987# HAVE_STRUCT_STAT_ST_BLOCKS.  Otherwise, add `fileblocks.o' to the
988# output variable LIBOBJS.  We still define HAVE_ST_BLOCKS for backward
989# compatibility.  In the future, we will activate specializations for
990# this macro, so don't obsolete it right now.
991#
992# AC_OBSOLETE([$0], [; replace it with
993#   AC_CHECK_MEMBERS([struct stat.st_blocks],
994#		      [AC_LIBOBJ([fileblocks])])
995# Please note that it will define `HAVE_STRUCT_STAT_ST_BLOCKS',
996# and not `HAVE_ST_BLOCKS'.])dnl
997#
998AN_IDENTIFIER([st_blocks],  [AC_STRUCT_ST_BLOCKS])
999AC_DEFUN([AC_STRUCT_ST_BLOCKS],
1000[AC_CHECK_MEMBERS([struct stat.st_blocks],
1001		  [AC_DEFINE(HAVE_ST_BLOCKS, 1,
1002			     [Define to 1 if your `struct stat' has
1003			      `st_blocks'.  Deprecated, use
1004			      `HAVE_STRUCT_STAT_ST_BLOCKS' instead.])],
1005		  [AC_LIBOBJ([fileblocks])])
1006])# AC_STRUCT_ST_BLOCKS
1007
1008
1009# AC_STRUCT_ST_RDEV
1010# -----------------
1011AU_DEFUN([AC_STRUCT_ST_RDEV],
1012[AC_CHECK_MEMBERS([struct stat.st_rdev],
1013		 [AC_DEFINE(HAVE_ST_RDEV, 1,
1014			    [Define to 1 if your `struct stat' has `st_rdev'.
1015			     Deprecated, use `HAVE_STRUCT_STAT_ST_RDEV'
1016			     instead.])])
1017], [your code should no longer depend upon `HAVE_ST_RDEV', but
1018`HAVE_STRUCT_STAT_ST_RDEV'.  Remove this warning and
1019the `AC_DEFINE' when you adjust the code.])# AC_STRUCT_ST_RDEV
1020
1021
1022# AC_STRUCT_TM
1023# ------------
1024# FIXME: This macro is badly named, it should be AC_CHECK_TYPE_STRUCT_TM.
1025# Or something else, but what? AC_CHECK_TYPE_STRUCT_TM_IN_SYS_TIME?
1026AC_DEFUN([AC_STRUCT_TM],
1027[AC_CACHE_CHECK([whether struct tm is in sys/time.h or time.h],
1028  ac_cv_struct_tm,
1029[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
1030#include <time.h>
1031],
1032				    [struct tm tm;
1033				     int *p = &tm.tm_sec;
1034				     return !p;])],
1035		   [ac_cv_struct_tm=time.h],
1036		   [ac_cv_struct_tm=sys/time.h])])
1037if test $ac_cv_struct_tm = sys/time.h; then
1038  AC_DEFINE(TM_IN_SYS_TIME, 1,
1039	    [Define to 1 if your <sys/time.h> declares `struct tm'.])
1040fi
1041])# AC_STRUCT_TM
1042
1043
1044# AC_STRUCT_TIMEZONE
1045# ------------------
1046# Figure out how to get the current timezone.  If `struct tm' has a
1047# `tm_zone' member, define `HAVE_TM_ZONE'.  Otherwise, if the
1048# external array `tzname' is found, define `HAVE_TZNAME'.
1049AN_IDENTIFIER([tm_zone], [AC_STRUCT_TIMEZONE])
1050AC_DEFUN([AC_STRUCT_TIMEZONE],
1051[AC_REQUIRE([AC_STRUCT_TM])dnl
1052AC_CHECK_MEMBERS([struct tm.tm_zone],,,[#include <sys/types.h>
1053#include <$ac_cv_struct_tm>
1054])
1055if test "$ac_cv_member_struct_tm_tm_zone" = yes; then
1056  AC_DEFINE(HAVE_TM_ZONE, 1,
1057	    [Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
1058	     `HAVE_STRUCT_TM_TM_ZONE' instead.])
1059else
1060  AC_CHECK_DECLS([tzname], , , [#include <time.h>])
1061  AC_CACHE_CHECK(for tzname, ac_cv_var_tzname,
1062[AC_LINK_IFELSE([AC_LANG_PROGRAM(
1063[[#include <time.h>
1064#if !HAVE_DECL_TZNAME
1065extern char *tzname[];
1066#endif
1067]],
1068[[return tzname[0][0];]])],
1069		[ac_cv_var_tzname=yes],
1070		[ac_cv_var_tzname=no])])
1071  if test $ac_cv_var_tzname = yes; then
1072    AC_DEFINE(HAVE_TZNAME, 1,
1073	      [Define to 1 if you don't have `tm_zone' but do have the external
1074	       array `tzname'.])
1075  fi
1076fi
1077])# AC_STRUCT_TIMEZONE
1078