Patch from Maciej Adamczyk to set standard output to binary mode in
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 3 Jun 2012 20:51:47 +0000 (20:51 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 3 Jun 2012 20:51:47 +0000 (20:51 +0000)
the standalone deflate utility modes, so you can redirect output to a
file and end up with correct data in that file.

git-svn-id: svn://svn.tartarus.org/sgt/halibut@9552 cda61777-01e9-0310-a592-d414129be87e

deflate.c

index 186e14c..6bbceae 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -2601,6 +2601,15 @@ const char *const deflate_error_sym[DEFLATE_NUM_ERRORS] = {
 };
 #undef A
 
+#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64)
+#define WINDOWS_IO
+#endif
+
+#if defined(WINDOWS_IO) && (defined(STANDALONE) || defined(TESTMODE))
+#include <fcntl.h>
+#include <io.h>
+#endif
+
 #ifdef STANDALONE
 
 int main(int argc, char **argv)
@@ -2676,6 +2685,14 @@ int main(int argc, char **argv)
         fprintf(stderr, "unable to open '%s'\n", filename);
         return 1;
     }
+    
+#ifdef WINDOWS_IO   
+    if(_setmode(_fileno(stdout), _O_BINARY ) == -1)
+    {
+        fprintf(stderr, "Can't set stdout to binary mode\n");
+        return 1;
+    }
+#endif
 
     do {
        ret = fread(buf, 1, sizeof(buf), fp);
@@ -2764,6 +2781,14 @@ int main(int argc, char **argv)
 
     chandle = deflate_compress_new(DEFLATE_TYPE_ZLIB);
     dhandle = deflate_decompress_new(DEFLATE_TYPE_ZLIB);
+    
+#ifdef WINDOWS_IO   
+    if(_setmode(_fileno(stdout), _O_BINARY ) == -1)
+    {
+        fprintf(stderr, "Can't set stdout to binary mode\n");
+        return 1;
+    }
+#endif
 
     do {
        ret = fread(buf, 1, sizeof(buf), fp);