From 411fc07589eb4812390481eb12b2ef5eb8891998 Mon Sep 17 00:00:00 2001 From: Nathan Moinvaziri Date: Fri, 15 May 2020 13:22:49 -0400 Subject: Set binary mode for stdin and stdout in switchlevels. --- test/switchlevels.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/switchlevels.c b/test/switchlevels.c index 5c4770f8cd..f991a838cb 100644 --- a/test/switchlevels.c +++ b/test/switchlevels.c @@ -13,6 +13,14 @@ #include #include +#if defined(WIN32) || defined(__CYGWIN__) +# include +# include +# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) +#else +# define SET_BINARY_MODE(file) +#endif + static int read_all(unsigned char *buf, size_t size) { for (size_t total_read = 0; total_read < size;) { size_t n_read = fread(buf + total_read, 1, size - total_read, stdin); @@ -87,6 +95,8 @@ done: int main(int argc, char **argv) { int ret = EXIT_FAILURE; PREFIX3(stream) strm; + SET_BINARY_MODE(stdin); + SET_BINARY_MODE(stdout); memset(&strm, 0, sizeof(strm)); int err = PREFIX(deflateInit2)(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16, 8, Z_DEFAULT_STRATEGY); if (err != Z_OK) { -- cgit 0.0.5-2-1-g0f52