18 struct chunk *head, *tail;
21 struct strbuf *strbuf_new(void) {
22 struct strbuf *sb = malloc(sizeof(struct strbuf));
25 sb->head = sb->tail = NULL;
29 void strbuf_free(struct strbuf *sb) {
32 struct chunk *c = sb->head;
33 sb->head = sb->head->next;
40 char *strbuf_tostring(struct strbuf *sb) {
45 t = malloc(sb->length+1);
50 for (c = sb->head; c; c = c->next) {
58 void strbuf_puts(struct strbuf *sb, const char *t) {
64 c = malloc(sizeof(struct chunk)+l);
82 int strbuf_printf(struct strbuf *sb, const char *format, ...) {
84 struct chunk *c = NULL;
91 c = realloc(c, sizeof(struct chunk)+size);
95 r = vsnprintf(c->text, size, format, ap);
98 if (r > -1 && r < size) {
115 if (r > -1) /* glibc 2.1 */