limits.h 4.4 KB

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