diff --git a/daemon/bencode.c b/daemon/bencode.c index d83e858e0..7bb0a4e3c 100644 --- a/daemon/bencode.c +++ b/daemon/bencode.c @@ -146,6 +146,12 @@ void bencode_buffer_free(bencode_buffer_t *buf) { } } +void bencode_buffer_merge(bencode_buffer_t *to, bencode_buffer_t *from) { + from->pieces->next = to->pieces; + to->pieces = from->pieces; + from->pieces = NULL; +} + static bencode_item_t *__bencode_item_alloc(bencode_buffer_t *buf, size_t payload) { bencode_item_t *ret; diff --git a/include/bencode.h b/include/bencode.h index 3c3efb575..1d7816aa1 100644 --- a/include/bencode.h +++ b/include/bencode.h @@ -69,6 +69,9 @@ void *bencode_buffer_alloc(bencode_buffer_t *, size_t); * and all objects created through it become invalid. */ void bencode_buffer_free(bencode_buffer_t *buf); +// Move all objects from one buffer to another. The `from` buffer will be unusable afterwards. +void bencode_buffer_merge(bencode_buffer_t *to, bencode_buffer_t *from); + /* Creates a new empty dictionary object. Memory will be allocated from the bencode_buffer_t object. * Returns NULL if no memory could be allocated. */ bencode_item_t *bencode_dictionary(bencode_buffer_t *buf);