From a083c64f506175029280ff76defa0ad7d7ae2ea0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 28 Jun 2020 23:26:48 +0200 Subject: Simplify input stream API --- include/serd/stream.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'include/serd/stream.h') diff --git a/include/serd/stream.h b/include/serd/stream.h index 4b3582f5..f59e2c9d 100644 --- a/include/serd/stream.h +++ b/include/serd/stream.h @@ -32,11 +32,20 @@ SERD_BEGIN_DECLS */ typedef int (*SerdStreamErrorFunc)(void* ZIX_NONNULL stream); +/** + Function to close an I/O stream. + + Identical semantics to `fclose`. + + @return Non-zero if `stream` has encountered an error. +*/ +typedef int (*SerdStreamCloseFunc)(void* ZIX_NONNULL stream); + /** Function for reading input bytes from a stream. This has identical semantics to `fread`, but may set `errno` for more - informative error reporting than supported by #SerdStreamErrorFunc. + informative error reporting than supported by #SerdErrorFunc. @param buf Output buffer. @param size Size of a single element of data in bytes (always 1). @@ -66,6 +75,27 @@ typedef size_t (*SerdWriteFunc)(const void* ZIX_NONNULL buf, size_t nmemb, void* ZIX_NONNULL stream); +/** + Function for detecting I/O stream errors. + + This has identical semantics to `ferror`. + + @return Non-zero if `stream` has encountered an error. +*/ +typedef int (*SerdErrorFunc)(void* ZIX_NONNULL stream); + +/** + Function for closing an I/O stream. + + This has identical semantics to `fclose`. Note that when writing, this may + flush the stream which can cause errors, including errors caused by previous + writes that appeared successful at the time. Therefore it is necessary to + check the return value of this function to properly detect write errors. + + @return Non-zero if `stream` has encountered an error. +*/ +typedef int (*SerdCloseFunc)(void* ZIX_NONNULL stream); + /** @} */ -- cgit v1.2.1