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