From 9547c806dbf76d6afd1e324fc924abdf944c4bda Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 8 Aug 2021 20:00:43 -0400 Subject: Add a close function to SerdByteSink This simplifies everything by replacing special cases with a more general close function. A type is no longer stored in the structure, so the other constructors are now essentially syntactic sugar for the universal serd_byte_sink_new_function(). --- include/serd/serd.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'include/serd') diff --git a/include/serd/serd.h b/include/serd/serd.h index 96890dbd..e99e4e6a 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -2388,6 +2388,8 @@ typedef struct SerdByteSinkImpl SerdByteSink; Create a new byte sink that writes to a buffer. The `buffer` is owned by the caller, but will be expanded as necessary. + Note that the string in the buffer will not be null terminated until the + byte sink is closed. @param buffer Buffer to write output to. */ @@ -2415,15 +2417,17 @@ serd_byte_sink_new_filename(const char* SERD_NONNULL path, size_t block_size); The `stream` will be passed to the `write_func`, which is compatible with the standard C `fwrite` if `stream` is a `FILE*`. - @param write_func Function called with bytes to consume. + @param write_func Stream write function, like `fwrite`. + @param close_func Stream close function, like `fclose`. @param stream Context parameter passed to `sink`. @param block_size Number of bytes to write per call. */ SERD_API SerdByteSink* SERD_ALLOCATED -serd_byte_sink_new_function(SerdWriteFunc SERD_NONNULL write_func, - void* SERD_NULLABLE stream, - size_t block_size); +serd_byte_sink_new_function(SerdWriteFunc SERD_NONNULL write_func, + SerdStreamCloseFunc SERD_NULLABLE close_func, + void* SERD_NULLABLE stream, + size_t block_size); /// Flush any pending output in `sink` to the underlying write function SERD_API -- cgit v1.2.1