xref: /illumos-gate/usr/src/uts/common/sys/int_types.h (revision eda3ef2d)
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 /*
23ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24ba3594baSGarrett 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_TYPES_H
307c478bd9Sstevel@tonic-gate #define	_SYS_INT_TYPES_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * This file, <sys/int_types.h>, is part of the Sun Microsystems implementation
347c478bd9Sstevel@tonic-gate  * of <inttypes.h> 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  *	<sys/types.h>		Provides only the "_t" types defined in this
427c478bd9Sstevel@tonic-gate  *				file which is a subset of the contents of
437c478bd9Sstevel@tonic-gate  *				<inttypes.h>.  (This can be appropriate for
447c478bd9Sstevel@tonic-gate  *				all programs/modules except those claiming
457c478bd9Sstevel@tonic-gate  *				ANSI-C conformance.)
467c478bd9Sstevel@tonic-gate  *
477c478bd9Sstevel@tonic-gate  *	<sys/inttypes.h>	Provides the Kernel and Driver appropriate
487c478bd9Sstevel@tonic-gate  *				components of <inttypes.h>.
497c478bd9Sstevel@tonic-gate  *
507c478bd9Sstevel@tonic-gate  *	<inttypes.h>		For use by applications.
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * See these files for more details.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #ifdef __cplusplus
587c478bd9Sstevel@tonic-gate extern "C" {
597c478bd9Sstevel@tonic-gate #endif
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * Basic / Extended integer types
637c478bd9Sstevel@tonic-gate  *
647c478bd9Sstevel@tonic-gate  * The following defines the basic fixed-size integer types.
657c478bd9Sstevel@tonic-gate  *
667c478bd9Sstevel@tonic-gate  * Implementations are free to typedef them to Standard C integer types or
677c478bd9Sstevel@tonic-gate  * extensions that they support. If an implementation does not support one
687c478bd9Sstevel@tonic-gate  * of the particular integer data types below, then it should not define the
697c478bd9Sstevel@tonic-gate  * typedefs and macros corresponding to that data type.  Note that int8_t
707c478bd9Sstevel@tonic-gate  * is not defined in -Xs mode on ISAs for which the ABI specifies "char"
717c478bd9Sstevel@tonic-gate  * as an unsigned entity because there is no way to define an eight bit
727c478bd9Sstevel@tonic-gate  * signed integral.
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate #if defined(_CHAR_IS_SIGNED)
757c478bd9Sstevel@tonic-gate typedef char			int8_t;
767c478bd9Sstevel@tonic-gate #else
777c478bd9Sstevel@tonic-gate typedef signed char		int8_t;
787c478bd9Sstevel@tonic-gate #endif
797c478bd9Sstevel@tonic-gate typedef short			int16_t;
807c478bd9Sstevel@tonic-gate typedef int			int32_t;
817c478bd9Sstevel@tonic-gate #ifdef	_LP64
827c478bd9Sstevel@tonic-gate #define	_INT64_TYPE
837c478bd9Sstevel@tonic-gate typedef long			int64_t;
847c478bd9Sstevel@tonic-gate #else	/* _ILP32 */
857c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
867c478bd9Sstevel@tonic-gate #define	_INT64_TYPE
877c478bd9Sstevel@tonic-gate typedef	long long		int64_t;
887c478bd9Sstevel@tonic-gate #endif
897c478bd9Sstevel@tonic-gate #endif
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate typedef unsigned char		uint8_t;
927c478bd9Sstevel@tonic-gate typedef unsigned short		uint16_t;
937c478bd9Sstevel@tonic-gate typedef unsigned int		uint32_t;
947c478bd9Sstevel@tonic-gate #ifdef	_LP64
957c478bd9Sstevel@tonic-gate typedef unsigned long		uint64_t;
967c478bd9Sstevel@tonic-gate #else	/* _ILP32 */
977c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
987c478bd9Sstevel@tonic-gate typedef unsigned long long	uint64_t;
997c478bd9Sstevel@tonic-gate #endif
1007c478bd9Sstevel@tonic-gate #endif
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * intmax_t and uintmax_t are to be the longest (in number of bits) signed
1047c478bd9Sstevel@tonic-gate  * and unsigned integer types supported by the implementation.
1057c478bd9Sstevel@tonic-gate  */
1067c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
1077c478bd9Sstevel@tonic-gate typedef int64_t			intmax_t;
1087c478bd9Sstevel@tonic-gate typedef uint64_t		uintmax_t;
1097c478bd9Sstevel@tonic-gate #else
1107c478bd9Sstevel@tonic-gate typedef int32_t			intmax_t;
1117c478bd9Sstevel@tonic-gate typedef uint32_t		uintmax_t;
1127c478bd9Sstevel@tonic-gate #endif
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate  * intptr_t and uintptr_t are signed and unsigned integer types large enough
1167c478bd9Sstevel@tonic-gate  * to hold any data pointer; that is, data pointers can be assigned into or
1177c478bd9Sstevel@tonic-gate  * from these integer types without losing precision.
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_I32LPx)
1207c478bd9Sstevel@tonic-gate typedef long			intptr_t;
1217c478bd9Sstevel@tonic-gate typedef unsigned long		uintptr_t;
1227c478bd9Sstevel@tonic-gate #else
1237c478bd9Sstevel@tonic-gate typedef	int			intptr_t;
1247c478bd9Sstevel@tonic-gate typedef	unsigned int		uintptr_t;
1257c478bd9Sstevel@tonic-gate #endif
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate  * The following define the fastest integer types that can hold the
1297c478bd9Sstevel@tonic-gate  * specified number of bits.
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate #if defined(_CHAR_IS_SIGNED)
1327c478bd9Sstevel@tonic-gate typedef char			int_fast8_t;
1337c478bd9Sstevel@tonic-gate #else
1347c478bd9Sstevel@tonic-gate typedef signed char		int_fast8_t;
1357c478bd9Sstevel@tonic-gate #endif
1367c478bd9Sstevel@tonic-gate typedef int			int_fast16_t;
1377c478bd9Sstevel@tonic-gate typedef int			int_fast32_t;
1387c478bd9Sstevel@tonic-gate #ifdef	_LP64
1397c478bd9Sstevel@tonic-gate typedef long			int_fast64_t;
1407c478bd9Sstevel@tonic-gate #else	/* _ILP32 */
1417c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
1427c478bd9Sstevel@tonic-gate typedef long long		int_fast64_t;
1437c478bd9Sstevel@tonic-gate #endif
1447c478bd9Sstevel@tonic-gate #endif
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate typedef unsigned char		uint_fast8_t;
1477c478bd9Sstevel@tonic-gate typedef unsigned int		uint_fast16_t;
1487c478bd9Sstevel@tonic-gate typedef unsigned int		uint_fast32_t;
1497c478bd9Sstevel@tonic-gate #ifdef	_LP64
1507c478bd9Sstevel@tonic-gate typedef unsigned long		uint_fast64_t;
1517c478bd9Sstevel@tonic-gate #else	/* _ILP32 */
1527c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
1537c478bd9Sstevel@tonic-gate typedef unsigned long long	uint_fast64_t;
1547c478bd9Sstevel@tonic-gate #endif
1557c478bd9Sstevel@tonic-gate #endif
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate  * The following define the smallest integer types that can hold the
1597c478bd9Sstevel@tonic-gate  * specified number of bits.
1607c478bd9Sstevel@tonic-gate  */
1617c478bd9Sstevel@tonic-gate #if defined(_CHAR_IS_SIGNED)
1627c478bd9Sstevel@tonic-gate typedef char			int_least8_t;
1637c478bd9Sstevel@tonic-gate #else
1647c478bd9Sstevel@tonic-gate typedef signed char		int_least8_t;
1657c478bd9Sstevel@tonic-gate #endif
1667c478bd9Sstevel@tonic-gate typedef short			int_least16_t;
1677c478bd9Sstevel@tonic-gate typedef int			int_least32_t;
1687c478bd9Sstevel@tonic-gate #ifdef	_LP64
1697c478bd9Sstevel@tonic-gate typedef long			int_least64_t;
1707c478bd9Sstevel@tonic-gate #else	/* _ILP32 */
1717c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
1727c478bd9Sstevel@tonic-gate typedef long long		int_least64_t;
1737c478bd9Sstevel@tonic-gate #endif
1747c478bd9Sstevel@tonic-gate #endif
1757c478bd9Sstevel@tonic-gate 
176*eda3ef2dSRobert Mustacchi /*
177*eda3ef2dSRobert Mustacchi  * If these are changed, please update char16_t and char32_t in head/uchar.h.
178*eda3ef2dSRobert Mustacchi  */
1797c478bd9Sstevel@tonic-gate typedef unsigned char		uint_least8_t;
1807c478bd9Sstevel@tonic-gate typedef unsigned short		uint_least16_t;
1817c478bd9Sstevel@tonic-gate typedef unsigned int		uint_least32_t;
1827c478bd9Sstevel@tonic-gate #ifdef	_LP64
1837c478bd9Sstevel@tonic-gate typedef unsigned long		uint_least64_t;
1847c478bd9Sstevel@tonic-gate #else	/* _ILP32 */
1857c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
1867c478bd9Sstevel@tonic-gate typedef unsigned long long	uint_least64_t;
1877c478bd9Sstevel@tonic-gate #endif
1887c478bd9Sstevel@tonic-gate #endif
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate #endif
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate #endif /* _SYS_INT_TYPES_H */
195