diff options
author | June McEnroe <june@causal.agency> | 2020-02-16 19:12:19 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-02-16 19:12:19 -0500 |
commit | ba524ed8045ea0e14664a64790fee53dd72a4541 (patch) | |
tree | 609ceb1caa887dabad7e7088722d5bf279b7873a /chat.h | |
parent | Add 379 to WHOIS responses (diff) | |
download | catgirl-ba524ed8045ea0e14664a64790fee53dd72a4541.tar.gz catgirl-ba524ed8045ea0e14664a64790fee53dd72a4541.zip |
Replace a lot of snprintf with a catf implementation
Diffstat (limited to '')
-rw-r--r-- | chat.h | 12 |
1 files changed, 12 insertions, 0 deletions
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 <https://www.gnu.org/licenses/>. */ +#include <assert.h> #include <err.h> #include <getopt.h> +#include <stdarg.h> #include <stdbool.h> #include <stdint.h> +#include <stdio.h> #include <string.h> #include <sysexits.h> #include <time.h> @@ -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, |