1/* $NetBSD: int_fmtio.h,v 1.4 2019/04/17 11:01:19 mrg Exp $ */
2
3/*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Klaus Klein.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _RISCV_INT_FMTIO_H_
33#define _RISCV_INT_FMTIO_H_
34
35#ifdef __INTPTR_FMTd__
36#include <sys/common_int_fmtio.h>
37#else
38/*
39 * 7.8.1 Macros for format specifiers
40 */
41
42/* fprintf macros for signed integers */
43#define PRId8 "hhd" /* int8_t */
44#define PRId16 "hd" /* int16_t */
45#define PRId32 "d" /* int32_t */
46#ifdef _LP64
47#define PRId64 "ld" /* int64_t */
48#else
49#define PRId64 "lld" /* int64_t */
50#endif
51#define PRIdLEAST8 "hhd" /* int_least8_t */
52#define PRIdLEAST16 "hd" /* int_least16_t */
53#define PRIdLEAST32 "d" /* int_least32_t */
54#ifdef _LP64
55#define PRIdLEAST64 "ld" /* int_least64_t */
56#define PRIdFAST8 "d" /* int_fast8_t */
57#define PRIdFAST16 "d" /* int_fast16_t */
58#else
59#define PRIdLEAST64 "lld" /* int_least64_t */
60#define PRIdFAST8 "hhd" /* int_fast8_t */
61#define PRIdFAST16 "hd" /* int_fast16_t */
62#endif
63#define PRIdFAST32 "d" /* int_fast32_t */
64#ifdef _LP64
65#define PRIdFAST64 "ld" /* int_fast64_t */
66#define PRIdMAX "ld" /* intmax_t */
67#else
68#define PRIdFAST64 "lld" /* int_fast64_t */
69#define PRIdMAX "lld" /* intmax_t */
70#endif
71#define PRIdPTR "ld" /* intptr_t */
72
73#define PRIi8 "hhi" /* int8_t */
74#define PRIi16 "hi" /* int16_t */
75#define PRIi32 "i" /* int32_t */
76#ifdef _LP64
77#define PRIi64 "li" /* int64_t */
78#else
79#define PRIi64 "lli" /* int64_t */
80#endif
81#define PRIiLEAST8 "hhi" /* int_least8_t */
82#define PRIiLEAST16 "hi" /* int_least16_t */
83#define PRIiLEAST32 "i" /* int_least32_t */
84#ifdef _LP64
85#define PRIiLEAST64 "li" /* int_least64_t */
86#define PRIiFAST8 "i" /* int_fast8_t */
87#define PRIiFAST16 "i" /* int_fast16_t */
88#else
89#define PRIiLEAST64 "lli" /* int_least64_t */
90#define PRIiFAST8 "hhi" /* int_fast8_t */
91#define PRIiFAST16 "hi" /* int_fast16_t */
92#endif
93#define PRIiFAST32 "i" /* int_fast32_t */
94#ifdef _LP64
95#define PRIiFAST64 "li" /* int_fast64_t */
96#define PRIiMAX "li" /* intmax_t */
97#else
98#define PRIiFAST64 "lli" /* int_fast64_t */
99#define PRIiMAX "lli" /* intmax_t */
100#endif
101#define PRIiPTR "li" /* intptr_t */
102
103/* fprintf macros for unsigned integers */
104
105#define PRIo8 "hho" /* uint8_t */
106#define PRIo16 "ho" /* uint16_t */
107#define PRIo32 "o" /* uint32_t */
108#ifdef _LP64
109#define PRIo64 "lo" /* uint64_t */
110#else
111#define PRIo64 "llo" /* uint64_t */
112#endif
113#define PRIoLEAST8 "o" /* uint_least8_t */
114#define PRIoLEAST16 "hho" /* uint_least16_t */
115#define PRIoLEAST32 "ho" /* uint_least32_t */
116#ifdef _LP64
117#define PRIoLEAST64 "lo" /* uint_least64_t */
118#define PRIoFAST8 "o" /* uint_fast8_t */
119#define PRIoFAST16 "o" /* uint_fast16_t */
120#else
121#define PRIoLEAST64 "llo" /* uint_least64_t */
122#define PRIoFAST8 "hho" /* uint_fast8_t */
123#define PRIoFAST16 "ho" /* uint_fast16_t */
124#endif
125#define PRIoFAST32 "o" /* uint_fast32_t */
126#ifdef _LP64
127#define PRIoFAST64 "lo" /* uint_fast64_t */
128#define PRIoMAX "lo" /* uintmax_t */
129#else
130#define PRIoFAST64 "llo" /* uint_fast64_t */
131#define PRIoMAX "llo" /* uintmax_t */
132#endif
133#define PRIoPTR "lo" /* uintptr_t */
134
135#define PRIu8 "hhu" /* uint8_t */
136#define PRIu16 "hu" /* uint16_t */
137#define PRIu32 "u" /* uint32_t */
138#ifdef _LP64
139#define PRIu64 "lu" /* uint64_t */
140#else
141#define PRIu64 "llu" /* uint64_t */
142#endif
143#define PRIuLEAST8 "hhu" /* uint_least8_t */
144#define PRIuLEAST16 "hu" /* uint_least16_t */
145#define PRIuLEAST32 "u" /* uint_least32_t */
146#ifdef _LP64
147#define PRIuLEAST64 "lu" /* uint_least64_t */
148#define PRIuFAST8 "u" /* uint_fast8_t */
149#define PRIuFAST16 "u" /* uint_fast16_t */
150#else
151#define PRIuLEAST64 "llu" /* uint_least64_t */
152#define PRIuFAST8 "hhu" /* uint_fast8_t */
153#define PRIuFAST16 "hu" /* uint_fast16_t */
154#endif
155#define PRIuFAST32 "u" /* uint_fast32_t */
156#ifdef _LP64
157#define PRIuFAST64 "lu" /* uint_fast64_t */
158#define PRIuMAX "lu" /* uintmax_t */
159#else
160#define PRIuFAST64 "llu" /* uint_fast64_t */
161#define PRIuMAX "llu" /* uintmax_t */
162#endif
163#define PRIuPTR "lu" /* uintptr_t */
164
165#define PRIx8 "hhx" /* uint8_t */
166#define PRIx16 "hx" /* uint16_t */
167#define PRIx32 "x" /* uint32_t */
168#ifdef _LP64
169#define PRIx64 "lx" /* uint64_t */
170#else
171#define PRIx64 "llx" /* uint64_t */
172#endif
173#define PRIxLEAST8 "x" /* uint_least8_t */
174#define PRIxLEAST16 "x" /* uint_least16_t */
175#define PRIxLEAST32 "x" /* uint_least32_t */
176#ifdef _LP64
177#define PRIxLEAST64 "lx" /* uint_least64_t */
178#define PRIxFAST8 "x" /* uint_fast8_t */
179#define PRIxFAST16 "x" /* uint_fast16_t */
180#else
181#define PRIxLEAST64 "llx" /* uint_least64_t */
182#define PRIxFAST8 "hhx" /* uint_fast8_t */
183#define PRIxFAST16 "hx" /* uint_fast16_t */
184#endif
185#define PRIxFAST32 "x" /* uint_fast32_t */
186#ifdef _LP64
187#define PRIxFAST64 "lx" /* uint_fast64_t */
188#define PRIxMAX "lx" /* uintmax_t */
189#else
190#define PRIxFAST64 "llx" /* uint_fast64_t */
191#define PRIxMAX "llx" /* uintmax_t */
192#endif
193#define PRIxPTR "lx" /* uintptr_t */
194
195#define PRIX8 "hhX" /* uint8_t */
196#define PRIX16 "hX" /* uint16_t */
197#define PRIX32 "X" /* uint32_t */
198#ifdef _LP64
199#define PRIX64 "lX" /* uint64_t */
200#else
201#define PRIX64 "llX" /* uint64_t */
202#endif
203#define PRIXLEAST8 "X" /* uint_least8_t */
204#define PRIXLEAST16 "X" /* uint_least16_t */
205#define PRIXLEAST32 "X" /* uint_least32_t */
206#ifdef _LP64
207#define PRIXLEAST64 "lX" /* uint_least64_t */
208#define PRIXFAST8 "X" /* uint_fast8_t */
209#define PRIXFAST16 "X" /* uint_fast16_t */
210#else
211#define PRIXLEAST64 "llX" /* uint_least64_t */
212#define PRIXFAST8 "hhX" /* uint_fast8_t */
213#define PRIXFAST16 "hX" /* uint_fast16_t */
214#endif
215#define PRIXFAST32 "X" /* uint_fast32_t */
216#ifdef _LP64
217#define PRIXFAST64 "lX" /* uint_fast64_t */
218#define PRIXMAX "lX" /* uintmax_t */
219#else
220#define PRIXFAST64 "llX" /* uint_fast64_t */
221#define PRIXMAX "llX" /* uintmax_t */
222#endif
223#define PRIXPTR "lX" /* uintptr_t */
224
225/* fscanf macros for signed integers */
226
227#define SCNd8 "hhd" /* int8_t */
228#define SCNd16 "hd" /* int16_t */
229#define SCNd32 "d" /* int32_t */
230#ifdef _LP64
231#define SCNd64 "ld" /* int64_t */
232#else
233#define SCNd64 "lld" /* int64_t */
234#endif
235#define SCNdLEAST8 "hhd" /* int_least8_t */
236#define SCNdLEAST16 "hd" /* int_least16_t */
237#define SCNdLEAST32 "d" /* int_least32_t */
238#ifdef _LP64
239#define SCNdLEAST64 "ld" /* int_least64_t */
240#define SCNdFAST8 "d" /* int_fast8_t */
241#define SCNdFAST16 "d" /* int_fast16_t */
242#else
243#define SCNdLEAST64 "lld" /* int_least64_t */
244#define SCNdFAST8 "hhd" /* int_fast8_t */
245#define SCNdFAST16 "hd" /* int_fast16_t */
246#endif
247#define SCNdFAST32 "d" /* int_fast32_t */
248#ifdef _LP64
249#define SCNdFAST64 "ld" /* int_fast64_t */
250#define SCNdMAX "ld" /* intmax_t */
251#else
252#define SCNdFAST64 "lld" /* int_fast64_t */
253#define SCNdMAX "lld" /* intmax_t */
254#endif
255#define SCNdPTR "ld" /* intptr_t */
256
257#define SCNi8 "hhi" /* int8_t */
258#define SCNi16 "hi" /* int16_t */
259#define SCNi32 "i" /* int32_t */
260#ifdef _LP64
261#define SCNi64 "li" /* int64_t */
262#else
263#define SCNi64 "lli" /* int64_t */
264#endif
265#define SCNiLEAST8 "hhi" /* int_least8_t */
266#define SCNiLEAST16 "hi" /* int_least16_t */
267#define SCNiLEAST32 "i" /* int_least32_t */
268#ifdef _LP64
269#define SCNiLEAST64 "li" /* int_least64_t */
270#define SCNiFAST8 "i" /* int_fast8_t */
271#define SCNiFAST16 "i" /* int_fast16_t */
272#else
273#define SCNiLEAST64 "lli" /* int_least64_t */
274#define SCNiFAST8 "hhi" /* int_fast8_t */
275#define SCNiFAST16 "hi" /* int_fast16_t */
276#endif
277#define SCNiFAST32 "i" /* int_fast32_t */
278#ifdef _LP64
279#define SCNiFAST64 "li" /* int_fast64_t */
280#define SCNiMAX "li" /* intmax_t */
281#else
282#define SCNiFAST64 "lli" /* int_fast64_t */
283#define SCNiMAX "lli" /* intmax_t */
284#endif
285#define SCNiPTR "li" /* intptr_t */
286
287/* fscanf macros for unsigned integers */
288
289#define SCNo8 "hho" /* uint8_t */
290#define SCNo16 "ho" /* uint16_t */
291#define SCNo32 "o" /* uint32_t */
292#ifdef _LP64
293#define SCNo64 "lo" /* uint64_t */
294#else
295#define SCNo64 "llo" /* uint64_t */
296#endif
297#define SCNoLEAST8 "hho" /* uint_least8_t */
298#define SCNoLEAST16 "ho" /* uint_least16_t */
299#define SCNoLEAST32 "o" /* uint_least32_t */
300#ifdef _LP64
301#define SCNoLEAST64 "lo" /* uint_least64_t */
302#define SCNoFAST8 "o" /* uint_fast8_t */
303#define SCNoFAST16 "o" /* uint_fast16_t */
304#else
305#define SCNoLEAST64 "llo" /* uint_least64_t */
306#define SCNoFAST8 "hho" /* uint_fast8_t */
307#define SCNoFAST16 "ho" /* uint_fast16_t */
308#endif
309#define SCNoFAST32 "o" /* uint_fast32_t */
310#ifdef _LP64
311#define SCNoFAST64 "lo" /* uint_fast64_t */
312#define SCNoMAX "lo" /* uintmax_t */
313#else
314#define SCNoFAST64 "llo" /* uint_fast64_t */
315#define SCNoMAX "llo" /* uintmax_t */
316#endif
317#define SCNoPTR "lo" /* uintptr_t */
318
319#define SCNu8 "hhu" /* uint8_t */
320#define SCNu16 "hu" /* uint16_t */
321#define SCNu32 "u" /* uint32_t */
322#ifdef _LP64
323#define SCNu64 "lu" /* uint64_t */
324#else
325#define SCNu64 "llu" /* uint64_t */
326#endif
327#define SCNuLEAST8 "hhu" /* uint_least8_t */
328#define SCNuLEAST16 "hu" /* uint_least16_t */
329#define SCNuLEAST32 "u" /* uint_least32_t */
330#ifdef _LP64
331#define SCNuLEAST64 "lu" /* uint_least64_t */
332#define SCNuFAST8 "u" /* uint_fast8_t */
333#define SCNuFAST16 "u" /* uint_fast16_t */
334#else
335#define SCNuLEAST64 "llu" /* uint_least64_t */
336#define SCNuFAST8 "hhu" /* uint_fast8_t */
337#define SCNuFAST16 "hu" /* uint_fast16_t */
338#endif
339#define SCNuFAST32 "u" /* uint_fast32_t */
340#ifdef _LP64
341#define SCNuFAST64 "lu" /* uint_fast64_t */
342#define SCNuMAX "lu" /* uintmax_t */
343#else
344#define SCNuFAST64 "llu" /* uint_fast64_t */
345#define SCNuMAX "llu" /* uintmax_t */
346#endif
347#define SCNuPTR "lu" /* uintptr_t */
348
349#define SCNx8 "hhx" /* uint8_t */
350#define SCNx16 "hx" /* uint16_t */
351#define SCNx32 "x" /* uint32_t */
352#ifdef _LP64
353#define SCNx64 "lx" /* uint64_t */
354#else
355#define SCNx64 "llx" /* uint64_t */
356#endif
357#define SCNxLEAST8 "hhx" /* uint_least8_t */
358#define SCNxLEAST16 "hx" /* uint_least16_t */
359#define SCNxLEAST32 "x" /* uint_least32_t */
360#ifdef _LP64
361#define SCNxLEAST64 "lx" /* uint_least64_t */
362#define SCNxFAST8 "x" /* uint_fast8_t */
363#define SCNxFAST16 "x" /* uint_fast16_t */
364#else
365#define SCNxLEAST64 "llx" /* uint_least64_t */
366#define SCNxFAST8 "hhx" /* uint_fast8_t */
367#define SCNxFAST16 "hx" /* uint_fast16_t */
368#endif
369#define SCNxFAST32 "x" /* uint_fast32_t */
370#ifdef _LP64
371#define SCNxFAST64 "lx" /* uint_fast64_t */
372#define SCNxMAX "lx" /* uintmax_t */
373#else
374#define SCNxFAST64 "llx" /* uint_fast64_t */
375#define SCNxMAX "llx" /* uintmax_t */
376#endif
377#define SCNxPTR "lx" /* uintptr_t */
378
379#endif /* !__INTPTR_FMTd__ */
380
381#endif /* !_RISCV_INT_FMTIO_H_ */