diff options
author | wrmr | 2024-11-03 02:48:05 -0500 |
---|---|---|
committer | wrmr | 2024-11-03 02:48:05 -0500 |
commit | 3e9c75318b0eb1114fb7361dbc467990674804b6 (patch) | |
tree | 504efbb2fe56c4700055ec584170cb77237c732a /buf.c | |
parent | 610808a5902adad751a4acdbcc310803a51fed5d (diff) |
start working on fetching
Diffstat (limited to 'buf.c')
-rw-r--r-- | buf.c | 18 |
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); } |