limits.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Copyright (C) 1991-2026 Free Software Foundation, Inc.
  17. This file is part of the GNU C Library.
  18. The GNU C Library is free software; you can redistribute it and/or
  19. modify it under the terms of the GNU Lesser General Public
  20. License as published by the Free Software Foundation; either
  21. version 2.1 of the License, or (at your option) any later version.
  22. The GNU C Library is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. Lesser General Public License for more details.
  26. You should have received a copy of the GNU Lesser General Public
  27. License along with the GNU C Library; if not, see
  28. <https://www.gnu.org/licenses/>. */
  29. /*
  30. * ISO C99 Standard: 7.10/5.2.4.2.1 Sizes of integer types <limits.h>
  31. */
  32. #ifndef _LIBC_LIMITS_H_
  33. #define _LIBC_LIMITS_H_ 1
  34. #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
  35. #include <bits/libc-header-start.h>
  36. /* Maximum length of any multibyte character in any locale.
  37. We define this value here since the gcc header does not define
  38. the correct value. */
  39. #define MB_LEN_MAX 16
  40. /* If we are not using GNU CC we have to define all the symbols ourself.
  41. Otherwise use gcc's definitions (see below). */
  42. #if !defined __GNUC__ || __GNUC__ < 2
  43. /* We only protect from multiple inclusion here, because all the other
  44. #include's protect themselves, and in GCC 2 we may #include_next through
  45. multiple copies of this file before we get to GCC's. */
  46. # ifndef _LIMITS_H
  47. # define _LIMITS_H 1
  48. #include <bits/wordsize.h>
  49. /* We don't have #include_next.
  50. Define ANSI <limits.h> for standard 32-bit words. */
  51. /* These assume 8-bit `char's, 16-bit `short int's,
  52. and 32-bit `int's and `long int's. */
  53. /* Number of bits in a `char'. */
  54. # define CHAR_BIT 8
  55. /* Minimum and maximum values a `signed char' can hold. */
  56. # define SCHAR_MIN (-128)
  57. # define SCHAR_MAX 127
  58. /* Maximum value an `unsigned char' can hold. (Minimum is 0.) */
  59. # define UCHAR_MAX 255
  60. /* Minimum and maximum values a `char' can hold. */
  61. # ifdef __CHAR_UNSIGNED__
  62. # define CHAR_MIN 0
  63. # define CHAR_MAX UCHAR_MAX
  64. # else
  65. # define CHAR_MIN SCHAR_MIN
  66. # define CHAR_MAX SCHAR_MAX
  67. # endif
  68. /* Minimum and maximum values a `signed short int' can hold. */
  69. # define SHRT_MIN (-32768)
  70. # define SHRT_MAX 32767
  71. /* Maximum value an `unsigned short int' can hold. (Minimum is 0.) */
  72. # define USHRT_MAX 65535
  73. /* Minimum and maximum values a `signed int' can hold. */
  74. # define INT_MIN (-INT_MAX - 1)
  75. # define INT_MAX 2147483647
  76. /* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
  77. # define UINT_MAX 4294967295U
  78. /* Minimum and maximum values a `signed long int' can hold. */
  79. # if __WORDSIZE == 64
  80. # define LONG_MAX 9223372036854775807L
  81. # else
  82. # define LONG_MAX 2147483647L
  83. # endif
  84. # define LONG_MIN (-LONG_MAX - 1L)
  85. /* Maximum value an `unsigned long int' can hold. (Minimum is 0.) */
  86. # if __WORDSIZE == 64
  87. # define ULONG_MAX 18446744073709551615UL
  88. # else
  89. # define ULONG_MAX 4294967295UL
  90. # endif
  91. # ifdef __USE_ISOC99
  92. /* Minimum and maximum values a `signed long long int' can hold. */
  93. # define LLONG_MAX 9223372036854775807LL
  94. # define LLONG_MIN (-LLONG_MAX - 1LL)
  95. /* Maximum value an `unsigned long long int' can hold. (Minimum is 0.) */
  96. # define ULLONG_MAX 18446744073709551615ULL
  97. # endif /* ISO C99 */
  98. # endif /* limits.h */
  99. #endif /* GCC 2. */
  100. #endif /* !_LIBC_LIMITS_H_ */
  101. /* Get the compiler's limits.h, which defines almost all the ISO constants.
  102. We put this #include_next outside the double inclusion check because
  103. it should be possible to include this file more than once and still get
  104. the definitions from gcc's header. */
  105. #if defined __GNUC__ && !defined _GCC_LIMITS_H_
  106. /* `_GCC_LIMITS_H_' is what GCC's file defines. */
  107. # include_next <limits.h>
  108. #endif
  109. /* The <limits.h> files in some gcc versions don't define LLONG_MIN,
  110. LLONG_MAX, and ULLONG_MAX. Instead only the values gcc defined for
  111. ages are available. */
  112. #if defined __USE_ISOC99 && defined __GNUC__
  113. # ifndef LLONG_MIN
  114. # define LLONG_MIN (-LLONG_MAX-1)
  115. # endif
  116. # ifndef LLONG_MAX
  117. # define LLONG_MAX __LONG_LONG_MAX__
  118. # endif
  119. # ifndef ULLONG_MAX
  120. # define ULLONG_MAX (LLONG_MAX * 2ULL + 1)
  121. # endif
  122. #endif
  123. /* The integer width macros are not defined by GCC's <limits.h> before
  124. GCC 7, or if _GNU_SOURCE rather than
  125. __STDC_WANT_IEC_60559_BFP_EXT__ is used to enable this feature. */
  126. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23)
  127. # ifndef CHAR_WIDTH
  128. # define CHAR_WIDTH 8
  129. # endif
  130. # ifndef SCHAR_WIDTH
  131. # define SCHAR_WIDTH 8
  132. # endif
  133. # ifndef UCHAR_WIDTH
  134. # define UCHAR_WIDTH 8
  135. # endif
  136. # ifndef SHRT_WIDTH
  137. # define SHRT_WIDTH 16
  138. # endif
  139. # ifndef USHRT_WIDTH
  140. # define USHRT_WIDTH 16
  141. # endif
  142. # ifndef INT_WIDTH
  143. # define INT_WIDTH 32
  144. # endif
  145. # ifndef UINT_WIDTH
  146. # define UINT_WIDTH 32
  147. # endif
  148. # ifndef LONG_WIDTH
  149. # define LONG_WIDTH __WORDSIZE
  150. # endif
  151. # ifndef ULONG_WIDTH
  152. # define ULONG_WIDTH __WORDSIZE
  153. # endif
  154. # ifndef LLONG_WIDTH
  155. # define LLONG_WIDTH 64
  156. # endif
  157. # ifndef ULLONG_WIDTH
  158. # define ULLONG_WIDTH 64
  159. # endif
  160. #endif /* Use IEC_60559_BFP_EXT. */
  161. /* The macros for _Bool are not defined by GCC's <limits.h> before GCC
  162. 11, or if _GNU_SOURCE is defined rather than enabling C23 support
  163. with -std; likewise for the version macro before GCC 13. */
  164. #if __GLIBC_USE (ISOC23)
  165. # ifndef BOOL_MAX
  166. # define BOOL_MAX 1
  167. # endif
  168. # ifndef BOOL_WIDTH
  169. # define BOOL_WIDTH 1
  170. # endif
  171. # ifndef __STDC_VERSION_LIMITS_H__
  172. # define __STDC_VERSION_LIMITS_H__ 202311L
  173. # endif
  174. #endif
  175. #ifdef __USE_POSIX
  176. /* POSIX adds things to <limits.h>. */
  177. # include <bits/posix1_lim.h>
  178. #endif
  179. #ifdef __USE_POSIX2
  180. # include <bits/posix2_lim.h>
  181. #endif
  182. #ifdef __USE_XOPEN
  183. # include <bits/xopen_lim.h>
  184. #endif