diff options
author | David Robillard <d@drobilla.net> | 2021-08-08 20:00:43 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-28 21:57:07 -0500 |
commit | 9547c806dbf76d6afd1e324fc924abdf944c4bda (patch) | |
tree | 012ecf59cac892711d5bcf8f717f0ca579bbf7cd /include | |
parent | dc01b7e301e91d0d7bfc358f569f4f3849471c52 (diff) | |
download | serd-9547c806dbf76d6afd1e324fc924abdf944c4bda.tar.gz serd-9547c806dbf76d6afd1e324fc924abdf944c4bda.tar.bz2 serd-9547c806dbf76d6afd1e324fc924abdf944c4bda.zip |
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().
Diffstat (limited to 'include')
-rw-r--r-- | include/serd/serd.h | 12 |
1 files changed, 8 insertions, 4 deletions
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 |