chiark / gitweb /
buffer: Provide buffer_destroy
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 1 Oct 2014 17:00:00 +0000 (18:00 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 21 Oct 2014 00:07:10 +0000 (01:07 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
util.c
util.h

diff --git a/util.c b/util.c
index 0f24282..0215f25 100644 (file)
--- a/util.c
+++ b/util.c
@@ -291,6 +291,14 @@ void buffer_init(struct buffer_if *buffer, int32_t max_start_pad)
     buffer->size=0;
 }
 
+void buffer_destroy(struct buffer_if *buf)
+{
+    BUF_ASSERT_FREE(buf);
+    free(buf->base);
+    buf->start=buf->base=0;
+    buf->size=buf->alloclen=0;
+}
+
 void *buf_append(struct buffer_if *buf, int32_t amount) {
     void *p;
     assert(amount <= buf_remaining_space(buf));
diff --git a/util.h b/util.h
index a5a82a4..3549eb0 100644 (file)
--- a/util.h
+++ b/util.h
@@ -23,6 +23,7 @@ extern void buffer_assert_used(struct buffer_if *buffer, cstring_t file,
                               int line);
 extern void buffer_new(struct buffer_if *buffer, int32_t len);
 extern void buffer_init(struct buffer_if *buffer, int32_t max_start_pad);
+extern void buffer_destroy(struct buffer_if *buffer);
 extern void buffer_copy(struct buffer_if *dst, const struct buffer_if *src);
 extern void *buf_append(struct buffer_if *buf, int32_t amount);
 extern void *buf_prepend(struct buffer_if *buf, int32_t amount);