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