diff options
author | David Robillard <d@drobilla.net> | 2021-01-13 14:31:00 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-07 15:32:23 -0500 |
commit | a7be33a7640ee51066c41eded5812d9cee5ad27e (patch) | |
tree | 8c2cbe96a6973c73320ff793d452e36fe511b745 /src/writer.c | |
parent | 96bcba9cd94879794de477ae7c5c04971fbd6f32 (diff) | |
download | serd-a7be33a7640ee51066c41eded5812d9cee5ad27e.tar.gz serd-a7be33a7640ee51066c41eded5812d9cee5ad27e.tar.bz2 serd-a7be33a7640ee51066c41eded5812d9cee5ad27e.zip |
Add SerdBuffer type for mutable buffers
This avoids const violations from abusing SerdChunk as a mutable buffer
for string sinks.
Diffstat (limited to 'src/writer.c')
-rw-r--r-- | src/writer.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/writer.c b/src/writer.c index af2980c5..ee9ae352 100644 --- a/src/writer.c +++ b/src/writer.c @@ -1105,18 +1105,19 @@ serd_file_sink(const void* buf, size_t len, void* stream) } size_t -serd_chunk_sink(const void* buf, size_t len, void* stream) +serd_buffer_sink(const void* buf, size_t len, void* stream) { - SerdChunk* chunk = (SerdChunk*)stream; - chunk->buf = (uint8_t*)realloc((uint8_t*)chunk->buf, chunk->len + len); - memcpy((uint8_t*)chunk->buf + chunk->len, buf, len); - chunk->len += len; + SerdBuffer* buffer = (SerdBuffer*)stream; + + buffer->buf = (char*)realloc(buffer->buf, buffer->len + len); + memcpy((uint8_t*)buffer->buf + buffer->len, buf, len); + buffer->len += len; return len; } uint8_t* -serd_chunk_sink_finish(SerdChunk* stream) +serd_buffer_sink_finish(SerdBuffer* stream) { - serd_chunk_sink("", 1, stream); + serd_buffer_sink("", 1, stream); return (uint8_t*)stream->buf; } |