xref: /illumos-gate/usr/src/uts/common/sys/int_types.h (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_INT_TYPES_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_INT_TYPES_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate /*
33*7c478bd9Sstevel@tonic-gate  * This file, <sys/int_types.h>, is part of the Sun Microsystems implementation
34*7c478bd9Sstevel@tonic-gate  * of <inttypes.h> defined in the ISO C standard, ISO/IEC 9899:1999
35*7c478bd9Sstevel@tonic-gate  * Programming language - C.
36*7c478bd9Sstevel@tonic-gate  *
37*7c478bd9Sstevel@tonic-gate  * Programs/Modules should not directly include this file.  Access to the
38*7c478bd9Sstevel@tonic-gate  * types defined in this file should be through the inclusion of one of the
39*7c478bd9Sstevel@tonic-gate  * following files:
40*7c478bd9Sstevel@tonic-gate  *
41*7c478bd9Sstevel@tonic-gate  *	<sys/types.h>		Provides only the "_t" types defined in this
42*7c478bd9Sstevel@tonic-gate  *				file which is a subset of the contents of
43*7c478bd9Sstevel@tonic-gate  *				<inttypes.h>.  (This can be appropriate for
44*7c478bd9Sstevel@tonic-gate  *				all programs/modules except those claiming
45*7c478bd9Sstevel@tonic-gate  *				ANSI-C conformance.)
46*7c478bd9Sstevel@tonic-gate  *
47*7c478bd9Sstevel@tonic-gate  *	<sys/inttypes.h>	Provides the Kernel and Driver appropriate
48*7c478bd9Sstevel@tonic-gate  *				components of <inttypes.h>.
49*7c478bd9Sstevel@tonic-gate  *
50*7c478bd9Sstevel@tonic-gate  *	<inttypes.h>		For use by applications.
51*7c478bd9Sstevel@tonic-gate  *
52*7c478bd9Sstevel@tonic-gate  * See these files for more details.
53*7c478bd9Sstevel@tonic-gate  */
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
58*7c478bd9Sstevel@tonic-gate extern "C" {
59*7c478bd9Sstevel@tonic-gate #endif
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate /*
62*7c478bd9Sstevel@tonic-gate  * Basic / Extended integer types
63*7c478bd9Sstevel@tonic-gate  *
64*7c478bd9Sstevel@tonic-gate  * The following defines the basic fixed-size integer types.
65*7c478bd9Sstevel@tonic-gate  *
66*7c478bd9Sstevel@tonic-gate  * Implementations are free to typedef them to Standard C integer types or
67*7c478bd9Sstevel@tonic-gate  * extensions that they support. If an implementation does not support one
68*7c478bd9Sstevel@tonic-gate  * of the particular integer data types below, then it should not define the
69*7c478bd9Sstevel@tonic-gate  * typedefs and macros corresponding to that data type.  Note that int8_t
70*7c478bd9Sstevel@tonic-gate  * is not defined in -Xs mode on ISAs for which the ABI specifies "char"
71*7c478bd9Sstevel@tonic-gate  * as an unsigned entity because there is no way to define an eight bit
72*7c478bd9Sstevel@tonic-gate  * signed integral.
73*7c478bd9Sstevel@tonic-gate  */
74*7c478bd9Sstevel@tonic-gate #if defined(_CHAR_IS_SIGNED)
75*7c478bd9Sstevel@tonic-gate typedef char			int8_t;
76*7c478bd9Sstevel@tonic-gate #else
77*7c478bd9Sstevel@tonic-gate #if defined(__STDC__)
78*7c478bd9Sstevel@tonic-gate typedef signed char		int8_t;
79*7c478bd9Sstevel@tonic-gate #endif
80*7c478bd9Sstevel@tonic-gate #endif
81*7c478bd9Sstevel@tonic-gate typedef short			int16_t;
82*7c478bd9Sstevel@tonic-gate typedef int			int32_t;
83*7c478bd9Sstevel@tonic-gate #ifdef	_LP64
84*7c478bd9Sstevel@tonic-gate #define	_INT64_TYPE
85*7c478bd9Sstevel@tonic-gate typedef long			int64_t;
86*7c478bd9Sstevel@tonic-gate #else	/* _ILP32 */
87*7c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
88*7c478bd9Sstevel@tonic-gate #define	_INT64_TYPE
89*7c478bd9Sstevel@tonic-gate typedef	long long		int64_t;
90*7c478bd9Sstevel@tonic-gate #endif
91*7c478bd9Sstevel@tonic-gate #endif
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate typedef unsigned char		uint8_t;
94*7c478bd9Sstevel@tonic-gate typedef unsigned short		uint16_t;
95*7c478bd9Sstevel@tonic-gate typedef unsigned int		uint32_t;
96*7c478bd9Sstevel@tonic-gate #ifdef	_LP64
97*7c478bd9Sstevel@tonic-gate typedef unsigned long		uint64_t;
98*7c478bd9Sstevel@tonic-gate #else	/* _ILP32 */
99*7c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
100*7c478bd9Sstevel@tonic-gate typedef unsigned long long	uint64_t;
101*7c478bd9Sstevel@tonic-gate #endif
102*7c478bd9Sstevel@tonic-gate #endif
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate /*
105*7c478bd9Sstevel@tonic-gate  * intmax_t and uintmax_t are to be the longest (in number of bits) signed
106*7c478bd9Sstevel@tonic-gate  * and unsigned integer types supported by the implementation.
107*7c478bd9Sstevel@tonic-gate  */
108*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
109*7c478bd9Sstevel@tonic-gate typedef int64_t			intmax_t;
110*7c478bd9Sstevel@tonic-gate typedef uint64_t		uintmax_t;
111*7c478bd9Sstevel@tonic-gate #else
112*7c478bd9Sstevel@tonic-gate typedef int32_t			intmax_t;
113*7c478bd9Sstevel@tonic-gate typedef uint32_t		uintmax_t;
114*7c478bd9Sstevel@tonic-gate #endif
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate /*
117*7c478bd9Sstevel@tonic-gate  * intptr_t and uintptr_t are signed and unsigned integer types large enough
118*7c478bd9Sstevel@tonic-gate  * to hold any data pointer; that is, data pointers can be assigned into or
119*7c478bd9Sstevel@tonic-gate  * from these integer types without losing precision.
120*7c478bd9Sstevel@tonic-gate  */
121*7c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_I32LPx)
122*7c478bd9Sstevel@tonic-gate typedef long			intptr_t;
123*7c478bd9Sstevel@tonic-gate typedef unsigned long		uintptr_t;
124*7c478bd9Sstevel@tonic-gate #else
125*7c478bd9Sstevel@tonic-gate typedef	int			intptr_t;
126*7c478bd9Sstevel@tonic-gate typedef	unsigned int		uintptr_t;
127*7c478bd9Sstevel@tonic-gate #endif
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate /*
130*7c478bd9Sstevel@tonic-gate  * The following define the fastest integer types that can hold the
131*7c478bd9Sstevel@tonic-gate  * specified number of bits.
132*7c478bd9Sstevel@tonic-gate  */
133*7c478bd9Sstevel@tonic-gate #if defined(_CHAR_IS_SIGNED)
134*7c478bd9Sstevel@tonic-gate typedef char			int_fast8_t;
135*7c478bd9Sstevel@tonic-gate #else
136*7c478bd9Sstevel@tonic-gate #if defined(__STDC__)
137*7c478bd9Sstevel@tonic-gate typedef signed char		int_fast8_t;
138*7c478bd9Sstevel@tonic-gate #endif
139*7c478bd9Sstevel@tonic-gate #endif
140*7c478bd9Sstevel@tonic-gate typedef int			int_fast16_t;
141*7c478bd9Sstevel@tonic-gate typedef int			int_fast32_t;
142*7c478bd9Sstevel@tonic-gate #ifdef	_LP64
143*7c478bd9Sstevel@tonic-gate typedef long			int_fast64_t;
144*7c478bd9Sstevel@tonic-gate #else	/* _ILP32 */
145*7c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
146*7c478bd9Sstevel@tonic-gate typedef long long		int_fast64_t;
147*7c478bd9Sstevel@tonic-gate #endif
148*7c478bd9Sstevel@tonic-gate #endif
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate typedef unsigned char		uint_fast8_t;
151*7c478bd9Sstevel@tonic-gate typedef unsigned int		uint_fast16_t;
152*7c478bd9Sstevel@tonic-gate typedef unsigned int		uint_fast32_t;
153*7c478bd9Sstevel@tonic-gate #ifdef	_LP64
154*7c478bd9Sstevel@tonic-gate typedef unsigned long		uint_fast64_t;
155*7c478bd9Sstevel@tonic-gate #else	/* _ILP32 */
156*7c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
157*7c478bd9Sstevel@tonic-gate typedef unsigned long long	uint_fast64_t;
158*7c478bd9Sstevel@tonic-gate #endif
159*7c478bd9Sstevel@tonic-gate #endif
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate /*
162*7c478bd9Sstevel@tonic-gate  * The following define the smallest integer types that can hold the
163*7c478bd9Sstevel@tonic-gate  * specified number of bits.
164*7c478bd9Sstevel@tonic-gate  */
165*7c478bd9Sstevel@tonic-gate #if defined(_CHAR_IS_SIGNED)
166*7c478bd9Sstevel@tonic-gate typedef char			int_least8_t;
167*7c478bd9Sstevel@tonic-gate #else
168*7c478bd9Sstevel@tonic-gate #if defined(__STDC__)
169*7c478bd9Sstevel@tonic-gate typedef signed char		int_least8_t;
170*7c478bd9Sstevel@tonic-gate #endif
171*7c478bd9Sstevel@tonic-gate #endif
172*7c478bd9Sstevel@tonic-gate typedef short			int_least16_t;
173*7c478bd9Sstevel@tonic-gate typedef int			int_least32_t;
174*7c478bd9Sstevel@tonic-gate #ifdef	_LP64
175*7c478bd9Sstevel@tonic-gate typedef long			int_least64_t;
176*7c478bd9Sstevel@tonic-gate #else	/* _ILP32 */
177*7c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
178*7c478bd9Sstevel@tonic-gate typedef long long		int_least64_t;
179*7c478bd9Sstevel@tonic-gate #endif
180*7c478bd9Sstevel@tonic-gate #endif
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate typedef unsigned char		uint_least8_t;
183*7c478bd9Sstevel@tonic-gate typedef unsigned short		uint_least16_t;
184*7c478bd9Sstevel@tonic-gate typedef unsigned int		uint_least32_t;
185*7c478bd9Sstevel@tonic-gate #ifdef	_LP64
186*7c478bd9Sstevel@tonic-gate typedef unsigned long		uint_least64_t;
187*7c478bd9Sstevel@tonic-gate #else	/* _ILP32 */
188*7c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
189*7c478bd9Sstevel@tonic-gate typedef unsigned long long	uint_least64_t;
190*7c478bd9Sstevel@tonic-gate #endif
191*7c478bd9Sstevel@tonic-gate #endif
192*7c478bd9Sstevel@tonic-gate 
193*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
194*7c478bd9Sstevel@tonic-gate }
195*7c478bd9Sstevel@tonic-gate #endif
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate #endif /* _SYS_INT_TYPES_H */
198