xref: /openbmc/u-boot/include/inttypes.h (revision 3ba98ed8)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 1997-2001, 2004, 2007 Free Software Foundation, Inc.
4  *
5  * This file is taken from the GNU C Library v2.15, with the unimplemented
6  * functions removed and a few style fixes.
7  */
8 
9 /*
10  *	ISO C99: 7.8 Format conversion of integer types	<inttypes.h>
11  */
12 
13 #ifndef _INTTYPES_H
14 #define _INTTYPES_H	1
15 
16 #include <linux/compiler.h>
17 
18 /* Get a definition for wchar_t.  But we must not define wchar_t itself.  */
19 #ifndef ____gwchar_t_defined
20 # ifdef __cplusplus
21 #  define __gwchar_t wchar_t
22 # elif defined __WCHAR_TYPE__
23 typedef __WCHAR_TYPE__ __gwchar_t;
24 # else
25 #  define __need_wchar_t
26 #  include <linux/stddef.h>
27 typedef wchar_t __gwchar_t;
28 # endif
29 # define ____gwchar_t_defined	1
30 #endif
31 
32 /*
33  * The ISO C99 standard specifies that these macros must only be defined if
34  * explicitly requested
35  */
36 #if !defined __cplusplus || defined __STDC_FORMAT_MACROS
37 
38 /* linux/types.h always uses long long for 64-bit and long for uintptr_t */
39 # define __PRI64_PREFIX	"ll"
40 # define __PRIPTR_PREFIX	"l"
41 
42 /* Macros for printing format specifiers.  */
43 
44 /* Decimal notation.  */
45 # define PRId8		"d"
46 # define PRId16		"d"
47 # define PRId32		"d"
48 # define PRId64		__PRI64_PREFIX "d"
49 
50 # define PRIdLEAST8	"d"
51 # define PRIdLEAST16	"d"
52 # define PRIdLEAST32	"d"
53 # define PRIdLEAST64	__PRI64_PREFIX "d"
54 
55 # define PRIdFAST8	"d"
56 # define PRIdFAST16	__PRIPTR_PREFIX "d"
57 # define PRIdFAST32	__PRIPTR_PREFIX "d"
58 # define PRIdFAST64	__PRI64_PREFIX "d"
59 
60 # define PRIi8		"i"
61 # define PRIi16		"i"
62 # define PRIi32		"i"
63 # define PRIi64		__PRI64_PREFIX "i"
64 
65 # define PRIiLEAST8	"i"
66 # define PRIiLEAST16	"i"
67 # define PRIiLEAST32	"i"
68 # define PRIiLEAST64	__PRI64_PREFIX "i"
69 
70 # define PRIiFAST8	"i"
71 # define PRIiFAST16	__PRIPTR_PREFIX "i"
72 # define PRIiFAST32	__PRIPTR_PREFIX "i"
73 # define PRIiFAST64	__PRI64_PREFIX "i"
74 
75 /* Octal notation.  */
76 # define PRIo8		"o"
77 # define PRIo16		"o"
78 # define PRIo32		"o"
79 # define PRIo64		__PRI64_PREFIX "o"
80 
81 # define PRIoLEAST8	"o"
82 # define PRIoLEAST16	"o"
83 # define PRIoLEAST32	"o"
84 # define PRIoLEAST64	__PRI64_PREFIX "o"
85 
86 # define PRIoFAST8	"o"
87 # define PRIoFAST16	__PRIPTR_PREFIX "o"
88 # define PRIoFAST32	__PRIPTR_PREFIX "o"
89 # define PRIoFAST64	__PRI64_PREFIX "o"
90 
91 /* Unsigned integers.  */
92 # define PRIu8		"u"
93 # define PRIu16		"u"
94 # define PRIu32		"u"
95 # define PRIu64		__PRI64_PREFIX "u"
96 
97 # define PRIuLEAST8	"u"
98 # define PRIuLEAST16	"u"
99 # define PRIuLEAST32	"u"
100 # define PRIuLEAST64	__PRI64_PREFIX "u"
101 
102 # define PRIuFAST8	"u"
103 # define PRIuFAST16	__PRIPTR_PREFIX "u"
104 # define PRIuFAST32	__PRIPTR_PREFIX "u"
105 # define PRIuFAST64	__PRI64_PREFIX "u"
106 
107 /* lowercase hexadecimal notation.  */
108 # define PRIx8		"x"
109 # define PRIx16		"x"
110 # define PRIx32		"x"
111 # define PRIx64		__PRI64_PREFIX "x"
112 
113 # define PRIxLEAST8	"x"
114 # define PRIxLEAST16	"x"
115 # define PRIxLEAST32	"x"
116 # define PRIxLEAST64	__PRI64_PREFIX "x"
117 
118 # define PRIxFAST8	"x"
119 # define PRIxFAST16	__PRIPTR_PREFIX "x"
120 # define PRIxFAST32	__PRIPTR_PREFIX "x"
121 # define PRIxFAST64	__PRI64_PREFIX "x"
122 
123 /* UPPERCASE hexadecimal notation.  */
124 # define PRIX8		"X"
125 # define PRIX16		"X"
126 # define PRIX32		"X"
127 # define PRIX64		__PRI64_PREFIX "X"
128 
129 # define PRIXLEAST8	"X"
130 # define PRIXLEAST16	"X"
131 # define PRIXLEAST32	"X"
132 # define PRIXLEAST64	__PRI64_PREFIX "X"
133 
134 # define PRIXFAST8	"X"
135 # define PRIXFAST16	__PRIPTR_PREFIX "X"
136 # define PRIXFAST32	__PRIPTR_PREFIX "X"
137 # define PRIXFAST64	__PRI64_PREFIX "X"
138 
139 /* Macros for printing `intmax_t' and `uintmax_t'.  */
140 # define PRIdMAX	__PRI64_PREFIX "d"
141 # define PRIiMAX	__PRI64_PREFIX "i"
142 # define PRIoMAX	__PRI64_PREFIX "o"
143 # define PRIuMAX	__PRI64_PREFIX "u"
144 # define PRIxMAX	__PRI64_PREFIX "x"
145 # define PRIXMAX	__PRI64_PREFIX "X"
146 
147 /* Macros for printing `intptr_t' and `uintptr_t'.  */
148 # define PRIdPTR	__PRIPTR_PREFIX "d"
149 # define PRIiPTR	__PRIPTR_PREFIX "i"
150 # define PRIoPTR	__PRIPTR_PREFIX "o"
151 # define PRIuPTR	__PRIPTR_PREFIX "u"
152 # define PRIxPTR	__PRIPTR_PREFIX "x"
153 # define PRIXPTR	__PRIPTR_PREFIX "X"
154 
155 /* Macros for scanning format specifiers.  */
156 
157 /* Signed decimal notation.  */
158 # define SCNd8		"hhd"
159 # define SCNd16		"hd"
160 # define SCNd32		"d"
161 # define SCNd64		__PRI64_PREFIX "d"
162 
163 # define SCNdLEAST8	"hhd"
164 # define SCNdLEAST16	"hd"
165 # define SCNdLEAST32	"d"
166 # define SCNdLEAST64	__PRI64_PREFIX "d"
167 
168 # define SCNdFAST8	"hhd"
169 # define SCNdFAST16	__PRIPTR_PREFIX "d"
170 # define SCNdFAST32	__PRIPTR_PREFIX "d"
171 # define SCNdFAST64	__PRI64_PREFIX "d"
172 
173 /* Signed decimal notation.  */
174 # define SCNi8		"hhi"
175 # define SCNi16		"hi"
176 # define SCNi32		"i"
177 # define SCNi64		__PRI64_PREFIX "i"
178 
179 # define SCNiLEAST8	"hhi"
180 # define SCNiLEAST16	"hi"
181 # define SCNiLEAST32	"i"
182 # define SCNiLEAST64	__PRI64_PREFIX "i"
183 
184 # define SCNiFAST8	"hhi"
185 # define SCNiFAST16	__PRIPTR_PREFIX "i"
186 # define SCNiFAST32	__PRIPTR_PREFIX "i"
187 # define SCNiFAST64	__PRI64_PREFIX "i"
188 
189 /* Unsigned decimal notation.  */
190 # define SCNu8		"hhu"
191 # define SCNu16		"hu"
192 # define SCNu32		"u"
193 # define SCNu64		__PRI64_PREFIX "u"
194 
195 # define SCNuLEAST8	"hhu"
196 # define SCNuLEAST16	"hu"
197 # define SCNuLEAST32	"u"
198 # define SCNuLEAST64	__PRI64_PREFIX "u"
199 
200 # define SCNuFAST8	"hhu"
201 # define SCNuFAST16	__PRIPTR_PREFIX "u"
202 # define SCNuFAST32	__PRIPTR_PREFIX "u"
203 # define SCNuFAST64	__PRI64_PREFIX "u"
204 
205 /* Octal notation.  */
206 # define SCNo8		"hho"
207 # define SCNo16		"ho"
208 # define SCNo32		"o"
209 # define SCNo64		__PRI64_PREFIX "o"
210 
211 # define SCNoLEAST8	"hho"
212 # define SCNoLEAST16	"ho"
213 # define SCNoLEAST32	"o"
214 # define SCNoLEAST64	__PRI64_PREFIX "o"
215 
216 # define SCNoFAST8	"hho"
217 # define SCNoFAST16	__PRIPTR_PREFIX "o"
218 # define SCNoFAST32	__PRIPTR_PREFIX "o"
219 # define SCNoFAST64	__PRI64_PREFIX "o"
220 
221 /* Hexadecimal notation.  */
222 # define SCNx8		"hhx"
223 # define SCNx16		"hx"
224 # define SCNx32		"x"
225 # define SCNx64		__PRI64_PREFIX "x"
226 
227 # define SCNxLEAST8	"hhx"
228 # define SCNxLEAST16	"hx"
229 # define SCNxLEAST32	"x"
230 # define SCNxLEAST64	__PRI64_PREFIX "x"
231 
232 # define SCNxFAST8	"hhx"
233 # define SCNxFAST16	__PRIPTR_PREFIX "x"
234 # define SCNxFAST32	__PRIPTR_PREFIX "x"
235 # define SCNxFAST64	__PRI64_PREFIX "x"
236 
237 /* Macros for scanning `intmax_t' and `uintmax_t'.  */
238 # define SCNdMAX	__PRI64_PREFIX "d"
239 # define SCNiMAX	__PRI64_PREFIX "i"
240 # define SCNoMAX	__PRI64_PREFIX "o"
241 # define SCNuMAX	__PRI64_PREFIX "u"
242 # define SCNxMAX	__PRI64_PREFIX "x"
243 
244 /* Macros for scanning `intptr_t' and `uintptr_t'.  */
245 # define SCNdPTR	__PRIPTR_PREFIX "d"
246 # define SCNiPTR	__PRIPTR_PREFIX "i"
247 # define SCNoPTR	__PRIPTR_PREFIX "o"
248 # define SCNuPTR	__PRIPTR_PREFIX "u"
249 # define SCNxPTR	__PRIPTR_PREFIX "x"
250 
251 #endif	/* C++ && format macros */
252 
253 #if __WORDSIZE == 64
254 
255 /* We have to define the `uintmax_t' type using `ldiv_t'.  */
256 typedef struct {
257 	long int quot;		/* Quotient.  */
258 	long int rem;		/* Remainder.  */
259 } imaxdiv_t;
260 
261 #else
262 
263 /* We have to define the `uintmax_t' type using `lldiv_t'.  */
264 typedef struct {
265 	long long int quot;		/* Quotient.  */
266 	long long int rem;		/* Remainder.  */
267 } imaxdiv_t;
268 
269 #endif
270 
271 #endif /* inttypes.h */
272