For PR787:
Provide new llvm::sys::Program facilities for converting the stdout and
stdin to binary mode. There is no standard way to do this and the available
mechanisms are platform specific. Adjust the bytecode reader and writer to
use these methods when their input is stdin or output is stdout. THis avoids
the problem with \n writing CRLF to a bytecode file on windows.

Patch Contributed by Michael Smith.

llvm-svn: 28722
diff --git a/llvm/lib/System/Win32/Program.inc b/llvm/lib/System/Win32/Program.inc
index 95f56b2..c29adf0 100644
--- a/llvm/lib/System/Win32/Program.inc
+++ b/llvm/lib/System/Win32/Program.inc
@@ -12,8 +12,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "Win32.h"
+#include <cstdio>
 #include <malloc.h>
 #include <io.h>
+#include <fcntl.h>
 
 //===----------------------------------------------------------------------===//
 //=== WARNING: Implementation here must contain only Win32 specific code 
@@ -218,4 +220,16 @@
   return status;
 }
 
+void Program::ChangeStdinToBinary(){
+  int result = _setmode( _fileno(stdin), _O_BINARY );
+  if( result == -1 )
+    throw std::string("Cannot set input mode on stdin to binary.");
+}
+
+void Program::ChangeStdoutToBinary(){
+  int result = _setmode( _fileno(stdout), _O_BINARY );
+  if( result == -1 )
+    throw std::string("Cannot set output mode on stdout to binary.");
+}
+
 }