From 6fe8ce4d34d853f55eef1793bbe8cb8dee077bd3 Mon Sep 17 00:00:00 2001
From: Adrien Nader <adrien@notk.org>
Date: Tue, 28 Dec 2010 15:38:55 +0100
Subject: [PATCH 5/5] Properly set stdout to binary mode.

---
 src/main.c      |    9 +--------
 src/mswindows.h |    4 ++++
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/main.c b/src/main.c
index d859c88..bbed33e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1176,14 +1176,7 @@ for details.\n\n"));
       if (HYPHENP (opt.output_document))
         {
 #ifdef _WIN32
-          FILE *result;
-          result = freopen ("CONOUT$", "wb", stdout);
-          if (result == NULL)
-            {
-              logputs (LOG_NOTQUIET, _("\
-WARNING: Can't reopen standard output in binary mode;\n\
-         downloaded file may contain inappropriate line endings.\n"));
-            }
+          _setmode(_fileno(stdout), _O_BINARY);
 #endif
           output_stream = stdout;
         }
diff --git a/src/mswindows.h b/src/mswindows.h
index a803287..35a28ad 100644
--- a/src/mswindows.h
+++ b/src/mswindows.h
@@ -60,6 +60,10 @@ as that of the covered work.  */
    chmod.  Unix declares these in unistd.h and fcntl.h.  */
 #include <io.h>
 
+/* Provides _O_BINARY, for _setmode, when setting file descriptors to
+ * binary mode */
+#include <fcntl.h>
+
 /* Declares getpid(). */
 #include <process.h>
 
-- 
1.7.3.2

