aboutsummaryrefslogtreecommitdiff
path: root/zlib/examples/zpipe.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-06-22 15:56:58 +0200
committermarha <marha@users.sourceforge.net>2012-06-22 15:56:58 +0200
commit66841fa144ddd72df67ab1ddf880ca508d4bc9e3 (patch)
tree7cf0afebcfa94bcc8b2046c85532efcf6b0f91d0 /zlib/examples/zpipe.c
parent1a68b7aceea62a76127f0fa13b3f127e37b2ec76 (diff)
parent7baa3d795c87c11550f1686488c968320428cbf9 (diff)
downloadvcxsrv-66841fa144ddd72df67ab1ddf880ca508d4bc9e3.tar.gz
vcxsrv-66841fa144ddd72df67ab1ddf880ca508d4bc9e3.tar.bz2
vcxsrv-66841fa144ddd72df67ab1ddf880ca508d4bc9e3.zip
Merge remote-tracking branch 'origin/released'
Conflicts: zlib/Makefile
Diffstat (limited to 'zlib/examples/zpipe.c')
-rw-r--r--zlib/examples/zpipe.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/zlib/examples/zpipe.c b/zlib/examples/zpipe.c
index 26abb56a9..83535d169 100644
--- a/zlib/examples/zpipe.c
+++ b/zlib/examples/zpipe.c
@@ -1,6 +1,6 @@
/* zpipe.c: example of proper use of zlib's inflate() and deflate()
Not copyrighted -- provided to the public domain
- Version 1.2 9 November 2004 Mark Adler */
+ Version 1.4 11 December 2005 Mark Adler */
/* Version history:
1.0 30 Oct 2004 First version
@@ -8,6 +8,8 @@
Use switch statement for inflate() return values
1.2 9 Nov 2004 Add assertions to document zlib guarantees
1.3 6 Apr 2005 Remove incorrect assertion in inf()
+ 1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions
+ Avoid some compiler warnings for input and output buffers
*/
#include <stdio.h>
@@ -15,6 +17,14 @@
#include <assert.h>
#include "zlib.h"
+#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
+# include <fcntl.h>
+# include <io.h>
+# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
+#else
+# define SET_BINARY_MODE(file)
+#endif
+
#define CHUNK 16384
/* Compress from file source to file dest until EOF on source.
@@ -28,8 +38,8 @@ int def(FILE *source, FILE *dest, int level)
int ret, flush;
unsigned have;
z_stream strm;
- char in[CHUNK];
- char out[CHUNK];
+ unsigned char in[CHUNK];
+ unsigned char out[CHUNK];
/* allocate deflate state */
strm.zalloc = Z_NULL;
@@ -84,8 +94,8 @@ int inf(FILE *source, FILE *dest)
int ret;
unsigned have;
z_stream strm;
- char in[CHUNK];
- char out[CHUNK];
+ unsigned char in[CHUNK];
+ unsigned char out[CHUNK];
/* allocate inflate state */
strm.zalloc = Z_NULL;
@@ -167,6 +177,10 @@ int main(int argc, char **argv)
{
int ret;
+ /* avoid end-of-line conversions */
+ SET_BINARY_MODE(stdin);
+ SET_BINARY_MODE(stdout);
+
/* do compression if no arguments */
if (argc == 1) {
ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);