diff options
author | David Robillard <d@drobilla.net> | 2012-03-03 20:55:00 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-03-03 20:55:00 +0000 |
commit | 7b022006c47586dc00ed8bca85fcb0bdf5f9465d (patch) | |
tree | a8aa0a2be9ee7341ff02730130b3291ab2dcaace /src/writer.c | |
parent | 5d73ff3a0b529954e5192f892c21a4ad068905c9 (diff) | |
download | serd-7b022006c47586dc00ed8bca85fcb0bdf5f9465d.tar.gz serd-7b022006c47586dc00ed8bca85fcb0bdf5f9465d.tar.bz2 serd-7b022006c47586dc00ed8bca85fcb0bdf5f9465d.zip |
Add serd_chunk_sink for easy writing to a string.
git-svn-id: http://svn.drobilla.net/serd/trunk@329 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/writer.c')
-rw-r--r-- | src/writer.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/writer.c b/src/writer.c index 8bdd3382..eb9c5b2d 100644 --- a/src/writer.c +++ b/src/writer.c @@ -714,3 +714,22 @@ serd_file_sink(const void* buf, size_t len, void* stream) { return fwrite(buf, 1, len, (FILE*)stream); } + +SERD_API +size_t +serd_chunk_sink(const void* buf, size_t len, void* stream) +{ + SerdChunk* chunk = (SerdChunk*)stream; + chunk->buf = realloc((uint8_t*)chunk->buf, chunk->len + len); + memcpy((uint8_t*)chunk->buf + chunk->len, buf, len); + chunk->len += len; + return len; +} + +SERD_API +uint8_t* +serd_chunk_sink_finish(SerdChunk* stream) +{ + serd_chunk_sink("", 1, stream); + return (uint8_t*)stream->buf; +} |