1*c54f35caSApple OSS Distributions /* 2*c54f35caSApple OSS Distributions * Copyright (c) 2000-2010 Apple Inc. 3*c54f35caSApple OSS Distributions * All rights reserved. 4*c54f35caSApple OSS Distributions */ 5*c54f35caSApple OSS Distributions 6*c54f35caSApple OSS Distributions #ifndef _KERNEL_STDINT_H_ 7*c54f35caSApple OSS Distributions #define _KERNEL_STDINT_H_ 8*c54f35caSApple OSS Distributions 9*c54f35caSApple OSS Distributions #ifndef KERNEL 10*c54f35caSApple OSS Distributions /* For user-space code that may include this header */ 11*c54f35caSApple OSS Distributions #include_next <stdint.h> 12*c54f35caSApple OSS Distributions #else /* KERNEL */ 13*c54f35caSApple OSS Distributions 14*c54f35caSApple OSS Distributions #include <machine/types.h> 15*c54f35caSApple OSS Distributions 16*c54f35caSApple OSS Distributions #if __LP64__ 17*c54f35caSApple OSS Distributions #define __WORDSIZE 64 18*c54f35caSApple OSS Distributions #else 19*c54f35caSApple OSS Distributions #define __WORDSIZE 32 20*c54f35caSApple OSS Distributions #endif 21*c54f35caSApple OSS Distributions 22*c54f35caSApple OSS Distributions /* from ISO/IEC 988:1999 spec */ 23*c54f35caSApple OSS Distributions 24*c54f35caSApple OSS Distributions /* 7.18.1.1 Exact-width integer types */ 25*c54f35caSApple OSS Distributions /* int8_t is defined in <machine/types.h> */ 26*c54f35caSApple OSS Distributions /* int16_t is defined in <machine/types.h> */ 27*c54f35caSApple OSS Distributions /* int32_t is defined in <machine/types.h> */ 28*c54f35caSApple OSS Distributions /* int64_t is defined in <machine/types.h> */ 29*c54f35caSApple OSS Distributions typedef u_int8_t uint8_t; /* u_int8_t is defined in <machine/types.h> */ 30*c54f35caSApple OSS Distributions typedef u_int16_t uint16_t; /* u_int16_t is defined in <machine/types.h> */ 31*c54f35caSApple OSS Distributions typedef u_int32_t uint32_t; /* u_int32_t is defined in <machine/types.h> */ 32*c54f35caSApple OSS Distributions typedef u_int64_t uint64_t; /* u_int64_t is defined in <machine/types.h> */ 33*c54f35caSApple OSS Distributions 34*c54f35caSApple OSS Distributions 35*c54f35caSApple OSS Distributions /* 7.18.1.2 Minimum-width integer types */ 36*c54f35caSApple OSS Distributions typedef int8_t int_least8_t; 37*c54f35caSApple OSS Distributions typedef int16_t int_least16_t; 38*c54f35caSApple OSS Distributions typedef int32_t int_least32_t; 39*c54f35caSApple OSS Distributions typedef int64_t int_least64_t; 40*c54f35caSApple OSS Distributions typedef uint8_t uint_least8_t; 41*c54f35caSApple OSS Distributions typedef uint16_t uint_least16_t; 42*c54f35caSApple OSS Distributions typedef uint32_t uint_least32_t; 43*c54f35caSApple OSS Distributions typedef uint64_t uint_least64_t; 44*c54f35caSApple OSS Distributions 45*c54f35caSApple OSS Distributions 46*c54f35caSApple OSS Distributions /* 7.18.1.3 Fastest-width integer types */ 47*c54f35caSApple OSS Distributions typedef int8_t int_fast8_t; 48*c54f35caSApple OSS Distributions typedef int16_t int_fast16_t; 49*c54f35caSApple OSS Distributions typedef int32_t int_fast32_t; 50*c54f35caSApple OSS Distributions typedef int64_t int_fast64_t; 51*c54f35caSApple OSS Distributions typedef uint8_t uint_fast8_t; 52*c54f35caSApple OSS Distributions typedef uint16_t uint_fast16_t; 53*c54f35caSApple OSS Distributions typedef uint32_t uint_fast32_t; 54*c54f35caSApple OSS Distributions typedef uint64_t uint_fast64_t; 55*c54f35caSApple OSS Distributions 56*c54f35caSApple OSS Distributions 57*c54f35caSApple OSS Distributions /* 7.18.1.4 Integer types capable of holding object pointers */ 58*c54f35caSApple OSS Distributions /* intptr_t is defined in <machine/types.h> */ 59*c54f35caSApple OSS Distributions /* uintptr_t is defined in <machine/types.h> */ 60*c54f35caSApple OSS Distributions 61*c54f35caSApple OSS Distributions 62*c54f35caSApple OSS Distributions /* 7.18.1.5 Greatest-width integer types */ 63*c54f35caSApple OSS Distributions #ifdef __INTMAX_TYPE__ 64*c54f35caSApple OSS Distributions typedef __INTMAX_TYPE__ intmax_t; 65*c54f35caSApple OSS Distributions #else 66*c54f35caSApple OSS Distributions #ifdef __LP64__ 67*c54f35caSApple OSS Distributions typedef long int intmax_t; 68*c54f35caSApple OSS Distributions #else 69*c54f35caSApple OSS Distributions typedef long long int intmax_t; 70*c54f35caSApple OSS Distributions #endif /* __LP64__ */ 71*c54f35caSApple OSS Distributions #endif /* __INTMAX_TYPE__ */ 72*c54f35caSApple OSS Distributions #ifdef __UINTMAX_TYPE__ 73*c54f35caSApple OSS Distributions typedef __UINTMAX_TYPE__ uintmax_t; 74*c54f35caSApple OSS Distributions #else 75*c54f35caSApple OSS Distributions #ifdef __LP64__ 76*c54f35caSApple OSS Distributions typedef long unsigned int uintmax_t; 77*c54f35caSApple OSS Distributions #else 78*c54f35caSApple OSS Distributions typedef long long unsigned int uintmax_t; 79*c54f35caSApple OSS Distributions #endif /* __LP64__ */ 80*c54f35caSApple OSS Distributions #endif /* __UINTMAX_TYPE__ */ 81*c54f35caSApple OSS Distributions 82*c54f35caSApple OSS Distributions /* 7.18.4 Macros for integer constants */ 83*c54f35caSApple OSS Distributions #define INT8_C(v) (v) 84*c54f35caSApple OSS Distributions #define INT16_C(v) (v) 85*c54f35caSApple OSS Distributions #define INT32_C(v) (v) 86*c54f35caSApple OSS Distributions #define INT64_C(v) (v ## LL) 87*c54f35caSApple OSS Distributions 88*c54f35caSApple OSS Distributions #define UINT8_C(v) (v) 89*c54f35caSApple OSS Distributions #define UINT16_C(v) (v) 90*c54f35caSApple OSS Distributions #define UINT32_C(v) (v ## U) 91*c54f35caSApple OSS Distributions #define UINT64_C(v) (v ## ULL) 92*c54f35caSApple OSS Distributions 93*c54f35caSApple OSS Distributions #ifdef __LP64__ 94*c54f35caSApple OSS Distributions #define INTMAX_C(v) (v ## L) 95*c54f35caSApple OSS Distributions #define UINTMAX_C(v) (v ## UL) 96*c54f35caSApple OSS Distributions #else 97*c54f35caSApple OSS Distributions #define INTMAX_C(v) (v ## LL) 98*c54f35caSApple OSS Distributions #define UINTMAX_C(v) (v ## ULL) 99*c54f35caSApple OSS Distributions #endif 100*c54f35caSApple OSS Distributions 101*c54f35caSApple OSS Distributions /* 7.18.2 Limits of specified-width integer types: 102*c54f35caSApple OSS Distributions * These #defines specify the minimum and maximum limits 103*c54f35caSApple OSS Distributions * of each of the types declared above. 104*c54f35caSApple OSS Distributions * 105*c54f35caSApple OSS Distributions * They must have "the same type as would an expression that is an 106*c54f35caSApple OSS Distributions * object of the corresponding type converted according to the integer 107*c54f35caSApple OSS Distributions * promotion". 108*c54f35caSApple OSS Distributions */ 109*c54f35caSApple OSS Distributions 110*c54f35caSApple OSS Distributions 111*c54f35caSApple OSS Distributions /* 7.18.2.1 Limits of exact-width integer types */ 112*c54f35caSApple OSS Distributions #define INT8_MAX 127 113*c54f35caSApple OSS Distributions #define INT16_MAX 32767 114*c54f35caSApple OSS Distributions #define INT32_MAX 2147483647 115*c54f35caSApple OSS Distributions #define INT64_MAX 9223372036854775807LL 116*c54f35caSApple OSS Distributions 117*c54f35caSApple OSS Distributions #define INT8_MIN -128 118*c54f35caSApple OSS Distributions #define INT16_MIN -32768 119*c54f35caSApple OSS Distributions /* 120*c54f35caSApple OSS Distributions Note: the literal "most negative int" cannot be written in C -- 121*c54f35caSApple OSS Distributions the rules in the standard (section 6.4.4.1 in C99) will give it 122*c54f35caSApple OSS Distributions an unsigned type, so INT32_MIN (and the most negative member of 123*c54f35caSApple OSS Distributions any larger signed type) must be written via a constant expression. 124*c54f35caSApple OSS Distributions */ 125*c54f35caSApple OSS Distributions #define INT32_MIN (-INT32_MAX-1) 126*c54f35caSApple OSS Distributions #define INT64_MIN (-INT64_MAX-1) 127*c54f35caSApple OSS Distributions 128*c54f35caSApple OSS Distributions #define UINT8_MAX 255 129*c54f35caSApple OSS Distributions #define UINT16_MAX 65535 130*c54f35caSApple OSS Distributions #define UINT32_MAX 4294967295U 131*c54f35caSApple OSS Distributions #define UINT64_MAX 18446744073709551615ULL 132*c54f35caSApple OSS Distributions 133*c54f35caSApple OSS Distributions /* 7.18.2.2 Limits of minimum-width integer types */ 134*c54f35caSApple OSS Distributions #define INT_LEAST8_MIN INT8_MIN 135*c54f35caSApple OSS Distributions #define INT_LEAST16_MIN INT16_MIN 136*c54f35caSApple OSS Distributions #define INT_LEAST32_MIN INT32_MIN 137*c54f35caSApple OSS Distributions #define INT_LEAST64_MIN INT64_MIN 138*c54f35caSApple OSS Distributions 139*c54f35caSApple OSS Distributions #define INT_LEAST8_MAX INT8_MAX 140*c54f35caSApple OSS Distributions #define INT_LEAST16_MAX INT16_MAX 141*c54f35caSApple OSS Distributions #define INT_LEAST32_MAX INT32_MAX 142*c54f35caSApple OSS Distributions #define INT_LEAST64_MAX INT64_MAX 143*c54f35caSApple OSS Distributions 144*c54f35caSApple OSS Distributions #define UINT_LEAST8_MAX UINT8_MAX 145*c54f35caSApple OSS Distributions #define UINT_LEAST16_MAX UINT16_MAX 146*c54f35caSApple OSS Distributions #define UINT_LEAST32_MAX UINT32_MAX 147*c54f35caSApple OSS Distributions #define UINT_LEAST64_MAX UINT64_MAX 148*c54f35caSApple OSS Distributions 149*c54f35caSApple OSS Distributions /* 7.18.2.3 Limits of fastest minimum-width integer types */ 150*c54f35caSApple OSS Distributions #define INT_FAST8_MIN INT8_MIN 151*c54f35caSApple OSS Distributions #define INT_FAST16_MIN INT16_MIN 152*c54f35caSApple OSS Distributions #define INT_FAST32_MIN INT32_MIN 153*c54f35caSApple OSS Distributions #define INT_FAST64_MIN INT64_MIN 154*c54f35caSApple OSS Distributions 155*c54f35caSApple OSS Distributions #define INT_FAST8_MAX INT8_MAX 156*c54f35caSApple OSS Distributions #define INT_FAST16_MAX INT16_MAX 157*c54f35caSApple OSS Distributions #define INT_FAST32_MAX INT32_MAX 158*c54f35caSApple OSS Distributions #define INT_FAST64_MAX INT64_MAX 159*c54f35caSApple OSS Distributions 160*c54f35caSApple OSS Distributions #define UINT_FAST8_MAX UINT8_MAX 161*c54f35caSApple OSS Distributions #define UINT_FAST16_MAX UINT16_MAX 162*c54f35caSApple OSS Distributions #define UINT_FAST32_MAX UINT32_MAX 163*c54f35caSApple OSS Distributions #define UINT_FAST64_MAX UINT64_MAX 164*c54f35caSApple OSS Distributions 165*c54f35caSApple OSS Distributions /* 7.18.2.4 Limits of integer types capable of holding object pointers */ 166*c54f35caSApple OSS Distributions 167*c54f35caSApple OSS Distributions #if __WORDSIZE == 64 168*c54f35caSApple OSS Distributions #define INTPTR_MAX 9223372036854775807L 169*c54f35caSApple OSS Distributions #else 170*c54f35caSApple OSS Distributions #define INTPTR_MAX 2147483647L 171*c54f35caSApple OSS Distributions #endif 172*c54f35caSApple OSS Distributions #define INTPTR_MIN (-INTPTR_MAX-1) 173*c54f35caSApple OSS Distributions 174*c54f35caSApple OSS Distributions #if __WORDSIZE == 64 175*c54f35caSApple OSS Distributions #define UINTPTR_MAX 18446744073709551615UL 176*c54f35caSApple OSS Distributions #else 177*c54f35caSApple OSS Distributions #define UINTPTR_MAX 4294967295UL 178*c54f35caSApple OSS Distributions #endif 179*c54f35caSApple OSS Distributions 180*c54f35caSApple OSS Distributions /* 7.18.2.5 Limits of greatest-width integer types */ 181*c54f35caSApple OSS Distributions #define INTMAX_MAX INTMAX_C(9223372036854775807) 182*c54f35caSApple OSS Distributions #define UINTMAX_MAX UINTMAX_C(18446744073709551615) 183*c54f35caSApple OSS Distributions #define INTMAX_MIN (-INTMAX_MAX-1) 184*c54f35caSApple OSS Distributions 185*c54f35caSApple OSS Distributions /* 7.18.3 "Other" */ 186*c54f35caSApple OSS Distributions #if __WORDSIZE == 64 187*c54f35caSApple OSS Distributions #define PTRDIFF_MIN INTMAX_MIN 188*c54f35caSApple OSS Distributions #define PTRDIFF_MAX INTMAX_MAX 189*c54f35caSApple OSS Distributions #else 190*c54f35caSApple OSS Distributions #define PTRDIFF_MIN INT32_MIN 191*c54f35caSApple OSS Distributions #define PTRDIFF_MAX INT32_MAX 192*c54f35caSApple OSS Distributions #endif 193*c54f35caSApple OSS Distributions 194*c54f35caSApple OSS Distributions #define SIZE_MAX UINTPTR_MAX 195*c54f35caSApple OSS Distributions 196*c54f35caSApple OSS Distributions #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 197*c54f35caSApple OSS Distributions #define RSIZE_MAX (SIZE_MAX >> 1) 198*c54f35caSApple OSS Distributions #endif 199*c54f35caSApple OSS Distributions 200*c54f35caSApple OSS Distributions #ifndef WCHAR_MAX 201*c54f35caSApple OSS Distributions # ifdef __WCHAR_MAX__ 202*c54f35caSApple OSS Distributions # define WCHAR_MAX __WCHAR_MAX__ 203*c54f35caSApple OSS Distributions # else 204*c54f35caSApple OSS Distributions # define WCHAR_MAX 0x7fffffff 205*c54f35caSApple OSS Distributions # endif 206*c54f35caSApple OSS Distributions #endif 207*c54f35caSApple OSS Distributions 208*c54f35caSApple OSS Distributions /* WCHAR_MIN should be 0 if wchar_t is an unsigned type and 209*c54f35caSApple OSS Distributions (-WCHAR_MAX-1) if wchar_t is a signed type. Unfortunately, 210*c54f35caSApple OSS Distributions it turns out that -fshort-wchar changes the signedness of 211*c54f35caSApple OSS Distributions the type. */ 212*c54f35caSApple OSS Distributions #ifndef WCHAR_MIN 213*c54f35caSApple OSS Distributions # if WCHAR_MAX == 0xffff 214*c54f35caSApple OSS Distributions # define WCHAR_MIN 0 215*c54f35caSApple OSS Distributions # else 216*c54f35caSApple OSS Distributions # define WCHAR_MIN (-WCHAR_MAX-1) 217*c54f35caSApple OSS Distributions # endif 218*c54f35caSApple OSS Distributions #endif 219*c54f35caSApple OSS Distributions 220*c54f35caSApple OSS Distributions #define WINT_MIN INT32_MIN 221*c54f35caSApple OSS Distributions #define WINT_MAX INT32_MAX 222*c54f35caSApple OSS Distributions 223*c54f35caSApple OSS Distributions #define SIG_ATOMIC_MIN INT32_MIN 224*c54f35caSApple OSS Distributions #define SIG_ATOMIC_MAX INT32_MAX 225*c54f35caSApple OSS Distributions 226*c54f35caSApple OSS Distributions #endif /* KERNEL */ 227*c54f35caSApple OSS Distributions 228*c54f35caSApple OSS Distributions #endif /* _KERNEL_STDINT_H_ */ 229