Skip to content

Commit 9524b62

Browse files
committed
Also update zpipe test prog
1 parent 98881dd commit 9524b62

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

test/zpipe.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
/* zpipe.c: example of proper use of zlib's inflate() and deflate()
22
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 */
44

55
/* Version history:
66
1.0 30 Oct 2004 First version
77
1.1 8 Nov 2004 Add void casting for unused return values
88
Use switch statement for inflate() return values
99
1.2 9 Nov 2004 Add assertions to document zlib guarantees
1010
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
1113
*/
1214

1315
#include <stdio.h>
1416
#include <string.h>
1517
#include <assert.h>
1618
#include "zlib.h"
1719

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+
1828
#define CHUNK 16384
1929

2030
/* Compress from file source to file dest until EOF on source.
@@ -28,8 +38,8 @@ int def(FILE *source, FILE *dest, int level)
2838
int ret, flush;
2939
unsigned have;
3040
z_stream strm;
31-
char in[CHUNK];
32-
char out[CHUNK];
41+
unsigned char in[CHUNK];
42+
unsigned char out[CHUNK];
3343

3444
/* allocate deflate state */
3545
strm.zalloc = Z_NULL;
@@ -84,8 +94,8 @@ int inf(FILE *source, FILE *dest)
8494
int ret;
8595
unsigned have;
8696
z_stream strm;
87-
char in[CHUNK];
88-
char out[CHUNK];
97+
unsigned char in[CHUNK];
98+
unsigned char out[CHUNK];
8999

90100
/* allocate inflate state */
91101
strm.zalloc = Z_NULL;
@@ -167,6 +177,10 @@ int main(int argc, char **argv)
167177
{
168178
int ret;
169179

180+
/* avoid end-of-line conversions */
181+
SET_BINARY_MODE(stdin);
182+
SET_BINARY_MODE(stdout);
183+
170184
/* do compression if no arguments */
171185
if (argc == 1) {
172186
ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);

0 commit comments

Comments
 (0)