xref: /illumos-gate/usr/src/uts/common/sys/int_fmtio.h (revision 66c260c2dc9aa3abc53a820780d40a31b978ff0e)
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 2014 Garrett D'Amore <garrett@damore.org>
24  *
25  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #ifndef _SYS_INT_FMTIO_H
30 #define	_SYS_INT_FMTIO_H
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 #define	PRId8			_MODF8 _PRId
98 #define	PRIdLEAST8		PRId8
99 #define	PRIdFAST8		PRId8
100 #define	PRId16			_MODF16 _PRId
101 #define	PRIdLEAST16		PRId16
102 #define	PRId32			"d"
103 #define	PRIdFAST16		PRId32
104 #define	PRIdLEAST32		PRId32
105 #define	PRIdFAST32		PRId32
106 #ifdef  _LP64
107 #define	PRId64			"ld"
108 #else   /* _ILP32 */
109 #if defined(_LONGLONG_TYPE)
110 #define	PRId64			"lld"
111 #endif
112 #endif
113 #ifdef PRId64
114 #define	PRIdLEAST64		PRId64
115 #define	PRIdFAST64		PRId64
116 #endif
117 
118 #define	PRIi8			_MODF8 _PRIi
119 #define	PRIiLEAST8		PRIi8
120 #define	PRIiFAST8		PRIi8
121 #define	PRIi16			_MODF16 _PRIi
122 #define	PRIiLEAST16		PRIi16
123 #define	PRIi32			"i"
124 #define	PRIiFAST16		PRIi32
125 #define	PRIiLEAST32		PRIi32
126 #define	PRIiFAST32		PRIi32
127 #ifdef  _LP64
128 #define	PRIi64			"li"
129 #else   /* _ILP32 */
130 #if defined(_LONGLONG_TYPE)
131 #define	PRIi64			"lli"
132 #endif
133 #endif
134 #ifdef PRIi64
135 #define	PRIiLEAST64		PRIi64
136 #define	PRIiFAST64		PRIi64
137 #endif
138 
139 /*
140  * fprintf macros for unsigned integers
141  */
142 
143 #define	PRIo8			_MODF8 _PRIo
144 #define	PRIoLEAST8		PRIo8
145 #define	PRIoFAST8		PRIo8
146 #define	PRIo16			_MODF16 _PRIo
147 #define	PRIoLEAST16		PRIo16
148 #define	PRIo32			"o"
149 #define	PRIoFAST16		PRIo32
150 #define	PRIoLEAST32		PRIo32
151 #define	PRIoFAST32		PRIo32
152 #ifdef  _LP64
153 #define	PRIo64			"lo"
154 #else	/* _ILP32 */
155 #if defined(_LONGLONG_TYPE)
156 #define	PRIo64			"llo"
157 #endif
158 #endif
159 #ifdef PRIo64
160 #define	PRIoLEAST64		PRIo64
161 #define	PRIoFAST64		PRIo64
162 #endif
163 
164 #define	PRIu8			_MODF8 _PRIu
165 #define	PRIuLEAST8		PRIu8
166 #define	PRIuFAST8		PRIu8
167 #define	PRIu16			_MODF16 _PRIu
168 #define	PRIuLEAST16		PRIu16
169 #define	PRIu32			"u"
170 #define	PRIuFAST16		PRIu32
171 #define	PRIuLEAST32		PRIu32
172 #define	PRIuFAST32		PRIu32
173 #ifdef  _LP64
174 #define	PRIu64			"lu"
175 #else   /* _ILP32 */
176 #if defined(_LONGLONG_TYPE)
177 #define	PRIu64			"llu"
178 #endif
179 #endif
180 #ifdef PRIu64
181 #define	PRIuLEAST64		PRIu64
182 #define	PRIuFAST64		PRIu64
183 #endif
184 
185 #define	PRIx8			_MODF8 _PRIx
186 #define	PRIxLEAST8		PRIx8
187 #define	PRIxFAST8		PRIx8
188 #define	PRIx16			_MODF16 _PRIx
189 #define	PRIxLEAST16		PRIx16
190 #define	PRIx32			"x"
191 #define	PRIxFAST16		PRIx32
192 #define	PRIxLEAST32		PRIx32
193 #define	PRIxFAST32		PRIx32
194 #ifdef  _LP64
195 #define	PRIx64			"lx"
196 #else   /* _ILP32 */
197 #if defined(_LONGLONG_TYPE)
198 #define	PRIx64			"llx"
199 #endif
200 #endif
201 #ifdef PRIx64
202 #define	PRIxLEAST64		PRIx64
203 #define	PRIxFAST64		PRIx64
204 #endif
205 
206 #define	PRIX8			_MODF8 _PRIX
207 #define	PRIXLEAST8		PRIX8
208 #define	PRIXFAST8		PRIX8
209 #define	PRIX16			_MODF16 _PRIX
210 #define	PRIXLEAST16		PRIX16
211 #define	PRIX32			"X"
212 #define	PRIXFAST16		PRIX32
213 #define	PRIXLEAST32		PRIX32
214 #define	PRIXFAST32		PRIX32
215 #ifdef  _LP64
216 #define	PRIX64			"lX"
217 #else   /* _ILP32 */
218 #if defined(_LONGLONG_TYPE)
219 #define	PRIX64			"llX"
220 #endif
221 #endif
222 #ifdef PRIX64
223 #define	PRIXLEAST64		PRIX64
224 #define	PRIXFAST64		PRIX64
225 #endif
226 
227 /*
228  * fprintf macros for pointers
229  */
230 
231 #if defined(_LP64) || defined(_I32LPx)
232 #define	PRIdPTR			"ld"
233 #define	PRIiPTR			"li"
234 #define	PRIoPTR			"lo"
235 #define	PRIuPTR			"lu"
236 #define	PRIxPTR			"lx"
237 #define	PRIXPTR			"lX"
238 #else
239 #define	PRIdPTR			"d"
240 #define	PRIiPTR			"i"
241 #define	PRIoPTR			"o"
242 #define	PRIuPTR			"u"
243 #define	PRIxPTR			"x"
244 #define	PRIXPTR			"X"
245 #endif /* defined(_LP64) || defined(_I32LPx) */
246 
247 /*
248  * fscanf macros for signed integers
249  */
250 #define	SCNd8			"hhd"
251 #define	SCNdLEAST8		SCNd8
252 #define	SCNdFAST8		SCNd8
253 #define	SCNd16			"hd"
254 #define	SCNdLEAST16		SCNd16
255 #define	SCNd32			"d"
256 #define	SCNdFAST16		SCNd32
257 #define	SCNdLEAST32		SCNd32
258 #define	SCNdFAST32		SCNd32
259 #ifdef PRId64
260 #define	SCNd64			PRId64
261 #define	SCNdLEAST64		PRId64
262 #define	SCNdFAST64		PRId64
263 #endif
264 #define	SCNdPTR			PRIdPTR
265 
266 #define	SCNi8			"hhi"
267 #define	SCNiLEAST8		SCNi8
268 #define	SCNiFAST8		SCNi8
269 #define	SCNi16			"hi"
270 #define	SCNiLEAST16		SCNi16
271 #define	SCNi32			"i"
272 #define	SCNiFAST16		SCNi32
273 #define	SCNiLEAST32		SCNi32
274 #define	SCNiFAST32		SCNi32
275 #ifdef PRIi64
276 #define	SCNi64			PRIi64
277 #define	SCNiLEAST64		PRIi64
278 #define	SCNiFAST64		PRIi64
279 #endif
280 #define	SCNiPTR			PRIiPTR
281 
282 /*
283  * fscanf macros for unsigned integers
284  */
285 #define	SCNo8			"hho"
286 #define	SCNoLEAST8		SCNo8
287 #define	SCNoFAST8		SCNo8
288 #define	SCNo16			"ho"
289 #define	SCNoLEAST16		SCNo16
290 #define	SCNo32			"o"
291 #define	SCNoFAST16		SCNo32
292 #define	SCNoLEAST32		SCNo32
293 #define	SCNoFAST32		SCNo32
294 #ifdef PRIo64
295 #define	SCNo64			PRIo64
296 #define	SCNoLEAST64		PRIo64
297 #define	SCNoFAST64		PRIo64
298 #endif
299 #define	SCNoPTR			PRIoPTR
300 
301 #define	SCNu8			"hhu"
302 #define	SCNuLEAST8		SCNu8
303 #define	SCNuFAST8		SCNu8
304 #define	SCNu16			"hu"
305 #define	SCNuLEAST16		SCNu16
306 #define	SCNu32			"u"
307 #define	SCNuFAST16		SCNu32
308 #define	SCNuLEAST32		SCNu32
309 #define	SCNuFAST32		SCNu32
310 #ifdef PRIu64
311 #define	SCNu64			PRIu64
312 #define	SCNuLEAST64		PRIu64
313 #define	SCNuFAST64		PRIu64
314 #endif
315 #define	SCNuPTR			PRIuPTR
316 
317 #define	SCNx8			"hhx"
318 #define	SCNxLEAST8		SCNx8
319 #define	SCNxFAST8		SCNx8
320 #define	SCNx16			"hx"
321 #define	SCNxLEAST16		SCNx16
322 #define	SCNx32			"x"
323 #define	SCNxFAST16		SCNx32
324 #define	SCNxLEAST32		SCNx32
325 #define	SCNxFAST32		SCNx32
326 #ifdef PRIx64
327 #define	SCNx64			PRIx64
328 #define	SCNxLEAST64		PRIx64
329 #define	SCNxFAST64		PRIx64
330 #endif
331 #define	SCNxPTR			PRIxPTR
332 
333 #define	SCNX8			"hhX"
334 #define	SCNXLEAST8		SCNX8
335 #define	SCNXFAST8		SCNX8
336 #define	SCNX16			"hX"
337 #define	SCNXLEAST16		SCNX16
338 #define	SCNX32			"X"
339 #define	SCNXFAST16		SCNX32
340 #define	SCNXLEAST32		SCNX32
341 #define	SCNXFAST32		SCNX32
342 #ifdef PRIX64
343 #define	SCNX64			PRIX64
344 #define	SCNXLEAST64		PRIX64
345 #define	SCNXFAST64		PRIX64
346 #endif
347 #define	SCNXPTR			PRIXPTR
348 
349 /*
350  * The following macros define I/O formats for intmax_t and uintmax_t.
351  */
352 #if !defined(_LP64) && defined(_LONGLONG_TYPE)
353 #define	PRIdMAX			"lld"
354 #define	PRIiMAX			"lli"
355 #define	PRIoMAX			"llo"
356 #define	PRIxMAX			"llx"
357 #define	PRIuMAX			"llu"
358 #define	PRIXMAX			"llX"
359 #else
360 #define	PRIdMAX			"ld"
361 #define	PRIiMAX			"li"
362 #define	PRIoMAX			"lo"
363 #define	PRIxMAX			"lx"
364 #define	PRIuMAX			"lu"
365 #define	PRIXMAX			"lX"
366 #endif	/* !defined(_LP64) && defined(_LONGLONG_TYPE) */
367 
368 #define	SCNdMAX			PRIdMAX
369 #define	SCNiMAX			PRIiMAX
370 #define	SCNoMAX			PRIoMAX
371 #define	SCNxMAX			PRIxMAX
372 #define	SCNuMAX			PRIuMAX
373 #define	SCNXMAX			PRIXMAX
374 
375 /*
376  * Non-standard formatters and scanners, which are protected namespace-wise
377  * lest they become standard.  There are few good reasons to add to these,
378  * luckily.
379  *
380  * We define the full suite of formats per type, even in cases where that's
381  * not exactly useful.
382  */
383 #if !defined(_STRICT_SYMBOLS)
384 
385 /*
386  * The following macros define I/O formats for id_t, which is always 32bit but
387  * for historical reasons a real pain to format.
388  */
389 #if !defined(_LP64)
390 #define	_PRIdID			"ld"
391 #define	_PRIiID			"li"
392 #define	_PRIoID			"lo"
393 #define	_PRIxID			"lx"
394 #define	_PRIuID			"lu"
395 #define	_PRIXID			"lX"
396 #else
397 #define	_PRIdID			"d"
398 #define	_PRIiID			"i"
399 #define	_PRIoID			"o"
400 #define	_PRIxID			"x"
401 #define	_PRIuID			"u"
402 #define	_PRIXID			"X"
403 #endif
404 
405 #define	_SCNdID			_PRIdID
406 #define	_SCNiID			_PRIiID
407 #define	_SCNoID			_PRIoID
408 #define	_SCNxID			_PRIxID
409 #define	_SCNuID			_PRIuID
410 #define	_SCNXID			_PRIXID
411 
412 /*
413  * The following are set up for the wint_t and wchar_t which have the same
414  * general problem. They have the same types as above, but we use unique macros
415  * to help readers.
416  */
417 #define	_PRIdWC			_PRIdID
418 #define	_PRIiWC			_PRIiID
419 #define	_PRIoWC			_PRIoID
420 #define	_PRIxWC			_PRIxID
421 #define	_PRIuWC			_PRIuID
422 #define	_PRIXWC			_PRIXID
423 #define	_SCNdWC			_PRIdID
424 #define	_SCNiWC			_PRIiID
425 #define	_SCNoWC			_PRIoID
426 #define	_SCNxWC			_PRIxID
427 #define	_SCNuWC			_PRIuID
428 #define	_SCNXWC			_PRIXID
429 
430 
431 #endif	/* _STRICT_SYMBOLS */
432 
433 #ifdef __cplusplus
434 }
435 #endif
436 
437 #endif /* _SYS_INT_FMTIO_H */
438