/* Get wchar_t, WCHAR_MIN, WCHAR_MAX. */
#include <stddef.h>
+/* BSD/OS 4.2 defines WCHAR_MIN, WCHAR_MAX in <wchar.h>, not <stddef.h>. */
+#if !(defined(WCHAR_MIN) && defined(WCHAR_MAX)) && @HAVE_WCHAR_H@
+# include <wchar.h>
+#endif
+
/* Get LONG_MIN, LONG_MAX, ULONG_MAX. */
#include <limits.h>
/* Get those types that are already defined in other system include files. */
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) && (__FreeBSD__ >= 3) && (__FreeBSD__ <= 4)
# include <sys/inttypes.h>
#endif
-#if defined(__OpenBSD__)
+#if defined(__OpenBSD__) || defined(__bsdi__) || defined(__sgi)
/* In OpenBSD 3.8, <sys/types.h> includes <machine/types.h>, which defines
int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
<inttypes.h> includes <machine/types.h> and also defines intptr_t and
uintptr_t. */
+ /* BSD/OS 4.2 is similar, but doesn't have <inttypes.h> */
+ /* IRIX 6.5 has <inttypes.h>, and <sys/types.h> defines some of these
+ types as well. */
# include <sys/types.h>
# if @HAVE_INTTYPES_H@
# include @FULL_PATH_INTTYPES_H@
#endif
#if @HAVE_STDINT_H@
/* Other systems may have an incomplete <stdint.h>. */
-# include @FULL_PATH_STDINT_H@
+ /* On some versions of IRIX, the SGI C compiler comes with an <stdint.h>,
+ but
+ - in c99 mode, <inttypes.h> includes <stdint.h>,
+ - in c89 mode, <stdint.h> spews warnings and defines nothing.
+ <inttypes.h> defines only a subset of the types and macros that
+ <stdint.h> would define in c99 mode.
+ So we rely only on <inttypes.h> (included above). It means that in
+ c89 mode, we shadow the contents of warning-spewing <stdint.h>. */
+# if !(defined(__sgi) && @HAVE_INTTYPES_H@ && !defined(__c99))
+# include @FULL_PATH_STDINT_H@
+# endif
#endif
/* 7.18.1.1. Exact-width integer types */
public header files. */
#if !@HAVE_INTMAX_T@
+/* Remove possible redundant definition from gnulib's config.h first. */
+# undef intmax_t
# ifdef _STDINT_H_HAVE_INT64
typedef int64_t intmax_t;
# else
# endif
#endif
#if !@HAVE_UINTMAX_T@
+/* Remove possible redundant definition from gnulib's config.h first. */
+# undef uintmax_t
# ifdef _STDINT_H_HAVE_UINT64
typedef uint64_t uintmax_t;
# else
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
/* 7.18.4.1. Macros for minimum-width integer constants */
+/* According to ISO C 99 Technical Corrigendum 1 */
#undef INT8_C
#undef UINT8_C
#define INT8_C(x) x
-#define UINT8_C(x) x##U
+#if @HAVE_UINT8_T@
+# if @BITSIZEOF_UINT8_T@ < @BITSIZEOF_UNSIGNED_INT@
+# define UINT8_C(x) x
+# else
+# define UINT8_C(x) x##U
+# endif
+#else
+# define UINT8_C(x) x
+#endif
#undef INT16_C
#undef UINT16_C
#define INT16_C(x) x
-#define UINT16_C(x) x##U
+#if @HAVE_UINT16_T@
+# if @BITSIZEOF_UINT16_T@ < @BITSIZEOF_UNSIGNED_INT@
+# define UINT16_C(x) x
+# else
+# define UINT16_C(x) x##U
+# endif
+#else
+# define UINT16_C(x) x
+#endif
#undef INT32_C
#undef UINT32_C
#define INT32_C(x) x
-#define UINT32_C(x) x##U
+#if @HAVE_UINT32_T@
+# if @BITSIZEOF_UINT32_T@ < @BITSIZEOF_UNSIGNED_INT@
+# define UINT32_C(x) x
+# else
+# define UINT32_C(x) x##U
+# endif
+#else
+# define UINT32_C(x) x
+#endif
#undef INT64_C
#undef UINT64_C