From 8198f694f52b6a6284069a37b44bcce5847acdf2 Mon Sep 17 00:00:00 2001 From: Ralf Corsepius Date: Fri, 18 Mar 2011 10:10:55 +0000 Subject: Import zlib-1.2.3 --- cpukit/zlib/examples/README.examples | 13 +++++++++++++ cpukit/zlib/examples/fitblk.c | 14 ++++++-------- cpukit/zlib/examples/gzjoin.c | 5 +++-- cpukit/zlib/examples/zlib_how.html | 5 +++-- cpukit/zlib/examples/zpipe.c | 2 +- 5 files changed, 26 insertions(+), 13 deletions(-) (limited to 'cpukit/zlib/examples') diff --git a/cpukit/zlib/examples/README.examples b/cpukit/zlib/examples/README.examples index 1084525204..5632d7a4cc 100644 --- a/cpukit/zlib/examples/README.examples +++ b/cpukit/zlib/examples/README.examples @@ -4,6 +4,13 @@ fitblk.c compress just enough input to nearly fill a requested output size - zlib isn't designed to do this, but fitblk does it anyway +gun.c + uncompress a gzip file + - illustrates the use of inflateBack() for high speed file-to-file + decompression using call-back functions + - is approximately twice as fast as gzip -d + - also provides Unix uncompress functionality, again twice as fast + gzappend.c append to a gzip file - illustrates the use of the Z_BLOCK flush parameter for inflate() @@ -27,3 +34,9 @@ zlib_how.html zpipe.c reads and writes zlib streams from stdin to stdout - illustrates the proper use of deflate() and inflate() + - deeply commented in zlib_how.html (see above) + +zran.c + index a zlib or gzip stream and randomly access it + - illustrates the use of Z_BLOCK, inflatePrime(), and + inflateSetDictionary() to provide random access diff --git a/cpukit/zlib/examples/fitblk.c b/cpukit/zlib/examples/fitblk.c index 5f8311489d..c61de5c996 100644 --- a/cpukit/zlib/examples/fitblk.c +++ b/cpukit/zlib/examples/fitblk.c @@ -73,7 +73,7 @@ local void quit(char *why) local int partcompress(FILE *in, z_streamp def) { int ret, flush; - char raw[RAWLEN]; + unsigned char raw[RAWLEN]; flush = Z_NO_FLUSH; do { @@ -96,7 +96,7 @@ local int partcompress(FILE *in, z_streamp def) local int recompress(z_streamp inf, z_streamp def) { int ret, flush; - char raw[RAWLEN]; + unsigned char raw[RAWLEN]; flush = Z_NO_FLUSH; do { @@ -129,8 +129,8 @@ int main(int argc, char **argv) int ret; /* return code */ unsigned size; /* requested fixed output block size */ unsigned have; /* bytes written by deflate() call */ - char *blk; /* intermediate and final stream */ - char *tmp; /* close to desired size stream */ + unsigned char *blk; /* intermediate and final stream */ + unsigned char *tmp; /* close to desired size stream */ z_stream def, inf; /* zlib deflate and inflate states */ /* get requested output size */ @@ -163,8 +163,7 @@ int main(int argc, char **argv) if (ret == Z_STREAM_END && def.avail_out >= EXCESS) { /* write block to stdout */ have = size + EXCESS - def.avail_out; - ret = fwrite(blk, 1, have, stdout); - if (ret != have || ferror(stdout)) + if (fwrite(blk, 1, have, stdout) != have || ferror(stdout)) quit("error writing output"); /* clean up and print results to stderr */ @@ -217,8 +216,7 @@ int main(int argc, char **argv) /* done -- write block to stdout */ have = size - def.avail_out; - ret = fwrite(blk, 1, have, stdout); - if (ret != have || ferror(stdout)) + if (fwrite(blk, 1, have, stdout) != have || ferror(stdout)) quit("error writing output"); /* clean up and print results to stderr */ diff --git a/cpukit/zlib/examples/gzjoin.c b/cpukit/zlib/examples/gzjoin.c index 7434c5b83f..129347ce3c 100644 --- a/cpukit/zlib/examples/gzjoin.c +++ b/cpukit/zlib/examples/gzjoin.c @@ -26,6 +26,7 @@ * Change history: * * 1.0 11 Dec 2004 - First version + * 1.1 12 Jun 2005 - Changed ssize_t to long for portability */ /* @@ -118,7 +119,7 @@ local bin *bopen(char *name) 1 indicating that end-of-file was reached */ local int bload(bin *in) { - ssize_t len; + long len; if (in == NULL) return -1; @@ -126,7 +127,7 @@ local int bload(bin *in) return 0; in->next = in->buf; do { - len = read(in->fd, in->buf + in->left, CHUNK - in->left); + len = (long)read(in->fd, in->buf + in->left, CHUNK - in->left); if (len < 0) return -1; in->left += (unsigned)len; diff --git a/cpukit/zlib/examples/zlib_how.html b/cpukit/zlib/examples/zlib_how.html index b2bda6b6d6..40998dbf08 100644 --- a/cpukit/zlib/examples/zlib_how.html +++ b/cpukit/zlib/examples/zlib_how.html @@ -420,10 +420,11 @@ The output of inflate() is handled identically to that of deflate() } The inner do-loop ends when inflate() has no more output as indicated -by not filling the output buffer, just as for deflate(). +by not filling the output buffer, just as for deflate(). In this case, we cannot +assert that strm.avail_in will be zero, since the deflate stream may end before the file +does.

         } while (strm.avail_out == 0);
-        assert(strm.avail_in == 0);     /* all input will be used */
 
The outer do-loop ends when inflate() reports that it has reached the end of the input zlib stream, has completed the decompression and integrity diff --git a/cpukit/zlib/examples/zpipe.c b/cpukit/zlib/examples/zpipe.c index a602d59f9a..26abb56a9c 100644 --- a/cpukit/zlib/examples/zpipe.c +++ b/cpukit/zlib/examples/zpipe.c @@ -7,6 +7,7 @@ 1.1 8 Nov 2004 Add void casting for unused return values 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() */ #include @@ -127,7 +128,6 @@ int inf(FILE *source, FILE *dest) return Z_ERRNO; } } while (strm.avail_out == 0); - assert(strm.avail_in == 0); /* all input will be used */ /* done when inflate() says it's done */ } while (ret != Z_STREAM_END); -- cgit v1.2.3