summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin D Bennett <colin@gibibit.com>2016-05-12 18:09:51 (GMT)
committerColin D Bennett <colin@gibibit.com>2016-05-12 18:09:51 (GMT)
commitb0425804290dc25092a2af1a6a05a4f8238a8c93 (patch)
tree4043c80bc78de6da11daff5ff0eef863ec2967f5
parent63a8584b069a32b871237fc80dcb4c397b863ef7 (diff)
downloadNinja-b0425804290dc25092a2af1a6a05a4f8238a8c93.zip
Ninja-b0425804290dc25092a2af1a6a05a4f8238a8c93.tar.gz
Ninja-b0425804290dc25092a2af1a6a05a4f8238a8c93.tar.bz2
Write subprocess output to stdout in binary mode
Set stdout to binary mode while writing subprocess output, so that the CR in a CR LF sequence is not replaced with CR LF itself, which would result in CR CR LF. Based on patch posted by nico in issue #773 comment.
-rw-r--r--src/build.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/build.cc b/src/build.cc
index 7792016..e4fe21a 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -20,6 +20,11 @@
#include <stdlib.h>
#include <functional>
+#ifdef _WIN32
+#include <fcntl.h>
+#include <io.h>
+#endif
+
#if defined(__SVR4) && defined(__sun)
#include <sys/termios.h>
#endif
@@ -160,7 +165,17 @@ void BuildStatus::BuildEdgeFinished(Edge* edge,
final_output = StripAnsiEscapeCodes(output);
else
final_output = output;
+
+#ifdef _WIN32
+ // Fix extra CR being added on Windows, writing out CR CR LF (#773)
+ _setmode(_fileno(stdout), _O_BINARY); // Begin Windows extra CR fix
+#endif
+
printer_.PrintOnNewLine(final_output);
+
+#ifdef _WIN32
+ _setmode(_fileno(stdout), _O_TEXT); // End Windows extra CR fix
+#endif
}
}