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 | */ |
| 28 | #ifndef _STDINT_H |
| 29 | #define _STDINT_H |
| 30 | |
| 31 | #include <stddef.h> |
| 32 | #include <sys/_types.h> |
| 33 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 34 | #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) |
| 35 | # define __STDINT_LIMITS |
| 36 | #endif |
| 37 | |
| 38 | #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) |
| 39 | # define __STDINT_MACROS |
| 40 | #endif |
| 41 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 42 | typedef __int8_t int8_t; |
| 43 | typedef __uint8_t uint8_t; |
| 44 | typedef __int16_t int16_t; |
| 45 | typedef __uint16_t uint16_t; |
| 46 | typedef __int32_t int32_t; |
| 47 | typedef __uint32_t uint32_t; |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 48 | typedef __int64_t int64_t; |
| 49 | typedef __uint64_t uint64_t; |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * int8_t & uint8_t |
| 53 | */ |
| 54 | |
| 55 | typedef int8_t int_least8_t; |
| 56 | typedef int8_t int_fast8_t; |
| 57 | |
| 58 | typedef uint8_t uint_least8_t; |
| 59 | typedef uint8_t uint_fast8_t; |
| 60 | |
| 61 | #ifdef __STDINT_LIMITS |
| 62 | # define INT8_MIN (-128) |
| 63 | # define INT8_MAX (127) |
| 64 | # define INT_LEAST8_MIN INT8_MIN |
| 65 | # define INT_LEAST8_MAX INT8_MAX |
| 66 | # define INT_FAST8_MIN INT8_MIN |
| 67 | # define INT_FAST8_MAX INT8_MAX |
| 68 | |
Sergey Melnikov | dc5d342 | 2012-11-22 15:23:48 +0400 | [diff] [blame] | 69 | # define UINT8_MAX (255) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 70 | # define UINT_LEAST8_MAX UINT8_MAX |
| 71 | # define UINT_FAST8_MAX UINT8_MAX |
| 72 | #endif |
| 73 | |
| 74 | #ifdef __STDINT_MACROS |
| 75 | # define INT8_C(c) c |
| 76 | # define INT_LEAST8_C(c) INT8_C(c) |
| 77 | # define INT_FAST8_C(c) INT8_C(c) |
| 78 | |
Sergey Melnikov | dc5d342 | 2012-11-22 15:23:48 +0400 | [diff] [blame] | 79 | # define UINT8_C(c) c |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 80 | # define UINT_LEAST8_C(c) UINT8_C(c) |
| 81 | # define UINT_FAST8_C(c) UINT8_C(c) |
| 82 | #endif |
| 83 | |
| 84 | /* |
| 85 | * int16_t & uint16_t |
| 86 | */ |
| 87 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 88 | typedef int16_t int_least16_t; |
| 89 | typedef int32_t int_fast16_t; |
| 90 | |
| 91 | typedef uint16_t uint_least16_t; |
| 92 | typedef uint32_t uint_fast16_t; |
| 93 | |
| 94 | #ifdef __STDINT_LIMITS |
| 95 | # define INT16_MIN (-32768) |
| 96 | # define INT16_MAX (32767) |
| 97 | # define INT_LEAST16_MIN INT16_MIN |
| 98 | # define INT_LEAST16_MAX INT16_MAX |
| 99 | # define INT_FAST16_MIN INT32_MIN |
| 100 | # define INT_FAST16_MAX INT32_MAX |
| 101 | |
Sergey Melnikov | dc5d342 | 2012-11-22 15:23:48 +0400 | [diff] [blame] | 102 | # define UINT16_MAX (65535) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 103 | # define UINT_LEAST16_MAX UINT16_MAX |
| 104 | # define UINT_FAST16_MAX UINT32_MAX |
| 105 | #endif |
| 106 | |
| 107 | #ifdef __STDINT_MACROS |
| 108 | # define INT16_C(c) c |
| 109 | # define INT_LEAST16_C(c) INT16_C(c) |
| 110 | # define INT_FAST16_C(c) INT32_C(c) |
| 111 | |
Sergey Melnikov | dc5d342 | 2012-11-22 15:23:48 +0400 | [diff] [blame] | 112 | # define UINT16_C(c) c |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 113 | # define UINT_LEAST16_C(c) UINT16_C(c) |
| 114 | # define UINT_FAST16_C(c) UINT32_C(c) |
| 115 | #endif |
| 116 | |
| 117 | /* |
| 118 | * int32_t & uint32_t |
| 119 | */ |
| 120 | |
| 121 | typedef int32_t int_least32_t; |
| 122 | typedef int32_t int_fast32_t; |
| 123 | |
| 124 | typedef uint32_t uint_least32_t; |
| 125 | typedef uint32_t uint_fast32_t; |
| 126 | |
| 127 | #ifdef __STDINT_LIMITS |
| 128 | # define INT32_MIN (-2147483647-1) |
| 129 | # define INT32_MAX (2147483647) |
| 130 | # define INT_LEAST32_MIN INT32_MIN |
| 131 | # define INT_LEAST32_MAX INT32_MAX |
| 132 | # define INT_FAST32_MIN INT32_MIN |
| 133 | # define INT_FAST32_MAX INT32_MAX |
| 134 | |
| 135 | # define UINT32_MAX (4294967295U) |
| 136 | # define UINT_LEAST32_MAX UINT32_MAX |
| 137 | # define UINT_FAST32_MAX UINT32_MAX |
| 138 | #endif |
| 139 | |
| 140 | #ifdef __STDINT_MACROS |
| 141 | # define INT32_C(c) c |
| 142 | # define INT_LEAST32_C(c) INT32_C(c) |
| 143 | # define INT_FAST32_C(c) INT32_C(c) |
| 144 | |
| 145 | # define UINT32_C(c) c ## U |
| 146 | # define UINT_LEAST32_C(c) UINT32_C(c) |
| 147 | # define UINT_FAST32_C(c) UINT32_C(c) |
| 148 | #endif |
| 149 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 150 | /* |
| 151 | * int64_t |
| 152 | */ |
Elliott Hughes | 6d6731a | 2012-08-17 14:30:06 -0700 | [diff] [blame] | 153 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 154 | typedef int64_t int_least64_t; |
| 155 | typedef int64_t int_fast64_t; |
| 156 | |
| 157 | typedef uint64_t uint_least64_t; |
| 158 | typedef uint64_t uint_fast64_t; |
| 159 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 160 | #ifdef __STDINT_LIMITS |
| 161 | # define INT64_MIN (__INT64_C(-9223372036854775807)-1) |
| 162 | # define INT64_MAX (__INT64_C(9223372036854775807)) |
| 163 | # define INT_LEAST64_MIN INT64_MIN |
| 164 | # define INT_LEAST64_MAX INT64_MAX |
| 165 | # define INT_FAST64_MIN INT64_MIN |
| 166 | # define INT_FAST64_MAX INT64_MAX |
| 167 | # define UINT64_MAX (__UINT64_C(18446744073709551615)) |
| 168 | |
| 169 | # define UINT_LEAST64_MAX UINT64_MAX |
| 170 | # define UINT_FAST64_MAX UINT64_MAX |
| 171 | #endif |
| 172 | |
David 'Digit' Turner | 8b3cea6 | 2011-03-11 14:39:05 +0100 | [diff] [blame] | 173 | #define __INT64_C(c) c ## LL |
| 174 | #define __UINT64_C(c) c ## ULL |
| 175 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 176 | #ifdef __STDINT_MACROS |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 177 | # define INT64_C(c) __INT64_C(c) |
| 178 | # define INT_LEAST64_C(c) INT64_C(c) |
| 179 | # define INT_FAST64_C(c) INT64_C(c) |
| 180 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 181 | # define UINT64_C(c) __UINT64_C(c) |
| 182 | # define UINT_LEAST64_C(c) UINT64_C(c) |
| 183 | # define UINT_FAST64_C(c) UINT64_C(c) |
| 184 | #endif |
| 185 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 186 | # define __PRI64_RANK "ll" |
| 187 | # define __PRIFAST_RANK "" |
| 188 | # define __PRIPTR_RANK "" |
| 189 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 190 | /* |
| 191 | * intptr_t & uintptr_t |
| 192 | */ |
| 193 | |
Pavel Chupin | 0a9c615 | 2012-12-18 17:25:01 +0400 | [diff] [blame^] | 194 | #ifdef __LP64__ |
| 195 | typedef long intptr_t; |
| 196 | typedef unsigned long uintptr_t; |
| 197 | #else |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 198 | typedef int intptr_t; |
| 199 | typedef unsigned int uintptr_t; |
Pavel Chupin | 0a9c615 | 2012-12-18 17:25:01 +0400 | [diff] [blame^] | 200 | #endif |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 201 | |
David 'Digit' Turner | 08ff1a6 | 2011-03-10 18:02:01 +0100 | [diff] [blame] | 202 | #ifdef __STDINT_LIMITS |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 203 | # define INTPTR_MIN INT32_MIN |
| 204 | # define INTPTR_MAX INT32_MAX |
| 205 | # define UINTPTR_MAX UINT32_MAX |
David 'Digit' Turner | 08ff1a6 | 2011-03-10 18:02:01 +0100 | [diff] [blame] | 206 | # define PTRDIFF_MIN INT32_MIN |
| 207 | # define PTRDIFF_MAX INT32_MAX |
| 208 | #endif |
| 209 | |
| 210 | #ifdef __STDINT_MACROS |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 211 | # define INTPTR_C(c) INT32_C(c) |
| 212 | # define UINTPTR_C(c) UINT32_C(c) |
| 213 | # define PTRDIFF_C(c) INT32_C(c) |
David 'Digit' Turner | 08ff1a6 | 2011-03-10 18:02:01 +0100 | [diff] [blame] | 214 | #endif |
| 215 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 216 | /* |
| 217 | * intmax_t & uintmax_t |
| 218 | */ |
| 219 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 220 | typedef uint64_t uintmax_t; |
| 221 | typedef int64_t intmax_t; |
| 222 | |
David 'Digit' Turner | 08ff1a6 | 2011-03-10 18:02:01 +0100 | [diff] [blame] | 223 | #ifdef __STDINT_LIMITS |
| 224 | # define INTMAX_MIN INT64_MIN |
| 225 | # define INTMAX_MAX INT64_MAX |
| 226 | # define UINTMAX_MAX UINT64_MAX |
| 227 | #endif |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 228 | |
David 'Digit' Turner | 0e5411b | 2011-03-10 20:34:23 +0100 | [diff] [blame] | 229 | #ifdef __STDINT_MACROS |
David 'Digit' Turner | 08ff1a6 | 2011-03-10 18:02:01 +0100 | [diff] [blame] | 230 | # define INTMAX_C(c) INT64_C(c) |
| 231 | # define UINTMAX_C(c) UINT64_C(c) |
| 232 | #endif |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 233 | |
Elliott Hughes | 7c89506 | 2013-06-13 16:02:53 -0700 | [diff] [blame] | 234 | /* |
| 235 | * sig_atomic_t, size_t, wchar_t, and wint_t. |
| 236 | */ |
| 237 | |
| 238 | #ifdef __STDINT_LIMITS |
| 239 | # define SIG_ATOMIC_MAX INT32_MAX |
| 240 | # define SIG_ATOMIC_MIN INT32_MIN |
| 241 | |
| 242 | # define SIZE_MAX UINT32_MAX |
| 243 | |
| 244 | # ifndef WCHAR_MAX /* These might also have been defined by <wchar.h>. */ |
| 245 | # define WCHAR_MAX INT32_MAX |
| 246 | # define WCHAR_MIN INT32_MIN |
| 247 | # endif |
| 248 | |
| 249 | # define WINT_MAX INT32_MAX |
| 250 | # define WINT_MIN INT32_MIN |
| 251 | #endif |
| 252 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 253 | #define _BITSIZE 32 |
| 254 | |
| 255 | /* Keep the kernel from trying to define these types... */ |
| 256 | #define __BIT_TYPES_DEFINED__ |
| 257 | |
| 258 | #endif /* _STDINT_H */ |