xref: /illumos-gate/usr/src/uts/common/sys/int_limits.h (revision ba3594ba)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24*ba3594baSGarrett D'Amore  *
257c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef _SYS_INT_LIMITS_H
307c478bd9Sstevel@tonic-gate #define	_SYS_INT_LIMITS_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * This file, <sys/int_limits.h>, is part of the Sun Microsystems implementation
347c478bd9Sstevel@tonic-gate  * of <inttypes.h> as defined in the ISO C standard, ISO/IEC 9899:1999
357c478bd9Sstevel@tonic-gate  * Programming language - C.
367c478bd9Sstevel@tonic-gate  *
377c478bd9Sstevel@tonic-gate  * Programs/Modules should not directly include this file.  Access to the
387c478bd9Sstevel@tonic-gate  * types defined in this file should be through the inclusion of one of the
397c478bd9Sstevel@tonic-gate  * following files:
407c478bd9Sstevel@tonic-gate  *
417c478bd9Sstevel@tonic-gate  *	<limits.h>		This nested inclusion is disabled for strictly
427c478bd9Sstevel@tonic-gate  *				ANSI-C conforming compilations.  The *_MIN
437c478bd9Sstevel@tonic-gate  *				definitions are not visible to POSIX or XPG
447c478bd9Sstevel@tonic-gate  *				conforming applications (due to what may be
457c478bd9Sstevel@tonic-gate  *				a bug in the specification - this is under
467c478bd9Sstevel@tonic-gate  *				investigation)
477c478bd9Sstevel@tonic-gate  *
487c478bd9Sstevel@tonic-gate  *	<sys/inttypes.h>	Provides the Kernel and Driver appropriate
497c478bd9Sstevel@tonic-gate  *				components of <inttypes.h>.
507c478bd9Sstevel@tonic-gate  *
517c478bd9Sstevel@tonic-gate  *	<inttypes.h>		For use by applications.
527c478bd9Sstevel@tonic-gate  *
537c478bd9Sstevel@tonic-gate  * See these files for more details.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate #ifdef __cplusplus
597c478bd9Sstevel@tonic-gate extern "C" {
607c478bd9Sstevel@tonic-gate #endif
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * Limits
647c478bd9Sstevel@tonic-gate  *
657c478bd9Sstevel@tonic-gate  * The following define the limits for the types defined in <sys/int_types.h>.
667c478bd9Sstevel@tonic-gate  *
677c478bd9Sstevel@tonic-gate  * INTMAX_MIN (minimum value of the largest supported signed integer type),
687c478bd9Sstevel@tonic-gate  * INTMAX_MAX (maximum value of the largest supported signed integer type),
697c478bd9Sstevel@tonic-gate  * and UINTMAX_MAX (maximum value of the largest supported unsigned integer
707c478bd9Sstevel@tonic-gate  * type) can be set to implementation defined limits.
717c478bd9Sstevel@tonic-gate  *
727c478bd9Sstevel@tonic-gate  * NOTE : A programmer can test to see whether an implementation supports
737c478bd9Sstevel@tonic-gate  * a particular size of integer by testing if the macro that gives the
747c478bd9Sstevel@tonic-gate  * maximum for that datatype is defined. For example, if #ifdef UINT64_MAX
757c478bd9Sstevel@tonic-gate  * tests false, the implementation does not support unsigned 64 bit integers.
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  * The type of these macros is intentionally unspecified.
787c478bd9Sstevel@tonic-gate  *
797c478bd9Sstevel@tonic-gate  * The types int8_t, int_least8_t, and int_fast8_t are not defined for ISAs
807c478bd9Sstevel@tonic-gate  * where the ABI specifies "char" as unsigned when the translation mode is
817c478bd9Sstevel@tonic-gate  * not ANSI-C.
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate #define	INT8_MAX	(127)
847c478bd9Sstevel@tonic-gate #define	INT16_MAX	(32767)
857c478bd9Sstevel@tonic-gate #define	INT32_MAX	(2147483647)
867c478bd9Sstevel@tonic-gate #if defined(_LP64)
877c478bd9Sstevel@tonic-gate #define	INT64_MAX	(9223372036854775807L)
887c478bd9Sstevel@tonic-gate #elif defined(_LONGLONG_TYPE)
897c478bd9Sstevel@tonic-gate #define	INT64_MAX	(9223372036854775807LL)
907c478bd9Sstevel@tonic-gate #endif
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #define	UINT8_MAX	(255U)
937c478bd9Sstevel@tonic-gate #define	UINT16_MAX	(65535U)
947c478bd9Sstevel@tonic-gate #define	UINT32_MAX	(4294967295U)
957c478bd9Sstevel@tonic-gate #if defined(_LP64)
967c478bd9Sstevel@tonic-gate #define	UINT64_MAX	(18446744073709551615UL)
977c478bd9Sstevel@tonic-gate #elif defined(_LONGLONG_TYPE)
987c478bd9Sstevel@tonic-gate #define	UINT64_MAX	(18446744073709551615ULL)
997c478bd9Sstevel@tonic-gate #endif
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate #ifdef INT64_MAX
1027c478bd9Sstevel@tonic-gate #define	INTMAX_MAX	INT64_MAX
1037c478bd9Sstevel@tonic-gate #else
1047c478bd9Sstevel@tonic-gate #define	INTMAX_MAX	INT32_MAX
1057c478bd9Sstevel@tonic-gate #endif
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #ifdef UINT64_MAX
1087c478bd9Sstevel@tonic-gate #define	UINTMAX_MAX	UINT64_MAX
1097c478bd9Sstevel@tonic-gate #else
1107c478bd9Sstevel@tonic-gate #define	UINTMAX_MAX	UINT32_MAX
1117c478bd9Sstevel@tonic-gate #endif
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #define	INT_LEAST8_MAX	INT8_MAX
1147c478bd9Sstevel@tonic-gate #define	INT_LEAST16_MAX INT16_MAX
1157c478bd9Sstevel@tonic-gate #define	INT_LEAST32_MAX INT32_MAX
1167c478bd9Sstevel@tonic-gate #ifdef INT64_MAX
1177c478bd9Sstevel@tonic-gate #define	INT_LEAST64_MAX INT64_MAX
1187c478bd9Sstevel@tonic-gate #endif
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #define	UINT_LEAST8_MAX	UINT8_MAX
1217c478bd9Sstevel@tonic-gate #define	UINT_LEAST16_MAX UINT16_MAX
1227c478bd9Sstevel@tonic-gate #define	UINT_LEAST32_MAX UINT32_MAX
1237c478bd9Sstevel@tonic-gate #ifdef UINT64_MAX
1247c478bd9Sstevel@tonic-gate #define	UINT_LEAST64_MAX UINT64_MAX
1257c478bd9Sstevel@tonic-gate #endif
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #define	INT_FAST8_MAX	INT8_MAX
1287c478bd9Sstevel@tonic-gate #define	INT_FAST16_MAX INT16_MAX
1297c478bd9Sstevel@tonic-gate #define	INT_FAST32_MAX INT32_MAX
1307c478bd9Sstevel@tonic-gate #ifdef INT64_MAX
1317c478bd9Sstevel@tonic-gate #define	INT_FAST64_MAX INT64_MAX
1327c478bd9Sstevel@tonic-gate #endif
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate #define	UINT_FAST8_MAX	UINT8_MAX
1357c478bd9Sstevel@tonic-gate #define	UINT_FAST16_MAX UINT16_MAX
1367c478bd9Sstevel@tonic-gate #define	UINT_FAST32_MAX UINT32_MAX
1377c478bd9Sstevel@tonic-gate #ifdef UINT64_MAX
1387c478bd9Sstevel@tonic-gate #define	UINT_FAST64_MAX UINT64_MAX
1397c478bd9Sstevel@tonic-gate #endif
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate  * The following 2 macros are provided for testing whether the types
1437c478bd9Sstevel@tonic-gate  * intptr_t and uintptr_t (integers large enough to hold a void *) are
1447c478bd9Sstevel@tonic-gate  * defined in this header. They are needed in case the architecture can't
1457c478bd9Sstevel@tonic-gate  * represent a pointer in any standard integral type.
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_I32LPx)
1487c478bd9Sstevel@tonic-gate #define	INTPTR_MAX	INT64_MAX
1497c478bd9Sstevel@tonic-gate #define	UINTPTR_MAX	UINT64_MAX
1507c478bd9Sstevel@tonic-gate #else
1517c478bd9Sstevel@tonic-gate #define	INTPTR_MAX	INT32_MAX
1527c478bd9Sstevel@tonic-gate #define	UINTPTR_MAX	UINT32_MAX
1537c478bd9Sstevel@tonic-gate #endif
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /* Maximum limits of ptrdiff_t defined in <sys/types.h> */
1567c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_I32LPx)
1577c478bd9Sstevel@tonic-gate #define	PTRDIFF_MAX	9223372036854775807L
1587c478bd9Sstevel@tonic-gate #else
1597c478bd9Sstevel@tonic-gate #define	PTRDIFF_MAX	2147483647
1607c478bd9Sstevel@tonic-gate #endif
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate  * Maximum value of a "size_t".  SIZE_MAX was previously defined
1647c478bd9Sstevel@tonic-gate  * in <limits.h>, however, the standards specify it be defined
1657c478bd9Sstevel@tonic-gate  * in <stdint.h>. The <stdint.h> headers includes this header as
1667c478bd9Sstevel@tonic-gate  * does <limits.h>. The value of SIZE_MAX should not deviate
1677c478bd9Sstevel@tonic-gate  * from the value of ULONG_MAX defined <sys/types.h>.
1687c478bd9Sstevel@tonic-gate  */
1697c478bd9Sstevel@tonic-gate #if defined(_LP64)
1707c478bd9Sstevel@tonic-gate #define	SIZE_MAX	18446744073709551615UL
1717c478bd9Sstevel@tonic-gate #else
1727c478bd9Sstevel@tonic-gate #define	SIZE_MAX	4294967295UL
1737c478bd9Sstevel@tonic-gate #endif
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate /* Maximum limit of sig_atomic_t defined in <sys/types.h> */
1767c478bd9Sstevel@tonic-gate #ifndef SIG_ATOMIC_MAX
1777c478bd9Sstevel@tonic-gate #define	SIG_ATOMIC_MAX	2147483647
1787c478bd9Sstevel@tonic-gate #endif
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate /*
1817c478bd9Sstevel@tonic-gate  * Maximum limit of wchar_t. The WCHAR_* macros are also
1827c478bd9Sstevel@tonic-gate  * defined in <iso/wchar_iso.h>, but inclusion of that header
1837c478bd9Sstevel@tonic-gate  * will break ISO/IEC C namespace.
1847c478bd9Sstevel@tonic-gate  */
1857c478bd9Sstevel@tonic-gate #ifndef	WCHAR_MAX
1867c478bd9Sstevel@tonic-gate #define	WCHAR_MAX	2147483647
1877c478bd9Sstevel@tonic-gate #endif
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate /* Maximum limit of wint_t */
1907c478bd9Sstevel@tonic-gate #ifndef WINT_MAX
1917c478bd9Sstevel@tonic-gate #define	WINT_MAX	2147483647
1927c478bd9Sstevel@tonic-gate #endif
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate /*
1957c478bd9Sstevel@tonic-gate  * It is probably a bug in the POSIX specification (IEEE-1003.1-1990) that
1967c478bd9Sstevel@tonic-gate  * when including <limits.h> that the suffix _MAX is reserved but not the
1977c478bd9Sstevel@tonic-gate  * suffix _MIN.  However, until that issue is resolved....
1987c478bd9Sstevel@tonic-gate  */
1997c478bd9Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG6)
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate #define	INT8_MIN	(-128)
2027c478bd9Sstevel@tonic-gate #define	INT16_MIN	(-32767-1)
2037c478bd9Sstevel@tonic-gate #define	INT32_MIN	(-2147483647-1)
2047c478bd9Sstevel@tonic-gate #if defined(_LP64)
2057c478bd9Sstevel@tonic-gate #define	INT64_MIN	(-9223372036854775807L-1)
2067c478bd9Sstevel@tonic-gate #elif defined(_LONGLONG_TYPE)
2077c478bd9Sstevel@tonic-gate #define	INT64_MIN	(-9223372036854775807LL-1)
2087c478bd9Sstevel@tonic-gate #endif
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate #ifdef INT64_MIN
2117c478bd9Sstevel@tonic-gate #define	INTMAX_MIN	INT64_MIN
2127c478bd9Sstevel@tonic-gate #else
2137c478bd9Sstevel@tonic-gate #define	INTMAX_MIN	INT32_MIN
2147c478bd9Sstevel@tonic-gate #endif
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate #define	INT_LEAST8_MIN	INT8_MIN
2177c478bd9Sstevel@tonic-gate #define	INT_LEAST16_MIN	INT16_MIN
2187c478bd9Sstevel@tonic-gate #define	INT_LEAST32_MIN INT32_MIN
2197c478bd9Sstevel@tonic-gate #ifdef INT64_MIN
2207c478bd9Sstevel@tonic-gate #define	INT_LEAST64_MIN	INT64_MIN
2217c478bd9Sstevel@tonic-gate #endif
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate #define	INT_FAST8_MIN	INT8_MIN
2247c478bd9Sstevel@tonic-gate #define	INT_FAST16_MIN	INT16_MIN
2257c478bd9Sstevel@tonic-gate #define	INT_FAST32_MIN INT32_MIN
2267c478bd9Sstevel@tonic-gate #ifdef INT64_MIN
2277c478bd9Sstevel@tonic-gate #define	INT_FAST64_MIN	INT64_MIN
2287c478bd9Sstevel@tonic-gate #endif
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate /* Minimum value of a pointer-holding signed integer type */
2317c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_I32LPx)
2327c478bd9Sstevel@tonic-gate #define	INTPTR_MIN	INT64_MIN
2337c478bd9Sstevel@tonic-gate #else
2347c478bd9Sstevel@tonic-gate #define	INTPTR_MIN	INT32_MIN
2357c478bd9Sstevel@tonic-gate #endif
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate /* Minimum limits of ptrdiff_t defined in <sys/types.h> */
2387c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_I32LPx)
2397c478bd9Sstevel@tonic-gate #define	PTRDIFF_MIN	(-9223372036854775807L-1L)
2407c478bd9Sstevel@tonic-gate #else
2417c478bd9Sstevel@tonic-gate #define	PTRDIFF_MIN	(-2147483647-1)
2427c478bd9Sstevel@tonic-gate #endif
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate /* Minimum limit of sig_atomic_t defined in <sys/types.h> */
2457c478bd9Sstevel@tonic-gate #ifndef	SIG_ATOMIC_MIN
2467c478bd9Sstevel@tonic-gate #define	SIG_ATOMIC_MIN	(-2147483647-1)
2477c478bd9Sstevel@tonic-gate #endif
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate /*
2507c478bd9Sstevel@tonic-gate  * Minimum limit of wchar_t. The WCHAR_* macros are also
2517c478bd9Sstevel@tonic-gate  * defined in <iso/wchar_iso.h>, but inclusion of that header
2527c478bd9Sstevel@tonic-gate  * will break ISO/IEC C namespace.
2537c478bd9Sstevel@tonic-gate  */
2547c478bd9Sstevel@tonic-gate #ifndef	WCHAR_MIN
2557c478bd9Sstevel@tonic-gate #define	WCHAR_MIN	(-2147483647-1)
2567c478bd9Sstevel@tonic-gate #endif
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate /* Minimum limit of wint_t */
2597c478bd9Sstevel@tonic-gate #ifndef	WINT_MIN
2607c478bd9Sstevel@tonic-gate #define	WINT_MIN	(-2147483647-1)
2617c478bd9Sstevel@tonic-gate #endif
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate #endif	/* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) ... */
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate #endif
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate #endif /* _SYS_INT_LIMITS_H */
270