]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/stdio-util.h
629abf35eecdcdeecf30633c99ad7fe3837822fa
1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 Copyright 2010 Lennart Poettering
11 #include <sys/types.h>
15 #define snprintf_ok(buf, len, fmt, ...) \
16 ((size_t) snprintf(buf, len, fmt, __VA_ARGS__) < (len))
18 #define xsprintf(buf, fmt, ...) \
19 assert_message_se(snprintf_ok(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__), "xsprintf: " #buf "[] must be big enough")
21 #define VA_FORMAT_ADVANCE(format, ap) \
25 _k = parse_printf_format((format), ELEMENTSOF(_argtypes), _argtypes); \
26 assert(_k < ELEMENTSOF(_argtypes)); \
27 for (_i = 0; _i < _k; _i++) { \
28 if (_argtypes[_i] & PA_FLAG_PTR) { \
29 (void) va_arg(ap, void*); \
33 switch (_argtypes[_i]) { \
35 case PA_INT|PA_FLAG_SHORT: \
37 (void) va_arg(ap, int); \
39 case PA_INT|PA_FLAG_LONG: \
40 (void) va_arg(ap, long int); \
42 case PA_INT|PA_FLAG_LONG_LONG: \
43 (void) va_arg(ap, long long int); \
46 (void) va_arg(ap, wchar_t); \
51 (void) va_arg(ap, void*); \
55 (void) va_arg(ap, double); \
57 case PA_DOUBLE|PA_FLAG_LONG_DOUBLE: \
58 (void) va_arg(ap, long double); \
61 assert_not_reached("Unknown format string argument."); \