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