stdint.h (3102B)
1 /* -*-comment-start: "//";comment-end:""-*- 2 * GNU Mes --- Maxwell Equations of Software 3 * Copyright © 2017,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> 4 * Copyright © 2018 Peter De Wachter <pdewacht@gmail.com> 5 * Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech> 6 * 7 * This file is part of GNU Mes. 8 * 9 * GNU Mes is free software; you can redistribute it and/or modify it 10 * under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 3 of the License, or (at 12 * your option) any later version. 13 * 14 * GNU Mes is distributed in the hope that it will be useful, but 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 #ifndef __MES_STDINT_H 23 #define __MES_STDINT_H 1 24 25 #if SYSTEM_LIBC 26 #ifndef _GNU_SOURCE 27 #define _GNU_SOURCE 28 #endif 29 #undef __MES_STDINT_H 30 #include_next <stdint.h> 31 32 #else // ! SYSTEM_LIBC 33 34 #undef unsigned 35 #undef uint8_t 36 #undef int8_t 37 38 #undef uint16_t 39 #undef int16_t 40 41 #undef uint32_t 42 #undef int32_t 43 44 #undef uint64_t 45 #undef int64_t 46 47 #undef uintptr_t 48 #undef intmax_t 49 #undef intptr_t 50 #undef uintmax_t 51 #undef ptrdiff_t 52 53 typedef unsigned char uint8_t; 54 typedef signed char int8_t; 55 typedef unsigned short uint16_t; 56 typedef short int16_t; 57 typedef unsigned uint32_t; 58 typedef int int32_t; 59 #if __SIZEOF_LONG_LONG__ == 8 60 typedef unsigned long long uint64_t; 61 typedef long long int64_t; 62 #endif // __SIZEOF_LONG_LONG__ == 8 63 64 #if __i386__ || __arm__ || __riscv_xlen == 32 65 typedef int intmax_t; 66 typedef unsigned uintmax_t; 67 #elif __x86_64__ || __riscv_xlen == 64 68 typedef long intmax_t; 69 typedef unsigned long uintmax_t; 70 #endif 71 72 #include <sys/types.h> 73 74 #define CHAR_BIT 8 75 #define SCHAR_MIN (-128) 76 #define SCHAR_MAX 127 77 #define UCHAR_MAX 255 78 79 /* Check if we are in signed or unsigned char case */ 80 #if '\xff' > 0 81 #define CHAR_MIN 0 82 #define CHAR_MAX UCHAR_MAX 83 #else 84 #define CHAR_MIN SCHAR_MIN 85 #define CHAR_MAX SCHAR_MAX 86 #endif 87 88 #define INT8_MAX 127 89 #define INT8_MIN (-INT8_MAX-1) 90 #define UINT8_MAX 255 91 92 #define INT16_MAX 32767 93 #define INT16_MIN (-INT16_MAX-1) 94 #define UINT16_MAX 65535 95 96 #define INT32_MAX 2147483647 97 #define INT32_MIN (-INT32_MAX-1) 98 #define UINT32_MAX 4294967295U 99 100 #define INT64_MAX 9223372036854775807LL 101 #define INT64_MIN (-INT64_MAX-1) 102 #define UINT64_MAX 18446744073709551615ULL 103 104 #define INT_MIN -2147483648 105 #define INT_MAX 2147483647 106 #if __i386__ || __arm__ || __riscv_xlen == 32 107 #define LONG_MIN INT_MIN 108 #define LONG_MAX INT_MAX 109 #define UINT_MAX UINT32_MAX 110 #define ULONG_MAX UINT32_MAX 111 #define LLONG_MIN INT64_MIN 112 #define LLONG_MAX INT64_MAX 113 #define SIZE_MAX UINT32_MAX 114 #elif __x86_64__ || __riscv_xlen == 64 115 #define LONG_MIN INT64_MIN 116 #define LONG_MAX INT64_MAX 117 #define UINT_MAX UINT32_MAX 118 #define ULONG_MAX UINT64_MAX 119 #define LLONG_MIN INT64_MIN 120 #define LLONG_MAX INT64_MAX 121 #define SIZE_MAX UINT64_MAX 122 #endif 123 124 #endif // ! SYSTEM_LIBC 125 126 #endif // __MES_STDINT_H