From d4775e375e2e69e33efad066eb8a5c30b5347361 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 29 Jun 2022 15:52:35 +0200 Subject: [PATCH] output buffering: set explicitly Set output buffering to "line" for stdout and "no" for stderr. This is the case usually but not always (eg. MSYS, GUI console) so make this explicit to be deterministic. --- src/host.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/host.cpp b/src/host.cpp index d920ade8a..6f89086b7 100644 --- a/src/host.cpp +++ b/src/host.cpp @@ -73,6 +73,7 @@ #include #include #include +#include #if defined HAVE_X || defined BUILD_LIBRARIES #include @@ -150,9 +151,9 @@ ADD_TO_PARAM("stderr-buf", "* stderr-buf={no|line|full}\n" " Buffering for stderr\n"); bool set_output_buffering() { - const unordered_map outs = { - { "stdout-buf", stdout }, - { "stderr-buf", stderr } + const unordered_map> outs = { // pair + { "stdout-buf", pair{stdout, _IOLBF} }, + { "stderr-buf", pair{stderr, _IONBF} } }; for (auto outp : outs) { if (get_commandline_param(outp.first)) { @@ -165,15 +166,11 @@ bool set_output_buffering() { log_msg(LOG_LEVEL_ERROR, "Wrong buffer type: %s\n", get_commandline_param(outp.first)); return false; } else { - setvbuf(outp.second, NULL, it->second, 0); + setvbuf(outp.second.first, NULL, it->second, 0); } - } else { -#ifdef _WIN32 - if (rang::rang_implementation::isMsysPty(_fileno(outp.second))) { - cout << rang::fg::cyan << "MSYS terminal detected, setting \"--param " << outp.first << "=no\" automatically." << rang::fg::reset << endl; - setvbuf(outp.second, NULL, _IONBF, 0); - } -#endif + } else { // default + //if (rang::rang_implementation::isMsysPty(_fileno(outp.second))) { + setvbuf(outp.second.first, NULL, outp.second.second, 0); } } return true;