Proper size return from output buffers
[fio.git] / lib / output_buffer.c
index 7a8d792f26294c1afc956ba57dfa7acca2a4769a..145272a00d60e4ed067ac404c1a1966a4bb98668 100644 (file)
@@ -20,25 +20,30 @@ void buf_output_free(struct buf_output *out)
        free(out->buf);
 }
 
-void buf_output_add(struct buf_output *out, const char *buf, size_t len)
+size_t buf_output_add(struct buf_output *out, const char *buf, size_t len)
 {
        while (out->max_buflen - out->buflen < len) {
                size_t newlen = out->max_buflen + BUF_INC - out->buflen;
 
-               out->buf = realloc(out->buf, out->max_buflen + BUF_INC);
                out->max_buflen += BUF_INC;
+               out->buf = realloc(out->buf, out->max_buflen);
                memset(&out->buf[out->buflen], 0, newlen);
        }
 
        memcpy(&out->buf[out->buflen], buf, len);
        out->buflen += len;
+       return len;
 }
 
-void buf_output_flush(struct buf_output *out)
+size_t buf_output_flush(struct buf_output *out)
 {
+       size_t ret = 0;
+
        if (out->buflen) {
-               log_local_buf(out->buf, out->buflen);
+               ret = log_local_buf(out->buf, out->buflen);
                memset(out->buf, 0, out->max_buflen);
                out->buflen = 0;
        }
+
+       return ret;
 }