1 #pragma once
2 
3 #include <stdbool.h>
4 
5 /*
6  * Buffer abstract data type
7  */
8 struct strbuf {
9 	char *bytes;
10 	unsigned size;
11 	unsigned used;
12 };
13 
14 void strbuf_init(struct strbuf *buf);
15 void strbuf_release(struct strbuf *buf);
16 void strbuf_clear(struct strbuf *buf);
17 
18 /* Destroy buffer and return a copy as a C string */
19 char *strbuf_steal(struct strbuf *buf);
20 
21 /*
22  * Return a C string owned by the buffer invalidated if the buffer is
23  * changed).
24  */
25 const char *strbuf_str(struct strbuf *buf);
26 
27 bool strbuf_pushchar(struct strbuf *buf, char ch);
28 unsigned strbuf_pushchars(struct strbuf *buf, const char *str);
29 void strbuf_popchar(struct strbuf *buf);
30 void strbuf_popchars(struct strbuf *buf, unsigned n);
31