]> git.notmuchmail.org Git - apitrace/commitdiff
Set binary mode when outputing PNM from glretrace via stdout.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 9 Feb 2012 14:03:57 +0000 (14:03 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 9 Feb 2012 14:03:57 +0000 (14:03 +0000)
cli/cli_pickle.cpp
common/os_binary.hpp [new file with mode: 0644]
glretrace_main.cpp

index 6af879fa3da6960d7aca1a02b2c06cf8e27e2b4a..c37c0f8bf8c85d00d4a83484bb9eab294c903c6d 100644 (file)
 
 #include <string.h>
 
-#ifdef _WIN32
-#include <fcntl.h>
-#include <io.h>
-#endif
-
 #include "pickle.hpp"
 
+#include "os_binary.hpp"
+
 #include "cli.hpp"
 #include "cli_pager.hpp"
 
@@ -189,14 +186,7 @@ command(int argc, char *argv[])
         }
     }
 
-#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
+    os::setBinaryMode(stdout);
 
     for (; i < argc; ++i) {
         trace::Parser parser;
@@ -218,14 +208,6 @@ 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/common/os_binary.hpp b/common/os_binary.hpp
new file mode 100644 (file)
index 0000000..876bdb6
--- /dev/null
@@ -0,0 +1,60 @@
+/**************************************************************************
+ *
+ * Copyright 2011 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/*
+ * Force binary mode standard files on Windows.
+ */
+
+#ifndef _OS_BINARY_HPP_
+#define _OS_BINARY_HPP_
+
+
+#include <stdio.h>
+
+#ifdef _WIN32
+#include <assert.h>
+
+#include <fcntl.h>
+#include <io.h>
+#endif
+
+
+namespace os {
+
+
+void setBinaryMode(FILE *fp) {
+#ifdef _WIN32
+    fflush(fp);
+    int mode = _setmode(_fileno(fp), _O_BINARY);
+    assert(mode != -1);
+#else
+    (void)fp;
+#endif
+}
+
+
+} /* namespace os */
+
+#endif /* _OS_BINARY_HPP_ */
index 785d6feaadf6bdbf90b4c359958b7478f2254315..11f34ce8200ca16215780c0fbfce976f918ca414 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <string.h>
 
+#include "os_binary.hpp"
 #include "os_string.hpp"
 #include "os_time.hpp"
 #include "image.hpp"
@@ -342,6 +343,7 @@ int main(int argc, char **argv)
                 snapshot_frequency = trace::CallSet(trace::FREQUENCY_FRAME);
             }
             if (snapshot_prefix[0] == '-' && snapshot_prefix[1] == 0) {
+                os::setBinaryMode(stdout);
                 retrace::verbosity = -2;
             }
         } else if (!strcmp(arg, "-S")) {