limits.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* Copyright (C) 1991-2016 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. /*
  15. * ISO C99 Standard: 7.10/5.2.4.2.1 Sizes of integer types <limits.h>
  16. */
  17. #ifndef _LIBC_LIMITS_H_
  18. #define _LIBC_LIMITS_H_ 1
  19. #include <features.h>
  20. /* Maximum length of any multibyte character in any locale.
  21. We define this value here since the gcc header does not define
  22. the correct value. */
  23. #define MB_LEN_MAX 16
  24. /* If we are not using GNU CC we have to define all the symbols ourself.
  25. Otherwise use gcc's definitions (see below). */
  26. #if !defined __GNUC__ || __GNUC__ < 2
  27. /* We only protect from multiple inclusion here, because all the other
  28. #include's protect themselves, and in GCC 2 we may #include_next through
  29. multiple copies of this file before we get to GCC's. */
  30. # ifndef _LIMITS_H
  31. # define _LIMITS_H 1
  32. #include <bits/wordsize.h>
  33. /* We don't have #include_next.
  34. Define ANSI <limits.h> for standard 32-bit words. */
  35. /* These assume 8-bit `char's, 16-bit `short int's,
  36. and 32-bit `int's and `long int's. */
  37. /* Number of bits in a `char'. */
  38. # define CHAR_BIT 8
  39. /* Minimum and maximum values a `signed char' can hold. */
  40. # define SCHAR_MIN (-128)
  41. # define SCHAR_MAX 127
  42. /* Maximum value an `unsigned char' can hold. (Minimum is 0.) */
  43. # define UCHAR_MAX 255
  44. /* Minimum and maximum values a `char' can hold. */
  45. # ifdef __CHAR_UNSIGNED__
  46. # define CHAR_MIN 0
  47. # define CHAR_MAX UCHAR_MAX
  48. # else
  49. # define CHAR_MIN SCHAR_MIN
  50. # define CHAR_MAX SCHAR_MAX
  51. # endif
  52. /* Minimum and maximum values a `signed short int' can hold. */
  53. # define SHRT_MIN (-32768)
  54. # define SHRT_MAX 32767
  55. /* Maximum value an `unsigned short int' can hold. (Minimum is 0.) */
  56. # define USHRT_MAX 65535
  57. /* Minimum and maximum values a `signed int' can hold. */
  58. # define INT_MIN (-INT_MAX - 1)
  59. # define INT_MAX 2147483647
  60. /* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
  61. # define UINT_MAX 4294967295U
  62. /* Minimum and maximum values a `signed long int' can hold. */
  63. # if __WORDSIZE == 64
  64. # define LONG_MAX 9223372036854775807L
  65. # else
  66. # define LONG_MAX 2147483647L
  67. # endif
  68. # define LONG_MIN (-LONG_MAX - 1L)
  69. /* Maximum value an `unsigned long int' can hold. (Minimum is 0.) */
  70. # if __WORDSIZE == 64
  71. # define ULONG_MAX 18446744073709551615UL
  72. # else
  73. # define ULONG_MAX 4294967295UL
  74. # endif
  75. # ifdef __USE_ISOC99
  76. /* Minimum and maximum values a `signed long long int' can hold. */
  77. # define LLONG_MAX 9223372036854775807LL
  78. # define LLONG_MIN (-LLONG_MAX - 1LL)
  79. /* Maximum value an `unsigned long long int' can hold. (Minimum is 0.) */
  80. # define ULLONG_MAX 18446744073709551615ULL
  81. # endif /* ISO C99 */
  82. # endif /* limits.h */
  83. #endif /* GCC 2. */
  84. #endif /* !_LIBC_LIMITS_H_ */
  85. /* Get the compiler's limits.h, which defines almost all the ISO constants.
  86. We put this #include_next outside the double inclusion check because
  87. it should be possible to include this file more than once and still get
  88. the definitions from gcc's header. */
  89. #if defined __GNUC__ && !defined _GCC_LIMITS_H_
  90. /* `_GCC_LIMITS_H_' is what GCC's file defines. */
  91. # include_next <limits.h>
  92. #endif
  93. /* The <limits.h> files in some gcc versions don't define LLONG_MIN,
  94. LLONG_MAX, and ULLONG_MAX. Instead only the values gcc defined for
  95. ages are available. */
  96. #if defined __USE_ISOC99 && defined __GNUC__
  97. # ifndef LLONG_MIN
  98. # define LLONG_MIN (-LLONG_MAX-1)
  99. # endif
  100. # ifndef LLONG_MAX
  101. # define LLONG_MAX __LONG_LONG_MAX__
  102. # endif
  103. # ifndef ULLONG_MAX
  104. # define ULLONG_MAX (LLONG_MAX * 2ULL + 1)
  105. # endif
  106. #endif
  107. #ifdef __USE_POSIX
  108. /* POSIX adds things to <limits.h>. */
  109. # include <bits/posix1_lim.h>
  110. #endif
  111. #ifdef __USE_POSIX2
  112. # include <bits/posix2_lim.h>
  113. #endif
  114. #ifdef __USE_XOPEN
  115. # include <bits/xopen_lim.h>
  116. #endif