aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/console.c12
-rw-r--r--src/console.h3
-rw-r--r--src/serdi.c6
3 files changed, 16 insertions, 5 deletions
diff --git a/src/console.c b/src/console.c
index fd339526..3d2c110a 100644
--- a/src/console.c
+++ b/src/console.c
@@ -79,3 +79,15 @@ serd_open_input(const char* const filename, const size_t page_size)
return byte_source;
}
+
+SerdByteSink*
+serd_open_output(const char* const filename, const size_t page_size)
+{
+ if (!filename || !strcmp(filename, "-")) {
+ serd_set_stream_utf8_mode(stdout);
+ return serd_byte_sink_new_function(
+ (SerdWriteFunc)fwrite, stdout, page_size);
+ }
+
+ return serd_byte_sink_new_filename(filename, page_size);
+}
diff --git a/src/console.h b/src/console.h
index 80c7590b..f1d11f8e 100644
--- a/src/console.h
+++ b/src/console.h
@@ -26,3 +26,6 @@ serd_print_version(const char* program);
SerdByteSource*
serd_open_input(const char* filename, size_t page_size);
+
+SerdByteSink*
+serd_open_output(const char* filename, size_t page_size);
diff --git a/src/serdi.c b/src/serdi.c
index 56762b23..b1771fec 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -380,12 +380,8 @@ main(int argc, char** argv)
const SerdDescribeFlags describe_flags =
no_inline ? SERD_NO_INLINE_OBJECTS : 0u;
- const size_t block_size = bulk_write ? 4096u : 1u;
SerdByteSink* const byte_sink =
- out_filename
- ? serd_byte_sink_new_filename(out_filename, block_size)
- : serd_byte_sink_new_function((SerdWriteFunc)fwrite, stdout, block_size);
-
+ serd_open_output(out_filename, bulk_write ? 4096u : 1u);
if (!byte_sink) {
perror("serdi: error opening output file");
return 1;