aboutsummaryrefslogtreecommitdiffstats
path: root/include/serd
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-06-15 09:26:17 -0400
committerDavid Robillard <d@drobilla.net>2021-03-07 15:32:24 -0500
commitee254d3e92900986526078bb9cbef1642a51dac1 (patch)
tree5e3197d7abbebde216024efec5b7189559ac6b4e /include/serd
parent9a8e06aa5bdc62ed589bd8ed5789bd059cec0700 (diff)
downloadserd-ee254d3e92900986526078bb9cbef1642a51dac1.tar.gz
serd-ee254d3e92900986526078bb9cbef1642a51dac1.tar.bz2
serd-ee254d3e92900986526078bb9cbef1642a51dac1.zip
Bring read/write interface closer to C standard
Diffstat (limited to 'include/serd')
-rw-r--r--include/serd/serd.h65
1 files changed, 33 insertions, 32 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 000a8ef8..fcc8fb47 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -363,17 +363,29 @@ typedef int (*SerdStreamErrorFunc)(void* SERD_NONNULL stream);
@param size Size of a single element of data in bytes (always 1).
@param nmemb Number of elements to read.
@param stream Stream to read from (FILE* for fread).
- @return Number of elements (bytes) read.
+ @return Number of elements (bytes) read, which is short on error.
*/
-typedef size_t (*SerdSource)(void* SERD_NONNULL buf,
- size_t size,
- size_t nmemb,
- void* SERD_NONNULL stream);
+typedef size_t (*SerdReadFunc)(void* SERD_NONNULL buf,
+ size_t size,
+ size_t nmemb,
+ void* SERD_NONNULL stream);
-/// Sink function for raw string output
-typedef size_t (*SerdSink)(const void* SERD_NONNULL buf,
- size_t len,
- void* SERD_NONNULL stream);
+/**
+ Sink function for raw string output.
+
+ Identical semantics to `fwrite`, but may set errno for more informative
+ error reporting than supported by SerdStreamErrorFunc.
+
+ @param buf Input buffer.
+ @param size Size of a single element of data in bytes (always 1).
+ @param nmemb Number of elements to read.
+ @param stream Stream to write to (FILE* for fread).
+ @return Number of elements (bytes) written, which is short on error.
+*/
+typedef size_t (*SerdWriteFunc)(const void* SERD_NONNULL buf,
+ size_t size,
+ size_t nmemb,
+ void* SERD_NONNULL stream);
/**
@}
@@ -475,9 +487,9 @@ serd_uri_is_within(SerdURIView r, SerdURIView base);
*/
SERD_API
size_t
-serd_write_uri(SerdURIView uri,
- SerdSink SERD_NONNULL sink,
- void* SERD_NONNULL stream);
+serd_write_uri(SerdURIView uri,
+ SerdWriteFunc SERD_NONNULL sink,
+ void* SERD_NONNULL stream);
/**
@}
@@ -884,7 +896,7 @@ serd_reader_read_file(SerdReader* SERD_NONNULL reader,
SERD_API
SerdStatus
serd_reader_start_stream(SerdReader* SERD_NONNULL reader,
- SerdSource SERD_NONNULL read_func,
+ SerdReadFunc SERD_NONNULL read_func,
SerdStreamErrorFunc SERD_NONNULL error_func,
void* SERD_NONNULL stream,
const char* SERD_NULLABLE name,
@@ -944,11 +956,11 @@ serd_reader_free(SerdReader* SERD_NULLABLE reader);
/// Create a new RDF writer
SERD_API
SerdWriter* SERD_ALLOCATED
-serd_writer_new(SerdSyntax syntax,
- SerdWriterFlags flags,
- SerdEnv* SERD_NONNULL env,
- SerdSink SERD_NONNULL ssink,
- void* SERD_NULLABLE stream);
+serd_writer_new(SerdSyntax syntax,
+ SerdWriterFlags flags,
+ SerdEnv* SERD_NONNULL env,
+ SerdWriteFunc SERD_NONNULL ssink,
+ void* SERD_NULLABLE stream);
/// Free `writer`
SERD_API
@@ -961,19 +973,7 @@ SerdEnv* SERD_NONNULL
serd_writer_env(SerdWriter* SERD_NONNULL writer);
/**
- A convenience sink function for writing to a FILE*.
-
- This function can be used as a SerdSink when writing to a FILE*. The
- `stream` parameter must be a FILE* opened for writing.
-*/
-SERD_API
-size_t
-serd_file_sink(const void* SERD_NONNULL buf,
- size_t len,
- void* SERD_NONNULL stream);
-
-/**
- A convenience sink function for writing to a string
+ A convenience sink function for writing to a string.
This function can be used as a SerdSink to write to a SerdBuffer which is
resized as necessary with realloc(). The `stream` parameter must point to
@@ -983,7 +983,8 @@ serd_file_sink(const void* SERD_NONNULL buf,
SERD_API
size_t
serd_buffer_sink(const void* SERD_NONNULL buf,
- size_t len,
+ size_t size,
+ size_t nmemb,
void* SERD_NONNULL stream);
/**