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