]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
utils: provide snprintf helper macro
authorFlorian Westphal <fw@strlen.de>
Wed, 27 Jul 2016 13:22:25 +0000 (15:22 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 27 Oct 2016 20:34:31 +0000 (22:34 +0200)
lifted from libnftnl, except that we will abort on snprintf errors.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/utils.h

index d88676476efb49a3856f81c680ab39098f431ab6..bb58ba424165c80b2e9eb83d82ea392b338f4c0a 100644 (file)
        (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
 
 /**