diff options
| author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:08:07 -0700 |
|---|---|---|
| committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:08:07 -0700 |
| commit | bdde4e09d21edff02ea5093b7f6eccbf166b272f (patch) | |
| tree | a64632a98a6bea6e5df864d6e5b6f2e51ea69c1c /example.c | |
| parent | 1c71d8b13b54f91ddec361d3053ecce26e6ff761 (diff) | |
| download | zlib-bdde4e09d21edff02ea5093b7f6eccbf166b272f.tar.gz zlib-bdde4e09d21edff02ea5093b7f6eccbf166b272f.tar.bz2 zlib-bdde4e09d21edff02ea5093b7f6eccbf166b272f.zip | |
zlib 0.92v0.92
Diffstat (limited to '')
| -rw-r--r-- | example.c | 60 |
1 files changed, 30 insertions, 30 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | /* $Id: example.c,v 1.8 1995/05/02 15:52:32 jloup Exp $ */ | 6 | /* $Id: example.c,v 1.9 1995/05/03 17:27:09 jloup Exp $ */ |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include "zlib.h" | 9 | #include "zlib.h" |
| @@ -27,7 +27,7 @@ extern void exit __P((int)); | |||
| 27 | #define CHECK_ERR(err, msg) { \ | 27 | #define CHECK_ERR(err, msg) { \ |
| 28 | if (err != Z_OK) { \ | 28 | if (err != Z_OK) { \ |
| 29 | fprintf(stderr, "%s error: %d\n", msg, err); \ | 29 | fprintf(stderr, "%s error: %d\n", msg, err); \ |
| 30 | exit(1); \ | 30 | exit(1); \ |
| 31 | } \ | 31 | } \ |
| 32 | } | 32 | } |
| 33 | 33 | ||
| @@ -60,9 +60,9 @@ void test_compress() | |||
| 60 | CHECK_ERR(err, "uncompress"); | 60 | CHECK_ERR(err, "uncompress"); |
| 61 | 61 | ||
| 62 | if (strcmp((char*)uncompr, hello)) { | 62 | if (strcmp((char*)uncompr, hello)) { |
| 63 | fprintf(stderr, "bad uncompress\n"); | 63 | fprintf(stderr, "bad uncompress\n"); |
| 64 | } else { | 64 | } else { |
| 65 | printf("uncompress(): %s\n", uncompr); | 65 | printf("uncompress(): %s\n", uncompr); |
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | 68 | ||
| @@ -81,31 +81,31 @@ void test_gzio(out, in) | |||
| 81 | 81 | ||
| 82 | file = gzopen(out, "wb"); | 82 | file = gzopen(out, "wb"); |
| 83 | if (file == NULL) { | 83 | if (file == NULL) { |
| 84 | fprintf(stderr, "gzopen error\n"); | 84 | fprintf(stderr, "gzopen error\n"); |
| 85 | exit(1); | 85 | exit(1); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | if (gzwrite(file, hello, len) != len) { | 88 | if (gzwrite(file, hello, len) != len) { |
| 89 | fprintf(stderr, "gzwrite err: %s\n", gzerror(file, &err)); | 89 | fprintf(stderr, "gzwrite err: %s\n", gzerror(file, &err)); |
| 90 | } | 90 | } |
| 91 | gzclose(file); | 91 | gzclose(file); |
| 92 | 92 | ||
| 93 | file = gzopen(in, "rb"); | 93 | file = gzopen(in, "rb"); |
| 94 | if (file == NULL) { | 94 | if (file == NULL) { |
| 95 | fprintf(stderr, "gzopen error\n"); | 95 | fprintf(stderr, "gzopen error\n"); |
| 96 | } | 96 | } |
| 97 | strcpy((char*)uncompr, "garbage"); | 97 | strcpy((char*)uncompr, "garbage"); |
| 98 | 98 | ||
| 99 | uncomprLen = gzread(file, uncompr, uncomprLen); | 99 | uncomprLen = gzread(file, uncompr, uncomprLen); |
| 100 | if (uncomprLen != len) { | 100 | if (uncomprLen != len) { |
| 101 | fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); | 101 | fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); |
| 102 | } | 102 | } |
| 103 | gzclose(file); | 103 | gzclose(file); |
| 104 | 104 | ||
| 105 | if (strcmp((char*)uncompr, hello)) { | 105 | if (strcmp((char*)uncompr, hello)) { |
| 106 | fprintf(stderr, "bad gzread\n"); | 106 | fprintf(stderr, "bad gzread\n"); |
| 107 | } else { | 107 | } else { |
| 108 | printf("gzread(): %s\n", uncompr); | 108 | printf("gzread(): %s\n", uncompr); |
| 109 | } | 109 | } |
| 110 | } | 110 | } |
| 111 | 111 | ||
| @@ -129,16 +129,16 @@ void test_deflate(compr) | |||
| 129 | c_stream.next_out = compr; | 129 | c_stream.next_out = compr; |
| 130 | 130 | ||
| 131 | while (c_stream.total_in != (uLong)len) { | 131 | while (c_stream.total_in != (uLong)len) { |
| 132 | c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */ | 132 | c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */ |
| 133 | err = deflate(&c_stream, Z_NO_FLUSH); | 133 | err = deflate(&c_stream, Z_NO_FLUSH); |
| 134 | CHECK_ERR(err, "deflate"); | 134 | CHECK_ERR(err, "deflate"); |
| 135 | } | 135 | } |
| 136 | /* Finish the stream, still forcing small buffers: */ | 136 | /* Finish the stream, still forcing small buffers: */ |
| 137 | for (;;) { | 137 | for (;;) { |
| 138 | c_stream.avail_out = 1; | 138 | c_stream.avail_out = 1; |
| 139 | err = deflate(&c_stream, Z_FINISH); | 139 | err = deflate(&c_stream, Z_FINISH); |
| 140 | if (err == Z_STREAM_END) break; | 140 | if (err == Z_STREAM_END) break; |
| 141 | CHECK_ERR(err, "deflate"); | 141 | CHECK_ERR(err, "deflate"); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | err = deflateEnd(&c_stream); | 144 | err = deflateEnd(&c_stream); |
| @@ -167,19 +167,19 @@ void test_inflate(compr) | |||
| 167 | d_stream.next_out = uncompr; | 167 | d_stream.next_out = uncompr; |
| 168 | 168 | ||
| 169 | for (;;) { | 169 | for (;;) { |
| 170 | d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ | 170 | d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ |
| 171 | err = inflate(&d_stream, Z_NO_FLUSH); | 171 | err = inflate(&d_stream, Z_NO_FLUSH); |
| 172 | if (err == Z_STREAM_END) break; | 172 | if (err == Z_STREAM_END) break; |
| 173 | CHECK_ERR(err, "inflate"); | 173 | CHECK_ERR(err, "inflate"); |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | err = inflateEnd(&d_stream); | 176 | err = inflateEnd(&d_stream); |
| 177 | CHECK_ERR(err, "inflateEnd"); | 177 | CHECK_ERR(err, "inflateEnd"); |
| 178 | 178 | ||
| 179 | if (strcmp((char*)uncompr, hello)) { | 179 | if (strcmp((char*)uncompr, hello)) { |
| 180 | fprintf(stderr, "bad inflate\n"); | 180 | fprintf(stderr, "bad inflate\n"); |
| 181 | } else { | 181 | } else { |
| 182 | printf("inflate(): %s\n", uncompr); | 182 | printf("inflate(): %s\n", uncompr); |
| 183 | } | 183 | } |
| 184 | } | 184 | } |
| 185 | 185 | ||
| @@ -211,7 +211,7 @@ void test_flush(compr) | |||
| 211 | 211 | ||
| 212 | err = deflate(&c_stream, Z_FINISH); | 212 | err = deflate(&c_stream, Z_FINISH); |
| 213 | if (err != Z_STREAM_END) { | 213 | if (err != Z_STREAM_END) { |
| 214 | CHECK_ERR(err, "deflate"); | 214 | CHECK_ERR(err, "deflate"); |
| 215 | } | 215 | } |
| 216 | err = deflateEnd(&c_stream); | 216 | err = deflateEnd(&c_stream); |
| 217 | CHECK_ERR(err, "deflateEnd"); | 217 | CHECK_ERR(err, "deflateEnd"); |
| @@ -250,7 +250,7 @@ void test_sync(compr) | |||
| 250 | err = inflate(&d_stream, Z_FINISH); | 250 | err = inflate(&d_stream, Z_FINISH); |
| 251 | if (err != Z_DATA_ERROR) { | 251 | if (err != Z_DATA_ERROR) { |
| 252 | fprintf(stderr, "inflate should report DATA_ERROR\n"); | 252 | fprintf(stderr, "inflate should report DATA_ERROR\n"); |
| 253 | /* Because of incorrect adler32 */ | 253 | /* Because of incorrect adler32 */ |
| 254 | } | 254 | } |
| 255 | err = inflateEnd(&d_stream); | 255 | err = inflateEnd(&d_stream); |
| 256 | CHECK_ERR(err, "inflateEnd"); | 256 | CHECK_ERR(err, "inflateEnd"); |
| @@ -269,16 +269,16 @@ void main(argc, argv) | |||
| 269 | local Byte compr[BUFLEN]; | 269 | local Byte compr[BUFLEN]; |
| 270 | 270 | ||
| 271 | if (zlib_version[0] != ZLIB_VERSION[0]) { | 271 | if (zlib_version[0] != ZLIB_VERSION[0]) { |
| 272 | fprintf(stderr, "incompatible zlib version\n"); | 272 | fprintf(stderr, "incompatible zlib version\n"); |
| 273 | exit(1); | 273 | exit(1); |
| 274 | 274 | ||
| 275 | } else if (strcmp(zlib_version, ZLIB_VERSION) != 0) { | 275 | } else if (strcmp(zlib_version, ZLIB_VERSION) != 0) { |
| 276 | fprintf(stderr, "warning: different zlib version\n"); | 276 | fprintf(stderr, "warning: different zlib version\n"); |
| 277 | } | 277 | } |
| 278 | test_compress(); | 278 | test_compress(); |
| 279 | 279 | ||
| 280 | test_gzio((argc > 1 ? argv[1] : "foo.gz"), | 280 | test_gzio((argc > 1 ? argv[1] : "foo.gz"), |
| 281 | (argc > 2 ? argv[2] : "foo.gz")); | 281 | (argc > 2 ? argv[2] : "foo.gz")); |
| 282 | 282 | ||
| 283 | test_deflate(compr); | 283 | test_deflate(compr); |
| 284 | test_inflate(compr); | 284 | test_inflate(compr); |
