diff options
Diffstat (limited to 'src/txtacc.c')
-rw-r--r-- | src/txtacc.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/txtacc.c b/src/txtacc.c index c094c22..91659f6 100644 --- a/src/txtacc.c +++ b/src/txtacc.c @@ -112,60 +112,65 @@ txtacc_grow (struct txtacc *acc, const char *buf, size_t size) { struct txtacc_entry *ent = txtacc_cur_entry (acc); size_t rest = txtacc_entry_freesize (ent); if (rest > size) rest = size; txtacc_entry_append (ent, buf, rest); buf += rest; size -= rest; } } char * -txtacc_finish (struct txtacc *acc) +txtacc_finish (struct txtacc *acc, int steal) { struct grecs_list_entry *ep; struct txtacc_entry *txtent; size_t size; + char *p; switch (grecs_list_size (acc->cur)) { case 0: return NULL; case 1: txtent = acc->cur->head->data; acc->cur->head->data = NULL; - grecs_list_append (acc->mem, txtent); txtacc_entry_tailor (txtent); break; default: size = 0; for (ep = acc->cur->head; ep; ep = ep->next) { txtent = ep->data; size += txtent->len; } txtent = txtacc_alloc_entry (acc->mem, size); for (ep = acc->cur->head; ep; ep = ep->next) { struct txtacc_entry *tp = ep->data; txtacc_entry_append (txtent, tp->buf, tp->len); } } grecs_list_clear (acc->cur); - return txtent->buf; + p = txtent->buf; + if (steal) + free (txtent); + else + grecs_list_append (acc->mem, txtent); + return p; } void txtacc_free_string (struct txtacc *acc, char *str) { struct grecs_list_entry *ep; for (ep = acc->mem->head; ep; ep = ep->next) { struct txtacc_entry *tp = ep->data; if (tp->buf == str) { grecs_list_remove_entry(acc->mem, ep); |