diff options
author | David Robillard <d@drobilla.net> | 2018-06-15 09:26:17 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-06-21 18:12:03 +0200 |
commit | 10bf7f7ce76d8b679449bfc9ba8b1814a79407fb (patch) | |
tree | ccb0aef1a21bdb603e4125e1b112d6ffd8b4ab53 /serd | |
parent | 531b6c972df84a8f7545af2158236e9d0c3a460c (diff) | |
download | serd-10bf7f7ce76d8b679449bfc9ba8b1814a79407fb.tar.gz serd-10bf7f7ce76d8b679449bfc9ba8b1814a79407fb.tar.bz2 serd-10bf7f7ce76d8b679449bfc9ba8b1814a79407fb.zip |
Bring read/write interface closer to C standard
Diffstat (limited to 'serd')
-rw-r--r-- | serd/serd.h | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/serd/serd.h b/serd/serd.h index 5e327f2c..37a6ef52 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -354,17 +354,29 @@ typedef int (*SerdStreamErrorFunc)(void* 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* buf, - size_t size, - size_t nmemb, - void* stream); +typedef size_t (*SerdReadFunc)(void* buf, + size_t size, + size_t nmemb, + void* 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 (*SerdSink)(const void* buf, size_t len, void* stream); +typedef size_t (*SerdWriteFunc)(const void* buf, + size_t size, + size_t nmemb, + void* stream); /** @} @@ -416,7 +428,7 @@ serd_uri_resolve(const SerdURI* r, const SerdURI* base, SerdURI* t); */ SERD_API size_t -serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream); +serd_uri_serialise(const SerdURI* uri, SerdWriteFunc sink, void* stream); /** Serialise `uri` relative to `base` with a series of calls to `sink`. @@ -430,7 +442,7 @@ size_t serd_uri_serialise_relative(const SerdURI* uri, const SerdURI* base, const SerdURI* root, - SerdSink sink, + SerdWriteFunc sink, void* stream); /** @@ -875,7 +887,7 @@ serd_reader_read_file(SerdReader* reader, SERD_API SerdStatus serd_reader_start_stream(SerdReader* reader, - SerdSource read_func, + SerdReadFunc read_func, SerdStreamErrorFunc error_func, void* stream, const char* name, @@ -947,7 +959,7 @@ serd_writer_new(SerdSyntax syntax, SerdStyle style, SerdEnv* env, const SerdURI* base_uri, - SerdSink ssink, + SerdWriteFunc ssink, void* stream); /** @@ -965,16 +977,6 @@ SerdEnv* serd_writer_get_env(SerdWriter* 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* buf, size_t len, void* stream); - -/** A convenience sink function for writing to a string. This function can be used as a SerdSink to write to a SerdBuffer which is @@ -984,7 +986,7 @@ serd_file_sink(const void* buf, size_t len, void* stream); */ SERD_API size_t -serd_buffer_sink(const void* buf, size_t len, void* stream); +serd_buffer_sink(const void* buf, size_t size, size_t nmemb, void* stream); /** Finish a serialisation to a buffer with serd_buffer_sink(). |