diff options
author | David Robillard <d@drobilla.net> | 2018-06-15 09:26:17 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-11-25 15:58:12 +0100 |
commit | 6cf2ecfab4b3cb150b154bdc1130aca022a8f89c (patch) | |
tree | 5ebefe63c8d06c6727f5d7a09cf888960d2a1c87 /serd | |
parent | c8a91d6fcae2b5c7121f059f75e2a164735e56c1 (diff) | |
download | serd-6cf2ecfab4b3cb150b154bdc1130aca022a8f89c.tar.gz serd-6cf2ecfab4b3cb150b154bdc1130aca022a8f89c.tar.bz2 serd-6cf2ecfab4b3cb150b154bdc1130aca022a8f89c.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 c7fac34a..b5b00d50 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -363,17 +363,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); /** @} @@ -425,7 +437,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`. @@ -439,7 +451,7 @@ size_t serd_uri_serialise_relative(const SerdURI* uri, const SerdURI* base, const SerdURI* root, - SerdSink sink, + SerdWriteFunc sink, void* stream); /** @@ -887,7 +899,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, @@ -959,7 +971,7 @@ serd_writer_new(SerdSyntax syntax, SerdStyle style, SerdEnv* env, const SerdURI* base_uri, - SerdSink ssink, + SerdWriteFunc ssink, void* stream); /** @@ -977,16 +989,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 @@ -996,7 +998,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(). |