about summary refs log tree commit diff
path: root/chat.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--chat.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/chat.h b/chat.h
index fd8f81a..023baf6 100644
--- a/chat.h
+++ b/chat.h
@@ -43,13 +43,20 @@
 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);
+struct Cat {
+	char *buf;
+	size_t cap;
+	size_t len;
+};
+static inline void __attribute__((format(printf, 2, 3)))
+catf(struct Cat *cat, const char *format, ...) {
 	va_list ap;
 	va_start(ap, format);
-	assert(0 <= vsnprintf(&buf[len], cap - len, format, ap));
+	int len = vsnprintf(&cat->buf[cat->len], cat->cap - cat->len, format, ap);
+	assert(len >= 0);
 	va_end(ap);
+	cat->len += len;
+	if (cat->len >= cat->cap) cat->len = cat->cap - 1;
 }
 
 enum Color {