summaryrefslogtreecommitdiff
path: root/examples/zpipe.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:25:27 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:25:27 -0700
commitb1c19ca6d82c98a8be6cd9cad7a9c5fa5e8e634e (patch)
treef0eeb8f52d07819f417411da5104c9d743dd46de /examples/zpipe.c
parentabf180a067223611620dd97dd5681df7c7fa7c9b (diff)
downloadzlib-1.2.3.1.tar.gz
zlib-1.2.3.1.tar.bz2
zlib-1.2.3.1.zip
zlib 1.2.3.1v1.2.3.1
Diffstat (limited to 'examples/zpipe.c')
-rw-r--r--examples/zpipe.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/examples/zpipe.c b/examples/zpipe.c
index 26abb56..83535d1 100644
--- a/examples/zpipe.c
+++ b/examples/zpipe.c
@@ -1,6 +1,6 @@
1/* zpipe.c: example of proper use of zlib's inflate() and deflate() 1/* zpipe.c: example of proper use of zlib's inflate() and deflate()
2 Not copyrighted -- provided to the public domain 2 Not copyrighted -- provided to the public domain
3 Version 1.2 9 November 2004 Mark Adler */ 3 Version 1.4 11 December 2005 Mark Adler */
4 4
5/* Version history: 5/* Version history:
6 1.0 30 Oct 2004 First version 6 1.0 30 Oct 2004 First version
@@ -8,6 +8,8 @@
8 Use switch statement for inflate() return values 8 Use switch statement for inflate() return values
9 1.2 9 Nov 2004 Add assertions to document zlib guarantees 9 1.2 9 Nov 2004 Add assertions to document zlib guarantees
10 1.3 6 Apr 2005 Remove incorrect assertion in inf() 10 1.3 6 Apr 2005 Remove incorrect assertion in inf()
11 1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions
12 Avoid some compiler warnings for input and output buffers
11 */ 13 */
12 14
13#include <stdio.h> 15#include <stdio.h>
@@ -15,6 +17,14 @@
15#include <assert.h> 17#include <assert.h>
16#include "zlib.h" 18#include "zlib.h"
17 19
20#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
21# include <fcntl.h>
22# include <io.h>
23# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
24#else
25# define SET_BINARY_MODE(file)
26#endif
27
18#define CHUNK 16384 28#define CHUNK 16384
19 29
20/* Compress from file source to file dest until EOF on source. 30/* Compress from file source to file dest until EOF on source.
@@ -28,8 +38,8 @@ int def(FILE *source, FILE *dest, int level)
28 int ret, flush; 38 int ret, flush;
29 unsigned have; 39 unsigned have;
30 z_stream strm; 40 z_stream strm;
31 char in[CHUNK]; 41 unsigned char in[CHUNK];
32 char out[CHUNK]; 42 unsigned char out[CHUNK];
33 43
34 /* allocate deflate state */ 44 /* allocate deflate state */
35 strm.zalloc = Z_NULL; 45 strm.zalloc = Z_NULL;
@@ -84,8 +94,8 @@ int inf(FILE *source, FILE *dest)
84 int ret; 94 int ret;
85 unsigned have; 95 unsigned have;
86 z_stream strm; 96 z_stream strm;
87 char in[CHUNK]; 97 unsigned char in[CHUNK];
88 char out[CHUNK]; 98 unsigned char out[CHUNK];
89 99
90 /* allocate inflate state */ 100 /* allocate inflate state */
91 strm.zalloc = Z_NULL; 101 strm.zalloc = Z_NULL;
@@ -167,6 +177,10 @@ int main(int argc, char **argv)
167{ 177{
168 int ret; 178 int ret;
169 179
180 /* avoid end-of-line conversions */
181 SET_BINARY_MODE(stdin);
182 SET_BINARY_MODE(stdout);
183
170 /* do compression if no arguments */ 184 /* do compression if no arguments */
171 if (argc == 1) { 185 if (argc == 1) {
172 ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION); 186 ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);