aboutsummaryrefslogtreecommitdiffstats
path: root/include/serd/stream.h
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 /include/serd/stream.h
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 'include/serd/stream.h')
-rw-r--r--include/serd/stream.h38
1 files changed, 25 insertions, 13 deletions
diff --git a/include/serd/stream.h b/include/serd/stream.h
index 8b023add..992db552 100644
--- a/include/serd/stream.h
+++ b/include/serd/stream.h
@@ -32,26 +32,38 @@ SERD_BEGIN_DECLS
typedef int (*SerdStreamErrorFunc)(void* SERD_NONNULL stream);
/**
- Source function for raw string input.
+ Function for reading input bytes from a stream.
- Identical semantics to `fread`, but may set errno for more informative error
- reporting than supported by SerdStreamErrorFunc.
+ This has identical semantics to `fread`, but may set `errno` for more
+ informative error reporting than supported by #SerdStreamErrorFunc.
@param buf Output 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 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);
-
-/// Sink function for raw string output
-typedef size_t (*SerdSink)(const void* SERD_NONNULL buf,
- size_t len,
- void* SERD_NONNULL stream);
+typedef size_t (*SerdReadFunc)(void* SERD_NONNULL buf,
+ size_t size,
+ size_t nmemb,
+ void* SERD_NONNULL stream);
+
+/**
+ Function for writing output bytes to a stream.
+
+ This has 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);
/**
@}