From 2c6a3b7c4f662b7a94a8ba6870565a45df0cbe2c Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Wed, 27 Jul 2016 15:22:25 +0200 Subject: utils: provide snprintf helper macro lifted from libnftnl, except that we will abort on snprintf errors. Signed-off-by: Florian Westphal Acked-by: Pablo Neira Ayuso --- include/utils.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/utils.h') diff --git a/include/utils.h b/include/utils.h index d8867647..bb58ba42 100644 --- a/include/utils.h +++ b/include/utils.h @@ -83,6 +83,16 @@ (void) (&_max1 == &_max2); \ _max1 > _max2 ? _max1 : _max2; }) +#define SNPRINTF_BUFFER_SIZE(ret, size, len, offset) \ + if (ret < 0) \ + abort(); \ + offset += ret; \ + assert(ret < len); \ + if (ret > len) \ + ret = len; \ + size += ret; \ + len -= ret; + #define MSEC_PER_SEC 1000L /** -- cgit v1.2.3