1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #if 0 /// elogind is musl-libc compatible and does not directly include printf.h
8 #include "parse-printf-format.h"
12 #include <sys/types.h>
16 #define snprintf_ok(buf, len, fmt, ...) \
17 ((size_t) snprintf(buf, len, fmt, __VA_ARGS__) < (len))
19 #define xsprintf(buf, fmt, ...) \
20 assert_message_se(snprintf_ok(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__), "xsprintf: " #buf "[] must be big enough")
22 #define VA_FORMAT_ADVANCE(format, ap) \
26 _k = parse_printf_format((format), ELEMENTSOF(_argtypes), _argtypes); \
27 assert(_k < ELEMENTSOF(_argtypes)); \
28 for (_i = 0; _i < _k; _i++) { \
29 if (_argtypes[_i] & PA_FLAG_PTR) { \
30 (void) va_arg(ap, void*); \
34 switch (_argtypes[_i]) { \
36 case PA_INT|PA_FLAG_SHORT: \
38 (void) va_arg(ap, int); \
40 case PA_INT|PA_FLAG_LONG: \
41 (void) va_arg(ap, long int); \
43 case PA_INT|PA_FLAG_LONG_LONG: \
44 (void) va_arg(ap, long long int); \
47 (void) va_arg(ap, wchar_t); \
52 (void) va_arg(ap, void*); \
56 (void) va_arg(ap, double); \
58 case PA_DOUBLE|PA_FLAG_LONG_DOUBLE: \
59 (void) va_arg(ap, long double); \
62 assert_not_reached("Unknown format string argument."); \