1 /* 2 * Copyright (c) 2004, 2005 by 3 * Ralf Corsepius, Ulm/Germany. All rights reserved. 4 * 5 * Permission to use, copy, modify, and distribute this software 6 * is freely granted, provided that this notice is preserved. 7 */ 8 9 #ifndef _STDINT_H 10 #define _STDINT_H 11 12 #include <sys/cdefs.h> 13 #include <machine/_default_types.h> 14 #include <sys/_intsup.h> 15 #include <sys/_stdint.h> 16 17 _BEGIN_STD_C 18 19 #ifdef ___int_least8_t_defined 20 typedef __int_least8_t int_least8_t; 21 typedef __uint_least8_t uint_least8_t; 22 #define __int_least8_t_defined 1 23 #endif 24 25 #ifdef ___int_least16_t_defined 26 typedef __int_least16_t int_least16_t; 27 typedef __uint_least16_t uint_least16_t; 28 #define __int_least16_t_defined 1 29 #endif 30 31 #ifdef ___int_least32_t_defined 32 typedef __int_least32_t int_least32_t; 33 typedef __uint_least32_t uint_least32_t; 34 #define __int_least32_t_defined 1 35 #endif 36 37 #ifdef ___int_least64_t_defined 38 typedef __int_least64_t int_least64_t; 39 typedef __uint_least64_t uint_least64_t; 40 #define __int_least64_t_defined 1 41 #endif 42 43 /* 44 * Fastest minimum-width integer types 45 * 46 * Assume int to be the fastest type for all types with a width 47 * less than __INT_MAX__ rsp. INT_MAX 48 */ 49 #ifdef __INT_FAST8_TYPE__ 50 typedef __INT_FAST8_TYPE__ int_fast8_t; 51 typedef __UINT_FAST8_TYPE__ uint_fast8_t; 52 #define __int_fast8_t_defined 1 53 #elif __STDINT_EXP(INT_MAX) >= 0x7f 54 typedef signed int int_fast8_t; 55 typedef unsigned int uint_fast8_t; 56 #define __int_fast8_t_defined 1 57 #endif 58 59 #ifdef __INT_FAST16_TYPE__ 60 typedef __INT_FAST16_TYPE__ int_fast16_t; 61 typedef __UINT_FAST16_TYPE__ uint_fast16_t; 62 #define __int_fast16_t_defined 1 63 #elif __STDINT_EXP(INT_MAX) >= 0x7fff 64 typedef signed int int_fast16_t; 65 typedef unsigned int uint_fast16_t; 66 #define __int_fast16_t_defined 1 67 #endif 68 69 #ifdef __INT_FAST32_TYPE__ 70 typedef __INT_FAST32_TYPE__ int_fast32_t; 71 typedef __UINT_FAST32_TYPE__ uint_fast32_t; 72 #define __int_fast32_t_defined 1 73 #elif __STDINT_EXP(INT_MAX) >= 0x7fffffff 74 typedef signed int int_fast32_t; 75 typedef unsigned int uint_fast32_t; 76 #define __int_fast32_t_defined 1 77 #endif 78 79 #ifdef __INT_FAST64_TYPE__ 80 typedef __INT_FAST64_TYPE__ int_fast64_t; 81 typedef __UINT_FAST64_TYPE__ uint_fast64_t; 82 #define __int_fast64_t_defined 1 83 #elif __STDINT_EXP(INT_MAX) > 0x7fffffff 84 typedef signed int int_fast64_t; 85 typedef unsigned int uint_fast64_t; 86 #define __int_fast64_t_defined 1 87 #endif 88 89 /* 90 * Fall back to [u]int_least<N>_t for [u]int_fast<N>_t types 91 * not having been defined, yet. 92 * Leave undefined, if [u]int_least<N>_t should not be available. 93 */ 94 #if !__int_fast8_t_defined 95 #if __int_least8_t_defined 96 typedef int_least8_t int_fast8_t; 97 typedef uint_least8_t uint_fast8_t; 98 #define __int_fast8_t_defined 1 99 #endif 100 #endif 101 102 #if !__int_fast16_t_defined 103 #if __int_least16_t_defined 104 typedef int_least16_t int_fast16_t; 105 typedef uint_least16_t uint_fast16_t; 106 #define __int_fast16_t_defined 1 107 #endif 108 #endif 109 110 #if !__int_fast32_t_defined 111 #if __int_least32_t_defined 112 typedef int_least32_t int_fast32_t; 113 typedef uint_least32_t uint_fast32_t; 114 #define __int_fast32_t_defined 1 115 #endif 116 #endif 117 118 #if !__int_fast64_t_defined 119 #if __int_least64_t_defined 120 typedef int_least64_t int_fast64_t; 121 typedef uint_least64_t uint_fast64_t; 122 #define __int_fast64_t_defined 1 123 #endif 124 #endif 125 126 #ifdef __INTPTR_TYPE__ 127 #define INTPTR_MIN (-__INTPTR_MAX__ - 1) 128 #define INTPTR_MAX (__INTPTR_MAX__) 129 #define UINTPTR_MAX (__UINTPTR_MAX__) 130 #elif defined(__PTRDIFF_TYPE__) 131 #define INTPTR_MAX PTRDIFF_MAX 132 #define INTPTR_MIN PTRDIFF_MIN 133 #ifdef __UINTPTR_MAX__ 134 #define UINTPTR_MAX (__UINTPTR_MAX__) 135 #else 136 #define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1) 137 #endif 138 #else 139 /* 140 * Fallback to hardcoded values, 141 * should be valid on cpu's with 32bit int/32bit void* 142 */ 143 #define INTPTR_MAX (__STDINT_EXP(LONG_MAX)) 144 #define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1) 145 #define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) 146 #endif 147 148 /* Limits of Specified-Width Integer Types */ 149 150 #ifdef __INT8_MAX__ 151 #define INT8_MIN (-__INT8_MAX__ - 1) 152 #define INT8_MAX (__INT8_MAX__) 153 #define UINT8_MAX (__UINT8_MAX__) 154 #elif defined(__int8_t_defined) 155 #define INT8_MIN (-128) 156 #define INT8_MAX (127) 157 #define UINT8_MAX (255) 158 #endif 159 160 #ifdef __INT_LEAST8_MAX__ 161 #define INT_LEAST8_MIN (-__INT_LEAST8_MAX__ - 1) 162 #define INT_LEAST8_MAX (__INT_LEAST8_MAX__) 163 #define UINT_LEAST8_MAX (__UINT_LEAST8_MAX__) 164 #elif defined(__int_least8_t_defined) 165 #define INT_LEAST8_MIN (-128) 166 #define INT_LEAST8_MAX (127) 167 #define UINT_LEAST8_MAX (255) 168 #else 169 #error required type int_least8_t missing 170 #endif 171 172 #ifdef __INT16_MAX__ 173 #define INT16_MIN (-__INT16_MAX__ - 1) 174 #define INT16_MAX (__INT16_MAX__) 175 #define UINT16_MAX (__UINT16_MAX__) 176 #elif defined(__int16_t_defined) 177 #define INT16_MIN (-32768) 178 #define INT16_MAX (32767) 179 #define UINT16_MAX (65535) 180 #endif 181 182 #ifdef __INT_LEAST16_MAX__ 183 #define INT_LEAST16_MIN (-__INT_LEAST16_MAX__ - 1) 184 #define INT_LEAST16_MAX (__INT_LEAST16_MAX__) 185 #define UINT_LEAST16_MAX (__UINT_LEAST16_MAX__) 186 #elif defined(__int_least16_t_defined) 187 #define INT_LEAST16_MIN (-32768) 188 #define INT_LEAST16_MAX (32767) 189 #define UINT_LEAST16_MAX (65535) 190 #else 191 #error required type int_least16_t missing 192 #endif 193 194 #ifdef __INT32_MAX__ 195 #define INT32_MIN (-__INT32_MAX__ - 1) 196 #define INT32_MAX (__INT32_MAX__) 197 #define UINT32_MAX (__UINT32_MAX__) 198 #elif defined(__int32_t_defined) 199 #if defined (_INT32_EQ_LONG) 200 #define INT32_MIN (-2147483647L-1) 201 #define INT32_MAX (2147483647L) 202 #define UINT32_MAX (4294967295UL) 203 #else 204 #define INT32_MIN (-2147483647-1) 205 #define INT32_MAX (2147483647) 206 #define UINT32_MAX (4294967295U) 207 #endif 208 #endif 209 210 #ifdef __INT_LEAST32_MAX__ 211 #define INT_LEAST32_MIN (-__INT_LEAST32_MAX__ - 1) 212 #define INT_LEAST32_MAX (__INT_LEAST32_MAX__) 213 #define UINT_LEAST32_MAX (__UINT_LEAST32_MAX__) 214 #elif defined(__int_least32_t_defined) 215 #if defined (_INT32_EQ_LONG) 216 #define INT_LEAST32_MIN (-2147483647L-1) 217 #define INT_LEAST32_MAX (2147483647L) 218 #define UINT_LEAST32_MAX (4294967295UL) 219 #else 220 #define INT_LEAST32_MIN (-2147483647-1) 221 #define INT_LEAST32_MAX (2147483647) 222 #define UINT_LEAST32_MAX (4294967295U) 223 #endif 224 #else 225 #error required type int_least32_t missing 226 #endif 227 228 #ifdef __INT64_MAX__ 229 #define INT64_MIN (-__INT64_MAX__ - 1) 230 #define INT64_MAX (__INT64_MAX__) 231 #define UINT64_MAX (__UINT64_MAX__) 232 #elif defined(__int64_t_defined) 233 #if __have_long64 234 #define INT64_MIN (-9223372036854775807L-1L) 235 #define INT64_MAX (9223372036854775807L) 236 #define UINT64_MAX (18446744073709551615U) 237 #elif __have_longlong64 238 #define INT64_MIN (-9223372036854775807LL-1LL) 239 #define INT64_MAX (9223372036854775807LL) 240 #define UINT64_MAX (18446744073709551615ULL) 241 #endif 242 #endif 243 244 #ifdef __INT_LEAST64_MAX__ 245 #define INT_LEAST64_MIN (-__INT_LEAST64_MAX__ - 1) 246 #define INT_LEAST64_MAX (__INT_LEAST64_MAX__) 247 #define UINT_LEAST64_MAX (__UINT_LEAST64_MAX__) 248 #elif defined(__int_least64_t_defined) 249 #if __have_long64 250 #define INT_LEAST64_MIN (-9223372036854775807L-1L) 251 #define INT_LEAST64_MAX (9223372036854775807L) 252 #define UINT_LEAST64_MAX (18446744073709551615U) 253 #elif __have_longlong64 254 #define INT_LEAST64_MIN (-9223372036854775807LL-1LL) 255 #define INT_LEAST64_MAX (9223372036854775807LL) 256 #define UINT_LEAST64_MAX (18446744073709551615ULL) 257 #endif 258 #endif 259 260 #ifdef __INT_FAST8_MAX__ 261 #define INT_FAST8_MIN (-__INT_FAST8_MAX__ - 1) 262 #define INT_FAST8_MAX (__INT_FAST8_MAX__) 263 #define UINT_FAST8_MAX (__UINT_FAST8_MAX__) 264 #elif defined(__int_fast8_t_defined) 265 #if __STDINT_EXP(INT_MAX) >= 0x7f 266 #define INT_FAST8_MIN (-__STDINT_EXP(INT_MAX)-1) 267 #define INT_FAST8_MAX (__STDINT_EXP(INT_MAX)) 268 #define UINT_FAST8_MAX (__STDINT_EXP(INT_MAX)*2U+1U) 269 #else 270 #define INT_FAST8_MIN INT_LEAST8_MIN 271 #define INT_FAST8_MAX INT_LEAST8_MAX 272 #define UINT_FAST8_MAX UINT_LEAST8_MAX 273 #endif 274 #endif 275 276 #ifdef __INT_FAST16_MAX__ 277 #define INT_FAST16_MIN (-__INT_FAST16_MAX__ - 1) 278 #define INT_FAST16_MAX (__INT_FAST16_MAX__) 279 #define UINT_FAST16_MAX (__UINT_FAST16_MAX__) 280 #elif defined(__int_fast16_t_defined) 281 #if __STDINT_EXP(INT_MAX) >= 0x7fff 282 #define INT_FAST16_MIN (-__STDINT_EXP(INT_MAX)-1) 283 #define INT_FAST16_MAX (__STDINT_EXP(INT_MAX)) 284 #define UINT_FAST16_MAX (__STDINT_EXP(INT_MAX)*2U+1U) 285 #else 286 #define INT_FAST16_MIN INT_LEAST16_MIN 287 #define INT_FAST16_MAX INT_LEAST16_MAX 288 #define UINT_FAST16_MAX UINT_LEAST16_MAX 289 #endif 290 #endif 291 292 #ifdef __INT_FAST32_MAX__ 293 #define INT_FAST32_MIN (-__INT_FAST32_MAX__ - 1) 294 #define INT_FAST32_MAX (__INT_FAST32_MAX__) 295 #define UINT_FAST32_MAX (__UINT_FAST32_MAX__) 296 #elif defined(__int_fast32_t_defined) 297 #if __STDINT_EXP(INT_MAX) >= 0x7fffffff 298 #define INT_FAST32_MIN (-__STDINT_EXP(INT_MAX)-1) 299 #define INT_FAST32_MAX (__STDINT_EXP(INT_MAX)) 300 #define UINT_FAST32_MAX (__STDINT_EXP(INT_MAX)*2U+1U) 301 #else 302 #define INT_FAST32_MIN INT_LEAST32_MIN 303 #define INT_FAST32_MAX INT_LEAST32_MAX 304 #define UINT_FAST32_MAX UINT_LEAST32_MAX 305 #endif 306 #endif 307 308 #ifdef __INT_FAST64_MAX__ 309 #define INT_FAST64_MIN (-__INT_FAST64_MAX__ - 1) 310 #define INT_FAST64_MAX (__INT_FAST64_MAX__) 311 #define UINT_FAST64_MAX (__UINT_FAST64_MAX__) 312 #elif defined(__int_fast64_t_defined) 313 #if __STDINT_EXP(INT_MAX) > 0x7fffffff 314 #define INT_FAST64_MIN (-__STDINT_EXP(INT_MAX)-1) 315 #define INT_FAST64_MAX (__STDINT_EXP(INT_MAX)) 316 #define UINT_FAST64_MAX (__STDINT_EXP(INT_MAX)*2U+1U) 317 #else 318 #define INT_FAST64_MIN INT_LEAST64_MIN 319 #define INT_FAST64_MAX INT_LEAST64_MAX 320 #define UINT_FAST64_MAX UINT_LEAST64_MAX 321 #endif 322 #endif 323 324 #ifdef __INTMAX_MAX__ 325 #define INTMAX_MAX (__INTMAX_MAX__) 326 #define INTMAX_MIN (-INTMAX_MAX - 1) 327 #elif defined(__INTMAX_TYPE__) 328 /* All relevant GCC versions prefer long to long long for intmax_t. */ 329 #define INTMAX_MAX INT64_MAX 330 #define INTMAX_MIN INT64_MIN 331 #endif 332 333 #ifdef __UINTMAX_MAX__ 334 #define UINTMAX_MAX (__UINTMAX_MAX__) 335 #elif defined(__UINTMAX_TYPE__) 336 /* All relevant GCC versions prefer long to long long for intmax_t. */ 337 #define UINTMAX_MAX UINT64_MAX 338 #endif 339 340 /* This must match size_t in stddef.h, currently long unsigned int */ 341 #ifdef __SIZE_MAX__ 342 #define SIZE_MAX (__SIZE_MAX__) 343 #else 344 #define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) 345 #endif 346 347 /* This must match sig_atomic_t in <signal.h> (currently int) */ 348 #define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1) 349 #define SIG_ATOMIC_MAX (__STDINT_EXP(INT_MAX)) 350 351 /* This must match ptrdiff_t in <stddef.h> (currently long int) */ 352 #ifdef __PTRDIFF_MAX__ 353 #define PTRDIFF_MAX (__PTRDIFF_MAX__) 354 #else 355 #define PTRDIFF_MAX (__STDINT_EXP(LONG_MAX)) 356 #endif 357 #define PTRDIFF_MIN (-PTRDIFF_MAX - 1) 358 359 /* This must match definition in <wchar.h> */ 360 #ifndef WCHAR_MIN 361 #ifdef __WCHAR_MIN__ 362 #define WCHAR_MIN (__WCHAR_MIN__) 363 #elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0) 364 #define WCHAR_MIN (0 + L'\0') 365 #else 366 #define WCHAR_MIN (-0x7fffffff - 1 + L'\0') 367 #endif 368 #endif 369 370 /* This must match definition in <wchar.h> */ 371 #ifndef WCHAR_MAX 372 #ifdef __WCHAR_MAX__ 373 #define WCHAR_MAX (__WCHAR_MAX__) 374 #elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0) 375 #define WCHAR_MAX (0xffffffffu + L'\0') 376 #else 377 #define WCHAR_MAX (0x7fffffff + L'\0') 378 #endif 379 #endif 380 381 /* wint_t is unsigned int on almost all GCC targets. */ 382 #ifdef __WINT_MAX__ 383 #define WINT_MAX (__WINT_MAX__) 384 #else 385 #define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) 386 #endif 387 #ifdef __WINT_MIN__ 388 #define WINT_MIN (__WINT_MIN__) 389 #else 390 #define WINT_MIN (0U) 391 #endif 392 393 /** Macros for minimum-width integer constant expressions */ 394 #ifdef __INT8_C 395 #define INT8_C(x) __INT8_C(x) 396 #define UINT8_C(x) __UINT8_C(x) 397 #else 398 #define INT8_C(x) x 399 #if __STDINT_EXP(INT_MAX) > 0x7f 400 #define UINT8_C(x) x 401 #else 402 #define UINT8_C(x) x##U 403 #endif 404 #endif 405 406 #ifdef __INT16_C 407 #define INT16_C(x) __INT16_C(x) 408 #define UINT16_C(x) __UINT16_C(x) 409 #else 410 #define INT16_C(x) x 411 #if __STDINT_EXP(INT_MAX) > 0x7fff 412 #define UINT16_C(x) x 413 #else 414 #define UINT16_C(x) x##U 415 #endif 416 #endif 417 418 #ifdef __INT32_C 419 #define INT32_C(x) __INT32_C(x) 420 #define UINT32_C(x) __UINT32_C(x) 421 #else 422 #if defined (_INT32_EQ_LONG) 423 #define INT32_C(x) x##L 424 #define UINT32_C(x) x##UL 425 #else 426 #define INT32_C(x) x 427 #define UINT32_C(x) x##U 428 #endif 429 #endif 430 431 #ifdef __INT64_C 432 #define INT64_C(x) __INT64_C(x) 433 #define UINT64_C(x) __UINT64_C(x) 434 #else 435 #if __int64_t_defined 436 #if __have_long64 437 #define INT64_C(x) x##L 438 #define UINT64_C(x) x##UL 439 #else 440 #define INT64_C(x) x##LL 441 #define UINT64_C(x) x##ULL 442 #endif 443 #endif 444 #endif 445 446 /** Macros for greatest-width integer constant expression */ 447 #ifdef __INTMAX_C 448 #define INTMAX_C(x) __INTMAX_C(x) 449 #define UINTMAX_C(x) __UINTMAX_C(x) 450 #else 451 #if __have_long64 452 #define INTMAX_C(x) x##L 453 #define UINTMAX_C(x) x##UL 454 #else 455 #define INTMAX_C(x) x##LL 456 #define UINTMAX_C(x) x##ULL 457 #endif 458 #endif 459 460 #if __STDC_WANT_LIB_EXT1__ == 1 461 // could be defined by the user 462 #ifndef RSIZE_MAX 463 #define RSIZE_MAX SIZE_MAX 464 #endif 465 #endif 466 467 _END_STD_C 468 469 #endif /* _STDINT_H */ 470 471