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