1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 Copyright 2010 Lennart Poettering
8 #if 0 /// elogind is musl-libc compatible and does not directly include printf.h
11 #include "parse-printf-format.h"
15 #include <sys/types.h>
19 #define snprintf_ok(buf, len, fmt, ...) \
20 ((size_t) snprintf(buf, len, fmt, __VA_ARGS__) < (len))
22 #define xsprintf(buf, fmt, ...) \
23 assert_message_se(snprintf_ok(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__), "xsprintf: " #buf "[] must be big enough")
25 #define VA_FORMAT_ADVANCE(format, ap) \
29 _k = parse_printf_format((format), ELEMENTSOF(_argtypes), _argtypes); \
30 assert(_k < ELEMENTSOF(_argtypes)); \
31 for (_i = 0; _i < _k; _i++) { \
32 if (_argtypes[_i] & PA_FLAG_PTR) { \
33 (void) va_arg(ap, void*); \
37 switch (_argtypes[_i]) { \
39 case PA_INT|PA_FLAG_SHORT: \
41 (void) va_arg(ap, int); \
43 case PA_INT|PA_FLAG_LONG: \
44 (void) va_arg(ap, long int); \
46 case PA_INT|PA_FLAG_LONG_LONG: \
47 (void) va_arg(ap, long long int); \
50 (void) va_arg(ap, wchar_t); \
55 (void) va_arg(ap, void*); \
59 (void) va_arg(ap, double); \
61 case PA_DOUBLE|PA_FLAG_LONG_DOUBLE: \
62 (void) va_arg(ap, long double); \
65 assert_not_reached("Unknown format string argument."); \