From ee254d3e92900986526078bb9cbef1642a51dac1 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 15 Jun 2018 09:26:17 -0400 Subject: Bring read/write interface closer to C standard --- include/serd/serd.h | 65 +++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) (limited to 'include/serd/serd.h') 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); /** -- cgit v1.2.1