From 3e9c75318b0eb1114fb7361dbc467990674804b6 Mon Sep 17 00:00:00 2001 From: wrmr Date: Sun, 3 Nov 2024 02:48:05 -0500 Subject: start working on fetching --- buf.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'buf.c') diff --git a/buf.c b/buf.c index dd93116..1f0e2b3 100644 --- a/buf.c +++ b/buf.c @@ -1,8 +1,9 @@ #include +#include #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); } -- cgit 1.4.1-2-gfad0