projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
replace typeof with __typeof__
[fio.git]
/
lib
/
output_buffer.c
diff --git
a/lib/output_buffer.c
b/lib/output_buffer.c
index 03cd848bfd9f05aa9dbace684766503b17d6ea55..beb8a1426a1a1e620fbe783f9e0648a95dd6c181 100644
(file)
--- a/
lib/output_buffer.c
+++ b/
lib/output_buffer.c
@@
-1,9
+1,8
@@
-#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "output_buffer.h"
#include <string.h>
#include <stdlib.h>
#include "output_buffer.h"
-#include "../
log
.h"
+#include "../
minmax
.h"
#define BUF_INC 1024
#define BUF_INC 1024
@@
-17,32
+16,26
@@
void buf_output_init(struct buf_output *out)
void buf_output_free(struct buf_output *out)
{
free(out->buf);
void buf_output_free(struct buf_output *out)
{
free(out->buf);
+ buf_output_init(out);
}
size_t 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) {
+ if (out->max_buflen - out->buflen < len) {
+ size_t need = len - (out->max_buflen - out->buflen);
size_t old_max = out->max_buflen;
size_t old_max = out->max_buflen;
- out->max_buflen += BUF_INC;
+ need = max((size_t) BUF_INC, need);
+ out->max_buflen += need;
out->buf = realloc(out->buf, out->max_buflen);
out->buf = realloc(out->buf, out->max_buflen);
- memset(&out->buf[old_max], 0, BUF_INC);
+
+ old_max = max(old_max, out->buflen + len);
+ if (old_max + need > out->max_buflen)
+ need = out->max_buflen - old_max;
+ memset(&out->buf[old_max], 0, need);
}
memcpy(&out->buf[out->buflen], buf, len);
out->buflen += len;
return len;
}
}
memcpy(&out->buf[out->buflen], buf, len);
out->buflen += len;
return len;
}
-
-size_t buf_output_flush(struct buf_output *out)
-{
- size_t ret = 0;
-
- if (out->buflen) {
- ret = log_info_buf(out->buf, out->buflen);
- memset(out->buf, 0, out->max_buflen);
- out->buflen = 0;
- }
-
- return ret;
-}