xref: /titanic_44/usr/src/uts/common/sys/int_fmtio.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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_FMTIO_H
28 #define	_SYS_INT_FMTIO_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * This file, <sys/int_fmtio.h>, is part of the Sun Microsystems implementation
34  * of <inttypes.h> as defined by the ISO C Standard, ISO/IEC 9899:1999
35  * Programming language - C.
36  *
37  * ISO  International Organization for Standardization.
38  *
39  * Programs/Modules should not directly include this file.  Access to the
40  * types defined in this file should be through the inclusion of one of the
41  * following files:
42  *
43  *	<sys/inttypes.h>	Provides the Kernel and Driver appropriate
44  *				components of <inttypes.h>.
45  *
46  *	<inttypes.h>		For use by applications.
47  *
48  * See these files for more details.
49  */
50 
51 #include <sys/feature_tests.h>
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 /*
58  * Formatted I/O
59  *
60  * The following macros can be used even when an implementation has not
61  * extended the printf/scanf family of functions.
62  *
63  * The form of the names of the macros is either "PRI" for printf specifiers
64  * or "SCN" for scanf specifiers, followed by the conversion specifier letter
65  * followed by the datatype size. For example, PRId32 is the macro for
66  * the printf d conversion specifier with the flags for 32 bit datatype.
67  *
68  * An example using one of these macros:
69  *
70  *	uint64_t u;
71  *	printf("u = %016" PRIx64 "\n", u);
72  *
73  * For the purpose of example, the definitions of the printf/scanf macros
74  * below have the values appropriate for a machine with 8 bit shorts, 16
75  * bit shorts, 32 bit ints, 32 or 64 bit longs depending on compilation
76  * mode, and 64 bit long longs.
77  */
78 
79 /*
80  * fprintf macros for signed integers
81  */
82 #if defined(_KERNEL)
83 #define	_MODF8	""
84 #define	_MODF16	""
85 #else
86 #define	_MODF8	"hh"
87 #define	_MODF16	"h"
88 #endif
89 
90 #define	_PRId	"d"
91 #define	_PRIi	"i"
92 #define	_PRIo	"o"
93 #define	_PRIu	"u"
94 #define	_PRIx	"x"
95 #define	_PRIX	"X"
96 
97 #if defined(_CHAR_IS_SIGNED) || defined(__STDC__)
98 #define	PRId8			_MODF8 _PRId
99 #define	PRIdLEAST8		PRId8
100 #define	PRIdFAST8		PRId8
101 #endif
102 #define	PRId16			_MODF16 _PRId
103 #define	PRIdLEAST16		PRId16
104 #define	PRId32			"d"
105 #define	PRIdFAST16		PRId32
106 #define	PRIdLEAST32		PRId32
107 #define	PRIdFAST32		PRId32
108 #ifdef  _LP64
109 #define	PRId64			"ld"
110 #else   /* _ILP32 */
111 #if defined(_LONGLONG_TYPE)
112 #define	PRId64			"lld"
113 #endif
114 #endif
115 #ifdef PRId64
116 #define	PRIdLEAST64		PRId64
117 #define	PRIdFAST64		PRId64
118 #endif
119 
120 #if defined(_CHAR_IS_SIGNED) || defined(__STDC__)
121 #define	PRIi8			_MODF8 _PRIi
122 #define	PRIiLEAST8		PRIi8
123 #define	PRIiFAST8		PRIi8
124 #endif
125 #define	PRIi16			_MODF16 _PRIi
126 #define	PRIiLEAST16		PRIi16
127 #define	PRIi32			"i"
128 #define	PRIiFAST16		PRIi32
129 #define	PRIiLEAST32		PRIi32
130 #define	PRIiFAST32		PRIi32
131 #ifdef  _LP64
132 #define	PRIi64			"li"
133 #else   /* _ILP32 */
134 #if defined(_LONGLONG_TYPE)
135 #define	PRIi64			"lli"
136 #endif
137 #endif
138 #ifdef PRIi64
139 #define	PRIiLEAST64		PRIi64
140 #define	PRIiFAST64		PRIi64
141 #endif
142 
143 /*
144  * fprintf macros for unsigned integers
145  */
146 
147 #define	PRIo8			_MODF8 _PRIo
148 #define	PRIoLEAST8		PRIo8
149 #define	PRIoFAST8		PRIo8
150 #define	PRIo16			_MODF16 _PRIo
151 #define	PRIoLEAST16		PRIo16
152 #define	PRIo32			"o"
153 #define	PRIoFAST16		PRIo32
154 #define	PRIoLEAST32		PRIo32
155 #define	PRIoFAST32		PRIo32
156 #ifdef  _LP64
157 #define	PRIo64			"lo"
158 #else	/* _ILP32 */
159 #if defined(_LONGLONG_TYPE)
160 #define	PRIo64			"llo"
161 #endif
162 #endif
163 #ifdef PRIo64
164 #define	PRIoLEAST64		PRIo64
165 #define	PRIoFAST64		PRIo64
166 #endif
167 
168 #define	PRIu8			_MODF8 _PRIu
169 #define	PRIuLEAST8		PRIu8
170 #define	PRIuFAST8		PRIu8
171 #define	PRIu16			_MODF16 _PRIu
172 #define	PRIuLEAST16		PRIu16
173 #define	PRIu32			"u"
174 #define	PRIuFAST16		PRIu32
175 #define	PRIuLEAST32		PRIu32
176 #define	PRIuFAST32		PRIu32
177 #ifdef  _LP64
178 #define	PRIu64			"lu"
179 #else   /* _ILP32 */
180 #if defined(_LONGLONG_TYPE)
181 #define	PRIu64			"llu"
182 #endif
183 #endif
184 #ifdef PRIu64
185 #define	PRIuLEAST64		PRIu64
186 #define	PRIuFAST64		PRIu64
187 #endif
188 
189 #define	PRIx8			_MODF8 _PRIx
190 #define	PRIxLEAST8		PRIx8
191 #define	PRIxFAST8		PRIx8
192 #define	PRIx16			_MODF16 _PRIx
193 #define	PRIxLEAST16		PRIx16
194 #define	PRIx32			"x"
195 #define	PRIxFAST16		PRIx32
196 #define	PRIxLEAST32		PRIx32
197 #define	PRIxFAST32		PRIx32
198 #ifdef  _LP64
199 #define	PRIx64			"lx"
200 #else   /* _ILP32 */
201 #if defined(_LONGLONG_TYPE)
202 #define	PRIx64			"llx"
203 #endif
204 #endif
205 #ifdef PRIx64
206 #define	PRIxLEAST64		PRIx64
207 #define	PRIxFAST64		PRIx64
208 #endif
209 
210 #define	PRIX8			_MODF8 _PRIX
211 #define	PRIXLEAST8		PRIX8
212 #define	PRIXFAST8		PRIX8
213 #define	PRIX16			_MODF16 _PRIX
214 #define	PRIXLEAST16		PRIX16
215 #define	PRIX32			"X"
216 #define	PRIXFAST16		PRIX32
217 #define	PRIXLEAST32		PRIX32
218 #define	PRIXFAST32		PRIX32
219 #ifdef  _LP64
220 #define	PRIX64			"lX"
221 #else   /* _ILP32 */
222 #if defined(_LONGLONG_TYPE)
223 #define	PRIX64			"llX"
224 #endif
225 #endif
226 #ifdef PRIX64
227 #define	PRIXLEAST64		PRIX64
228 #define	PRIXFAST64		PRIX64
229 #endif
230 
231 /*
232  * fprintf macros for pointers
233  */
234 
235 #if defined(_LP64) || defined(_I32LPx)
236 #define	PRIdPTR			"ld"
237 #define	PRIiPTR			"li"
238 #define	PRIoPTR			"lo"
239 #define	PRIuPTR			"lu"
240 #define	PRIxPTR			"lx"
241 #define	PRIXPTR			"lX"
242 #else
243 #define	PRIdPTR			"d"
244 #define	PRIiPTR			"i"
245 #define	PRIoPTR			"o"
246 #define	PRIuPTR			"u"
247 #define	PRIxPTR			"x"
248 #define	PRIXPTR			"X"
249 #endif /* defined(_LP64) || defined(_I32LPx) */
250 
251 /*
252  * fscanf macros for signed integers
253  */
254 #if defined(_CHAR_IS_SIGNED) || defined(__STDC__)
255 #define	SCNd8			"hhd"
256 #define	SCNdLEAST8		SCNd8
257 #define	SCNdFAST8		SCNd8
258 #endif
259 #define	SCNd16			"hd"
260 #define	SCNdLEAST16		SCNd16
261 #define	SCNd32			"d"
262 #define	SCNdFAST16		SCNd32
263 #define	SCNdLEAST32		SCNd32
264 #define	SCNdFAST32		SCNd32
265 #ifdef PRId64
266 #define	SCNd64			PRId64
267 #define	SCNdLEAST64		PRId64
268 #define	SCNdFAST64		PRId64
269 #endif
270 #define	SCNdPTR			PRIdPTR
271 
272 #if defined(_CHAR_IS_SIGNED) || defined(__STDC__)
273 #define	SCNi8			"hhi"
274 #define	SCNiLEAST8		SCNi8
275 #define	SCNiFAST8		SCNi8
276 #endif
277 #define	SCNi16			"hi"
278 #define	SCNiLEAST16		SCNi16
279 #define	SCNi32			"i"
280 #define	SCNiFAST16		SCNi32
281 #define	SCNiLEAST32		SCNi32
282 #define	SCNiFAST32		SCNi32
283 #ifdef PRIi64
284 #define	SCNi64			PRIi64
285 #define	SCNiLEAST64		PRIi64
286 #define	SCNiFAST64		PRIi64
287 #endif
288 #define	SCNiPTR			PRIiPTR
289 
290 /*
291  * fscanf macros for unsigned integers
292  */
293 #define	SCNo8			"hho"
294 #define	SCNoLEAST8		SCNo8
295 #define	SCNoFAST8		SCNo8
296 #define	SCNo16			"ho"
297 #define	SCNoLEAST16		SCNo16
298 #define	SCNo32			"o"
299 #define	SCNoFAST16		SCNo32
300 #define	SCNoLEAST32		SCNo32
301 #define	SCNoFAST32		SCNo32
302 #ifdef PRIo64
303 #define	SCNo64			PRIo64
304 #define	SCNoLEAST64		PRIo64
305 #define	SCNoFAST64		PRIo64
306 #endif
307 #define	SCNoPTR			PRIoPTR
308 
309 #define	SCNu8			"hhu"
310 #define	SCNuLEAST8		SCNu8
311 #define	SCNuFAST8		SCNu8
312 #define	SCNu16			"hu"
313 #define	SCNuLEAST16		SCNu16
314 #define	SCNu32			"u"
315 #define	SCNuFAST16		SCNu32
316 #define	SCNuLEAST32		SCNu32
317 #define	SCNuFAST32		SCNu32
318 #ifdef PRIu64
319 #define	SCNu64			PRIu64
320 #define	SCNuLEAST64		PRIu64
321 #define	SCNuFAST64		PRIu64
322 #endif
323 #define	SCNuPTR			PRIuPTR
324 
325 #define	SCNx8			"hhx"
326 #define	SCNxLEAST8		SCNx8
327 #define	SCNxFAST8		SCNx8
328 #define	SCNx16			"hx"
329 #define	SCNxLEAST16		SCNx16
330 #define	SCNx32			"x"
331 #define	SCNxFAST16		SCNx32
332 #define	SCNxLEAST32		SCNx32
333 #define	SCNxFAST32		SCNx32
334 #ifdef PRIx64
335 #define	SCNx64			PRIx64
336 #define	SCNxLEAST64		PRIx64
337 #define	SCNxFAST64		PRIx64
338 #endif
339 #define	SCNxPTR			PRIxPTR
340 
341 #define	SCNX8			"hhX"
342 #define	SCNXLEAST8		SCNX8
343 #define	SCNXFAST8		SCNX8
344 #define	SCNX16			"hX"
345 #define	SCNXLEAST16		SCNX16
346 #define	SCNX32			"X"
347 #define	SCNXFAST16		SCNX32
348 #define	SCNXLEAST32		SCNX32
349 #define	SCNXFAST32		SCNX32
350 #ifdef PRIX64
351 #define	SCNX64			PRIX64
352 #define	SCNXLEAST64		PRIX64
353 #define	SCNXFAST64		PRIX64
354 #endif
355 #define	SCNXPTR			PRIXPTR
356 
357 /*
358  * The following macros define I/O formats for intmax_t and uintmax_t.
359  */
360 #if !defined(_LP64) && defined(_LONGLONG_TYPE)
361 #define	PRIdMAX			"lld"
362 #define	PRIiMAX			"lli"
363 #define	PRIoMAX			"llo"
364 #define	PRIxMAX			"llx"
365 #define	PRIuMAX			"llu"
366 #define	PRIXMAX			"llX"
367 #else
368 #define	PRIdMAX			"ld"
369 #define	PRIiMAX			"li"
370 #define	PRIoMAX			"lo"
371 #define	PRIxMAX			"lx"
372 #define	PRIuMAX			"lu"
373 #define	PRIXMAX			"lX"
374 #endif	/* !defined(_LP64) && defined(_LONGLONG_TYPE) */
375 
376 #define	SCNdMAX			PRIdMAX
377 #define	SCNiMAX			PRIiMAX
378 #define	SCNoMAX			PRIoMAX
379 #define	SCNxMAX			PRIxMAX
380 #define	SCNuMAX			PRIuMAX
381 #define	SCNXMAX			PRIXMAX
382 
383 #ifdef __cplusplus
384 }
385 #endif
386 
387 #endif /* _SYS_INT_FMTIO_H */
388