1 /*
2 * Copyright (c) 2020 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #ifndef ZEPHYR_INCLUDE_SYS_CBPRINTF_INTERNAL_H_
8 #define ZEPHYR_INCLUDE_SYS_CBPRINTF_INTERNAL_H_
9
10 #include <errno.h>
11 #include <stdarg.h>
12 #include <stddef.h>
13 #include <stdint.h>
14 #include <zephyr/toolchain.h>
15 #include <zephyr/sys/util.h>
16 #include <zephyr/sys/__assert.h>
17 #include <zephyr/arch/cpu.h>
18
19 /*
20 * Special alignment cases
21 */
22
23 #if defined(__i386__)
24 /* there are no gaps on the stack */
25 #define VA_STACK_ALIGN(type) 1
26 #elif defined(__sparc__)
27 /* there are no gaps on the stack */
28 #define VA_STACK_ALIGN(type) 1
29 #elif defined(__x86_64__)
30 #define VA_STACK_MIN_ALIGN 8
31 #elif defined(__aarch64__)
32 #define VA_STACK_MIN_ALIGN 8
33 #elif defined(CONFIG_ARC)
34 #define VA_STACK_MIN_ALIGN ARCH_STACK_PTR_ALIGN
35 #elif defined(__riscv)
36 #ifdef CONFIG_RISCV_ISA_RV32E
37 #define VA_STACK_ALIGN(type) 4
38 #else
39 #define VA_STACK_MIN_ALIGN (__riscv_xlen / 8)
40 #endif /* CONFIG_RISCV_ISA_RV32E */
41 #endif
42
43 /*
44 * Default alignment values if not specified by architecture config
45 */
46
47 #ifndef VA_STACK_MIN_ALIGN
48 #define VA_STACK_MIN_ALIGN 1
49 #endif
50
51 #ifndef VA_STACK_ALIGN
52 #define VA_STACK_ALIGN(type) MAX(VA_STACK_MIN_ALIGN, __alignof__(type))
53 #endif
54
z_cbprintf_wcpy(int * dst,int * src,size_t len)55 static inline void z_cbprintf_wcpy(int *dst, int *src, size_t len)
56 {
57 for (size_t i = 0; i < len; i++) {
58 dst[i] = src[i];
59 }
60 }
61
62 #include <zephyr/sys/cbprintf_cxx.h>
63
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67
68
69 #if defined(__sparc__)
70 /* The SPARC V8 ABI guarantees that the arguments of a variable argument
71 * list function are stored on the stack at addresses which are 32-bit
72 * aligned. It means that variables of type unit64_t and double may not
73 * be properly aligned on the stack.
74 *
75 * The compiler is aware of the ABI and takes care of this. However,
76 * as we are directly accessing the variable argument list here, we need
77 * to take the alignment into consideration and copy 64-bit arguments
78 * as 32-bit words.
79 */
80 #define Z_CBPRINTF_VA_STACK_LL_DBL_MEMCPY 1
81 #else
82 #define Z_CBPRINTF_VA_STACK_LL_DBL_MEMCPY 0
83 #endif
84
85 /** @brief Return 1 if argument is a pointer to char or wchar_t
86 *
87 * @param x argument.
88 *
89 * @return 1 if char * or wchar_t *, 0 otherwise.
90 */
91 #ifdef __cplusplus
92 #define Z_CBPRINTF_IS_PCHAR(x, flags) \
93 z_cbprintf_cxx_is_pchar(x, (flags) & CBPRINTF_PACKAGE_CONST_CHAR_RO)
94 #else
95 /* NOLINTBEGIN(misc-redundant-expression) */
96 #define Z_CBPRINTF_IS_PCHAR(x, flags) \
97 _Generic((x) + 0, \
98 /* char * */ \
99 char * : 1, \
100 const char * : ((flags) & CBPRINTF_PACKAGE_CONST_CHAR_RO) ? 0 : 1, \
101 volatile char * : 1, \
102 const volatile char * : 1, \
103 /* unsigned char * */ \
104 unsigned char * : 1, \
105 const unsigned char * : ((flags) & CBPRINTF_PACKAGE_CONST_CHAR_RO) ? 0 : 1, \
106 volatile unsigned char * : 1, \
107 const volatile unsigned char * : 1,\
108 /* wchar_t * */ \
109 wchar_t * : 1, \
110 const wchar_t * : ((flags) & CBPRINTF_PACKAGE_CONST_CHAR_RO) ? 0 : 1, \
111 volatile wchar_t * : 1, \
112 const volatile wchar_t * : 1, \
113 default : \
114 0)
115 /* NOLINTEND(misc-redundant-expression) */
116 #endif
117
118 /** @brief Check if argument fits in 32 bit word.
119 *
120 * @param x Input argument.
121 *
122 * @retval 1 if variable is of type that fits in 32 bit word.
123 * @retval 0 if variable is of different type.
124 */
125 #ifdef __cplusplus
126 #define Z_CBPRINTF_IS_WORD_NUM(x) \
127 z_cbprintf_cxx_is_word_num(x)
128 #else
129 #define Z_CBPRINTF_IS_WORD_NUM(x) \
130 _Generic(x, \
131 char : 1, \
132 unsigned char : 1, \
133 short : 1, \
134 unsigned short : 1, \
135 int : 1, \
136 unsigned int : 1, \
137 long : sizeof(long) <= 4, \
138 unsigned long : sizeof(long) <= 4, \
139 default : \
140 0)
141 #endif
142
143 /** @brief Check if argument is a none character pointer.
144 *
145 * @note Macro triggers a pointer arithmetic warning and usage shall be wrapped in
146 * the pragma that suppresses this warning.
147 *
148 * @param x Input argument.
149 *
150 * @retval 1 if variable is a none character pointer.
151 * @retval 0 if variable is of different type.
152 */
153 #ifdef __cplusplus
154 #define Z_CBPRINTF_IS_NONE_CHAR_PTR(x) z_cbprintf_cxx_is_none_char_ptr(x)
155 #else
156 #define Z_CBPRINTF_IS_NONE_CHAR_PTR(x) \
157 _Generic((x) + 0, \
158 char * : 0, \
159 volatile char * : 0, \
160 const char * : 0, \
161 const volatile char * : 0, \
162 unsigned char * : 0, \
163 volatile unsigned char * : 0, \
164 const unsigned char * : 0, \
165 const volatile unsigned char * : 0, \
166 char: 0, \
167 unsigned char: 0, \
168 short: 0, \
169 unsigned short: 0, \
170 int: 0, \
171 unsigned int: 0,\
172 long: 0, \
173 unsigned long: 0,\
174 long long: 0, \
175 unsigned long long: 0, \
176 float: 0, \
177 double: 0, \
178 default : \
179 1)
180 #endif
181
182 /** @brief Get number of none character pointers in the string with at least 1 argument.
183 *
184 * @param ... String with at least 1 argument.
185 *
186 * @return Number of none character pointer arguments.
187 */
188 #define Z_CBPRINTF_NONE_CHAR_PTR_ARGS(...) \
189 (FOR_EACH(Z_CBPRINTF_IS_NONE_CHAR_PTR, (+), __VA_ARGS__)) \
190
191 /** @brief Get number of none character pointers in the string argument list.
192 *
193 * @param ... Format string with arguments.
194 *
195 * @return Number of none character pointer arguments.
196 */
197 #define Z_CBPRINTF_NONE_CHAR_PTR_COUNT(...) \
198 COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), \
199 (0), \
200 (Z_CBPRINTF_NONE_CHAR_PTR_ARGS(GET_ARGS_LESS_N(1, __VA_ARGS__))))
201
202 /** @brief Calculate number of pointer format specifiers in the string.
203 *
204 * If constant string is provided then result is calculated at compile time
205 * however for it is not consider constant by the compiler, e.g. can not be
206 * used in the static assert.
207 *
208 * String length is limited to 256.
209 *
210 * @param fmt Format string.
211 * @param ... String arguments.
212 *
213 * @return Number of %p format specifiers in the string.
214 */
215 #define Z_CBPRINTF_P_COUNT(fmt, ...) \
216 ((sizeof(fmt) >= 2 && fmt[0] == '%' && fmt[1] == 'p') ? 1 : 0) + \
217 ((sizeof(fmt) >= 3 && fmt[0] != '%' && fmt[1] == '%' && fmt[2] == 'p') ? 1 : 0) + \
218 ((sizeof(fmt) >= 4 && fmt[1] != '%' && fmt[2] == '%' && fmt[3] == 'p') ? 1 : 0) + \
219 ((sizeof(fmt) >= 5 && fmt[2] != '%' && fmt[3] == '%' && fmt[4] == 'p') ? 1 : 0) + \
220 ((sizeof(fmt) >= 6 && fmt[3] != '%' && fmt[4] == '%' && fmt[5] == 'p') ? 1 : 0) + \
221 ((sizeof(fmt) >= 7 && fmt[4] != '%' && fmt[5] == '%' && fmt[6] == 'p') ? 1 : 0) + \
222 ((sizeof(fmt) >= 8 && fmt[5] != '%' && fmt[6] == '%' && fmt[7] == 'p') ? 1 : 0) + \
223 ((sizeof(fmt) >= 9 && fmt[6] != '%' && fmt[7] == '%' && fmt[8] == 'p') ? 1 : 0) + \
224 ((sizeof(fmt) >= 10 && fmt[7] != '%' && fmt[8] == '%' && fmt[9] == 'p') ? 1 : 0) + \
225 ((sizeof(fmt) >= 11 && fmt[8] != '%' && fmt[9] == '%' && fmt[10] == 'p') ? 1 : 0) + \
226 ((sizeof(fmt) >= 12 && fmt[9] != '%' && fmt[10] == '%' && fmt[11] == 'p') ? 1 : 0) + \
227 ((sizeof(fmt) >= 13 && fmt[10] != '%' && fmt[11] == '%' && fmt[12] == 'p') ? 1 : 0) + \
228 ((sizeof(fmt) >= 14 && fmt[11] != '%' && fmt[12] == '%' && fmt[13] == 'p') ? 1 : 0) + \
229 ((sizeof(fmt) >= 15 && fmt[12] != '%' && fmt[13] == '%' && fmt[14] == 'p') ? 1 : 0) + \
230 ((sizeof(fmt) >= 16 && fmt[13] != '%' && fmt[14] == '%' && fmt[15] == 'p') ? 1 : 0) + \
231 ((sizeof(fmt) >= 17 && fmt[14] != '%' && fmt[15] == '%' && fmt[16] == 'p') ? 1 : 0) + \
232 ((sizeof(fmt) >= 18 && fmt[15] != '%' && fmt[16] == '%' && fmt[17] == 'p') ? 1 : 0) + \
233 ((sizeof(fmt) >= 19 && fmt[16] != '%' && fmt[17] == '%' && fmt[18] == 'p') ? 1 : 0) + \
234 ((sizeof(fmt) >= 20 && fmt[17] != '%' && fmt[18] == '%' && fmt[19] == 'p') ? 1 : 0) + \
235 ((sizeof(fmt) >= 21 && fmt[18] != '%' && fmt[19] == '%' && fmt[20] == 'p') ? 1 : 0) + \
236 ((sizeof(fmt) >= 22 && fmt[19] != '%' && fmt[20] == '%' && fmt[21] == 'p') ? 1 : 0) + \
237 ((sizeof(fmt) >= 23 && fmt[20] != '%' && fmt[21] == '%' && fmt[22] == 'p') ? 1 : 0) + \
238 ((sizeof(fmt) >= 24 && fmt[21] != '%' && fmt[22] == '%' && fmt[23] == 'p') ? 1 : 0) + \
239 ((sizeof(fmt) >= 25 && fmt[22] != '%' && fmt[23] == '%' && fmt[24] == 'p') ? 1 : 0) + \
240 ((sizeof(fmt) >= 26 && fmt[23] != '%' && fmt[24] == '%' && fmt[25] == 'p') ? 1 : 0) + \
241 ((sizeof(fmt) >= 27 && fmt[24] != '%' && fmt[25] == '%' && fmt[26] == 'p') ? 1 : 0) + \
242 ((sizeof(fmt) >= 28 && fmt[25] != '%' && fmt[26] == '%' && fmt[27] == 'p') ? 1 : 0) + \
243 ((sizeof(fmt) >= 29 && fmt[26] != '%' && fmt[27] == '%' && fmt[28] == 'p') ? 1 : 0) + \
244 ((sizeof(fmt) >= 30 && fmt[27] != '%' && fmt[28] == '%' && fmt[29] == 'p') ? 1 : 0) + \
245 ((sizeof(fmt) >= 31 && fmt[28] != '%' && fmt[29] == '%' && fmt[30] == 'p') ? 1 : 0) + \
246 ((sizeof(fmt) >= 32 && fmt[29] != '%' && fmt[30] == '%' && fmt[31] == 'p') ? 1 : 0) + \
247 ((sizeof(fmt) >= 33 && fmt[30] != '%' && fmt[31] == '%' && fmt[32] == 'p') ? 1 : 0) + \
248 ((sizeof(fmt) >= 34 && fmt[31] != '%' && fmt[32] == '%' && fmt[33] == 'p') ? 1 : 0) + \
249 ((sizeof(fmt) >= 35 && fmt[32] != '%' && fmt[33] == '%' && fmt[34] == 'p') ? 1 : 0) + \
250 ((sizeof(fmt) >= 36 && fmt[33] != '%' && fmt[34] == '%' && fmt[35] == 'p') ? 1 : 0) + \
251 ((sizeof(fmt) >= 37 && fmt[34] != '%' && fmt[35] == '%' && fmt[36] == 'p') ? 1 : 0) + \
252 ((sizeof(fmt) >= 38 && fmt[35] != '%' && fmt[36] == '%' && fmt[37] == 'p') ? 1 : 0) + \
253 ((sizeof(fmt) >= 39 && fmt[36] != '%' && fmt[37] == '%' && fmt[38] == 'p') ? 1 : 0) + \
254 ((sizeof(fmt) >= 40 && fmt[37] != '%' && fmt[38] == '%' && fmt[39] == 'p') ? 1 : 0) + \
255 ((sizeof(fmt) >= 41 && fmt[38] != '%' && fmt[39] == '%' && fmt[40] == 'p') ? 1 : 0) + \
256 ((sizeof(fmt) >= 42 && fmt[39] != '%' && fmt[40] == '%' && fmt[41] == 'p') ? 1 : 0) + \
257 ((sizeof(fmt) >= 43 && fmt[40] != '%' && fmt[41] == '%' && fmt[42] == 'p') ? 1 : 0) + \
258 ((sizeof(fmt) >= 44 && fmt[41] != '%' && fmt[42] == '%' && fmt[43] == 'p') ? 1 : 0) + \
259 ((sizeof(fmt) >= 45 && fmt[42] != '%' && fmt[43] == '%' && fmt[44] == 'p') ? 1 : 0) + \
260 ((sizeof(fmt) >= 46 && fmt[43] != '%' && fmt[44] == '%' && fmt[45] == 'p') ? 1 : 0) + \
261 ((sizeof(fmt) >= 47 && fmt[44] != '%' && fmt[45] == '%' && fmt[46] == 'p') ? 1 : 0) + \
262 ((sizeof(fmt) >= 48 && fmt[45] != '%' && fmt[46] == '%' && fmt[47] == 'p') ? 1 : 0) + \
263 ((sizeof(fmt) >= 49 && fmt[46] != '%' && fmt[47] == '%' && fmt[48] == 'p') ? 1 : 0) + \
264 ((sizeof(fmt) >= 50 && fmt[47] != '%' && fmt[48] == '%' && fmt[49] == 'p') ? 1 : 0) + \
265 ((sizeof(fmt) >= 51 && fmt[48] != '%' && fmt[49] == '%' && fmt[50] == 'p') ? 1 : 0) + \
266 ((sizeof(fmt) >= 52 && fmt[49] != '%' && fmt[50] == '%' && fmt[51] == 'p') ? 1 : 0) + \
267 ((sizeof(fmt) >= 53 && fmt[50] != '%' && fmt[51] == '%' && fmt[52] == 'p') ? 1 : 0) + \
268 ((sizeof(fmt) >= 54 && fmt[51] != '%' && fmt[52] == '%' && fmt[53] == 'p') ? 1 : 0) + \
269 ((sizeof(fmt) >= 55 && fmt[52] != '%' && fmt[53] == '%' && fmt[54] == 'p') ? 1 : 0) + \
270 ((sizeof(fmt) >= 56 && fmt[53] != '%' && fmt[54] == '%' && fmt[55] == 'p') ? 1 : 0) + \
271 ((sizeof(fmt) >= 57 && fmt[54] != '%' && fmt[55] == '%' && fmt[56] == 'p') ? 1 : 0) + \
272 ((sizeof(fmt) >= 58 && fmt[55] != '%' && fmt[56] == '%' && fmt[57] == 'p') ? 1 : 0) + \
273 ((sizeof(fmt) >= 59 && fmt[56] != '%' && fmt[57] == '%' && fmt[58] == 'p') ? 1 : 0) + \
274 ((sizeof(fmt) >= 60 && fmt[57] != '%' && fmt[58] == '%' && fmt[59] == 'p') ? 1 : 0) + \
275 ((sizeof(fmt) >= 61 && fmt[58] != '%' && fmt[59] == '%' && fmt[60] == 'p') ? 1 : 0) + \
276 ((sizeof(fmt) >= 62 && fmt[59] != '%' && fmt[60] == '%' && fmt[61] == 'p') ? 1 : 0) + \
277 ((sizeof(fmt) >= 63 && fmt[60] != '%' && fmt[61] == '%' && fmt[62] == 'p') ? 1 : 0) + \
278 ((sizeof(fmt) >= 64 && fmt[61] != '%' && fmt[62] == '%' && fmt[63] == 'p') ? 1 : 0) + \
279 ((sizeof(fmt) >= 65 && fmt[62] != '%' && fmt[63] == '%' && fmt[64] == 'p') ? 1 : 0) + \
280 ((sizeof(fmt) >= 66 && fmt[63] != '%' && fmt[64] == '%' && fmt[65] == 'p') ? 1 : 0) + \
281 ((sizeof(fmt) >= 67 && fmt[64] != '%' && fmt[65] == '%' && fmt[66] == 'p') ? 1 : 0) + \
282 ((sizeof(fmt) >= 68 && fmt[65] != '%' && fmt[66] == '%' && fmt[67] == 'p') ? 1 : 0) + \
283 ((sizeof(fmt) >= 69 && fmt[66] != '%' && fmt[67] == '%' && fmt[68] == 'p') ? 1 : 0) + \
284 ((sizeof(fmt) >= 70 && fmt[67] != '%' && fmt[68] == '%' && fmt[69] == 'p') ? 1 : 0) + \
285 ((sizeof(fmt) >= 71 && fmt[68] != '%' && fmt[69] == '%' && fmt[70] == 'p') ? 1 : 0) + \
286 ((sizeof(fmt) >= 72 && fmt[69] != '%' && fmt[70] == '%' && fmt[71] == 'p') ? 1 : 0) + \
287 ((sizeof(fmt) >= 73 && fmt[70] != '%' && fmt[71] == '%' && fmt[72] == 'p') ? 1 : 0) + \
288 ((sizeof(fmt) >= 74 && fmt[71] != '%' && fmt[72] == '%' && fmt[73] == 'p') ? 1 : 0) + \
289 ((sizeof(fmt) >= 75 && fmt[72] != '%' && fmt[73] == '%' && fmt[74] == 'p') ? 1 : 0) + \
290 ((sizeof(fmt) >= 76 && fmt[73] != '%' && fmt[74] == '%' && fmt[75] == 'p') ? 1 : 0) + \
291 ((sizeof(fmt) >= 77 && fmt[74] != '%' && fmt[75] == '%' && fmt[76] == 'p') ? 1 : 0) + \
292 ((sizeof(fmt) >= 78 && fmt[75] != '%' && fmt[76] == '%' && fmt[77] == 'p') ? 1 : 0) + \
293 ((sizeof(fmt) >= 79 && fmt[76] != '%' && fmt[77] == '%' && fmt[78] == 'p') ? 1 : 0) + \
294 ((sizeof(fmt) >= 80 && fmt[77] != '%' && fmt[78] == '%' && fmt[79] == 'p') ? 1 : 0) + \
295 ((sizeof(fmt) >= 81 && fmt[78] != '%' && fmt[79] == '%' && fmt[80] == 'p') ? 1 : 0) + \
296 ((sizeof(fmt) >= 82 && fmt[79] != '%' && fmt[80] == '%' && fmt[81] == 'p') ? 1 : 0) + \
297 ((sizeof(fmt) >= 83 && fmt[80] != '%' && fmt[81] == '%' && fmt[82] == 'p') ? 1 : 0) + \
298 ((sizeof(fmt) >= 84 && fmt[81] != '%' && fmt[82] == '%' && fmt[83] == 'p') ? 1 : 0) + \
299 ((sizeof(fmt) >= 85 && fmt[82] != '%' && fmt[83] == '%' && fmt[84] == 'p') ? 1 : 0) + \
300 ((sizeof(fmt) >= 86 && fmt[83] != '%' && fmt[84] == '%' && fmt[85] == 'p') ? 1 : 0) + \
301 ((sizeof(fmt) >= 87 && fmt[84] != '%' && fmt[85] == '%' && fmt[86] == 'p') ? 1 : 0) + \
302 ((sizeof(fmt) >= 88 && fmt[85] != '%' && fmt[86] == '%' && fmt[87] == 'p') ? 1 : 0) + \
303 ((sizeof(fmt) >= 89 && fmt[86] != '%' && fmt[87] == '%' && fmt[88] == 'p') ? 1 : 0) + \
304 ((sizeof(fmt) >= 90 && fmt[87] != '%' && fmt[88] == '%' && fmt[89] == 'p') ? 1 : 0) + \
305 ((sizeof(fmt) >= 91 && fmt[88] != '%' && fmt[89] == '%' && fmt[90] == 'p') ? 1 : 0) + \
306 ((sizeof(fmt) >= 92 && fmt[89] != '%' && fmt[90] == '%' && fmt[91] == 'p') ? 1 : 0) + \
307 ((sizeof(fmt) >= 93 && fmt[90] != '%' && fmt[91] == '%' && fmt[92] == 'p') ? 1 : 0) + \
308 ((sizeof(fmt) >= 94 && fmt[91] != '%' && fmt[92] == '%' && fmt[93] == 'p') ? 1 : 0) + \
309 ((sizeof(fmt) >= 95 && fmt[92] != '%' && fmt[93] == '%' && fmt[94] == 'p') ? 1 : 0) + \
310 ((sizeof(fmt) >= 96 && fmt[93] != '%' && fmt[94] == '%' && fmt[95] == 'p') ? 1 : 0) + \
311 ((sizeof(fmt) >= 97 && fmt[94] != '%' && fmt[95] == '%' && fmt[96] == 'p') ? 1 : 0) + \
312 ((sizeof(fmt) >= 98 && fmt[95] != '%' && fmt[96] == '%' && fmt[97] == 'p') ? 1 : 0) + \
313 ((sizeof(fmt) >= 99 && fmt[96] != '%' && fmt[97] == '%' && fmt[98] == 'p') ? 1 : 0) + \
314 ((sizeof(fmt) >= 100 && fmt[97] != '%' && fmt[98] == '%' && fmt[99] == 'p') ? 1 : 0) + \
315 ((sizeof(fmt) >= 101 && fmt[98] != '%' && fmt[99] == '%' && fmt[100] == 'p') ? 1 : 0) + \
316 ((sizeof(fmt) >= 102 && fmt[99] != '%' && fmt[100] == '%' && fmt[101] == 'p') ? 1 : 0) + \
317 ((sizeof(fmt) >= 103 && fmt[100] != '%' && fmt[101] == '%' && fmt[102] == 'p') ? 1 : 0) + \
318 ((sizeof(fmt) >= 104 && fmt[101] != '%' && fmt[102] == '%' && fmt[103] == 'p') ? 1 : 0) + \
319 ((sizeof(fmt) >= 105 && fmt[102] != '%' && fmt[103] == '%' && fmt[104] == 'p') ? 1 : 0) + \
320 ((sizeof(fmt) >= 106 && fmt[103] != '%' && fmt[104] == '%' && fmt[105] == 'p') ? 1 : 0) + \
321 ((sizeof(fmt) >= 107 && fmt[104] != '%' && fmt[105] == '%' && fmt[106] == 'p') ? 1 : 0) + \
322 ((sizeof(fmt) >= 108 && fmt[105] != '%' && fmt[106] == '%' && fmt[107] == 'p') ? 1 : 0) + \
323 ((sizeof(fmt) >= 109 && fmt[106] != '%' && fmt[107] == '%' && fmt[108] == 'p') ? 1 : 0) + \
324 ((sizeof(fmt) >= 110 && fmt[107] != '%' && fmt[108] == '%' && fmt[109] == 'p') ? 1 : 0) + \
325 ((sizeof(fmt) >= 111 && fmt[108] != '%' && fmt[109] == '%' && fmt[110] == 'p') ? 1 : 0) + \
326 ((sizeof(fmt) >= 112 && fmt[109] != '%' && fmt[110] == '%' && fmt[111] == 'p') ? 1 : 0) + \
327 ((sizeof(fmt) >= 113 && fmt[110] != '%' && fmt[111] == '%' && fmt[112] == 'p') ? 1 : 0) + \
328 ((sizeof(fmt) >= 114 && fmt[111] != '%' && fmt[112] == '%' && fmt[113] == 'p') ? 1 : 0) + \
329 ((sizeof(fmt) >= 115 && fmt[112] != '%' && fmt[113] == '%' && fmt[114] == 'p') ? 1 : 0) + \
330 ((sizeof(fmt) >= 116 && fmt[113] != '%' && fmt[114] == '%' && fmt[115] == 'p') ? 1 : 0) + \
331 ((sizeof(fmt) >= 117 && fmt[114] != '%' && fmt[115] == '%' && fmt[116] == 'p') ? 1 : 0) + \
332 ((sizeof(fmt) >= 118 && fmt[115] != '%' && fmt[116] == '%' && fmt[117] == 'p') ? 1 : 0) + \
333 ((sizeof(fmt) >= 119 && fmt[116] != '%' && fmt[117] == '%' && fmt[118] == 'p') ? 1 : 0) + \
334 ((sizeof(fmt) >= 120 && fmt[117] != '%' && fmt[118] == '%' && fmt[119] == 'p') ? 1 : 0) + \
335 ((sizeof(fmt) >= 121 && fmt[118] != '%' && fmt[119] == '%' && fmt[120] == 'p') ? 1 : 0) + \
336 ((sizeof(fmt) >= 122 && fmt[119] != '%' && fmt[120] == '%' && fmt[121] == 'p') ? 1 : 0) + \
337 ((sizeof(fmt) >= 123 && fmt[120] != '%' && fmt[121] == '%' && fmt[122] == 'p') ? 1 : 0) + \
338 ((sizeof(fmt) >= 124 && fmt[121] != '%' && fmt[122] == '%' && fmt[123] == 'p') ? 1 : 0) + \
339 ((sizeof(fmt) >= 125 && fmt[122] != '%' && fmt[123] == '%' && fmt[124] == 'p') ? 1 : 0) + \
340 ((sizeof(fmt) >= 126 && fmt[123] != '%' && fmt[124] == '%' && fmt[125] == 'p') ? 1 : 0) + \
341 ((sizeof(fmt) >= 127 && fmt[124] != '%' && fmt[125] == '%' && fmt[126] == 'p') ? 1 : 0) + \
342 ((sizeof(fmt) >= 128 && fmt[125] != '%' && fmt[126] == '%' && fmt[127] == 'p') ? 1 : 0) + \
343 ((sizeof(fmt) >= 129 && fmt[126] != '%' && fmt[127] == '%' && fmt[128] == 'p') ? 1 : 0) + \
344 ((sizeof(fmt) >= 130 && fmt[127] != '%' && fmt[128] == '%' && fmt[129] == 'p') ? 1 : 0) + \
345 ((sizeof(fmt) >= 131 && fmt[128] != '%' && fmt[129] == '%' && fmt[130] == 'p') ? 1 : 0) + \
346 ((sizeof(fmt) >= 132 && fmt[129] != '%' && fmt[130] == '%' && fmt[131] == 'p') ? 1 : 0) + \
347 ((sizeof(fmt) >= 133 && fmt[130] != '%' && fmt[131] == '%' && fmt[132] == 'p') ? 1 : 0) + \
348 ((sizeof(fmt) >= 134 && fmt[131] != '%' && fmt[132] == '%' && fmt[133] == 'p') ? 1 : 0) + \
349 ((sizeof(fmt) >= 135 && fmt[132] != '%' && fmt[133] == '%' && fmt[134] == 'p') ? 1 : 0) + \
350 ((sizeof(fmt) >= 136 && fmt[133] != '%' && fmt[134] == '%' && fmt[135] == 'p') ? 1 : 0) + \
351 ((sizeof(fmt) >= 137 && fmt[134] != '%' && fmt[135] == '%' && fmt[136] == 'p') ? 1 : 0) + \
352 ((sizeof(fmt) >= 138 && fmt[135] != '%' && fmt[136] == '%' && fmt[137] == 'p') ? 1 : 0) + \
353 ((sizeof(fmt) >= 139 && fmt[136] != '%' && fmt[137] == '%' && fmt[138] == 'p') ? 1 : 0) + \
354 ((sizeof(fmt) >= 140 && fmt[137] != '%' && fmt[138] == '%' && fmt[139] == 'p') ? 1 : 0) + \
355 ((sizeof(fmt) >= 141 && fmt[138] != '%' && fmt[139] == '%' && fmt[140] == 'p') ? 1 : 0) + \
356 ((sizeof(fmt) >= 142 && fmt[139] != '%' && fmt[140] == '%' && fmt[141] == 'p') ? 1 : 0) + \
357 ((sizeof(fmt) >= 143 && fmt[140] != '%' && fmt[141] == '%' && fmt[142] == 'p') ? 1 : 0) + \
358 ((sizeof(fmt) >= 144 && fmt[141] != '%' && fmt[142] == '%' && fmt[143] == 'p') ? 1 : 0) + \
359 ((sizeof(fmt) >= 145 && fmt[142] != '%' && fmt[143] == '%' && fmt[144] == 'p') ? 1 : 0) + \
360 ((sizeof(fmt) >= 146 && fmt[143] != '%' && fmt[144] == '%' && fmt[145] == 'p') ? 1 : 0) + \
361 ((sizeof(fmt) >= 147 && fmt[144] != '%' && fmt[145] == '%' && fmt[146] == 'p') ? 1 : 0) + \
362 ((sizeof(fmt) >= 148 && fmt[145] != '%' && fmt[146] == '%' && fmt[147] == 'p') ? 1 : 0) + \
363 ((sizeof(fmt) >= 149 && fmt[146] != '%' && fmt[147] == '%' && fmt[148] == 'p') ? 1 : 0) + \
364 ((sizeof(fmt) >= 150 && fmt[147] != '%' && fmt[148] == '%' && fmt[149] == 'p') ? 1 : 0) + \
365 ((sizeof(fmt) >= 151 && fmt[148] != '%' && fmt[149] == '%' && fmt[150] == 'p') ? 1 : 0) + \
366 ((sizeof(fmt) >= 152 && fmt[149] != '%' && fmt[150] == '%' && fmt[151] == 'p') ? 1 : 0) + \
367 ((sizeof(fmt) >= 153 && fmt[150] != '%' && fmt[151] == '%' && fmt[152] == 'p') ? 1 : 0) + \
368 ((sizeof(fmt) >= 154 && fmt[151] != '%' && fmt[152] == '%' && fmt[153] == 'p') ? 1 : 0) + \
369 ((sizeof(fmt) >= 155 && fmt[152] != '%' && fmt[153] == '%' && fmt[154] == 'p') ? 1 : 0) + \
370 ((sizeof(fmt) >= 156 && fmt[153] != '%' && fmt[154] == '%' && fmt[155] == 'p') ? 1 : 0) + \
371 ((sizeof(fmt) >= 157 && fmt[154] != '%' && fmt[155] == '%' && fmt[156] == 'p') ? 1 : 0) + \
372 ((sizeof(fmt) >= 158 && fmt[155] != '%' && fmt[156] == '%' && fmt[157] == 'p') ? 1 : 0) + \
373 ((sizeof(fmt) >= 159 && fmt[156] != '%' && fmt[157] == '%' && fmt[158] == 'p') ? 1 : 0) + \
374 ((sizeof(fmt) >= 160 && fmt[157] != '%' && fmt[158] == '%' && fmt[159] == 'p') ? 1 : 0) + \
375 ((sizeof(fmt) >= 161 && fmt[158] != '%' && fmt[159] == '%' && fmt[160] == 'p') ? 1 : 0) + \
376 ((sizeof(fmt) >= 162 && fmt[159] != '%' && fmt[160] == '%' && fmt[161] == 'p') ? 1 : 0) + \
377 ((sizeof(fmt) >= 163 && fmt[160] != '%' && fmt[161] == '%' && fmt[162] == 'p') ? 1 : 0) + \
378 ((sizeof(fmt) >= 164 && fmt[161] != '%' && fmt[162] == '%' && fmt[163] == 'p') ? 1 : 0) + \
379 ((sizeof(fmt) >= 165 && fmt[162] != '%' && fmt[163] == '%' && fmt[164] == 'p') ? 1 : 0) + \
380 ((sizeof(fmt) >= 166 && fmt[163] != '%' && fmt[164] == '%' && fmt[165] == 'p') ? 1 : 0) + \
381 ((sizeof(fmt) >= 167 && fmt[164] != '%' && fmt[165] == '%' && fmt[166] == 'p') ? 1 : 0) + \
382 ((sizeof(fmt) >= 168 && fmt[165] != '%' && fmt[166] == '%' && fmt[167] == 'p') ? 1 : 0) + \
383 ((sizeof(fmt) >= 169 && fmt[166] != '%' && fmt[167] == '%' && fmt[168] == 'p') ? 1 : 0) + \
384 ((sizeof(fmt) >= 170 && fmt[167] != '%' && fmt[168] == '%' && fmt[169] == 'p') ? 1 : 0) + \
385 ((sizeof(fmt) >= 171 && fmt[168] != '%' && fmt[169] == '%' && fmt[170] == 'p') ? 1 : 0) + \
386 ((sizeof(fmt) >= 172 && fmt[169] != '%' && fmt[170] == '%' && fmt[171] == 'p') ? 1 : 0) + \
387 ((sizeof(fmt) >= 173 && fmt[170] != '%' && fmt[171] == '%' && fmt[172] == 'p') ? 1 : 0) + \
388 ((sizeof(fmt) >= 174 && fmt[171] != '%' && fmt[172] == '%' && fmt[173] == 'p') ? 1 : 0) + \
389 ((sizeof(fmt) >= 175 && fmt[172] != '%' && fmt[173] == '%' && fmt[174] == 'p') ? 1 : 0) + \
390 ((sizeof(fmt) >= 176 && fmt[173] != '%' && fmt[174] == '%' && fmt[175] == 'p') ? 1 : 0) + \
391 ((sizeof(fmt) >= 177 && fmt[174] != '%' && fmt[175] == '%' && fmt[176] == 'p') ? 1 : 0) + \
392 ((sizeof(fmt) >= 178 && fmt[175] != '%' && fmt[176] == '%' && fmt[177] == 'p') ? 1 : 0) + \
393 ((sizeof(fmt) >= 179 && fmt[176] != '%' && fmt[177] == '%' && fmt[178] == 'p') ? 1 : 0) + \
394 ((sizeof(fmt) >= 180 && fmt[177] != '%' && fmt[178] == '%' && fmt[179] == 'p') ? 1 : 0) + \
395 ((sizeof(fmt) >= 181 && fmt[178] != '%' && fmt[179] == '%' && fmt[180] == 'p') ? 1 : 0) + \
396 ((sizeof(fmt) >= 182 && fmt[179] != '%' && fmt[180] == '%' && fmt[181] == 'p') ? 1 : 0) + \
397 ((sizeof(fmt) >= 183 && fmt[180] != '%' && fmt[181] == '%' && fmt[182] == 'p') ? 1 : 0) + \
398 ((sizeof(fmt) >= 184 && fmt[181] != '%' && fmt[182] == '%' && fmt[183] == 'p') ? 1 : 0) + \
399 ((sizeof(fmt) >= 185 && fmt[182] != '%' && fmt[183] == '%' && fmt[184] == 'p') ? 1 : 0) + \
400 ((sizeof(fmt) >= 186 && fmt[183] != '%' && fmt[184] == '%' && fmt[185] == 'p') ? 1 : 0) + \
401 ((sizeof(fmt) >= 187 && fmt[184] != '%' && fmt[185] == '%' && fmt[186] == 'p') ? 1 : 0) + \
402 ((sizeof(fmt) >= 188 && fmt[185] != '%' && fmt[186] == '%' && fmt[187] == 'p') ? 1 : 0) + \
403 ((sizeof(fmt) >= 189 && fmt[186] != '%' && fmt[187] == '%' && fmt[188] == 'p') ? 1 : 0) + \
404 ((sizeof(fmt) >= 190 && fmt[187] != '%' && fmt[188] == '%' && fmt[189] == 'p') ? 1 : 0) + \
405 ((sizeof(fmt) >= 191 && fmt[188] != '%' && fmt[189] == '%' && fmt[190] == 'p') ? 1 : 0) + \
406 ((sizeof(fmt) >= 192 && fmt[189] != '%' && fmt[190] == '%' && fmt[191] == 'p') ? 1 : 0) + \
407 ((sizeof(fmt) >= 193 && fmt[190] != '%' && fmt[191] == '%' && fmt[192] == 'p') ? 1 : 0) + \
408 ((sizeof(fmt) >= 194 && fmt[191] != '%' && fmt[192] == '%' && fmt[193] == 'p') ? 1 : 0) + \
409 ((sizeof(fmt) >= 195 && fmt[192] != '%' && fmt[193] == '%' && fmt[194] == 'p') ? 1 : 0) + \
410 ((sizeof(fmt) >= 196 && fmt[193] != '%' && fmt[194] == '%' && fmt[195] == 'p') ? 1 : 0) + \
411 ((sizeof(fmt) >= 197 && fmt[194] != '%' && fmt[195] == '%' && fmt[196] == 'p') ? 1 : 0) + \
412 ((sizeof(fmt) >= 198 && fmt[195] != '%' && fmt[196] == '%' && fmt[197] == 'p') ? 1 : 0) + \
413 ((sizeof(fmt) >= 199 && fmt[196] != '%' && fmt[197] == '%' && fmt[198] == 'p') ? 1 : 0) + \
414 ((sizeof(fmt) >= 200 && fmt[197] != '%' && fmt[198] == '%' && fmt[199] == 'p') ? 1 : 0) + \
415 ((sizeof(fmt) >= 201 && fmt[198] != '%' && fmt[199] == '%' && fmt[200] == 'p') ? 1 : 0) + \
416 ((sizeof(fmt) >= 202 && fmt[199] != '%' && fmt[200] == '%' && fmt[201] == 'p') ? 1 : 0) + \
417 ((sizeof(fmt) >= 203 && fmt[200] != '%' && fmt[201] == '%' && fmt[202] == 'p') ? 1 : 0) + \
418 ((sizeof(fmt) >= 204 && fmt[201] != '%' && fmt[202] == '%' && fmt[203] == 'p') ? 1 : 0) + \
419 ((sizeof(fmt) >= 205 && fmt[202] != '%' && fmt[203] == '%' && fmt[204] == 'p') ? 1 : 0) + \
420 ((sizeof(fmt) >= 206 && fmt[203] != '%' && fmt[204] == '%' && fmt[205] == 'p') ? 1 : 0) + \
421 ((sizeof(fmt) >= 207 && fmt[204] != '%' && fmt[205] == '%' && fmt[206] == 'p') ? 1 : 0) + \
422 ((sizeof(fmt) >= 208 && fmt[205] != '%' && fmt[206] == '%' && fmt[207] == 'p') ? 1 : 0) + \
423 ((sizeof(fmt) >= 209 && fmt[206] != '%' && fmt[207] == '%' && fmt[208] == 'p') ? 1 : 0) + \
424 ((sizeof(fmt) >= 210 && fmt[207] != '%' && fmt[208] == '%' && fmt[209] == 'p') ? 1 : 0) + \
425 ((sizeof(fmt) >= 211 && fmt[208] != '%' && fmt[209] == '%' && fmt[210] == 'p') ? 1 : 0) + \
426 ((sizeof(fmt) >= 212 && fmt[209] != '%' && fmt[210] == '%' && fmt[211] == 'p') ? 1 : 0) + \
427 ((sizeof(fmt) >= 213 && fmt[210] != '%' && fmt[211] == '%' && fmt[212] == 'p') ? 1 : 0) + \
428 ((sizeof(fmt) >= 214 && fmt[211] != '%' && fmt[212] == '%' && fmt[213] == 'p') ? 1 : 0) + \
429 ((sizeof(fmt) >= 215 && fmt[212] != '%' && fmt[213] == '%' && fmt[214] == 'p') ? 1 : 0) + \
430 ((sizeof(fmt) >= 216 && fmt[213] != '%' && fmt[214] == '%' && fmt[215] == 'p') ? 1 : 0) + \
431 ((sizeof(fmt) >= 217 && fmt[214] != '%' && fmt[215] == '%' && fmt[216] == 'p') ? 1 : 0) + \
432 ((sizeof(fmt) >= 218 && fmt[215] != '%' && fmt[216] == '%' && fmt[217] == 'p') ? 1 : 0) + \
433 ((sizeof(fmt) >= 219 && fmt[216] != '%' && fmt[217] == '%' && fmt[218] == 'p') ? 1 : 0) + \
434 ((sizeof(fmt) >= 220 && fmt[217] != '%' && fmt[218] == '%' && fmt[219] == 'p') ? 1 : 0) + \
435 ((sizeof(fmt) >= 221 && fmt[218] != '%' && fmt[219] == '%' && fmt[220] == 'p') ? 1 : 0) + \
436 ((sizeof(fmt) >= 222 && fmt[219] != '%' && fmt[220] == '%' && fmt[221] == 'p') ? 1 : 0) + \
437 ((sizeof(fmt) >= 223 && fmt[220] != '%' && fmt[221] == '%' && fmt[222] == 'p') ? 1 : 0) + \
438 ((sizeof(fmt) >= 224 && fmt[221] != '%' && fmt[222] == '%' && fmt[223] == 'p') ? 1 : 0) + \
439 ((sizeof(fmt) >= 225 && fmt[222] != '%' && fmt[223] == '%' && fmt[224] == 'p') ? 1 : 0) + \
440 ((sizeof(fmt) >= 226 && fmt[223] != '%' && fmt[224] == '%' && fmt[225] == 'p') ? 1 : 0) + \
441 ((sizeof(fmt) >= 227 && fmt[224] != '%' && fmt[225] == '%' && fmt[226] == 'p') ? 1 : 0) + \
442 ((sizeof(fmt) >= 228 && fmt[225] != '%' && fmt[226] == '%' && fmt[227] == 'p') ? 1 : 0) + \
443 ((sizeof(fmt) >= 229 && fmt[226] != '%' && fmt[227] == '%' && fmt[228] == 'p') ? 1 : 0) + \
444 ((sizeof(fmt) >= 230 && fmt[227] != '%' && fmt[228] == '%' && fmt[229] == 'p') ? 1 : 0) + \
445 ((sizeof(fmt) >= 231 && fmt[228] != '%' && fmt[229] == '%' && fmt[230] == 'p') ? 1 : 0) + \
446 ((sizeof(fmt) >= 232 && fmt[229] != '%' && fmt[230] == '%' && fmt[231] == 'p') ? 1 : 0) + \
447 ((sizeof(fmt) >= 233 && fmt[230] != '%' && fmt[231] == '%' && fmt[232] == 'p') ? 1 : 0) + \
448 ((sizeof(fmt) >= 234 && fmt[231] != '%' && fmt[232] == '%' && fmt[233] == 'p') ? 1 : 0) + \
449 ((sizeof(fmt) >= 235 && fmt[232] != '%' && fmt[233] == '%' && fmt[234] == 'p') ? 1 : 0) + \
450 ((sizeof(fmt) >= 236 && fmt[233] != '%' && fmt[234] == '%' && fmt[235] == 'p') ? 1 : 0) + \
451 ((sizeof(fmt) >= 237 && fmt[234] != '%' && fmt[235] == '%' && fmt[236] == 'p') ? 1 : 0) + \
452 ((sizeof(fmt) >= 238 && fmt[235] != '%' && fmt[236] == '%' && fmt[237] == 'p') ? 1 : 0) + \
453 ((sizeof(fmt) >= 239 && fmt[236] != '%' && fmt[237] == '%' && fmt[238] == 'p') ? 1 : 0) + \
454 ((sizeof(fmt) >= 240 && fmt[237] != '%' && fmt[238] == '%' && fmt[239] == 'p') ? 1 : 0) + \
455 ((sizeof(fmt) >= 241 && fmt[238] != '%' && fmt[239] == '%' && fmt[240] == 'p') ? 1 : 0) + \
456 ((sizeof(fmt) >= 242 && fmt[239] != '%' && fmt[240] == '%' && fmt[241] == 'p') ? 1 : 0) + \
457 ((sizeof(fmt) >= 243 && fmt[240] != '%' && fmt[241] == '%' && fmt[242] == 'p') ? 1 : 0) + \
458 ((sizeof(fmt) >= 244 && fmt[241] != '%' && fmt[242] == '%' && fmt[243] == 'p') ? 1 : 0) + \
459 ((sizeof(fmt) >= 245 && fmt[242] != '%' && fmt[243] == '%' && fmt[244] == 'p') ? 1 : 0) + \
460 ((sizeof(fmt) >= 246 && fmt[243] != '%' && fmt[244] == '%' && fmt[245] == 'p') ? 1 : 0) + \
461 ((sizeof(fmt) >= 247 && fmt[244] != '%' && fmt[245] == '%' && fmt[246] == 'p') ? 1 : 0) + \
462 ((sizeof(fmt) >= 248 && fmt[245] != '%' && fmt[246] == '%' && fmt[247] == 'p') ? 1 : 0) + \
463 ((sizeof(fmt) >= 249 && fmt[246] != '%' && fmt[247] == '%' && fmt[248] == 'p') ? 1 : 0) + \
464 ((sizeof(fmt) >= 250 && fmt[247] != '%' && fmt[248] == '%' && fmt[249] == 'p') ? 1 : 0) + \
465 ((sizeof(fmt) >= 251 && fmt[248] != '%' && fmt[249] == '%' && fmt[250] == 'p') ? 1 : 0) + \
466 ((sizeof(fmt) >= 252 && fmt[249] != '%' && fmt[250] == '%' && fmt[251] == 'p') ? 1 : 0) + \
467 ((sizeof(fmt) >= 253 && fmt[250] != '%' && fmt[251] == '%' && fmt[252] == 'p') ? 1 : 0) + \
468 ((sizeof(fmt) >= 254 && fmt[251] != '%' && fmt[252] == '%' && fmt[253] == 'p') ? 1 : 0) + \
469 ((sizeof(fmt) >= 255 && fmt[252] != '%' && fmt[253] == '%' && fmt[254] == 'p') ? 1 : 0) + \
470 ((sizeof(fmt) >= 256 && fmt[253] != '%' && fmt[254] == '%' && fmt[255] == 'p') ? 1 : 0)
471
472 /** @brief Determine if all %p arguments are none character pointer arguments.
473 *
474 * Static package creation relies on the assumption that character pointers are
475 * only using %s arguments. To not confuse it with %p, any character pointer
476 * that is used with %p should be casted to a pointer of a different type, e.g.
477 * void *. This macro can be used to determine, at compile time, if such casting
478 * is missing. It is determined at compile time but cannot be used for static
479 * assertion so only runtime error reporting can be added.
480 *
481 * @note Macro triggers a pointer arithmetic warning and usage shall be wrapped in
482 * the pragma that suppresses this warning.
483 *
484 * @param ... Format string with arguments.
485 *
486 * @retval True if string is okay.
487 * @retval False if casting is missing.
488 */
489 #define Z_CBPRINTF_POINTERS_VALIDATE(...) \
490 (Z_CBPRINTF_NONE_CHAR_PTR_COUNT(__VA_ARGS__) == \
491 Z_CBPRINTF_P_COUNT(GET_ARG_N(1, __VA_ARGS__)))
492
493 /* @brief Check if argument is a certain type of char pointer. What exactly is checked
494 * depends on @p flags. If flags is 0 then 1 is returned if @p x is a char pointer.
495 *
496 * @param idx Argument index.
497 * @param x Argument.
498 * @param flags Flags. See @p CBPRINTF_PACKAGE_FLAGS.
499 *
500 * @retval 1 if @p x is char pointer meeting criteria identified by @p flags.
501 * @retval 0 otherwise.
502 */
503 #define Z_CBPRINTF_IS_X_PCHAR(idx, x, flags) \
504 (idx < Z_CBPRINTF_PACKAGE_FIRST_RO_STR_CNT_GET(flags) ? \
505 0 : Z_CBPRINTF_IS_PCHAR(x, flags))
506
507 /** @brief Calculate number of char * or wchar_t * arguments in the arguments.
508 *
509 * @param fmt string.
510 *
511 * @param ... string arguments.
512 *
513 * @return number of arguments which are char * or wchar_t *.
514 */
515 #define Z_CBPRINTF_HAS_PCHAR_ARGS(flags, fmt, ...) \
516 (FOR_EACH_IDX_FIXED_ARG(Z_CBPRINTF_IS_X_PCHAR, (+), flags, __VA_ARGS__))
517
518 #define Z_CBPRINTF_PCHAR_COUNT(flags, ...) \
519 COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), \
520 (0), \
521 (Z_CBPRINTF_HAS_PCHAR_ARGS(flags, __VA_ARGS__)))
522
523 /**
524 * @brief Check if formatted string must be packaged in runtime.
525 *
526 * @param ... String with arguments (fmt, ...).
527 *
528 * @retval 1 if string must be packaged at runtime.
529 * @retval 0 if string can be statically packaged.
530 */
531 #if Z_C_GENERIC
532 #define Z_CBPRINTF_MUST_RUNTIME_PACKAGE(flags, ...) ({\
533 _Pragma("GCC diagnostic push") \
534 _Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \
535 int _rv; \
536 if ((flags) & CBPRINTF_PACKAGE_ADD_RW_STR_POS) { \
537 _rv = 0; \
538 } else { \
539 _rv = Z_CBPRINTF_PCHAR_COUNT(flags, __VA_ARGS__) > 0 ? 1 : 0; \
540 } \
541 _Pragma("GCC diagnostic pop")\
542 _rv; \
543 })
544 #else
545 #define Z_CBPRINTF_MUST_RUNTIME_PACKAGE(flags, ...) 1
546 #endif
547
548 /** @brief Get storage size for given argument.
549 *
550 * Floats are promoted to double so they use size of double, others int storage
551 * or it's own storage size if it is bigger than int.
552 *
553 * @param v argument.
554 *
555 * @return Number of bytes used for storing the argument.
556 */
557 #ifdef __cplusplus
558 #define Z_CBPRINTF_ARG_SIZE(v) z_cbprintf_cxx_arg_size(v)
559 #else
560 #define Z_CONSTIFY(v) (_Generic((v), char * : (const char *)(uintptr_t)(v), default : (v)))
561 #define Z_CBPRINTF_ARG_SIZE(v) ({\
562 __auto_type __v = (Z_CONSTIFY(v)) + 0; \
563 /* Static code analysis may complain about unused variable. */ \
564 (void)__v; \
565 size_t __arg_size = _Generic((v), \
566 float : sizeof(double), \
567 default : \
568 sizeof((__v)) \
569 ); \
570 __arg_size; \
571 })
572 #endif
573
574 /** @brief Promote and store argument in the buffer.
575 *
576 * @param buf Buffer.
577 *
578 * @param arg Argument.
579 */
580 #ifdef __cplusplus
581 #define Z_CBPRINTF_STORE_ARG(buf, arg) z_cbprintf_cxx_store_arg(buf, arg)
582 #else
583 #define Z_CBPRINTF_STORE_ARG(buf, arg) do { \
584 if (Z_CBPRINTF_VA_STACK_LL_DBL_MEMCPY) { \
585 /* If required, copy arguments by word to avoid unaligned access.*/ \
586 __auto_type _v = (Z_CONSTIFY(arg)) + 0; \
587 double _d = _Generic((arg) + 0, \
588 float : (arg) + 0, \
589 default : \
590 0.0); \
591 /* Static code analysis may complain about unused variable. */ \
592 (void)_v; \
593 (void)_d; \
594 size_t arg_size = Z_CBPRINTF_ARG_SIZE(arg); \
595 size_t _wsize = arg_size / sizeof(int); \
596 z_cbprintf_wcpy((int *)(buf), \
597 (int *) _Generic((arg) + 0, float : &_d, default : &_v), \
598 _wsize); \
599 } else { \
600 *_Generic((arg) + 0, \
601 char : (int *)(buf), \
602 unsigned char: (int *)(buf), \
603 short : (int *)(buf), \
604 unsigned short : (int *)(buf), \
605 int : (int *)(buf), \
606 unsigned int : (unsigned int *)(buf), \
607 long : (long *)(buf), \
608 unsigned long : (unsigned long *)(buf), \
609 long long : (long long *)(buf), \
610 unsigned long long : (unsigned long long *)(buf), \
611 float : (double *)(buf), \
612 double : (double *)(buf), \
613 long double : (long double *)(buf), \
614 default : \
615 (const void **)(buf)) = (arg); \
616 } \
617 } while (false)
618 #endif
619
620 /** @brief Return alignment needed for given argument.
621 *
622 * @param _arg Argument
623 *
624 * @return Alignment in bytes.
625 */
626 #ifdef __cplusplus
627 #define Z_CBPRINTF_ALIGNMENT(_arg) z_cbprintf_cxx_alignment(_arg)
628 #else
629 #define Z_CBPRINTF_ALIGNMENT(_arg) \
630 MAX(_Generic((_arg) + 0, \
631 float : VA_STACK_ALIGN(double), \
632 double : VA_STACK_ALIGN(double), \
633 long double : VA_STACK_ALIGN(long double), \
634 long long : VA_STACK_ALIGN(long long), \
635 unsigned long long : VA_STACK_ALIGN(long long), \
636 default : \
637 __alignof__((_arg) + 0)), VA_STACK_MIN_ALIGN)
638 #endif
639
640 /** @brief Detect long double variable as a constant expression.
641 *
642 * Macro is used in static assertion. On some platforms C++ static inline
643 * template function is not a constant expression and cannot be used. In that
644 * case long double usage will not be detected.
645 *
646 * @param x Argument.
647 *
648 * @return 1 if @p x is a long double, 0 otherwise.
649 */
650 #ifdef __cplusplus
651 #if defined(__x86_64__) || defined(__riscv) || defined(__aarch64__)
652 #define Z_CBPRINTF_IS_LONGDOUBLE(x) 0
653 #else
654 #define Z_CBPRINTF_IS_LONGDOUBLE(x) z_cbprintf_cxx_is_longdouble(x)
655 #endif
656 #else
657 #define Z_CBPRINTF_IS_LONGDOUBLE(x) \
658 _Generic((x) + 0, long double : 1, default : 0)
659 #endif
660
661 /** @brief Safely package arguments to a buffer.
662 *
663 * Argument is put into the buffer if capable buffer is provided. Length is
664 * incremented even if data is not packaged.
665 *
666 * @param _buf buffer.
667 *
668 * @param _idx index. Index is postincremented.
669 *
670 * @param _align_offset Current index with alignment offset.
671 *
672 * @param _max maximum index (buffer capacity).
673 *
674 * @param _arg argument.
675 */
676 #define Z_CBPRINTF_PACK_ARG2(arg_idx, _buf, _idx, _align_offset, _max, _arg) \
677 do { \
678 BUILD_ASSERT(!((sizeof(double) < VA_STACK_ALIGN(long double)) && \
679 Z_CBPRINTF_IS_LONGDOUBLE(_arg) && \
680 !IS_ENABLED(CONFIG_CBPRINTF_PACKAGE_LONGDOUBLE)),\
681 "Packaging of long double not enabled in Kconfig."); \
682 while (((_align_offset) % Z_CBPRINTF_ALIGNMENT(_arg)) != 0UL) { \
683 (_idx) += sizeof(int); \
684 (_align_offset) += sizeof(int); \
685 } \
686 uint32_t _arg_size = Z_CBPRINTF_ARG_SIZE(_arg); \
687 uint8_t _loc = (uint8_t)(_idx / sizeof(int)); \
688 if (arg_idx < 1 + _fros_cnt) { \
689 if (_ros_pos_en) { \
690 _ros_pos_buf[_ros_pos_idx++] = _loc; \
691 } \
692 } else if (Z_CBPRINTF_IS_PCHAR(_arg, 0)) { \
693 if (_cros_en) { \
694 if (Z_CBPRINTF_IS_X_PCHAR(arg_idx, _arg, _flags)) { \
695 if (_rws_pos_en) { \
696 _rws_buffer[_rws_pos_idx++] = arg_idx - 1; \
697 _rws_buffer[_rws_pos_idx++] = _loc; \
698 } \
699 } else { \
700 if (_ros_pos_en) { \
701 _ros_pos_buf[_ros_pos_idx++] = _loc; \
702 } \
703 } \
704 } else if (_rws_pos_en) { \
705 _rws_buffer[_rws_pos_idx++] = arg_idx - 1; \
706 _rws_buffer[_rws_pos_idx++] = (uint8_t)(_idx / sizeof(int)); \
707 } \
708 } \
709 if ((_buf) && (_idx) < (int)(_max)) { \
710 Z_CBPRINTF_STORE_ARG(&(_buf)[(_idx)], _arg); \
711 } \
712 (_idx) += (_arg_size); \
713 (_align_offset) += (_arg_size); \
714 } while (false)
715
716 /** @brief Package single argument.
717 *
718 * Macro is called in a loop for each argument in the string.
719 *
720 * @param arg argument.
721 */
722 #define Z_CBPRINTF_PACK_ARG(arg_idx, arg) \
723 Z_CBPRINTF_PACK_ARG2(arg_idx, _pbuf, _pkg_len, _pkg_offset, _pmax, arg)
724
725 /* When using clang additional warning needs to be suppressed since each
726 * argument of fmt string is used for sizeof() which results in the warning
727 * if argument is a string literal. Suppression is added here instead of
728 * the macro which generates the warning to not slow down the compiler.
729 */
730 #ifdef __clang__
731 #define Z_CBPRINTF_SUPPRESS_SIZEOF_ARRAY_DECAY \
732 _Pragma("GCC diagnostic ignored \"-Wsizeof-array-decay\"")
733 #else
734 #define Z_CBPRINTF_SUPPRESS_SIZEOF_ARRAY_DECAY
735 #endif
736
737 /* Allocation to avoid using VLA and alloca. Alloc frees space when leaving
738 * a function which can lead to increased stack usage if logging is used
739 * multiple times. VLA is not always available.
740 *
741 * Use large array when optimization is off to avoid increased stack usage.
742 */
743 #ifdef CONFIG_NO_OPTIMIZATIONS
744 #define Z_CBPRINTF_ON_STACK_ALLOC(_name, _len) \
745 __ASSERT(_len <= 32, "Too many string arguments."); \
746 uint8_t _name##_buf32[32]; \
747 _name = _name##_buf32
748 #else
749 #define Z_CBPRINTF_ON_STACK_ALLOC(_name, _len) \
750 __ASSERT(_len <= 32, "Too many string arguments."); \
751 uint8_t _name##_buf4[4]; \
752 uint8_t _name##_buf8[8]; \
753 uint8_t _name##_buf12[12]; \
754 uint8_t _name##_buf16[16]; \
755 uint8_t _name##_buf32[32]; \
756 _name = (_len) <= 4 ? _name##_buf4 : \
757 ((_len) <= 8 ? _name##_buf8 : \
758 ((_len) <= 12 ? _name##_buf12 : \
759 ((_len) <= 16 ? _name##_buf16 : \
760 _name##_buf32)))
761 #endif
762
763 /** @brief Statically package a formatted string with arguments.
764 *
765 * @param buf buffer. If null then only length is calculated.
766 *
767 * @param _inlen buffer capacity on input. Ignored when @p buf is null.
768 *
769 * @param _outlen number of bytes required to store the package.
770 *
771 * @param _align_offset Input buffer alignment offset in words. Where offset 0
772 * means that buffer is aligned to CBPRINTF_PACKAGE_ALIGNMENT.
773 *
774 * @param flags Option flags. See @ref CBPRINTF_PACKAGE_FLAGS.
775 *
776 * @param ... String with variable list of arguments.
777 */
778 #define Z_CBPRINTF_STATIC_PACKAGE_GENERIC(buf, _inlen, _outlen, _align_offset, \
779 flags, ... /* fmt, ... */) \
780 do { \
781 _Pragma("GCC diagnostic push") \
782 _Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \
783 Z_CBPRINTF_SUPPRESS_SIZEOF_ARRAY_DECAY \
784 BUILD_ASSERT(!IS_ENABLED(CONFIG_XTENSA) || \
785 (IS_ENABLED(CONFIG_XTENSA) && \
786 !((_align_offset) % CBPRINTF_PACKAGE_ALIGNMENT)), \
787 "Xtensa requires aligned package."); \
788 BUILD_ASSERT(((_align_offset) % sizeof(int)) == 0, \
789 "Alignment offset must be multiply of a word."); \
790 IF_ENABLED(CONFIG_CBPRINTF_STATIC_PACKAGE_CHECK_ALIGNMENT, \
791 (__ASSERT(!((uintptr_t)buf & (CBPRINTF_PACKAGE_ALIGNMENT - 1)), \
792 "Buffer must be aligned.");)) \
793 uint32_t _flags = flags; \
794 bool _ros_pos_en = (_flags) & CBPRINTF_PACKAGE_ADD_RO_STR_POS; \
795 bool _rws_pos_en = (_flags) & CBPRINTF_PACKAGE_ADD_RW_STR_POS; \
796 bool _cros_en = (_flags) & CBPRINTF_PACKAGE_CONST_CHAR_RO; \
797 uint8_t *_pbuf = (buf); \
798 uint8_t _rws_pos_idx = 0; \
799 uint8_t _ros_pos_idx = 0; \
800 /* Variable holds count of all string pointer arguments. */ \
801 uint8_t _alls_cnt = Z_CBPRINTF_PCHAR_COUNT(0, __VA_ARGS__); \
802 uint8_t _fros_cnt = Z_CBPRINTF_PACKAGE_FIRST_RO_STR_CNT_GET(_flags); \
803 /* Variable holds count of non const string pointers. */ \
804 uint8_t _rws_cnt = _cros_en ? \
805 Z_CBPRINTF_PCHAR_COUNT(_flags, __VA_ARGS__) : _alls_cnt - _fros_cnt; \
806 uint8_t _ros_cnt = _ros_pos_en ? (1 + _alls_cnt - _rws_cnt) : 0; \
807 uint8_t *_ros_pos_buf; \
808 Z_CBPRINTF_ON_STACK_ALLOC(_ros_pos_buf, _ros_cnt); \
809 uint8_t *_rws_buffer; \
810 Z_CBPRINTF_ON_STACK_ALLOC(_rws_buffer, 2 * _rws_cnt); \
811 size_t _pmax = !is_null_no_warn(buf) ? _inlen : INT32_MAX; \
812 int _pkg_len = 0; \
813 int _total_len = 0; \
814 int _pkg_offset = (_align_offset); \
815 union cbprintf_package_hdr *_len_loc; \
816 /* If string has rw string arguments CBPRINTF_PACKAGE_ADD_RW_STR_POS is a must. */ \
817 if (_rws_cnt && !((_flags) & CBPRINTF_PACKAGE_ADD_RW_STR_POS)) { \
818 _outlen = -EINVAL; \
819 break; \
820 } \
821 /* package starts with string address and field with length */ \
822 if (_pmax < sizeof(*_len_loc)) { \
823 (_outlen) = -ENOSPC; \
824 break; \
825 } \
826 _len_loc = (union cbprintf_package_hdr *)_pbuf; \
827 _pkg_len += sizeof(*_len_loc); \
828 _pkg_offset += sizeof(*_len_loc); \
829 /* Pack remaining arguments */\
830 FOR_EACH_IDX(Z_CBPRINTF_PACK_ARG, (;), __VA_ARGS__);\
831 _total_len = _pkg_len; \
832 /* Append string indexes to the package. */ \
833 _total_len += _ros_cnt; \
834 _total_len += 2 * _rws_cnt; \
835 if (_pbuf != NULL) { \
836 /* Append string locations. */ \
837 uint8_t *_pbuf_loc = &_pbuf[_pkg_len]; \
838 for (size_t _ros_idx = 0; _ros_idx < _ros_cnt; _ros_idx++) { \
839 *_pbuf_loc++ = _ros_pos_buf[_ros_idx]; \
840 } \
841 for (size_t _rws_idx = 0; _rws_idx < (2 * _rws_cnt); _rws_idx++) { \
842 *_pbuf_loc++ = _rws_buffer[_rws_idx]; \
843 } \
844 } \
845 /* Store length */ \
846 (_outlen) = (_total_len > (int)_pmax) ? -ENOSPC : _total_len; \
847 /* Store length in the header, set number of dumped strings to 0 */ \
848 if (_pbuf != NULL) { \
849 union cbprintf_package_hdr pkg_hdr = { \
850 .desc = { \
851 .len = (uint8_t)(_pkg_len / sizeof(int)), \
852 .str_cnt = 0, \
853 .ro_str_cnt = _ros_cnt, \
854 .rw_str_cnt = _rws_cnt, \
855 } \
856 }; \
857 IF_ENABLED(CONFIG_CBPRINTF_PACKAGE_HEADER_STORE_CREATION_FLAGS, \
858 (pkg_hdr.desc.pkg_flags = flags)); \
859 *_len_loc = pkg_hdr; \
860 } \
861 _Pragma("GCC diagnostic pop") \
862 } while (false)
863
864 #if Z_C_GENERIC
865 #define Z_CBPRINTF_STATIC_PACKAGE(packaged, inlen, outlen, align_offset, flags, \
866 ... /* fmt, ... */) \
867 Z_CBPRINTF_STATIC_PACKAGE_GENERIC(packaged, inlen, outlen, \
868 align_offset, flags, __VA_ARGS__)
869 #else
870 #define Z_CBPRINTF_STATIC_PACKAGE(packaged, inlen, outlen, align_offset, flags, \
871 ... /* fmt, ... */) \
872 do { \
873 /* Small trick needed to avoid warning on always true */ \
874 if (((uintptr_t)packaged + 1) != 1) { \
875 outlen = cbprintf_package(packaged, inlen, flags, __VA_ARGS__); \
876 } else { \
877 outlen = cbprintf_package(NULL, align_offset, flags, __VA_ARGS__); \
878 } \
879 } while (false)
880 #endif /* Z_C_GENERIC */
881
882 #ifdef __cplusplus
883 }
884 #endif
885
886 #ifdef CONFIG_CBPRINTF_PACKAGE_SUPPORT_TAGGED_ARGUMENTS
887 #ifdef __cplusplus
888 /*
889 * Remove qualifiers like const, volatile. And also transform
890 * C++ argument reference back to its basic type.
891 */
892 #define Z_CBPRINTF_ARG_REMOVE_QUAL(arg) \
893 z_cbprintf_cxx_remove_cv < \
894 z_cbprintf_cxx_remove_reference < decltype(arg) > ::type \
895 > ::type
896
897 /*
898 * Get the type of elements in an array.
899 */
900 #define Z_CBPRINTF_CXX_ARG_ARRAY_TYPE(arg) \
901 z_cbprintf_cxx_remove_cv < \
902 z_cbprintf_cxx_remove_extent < decltype(arg) > ::type \
903 > ::type
904
905 /*
906 * Determine if incoming type is char.
907 */
908 #define Z_CBPRINTF_CXX_ARG_IS_TYPE_CHAR(type) \
909 (z_cbprintf_cxx_is_same_type < type, \
910 char > :: value ? \
911 true : \
912 (z_cbprintf_cxx_is_same_type < type, \
913 const char > :: value ? \
914 true : \
915 (z_cbprintf_cxx_is_same_type < type, \
916 volatile char > :: value ? \
917 true : \
918 (z_cbprintf_cxx_is_same_type < type, \
919 const volatile char > :: value ? \
920 true : \
921 false))))
922
923 /*
924 * Figure out if this is a char array since (char *) and (char[])
925 * are of different types in C++.
926 */
927 #define Z_CBPRINTF_CXX_ARG_IS_CHAR_ARRAY(arg) \
928 (z_cbprintf_cxx_is_array < decltype(arg) > :: value ? \
929 (Z_CBPRINTF_CXX_ARG_IS_TYPE_CHAR(Z_CBPRINTF_CXX_ARG_ARRAY_TYPE(arg)) ? \
930 true : \
931 false) : \
932 false)
933
934 /*
935 * Note that qualifiers of char * must be explicitly matched
936 * due to type matching in C++, where remove_cv() does not work.
937 */
938 #define Z_CBPRINTF_ARG_TYPE(arg) \
939 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
940 char > ::value ? \
941 CBPRINTF_PACKAGE_ARG_TYPE_CHAR : \
942 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
943 unsigned char > ::value ? \
944 CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_CHAR : \
945 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
946 short > ::value ? \
947 CBPRINTF_PACKAGE_ARG_TYPE_SHORT : \
948 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
949 unsigned short > ::value ? \
950 CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_SHORT : \
951 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
952 int > ::value ? \
953 CBPRINTF_PACKAGE_ARG_TYPE_INT : \
954 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
955 unsigned int > ::value ? \
956 CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_INT : \
957 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
958 long > ::value ? \
959 CBPRINTF_PACKAGE_ARG_TYPE_LONG : \
960 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
961 unsigned long > ::value ? \
962 CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_LONG : \
963 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
964 long long > ::value ? \
965 CBPRINTF_PACKAGE_ARG_TYPE_LONG_LONG : \
966 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
967 unsigned long long > ::value ? \
968 CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_LONG_LONG : \
969 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
970 float > ::value ? \
971 CBPRINTF_PACKAGE_ARG_TYPE_FLOAT : \
972 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
973 double > ::value ? \
974 CBPRINTF_PACKAGE_ARG_TYPE_DOUBLE : \
975 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
976 long double > ::value ? \
977 CBPRINTF_PACKAGE_ARG_TYPE_LONG_DOUBLE : \
978 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
979 char * > :: value ? \
980 CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR : \
981 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
982 const char * > :: value ? \
983 CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR : \
984 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
985 volatile char * > :: value ? \
986 CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR : \
987 (z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
988 const volatile char * > :: value ? \
989 CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR : \
990 (Z_CBPRINTF_CXX_ARG_IS_CHAR_ARRAY(arg) ? \
991 CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR : \
992 CBPRINTF_PACKAGE_ARG_TYPE_PTR_VOID))))))))))))))))))
993 #else
994 #define Z_CBPRINTF_ARG_TYPE(arg) \
995 _Generic(arg, \
996 char : CBPRINTF_PACKAGE_ARG_TYPE_CHAR, \
997 unsigned char : CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_CHAR, \
998 short : CBPRINTF_PACKAGE_ARG_TYPE_SHORT, \
999 unsigned short : CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_SHORT, \
1000 int : CBPRINTF_PACKAGE_ARG_TYPE_INT, \
1001 unsigned int : CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_INT, \
1002 long : CBPRINTF_PACKAGE_ARG_TYPE_LONG, \
1003 unsigned long : CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_LONG, \
1004 long long : CBPRINTF_PACKAGE_ARG_TYPE_LONG_LONG, \
1005 unsigned long long : CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_LONG_LONG, \
1006 float : CBPRINTF_PACKAGE_ARG_TYPE_FLOAT, \
1007 double : CBPRINTF_PACKAGE_ARG_TYPE_DOUBLE, \
1008 long double : CBPRINTF_PACKAGE_ARG_TYPE_LONG_DOUBLE, \
1009 char * : CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR, \
1010 const char * : CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR, \
1011 void * : CBPRINTF_PACKAGE_ARG_TYPE_PTR_VOID, \
1012 default : \
1013 CBPRINTF_PACKAGE_ARG_TYPE_PTR_VOID \
1014 )
1015 #endif /* _cplusplus */
1016
1017 #define Z_CBPRINTF_TAGGED_EMPTY_ARGS(...) \
1018 CBPRINTF_PACKAGE_ARG_TYPE_END
1019
1020 #define Z_CBPRINTF_TAGGED_ARGS_3(arg) \
1021 Z_CBPRINTF_ARG_TYPE(arg), arg
1022
1023 #define Z_CBPRINTF_TAGGED_ARGS_2(...) \
1024 FOR_EACH(Z_CBPRINTF_TAGGED_ARGS_3, (,), __VA_ARGS__), \
1025 CBPRINTF_PACKAGE_ARG_TYPE_END
1026
1027 #define Z_CBPRINTF_TAGGED_ARGS(_num_args, ...) \
1028 COND_CODE_0(_num_args, \
1029 (CBPRINTF_PACKAGE_ARG_TYPE_END), \
1030 (Z_CBPRINTF_TAGGED_ARGS_2(__VA_ARGS__)))
1031
1032 #endif /* CONFIG_CBPRINTF_PACKAGE_SUPPORT_TAGGED_ARGUMENTS */
1033
1034 #endif /* ZEPHYR_INCLUDE_SYS_CBPRINTF_INTERNAL_H_ */
1035