aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meson.build5
-rw-r--r--src/console.c22
-rw-r--r--src/console.h7
-rw-r--r--src/serdi.c16
4 files changed, 37 insertions, 13 deletions
diff --git a/meson.build b/meson.build
index 71f2dd3a..66ef536f 100644
--- a/meson.build
+++ b/meson.build
@@ -241,7 +241,10 @@ if not get_option('tools').disabled()
serdi = executable(
'serdi',
- files('src/serdi.c'),
+ files(
+ 'src/console.c',
+ 'src/serdi.c',
+ ),
c_args: c_suppressions + platform_c_args,
dependencies: [serd_dep, zix_dep],
install: true,
diff --git a/src/console.c b/src/console.c
new file mode 100644
index 00000000..a15c8e7d
--- /dev/null
+++ b/src/console.c
@@ -0,0 +1,22 @@
+// Copyright 2011-2021 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#include "console.h"
+
+#ifdef _WIN32
+# ifdef _MSC_VER
+# define WIN32_LEAN_AND_MEAN 1
+# endif
+# include <fcntl.h>
+# include <io.h>
+#endif
+
+void
+serd_set_stream_utf8_mode(FILE* const stream)
+{
+#ifdef _WIN32
+ _setmode(_fileno(stream), _O_BINARY);
+#else
+ (void)stream;
+#endif
+}
diff --git a/src/console.h b/src/console.h
new file mode 100644
index 00000000..ff21e442
--- /dev/null
+++ b/src/console.h
@@ -0,0 +1,7 @@
+// Copyright 2021 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#include <stdio.h>
+
+void
+serd_set_stream_utf8_mode(FILE* stream);
diff --git a/src/serdi.c b/src/serdi.c
index ac4d3178..bc68e591 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -1,6 +1,8 @@
// Copyright 2011-2023 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
+#include "console.h"
+
#include "serd/env.h"
#include "serd/error.h"
#include "serd/input_stream.h"
@@ -15,14 +17,6 @@
#include "serd/world.h"
#include "serd/writer.h"
-#ifdef _WIN32
-# ifdef _MSC_VER
-# define WIN32_LEAN_AND_MEAN
-# endif
-# include <fcntl.h>
-# include <io.h>
-#endif
-
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
@@ -221,10 +215,8 @@ main(int argc, char** argv)
return print_usage(prog, true);
}
-#ifdef _WIN32
- _setmode(_fileno(stdin), _O_BINARY);
- _setmode(_fileno(stdout), _O_BINARY);
-#endif
+ serd_set_stream_utf8_mode(stdin);
+ serd_set_stream_utf8_mode(stdout);
const char* input = argv[a++];