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(). --- tools/console.c | 3 ++- tools/serdi.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/console.c b/tools/console.c index 339aca29..235d15d0 100644 --- a/tools/console.c +++ b/tools/console.c @@ -168,7 +168,8 @@ serd_open_output(const char* const filename, const size_t block_size) { if (!filename || !strcmp(filename, "-")) { serd_set_stream_utf8_mode(stdout); - return serd_byte_sink_new_function((SerdWriteFunc)fwrite, stdout, 1); + return serd_byte_sink_new_function( + (SerdWriteFunc)fwrite, (SerdStreamCloseFunc)fclose, stdout, 1); } return serd_byte_sink_new_filename(filename, block_size); diff --git a/tools/serdi.c b/tools/serdi.c index db1cfde0..db4a016f 100644 --- a/tools/serdi.c +++ b/tools/serdi.c @@ -527,7 +527,7 @@ main(int argc, char** argv) serd_node_free(base); serd_world_free(world); - if (serd_byte_sink_close(byte_sink) || (!out_filename && fclose(stdout))) { + if (serd_byte_sink_close(byte_sink)) { perror("serdi: write error"); st = SERD_ERR_UNKNOWN; } -- cgit v1.2.1