limits.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. /*
  17. * ISO C99 Standard: 7.10/5.2.4.2.1 Sizes of integer types <limits.h>
  18. */
  19. #ifndef _LIBC_LIMITS_H_
  20. #define _LIBC_LIMITS_H_ 1
  21. #include <features.h>
  22. /* Maximum length of any multibyte character in any locale.
  23. We define this value here since the gcc header does not define
  24. the correct value. */
  25. #define MB_LEN_MAX 16
  26. /* If we are not using GNU CC we have to define all the symbols ourself.
  27. Otherwise use gcc's definitions (see below). */
  28. #if !defined __GNUC__ || __GNUC__ < 2
  29. /* We only protect from multiple inclusion here, because all the other
  30. #include's protect themselves, and in GCC 2 we may #include_next through
  31. multiple copies of this file before we get to GCC's. */
  32. # ifndef _LIMITS_H
  33. # define _LIMITS_H 1
  34. #include <bits/wordsize.h>
  35. /* We don't have #include_next.
  36. Define ANSI <limits.h> for standard 32-bit words. */
  37. /* These assume 8-bit `char's, 16-bit `short int's,
  38. and 32-bit `int's and `long int's. */
  39. /* Number of bits in a `char'. */
  40. # define CHAR_BIT 8
  41. /* Minimum and maximum values a `signed char' can hold. */
  42. # define SCHAR_MIN (-128)
  43. # define SCHAR_MAX 127
  44. /* Maximum value an `unsigned char' can hold. (Minimum is 0.) */
  45. # define UCHAR_MAX 255
  46. /* Minimum and maximum values a `char' can hold. */
  47. # ifdef __CHAR_UNSIGNED__
  48. # define CHAR_MIN 0
  49. # define CHAR_MAX UCHAR_MAX
  50. # else
  51. # define CHAR_MIN SCHAR_MIN
  52. # define CHAR_MAX SCHAR_MAX
  53. # endif
  54. /* Minimum and maximum values a `signed short int' can hold. */
  55. # define SHRT_MIN (-32768)
  56. # define SHRT_MAX 32767
  57. /* Maximum value an `unsigned short int' can hold. (Minimum is 0.) */
  58. # define USHRT_MAX 65535
  59. /* Minimum and maximum values a `signed int' can hold. */
  60. # define INT_MIN (-INT_MAX - 1)
  61. # define INT_MAX 2147483647
  62. /* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
  63. # define UINT_MAX 4294967295U
  64. /* Minimum and maximum values a `signed long int' can hold. */
  65. # if __WORDSIZE == 64
  66. # define LONG_MAX 9223372036854775807L
  67. # else
  68. # define LONG_MAX 2147483647L
  69. # endif
  70. # define LONG_MIN (-LONG_MAX - 1L)
  71. /* Maximum value an `unsigned long int' can hold. (Minimum is 0.) */
  72. # if __WORDSIZE == 64
  73. # define ULONG_MAX 18446744073709551615UL
  74. # else
  75. # define ULONG_MAX 4294967295UL
  76. # endif
  77. # ifdef __USE_ISOC99
  78. /* Minimum and maximum values a `signed long long int' can hold. */
  79. # define LLONG_MAX 9223372036854775807LL
  80. # define LLONG_MIN (-LLONG_MAX - 1LL)
  81. /* Maximum value an `unsigned long long int' can hold. (Minimum is 0.) */
  82. # define ULLONG_MAX 18446744073709551615ULL
  83. # endif /* ISO C99 */
  84. # endif /* limits.h */
  85. #endif /* GCC 2. */
  86. #endif /* !_LIBC_LIMITS_H_ */
  87. /* Get the compiler's limits.h, which defines almost all the ISO constants.
  88. We put this #include_next outside the double inclusion check because
  89. it should be possible to include this file more than once and still get
  90. the definitions from gcc's header. */
  91. #if defined __GNUC__ && !defined _GCC_LIMITS_H_
  92. /* `_GCC_LIMITS_H_' is what GCC's file defines. */
  93. # include_next <limits.h>
  94. #endif
  95. /* The <limits.h> files in some gcc versions don't define LLONG_MIN,
  96. LLONG_MAX, and ULLONG_MAX. Instead only the values gcc defined for
  97. ages are available. */
  98. #if defined __USE_ISOC99 && defined __GNUC__
  99. # ifndef LLONG_MIN
  100. # define LLONG_MIN (-LLONG_MAX-1)
  101. # endif
  102. # ifndef LLONG_MAX
  103. # define LLONG_MAX __LONG_LONG_MAX__
  104. # endif
  105. # ifndef ULLONG_MAX
  106. # define ULLONG_MAX (LLONG_MAX * 2ULL + 1)
  107. # endif
  108. #endif
  109. #ifdef __USE_POSIX
  110. /* POSIX adds things to <limits.h>. */
  111. # include <bits/posix1_lim.h>
  112. #endif
  113. #ifdef __USE_POSIX2
  114. # include <bits/posix2_lim.h>
  115. #endif
  116. #ifdef __USE_XOPEN
  117. # include <bits/xopen_lim.h>
  118. #endif