diff options
author | Heikki Kallasjoki <fis@zem.fi> | 2018-12-23 13:53:07 +0000 |
---|---|---|
committer | Heikki Kallasjoki <fis+github@zem.fi> | 2018-12-23 21:50:27 +0000 |
commit | cfaf78325bb636c38166a2a19f05c1c89f010832 (patch) | |
tree | b75b004a379e754a5917a7ab9606faec41066d8c /util.c | |
parent | 9f9b6230dfd9ef7973641987bfd57ea7e361359a (diff) | |
download | nano-exporter-cfaf78325bb636c38166a2a19f05c1c89f010832.tar.gz nano-exporter-cfaf78325bb636c38166a2a19f05c1c89f010832.tar.xz nano-exporter-cfaf78325bb636c38166a2a19f05c1c89f010832.zip |
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.
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 7 |
1 files changed, 6 insertions, 1 deletions
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; } |