From ced82a0501423bdce13210006bf39fe0263f0c24 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 17 Jan 2020 19:01:13 +0000 Subject: [PATCH] examples: Change stdin and stdout to binary mode On windows text mode for these plays with newline escape sequences, breaking the ContextStream encoding. Fixes: #12 --- examples/hello_debugger.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/hello_debugger.cpp b/examples/hello_debugger.cpp index dd234f2..342e862 100644 --- a/examples/hello_debugger.cpp +++ b/examples/hello_debugger.cpp @@ -24,11 +24,20 @@ #include #include +#ifdef _MSC_VER +#define OS_WINDOWS 1 +#endif + // Uncomment the line below and change to a file path to // write all DAP communications to the given path. // // #define LOG_TO_FILE "" +#ifdef OS_WINDOWS +#include // _O_BINARY +#include // _setmode +#endif // OS_WINDOWS + namespace { // sourceContent holds the synthetic file source. @@ -147,7 +156,14 @@ void Event::fire() { } // anonymous namespace // main() entry point to the DAP server. -int main(int, char*[]) { +int main(int, char* []) { +#ifdef OS_WINDOWS + // Change stdin & stdout from text mode to binary mode. + // This ensures sequences of \r\n are not changed to \n. + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); +#endif // OS_WINDOWS + std::shared_ptr log; #ifdef LOG_TO_FILE log = dap::file(LOG_TO_FILE);