Commit ced82a05 by Ben Clayton Committed by Ben Clayton

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
parent 96b25aaf
...@@ -24,11 +24,20 @@ ...@@ -24,11 +24,20 @@
#include <mutex> #include <mutex>
#include <unordered_set> #include <unordered_set>
#ifdef _MSC_VER
#define OS_WINDOWS 1
#endif
// Uncomment the line below and change <path-to-log-file> to a file path to // Uncomment the line below and change <path-to-log-file> to a file path to
// write all DAP communications to the given path. // write all DAP communications to the given path.
// //
// #define LOG_TO_FILE "<path-to-log-file>" // #define LOG_TO_FILE "<path-to-log-file>"
#ifdef OS_WINDOWS
#include <fcntl.h> // _O_BINARY
#include <io.h> // _setmode
#endif // OS_WINDOWS
namespace { namespace {
// sourceContent holds the synthetic file source. // sourceContent holds the synthetic file source.
...@@ -147,7 +156,14 @@ void Event::fire() { ...@@ -147,7 +156,14 @@ void Event::fire() {
} // anonymous namespace } // anonymous namespace
// main() entry point to the DAP server. // 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<dap::Writer> log; std::shared_ptr<dap::Writer> log;
#ifdef LOG_TO_FILE #ifdef LOG_TO_FILE
log = dap::file(LOG_TO_FILE); log = dap::file(LOG_TO_FILE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment