Changeset: 594adda990f4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=594adda990f4
Modified Files:
        clients/examples/C/streamcat.c
Branch: makelibstreamgreatagain
Log Message:

Open stdout in binary mode the right way


diffs (48 lines):

diff --git a/clients/examples/C/streamcat.c b/clients/examples/C/streamcat.c
--- a/clients/examples/C/streamcat.c
+++ b/clients/examples/C/streamcat.c
@@ -2,11 +2,16 @@
 #include "stream.h"
 
 #include <errno.h>
+#include <fcntl.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+#define fdopen _fdopen
+#endif
+
 
 const char *USAGE =
        "Usage:\n"
@@ -168,9 +173,11 @@ int cmd_read(char *argv[])
        }
 
        if (out == NULL) {
-               // Try to get binary stdout on Windows
                fflush(stdout);
-               out = fdopen(fileno(stdout), "wb");
+               out = stdout;
+#ifdef _MSC_VER
+               _setmode(_fileno(out), O_BINARY);
+#endif
        }
 
        copy_stream_to_file(s, out, bufsize);
@@ -261,9 +268,10 @@ int cmd_write(char *argv[])
        }
 
        if (in == NULL) {
-               // We can't flush stdin but it hasn't been used yet so with any
-               // luck, no input has been buffered yet
-               in = fdopen(fileno(stdin), "rb");
+               in = stdin;
+#ifdef _MSC_VER
+               _setmode(_fileno(in), O_BINARY);
+#endif
        }
 
        copy_file_to_stream(in, s, bufsize);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to