backport.h
| 1 | #ifndef CUTILS_BACKPORT_H |
| 2 | #define CUTILS_BACKPORT_H |
| 3 | |
| 4 | #include <limits.h> |
| 5 | #if __STDC_VERSION__ >= 199901L |
| 6 | #include <stdint.h> |
| 7 | #include <stdbool.h> |
| 8 | #else |
| 9 | |
| 10 | #ifndef SIZE_MAX |
| 11 | #define SIZE_MAX ((size_t)-1) |
| 12 | #endif /* SIZE_MAX */ |
| 13 | |
| 14 | #ifndef CUTILS_NO_BOOL |
| 15 | typedef enum {false = 0, true = !false} bool; |
| 16 | #endif /* CUTILS_NO_BOOL */ |
| 17 | |
| 18 | #ifndef CUTILS_NO_MAX |
| 19 | #ifdef ULLONG_MAX |
| 20 | #define UINTMAX_MAX ULLONG_MAX |
| 21 | typedef unsigned long long uintmax_t; |
| 22 | #else |
| 23 | #define UINTMAX_MAX ULONG_MAX |
| 24 | typedef unsigned long uintmax_t; |
| 25 | #endif |
| 26 | #ifdef LLONG_MAX |
| 27 | #define INTMAX_MAX LLONG_MAX |
| 28 | #define INTMAX_MIN LLONG_MIN |
| 29 | typedef long long intmax_t; |
| 30 | #else |
| 31 | #define INTMAX_MAX LONG_MAX |
| 32 | #define INTMAX_MIN LONG_MIN |
| 33 | typedef long intmax_t; |
| 34 | #endif |
| 35 | #endif /* CUTILS_NO_MAX */ |
| 36 | |
| 37 | #ifndef CUTILS_NO_LEAST |
| 38 | #define UINTLEAST8_MAX UCHAR_MAX |
| 39 | typedef unsigned char uint_least8_t; |
| 40 | #define UINT8_C(x) ((uint_least8_t)x) |
| 41 | |
| 42 | #define UINTLEAST16_MAX USHRT_MAX |
| 43 | typedef unsigned short uint_least16_t; |
| 44 | #define UINT16_C(x) ((uint_least16_t)x) |
| 45 | |
| 46 | #define UINTLEAST32_MAX ULONG_MAX |
| 47 | typedef unsigned long uint_least32_t; |
| 48 | #define UINT32_C(x) ((uint_least32_t)x) |
| 49 | |
| 50 | #ifdef ULLONG_MAX |
| 51 | #define UINTLEAST64_MAX ULLONG_MAX |
| 52 | typedef unsigned long long uint_least64_t; |
| 53 | #define UINT64_C(x) ((uint_least64_t)x) |
| 54 | #endif /* ULLONG_MAX */ |
| 55 | |
| 56 | |
| 57 | #define INTLEAST8_MAX SCHAR_MAX |
| 58 | #define INTLEAST8_MIN SCHAR_MIN |
| 59 | typedef signed char int_least8_t; |
| 60 | #define INT8_C(x) ((int_least8_t)x) |
| 61 | |
| 62 | #define INTLEAST16_MAX SHRT_MAX |
| 63 | #define INTLEAST16_MIN SHRT_MIN |
| 64 | typedef short int_least16_t; |
| 65 | #define INT16_C(x) ((int_least16_t)x) |
| 66 | |
| 67 | #define INTLEAST32_MAX LONG_MAX |
| 68 | #define INTLEAST32_MIN LONG_MIN |
| 69 | typedef long int_least32_t; |
| 70 | #define INT32_C(x) ((int_least32_t)x) |
| 71 | |
| 72 | #ifdef LLONG_MAX |
| 73 | #define INTLEAST64_MAX LLONG_MAX |
| 74 | #define INTLEAST64_MIN LLONG_MIN |
| 75 | typedef long long int_least64_t; |
| 76 | #define INT64_C(x) ((int_least64_t)x) |
| 77 | #endif /* LLONG_MAX */ |
| 78 | #endif /* CUTILS_NO_LEAST */ |
| 79 | |
| 80 | /* for now just copy least types */ |
| 81 | #ifndef CUTILS_NO_FAST |
| 82 | #define UINTFAST8_MAX UCHAR_MAX |
| 83 | typedef unsigned char uint_fast8_t; |
| 84 | |
| 85 | #define UINTFAST16_MAX USHRT_MAX |
| 86 | typedef unsigned short uint_fast16_t; |
| 87 | |
| 88 | #define UINTFAST32_MAX ULONG_MAX |
| 89 | typedef unsigned long uint_fast32_t; |
| 90 | |
| 91 | #ifdef ULLONG_MAX |
| 92 | #define UINTFAST64_MAX ULLONG_MAX |
| 93 | typedef unsigned long long uint_fast64_t; |
| 94 | #endif /* ULLONG_MAX */ |
| 95 | |
| 96 | |
| 97 | #define INTFAST8_MAX SCHAR_MAX |
| 98 | #define INTFAST8_MIN SCHAR_MIN |
| 99 | typedef signed char int_fast8_t; |
| 100 | |
| 101 | #define INTFAST16_MAX SHRT_MAX |
| 102 | #define INTFAST16_MIN SHRT_MIN |
| 103 | typedef short int_fast16_t; |
| 104 | |
| 105 | #define INTFAST32_MAX LONG_MAX |
| 106 | #define INTFAST32_MIN LONG_MIN |
| 107 | typedef long int_fast32_t; |
| 108 | |
| 109 | #ifdef LLONG_MAX |
| 110 | #define INTFAST64_MAX LLONG_MAX |
| 111 | #define INTFAST64_MIN LLONG_MIN |
| 112 | typedef long long int_fast64_t; |
| 113 | #endif /* LLONG_MAX */ |
| 114 | #endif /* CUTILS_NO_FAST */ |
| 115 | |
| 116 | #endif |
| 117 | |
| 118 | |
| 119 | #endif /* CUTILS_BACKPORT_H */ |
| 120 |