From c4c763e75ee09511621eb432618116e8ec2013c5 Mon Sep 17 00:00:00 2001 From: ALTracer <11005378+ALTracer@users.noreply.github.com> Date: Sun, 21 Apr 2024 12:34:56 +0300 Subject: [PATCH] hosted: Use unbuffered stdout on Windows * Line-buffered mode is unsupported on Windows libc, and 4k-buffered mode is not interactive enough. * Disable buffering completely as an alternative to sprinkling tons of fflush() calls. --- src/platforms/hosted/platform.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/platforms/hosted/platform.c b/src/platforms/hosted/platform.c index 22bb30a3dfa..1288818fc53 100644 --- a/src/platforms/hosted/platform.c +++ b/src/platforms/hosted/platform.c @@ -114,6 +114,10 @@ void platform_init(int argc, char **argv) { #if defined(_WIN32) || defined(__CYGWIN__) SetConsoleOutputCP(CP_UTF8); + if (setvbuf(stdout, NULL, _IONBF, 0) < 0) { + int err = errno; + fprintf(stderr, "%s: %s returns %s\n", __func__, "setvbuf()", strerror(err)); + } #endif cl_init(&cl_opts, argc, argv); atexit(exit_function);