This patch allows zlib to compile cleanly with the -Wcast-qual gcc
warning enabled, but only if ZLIB_CONST is defined, which adds
const to next_in and msg in z_stream and in the in_func prototype.
A --const option is added to ./configure which adds -DZLIB_CONST
to the compile flags, and adds -Wcast-qual to the compile flags
when ZLIBGCCWARN is set in the environment.
crc_table is made using a four-byte integer (when that can be
determined). However get_crc_table() returned a pointer to an
unsigned long, which could be eight bytes. This fixes that by
creating a new z_crc_t type for the crc_table.
This type is also used for the BYFOUR crc calculations that depend
on a four-byte type. The four-byte type can now be determined by
./configure, which also solves a problem where ./configure --solo
would never use BYFOUR. No the Z_U4 #define indicates that four-
byte integer was found either by ./configure or by zconf.h.
gzflags() was put in gzwrite.c in order to be compiled exactly the
same as gzprintf(), so that it was guaranteed to return the correct
information. However that causes a static linkage to zlib to bring
in many routines that are often not used. All that is required to
duplicate the compilation environment of gzprintf() is to include
gzguts.h. So that is now done in zutil.c to assure that the correct
flags are returned.
Also since gzread() will no longer return an error for an incomplete
gzip file, have gzclose() return an error if the last gzread() ended
in the middle of a gzip stream.
inflate() avoided that allocation normally, until it was modified to
update the window on a normal completion so that inflateResetKeep()
could work. This patch restores that behavior, but only when
Z_FINISH is used successfully to complete an inflation of a stream in
a single call of inflate(). The comments in zlib.h have been updated
accordingly.
This patch adds the deflateResetKeep() function to retain the sliding
window for the next deflate operation, and fixes an inflateResetKeep()
problem that came from inflate() not updating the window when the
stream completed. This enables constructing and decompressing a series
of concatenated deflate streams where each can depend on the history of
uncompressed data that precedes it.
This generalizes deflateSetDictionary() and inflateSetDictionary() to
permit setting the dictionary in the middle of a stream for raw deflate
and inflate. This in combination with the Keep functions enables a
scheme for updating files block by block with the transmission of
compressed data, where blocks are sent with deflateResetKeep() to
retain history for better compression, and deflateSetDictionary() is
used for blocks already present at the receiver to skip compression but
insert that data in the history, again for better compression. The
corresponding inflate calls are done on the receiver side.
Using "ON" was a dumb idea, since it is common to have macros with
names like ON and OFF. In fact, defining the OF macro back in 1995
was a bad idea, but now we're stuck with it. Attempts to rename OF
to something else breaks many applications.
A problem surfaced in a multi-threaded application where fileno() was
used to get a file descriptor from an fopen(), which was then fed to
gzdopen(). The problem occurred when the gzclose() followed by the
fclose() tried to close the same file descriptor twice. If fclose()
were not done, there would be a memory leak. The only way out is to
dup() the file descriptor so that gzclose() closes the duplicated
file descriptor, and fclose() closes the original file descriptor.
This permits compilers to check for the proper treatment of next_in and
msg in the z_stream structure. This is an option instead of the default
in order to preserve backward compatibility. Some applications make use
of the z_stream structure outside of zlib, and perform operations such
as free(strm->next_in), which would not be permitted when next_in is
const. The #define ZLIB_CONST needs to precede the #include "zlib.h">,
in order to make next_in and msg const pointers in the z_stream type.
The Microsoft CAB file format compresses each block with completed
deflate streams that depend on the sliding window history of the
previous block in order to decode. inflateResetKeep() does what
inflateReset() does, except the sliding window history from the
previous inflate operation is retained.
A common request has been the ability to compile zlib to require no
other libraries. This --solo option provides that ability. The price
is that the gz*, compress*, and uncompress functions are eliminated,
and that the user must provide memory allocation and free routines to
deflate and inflate when initializing.