5 #include "output_buffer.h"
10 void buf_output_init(struct buf_output *out)
17 void buf_output_free(struct buf_output *out)
23 size_t buf_output_add(struct buf_output *out, const char *buf, size_t len)
25 if (out->max_buflen - out->buflen < len) {
26 size_t need = len - (out->max_buflen - out->buflen);
27 size_t old_max = out->max_buflen;
29 need = max((size_t) BUF_INC, need);
30 out->max_buflen += need;
31 out->buf = realloc(out->buf, out->max_buflen);
33 old_max = max(old_max, out->buflen + len);
34 if (old_max + need > out->max_buflen)
35 need = out->max_buflen - old_max;
36 memset(&out->buf[old_max], 0, need);
39 memcpy(&out->buf[out->buflen], buf, len);