summary refs log tree commit diff
path: root/buf.c
diff options
context:
space:
mode:
Diffstat (limited to 'buf.c')
-rw-r--r--buf.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/buf.c b/buf.c
index dd93116..1f0e2b3 100644
--- a/buf.c
+++ b/buf.c
@@ -1,8 +1,9 @@
 #include <stdlib.h>
+#include <string.h>
 #include "buf.h"
 #include "err.h"
 
-void buf_init(struct buf *b, size_t n) {
+void buf_init(buf_t *b, size_t n) {
 	b->buf = calloc(1, n);
 	if (!b->buf) {
 		efatal("buf_init");
@@ -11,7 +12,7 @@ void buf_init(struct buf *b, size_t n) {
 	b->sz = 0;
 }
 
-void buf_grow(struct buf *b, size_t n) {
+void buf_grow(buf_t *b, size_t n) {
 	size_t sz = b->sz + n;
 	size_t c = b->cap;
 	if (sz > c) {
@@ -23,6 +24,17 @@ void buf_grow(struct buf *b, size_t n) {
 	}
 }
 
-void buf_free(struct buf *b) {
+void buf_cat(buf_t *b, char *src, size_t n) {
+	buf_grow(b, n);
+	memcpy(&b->buf[b->sz], src, n);
+	b->sz += n;
+}
+
+void buf_catc(buf_t *b, char c) {
+	buf_grow(b, 1);
+	b->buf[b->sz++] = c;
+}
+
+void buf_free(buf_t *b) {
 	free(b->buf);
 }