15 struct chunk *head, *tail;
18 struct strbuf *strbuf_new(void) {
19 struct strbuf *sb = malloc(sizeof(struct strbuf));
22 sb->head = sb->tail = NULL;
26 void strbuf_free(struct strbuf *sb) {
29 struct chunk *c = sb->head;
30 sb->head = sb->head->next;
37 char *strbuf_tostring(struct strbuf *sb) {
42 t = malloc(sb->length+1);
47 for (c = sb->head; c; c = c->next) {
55 char *strbuf_tostring_free(struct strbuf *sb) {
58 t = strbuf_tostring(sb);
63 void strbuf_puts(struct strbuf *sb, const char *t) {
69 c = malloc(sizeof(struct chunk)+l);
87 int strbuf_printf(struct strbuf *sb, const char *format, ...) {
89 struct chunk *c = NULL;
96 c = realloc(c, sizeof(struct chunk)+size);
100 r = vsnprintf(c->text, size, format, ap);
103 if (r > -1 && r < size) {
120 if (r > -1) /* glibc 2.1 */