xref: /titanic_52/usr/src/uts/common/sys/int_limits.h (revision 0a0e9771ca0211c15f3ac4466b661c145feeb9e4)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_INT_LIMITS_H
28 #define	_SYS_INT_LIMITS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * This file, <sys/int_limits.h>, is part of the Sun Microsystems implementation
34  * of <inttypes.h> as defined in the ISO C standard, ISO/IEC 9899:1999
35  * Programming language - C.
36  *
37  * Programs/Modules should not directly include this file.  Access to the
38  * types defined in this file should be through the inclusion of one of the
39  * following files:
40  *
41  *	<limits.h>		This nested inclusion is disabled for strictly
42  *				ANSI-C conforming compilations.  The *_MIN
43  *				definitions are not visible to POSIX or XPG
44  *				conforming applications (due to what may be
45  *				a bug in the specification - this is under
46  *				investigation)
47  *
48  *	<sys/inttypes.h>	Provides the Kernel and Driver appropriate
49  *				components of <inttypes.h>.
50  *
51  *	<inttypes.h>		For use by applications.
52  *
53  * See these files for more details.
54  */
55 
56 #include <sys/feature_tests.h>
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 /*
63  * Limits
64  *
65  * The following define the limits for the types defined in <sys/int_types.h>.
66  *
67  * INTMAX_MIN (minimum value of the largest supported signed integer type),
68  * INTMAX_MAX (maximum value of the largest supported signed integer type),
69  * and UINTMAX_MAX (maximum value of the largest supported unsigned integer
70  * type) can be set to implementation defined limits.
71  *
72  * NOTE : A programmer can test to see whether an implementation supports
73  * a particular size of integer by testing if the macro that gives the
74  * maximum for that datatype is defined. For example, if #ifdef UINT64_MAX
75  * tests false, the implementation does not support unsigned 64 bit integers.
76  *
77  * The type of these macros is intentionally unspecified.
78  *
79  * The types int8_t, int_least8_t, and int_fast8_t are not defined for ISAs
80  * where the ABI specifies "char" as unsigned when the translation mode is
81  * not ANSI-C.
82  */
83 #if defined(_CHAR_IS_SIGNED) || defined(__STDC__)
84 #define	INT8_MAX	(127)
85 #endif
86 #define	INT16_MAX	(32767)
87 #define	INT32_MAX	(2147483647)
88 #if defined(_LP64)
89 #define	INT64_MAX	(9223372036854775807L)
90 #elif defined(_LONGLONG_TYPE)
91 #define	INT64_MAX	(9223372036854775807LL)
92 #endif
93 
94 #define	UINT8_MAX	(255U)
95 #define	UINT16_MAX	(65535U)
96 #define	UINT32_MAX	(4294967295U)
97 #if defined(_LP64)
98 #define	UINT64_MAX	(18446744073709551615UL)
99 #elif defined(_LONGLONG_TYPE)
100 #define	UINT64_MAX	(18446744073709551615ULL)
101 #endif
102 
103 #ifdef INT64_MAX
104 #define	INTMAX_MAX	INT64_MAX
105 #else
106 #define	INTMAX_MAX	INT32_MAX
107 #endif
108 
109 #ifdef UINT64_MAX
110 #define	UINTMAX_MAX	UINT64_MAX
111 #else
112 #define	UINTMAX_MAX	UINT32_MAX
113 #endif
114 
115 #if defined(_CHAR_IS_SIGNED) || defined(__STDC__)
116 #define	INT_LEAST8_MAX	INT8_MAX
117 #endif
118 #define	INT_LEAST16_MAX INT16_MAX
119 #define	INT_LEAST32_MAX INT32_MAX
120 #ifdef INT64_MAX
121 #define	INT_LEAST64_MAX INT64_MAX
122 #endif
123 
124 #define	UINT_LEAST8_MAX	UINT8_MAX
125 #define	UINT_LEAST16_MAX UINT16_MAX
126 #define	UINT_LEAST32_MAX UINT32_MAX
127 #ifdef UINT64_MAX
128 #define	UINT_LEAST64_MAX UINT64_MAX
129 #endif
130 
131 #if defined(_CHAR_IS_SIGNED) || defined(__STDC__)
132 #define	INT_FAST8_MAX	INT8_MAX
133 #endif
134 #define	INT_FAST16_MAX INT16_MAX
135 #define	INT_FAST32_MAX INT32_MAX
136 #ifdef INT64_MAX
137 #define	INT_FAST64_MAX INT64_MAX
138 #endif
139 
140 #define	UINT_FAST8_MAX	UINT8_MAX
141 #define	UINT_FAST16_MAX UINT16_MAX
142 #define	UINT_FAST32_MAX UINT32_MAX
143 #ifdef UINT64_MAX
144 #define	UINT_FAST64_MAX UINT64_MAX
145 #endif
146 
147 /*
148  * The following 2 macros are provided for testing whether the types
149  * intptr_t and uintptr_t (integers large enough to hold a void *) are
150  * defined in this header. They are needed in case the architecture can't
151  * represent a pointer in any standard integral type.
152  */
153 #if defined(_LP64) || defined(_I32LPx)
154 #define	INTPTR_MAX	INT64_MAX
155 #define	UINTPTR_MAX	UINT64_MAX
156 #else
157 #define	INTPTR_MAX	INT32_MAX
158 #define	UINTPTR_MAX	UINT32_MAX
159 #endif
160 
161 /* Maximum limits of ptrdiff_t defined in <sys/types.h> */
162 #if defined(_LP64) || defined(_I32LPx)
163 #define	PTRDIFF_MAX	9223372036854775807L
164 #else
165 #define	PTRDIFF_MAX	2147483647
166 #endif
167 
168 /*
169  * Maximum value of a "size_t".  SIZE_MAX was previously defined
170  * in <limits.h>, however, the standards specify it be defined
171  * in <stdint.h>. The <stdint.h> headers includes this header as
172  * does <limits.h>. The value of SIZE_MAX should not deviate
173  * from the value of ULONG_MAX defined <sys/types.h>.
174  */
175 #if defined(_LP64)
176 #define	SIZE_MAX	18446744073709551615UL
177 #else
178 #define	SIZE_MAX	4294967295UL
179 #endif
180 
181 /* Maximum limit of sig_atomic_t defined in <sys/types.h> */
182 #ifndef SIG_ATOMIC_MAX
183 #define	SIG_ATOMIC_MAX	2147483647
184 #endif
185 
186 /*
187  * Maximum limit of wchar_t. The WCHAR_* macros are also
188  * defined in <iso/wchar_iso.h>, but inclusion of that header
189  * will break ISO/IEC C namespace.
190  */
191 #ifndef	WCHAR_MAX
192 #define	WCHAR_MAX	2147483647
193 #endif
194 
195 /* Maximum limit of wint_t */
196 #ifndef WINT_MAX
197 #define	WINT_MAX	2147483647
198 #endif
199 
200 /*
201  * It is probably a bug in the POSIX specification (IEEE-1003.1-1990) that
202  * when including <limits.h> that the suffix _MAX is reserved but not the
203  * suffix _MIN.  However, until that issue is resolved....
204  */
205 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG6)
206 
207 #if defined(_CHAR_IS_SIGNED) || defined(__STDC__)
208 #define	INT8_MIN	(-128)
209 #endif
210 #define	INT16_MIN	(-32767-1)
211 #define	INT32_MIN	(-2147483647-1)
212 #if defined(_LP64)
213 #define	INT64_MIN	(-9223372036854775807L-1)
214 #elif defined(_LONGLONG_TYPE)
215 #define	INT64_MIN	(-9223372036854775807LL-1)
216 #endif
217 
218 #ifdef INT64_MIN
219 #define	INTMAX_MIN	INT64_MIN
220 #else
221 #define	INTMAX_MIN	INT32_MIN
222 #endif
223 
224 #if defined(_CHAR_IS_SIGNED) || defined(__STDC__)
225 #define	INT_LEAST8_MIN	INT8_MIN
226 #endif
227 #define	INT_LEAST16_MIN	INT16_MIN
228 #define	INT_LEAST32_MIN INT32_MIN
229 #ifdef INT64_MIN
230 #define	INT_LEAST64_MIN	INT64_MIN
231 #endif
232 
233 #if defined(_CHAR_IS_SIGNED) || defined(__STDC__)
234 #define	INT_FAST8_MIN	INT8_MIN
235 #endif
236 #define	INT_FAST16_MIN	INT16_MIN
237 #define	INT_FAST32_MIN INT32_MIN
238 #ifdef INT64_MIN
239 #define	INT_FAST64_MIN	INT64_MIN
240 #endif
241 
242 /* Minimum value of a pointer-holding signed integer type */
243 #if defined(_LP64) || defined(_I32LPx)
244 #define	INTPTR_MIN	INT64_MIN
245 #else
246 #define	INTPTR_MIN	INT32_MIN
247 #endif
248 
249 /* Minimum limits of ptrdiff_t defined in <sys/types.h> */
250 #if defined(_LP64) || defined(_I32LPx)
251 #define	PTRDIFF_MIN	(-9223372036854775807L-1L)
252 #else
253 #define	PTRDIFF_MIN	(-2147483647-1)
254 #endif
255 
256 /* Minimum limit of sig_atomic_t defined in <sys/types.h> */
257 #ifndef	SIG_ATOMIC_MIN
258 #define	SIG_ATOMIC_MIN	(-2147483647-1)
259 #endif
260 
261 /*
262  * Minimum limit of wchar_t. The WCHAR_* macros are also
263  * defined in <iso/wchar_iso.h>, but inclusion of that header
264  * will break ISO/IEC C namespace.
265  */
266 #ifndef	WCHAR_MIN
267 #define	WCHAR_MIN	(-2147483647-1)
268 #endif
269 
270 /* Minimum limit of wint_t */
271 #ifndef	WINT_MIN
272 #define	WINT_MIN	(-2147483647-1)
273 #endif
274 
275 #endif	/* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) ... */
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #endif /* _SYS_INT_LIMITS_H */
282