1 //===-- Definition of macros from limits.h --------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_MACROS_LIMITS_MACROS_H
10 #define LLVM_LIBC_MACROS_LIMITS_MACROS_H
12 // Define all C23 macro constants of limits.h
16 #define CHAR_BIT __CHAR_BIT__
19 #endif // __CHAR_BIT__
23 // Represents a single UTF-32 wide character in the default locale.
30 #define CHAR_WIDTH CHAR_BIT
34 #define SCHAR_WIDTH CHAR_BIT
38 #define UCHAR_WIDTH CHAR_BIT
43 #define SHRT_WIDTH __SHRT_WIDTH__
46 #endif // __SHRT_WIDTH__
50 #define USHRT_WIDTH SHRT_WIDTH
55 #define INT_WIDTH __INT_WIDTH__
58 #endif // __INT_WIDTH__
62 #define UINT_WIDTH INT_WIDTH
67 #define LONG_WIDTH __LONG_WIDTH__
68 #elif defined(__WORDSIZE)
69 #define LONG_WIDTH __WORDSIZE
71 // Use __SIZEOF_LONG__ * CHAR_BIT as backup. This is needed for clang-13 or
73 #define LONG_WIDTH (__SIZEOF_LONG__ * CHAR_BIT)
74 #endif // __LONG_WIDTH__
78 #define ULONG_WIDTH LONG_WIDTH
82 #ifdef __LLONG_WIDTH__
83 #define LLONG_WIDTH __LLONG_WIDTH__
85 #define LLONG_WIDTH 64
86 #endif // __LLONG_WIDTH__
90 #define ULLONG_WIDTH LLONG_WIDTH
91 #endif // ULLONG_WIDTH
95 #define BOOL_WIDTH __BOOL_WIDTH__
98 #endif // __BOOL_WIDTH__
105 #define SCHAR_MAX __SCHAR_MAX__
107 #define SCHAR_MAX 0x7f
108 #endif // __SCHAR_MAX__
112 #define UCHAR_MAX (SCHAR_MAX * 2 + 1)
115 // Check if char is unsigned.
116 #if !defined(__CHAR_UNSIGNED__) && ('\xff' > 0)
117 #define __CHAR_UNSIGNED__
121 #ifdef __CHAR_UNSIGNED__
122 #define CHAR_MAX UCHAR_MAX
124 #define CHAR_MAX SCHAR_MAX
125 #endif // __CHAR_UNSIGNED__
130 #define SHRT_MAX __SHRT_MAX__
132 #define SHRT_MAX 0x7fff
133 #endif // __SHRT_MAX__
137 #define USHRT_MAX (SHRT_MAX * 2U + 1U)
142 #define INT_MAX __INT_MAX__
144 #define INT_MAX (0 ^ (1 << (INT_WIDTH - 1)))
145 #endif // __INT_MAX__
149 #define UINT_MAX (INT_MAX * 2U + 1U)
154 #define LONG_MAX __LONG_MAX__
156 #define LONG_MAX (0L ^ (1L << (LONG_WIDTH - 1)))
157 #endif // __LONG_MAX__
161 #define ULONG_MAX (LONG_MAX * 2UL + 1UL)
165 #ifdef __LONG_LONG_MAX__
166 #define LLONG_MAX __LONG_LONG_MAX__
168 #define LLONG_MAX (0LL ^ (1LL << (LLONG_WIDTH - 1)))
169 #endif // __LONG_LONG_MAX__
173 #define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
179 #define SCHAR_MIN (-SCHAR_MAX - 1)
187 #ifdef __CHAR_UNSIGNED__
188 #define CHAR_MIN UCHAR_MIN
190 #define CHAR_MIN SCHAR_MIN
191 #endif // __CHAR_UNSIGNED__
195 #define SHRT_MIN (-SHRT_MAX - 1)
203 #define INT_MIN (-INT_MAX - 1)
211 #define LONG_MIN (-LONG_MAX - 1L)
215 #define ULONG_MIN 0UL
219 #define LLONG_MIN (-LLONG_MAX - 1LL)
223 #define ULLONG_MIN 0ULL
226 #ifndef _POSIX_MAX_CANON
227 #define _POSIX_MAX_CANON 255
230 #ifndef _POSIX_MAX_INPUT
231 #define _POSIX_MAX_INPUT 255
234 #ifndef _POSIX_NAME_MAX
235 #define _POSIX_PATH_MAX 256
238 #endif // LLVM_LIBC_MACROS_LIMITS_MACROS_H