Rewrite module 'stdint' to be fully autoconfiguring.
authorBruno Haible <bruno@clisp.org>
Fri, 16 Jun 2006 13:29:51 +0000 (13:29 +0000)
committerBruno Haible <bruno@clisp.org>
Fri, 16 Jun 2006 13:29:51 +0000 (13:29 +0000)
ChangeLog
lib/ChangeLog
lib/stdint_.h
m4/ChangeLog
m4/stdint.m4
modules/stdint

index 22bf35e..4a9e77b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-06-15  Bruno Haible  <bruno@clisp.org>
+
+       * modules/stdint (Files): Include m4/full-header-path.m4,
+       m4/size_max.m4, m4/wchar_t.m4.
+       (Makefile.am): Many more substitutions.
+       * modules/stdint-tests: New file.
+       * tests/test-stdint.c: New file.
+
 2006-05-15  Bruno Haible  <bruno@clisp.org>
 
        * build-aux/config.rpath: Improve support for Sun C 5.9 on Linux, based
index 6c3d7dd..9fb9ad9 100644 (file)
@@ -1,3 +1,8 @@
+2006-06-15  Bruno Haible  <bruno@clisp.org>
+
+       * stdint_.h: Rewritten to be fully auto-configured.
+       Fixes bug on HP-UX/IA64.
+
 2006-06-11  Paul Eggert  <eggert@cs.ucla.edu>
 
        * getdate.y (__attribute__): Don't define if already defined.
index 53d8ab1..5ac8ce8 100644 (file)
@@ -26,7 +26,7 @@
 
 /* Get wchar_t, WCHAR_MIN, WCHAR_MAX.  */
 #include <stddef.h>
-/* Get CHAR_BIT, LONG_MIN, LONG_MAX, ULONG_MAX.  */
+/* Get LONG_MIN, LONG_MAX, ULONG_MAX.  */
 #include <limits.h>
 
 /* Get those types that are already defined in other system include files.  */
      <inttypes.h> includes <machine/types.h> and also defines intptr_t and
      uintptr_t.  */
 # include <sys/types.h>
-# if HAVE_INTTYPES_H
-#  include <inttypes.h>
+# if @HAVE_INTTYPES_H@
+#  include @FULL_PATH_INTTYPES_H@
 # endif
 #endif
-#if defined(__linux__) && HAVE_SYS_BITYPES_H
+#if defined(__linux__) && @HAVE_SYS_BITYPES_H@
   /* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines
      int{8,16,32,64}_t and __BIT_TYPES_DEFINED__.  In libc5 >= 5.2.2 it is
      included by <sys/types.h>.  */
 # include <sys/bitypes.h>
 #endif
-#if defined(__sun) && HAVE_SYS_INTTYPES_H
-# include <sys/inttypes.h>
+#if defined(__sun) && @HAVE_SYS_INTTYPES_H@
   /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
      the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX.
      But note that <sys/int_types.h> contains only the type definitions!  */
-# define _STDINT_H_HAVE_SYSTEM_INTTYPES
+# include <sys/inttypes.h>
 #endif
-#if (defined(__hpux) || defined(_AIX)) && HAVE_INTTYPES_H
-# include <inttypes.h>
+#if (defined(__hpux) || defined(_AIX)) && @HAVE_INTTYPES_H@
   /* HP-UX 10 <inttypes.h> has nearly everything, except UINT_LEAST8_MAX,
      UINT_FAST8_MAX, PTRDIFF_MIN, PTRDIFF_MAX.  */
   /* AIX 4 <inttypes.h> has nearly everything, except INTPTR_MIN, INTPTR_MAX,
      UINTPTR_MAX, PTRDIFF_MIN, PTRDIFF_MAX.  */
-# define _STDINT_H_HAVE_SYSTEM_INTTYPES
+# include @FULL_PATH_INTTYPES_H@
 #endif
-#if !((defined(__CYGWIN__) || defined(__linux__)) && defined(__BIT_TYPES_DEFINED__))
-# define _STDINT_H_NEED_SIGNED_INT_TYPES
+#if @HAVE_STDINT_H@
+  /* Other systems may have an incomplete <stdint.h>.  */
+# include @FULL_PATH_STDINT_H@
 #endif
 
-#if !defined(_STDINT_H_HAVE_SYSTEM_INTTYPES)
-
 /* 7.18.1.1. Exact-width integer types */
 
-#if !(defined(__FreeBSD__) || defined(__OpenBSD__))
+/* Here we assume a standard architecture where the hardware integer
+   types have 8, 16, 32, optionally 64 bits.  */
 
-#ifdef _STDINT_H_NEED_SIGNED_INT_TYPES
+#if !@HAVE_INT8_T@
 typedef signed char    int8_t;
 #endif
+#if !@HAVE_UINT8_T@
 typedef unsigned char  uint8_t;
+#endif
 
-#ifdef _STDINT_H_NEED_SIGNED_INT_TYPES
+#if !@HAVE_INT16_T@
 typedef short          int16_t;
 #endif
+#if !@HAVE_UINT16_T@
 typedef unsigned short uint16_t;
+#endif
 
-#ifdef _STDINT_H_NEED_SIGNED_INT_TYPES
+#if !@HAVE_INT32_T@
 typedef int            int32_t;
 #endif
+#if !@HAVE_UINT32_T@
 typedef unsigned int   uint32_t;
+#endif
 
-#if @HAVE_LONG_64BIT@
-#ifdef _STDINT_H_NEED_SIGNED_INT_TYPES
+#if @HAVE_INT64_T@
+# define _STDINT_H_HAVE_INT64 1
+#else
+# if @HAVE_LONG_64BIT@
 typedef long           int64_t;
+#  define _STDINT_H_HAVE_INT64 1
+# elif @HAVE_LONG_LONG_64BIT@
+typedef long long      int64_t;
+#  define _STDINT_H_HAVE_INT64 1
+# elif defined _MSC_VER
+typedef __int64        int64_t;
+#  define _STDINT_H_HAVE_INT64 1
+# endif
 #endif
-typedef unsigned long  uint64_t;
-#define _STDINT_H_HAVE_INT64
-#elif @HAVE_LONG_LONG_64BIT@
-#ifdef _STDINT_H_NEED_SIGNED_INT_TYPES
-typedef long long          int64_t;
-#endif
+#if @HAVE_UINT64_T@
+# define _STDINT_H_HAVE_UINT64 1
+#else
+# if @HAVE_LONG_64BIT@
+typedef unsigned long      uint64_t;
+#  define _STDINT_H_HAVE_UINT64 1
+# elif @HAVE_LONG_LONG_64BIT@
 typedef unsigned long long uint64_t;
-#define _STDINT_H_HAVE_INT64
-#elif defined(_MSC_VER)
-typedef __int64          int64_t;
-typedef unsigned __int64 uint64_t;
-#define _STDINT_H_HAVE_INT64
+#  define _STDINT_H_HAVE_UINT64 1
+# elif defined _MSC_VER
+typedef unsigned __int64   uint64_t;
+#  define _STDINT_H_HAVE_UINT64 1
+# endif
 #endif
 
-#endif /* !(FreeBSD || OpenBSD) */
-
 /* 7.18.1.2. Minimum-width integer types */
 
+/* Here we assume a standard architecture where the hardware integer
+   types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
+   are the same as the corresponding N_t types.  */
+
+#if !@HAVE_INT_LEAST8_T@
 typedef int8_t   int_least8_t;
+#endif
+#if !@HAVE_UINT_LEAST8_T@
 typedef uint8_t  uint_least8_t;
+#endif
+
+#if !@HAVE_INT_LEAST16_T@
 typedef int16_t  int_least16_t;
+#endif
+#if !@HAVE_UINT_LEAST16_T@
 typedef uint16_t uint_least16_t;
+#endif
+
+#if !@HAVE_INT_LEAST32_T@
 typedef int32_t  int_least32_t;
+#endif
+#if !@HAVE_UINT_LEAST32_T@
 typedef uint32_t uint_least32_t;
-#ifdef _STDINT_H_HAVE_INT64
+#endif
+
+#if !@HAVE_INT_LEAST64_T@ && _STDINT_H_HAVE_INT64
 typedef int64_t  int_least64_t;
+#endif
+#if !@HAVE_UINT_LEAST64_T@ && _STDINT_H_HAVE_UINT64
 typedef uint64_t uint_least64_t;
 #endif
 
 /* 7.18.1.3. Fastest minimum-width integer types */
 
+/* Note: Other <stdint.h> substitutes may define these types differently.
+   It is not recommended to use these types in public header files. */
+
+/* Here we assume a standard architecture where the hardware integer
+   types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
+   are taken from the same list of types.  */
+
+/* On alpha processors, int32_t variables are slower than int64_t variables,
+   due to the necessary zap instructions.  */
+#if defined __alpha
+# define _STDINT_H_INT64_FASTER_THAN_INT32 1
+#endif
+
+#if !@HAVE_INT_FAST8_T@
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+typedef int64_t  int_fast8_t;
+# else
 typedef int32_t  int_fast8_t;
+# endif
+#endif
+#if !@HAVE_UINT_FAST8_T@
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+typedef uint64_t uint_fast8_t;
+# else
 typedef uint32_t uint_fast8_t;
+# endif
+#endif
+
+#if !@HAVE_INT_FAST16_T@
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+typedef int64_t  int_fast16_t;
+# else
 typedef int32_t  int_fast16_t;
+# endif
+#endif
+#if !@HAVE_UINT_FAST16_T@
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+typedef uint64_t uint_fast16_t;
+# else
 typedef uint32_t uint_fast16_t;
+# endif
+#endif
+
+#if !@HAVE_INT_FAST32_T@
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+typedef int64_t  int_fast32_t;
+# else
 typedef int32_t  int_fast32_t;
+# endif
+#endif
+#if !@HAVE_UINT_FAST32_T@
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+typedef uint64_t uint_fast32_t;
+# else
 typedef uint32_t uint_fast32_t;
-#ifdef _STDINT_H_HAVE_INT64
+# endif
+#endif
+
+#if !@HAVE_INT_FAST64_T@ && _STDINT_H_HAVE_INT64
 typedef int64_t  int_fast64_t;
+#endif
+#if !@HAVE_UINT_FAST64_T@ && _STDINT_H_HAVE_UINT64
 typedef uint64_t uint_fast64_t;
 #endif
 
 /* 7.18.1.4. Integer types capable of holding object pointers */
 
-#if !(defined(__FreeBSD__) || (defined(__OpenBSD__) && HAVE_INTTYPES_H))
-
 /* On some platforms (like IRIX6 MIPS with -n32) sizeof(void*) < sizeof(long),
    but this doesn't matter here.  */
+#if !@HAVE_INTPTR_T@
 typedef long          intptr_t;
+#endif
+#if !@HAVE_UINTPTR_T@
 typedef unsigned long uintptr_t;
-
-#endif /* !(FreeBSD || (OpenBSD && HAVE_INTTYPES_H)) */
+#endif
 
 /* 7.18.1.5. Greatest-width integer types */
 
-#ifdef _STDINT_H_HAVE_INT64
-# ifndef intmax_t
+/* Note: These types are compiler dependent. It may be unwise to use them in
+   public header files. */
+
+#if !@HAVE_INTMAX_T@
+# ifdef _STDINT_H_HAVE_INT64
 typedef int64_t  intmax_t;
-# endif
-# ifndef uintmax_t
-typedef uint64_t uintmax_t;
-# endif
-#else
-# ifndef intmax_t
+# else
 typedef int32_t  intmax_t;
 # endif
-# ifndef uintmax_t
+#endif
+#if !@HAVE_UINTMAX_T@
+# ifdef _STDINT_H_HAVE_UINT64
+typedef uint64_t uintmax_t;
+# else
 typedef uint32_t uintmax_t;
 # endif
 #endif
@@ -170,96 +260,659 @@ typedef uint32_t uintmax_t;
 
 /* 7.18.2.1. Limits of exact-width integer types */
 
-#define INT8_MIN  -128
-#define INT8_MAX   127
-#define UINT8_MAX  255U
-#define INT16_MIN  -32768
-#define INT16_MAX   32767
-#define UINT16_MAX  65535U
-#define INT32_MIN   (~INT32_MAX)
-#define INT32_MAX   2147483647
-#define UINT32_MAX  4294967295U
-#ifdef _STDINT_H_HAVE_INT64
-#define INT64_MIN   (~INT64_MAX)
-#if @HAVE_LONG_64BIT@
-#define INT64_MAX   9223372036854775807L
-#define UINT64_MAX 18446744073709551615UL
-#elif @HAVE_LONG_LONG_64BIT@
-#define INT64_MAX   9223372036854775807LL
-#define UINT64_MAX 18446744073709551615ULL
-#elif defined(_MSC_VER)
-#define INT64_MAX   9223372036854775807i64
-#define UINT64_MAX 18446744073709551615ui64
+/* Here we assume a standard architecture where the hardware integer
+   types have 8, 16, 32, optionally 64 bits.  */
+
+#if @HAVE_INT8_T@
+# ifndef INT8_MIN
+#  define INT8_MIN  (-1 << (@BITSIZEOF_INT8_T@ - 1))
+# endif
+#else
+# define INT8_MIN  -128
+#endif
+#if @HAVE_INT8_T@
+# ifndef INT8_MAX
+#  define INT8_MAX  (~ (-1 << (@BITSIZEOF_INT8_T@ - 1)))
+# endif
+#else
+# define INT8_MAX  127
+#endif
+#if @HAVE_UINT8_T@
+# ifndef UINT8_MAX
+#  if @BITSIZEOF_UINT8_T@ < @BITSIZEOF_UNSIGNED_INT@
+#   define UINT8_MAX  (((1 << (@BITSIZEOF_UINT8_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define UINT8_MAX  (((1U << (@BITSIZEOF_UINT8_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# define UINT8_MAX  255
+#endif
+
+#if @HAVE_INT16_T@
+# ifndef INT16_MIN
+#  define INT16_MIN  (-1 << (@BITSIZEOF_INT16_T@ - 1))
+# endif
+#else
+# define INT16_MIN  -32768
+#endif
+#if @HAVE_INT16_T@
+# ifndef INT16_MAX
+#  define INT16_MAX  (~ (-1 << (@BITSIZEOF_INT16_T@ - 1)))
+# endif
+#else
+# define INT16_MAX  32767
 #endif
+#if @HAVE_UINT16_T@
+# ifndef UINT16_MAX
+#  if @BITSIZEOF_UINT16_T@ < @BITSIZEOF_UNSIGNED_INT@
+#   define UINT16_MAX  (((1 << (@BITSIZEOF_UINT16_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define UINT16_MAX  (((1U << (@BITSIZEOF_UINT16_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# define UINT16_MAX  65535
+#endif
+
+#if @HAVE_INT32_T@
+# ifndef INT32_MIN
+#  define INT32_MIN  (-1 << (@BITSIZEOF_INT32_T@ - 1))
+# endif
+#else
+# define INT32_MIN  (~INT32_MAX)
+#endif
+#if @HAVE_INT32_T@
+# ifndef INT32_MAX
+#  define INT32_MAX  (~ (-1 << (@BITSIZEOF_INT32_T@ - 1)))
+# endif
+#else
+# define INT32_MAX  2147483647
+#endif
+#if @HAVE_UINT32_T@
+# ifndef UINT32_MAX
+#  if @BITSIZEOF_UINT32_T@ < @BITSIZEOF_UNSIGNED_INT@
+#   define UINT32_MAX  (((1 << (@BITSIZEOF_UINT32_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define UINT32_MAX  (((1U << (@BITSIZEOF_UINT32_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# define UINT32_MAX  4294967295U
+#endif
+
+#if @HAVE_INT64_T@
+# ifndef INT64_MIN
+#  if @HAVE_LONG_64BIT@
+#   define INT64_MIN  (-1L << (@BITSIZEOF_INT64_T@ - 1))
+#  elif @HAVE_LONG_LONG_64BIT@
+#   define INT64_MIN  (-1LL << (@BITSIZEOF_INT64_T@ - 1))
+#  elif defined _MSC_VER
+#   define INT64_MIN  (-1i64 << (@BITSIZEOF_INT64_T@ - 1))
+#  endif
+# endif
+#else
+# ifdef _STDINT_H_HAVE_INT64
+#  define INT64_MIN  (~INT64_MAX)
+# endif
+#endif
+#if @HAVE_INT64_T@
+# ifndef INT64_MAX
+#  if @HAVE_LONG_64BIT@
+#   define INT64_MAX  (~ (-1L << (@BITSIZEOF_INT64_T@ - 1)))
+#  elif @HAVE_LONG_LONG_64BIT@
+#   define INT64_MAX  (~ (-1LL << (@BITSIZEOF_INT64_T@ - 1)))
+#  elif defined _MSC_VER
+#   define INT64_MAX  (~ (-1i64 << (@BITSIZEOF_INT64_T@ - 1)))
+#  endif
+# endif
+#else
+# ifdef _STDINT_H_HAVE_INT64
+#  if @HAVE_LONG_64BIT@
+#   define INT64_MAX  9223372036854775807L
+#  elif @HAVE_LONG_LONG_64BIT@
+#   define INT64_MAX  9223372036854775807LL
+#  elif defined _MSC_VER
+#   define INT64_MAX  9223372036854775807i64
+#  endif
+# endif
+#endif
+#if @HAVE_UINT64_T@
+# ifndef UINT64_MAX
+#  if @HAVE_LONG_64BIT@
+#   define UINT64_MAX  (((1UL << (@BITSIZEOF_UINT64_T@ - 1)) - 1) * 2 + 1)
+#  elif @HAVE_LONG_LONG_64BIT@
+#   define UINT64_MAX  (((1ULL << (@BITSIZEOF_UINT64_T@ - 1)) - 1) * 2 + 1)
+#  elif defined _MSC_VER
+#   define UINT64_MAX  (((1ui64 << (@BITSIZEOF_UINT64_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# ifdef _STDINT_H_HAVE_UINT64
+#  if @HAVE_LONG_64BIT@
+#   define UINT64_MAX 18446744073709551615UL
+#  elif @HAVE_LONG_LONG_64BIT@
+#   define UINT64_MAX 18446744073709551615ULL
+#  elif defined _MSC_VER
+#   define UINT64_MAX 18446744073709551615ui64
+#  endif
+# endif
 #endif
 
 /* 7.18.2.2. Limits of minimum-width integer types */
 
-#define INT_LEAST8_MIN INT8_MIN
-#define INT_LEAST8_MAX INT8_MAX
-#define UINT_LEAST8_MAX UINT8_MAX
-#define INT_LEAST16_MIN INT16_MIN
-#define INT_LEAST16_MAX INT16_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-#define INT_LEAST32_MIN INT32_MIN
-#define INT_LEAST32_MAX INT32_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-#ifdef _STDINT_H_HAVE_INT64
-#define INT_LEAST64_MIN INT64_MIN
-#define INT_LEAST64_MAX INT64_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
+/* Here we assume a standard architecture where the hardware integer
+   types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
+   are the same as the corresponding N_t types.  */
+
+#if @HAVE_INT_LEAST8_T@
+# ifndef INT_LEAST8_MIN
+#  define INT_LEAST8_MIN  (-1 << (@BITSIZEOF_INT_LEAST8_T@ - 1))
+# endif
+#else
+# define INT_LEAST8_MIN  INT8_MIN
+#endif
+#if @HAVE_INT_LEAST8_T@
+# ifndef INT_LEAST8_MAX
+#  define INT_LEAST8_MAX  (~ (-1 << (@BITSIZEOF_INT_LEAST8_T@ - 1)))
+# endif
+#else
+# define INT_LEAST8_MAX  INT8_MAX
+#endif
+#if @HAVE_UINT_LEAST8_T@
+# ifndef UINT_LEAST8_MAX
+#  if @BITSIZEOF_UINT_LEAST8_T@ < @BITSIZEOF_UNSIGNED_INT@
+#   define UINT_LEAST8_MAX  (((1 << (@BITSIZEOF_UINT_LEAST8_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define UINT_LEAST8_MAX  (((1U << (@BITSIZEOF_UINT_LEAST8_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# define UINT_LEAST8_MAX  UINT8_MAX
+#endif
+
+#if @HAVE_INT_LEAST16_T@
+# ifndef INT_LEAST16_MIN
+#  define INT_LEAST16_MIN  (-1 << (@BITSIZEOF_INT_LEAST16_T@ - 1))
+# endif
+#else
+# define INT_LEAST16_MIN  INT16_MIN
+#endif
+#if @HAVE_INT_LEAST16_T@
+# ifndef INT_LEAST16_MAX
+#  define INT_LEAST16_MAX  (~ (-1 << (@BITSIZEOF_INT_LEAST16_T@ - 1)))
+# endif
+#else
+# define INT_LEAST16_MAX  INT16_MAX
+#endif
+#if @HAVE_UINT_LEAST16_T@
+# ifndef UINT_LEAST16_MAX
+#  if @BITSIZEOF_UINT_LEAST16_T@ < @BITSIZEOF_UNSIGNED_INT@
+#   define UINT_LEAST16_MAX  (((1 << (@BITSIZEOF_UINT_LEAST16_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define UINT_LEAST16_MAX  (((1U << (@BITSIZEOF_UINT_LEAST16_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# define UINT_LEAST16_MAX  UINT16_MAX
+#endif
+
+#if @HAVE_INT_LEAST32_T@
+# ifndef INT_LEAST32_MIN
+#  define INT_LEAST32_MIN  (-1 << (@BITSIZEOF_INT_LEAST32_T@ - 1))
+# endif
+#else
+# define INT_LEAST32_MIN  INT32_MIN
+#endif
+#if @HAVE_INT_LEAST32_T@
+# ifndef INT_LEAST32_MAX
+#  define INT_LEAST32_MAX  (~ (-1 << (@BITSIZEOF_INT_LEAST32_T@ - 1)))
+# endif
+#else
+# define INT_LEAST32_MAX  INT32_MAX
+#endif
+#if @HAVE_UINT_LEAST32_T@
+# ifndef UINT_LEAST32_MAX
+#  if @BITSIZEOF_UINT_LEAST32_T@ < @BITSIZEOF_UNSIGNED_INT@
+#   define UINT_LEAST32_MAX  (((1 << (@BITSIZEOF_UINT_LEAST32_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define UINT_LEAST32_MAX  (((1U << (@BITSIZEOF_UINT_LEAST32_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# define UINT_LEAST32_MAX  UINT32_MAX
+#endif
+
+#if @HAVE_INT_LEAST64_T@
+# ifndef INT_LEAST64_MIN
+#  if @HAVE_LONG_64BIT@
+#   define INT_LEAST64_MIN  (-1L << (@BITSIZEOF_INT_LEAST64_T@ - 1))
+#  elif @HAVE_LONG_LONG_64BIT@
+#   define INT_LEAST64_MIN  (-1LL << (@BITSIZEOF_INT_LEAST64_T@ - 1))
+#  elif defined _MSC_VER
+#   define INT_LEAST64_MIN  (-1i64 << (@BITSIZEOF_INT_LEAST64_T@ - 1))
+#  endif
+# endif
+#else
+# ifdef _STDINT_H_HAVE_INT64
+#  define INT_LEAST64_MIN  INT64_MIN
+# endif
+#endif
+#if @HAVE_INT_LEAST64_T@
+# ifndef INT_LEAST64_MAX
+#  if @HAVE_LONG_64BIT@
+#   define INT_LEAST64_MAX  (~ (-1L << (@BITSIZEOF_INT_LEAST64_T@ - 1)))
+#  elif @HAVE_LONG_LONG_64BIT@
+#   define INT_LEAST64_MAX  (~ (-1LL << (@BITSIZEOF_INT_LEAST64_T@ - 1)))
+#  elif defined _MSC_VER
+#   define INT_LEAST64_MAX  (~ (-1i64 << (@BITSIZEOF_INT_LEAST64_T@ - 1)))
+#  endif
+# endif
+#else
+# ifdef _STDINT_H_HAVE_INT64
+#  define INT_LEAST64_MAX  INT64_MAX
+# endif
+#endif
+#if @HAVE_UINT_LEAST64_T@
+# ifndef UINT_LEAST64_MAX
+#  if @HAVE_LONG_64BIT@
+#   define UINT_LEAST64_MAX  (((1UL << (@BITSIZEOF_UINT_LEAST64_T@ - 1)) - 1) * 2 + 1)
+#  elif @HAVE_LONG_LONG_64BIT@
+#   define UINT_LEAST64_MAX  (((1ULL << (@BITSIZEOF_UINT_LEAST64_T@ - 1)) - 1) * 2 + 1)
+#  elif defined _MSC_VER
+#   define UINT_LEAST64_MAX  (((1ui64 << (@BITSIZEOF_UINT_LEAST64_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# ifdef _STDINT_H_HAVE_UINT64
+#  define UINT_LEAST64_MAX  UINT64_MAX
+# endif
 #endif
 
 /* 7.18.2.3. Limits of fastest minimum-width integer types */
 
-#define INT_FAST8_MIN INT32_MIN
-#define INT_FAST8_MAX INT32_MAX
-#define UINT_FAST8_MAX UINT32_MAX
-#define INT_FAST16_MIN INT32_MIN
-#define INT_FAST16_MAX INT32_MAX
-#define UINT_FAST16_MAX UINT32_MAX
-#define INT_FAST32_MIN INT32_MIN
-#define INT_FAST32_MAX INT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-#ifdef _STDINT_H_HAVE_INT64
-#define INT_FAST64_MIN INT64_MIN
-#define INT_FAST64_MAX INT64_MAX
-#define UINT_FAST64_MAX UINT64_MAX
+/* Here we assume a standard architecture where the hardware integer
+   types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
+   are taken from the same list of types.  */
+
+#if @HAVE_INT_FAST8_T@
+# ifndef INT_FAST8_MIN
+#  define INT_FAST8_MIN  (-1L << (@BITSIZEOF_INT_FAST8_T@ - 1))
+# endif
+#else
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+#  define INT_FAST8_MIN  INT64_MIN
+# else
+#  define INT_FAST8_MIN  INT32_MIN
+# endif
+#endif
+#if @HAVE_INT_FAST8_T@
+# ifndef INT_FAST8_MAX
+#  define INT_FAST8_MAX  (~ (-1L << (@BITSIZEOF_INT_FAST8_T@ - 1)))
+# endif
+#else
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+#  define INT_FAST8_MAX  INT64_MAX
+# else
+#  define INT_FAST8_MAX  INT32_MAX
+# endif
+#endif
+#if @HAVE_UINT_FAST8_T@
+# ifndef UINT_FAST8_MAX
+#  if @BITSIZEOF_UINT_FAST8_T@ < @BITSIZEOF_UNSIGNED_INT@
+#   define UINT_FAST8_MAX  (((1 << (@BITSIZEOF_UINT_FAST8_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define UINT_FAST8_MAX  (((1UL << (@BITSIZEOF_UINT_FAST8_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+#  define UINT_FAST8_MAX  UINT64_MAX
+# else
+#  define UINT_FAST8_MAX  UINT32_MAX
+# endif
+#endif
+
+#if @HAVE_INT_FAST16_T@
+# ifndef INT_FAST16_MIN
+#  define INT_FAST16_MIN  (-1L << (@BITSIZEOF_INT_FAST16_T@ - 1))
+# endif
+#else
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+#  define INT_FAST16_MIN  INT64_MIN
+# else
+#  define INT_FAST16_MIN  INT32_MIN
+# endif
+#endif
+#if @HAVE_INT_FAST16_T@
+# ifndef INT_FAST16_MAX
+#  define INT_FAST16_MAX  (~ (-1L << (@BITSIZEOF_INT_FAST16_T@ - 1)))
+# endif
+#else
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+#  define INT_FAST16_MAX  INT64_MAX
+# else
+#  define INT_FAST16_MAX  INT32_MAX
+# endif
+#endif
+#if @HAVE_UINT_FAST16_T@
+# ifndef UINT_FAST16_MAX
+#  if @BITSIZEOF_UINT_FAST16_T@ < @BITSIZEOF_UNSIGNED_INT@
+#   define UINT_FAST16_MAX  (((1 << (@BITSIZEOF_UINT_FAST16_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define UINT_FAST16_MAX  (((1UL << (@BITSIZEOF_UINT_FAST16_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+#  define UINT_FAST16_MAX  UINT64_MAX
+# else
+#  define UINT_FAST16_MAX  UINT32_MAX
+# endif
+#endif
+
+#if @HAVE_INT_FAST32_T@
+# ifndef INT_FAST32_MIN
+#  define INT_FAST32_MIN  (-1L << (@BITSIZEOF_INT_FAST32_T@ - 1))
+# endif
+#else
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+#  define INT_FAST32_MIN  INT64_MIN
+# else
+#  define INT_FAST32_MIN  INT32_MIN
+# endif
+#endif
+#if @HAVE_INT_FAST32_T@
+# ifndef INT_FAST32_MAX
+#  define INT_FAST32_MAX  (~ (-1L << (@BITSIZEOF_INT_FAST32_T@ - 1)))
+# endif
+#else
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+#  define INT_FAST32_MAX  INT64_MAX
+# else
+#  define INT_FAST32_MAX  INT32_MAX
+# endif
+#endif
+#if @HAVE_UINT_FAST32_T@
+# ifndef UINT_FAST32_MAX
+#  if @BITSIZEOF_UINT_FAST32_T@ < @BITSIZEOF_UNSIGNED_INT@
+#   define UINT_FAST32_MAX  (((1 << (@BITSIZEOF_UINT_FAST32_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define UINT_FAST32_MAX  (((1UL << (@BITSIZEOF_UINT_FAST32_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# if _STDINT_H_INT64_FASTER_THAN_INT32
+#  define UINT_FAST32_MAX  UINT64_MAX
+# else
+#  define UINT_FAST32_MAX  UINT32_MAX
+# endif
+#endif
+
+#if @HAVE_INT_FAST64_T@
+# ifndef INT_FAST64_MIN
+#  if @HAVE_LONG_64BIT@
+#   define INT_FAST64_MIN  (-1L << (@BITSIZEOF_INT_FAST64_T@ - 1))
+#  elif @HAVE_LONG_LONG_64BIT@
+#   define INT_FAST64_MIN  (-1LL << (@BITSIZEOF_INT_FAST64_T@ - 1))
+#  elif defined _MSC_VER
+#   define INT_FAST64_MIN  (-1i64 << (@BITSIZEOF_INT_FAST64_T@ - 1))
+#  endif
+# endif
+#else
+# ifdef _STDINT_H_HAVE_INT64
+#  define INT_FAST64_MIN  INT64_MIN
+# endif
+#endif
+#if @HAVE_INT_FAST64_T@
+# ifndef INT_FAST64_MAX
+#  if @HAVE_LONG_64BIT@
+#   define INT_FAST64_MAX  (~ (-1L << (@BITSIZEOF_INT_FAST64_T@ - 1)))
+#  elif @HAVE_LONG_LONG_64BIT@
+#   define INT_FAST64_MAX  (~ (-1LL << (@BITSIZEOF_INT_FAST64_T@ - 1)))
+#  elif defined _MSC_VER
+#   define INT_FAST64_MAX  (~ (-1i64 << (@BITSIZEOF_INT_FAST64_T@ - 1)))
+#  endif
+# endif
+#else
+# ifdef _STDINT_H_HAVE_INT64
+#  define INT_FAST64_MAX  INT64_MAX
+# endif
+#endif
+#if @HAVE_UINT_FAST64_T@
+# ifndef UINT_FAST64_MAX
+#  if @HAVE_LONG_64BIT@
+#   define UINT_FAST64_MAX  (((1UL << (@BITSIZEOF_UINT_FAST64_T@ - 1)) - 1) * 2 + 1)
+#  elif @HAVE_LONG_LONG_64BIT@
+#   define UINT_FAST64_MAX  (((1ULL << (@BITSIZEOF_UINT_FAST64_T@ - 1)) - 1) * 2 + 1)
+#  elif defined _MSC_VER
+#   define UINT_FAST64_MAX  (((1ui64 << (@BITSIZEOF_UINT_FAST64_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# ifdef _STDINT_H_HAVE_UINT64
+#  define UINT_FAST64_MAX  UINT64_MAX
+# endif
 #endif
 
 /* 7.18.2.4. Limits of integer types capable of holding object pointers */
 
-#define INTPTR_MIN LONG_MIN
-#define INTPTR_MAX LONG_MAX
-#define UINTPTR_MAX ULONG_MAX
+#if @HAVE_INTPTR_T@
+# ifndef INTPTR_MIN
+#  if @BITSIZEOF_INTPTR_T@ > @BITSIZEOF_LONG@
+#   define INTPTR_MIN  (-1LL << (@BITSIZEOF_INTPTR_T@ - 1))
+#  else
+#   define INTPTR_MIN  (-1L << (@BITSIZEOF_INTPTR_T@ - 1))
+#  endif
+# endif
+#else
+# define INTPTR_MIN  LONG_MIN
+#endif
+#if @HAVE_INTPTR_T@
+# ifndef INTPTR_MAX
+#  if @BITSIZEOF_INTPTR_T@ > @BITSIZEOF_LONG@
+#   define INTPTR_MAX  (~ (-1LL << (@BITSIZEOF_INTPTR_T@ - 1)))
+#  else
+#   define INTPTR_MAX  (~ (-1L << (@BITSIZEOF_INTPTR_T@ - 1)))
+#  endif
+# endif
+#else
+# define INTPTR_MAX  LONG_MAX
+#endif
+#if @HAVE_UINTPTR_T@
+# ifndef UINTPTR_MAX
+#  if @BITSIZEOF_UINTPTR_T@ > @BITSIZEOF_UNSIGNED_LONG@
+#   define UINTPTR_MAX  (((1ULL << (@BITSIZEOF_UINTPTR_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define UINTPTR_MAX  (((1UL << (@BITSIZEOF_UINTPTR_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#else
+# define UINTPTR_MAX  ULONG_MAX
+#endif
 
 /* 7.18.2.5. Limits of greatest-width integer types */
 
-#ifdef _STDINT_H_HAVE_INT64
-#define INTMAX_MIN INT64_MIN
-#define INTMAX_MAX INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
+#if @HAVE_INTMAX_T@
+# ifndef INTMAX_MIN
+#  if @BITSIZEOF_INTMAX_T@ > @BITSIZEOF_LONG@
+#   define INTMAX_MIN  (-1LL << (@BITSIZEOF_INTMAX_T@ - 1))
+#  else
+#   define INTMAX_MIN  (-1L << (@BITSIZEOF_INTMAX_T@ - 1))
+#  endif
+# endif
+#else
+# ifdef _STDINT_H_HAVE_INT64
+#  define INTMAX_MIN  INT64_MIN
+# else
+#  define INTMAX_MIN  INT32_MIN
+# endif
+#endif
+#if @HAVE_INTMAX_T@
+# ifndef INTMAX_MAX
+#  if @BITSIZEOF_INTMAX_T@ > @BITSIZEOF_LONG@
+#   define INTMAX_MAX  (~ (-1LL << (@BITSIZEOF_INTMAX_T@ - 1)))
+#  else
+#   define INTMAX_MAX  (~ (-1L << (@BITSIZEOF_INTMAX_T@ - 1)))
+#  endif
+# endif
+#else
+# ifdef _STDINT_H_HAVE_INT64
+#  define INTMAX_MAX  INT64_MAX
+# else
+#  define INTMAX_MAX  INT32_MAX
+# endif
+#endif
+#if @HAVE_UINTMAX_T@
+# ifndef UINTMAX_MAX
+#  if @BITSIZEOF_UINTMAX_T@ > @BITSIZEOF_UNSIGNED_LONG@
+#   define UINTMAX_MAX  (((1ULL << (@BITSIZEOF_UINTMAX_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define UINTMAX_MAX  (((1UL << (@BITSIZEOF_UINTMAX_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
 #else
-#define INTMAX_MIN INT32_MIN
-#define INTMAX_MAX INT32_MAX
-#define UINTMAX_MAX UINT32_MAX
+# ifdef _STDINT_H_HAVE_INT64
+#  define UINTMAX_MAX  UINT64_MAX
+# else
+#  define UINTMAX_MAX  UINT32_MAX
+# endif
 #endif
 
 /* 7.18.3. Limits of other integer types */
 
-#define PTRDIFF_MIN (~(ptrdiff_t)0 << (sizeof(ptrdiff_t)*CHAR_BIT-1))
-#define PTRDIFF_MAX (~PTRDIFF_MIN)
+/* ptrdiff_t limits */
+#ifndef PTRDIFF_MIN
+# if @BITSIZEOF_PTRDIFF_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_PTRDIFF_T_LONG@
+#  define PTRDIFF_MIN  (-1L << (@BITSIZEOF_PTRDIFF_T@ - 1))
+# else
+#  define PTRDIFF_MIN  (-1 << (@BITSIZEOF_PTRDIFF_T@ - 1))
+# endif
+#endif
+#ifndef PTRDIFF_MAX
+# if @BITSIZEOF_PTRDIFF_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_PTRDIFF_T_LONG@
+#  define PTRDIFF_MAX  (~ (-1L << (@BITSIZEOF_PTRDIFF_T@ - 1)))
+# else
+#  define PTRDIFF_MAX  (~ (-1 << (@BITSIZEOF_PTRDIFF_T@ - 1)))
+# endif
+#endif
 
-/* This may be wrong...  */
-#define SIG_ATOMIC_MIN 0
-#define SIG_ATOMIC_MAX 127
+/* sig_atomic_t limits */
+#ifndef SIG_ATOMIC_MIN
+# if @HAVE_SIGNED_SIG_ATOMIC_T@
+#  if @BITSIZEOF_SIG_ATOMIC_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_SIG_ATOMIC_T_LONG@
+#   define SIG_ATOMIC_MIN  (-1L << (@BITSIZEOF_SIG_ATOMIC_T@ - 1))
+#  else
+#   define SIG_ATOMIC_MIN  (-1 << (@BITSIZEOF_SIG_ATOMIC_T@ - 1))
+#  endif
+# else
+#  if @BITSIZEOF_SIG_ATOMIC_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_SIG_ATOMIC_T_UNSIGNED_LONG@
+#   define SIG_ATOMIC_MIN  0UL
+#  elif @BITSIZEOF_SIG_ATOMIC_T@ >= @BITSIZEOF_UNSIGNED_INT@
+#   define SIG_ATOMIC_MIN  0U
+#  else
+#   define SIG_ATOMIC_MIN  0
+#  endif
+# endif
+#endif
+#ifndef SIG_ATOMIC_MAX
+# if @HAVE_SIGNED_SIG_ATOMIC_T@
+#  if @BITSIZEOF_SIG_ATOMIC_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_SIG_ATOMIC_T_LONG@
+#   define SIG_ATOMIC_MAX  (~ (-1L << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)))
+#  else
+#   define SIG_ATOMIC_MAX  (~ (-1 << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)))
+#  endif
+# else
+#  if @BITSIZEOF_SIG_ATOMIC_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_SIG_ATOMIC_T_UNSIGNED_LONG@
+#   define SIG_ATOMIC_MAX  (((1UL << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)) - 1) * 2 + 1)
+#  elif @BITSIZEOF_SIG_ATOMIC_T@ >= @BITSIZEOF_UNSIGNED_INT@
+#   define SIG_ATOMIC_MAX  (((1U << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define SIG_ATOMIC_MAX  (((1 << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#endif
 
+/* size_t limit */
 #ifndef SIZE_MAX /* SIZE_MAX may also be defined in config.h. */
-# define SIZE_MAX ((size_t)~(size_t)0)
+# if @BITSIZEOF_SIZE_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_SIZE_T_UNSIGNED_LONG@
+#  define SIZE_MAX  (((1UL << (@BITSIZEOF_SIZE_T@ - 1)) - 1) * 2 + 1)
+# else
+#  define SIZE_MAX  (((1U << (@BITSIZEOF_SIZE_T@ - 1)) - 1) * 2 + 1)
+# endif
 #endif
 
-/* wchar_t limits already defined in <stddef.h>.  */
-/* wint_t limits already defined in <wchar.h>.  */
+/* wchar_t limits may already be defined in <stddef.h>.  */
+#ifndef WCHAR_MIN
+# if @HAVE_SIGNED_WCHAR_T@
+#  if @BITSIZEOF_WCHAR_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_WCHAR_T_LONG@
+#   define WCHAR_MIN  (-1L << (@BITSIZEOF_WCHAR_T@ - 1))
+#  else
+#   define WCHAR_MIN  (-1 << (@BITSIZEOF_WCHAR_T@ - 1))
+#  endif
+# else
+#  if @BITSIZEOF_WCHAR_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_WCHAR_T_UNSIGNED_LONG@
+#   define WCHAR_MIN  0UL
+#  elif @BITSIZEOF_WCHAR_T@ >= @BITSIZEOF_UNSIGNED_INT@
+#   define WCHAR_MIN  0U
+#  else
+#   define WCHAR_MIN  0
+#  endif
+# endif
+#endif
+#ifndef WCHAR_MAX
+# if @HAVE_SIGNED_WCHAR_T@
+#  if @BITSIZEOF_WCHAR_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_WCHAR_T_LONG@
+#   define WCHAR_MAX  (~ (-1L << (@BITSIZEOF_WCHAR_T@ - 1)))
+#  else
+#   define WCHAR_MAX  (~ (-1 << (@BITSIZEOF_WCHAR_T@ - 1)))
+#  endif
+# else
+#  if @BITSIZEOF_WCHAR_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_WCHAR_T_UNSIGNED_LONG@
+#   define WCHAR_MAX  (((1UL << (@BITSIZEOF_WCHAR_T@ - 1)) - 1) * 2 + 1)
+#  elif @BITSIZEOF_WCHAR_T@ >= @BITSIZEOF_UNSIGNED_INT@
+#   define WCHAR_MAX  (((1U << (@BITSIZEOF_WCHAR_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define WCHAR_MAX  (((1 << (@BITSIZEOF_WCHAR_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#endif
+
+/* wint_t limits */
+#ifndef WINT_MIN
+# if @HAVE_SIGNED_WINT_T@
+#  if @BITSIZEOF_WINT_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_WINT_T_LONG@
+#   define WINT_MIN  (-1L << (@BITSIZEOF_WINT_T@ - 1))
+#  else
+#   define WINT_MIN  (-1 << (@BITSIZEOF_WINT_T@ - 1))
+#  endif
+# else
+#  if @BITSIZEOF_WINT_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_WINT_T_UNSIGNED_LONG@
+#   define WINT_MIN  0UL
+#  elif @BITSIZEOF_WINT_T@ >= @BITSIZEOF_UNSIGNED_INT@
+#   define WINT_MIN  0U
+#  else
+#   define WINT_MIN  0
+#  endif
+# endif
+#endif
+#ifndef WINT_MAX
+# if @HAVE_SIGNED_WINT_T@
+#  if @BITSIZEOF_WINT_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_WINT_T_LONG@
+#   define WINT_MAX  (~ (-1L << (@BITSIZEOF_WINT_T@ - 1)))
+#  else
+#   define WINT_MAX  (~ (-1 << (@BITSIZEOF_WINT_T@ - 1)))
+#  endif
+# else
+#  if @BITSIZEOF_WINT_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_WINT_T_UNSIGNED_LONG@
+#   define WINT_MAX  (((1UL << (@BITSIZEOF_WINT_T@ - 1)) - 1) * 2 + 1)
+#  elif @BITSIZEOF_WINT_T@ >= @BITSIZEOF_UNSIGNED_INT@
+#   define WINT_MAX  (((1U << (@BITSIZEOF_WINT_T@ - 1)) - 1) * 2 + 1)
+#  else
+#   define WINT_MAX  (((1 << (@BITSIZEOF_WINT_T@ - 1)) - 1) * 2 + 1)
+#  endif
+# endif
+#endif
 
 #endif
 
@@ -269,41 +922,52 @@ typedef uint32_t uintmax_t;
 
 /* 7.18.4.1. Macros for minimum-width integer constants */
 
+#undef INT8_C
+#undef UINT8_C
 #define INT8_C(x) x
 #define UINT8_C(x) x##U
+
+#undef INT16_C
+#undef UINT16_C
 #define INT16_C(x) x
 #define UINT16_C(x) x##U
+
+#undef INT32_C
+#undef UINT32_C
 #define INT32_C(x) x
 #define UINT32_C(x) x##U
+
+#undef INT64_C
+#undef UINT64_C
 #if @HAVE_LONG_64BIT@
-#define INT64_C(x) x##L
-#define UINT64_C(x) x##UL
+# define INT64_C(x) x##L
+# define UINT64_C(x) x##UL
 #elif @HAVE_LONG_LONG_64BIT@
-#define INT64_C(x) x##LL
-#define UINT64_C(x) x##ULL
+# define INT64_C(x) x##LL
+# define UINT64_C(x) x##ULL
 #elif defined(_MSC_VER)
-#define INT64_C(x) x##i64
-#define UINT64_C(x) x##ui64
+# define INT64_C(x) x##i64
+# define UINT64_C(x) x##ui64
 #endif
 
 /* 7.18.4.2. Macros for greatest-width integer constants */
 
+#undef INTMAX_C
+#undef UINTMAX_C
 #if @HAVE_LONG_64BIT@
-#define INTMAX_C(x) x##L
-#define UINTMAX_C(x) x##UL
+# define INTMAX_C(x) x##L
+# define UINTMAX_C(x) x##UL
 #elif @HAVE_LONG_LONG_64BIT@
-#define INTMAX_C(x) x##LL
-#define UINTMAX_C(x) x##ULL
+# define INTMAX_C(x) x##LL
+# define UINTMAX_C(x) x##ULL
 #elif defined(_MSC_VER)
-#define INTMAX_C(x) x##i64
-#define UINTMAX_C(x) x##ui64
+# define INTMAX_C(x) x##i64
+# define UINTMAX_C(x) x##ui64
 #else
-#define INTMAX_C(x) x
-#define UINTMAX_C(x) x##U
+# define INTMAX_C(x) x
+# define UINTMAX_C(x) x##U
 #endif
 
 #endif
 
-#endif  /* !_STDINT_H_HAVE_SYSTEM_INTTYPES */
-
 #endif /* _STDINT_H */
index 9299d25..bc57ef5 100644 (file)
@@ -1,5 +1,13 @@
 2006-06-15  Bruno Haible  <bruno@clisp.org>
 
+       * stdint.m4 (gl_STDINT_H): Rewritten to produce a complete stdint.h.
+       (gl_HEADER_STDINT_H, gl_HEADER_INTTYPES_H, gl_STDINT_CHECK_TYPES,
+       gl_STDINT_MISSING_BOUND, gl_STDINT_MISSING_BOUNDS,
+       gl_STDINT_MISSING_BOUNDS2, gl_STDINT_BITSIZEOF, gl_CHECK_TYPES_SIGNED,
+       gl_CHECK_TYPE_SAME): New macros.
+
+2006-06-15  Bruno Haible  <bruno@clisp.org>
+
        * size_max.m4 (gl_SIZE_MAX): Make it work also when cross-compiling.
 
 2006-06-15  Eric Blake  <ebb9@byu.net>
index d4a6994..33a443c 100644 (file)
@@ -1,5 +1,5 @@
-# stdint.m4 serial 5
-dnl Copyright (C) 2001-2002, 2004-2005 Free Software Foundation, Inc.
+# stdint.m4 serial 6
+dnl Copyright (C) 2001-2002, 2004-2006 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -8,24 +8,50 @@ dnl From Bruno Haible.
 dnl Test whether <stdint.h> is supported or must be substituted.
 
 AC_DEFUN([gl_STDINT_H],
-[dnl Check for <inttypes.h>.
-AC_REQUIRE([gt_HEADER_INTTYPES_H])
-dnl Check for <sys/inttypes.h>.
-AC_CHECK_HEADERS([sys/inttypes.h])
-dnl Check for <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5).
-AC_CHECK_HEADERS([sys/bitypes.h])
-
-AC_MSG_CHECKING([for stdint.h])
-AC_CACHE_VAL(gl_cv_header_stdint_h, [
-  AC_TRY_COMPILE([#include <stdint.h>], [],
-    gl_cv_header_stdint_h=yes, gl_cv_header_stdint_h=no)])
-AC_MSG_RESULT([$gl_cv_header_stdint_h])
-if test $gl_cv_header_stdint_h = yes; then
-  AC_DEFINE(HAVE_STDINT_H, 1,
-            [Define if you have a working <stdint.h> header file.])
-  STDINT_H=''
-else
-  STDINT_H='stdint.h'
+[
+  dnl Check for <stdint.h> that doesn't clash with <sys/types.h>.
+  gl_HEADER_STDINT_H
+  if test $gl_cv_header_stdint_h = yes; then
+    ac_cv_header_stdint_h=yes; dnl Hack for gl_FULL_HEADER_PATH.
+    gl_FULL_HEADER_PATH([stdint.h])
+    FULL_PATH_STDINT_H=$gl_cv_full_path_stdint_h
+    AC_SUBST([FULL_PATH_STDINT_H])
+    HAVE_STDINT_H=1
+  else
+    HAVE_STDINT_H=0
+  fi
+  AC_SUBST([HAVE_STDINT_H])
+
+  dnl Check for <inttypes.h> that doesn't clash with <sys/types.h>.
+  gl_HEADER_INTTYPES_H
+  if test $gl_cv_header_inttypes_h = yes; then
+    ac_cv_header_inttypes_h=yes; dnl Hack for gl_FULL_HEADER_PATH.
+    gl_FULL_HEADER_PATH([inttypes.h])
+    FULL_PATH_INTTYPES_H=$gl_cv_full_path_inttypes_h
+    AC_SUBST([FULL_PATH_INTTYPES_H])
+    HAVE_INTTYPES_H=1
+  else
+    HAVE_INTTYPES_H=0
+  fi
+  AC_SUBST([HAVE_INTTYPES_H])
+
+  dnl Check for <sys/inttypes.h>.
+  AC_CHECK_HEADERS([sys/inttypes.h])
+  if test $ac_cv_header_sys_inttypes_h = yes; then
+    HAVE_SYS_INTTYPES_H=1
+  else
+    HAVE_SYS_INTTYPES_H=0
+  fi
+  AC_SUBST([HAVE_SYS_INTTYPES_H])
+
+  dnl Check for <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5).
+  AC_CHECK_HEADERS([sys/bitypes.h])
+  if test $ac_cv_header_sys_bitypes_h = yes; then
+    HAVE_SYS_BITYPES_H=1
+  else
+    HAVE_SYS_BITYPES_H=0
+  fi
+  AC_SUBST([HAVE_SYS_BITYPES_H])
 
   dnl Is long == int64_t ?
   AC_CACHE_CHECK([whether 'long' is 64 bit wide], gl_cv_long_bitsize_64, [
@@ -55,6 +81,581 @@ typedef int array [2 * (POW63 != 0 && POW64 == 0) - 1];
   fi
   AC_SUBST(HAVE_LONG_LONG_64BIT)
 
-fi
-AC_SUBST(STDINT_H)
+  dnl Here we use FULL_PATH_INTTYPES_H and FULL_PATH_STDINT_H, not just
+  dnl <inttypes.h> and <stdint.h>, so that it also works during a
+  dnl "config.status --recheck" if an inttypes.h or stdint.h have been
+  dnl created in the build directory.
+  other_includes='
+/* Get those types that are already defined in other system include files.  */
+#if defined(__FreeBSD__)
+# include <sys/inttypes.h>
+#endif
+#if defined(__OpenBSD__)
+# include <sys/types.h>
+# if HAVE_INTTYPES_H
+#  include FULL_PATH_INTTYPES_H
+# endif
+#endif
+#if defined(__linux__) && HAVE_SYS_BITYPES_H
+# include <sys/bitypes.h>
+#endif
+#if defined(__sun) && HAVE_SYS_INTTYPES_H
+# include <sys/inttypes.h>
+#endif
+#if (defined(__hpux) || defined(_AIX)) && HAVE_INTTYPES_H
+# include FULL_PATH_INTTYPES_H
+#endif
+#if HAVE_STDINT_H
+# include FULL_PATH_STDINT_H
+#endif
+'
+  gl_STDINT_CHECK_TYPES(
+    [int8_t int16_t int32_t int64_t \
+     uint8_t uint16_t uint32_t uint64_t \
+     int_least8_t int_least16_t int_least32_t int_least64_t \
+     uint_least8_t uint_least16_t uint_least32_t uint_least64_t \
+     int_fast8_t int_fast16_t int_fast32_t int_fast64_t \
+     uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t \
+     intptr_t uintptr_t \
+     intmax_t uintmax_t],
+    [$other_includes],
+    [gl_cv_type_], [], [])
+
+  dnl Now see if we need a substitute <stdint.h>.
+  gl_cv_header_working_stdint_h=no
+  if test $gl_cv_header_stdint_h = yes; then
+    gl_STDINT_CHECK_TYPES(
+      [int64_t uint64_t \
+       int_least64_t uint_least64_t \
+       int_fast64_t uint_fast64_t],
+      [#include <stdint.h>],
+      [gl_cv_stdint_], [_IN_STDINT_H], [in <stdint.h>])
+    AC_COMPILE_IFELSE([
+      AC_LANG_PROGRAM([
+#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
+#include <stdint.h>
+int8_t a1 = INT8_C (17);
+int16_t a2 = INT16_C (17);
+int32_t a3 = INT32_C (17);
+#if HAVE_INT64_T_IN_STDINT_H
+int64_t a4 = INT64_C (17);
+#endif
+uint8_t b1 = UINT8_C (17);
+uint16_t b2 = UINT16_C (17);
+uint32_t b3 = UINT32_C (17);
+#if HAVE_UINT64_T_IN_STDINT_H
+uint64_t b4 = UINT64_C (17);
+#endif
+int_least8_t c1 = 17;
+int_least16_t c2 = 17;
+int_least32_t c3 = 17;
+#if HAVE_INT_LEAST64_T_IN_STDINT_H
+int_least64_t c4 = 17;
+#endif
+uint_least8_t d1 = 17;
+uint_least16_t d2 = 17;
+uint_least32_t d3 = 17;
+#if HAVE_UINT_LEAST64_T_IN_STDINT_H
+uint_least64_t d4 = 17;
+#endif
+int_fast8_t e1 = 17;
+int_fast16_t e2 = 17;
+int_fast32_t e3 = 17;
+#if HAVE_INT_FAST64_T_IN_STDINT_H
+int_fast64_t e4 = 17;
+#endif
+uint_fast8_t f1 = 17;
+uint_fast16_t f2 = 17;
+uint_fast32_t f3 = 17;
+#if HAVE_UINT_FAST64_T_IN_STDINT_H
+uint_fast64_t f4 = 17;
+#endif
+intptr_t g = 17;
+uintptr_t h = 17;
+intmax_t i = INTMAX_C (17);
+uintmax_t j = UINTMAX_C (17);
+      ])],
+      [gl_cv_header_working_stdint_h=yes])
+  fi
+  if test $gl_cv_header_working_stdint_h = yes; then
+    dnl Use the existing <stdint.h>, adding missing macro definitions.
+    suff64=
+    suffu64=
+    if test $HAVE_LONG_64BIT = 1; then
+      suff64=L
+      suffu64=UL
+    else
+      if test $HAVE_LONG_LONG_64BIT = 1; then
+        suff64=LL
+        suffu64=ULL
+      else
+        AC_EGREP_CPP([msvc compiler], [
+#ifdef _MSC_VER
+msvc compiler
+#endif
+          ], [
+          suff64=i64
+          suffu64=ui64
+        ])
+      fi
+    fi
+    dnl Here we assume a standard architecture where the hardware integer
+    dnl types have 8, 16, 32, optionally 64 bits.
+    gl_STDINT_MISSING_BOUND([INT8_MIN], [-128],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([INT8_MAX], [127],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([UINT8_MAX], [255],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([INT16_MIN], [-32768],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([INT16_MAX], [32767],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([UINT16_MAX], [65535],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([INT32_MIN], [(~INT32_MAX)],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([INT32_MAX], [2147483647],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([UINT32_MAX], [4294967295U],
+      [Define if <stdint.h> doesn't define it.])
+    if test $gl_cv_stdint_int64_t = yes; then
+      gl_STDINT_MISSING_BOUND([INT64_MIN], [(~INT64_MAX)],
+        [Define if <stdint.h> doesn't define it but has the int64_t type.])
+      gl_STDINT_MISSING_BOUND([INT64_MAX], [9223372036854775807${suff64}],
+        [Define if <stdint.h> doesn't define it but has the int64_t type.])
+    fi
+    if test $gl_cv_stdint_uint64_t = yes; then
+      gl_STDINT_MISSING_BOUND([UINT64_MAX], [18446744073709551615${suffu64}],
+        [Define if <stdint.h> doesn't define it but has the uint64_t type.])
+    fi
+    dnl Here we assume a standard architecture where the hardware integer
+    dnl types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
+    dnl are the same as the corresponding N_t types.
+    gl_STDINT_MISSING_BOUND([INT_LEAST8_MIN], [INT8_MIN],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([INT_LEAST8_MAX], [INT8_MAX],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([UINT_LEAST8_MAX], [UINT8_MAX],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([INT_LEAST16_MIN], [INT16_MIN],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([INT_LEAST16_MAX], [INT16_MAX],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([UINT_LEAST16_MAX], [UINT16_MAX],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([INT_LEAST32_MIN], [INT32_MIN],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([INT_LEAST32_MAX], [INT32_MAX],
+      [Define if <stdint.h> doesn't define it.])
+    gl_STDINT_MISSING_BOUND([UINT_LEAST32_MAX], [UINT32_MAX],
+      [Define if <stdint.h> doesn't define it.])
+    if test $gl_cv_stdint_int_least64_t = yes; then
+      gl_STDINT_MISSING_BOUND([INT_LEAST64_MIN], [INT64_MIN],
+        [Define if <stdint.h> doesn't define it but has the int_least64_t type.])
+      gl_STDINT_MISSING_BOUND([INT_LEAST64_MAX], [INT64_MAX],
+        [Define if <stdint.h> doesn't define it but has the int_least64_t type.])
+    fi
+    if test $gl_cv_stdint_uint_least64_t = yes; then
+      gl_STDINT_MISSING_BOUND([UINT_LEAST64_MAX], [UINT64_MAX],
+        [Define if <stdint.h> doesn't define it but has the uint_least64_t type.])
+    fi
+    dnl Here we assume a standard architecture where the hardware integer
+    dnl types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
+    dnl are taken from the same list of types.
+    gl_STDINT_MISSING_BOUNDS([INT_FAST8_MIN INT_FAST8_MAX UINT_FAST8_MAX \
+                              INT_FAST16_MIN INT_FAST16_MAX UINT_FAST16_MAX \
+                              INT_FAST32_MIN INT_FAST32_MAX UINT_FAST32_MAX])
+    if test $gl_cv_stdint_uint_fast64_t = yes; then
+      gl_STDINT_MISSING_BOUNDS([INT_FAST64_MIN INT_FAST64_MAX])
+    fi
+    if test $gl_cv_stdint_uint_fast64_t = yes; then
+      gl_STDINT_MISSING_BOUNDS([UINT_FAST64_MAX])
+    fi
+    gl_STDINT_MISSING_BOUNDS([INTPTR_MIN INTPTR_MAX UINTPTR_MAX \
+                              INTMAX_MIN INTMAX_MAX UINTMAX_MAX])
+    gl_STDINT_MISSING_BOUNDS([PTRDIFF_MIN PTRDIFF_MAX], [#include <stddef.h>])
+    gl_SIZE_MAX
+    gl_STDINT_MISSING_BOUNDS2([SIG_ATOMIC_MIN SIG_ATOMIC_MAX],
+      [#include <signal.h>])
+    dnl Don't bother defining WCHAR_MIN and WCHAR_MAX, since they should
+    dnl already be defined in <stddef.h>.
+    dnl For wint_t we need <wchar.h>.
+    dnl Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included
+    dnl before <wchar.h>.
+    dnl BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
+    dnl <wchar.h>.
+    gl_STDINT_MISSING_BOUNDS2([WINT_MIN WINT_MAX], [
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+])
+    STDINT_H=''
+  else
+
+    gl_STDINT_BITSIZEOF(
+      [int8_t int16_t int32_t int64_t \
+       uint8_t uint16_t uint32_t uint64_t \
+       int_least8_t int_least16_t int_least32_t int_least64_t \
+       uint_least8_t uint_least16_t uint_least32_t uint_least64_t \
+       int_fast8_t int_fast16_t int_fast32_t int_fast64_t \
+       uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t \
+       intptr_t uintptr_t \
+       intmax_t uintmax_t],
+      [$other_includes])
+
+    gl_cv_type_unsigned_int=yes
+    gl_cv_type_long=yes
+    gl_cv_type_unsigned_long=yes
+    gl_STDINT_BITSIZEOF([unsigned_int long unsigned_long],
+      [typedef unsigned int unsigned_int;
+       typedef unsigned long unsigned_long;])
+
+    AC_CHECK_TYPES([ptrdiff_t])
+    gl_cv_type_ptrdiff_t=$ac_cv_type_ptrdiff_t
+    AC_REQUIRE([AC_TYPE_SIZE_T])
+    gl_cv_type_size_t=yes
+    gl_STDINT_BITSIZEOF([ptrdiff_t size_t], [#include <stddef.h>])
+    gl_CHECK_TYPE_SAME([ptrdiff_t], [long], [#include <stddef.h>])
+    gl_CHECK_TYPE_SAME([size_t], [unsigned long], [#include <stddef.h>])
+
+    AC_CHECK_TYPES([sig_atomic_t], , , [#include <signal.h>])
+    gl_cv_type_sig_atomic_t=$ac_cv_type_sig_atomic_t
+    gl_STDINT_BITSIZEOF([sig_atomic_t], [#include <signal.h>])
+    gl_CHECK_TYPES_SIGNED([sig_atomic_t], [#include <signal.h>])
+    if test $HAVE_SIGNED_SIG_ATOMIC_T = 1; then
+      gl_CHECK_TYPE_SAME([sig_atomic_t], [long], [#include <signal.h>])
+    else
+      gl_CHECK_TYPE_SAME([sig_atomic_t], [unsigned long], [#include <signal.h>])
+    fi
+
+    AC_REQUIRE([gt_TYPE_WCHAR_T])
+    gl_cv_type_wchar_t=$gt_cv_c_wchar_t
+    gl_STDINT_BITSIZEOF([wchar_t], [#include <stddef.h>])
+    gl_CHECK_TYPES_SIGNED([wchar_t], [#include <stddef.h>])
+    if test $HAVE_SIGNED_WCHAR_T = 1; then
+      gl_CHECK_TYPE_SAME([wchar_t], [long], [#include <stddef.h>])
+    else
+      gl_CHECK_TYPE_SAME([wchar_t], [unsigned long], [#include <stddef.h>])
+    fi
+
+    dnl For wint_t we need <wchar.h>.
+    dnl Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included
+    dnl before <wchar.h>.
+    dnl BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
+    dnl <wchar.h>.
+    AC_CHECK_TYPES([wint_t], , , [#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+])
+    gl_cv_type_wint_t=$ac_cv_type_wint_t
+    gl_STDINT_BITSIZEOF([wint_t], [#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+])
+    gl_CHECK_TYPES_SIGNED([wint_t], [#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+])
+    if test $HAVE_SIGNED_WINT_T = 1; then
+      gl_CHECK_TYPE_SAME([wint_t], [long], [#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+])
+    else
+      gl_CHECK_TYPE_SAME([wint_t], [unsigned long], [#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+])
+    fi
+
+    STDINT_H='stdint.h'
+  fi
+  AC_SUBST(STDINT_H)
+])
+
+dnl Set gl_cv_header_stdint_h to yes and define HAVE_STDINT_H if
+dnl <stdint.h> exists and doesn't clash with <sys/types.h>.
+AC_DEFUN([gl_HEADER_STDINT_H],
+[
+  dnl Check for <stdint.h> that doesn't clash with <sys/types.h>.
+  AC_CACHE_CHECK([for stdint.h], gl_cv_header_stdint_h, [
+    AC_TRY_COMPILE([
+#include <sys/types.h>
+#include <stdint.h>],
+      [], gl_cv_header_stdint_h=yes, gl_cv_header_stdint_h=no)
+  ])
+  if test $gl_cv_header_stdint_h = yes; then
+    AC_DEFINE_UNQUOTED(HAVE_STDINT_H, 1,
+      [Define if <stdint.h> exists and doesn't clash with <sys/types.h>.])
+  fi
+])
+
+dnl Set gl_cv_header_inttypes_h to yes and define HAVE_INTTYPES_H if
+dnl <inttypes.h> exists and doesn't clash with <sys/types.h>.
+AC_DEFUN([gl_HEADER_INTTYPES_H],
+[
+  dnl Check for <inttypes.h> that doesn't clash with <sys/types.h>.
+  dnl On IRIX 5.3, <inttypes.h> conflicts with <sys/types.h>.
+  AC_CACHE_CHECK([for inttypes.h], gl_cv_header_inttypes_h, [
+    AC_TRY_COMPILE([
+#include <sys/types.h>
+#include <inttypes.h>],
+      [], gl_cv_header_inttypes_h=yes, gl_cv_header_inttypes_h=no)
+  ])
+  if test $gl_cv_header_inttypes_h = yes; then
+    AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H, 1,
+      [Define if <inttypes.h> exists and doesn't clash with <sys/types.h>.])
+  fi
+])
+
+dnl gl_STDINT_CHECK_TYPES(TYPES, INCLUDES, CACHE_VAR_PREFIX, MACRO_SUFFIX, DESCRIPTION_SUFFIX)
+dnl Check each of the given types, whether they are defined in the given
+dnl include files.
+AC_DEFUN([gl_STDINT_CHECK_TYPES],
+[
+  dnl Use a shell loop, to avoid bloating configure, and
+  dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
+  dnl   config.h.in,
+  dnl - extra AC_SUBST calls, so that the right substitutions are made.
+  AC_FOREACH([gltype], [$1],
+    [AH_TEMPLATE([HAVE_]translit(gltype,[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ])[$4],
+       [Define to 1 if the type ']gltype[' is already defined$5.])])
+  for gltype in $1 ; do
+    AC_MSG_CHECKING([for $gltype])
+    AC_COMPILE_IFELSE([
+      AC_LANG_PROGRAM([$2
+/* Test if the type exists.  */
+$gltype x = 17;
+      ])],
+      result=yes, result=no)
+    eval $3${gltype}=\$result
+    AC_MSG_RESULT($result)
+    GLTYPE=`echo "$gltype" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
+    if test $result = yes; then
+      AC_DEFINE_UNQUOTED([HAVE_${GLTYPE}$4], 1)
+      eval HAVE_${GLTYPE}$4=1
+    else
+      eval HAVE_${GLTYPE}$4=0
+    fi
+  done
+  AC_FOREACH([gltype], [$1],
+    [AC_SUBST([HAVE_]translit(gltype,[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ])[$4])])
+])
+
+dnl gl_STDINT_MISSING_BOUND(TYPE_BOUND, DEFAULT, DESCRIPTION)
+dnl assumes an otherwise complete <stdint.h> and defines TYPE_BOUND if
+dnl <stdint.h> doesn't define it.
+AC_DEFUN([gl_STDINT_MISSING_BOUND],
+[
+  AC_CACHE_CHECK([for $1], [gl_cv_stdint_$1],
+    [AC_EGREP_CPP([found it], [#include <stdint.h>
+#ifdef $1
+found it
+#endif
+       ], [gl_cv_stdint_$1=yes], [gl_cv_stdint_$1="$2"])])
+  if test "$gl_cv_stdint_$1" != yes; then
+    AC_DEFINE_UNQUOTED([$1], [$2], [$3])
+  fi
+])
+
+dnl gl_STDINT_MISSING_BOUNDS(BOUNDS, INCLUDES)
+dnl assumes an otherwise complete <stdint.h> and defines each element of BOUNDS
+dnl if <stdint.h> doesn't define it.
+dnl Use this for types whose signedness is determined by the first letter
+dnl ('u' or not).
+AC_DEFUN([gl_STDINT_MISSING_BOUNDS],
+[
+  dnl Use a shell loop, to avoid bloating configure, and
+  dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
+  dnl   config.h.in.
+  AC_FOREACH([bound], [$1],
+    [AH_TEMPLATE(bound, [Define if <stdint.h> doesn't define it.])])
+changequote(,)dnl
+  sed_unsigned='s,^\(U*\).*,\1,'
+  sed_limitkind='s,^.*\(_[^_]*\)$,\1,'
+changequote([,])dnl
+  for bound in $1; do
+    type=`echo $bound | sed -e 's,_MAX,_t,' -e 's,_MIN,_t,' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
+    unsigned=`echo $bound | sed -e "$sed_unsigned" | tr U u`
+    width=`echo $bound | sed -e 's,^U*INT,,' -e 's,_MIN,,' -e 's,_MAX,,'`
+    limitkind=`echo $bound | sed -e "$sed_limitkind"`
+    AC_CACHE_CHECK([for $bound], [gl_cv_stdint_$bound],
+      [AC_EGREP_CPP([found it], [#include <stdint.h>
+#ifdef $bound
+found it
+#endif
+         ], [eval gl_cv_stdint_$bound=yes],
+         [result=
+          case $width in
+            *8) widthlist="8 16 32 64" ;;
+            *16) widthlist="16 32 64" ;;
+            *32 | PTR | MAX | PTRDIFF) widthlist="32 64" ;;
+            *64) widthlist="64" ;;
+          esac
+          for w in $widthlist; do
+            if test -z "$result"; then
+              AC_COMPILE_IFELSE([[$2
+#include <stdint.h>
+int verify[2 * (sizeof ($type) == sizeof (${unsigned}int${w}_t)) - 1];
+                ]], [result=`echo "$unsigned" | tr u U`INT${w}${limitkind}])
+            else
+              break
+            fi
+          done
+          if test -z "$result"; then
+            result=no
+          fi
+          eval gl_cv_stdint_$bound=\$result
+         ])])
+    eval result=\$gl_cv_stdint_$bound
+    if test "$result" != yes && test "$result" != no; then
+      AC_DEFINE_UNQUOTED([$bound], [$result],
+        [Define if <stdint.h> doesn't define it.])
+    fi
+  done
+])
+
+dnl gl_STDINT_MISSING_BOUNDS2(BOUNDS, INCLUDES)
+dnl assumes an otherwise complete <stdint.h> and defines each element of BOUNDS
+dnl if <stdint.h> doesn't define it.
+dnl Use this for types whose signedness is a priori unknown.
+AC_DEFUN([gl_STDINT_MISSING_BOUNDS2],
+[
+  dnl Use a shell loop, to avoid bloating configure, and
+  dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
+  dnl   config.h.in.
+  AC_FOREACH([bound], [$1],
+    [AH_TEMPLATE(bound, [Define if <stdint.h> doesn't define it.])])
+changequote(,)dnl
+  sed_limitkind='s,^.*\(_[^_]*\)$,\1,'
+changequote([,])dnl
+  for bound in $1; do
+    type=`echo $bound | sed -e 's,_MAX,_t,' -e 's,_MIN,_t,' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
+    limitkind=`echo $bound | sed -e "$sed_limitkind"`
+    AC_CACHE_CHECK([for $bound], [gl_cv_stdint_$bound],
+      [AC_EGREP_CPP([found it], [#include <stdint.h>
+#ifdef $bound
+found it
+#endif
+         ], [eval gl_cv_stdint_$bound=yes],
+         [result=
+          AC_COMPILE_IFELSE([[$2
+            int verify[2 * (($type) -1 >= ($type) 0) - 1];
+            ]],
+            [eval gl_cv_${type}_signed=no],
+            [eval gl_cv_${type}_signed=yes])
+          if eval test \$gl_cv_${type}_signed = yes; then
+            for w in 8 16 32 64; do
+              if test -z "$result"; then
+                AC_COMPILE_IFELSE([[$2
+#include <stdint.h>
+int verify[2 * (sizeof ($type) == sizeof (int${w}_t)) - 1];
+                  ]], [result=INT${w}${limitkind}])
+              else
+                break
+              fi
+            done
+          else
+            if test ${limitkind} = _MIN; then
+              result=0
+            else
+              for w in 8 16 32 64; do
+                if test -z "$result"; then
+                  AC_COMPILE_IFELSE([[$2
+#include <stdint.h>
+int verify[2 * (sizeof ($type) == sizeof (uint${w}_t)) - 1];
+                    ]], [result=UINT${w}${limitkind}])
+                else
+                  break
+                fi
+              done
+            fi
+          fi
+          if test -z "$result"; then
+            result=no
+          fi
+          eval gl_cv_stdint_$bound=\$result
+         ])])
+    eval result=\$gl_cv_stdint_$bound
+    if test "$result" != yes && test "$result" != no; then
+      AC_DEFINE_UNQUOTED([$bound], [$result],
+        [Define if <stdint.h> doesn't define it.])
+    fi
+  done
+])
+
+dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES)
+dnl Determine the size of each of the given types in bits.
+AC_DEFUN([gl_STDINT_BITSIZEOF],
+[
+  dnl Use a shell loop, to avoid bloating configure, and
+  dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
+  dnl   config.h.in,
+  dnl - extra AC_SUBST calls, so that the right substitutions are made.
+  AC_FOREACH([gltype], [$1],
+    [AH_TEMPLATE([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]),
+       [Define to the number of bits in type ']gltype['.])])
+  for gltype in $1 ; do
+    if eval test \$gl_cv_type_${gltype} = yes; then
+      AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}],
+        [_AC_COMPUTE_INT([sizeof ($gltype) * CHAR_BIT], result,
+           [$2
+#include <limits.h>], result=unknown)
+         eval gl_cv_bitsizeof_${gltype}=\$result
+        ])
+      eval result=\$gl_cv_bitsizeof_${gltype}
+      GLTYPE=`echo "$gltype" | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
+      AC_DEFINE_UNQUOTED([BITSIZEOF_${GLTYPE}], [$result])
+      eval BITSIZEOF_${GLTYPE}=\$result
+    fi
+  done
+  AC_FOREACH([gltype], [$1],
+    [AC_SUBST([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))])
+])
+
+dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES)
+dnl Determine the signedness of each of the given types.
+dnl Define HAVE_SIGNED_TYPE if type is signed.
+AC_DEFUN([gl_CHECK_TYPES_SIGNED],
+[
+  dnl Use a shell loop, to avoid bloating configure, and
+  dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
+  dnl   config.h.in,
+  dnl - extra AC_SUBST calls, so that the right substitutions are made.
+  AC_FOREACH([gltype], [$1],
+    [AH_TEMPLATE([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]),
+       [Define to 1 if ']gltype[' is a signed integer type.])])
+  for gltype in $1 ; do
+    AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM([[$2
+            int verify[2 * (($1) -1 < ($1) 0) - 1];
+            ]])],
+         result=yes, result=no)
+       eval gl_cv_type_${gltype}_signed=\$result
+      ])
+    eval result=\$gl_cv_type_${gltype}_signed
+    GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
+    if test "$result" = yes; then
+      AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], 1)
+      eval HAVE_SIGNED_${GLTYPE}=1
+    else
+      eval HAVE_SIGNED_${GLTYPE}=0
+    fi
+  done
+  AC_FOREACH([gltype], [$1],
+    [AC_SUBST([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))])
+])
+
+dnl gl_CHECK_TYPE_SAME(TYPE, KNOWNTYPE, INCLUDES)
+dnl Determines whether two types are the same.
+AC_DEFUN([gl_CHECK_TYPE_SAME],
+[
+  AC_TRY_COMPILE([$3
+    extern $1 foo;
+    extern $2 foo;], [],
+    [SAME_TYPE_]AS_TR_CPP([$1])[_]AS_TR_CPP([$2])[=1],
+    [SAME_TYPE_]AS_TR_CPP([$1])[_]AS_TR_CPP([$2])[=0])
+  AC_SUBST([SAME_TYPE_]AS_TR_CPP([$1])[_]AS_TR_CPP([$2]))
 ])
index 3bc0be1..e50bb2b 100644 (file)
@@ -6,7 +6,9 @@ to the fastest and smallest types available on the system.)
 Files:
 lib/stdint_.h
 m4/stdint.m4
-m4/inttypes.m4
+m4/full-header-path.m4
+m4/size_max.m4
+m4/wchar_t.m4
 
 Depends-on:
 
@@ -20,7 +22,90 @@ EXTRA_DIST += stdint_.h
 # We need the following in order to create <stdint.h> when the system
 # doesn't have one that works with the given compiler.
 stdint.h: stdint_.h
-       sed -e 's/@''HAVE_LONG_64BIT''@/$(HAVE_LONG_64BIT)/g;s/@''HAVE_LONG_LONG_64BIT@/$(HAVE_LONG_LONG_64BIT)/g' < $(srcdir)/stdint_.h > $@-t
+       sed -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \
+           -e 's|@''FULL_PATH_STDINT_H''@|$(FULL_PATH_STDINT_H)|g' \
+           -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
+           -e 's|@''FULL_PATH_INTTYPES_H''@|$(FULL_PATH_INTTYPES_H)|g' \
+           -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \
+           -e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \
+           -e 's/@''HAVE_LONG_64BIT''@/$(HAVE_LONG_64BIT)/g' \
+           -e 's/@''HAVE_LONG_LONG_64BIT''@/$(HAVE_LONG_LONG_64BIT)/g' \
+           -e 's/@''HAVE_INT8_T''@/$(HAVE_INT8_T)/g' \
+           -e 's/@''HAVE_INT16_T''@/$(HAVE_INT16_T)/g' \
+           -e 's/@''HAVE_INT32_T''@/$(HAVE_INT32_T)/g' \
+           -e 's/@''HAVE_INT64_T''@/$(HAVE_INT64_T)/g' \
+           -e 's/@''HAVE_UINT8_T''@/$(HAVE_UINT8_T)/g' \
+           -e 's/@''HAVE_UINT16_T''@/$(HAVE_UINT16_T)/g' \
+           -e 's/@''HAVE_UINT32_T''@/$(HAVE_UINT32_T)/g' \
+           -e 's/@''HAVE_UINT64_T''@/$(HAVE_UINT64_T)/g' \
+           -e 's/@''HAVE_INT_LEAST8_T''@/$(HAVE_INT_LEAST8_T)/g' \
+           -e 's/@''HAVE_INT_LEAST16_T''@/$(HAVE_INT_LEAST16_T)/g' \
+           -e 's/@''HAVE_INT_LEAST32_T''@/$(HAVE_INT_LEAST32_T)/g' \
+           -e 's/@''HAVE_INT_LEAST64_T''@/$(HAVE_INT_LEAST64_T)/g' \
+           -e 's/@''HAVE_UINT_LEAST8_T''@/$(HAVE_UINT_LEAST8_T)/g' \
+           -e 's/@''HAVE_UINT_LEAST16_T''@/$(HAVE_UINT_LEAST16_T)/g' \
+           -e 's/@''HAVE_UINT_LEAST32_T''@/$(HAVE_UINT_LEAST32_T)/g' \
+           -e 's/@''HAVE_UINT_LEAST64_T''@/$(HAVE_UINT_LEAST64_T)/g' \
+           -e 's/@''HAVE_INT_FAST8_T''@/$(HAVE_INT_FAST8_T)/g' \
+           -e 's/@''HAVE_INT_FAST16_T''@/$(HAVE_INT_FAST16_T)/g' \
+           -e 's/@''HAVE_INT_FAST32_T''@/$(HAVE_INT_FAST32_T)/g' \
+           -e 's/@''HAVE_INT_FAST64_T''@/$(HAVE_INT_FAST64_T)/g' \
+           -e 's/@''HAVE_UINT_FAST8_T''@/$(HAVE_UINT_FAST8_T)/g' \
+           -e 's/@''HAVE_UINT_FAST16_T''@/$(HAVE_UINT_FAST16_T)/g' \
+           -e 's/@''HAVE_UINT_FAST32_T''@/$(HAVE_UINT_FAST32_T)/g' \
+           -e 's/@''HAVE_UINT_FAST64_T''@/$(HAVE_UINT_FAST64_T)/g' \
+           -e 's/@''HAVE_INTPTR_T''@/$(HAVE_INTPTR_T)/g' \
+           -e 's/@''HAVE_UINTPTR_T''@/$(HAVE_UINTPTR_T)/g' \
+           -e 's/@''HAVE_INTMAX_T''@/$(HAVE_INTMAX_T)/g' \
+           -e 's/@''HAVE_UINTMAX_T''@/$(HAVE_UINTMAX_T)/g' \
+           -e 's/@''BITSIZEOF_UNSIGNED_INT''@/$(BITSIZEOF_UNSIGNED_INT)/g' \
+           -e 's/@''BITSIZEOF_LONG''@/$(BITSIZEOF_LONG)/g' \
+           -e 's/@''BITSIZEOF_UNSIGNED_LONG''@/$(BITSIZEOF_UNSIGNED_LONG)/g' \
+           -e 's/@''BITSIZEOF_INT8_T''@/$(BITSIZEOF_INT8_T)/g' \
+           -e 's/@''BITSIZEOF_INT16_T''@/$(BITSIZEOF_INT16_T)/g' \
+           -e 's/@''BITSIZEOF_INT32_T''@/$(BITSIZEOF_INT32_T)/g' \
+           -e 's/@''BITSIZEOF_INT64_T''@/$(BITSIZEOF_INT64_T)/g' \
+           -e 's/@''BITSIZEOF_UINT8_T''@/$(BITSIZEOF_UINT8_T)/g' \
+           -e 's/@''BITSIZEOF_UINT16_T''@/$(BITSIZEOF_UINT16_T)/g' \
+           -e 's/@''BITSIZEOF_UINT32_T''@/$(BITSIZEOF_UINT32_T)/g' \
+           -e 's/@''BITSIZEOF_UINT64_T''@/$(BITSIZEOF_UINT64_T)/g' \
+           -e 's/@''BITSIZEOF_INT_LEAST8_T''@/$(BITSIZEOF_INT_LEAST8_T)/g' \
+           -e 's/@''BITSIZEOF_INT_LEAST16_T''@/$(BITSIZEOF_INT_LEAST16_T)/g' \
+           -e 's/@''BITSIZEOF_INT_LEAST32_T''@/$(BITSIZEOF_INT_LEAST32_T)/g' \
+           -e 's/@''BITSIZEOF_INT_LEAST64_T''@/$(BITSIZEOF_INT_LEAST64_T)/g' \
+           -e 's/@''BITSIZEOF_UINT_LEAST8_T''@/$(BITSIZEOF_UINT_LEAST8_T)/g' \
+           -e 's/@''BITSIZEOF_UINT_LEAST16_T''@/$(BITSIZEOF_UINT_LEAST16_T)/g' \
+           -e 's/@''BITSIZEOF_UINT_LEAST32_T''@/$(BITSIZEOF_UINT_LEAST32_T)/g' \
+           -e 's/@''BITSIZEOF_UINT_LEAST64_T''@/$(BITSIZEOF_UINT_LEAST64_T)/g' \
+           -e 's/@''BITSIZEOF_INT_FAST8_T''@/$(BITSIZEOF_INT_FAST8_T)/g' \
+           -e 's/@''BITSIZEOF_INT_FAST16_T''@/$(BITSIZEOF_INT_FAST16_T)/g' \
+           -e 's/@''BITSIZEOF_INT_FAST32_T''@/$(BITSIZEOF_INT_FAST32_T)/g' \
+           -e 's/@''BITSIZEOF_INT_FAST64_T''@/$(BITSIZEOF_INT_FAST64_T)/g' \
+           -e 's/@''BITSIZEOF_UINT_FAST8_T''@/$(BITSIZEOF_UINT_FAST8_T)/g' \
+           -e 's/@''BITSIZEOF_UINT_FAST16_T''@/$(BITSIZEOF_UINT_FAST16_T)/g' \
+           -e 's/@''BITSIZEOF_UINT_FAST32_T''@/$(BITSIZEOF_UINT_FAST32_T)/g' \
+           -e 's/@''BITSIZEOF_UINT_FAST64_T''@/$(BITSIZEOF_UINT_FAST64_T)/g' \
+           -e 's/@''BITSIZEOF_INTPTR_T''@/$(BITSIZEOF_INTPTR_T)/g' \
+           -e 's/@''BITSIZEOF_UINTPTR_T''@/$(BITSIZEOF_UINTPTR_T)/g' \
+           -e 's/@''BITSIZEOF_INTMAX_T''@/$(BITSIZEOF_INTMAX_T)/g' \
+           -e 's/@''BITSIZEOF_UINTMAX_T''@/$(BITSIZEOF_UINTMAX_T)/g' \
+           -e 's/@''BITSIZEOF_PTRDIFF_T''@/$(BITSIZEOF_PTRDIFF_T)/g' \
+           -e 's/@''SAME_TYPE_PTRDIFF_T_LONG''@/$(SAME_TYPE_PTRDIFF_T_LONG)/g' \
+           -e 's/@''BITSIZEOF_SIG_ATOMIC_T''@/$(BITSIZEOF_SIG_ATOMIC_T)/g' \
+           -e 's/@''HAVE_SIGNED_SIG_ATOMIC_T''@/$(HAVE_SIGNED_SIG_ATOMIC_T)/g' \
+           -e 's/@''SAME_TYPE_SIG_ATOMIC_T_LONG''@/$(SAME_TYPE_SIG_ATOMIC_T_LONG)/g' \
+           -e 's/@''SAME_TYPE_SIG_ATOMIC_T_UNSIGNED_LONG''@/$(SAME_TYPE_SIG_ATOMIC_T_UNSIGNED_LONG)/g' \
+           -e 's/@''BITSIZEOF_SIZE_T''@/$(BITSIZEOF_SIZE_T)/g' \
+           -e 's/@''SAME_TYPE_SIZE_T_UNSIGNED_LONG''@/$(SAME_TYPE_SIZE_T_UNSIGNED_LONG)/g' \
+           -e 's/@''BITSIZEOF_WCHAR_T''@/$(BITSIZEOF_WCHAR_T)/g' \
+           -e 's/@''HAVE_SIGNED_WCHAR_T''@/$(HAVE_SIGNED_WCHAR_T)/g' \
+           -e 's/@''SAME_TYPE_WCHAR_T_LONG''@/$(SAME_TYPE_WCHAR_T_LONG)/g' \
+           -e 's/@''SAME_TYPE_WCHAR_T_UNSIGNED_LONG''@/$(SAME_TYPE_WCHAR_T_UNSIGNED_LONG)/g' \
+           -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \
+           -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \
+           -e 's/@''SAME_TYPE_WINT_T_LONG''@/$(SAME_TYPE_WINT_T_LONG)/g' \
+           -e 's/@''SAME_TYPE_WINT_T_UNSIGNED_LONG''@/$(SAME_TYPE_WINT_T_UNSIGNED_LONG)/g' \
+           < $(srcdir)/stdint_.h > $@-t
        mv $@-t $@
 MOSTLYCLEANFILES += stdint.h stdint.h-t