1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 This file is part of systemd.
7 Copyright 2010 Lennart Poettering
10 #if 0 /// elogind is musl-libc compatible and does not directly include printf.h
13 #include "parse-printf-format.h"
17 #include <sys/types.h>
21 #define snprintf_ok(buf, len, fmt, ...) \
22 ((size_t) snprintf(buf, len, fmt, __VA_ARGS__) < (len))
24 #define xsprintf(buf, fmt, ...) \
25 assert_message_se(snprintf_ok(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__), "xsprintf: " #buf "[] must be big enough")
27 #define VA_FORMAT_ADVANCE(format, ap) \
31 _k = parse_printf_format((format), ELEMENTSOF(_argtypes), _argtypes); \
32 assert(_k < ELEMENTSOF(_argtypes)); \
33 for (_i = 0; _i < _k; _i++) { \
34 if (_argtypes[_i] & PA_FLAG_PTR) { \
35 (void) va_arg(ap, void*); \
39 switch (_argtypes[_i]) { \
41 case PA_INT|PA_FLAG_SHORT: \
43 (void) va_arg(ap, int); \
45 case PA_INT|PA_FLAG_LONG: \
46 (void) va_arg(ap, long int); \
48 case PA_INT|PA_FLAG_LONG_LONG: \
49 (void) va_arg(ap, long long int); \
52 (void) va_arg(ap, wchar_t); \
57 (void) va_arg(ap, void*); \
61 (void) va_arg(ap, double); \
63 case PA_DOUBLE|PA_FLAG_LONG_DOUBLE: \
64 (void) va_arg(ap, long double); \
67 assert_not_reached("Unknown format string argument."); \