From: José Fonseca Date: Fri, 27 Jan 2012 14:28:06 +0000 (+0000) Subject: Ensure stdin/stdout is in binary mode on windows when pickling. X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=c6977a7e7f7b44e514b462067b8c7cb5b9040b75 Ensure stdin/stdout is in binary mode on windows when pickling. --- diff --git a/cli/cli_pickle.cpp b/cli/cli_pickle.cpp index 460a3c3..f435e20 100644 --- a/cli/cli_pickle.cpp +++ b/cli/cli_pickle.cpp @@ -26,6 +26,11 @@ #include +#ifdef _WIN32 +#include +#include +#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; } diff --git a/scripts/unpickle.py b/scripts/unpickle.py index efb8608..a3c274c 100755 --- a/scripts/unpickle.py +++ b/scripts/unpickle.py @@ -52,6 +52,15 @@ def main(): if args: optparser.error('unexpected arguments') + # Change stdin to binary mode + try: + import msvcrt + except ImportError: + pass + else: + import os + msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) + calls = 0 startTime = time.time() while True: