From fcab8cb3072724eca6ab8618ec16704451891f69 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 9 Feb 2012 14:03:57 +0000 Subject: [PATCH] Set binary mode when outputing PNM from glretrace via stdout. --- cli/cli_pickle.cpp | 24 +++--------------- common/os_binary.hpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ glretrace_main.cpp | 2 ++ 3 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 common/os_binary.hpp diff --git a/cli/cli_pickle.cpp b/cli/cli_pickle.cpp index 6af879f..c37c0f8 100644 --- a/cli/cli_pickle.cpp +++ b/cli/cli_pickle.cpp @@ -26,13 +26,10 @@ #include -#ifdef _WIN32 -#include -#include -#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 index 0000000..876bdb6 --- /dev/null +++ b/common/os_binary.hpp @@ -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 + +#ifdef _WIN32 +#include + +#include +#include +#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_ */ diff --git a/glretrace_main.cpp b/glretrace_main.cpp index 785d6fe..11f34ce 100644 --- a/glretrace_main.cpp +++ b/glretrace_main.cpp @@ -26,6 +26,7 @@ #include +#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")) { -- 2.45.2