From cfaf78325bb636c38166a2a19f05c1c89f010832 Mon Sep 17 00:00:00 2001 From: Heikki Kallasjoki Date: Sun, 23 Dec 2018 13:53:07 +0000 Subject: Make `bbuf_get` result non-const, and add `bbuf_free`. It's reasonable to want to modify the contents of the buffer in other ways than just plain appending, and the storage is already guaranteed contiguous. Drop the `const` from the `bbuf_get` return type, so it can be used to modify bytes in-place. The parallel request processing code may need to actually deallocate buffers as well, so add a `bbuf_free` function. --- util.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'util.c') diff --git a/util.c b/util.c index c302fc7..0443c98 100644 --- a/util.c +++ b/util.c @@ -60,6 +60,11 @@ bbuf *bbuf_alloc(size_t initial_size, size_t max_size) { return buf; } +void bbuf_free(bbuf *buf) { + free(buf->data); + free(buf); +} + void bbuf_reset(bbuf *buf) { buf->len = 0; } @@ -103,7 +108,7 @@ void bbuf_putf(bbuf *buf, const char *fmt, ...) { } } -const char *bbuf_get(struct bbuf *buf, size_t *len) { +char *bbuf_get(struct bbuf *buf, size_t *len) { *len = buf->len; return buf->data; } -- cgit 1.4.1