5 #include "output_buffer.h"
10 void buf_output_init(struct buf_output *out, int index)
12 out->max_buflen = BUF_INC;
13 out->buf = malloc(out->max_buflen);
14 memset(out->buf, 0, out->max_buflen);
18 void buf_output_free(struct buf_output *out)
23 void buf_output_add(struct buf_output *out, const char *buf, size_t len)
25 while (out->max_buflen - out->buflen < len) {
26 size_t newlen = out->max_buflen + BUF_INC - out->buflen;
28 out->buf = realloc(out->buf, out->max_buflen + BUF_INC);
29 out->max_buflen += BUF_INC;
30 memset(&out->buf[out->buflen], 0, newlen);
33 memcpy(&out->buf[out->buflen], buf, len);
37 void buf_output_flush(struct buf_output *out)
40 log_local_buf(out->buf, out->buflen);
41 memset(out->buf, 0, out->max_buflen);