aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-06-15 09:26:17 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commitb631e7a3d6a807aaf4919396b62ba96e1a9f0bd9 (patch)
tree70a49bcc4d79d83d0f80f115da457514e09977d0 /src/writer.c
parentfe0b6d5d4d78cb31e1bf2381198890d070e46ed1 (diff)
downloadserd-b631e7a3d6a807aaf4919396b62ba96e1a9f0bd9.tar.gz
serd-b631e7a3d6a807aaf4919396b62ba96e1a9f0bd9.tar.bz2
serd-b631e7a3d6a807aaf4919396b62ba96e1a9f0bd9.zip
Bring read/write interface closer to the C standard
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/writer.c b/src/writer.c
index cea75aec..01beb315 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -23,6 +23,7 @@
#include "serd/uri.h"
#include "serd/writer.h"
+#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
@@ -553,12 +554,15 @@ typedef struct {
} UriSinkContext;
SERD_NODISCARD 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)
{
+ (void)size;
+ assert(size == 1);
+
UriSinkContext* const context = (UriSinkContext*)stream;
SerdWriter* const writer = context->writer;
- return write_uri(writer, (const char*)buf, len, &context->status);
+ return write_uri(writer, (const char*)buf, nmemb, &context->status);
}
SERD_NODISCARD static SerdStatus
@@ -1126,7 +1130,7 @@ SerdWriter*
serd_writer_new(SerdSyntax syntax,
SerdWriterFlags flags,
SerdEnv* env,
- SerdSink ssink,
+ SerdWriteFunc ssink,
void* stream)
{
const WriteContext context = WRITE_CONTEXT_NULL;
@@ -1262,27 +1266,27 @@ serd_writer_env(SerdWriter* writer)
}
size_t
-serd_file_sink(const void* buf, size_t len, void* stream)
+serd_buffer_sink(const void* const buf,
+ const size_t size,
+ const size_t nmemb,
+ void* const stream)
{
- return fwrite(buf, 1, len, (FILE*)stream);
-}
+ assert(size == 1);
+ (void)size;
-size_t
-serd_buffer_sink(const void* const buf, const size_t len, void* const stream)
-{
SerdBuffer* buffer = (SerdBuffer*)stream;
- char* new_buf = (char*)realloc((char*)buffer->buf, buffer->len + len);
+ char* new_buf = (char*)realloc(buffer->buf, buffer->len + nmemb);
if (new_buf) {
- memcpy(new_buf + buffer->len, buf, len);
+ memcpy(new_buf + buffer->len, buf, nmemb);
buffer->buf = new_buf;
- buffer->len += len;
+ buffer->len += nmemb;
}
- return len;
+ return nmemb;
}
char*
serd_buffer_sink_finish(SerdBuffer* const stream)
{
- serd_buffer_sink("", 1, stream);
+ serd_buffer_sink("", 1, 1, stream);
return (char*)stream->buf;
}