Reword the copyright notices to match what's suggested in GPLv3.
[autoconf.git] / lib / autoconf / types.m4
blobdd5f2c884c249be59c668c5a93226c5d644aa8a7
1 # This file is part of Autoconf.                        -*- Autoconf -*-
2 # Type related macros: existence, sizeof, and structure members.
4 # Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006 Free Software
5 # Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
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.
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 # As a special exception, the Free Software Foundation gives unlimited
21 # permission to copy, distribute and modify the configure scripts that
22 # are the output of Autoconf.  You need not follow the terms of the GNU
23 # General Public License when using or distributing such scripts, even
24 # though portions of the text of Autoconf appear in them.  The GNU
25 # General Public License (GPL) does govern all other use of the material
26 # that constitutes the Autoconf program.
28 # Certain portions of the Autoconf source text are designed to be copied
29 # (in certain cases, depending on the input) into the output of
30 # Autoconf.  We call these the "data" portions.  The rest of the Autoconf
31 # source text consists of comments plus executable code that decides which
32 # of the data portions to output in any given case.  We call these
33 # comments and executable code the "non-data" portions.  Autoconf never
34 # copies any of the non-data portions into its output.
36 # This special exception to the GPL applies to versions of Autoconf
37 # released by the Free Software Foundation.  When you make and
38 # distribute a modified version of Autoconf, you may extend this special
39 # exception to the GPL to apply to your modified version as well, *unless*
40 # your modified version has the potential to copy into its output some
41 # of the text that was the non-data portion of the version that you started
42 # with.  (In other words, unless your change moves or copies text from
43 # the non-data portions to the data portions.)  If your modification has
44 # such potential, you must delete any notice of this special exception
45 # to the GPL from your modified version.
47 # Written by David MacKenzie, with help from
48 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
49 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
52 ## ---------------- ##
53 ## Type existence.  ##
54 ## ---------------- ##
56 # ---------------- #
57 # General checks.  #
58 # ---------------- #
60 # Up to 2.13 included, Autoconf used to provide the macro
62 #    AC_CHECK_TYPE(TYPE, DEFAULT)
64 # Since, it provides another version which fits better with the other
65 # AC_CHECK_ families:
67 #    AC_CHECK_TYPE(TYPE,
68 #                  [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
69 #                  [INCLUDES = DEFAULT-INCLUDES])
71 # In order to provide backward compatibility, the new scheme is
72 # implemented as _AC_CHECK_TYPE_NEW, the old scheme as _AC_CHECK_TYPE_OLD,
73 # and AC_CHECK_TYPE branches to one or the other, depending upon its
74 # arguments.
78 # _AC_CHECK_TYPE_NEW(TYPE,
79 #                    [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
80 #                    [INCLUDES = DEFAULT-INCLUDES])
81 # ------------------------------------------------------------
82 # Check whether the type TYPE is supported by the system, maybe via the
83 # the provided includes.  This macro implements the former task of
84 # AC_CHECK_TYPE, with one big difference though: AC_CHECK_TYPE was
85 # grepping in the headers, which, BTW, led to many problems until the
86 # extended regular expression was correct and did not given false positives.
87 # It turned out there are even portability issues with egrep...
89 # The most obvious way to check for a TYPE is just to compile a variable
90 # definition:
92 #         TYPE my_var;
94 # Unfortunately this does not work for const qualified types in C++,
95 # where you need an initializer.  So you think of
97 #         TYPE my_var = (TYPE) 0;
99 # Unfortunately, again, this is not valid for some C++ classes.
101 # Then you look for another scheme.  For instance you think of declaring
102 # a function which uses a parameter of type TYPE:
104 #         int foo (TYPE param);
106 # but of course you soon realize this does not make it with K&R
107 # compilers.  And by no ways you want to
109 #         int foo (param)
110 #           TYPE param
111 #         { ; }
113 # since this time it's C++ who is not happy.
115 # Don't even think of the return type of a function, since K&R cries
116 # there too.  So you start thinking of declaring a *pointer* to this TYPE:
118 #         TYPE *p;
120 # but you know fairly well that this is legal in C for aggregates which
121 # are unknown (TYPE = struct does-not-exist).
123 # Then you think of using sizeof to make sure the TYPE is really
124 # defined:
126 #         sizeof (TYPE);
128 # But this succeeds if TYPE is a variable: you get the size of the
129 # variable's type!!!
131 # So, to filter out the last possibility, you try this too:
133 #         sizeof ((TYPE));
135 # This fails if TYPE is a type, but succeeds if TYPE is actually a variable.
137 # Also note that we use
139 #         if (sizeof (TYPE))
141 # to `read' sizeof (to avoid warnings), while not depending on its type
142 # (not necessarily size_t etc.).
144 # C++ disallows defining types inside `sizeof ()', but that's OK,
145 # since we don't want to consider unnamed structs to be types for C++,
146 # precisely because they don't work in cases like that.
147 m4_define([_AC_CHECK_TYPE_NEW],
148 [AS_VAR_PUSHDEF([ac_Type], [ac_cv_type_$1])dnl
149 AC_CACHE_CHECK([for $1], [ac_Type],
150 [AS_VAR_SET([ac_Type], [no])
151 AC_COMPILE_IFELSE(
152   [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
153      [if (sizeof ($1))
154        return 0;])],
155   [AC_COMPILE_IFELSE(
156      [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
157         [if (sizeof (($1)))
158           return 0;])],
159      [],
160      [AS_VAR_SET([ac_Type], [yes])])])])
161 AS_IF([test AS_VAR_GET([ac_Type]) = yes], [$2], [$3])[]dnl
162 AS_VAR_POPDEF([ac_Type])dnl
163 ])# _AC_CHECK_TYPE_NEW
166 # AC_CHECK_TYPES(TYPES,
167 #                [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
168 #                [INCLUDES = DEFAULT-INCLUDES])
169 # --------------------------------------------------------
170 # TYPES is an m4 list.  There are no ambiguities here, we mean the newer
171 # AC_CHECK_TYPE.
172 AC_DEFUN([AC_CHECK_TYPES],
173 [m4_foreach([AC_Type], [$1],
174   [_AC_CHECK_TYPE_NEW(AC_Type,
175                       [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]AC_Type), 1,
176                                           [Define to 1 if the system has the
177                                            type `]AC_Type['.])
178 $2],
179                       [$3],
180                       [$4])])])
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.
188 m4_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
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-useward backward compatibility.
203 m4_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
210 # _AC_CHECK_TYPE_MAYBE_TYPE_P(STRING)
211 # -----------------------------------
212 # Return `1' if STRING looks like a C/C++ type.
213 m4_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
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 # -------------------------------------------------------
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
232 AC_DEFUN([AC_CHECK_TYPE],
233 [m4_if($#, 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($@)])[]dnl
243 ])# AC_CHECK_TYPE
247 # ---------------------------- #
248 # Types that must be checked.  #
249 # ---------------------------- #
251 AN_IDENTIFIER([ptrdiff_t], [AC_CHECK_TYPES])
254 # ----------------- #
255 # Specific checks.  #
256 # ----------------- #
258 # AC_TYPE_GETGROUPS
259 # -----------------
260 AC_DEFUN([AC_TYPE_GETGROUPS],
261 [AC_REQUIRE([AC_TYPE_UID_T])dnl
262 AC_CACHE_CHECK(type of array argument to getgroups, ac_cv_type_getgroups,
263 [AC_RUN_IFELSE([AC_LANG_SOURCE(
264 [[/* Thanks to Mike Rendell for this test.  */
265 ]AC_INCLUDES_DEFAULT[
266 #define NGID 256
267 #undef MAX
268 #define MAX(x, y) ((x) > (y) ? (x) : (y))
271 main ()
273   gid_t gidset[NGID];
274   int i, n;
275   union { gid_t gval; long int lval; }  val;
277   val.lval = -1;
278   for (i = 0; i < NGID; i++)
279     gidset[i] = val.gval;
280   n = getgroups (sizeof (gidset) / MAX (sizeof (int), sizeof (gid_t)) - 1,
281                  gidset);
282   /* Exit non-zero if getgroups seems to require an array of ints.  This
283      happens when gid_t is short int but getgroups modifies an array
284      of ints.  */
285   return n > 0 && gidset[n] != val.gval;
286 }]])],
287                [ac_cv_type_getgroups=gid_t],
288                [ac_cv_type_getgroups=int],
289                [ac_cv_type_getgroups=cross])
290 if test $ac_cv_type_getgroups = cross; then
291   dnl When we can't run the test program (we are cross compiling), presume
292   dnl that <unistd.h> has either an accurate prototype for getgroups or none.
293   dnl Old systems without prototypes probably use int.
294   AC_EGREP_HEADER([getgroups.*int.*gid_t], unistd.h,
295                   ac_cv_type_getgroups=gid_t, ac_cv_type_getgroups=int)
296 fi])
297 AC_DEFINE_UNQUOTED(GETGROUPS_T, $ac_cv_type_getgroups,
298                    [Define to the type of elements in the array set by
299                     `getgroups'. Usually this is either `int' or `gid_t'.])
300 ])# AC_TYPE_GETGROUPS
303 # AU::AM_TYPE_PTRDIFF_T
304 # ---------------------
305 AU_DEFUN([AM_TYPE_PTRDIFF_T],
306 [AC_CHECK_TYPES(ptrdiff_t)])
309 # AC_TYPE_INTMAX_T
310 # -----------------
311 AC_DEFUN([AC_TYPE_INTMAX_T],
313   AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
314   AC_CHECK_TYPE([intmax_t],
315     [AC_DEFINE([HAVE_INTMAX_T], 1,
316        [Define to 1 if the system has the type `intmax_t'.])],
317     [test $ac_cv_type_long_long_int = yes \
318        && ac_type='long long int' \
319        || ac_type='long int'
320      AC_DEFINE_UNQUOTED([intmax_t], [$ac_type],
321        [Define to the widest signed integer type
322         if <stdint.h> and <inttypes.h> do not define.])])
326 # AC_TYPE_UINTMAX_T
327 # -----------------
328 AC_DEFUN([AC_TYPE_UINTMAX_T],
330   AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
331   AC_CHECK_TYPE([uintmax_t],
332     [AC_DEFINE([HAVE_UINTMAX_T], 1,
333        [Define to 1 if the system has the type `uintmax_t'.])],
334     [test $ac_cv_type_unsigned_long_long_int = yes \
335        && ac_type='unsigned long long int' \
336        || ac_type='unsigned long int'
337      AC_DEFINE_UNQUOTED([uintmax_t], [$ac_type],
338        [Define to the widest unsigned integer type
339         if <stdint.h> and <inttypes.h> do not define.])])
343 # AC_TYPE_INTPTR_T
344 # -----------------
345 AC_DEFUN([AC_TYPE_INTPTR_T],
347   AC_CHECK_TYPE([intptr_t],
348     [AC_DEFINE([HAVE_INTPTR_T], 1,
349        [Define to 1 if the system has the type `intptr_t'.])],
350     [for ac_type in 'int' 'long int' 'long long int'; do
351        AC_COMPILE_IFELSE(
352          [AC_LANG_BOOL_COMPILE_TRY(
353             [AC_INCLUDES_DEFAULT],
354             [[sizeof (void *) <= sizeof ($ac_type)]])],
355          [AC_DEFINE_UNQUOTED([intptr_t], [$ac_type],
356             [Define to the type of a signed integer type wide enough to
357              hold a pointer, if such a type exists, and if the system
358              does not define it.])
359           ac_type=])
360        test -z "$ac_type" && break
361      done])
365 # AC_TYPE_UINTPTR_T
366 # -----------------
367 AC_DEFUN([AC_TYPE_UINTPTR_T],
369   AC_CHECK_TYPE([uintptr_t],
370     [AC_DEFINE([HAVE_UINTPTR_T], 1,
371        [Define to 1 if the system has the type `uintptr_t'.])],
372     [for ac_type in 'unsigned int' 'unsigned long int' \
373         'unsigned long long int'; do
374        AC_COMPILE_IFELSE(
375          [AC_LANG_BOOL_COMPILE_TRY(
376             [AC_INCLUDES_DEFAULT],
377             [[sizeof (void *) <= sizeof ($ac_type)]])],
378          [AC_DEFINE_UNQUOTED([uintptr_t], [$ac_type],
379             [Define to the type of an unsigned integer type wide enough to
380              hold a pointer, if such a type exists, and if the system
381              does not define it.])
382           ac_type=])
383        test -z "$ac_type" && break
384      done])
388 # AC_TYPE_LONG_DOUBLE
389 # -------------------
390 AC_DEFUN([AC_TYPE_LONG_DOUBLE],
392   AC_CACHE_CHECK([for long double], [ac_cv_type_long_double],
393     [if test "$GCC" = yes; then
394        ac_cv_type_long_double=yes
395      else
396        AC_COMPILE_IFELSE(
397          [AC_LANG_BOOL_COMPILE_TRY(
398             [[/* The Stardent Vistra knows sizeof (long double), but does
399                  not support it.  */
400               long double foo = 0.0L;]],
401             [[/* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
402               sizeof (double) <= sizeof (long double)]])],
403          [ac_cv_type_long_double=yes],
404          [ac_cv_type_long_double=no])
405      fi])
406   if test $ac_cv_type_long_double = yes; then
407     AC_DEFINE([HAVE_LONG_DOUBLE], 1,
408       [Define to 1 if the system has the type `long double'.])
409   fi
413 # AC_TYPE_LONG_DOUBLE_WIDER
414 # -------------------------
415 AC_DEFUN([AC_TYPE_LONG_DOUBLE_WIDER],
417   AC_CACHE_CHECK(
418     [for long double with more range or precision than double],
419     [ac_cv_type_long_double_wider],
420     [AC_COMPILE_IFELSE(
421        [AC_LANG_BOOL_COMPILE_TRY(
422           [[#include <float.h>
423             long double const a[] =
424               {
425                  0.0L, DBL_MIN, DBL_MAX, DBL_EPSILON,
426                  LDBL_MIN, LDBL_MAX, LDBL_EPSILON
427               };
428             long double
429             f (long double x)
430             {
431                return ((x + (unsigned long int) 10) * (-1 / x) + a[0]
432                         + (x ? f (x) : 'c'));
433             }
434           ]],
435           [[(0 < ((DBL_MAX_EXP < LDBL_MAX_EXP)
436                    + (DBL_MANT_DIG < LDBL_MANT_DIG)
437                    - (LDBL_MAX_EXP < DBL_MAX_EXP)
438                    - (LDBL_MANT_DIG < DBL_MANT_DIG)))
439             && (int) LDBL_EPSILON == 0
440           ]])],
441        ac_cv_type_long_double_wider=yes,
442        ac_cv_type_long_double_wider=no)])
443   if test $ac_cv_type_long_double_wider = yes; then
444     AC_DEFINE([HAVE_LONG_DOUBLE_WIDER], 1,
445       [Define to 1 if the type `long double' works and has more range or
446        precision than `double'.])
447   fi
448 ])# AC_TYPE_LONG_DOUBLE_WIDER
451 # AC_C_LONG_DOUBLE
452 # ----------------
453 AU_DEFUN([AC_C_LONG_DOUBLE],
454   [
455     AC_TYPE_LONG_DOUBLE_WIDER
456     ac_cv_c_long_double=$ac_cv_type_long_double_wider
457     if test $ac_cv_c_long_double = yes; then
458       AC_DEFINE([HAVE_LONG_DOUBLE], 1,
459         [Define to 1 if the type `long double' works and has more range or
460          precision than `double'.])
461     fi
462   ],
463   [The macro `AC_C_LONG_DOUBLE' is obsolete.
464 You should use `AC_TYPE_LONG_DOUBLE' or `AC_TYPE_LONG_DOUBLE_WIDER' instead.]
468 # AC_TYPE_LONG_LONG_INT
469 # ---------------------
470 AC_DEFUN([AC_TYPE_LONG_LONG_INT],
472   AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int],
473     [AC_LINK_IFELSE(
474        [AC_LANG_PROGRAM(
475           [[long long int ll = 9223372036854775807ll;
476             long long int nll = -9223372036854775807LL;
477             typedef int a[((-9223372036854775807LL < 0
478                             && 0 < 9223372036854775807ll)
479                            ? 1 : -1)];
480             int i = 63;]],
481           [[long long int llmax = 9223372036854775807ll;
482             return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
483                     | (llmax / ll) | (llmax % ll));]])],
484        [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004.
485         dnl If cross compiling, assume the bug isn't important, since
486         dnl nobody cross compiles for this platform as far as we know.
487         AC_RUN_IFELSE(
488           [AC_LANG_PROGRAM(
489              [[@%:@include <limits.h>
490                @%:@ifndef LLONG_MAX
491                @%:@ define HALF \
492                         (1LL << (sizeof (long long int) * CHAR_BIT - 2))
493                @%:@ define LLONG_MAX (HALF - 1 + HALF)
494                @%:@endif]],
495              [[long long int n = 1;
496                int i;
497                for (i = 0; ; i++)
498                  {
499                    long long int m = n << i;
500                    if (m >> i != n)
501                      return 1;
502                    if (LLONG_MAX / 2 < m)
503                      break;
504                  }
505                return 0;]])],
506           [ac_cv_type_long_long_int=yes],
507           [ac_cv_type_long_long_int=no],
508           [ac_cv_type_long_long_int=yes])],
509        [ac_cv_type_long_long_int=no])])
510   if test $ac_cv_type_long_long_int = yes; then
511     AC_DEFINE([HAVE_LONG_LONG_INT], 1,
512       [Define to 1 if the system has the type `long long int'.])
513   fi
517 # AC_TYPE_UNSIGNED_LONG_LONG_INT
518 # ------------------------------
519 AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
521   AC_CACHE_CHECK([for unsigned long long int],
522     [ac_cv_type_unsigned_long_long_int],
523     [AC_LINK_IFELSE(
524        [AC_LANG_PROGRAM(
525           [[unsigned long long int ull = 18446744073709551615ULL;
526             typedef int a[(18446744073709551615ULL <= (unsigned long long int) -1
527                            ? 1 : -1)];
528            int i = 63;]],
529           [[unsigned long long int ullmax = 18446744073709551615ull;
530             return (ull << 63 | ull >> 63 | ull << i | ull >> i
531                     | ullmax / ull | ullmax % ull);]])],
532        [ac_cv_type_unsigned_long_long_int=yes],
533        [ac_cv_type_unsigned_long_long_int=no])])
534   if test $ac_cv_type_unsigned_long_long_int = yes; then
535     AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1,
536       [Define to 1 if the system has the type `unsigned long long int'.])
537   fi
541 # AC_TYPE_MBSTATE_T
542 # -----------------
543 AC_DEFUN([AC_TYPE_MBSTATE_T],
544   [AC_CACHE_CHECK([for mbstate_t], ac_cv_type_mbstate_t,
545      [AC_COMPILE_IFELSE(
546         [AC_LANG_PROGRAM(
547            [AC_INCLUDES_DEFAULT
548 #           include <wchar.h>],
549            [mbstate_t x; return sizeof x;])],
550         [ac_cv_type_mbstate_t=yes],
551         [ac_cv_type_mbstate_t=no])])
552    if test $ac_cv_type_mbstate_t = yes; then
553      AC_DEFINE([HAVE_MBSTATE_T], 1,
554                [Define to 1 if <wchar.h> declares mbstate_t.])
555    else
556      AC_DEFINE([mbstate_t], int,
557                [Define to a type if <wchar.h> does not define.])
558    fi])
561 # AC_TYPE_UID_T
562 # -------------
563 # FIXME: Rewrite using AC_CHECK_TYPE.
564 AN_IDENTIFIER([gid_t], [AC_TYPE_UID_T])
565 AN_IDENTIFIER([uid_t], [AC_TYPE_UID_T])
566 AC_DEFUN([AC_TYPE_UID_T],
567 [AC_CACHE_CHECK(for uid_t in sys/types.h, ac_cv_type_uid_t,
568 [AC_EGREP_HEADER(uid_t, sys/types.h,
569   ac_cv_type_uid_t=yes, ac_cv_type_uid_t=no)])
570 if test $ac_cv_type_uid_t = no; then
571   AC_DEFINE(uid_t, int, [Define to `int' if <sys/types.h> doesn't define.])
572   AC_DEFINE(gid_t, int, [Define to `int' if <sys/types.h> doesn't define.])
577 AN_IDENTIFIER([size_t], [AC_TYPE_SIZE_T])
578 AC_DEFUN([AC_TYPE_SIZE_T], [AC_CHECK_TYPE(size_t, unsigned int)])
580 AN_IDENTIFIER([ssize_t], [AC_TYPE_SSIZE_T])
581 AC_DEFUN([AC_TYPE_SSIZE_T], [AC_CHECK_TYPE(ssize_t, int)])
583 AN_IDENTIFIER([pid_t], [AC_TYPE_PID_T])
584 AC_DEFUN([AC_TYPE_PID_T],  [AC_CHECK_TYPE(pid_t,  int)])
586 AN_IDENTIFIER([off_t], [AC_TYPE_OFF_T])
587 AC_DEFUN([AC_TYPE_OFF_T],  [AC_CHECK_TYPE(off_t,  long int)])
589 AN_IDENTIFIER([mode_t], [AC_TYPE_MODE_T])
590 AC_DEFUN([AC_TYPE_MODE_T], [AC_CHECK_TYPE(mode_t, int)])
592 AN_IDENTIFIER([int8_t], [AC_TYPE_INT8_T])
593 AN_IDENTIFIER([int16_t], [AC_TYPE_INT16_T])
594 AN_IDENTIFIER([int32_t], [AC_TYPE_INT32_T])
595 AN_IDENTIFIER([int64_t], [AC_TYPE_INT64_T])
596 AN_IDENTIFIER([uint8_t], [AC_TYPE_UINT8_T])
597 AN_IDENTIFIER([uint16_t], [AC_TYPE_UINT16_T])
598 AN_IDENTIFIER([uint32_t], [AC_TYPE_UINT32_T])
599 AN_IDENTIFIER([uint64_t], [AC_TYPE_UINT64_T])
600 AC_DEFUN([AC_TYPE_INT8_T], [_AC_TYPE_INT(8)])
601 AC_DEFUN([AC_TYPE_INT16_T], [_AC_TYPE_INT(16)])
602 AC_DEFUN([AC_TYPE_INT32_T], [_AC_TYPE_INT(32)])
603 AC_DEFUN([AC_TYPE_INT64_T], [_AC_TYPE_INT(64)])
604 AC_DEFUN([AC_TYPE_UINT8_T], [_AC_TYPE_UNSIGNED_INT(8)])
605 AC_DEFUN([AC_TYPE_UINT16_T], [_AC_TYPE_UNSIGNED_INT(16)])
606 AC_DEFUN([AC_TYPE_UINT32_T], [_AC_TYPE_UNSIGNED_INT(32)])
607 AC_DEFUN([AC_TYPE_UINT64_T], [_AC_TYPE_UNSIGNED_INT(64)])
609 # _AC_TYPE_INT(NBITS)
610 # -------------------
611 AC_DEFUN([_AC_TYPE_INT],
613   AC_CACHE_CHECK([for int$1_t], [ac_cv_c_int$1_t],
614     [ac_cv_c_int$1_t=no
615      for ac_type in 'int$1_t' 'int' 'long int' \
616          'long long int' 'short int' 'signed char'; do
617        AC_COMPILE_IFELSE(
618          [AC_LANG_BOOL_COMPILE_TRY(
619             [AC_INCLUDES_DEFAULT],
620             [[0 < ($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 1)]])],
621          [AC_COMPILE_IFELSE(
622             [AC_LANG_BOOL_COMPILE_TRY(
623                [AC_INCLUDES_DEFAULT],
624                [[($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 1)
625                  < ($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 2)]])],
626             [],
627             [AS_CASE([$ac_type], [int$1_t],
628                [ac_cv_c_int$1_t=yes],
629                [ac_cv_c_int$1_t=$ac_type])])])
630        test "$ac_cv_c_int$1_t" != no && break
631      done])
632   case $ac_cv_c_int$1_t in #(
633   no|yes) ;; #(
634   *)
635     AC_DEFINE_UNQUOTED([int$1_t], [$ac_cv_c_int$1_t],
636       [Define to the type of a signed integer type of width exactly $1 bits
637        if such a type exists and the standard includes do not define it.]);;
638   esac
639 ])# _AC_TYPE_INT
641 # _AC_TYPE_UNSIGNED_INT(NBITS)
642 # ----------------------------
643 AC_DEFUN([_AC_TYPE_UNSIGNED_INT],
645   AC_CACHE_CHECK([for uint$1_t], [ac_cv_c_uint$1_t],
646     [ac_cv_c_uint$1_t=no
647      for ac_type in 'uint$1_t' 'unsigned int' 'unsigned long int' \
648          'unsigned long long int' 'unsigned short int' 'unsigned char'; do
649        AC_COMPILE_IFELSE(
650          [AC_LANG_BOOL_COMPILE_TRY(
651             [AC_INCLUDES_DEFAULT],
652             [[($ac_type) -1 >> ($1 - 1) == 1]])],
653          [AS_CASE([$ac_type], [uint$1_t],
654             [ac_cv_c_uint$1_t=yes],
655             [ac_cv_c_uint$1_t=$ac_type])])
656        test "$ac_cv_c_uint$1_t" != no && break
657      done])
658   case $ac_cv_c_uint$1_t in #(
659   no|yes) ;; #(
660   *)
661     m4_bmatch([$1], [^\(8\|32\|64\)$],
662       [AC_DEFINE([_UINT$1_T], 1,
663          [Define for Solaris 2.5.1 so the uint$1_t typedef from
664           <sys/synch.h>, <pthread.h>, or <semaphore.h> is not used.
665           If the typedef were allowed, the #define below would cause a
666           syntax error.])])
667     AC_DEFINE_UNQUOTED([uint$1_t], [$ac_cv_c_uint$1_t],
668       [Define to the type of an unsigned integer type of width exactly $1 bits
669        if such a type exists and the standard includes do not define it.]);;
670   esac
671 ])# _AC_TYPE_UNSIGNED_INT
673 # AC_TYPE_SIGNAL
674 # --------------
675 # Note that identifiers starting with SIG are reserved by ANSI C.
676 AN_FUNCTION([signal],  [AC_TYPE_SIGNAL])
677 AC_DEFUN([AC_TYPE_SIGNAL],
678 [AC_CACHE_CHECK([return type of signal handlers], ac_cv_type_signal,
679 [AC_COMPILE_IFELSE(
680 [AC_LANG_PROGRAM([#include <sys/types.h>
681 #include <signal.h>
683                  [return *(signal (0, 0)) (0) == 1;])],
684                    [ac_cv_type_signal=int],
685                    [ac_cv_type_signal=void])])
686 AC_DEFINE_UNQUOTED(RETSIGTYPE, $ac_cv_type_signal,
687                    [Define as the return type of signal handlers
688                     (`int' or `void').])
692 ## ------------------------ ##
693 ## Checking size of types.  ##
694 ## ------------------------ ##
696 # ---------------- #
697 # Generic checks.  #
698 # ---------------- #
701 # AC_CHECK_SIZEOF(TYPE, [IGNORED], [INCLUDES = DEFAULT-INCLUDES])
702 # ---------------------------------------------------------------
703 AC_DEFUN([AC_CHECK_SIZEOF],
704 [AS_LITERAL_IF([$1], [],
705                [AC_FATAL([$0: requires literal arguments])])dnl
706 # The cast to long int works around a bug in the HP C Compiler
707 # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
708 # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
709 # This bug is HP SR number 8606223364.
710 _AC_CACHE_CHECK_INT([size of $1], [AS_TR_SH([ac_cv_sizeof_$1])],
711   [(long int) (sizeof ($1))],
712   [AC_INCLUDES_DEFAULT([$3])],
713   [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
714      AC_MSG_FAILURE([cannot compute sizeof ($1)], 77)
715    else
716      AS_TR_SH([ac_cv_sizeof_$1])=0
717    fi])
719 AC_DEFINE_UNQUOTED(AS_TR_CPP(sizeof_$1), $AS_TR_SH([ac_cv_sizeof_$1]),
720                    [The size of `$1', as computed by sizeof.])
721 ])# AC_CHECK_SIZEOF
724 # AC_CHECK_ALIGNOF(TYPE, [INCLUDES = DEFAULT-INCLUDES])
725 # -----------------------------------------------------
726 AC_DEFUN([AC_CHECK_ALIGNOF],
727 [AS_LITERAL_IF([$1], [],
728                [AC_FATAL([$0: requires literal arguments])])dnl
729 # The cast to long int works around a bug in the HP C Compiler,
730 # see AC_CHECK_SIZEOF for more information.
731 _AC_CACHE_CHECK_INT([alignment of $1], [AS_TR_SH([ac_cv_alignof_$1])],
732   [(long int) offsetof (ac__type_alignof_, y)],
733   [AC_INCLUDES_DEFAULT([$2])
734 #ifndef offsetof
735 # define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
736 #endif
737 typedef struct { char x; $1 y; } ac__type_alignof_;],
738   [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
739      AC_MSG_FAILURE([cannot compute alignment of $1], 77)
740    else
741      AS_TR_SH([ac_cv_alignof_$1])=0
742    fi])
744 AC_DEFINE_UNQUOTED(AS_TR_CPP(alignof_$1), $AS_TR_SH([ac_cv_alignof_$1]),
745                    [The normal alignment of `$1', in bytes.])
746 ])# AC_CHECK_ALIGNOF
749 # AU::AC_INT_16_BITS
750 # ------------------
751 # What a great name :)
752 AU_DEFUN([AC_INT_16_BITS],
753 [AC_CHECK_SIZEOF([int])
754 test $ac_cv_sizeof_int = 2 &&
755   AC_DEFINE(INT_16_BITS, 1,
756             [Define to 1 if `sizeof (int)' = 2.  Obsolete, use `SIZEOF_INT'.])
757 ], [your code should no longer depend upon `INT_16_BITS', but upon
758 `SIZEOF_INT == 2'.  Remove this warning and the `AC_DEFINE' when you
759 adjust the code.])
762 # AU::AC_LONG_64_BITS
763 # -------------------
764 AU_DEFUN([AC_LONG_64_BITS],
765 [AC_CHECK_SIZEOF([long int])
766 test $ac_cv_sizeof_long_int = 8 &&
767   AC_DEFINE(LONG_64_BITS, 1,
768             [Define to 1 if `sizeof (long int)' = 8.  Obsolete, use
769              `SIZEOF_LONG_INT'.])
770 ], [your code should no longer depend upon `LONG_64_BITS', but upon
771 `SIZEOF_LONG_INT == 8'.  Remove this warning and the `AC_DEFINE' when
772 you adjust the code.])
776 ## -------------------------- ##
777 ## Generic structure checks.  ##
778 ## -------------------------- ##
781 # ---------------- #
782 # Generic checks.  #
783 # ---------------- #
785 # AC_CHECK_MEMBER(AGGREGATE.MEMBER,
786 #                 [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
787 #                 [INCLUDES = DEFAULT-INCLUDES])
788 # ---------------------------------------------------------
789 # AGGREGATE.MEMBER is for instance `struct passwd.pw_gecos', shell
790 # variables are not a valid argument.
791 AC_DEFUN([AC_CHECK_MEMBER],
792 [AS_LITERAL_IF([$1], [],
793                [AC_FATAL([$0: requires literal arguments])])dnl
794 m4_bmatch([$1], [\.], ,
795          [m4_fatal([$0: Did not see any dot in `$1'])])dnl
796 AS_VAR_PUSHDEF([ac_Member], [ac_cv_member_$1])dnl
797 dnl Extract the aggregate name, and the member name
798 AC_CACHE_CHECK([for $1], [ac_Member],
799 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
800 [dnl AGGREGATE ac_aggr;
801 static m4_bpatsubst([$1], [\..*]) ac_aggr;
802 dnl ac_aggr.MEMBER;
803 if (ac_aggr.m4_bpatsubst([$1], [^[^.]*\.]))
804 return 0;])],
805                 [AS_VAR_SET([ac_Member], [yes])],
806 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
807 [dnl AGGREGATE ac_aggr;
808 static m4_bpatsubst([$1], [\..*]) ac_aggr;
809 dnl sizeof ac_aggr.MEMBER;
810 if (sizeof ac_aggr.m4_bpatsubst([$1], [^[^.]*\.]))
811 return 0;])],
812                 [AS_VAR_SET([ac_Member], [yes])],
813                 [AS_VAR_SET([ac_Member], [no])])])])
814 AS_IF([test AS_VAR_GET([ac_Member]) = yes], [$2], [$3])dnl
815 AS_VAR_POPDEF([ac_Member])dnl
816 ])# AC_CHECK_MEMBER
819 # AC_CHECK_MEMBERS([AGGREGATE.MEMBER, ...],
820 #                  [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]
821 #                  [INCLUDES = DEFAULT-INCLUDES])
822 # ---------------------------------------------------------
823 # The first argument is an m4 list.
824 AC_DEFUN([AC_CHECK_MEMBERS],
825 [m4_foreach([AC_Member], [$1],
826   [AC_CHECK_MEMBER(AC_Member,
827          [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]AC_Member), 1,
828                             [Define to 1 if `]m4_bpatsubst(AC_Member,
829                                                      [^[^.]*\.])[' is
830                              member of `]m4_bpatsubst(AC_Member, [\..*])['.])
831 $2],
832                  [$3],
833                  [$4])])])
837 # ------------------------------------------------------- #
838 # Members that ought to be tested with AC_CHECK_MEMBERS.  #
839 # ------------------------------------------------------- #
841 AN_IDENTIFIER([st_blksize], [AC_CHECK_MEMBERS([struct stat.st_blksize])])
842 AN_IDENTIFIER([st_rdev],    [AC_CHECK_MEMBERS([struct stat.st_rdev])])
845 # Alphabetic order, please.
847 # _AC_STRUCT_DIRENT(MEMBER)
848 # -------------------------
849 AC_DEFUN([_AC_STRUCT_DIRENT],
851   AC_REQUIRE([AC_HEADER_DIRENT])
852   AC_CHECK_MEMBERS([struct dirent.$1], [], [],
853     [[
854 #include <sys/types.h>
855 #ifdef HAVE_DIRENT_H
856 # include <dirent.h>
857 #else
858 # define dirent direct
859 # ifdef HAVE_SYS_NDIR_H
860 #  include <sys/ndir.h>
861 # endif
862 # ifdef HAVE_SYS_DIR_H
863 #  include <sys/dir.h>
864 # endif
865 # ifdef HAVE_NDIR_H
866 #  include <ndir.h>
867 # endif
868 #endif
869     ]])
872 # AC_STRUCT_DIRENT_D_INO
873 # -----------------------------------
874 AC_DEFUN([AC_STRUCT_DIRENT_D_INO], [_AC_STRUCT_DIRENT([d_ino])])
876 # AC_STRUCT_DIRENT_D_TYPE
877 # ------------------------------------
878 AC_DEFUN([AC_STRUCT_DIRENT_D_TYPE], [_AC_STRUCT_DIRENT([d_type])])
881 # AC_STRUCT_ST_BLKSIZE
882 # --------------------
883 AU_DEFUN([AC_STRUCT_ST_BLKSIZE],
884 [AC_CHECK_MEMBERS([struct stat.st_blksize],
885                  [AC_DEFINE(HAVE_ST_BLKSIZE, 1,
886                             [Define to 1 if your `struct stat' has
887                              `st_blksize'.  Deprecated, use
888                              `HAVE_STRUCT_STAT_ST_BLKSIZE' instead.])])
889 ], [your code should no longer depend upon `HAVE_ST_BLKSIZE', but
890 `HAVE_STRUCT_STAT_ST_BLKSIZE'.  Remove this warning and
891 the `AC_DEFINE' when you adjust the code.])# AC_STRUCT_ST_BLKSIZE
894 # AC_STRUCT_ST_BLOCKS
895 # -------------------
896 # If `struct stat' contains an `st_blocks' member, define
897 # HAVE_STRUCT_STAT_ST_BLOCKS.  Otherwise, add `fileblocks.o' to the
898 # output variable LIBOBJS.  We still define HAVE_ST_BLOCKS for backward
899 # compatibility.  In the future, we will activate specializations for
900 # this macro, so don't obsolete it right now.
902 # AC_OBSOLETE([$0], [; replace it with
903 #   AC_CHECK_MEMBERS([struct stat.st_blocks],
904 #                     [AC_LIBOBJ([fileblocks])])
905 # Please note that it will define `HAVE_STRUCT_STAT_ST_BLOCKS',
906 # and not `HAVE_ST_BLOCKS'.])dnl
908 AN_IDENTIFIER([st_blocks],  [AC_STRUCT_ST_BLOCKS])
909 AC_DEFUN([AC_STRUCT_ST_BLOCKS],
910 [AC_CHECK_MEMBERS([struct stat.st_blocks],
911                   [AC_DEFINE(HAVE_ST_BLOCKS, 1,
912                              [Define to 1 if your `struct stat' has
913                               `st_blocks'.  Deprecated, use
914                               `HAVE_STRUCT_STAT_ST_BLOCKS' instead.])],
915                   [AC_LIBOBJ([fileblocks])])
916 ])# AC_STRUCT_ST_BLOCKS
919 # AC_STRUCT_ST_RDEV
920 # -----------------
921 AU_DEFUN([AC_STRUCT_ST_RDEV],
922 [AC_CHECK_MEMBERS([struct stat.st_rdev],
923                  [AC_DEFINE(HAVE_ST_RDEV, 1,
924                             [Define to 1 if your `struct stat' has `st_rdev'.
925                              Deprecated, use `HAVE_STRUCT_STAT_ST_RDEV'
926                              instead.])])
927 ], [your code should no longer depend upon `HAVE_ST_RDEV', but
928 `HAVE_STRUCT_STAT_ST_RDEV'.  Remove this warning and
929 the `AC_DEFINE' when you adjust the code.])# AC_STRUCT_ST_RDEV
932 # AC_STRUCT_TM
933 # ------------
934 # FIXME: This macro is badly named, it should be AC_CHECK_TYPE_STRUCT_TM.
935 # Or something else, but what? AC_CHECK_TYPE_STRUCT_TM_IN_SYS_TIME?
936 AC_DEFUN([AC_STRUCT_TM],
937 [AC_CACHE_CHECK([whether struct tm is in sys/time.h or time.h],
938   ac_cv_struct_tm,
939 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
940 #include <time.h>
942                                     [struct tm tm;
943                                      int *p = &tm.tm_sec;
944                                      return !p;])],
945                    [ac_cv_struct_tm=time.h],
946                    [ac_cv_struct_tm=sys/time.h])])
947 if test $ac_cv_struct_tm = sys/time.h; then
948   AC_DEFINE(TM_IN_SYS_TIME, 1,
949             [Define to 1 if your <sys/time.h> declares `struct tm'.])
951 ])# AC_STRUCT_TM
954 # AC_STRUCT_TIMEZONE
955 # ------------------
956 # Figure out how to get the current timezone.  If `struct tm' has a
957 # `tm_zone' member, define `HAVE_TM_ZONE'.  Otherwise, if the
958 # external array `tzname' is found, define `HAVE_TZNAME'.
959 AN_IDENTIFIER([tm_zone], [AC_STRUCT_TIMEZONE])
960 AC_DEFUN([AC_STRUCT_TIMEZONE],
961 [AC_REQUIRE([AC_STRUCT_TM])dnl
962 AC_CHECK_MEMBERS([struct tm.tm_zone],,,[#include <sys/types.h>
963 #include <$ac_cv_struct_tm>
965 if test "$ac_cv_member_struct_tm_tm_zone" = yes; then
966   AC_DEFINE(HAVE_TM_ZONE, 1,
967             [Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
968              `HAVE_STRUCT_TM_TM_ZONE' instead.])
969 else
970   AC_CHECK_DECLS([tzname], , , [#include <time.h>])
971   AC_CACHE_CHECK(for tzname, ac_cv_var_tzname,
972 [AC_LINK_IFELSE([AC_LANG_PROGRAM(
973 [[#include <time.h>
974 #if !HAVE_DECL_TZNAME
975 extern char *tzname[];
976 #endif
978 [[return tzname[0][0];]])],
979                 [ac_cv_var_tzname=yes],
980                 [ac_cv_var_tzname=no])])
981   if test $ac_cv_var_tzname = yes; then
982     AC_DEFINE(HAVE_TZNAME, 1,
983               [Define to 1 if you don't have `tm_zone' but do have the external
984                array `tzname'.])
985   fi
987 ])# AC_STRUCT_TIMEZONE