diff options
author | David Robillard <d@drobilla.net> | 2018-06-15 09:26:17 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-07 15:32:24 -0500 |
commit | ee254d3e92900986526078bb9cbef1642a51dac1 (patch) | |
tree | 5e3197d7abbebde216024efec5b7189559ac6b4e /src/writer.c | |
parent | 9a8e06aa5bdc62ed589bd8ed5789bd059cec0700 (diff) | |
download | serd-ee254d3e92900986526078bb9cbef1642a51dac1.tar.gz serd-ee254d3e92900986526078bb9cbef1642a51dac1.tar.bz2 serd-ee254d3e92900986526078bb9cbef1642a51dac1.zip |
Bring read/write interface closer to C standard
Diffstat (limited to 'src/writer.c')
-rw-r--r-- | src/writer.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/writer.c b/src/writer.c index 75734c0c..c70c5f1d 100644 --- a/src/writer.c +++ b/src/writer.c @@ -434,9 +434,11 @@ write_text(SerdWriter* writer, } static size_t -uri_sink(const void* buf, size_t len, void* stream) +uri_sink(const void* buf, size_t size, size_t nmemb, void* stream) { - return write_uri((SerdWriter*)stream, (const char*)buf, len); + (void)size; + assert(size == 1); + return write_uri((SerdWriter*)stream, (const char*)buf, nmemb); } static void @@ -956,7 +958,7 @@ SerdWriter* serd_writer_new(SerdSyntax syntax, SerdWriterFlags flags, SerdEnv* env, - SerdSink ssink, + SerdWriteFunc ssink, void* stream) { const WriteContext context = WRITE_CONTEXT_NULL; @@ -1088,25 +1090,21 @@ serd_writer_env(SerdWriter* writer) } size_t -serd_file_sink(const void* buf, size_t len, void* stream) +serd_buffer_sink(const void* buf, size_t size, size_t nmemb, void* stream) { - return fwrite(buf, 1, len, (FILE*)stream); -} + assert(size == 1); + (void)size; -size_t -serd_buffer_sink(const void* buf, size_t len, void* stream) -{ 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; + buffer->buf = (char*)realloc(buffer->buf, buffer->len + nmemb); + memcpy((uint8_t*)buffer->buf + buffer->len, buf, nmemb); + buffer->len += nmemb; + return nmemb; } char* serd_buffer_sink_finish(SerdBuffer* stream) { - serd_buffer_sink("", 1, stream); + serd_buffer_sink("", 1, 1, stream); return (char*)stream->buf; } |