diff options
author | José Fonseca <jose.r.fonseca@gmail.com> | 2012-01-27 14:28:06 +0000 |
---|---|---|
committer | José Fonseca <jose.r.fonseca@gmail.com> | 2012-01-27 14:28:06 +0000 |
commit | c6977a7e7f7b44e514b462067b8c7cb5b9040b75 (patch) | |
tree | a9078f62a6ffcdf21d76a6a8806788b2b7bf618d /cli | |
parent | 447576da195e098d54c8e1279f7bb3ff1b5f2d49 (diff) |
Ensure stdin/stdout is in binary mode on windows when pickling.
Diffstat (limited to 'cli')
-rw-r--r-- | cli/cli_pickle.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/cli/cli_pickle.cpp b/cli/cli_pickle.cpp index 460a3c3c..f435e207 100644 --- a/cli/cli_pickle.cpp +++ b/cli/cli_pickle.cpp @@ -26,6 +26,11 @@ #include <string.h> +#ifdef _WIN32 +#include <fcntl.h> +#include <io.h> +#endif + #include "pickle.hpp" #include "cli.hpp" @@ -183,7 +188,15 @@ command(int argc, char *argv[]) return 1; } } - + +#ifdef _WIN32 + // Set stdout in binary mode + fflush(stdout); + int mode = _setmode(_fileno(stdout), _O_BINARY); + if (mode == -1) { + std::cerr << "warning: failed to set stdout in binary mode\n"; + } +#endif for (; i < argc; ++i) { trace::Parser parser; @@ -205,6 +218,14 @@ command(int argc, char *argv[]) } } +#ifdef _WIN32 + std::cout.flush(); + fflush(stdout); + if (mode != -1) { + _setmode(_fileno(stdout), mode); + } +#endif + return 0; } |