Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 2 | |
| 3 | #ifndef STDINT_H |
| 4 | #define STDINT_H |
| 5 | |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 6 | /* Fixed width integer types */ |
| 7 | typedef signed char int8_t; |
| 8 | typedef unsigned char uint8_t; |
| 9 | |
| 10 | typedef signed short int16_t; |
| 11 | typedef unsigned short uint16_t; |
| 12 | |
| 13 | typedef signed int int32_t; |
| 14 | typedef unsigned int uint32_t; |
| 15 | |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 16 | typedef signed long long int64_t; |
| 17 | typedef unsigned long long uint64_t; |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 18 | |
| 19 | /* Types for 'void *' pointers */ |
| 20 | typedef signed long intptr_t; |
| 21 | typedef unsigned long uintptr_t; |
| 22 | |
| 23 | /* Ensure that the widths are all correct */ |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 24 | _Static_assert(sizeof(int8_t) == 1, "Size of int8_t is incorrect"); |
| 25 | _Static_assert(sizeof(uint8_t) == 1, "Size of uint8_t is incorrect"); |
| 26 | |
| 27 | _Static_assert(sizeof(int16_t) == 2, "Size of int16_t is incorrect"); |
| 28 | _Static_assert(sizeof(uint16_t) == 2, "Size of uint16_t is incorrect"); |
| 29 | |
| 30 | _Static_assert(sizeof(int32_t) == 4, "Size of int32_t is incorrect"); |
| 31 | _Static_assert(sizeof(uint32_t) == 4, "Size of uint32_t is incorrect"); |
| 32 | |
| 33 | _Static_assert(sizeof(int64_t) == 8, "Size of int64_t is incorrect"); |
| 34 | _Static_assert(sizeof(uint64_t) == 8, "Size of uint64_t is incorrect"); |
| 35 | |
| 36 | _Static_assert(sizeof(intptr_t) == sizeof(void *), "Size of intptr_t is incorrect"); |
| 37 | _Static_assert(sizeof(uintptr_t) == sizeof(void *), "Size of uintptr_t is incorrect"); |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 38 | |
| 39 | /* Maximum width integer types */ |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 40 | typedef int64_t intmax_t; |
| 41 | typedef uint64_t uintmax_t; |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 42 | |
| 43 | /* Convenient typedefs */ |
| 44 | typedef int8_t s8; |
| 45 | typedef uint8_t u8; |
| 46 | |
| 47 | typedef int16_t s16; |
| 48 | typedef uint16_t u16; |
| 49 | |
| 50 | typedef int32_t s32; |
| 51 | typedef uint32_t u32; |
| 52 | |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 53 | typedef int64_t s64; |
| 54 | typedef uint64_t u64; |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 55 | |
| 56 | /* Limits of integer types */ |
| 57 | #define INT8_MIN ((int8_t)0x80) |
| 58 | #define INT8_MAX ((int8_t)0x7F) |
| 59 | #define UINT8_MAX ((uint8_t)0xFF) |
| 60 | |
| 61 | #define INT16_MIN ((int16_t)0x8000) |
| 62 | #define INT16_MAX ((int16_t)0x7FFF) |
| 63 | #define UINT16_MAX ((uint16_t)0xFFFF) |
| 64 | |
| 65 | #define INT32_MIN ((int32_t)0x80000000) |
| 66 | #define INT32_MAX ((int32_t)0x7FFFFFFF) |
| 67 | #define UINT32_MAX ((uint32_t)0xFFFFFFFF) |
| 68 | |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 69 | #define INT64_MIN ((int64_t)0x8000000000000000) |
| 70 | #define INT64_MAX ((int64_t)0x7FFFFFFFFFFFFFFF) |
| 71 | #define UINT64_MAX ((uint64_t)0xFFFFFFFFFFFFFFFF) |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 72 | |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 73 | #define INTMAX_MIN INT64_MIN |
| 74 | #define INTMAX_MAX INT64_MAX |
| 75 | #define UINTMAX_MAX UINT64_MAX |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 76 | |
Jacob Garber | 0c4ed4b | 2019-07-04 12:55:35 -0600 | [diff] [blame] | 77 | #endif /* STDINT_H */ |