1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28#ifndef _STDINT_H 29#define _STDINT_H 30 31#include <stddef.h> 32#include <sys/_types.h> 33 34 35 36#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) 37# define __STDINT_LIMITS 38#endif 39 40#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) 41# define __STDINT_MACROS 42#endif 43 44/* the definitions of STDINT_LIMITS depend on those of STDINT_MACROS */ 45#if defined __STDINT_LIMITS && !defined __STDINT_MACROS 46# define __STDINT_MACROS 47#endif 48 49#if !defined __STRICT_ANSI__ || __STDC_VERSION__ >= 199901L 50# define __STDC_INT64__ 51#endif 52 53typedef __int8_t int8_t; 54typedef __uint8_t uint8_t; 55typedef __int16_t int16_t; 56typedef __uint16_t uint16_t; 57typedef __int32_t int32_t; 58typedef __uint32_t uint32_t; 59#if defined(__STDC_INT64__) 60typedef __int64_t int64_t; 61typedef __uint64_t uint64_t; 62#endif 63 64/* 65 * int8_t & uint8_t 66 */ 67 68typedef int8_t int_least8_t; 69typedef int8_t int_fast8_t; 70 71typedef uint8_t uint_least8_t; 72typedef uint8_t uint_fast8_t; 73 74#ifdef __STDINT_LIMITS 75# define INT8_MIN (-128) 76# define INT8_MAX (127) 77# define INT_LEAST8_MIN INT8_MIN 78# define INT_LEAST8_MAX INT8_MAX 79# define INT_FAST8_MIN INT8_MIN 80# define INT_FAST8_MAX INT8_MAX 81 82# define UINT8_MAX (255U) 83# define UINT_LEAST8_MAX UINT8_MAX 84# define UINT_FAST8_MAX UINT8_MAX 85#endif 86 87#ifdef __STDINT_MACROS 88# define INT8_C(c) c 89# define INT_LEAST8_C(c) INT8_C(c) 90# define INT_FAST8_C(c) INT8_C(c) 91 92# define UINT8_C(c) c ## U 93# define UINT_LEAST8_C(c) UINT8_C(c) 94# define UINT_FAST8_C(c) UINT8_C(c) 95#endif 96 97/* 98 * int16_t & uint16_t 99 */ 100 101 102typedef int16_t int_least16_t; 103typedef int32_t int_fast16_t; 104 105typedef uint16_t uint_least16_t; 106typedef uint32_t uint_fast16_t; 107 108#ifdef __STDINT_LIMITS 109# define INT16_MIN (-32768) 110# define INT16_MAX (32767) 111# define INT_LEAST16_MIN INT16_MIN 112# define INT_LEAST16_MAX INT16_MAX 113# define INT_FAST16_MIN INT32_MIN 114# define INT_FAST16_MAX INT32_MAX 115 116# define UINT16_MAX (65535U) 117# define UINT_LEAST16_MAX UINT16_MAX 118# define UINT_FAST16_MAX UINT32_MAX 119#endif 120 121#ifdef __STDINT_MACROS 122# define INT16_C(c) c 123# define INT_LEAST16_C(c) INT16_C(c) 124# define INT_FAST16_C(c) INT32_C(c) 125 126# define UINT16_C(c) c ## U 127# define UINT_LEAST16_C(c) UINT16_C(c) 128# define UINT_FAST16_C(c) UINT32_C(c) 129#endif 130 131/* 132 * int32_t & uint32_t 133 */ 134 135typedef int32_t int_least32_t; 136typedef int32_t int_fast32_t; 137 138typedef uint32_t uint_least32_t; 139typedef uint32_t uint_fast32_t; 140 141#ifdef __STDINT_LIMITS 142# define INT32_MIN (-2147483647-1) 143# define INT32_MAX (2147483647) 144# define INT_LEAST32_MIN INT32_MIN 145# define INT_LEAST32_MAX INT32_MAX 146# define INT_FAST32_MIN INT32_MIN 147# define INT_FAST32_MAX INT32_MAX 148 149# define UINT32_MAX (4294967295U) 150# define UINT_LEAST32_MAX UINT32_MAX 151# define UINT_FAST32_MAX UINT32_MAX 152#endif 153 154#ifdef __STDINT_MACROS 155# define INT32_C(c) c 156# define INT_LEAST32_C(c) INT32_C(c) 157# define INT_FAST32_C(c) INT32_C(c) 158 159# define UINT32_C(c) c ## U 160# define UINT_LEAST32_C(c) UINT32_C(c) 161# define UINT_FAST32_C(c) UINT32_C(c) 162#endif 163 164#if defined(__STDC_INT64__) 165/* 166 * int64_t 167 */ 168typedef int64_t int_least64_t; 169typedef int64_t int_fast64_t; 170 171typedef uint64_t uint_least64_t; 172typedef uint64_t uint_fast64_t; 173 174 175#ifdef __STDINT_LIMITS 176# define INT64_MIN (__INT64_C(-9223372036854775807)-1) 177# define INT64_MAX (__INT64_C(9223372036854775807)) 178# define INT_LEAST64_MIN INT64_MIN 179# define INT_LEAST64_MAX INT64_MAX 180# define INT_FAST64_MIN INT64_MIN 181# define INT_FAST64_MAX INT64_MAX 182# define UINT64_MAX (__UINT64_C(18446744073709551615)) 183 184# define UINT_LEAST64_MAX UINT64_MAX 185# define UINT_FAST64_MAX UINT64_MAX 186#endif 187 188#ifdef __STDINT_MACROS 189# define __INT64_C(c) c ## LL 190# define INT64_C(c) __INT64_C(c) 191# define INT_LEAST64_C(c) INT64_C(c) 192# define INT_FAST64_C(c) INT64_C(c) 193 194# define __UINT64_C(c) c ## ULL 195# define UINT64_C(c) __UINT64_C(c) 196# define UINT_LEAST64_C(c) UINT64_C(c) 197# define UINT_FAST64_C(c) UINT64_C(c) 198#endif 199 200 201# define __PRI64_RANK "ll" 202# define __PRIFAST_RANK "" 203# define __PRIPTR_RANK "" 204 205#endif /* __STDC_INT64__ */ 206 207/* 208 * intptr_t & uintptr_t 209 */ 210 211typedef int intptr_t; 212typedef unsigned int uintptr_t; 213 214# define INTPTR_MIN INT32_MIN 215# define INTPTR_MAX INT32_MAX 216# define UINTPTR_MAX UINT32_MAX 217# define INTPTR_C(c) INT32_C(c) 218# define UINTPTR_C(c) UINT32_C(c) 219# define PTRDIFF_C(c) INT32_C(c) 220# define PTRDIFF_MIN INT32_MIN 221# define PTRDIFF_MAX INT32_MAX 222 223 224/* 225 * intmax_t & uintmax_t 226 */ 227 228#if defined(__STDC_INT64__) 229 230typedef uint64_t uintmax_t; 231typedef int64_t intmax_t; 232 233#define INTMAX_MIN INT64_MIN 234#define INTMAX_MAX INT64_MAX 235#define UINTMAX_MAX UINT64_MAX 236 237#define INTMAX_C(c) INT64_C(c) 238#define UINTMAX_C(c) UINT64_C(c) 239 240#else /* !__STDC_INT64__ */ 241 242typedef uint32_t uintmax_t; 243typedef int32_t intmax_t; 244 245#define INTMAX_MIN INT32_MIN 246#define INTMAX_MAX INT32_MAX 247#define UINTMAX_MAX UINT32_MAX 248 249#define INTMAX_C(c) INT32_C(c) 250#define UINTMAX_C(c) UINT32_C(c) 251 252#endif /* !__STDC_INT64__ */ 253 254 255/* size_t is defined by the GCC-specific <stddef.h> */ 256#ifndef _SSIZE_T_DEFINED_ 257#define _SSIZE_T_DEFINED_ 258typedef long int ssize_t; 259#endif 260 261#define _BITSIZE 32 262 263/* Keep the kernel from trying to define these types... */ 264#define __BIT_TYPES_DEFINED__ 265 266#endif /* _STDINT_H */ 267