Win32: Fix deadlock on std::cerr usage

This commit is contained in:
Eladash 2024-04-16 23:29:38 +03:00 committed by Elad Ashkenazi
parent 51e1598e42
commit b55f38290b
3 changed files with 30 additions and 4 deletions

View file

@ -5,6 +5,8 @@
#include <stdio.h>
#endif
#include <iostream>
namespace utils
{
void attach_console([[maybe_unused]] int stream, [[maybe_unused]] bool open_console)
@ -34,6 +36,26 @@ namespace utils
{
[[maybe_unused]] const auto con_in = freopen("CONIN$", "r", stdin);
}
#endif
}
void output_stderr(std::string_view str, bool with_endline)
{
if (with_endline)
{
#ifdef _WIN32
std::clog << str;
#else
std::cerr << str;
#endif
str = "\n";
}
#ifdef _WIN32
// Flush seems broken on Windows (deadlocks)
std::clog << str;
#else
std::cerr << str;
#endif
}
}