8 typedef struct { /* a dynamically growing buffer storing arbitrary data */
9 char *data
; /* NULL if empty */
10 size_t len
; /* current length of data */
11 size_t size
; /* maximal capacity of the buffer */
14 /* initalize a (stack allocated) Buffer insteance */
15 void buffer_init(Buffer
*);
16 /* relase/free all data stored in this buffer, reset size to zero */
17 void buffer_release(Buffer
*);
18 /* reserve space to store at least size bytes in this buffer.*/
19 bool buffer_grow(Buffer
*, size_t size
);
20 /* truncate buffer, but keep associated memory region for further data */
21 void buffer_truncate(Buffer
*);
22 /* replace buffer content with given data, growing the buffer if needed */
23 bool buffer_put(Buffer
*, const void *data
, size_t len
);
24 /* same but with NUL-terminated data */
25 bool buffer_put0(Buffer
*, const char *data
);
26 /* insert arbitrary data of length len at pos (in [0, buf->len]) */
27 bool buffer_insert(Buffer
*, size_t pos
, const void *data
, size_t len
);
28 /* insert NUL-terminate data at pos (in [0, buf->len]) */
29 bool buffer_insert0(Buffer
*, size_t pos
, const char *data
);
30 /* append futher content to the end of the buffer data */
31 bool buffer_append(Buffer
*, const void *data
, size_t len
);
32 /* append NUl-terminated data */
33 bool buffer_append0(Buffer
*, const char *data
);
35 bool buffer_prepend(Buffer
*, const void *data
, size_t len
);
36 bool buffer_prepend0(Buffer
*, const char *data
);