kythe: Put stdout in binary mode on Windows

The Windows build failed the new --output_path test. Windows opens stdout
in text mode, so it turns every "\n" into "\r\n". The --output_path file is
opened in binary mode, so the two outputs did not match byte for byte, and
the test compares them.

Set stdout to binary mode, the same way verible-verilog-format and
verible-verilog-obfuscate already do. Kythe facts are data, not text: the
proto entries are binary, and the JSON modes have to produce the same bytes
on every platform.

This also repairs --print_kythe_facts=proto to stdout on Windows, which
wrote "\r" bytes into the proto stream before this change.
diff --git a/verible/verilog/tools/kythe/verilog-kythe-extractor.cc b/verible/verilog/tools/kythe/verilog-kythe-extractor.cc
index f21fdf4..321db49 100644
--- a/verible/verilog/tools/kythe/verilog-kythe-extractor.cc
+++ b/verible/verilog/tools/kythe/verilog-kythe-extractor.cc
@@ -37,6 +37,11 @@
 #include "verible/verilog/tools/kythe/kythe-facts.h"
 #include "verible/verilog/tools/kythe/kythe-proto-output.h"
 
+#ifdef _WIN32
+#include <fcntl.h>
+#include <io.h>
+#endif
+
 // for --print_kythe_facts flag
 enum class PrintMode {
   kJSON,
@@ -174,6 +179,13 @@
 }  // namespace verilog
 
 int main(int argc, char **argv) {
+#ifdef _WIN32
+  // Windows messes with newlines by default. Fix this here, so that stdout
+  // carries the same bytes as --output_path, and so that the proto entries
+  // stay binary.
+  _setmode(_fileno(stdout), _O_BINARY);
+#endif
+
   const auto usage =
       absl::StrCat("usage: ", argv[0], " [options] --file_list_path FILE\n", R"(
 Extracts kythe indexing facts from the given SystemVerilog source files.
@@ -212,8 +224,8 @@
                                   absl::GetFlag(FLAGS_verilog_project_name),
                                   /*provide_lookup_file_origin=*/false);
 
-  // Send the facts to a file when asked to, otherwise to stdout. The file is
-  // opened in binary mode because --print_kythe_facts=proto is not text.
+  // Send the facts to a file when asked to, otherwise to stdout. Both go out
+  // in binary mode, because --print_kythe_facts=proto is not text.
   const std::string output_path = absl::GetFlag(FLAGS_output_path);
   std::unique_ptr<std::ofstream> file_closer;
   std::ostream *output_stream = &std::cout;