From: millert Date: Sun, 19 Jan 1997 17:11:21 +0000 (+0000) Subject: zlib 1.0.4 X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f503157c392d5d00f16437335fafd5e9c511cabc;p=openbsd zlib 1.0.4 --- diff --git a/lib/libz/README b/lib/libz/README index 1a3c8bf1b46..28adc90b218 100644 --- a/lib/libz/README +++ b/lib/libz/README @@ -1,4 +1,4 @@ -zlib 1.0.3 is a general purpose data compression library. All the code +zlib 1.0.4 is a general purpose data compression library. All the code is reentrant (thread safe). The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate @@ -20,16 +20,14 @@ Questions about zlib should be sent to or, if this fails, to the addresses given below in the Copyright section. The zlib home page is http://quest.jpl.nasa.gov/zlib/ -The changes made in version 1.0.3 are documented in the file ChangeLog. -The main changes since 1.0.2 are: +The changes made in version 1.0.4 are documented in the file ChangeLog. +The main changes since 1.0.3 are: -- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS - small and medium models; this makes the library incompatible with previous - versions for these models. (No effect in large model or on other systems.) -- return OK instead of BUF_ERROR if previous deflate call returned with - avail_out as zero but there is nothing to do -- as usual, a few more changes to deal with peculiarities of Mac and MSDOS - compilers +- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF + bit, so the decompressor could decompress all the correct data but went + on to attempt decompressing extra garbage data. This affected minigzip too. +- zlibVersion and gzerror return const char* (needed for DLL) +- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno) A Perl interface to zlib written by Paul Marquess @@ -55,7 +53,10 @@ Notes for some targets: - To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL For help on building a zlib DLL, contact Alessandro Iacopetti - + http://lisa.unial.it/iaco , + or contact Brad Clarke . + +- gzdopen is not supported on RISCOS Acknowledgments: diff --git a/lib/libz/deflate.c b/lib/libz/deflate.c index c5856fdc87f..24e44c86fa9 100644 --- a/lib/libz/deflate.c +++ b/lib/libz/deflate.c @@ -47,11 +47,11 @@ * */ -/* $Id: deflate.c,v 1.1 1996/07/27 02:39:43 tholo Exp $ */ +/* $Id: deflate.c,v 1.2 1997/01/19 17:11:22 millert Exp $ */ #include "deflate.h" -char deflate_copyright[] = " deflate 1.0.3 Copyright 1995-1996 Jean-loup Gailly "; +char deflate_copyright[] = " deflate 1.0.4 Copyright 1995-1996 Jean-loup Gailly "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -62,10 +62,20 @@ char deflate_copyright[] = " deflate 1.0.3 Copyright 1995-1996 Jean-loup Gailly /* =========================================================================== * Function prototypes. */ +typedef enum { + need_more, /* block not completed, need more input or more output */ + block_done, /* block flush performed */ + finish_started, /* finish started, need only more output at next deflate */ + finish_done /* finish done, accept no more input or output */ +} block_state; + +typedef block_state (*compress_func) OF((deflate_state *s, int flush)); +/* Compression function. Returns the block state after the call. */ + local void fill_window OF((deflate_state *s)); -local int deflate_stored OF((deflate_state *s, int flush)); -local int deflate_fast OF((deflate_state *s, int flush)); -local int deflate_slow OF((deflate_state *s, int flush)); +local block_state deflate_stored OF((deflate_state *s, int flush)); +local block_state deflate_fast OF((deflate_state *s, int flush)); +local block_state deflate_slow OF((deflate_state *s, int flush)); local void lm_init OF((deflate_state *s)); local uInt longest_match OF((deflate_state *s, IPos cur_match)); local void putShortMSB OF((deflate_state *s, uInt b)); @@ -97,9 +107,6 @@ local void check_match OF((deflate_state *s, IPos start, IPos match, * See deflate.c for comments about the MIN_MATCH+1. */ -typedef int (*compress_func) OF((deflate_state *s, int flush)); -/* Compressing function */ - /* Values for max_lazy_match, good_match and max_chain_length, depending on * the desired pack level (0..9). The values given below have been tuned to * exclude worst case performance for pathological files. Better values may be @@ -249,7 +256,7 @@ int deflateInit2_(strm, level, method, windowBits, memLevel, strategy, if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || s->pending_buf == Z_NULL) { - strm->msg = ERR_MSG(Z_MEM_ERROR); + strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); deflateEnd (strm); return Z_MEM_ERROR; } @@ -485,25 +492,27 @@ int deflate (strm, flush) */ if (strm->avail_in != 0 || s->lookahead != 0 || (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { - int quit; + block_state bstate; + + bstate = (*(configuration_table[s->level].func))(s, flush); - if (flush == Z_FINISH) { + if (bstate == finish_started || bstate == finish_done) { s->status = FINISH_STATE; } - quit = (*(configuration_table[s->level].func))(s, flush); - - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ + if (bstate == need_more || bstate == finish_started) { + if (strm->avail_out == 0) { + s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ + } + return Z_OK; + /* If flush != Z_NO_FLUSH && avail_out == 0, the next call + * of deflate should use the same flush parameter to make sure + * that the flush is complete. So we don't have to output an + * empty block here, this will be done at next call. This also + * ensures that for a very small output buffer, we emit at most + * one empty block. + */ } - if (quit || strm->avail_out == 0) return Z_OK; - /* If flush != Z_NO_FLUSH && avail_out == 0, the next call - * of deflate should use the same flush parameter to make sure - * that the flush is complete. So we don't have to output an - * empty block here, this will be done at next call. This also - * ensures that for a very small output buffer, we emit at most - * one empty block. - */ - if (flush != Z_NO_FLUSH && flush != Z_FINISH) { + if (bstate == block_done) { if (flush == Z_PARTIAL_FLUSH) { _tr_align(s); } else { /* FULL_FLUSH or SYNC_FLUSH */ @@ -933,18 +942,18 @@ local void fill_window(s) /* Same but force premature exit if necessary. */ #define FLUSH_BLOCK(s, eof) { \ FLUSH_BLOCK_ONLY(s, eof); \ - if (s->strm->avail_out == 0) return 1; \ + if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \ } /* =========================================================================== * Copy without compression as much as possible from the input stream, return - * true if processing was terminated prematurely (no more input or output - * space). This function does not insert new strings in the dictionary - * since uncompressible data is probably not useful. This function is used + * the current block state. + * This function does not insert new strings in the dictionary since + * uncompressible data is probably not useful. This function is used * only for the level=0 compression option. * NOTE: this function should be optimized to avoid extra copying. */ -local int deflate_stored(s, flush) +local block_state deflate_stored(s, flush) deflate_state *s; int flush; { @@ -956,7 +965,7 @@ local int deflate_stored(s, flush) s->block_start >= (long)s->w_size, "slide too late"); fill_window(s); - if (s->lookahead == 0 && flush == Z_NO_FLUSH) return 1; + if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; if (s->lookahead == 0) break; /* flush the current block */ } @@ -978,17 +987,17 @@ local int deflate_stored(s, flush) } } FLUSH_BLOCK(s, flush == Z_FINISH); - return 0; /* normal exit */ + return flush == Z_FINISH ? finish_done : block_done; } /* =========================================================================== - * Compress as much as possible from the input stream, return true if - * processing was terminated prematurely (no more input or output space). + * Compress as much as possible from the input stream, return the current + * block state. * This function does not perform lazy evaluation of matches and inserts * new strings in the dictionary only for unmatched strings or for short * matches. It is used only for the fast compression options. */ -local int deflate_fast(s, flush) +local block_state deflate_fast(s, flush) deflate_state *s; int flush; { @@ -1003,8 +1012,9 @@ local int deflate_fast(s, flush) */ if (s->lookahead < MIN_LOOKAHEAD) { fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) return 1; - + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { + return need_more; + } if (s->lookahead == 0) break; /* flush the current block */ } @@ -1072,7 +1082,7 @@ local int deflate_fast(s, flush) if (bflush) FLUSH_BLOCK(s, 0); } FLUSH_BLOCK(s, flush == Z_FINISH); - return 0; /* normal exit */ + return flush == Z_FINISH ? finish_done : block_done; } /* =========================================================================== @@ -1080,7 +1090,7 @@ local int deflate_fast(s, flush) * evaluation for matches: a match is finally adopted only if there is * no better match at the next window position. */ -local int deflate_slow(s, flush) +local block_state deflate_slow(s, flush) deflate_state *s; int flush; { @@ -1096,8 +1106,9 @@ local int deflate_slow(s, flush) */ if (s->lookahead < MIN_LOOKAHEAD) { fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) return 1; - + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { + return need_more; + } if (s->lookahead == 0) break; /* flush the current block */ } @@ -1175,7 +1186,7 @@ local int deflate_slow(s, flush) } s->strstart++; s->lookahead--; - if (s->strm->avail_out == 0) return 1; + if (s->strm->avail_out == 0) return need_more; } else { /* There is no previous match to compare with, wait for * the next step to decide. @@ -1192,6 +1203,5 @@ local int deflate_slow(s, flush) s->match_available = 0; } FLUSH_BLOCK(s, flush == Z_FINISH); - return 0; + return flush == Z_FINISH ? finish_done : block_done; } - diff --git a/lib/libz/gzio.c b/lib/libz/gzio.c index 8a2b770252d..d09310eed2a 100644 --- a/lib/libz/gzio.c +++ b/lib/libz/gzio.c @@ -3,7 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -/* $Id: gzio.c,v 1.2 1996/10/27 00:29:33 millert Exp $ */ +/* $Id: gzio.c,v 1.3 1997/01/19 17:11:23 millert Exp $ */ #include @@ -496,7 +496,7 @@ int gzclose (file) errnum is set to Z_ERRNO and the application may consult errno to get the exact error code. */ -char* gzerror (file, errnum) +const char* gzerror (file, errnum) gzFile file; int *errnum; { @@ -505,30 +505,19 @@ char* gzerror (file, errnum) if (s == NULL) { *errnum = Z_STREAM_ERROR; - return ERR_MSG(Z_STREAM_ERROR); + return (const char*)ERR_MSG(Z_STREAM_ERROR); } *errnum = s->z_err; - if (*errnum == Z_OK) return (char*)""; + if (*errnum == Z_OK) return (const char*)""; m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg); - if (m == NULL || *m == '\0') m = ERR_MSG(s->z_err); + if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err); TRYFREE(s->msg); s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3); strcpy(s->msg, s->path); strcat(s->msg, ": "); strcat(s->msg, m); - return s->msg; -} - -/* =========================================================================== - Returns true (1) if file is zipped, else returns false (0). -*/ -int gz_iszipped (file) - gzFile file; -{ - gz_stream *s = (gz_stream*)file; - - return(!(s->transparent)); + return (const char*)s->msg; } diff --git a/lib/libz/inftrees.c b/lib/libz/inftrees.c index 48c0ac5ea27..90205bd1e57 100644 --- a/lib/libz/inftrees.c +++ b/lib/libz/inftrees.c @@ -6,7 +6,7 @@ #include "zutil.h" #include "inftrees.h" -char inflate_copyright[] = " inflate 1.0.3 Copyright 1995-1996 Mark Adler "; +char inflate_copyright[] = " inflate 1.0.4 Copyright 1995-1996 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot diff --git a/lib/libz/shlib_version b/lib/libz/shlib_version index 893819d18ff..c8860078e50 100644 --- a/lib/libz/shlib_version +++ b/lib/libz/shlib_version @@ -1,2 +1,2 @@ major=1 -minor=1 +minor=2 diff --git a/lib/libz/trees.c b/lib/libz/trees.c index 2a35b5398b5..8bd6d690298 100644 --- a/lib/libz/trees.c +++ b/lib/libz/trees.c @@ -29,7 +29,7 @@ * Addison-Wesley, 1983. ISBN 0-201-06672-6. */ -/* $Id: trees.c,v 1.1 1996/07/27 02:39:49 tholo Exp $ */ +/* $Id: trees.c,v 1.2 1997/01/19 17:11:24 millert Exp $ */ #include "deflate.h" @@ -154,7 +154,7 @@ local void copy_block OF((deflate_state *s, charf *buf, unsigned len, #else /* DEBUG */ # define send_code(s, c, tree) \ - { if (verbose>1) fprintf(stderr,"\ncd %3d ",(c)); \ + { if (verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ send_bits(s, tree[c].Code, tree[c].Len); } #endif diff --git a/lib/libz/zlib.h b/lib/libz/zlib.h index 32109747f82..337fe9fe8a3 100644 --- a/lib/libz/zlib.h +++ b/lib/libz/zlib.h @@ -1,5 +1,5 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.0.3, Jul 2nd, 1996. + version 1.0.4, Jul 24th, 1996. Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler @@ -37,7 +37,7 @@ extern "C" { #include "zconf.h" -#define ZLIB_VERSION "1.0.3" +#define ZLIB_VERSION "1.0.4" /* The 'zlib' compression library provides in-memory compression and @@ -168,7 +168,7 @@ typedef z_stream FAR *z_streamp; /* basic functions */ -extern char EXPORT *zlibVersion OF((void)); +extern const char * EXPORT zlibVersion OF((void)); /* The application can compare zlibVersion and ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. @@ -241,8 +241,8 @@ extern int EXPORT deflate OF((z_streamp strm, int flush)); parameter and more output space (updated avail_out), until the flush is complete (deflate returns with non-zero avail_out). - If the parameter flush is set to Z_FINISH, all pending input is processed, - all pending output is flushed and deflate returns with Z_STREAM_END if there + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there was enough output space; if deflate returns with Z_OK, this function must be called again with Z_FINISH and more output space (updated avail_out) but no more input data, until it returns with Z_STREAM_END or an error. After @@ -692,7 +692,7 @@ extern int EXPORT gzclose OF((gzFile file)); error number (see function gzerror below). */ -extern char EXPORT *gzerror OF((gzFile file, int *errnum)); +extern const char * EXPORT gzerror OF((gzFile file, int *errnum)); /* Returns the error message for the last error which occurred on the given compressed file. errnum is set to zlib error number. If an @@ -701,11 +701,6 @@ extern char EXPORT *gzerror OF((gzFile file, int *errnum)); to get the exact error code. */ -/* =========================================================================== - Returns true (1) if file is zipped, else returns false (0). -*/ -extern int gz_iszipped OF((gzFile file)); - /* checksum functions */ /* diff --git a/lib/libz/zutil.c b/lib/libz/zutil.c index 6b6f5f71548..07ca95da019 100644 --- a/lib/libz/zutil.c +++ b/lib/libz/zutil.c @@ -3,7 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -/* $Id: zutil.c,v 1.1 1996/07/27 02:39:51 tholo Exp $ */ +/* $Id: zutil.c,v 1.2 1997/01/19 17:11:26 millert Exp $ */ #include @@ -28,17 +28,19 @@ const char *z_errmsg[10] = { ""}; -char *zlibVersion() +const char *zlibVersion() { return ZLIB_VERSION; } +#ifdef DEBUG void z_error (m) char *m; { fprintf(stderr, "%s\n", m); exit(1); } +#endif #ifndef HAVE_MEMCPY @@ -151,7 +153,7 @@ void zcfree (voidpf opaque, voidpf ptr) return; } ptr = opaque; /* just to make some compilers happy */ - z_error("zcfree: ptr not found"); + Assert(0, "zcfree: ptr not found"); } #endif #endif /* __TURBOC__ */ diff --git a/lib/libz/zutil.h b/lib/libz/zutil.h index cd1e5fd9dc4..af6dee0a9af 100644 --- a/lib/libz/zutil.h +++ b/lib/libz/zutil.h @@ -8,14 +8,14 @@ subject to change. Applications should only use zlib.h. */ -/* $Id: zutil.h,v 1.1 1996/07/27 02:39:51 tholo Exp $ */ +/* $Id: zutil.h,v 1.2 1997/01/19 17:11:26 millert Exp $ */ #ifndef _Z_UTIL_H #define _Z_UTIL_H #include "zlib.h" -#if defined(MSDOS) || defined(VMS) || defined(CRAY) || defined(WIN32) +#if defined(MSDOS)||defined(VMS)||defined(CRAY)||defined(WIN32)||defined(RISCOS) # include # include #else @@ -40,10 +40,10 @@ typedef unsigned long ulg; extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ /* (size given to avoid silly warnings with Visual C++) */ -#define ERR_MSG(err) (char*)z_errmsg[Z_NEED_DICT-(err)] +#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] #define ERR_RETURN(strm,err) \ - return (strm->msg = ERR_MSG(err), (err)) + return (strm->msg = (char*)ERR_MSG(err), (err)) /* To be used only when the state is known to be valid */ /* common constants */ @@ -116,7 +116,7 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ # define OS_CODE 0x0a #endif -#ifdef _BEOS_ +#if defined(_BEOS_) || defined(RISCOS) # define fdopen(fd,mode) NULL /* No fdopen() */ #endif @@ -173,6 +173,7 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ # ifndef verbose # define verbose 0 # endif + extern void z_error OF((char *m)); # define Assert(cond,msg) {if(!(cond)) z_error(msg);} # define Trace(x) fprintf x # define Tracev(x) {if (verbose) fprintf x ;} @@ -191,8 +192,6 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ typedef uLong (*check_func) OF((uLong check, const Bytef *buf, uInt len)); -extern void z_error OF((char *m)); - voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); void zcfree OF((voidpf opaque, voidpf ptr));