author | Volker Birk <vb@pep.foundation> |
Wed, 29 Aug 2018 17:10:23 +0200 | |
branch | sync |
changeset 2899 | 63b619aef131 |
parent 2840 | b881c48c9e9d |
child 4792 | 7056435ab9e7 |
permissions | -rw-r--r-- |
1 // This file is under GNU General Public License 3.0
2 // see LICENSE.txt
4 #include "pEp_internal.h"
5 #include "growing_buf.h"
7 growing_buf_t *new_growing_buf(void)
8 {
9 growing_buf_t *result = calloc(1, sizeof(growing_buf_t));
10 assert(result);
11 return result;
12 }
14 void free_growing_buf(growing_buf_t *buf)
15 {
16 if (buf) {
17 free(buf->data);
18 free(buf);
19 }
20 }
22 int growing_buf_consume(const void *src, size_t size, growing_buf_t *dst)
23 {
24 assert(src && dst);
25 if (!(src && dst))
26 return -1;
28 char *new_data = realloc(dst->data, dst->size + size + 1);
29 assert(new_data);
30 if (!new_data)
31 return -1;
32 dst->data = new_data;
33 memcpy(dst->data + dst->size, src, size);
34 dst->size += size;
35 dst->data[dst->size] = 0; // safeguard
37 return 1;
38 }