]> git.cworth.org Git - apitrace/blobdiff - cli/cli_pickle.cpp
Ensure stdin/stdout is in binary mode on windows when pickling.
[apitrace] / cli / cli_pickle.cpp
index 460a3c3c516dac018bbac8893cd41ed7060e4048..f435e2072316b8e459e94cba948cb4fe6bba6c7a 100644 (file)
 
 #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;
 }