mirror of https://github.com/madler/zlib.git
parent
13a294f044
commit
8e34b3a802
58 changed files with 7305 additions and 5376 deletions
@ -1,9 +0,0 @@ |
|||||||
To make a shared library: |
|
||||||
|
|
||||||
1. Compile a static library |
|
||||||
2. Use mkexps on that to create libz.exp |
|
||||||
3. Apply the configure.diff patch to configure |
|
||||||
4. Run the new configure to make a new Makefile |
|
||||||
5. Use the new Makefile to make the shared library |
|
||||||
|
|
||||||
Courtesy of dbakker@arrayasolutions.com |
|
@ -1,57 +0,0 @@ |
|||||||
*** ../orig/zlib-1.1.4/configure Wed Jul 8 14:19:35 1998
|
|
||||||
--- configure Sun Feb 9 11:11:19 2003
|
|
||||||
***************
|
|
||||||
*** 18,23 ****
|
|
||||||
--- 18,24 ----
|
|
||||||
# If you have problems, try without defining CC and CFLAGS before reporting
|
|
||||||
# an error.
|
|
||||||
|
|
||||||
+ LDFLAGS="-L. -lz"
|
|
||||||
LIBS=libz.a
|
|
||||||
SHAREDLIB=libz.so
|
|
||||||
VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
|
|
||||||
***************
|
|
||||||
*** 116,121 ****
|
|
||||||
--- 117,128 ----
|
|
||||||
SFLAGS=${CFLAGS-"-Kconform_pic -O"}
|
|
||||||
CFLAGS=${CFLAGS-"-O"}
|
|
||||||
LDSHARED=${LDSHARED-"cc -G"};;
|
|
||||||
+ AIX*)
|
|
||||||
+ SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
|
|
||||||
+ CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
|
|
||||||
+ LDTESTSHARED=${LDSHARED-"cc -G"}
|
|
||||||
+ LDSHAREDFLAGS="-L. libz.so"
|
|
||||||
+ LDSHARED=${LDSHARED-"cc -G"};;
|
|
||||||
# send working options for other systems to support@gzip.org
|
|
||||||
*) SFLAGS=${CFLAGS-"-O"}
|
|
||||||
CFLAGS=${CFLAGS-"-O"}
|
|
||||||
***************
|
|
||||||
*** 127,135 ****
|
|
||||||
echo Checking for shared library support...
|
|
||||||
# we must test in two steps (cc then ld), required at least on SunOS 4.x
|
|
||||||
if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
|
|
||||||
! test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
|
|
||||||
CFLAGS="$SFLAGS"
|
|
||||||
LIBS="$SHAREDLIB.$VER"
|
|
||||||
echo Building shared library $SHAREDLIB.$VER with $CC.
|
|
||||||
elif test -z "$old_cc" -a -z "$old_cflags"; then
|
|
||||||
echo No shared library suppport.
|
|
||||||
--- 134,143 ----
|
|
||||||
echo Checking for shared library support...
|
|
||||||
# we must test in two steps (cc then ld), required at least on SunOS 4.x
|
|
||||||
if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
|
|
||||||
! test "`($LDTESTSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
|
|
||||||
CFLAGS="$SFLAGS"
|
|
||||||
LIBS="$SHAREDLIB.$VER"
|
|
||||||
+ LDFLAGS="$LDSHAREDFLAGS"
|
|
||||||
echo Building shared library $SHAREDLIB.$VER with $CC.
|
|
||||||
elif test -z "$old_cc" -a -z "$old_cflags"; then
|
|
||||||
echo No shared library suppport.
|
|
||||||
***************
|
|
||||||
*** 209,212 ****
|
|
||||||
--- 217,221 ----
|
|
||||||
/^exec_prefix *=/s%=.*%=$exec_prefix%
|
|
||||||
/^libdir *=/s%=.*%=$libdir%
|
|
||||||
/^includedir *=/s%=.*%=$includedir%
|
|
||||||
+ /^LDFLAGS *=/s%=.*%=$LDFLAGS%
|
|
||||||
" > Makefile
|
|
@ -1,37 +0,0 @@ |
|||||||
#!/bin/ksh |
|
||||||
# |
|
||||||
# mkexps - make export list |
|
||||||
# This program creates an export list by combining all the "." and normal names |
|
||||||
# into one list. |
|
||||||
# |
|
||||||
if [[ "$#" -ne 1 ]] |
|
||||||
then |
|
||||||
print "Usage: mkexps ArchiveFile" |
|
||||||
exit -2 |
|
||||||
fi |
|
||||||
if [[ ! -f $1 ]] |
|
||||||
then |
|
||||||
print "mkexps: Cannot open file \"$1\"" |
|
||||||
exit -1 |
|
||||||
fi |
|
||||||
|
|
||||||
dump -g $1 | awk ' |
|
||||||
BEGIN { |
|
||||||
top = 1 |
|
||||||
} |
|
||||||
/^[ ]*[0-9][0-9]*/ { |
|
||||||
if ( (n = index( $2, "." )) > 0 ) { |
|
||||||
export_array[ top++ ] = substr( $2, n+1, length( $2 )) |
|
||||||
} |
|
||||||
else { |
|
||||||
export_array[ top++ ] = $2 |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
END { |
|
||||||
for ( i = 1; i < top; i++ ) |
|
||||||
{ |
|
||||||
print export_array[ i ] |
|
||||||
} |
|
||||||
|
|
||||||
}' | sort | uniq |
|
@ -0,0 +1,35 @@ |
|||||||
|
These classes provide a C++ stream interface to the zlib library. It allows you |
||||||
|
to do things like: |
||||||
|
|
||||||
|
gzofstream outf("blah.gz"); |
||||||
|
outf << "These go into the gzip file " << 123 << endl; |
||||||
|
|
||||||
|
It does this by deriving a specialized stream buffer for gzipped files, which is |
||||||
|
the way Stroustrup would have done it. :-> |
||||||
|
|
||||||
|
The gzifstream and gzofstream classes were originally written by Kevin Ruland |
||||||
|
and made available in the zlib contrib/iostream directory. The older version still |
||||||
|
compiles under gcc 2.xx, but not under gcc 3.xx, which sparked the development of |
||||||
|
this version. |
||||||
|
|
||||||
|
The new classes are as standard-compliant as possible, closely following the |
||||||
|
approach of the standard library's fstream classes. It compiles under gcc versions |
||||||
|
3.2 and 3.3, but not under gcc 2.xx. This is mainly due to changes in the standard |
||||||
|
library naming scheme. The new version of gzifstream/gzofstream/gzfilebuf differs |
||||||
|
from the previous one in the following respects: |
||||||
|
- added showmanyc |
||||||
|
- added setbuf, with support for unbuffered output via setbuf(0,0) |
||||||
|
- a few bug fixes of stream behavior |
||||||
|
- gzipped output file opened with default compression level instead of maximum level |
||||||
|
- setcompressionlevel()/strategy() members replaced by single setcompression() |
||||||
|
|
||||||
|
The code is provided "as is", with the permission to use, copy, modify, distribute |
||||||
|
and sell it for any purpose without fee. |
||||||
|
|
||||||
|
Ludwig Schwardt |
||||||
|
<schwardt@sun.ac.za> |
||||||
|
|
||||||
|
DSP Lab |
||||||
|
Electrical & Electronic Engineering Department |
||||||
|
University of Stellenbosch |
||||||
|
South Africa |
@ -0,0 +1,17 @@ |
|||||||
|
Possible upgrades to gzfilebuf: |
||||||
|
|
||||||
|
- The ability to do putback (e.g. putbackfail) |
||||||
|
|
||||||
|
- The ability to seek (zlib supports this, but could be slow/tricky) |
||||||
|
|
||||||
|
- Simultaneous read/write access (does it make sense?) |
||||||
|
|
||||||
|
- Support for ios_base::ate open mode |
||||||
|
|
||||||
|
- Locale support? |
||||||
|
|
||||||
|
- Check public interface to see which calls give problems |
||||||
|
(due to dependence on library internals) |
||||||
|
|
||||||
|
- Override operator<<(ostream&, gzfilebuf*) to allow direct copying |
||||||
|
of stream buffer to stream ( i.e. os << is.rdbuf(); ) |
@ -0,0 +1,50 @@ |
|||||||
|
/*
|
||||||
|
* Test program for gzifstream and gzofstream |
||||||
|
*
|
||||||
|
* by Ludwig Schwardt <schwardt@sun.ac.za> |
||||||
|
* original version by Kevin Ruland <kevin@rodin.wustl.edu> |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "zfstream.h" |
||||||
|
#include <iostream> // for cout |
||||||
|
|
||||||
|
int main() { |
||||||
|
|
||||||
|
gzofstream outf; |
||||||
|
gzifstream inf; |
||||||
|
char buf[80]; |
||||||
|
|
||||||
|
outf.open("test1.txt.gz"); |
||||||
|
outf << "The quick brown fox sidestepped the lazy canine\n"
|
||||||
|
<< 1.3 << "\nPlan " << 9 << std::endl; |
||||||
|
outf.close(); |
||||||
|
std::cout << "Wrote the following message to 'test1.txt.gz' (check with zcat or zless):\n" |
||||||
|
<< "The quick brown fox sidestepped the lazy canine\n" |
||||||
|
<< 1.3 << "\nPlan " << 9 << std::endl; |
||||||
|
|
||||||
|
std::cout << "\nReading 'test1.txt.gz' (buffered) produces:\n"; |
||||||
|
inf.open("test1.txt.gz"); |
||||||
|
while (inf.getline(buf,80,'\n')) { |
||||||
|
std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; |
||||||
|
} |
||||||
|
inf.close(); |
||||||
|
|
||||||
|
outf.rdbuf()->pubsetbuf(0,0); |
||||||
|
outf.open("test2.txt.gz"); |
||||||
|
outf << setcompression(Z_NO_COMPRESSION) |
||||||
|
<< "The quick brown fox sidestepped the lazy canine\n" |
||||||
|
<< 1.3 << "\nPlan " << 9 << std::endl; |
||||||
|
outf.close(); |
||||||
|
std::cout << "\nWrote the same message to 'test2.txt.gz' in uncompressed form"; |
||||||
|
|
||||||
|
std::cout << "\nReading 'test2.txt.gz' (unbuffered) produces:\n"; |
||||||
|
inf.rdbuf()->pubsetbuf(0,0); |
||||||
|
inf.open("test2.txt.gz"); |
||||||
|
while (inf.getline(buf,80,'\n')) { |
||||||
|
std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; |
||||||
|
} |
||||||
|
inf.close(); |
||||||
|
|
||||||
|
return 0; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,479 @@ |
|||||||
|
/*
|
||||||
|
* A C++ I/O streams interface to the zlib gz* functions |
||||||
|
*
|
||||||
|
* by Ludwig Schwardt <schwardt@sun.ac.za> |
||||||
|
* original version by Kevin Ruland <kevin@rodin.wustl.edu> |
||||||
|
*
|
||||||
|
* This version is standard-compliant and compatible with gcc 3.x. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "zfstream.h" |
||||||
|
#include <cstring> // for strcpy, strcat, strlen (mode strings) |
||||||
|
#include <cstdio> // for BUFSIZ |
||||||
|
|
||||||
|
// Internal buffer sizes (default and "unbuffered" versions)
|
||||||
|
#define BIGBUFSIZE BUFSIZ |
||||||
|
#define SMALLBUFSIZE 1 |
||||||
|
|
||||||
|
/*****************************************************************************/ |
||||||
|
|
||||||
|
// Default constructor
|
||||||
|
gzfilebuf::gzfilebuf()
|
||||||
|
: file(NULL), io_mode(std::ios_base::openmode(0)), own_fd(false),
|
||||||
|
buffer(NULL), buffer_size(BIGBUFSIZE), own_buffer(true) |
||||||
|
{ |
||||||
|
// No buffers to start with
|
||||||
|
this->disable_buffer(); |
||||||
|
} |
||||||
|
|
||||||
|
// Destructor
|
||||||
|
gzfilebuf::~gzfilebuf()
|
||||||
|
{ |
||||||
|
// Sync output buffer and close only if responsible for file
|
||||||
|
// (i.e. attached streams should be left open at this stage)
|
||||||
|
this->sync(); |
||||||
|
if (own_fd)
|
||||||
|
this->close(); |
||||||
|
// Make sure internal buffer is deallocated
|
||||||
|
this->disable_buffer(); |
||||||
|
} |
||||||
|
|
||||||
|
// Set compression level and strategy
|
||||||
|
int |
||||||
|
gzfilebuf::setcompression(int comp_level, |
||||||
|
int comp_strategy) |
||||||
|
{ |
||||||
|
return gzsetparams(file, comp_level, comp_strategy); |
||||||
|
} |
||||||
|
|
||||||
|
// Open gzipped file
|
||||||
|
gzfilebuf*
|
||||||
|
gzfilebuf::open(const char *name,
|
||||||
|
std::ios_base::openmode mode) |
||||||
|
{ |
||||||
|
// Fail if file already open
|
||||||
|
if (this->is_open())
|
||||||
|
return NULL; |
||||||
|
// Don't support simultaneous read/write access (yet)
|
||||||
|
if ((mode & std::ios_base::in) && (mode & std::ios_base::out))
|
||||||
|
return NULL; |
||||||
|
|
||||||
|
// Build mode string for gzopen and check it [27.8.1.3.2]
|
||||||
|
char char_mode[6] = "\0\0\0\0\0"; |
||||||
|
if (!this->open_mode(mode, char_mode)) |
||||||
|
return NULL; |
||||||
|
|
||||||
|
// Attempt to open file
|
||||||
|
if ((file = gzopen(name, char_mode)) == NULL)
|
||||||
|
return NULL; |
||||||
|
|
||||||
|
// On success, allocate internal buffer and set flags
|
||||||
|
this->enable_buffer(); |
||||||
|
io_mode = mode; |
||||||
|
own_fd = true; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
// Attach to gzipped file
|
||||||
|
gzfilebuf* |
||||||
|
gzfilebuf::attach(int fd, |
||||||
|
std::ios_base::openmode mode)
|
||||||
|
{ |
||||||
|
// Fail if file already open
|
||||||
|
if (this->is_open())
|
||||||
|
return NULL; |
||||||
|
// Don't support simultaneous read/write access (yet)
|
||||||
|
if ((mode & std::ios_base::in) && (mode & std::ios_base::out))
|
||||||
|
return NULL; |
||||||
|
|
||||||
|
// Build mode string for gzdopen and check it [27.8.1.3.2]
|
||||||
|
char char_mode[6] = "\0\0\0\0\0"; |
||||||
|
if (!this->open_mode(mode, char_mode)) |
||||||
|
return NULL; |
||||||
|
|
||||||
|
// Attempt to attach to file
|
||||||
|
if ((file = gzdopen(fd, char_mode)) == NULL) |
||||||
|
return NULL; |
||||||
|
|
||||||
|
// On success, allocate internal buffer and set flags
|
||||||
|
this->enable_buffer(); |
||||||
|
io_mode = mode; |
||||||
|
own_fd = false; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
// Close gzipped file
|
||||||
|
gzfilebuf* |
||||||
|
gzfilebuf::close()
|
||||||
|
{ |
||||||
|
// Fail immediately if no file is open
|
||||||
|
if (!this->is_open()) |
||||||
|
return NULL; |
||||||
|
// Assume success
|
||||||
|
gzfilebuf* retval = this; |
||||||
|
// Attempt to sync and close gzipped file
|
||||||
|
if (this->sync() == -1) |
||||||
|
retval = NULL; |
||||||
|
if (gzclose(file) < 0) |
||||||
|
retval = NULL; |
||||||
|
// File is now gone anyway (postcondition [27.8.1.3.8])
|
||||||
|
file = NULL; |
||||||
|
own_fd = false; |
||||||
|
// Destroy internal buffer if it exists
|
||||||
|
this->disable_buffer(); |
||||||
|
return retval; |
||||||
|
} |
||||||
|
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
||||||
|
|
||||||
|
// Convert int open mode to mode string
|
||||||
|
bool
|
||||||
|
gzfilebuf::open_mode(std::ios_base::openmode mode,
|
||||||
|
char* c_mode) const |
||||||
|
{ |
||||||
|
bool testb = mode & std::ios_base::binary; |
||||||
|
bool testi = mode & std::ios_base::in; |
||||||
|
bool testo = mode & std::ios_base::out; |
||||||
|
bool testt = mode & std::ios_base::trunc; |
||||||
|
bool testa = mode & std::ios_base::app; |
||||||
|
|
||||||
|
// Check for valid flag combinations - see [27.8.1.3.2] (Table 92)
|
||||||
|
// Original zfstream hardcoded the compression level to maximum here...
|
||||||
|
// Double the time for less than 1% size improvement seems
|
||||||
|
// excessive though - keeping it at the default level
|
||||||
|
// To change back, just append "9" to the next three mode strings
|
||||||
|
if (!testi && testo && !testt && !testa) |
||||||
|
strcpy(c_mode, "w"); |
||||||
|
if (!testi && testo && !testt && testa) |
||||||
|
strcpy(c_mode, "a"); |
||||||
|
if (!testi && testo && testt && !testa) |
||||||
|
strcpy(c_mode, "w"); |
||||||
|
if (testi && !testo && !testt && !testa) |
||||||
|
strcpy(c_mode, "r"); |
||||||
|
// No read/write mode yet
|
||||||
|
// if (testi && testo && !testt && !testa)
|
||||||
|
// strcpy(c_mode, "r+");
|
||||||
|
// if (testi && testo && testt && !testa)
|
||||||
|
// strcpy(c_mode, "w+");
|
||||||
|
|
||||||
|
// Mode string should be empty for invalid combination of flags
|
||||||
|
if (strlen(c_mode) == 0) |
||||||
|
return false; |
||||||
|
if (testb) |
||||||
|
strcat(c_mode, "b"); |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
// Determine number of characters in internal get buffer
|
||||||
|
std::streamsize
|
||||||
|
gzfilebuf::showmanyc() |
||||||
|
{ |
||||||
|
// Calls to underflow will fail if file not opened for reading
|
||||||
|
if (!this->is_open() || !(io_mode & std::ios_base::in)) |
||||||
|
return -1; |
||||||
|
// Make sure get area is in use
|
||||||
|
if (this->gptr() && (this->gptr() < this->egptr())) |
||||||
|
return std::streamsize(this->egptr() - this->gptr()); |
||||||
|
else |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
// Fill get area from gzipped file
|
||||||
|
gzfilebuf::int_type |
||||||
|
gzfilebuf::underflow()
|
||||||
|
{ |
||||||
|
// If something is left in the get area by chance, return it
|
||||||
|
// (this shouldn't normally happen, as underflow is only supposed
|
||||||
|
// to be called when gptr >= egptr, but it serves as error check)
|
||||||
|
if (this->gptr() && (this->gptr() < this->egptr())) |
||||||
|
return traits_type::to_int_type(*(this->gptr())); |
||||||
|
|
||||||
|
// If the file hasn't been opened for reading, produce error
|
||||||
|
if (!this->is_open() || !(io_mode & std::ios_base::in)) |
||||||
|
return traits_type::eof(); |
||||||
|
|
||||||
|
// Attempt to fill internal buffer from gzipped file
|
||||||
|
// (buffer must be guaranteed to exist...)
|
||||||
|
int bytes_read = gzread(file, buffer, buffer_size); |
||||||
|
// Indicates error or EOF
|
||||||
|
if (bytes_read <= 0) |
||||||
|
{ |
||||||
|
// Reset get area
|
||||||
|
this->setg(buffer, buffer, buffer); |
||||||
|
return traits_type::eof(); |
||||||
|
} |
||||||
|
// Make all bytes read from file available as get area
|
||||||
|
this->setg(buffer, buffer, buffer + bytes_read); |
||||||
|
|
||||||
|
// Return next character in get area
|
||||||
|
return traits_type::to_int_type(*(this->gptr())); |
||||||
|
} |
||||||
|
|
||||||
|
// Write put area to gzipped file
|
||||||
|
gzfilebuf::int_type |
||||||
|
gzfilebuf::overflow(int_type c)
|
||||||
|
{ |
||||||
|
// Determine whether put area is in use
|
||||||
|
if (this->pbase()) |
||||||
|
{ |
||||||
|
// Double-check pointer range
|
||||||
|
if (this->pptr() > this->epptr() || this->pptr() < this->pbase()) |
||||||
|
return traits_type::eof(); |
||||||
|
// Add extra character to buffer if not EOF
|
||||||
|
if (!traits_type::eq_int_type(c, traits_type::eof())) |
||||||
|
{ |
||||||
|
*(this->pptr()) = traits_type::to_char_type(c); |
||||||
|
this->pbump(1); |
||||||
|
} |
||||||
|
// Number of characters to write to file
|
||||||
|
int bytes_to_write = this->pptr() - this->pbase(); |
||||||
|
// Overflow doesn't fail if nothing is to be written
|
||||||
|
if (bytes_to_write > 0) |
||||||
|
{ |
||||||
|
// If the file hasn't been opened for writing, produce error
|
||||||
|
if (!this->is_open() || !(io_mode & std::ios_base::out)) |
||||||
|
return traits_type::eof(); |
||||||
|
// If gzipped file won't accept all bytes written to it, fail
|
||||||
|
if (gzwrite(file, this->pbase(), bytes_to_write) != bytes_to_write) |
||||||
|
return traits_type::eof(); |
||||||
|
// Reset next pointer to point to pbase on success
|
||||||
|
this->pbump(-bytes_to_write); |
||||||
|
} |
||||||
|
} |
||||||
|
// Write extra character to file if not EOF
|
||||||
|
else if (!traits_type::eq_int_type(c, traits_type::eof())) |
||||||
|
{ |
||||||
|
// If the file hasn't been opened for writing, produce error
|
||||||
|
if (!this->is_open() || !(io_mode & std::ios_base::out)) |
||||||
|
return traits_type::eof(); |
||||||
|
// Impromptu char buffer (allows "unbuffered" output)
|
||||||
|
char_type last_char = traits_type::to_char_type(c); |
||||||
|
// If gzipped file won't accept this character, fail
|
||||||
|
if (gzwrite(file, &last_char, 1) != 1) |
||||||
|
return traits_type::eof();
|
||||||
|
} |
||||||
|
|
||||||
|
// If you got here, you have succeeded (even if c was EOF)
|
||||||
|
// The return value should therefore be non-EOF
|
||||||
|
if (traits_type::eq_int_type(c, traits_type::eof())) |
||||||
|
return traits_type::not_eof(c); |
||||||
|
else |
||||||
|
return c; |
||||||
|
} |
||||||
|
|
||||||
|
// Assign new buffer
|
||||||
|
std::streambuf*
|
||||||
|
gzfilebuf::setbuf(char_type* p, |
||||||
|
std::streamsize n) |
||||||
|
{ |
||||||
|
// First make sure stuff is sync'ed, for safety
|
||||||
|
if (this->sync() == -1) |
||||||
|
return NULL; |
||||||
|
// If buffering is turned off on purpose via setbuf(0,0), still allocate one...
|
||||||
|
// "Unbuffered" only really refers to put [27.8.1.4.10], while get needs at
|
||||||
|
// least a buffer of size 1 (very inefficient though, therefore make it bigger?)
|
||||||
|
// This follows from [27.5.2.4.3]/12 (gptr needs to point at something, it seems)
|
||||||
|
if (!p || !n) |
||||||
|
{ |
||||||
|
// Replace existing buffer (if any) with small internal buffer
|
||||||
|
this->disable_buffer(); |
||||||
|
buffer = NULL; |
||||||
|
buffer_size = 0; |
||||||
|
own_buffer = true; |
||||||
|
this->enable_buffer(); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
// Replace existing buffer (if any) with external buffer
|
||||||
|
this->disable_buffer(); |
||||||
|
buffer = p; |
||||||
|
buffer_size = n; |
||||||
|
own_buffer = false; |
||||||
|
this->enable_buffer(); |
||||||
|
} |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
// Write put area to gzipped file (i.e. ensures that put area is empty)
|
||||||
|
int
|
||||||
|
gzfilebuf::sync()
|
||||||
|
{ |
||||||
|
return traits_type::eq_int_type(this->overflow(), traits_type::eof()) ? -1 : 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
||||||
|
|
||||||
|
// Allocate internal buffer
|
||||||
|
void
|
||||||
|
gzfilebuf::enable_buffer()
|
||||||
|
{ |
||||||
|
// If internal buffer required, allocate one
|
||||||
|
if (own_buffer && !buffer)
|
||||||
|
{ |
||||||
|
// Check for buffered vs. "unbuffered"
|
||||||
|
if (buffer_size > 0) |
||||||
|
{ |
||||||
|
// Allocate internal buffer
|
||||||
|
buffer = new char_type[buffer_size]; |
||||||
|
// Get area starts empty and will be expanded by underflow as need arises
|
||||||
|
this->setg(buffer, buffer, buffer); |
||||||
|
// Setup entire internal buffer as put area.
|
||||||
|
// The one-past-end pointer actually points to the last element of the buffer,
|
||||||
|
// so that overflow(c) can safely add the extra character c to the sequence.
|
||||||
|
// These pointers remain in place for the duration of the buffer
|
||||||
|
this->setp(buffer, buffer + buffer_size - 1); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
// Even in "unbuffered" case, (small?) get buffer is still required
|
||||||
|
buffer_size = SMALLBUFSIZE; |
||||||
|
buffer = new char_type[buffer_size]; |
||||||
|
this->setg(buffer, buffer, buffer); |
||||||
|
// "Unbuffered" means no put buffer
|
||||||
|
this->setp(0, 0); |
||||||
|
} |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
// If buffer already allocated, reset buffer pointers just to make sure no
|
||||||
|
// stale chars are lying around
|
||||||
|
this->setg(buffer, buffer, buffer); |
||||||
|
this->setp(buffer, buffer + buffer_size - 1); |
||||||
|
}
|
||||||
|
} |
||||||
|
|
||||||
|
// Destroy internal buffer
|
||||||
|
void
|
||||||
|
gzfilebuf::disable_buffer()
|
||||||
|
{ |
||||||
|
// If internal buffer exists, deallocate it
|
||||||
|
if (own_buffer && buffer) |
||||||
|
{ |
||||||
|
// Preserve unbuffered status by zeroing size
|
||||||
|
if (!this->pbase()) |
||||||
|
buffer_size = 0; |
||||||
|
delete[] buffer; |
||||||
|
buffer = NULL; |
||||||
|
this->setg(0, 0, 0); |
||||||
|
this->setp(0, 0); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
// Reset buffer pointers to initial state if external buffer exists
|
||||||
|
this->setg(buffer, buffer, buffer); |
||||||
|
if (buffer) |
||||||
|
this->setp(buffer, buffer + buffer_size - 1); |
||||||
|
else |
||||||
|
this->setp(0, 0); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/*****************************************************************************/ |
||||||
|
|
||||||
|
// Default constructor initializes stream buffer
|
||||||
|
gzifstream::gzifstream()
|
||||||
|
: std::istream(NULL), sb() |
||||||
|
{ this->init(&sb); } |
||||||
|
|
||||||
|
// Initialize stream buffer and open file
|
||||||
|
gzifstream::gzifstream(const char* name, |
||||||
|
std::ios_base::openmode mode) |
||||||
|
: std::istream(NULL), sb() |
||||||
|
{ |
||||||
|
this->init(&sb); |
||||||
|
this->open(name, mode); |
||||||
|
} |
||||||
|
|
||||||
|
// Initialize stream buffer and attach to file
|
||||||
|
gzifstream::gzifstream(int fd, |
||||||
|
std::ios_base::openmode mode) |
||||||
|
: std::istream(NULL), sb() |
||||||
|
{ |
||||||
|
this->init(&sb); |
||||||
|
this->attach(fd, mode); |
||||||
|
} |
||||||
|
|
||||||
|
// Open file and go into fail() state if unsuccessful
|
||||||
|
void
|
||||||
|
gzifstream::open(const char* name,
|
||||||
|
std::ios_base::openmode mode) |
||||||
|
{ |
||||||
|
if (!sb.open(name, mode | std::ios_base::in)) |
||||||
|
this->setstate(std::ios_base::failbit); |
||||||
|
else |
||||||
|
this->clear(); |
||||||
|
} |
||||||
|
|
||||||
|
// Attach to file and go into fail() state if unsuccessful
|
||||||
|
void
|
||||||
|
gzifstream::attach(int fd,
|
||||||
|
std::ios_base::openmode mode) |
||||||
|
{ |
||||||
|
if (!sb.attach(fd, mode | std::ios_base::in)) |
||||||
|
this->setstate(std::ios_base::failbit); |
||||||
|
else |
||||||
|
this->clear(); |
||||||
|
} |
||||||
|
|
||||||
|
// Close file
|
||||||
|
void
|
||||||
|
gzifstream::close() |
||||||
|
{ |
||||||
|
if (!sb.close()) |
||||||
|
this->setstate(std::ios_base::failbit); |
||||||
|
} |
||||||
|
|
||||||
|
/*****************************************************************************/ |
||||||
|
|
||||||
|
// Default constructor initializes stream buffer
|
||||||
|
gzofstream::gzofstream()
|
||||||
|
: std::ostream(NULL), sb() |
||||||
|
{ this->init(&sb); } |
||||||
|
|
||||||
|
// Initialize stream buffer and open file
|
||||||
|
gzofstream::gzofstream(const char* name, |
||||||
|
std::ios_base::openmode mode) |
||||||
|
: std::ostream(NULL), sb() |
||||||
|
{ |
||||||
|
this->init(&sb); |
||||||
|
this->open(name, mode); |
||||||
|
} |
||||||
|
|
||||||
|
// Initialize stream buffer and attach to file
|
||||||
|
gzofstream::gzofstream(int fd, |
||||||
|
std::ios_base::openmode mode) |
||||||
|
: std::ostream(NULL), sb() |
||||||
|
{ |
||||||
|
this->init(&sb); |
||||||
|
this->attach(fd, mode); |
||||||
|
} |
||||||
|
|
||||||
|
// Open file and go into fail() state if unsuccessful
|
||||||
|
void
|
||||||
|
gzofstream::open(const char* name,
|
||||||
|
std::ios_base::openmode mode) |
||||||
|
{ |
||||||
|
if (!sb.open(name, mode | std::ios_base::out)) |
||||||
|
this->setstate(std::ios_base::failbit); |
||||||
|
else |
||||||
|
this->clear(); |
||||||
|
} |
||||||
|
|
||||||
|
// Attach to file and go into fail() state if unsuccessful
|
||||||
|
void
|
||||||
|
gzofstream::attach(int fd,
|
||||||
|
std::ios_base::openmode mode) |
||||||
|
{ |
||||||
|
if (!sb.attach(fd, mode | std::ios_base::out)) |
||||||
|
this->setstate(std::ios_base::failbit); |
||||||
|
else |
||||||
|
this->clear(); |
||||||
|
} |
||||||
|
|
||||||
|
// Close file
|
||||||
|
void
|
||||||
|
gzofstream::close() |
||||||
|
{ |
||||||
|
if (!sb.close()) |
||||||
|
this->setstate(std::ios_base::failbit); |
||||||
|
} |
@ -0,0 +1,466 @@ |
|||||||
|
/*
|
||||||
|
* A C++ I/O streams interface to the zlib gz* functions |
||||||
|
*
|
||||||
|
* by Ludwig Schwardt <schwardt@sun.ac.za> |
||||||
|
* original version by Kevin Ruland <kevin@rodin.wustl.edu> |
||||||
|
*
|
||||||
|
* This version is standard-compliant and compatible with gcc 3.x. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef ZFSTREAM_H |
||||||
|
#define ZFSTREAM_H |
||||||
|
|
||||||
|
#include <istream> // not iostream, since we don't need cin/cout |
||||||
|
#include <ostream> |
||||||
|
#include "zlib.h" |
||||||
|
|
||||||
|
/*****************************************************************************/ |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gzipped file stream buffer class. |
||||||
|
* |
||||||
|
* This class implements basic_filebuf for gzipped files. It doesn't yet support |
||||||
|
* seeking (allowed by zlib but slow/limited), putback and read/write access
|
||||||
|
* (tricky). Otherwise, it attempts to be a drop-in replacement for the standard
|
||||||
|
* file streambuf. |
||||||
|
*/ |
||||||
|
class gzfilebuf : public std::streambuf
|
||||||
|
{ |
||||||
|
public:
|
||||||
|
// Default constructor.
|
||||||
|
gzfilebuf(); |
||||||
|
|
||||||
|
// Destructor.
|
||||||
|
virtual
|
||||||
|
~gzfilebuf(); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set compression level and strategy on the fly. |
||||||
|
* @param comp_level Compression level (see zlib.h for allowed values)
|
||||||
|
* @param comp_strategy Compression strategy (see zlib.h for allowed values)
|
||||||
|
* @return Z_OK on success, Z_STREAM_ERROR otherwise. |
||||||
|
*
|
||||||
|
* Unfortunately, these parameters cannot be modified separately, as the |
||||||
|
* previous zfstream version assumed. Since the strategy is seldom changed, |
||||||
|
* it can default and setcompression(level) then becomes like the old |
||||||
|
* setcompressionlevel(level). |
||||||
|
*/ |
||||||
|
int
|
||||||
|
setcompression(int comp_level,
|
||||||
|
int comp_strategy = Z_DEFAULT_STRATEGY); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if file is open. |
||||||
|
* @return True if file is open. |
||||||
|
*/ |
||||||
|
bool
|
||||||
|
is_open() const { return (file != NULL); } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Open gzipped file. |
||||||
|
* @param name File name. |
||||||
|
* @param mode Open mode flags. |
||||||
|
* @return @c this on success, NULL on failure. |
||||||
|
*/ |
||||||
|
gzfilebuf*
|
||||||
|
open(const char* name,
|
||||||
|
std::ios_base::openmode mode); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Attach to already open gzipped file. |
||||||
|
* @param fd File descriptor. |
||||||
|
* @param mode Open mode flags. |
||||||
|
* @return @c this on success, NULL on failure. |
||||||
|
*/ |
||||||
|
gzfilebuf*
|
||||||
|
attach(int fd,
|
||||||
|
std::ios_base::openmode mode); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Close gzipped file. |
||||||
|
* @return @c this on success, NULL on failure. |
||||||
|
*/ |
||||||
|
gzfilebuf*
|
||||||
|
close(); |
||||||
|
|
||||||
|
protected: |
||||||
|
/**
|
||||||
|
* @brief Convert ios open mode int to mode string used by zlib. |
||||||
|
* @return True if valid mode flag combination. |
||||||
|
*/ |
||||||
|
bool
|
||||||
|
open_mode(std::ios_base::openmode mode,
|
||||||
|
char* c_mode) const; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Number of characters available in stream buffer. |
||||||
|
* @return Number of characters. |
||||||
|
*
|
||||||
|
* This indicates number of characters in get area of stream buffer. |
||||||
|
* These characters can be read without accessing the gzipped file. |
||||||
|
*/ |
||||||
|
virtual std::streamsize |
||||||
|
showmanyc(); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fill get area from gzipped file. |
||||||
|
* @return First character in get area on success, EOF on error. |
||||||
|
*
|
||||||
|
* This actually reads characters from gzipped file to stream |
||||||
|
* buffer. Always buffered. |
||||||
|
*/ |
||||||
|
virtual int_type |
||||||
|
underflow(); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Write put area to gzipped file. |
||||||
|
* @param c Extra character to add to buffer contents. |
||||||
|
* @return Non-EOF on success, EOF on error. |
||||||
|
*
|
||||||
|
* This actually writes characters in stream buffer to
|
||||||
|
* gzipped file. With unbuffered output this is done one
|
||||||
|
* character at a time. |
||||||
|
*/
|
||||||
|
virtual int_type
|
||||||
|
overflow(int_type c = traits_type::eof()); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Installs external stream buffer. |
||||||
|
* @param p Pointer to char buffer. |
||||||
|
* @param n Size of external buffer. |
||||||
|
* @return @c this on success, NULL on failure. |
||||||
|
*
|
||||||
|
* Call setbuf(0,0) to enable unbuffered output. |
||||||
|
*/ |
||||||
|
virtual std::streambuf*
|
||||||
|
setbuf(char_type* p,
|
||||||
|
std::streamsize n); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Flush stream buffer to file. |
||||||
|
* @return 0 on success, -1 on error. |
||||||
|
*
|
||||||
|
* This calls underflow(EOF) to do the job. |
||||||
|
*/ |
||||||
|
virtual int
|
||||||
|
sync(); |
||||||
|
|
||||||
|
//
|
||||||
|
// Some future enhancements
|
||||||
|
//
|
||||||
|
// virtual int_type uflow();
|
||||||
|
// virtual int_type pbackfail(int_type c = traits_type::eof());
|
||||||
|
// virtual pos_type
|
||||||
|
// seekoff(off_type off,
|
||||||
|
// std::ios_base::seekdir way,
|
||||||
|
// std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out);
|
||||||
|
// virtual pos_type
|
||||||
|
// seekpos(pos_type sp,
|
||||||
|
// std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out);
|
||||||
|
|
||||||
|
private: |
||||||
|
/**
|
||||||
|
* @brief Allocate internal buffer. |
||||||
|
*
|
||||||
|
* This function is safe to call multiple times. It will ensure |
||||||
|
* that a proper internal buffer exists if it is required. If the |
||||||
|
* buffer already exists or is external, the buffer pointers will be |
||||||
|
* reset to their original state. |
||||||
|
*/ |
||||||
|
void
|
||||||
|
enable_buffer(); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destroy internal buffer. |
||||||
|
*
|
||||||
|
* This function is safe to call multiple times. It will ensure |
||||||
|
* that the internal buffer is deallocated if it exists. In any |
||||||
|
* case, it will also reset the buffer pointers. |
||||||
|
*/ |
||||||
|
void
|
||||||
|
disable_buffer(); |
||||||
|
|
||||||
|
/**
|
||||||
|
* Underlying file pointer. |
||||||
|
*/ |
||||||
|
gzFile file; |
||||||
|
|
||||||
|
/**
|
||||||
|
* Mode in which file was opened. |
||||||
|
*/ |
||||||
|
std::ios_base::openmode io_mode; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief True if this object owns file descriptor. |
||||||
|
* |
||||||
|
* This makes the class responsible for closing the file
|
||||||
|
* upon destruction. |
||||||
|
*/ |
||||||
|
bool own_fd; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Stream buffer. |
||||||
|
*
|
||||||
|
* For simplicity this remains allocated on the free store for the
|
||||||
|
* entire life span of the gzfilebuf object, unless replaced by setbuf. |
||||||
|
*/ |
||||||
|
char_type* buffer; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Stream buffer size. |
||||||
|
*
|
||||||
|
* Defaults to system default buffer size (typically 8192 bytes). |
||||||
|
* Modified by setbuf. |
||||||
|
*/ |
||||||
|
std::streamsize buffer_size; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief True if this object owns stream buffer. |
||||||
|
* |
||||||
|
* This makes the class responsible for deleting the buffer
|
||||||
|
* upon destruction. |
||||||
|
*/ |
||||||
|
bool own_buffer; |
||||||
|
}; |
||||||
|
|
||||||
|
/*****************************************************************************/ |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gzipped file input stream class. |
||||||
|
* |
||||||
|
* This class implements ifstream for gzipped files. Seeking and putback |
||||||
|
* is not supported yet. |
||||||
|
*/ |
||||||
|
class gzifstream : public std::istream
|
||||||
|
{ |
||||||
|
public: |
||||||
|
// Default constructor
|
||||||
|
gzifstream(); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct stream on gzipped file to be opened. |
||||||
|
* @param name File name. |
||||||
|
* @param mode Open mode flags (forced to contain ios::in). |
||||||
|
*/ |
||||||
|
explicit |
||||||
|
gzifstream(const char* name,
|
||||||
|
std::ios_base::openmode mode = std::ios_base::in); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct stream on already open gzipped file. |
||||||
|
* @param fd File descriptor. |
||||||
|
* @param mode Open mode flags (forced to contain ios::in). |
||||||
|
*/ |
||||||
|
explicit
|
||||||
|
gzifstream(int fd,
|
||||||
|
std::ios_base::openmode mode = std::ios_base::in); |
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain underlying stream buffer. |
||||||
|
*/
|
||||||
|
gzfilebuf*
|
||||||
|
rdbuf() const |
||||||
|
{ return const_cast<gzfilebuf*>(&sb); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if file is open. |
||||||
|
* @return True if file is open. |
||||||
|
*/ |
||||||
|
bool
|
||||||
|
is_open() { return sb.is_open(); } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Open gzipped file. |
||||||
|
* @param name File name. |
||||||
|
* @param mode Open mode flags (forced to contain ios::in). |
||||||
|
*
|
||||||
|
* Stream will be in state good() if file opens successfully; |
||||||
|
* otherwise in state fail(). This differs from the behavior of |
||||||
|
* ifstream, which never sets the state to good() and therefore |
||||||
|
* won't allow you to reuse the stream for a second file unless |
||||||
|
* you manually clear() the state. The choice is a matter of |
||||||
|
* convenience. |
||||||
|
*/ |
||||||
|
void
|
||||||
|
open(const char* name,
|
||||||
|
std::ios_base::openmode mode = std::ios_base::in); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Attach to already open gzipped file. |
||||||
|
* @param fd File descriptor. |
||||||
|
* @param mode Open mode flags (forced to contain ios::in). |
||||||
|
*
|
||||||
|
* Stream will be in state good() if attach succeeded; otherwise |
||||||
|
* in state fail(). |
||||||
|
*/ |
||||||
|
void
|
||||||
|
attach(int fd,
|
||||||
|
std::ios_base::openmode mode = std::ios_base::in); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Close gzipped file. |
||||||
|
*
|
||||||
|
* Stream will be in state fail() if close failed. |
||||||
|
*/ |
||||||
|
void
|
||||||
|
close(); |
||||||
|
|
||||||
|
private: |
||||||
|
/**
|
||||||
|
* Underlying stream buffer. |
||||||
|
*/
|
||||||
|
gzfilebuf sb; |
||||||
|
}; |
||||||
|
|
||||||
|
/*****************************************************************************/ |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gzipped file output stream class. |
||||||
|
* |
||||||
|
* This class implements ofstream for gzipped files. Seeking and putback |
||||||
|
* is not supported yet. |
||||||
|
*/ |
||||||
|
class gzofstream : public std::ostream |
||||||
|
{ |
||||||
|
public: |
||||||
|
// Default constructor
|
||||||
|
gzofstream(); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct stream on gzipped file to be opened. |
||||||
|
* @param name File name. |
||||||
|
* @param mode Open mode flags (forced to contain ios::out). |
||||||
|
*/ |
||||||
|
explicit |
||||||
|
gzofstream(const char* name,
|
||||||
|
std::ios_base::openmode mode = std::ios_base::out); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct stream on already open gzipped file. |
||||||
|
* @param fd File descriptor. |
||||||
|
* @param mode Open mode flags (forced to contain ios::out). |
||||||
|
*/ |
||||||
|
explicit
|
||||||
|
gzofstream(int fd,
|
||||||
|
std::ios_base::openmode mode = std::ios_base::out); |
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain underlying stream buffer. |
||||||
|
*/
|
||||||
|
gzfilebuf*
|
||||||
|
rdbuf() const |
||||||
|
{ return const_cast<gzfilebuf*>(&sb); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if file is open. |
||||||
|
* @return True if file is open. |
||||||
|
*/ |
||||||
|
bool
|
||||||
|
is_open() { return sb.is_open(); } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Open gzipped file. |
||||||
|
* @param name File name. |
||||||
|
* @param mode Open mode flags (forced to contain ios::out). |
||||||
|
*
|
||||||
|
* Stream will be in state good() if file opens successfully; |
||||||
|
* otherwise in state fail(). This differs from the behavior of |
||||||
|
* ofstream, which never sets the state to good() and therefore |
||||||
|
* won't allow you to reuse the stream for a second file unless |
||||||
|
* you manually clear() the state. The choice is a matter of |
||||||
|
* convenience. |
||||||
|
*/ |
||||||
|
void
|
||||||
|
open(const char* name,
|
||||||
|
std::ios_base::openmode mode = std::ios_base::out); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Attach to already open gzipped file. |
||||||
|
* @param fd File descriptor. |
||||||
|
* @param mode Open mode flags (forced to contain ios::out). |
||||||
|
*
|
||||||
|
* Stream will be in state good() if attach succeeded; otherwise |
||||||
|
* in state fail(). |
||||||
|
*/ |
||||||
|
void
|
||||||
|
attach(int fd,
|
||||||
|
std::ios_base::openmode mode = std::ios_base::out); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Close gzipped file. |
||||||
|
*
|
||||||
|
* Stream will be in state fail() if close failed. |
||||||
|
*/ |
||||||
|
void
|
||||||
|
close(); |
||||||
|
|
||||||
|
private: |
||||||
|
/**
|
||||||
|
* Underlying stream buffer. |
||||||
|
*/
|
||||||
|
gzfilebuf sb; |
||||||
|
}; |
||||||
|
|
||||||
|
/*****************************************************************************/ |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gzipped file output stream manipulator class. |
||||||
|
* |
||||||
|
* This class defines a two-argument manipulator for gzofstream. It is used |
||||||
|
* as base for the setcompression(int,int) manipulator. |
||||||
|
*/ |
||||||
|
template<typename T1, typename T2> |
||||||
|
class gzomanip2 |
||||||
|
{ |
||||||
|
public: |
||||||
|
// Allows insertor to peek at internals
|
||||||
|
template <typename Ta, typename Tb> |
||||||
|
friend gzofstream&
|
||||||
|
operator<<(gzofstream&,
|
||||||
|
const gzomanip2<Ta,Tb>&); |
||||||
|
|
||||||
|
// Constructor
|
||||||
|
gzomanip2(gzofstream& (*f)(gzofstream&, T1, T2), |
||||||
|
T1 v1, |
||||||
|
T2 v2); |
||||||
|
private: |
||||||
|
// Underlying manipulator function
|
||||||
|
gzofstream& |
||||||
|
(*func)(gzofstream&, T1, T2); |
||||||
|
|
||||||
|
// Arguments for manipulator function
|
||||||
|
T1 val1; |
||||||
|
T2 val2; |
||||||
|
}; |
||||||
|
|
||||||
|
/*****************************************************************************/ |
||||||
|
|
||||||
|
// Manipulator function thunks through to stream buffer
|
||||||
|
inline gzofstream&
|
||||||
|
setcompression(gzofstream &gzs, int l, int s = Z_DEFAULT_STRATEGY) |
||||||
|
{ |
||||||
|
(gzs.rdbuf())->setcompression(l, s); |
||||||
|
return gzs; |
||||||
|
} |
||||||
|
|
||||||
|
// Manipulator constructor stores arguments
|
||||||
|
template<typename T1, typename T2> |
||||||
|
inline
|
||||||
|
gzomanip2<T1,T2>::gzomanip2(gzofstream &(*f)(gzofstream &, T1, T2), |
||||||
|
T1 v1, |
||||||
|
T2 v2)
|
||||||
|
: func(f), val1(v1), val2(v2) |
||||||
|
{ } |
||||||
|
|
||||||
|
// Insertor applies underlying manipulator function to stream
|
||||||
|
template<typename T1, typename T2> |
||||||
|
inline gzofstream&
|
||||||
|
operator<<(gzofstream& s, const gzomanip2<T1,T2>& m)
|
||||||
|
{ return (*m.func)(s, m.val1, m.val2); } |
||||||
|
|
||||||
|
// Insert this onto stream to simplify setting of compression level
|
||||||
|
inline gzomanip2<int,int>
|
||||||
|
setcompression(int l, int s = Z_DEFAULT_STRATEGY)
|
||||||
|
{ return gzomanip2<int,int>(&setcompression, l, s); } |
||||||
|
|
||||||
|
#endif // ZFSTREAM_H
|
@ -1,47 +1,51 @@ |
|||||||
Change in 0.21: (10 Mar 03) |
Change in 0.22: (19 May 03) |
||||||
- bug fixes |
- crypting support (unless you define NOCRYPT) |
||||||
|
- append file in existing zipfile |
||||||
Change in 0.17: (27 Jan 02) |
|
||||||
- bug fixes |
Change in 0.21: (10 Mar 03) |
||||||
|
- bug fixes |
||||||
Change in 0.16: (19 Jan 02) |
|
||||||
- Support of ioapi for virtualize zip file access |
Change in 0.17: (27 Jan 02) |
||||||
|
- bug fixes |
||||||
Change in 0.15: (19 Mar 98) |
|
||||||
- fix memory leak in minizip.c |
Change in 0.16: (19 Jan 02) |
||||||
|
- Support of ioapi for virtualize zip file access |
||||||
Change in 0.14: (10 Mar 98) |
|
||||||
- fix bugs in minizip.c sample for zipping big file |
Change in 0.15: (19 Mar 98) |
||||||
- fix problem in month in date handling |
- fix memory leak in minizip.c |
||||||
- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for |
|
||||||
comment handling |
Change in 0.14: (10 Mar 98) |
||||||
|
- fix bugs in minizip.c sample for zipping big file |
||||||
Change in 0.13: (6 Mar 98) |
- fix problem in month in date handling |
||||||
- fix bugs in zip.c |
- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for |
||||||
- add real minizip sample |
comment handling |
||||||
|
|
||||||
Change in 0.12: (4 Mar 98) |
Change in 0.13: (6 Mar 98) |
||||||
- add zip.c and zip.h for creates .zip file |
- fix bugs in zip.c |
||||||
- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly) |
- add real minizip sample |
||||||
- fix miniunz.c for file without specific record for directory |
|
||||||
|
Change in 0.12: (4 Mar 98) |
||||||
Change in 0.11: (3 Mar 98) |
- add zip.c and zip.h for creates .zip file |
||||||
- fix bug in unzGetCurrentFileInfo for get extra field and comment |
- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly) |
||||||
- enhance miniunz sample, remove the bad unztst.c sample |
- fix miniunz.c for file without specific record for directory |
||||||
|
|
||||||
Change in 0.10: (2 Mar 98) |
Change in 0.11: (3 Mar 98) |
||||||
- fix bug in unzReadCurrentFile |
- fix bug in unzGetCurrentFileInfo for get extra field and comment |
||||||
- rename unzip* to unz* function and structure |
- enhance miniunz sample, remove the bad unztst.c sample |
||||||
- remove Windows-like hungary notation variable name |
|
||||||
- modify some structure in unzip.h |
Change in 0.10: (2 Mar 98) |
||||||
- add somes comment in source |
- fix bug in unzReadCurrentFile |
||||||
- remove unzipGetcCurrentFile function |
- rename unzip* to unz* function and structure |
||||||
- replace ZUNZEXPORT by ZEXPORT |
- remove Windows-like hungary notation variable name |
||||||
- add unzGetLocalExtrafield for get the local extrafield info |
- modify some structure in unzip.h |
||||||
- add a new sample, miniunz.c |
- add somes comment in source |
||||||
|
- remove unzipGetcCurrentFile function |
||||||
Change in 0.4: (25 Feb 98) |
- replace ZUNZEXPORT by ZEXPORT |
||||||
- suppress the type unzipFileInZip. |
- add unzGetLocalExtrafield for get the local extrafield info |
||||||
Only on file in the zipfile can be open at the same time |
- add a new sample, miniunz.c |
||||||
- fix somes typo in code |
|
||||||
- added tm_unz structure in unzip_file_info (date/time in readable format) |
Change in 0.4: (25 Feb 98) |
||||||
|
- suppress the type unzipFileInZip. |
||||||
|
Only on file in the zipfile can be open at the same time |
||||||
|
- fix somes typo in code |
||||||
|
- added tm_unz structure in unzip_file_info (date/time in readable format) |
||||||
|
@ -1,25 +1,25 @@ |
|||||||
CC=cc
|
CC=cc
|
||||||
CFLAGS=-O -I../..
|
CFLAGS=-O -I../..
|
||||||
|
|
||||||
UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
|
UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
|
||||||
ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
|
ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
|
||||||
|
|
||||||
.c.o: |
.c.o: |
||||||
$(CC) -c $(CFLAGS) $*.c
|
$(CC) -c $(CFLAGS) $*.c
|
||||||
|
|
||||||
all: miniunz minizip |
all: miniunz minizip |
||||||
|
|
||||||
miniunz: $(UNZ_OBJS) |
miniunz: $(UNZ_OBJS) |
||||||
$(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
|
$(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
|
||||||
|
|
||||||
minizip: $(ZIP_OBJS) |
minizip: $(ZIP_OBJS) |
||||||
$(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
|
$(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
|
||||||
|
|
||||||
test: miniunz minizip |
test: miniunz minizip |
||||||
./minizip test readme.txt
|
./minizip test readme.txt
|
||||||
./miniunz -l test.zip
|
./miniunz -l test.zip
|
||||||
mv readme.txt readme.old
|
mv readme.txt readme.old
|
||||||
./miniunz test.zip
|
./miniunz test.zip
|
||||||
|
|
||||||
clean: |
clean: |
||||||
/bin/rm -f *.o *~ minizip miniunz
|
/bin/rm -f *.o *~ minizip miniunz
|
||||||
|
@ -1,104 +1,104 @@ |
|||||||
|
|
||||||
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) |
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) |
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Return the next byte in the pseudo-random sequence |
* Return the next byte in the pseudo-random sequence |
||||||
*/ |
*/ |
||||||
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) |
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) |
||||||
{ |
{ |
||||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||||
* unpredictable manner on 16-bit systems; not a problem |
* unpredictable manner on 16-bit systems; not a problem |
||||||
* with any known compiler so far, though */ |
* with any known compiler so far, though */ |
||||||
|
|
||||||
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; |
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; |
||||||
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); |
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); |
||||||
} |
} |
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Update the encryption keys with the next byte of plain text |
* Update the encryption keys with the next byte of plain text |
||||||
*/ |
*/ |
||||||
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) |
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) |
||||||
{ |
{ |
||||||
(*(pkeys+0)) = CRC32((*(pkeys+0)), c); |
(*(pkeys+0)) = CRC32((*(pkeys+0)), c); |
||||||
(*(pkeys+1)) += (*(pkeys+0)) & 0xff; |
(*(pkeys+1)) += (*(pkeys+0)) & 0xff; |
||||||
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; |
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; |
||||||
{ |
{ |
||||||
register int keyshift = (int)((*(pkeys+1)) >> 24); |
register int keyshift = (int)((*(pkeys+1)) >> 24); |
||||||
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); |
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); |
||||||
} |
} |
||||||
return c; |
return c; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Initialize the encryption keys and the random header according to |
* Initialize the encryption keys and the random header according to |
||||||
* the given password. |
* the given password. |
||||||
*/ |
*/ |
||||||
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) |
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) |
||||||
{ |
{ |
||||||
*(pkeys+0) = 305419896L; |
*(pkeys+0) = 305419896L; |
||||||
*(pkeys+1) = 591751049L; |
*(pkeys+1) = 591751049L; |
||||||
*(pkeys+2) = 878082192L; |
*(pkeys+2) = 878082192L; |
||||||
while (*passwd != '\0') { |
while (*passwd != '\0') { |
||||||
update_keys(pkeys,pcrc_32_tab,(int)*passwd); |
update_keys(pkeys,pcrc_32_tab,(int)*passwd); |
||||||
passwd++; |
passwd++; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
#define zdecode(pkeys,pcrc_32_tab,c) \ |
#define zdecode(pkeys,pcrc_32_tab,c) \ |
||||||
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) |
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) |
||||||
|
|
||||||
#define zencode(pkeys,pcrc_32_tab,c,t) \ |
#define zencode(pkeys,pcrc_32_tab,c,t) \ |
||||||
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) |
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) |
||||||
|
|
||||||
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED |
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED |
||||||
|
|
||||||
#define RAND_HEAD_LEN 12 |
#define RAND_HEAD_LEN 12 |
||||||
/* "last resort" source for second part of crypt seed pattern */ |
/* "last resort" source for second part of crypt seed pattern */ |
||||||
# ifndef ZCR_SEED2 |
# ifndef ZCR_SEED2 |
||||||
# define ZCR_SEED2 (unsigned long)3141592654L /* use PI as default pattern */ |
# define ZCR_SEED2 (unsigned long)3141592654L /* use PI as default pattern */ |
||||||
# endif |
# endif |
||||||
|
|
||||||
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) |
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) |
||||||
const char *passwd; /* password string */ |
const char *passwd; /* password string */ |
||||||
unsigned char *buf; /* where to write header */ |
unsigned char *buf; /* where to write header */ |
||||||
int bufSize; |
int bufSize; |
||||||
unsigned long* pkeys; |
unsigned long* pkeys; |
||||||
const unsigned long* pcrc_32_tab; |
const unsigned long* pcrc_32_tab; |
||||||
unsigned long crcForCrypting; |
unsigned long crcForCrypting; |
||||||
{ |
{ |
||||||
int n; /* index in random header */ |
int n; /* index in random header */ |
||||||
int t; /* temporary */ |
int t; /* temporary */ |
||||||
int c; /* random byte */ |
int c; /* random byte */ |
||||||
unsigned char header[RAND_HEAD_LEN-2]; /* random header */ |
unsigned char header[RAND_HEAD_LEN-2]; /* random header */ |
||||||
static unsigned calls = 0; /* ensure different random header each time */ |
static unsigned calls = 0; /* ensure different random header each time */ |
||||||
|
|
||||||
if (bufSize<RAND_HEAD_LEN) |
if (bufSize<RAND_HEAD_LEN) |
||||||
return 0; |
return 0; |
||||||
|
|
||||||
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
||||||
* output of rand() to get less predictability, since rand() is |
* output of rand() to get less predictability, since rand() is |
||||||
* often poorly implemented. |
* often poorly implemented. |
||||||
*/ |
*/ |
||||||
if (++calls == 1) |
if (++calls == 1) |
||||||
{ |
{ |
||||||
srand((unsigned)(time(NULL) ^ ZCR_SEED2)); |
srand((unsigned)(time(NULL) ^ ZCR_SEED2)); |
||||||
} |
} |
||||||
init_keys(passwd, pkeys, pcrc_32_tab); |
init_keys(passwd, pkeys, pcrc_32_tab); |
||||||
for (n = 0; n < RAND_HEAD_LEN-2; n++) |
for (n = 0; n < RAND_HEAD_LEN-2; n++) |
||||||
{ |
{ |
||||||
c = (rand() >> 7) & 0xff; |
c = (rand() >> 7) & 0xff; |
||||||
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); |
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); |
||||||
} |
} |
||||||
/* Encrypt random header (last two bytes is high word of crc) */ |
/* Encrypt random header (last two bytes is high word of crc) */ |
||||||
init_keys(passwd, pkeys, pcrc_32_tab); |
init_keys(passwd, pkeys, pcrc_32_tab); |
||||||
for (n = 0; n < RAND_HEAD_LEN-2; n++) |
for (n = 0; n < RAND_HEAD_LEN-2; n++) |
||||||
{ |
{ |
||||||
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); |
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); |
||||||
} |
} |
||||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); |
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); |
||||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); |
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); |
||||||
return n; |
return n; |
||||||
} |
} |
||||||
|
|
||||||
#endif |
#endif |
||||||
|
@ -1,177 +1,177 @@ |
|||||||
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
||||||
files using zlib + zip or unzip API |
files using zlib + zip or unzip API |
||||||
|
|
||||||
Version 0.21, March 10th, 2003 |
Version 0.22, May 19th, 2003 |
||||||
|
|
||||||
Copyright (C) 1998-2003 Gilles Vollant |
Copyright (C) 1998-2003 Gilles Vollant |
||||||
*/ |
*/ |
||||||
|
|
||||||
#include <stdio.h> |
#include <stdio.h> |
||||||
#include <stdlib.h> |
#include <stdlib.h> |
||||||
#include <string.h> |
#include <string.h> |
||||||
|
|
||||||
#include "zlib.h" |
#include "zlib.h" |
||||||
#include "ioapi.h" |
#include "ioapi.h" |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ |
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ |
||||||
|
|
||||||
#ifndef SEEK_CUR |
#ifndef SEEK_CUR |
||||||
#define SEEK_CUR 1 |
#define SEEK_CUR 1 |
||||||
#endif |
#endif |
||||||
|
|
||||||
#ifndef SEEK_END |
#ifndef SEEK_END |
||||||
#define SEEK_END 2 |
#define SEEK_END 2 |
||||||
#endif |
#endif |
||||||
|
|
||||||
#ifndef SEEK_SET |
#ifndef SEEK_SET |
||||||
#define SEEK_SET 0 |
#define SEEK_SET 0 |
||||||
#endif |
#endif |
||||||
|
|
||||||
voidpf ZCALLBACK fopen_file_func OF(( |
voidpf ZCALLBACK fopen_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
const char* filename, |
const char* filename, |
||||||
int mode)); |
int mode)); |
||||||
|
|
||||||
uLong ZCALLBACK fread_file_func OF(( |
uLong ZCALLBACK fread_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
voidpf stream, |
voidpf stream, |
||||||
void* buf, |
void* buf, |
||||||
uLong size)); |
uLong size)); |
||||||
|
|
||||||
uLong ZCALLBACK fwrite_file_func OF(( |
uLong ZCALLBACK fwrite_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
voidpf stream, |
voidpf stream, |
||||||
const void* buf, |
const void* buf, |
||||||
uLong size)); |
uLong size)); |
||||||
|
|
||||||
long ZCALLBACK ftell_file_func OF(( |
long ZCALLBACK ftell_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
voidpf stream)); |
voidpf stream)); |
||||||
|
|
||||||
long ZCALLBACK fseek_file_func OF(( |
long ZCALLBACK fseek_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
voidpf stream, |
voidpf stream, |
||||||
uLong offset, |
uLong offset, |
||||||
int origin)); |
int origin)); |
||||||
|
|
||||||
int ZCALLBACK fclose_file_func OF(( |
int ZCALLBACK fclose_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
voidpf stream)); |
voidpf stream)); |
||||||
|
|
||||||
int ZCALLBACK ferror_file_func OF(( |
int ZCALLBACK ferror_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
voidpf stream)); |
voidpf stream)); |
||||||
|
|
||||||
|
|
||||||
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) |
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
const char* filename; |
const char* filename; |
||||||
int mode; |
int mode; |
||||||
{ |
{ |
||||||
FILE* file = NULL; |
FILE* file = NULL; |
||||||
const char* mode_fopen = NULL; |
const char* mode_fopen = NULL; |
||||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) |
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) |
||||||
mode_fopen = "rb"; |
mode_fopen = "rb"; |
||||||
else |
else |
||||||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING) |
if (mode & ZLIB_FILEFUNC_MODE_EXISTING) |
||||||
mode_fopen = "r+b"; |
mode_fopen = "r+b"; |
||||||
else |
else |
||||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE) |
if (mode & ZLIB_FILEFUNC_MODE_CREATE) |
||||||
mode_fopen = "wb"; |
mode_fopen = "wb"; |
||||||
|
|
||||||
if ((filename!=NULL) && (mode_fopen != NULL)) |
if ((filename!=NULL) && (mode_fopen != NULL)) |
||||||
file = fopen(filename, mode_fopen); |
file = fopen(filename, mode_fopen); |
||||||
return file; |
return file; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) |
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
voidpf stream; |
voidpf stream; |
||||||
void* buf; |
void* buf; |
||||||
uLong size; |
uLong size; |
||||||
{ |
{ |
||||||
uLong ret; |
uLong ret; |
||||||
ret = fread(buf, 1, (size_t)size, (FILE *)stream); |
ret = fread(buf, 1, (size_t)size, (FILE *)stream); |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) |
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
voidpf stream; |
voidpf stream; |
||||||
const void* buf; |
const void* buf; |
||||||
uLong size; |
uLong size; |
||||||
{ |
{ |
||||||
uLong ret; |
uLong ret; |
||||||
ret = fwrite(buf, 1, (size_t)size, (FILE *)stream); |
ret = fwrite(buf, 1, (size_t)size, (FILE *)stream); |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
long ZCALLBACK ftell_file_func (opaque, stream) |
long ZCALLBACK ftell_file_func (opaque, stream) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
voidpf stream; |
voidpf stream; |
||||||
{ |
{ |
||||||
long ret; |
long ret; |
||||||
ret = ftell((FILE *)stream); |
ret = ftell((FILE *)stream); |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) |
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
voidpf stream; |
voidpf stream; |
||||||
uLong offset; |
uLong offset; |
||||||
int origin; |
int origin; |
||||||
{ |
{ |
||||||
int fseek_origin=0; |
int fseek_origin=0; |
||||||
long ret; |
long ret; |
||||||
switch (origin) |
switch (origin) |
||||||
{ |
{ |
||||||
case ZLIB_FILEFUNC_SEEK_CUR : |
case ZLIB_FILEFUNC_SEEK_CUR : |
||||||
fseek_origin = SEEK_CUR; |
fseek_origin = SEEK_CUR; |
||||||
break; |
break; |
||||||
case ZLIB_FILEFUNC_SEEK_END : |
case ZLIB_FILEFUNC_SEEK_END : |
||||||
fseek_origin = SEEK_END; |
fseek_origin = SEEK_END; |
||||||
break; |
break; |
||||||
case ZLIB_FILEFUNC_SEEK_SET : |
case ZLIB_FILEFUNC_SEEK_SET : |
||||||
fseek_origin = SEEK_SET; |
fseek_origin = SEEK_SET; |
||||||
break; |
break; |
||||||
default: return -1; |
default: return -1; |
||||||
} |
} |
||||||
ret = 0; |
ret = 0; |
||||||
fseek((FILE *)stream, offset, fseek_origin); |
fseek((FILE *)stream, offset, fseek_origin); |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
int ZCALLBACK fclose_file_func (opaque, stream) |
int ZCALLBACK fclose_file_func (opaque, stream) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
voidpf stream; |
voidpf stream; |
||||||
{ |
{ |
||||||
int ret; |
int ret; |
||||||
ret = fclose((FILE *)stream); |
ret = fclose((FILE *)stream); |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
int ZCALLBACK ferror_file_func (opaque, stream) |
int ZCALLBACK ferror_file_func (opaque, stream) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
voidpf stream; |
voidpf stream; |
||||||
{ |
{ |
||||||
int ret; |
int ret; |
||||||
ret = ferror((FILE *)stream); |
ret = ferror((FILE *)stream); |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
void fill_fopen_filefunc (pzlib_filefunc_def) |
void fill_fopen_filefunc (pzlib_filefunc_def) |
||||||
zlib_filefunc_def* pzlib_filefunc_def; |
zlib_filefunc_def* pzlib_filefunc_def; |
||||||
{ |
{ |
||||||
pzlib_filefunc_def->zopen_file = fopen_file_func; |
pzlib_filefunc_def->zopen_file = fopen_file_func; |
||||||
pzlib_filefunc_def->zread_file = fread_file_func; |
pzlib_filefunc_def->zread_file = fread_file_func; |
||||||
pzlib_filefunc_def->zwrite_file = fwrite_file_func; |
pzlib_filefunc_def->zwrite_file = fwrite_file_func; |
||||||
pzlib_filefunc_def->ztell_file = ftell_file_func; |
pzlib_filefunc_def->ztell_file = ftell_file_func; |
||||||
pzlib_filefunc_def->zseek_file = fseek_file_func; |
pzlib_filefunc_def->zseek_file = fseek_file_func; |
||||||
pzlib_filefunc_def->zclose_file = fclose_file_func; |
pzlib_filefunc_def->zclose_file = fclose_file_func; |
||||||
pzlib_filefunc_def->zerror_file = ferror_file_func; |
pzlib_filefunc_def->zerror_file = ferror_file_func; |
||||||
pzlib_filefunc_def->opaque = NULL; |
pzlib_filefunc_def->opaque = NULL; |
||||||
} |
} |
||||||
|
@ -1,75 +1,75 @@ |
|||||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||||
files using zlib + zip or unzip API |
files using zlib + zip or unzip API |
||||||
|
|
||||||
Version 0.21, March 10th, 2003 |
Version 0.22, May 19th, 2003 |
||||||
|
|
||||||
Copyright (C) 1998-2003 Gilles Vollant |
Copyright (C) 1998-2003 Gilles Vollant |
||||||
*/ |
*/ |
||||||
|
|
||||||
#ifndef _ZLIBIOAPI_H |
#ifndef _ZLIBIOAPI_H |
||||||
#define _ZLIBIOAPI_H |
#define _ZLIBIOAPI_H |
||||||
|
|
||||||
|
|
||||||
#define ZLIB_FILEFUNC_SEEK_CUR (1) |
#define ZLIB_FILEFUNC_SEEK_CUR (1) |
||||||
#define ZLIB_FILEFUNC_SEEK_END (2) |
#define ZLIB_FILEFUNC_SEEK_END (2) |
||||||
#define ZLIB_FILEFUNC_SEEK_SET (0) |
#define ZLIB_FILEFUNC_SEEK_SET (0) |
||||||
|
|
||||||
#define ZLIB_FILEFUNC_MODE_READ (1) |
#define ZLIB_FILEFUNC_MODE_READ (1) |
||||||
#define ZLIB_FILEFUNC_MODE_WRITE (2) |
#define ZLIB_FILEFUNC_MODE_WRITE (2) |
||||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) |
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) |
||||||
|
|
||||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4) |
#define ZLIB_FILEFUNC_MODE_EXISTING (4) |
||||||
#define ZLIB_FILEFUNC_MODE_CREATE (8) |
#define ZLIB_FILEFUNC_MODE_CREATE (8) |
||||||
|
|
||||||
|
|
||||||
#ifndef ZCALLBACK |
#ifndef ZCALLBACK |
||||||
|
|
||||||
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) |
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) |
||||||
#define ZCALLBACK CALLBACK |
#define ZCALLBACK CALLBACK |
||||||
#else |
#else |
||||||
#define ZCALLBACK |
#define ZCALLBACK |
||||||
#endif |
#endif |
||||||
#endif |
#endif |
||||||
|
|
||||||
#ifdef __cplusplus |
#ifdef __cplusplus |
||||||
extern "C" { |
extern "C" { |
||||||
#endif |
#endif |
||||||
|
|
||||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); |
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); |
||||||
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); |
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); |
||||||
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); |
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); |
||||||
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); |
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); |
||||||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); |
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); |
||||||
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); |
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); |
||||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); |
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); |
||||||
|
|
||||||
typedef struct zlib_filefunc_def_s |
typedef struct zlib_filefunc_def_s |
||||||
{ |
{ |
||||||
open_file_func zopen_file; |
open_file_func zopen_file; |
||||||
read_file_func zread_file; |
read_file_func zread_file; |
||||||
write_file_func zwrite_file; |
write_file_func zwrite_file; |
||||||
tell_file_func ztell_file; |
tell_file_func ztell_file; |
||||||
seek_file_func zseek_file; |
seek_file_func zseek_file; |
||||||
close_file_func zclose_file; |
close_file_func zclose_file; |
||||||
testerror_file_func zerror_file; |
testerror_file_func zerror_file; |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
} zlib_filefunc_def; |
} zlib_filefunc_def; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); |
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); |
||||||
|
|
||||||
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) |
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) |
||||||
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) |
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) |
||||||
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) |
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) |
||||||
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) |
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) |
||||||
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) |
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) |
||||||
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) |
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) |
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus |
#ifdef __cplusplus |
||||||
} |
} |
||||||
#endif |
#endif |
||||||
|
|
||||||
#endif |
#endif |
||||||
|
|
||||||
|
@ -1,271 +1,271 @@ |
|||||||
/* iowin32.c -- IO base function header for compress/uncompress .zip
|
/* iowin32.c -- IO base function header for compress/uncompress .zip
|
||||||
files using zlib + zip or unzip API |
files using zlib + zip or unzip API |
||||||
This IO API version uses the Win32 API (for Microsoft Windows) |
This IO API version uses the Win32 API (for Microsoft Windows) |
||||||
|
|
||||||
Version 0.21, March 10th, 2003 |
Version 0.22, May 19th, 2003 |
||||||
|
|
||||||
Copyright (C) 1998-2003 Gilles Vollant |
Copyright (C) 1998-2003 Gilles Vollant |
||||||
*/ |
*/ |
||||||
|
|
||||||
#include <windows.h> |
#include <windows.h> |
||||||
#include <stdlib.h> |
#include <stdlib.h> |
||||||
|
|
||||||
#include "zlib.h" |
#include "zlib.h" |
||||||
#include "ioapi.h" |
#include "ioapi.h" |
||||||
#include "iowin32.h" |
#include "iowin32.h" |
||||||
|
|
||||||
#ifndef INVALID_HANDLE_VALUE |
#ifndef INVALID_HANDLE_VALUE |
||||||
#define INVALID_HANDLE_VALUE (0xFFFFFFFF) |
#define INVALID_HANDLE_VALUE (0xFFFFFFFF) |
||||||
#endif |
#endif |
||||||
|
|
||||||
#ifndef INVALID_SET_FILE_POINTER |
#ifndef INVALID_SET_FILE_POINTER |
||||||
#define INVALID_SET_FILE_POINTER ((DWORD)-1) |
#define INVALID_SET_FILE_POINTER ((DWORD)-1) |
||||||
#endif |
#endif |
||||||
|
|
||||||
voidpf ZCALLBACK win32_open_file_func OF(( |
voidpf ZCALLBACK win32_open_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
const char* filename, |
const char* filename, |
||||||
int mode)); |
int mode)); |
||||||
|
|
||||||
uLong ZCALLBACK win32_read_file_func OF(( |
uLong ZCALLBACK win32_read_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
voidpf stream, |
voidpf stream, |
||||||
void* buf, |
void* buf, |
||||||
uLong size)); |
uLong size)); |
||||||
|
|
||||||
uLong ZCALLBACK win32_write_file_func OF(( |
uLong ZCALLBACK win32_write_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
voidpf stream, |
voidpf stream, |
||||||
const void* buf, |
const void* buf, |
||||||
uLong size)); |
uLong size)); |
||||||
|
|
||||||
long ZCALLBACK win32_tell_file_func OF(( |
long ZCALLBACK win32_tell_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
voidpf stream)); |
voidpf stream)); |
||||||
|
|
||||||
long ZCALLBACK win32_seek_file_func OF(( |
long ZCALLBACK win32_seek_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
voidpf stream, |
voidpf stream, |
||||||
uLong offset, |
uLong offset, |
||||||
int origin)); |
int origin)); |
||||||
|
|
||||||
long ZCALLBACK win32_close_file_func OF(( |
long ZCALLBACK win32_close_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
voidpf stream)); |
voidpf stream)); |
||||||
|
|
||||||
int ZCALLBACK win32_error_file_func OF(( |
int ZCALLBACK win32_error_file_func OF(( |
||||||
voidpf opaque, |
voidpf opaque, |
||||||
voidpf stream)); |
voidpf stream)); |
||||||
|
|
||||||
typedef struct |
typedef struct |
||||||
{ |
{ |
||||||
HANDLE hf; |
HANDLE hf; |
||||||
int error; |
int error; |
||||||
} WIN32FILE_IOWIN; |
} WIN32FILE_IOWIN; |
||||||
|
|
||||||
voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode) |
voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
const char* filename; |
const char* filename; |
||||||
int mode; |
int mode; |
||||||
{ |
{ |
||||||
const char* mode_fopen = NULL; |
const char* mode_fopen = NULL; |
||||||
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; |
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; |
||||||
HANDLE hFile = 0; |
HANDLE hFile = 0; |
||||||
voidpf ret=NULL; |
voidpf ret=NULL; |
||||||
|
|
||||||
dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0; |
dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0; |
||||||
|
|
||||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) |
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) |
||||||
{ |
{ |
||||||
dwDesiredAccess = GENERIC_READ; |
dwDesiredAccess = GENERIC_READ; |
||||||
dwCreationDisposition = OPEN_EXISTING; |
dwCreationDisposition = OPEN_EXISTING; |
||||||
dwShareMode = FILE_SHARE_READ; |
dwShareMode = FILE_SHARE_READ; |
||||||
} |
} |
||||||
else |
else |
||||||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING) |
if (mode & ZLIB_FILEFUNC_MODE_EXISTING) |
||||||
{ |
{ |
||||||
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; |
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; |
||||||
dwCreationDisposition = OPEN_EXISTING; |
dwCreationDisposition = OPEN_EXISTING; |
||||||
} |
} |
||||||
else |
else |
||||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE) |
if (mode & ZLIB_FILEFUNC_MODE_CREATE) |
||||||
{ |
{ |
||||||
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; |
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; |
||||||
dwCreationDisposition = CREATE_ALWAYS; |
dwCreationDisposition = CREATE_ALWAYS; |
||||||
} |
} |
||||||
|
|
||||||
if ((filename!=NULL) && (dwDesiredAccess != 0)) |
if ((filename!=NULL) && (dwDesiredAccess != 0)) |
||||||
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, |
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, |
||||||
dwCreationDisposition, dwFlagsAndAttributes, NULL); |
dwCreationDisposition, dwFlagsAndAttributes, NULL); |
||||||
|
|
||||||
if (hFile == INVALID_HANDLE_VALUE) |
if (hFile == INVALID_HANDLE_VALUE) |
||||||
hFile = NULL; |
hFile = NULL; |
||||||
|
|
||||||
if (hFile != NULL) |
if (hFile != NULL) |
||||||
{ |
{ |
||||||
WIN32FILE_IOWIN w32fiow; |
WIN32FILE_IOWIN w32fiow; |
||||||
w32fiow.hf = hFile; |
w32fiow.hf = hFile; |
||||||
w32fiow.error = 0; |
w32fiow.error = 0; |
||||||
ret = malloc(sizeof(WIN32FILE_IOWIN)); |
ret = malloc(sizeof(WIN32FILE_IOWIN)); |
||||||
if (ret==NULL) |
if (ret==NULL) |
||||||
CloseHandle(hFile); |
CloseHandle(hFile); |
||||||
else *((WIN32FILE_IOWIN*)ret) = w32fiow; |
else *((WIN32FILE_IOWIN*)ret) = w32fiow; |
||||||
} |
} |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size) |
uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
voidpf stream; |
voidpf stream; |
||||||
void* buf; |
void* buf; |
||||||
uLong size; |
uLong size; |
||||||
{ |
{ |
||||||
uLong ret=0; |
uLong ret=0; |
||||||
HANDLE hFile = NULL; |
HANDLE hFile = NULL; |
||||||
if (stream!=NULL) |
if (stream!=NULL) |
||||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
||||||
if (hFile != NULL) |
if (hFile != NULL) |
||||||
if (!ReadFile(hFile, buf, size, &ret, NULL)) |
if (!ReadFile(hFile, buf, size, &ret, NULL)) |
||||||
{ |
{ |
||||||
DWORD dwErr = GetLastError(); |
DWORD dwErr = GetLastError(); |
||||||
if (dwErr == ERROR_HANDLE_EOF) |
if (dwErr == ERROR_HANDLE_EOF) |
||||||
dwErr = 0; |
dwErr = 0; |
||||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
||||||
} |
} |
||||||
|
|
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size) |
uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
voidpf stream; |
voidpf stream; |
||||||
const void* buf; |
const void* buf; |
||||||
uLong size; |
uLong size; |
||||||
{ |
{ |
||||||
uLong ret=0; |
uLong ret=0; |
||||||
HANDLE hFile = NULL; |
HANDLE hFile = NULL; |
||||||
if (stream!=NULL) |
if (stream!=NULL) |
||||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
||||||
|
|
||||||
if (hFile !=NULL) |
if (hFile !=NULL) |
||||||
if (!WriteFile(hFile, buf, size, &ret, NULL)) |
if (!WriteFile(hFile, buf, size, &ret, NULL)) |
||||||
{ |
{ |
||||||
DWORD dwErr = GetLastError(); |
DWORD dwErr = GetLastError(); |
||||||
if (dwErr == ERROR_HANDLE_EOF) |
if (dwErr == ERROR_HANDLE_EOF) |
||||||
dwErr = 0; |
dwErr = 0; |
||||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
||||||
} |
} |
||||||
|
|
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
long ZCALLBACK win32_tell_file_func (opaque, stream) |
long ZCALLBACK win32_tell_file_func (opaque, stream) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
voidpf stream; |
voidpf stream; |
||||||
{ |
{ |
||||||
long ret=-1; |
long ret=-1; |
||||||
HANDLE hFile = NULL; |
HANDLE hFile = NULL; |
||||||
if (stream!=NULL) |
if (stream!=NULL) |
||||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
||||||
if (hFile != NULL) |
if (hFile != NULL) |
||||||
{ |
{ |
||||||
DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); |
DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); |
||||||
if (dwSet == INVALID_SET_FILE_POINTER) |
if (dwSet == INVALID_SET_FILE_POINTER) |
||||||
{ |
{ |
||||||
DWORD dwErr = GetLastError(); |
DWORD dwErr = GetLastError(); |
||||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
||||||
ret = -1; |
ret = -1; |
||||||
} |
} |
||||||
else |
else |
||||||
ret=(long)dwSet; |
ret=(long)dwSet; |
||||||
} |
} |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin) |
long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
voidpf stream; |
voidpf stream; |
||||||
uLong offset; |
uLong offset; |
||||||
int origin; |
int origin; |
||||||
{ |
{ |
||||||
DWORD dwMoveMethod=0xFFFFFFFF; |
DWORD dwMoveMethod=0xFFFFFFFF; |
||||||
HANDLE hFile = NULL; |
HANDLE hFile = NULL; |
||||||
|
|
||||||
long ret=-1; |
long ret=-1; |
||||||
if (stream!=NULL) |
if (stream!=NULL) |
||||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
||||||
switch (origin) |
switch (origin) |
||||||
{ |
{ |
||||||
case ZLIB_FILEFUNC_SEEK_CUR : |
case ZLIB_FILEFUNC_SEEK_CUR : |
||||||
dwMoveMethod = FILE_CURRENT; |
dwMoveMethod = FILE_CURRENT; |
||||||
break; |
break; |
||||||
case ZLIB_FILEFUNC_SEEK_END : |
case ZLIB_FILEFUNC_SEEK_END : |
||||||
dwMoveMethod = FILE_END; |
dwMoveMethod = FILE_END; |
||||||
break; |
break; |
||||||
case ZLIB_FILEFUNC_SEEK_SET : |
case ZLIB_FILEFUNC_SEEK_SET : |
||||||
dwMoveMethod = FILE_BEGIN; |
dwMoveMethod = FILE_BEGIN; |
||||||
break; |
break; |
||||||
default: return -1; |
default: return -1; |
||||||
} |
} |
||||||
|
|
||||||
if (hFile != NULL) |
if (hFile != NULL) |
||||||
{ |
{ |
||||||
DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod); |
DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod); |
||||||
if (dwSet == INVALID_SET_FILE_POINTER) |
if (dwSet == INVALID_SET_FILE_POINTER) |
||||||
{ |
{ |
||||||
DWORD dwErr = GetLastError(); |
DWORD dwErr = GetLastError(); |
||||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
||||||
ret = -1; |
ret = -1; |
||||||
} |
} |
||||||
else |
else |
||||||
ret=0; |
ret=0; |
||||||
} |
} |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
long ZCALLBACK win32_close_file_func (opaque, stream) |
long ZCALLBACK win32_close_file_func (opaque, stream) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
voidpf stream; |
voidpf stream; |
||||||
{ |
{ |
||||||
long ret=-1; |
long ret=-1; |
||||||
|
|
||||||
if (stream!=NULL) |
if (stream!=NULL) |
||||||
{ |
{ |
||||||
HANDLE hFile; |
HANDLE hFile; |
||||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
||||||
if (hFile != NULL) |
if (hFile != NULL) |
||||||
{ |
{ |
||||||
CloseHandle(hFile); |
CloseHandle(hFile); |
||||||
ret=0; |
ret=0; |
||||||
} |
} |
||||||
free(stream); |
free(stream); |
||||||
} |
} |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
int ZCALLBACK win32_error_file_func (opaque, stream) |
int ZCALLBACK win32_error_file_func (opaque, stream) |
||||||
voidpf opaque; |
voidpf opaque; |
||||||
voidpf stream; |
voidpf stream; |
||||||
{ |
{ |
||||||
int ret=-1; |
int ret=-1; |
||||||
if (stream!=NULL) |
if (stream!=NULL) |
||||||
{ |
{ |
||||||
ret = ((WIN32FILE_IOWIN*)stream) -> error; |
ret = ((WIN32FILE_IOWIN*)stream) -> error; |
||||||
} |
} |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
void fill_win32_filefunc (pzlib_filefunc_def) |
void fill_win32_filefunc (pzlib_filefunc_def) |
||||||
zlib_filefunc_def* pzlib_filefunc_def; |
zlib_filefunc_def* pzlib_filefunc_def; |
||||||
{ |
{ |
||||||
pzlib_filefunc_def->zopen_file = win32_open_file_func; |
pzlib_filefunc_def->zopen_file = win32_open_file_func; |
||||||
pzlib_filefunc_def->zread_file = win32_read_file_func; |
pzlib_filefunc_def->zread_file = win32_read_file_func; |
||||||
pzlib_filefunc_def->zwrite_file = win32_write_file_func; |
pzlib_filefunc_def->zwrite_file = win32_write_file_func; |
||||||
pzlib_filefunc_def->ztell_file = win32_tell_file_func; |
pzlib_filefunc_def->ztell_file = win32_tell_file_func; |
||||||
pzlib_filefunc_def->zseek_file = win32_seek_file_func; |
pzlib_filefunc_def->zseek_file = win32_seek_file_func; |
||||||
pzlib_filefunc_def->zclose_file = win32_close_file_func; |
pzlib_filefunc_def->zclose_file = win32_close_file_func; |
||||||
pzlib_filefunc_def->zerror_file = win32_error_file_func; |
pzlib_filefunc_def->zerror_file = win32_error_file_func; |
||||||
pzlib_filefunc_def->opaque=NULL; |
pzlib_filefunc_def->opaque=NULL; |
||||||
} |
} |
||||||
|
@ -1,19 +1,19 @@ |
|||||||
/* iowin32.h -- IO base function header for compress/uncompress .zip
|
/* iowin32.h -- IO base function header for compress/uncompress .zip
|
||||||
files using zlib + zip or unzip API |
files using zlib + zip or unzip API |
||||||
This IO API version uses the Win32 API (for Microsoft Windows) |
This IO API version uses the Win32 API (for Microsoft Windows) |
||||||
|
|
||||||
Version 0.21, March 10th, 2003 |
Version 0.22, May 19th, 2003 |
||||||
|
|
||||||
Copyright (C) 1998-2003 Gilles Vollant |
Copyright (C) 1998-2003 Gilles Vollant |
||||||
*/ |
*/ |
||||||
|
|
||||||
#ifdef __cplusplus |
#ifdef __cplusplus |
||||||
extern "C" { |
extern "C" { |
||||||
#endif |
#endif |
||||||
|
|
||||||
void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); |
void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); |
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus |
#ifdef __cplusplus |
||||||
} |
} |
||||||
#endif |
#endif |
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,392 +1,397 @@ |
|||||||
#include <stdio.h> |
#include <stdio.h> |
||||||
#include <stdlib.h> |
#include <stdlib.h> |
||||||
#include <string.h> |
#include <string.h> |
||||||
#include <time.h> |
#include <time.h> |
||||||
#include <errno.h> |
#include <errno.h> |
||||||
#include <fcntl.h> |
#include <fcntl.h> |
||||||
|
|
||||||
#ifdef unix |
#ifdef unix |
||||||
# include <unistd.h> |
# include <unistd.h> |
||||||
# include <utime.h> |
# include <utime.h> |
||||||
# include <sys/types.h> |
# include <sys/types.h> |
||||||
# include <sys/stat.h> |
# include <sys/stat.h> |
||||||
#else |
#else |
||||||
# include <direct.h> |
# include <direct.h> |
||||||
# include <io.h> |
# include <io.h> |
||||||
#endif |
#endif |
||||||
|
|
||||||
#include "zip.h" |
#include "zip.h" |
||||||
|
|
||||||
#ifdef WIN32 |
#ifdef WIN32 |
||||||
#define USEWIN32IOAPI |
#define USEWIN32IOAPI |
||||||
#include "iowin32.h" |
#include "iowin32.h" |
||||||
#endif |
#endif |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define WRITEBUFFERSIZE (16384) |
#define WRITEBUFFERSIZE (16384) |
||||||
#define MAXFILENAME (256) |
#define MAXFILENAME (256) |
||||||
|
|
||||||
#ifdef WIN32 |
#ifdef WIN32 |
||||||
uLong filetime(f, tmzip, dt) |
uLong filetime(f, tmzip, dt) |
||||||
char *f; /* name of file to get info on */ |
char *f; /* name of file to get info on */ |
||||||
tm_zip *tmzip; /* return value: access, modific. and creation times */ |
tm_zip *tmzip; /* return value: access, modific. and creation times */ |
||||||
uLong *dt; /* dostime */ |
uLong *dt; /* dostime */ |
||||||
{ |
{ |
||||||
int ret = 0; |
int ret = 0; |
||||||
{ |
{ |
||||||
FILETIME ftLocal; |
FILETIME ftLocal; |
||||||
HANDLE hFind; |
HANDLE hFind; |
||||||
WIN32_FIND_DATA ff32; |
WIN32_FIND_DATA ff32; |
||||||
|
|
||||||
hFind = FindFirstFile(f,&ff32); |
hFind = FindFirstFile(f,&ff32); |
||||||
if (hFind != INVALID_HANDLE_VALUE) |
if (hFind != INVALID_HANDLE_VALUE) |
||||||
{ |
{ |
||||||
FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); |
FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); |
||||||
FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); |
FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); |
||||||
FindClose(hFind); |
FindClose(hFind); |
||||||
ret = 1; |
ret = 1; |
||||||
} |
} |
||||||
} |
} |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
#else |
#else |
||||||
#ifdef unix |
#ifdef unix |
||||||
uLong filetime(f, tmzip, dt) |
uLong filetime(f, tmzip, dt) |
||||||
char *f; /* name of file to get info on */ |
char *f; /* name of file to get info on */ |
||||||
tm_zip *tmzip; /* return value: access, modific. and creation times */ |
tm_zip *tmzip; /* return value: access, modific. and creation times */ |
||||||
uLong *dt; /* dostime */ |
uLong *dt; /* dostime */ |
||||||
{ |
{ |
||||||
int ret=0; |
int ret=0; |
||||||
struct stat s; /* results of stat() */ |
struct stat s; /* results of stat() */ |
||||||
struct tm* filedate; |
struct tm* filedate; |
||||||
time_t tm_t=0; |
time_t tm_t=0; |
||||||
|
|
||||||
if (strcmp(f,"-")!=0) |
if (strcmp(f,"-")!=0) |
||||||
{ |
{ |
||||||
char name[MAXFILENAME+1]; |
char name[MAXFILENAME+1]; |
||||||
int len = strlen(f); |
int len = strlen(f); |
||||||
|
|
||||||
strncpy(name, f,MAXFILENAME-1); |
strncpy(name, f,MAXFILENAME-1); |
||||||
/* strncpy doesnt append the trailing NULL, of the string is too long. */ |
/* strncpy doesnt append the trailing NULL, of the string is too long. */ |
||||||
name[ MAXFILENAME ] = '\0'; |
name[ MAXFILENAME ] = '\0'; |
||||||
|
|
||||||
if (name[len - 1] == '/') |
if (name[len - 1] == '/') |
||||||
name[len - 1] = '\0'; |
name[len - 1] = '\0'; |
||||||
/* not all systems allow stat'ing a file with / appended */ |
/* not all systems allow stat'ing a file with / appended */ |
||||||
if (stat(name,&s)==0) |
if (stat(name,&s)==0) |
||||||
{ |
{ |
||||||
tm_t = s.st_mtime; |
tm_t = s.st_mtime; |
||||||
ret = 1; |
ret = 1; |
||||||
} |
} |
||||||
} |
} |
||||||
filedate = localtime(&tm_t); |
filedate = localtime(&tm_t); |
||||||
|
|
||||||
tmzip->tm_sec = filedate->tm_sec; |
tmzip->tm_sec = filedate->tm_sec; |
||||||
tmzip->tm_min = filedate->tm_min; |
tmzip->tm_min = filedate->tm_min; |
||||||
tmzip->tm_hour = filedate->tm_hour; |
tmzip->tm_hour = filedate->tm_hour; |
||||||
tmzip->tm_mday = filedate->tm_mday; |
tmzip->tm_mday = filedate->tm_mday; |
||||||
tmzip->tm_mon = filedate->tm_mon ; |
tmzip->tm_mon = filedate->tm_mon ; |
||||||
tmzip->tm_year = filedate->tm_year; |
tmzip->tm_year = filedate->tm_year; |
||||||
|
|
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
#else |
#else |
||||||
uLong filetime(f, tmzip, dt) |
uLong filetime(f, tmzip, dt) |
||||||
char *f; /* name of file to get info on */ |
char *f; /* name of file to get info on */ |
||||||
tm_zip *tmzip; /* return value: access, modific. and creation times */ |
tm_zip *tmzip; /* return value: access, modific. and creation times */ |
||||||
uLong *dt; /* dostime */ |
uLong *dt; /* dostime */ |
||||||
{ |
{ |
||||||
return 0; |
return 0; |
||||||
} |
} |
||||||
#endif |
#endif |
||||||
#endif |
#endif |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int check_exist_file(filename) |
int check_exist_file(filename) |
||||||
const char* filename; |
const char* filename; |
||||||
{ |
{ |
||||||
FILE* ftestexist; |
FILE* ftestexist; |
||||||
int ret = 1; |
int ret = 1; |
||||||
ftestexist = fopen(filename,"rb"); |
ftestexist = fopen(filename,"rb"); |
||||||
if (ftestexist==NULL) |
if (ftestexist==NULL) |
||||||
ret = 0; |
ret = 0; |
||||||
else |
else |
||||||
fclose(ftestexist); |
fclose(ftestexist); |
||||||
return ret; |
return ret; |
||||||
} |
} |
||||||
|
|
||||||
void do_banner() |
void do_banner() |
||||||
{ |
{ |
||||||
printf("MiniZip 0.15, demo of zLib + Zip package written by Gilles Vollant\n"); |
printf("MiniZip 0.22, demo of zLib + Zip package written by Gilles Vollant\n"); |
||||||
printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); |
printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); |
||||||
} |
} |
||||||
|
|
||||||
void do_help() |
void do_help() |
||||||
{ |
{ |
||||||
printf("Usage : minizip [-o] file.zip [files_to_add]\n\n") ; |
printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \
|
||||||
} |
" -o Overwrite existing file.zip\n" \
|
||||||
|
" -a Append to existing file.zip\n" \
|
||||||
/* calculate the CRC32 of a file,
|
" -0 Store only\n" \
|
||||||
because to encrypt a file, we need known the CRC32 of the file before */ |
" -1 Compress faster\n" \
|
||||||
int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) |
" -9 Compress better\n\n"); |
||||||
{ |
} |
||||||
unsigned long calculate_crc=0; |
|
||||||
int err=ZIP_OK; |
/* calculate the CRC32 of a file,
|
||||||
FILE * fin = fopen(filenameinzip,"rb"); |
because to encrypt a file, we need known the CRC32 of the file before */ |
||||||
unsigned long size_read = 0; |
int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) |
||||||
unsigned long total_read = 0; |
{ |
||||||
if (fin==NULL) |
unsigned long calculate_crc=0; |
||||||
{ |
int err=ZIP_OK; |
||||||
err = ZIP_ERRNO; |
FILE * fin = fopen(filenameinzip,"rb"); |
||||||
} |
unsigned long size_read = 0; |
||||||
|
unsigned long total_read = 0; |
||||||
if (err == ZIP_OK) |
if (fin==NULL) |
||||||
do |
{ |
||||||
{ |
err = ZIP_ERRNO; |
||||||
err = ZIP_OK; |
} |
||||||
size_read = (int)fread(buf,1,size_buf,fin); |
|
||||||
if (size_read < size_buf) |
if (err == ZIP_OK) |
||||||
if (feof(fin)==0) |
do |
||||||
{ |
{ |
||||||
printf("error in reading %s\n",filenameinzip); |
err = ZIP_OK; |
||||||
err = ZIP_ERRNO; |
size_read = (int)fread(buf,1,size_buf,fin); |
||||||
} |
if (size_read < size_buf) |
||||||
|
if (feof(fin)==0) |
||||||
if (size_read>0) |
{ |
||||||
calculate_crc = crc32(calculate_crc,buf,size_read); |
printf("error in reading %s\n",filenameinzip); |
||||||
total_read += size_read; |
err = ZIP_ERRNO; |
||||||
|
} |
||||||
} while ((err == ZIP_OK) && (size_read>0)); |
|
||||||
|
if (size_read>0) |
||||||
if (fin) |
calculate_crc = crc32(calculate_crc,buf,size_read); |
||||||
fclose(fin); |
total_read += size_read; |
||||||
|
|
||||||
*result_crc=calculate_crc; |
} while ((err == ZIP_OK) && (size_read>0)); |
||||||
printf("file %s crc %x\n",filenameinzip,calculate_crc); |
|
||||||
return err; |
if (fin) |
||||||
} |
fclose(fin); |
||||||
|
|
||||||
int main(argc,argv) |
*result_crc=calculate_crc; |
||||||
int argc; |
printf("file %s crc %x\n",filenameinzip,calculate_crc); |
||||||
char *argv[]; |
return err; |
||||||
{ |
} |
||||||
int i; |
|
||||||
int opt_overwrite=0; |
int main(argc,argv) |
||||||
int opt_compress_level=Z_DEFAULT_COMPRESSION; |
int argc; |
||||||
int zipfilenamearg = 0; |
char *argv[]; |
||||||
char filename_try[MAXFILENAME+16]; |
{ |
||||||
int zipok; |
int i; |
||||||
int err=0; |
int opt_overwrite=0; |
||||||
int size_buf=0; |
int opt_compress_level=Z_DEFAULT_COMPRESSION; |
||||||
void* buf=NULL; |
int zipfilenamearg = 0; |
||||||
const char* password=NULL; |
char filename_try[MAXFILENAME+16]; |
||||||
|
int zipok; |
||||||
|
int err=0; |
||||||
do_banner(); |
int size_buf=0; |
||||||
if (argc==1) |
void* buf=NULL; |
||||||
{ |
const char* password=NULL; |
||||||
do_help(); |
|
||||||
return 0; |
|
||||||
} |
do_banner(); |
||||||
else |
if (argc==1) |
||||||
{ |
{ |
||||||
for (i=1;i<argc;i++) |
do_help(); |
||||||
{ |
return 0; |
||||||
if ((*argv[i])=='-') |
} |
||||||
{ |
else |
||||||
const char *p=argv[i]+1; |
{ |
||||||
|
for (i=1;i<argc;i++) |
||||||
while ((*p)!='\0') |
{ |
||||||
{ |
if ((*argv[i])=='-') |
||||||
char c=*(p++);; |
{ |
||||||
if ((c=='o') || (c=='O')) |
const char *p=argv[i]+1; |
||||||
opt_overwrite = 1; |
|
||||||
if ((c=='a') || (c=='A')) |
while ((*p)!='\0') |
||||||
opt_overwrite = 2; |
{ |
||||||
if ((c>='0') && (c<='9')) |
char c=*(p++);; |
||||||
opt_compress_level = c-'0'; |
if ((c=='o') || (c=='O')) |
||||||
|
opt_overwrite = 1; |
||||||
if (((c=='p') || (c=='P')) && (i+1<argc)) |
if ((c=='a') || (c=='A')) |
||||||
{ |
opt_overwrite = 2; |
||||||
password=argv[i+1]; |
if ((c>='0') && (c<='9')) |
||||||
i++; |
opt_compress_level = c-'0'; |
||||||
} |
|
||||||
} |
if (((c=='p') || (c=='P')) && (i+1<argc)) |
||||||
} |
{ |
||||||
else |
password=argv[i+1]; |
||||||
if (zipfilenamearg == 0) |
i++; |
||||||
zipfilenamearg = i ; |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
else |
||||||
size_buf = WRITEBUFFERSIZE; |
if (zipfilenamearg == 0) |
||||||
buf = (void*)malloc(size_buf); |
zipfilenamearg = i ; |
||||||
if (buf==NULL) |
} |
||||||
{ |
} |
||||||
printf("Error allocating memory\n"); |
|
||||||
return ZIP_INTERNALERROR; |
size_buf = WRITEBUFFERSIZE; |
||||||
} |
buf = (void*)malloc(size_buf); |
||||||
|
if (buf==NULL) |
||||||
if (zipfilenamearg==0) |
{ |
||||||
zipok=0; |
printf("Error allocating memory\n"); |
||||||
else |
return ZIP_INTERNALERROR; |
||||||
{ |
} |
||||||
int i,len; |
|
||||||
int dot_found=0; |
if (zipfilenamearg==0) |
||||||
|
zipok=0; |
||||||
zipok = 1 ; |
else |
||||||
strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1); |
{ |
||||||
/* strncpy doesnt append the trailing NULL, of the string is too long. */ |
int i,len; |
||||||
filename_try[ MAXFILENAME ] = '\0'; |
int dot_found=0; |
||||||
|
|
||||||
len=(int)strlen(filename_try); |
zipok = 1 ; |
||||||
for (i=0;i<len;i++) |
strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1); |
||||||
if (filename_try[i]=='.') |
/* strncpy doesnt append the trailing NULL, of the string is too long. */ |
||||||
dot_found=1; |
filename_try[ MAXFILENAME ] = '\0'; |
||||||
|
|
||||||
if (dot_found==0) |
len=(int)strlen(filename_try); |
||||||
strcat(filename_try,".zip"); |
for (i=0;i<len;i++) |
||||||
|
if (filename_try[i]=='.') |
||||||
if (opt_overwrite==2) |
dot_found=1; |
||||||
{ |
|
||||||
/* if the file don't exist, we not append file */ |
if (dot_found==0) |
||||||
if (check_exist_file(filename_try)==0) |
strcat(filename_try,".zip"); |
||||||
opt_overwrite=1; |
|
||||||
} |
if (opt_overwrite==2) |
||||||
else |
{ |
||||||
if (opt_overwrite==0) |
/* if the file don't exist, we not append file */ |
||||||
if (check_exist_file(filename_try)!=0) |
if (check_exist_file(filename_try)==0) |
||||||
{ |
opt_overwrite=1; |
||||||
char rep=0; |
} |
||||||
do |
else |
||||||
{ |
if (opt_overwrite==0) |
||||||
char answer[128]; |
if (check_exist_file(filename_try)!=0) |
||||||
printf("The file %s exist. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try); |
{ |
||||||
scanf("%1s",answer); |
char rep=0; |
||||||
rep = answer[0] ; |
do |
||||||
if ((rep>='a') && (rep<='z')) |
{ |
||||||
rep -= 0x20; |
char answer[128]; |
||||||
} |
printf("The file %s exist. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try); |
||||||
while ((rep!='Y') && (rep!='N') && (rep!='A')); |
scanf("%1s",answer); |
||||||
if (rep=='N') |
rep = answer[0] ; |
||||||
zipok = 0; |
if ((rep>='a') && (rep<='z')) |
||||||
if (rep=='A') |
rep -= 0x20; |
||||||
opt_overwrite = 2; |
} |
||||||
} |
while ((rep!='Y') && (rep!='N') && (rep!='A')); |
||||||
} |
if (rep=='N') |
||||||
|
zipok = 0; |
||||||
if (zipok==1) |
if (rep=='A') |
||||||
{ |
opt_overwrite = 2; |
||||||
zipFile zf; |
} |
||||||
int errclose; |
} |
||||||
#ifdef USEWIN32IOAPI |
|
||||||
zlib_filefunc_def ffunc; |
if (zipok==1) |
||||||
fill_win32_filefunc(&ffunc); |
{ |
||||||
zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); |
zipFile zf; |
||||||
#else |
int errclose; |
||||||
zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0); |
#ifdef USEWIN32IOAPI |
||||||
#endif |
zlib_filefunc_def ffunc; |
||||||
|
fill_win32_filefunc(&ffunc); |
||||||
if (zf == NULL) |
zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); |
||||||
{ |
#else |
||||||
printf("error opening %s\n",filename_try); |
zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0); |
||||||
err= ZIP_ERRNO; |
#endif |
||||||
} |
|
||||||
else |
if (zf == NULL) |
||||||
printf("creating %s\n",filename_try); |
{ |
||||||
|
printf("error opening %s\n",filename_try); |
||||||
for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++) |
err= ZIP_ERRNO; |
||||||
{ |
} |
||||||
if (((*(argv[i]))!='-') && ((*(argv[i]))!='/')) |
else |
||||||
{ |
printf("creating %s\n",filename_try); |
||||||
FILE * fin; |
|
||||||
int size_read; |
for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++) |
||||||
const char* filenameinzip = argv[i]; |
{ |
||||||
zip_fileinfo zi; |
if (((*(argv[i]))!='-') && ((*(argv[i]))!='/')) |
||||||
unsigned long crcFile=0; |
{ |
||||||
|
FILE * fin; |
||||||
zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = |
int size_read; |
||||||
zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; |
const char* filenameinzip = argv[i]; |
||||||
zi.dosDate = 0; |
zip_fileinfo zi; |
||||||
zi.internal_fa = 0; |
unsigned long crcFile=0; |
||||||
zi.external_fa = 0; |
|
||||||
filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); |
zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = |
||||||
|
zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; |
||||||
/*
|
zi.dosDate = 0; |
||||||
err = zipOpenNewFileInZip(zf,filenameinzip,&zi, |
zi.internal_fa = 0; |
||||||
NULL,0,NULL,0,NULL / * comment * /, |
zi.external_fa = 0; |
||||||
(opt_compress_level != 0) ? Z_DEFLATED : 0, |
filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); |
||||||
opt_compress_level); |
|
||||||
*/ |
/*
|
||||||
if ((password != NULL) && (err==ZIP_OK)) |
err = zipOpenNewFileInZip(zf,filenameinzip,&zi, |
||||||
err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); |
NULL,0,NULL,0,NULL / * comment * /, |
||||||
|
(opt_compress_level != 0) ? Z_DEFLATED : 0, |
||||||
err = zipOpenNewFileInZip3(zf,filenameinzip,&zi, |
opt_compress_level); |
||||||
NULL,0,NULL,0,NULL /* comment*/, |
*/ |
||||||
(opt_compress_level != 0) ? Z_DEFLATED : 0, |
if ((password != NULL) && (err==ZIP_OK)) |
||||||
opt_compress_level,0, |
err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); |
||||||
/* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ |
|
||||||
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, |
err = zipOpenNewFileInZip3(zf,filenameinzip,&zi, |
||||||
password,crcFile); |
NULL,0,NULL,0,NULL /* comment*/, |
||||||
|
(opt_compress_level != 0) ? Z_DEFLATED : 0, |
||||||
if (err != ZIP_OK) |
opt_compress_level,0, |
||||||
printf("error in opening %s in zipfile\n",filenameinzip); |
/* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ |
||||||
else |
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, |
||||||
{ |
password,crcFile); |
||||||
fin = fopen(filenameinzip,"rb"); |
|
||||||
if (fin==NULL) |
if (err != ZIP_OK) |
||||||
{ |
printf("error in opening %s in zipfile\n",filenameinzip); |
||||||
err=ZIP_ERRNO; |
else |
||||||
printf("error in opening %s for reading\n",filenameinzip); |
{ |
||||||
} |
fin = fopen(filenameinzip,"rb"); |
||||||
} |
if (fin==NULL) |
||||||
|
{ |
||||||
if (err == ZIP_OK) |
err=ZIP_ERRNO; |
||||||
do |
printf("error in opening %s for reading\n",filenameinzip); |
||||||
{ |
} |
||||||
err = ZIP_OK; |
} |
||||||
size_read = (int)fread(buf,1,size_buf,fin); |
|
||||||
if (size_read < size_buf) |
if (err == ZIP_OK) |
||||||
if (feof(fin)==0) |
do |
||||||
{ |
{ |
||||||
printf("error in reading %s\n",filenameinzip); |
err = ZIP_OK; |
||||||
err = ZIP_ERRNO; |
size_read = (int)fread(buf,1,size_buf,fin); |
||||||
} |
if (size_read < size_buf) |
||||||
|
if (feof(fin)==0) |
||||||
if (size_read>0) |
{ |
||||||
{ |
printf("error in reading %s\n",filenameinzip); |
||||||
err = zipWriteInFileInZip (zf,buf,size_read); |
err = ZIP_ERRNO; |
||||||
if (err<0) |
} |
||||||
{ |
|
||||||
printf("error in writing %s in the zipfile\n", |
if (size_read>0) |
||||||
filenameinzip); |
{ |
||||||
} |
err = zipWriteInFileInZip (zf,buf,size_read); |
||||||
|
if (err<0) |
||||||
} |
{ |
||||||
} while ((err == ZIP_OK) && (size_read>0)); |
printf("error in writing %s in the zipfile\n", |
||||||
|
filenameinzip); |
||||||
if (fin) |
} |
||||||
fclose(fin); |
|
||||||
|
} |
||||||
if (err<0) |
} while ((err == ZIP_OK) && (size_read>0)); |
||||||
err=ZIP_ERRNO; |
|
||||||
else |
if (fin) |
||||||
{ |
fclose(fin); |
||||||
err = zipCloseFileInZip(zf); |
|
||||||
if (err!=ZIP_OK) |
if (err<0) |
||||||
printf("error in closing %s in the zipfile\n", |
err=ZIP_ERRNO; |
||||||
filenameinzip); |
else |
||||||
} |
{ |
||||||
} |
err = zipCloseFileInZip(zf); |
||||||
} |
if (err!=ZIP_OK) |
||||||
errclose = zipClose(zf,NULL); |
printf("error in closing %s in the zipfile\n", |
||||||
if (errclose != ZIP_OK) |
filenameinzip); |
||||||
printf("error in closing %s\n",filename_try); |
} |
||||||
} |
} |
||||||
|
} |
||||||
free(buf); |
errclose = zipClose(zf,NULL); |
||||||
return 0; |
if (errclose != ZIP_OK) |
||||||
} |
printf("error in closing %s\n",filename_try); |
||||||
|
} |
||||||
|
|
||||||
|
free(buf); |
||||||
|
return 0; |
||||||
|
} |
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,342 +1,342 @@ |
|||||||
/* unzip.h -- IO for uncompress .zip files using zlib
|
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||||
Version 0.21, March 10th, 2003 |
Version 0.22, May 19th, 2003 |
||||||
|
|
||||||
Copyright (C) 1998-2003 Gilles Vollant |
Copyright (C) 1998-2003 Gilles Vollant |
||||||
|
|
||||||
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g |
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g |
||||||
WinZip, InfoZip tools and compatible. |
WinZip, InfoZip tools and compatible. |
||||||
Encryption and multi volume ZipFile (span) are not supported. |
Encryption and multi volume ZipFile (span) are not supported. |
||||||
Old compressions used by old PKZip 1.x are not supported |
Old compressions used by old PKZip 1.x are not supported |
||||||
|
|
||||||
|
|
||||||
I WAIT FEEDBACK at mail info@winimage.com |
I WAIT FEEDBACK at mail info@winimage.com |
||||||
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
||||||
|
|
||||||
Condition of use and distribution are the same than zlib : |
Condition of use and distribution are the same than zlib : |
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied |
This software is provided 'as-is', without any express or implied |
||||||
warranty. In no event will the authors be held liable for any damages |
warranty. In no event will the authors be held liable for any damages |
||||||
arising from the use of this software. |
arising from the use of this software. |
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose, |
Permission is granted to anyone to use this software for any purpose, |
||||||
including commercial applications, and to alter it and redistribute it |
including commercial applications, and to alter it and redistribute it |
||||||
freely, subject to the following restrictions: |
freely, subject to the following restrictions: |
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not |
1. The origin of this software must not be misrepresented; you must not |
||||||
claim that you wrote the original software. If you use this software |
claim that you wrote the original software. If you use this software |
||||||
in a product, an acknowledgment in the product documentation would be |
in a product, an acknowledgment in the product documentation would be |
||||||
appreciated but is not required. |
appreciated but is not required. |
||||||
2. Altered source versions must be plainly marked as such, and must not be |
2. Altered source versions must be plainly marked as such, and must not be |
||||||
misrepresented as being the original software. |
misrepresented as being the original software. |
||||||
3. This notice may not be removed or altered from any source distribution. |
3. This notice may not be removed or altered from any source distribution. |
||||||
|
|
||||||
|
|
||||||
*/ |
*/ |
||||||
|
|
||||||
/* for more info about .ZIP format, see
|
/* for more info about .ZIP format, see
|
||||||
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||||
http://www.info-zip.org/pub/infozip/doc/
|
http://www.info-zip.org/pub/infozip/doc/
|
||||||
PkWare has also a specification at : |
PkWare has also a specification at : |
||||||
ftp://ftp.pkware.com/probdesc.zip
|
ftp://ftp.pkware.com/probdesc.zip
|
||||||
*/ |
*/ |
||||||
|
|
||||||
#ifndef _unz_H |
#ifndef _unz_H |
||||||
#define _unz_H |
#define _unz_H |
||||||
|
|
||||||
#ifdef __cplusplus |
#ifdef __cplusplus |
||||||
extern "C" { |
extern "C" { |
||||||
#endif |
#endif |
||||||
|
|
||||||
#ifndef _ZLIB_H |
#ifndef _ZLIB_H |
||||||
#include "zlib.h" |
#include "zlib.h" |
||||||
#endif |
#endif |
||||||
|
|
||||||
#ifndef _ZLIBIOAPI_H |
#ifndef _ZLIBIOAPI_H |
||||||
#include "ioapi.h" |
#include "ioapi.h" |
||||||
#endif |
#endif |
||||||
|
|
||||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) |
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) |
||||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||||
from (void*) without cast */ |
from (void*) without cast */ |
||||||
typedef struct TagunzFile__ { int unused; } unzFile__; |
typedef struct TagunzFile__ { int unused; } unzFile__; |
||||||
typedef unzFile__ *unzFile; |
typedef unzFile__ *unzFile; |
||||||
#else |
#else |
||||||
typedef voidp unzFile; |
typedef voidp unzFile; |
||||||
#endif |
#endif |
||||||
|
|
||||||
|
|
||||||
#define UNZ_OK (0) |
#define UNZ_OK (0) |
||||||
#define UNZ_END_OF_LIST_OF_FILE (-100) |
#define UNZ_END_OF_LIST_OF_FILE (-100) |
||||||
#define UNZ_ERRNO (Z_ERRNO) |
#define UNZ_ERRNO (Z_ERRNO) |
||||||
#define UNZ_EOF (0) |
#define UNZ_EOF (0) |
||||||
#define UNZ_PARAMERROR (-102) |
#define UNZ_PARAMERROR (-102) |
||||||
#define UNZ_BADZIPFILE (-103) |
#define UNZ_BADZIPFILE (-103) |
||||||
#define UNZ_INTERNALERROR (-104) |
#define UNZ_INTERNALERROR (-104) |
||||||
#define UNZ_CRCERROR (-105) |
#define UNZ_CRCERROR (-105) |
||||||
|
|
||||||
/* tm_unz contain date/time info */ |
/* tm_unz contain date/time info */ |
||||||
typedef struct tm_unz_s |
typedef struct tm_unz_s |
||||||
{ |
{ |
||||||
uInt tm_sec; /* seconds after the minute - [0,59] */ |
uInt tm_sec; /* seconds after the minute - [0,59] */ |
||||||
uInt tm_min; /* minutes after the hour - [0,59] */ |
uInt tm_min; /* minutes after the hour - [0,59] */ |
||||||
uInt tm_hour; /* hours since midnight - [0,23] */ |
uInt tm_hour; /* hours since midnight - [0,23] */ |
||||||
uInt tm_mday; /* day of the month - [1,31] */ |
uInt tm_mday; /* day of the month - [1,31] */ |
||||||
uInt tm_mon; /* months since January - [0,11] */ |
uInt tm_mon; /* months since January - [0,11] */ |
||||||
uInt tm_year; /* years - [1980..2044] */ |
uInt tm_year; /* years - [1980..2044] */ |
||||||
} tm_unz; |
} tm_unz; |
||||||
|
|
||||||
/* unz_global_info structure contain global data about the ZIPfile
|
/* unz_global_info structure contain global data about the ZIPfile
|
||||||
These data comes from the end of central dir */ |
These data comes from the end of central dir */ |
||||||
typedef struct unz_global_info_s |
typedef struct unz_global_info_s |
||||||
{ |
{ |
||||||
uLong number_entry; /* total number of entries in
|
uLong number_entry; /* total number of entries in
|
||||||
the central dir on this disk */ |
the central dir on this disk */ |
||||||
uLong size_comment; /* size of the global comment of the zipfile */ |
uLong size_comment; /* size of the global comment of the zipfile */ |
||||||
} unz_global_info; |
} unz_global_info; |
||||||
|
|
||||||
|
|
||||||
/* unz_file_info contain information about a file in the zipfile */ |
/* unz_file_info contain information about a file in the zipfile */ |
||||||
typedef struct unz_file_info_s |
typedef struct unz_file_info_s |
||||||
{ |
{ |
||||||
uLong version; /* version made by 2 bytes */ |
uLong version; /* version made by 2 bytes */ |
||||||
uLong version_needed; /* version needed to extract 2 bytes */ |
uLong version_needed; /* version needed to extract 2 bytes */ |
||||||
uLong flag; /* general purpose bit flag 2 bytes */ |
uLong flag; /* general purpose bit flag 2 bytes */ |
||||||
uLong compression_method; /* compression method 2 bytes */ |
uLong compression_method; /* compression method 2 bytes */ |
||||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ |
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ |
||||||
uLong crc; /* crc-32 4 bytes */ |
uLong crc; /* crc-32 4 bytes */ |
||||||
uLong compressed_size; /* compressed size 4 bytes */ |
uLong compressed_size; /* compressed size 4 bytes */ |
||||||
uLong uncompressed_size; /* uncompressed size 4 bytes */ |
uLong uncompressed_size; /* uncompressed size 4 bytes */ |
||||||
uLong size_filename; /* filename length 2 bytes */ |
uLong size_filename; /* filename length 2 bytes */ |
||||||
uLong size_file_extra; /* extra field length 2 bytes */ |
uLong size_file_extra; /* extra field length 2 bytes */ |
||||||
uLong size_file_comment; /* file comment length 2 bytes */ |
uLong size_file_comment; /* file comment length 2 bytes */ |
||||||
|
|
||||||
uLong disk_num_start; /* disk number start 2 bytes */ |
uLong disk_num_start; /* disk number start 2 bytes */ |
||||||
uLong internal_fa; /* internal file attributes 2 bytes */ |
uLong internal_fa; /* internal file attributes 2 bytes */ |
||||||
uLong external_fa; /* external file attributes 4 bytes */ |
uLong external_fa; /* external file attributes 4 bytes */ |
||||||
|
|
||||||
tm_unz tmu_date; |
tm_unz tmu_date; |
||||||
} unz_file_info; |
} unz_file_info; |
||||||
|
|
||||||
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, |
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, |
||||||
const char* fileName2, |
const char* fileName2, |
||||||
int iCaseSensitivity)); |
int iCaseSensitivity)); |
||||||
/*
|
/*
|
||||||
Compare two filename (fileName1,fileName2). |
Compare two filename (fileName1,fileName2). |
||||||
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) |
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) |
||||||
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi |
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi |
||||||
or strcasecmp) |
or strcasecmp) |
||||||
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system |
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system |
||||||
(like 1 on Unix, 2 on Windows) |
(like 1 on Unix, 2 on Windows) |
||||||
*/ |
*/ |
||||||
|
|
||||||
|
|
||||||
extern unzFile ZEXPORT unzOpen OF((const char *path)); |
extern unzFile ZEXPORT unzOpen OF((const char *path)); |
||||||
/*
|
/*
|
||||||
Open a Zip file. path contain the full pathname (by example, |
Open a Zip file. path contain the full pathname (by example, |
||||||
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer |
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer |
||||||
"zlib/zlib113.zip". |
"zlib/zlib113.zip". |
||||||
If the zipfile cannot be opened (file don't exist or in not valid), the |
If the zipfile cannot be opened (file don't exist or in not valid), the |
||||||
return value is NULL. |
return value is NULL. |
||||||
Else, the return value is a unzFile Handle, usable with other function |
Else, the return value is a unzFile Handle, usable with other function |
||||||
of this unzip package. |
of this unzip package. |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern unzFile ZEXPORT unzOpen2 OF((const char *path, |
extern unzFile ZEXPORT unzOpen2 OF((const char *path, |
||||||
zlib_filefunc_def* pzlib_filefunc_def)); |
zlib_filefunc_def* pzlib_filefunc_def)); |
||||||
/*
|
/*
|
||||||
Open a Zip file, like unzOpen, but provide a set of file low level API |
Open a Zip file, like unzOpen, but provide a set of file low level API |
||||||
for read/write the zip file (see ioapi.h) |
for read/write the zip file (see ioapi.h) |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT unzClose OF((unzFile file)); |
extern int ZEXPORT unzClose OF((unzFile file)); |
||||||
/*
|
/*
|
||||||
Close a ZipFile opened with unzipOpen. |
Close a ZipFile opened with unzipOpen. |
||||||
If there is files inside the .Zip opened with unzOpenCurrentFile (see later), |
If there is files inside the .Zip opened with unzOpenCurrentFile (see later), |
||||||
these files MUST be closed with unzipCloseCurrentFile before call unzipClose. |
these files MUST be closed with unzipCloseCurrentFile before call unzipClose. |
||||||
return UNZ_OK if there is no problem. */ |
return UNZ_OK if there is no problem. */ |
||||||
|
|
||||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, |
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, |
||||||
unz_global_info *pglobal_info)); |
unz_global_info *pglobal_info)); |
||||||
/*
|
/*
|
||||||
Write info about the ZipFile in the *pglobal_info structure. |
Write info about the ZipFile in the *pglobal_info structure. |
||||||
No preparation of the structure is needed |
No preparation of the structure is needed |
||||||
return UNZ_OK if there is no problem. */ |
return UNZ_OK if there is no problem. */ |
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file, |
extern int ZEXPORT unzGetGlobalComment OF((unzFile file, |
||||||
char *szComment, |
char *szComment, |
||||||
uLong uSizeBuf)); |
uLong uSizeBuf)); |
||||||
/*
|
/*
|
||||||
Get the global comment string of the ZipFile, in the szComment buffer. |
Get the global comment string of the ZipFile, in the szComment buffer. |
||||||
uSizeBuf is the size of the szComment buffer. |
uSizeBuf is the size of the szComment buffer. |
||||||
return the number of byte copied or an error code <0 |
return the number of byte copied or an error code <0 |
||||||
*/ |
*/ |
||||||
|
|
||||||
|
|
||||||
/***************************************************************************/ |
/***************************************************************************/ |
||||||
/* Unzip package allow you browse the directory of the zipfile */ |
/* Unzip package allow you browse the directory of the zipfile */ |
||||||
|
|
||||||
extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); |
extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); |
||||||
/*
|
/*
|
||||||
Set the current file of the zipfile to the first file. |
Set the current file of the zipfile to the first file. |
||||||
return UNZ_OK if there is no problem |
return UNZ_OK if there is no problem |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT unzGoToNextFile OF((unzFile file)); |
extern int ZEXPORT unzGoToNextFile OF((unzFile file)); |
||||||
/*
|
/*
|
||||||
Set the current file of the zipfile to the next file. |
Set the current file of the zipfile to the next file. |
||||||
return UNZ_OK if there is no problem |
return UNZ_OK if there is no problem |
||||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. |
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT unzLocateFile OF((unzFile file, |
extern int ZEXPORT unzLocateFile OF((unzFile file, |
||||||
const char *szFileName, |
const char *szFileName, |
||||||
int iCaseSensitivity)); |
int iCaseSensitivity)); |
||||||
/*
|
/*
|
||||||
Try locate the file szFileName in the zipfile. |
Try locate the file szFileName in the zipfile. |
||||||
For the iCaseSensitivity signification, see unzStringFileNameCompare |
For the iCaseSensitivity signification, see unzStringFileNameCompare |
||||||
|
|
||||||
return value : |
return value : |
||||||
UNZ_OK if the file is found. It becomes the current file. |
UNZ_OK if the file is found. It becomes the current file. |
||||||
UNZ_END_OF_LIST_OF_FILE if the file is not found |
UNZ_END_OF_LIST_OF_FILE if the file is not found |
||||||
*/ |
*/ |
||||||
|
|
||||||
|
|
||||||
/* ****************************************** */ |
/* ****************************************** */ |
||||||
/* Ryan supplied functions */ |
/* Ryan supplied functions */ |
||||||
/* unz_file_info contain information about a file in the zipfile */ |
/* unz_file_info contain information about a file in the zipfile */ |
||||||
typedef struct unz_file_pos_s |
typedef struct unz_file_pos_s |
||||||
{ |
{ |
||||||
uLong pos_in_zip_directory; /* offset in zip file directory */ |
uLong pos_in_zip_directory; /* offset in zip file directory */ |
||||||
uLong num_of_file; /* # of file */ |
uLong num_of_file; /* # of file */ |
||||||
} unz_file_pos; |
} unz_file_pos; |
||||||
|
|
||||||
extern int ZEXPORT unzGetFilePos( |
extern int ZEXPORT unzGetFilePos( |
||||||
unzFile file, |
unzFile file, |
||||||
unz_file_pos* file_pos); |
unz_file_pos* file_pos); |
||||||
|
|
||||||
extern int ZEXPORT unzGoToFilePos( |
extern int ZEXPORT unzGoToFilePos( |
||||||
unzFile file, |
unzFile file, |
||||||
unz_file_pos* file_pos); |
unz_file_pos* file_pos); |
||||||
|
|
||||||
/* ****************************************** */ |
/* ****************************************** */ |
||||||
|
|
||||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, |
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, |
||||||
unz_file_info *pfile_info, |
unz_file_info *pfile_info, |
||||||
char *szFileName, |
char *szFileName, |
||||||
uLong fileNameBufferSize, |
uLong fileNameBufferSize, |
||||||
void *extraField, |
void *extraField, |
||||||
uLong extraFieldBufferSize, |
uLong extraFieldBufferSize, |
||||||
char *szComment, |
char *szComment, |
||||||
uLong commentBufferSize)); |
uLong commentBufferSize)); |
||||||
/*
|
/*
|
||||||
Get Info about the current file |
Get Info about the current file |
||||||
if pfile_info!=NULL, the *pfile_info structure will contain somes info about |
if pfile_info!=NULL, the *pfile_info structure will contain somes info about |
||||||
the current file |
the current file |
||||||
if szFileName!=NULL, the filemane string will be copied in szFileName |
if szFileName!=NULL, the filemane string will be copied in szFileName |
||||||
(fileNameBufferSize is the size of the buffer) |
(fileNameBufferSize is the size of the buffer) |
||||||
if extraField!=NULL, the extra field information will be copied in extraField |
if extraField!=NULL, the extra field information will be copied in extraField |
||||||
(extraFieldBufferSize is the size of the buffer). |
(extraFieldBufferSize is the size of the buffer). |
||||||
This is the Central-header version of the extra field |
This is the Central-header version of the extra field |
||||||
if szComment!=NULL, the comment string of the file will be copied in szComment |
if szComment!=NULL, the comment string of the file will be copied in szComment |
||||||
(commentBufferSize is the size of the buffer) |
(commentBufferSize is the size of the buffer) |
||||||
*/ |
*/ |
||||||
|
|
||||||
/***************************************************************************/ |
/***************************************************************************/ |
||||||
/* for reading the content of the current zipfile, you can open it, read data
|
/* for reading the content of the current zipfile, you can open it, read data
|
||||||
from it, and close it (you can close it before reading all the file) |
from it, and close it (you can close it before reading all the file) |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); |
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); |
||||||
/*
|
/*
|
||||||
Open for reading data the current file in the zipfile. |
Open for reading data the current file in the zipfile. |
||||||
If there is no error, the return value is UNZ_OK. |
If there is no error, the return value is UNZ_OK. |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, |
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, |
||||||
const char* password)); |
const char* password)); |
||||||
/*
|
/*
|
||||||
Open for reading data the current file in the zipfile. |
Open for reading data the current file in the zipfile. |
||||||
password is a crypting password |
password is a crypting password |
||||||
If there is no error, the return value is UNZ_OK. |
If there is no error, the return value is UNZ_OK. |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, |
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, |
||||||
int* method, |
int* method, |
||||||
int* level, |
int* level, |
||||||
int raw)); |
int raw)); |
||||||
/*
|
/*
|
||||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) |
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) |
||||||
if raw==1 |
if raw==1 |
||||||
*method will receive method of compression, *level will receive level of |
*method will receive method of compression, *level will receive level of |
||||||
compression |
compression |
||||||
note : you can set level parameter as NULL (if you did not want known level, |
note : you can set level parameter as NULL (if you did not want known level, |
||||||
but you CANNOT set method parameter as NULL |
but you CANNOT set method parameter as NULL |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, |
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, |
||||||
int* method, |
int* method, |
||||||
int* level, |
int* level, |
||||||
int raw, |
int raw, |
||||||
const char* password)); |
const char* password)); |
||||||
/*
|
/*
|
||||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) |
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) |
||||||
if raw==1 |
if raw==1 |
||||||
*method will receive method of compression, *level will receive level of |
*method will receive method of compression, *level will receive level of |
||||||
compression |
compression |
||||||
note : you can set level parameter as NULL (if you did not want known level, |
note : you can set level parameter as NULL (if you did not want known level, |
||||||
but you CANNOT set method parameter as NULL |
but you CANNOT set method parameter as NULL |
||||||
*/ |
*/ |
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); |
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); |
||||||
/*
|
/*
|
||||||
Close the file in zip opened with unzOpenCurrentFile |
Close the file in zip opened with unzOpenCurrentFile |
||||||
Return UNZ_CRCERROR if all the file was read but the CRC is not good |
Return UNZ_CRCERROR if all the file was read but the CRC is not good |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file, |
extern int ZEXPORT unzReadCurrentFile OF((unzFile file, |
||||||
voidp buf, |
voidp buf, |
||||||
unsigned len)); |
unsigned len)); |
||||||
/*
|
/*
|
||||||
Read bytes from the current file (opened by unzOpenCurrentFile) |
Read bytes from the current file (opened by unzOpenCurrentFile) |
||||||
buf contain buffer where data must be copied |
buf contain buffer where data must be copied |
||||||
len the size of buf. |
len the size of buf. |
||||||
|
|
||||||
return the number of byte copied if somes bytes are copied |
return the number of byte copied if somes bytes are copied |
||||||
return 0 if the end of file was reached |
return 0 if the end of file was reached |
||||||
return <0 with error code if there is an error |
return <0 with error code if there is an error |
||||||
(UNZ_ERRNO for IO error, or zLib error for uncompress error) |
(UNZ_ERRNO for IO error, or zLib error for uncompress error) |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern z_off_t ZEXPORT unztell OF((unzFile file)); |
extern z_off_t ZEXPORT unztell OF((unzFile file)); |
||||||
/*
|
/*
|
||||||
Give the current position in uncompressed data |
Give the current position in uncompressed data |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT unzeof OF((unzFile file)); |
extern int ZEXPORT unzeof OF((unzFile file)); |
||||||
/*
|
/*
|
||||||
return 1 if the end of file was reached, 0 elsewhere |
return 1 if the end of file was reached, 0 elsewhere |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, |
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, |
||||||
voidp buf, |
voidp buf, |
||||||
unsigned len)); |
unsigned len)); |
||||||
/*
|
/*
|
||||||
Read extra field from the current file (opened by unzOpenCurrentFile) |
Read extra field from the current file (opened by unzOpenCurrentFile) |
||||||
This is the local-header version of the extra field (sometimes, there is |
This is the local-header version of the extra field (sometimes, there is |
||||||
more info in the local-header version than in the central-header) |
more info in the local-header version than in the central-header) |
||||||
|
|
||||||
if buf==NULL, it return the size of the local extra field |
if buf==NULL, it return the size of the local extra field |
||||||
|
|
||||||
if buf!=NULL, len is the size of the buffer, the extra header is copied in |
if buf!=NULL, len is the size of the buffer, the extra header is copied in |
||||||
buf. |
buf. |
||||||
the return value is the number of bytes copied in buf, or (if <0) |
the return value is the number of bytes copied in buf, or (if <0) |
||||||
the error code |
the error code |
||||||
*/ |
*/ |
||||||
|
|
||||||
#ifdef __cplusplus |
#ifdef __cplusplus |
||||||
} |
} |
||||||
#endif |
#endif |
||||||
|
|
||||||
#endif /* _unz_H */ |
#endif /* _unz_H */ |
||||||
|
@ -0,0 +1,326 @@ |
|||||||
|
/* zconf.h -- configuration of the zlib compression library
|
||||||
|
* Copyright (C) 1995-2003 Jean-loup Gailly. |
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h |
||||||
|
*/ |
||||||
|
|
||||||
|
/* @(#) $Id$ */ |
||||||
|
|
||||||
|
#ifndef _ZCONF_H |
||||||
|
#define _ZCONF_H |
||||||
|
|
||||||
|
/*
|
||||||
|
* If you *really* need a unique prefix for all types and library functions, |
||||||
|
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. |
||||||
|
*/ |
||||||
|
#ifdef Z_PREFIX |
||||||
|
# define deflateInit_ z_deflateInit_ |
||||||
|
# define deflate z_deflate |
||||||
|
# define deflateEnd z_deflateEnd |
||||||
|
# define inflateInit_ z_inflateInit_ |
||||||
|
# define inflate z_inflate |
||||||
|
# define inflateEnd z_inflateEnd |
||||||
|
# define deflateInit2_ z_deflateInit2_ |
||||||
|
# define deflateSetDictionary z_deflateSetDictionary |
||||||
|
# define deflateCopy z_deflateCopy |
||||||
|
# define deflateReset z_deflateReset |
||||||
|
# define deflateParams z_deflateParams |
||||||
|
# define deflateBound z_deflateBound |
||||||
|
# define inflateInit2_ z_inflateInit2_ |
||||||
|
# define inflateSetDictionary z_inflateSetDictionary |
||||||
|
# define inflateSync z_inflateSync |
||||||
|
# define inflateSyncPoint z_inflateSyncPoint |
||||||
|
# define inflateCopy z_inflateCopy |
||||||
|
# define inflateReset z_inflateReset |
||||||
|
# define compress z_compress |
||||||
|
# define compress2 z_compress2 |
||||||
|
# define compressBound z_compressBound |
||||||
|
# define uncompress z_uncompress |
||||||
|
# define adler32 z_adler32 |
||||||
|
# define crc32 z_crc32 |
||||||
|
# define get_crc_table z_get_crc_table |
||||||
|
|
||||||
|
# define Byte z_Byte |
||||||
|
# define uInt z_uInt |
||||||
|
# define uLong z_uLong |
||||||
|
# define Bytef z_Bytef |
||||||
|
# define charf z_charf |
||||||
|
# define intf z_intf |
||||||
|
# define uIntf z_uIntf |
||||||
|
# define uLongf z_uLongf |
||||||
|
# define voidpf z_voidpf |
||||||
|
# define voidp z_voidp |
||||||
|
#endif |
||||||
|
|
||||||
|
|
||||||
|
#ifdef __STDC_VERSION__ |
||||||
|
# ifndef STDC |
||||||
|
# define STDC |
||||||
|
# endif |
||||||
|
# if __STDC_VERSION__ >= 199901L |
||||||
|
# ifndef STDC99 |
||||||
|
# define STDC99 |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
|
||||||
|
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) |
||||||
|
# define WIN32 |
||||||
|
#endif |
||||||
|
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386) |
||||||
|
# ifndef __32BIT__ |
||||||
|
# define __32BIT__ |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
#if defined(__MSDOS__) && !defined(MSDOS) |
||||||
|
# define MSDOS |
||||||
|
#endif |
||||||
|
|
||||||
|
/*
|
||||||
|
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more |
||||||
|
* than 64k bytes at a time (needed on systems with 16-bit int). |
||||||
|
*/ |
||||||
|
#if defined(MSDOS) && !defined(__32BIT__) |
||||||
|
# define MAXSEG_64K |
||||||
|
#endif |
||||||
|
#ifdef MSDOS |
||||||
|
# define UNALIGNED_OK |
||||||
|
#endif |
||||||
|
|
||||||
|
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC) |
||||||
|
# define STDC |
||||||
|
#endif |
||||||
|
#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__) |
||||||
|
# ifndef STDC |
||||||
|
# define STDC |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
#if defined __HOS_AIX__ |
||||||
|
# ifndef STDC |
||||||
|
# define STDC |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifndef STDC |
||||||
|
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ |
||||||
|
# define const /* note: need a more gentle solution here */ |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Some Mac compilers merge all .h files incorrectly: */ |
||||||
|
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__) |
||||||
|
# define NO_DUMMY_DECL |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Old Borland C incorrectly complains about missing returns: */ |
||||||
|
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x460) |
||||||
|
# define NEED_DUMMY_RETURN |
||||||
|
#endif |
||||||
|
#if defined(__TURBOC__) && !defined(__BORLANDC__) |
||||||
|
# define NEED_DUMMY_RETURN |
||||||
|
#endif |
||||||
|
|
||||||
|
|
||||||
|
/* Maximum value for memLevel in deflateInit2 */ |
||||||
|
#ifndef MAX_MEM_LEVEL |
||||||
|
# ifdef MAXSEG_64K |
||||||
|
# define MAX_MEM_LEVEL 8 |
||||||
|
# else |
||||||
|
# define MAX_MEM_LEVEL 9 |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||||
|
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files |
||||||
|
* created by gzip. (Files created by minigzip can still be extracted by |
||||||
|
* gzip.) |
||||||
|
*/ |
||||||
|
#ifndef MAX_WBITS |
||||||
|
# define MAX_WBITS 15 /* 32K LZ77 window */ |
||||||
|
#endif |
||||||
|
|
||||||
|
/* The memory requirements for deflate are (in bytes):
|
||||||
|
(1 << (windowBits+2)) + (1 << (memLevel+9)) |
||||||
|
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) |
||||||
|
plus a few kilobytes for small objects. For example, if you want to reduce |
||||||
|
the default memory requirements from 256K to 128K, compile with |
||||||
|
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" |
||||||
|
Of course this will generally degrade compression (there's no free lunch). |
||||||
|
|
||||||
|
The memory requirements for inflate are (in bytes) 1 << windowBits |
||||||
|
that is, 32K for windowBits=15 (default value) plus a few kilobytes |
||||||
|
for small objects. |
||||||
|
*/ |
||||||
|
|
||||||
|
/* Type declarations */ |
||||||
|
|
||||||
|
#ifndef OF /* function prototypes */ |
||||||
|
# ifdef STDC |
||||||
|
# define OF(args) args |
||||||
|
# else |
||||||
|
# define OF(args) () |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
/*
|
||||||
|
* Microsoft Visual Studio define _vsnprintf but not vsnprintf |
||||||
|
*/ |
||||||
|
#if !defined(STDC99) && !(defined(__TURBOC__) && __TURBOC__ >= 0x550) && !defined(VSNPRINTF_DEFINED) |
||||||
|
# ifdef MSDOS |
||||||
|
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
||||||
|
but for now we just assume it doesn't. */ |
||||||
|
# define NO_vsnprintf |
||||||
|
# endif |
||||||
|
# ifdef WIN32 |
||||||
|
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ |
||||||
|
# if !defined(vsnprintf) && !defined(__TURBOC__) |
||||||
|
# define vsnprintf _vsnprintf |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
# ifdef __TURBOC__ |
||||||
|
# define NO_vsnprintf |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||||
|
* model programming (small or medium model with some far allocations). |
||||||
|
* This was tested only with MSC; for other MSDOS compilers you may have |
||||||
|
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model, |
||||||
|
* just define FAR to be empty. |
||||||
|
*/ |
||||||
|
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__) |
||||||
|
/* MSC small or medium model */ |
||||||
|
# define SMALL_MEDIUM |
||||||
|
# ifdef _MSC_VER |
||||||
|
# define FAR _far |
||||||
|
# else |
||||||
|
# define FAR far |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__)) |
||||||
|
# ifndef __32BIT__ |
||||||
|
# define SMALL_MEDIUM |
||||||
|
# define FAR _far |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
#if defined(WIN32) && (!defined(ZLIB_WIN32_NODLL)) && (!defined(ZLIB_DLL)) |
||||||
|
# define ZLIB_DLL |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Compile with -DZLIB_DLL for Windows DLL support */ |
||||||
|
#if defined(ZLIB_DLL) |
||||||
|
# if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32) |
||||||
|
# ifndef WINAPIV |
||||||
|
# ifdef FAR |
||||||
|
# undef FAR |
||||||
|
# endif |
||||||
|
# include <windows.h> |
||||||
|
# endif |
||||||
|
# ifdef WIN32 |
||||||
|
# define ZEXPORT WINAPI |
||||||
|
# define ZEXPORTVA WINAPIV |
||||||
|
# else |
||||||
|
# define ZEXPORT WINAPI _export |
||||||
|
# define ZEXPORTVA FAR _cdecl _export |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
# if defined (__BORLANDC__) |
||||||
|
# if (__BORLANDC__ >= 0x0500) && defined (WIN32) |
||||||
|
# include <windows.h> |
||||||
|
# define ZEXPORT __declspec(dllexport) WINAPI |
||||||
|
# define ZEXPORTVA __declspec(dllexport) WINAPIV |
||||||
|
# else |
||||||
|
# if defined (_Windows) && defined (__DLL__) |
||||||
|
# define ZEXPORT _export |
||||||
|
# define ZEXPORTVA _export |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
#if defined (__BEOS__) |
||||||
|
# if defined (ZLIB_DLL) |
||||||
|
# define ZEXTERN extern __declspec(dllexport) |
||||||
|
# else |
||||||
|
# define ZEXTERN extern __declspec(dllimport) |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifndef ZEXPORT |
||||||
|
# define ZEXPORT |
||||||
|
#endif |
||||||
|
#ifndef ZEXPORTVA |
||||||
|
# define ZEXPORTVA |
||||||
|
#endif |
||||||
|
#ifndef ZEXTERN |
||||||
|
# define ZEXTERN extern |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifndef FAR |
||||||
|
# define FAR |
||||||
|
#endif |
||||||
|
|
||||||
|
#if !defined(__MACTYPES__) |
||||||
|
typedef unsigned char Byte; /* 8 bits */ |
||||||
|
#endif |
||||||
|
typedef unsigned int uInt; /* 16 bits or more */ |
||||||
|
typedef unsigned long uLong; /* 32 bits or more */ |
||||||
|
|
||||||
|
#ifdef SMALL_MEDIUM |
||||||
|
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ |
||||||
|
# define Bytef Byte FAR |
||||||
|
#else |
||||||
|
typedef Byte FAR Bytef; |
||||||
|
#endif |
||||||
|
typedef char FAR charf; |
||||||
|
typedef int FAR intf; |
||||||
|
typedef uInt FAR uIntf; |
||||||
|
typedef uLong FAR uLongf; |
||||||
|
|
||||||
|
#ifdef STDC |
||||||
|
typedef void const *voidpc; |
||||||
|
typedef void FAR *voidpf; |
||||||
|
typedef void *voidp; |
||||||
|
#else |
||||||
|
typedef Byte const *voidpc; |
||||||
|
typedef Byte FAR *voidpf; |
||||||
|
typedef Byte *voidp; |
||||||
|
#endif |
||||||
|
|
||||||
|
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
|
||||||
|
# include <sys/types.h> /* for off_t */ |
||||||
|
# include <unistd.h> /* for SEEK_* and off_t */ |
||||||
|
# ifdef VMS |
||||||
|
# include <unixio.h> /* for off_t */ |
||||||
|
# endif |
||||||
|
# define z_off_t off_t |
||||||
|
#endif |
||||||
|
#ifndef SEEK_SET |
||||||
|
# define SEEK_SET 0 /* Seek from beginning of file. */ |
||||||
|
# define SEEK_CUR 1 /* Seek from current position. */ |
||||||
|
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ |
||||||
|
#endif |
||||||
|
#ifndef z_off_t |
||||||
|
# define z_off_t long |
||||||
|
#endif |
||||||
|
|
||||||
|
/* MVS linker does not support external names larger than 8 bytes */ |
||||||
|
#if defined(__MVS__) |
||||||
|
# pragma map(deflateInit_,"DEIN") |
||||||
|
# pragma map(deflateInit2_,"DEIN2") |
||||||
|
# pragma map(deflateEnd,"DEEND") |
||||||
|
# pragma map(deflateBound,"DEBND") |
||||||
|
# pragma map(inflateInit_,"ININ") |
||||||
|
# pragma map(inflateInit2_,"ININ2") |
||||||
|
# pragma map(inflateEnd,"INEND") |
||||||
|
# pragma map(inflateSync,"INSY") |
||||||
|
# pragma map(inflateSetDictionary,"INSEDI") |
||||||
|
# pragma map(compressBound,"CMBND") |
||||||
|
# pragma map(inflate_table,"INTABL") |
||||||
|
# pragma map(inflate_fast,"INFA") |
||||||
|
# pragma map(inflate_copyright,"INCOPY") |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif /* _ZCONF_H */ |
File diff suppressed because it is too large
Load Diff
@ -1,235 +1,235 @@ |
|||||||
/* zip.h -- IO for compress .zip files using zlib
|
/* zip.h -- IO for compress .zip files using zlib
|
||||||
Version 0.21, March 10th, 2003 |
Version 0.22, May 19th, 2003 |
||||||
|
|
||||||
Copyright (C) 1998-2003 Gilles Vollant |
Copyright (C) 1998-2003 Gilles Vollant |
||||||
|
|
||||||
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g |
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g |
||||||
WinZip, InfoZip tools and compatible. |
WinZip, InfoZip tools and compatible. |
||||||
Encryption and multi volume ZipFile (span) are not supported. |
Encryption and multi volume ZipFile (span) are not supported. |
||||||
Old compressions used by old PKZip 1.x are not supported |
Old compressions used by old PKZip 1.x are not supported |
||||||
|
|
||||||
For uncompress .zip file, look at unzip.h |
For uncompress .zip file, look at unzip.h |
||||||
|
|
||||||
|
|
||||||
I WAIT FEEDBACK at mail info@winimage.com |
I WAIT FEEDBACK at mail info@winimage.com |
||||||
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
|
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
|
||||||
|
|
||||||
Condition of use and distribution are the same than zlib : |
Condition of use and distribution are the same than zlib : |
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied |
This software is provided 'as-is', without any express or implied |
||||||
warranty. In no event will the authors be held liable for any damages |
warranty. In no event will the authors be held liable for any damages |
||||||
arising from the use of this software. |
arising from the use of this software. |
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose, |
Permission is granted to anyone to use this software for any purpose, |
||||||
including commercial applications, and to alter it and redistribute it |
including commercial applications, and to alter it and redistribute it |
||||||
freely, subject to the following restrictions: |
freely, subject to the following restrictions: |
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not |
1. The origin of this software must not be misrepresented; you must not |
||||||
claim that you wrote the original software. If you use this software |
claim that you wrote the original software. If you use this software |
||||||
in a product, an acknowledgment in the product documentation would be |
in a product, an acknowledgment in the product documentation would be |
||||||
appreciated but is not required. |
appreciated but is not required. |
||||||
2. Altered source versions must be plainly marked as such, and must not be |
2. Altered source versions must be plainly marked as such, and must not be |
||||||
misrepresented as being the original software. |
misrepresented as being the original software. |
||||||
3. This notice may not be removed or altered from any source distribution. |
3. This notice may not be removed or altered from any source distribution. |
||||||
|
|
||||||
|
|
||||||
*/ |
*/ |
||||||
|
|
||||||
/* for more info about .ZIP format, see
|
/* for more info about .ZIP format, see
|
||||||
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||||
http://www.info-zip.org/pub/infozip/doc/
|
http://www.info-zip.org/pub/infozip/doc/
|
||||||
PkWare has also a specification at : |
PkWare has also a specification at : |
||||||
ftp://ftp.pkware.com/probdesc.zip
|
ftp://ftp.pkware.com/probdesc.zip
|
||||||
*/ |
*/ |
||||||
|
|
||||||
#ifndef _zip_H |
#ifndef _zip_H |
||||||
#define _zip_H |
#define _zip_H |
||||||
|
|
||||||
#ifdef __cplusplus |
#ifdef __cplusplus |
||||||
extern "C" { |
extern "C" { |
||||||
#endif |
#endif |
||||||
|
|
||||||
#ifndef _ZLIB_H |
#ifndef _ZLIB_H |
||||||
#include "zlib.h" |
#include "zlib.h" |
||||||
#endif |
#endif |
||||||
|
|
||||||
#ifndef _ZLIBIOAPI_H |
#ifndef _ZLIBIOAPI_H |
||||||
#include "ioapi.h" |
#include "ioapi.h" |
||||||
#endif |
#endif |
||||||
|
|
||||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) |
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) |
||||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||||
from (void*) without cast */ |
from (void*) without cast */ |
||||||
typedef struct TagzipFile__ { int unused; } zipFile__; |
typedef struct TagzipFile__ { int unused; } zipFile__; |
||||||
typedef zipFile__ *zipFile; |
typedef zipFile__ *zipFile; |
||||||
#else |
#else |
||||||
typedef voidp zipFile; |
typedef voidp zipFile; |
||||||
#endif |
#endif |
||||||
|
|
||||||
#define ZIP_OK (0) |
#define ZIP_OK (0) |
||||||
#define ZIP_EOF (0) |
#define ZIP_EOF (0) |
||||||
#define ZIP_ERRNO (Z_ERRNO) |
#define ZIP_ERRNO (Z_ERRNO) |
||||||
#define ZIP_PARAMERROR (-102) |
#define ZIP_PARAMERROR (-102) |
||||||
#define ZIP_BADZIPFILE (-103) |
#define ZIP_BADZIPFILE (-103) |
||||||
#define ZIP_INTERNALERROR (-104) |
#define ZIP_INTERNALERROR (-104) |
||||||
|
|
||||||
#ifndef DEF_MEM_LEVEL |
#ifndef DEF_MEM_LEVEL |
||||||
# if MAX_MEM_LEVEL >= 8 |
# if MAX_MEM_LEVEL >= 8 |
||||||
# define DEF_MEM_LEVEL 8 |
# define DEF_MEM_LEVEL 8 |
||||||
# else |
# else |
||||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL |
# define DEF_MEM_LEVEL MAX_MEM_LEVEL |
||||||
# endif |
# endif |
||||||
#endif |
#endif |
||||||
/* default memLevel */ |
/* default memLevel */ |
||||||
|
|
||||||
/* tm_zip contain date/time info */ |
/* tm_zip contain date/time info */ |
||||||
typedef struct tm_zip_s |
typedef struct tm_zip_s |
||||||
{ |
{ |
||||||
uInt tm_sec; /* seconds after the minute - [0,59] */ |
uInt tm_sec; /* seconds after the minute - [0,59] */ |
||||||
uInt tm_min; /* minutes after the hour - [0,59] */ |
uInt tm_min; /* minutes after the hour - [0,59] */ |
||||||
uInt tm_hour; /* hours since midnight - [0,23] */ |
uInt tm_hour; /* hours since midnight - [0,23] */ |
||||||
uInt tm_mday; /* day of the month - [1,31] */ |
uInt tm_mday; /* day of the month - [1,31] */ |
||||||
uInt tm_mon; /* months since January - [0,11] */ |
uInt tm_mon; /* months since January - [0,11] */ |
||||||
uInt tm_year; /* years - [1980..2044] */ |
uInt tm_year; /* years - [1980..2044] */ |
||||||
} tm_zip; |
} tm_zip; |
||||||
|
|
||||||
typedef struct |
typedef struct |
||||||
{ |
{ |
||||||
tm_zip tmz_date; /* date in understandable format */ |
tm_zip tmz_date; /* date in understandable format */ |
||||||
uLong dosDate; /* if dos_date == 0, tmu_date is used */ |
uLong dosDate; /* if dos_date == 0, tmu_date is used */ |
||||||
/* uLong flag; */ /* general purpose bit flag 2 bytes */ |
/* uLong flag; */ /* general purpose bit flag 2 bytes */ |
||||||
|
|
||||||
uLong internal_fa; /* internal file attributes 2 bytes */ |
uLong internal_fa; /* internal file attributes 2 bytes */ |
||||||
uLong external_fa; /* external file attributes 4 bytes */ |
uLong external_fa; /* external file attributes 4 bytes */ |
||||||
} zip_fileinfo; |
} zip_fileinfo; |
||||||
|
|
||||||
typedef const char* zipcharpc; |
typedef const char* zipcharpc; |
||||||
|
|
||||||
|
|
||||||
#define APPEND_STATUS_CREATE (0) |
#define APPEND_STATUS_CREATE (0) |
||||||
#define APPEND_STATUS_CREATEAFTER (1) |
#define APPEND_STATUS_CREATEAFTER (1) |
||||||
#define APPEND_STATUS_ADDINZIP (2) |
#define APPEND_STATUS_ADDINZIP (2) |
||||||
|
|
||||||
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); |
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); |
||||||
/*
|
/*
|
||||||
Create a zipfile. |
Create a zipfile. |
||||||
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on |
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on |
||||||
an Unix computer "zlib/zlib113.zip". |
an Unix computer "zlib/zlib113.zip". |
||||||
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip |
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip |
||||||
will be created at the end of the file. |
will be created at the end of the file. |
||||||
(useful if the file contain a self extractor code) |
(useful if the file contain a self extractor code) |
||||||
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will |
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will |
||||||
add files in existing zip (be sure you don't add file that doesn't exist) |
add files in existing zip (be sure you don't add file that doesn't exist) |
||||||
If the zipfile cannot be opened, the return value is NULL. |
If the zipfile cannot be opened, the return value is NULL. |
||||||
Else, the return value is a zipFile Handle, usable with other function |
Else, the return value is a zipFile Handle, usable with other function |
||||||
of this zip package. |
of this zip package. |
||||||
*/ |
*/ |
||||||
|
|
||||||
/* Note : there is no delete function into a zipfile.
|
/* Note : there is no delete function into a zipfile.
|
||||||
If you want delete file into a zipfile, you must open a zipfile, and create another |
If you want delete file into a zipfile, you must open a zipfile, and create another |
||||||
Of couse, you can use RAW reading and writing to copy the file you did not want delte |
Of couse, you can use RAW reading and writing to copy the file you did not want delte |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, |
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, |
||||||
int append, |
int append, |
||||||
zipcharpc* globalcomment, |
zipcharpc* globalcomment, |
||||||
zlib_filefunc_def* pzlib_filefunc_def)); |
zlib_filefunc_def* pzlib_filefunc_def)); |
||||||
|
|
||||||
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, |
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, |
||||||
const char* filename, |
const char* filename, |
||||||
const zip_fileinfo* zipfi, |
const zip_fileinfo* zipfi, |
||||||
const void* extrafield_local, |
const void* extrafield_local, |
||||||
uInt size_extrafield_local, |
uInt size_extrafield_local, |
||||||
const void* extrafield_global, |
const void* extrafield_global, |
||||||
uInt size_extrafield_global, |
uInt size_extrafield_global, |
||||||
const char* comment, |
const char* comment, |
||||||
int method, |
int method, |
||||||
int level)); |
int level)); |
||||||
/*
|
/*
|
||||||
Open a file in the ZIP for writing. |
Open a file in the ZIP for writing. |
||||||
filename : the filename in zip (if NULL, '-' without quote will be used |
filename : the filename in zip (if NULL, '-' without quote will be used |
||||||
*zipfi contain supplemental information |
*zipfi contain supplemental information |
||||||
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local |
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local |
||||||
contains the extrafield data the the local header |
contains the extrafield data the the local header |
||||||
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global |
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global |
||||||
contains the extrafield data the the local header |
contains the extrafield data the the local header |
||||||
if comment != NULL, comment contain the comment string |
if comment != NULL, comment contain the comment string |
||||||
method contain the compression method (0 for store, Z_DEFLATED for deflate) |
method contain the compression method (0 for store, Z_DEFLATED for deflate) |
||||||
level contain the level of compression (can be Z_DEFAULT_COMPRESSION) |
level contain the level of compression (can be Z_DEFAULT_COMPRESSION) |
||||||
*/ |
*/ |
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, |
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, |
||||||
const char* filename, |
const char* filename, |
||||||
const zip_fileinfo* zipfi, |
const zip_fileinfo* zipfi, |
||||||
const void* extrafield_local, |
const void* extrafield_local, |
||||||
uInt size_extrafield_local, |
uInt size_extrafield_local, |
||||||
const void* extrafield_global, |
const void* extrafield_global, |
||||||
uInt size_extrafield_global, |
uInt size_extrafield_global, |
||||||
const char* comment, |
const char* comment, |
||||||
int method, |
int method, |
||||||
int level, |
int level, |
||||||
int raw)); |
int raw)); |
||||||
|
|
||||||
/*
|
/*
|
||||||
Same than zipOpenNewFileInZip, except if raw=1, we write raw file |
Same than zipOpenNewFileInZip, except if raw=1, we write raw file |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, |
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, |
||||||
const char* filename, |
const char* filename, |
||||||
const zip_fileinfo* zipfi, |
const zip_fileinfo* zipfi, |
||||||
const void* extrafield_local, |
const void* extrafield_local, |
||||||
uInt size_extrafield_local, |
uInt size_extrafield_local, |
||||||
const void* extrafield_global, |
const void* extrafield_global, |
||||||
uInt size_extrafield_global, |
uInt size_extrafield_global, |
||||||
const char* comment, |
const char* comment, |
||||||
int method, |
int method, |
||||||
int level, |
int level, |
||||||
int raw, |
int raw, |
||||||
int windowBits, |
int windowBits, |
||||||
int memLevel, |
int memLevel, |
||||||
int strategy, |
int strategy, |
||||||
const char* password, |
const char* password, |
||||||
uLong crcForCtypting)); |
uLong crcForCtypting)); |
||||||
|
|
||||||
/*
|
/*
|
||||||
Same than zipOpenNewFileInZip2, except |
Same than zipOpenNewFileInZip2, except |
||||||
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 |
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 |
||||||
password : crypting password (NULL for no crypting) |
password : crypting password (NULL for no crypting) |
||||||
crcForCtypting : crc of file to compress (needed for crypting) |
crcForCtypting : crc of file to compress (needed for crypting) |
||||||
*/ |
*/ |
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, |
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, |
||||||
const void* buf, |
const void* buf, |
||||||
unsigned len)); |
unsigned len)); |
||||||
/*
|
/*
|
||||||
Write data in the zipfile |
Write data in the zipfile |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); |
extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); |
||||||
/*
|
/*
|
||||||
Close the current file in the zipfile |
Close the current file in the zipfile |
||||||
*/ |
*/ |
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, |
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, |
||||||
uLong uncompressed_size, |
uLong uncompressed_size, |
||||||
uLong crc32)); |
uLong crc32)); |
||||||
/*
|
/*
|
||||||
Close the current file in the zipfile, for fiel opened with |
Close the current file in the zipfile, for fiel opened with |
||||||
parameter raw=1 in zipOpenNewFileInZip2 |
parameter raw=1 in zipOpenNewFileInZip2 |
||||||
uncompressed_size and crc32 are value for the uncompressed size |
uncompressed_size and crc32 are value for the uncompressed size |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern int ZEXPORT zipClose OF((zipFile file, |
extern int ZEXPORT zipClose OF((zipFile file, |
||||||
const char* global_comment)); |
const char* global_comment)); |
||||||
/*
|
/*
|
||||||
Close the zipfile |
Close the zipfile |
||||||
*/ |
*/ |
||||||
|
|
||||||
#ifdef __cplusplus |
#ifdef __cplusplus |
||||||
} |
} |
||||||
#endif |
#endif |
||||||
|
|
||||||
#endif /* _zip_H */ |
#endif /* _zip_H */ |
||||||
|
@ -0,0 +1,257 @@ |
|||||||
|
|
||||||
|
Frequently Asked Questions about ZLIB.DLL |
||||||
|
|
||||||
|
|
||||||
|
This FAQ is about the design, the rationale, and the use of |
||||||
|
ZLIB.DLL. If you have general questions about zlib, you should |
||||||
|
check the file "FAQ" found in the zlib distribution, or at the |
||||||
|
location http://www.gzip.org/zlib/zlib_faq.html |
||||||
|
|
||||||
|
|
||||||
|
1. Why am I having problems using ZLIB.DLL? My application works |
||||||
|
with the static build of zlib just fine, and I didn't make any |
||||||
|
modification when recompiling it for ZLIB.DLL. |
||||||
|
|
||||||
|
- Make sure you define ZLIB_DLL before including "zlib.h". |
||||||
|
Applications that link to ZLIB.DLL will work properly if |
||||||
|
the source files are compiled in this (or in a compatible) |
||||||
|
way, and the executables are linked to MSVCRT.DLL. |
||||||
|
|
||||||
|
|
||||||
|
2. Why do I have to do this? When I use other libraries, I can |
||||||
|
link my code to their static or dynamic versions, without |
||||||
|
needing any source code modification or recompilation. |
||||||
|
|
||||||
|
- In order to preserve the backwards compatibility with the |
||||||
|
older versions of ZLIB.DLL, and give the ability to use zlib |
||||||
|
to the non-C programmers at the same time, we had to do this |
||||||
|
compromise. |
||||||
|
|
||||||
|
|
||||||
|
3. What exactly is this mess about, and why is it happening? |
||||||
|
|
||||||
|
- It's about the calling convention used for the zlib functions. |
||||||
|
If linked in statically, zlib uses the C (CDECL) convention. |
||||||
|
If linked in dynamically (via ZLIB.DLL), it uses the STDCALL |
||||||
|
convention. The ZLIB_DLL macro switches on the use of STDCALL. |
||||||
|
|
||||||
|
It happens because we need to preserve compatibility with the |
||||||
|
old releases of ZLIB.DLL that use STDCALL, and, at the same |
||||||
|
time, we must provide support for programmers who use other |
||||||
|
programming languages with bindings that require CDECL. |
||||||
|
|
||||||
|
|
||||||
|
4. Why not use the STDCALL convention all the time? |
||||||
|
It's the standard convention in Win32, and I need it in my |
||||||
|
Visual Basic project! |
||||||
|
|
||||||
|
- Most of the Win32 API functions (without varargs) use indeed |
||||||
|
the STDCALL (WINAPI) convention, but the standard C functions |
||||||
|
use the default CDECL. If one calls Win32 functions such as |
||||||
|
CreateFile(), sometimes it makes sense to decorate one's own |
||||||
|
functions with STDCALL. But if one is aiming at ANSI C or |
||||||
|
POSIX portability, and calls functions such as fopen(), it is |
||||||
|
not a sound decision to include <windows.h> or to use non-ANSI |
||||||
|
constructs only to make one's functions STDCALL-able. This is |
||||||
|
not the biggest problem, however. |
||||||
|
|
||||||
|
Technically, STDCALL is not bad; it is even a little faster |
||||||
|
than CDECL. The problem of using STDCALL is actually a problem |
||||||
|
of using any explicit calling convention. FASTCALL falls into |
||||||
|
the same category. |
||||||
|
|
||||||
|
Explicit specification of calling conventions, whether it's |
||||||
|
direct or indirect via a macro, happens commonly in Windows, |
||||||
|
but it is regarded as a noisy, non-standard C quirk on other |
||||||
|
platforms. It isn't possible to write an ANSI C -conforming |
||||||
|
program, for example, if it is necessary to specify calling |
||||||
|
conventions. Libraries can hide the dirty stuff in header |
||||||
|
files, under macros, but callbacks will still remain exposed. |
||||||
|
This is why the zlib callbacks will not be decorated. |
||||||
|
(The old Windows callbacks, such as WndProc, are decorated, |
||||||
|
but the newer ones are not.) |
||||||
|
|
||||||
|
There is one more problem with explicit, non-default calling |
||||||
|
conventions: the ability to use zlib in other programming |
||||||
|
languages. Some of them, like Ada (GNAT) and Fortran (GNU G77) |
||||||
|
have C bindings implemented initially on Unix, hence relying |
||||||
|
on the C calling convention. |
||||||
|
|
||||||
|
So we are decorating the functions using STDCALL in ZLIB.DLL |
||||||
|
to maintain compatibility with the old versions, but we are |
||||||
|
using the default CDECL in the static library, to allow other |
||||||
|
programming languages to use zlib in a portable fashion, via |
||||||
|
C bindings. |
||||||
|
|
||||||
|
|
||||||
|
5. Why not use the default (CDECL) convention all the time? |
||||||
|
It's the standard convention in C, and I need it in my Ada |
||||||
|
project! |
||||||
|
|
||||||
|
- Originally, ZLIB.DLL was intended to run under Visual Basic, |
||||||
|
and VB6 and earlier need STDCALL. |
||||||
|
|
||||||
|
We admit that cluttering the main zlib sources, for the sake |
||||||
|
of interfacing with Visual Basic and at the expense of other |
||||||
|
programming languages, is not fair. It would have been better |
||||||
|
to maintain a "VB-only" project in the contrib/ directory, and |
||||||
|
to build a custom ZLIBVB.DLL, for example -- as we did with |
||||||
|
the Delphi projects. Another possible solution would have been |
||||||
|
to build STDCALL wrappers around the CDECL-exported functions. |
||||||
|
|
||||||
|
But this was the accident that we have to live with, in order |
||||||
|
to maintain binary compatibility with the older versions of |
||||||
|
ZLIB.DLL. |
||||||
|
|
||||||
|
|
||||||
|
6. If my application uses ZLIB.DLL, do I have to link it to |
||||||
|
MSVCRT.DLL? Why? |
||||||
|
|
||||||
|
- The executables (.EXE, .DLL, etc.) that are involved in the |
||||||
|
same process and are using the C run-time library (i.e. they |
||||||
|
are calling any standard C function), must link to the same |
||||||
|
library. There are several libraries in the Win32 system: |
||||||
|
CRTDLL.DLL, MSVCRT.DLL, the static C libraries, etc. |
||||||
|
Since ZLIB.DLL is linked to MSVCRT.DLL, the executables that |
||||||
|
depend on it must also link to MSVCRT.DLL. |
||||||
|
|
||||||
|
|
||||||
|
7. Why are you saying that ZLIB.DLL and my application must be |
||||||
|
linked to the same C run-time library (CRT)? I linked my |
||||||
|
application and my DLLs to different C libraries (e.g. my |
||||||
|
application to a static library, and my DLLs to MSVCRT.DLL), |
||||||
|
and everything works fine. |
||||||
|
|
||||||
|
- If a library invokes only pure Win32 API (i.e. accessible |
||||||
|
via <windows.h>), its DLL build will work in any context. |
||||||
|
But if a library invokes standard C functions, things get |
||||||
|
more complicated. |
||||||
|
|
||||||
|
There is a single Win32 library in a Win32 system. Every |
||||||
|
function in this library resides in a single DLL module, that |
||||||
|
is safe to call from anywhere. On the other hand, there are |
||||||
|
multiple versions of the C library that are all at the same |
||||||
|
time in the system, and all of them have internal states, |
||||||
|
therefore it is dangerous to intermix them with each other. |
||||||
|
|
||||||
|
Intermixing multiple C libraries is possible, as long as their |
||||||
|
internal states are kept intact. The Microsoft Knowledge Base |
||||||
|
article Q140584 "HOWTO: Link with the Correct C Run-Time (CRT) |
||||||
|
Library" enumerates some of the potential problems raised by |
||||||
|
intermixing, but does not offer a complete description of how |
||||||
|
to avoid them, except by advising not to mix the C libraries. |
||||||
|
If you can send us more information about this issue, we will |
||||||
|
highly appreciate it. (But please do NOT send us source code |
||||||
|
from Microsoft, even if it comes with your legitimate copy of |
||||||
|
Visual C++!) |
||||||
|
|
||||||
|
If this kind of intermixing works for you, it's because your |
||||||
|
application and DLLs are avoiding the corruption of the CRT's |
||||||
|
internal states, due to a fortunate accident. It's not because |
||||||
|
those libraries really work together. |
||||||
|
|
||||||
|
Also note that linking ZLIB.DLL to non-Microsoft C libraries |
||||||
|
(such as Borland's) raises similar problems. |
||||||
|
|
||||||
|
|
||||||
|
8. Why are you linking ZLIB.DLL to MSVCRT.DLL? |
||||||
|
|
||||||
|
- MSVCRT.DLL exists on every Windows 95 with a new service pack |
||||||
|
installed, or with Microsoft Internet Explorer 4 or later, and |
||||||
|
on all other Windows 4.x or later (Windows 98, Windows NT 4, |
||||||
|
or later). It is freely distributable; if not present in the |
||||||
|
system, it can be downloaded from Microsoft or from other |
||||||
|
software provider for free. |
||||||
|
|
||||||
|
The fact that MSVCRT.DLL does not exist on a virgin Windows 95 |
||||||
|
is not so problematic. The number of Windows 95 installations |
||||||
|
is rapidly decreasing, Microsoft stopped supporting it a long |
||||||
|
time ago, and many recent applications from various vendors |
||||||
|
including Microsoft, do not even run on it. Even without these |
||||||
|
arguments, no serious user should run Windows 95 without a |
||||||
|
proper update installed. |
||||||
|
|
||||||
|
There is also the fact that the mainstream C compilers for |
||||||
|
Windows are Microsoft Visual C++ 6.0, and gcc/MinGW. Both |
||||||
|
are producing executables that link to MSVCRT.DLL by default, |
||||||
|
without offering other dynamic CRTs as alternatives easy to |
||||||
|
select by users. |
||||||
|
|
||||||
|
|
||||||
|
9. Why are you not linking ZLIB.DLL to |
||||||
|
<<my favorite C run-time library>> ? |
||||||
|
|
||||||
|
- We considered and abandoned the following alternatives: |
||||||
|
|
||||||
|
* Linking ZLIB.DLL to a static C library (LIBC.LIB, or |
||||||
|
LIBCMT.LIB) is not a good option. People are using ZLIB.DLL |
||||||
|
mainly to save disk space. If you are linking your program |
||||||
|
to a static C library, you may as well consider linking zlib |
||||||
|
in statically, too. |
||||||
|
|
||||||
|
* Linking ZLIB.DLL to CRTDLL.DLL looks very appealing, |
||||||
|
because CRTDLL.DLL is present on every Win32 installation. |
||||||
|
Unfortunately, it has a series of problems: it raises |
||||||
|
difficulties when linking to the Microsoft C++ libraries, |
||||||
|
it is not thread-safe, and Microsoft has discontinued its |
||||||
|
support a long time ago. |
||||||
|
|
||||||
|
* Linking ZLIB.DLL to MSVCRT70.DLL, supplied with the |
||||||
|
Microsoft .NET platform and Visual C++ 7.0, is not a good |
||||||
|
option. Although it can be downloaded and distributed |
||||||
|
freely, it is hardly present on today's Win32 installations. |
||||||
|
If it will become more popular than MSVCRT.DLL, and will be |
||||||
|
pre-installed on the future Win32 systems, we will probably |
||||||
|
think again about it. |
||||||
|
|
||||||
|
* Linking ZLIB.DLL to NTDLL.DLL is not possible. |
||||||
|
NTDLL.DLL exports only a part of the C library, and only |
||||||
|
on Windows NT systems. |
||||||
|
|
||||||
|
|
||||||
|
10. I understand your reasons. However, my project needs ZLIB.DLL |
||||||
|
linked to something different than MSVCRT.DLL. What can I do? |
||||||
|
|
||||||
|
Feel free to rebuild this DLL from the zlib sources, and link |
||||||
|
it the way you want. It is required, however, to clearly |
||||||
|
state that your build is unofficial. Another thing that is not |
||||||
|
required, but highly recommended, is to name that custom DLL |
||||||
|
differently, and/or to install it in a private directory that |
||||||
|
can be accessed by your application, but is not visible to the |
||||||
|
others (e.g. it's not the SYSTEM or the SYSTEM32 directory, |
||||||
|
and it's not in the PATH). Otherwise, your build may clash |
||||||
|
with applications that link to the official build. |
||||||
|
|
||||||
|
For example, in Cygwin, zlib is linked to their runtime |
||||||
|
CYGWIN1.DLL, and it is distributed under the name CYGZ.DLL. |
||||||
|
|
||||||
|
|
||||||
|
11. My I include additional pieces of code that I find useful, |
||||||
|
link them in ZLIB.DLL, and export them? |
||||||
|
|
||||||
|
No. A legitimate build of ZLIB.DLL must not include code that |
||||||
|
does not originate from the official zlib sources. But you can |
||||||
|
make your own private build, and give it a different name, as |
||||||
|
suggested in the previous answer. |
||||||
|
|
||||||
|
For example, in Borland Delphi and C++ Builder, zlib is part |
||||||
|
of the standard VCL library. If an application links to VCL |
||||||
|
dynamically, the name of the distributable binary (VCLxx.DLL) |
||||||
|
does not posess any danger of clashing with a legitimate but |
||||||
|
incompatible ZLIB.DLL. |
||||||
|
|
||||||
|
|
||||||
|
12. I see that I may have all kinds of problems if I use ZLIB.DLL. |
||||||
|
Do you recommend to link zlib in statically? Do I get rid of |
||||||
|
problems? |
||||||
|
|
||||||
|
- Yes, definitely. In fact, unless you are distributing a large |
||||||
|
number of executables, each of them linking to zlib, you will |
||||||
|
save space by linking zlib in statically (assuming that you |
||||||
|
would otherwise distribute ZLIB.DLL with your application). |
||||||
|
zlib is not a big library, and the space saved by ZLIB.DLL is |
||||||
|
little. Much of the actual size of the DLL is due to the 4KB |
||||||
|
alignment in the binary. |
||||||
|
|
||||||
|
But you may have reasons, other than size, to use the DLL. |
||||||
|
That is entirely up to you. |
@ -1,107 +0,0 @@ |
|||||||
.TH ZLIB 3 "11 March 2002" |
|
||||||
.SH NAME |
|
||||||
zlib \- compression/decompression library |
|
||||||
.SH SYNOPSIS |
|
||||||
[see |
|
||||||
.I zlib.h |
|
||||||
for full description] |
|
||||||
.SH DESCRIPTION |
|
||||||
The |
|
||||||
.I zlib |
|
||||||
library is a general purpose data compression library. |
|
||||||
The code is thread safe. |
|
||||||
It provides in-memory compression and decompression functions, |
|
||||||
including integrity checks of the uncompressed data. |
|
||||||
This version of the library supports only one compression method (deflation) |
|
||||||
but other algorithms will be added later and will have the same stream interface. |
|
||||||
.LP |
|
||||||
Compression can be done in a single step if the buffers are large enough |
|
||||||
(for example if an input file is mmap'ed), |
|
||||||
or can be done by repeated calls of the compression function. |
|
||||||
In the latter case, |
|
||||||
the application must provide more input and/or consume the output |
|
||||||
(providing more output space) before each call. |
|
||||||
.LP |
|
||||||
The library also supports reading and writing files in |
|
||||||
.I gzip |
|
||||||
(.gz) format |
|
||||||
with an interface similar to that of stdio. |
|
||||||
.LP |
|
||||||
The library does not install any signal handler. The decoder checks |
|
||||||
the consistency of the compressed data, so the library should never |
|
||||||
crash even in case of corrupted input. |
|
||||||
.LP |
|
||||||
All functions of the compression library are documented in the file |
|
||||||
.IR zlib.h. |
|
||||||
The distribution source includes examples of use of the library |
|
||||||
the files |
|
||||||
.I example.c |
|
||||||
and |
|
||||||
.IR minigzip.c . |
|
||||||
.LP |
|
||||||
A Java implementation of |
|
||||||
.IR zlib |
|
||||||
is available in the Java Development Kit 1.1 |
|
||||||
.IP |
|
||||||
http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html |
|
||||||
.LP |
|
||||||
A Perl interface to |
|
||||||
.IR zlib , |
|
||||||
written by Paul Marquess (pmarquess@bfsec.bt.co.uk) |
|
||||||
is available at CPAN (Comprehensive Perl Archive Network) sites, |
|
||||||
such as: |
|
||||||
.IP |
|
||||||
ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib* |
|
||||||
.LP |
|
||||||
A Python interface to |
|
||||||
.IR zlib |
|
||||||
written by A.M. Kuchling <amk@magnet.com> |
|
||||||
is available from the Python Software Association sites, such as: |
|
||||||
.IP |
|
||||||
ftp://ftp.python.org/pub/python/contrib/Encoding/zlib*.tar.gz |
|
||||||
.SH "SEE ALSO" |
|
||||||
Questions about zlib should be sent to: |
|
||||||
.IP |
|
||||||
zlib@quest.jpl.nasa.gov |
|
||||||
or, if this fails, to the author addresses given below. |
|
||||||
The zlib home page is: |
|
||||||
.IP |
|
||||||
http://www.cdrom.com/pub/infozip/zlib/ |
|
||||||
.LP |
|
||||||
The data format used by the zlib library is described by RFC |
|
||||||
(Request for Comments) 1950 to 1952 in the files: |
|
||||||
.IP |
|
||||||
ftp://ds.internic.net/rfc/rfc1950.txt (zlib format) |
|
||||||
.br |
|
||||||
rfc1951.txt (deflate format) |
|
||||||
.br |
|
||||||
rfc1952.txt (gzip format) |
|
||||||
.LP |
|
||||||
These documents are also available in other formats from: |
|
||||||
.IP |
|
||||||
ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html |
|
||||||
.SH AUTHORS |
|
||||||
Version 1.1.4 |
|
||||||
Copyright (C) 1995-2002 Jean-loup Gailly (jloup@gzip.org) |
|
||||||
and Mark Adler (madler@alumni.caltech.edu). |
|
||||||
.LP |
|
||||||
This software is provided "as-is," |
|
||||||
without any express or implied warranty. |
|
||||||
In no event will the authors be held liable for any damages |
|
||||||
arising from the use of this software. |
|
||||||
See the distribution directory with respect to requirements |
|
||||||
governing redistribution. |
|
||||||
The deflate format used by |
|
||||||
.I zlib |
|
||||||
was defined by Phil Katz. |
|
||||||
The deflate and |
|
||||||
.I zlib |
|
||||||
specifications were written by L. Peter Deutsch. |
|
||||||
Thanks to all the people who reported problems and suggested various |
|
||||||
improvements in |
|
||||||
.IR zlib ; |
|
||||||
who are too numerous to cite here. |
|
||||||
.LP |
|
||||||
UNIX manual page by R. P. C. Rodgers, |
|
||||||
U.S. National Library of Medicine (rodgers@nlm.nih.gov). |
|
||||||
.\" end of man page |
|
@ -0,0 +1,159 @@ |
|||||||
|
.TH ZLIB 3 "12 May 2003" |
||||||
|
.SH NAME |
||||||
|
zlib \- compression/decompression library |
||||||
|
.SH SYNOPSIS |
||||||
|
[see |
||||||
|
.I zlib.h |
||||||
|
for full description] |
||||||
|
.SH DESCRIPTION |
||||||
|
The |
||||||
|
.I zlib |
||||||
|
library is a general purpose data compression library. |
||||||
|
The code is thread safe. |
||||||
|
It provides in-memory compression and decompression functions, |
||||||
|
including integrity checks of the uncompressed data. |
||||||
|
This version of the library supports only one compression method (deflation) |
||||||
|
but other algorithms will be added later |
||||||
|
and will have the same stream interface. |
||||||
|
.LP |
||||||
|
Compression can be done in a single step if the buffers are large enough |
||||||
|
(for example if an input file is mmap'ed), |
||||||
|
or can be done by repeated calls of the compression function. |
||||||
|
In the latter case, |
||||||
|
the application must provide more input and/or consume the output |
||||||
|
(providing more output space) before each call. |
||||||
|
.LP |
||||||
|
The library also supports reading and writing files in |
||||||
|
.IR gzip (1) |
||||||
|
(.gz) format |
||||||
|
with an interface similar to that of stdio. |
||||||
|
.LP |
||||||
|
The library does not install any signal handler. |
||||||
|
The decoder checks the consistency of the compressed data, |
||||||
|
so the library should never crash even in case of corrupted input. |
||||||
|
.LP |
||||||
|
All functions of the compression library are documented in the file |
||||||
|
.IR zlib.h . |
||||||
|
The distribution source includes examples of use of the library |
||||||
|
in the files |
||||||
|
.I example.c |
||||||
|
and |
||||||
|
.IR minigzip.c . |
||||||
|
.LP |
||||||
|
Changes to this version are documented in the file |
||||||
|
.I ChangeLog |
||||||
|
that accompanies the source, |
||||||
|
and are concerned primarily with bug fixes and portability enhancements. |
||||||
|
.LP |
||||||
|
A Java implementation of |
||||||
|
.I zlib |
||||||
|
is available in the Java Development Kit 1.1: |
||||||
|
.IP |
||||||
|
http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html |
||||||
|
.LP |
||||||
|
A Perl interface to |
||||||
|
.IR zlib , |
||||||
|
written by Paul Marquess (pmqs@cpan.org), |
||||||
|
is available at CPAN (Comprehensive Perl Archive Network) sites, |
||||||
|
including: |
||||||
|
.IP |
||||||
|
http://www.cpan.org/modules/by-module/Compress/ |
||||||
|
.LP |
||||||
|
A Python interface to |
||||||
|
.IR zlib , |
||||||
|
written by A.M. Kuchling (amk@magnet.com), |
||||||
|
is available in Python 1.5 and later versions: |
||||||
|
.IP |
||||||
|
http://www.python.org/doc/lib/module-zlib.html |
||||||
|
.LP |
||||||
|
A |
||||||
|
.I zlib |
||||||
|
binding for |
||||||
|
.IR tcl (1), |
||||||
|
written by Andreas Kupries (a.kupries@westend.com), |
||||||
|
is availlable at: |
||||||
|
.IP |
||||||
|
http://www.westend.com/~kupries/doc/trf/man/man.html |
||||||
|
.LP |
||||||
|
An experimental package to read and write files in .zip format, |
||||||
|
written on top of |
||||||
|
.I zlib |
||||||
|
by Gilles Vollant (info@winimage.com), |
||||||
|
is available at: |
||||||
|
.IP |
||||||
|
http://www.winimage.com/zLibDll/unzip.html |
||||||
|
and also in the |
||||||
|
.I contrib/minizip |
||||||
|
directory of the main |
||||||
|
.I zlib |
||||||
|
web site. |
||||||
|
.SH "SEE ALSO" |
||||||
|
The |
||||||
|
.I zlib |
||||||
|
web site can be found at either of these locations: |
||||||
|
.IP |
||||||
|
http://www.zlib.org |
||||||
|
.br |
||||||
|
http://www.gzip.org/zlib/ |
||||||
|
.LP |
||||||
|
The data format used by the zlib library is described by RFC |
||||||
|
(Request for Comments) 1950 to 1952 in the files: |
||||||
|
.IP |
||||||
|
http://www.ietf.org/rfc/rfc1950.txt (concerning zlib format) |
||||||
|
.br |
||||||
|
http://www.ietf.org/rfc/rfc1951.txt (concerning deflate format) |
||||||
|
.br |
||||||
|
http://www.ietf.org/rfc/rfc1952.txt (concerning gzip format) |
||||||
|
.LP |
||||||
|
These documents are also available in other formats from: |
||||||
|
.IP |
||||||
|
ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html |
||||||
|
.LP |
||||||
|
Mark Nelson (markn@ieee.org) wrote an article about |
||||||
|
.I zlib |
||||||
|
for the Jan. 1997 issue of Dr. Dobb's Journal; |
||||||
|
a copy of the article is available at: |
||||||
|
.IP |
||||||
|
http://dogma.net/markn/articles/zlibtool/zlibtool.htm |
||||||
|
.SH "REPORTING PROBLEMS" |
||||||
|
Before reporting a problem, |
||||||
|
please check the |
||||||
|
.I zlib |
||||||
|
web site to verify that you have the latest version of |
||||||
|
.IR zlib ; |
||||||
|
otherwise, |
||||||
|
obtain the latest version and see if the problem still exists. |
||||||
|
Please read the |
||||||
|
.I zlib |
||||||
|
FAQ at: |
||||||
|
.IP |
||||||
|
http://www.gzip.org/zlib/zlib_faq.html |
||||||
|
.LP |
||||||
|
before asking for help. |
||||||
|
Send questions and/or comments to zlib@gzip.org, |
||||||
|
or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). |
||||||
|
.SH AUTHORS |
||||||
|
Version 1.2.0.1 |
||||||
|
Copyright (C) 1995-2003 Jean-loup Gailly (jloup@gzip.org) |
||||||
|
and Mark Adler (madler@alumni.caltech.edu). |
||||||
|
.LP |
||||||
|
This software is provided "as-is," |
||||||
|
without any express or implied warranty. |
||||||
|
In no event will the authors be held liable for any damages |
||||||
|
arising from the use of this software. |
||||||
|
See the distribution directory with respect to requirements |
||||||
|
governing redistribution. |
||||||
|
The deflate format used by |
||||||
|
.I zlib |
||||||
|
was defined by Phil Katz. |
||||||
|
The deflate and |
||||||
|
.I zlib |
||||||
|
specifications were written by L. Peter Deutsch. |
||||||
|
Thanks to all the people who reported problems and suggested various |
||||||
|
improvements in |
||||||
|
.IR zlib ; |
||||||
|
who are too numerous to cite here. |
||||||
|
.LP |
||||||
|
UNIX manual page by R. P. C. Rodgers, |
||||||
|
U.S. National Library of Medicine (rodgers@nlm.nih.gov). |
||||||
|
.\" end of man page |
Loading…
Reference in new issue