diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-05-16 15:28:09 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-05-16 22:33:26 +0200 |
| commit | ff0fb0e5a5ef0da28d74d423e2c8ca534e549a4a (patch) | |
| tree | 2abe0ab01534dc148a2ff7c7e1a58af7ba07dc43 /buffer.h | |
| parent | b58c9169bb5986cd87a2f98fb8854c86638b70f6 (diff) | |
| download | vis-ff0fb0e5a5ef0da28d74d423e2c8ca534e549a4a.tar.gz vis-ff0fb0e5a5ef0da28d74d423e2c8ca534e549a4a.tar.xz | |
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.
Diffstat (limited to 'buffer.h')
| -rw-r--r-- | buffer.h | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -5,16 +5,23 @@ #include <stdbool.h> #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 |
