1/* Copyright (C) 2001-2002, 2004-2007 Free Software Foundation, Inc. 2 Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood. 3 This file is part of gnulib. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2, or (at your option) 8 any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software Foundation, 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 19/* 20 * ISO C 99 <stdint.h> for platforms that lack it. 21 * <http://www.opengroup.org/susv3xbd/stdint.h.html> 22 */ 23 24#ifndef _GL_STDINT_H 25 26/* Get those types that are already defined in other system include 27 files, so that we can "#define int8_t signed char" below without 28 worrying about a later system include file containing a "typedef 29 signed char int8_t;" that will get messed up by our macro. Our 30 macros should all be consistent with the system versions, except 31 for the "fast" types and macros, which we recommend against using 32 in public interfaces due to compiler differences. */ 33 34#if @HAVE_STDINT_H@ 35# if defined __sgi && ! defined __c99 36 /* Bypass IRIX's <stdint.h> if in C89 mode, since it merely annoys users 37 with "This header file is to be used only for c99 mode compilations" 38 diagnostics. */ 39# define __STDINT_H__ 40# endif 41 /* Other systems may have an incomplete or buggy <stdint.h>. 42 Include it before <inttypes.h>, since any "#include <stdint.h>" 43 in <inttypes.h> would reinclude us, skipping our contents because 44 _GL_STDINT_H is defined. 45 The include_next requires a split double-inclusion guard. */ 46# if @HAVE_INCLUDE_NEXT@ 47# include_next <stdint.h> 48# else 49# include @ABSOLUTE_STDINT_H@ 50# endif 51#endif 52 53#ifndef _GL_STDINT_H 54#define _GL_STDINT_H 55 56/* <sys/types.h> defines some of the stdint.h types as well, on glibc, 57 IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>). 58 AIX 5.2 <sys/types.h> isn't needed and causes troubles. 59 MacOS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but 60 relies on the system <stdint.h> definitions, so include 61 <sys/types.h> after @ABSOLUTE_STDINT_H@. */ 62#if @HAVE_SYS_TYPES_H@ && ! defined _AIX 63# include <sys/types.h> 64#endif 65 66/* Get LONG_MIN, LONG_MAX, ULONG_MAX. */ 67#include <limits.h> 68 69#if @HAVE_INTTYPES_H@ 70 /* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines 71 int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__. 72 <inttypes.h> also defines intptr_t and uintptr_t. */ 73# define _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H 74# include <inttypes.h> 75# undef _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H 76#elif @HAVE_SYS_INTTYPES_H@ 77 /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and 78 the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */ 79# include <sys/inttypes.h> 80#endif 81 82#if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__ 83 /* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines 84 int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is 85 included by <sys/types.h>. */ 86# include <sys/bitypes.h> 87#endif 88 89#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS 90 91/* Get WCHAR_MIN, WCHAR_MAX. */ 92# if ! (defined WCHAR_MIN && defined WCHAR_MAX) 93# include <wchar.h> 94# endif 95 96#endif 97 98/* Minimum and maximum values for a integer type under the usual assumption. 99 Return an unspecified value if BITS == 0, adding a check to pacify 100 picky compilers. */ 101 102#define _STDINT_MIN(signed, bits, zero) \ 103 ((signed) ? (- ((zero) + 1) << ((bits) ? (bits) - 1 : 0)) : (zero)) 104 105#define _STDINT_MAX(signed, bits, zero) \ 106 ((signed) \ 107 ? ~ _STDINT_MIN (signed, bits, zero) \ 108 : ((((zero) + 1) << ((bits) ? (bits) - 1 : 0)) - 1) * 2 + 1) 109 110/* 7.18.1.1. Exact-width integer types */ 111 112/* Here we assume a standard architecture where the hardware integer 113 types have 8, 16, 32, optionally 64 bits. */ 114 115#undef int8_t 116#undef uint8_t 117#define int8_t signed char 118#define uint8_t unsigned char 119 120#undef int16_t 121#undef uint16_t 122#define int16_t short int 123#define uint16_t unsigned short int 124 125#undef int32_t 126#undef uint32_t 127#define int32_t int 128#define uint32_t unsigned int 129 130/* Do not undefine int64_t if gnulib is not being used with 64-bit 131 types, since otherwise it breaks platforms like Tandem/NSK. */ 132#if LONG_MAX >> 31 >> 31 == 1 133# undef int64_t 134# define int64_t long int 135# define GL_INT64_T 136#elif defined _MSC_VER 137# undef int64_t 138# define int64_t __int64 139# define GL_INT64_T 140#elif @HAVE_LONG_LONG_INT@ 141# undef int64_t 142# define int64_t long long int 143# define GL_INT64_T 144#endif 145 146#if ULONG_MAX >> 31 >> 31 >> 1 == 1 147# undef uint64_t 148# define uint64_t unsigned long int 149# define GL_UINT64_T 150#elif defined _MSC_VER 151# undef uint64_t 152# define uint64_t unsigned __int64 153# define GL_UINT64_T 154#elif @HAVE_UNSIGNED_LONG_LONG_INT@ 155# undef uint64_t 156# define uint64_t unsigned long long int 157# define GL_UINT64_T 158#endif 159 160/* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */ 161#define _UINT8_T 162#define _UINT32_T 163#define _UINT64_T 164 165 166/* 7.18.1.2. Minimum-width integer types */ 167 168/* Here we assume a standard architecture where the hardware integer 169 types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types 170 are the same as the corresponding N_t types. */ 171 172#undef int_least8_t 173#undef uint_least8_t 174#undef int_least16_t 175#undef uint_least16_t 176#undef int_least32_t 177#undef uint_least32_t 178#undef int_least64_t 179#undef uint_least64_t 180#define int_least8_t int8_t 181#define uint_least8_t uint8_t 182#define int_least16_t int16_t 183#define uint_least16_t uint16_t 184#define int_least32_t int32_t 185#define uint_least32_t uint32_t 186#ifdef GL_INT64_T 187# define int_least64_t int64_t 188#endif 189#ifdef GL_UINT64_T 190# define uint_least64_t uint64_t 191#endif 192 193/* 7.18.1.3. Fastest minimum-width integer types */ 194 195/* Note: Other <stdint.h> substitutes may define these types differently. 196 It is not recommended to use these types in public header files. */ 197 198/* Here we assume a standard architecture where the hardware integer 199 types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types 200 are taken from the same list of types. Assume that 'long int' 201 is fast enough for all narrower integers. */ 202 203#undef int_fast8_t 204#undef uint_fast8_t 205#undef int_fast16_t 206#undef uint_fast16_t 207#undef int_fast32_t 208#undef uint_fast32_t 209#undef int_fast64_t 210#undef uint_fast64_t 211#define int_fast8_t long int 212#define uint_fast8_t unsigned int_fast8_t 213#define int_fast16_t long int 214#define uint_fast16_t unsigned int_fast16_t 215#define int_fast32_t long int 216#define uint_fast32_t unsigned int_fast32_t 217#ifdef GL_INT64_T 218# define int_fast64_t int64_t 219#endif 220#ifdef GL_UINT64_T 221# define uint_fast64_t uint64_t 222#endif 223 224/* 7.18.1.4. Integer types capable of holding object pointers */ 225 226#undef intptr_t 227#undef uintptr_t 228#define intptr_t long int 229#define uintptr_t unsigned long int 230 231/* 7.18.1.5. Greatest-width integer types */ 232 233/* Note: These types are compiler dependent. It may be unwise to use them in 234 public header files. */ 235 236#undef intmax_t 237#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 238# define intmax_t long long int 239#elif defined GL_INT64_T 240# define intmax_t int64_t 241#else 242# define intmax_t long int 243#endif 244 245#undef uintmax_t 246#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 247# define uintmax_t unsigned long long int 248#elif defined GL_UINT64_T 249# define uintmax_t uint64_t 250#else 251# define uintmax_t unsigned long int 252#endif 253 254/* 7.18.2. Limits of specified-width integer types */ 255 256#if ! defined __cplusplus || defined __STDC_LIMIT_MACROS 257 258/* 7.18.2.1. Limits of exact-width integer types */ 259 260/* Here we assume a standard architecture where the hardware integer 261 types have 8, 16, 32, optionally 64 bits. */ 262 263#undef INT8_MIN 264#undef INT8_MAX 265#undef UINT8_MAX 266#define INT8_MIN (~ INT8_MAX) 267#define INT8_MAX 127 268#define UINT8_MAX 255 269 270#undef INT16_MIN 271#undef INT16_MAX 272#undef UINT16_MAX 273#define INT16_MIN (~ INT16_MAX) 274#define INT16_MAX 32767 275#define UINT16_MAX 65535 276 277#undef INT32_MIN 278#undef INT32_MAX 279#undef UINT32_MAX 280#define INT32_MIN (~ INT32_MAX) 281#define INT32_MAX 2147483647 282#define UINT32_MAX 4294967295U 283 284#undef INT64_MIN 285#undef INT64_MAX 286#ifdef GL_INT64_T 287/* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0 288 evaluates the latter incorrectly in preprocessor expressions. */ 289# define INT64_MIN (- INTMAX_C (1) << 63) 290# define INT64_MAX INTMAX_C (9223372036854775807) 291#endif 292 293#undef UINT64_MAX 294#ifdef GL_UINT64_T 295# define UINT64_MAX UINTMAX_C (18446744073709551615) 296#endif 297 298/* 7.18.2.2. Limits of minimum-width integer types */ 299 300/* Here we assume a standard architecture where the hardware integer 301 types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types 302 are the same as the corresponding N_t types. */ 303 304#undef INT_LEAST8_MIN 305#undef INT_LEAST8_MAX 306#undef UINT_LEAST8_MAX 307#define INT_LEAST8_MIN INT8_MIN 308#define INT_LEAST8_MAX INT8_MAX 309#define UINT_LEAST8_MAX UINT8_MAX 310 311#undef INT_LEAST16_MIN 312#undef INT_LEAST16_MAX 313#undef UINT_LEAST16_MAX 314#define INT_LEAST16_MIN INT16_MIN 315#define INT_LEAST16_MAX INT16_MAX 316#define UINT_LEAST16_MAX UINT16_MAX 317 318#undef INT_LEAST32_MIN 319#undef INT_LEAST32_MAX 320#undef UINT_LEAST32_MAX 321#define INT_LEAST32_MIN INT32_MIN 322#define INT_LEAST32_MAX INT32_MAX 323#define UINT_LEAST32_MAX UINT32_MAX 324 325#undef INT_LEAST64_MIN 326#undef INT_LEAST64_MAX 327#ifdef GL_INT64_T 328# define INT_LEAST64_MIN INT64_MIN 329# define INT_LEAST64_MAX INT64_MAX 330#endif 331 332#undef UINT_LEAST64_MAX 333#ifdef GL_UINT64_T 334# define UINT_LEAST64_MAX UINT64_MAX 335#endif 336 337/* 7.18.2.3. Limits of fastest minimum-width integer types */ 338 339/* Here we assume a standard architecture where the hardware integer 340 types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types 341 are taken from the same list of types. */ 342 343#undef INT_FAST8_MIN 344#undef INT_FAST8_MAX 345#undef UINT_FAST8_MAX 346#define INT_FAST8_MIN LONG_MIN 347#define INT_FAST8_MAX LONG_MAX 348#define UINT_FAST8_MAX ULONG_MAX 349 350#undef INT_FAST16_MIN 351#undef INT_FAST16_MAX 352#undef UINT_FAST16_MAX 353#define INT_FAST16_MIN LONG_MIN 354#define INT_FAST16_MAX LONG_MAX 355#define UINT_FAST16_MAX ULONG_MAX 356 357#undef INT_FAST32_MIN 358#undef INT_FAST32_MAX 359#undef UINT_FAST32_MAX 360#define INT_FAST32_MIN LONG_MIN 361#define INT_FAST32_MAX LONG_MAX 362#define UINT_FAST32_MAX ULONG_MAX 363 364#undef INT_FAST64_MIN 365#undef INT_FAST64_MAX 366#ifdef GL_INT64_T 367# define INT_FAST64_MIN INT64_MIN 368# define INT_FAST64_MAX INT64_MAX 369#endif 370 371#undef UINT_FAST64_MAX 372#ifdef GL_UINT64_T 373# define UINT_FAST64_MAX UINT64_MAX 374#endif 375 376/* 7.18.2.4. Limits of integer types capable of holding object pointers */ 377 378#undef INTPTR_MIN 379#undef INTPTR_MAX 380#undef UINTPTR_MAX 381#define INTPTR_MIN LONG_MIN 382#define INTPTR_MAX LONG_MAX 383#define UINTPTR_MAX ULONG_MAX 384 385/* 7.18.2.5. Limits of greatest-width integer types */ 386 387#undef INTMAX_MIN 388#undef INTMAX_MAX 389#ifdef INT64_MAX 390# define INTMAX_MIN INT64_MIN 391# define INTMAX_MAX INT64_MAX 392#else 393# define INTMAX_MIN INT32_MIN 394# define INTMAX_MAX INT32_MAX 395#endif 396 397#undef UINTMAX_MAX 398#ifdef UINT64_MAX 399# define UINTMAX_MAX UINT64_MAX 400#else 401# define UINTMAX_MAX UINT32_MAX 402#endif 403 404/* 7.18.3. Limits of other integer types */ 405 406/* ptrdiff_t limits */ 407#undef PTRDIFF_MIN 408#undef PTRDIFF_MAX 409#define PTRDIFF_MIN \ 410 _STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) 411#define PTRDIFF_MAX \ 412 _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) 413 414/* sig_atomic_t limits */ 415#undef SIG_ATOMIC_MIN 416#undef SIG_ATOMIC_MAX 417#define SIG_ATOMIC_MIN \ 418 _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ 419 0@SIG_ATOMIC_T_SUFFIX@) 420#define SIG_ATOMIC_MAX \ 421 _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ 422 0@SIG_ATOMIC_T_SUFFIX@) 423 424 425/* size_t limit */ 426#undef SIZE_MAX 427#define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@) 428 429/* wchar_t limits */ 430#undef WCHAR_MIN 431#undef WCHAR_MAX 432#define WCHAR_MIN \ 433 _STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) 434#define WCHAR_MAX \ 435 _STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) 436 437/* wint_t limits */ 438#undef WINT_MIN 439#undef WINT_MAX 440#define WINT_MIN \ 441 _STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) 442#define WINT_MAX \ 443 _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) 444 445#endif /* !defined __cplusplus || defined __STDC_LIMIT_MACROS */ 446 447/* 7.18.4. Macros for integer constants */ 448 449#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS 450 451/* 7.18.4.1. Macros for minimum-width integer constants */ 452/* According to ISO C 99 Technical Corrigendum 1 */ 453 454/* Here we assume a standard architecture where the hardware integer 455 types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */ 456 457#undef INT8_C 458#undef UINT8_C 459#define INT8_C(x) x 460#define UINT8_C(x) x 461 462#undef INT16_C 463#undef UINT16_C 464#define INT16_C(x) x 465#define UINT16_C(x) x 466 467#undef INT32_C 468#undef UINT32_C 469#define INT32_C(x) x 470#define UINT32_C(x) x ## U 471 472#undef INT64_C 473#undef UINT64_C 474#if LONG_MAX >> 31 >> 31 == 1 475# define INT64_C(x) x##L 476#elif defined _MSC_VER 477# define INT64_C(x) x##i64 478#elif @HAVE_LONG_LONG_INT@ 479# define INT64_C(x) x##LL 480#endif 481#if ULONG_MAX >> 31 >> 31 >> 1 == 1 482# define UINT64_C(x) x##UL 483#elif defined _MSC_VER 484# define UINT64_C(x) x##ui64 485#elif @HAVE_UNSIGNED_LONG_LONG_INT@ 486# define UINT64_C(x) x##ULL 487#endif 488 489/* 7.18.4.2. Macros for greatest-width integer constants */ 490 491#undef INTMAX_C 492#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 493# define INTMAX_C(x) x##LL 494#elif defined GL_INT64_T 495# define INTMAX_C(x) INT64_C(x) 496#else 497# define INTMAX_C(x) x##L 498#endif 499 500#undef UINTMAX_C 501#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 502# define UINTMAX_C(x) x##ULL 503#elif defined GL_UINT64_T 504# define UINTMAX_C(x) UINT64_C(x) 505#else 506# define UINTMAX_C(x) x##UL 507#endif 508 509#endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */ 510 511#endif /* _GL_STDINT_H */ 512#endif /* _GL_STDINT_H */ 513