summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bytearray.c11
-rw-r--r--src/bytearray.h1
-rw-r--r--src/strbuf.h1
-rw-r--r--src/xplist.c1
4 files changed, 11 insertions, 3 deletions
diff --git a/src/bytearray.c b/src/bytearray.c
index 861890e..fff5089 100644
--- a/src/bytearray.c
+++ b/src/bytearray.c
@@ -41,15 +41,20 @@ void byte_array_free(bytearray_t *ba)
41 free(ba); 41 free(ba);
42} 42}
43 43
44void byte_array_grow(bytearray_t *ba, size_t amount)
45{
46 size_t increase = (amount > PAGE_SIZE) ? (amount+(PAGE_SIZE-1)) & (~(PAGE_SIZE-1)) : PAGE_SIZE;
47 ba->data = realloc(ba->data, ba->capacity + increase);
48 ba->capacity += increase;
49}
50
44void byte_array_append(bytearray_t *ba, void *buf, size_t len) 51void byte_array_append(bytearray_t *ba, void *buf, size_t len)
45{ 52{
46 if (!ba || !ba->data || (len <= 0)) return; 53 if (!ba || !ba->data || (len <= 0)) return;
47 size_t remaining = ba->capacity-ba->len; 54 size_t remaining = ba->capacity-ba->len;
48 if (len > remaining) { 55 if (len > remaining) {
49 size_t needed = len - remaining; 56 size_t needed = len - remaining;
50 size_t increase = (needed > PAGE_SIZE) ? (needed+(PAGE_SIZE-1)) & (~(PAGE_SIZE-1)) : PAGE_SIZE; 57 byte_array_grow(ba, needed);
51 ba->data = realloc(ba->data, ba->capacity + increase);
52 ba->capacity += increase;
53 } 58 }
54 memcpy(((char*)ba->data) + ba->len, buf, len); 59 memcpy(((char*)ba->data) + ba->len, buf, len);
55 ba->len += len; 60 ba->len += len;
diff --git a/src/bytearray.h b/src/bytearray.h
index 1613143..aae8c31 100644
--- a/src/bytearray.h
+++ b/src/bytearray.h
@@ -30,6 +30,7 @@ typedef struct bytearray_t {
30 30
31bytearray_t *byte_array_new(); 31bytearray_t *byte_array_new();
32void byte_array_free(bytearray_t *ba); 32void byte_array_free(bytearray_t *ba);
33void byte_array_grow(bytearray_t *ba, size_t amount);
33void byte_array_append(bytearray_t *ba, void *buf, size_t len); 34void byte_array_append(bytearray_t *ba, void *buf, size_t len);
34 35
35#endif 36#endif
diff --git a/src/strbuf.h b/src/strbuf.h
index 6b7f9d3..ba2c909 100644
--- a/src/strbuf.h
+++ b/src/strbuf.h
@@ -28,6 +28,7 @@ typedef struct bytearray_t strbuf_t;
28 28
29#define str_buf_new() byte_array_new() 29#define str_buf_new() byte_array_new()
30#define str_buf_free(__ba) byte_array_free(__ba) 30#define str_buf_free(__ba) byte_array_free(__ba)
31#define str_buf_grow(__ba, __am) byte_array_grow(__ba, __am)
31#define str_buf_append(__ba, __str, __len) byte_array_append(__ba, (void*)(__str), __len) 32#define str_buf_append(__ba, __str, __len) byte_array_append(__ba, (void*)(__str), __len)
32 33
33#endif 34#endif
diff --git a/src/xplist.c b/src/xplist.c
index 0e9b007..7f20ef2 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -294,6 +294,7 @@ static void node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth)
294 uint32_t maxread = ((76 - indent*8) / 4) * 3; 294 uint32_t maxread = ((76 - indent*8) / 4) * 3;
295 size_t count = 0; 295 size_t count = 0;
296 size_t b64count = 0; 296 size_t b64count = 0;
297 str_buf_grow(*outbuf, (node_data->length / 3 * 4) + 4 + (((node_data->length / maxread) + 1) * (indent+1)));
297 while (j < node_data->length) { 298 while (j < node_data->length) {
298 for (i = 0; i < indent; i++) { 299 for (i = 0; i < indent; i++) {
299 str_buf_append(*outbuf, "\t", 1); 300 str_buf_append(*outbuf, "\t", 1);