From ba524ed8045ea0e14664a64790fee53dd72a4541 Mon Sep 17 00:00:00 2001 From: C. McEnroe Date: Sun, 16 Feb 2020 19:12:19 -0500 Subject: Replace a lot of snprintf with a catf implementation --- chat.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'chat.h') diff --git a/chat.h b/chat.h index adde642..1f4274f 100644 --- a/chat.h +++ b/chat.h @@ -14,10 +14,13 @@ * along with this program. If not, see . */ +#include #include #include +#include #include #include +#include #include #include #include @@ -29,6 +32,15 @@ typedef unsigned uint; typedef unsigned char byte; +static inline void __attribute__((format(printf, 3, 4))) +catf(char *buf, size_t cap, const char *format, ...) { + size_t len = strnlen(buf, cap); + va_list ap; + va_start(ap, format); + assert(0 <= vsnprintf(&buf[len], cap - len, format, ap)); + va_end(ap); +} + enum Color { White, Black, Blue, Green, Red, Brown, Magenta, Orange, Yellow, LightGreen, Cyan, LightCyan, LightBlue, Pink, Gray, LightGray, -- cgit 1.4.1-2-gfad0