The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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 | */ |
Elliott Hughes | a9a02ac | 2013-09-30 14:46:47 -0700 | [diff] [blame] | 28 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 29 | #ifndef _STDINT_H |
| 30 | #define _STDINT_H |
| 31 | |
| 32 | #include <stddef.h> |
Elliott Hughes | 83c07b5 | 2014-04-21 18:09:46 -0700 | [diff] [blame] | 33 | #include <machine/wchar_limits.h> |
Elliott Hughes | 9f87a0b | 2014-02-07 14:55:58 -0800 | [diff] [blame] | 34 | |
| 35 | typedef __signed char __int8_t; |
| 36 | typedef unsigned char __uint8_t; |
| 37 | typedef short __int16_t; |
| 38 | typedef unsigned short __uint16_t; |
| 39 | typedef int __int32_t; |
| 40 | typedef unsigned int __uint32_t; |
| 41 | #if __LP64__ |
| 42 | typedef long __int64_t; |
| 43 | typedef unsigned long __uint64_t; |
| 44 | #else |
| 45 | typedef long long __int64_t; |
| 46 | typedef unsigned long long __uint64_t; |
| 47 | #endif |
| 48 | |
| 49 | #if __LP64__ |
| 50 | typedef long __intptr_t; |
| 51 | typedef unsigned long __uintptr_t; |
| 52 | #else |
| 53 | typedef int __intptr_t; |
| 54 | typedef unsigned int __uintptr_t; |
| 55 | #endif |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 56 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 57 | typedef __int8_t int8_t; |
| 58 | typedef __uint8_t uint8_t; |
Elliott Hughes | e2a292d | 2014-01-24 16:37:04 -0800 | [diff] [blame] | 59 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 60 | typedef __int16_t int16_t; |
| 61 | typedef __uint16_t uint16_t; |
Elliott Hughes | e2a292d | 2014-01-24 16:37:04 -0800 | [diff] [blame] | 62 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 63 | typedef __int32_t int32_t; |
| 64 | typedef __uint32_t uint32_t; |
Elliott Hughes | e2a292d | 2014-01-24 16:37:04 -0800 | [diff] [blame] | 65 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 66 | typedef __int64_t int64_t; |
| 67 | typedef __uint64_t uint64_t; |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 68 | |
Elliott Hughes | 9f87a0b | 2014-02-07 14:55:58 -0800 | [diff] [blame] | 69 | typedef __intptr_t intptr_t; |
| 70 | typedef __uintptr_t uintptr_t; |
| 71 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 72 | typedef int8_t int_least8_t; |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 73 | typedef uint8_t uint_least8_t; |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 74 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 75 | typedef int16_t int_least16_t; |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 76 | typedef uint16_t uint_least16_t; |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 77 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 78 | typedef int32_t int_least32_t; |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 79 | typedef uint32_t uint_least32_t; |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 80 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 81 | typedef int64_t int_least64_t; |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 82 | typedef uint64_t uint_least64_t; |
Calin Juravle | da030de | 2014-02-20 13:40:36 +0000 | [diff] [blame] | 83 | |
| 84 | typedef int8_t int_fast8_t; |
| 85 | typedef uint8_t uint_fast8_t; |
| 86 | |
| 87 | typedef int64_t int_fast64_t; |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 88 | typedef uint64_t uint_fast64_t; |
| 89 | |
Elliott Hughes | 83c07b5 | 2014-04-21 18:09:46 -0700 | [diff] [blame] | 90 | #if defined(__LP64__) |
Calin Juravle | da030de | 2014-02-20 13:40:36 +0000 | [diff] [blame] | 91 | typedef int64_t int_fast16_t; |
| 92 | typedef uint64_t uint_fast16_t; |
| 93 | typedef int64_t int_fast32_t; |
| 94 | typedef uint64_t uint_fast32_t; |
| 95 | #else |
| 96 | typedef int32_t int_fast16_t; |
| 97 | typedef uint32_t uint_fast16_t; |
| 98 | typedef int32_t int_fast32_t; |
| 99 | typedef uint32_t uint_fast32_t; |
| 100 | #endif |
| 101 | |
Elliott Hughes | 9f87a0b | 2014-02-07 14:55:58 -0800 | [diff] [blame] | 102 | typedef uint64_t uintmax_t; |
| 103 | typedef int64_t intmax_t; |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 104 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 105 | /* Keep the kernel from trying to define these types... */ |
| 106 | #define __BIT_TYPES_DEFINED__ |
| 107 | |
Elliott Hughes | e2a292d | 2014-01-24 16:37:04 -0800 | [diff] [blame] | 108 | #define INT8_C(c) c |
| 109 | #define INT_LEAST8_C(c) INT8_C(c) |
| 110 | #define INT_FAST8_C(c) INT8_C(c) |
| 111 | |
| 112 | #define UINT8_C(c) c |
| 113 | #define UINT_LEAST8_C(c) UINT8_C(c) |
| 114 | #define UINT_FAST8_C(c) UINT8_C(c) |
| 115 | |
| 116 | #define INT16_C(c) c |
| 117 | #define INT_LEAST16_C(c) INT16_C(c) |
| 118 | #define INT_FAST16_C(c) INT32_C(c) |
| 119 | |
| 120 | #define UINT16_C(c) c |
| 121 | #define UINT_LEAST16_C(c) UINT16_C(c) |
| 122 | #define UINT_FAST16_C(c) UINT32_C(c) |
| 123 | #define INT32_C(c) c |
| 124 | #define INT_LEAST32_C(c) INT32_C(c) |
| 125 | #define INT_FAST32_C(c) INT32_C(c) |
| 126 | |
| 127 | #define UINT32_C(c) c ## U |
| 128 | #define UINT_LEAST32_C(c) UINT32_C(c) |
| 129 | #define UINT_FAST32_C(c) UINT32_C(c) |
| 130 | #define INT_LEAST64_C(c) INT64_C(c) |
| 131 | #define INT_FAST64_C(c) INT64_C(c) |
| 132 | |
| 133 | #define UINT_LEAST64_C(c) UINT64_C(c) |
| 134 | #define UINT_FAST64_C(c) UINT64_C(c) |
| 135 | |
| 136 | #define INTMAX_C(c) INT64_C(c) |
| 137 | #define UINTMAX_C(c) UINT64_C(c) |
| 138 | |
Elliott Hughes | 83c07b5 | 2014-04-21 18:09:46 -0700 | [diff] [blame] | 139 | #if defined(__LP64__) |
Elliott Hughes | e2a292d | 2014-01-24 16:37:04 -0800 | [diff] [blame] | 140 | # define INT64_C(c) c ## L |
| 141 | # define UINT64_C(c) c ## UL |
| 142 | # define INTPTR_C(c) INT64_C(c) |
| 143 | # define UINTPTR_C(c) UINT64_C(c) |
| 144 | # define PTRDIFF_C(c) INT64_C(c) |
| 145 | #else |
| 146 | # define INT64_C(c) c ## LL |
| 147 | # define UINT64_C(c) c ## ULL |
| 148 | # define INTPTR_C(c) INT32_C(c) |
| 149 | # define UINTPTR_C(c) UINT32_C(c) |
| 150 | # define PTRDIFF_C(c) INT32_C(c) |
| 151 | #endif |
| 152 | |
| 153 | #define INT8_MIN (-128) |
| 154 | #define INT8_MAX (127) |
| 155 | #define INT_LEAST8_MIN INT8_MIN |
| 156 | #define INT_LEAST8_MAX INT8_MAX |
| 157 | #define INT_FAST8_MIN INT8_MIN |
| 158 | #define INT_FAST8_MAX INT8_MAX |
| 159 | |
| 160 | #define UINT8_MAX (255) |
| 161 | #define UINT_LEAST8_MAX UINT8_MAX |
| 162 | #define UINT_FAST8_MAX UINT8_MAX |
| 163 | |
| 164 | #define INT16_MIN (-32768) |
| 165 | #define INT16_MAX (32767) |
| 166 | #define INT_LEAST16_MIN INT16_MIN |
| 167 | #define INT_LEAST16_MAX INT16_MAX |
| 168 | #define INT_FAST16_MIN INT32_MIN |
| 169 | #define INT_FAST16_MAX INT32_MAX |
| 170 | |
| 171 | #define UINT16_MAX (65535) |
| 172 | #define UINT_LEAST16_MAX UINT16_MAX |
| 173 | #define UINT_FAST16_MAX UINT32_MAX |
| 174 | |
| 175 | #define INT32_MIN (-2147483647-1) |
| 176 | #define INT32_MAX (2147483647) |
| 177 | #define INT_LEAST32_MIN INT32_MIN |
| 178 | #define INT_LEAST32_MAX INT32_MAX |
| 179 | #define INT_FAST32_MIN INT32_MIN |
| 180 | #define INT_FAST32_MAX INT32_MAX |
| 181 | |
| 182 | #define UINT32_MAX (4294967295U) |
| 183 | #define UINT_LEAST32_MAX UINT32_MAX |
| 184 | #define UINT_FAST32_MAX UINT32_MAX |
| 185 | |
| 186 | #define INT64_MIN (INT64_C(-9223372036854775807)-1) |
| 187 | #define INT64_MAX (INT64_C(9223372036854775807)) |
| 188 | #define INT_LEAST64_MIN INT64_MIN |
| 189 | #define INT_LEAST64_MAX INT64_MAX |
| 190 | #define INT_FAST64_MIN INT64_MIN |
| 191 | #define INT_FAST64_MAX INT64_MAX |
| 192 | #define UINT64_MAX (UINT64_C(18446744073709551615)) |
| 193 | |
| 194 | #define UINT_LEAST64_MAX UINT64_MAX |
| 195 | #define UINT_FAST64_MAX UINT64_MAX |
| 196 | |
| 197 | #define INTMAX_MIN INT64_MIN |
| 198 | #define INTMAX_MAX INT64_MAX |
| 199 | #define UINTMAX_MAX UINT64_MAX |
| 200 | |
| 201 | #define SIG_ATOMIC_MAX INT32_MAX |
| 202 | #define SIG_ATOMIC_MIN INT32_MIN |
| 203 | |
Elliott Hughes | 83c07b5 | 2014-04-21 18:09:46 -0700 | [diff] [blame] | 204 | #if defined(__WINT_UNSIGNED__) |
| 205 | # define WINT_MAX UINT32_MAX |
Dan Albert | ee7f1b5 | 2014-07-21 17:16:30 -0700 | [diff] [blame] | 206 | # define WINT_MIN 0 |
Elliott Hughes | 83c07b5 | 2014-04-21 18:09:46 -0700 | [diff] [blame] | 207 | #else |
| 208 | # define WINT_MAX INT32_MAX |
| 209 | # define WINT_MIN INT32_MIN |
Elliott Hughes | e2a292d | 2014-01-24 16:37:04 -0800 | [diff] [blame] | 210 | #endif |
| 211 | |
Elliott Hughes | 83c07b5 | 2014-04-21 18:09:46 -0700 | [diff] [blame] | 212 | #if defined(__LP64__) |
Elliott Hughes | e2a292d | 2014-01-24 16:37:04 -0800 | [diff] [blame] | 213 | # define INTPTR_MIN INT64_MIN |
| 214 | # define INTPTR_MAX INT64_MAX |
| 215 | # define UINTPTR_MAX UINT64_MAX |
| 216 | # define PTRDIFF_MIN INT64_MIN |
| 217 | # define PTRDIFF_MAX INT64_MAX |
| 218 | # define SIZE_MAX UINT64_MAX |
| 219 | #else |
| 220 | # define INTPTR_MIN INT32_MIN |
| 221 | # define INTPTR_MAX INT32_MAX |
| 222 | # define UINTPTR_MAX UINT32_MAX |
| 223 | # define PTRDIFF_MIN INT32_MIN |
| 224 | # define PTRDIFF_MAX INT32_MAX |
| 225 | # define SIZE_MAX UINT32_MAX |
| 226 | #endif |
| 227 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 228 | #endif /* _STDINT_H */ |