From 5a7d5fa43536484508aad9d9553f64a33212311b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 27 Aug 2018 16:46:12 +0200 Subject: Initial commit --- utils.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 utils.c (limited to 'utils.c') diff --git a/utils.c b/utils.c new file mode 100644 index 0000000..04806dd --- /dev/null +++ b/utils.c @@ -0,0 +1,19 @@ +#include "utils.h" + +// Compute the size needed (including \0) to format given message +size_t printf_len(const char *msg, ...) { + va_list args; + va_start(args, msg); + size_t result = vsnprintf(NULL, 0, msg, args); + va_end(args); + return result + 1; +} + +// Like sprintf, but returs the string. Expects there's enough space. +char *printf_into(char *dst, const char *msg, ...) { + va_list args; + va_start(args, msg); + vsprintf(dst, msg, args); + va_end(args); + return dst; +} -- cgit v1.2.3