From: Nathan Moinvaziri Date: Fri, 15 May 2020 17:22:49 +0000 (-0400) Subject: Set binary mode for stdin and stdout in switchlevels. X-Git-Tag: 1.9.9-b1~285 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=411fc07589eb4812390481eb12b2ef5eb8891998;p=thirdparty%2Fzlib-ng.git Set binary mode for stdin and stdout in switchlevels. --- diff --git a/test/switchlevels.c b/test/switchlevels.c index 5c4770f8c..f991a838c 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) {