From ff0fb0e5a5ef0da28d74d423e2c8ca534e549a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 16 May 2015 15:28:09 +0200 Subject: Cleanup general purpose buffer API Introduce buffer_init to initialize a stack allocated buffer. Rename buffer_{alloc,free} functions because they do something different than the usual convention. They operate on the underlying buffer data but do not allocate/free an actual Buffer struct. --- buffer.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'buffer.h') diff --git a/buffer.h b/buffer.h index fc509b8..ef5a537 100644 --- a/buffer.h +++ b/buffer.h @@ -5,16 +5,23 @@ #include #include "text.h" -typedef struct { +typedef struct { /* a dynamically growing buffer storing arbitrary data */ char *data; /* NULL if empty */ size_t len; /* current length of data */ size_t size; /* maximal capacity of the buffer */ } Buffer; -void buffer_free(Buffer *buf); -bool buffer_alloc(Buffer *buf, size_t size); -void buffer_truncate(Buffer *buf); -bool buffer_put(Buffer *buf, const void *data, size_t len); -bool buffer_append(Buffer *buf, const void *data, size_t len); +/* initalize a (stack allocated) Buffer insteance */ +void buffer_init(Buffer*); +/* relase/free all data stored in this buffer, reset size to zero */ +void buffer_release(Buffer*); +/* reserve space to store at least size bytes in this buffer.*/ +bool buffer_grow(Buffer*, size_t size); +/* truncate buffer, but keep associated memory region for further data */ +void buffer_truncate(Buffer*); +/* replace buffer content with given data, growing the buffer if needed */ +bool buffer_put(Buffer*, const void *data, size_t len); +/* append futher content to the end of the buffer data */ +bool buffer_append(Buffer*, const void *data, size_t len); #endif -- cgit v1.2.3