diff options
author | wrmr | 2024-11-09 02:04:33 -0500 |
---|---|---|
committer | wrmr | 2024-11-09 02:04:33 -0500 |
commit | 38987f3f5a3919ac81ba419e05ac8610c269faff (patch) | |
tree | dc76c691f0e7d8385224ede708b9390b50b68dff /buf.c | |
parent | 12d5d0df5c4b958bbb5cc339a9e556c50136a974 (diff) |
rename buf_t to str_t, and consolidate str.c/h with strv.c/h
Diffstat (limited to 'buf.c')
-rw-r--r-- | buf.c | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/buf.c b/buf.c deleted file mode 100644 index 5575bbd..0000000 --- a/buf.c +++ /dev/null @@ -1,41 +0,0 @@ -#include <stdlib.h> -#include <string.h> -#include "buf.h" -#include "err.h" - -void buf_init(buf_t *b, size_t n) { - b->buf = calloc(1, n); - if (!b->buf) { - efatal("buf_init"); - } - b->cap = n; - b->sz = 0; -} - -/* does NOT change sz! just makes room */ -void buf_grow(buf_t *b, size_t n) { - size_t sz = b->sz + n; - size_t c = b->cap; - if (sz > c) { - while (sz > c) c <<= 1; - char *p = realloc(b->buf, c); - if (!p) efatal("buf_grow"); - b->buf = p; - b->cap = c; - } -} - -void buf_cat(buf_t *b, strv_t s) { - buf_grow(b, s.n); - memcpy(&b->buf[b->sz], s.s, s.n); - b->sz += s.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); -} |