summaryrefslogtreecommitdiff
path: root/example.c
diff options
context:
space:
mode:
Diffstat (limited to 'example.c')
-rw-r--r--example.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/example.c b/example.c
index 622c9e6..2acc099 100644
--- a/example.c
+++ b/example.c
@@ -38,8 +38,8 @@ uLong dictId; /* Adler32 value of the dictionary */
38 38
39void test_compress OF((Byte *compr, uLong comprLen, 39void test_compress OF((Byte *compr, uLong comprLen,
40 Byte *uncompr, uLong uncomprLen)); 40 Byte *uncompr, uLong uncomprLen));
41void test_gzio OF((const char *out, const char *in, 41void test_gzio OF((const char *fname,
42 Byte *uncompr, int uncomprLen)); 42 Byte *uncompr, uLong uncomprLen));
43void test_deflate OF((Byte *compr, uLong comprLen)); 43void test_deflate OF((Byte *compr, uLong comprLen));
44void test_inflate OF((Byte *compr, uLong comprLen, 44void test_inflate OF((Byte *compr, uLong comprLen,
45 Byte *uncompr, uLong uncomprLen)); 45 Byte *uncompr, uLong uncomprLen));
@@ -63,7 +63,7 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
63 uLong comprLen, uncomprLen; 63 uLong comprLen, uncomprLen;
64{ 64{
65 int err; 65 int err;
66 uLong len = strlen(hello)+1; 66 uLong len = (uLong)strlen(hello)+1;
67 67
68 err = compress(compr, &comprLen, (const Bytef*)hello, len); 68 err = compress(compr, &comprLen, (const Bytef*)hello, len);
69 CHECK_ERR(err, "compress"); 69 CHECK_ERR(err, "compress");
@@ -84,18 +84,17 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
84/* =========================================================================== 84/* ===========================================================================
85 * Test read/write of .gz files 85 * Test read/write of .gz files
86 */ 86 */
87void test_gzio(out, in, uncompr, uncomprLen) 87void test_gzio(fname, uncompr, uncomprLen)
88 const char *out; /* compressed output file */ 88 const char *fname; /* compressed file name */
89 const char *in; /* compressed input file */
90 Byte *uncompr; 89 Byte *uncompr;
91 int uncomprLen; 90 uLong uncomprLen;
92{ 91{
93 int err; 92 int err;
94 int len = strlen(hello)+1; 93 int len = (int)strlen(hello)+1;
95 gzFile file; 94 gzFile file;
96 z_off_t pos; 95 z_off_t pos;
97 96
98 file = gzopen(out, "wb"); 97 file = gzopen(fname, "wb");
99 if (file == NULL) { 98 if (file == NULL) {
100 fprintf(stderr, "gzopen error\n"); 99 fprintf(stderr, "gzopen error\n");
101 exit(1); 100 exit(1);
@@ -112,14 +111,14 @@ void test_gzio(out, in, uncompr, uncomprLen)
112 gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ 111 gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
113 gzclose(file); 112 gzclose(file);
114 113
115 file = gzopen(in, "rb"); 114 file = gzopen(fname, "rb");
116 if (file == NULL) { 115 if (file == NULL) {
117 fprintf(stderr, "gzopen error\n"); 116 fprintf(stderr, "gzopen error\n");
117 exit(1);
118 } 118 }
119 strcpy((char*)uncompr, "garbage"); 119 strcpy((char*)uncompr, "garbage");
120 120
121 uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen); 121 if (gzread(file, uncompr, (unsigned)uncomprLen) != len) {
122 if (uncomprLen != len) {
123 fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); 122 fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
124 exit(1); 123 exit(1);
125 } 124 }
@@ -127,7 +126,7 @@ void test_gzio(out, in, uncompr, uncomprLen)
127 fprintf(stderr, "bad gzread: %s\n", (char*)uncompr); 126 fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
128 exit(1); 127 exit(1);
129 } else { 128 } else {
130 printf("gzread(): %s\n", (char *)uncompr); 129 printf("gzread(): %s\n", (char*)uncompr);
131 } 130 }
132 131
133 pos = gzseek(file, -8L, SEEK_CUR); 132 pos = gzseek(file, -8L, SEEK_CUR);
@@ -147,17 +146,16 @@ void test_gzio(out, in, uncompr, uncomprLen)
147 exit(1); 146 exit(1);
148 } 147 }
149 148
150 gzgets(file, (char*)uncompr, uncomprLen); 149 gzgets(file, (char*)uncompr, (int)uncomprLen);
151 uncomprLen = strlen((char*)uncompr); 150 if (strlen((char*)uncompr) != 7) { /* " hello!" */
152 if (uncomprLen != 7) { /* " hello!" */
153 fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err)); 151 fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
154 exit(1); 152 exit(1);
155 } 153 }
156 if (strcmp((char*)uncompr, hello+6)) { 154 if (strcmp((char*)uncompr, hello + 6)) {
157 fprintf(stderr, "bad gzgets after gzseek\n"); 155 fprintf(stderr, "bad gzgets after gzseek\n");
158 exit(1); 156 exit(1);
159 } else { 157 } else {
160 printf("gzgets() after gzseek: %s\n", (char *)uncompr); 158 printf("gzgets() after gzseek: %s\n", (char*)uncompr);
161 } 159 }
162 160
163 gzclose(file); 161 gzclose(file);
@@ -172,7 +170,7 @@ void test_deflate(compr, comprLen)
172{ 170{
173 z_stream c_stream; /* compression stream */ 171 z_stream c_stream; /* compression stream */
174 int err; 172 int err;
175 int len = strlen(hello)+1; 173 uLong len = (uLong)strlen(hello)+1;
176 174
177 c_stream.zalloc = (alloc_func)0; 175 c_stream.zalloc = (alloc_func)0;
178 c_stream.zfree = (free_func)0; 176 c_stream.zfree = (free_func)0;
@@ -184,7 +182,7 @@ void test_deflate(compr, comprLen)
184 c_stream.next_in = (Bytef*)hello; 182 c_stream.next_in = (Bytef*)hello;
185 c_stream.next_out = compr; 183 c_stream.next_out = compr;
186 184
187 while (c_stream.total_in != (uLong)len && c_stream.total_out < comprLen) { 185 while (c_stream.total_in != len && c_stream.total_out < comprLen) {
188 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */ 186 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
189 err = deflate(&c_stream, Z_NO_FLUSH); 187 err = deflate(&c_stream, Z_NO_FLUSH);
190 CHECK_ERR(err, "deflate"); 188 CHECK_ERR(err, "deflate");
@@ -347,7 +345,7 @@ void test_flush(compr, comprLen)
347{ 345{
348 z_stream c_stream; /* compression stream */ 346 z_stream c_stream; /* compression stream */
349 int err; 347 int err;
350 int len = strlen(hello)+1; 348 uInt len = (uInt)strlen(hello)+1;
351 349
352 c_stream.zalloc = (alloc_func)0; 350 c_stream.zalloc = (alloc_func)0;
353 c_stream.zfree = (free_func)0; 351 c_stream.zfree = (free_func)0;
@@ -543,8 +541,7 @@ int main(argc, argv)
543 test_compress(compr, comprLen, uncompr, uncomprLen); 541 test_compress(compr, comprLen, uncompr, uncomprLen);
544 542
545 test_gzio((argc > 1 ? argv[1] : TESTFILE), 543 test_gzio((argc > 1 ? argv[1] : TESTFILE),
546 (argc > 2 ? argv[2] : TESTFILE), 544 uncompr, uncomprLen);
547 uncompr, (int)uncomprLen);
548 545
549 test_deflate(compr, comprLen); 546 test_deflate(compr, comprLen);
550 test_inflate(compr, comprLen, uncompr, uncomprLen); 547 test_inflate(compr, comprLen, uncompr, uncomprLen);