summaryrefslogtreecommitdiffstats
path: root/Source/cmcmd.cxx
diff options
context:
space:
mode:
authorJohnny Jazeix <jazeix@gmail.com>2020-10-13 21:48:12 (GMT)
committerBrad King <brad.king@kitware.com>2020-10-14 16:08:07 (GMT)
commitf7a5f283188c1e51b0fb549f0a78afaf1d570383 (patch)
treec5fade762b9cada9b7fd9cf964528c43ccd45c80 /Source/cmcmd.cxx
parent90b39a52090e6ba52424b441d5827b2b6e11ff56 (diff)
downloadCMake-f7a5f283188c1e51b0fb549f0a78afaf1d570383.zip
CMake-f7a5f283188c1e51b0fb549f0a78afaf1d570383.tar.gz
CMake-f7a5f283188c1e51b0fb549f0a78afaf1d570383.tar.bz2
cmake: Fix '-E cat' command for binary files on Windows
Reset `std::cout` to write in binary mode with no encoding conversions. Co-Author: Brad King <brad.king@kitware.com> Fixes: #21295
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r--Source/cmcmd.cxx14
1 files changed, 13 insertions, 1 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 150fefd..a1fafcb 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -48,6 +48,12 @@
#include <sstream>
#include <utility>
+#ifdef _WIN32
+# include <fcntl.h> // for _O_BINARY
+# include <io.h> // for _setmode
+# include <stdio.h> // for std{out,err} and fileno
+#endif
+
#include <cm/string_view>
#include "cmsys/Directory.hxx"
@@ -178,6 +184,9 @@ static bool cmTarFilesFrom(std::string const& file,
static void cmCatFile(const std::string& fileToAppend)
{
+#ifdef _WIN32
+ _setmode(fileno(stdout), _O_BINARY);
+#endif
cmsys::ifstream source(fileToAppend.c_str(),
(std::ios::binary | std::ios::in));
std::cout << source.rdbuf();
@@ -497,7 +506,8 @@ int cmcmd::HandleCoCompileCommands(std::vector<std::string> const& args)
return ret;
}
-int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args)
+int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
+ std::unique_ptr<cmConsoleBuf> consoleBuf)
{
// IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx
if (args.size() > 1) {
@@ -951,6 +961,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args)
cmSystemTools::Error(arg + ": no such file or directory (ignoring)");
return_value = 1;
} else {
+ // Destroy console buffers to drop cout/cerr encoding transform.
+ consoleBuf.reset();
cmCatFile(arg);
}
}