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
This commit is contained in:
parent
96b25aafe0
commit
ced82a0501
@ -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.
|
||||||
@ -148,6 +157,13 @@ void Event::fire() {
|
|||||||
|
|
||||||
// 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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user