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