aboutsummaryrefslogtreecommitdiff
path: root/buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'buffer.h')
-rw-r--r--buffer.h19
1 files changed, 13 insertions, 6 deletions
diff --git a/buffer.h b/buffer.h
index fc509b8..ef5a537 100644
--- a/buffer.h
+++ b/buffer.h
@@ -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