16 struct chunk *head, *tail;
19 struct pa_strbuf *pa_strbuf_new(void) {
20 struct pa_strbuf *sb = malloc(sizeof(struct pa_strbuf));
23 sb->head = sb->tail = NULL;
27 void pa_strbuf_free(struct pa_strbuf *sb) {
30 struct chunk *c = sb->head;
31 sb->head = sb->head->next;
38 char *pa_strbuf_tostring(struct pa_strbuf *sb) {
43 t = malloc(sb->length+1);
47 for (c = sb->head; c; c = c->next) {
48 memcpy(e, c->text, c->length);
57 char *pa_strbuf_tostring_free(struct pa_strbuf *sb) {
60 t = pa_strbuf_tostring(sb);
65 void pa_strbuf_puts(struct pa_strbuf *sb, const char *t) {
71 c = malloc(sizeof(struct chunk)+l);
76 memcpy(c->text, t, l);
90 /* The following is based on an example from the GNU libc documentation */
92 int pa_strbuf_printf(struct pa_strbuf *sb, const char *format, ...) {
94 struct chunk *c = NULL;
101 c = realloc(c, sizeof(struct chunk)+size);
104 va_start(ap, format);
105 r = vsnprintf(c->text, size, format, ap);
108 if (r > -1 && r < size) {
126 if (r > -1) /* glibc 2.1 */