parent
f6194ef39a
commit
d004b04783
74 changed files with 7120 additions and 1855 deletions
@ -0,0 +1,177 @@ |
|||||||
|
cmake_minimum_required(VERSION 2.4.4) |
||||||
|
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) |
||||||
|
|
||||||
|
project(zlib C) |
||||||
|
|
||||||
|
if(NOT DEFINED BUILD_SHARED_LIBS) |
||||||
|
option(BUILD_SHARED_LIBS "Build a shared library form of zlib" ON) |
||||||
|
endif() |
||||||
|
|
||||||
|
include(CheckTypeSize) |
||||||
|
include(CheckFunctionExists) |
||||||
|
include(CheckIncludeFile) |
||||||
|
include(CheckCSourceCompiles) |
||||||
|
enable_testing() |
||||||
|
|
||||||
|
check_include_file(sys/types.h HAVE_SYS_TYPES_H) |
||||||
|
check_include_file(stdint.h HAVE_STDINT_H) |
||||||
|
check_include_file(stddef.h HAVE_STDDEF_H) |
||||||
|
|
||||||
|
# |
||||||
|
# Check to see if we have large file support |
||||||
|
# |
||||||
|
set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE) |
||||||
|
|
||||||
|
# We add these other definitions here because CheckTypeSize.cmake |
||||||
|
# in CMake 2.4.x does not automatically do so and we want |
||||||
|
# compatibility with CMake 2.4.x. |
||||||
|
if(HAVE_SYS_TYPES_H) |
||||||
|
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H) |
||||||
|
endif() |
||||||
|
if(HAVE_STDINT_H) |
||||||
|
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H) |
||||||
|
endif() |
||||||
|
if(HAVE_STDDEF_H) |
||||||
|
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) |
||||||
|
endif() |
||||||
|
|
||||||
|
check_type_size(off64_t OFF64_T) |
||||||
|
|
||||||
|
if(HAVE_OFF64_T) |
||||||
|
add_definitions(-D_LARGEFILE64_SOURCE) |
||||||
|
endif() |
||||||
|
set(CMAKE_REQUIRED_DEFINITIONS) # clear variable |
||||||
|
|
||||||
|
# |
||||||
|
# Check for fseeko |
||||||
|
# |
||||||
|
check_function_exists(fseeko HAVE_FSEEKO) |
||||||
|
if(NOT HAVE_FSEEKO) |
||||||
|
add_definitions(-DNO_FSEEKO) |
||||||
|
endif() |
||||||
|
|
||||||
|
# |
||||||
|
# Check for unistd.h |
||||||
|
# |
||||||
|
check_include_file(unistd.h HAVE_UNISTD_H) |
||||||
|
|
||||||
|
# |
||||||
|
# Check for errno.h |
||||||
|
check_include_file(errno.h HAVE_ERRNO_H) |
||||||
|
if(NOT HAVE_ERRNO_H) |
||||||
|
add_definitions(-DNO_ERRNO_H) |
||||||
|
endif() |
||||||
|
|
||||||
|
# |
||||||
|
# Check for mmap support |
||||||
|
# |
||||||
|
set(mmap_test_code " |
||||||
|
#include <sys/types.h> |
||||||
|
#include <sys/mman.h> |
||||||
|
#include <sys/stat.h> |
||||||
|
caddr_t hello() { |
||||||
|
return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0); |
||||||
|
} |
||||||
|
int main() { return 0; } |
||||||
|
") |
||||||
|
check_c_source_compiles("${mmap_test_code}" USE_MMAP) |
||||||
|
if(USE_MMAP) |
||||||
|
add_definitions(-DUSE_MMAP) |
||||||
|
endif() |
||||||
|
|
||||||
|
# |
||||||
|
# Create the zlibdefs.h file. |
||||||
|
# Note: we create it in CMAKE_CURRENT_SOURCE_DIR instead |
||||||
|
# of CMAKE_CURRENT_BINARY_DIR because an empty zlibdefs.h |
||||||
|
# is shipped with zlib in the source tree. |
||||||
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h.cmakein |
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h) |
||||||
|
|
||||||
|
if(MSVC) |
||||||
|
set(CMAKE_DEBUG_POSTFIX "D") |
||||||
|
add_definitions(-D_CRT_SECURE_NO_DEPRECATE) |
||||||
|
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) |
||||||
|
endif() |
||||||
|
|
||||||
|
#============================================================================ |
||||||
|
# zlib |
||||||
|
#============================================================================ |
||||||
|
|
||||||
|
set(ZLIB_PUBLIC_HDRS |
||||||
|
zconf.h |
||||||
|
zlib.h |
||||||
|
zlibdefs.h |
||||||
|
) |
||||||
|
set(ZLIB_PRIVATE_HDRS |
||||||
|
crc32.h |
||||||
|
deflate.h |
||||||
|
gzguts.h |
||||||
|
inffast.h |
||||||
|
inffixed.h |
||||||
|
inflate.h |
||||||
|
inftrees.h |
||||||
|
trees.h |
||||||
|
zutil.h |
||||||
|
) |
||||||
|
set(ZLIB_SRCS |
||||||
|
adler32.c |
||||||
|
compress.c |
||||||
|
crc32.c |
||||||
|
deflate.c |
||||||
|
gzclose.c |
||||||
|
gzio.c |
||||||
|
gzlib.c |
||||||
|
gzread.c |
||||||
|
gzwrite.c |
||||||
|
inflate.c |
||||||
|
infback.c |
||||||
|
inftrees.c |
||||||
|
inffast.c |
||||||
|
trees.c |
||||||
|
uncompr.c |
||||||
|
zutil.c |
||||||
|
) |
||||||
|
|
||||||
|
add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) |
||||||
|
set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) |
||||||
|
set_target_properties(zlib PROPERTIES VERSION 1.2.3.4) |
||||||
|
set_target_properties(zlib PROPERTIES SOVERSION 1) |
||||||
|
if(UNIX) |
||||||
|
# On unix like platforms the library is almost always called libz |
||||||
|
set_target_properties(zlib PROPERTIES OUTPUT_NAME z) |
||||||
|
endif() |
||||||
|
|
||||||
|
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) |
||||||
|
install(TARGETS zlib |
||||||
|
RUNTIME DESTINATION bin |
||||||
|
ARCHIVE DESTINATION lib |
||||||
|
LIBRARY DESTINATION lib ) |
||||||
|
endif() |
||||||
|
if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) |
||||||
|
install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include) |
||||||
|
endif() |
||||||
|
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) |
||||||
|
install(FILES zlib.3 DESTINATION share/man/man3) |
||||||
|
endif() |
||||||
|
|
||||||
|
#============================================================================ |
||||||
|
# Example binaries |
||||||
|
#============================================================================ |
||||||
|
|
||||||
|
add_executable(example example.c) |
||||||
|
target_link_libraries(example zlib) |
||||||
|
add_test(example example) |
||||||
|
|
||||||
|
add_executable(minigzip minigzip.c) |
||||||
|
target_link_libraries(minigzip zlib) |
||||||
|
|
||||||
|
if(HAVE_OFF64_T) |
||||||
|
add_executable(example64 example.c) |
||||||
|
target_link_libraries(example64 zlib) |
||||||
|
set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") |
||||||
|
add_test(example64 example64) |
||||||
|
|
||||||
|
add_executable(minigzip64 minigzip.c) |
||||||
|
target_link_libraries(minigzip64 zlib) |
||||||
|
set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") |
||||||
|
endif() |
@ -1,67 +0,0 @@ |
|||||||
Change in 1.01e (12 feb 05) |
|
||||||
- Fix in zipOpen2 for globalcomment (Rolf Kalbermatter) |
|
||||||
- Fix possible memory leak in unzip.c (Zoran Stevanovic) |
|
||||||
|
|
||||||
Change in 1.01b (20 may 04) |
|
||||||
- Integrate patch from Debian package (submited by Mark Brown) |
|
||||||
- Add tools mztools from Xavier Roche |
|
||||||
|
|
||||||
Change in 1.01 (8 may 04) |
|
||||||
- fix buffer overrun risk in unzip.c (Xavier Roche) |
|
||||||
- fix a minor buffer insecurity in minizip.c (Mike Whittaker) |
|
||||||
|
|
||||||
Change in 1.00: (10 sept 03) |
|
||||||
- rename to 1.00 |
|
||||||
- cosmetic code change |
|
||||||
|
|
||||||
Change in 0.22: (19 May 03) |
|
||||||
- crypting support (unless you define NOCRYPT) |
|
||||||
- append file in existing zipfile |
|
||||||
|
|
||||||
Change in 0.21: (10 Mar 03) |
|
||||||
- bug fixes |
|
||||||
|
|
||||||
Change in 0.17: (27 Jan 02) |
|
||||||
- bug fixes |
|
||||||
|
|
||||||
Change in 0.16: (19 Jan 02) |
|
||||||
- Support of ioapi for virtualize zip file access |
|
||||||
|
|
||||||
Change in 0.15: (19 Mar 98) |
|
||||||
- fix memory leak in minizip.c |
|
||||||
|
|
||||||
Change in 0.14: (10 Mar 98) |
|
||||||
- fix bugs in minizip.c sample for zipping big file |
|
||||||
- fix problem in month in date handling |
|
||||||
- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for |
|
||||||
comment handling |
|
||||||
|
|
||||||
Change in 0.13: (6 Mar 98) |
|
||||||
- fix bugs in zip.c |
|
||||||
- add real minizip sample |
|
||||||
|
|
||||||
Change in 0.12: (4 Mar 98) |
|
||||||
- add zip.c and zip.h for creates .zip file |
|
||||||
- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly) |
|
||||||
- fix miniunz.c for file without specific record for directory |
|
||||||
|
|
||||||
Change in 0.11: (3 Mar 98) |
|
||||||
- fix bug in unzGetCurrentFileInfo for get extra field and comment |
|
||||||
- enhance miniunz sample, remove the bad unztst.c sample |
|
||||||
|
|
||||||
Change in 0.10: (2 Mar 98) |
|
||||||
- fix bug in unzReadCurrentFile |
|
||||||
- rename unzip* to unz* function and structure |
|
||||||
- remove Windows-like hungary notation variable name |
|
||||||
- modify some structure in unzip.h |
|
||||||
- add somes comment in source |
|
||||||
- remove unzipGetcCurrentFile function |
|
||||||
- replace ZUNZEXPORT by ZEXPORT |
|
||||||
- add unzGetLocalExtrafield for get the local extrafield info |
|
||||||
- add a new sample, miniunz.c |
|
||||||
|
|
||||||
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
|
||||||
|
@ -0,0 +1,7 @@ |
|||||||
|
|
||||||
|
MiniZip64 was derrived from MiniZip at version 1.01f |
||||||
|
|
||||||
|
Change in 1.0 (Okt 2009) |
||||||
|
- **TODO - Add history** |
||||||
|
|
||||||
|
|
@ -0,0 +1,79 @@ |
|||||||
|
MiniZip64 - Copyright (c) 2009-2010 - Mathias Svensson - Built from MiniZip by Gilles Vollant |
||||||
|
|
||||||
|
Introduction |
||||||
|
--------------------- |
||||||
|
MiniZip64 is built from MiniZip by Gilles Vollant ( http://www.winimage.com/zLibDll/minizip.html ) |
||||||
|
|
||||||
|
When adding ZIP64 support into minizip it would result into breaking compatibility with current minizip. |
||||||
|
And since breaking compatibility in minizip is not wanted. I decided to create a fork of minizip |
||||||
|
and create minizip64. |
||||||
|
|
||||||
|
Even though MiniZip64 is build from MiniZip, all functions and struct's have changed name so that it |
||||||
|
would not collide with each other. |
||||||
|
|
||||||
|
|
||||||
|
Background |
||||||
|
--------------------- |
||||||
|
When adding ZIP64 support I found that Even Rouault have added ZIP64 support for unzip.c into minizip |
||||||
|
for a open source project called gdal ( http://www.gdal.org/ ) |
||||||
|
|
||||||
|
That was used as a starting point. And after that ZIP64 support was added to zip.c |
||||||
|
some refactoring and code cleanup was also done. |
||||||
|
|
||||||
|
|
||||||
|
Changed from MiniZip to MiniZip64 |
||||||
|
------------------------------------- |
||||||
|
* Filenames has got a '64' at the end of them . eg unzip.c is now called unzip64.c |
||||||
|
* Added ZIP64 support for unzip ( by Even Rouault ) |
||||||
|
* Added ZIP64 support for zip ( by Mathias Svensson ) |
||||||
|
* Reverted some changed that Even Rouault did. |
||||||
|
* Bunch of patches received from Gulles Vollant that he received for MiniZip from various users. |
||||||
|
* Added unzip patch for BZIP Compression method (patch create by Daniel Borca) |
||||||
|
* Added BZIP Compress method for zip |
||||||
|
* Did some refactoring and code cleanup |
||||||
|
|
||||||
|
|
||||||
|
Credits |
||||||
|
|
||||||
|
Gilles Vollant - Original MiniZip author |
||||||
|
Even Rouault - ZIP64 unzip Support |
||||||
|
Daniel Borca - BZip Compression method support in unzip |
||||||
|
Mathias Svensson - ZIP64 zip support |
||||||
|
Mathias Svensson - BZip Compression method support in zip |
||||||
|
|
||||||
|
Resources |
||||||
|
|
||||||
|
ZipLayout http://result42.com/projects/ZipFileLayout |
||||||
|
Command line tool for Windows that shows the layout and information of the headers in a zip archive. |
||||||
|
Used when debugging and validating the creation of zip files using MiniZip64 |
||||||
|
|
||||||
|
|
||||||
|
ZIP App Note http://www.pkware.com/documents/casestudies/APPNOTE.TXT |
||||||
|
Zip File specification |
||||||
|
|
||||||
|
|
||||||
|
Notes. |
||||||
|
* To be able to use BZip compression method in zip64.c or unzip64.c the BZIP2 lib is needed and HAVE_BZIP2 need to be defined. |
||||||
|
|
||||||
|
License |
||||||
|
---------------------------------------------------------- |
||||||
|
Condition of use and distribution are the same than zlib : |
||||||
|
|
||||||
|
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. |
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose, |
||||||
|
including commercial applications, and to alter it and redistribute it |
||||||
|
freely, subject to the following restrictions: |
||||||
|
|
||||||
|
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 |
||||||
|
in a product, an acknowledgment in the product documentation would be |
||||||
|
appreciated but is not required. |
||||||
|
2. Altered source versions must be plainly marked as such, and must not be |
||||||
|
misrepresented as being the original software. |
||||||
|
3. This notice may not be removed or altered from any source distribution. |
||||||
|
|
||||||
|
---------------------------------------------------------- |
||||||
|
|
@ -1,281 +1,281 @@ |
|||||||
/*
|
/*
|
||||||
Additional tools for Minizip |
Additional tools for Minizip |
||||||
Code: Xavier Roche '2004 |
Code: Xavier Roche '2004 |
||||||
License: Same as ZLIB (www.gzip.org) |
License: Same as ZLIB (www.gzip.org) |
||||||
*/ |
*/ |
||||||
|
|
||||||
/* Code */ |
/* Code */ |
||||||
#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 "unzip.h" |
#include "unzip.h" |
||||||
|
|
||||||
#define READ_8(adr) ((unsigned char)*(adr)) |
#define READ_8(adr) ((unsigned char)*(adr)) |
||||||
#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) |
#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) |
||||||
#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) |
#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) |
||||||
|
|
||||||
#define WRITE_8(buff, n) do { \ |
#define WRITE_8(buff, n) do { \ |
||||||
*((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
|
*((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
|
||||||
} while(0) |
} while(0) |
||||||
#define WRITE_16(buff, n) do { \ |
#define WRITE_16(buff, n) do { \ |
||||||
WRITE_8((unsigned char*)(buff), n); \
|
WRITE_8((unsigned char*)(buff), n); \
|
||||||
WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
|
WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
|
||||||
} while(0) |
} while(0) |
||||||
#define WRITE_32(buff, n) do { \ |
#define WRITE_32(buff, n) do { \ |
||||||
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
|
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
|
||||||
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
|
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
|
||||||
} while(0) |
} while(0) |
||||||
|
|
||||||
extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) |
extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) |
||||||
const char* file; |
const char* file; |
||||||
const char* fileOut; |
const char* fileOut; |
||||||
const char* fileOutTmp; |
const char* fileOutTmp; |
||||||
uLong* nRecovered; |
uLong* nRecovered; |
||||||
uLong* bytesRecovered; |
uLong* bytesRecovered; |
||||||
{ |
{ |
||||||
int err = Z_OK; |
int err = Z_OK; |
||||||
FILE* fpZip = fopen(file, "rb"); |
FILE* fpZip = fopen(file, "rb"); |
||||||
FILE* fpOut = fopen(fileOut, "wb"); |
FILE* fpOut = fopen(fileOut, "wb"); |
||||||
FILE* fpOutCD = fopen(fileOutTmp, "wb"); |
FILE* fpOutCD = fopen(fileOutTmp, "wb"); |
||||||
if (fpZip != NULL && fpOut != NULL) { |
if (fpZip != NULL && fpOut != NULL) { |
||||||
int entries = 0; |
int entries = 0; |
||||||
uLong totalBytes = 0; |
uLong totalBytes = 0; |
||||||
char header[30]; |
char header[30]; |
||||||
char filename[256]; |
char filename[256]; |
||||||
char extra[1024]; |
char extra[1024]; |
||||||
int offset = 0; |
int offset = 0; |
||||||
int offsetCD = 0; |
int offsetCD = 0; |
||||||
while ( fread(header, 1, 30, fpZip) == 30 ) { |
while ( fread(header, 1, 30, fpZip) == 30 ) { |
||||||
int currentOffset = offset; |
int currentOffset = offset; |
||||||
|
|
||||||
/* File entry */ |
/* File entry */ |
||||||
if (READ_32(header) == 0x04034b50) { |
if (READ_32(header) == 0x04034b50) { |
||||||
unsigned int version = READ_16(header + 4); |
unsigned int version = READ_16(header + 4); |
||||||
unsigned int gpflag = READ_16(header + 6); |
unsigned int gpflag = READ_16(header + 6); |
||||||
unsigned int method = READ_16(header + 8); |
unsigned int method = READ_16(header + 8); |
||||||
unsigned int filetime = READ_16(header + 10); |
unsigned int filetime = READ_16(header + 10); |
||||||
unsigned int filedate = READ_16(header + 12); |
unsigned int filedate = READ_16(header + 12); |
||||||
unsigned int crc = READ_32(header + 14); /* crc */ |
unsigned int crc = READ_32(header + 14); /* crc */ |
||||||
unsigned int cpsize = READ_32(header + 18); /* compressed size */ |
unsigned int cpsize = READ_32(header + 18); /* compressed size */ |
||||||
unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ |
unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ |
||||||
unsigned int fnsize = READ_16(header + 26); /* file name length */ |
unsigned int fnsize = READ_16(header + 26); /* file name length */ |
||||||
unsigned int extsize = READ_16(header + 28); /* extra field length */ |
unsigned int extsize = READ_16(header + 28); /* extra field length */ |
||||||
filename[0] = extra[0] = '\0'; |
filename[0] = extra[0] = '\0'; |
||||||
|
|
||||||
/* Header */ |
/* Header */ |
||||||
if (fwrite(header, 1, 30, fpOut) == 30) { |
if (fwrite(header, 1, 30, fpOut) == 30) { |
||||||
offset += 30; |
offset += 30; |
||||||
} else { |
} else { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
break; |
break; |
||||||
} |
} |
||||||
|
|
||||||
/* Filename */ |
/* Filename */ |
||||||
if (fnsize > 0) { |
if (fnsize > 0) { |
||||||
if (fread(filename, 1, fnsize, fpZip) == fnsize) { |
if (fread(filename, 1, fnsize, fpZip) == fnsize) { |
||||||
if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { |
if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { |
||||||
offset += fnsize; |
offset += fnsize; |
||||||
} else { |
} else { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
break; |
break; |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
break; |
break; |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
err = Z_STREAM_ERROR; |
err = Z_STREAM_ERROR; |
||||||
break; |
break; |
||||||
} |
} |
||||||
|
|
||||||
/* Extra field */ |
/* Extra field */ |
||||||
if (extsize > 0) { |
if (extsize > 0) { |
||||||
if (fread(extra, 1, extsize, fpZip) == extsize) { |
if (fread(extra, 1, extsize, fpZip) == extsize) { |
||||||
if (fwrite(extra, 1, extsize, fpOut) == extsize) { |
if (fwrite(extra, 1, extsize, fpOut) == extsize) { |
||||||
offset += extsize; |
offset += extsize; |
||||||
} else { |
} else { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
break; |
break; |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
break; |
break; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/* Data */ |
/* Data */ |
||||||
{ |
{ |
||||||
int dataSize = cpsize; |
int dataSize = cpsize; |
||||||
if (dataSize == 0) { |
if (dataSize == 0) { |
||||||
dataSize = uncpsize; |
dataSize = uncpsize; |
||||||
} |
} |
||||||
if (dataSize > 0) { |
if (dataSize > 0) { |
||||||
char* data = malloc(dataSize); |
char* data = malloc(dataSize); |
||||||
if (data != NULL) { |
if (data != NULL) { |
||||||
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { |
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { |
||||||
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { |
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { |
||||||
offset += dataSize; |
offset += dataSize; |
||||||
totalBytes += dataSize; |
totalBytes += dataSize; |
||||||
} else { |
} else { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
} |
} |
||||||
free(data); |
free(data); |
||||||
if (err != Z_OK) { |
if (err != Z_OK) { |
||||||
break; |
break; |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
err = Z_MEM_ERROR; |
err = Z_MEM_ERROR; |
||||||
break; |
break; |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/* Central directory entry */ |
/* Central directory entry */ |
||||||
{ |
{ |
||||||
char header[46]; |
char header[46]; |
||||||
char* comment = ""; |
char* comment = ""; |
||||||
int comsize = (int) strlen(comment); |
int comsize = (int) strlen(comment); |
||||||
WRITE_32(header, 0x02014b50); |
WRITE_32(header, 0x02014b50); |
||||||
WRITE_16(header + 4, version); |
WRITE_16(header + 4, version); |
||||||
WRITE_16(header + 6, version); |
WRITE_16(header + 6, version); |
||||||
WRITE_16(header + 8, gpflag); |
WRITE_16(header + 8, gpflag); |
||||||
WRITE_16(header + 10, method); |
WRITE_16(header + 10, method); |
||||||
WRITE_16(header + 12, filetime); |
WRITE_16(header + 12, filetime); |
||||||
WRITE_16(header + 14, filedate); |
WRITE_16(header + 14, filedate); |
||||||
WRITE_32(header + 16, crc); |
WRITE_32(header + 16, crc); |
||||||
WRITE_32(header + 20, cpsize); |
WRITE_32(header + 20, cpsize); |
||||||
WRITE_32(header + 24, uncpsize); |
WRITE_32(header + 24, uncpsize); |
||||||
WRITE_16(header + 28, fnsize); |
WRITE_16(header + 28, fnsize); |
||||||
WRITE_16(header + 30, extsize); |
WRITE_16(header + 30, extsize); |
||||||
WRITE_16(header + 32, comsize); |
WRITE_16(header + 32, comsize); |
||||||
WRITE_16(header + 34, 0); /* disk # */ |
WRITE_16(header + 34, 0); /* disk # */ |
||||||
WRITE_16(header + 36, 0); /* int attrb */ |
WRITE_16(header + 36, 0); /* int attrb */ |
||||||
WRITE_32(header + 38, 0); /* ext attrb */ |
WRITE_32(header + 38, 0); /* ext attrb */ |
||||||
WRITE_32(header + 42, currentOffset); |
WRITE_32(header + 42, currentOffset); |
||||||
/* Header */ |
/* Header */ |
||||||
if (fwrite(header, 1, 46, fpOutCD) == 46) { |
if (fwrite(header, 1, 46, fpOutCD) == 46) { |
||||||
offsetCD += 46; |
offsetCD += 46; |
||||||
|
|
||||||
/* Filename */ |
/* Filename */ |
||||||
if (fnsize > 0) { |
if (fnsize > 0) { |
||||||
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { |
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { |
||||||
offsetCD += fnsize; |
offsetCD += fnsize; |
||||||
} else { |
} else { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
break; |
break; |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
err = Z_STREAM_ERROR; |
err = Z_STREAM_ERROR; |
||||||
break; |
break; |
||||||
} |
} |
||||||
|
|
||||||
/* Extra field */ |
/* Extra field */ |
||||||
if (extsize > 0) { |
if (extsize > 0) { |
||||||
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { |
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { |
||||||
offsetCD += extsize; |
offsetCD += extsize; |
||||||
} else { |
} else { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
break; |
break; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/* Comment field */ |
/* Comment field */ |
||||||
if (comsize > 0) { |
if (comsize > 0) { |
||||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { |
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { |
||||||
offsetCD += comsize; |
offsetCD += comsize; |
||||||
} else { |
} else { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
break; |
break; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
} else { |
} else { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
break; |
break; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/* Success */ |
/* Success */ |
||||||
entries++; |
entries++; |
||||||
|
|
||||||
} else { |
} else { |
||||||
break; |
break; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/* Final central directory */ |
/* Final central directory */ |
||||||
{ |
{ |
||||||
int entriesZip = entries; |
int entriesZip = entries; |
||||||
char header[22]; |
char header[22]; |
||||||
char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
|
char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
|
||||||
int comsize = (int) strlen(comment); |
int comsize = (int) strlen(comment); |
||||||
if (entriesZip > 0xffff) { |
if (entriesZip > 0xffff) { |
||||||
entriesZip = 0xffff; |
entriesZip = 0xffff; |
||||||
} |
} |
||||||
WRITE_32(header, 0x06054b50); |
WRITE_32(header, 0x06054b50); |
||||||
WRITE_16(header + 4, 0); /* disk # */ |
WRITE_16(header + 4, 0); /* disk # */ |
||||||
WRITE_16(header + 6, 0); /* disk # */ |
WRITE_16(header + 6, 0); /* disk # */ |
||||||
WRITE_16(header + 8, entriesZip); /* hack */ |
WRITE_16(header + 8, entriesZip); /* hack */ |
||||||
WRITE_16(header + 10, entriesZip); /* hack */ |
WRITE_16(header + 10, entriesZip); /* hack */ |
||||||
WRITE_32(header + 12, offsetCD); /* size of CD */ |
WRITE_32(header + 12, offsetCD); /* size of CD */ |
||||||
WRITE_32(header + 16, offset); /* offset to CD */ |
WRITE_32(header + 16, offset); /* offset to CD */ |
||||||
WRITE_16(header + 20, comsize); /* comment */ |
WRITE_16(header + 20, comsize); /* comment */ |
||||||
|
|
||||||
/* Header */ |
/* Header */ |
||||||
if (fwrite(header, 1, 22, fpOutCD) == 22) { |
if (fwrite(header, 1, 22, fpOutCD) == 22) { |
||||||
|
|
||||||
/* Comment field */ |
/* Comment field */ |
||||||
if (comsize > 0) { |
if (comsize > 0) { |
||||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { |
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
} else { |
} else { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/* Final merge (file + central directory) */ |
/* Final merge (file + central directory) */ |
||||||
fclose(fpOutCD); |
fclose(fpOutCD); |
||||||
if (err == Z_OK) { |
if (err == Z_OK) { |
||||||
fpOutCD = fopen(fileOutTmp, "rb"); |
fpOutCD = fopen(fileOutTmp, "rb"); |
||||||
if (fpOutCD != NULL) { |
if (fpOutCD != NULL) { |
||||||
int nRead; |
int nRead; |
||||||
char buffer[8192]; |
char buffer[8192]; |
||||||
while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { |
while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { |
||||||
if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { |
if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { |
||||||
err = Z_ERRNO; |
err = Z_ERRNO; |
||||||
break; |
break; |
||||||
} |
} |
||||||
} |
} |
||||||
fclose(fpOutCD); |
fclose(fpOutCD); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/* Close */ |
/* Close */ |
||||||
fclose(fpZip); |
fclose(fpZip); |
||||||
fclose(fpOut); |
fclose(fpOut); |
||||||
|
|
||||||
/* Wipe temporary file */ |
/* Wipe temporary file */ |
||||||
(void)remove(fileOutTmp); |
(void)remove(fileOutTmp); |
||||||
|
|
||||||
/* Number of recovered entries */ |
/* Number of recovered entries */ |
||||||
if (err == Z_OK) { |
if (err == Z_OK) { |
||||||
if (nRecovered != NULL) { |
if (nRecovered != NULL) { |
||||||
*nRecovered = entries; |
*nRecovered = entries; |
||||||
} |
} |
||||||
if (bytesRecovered != NULL) { |
if (bytesRecovered != NULL) { |
||||||
*bytesRecovered = totalBytes; |
*bytesRecovered = totalBytes; |
||||||
} |
} |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
err = Z_STREAM_ERROR; |
err = Z_STREAM_ERROR; |
||||||
} |
} |
||||||
return err; |
return err; |
||||||
} |
} |
||||||
|
@ -1,31 +1,31 @@ |
|||||||
/*
|
/*
|
||||||
Additional tools for Minizip |
Additional tools for Minizip |
||||||
Code: Xavier Roche '2004 |
Code: Xavier Roche '2004 |
||||||
License: Same as ZLIB (www.gzip.org) |
License: Same as ZLIB (www.gzip.org) |
||||||
*/ |
*/ |
||||||
|
|
||||||
#ifndef _zip_tools_H |
#ifndef _zip_tools_H |
||||||
#define _zip_tools_H |
#define _zip_tools_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 |
||||||
|
|
||||||
#include "unzip.h" |
#include "unzip.h" |
||||||
|
|
||||||
/* Repair a ZIP file (missing central directory)
|
/* Repair a ZIP file (missing central directory)
|
||||||
file: file to recover |
file: file to recover |
||||||
fileOut: output file after recovery |
fileOut: output file after recovery |
||||||
fileOutTmp: temporary file name used for recovery |
fileOutTmp: temporary file name used for recovery |
||||||
*/ |
*/ |
||||||
extern int ZEXPORT unzRepair(const char* file,
|
extern int ZEXPORT unzRepair(const char* file,
|
||||||
const char* fileOut,
|
const char* fileOut,
|
||||||
const char* fileOutTmp,
|
const char* fileOutTmp,
|
||||||
uLong* nRecovered, |
uLong* nRecovered, |
||||||
uLong* bytesRecovered); |
uLong* bytesRecovered); |
||||||
|
|
||||||
#endif |
#endif |
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,332 @@ |
|||||||
|
/* zconf.h -- configuration of the zlib compression library
|
||||||
|
* Copyright (C) 1995-2005 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 deflatePrime z_deflatePrime |
||||||
|
# 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 inflateBack z_inflateBack |
||||||
|
# define inflateBackEnd z_inflateBackEnd |
||||||
|
# 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 zError z_zError |
||||||
|
|
||||||
|
# define alloc_func z_alloc_func |
||||||
|
# define free_func z_free_func |
||||||
|
# define in_func z_in_func |
||||||
|
# define out_func z_out_func |
||||||
|
# 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 |
||||||
|
|
||||||
|
#if defined(__MSDOS__) && !defined(MSDOS) |
||||||
|
# define MSDOS |
||||||
|
#endif |
||||||
|
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) |
||||||
|
# define OS2 |
||||||
|
#endif |
||||||
|
#if defined(_WINDOWS) && !defined(WINDOWS) |
||||||
|
# define WINDOWS |
||||||
|
#endif |
||||||
|
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) |
||||||
|
# ifndef WIN32 |
||||||
|
# define WIN32 |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) |
||||||
|
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) |
||||||
|
# ifndef SYS16BIT |
||||||
|
# define SYS16BIT |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
#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). |
||||||
|
*/ |
||||||
|
#ifdef SYS16BIT |
||||||
|
# define MAXSEG_64K |
||||||
|
#endif |
||||||
|
#ifdef MSDOS |
||||||
|
# define UNALIGNED_OK |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifdef __STDC_VERSION__ |
||||||
|
# ifndef STDC |
||||||
|
# define STDC |
||||||
|
# endif |
||||||
|
# if __STDC_VERSION__ >= 199901L |
||||||
|
# ifndef STDC99 |
||||||
|
# define STDC99 |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) |
||||||
|
# define STDC |
||||||
|
#endif |
||||||
|
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) |
||||||
|
# define STDC |
||||||
|
#endif |
||||||
|
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) |
||||||
|
# define STDC |
||||||
|
#endif |
||||||
|
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) |
||||||
|
# define STDC |
||||||
|
#endif |
||||||
|
|
||||||
|
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ |
||||||
|
# define STDC |
||||||
|
#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 |
||||||
|
|
||||||
|
/* 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 |
||||||
|
|
||||||
|
/* 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. |
||||||
|
*/ |
||||||
|
#ifdef SYS16BIT |
||||||
|
# if defined(M_I86SM) || defined(M_I86MM) |
||||||
|
/* MSC small or medium model */ |
||||||
|
# define SMALL_MEDIUM |
||||||
|
# ifdef _MSC_VER |
||||||
|
# define FAR _far |
||||||
|
# else |
||||||
|
# define FAR far |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
# if (defined(__SMALL__) || defined(__MEDIUM__)) |
||||||
|
/* Turbo C small or medium model */ |
||||||
|
# define SMALL_MEDIUM |
||||||
|
# ifdef __BORLANDC__ |
||||||
|
# define FAR _far |
||||||
|
# else |
||||||
|
# define FAR far |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
#if defined(WINDOWS) || defined(WIN32) |
||||||
|
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
||||||
|
* This is not mandatory, but it offers a little performance increase. |
||||||
|
*/ |
||||||
|
# ifdef ZLIB_DLL |
||||||
|
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) |
||||||
|
# ifdef ZLIB_INTERNAL |
||||||
|
# define ZEXTERN extern __declspec(dllexport) |
||||||
|
# else |
||||||
|
# define ZEXTERN extern __declspec(dllimport) |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
# endif /* ZLIB_DLL */ |
||||||
|
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
||||||
|
* define ZLIB_WINAPI. |
||||||
|
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. |
||||||
|
*/ |
||||||
|
# ifdef ZLIB_WINAPI |
||||||
|
# ifdef FAR |
||||||
|
# undef FAR |
||||||
|
# endif |
||||||
|
# include <windows.h> |
||||||
|
/* No need for _export, use ZLIB.DEF instead. */ |
||||||
|
/* For complete Windows compatibility, use WINAPI, not __stdcall. */ |
||||||
|
# define ZEXPORT WINAPI |
||||||
|
# ifdef WIN32 |
||||||
|
# define ZEXPORTVA WINAPIV |
||||||
|
# else |
||||||
|
# define ZEXPORTVA FAR CDECL |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
#if defined (__BEOS__) |
||||||
|
# ifdef ZLIB_DLL |
||||||
|
# ifdef ZLIB_INTERNAL |
||||||
|
# define ZEXPORT __declspec(dllexport) |
||||||
|
# define ZEXPORTVA __declspec(dllexport) |
||||||
|
# else |
||||||
|
# define ZEXPORT __declspec(dllimport) |
||||||
|
# define ZEXPORTVA __declspec(dllimport) |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifndef ZEXTERN |
||||||
|
# define ZEXTERN extern |
||||||
|
#endif |
||||||
|
#ifndef ZEXPORT |
||||||
|
# define ZEXPORT |
||||||
|
#endif |
||||||
|
#ifndef ZEXPORTVA |
||||||
|
# define ZEXPORTVA |
||||||
|
#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 |
||||||
|
|
||||||
|
#if defined(__OS400__) |
||||||
|
# define NO_vsnprintf |
||||||
|
#endif |
||||||
|
|
||||||
|
#if defined(__MVS__) |
||||||
|
# define NO_vsnprintf |
||||||
|
# ifdef FAR |
||||||
|
# undef FAR |
||||||
|
# endif |
||||||
|
#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 */ |
@ -0,0 +1,332 @@ |
|||||||
|
/* zconf.h -- configuration of the zlib compression library
|
||||||
|
* Copyright (C) 1995-2005 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 deflatePrime z_deflatePrime |
||||||
|
# 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 inflateBack z_inflateBack |
||||||
|
# define inflateBackEnd z_inflateBackEnd |
||||||
|
# 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 zError z_zError |
||||||
|
|
||||||
|
# define alloc_func z_alloc_func |
||||||
|
# define free_func z_free_func |
||||||
|
# define in_func z_in_func |
||||||
|
# define out_func z_out_func |
||||||
|
# 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 |
||||||
|
|
||||||
|
#if defined(__MSDOS__) && !defined(MSDOS) |
||||||
|
# define MSDOS |
||||||
|
#endif |
||||||
|
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) |
||||||
|
# define OS2 |
||||||
|
#endif |
||||||
|
#if defined(_WINDOWS) && !defined(WINDOWS) |
||||||
|
# define WINDOWS |
||||||
|
#endif |
||||||
|
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) |
||||||
|
# ifndef WIN32 |
||||||
|
# define WIN32 |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) |
||||||
|
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) |
||||||
|
# ifndef SYS16BIT |
||||||
|
# define SYS16BIT |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
#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). |
||||||
|
*/ |
||||||
|
#ifdef SYS16BIT |
||||||
|
# define MAXSEG_64K |
||||||
|
#endif |
||||||
|
#ifdef MSDOS |
||||||
|
# define UNALIGNED_OK |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifdef __STDC_VERSION__ |
||||||
|
# ifndef STDC |
||||||
|
# define STDC |
||||||
|
# endif |
||||||
|
# if __STDC_VERSION__ >= 199901L |
||||||
|
# ifndef STDC99 |
||||||
|
# define STDC99 |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) |
||||||
|
# define STDC |
||||||
|
#endif |
||||||
|
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) |
||||||
|
# define STDC |
||||||
|
#endif |
||||||
|
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) |
||||||
|
# define STDC |
||||||
|
#endif |
||||||
|
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) |
||||||
|
# define STDC |
||||||
|
#endif |
||||||
|
|
||||||
|
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ |
||||||
|
# define STDC |
||||||
|
#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 |
||||||
|
|
||||||
|
/* 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 |
||||||
|
|
||||||
|
/* 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. |
||||||
|
*/ |
||||||
|
#ifdef SYS16BIT |
||||||
|
# if defined(M_I86SM) || defined(M_I86MM) |
||||||
|
/* MSC small or medium model */ |
||||||
|
# define SMALL_MEDIUM |
||||||
|
# ifdef _MSC_VER |
||||||
|
# define FAR _far |
||||||
|
# else |
||||||
|
# define FAR far |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
# if (defined(__SMALL__) || defined(__MEDIUM__)) |
||||||
|
/* Turbo C small or medium model */ |
||||||
|
# define SMALL_MEDIUM |
||||||
|
# ifdef __BORLANDC__ |
||||||
|
# define FAR _far |
||||||
|
# else |
||||||
|
# define FAR far |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
#if defined(WINDOWS) || defined(WIN32) |
||||||
|
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
||||||
|
* This is not mandatory, but it offers a little performance increase. |
||||||
|
*/ |
||||||
|
# ifdef ZLIB_DLL |
||||||
|
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) |
||||||
|
# ifdef ZLIB_INTERNAL |
||||||
|
# define ZEXTERN extern __declspec(dllexport) |
||||||
|
# else |
||||||
|
# define ZEXTERN extern __declspec(dllimport) |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
# endif /* ZLIB_DLL */ |
||||||
|
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
||||||
|
* define ZLIB_WINAPI. |
||||||
|
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. |
||||||
|
*/ |
||||||
|
# ifdef ZLIB_WINAPI |
||||||
|
# ifdef FAR |
||||||
|
# undef FAR |
||||||
|
# endif |
||||||
|
# include <windows.h> |
||||||
|
/* No need for _export, use ZLIB.DEF instead. */ |
||||||
|
/* For complete Windows compatibility, use WINAPI, not __stdcall. */ |
||||||
|
# define ZEXPORT WINAPI |
||||||
|
# ifdef WIN32 |
||||||
|
# define ZEXPORTVA WINAPIV |
||||||
|
# else |
||||||
|
# define ZEXPORTVA FAR CDECL |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
#if defined (__BEOS__) |
||||||
|
# ifdef ZLIB_DLL |
||||||
|
# ifdef ZLIB_INTERNAL |
||||||
|
# define ZEXPORT __declspec(dllexport) |
||||||
|
# define ZEXPORTVA __declspec(dllexport) |
||||||
|
# else |
||||||
|
# define ZEXPORT __declspec(dllimport) |
||||||
|
# define ZEXPORTVA __declspec(dllimport) |
||||||
|
# endif |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifndef ZEXTERN |
||||||
|
# define ZEXTERN extern |
||||||
|
#endif |
||||||
|
#ifndef ZEXPORT |
||||||
|
# define ZEXPORT |
||||||
|
#endif |
||||||
|
#ifndef ZEXPORTVA |
||||||
|
# define ZEXPORTVA |
||||||
|
#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 |
||||||
|
|
||||||
|
#if defined(__OS400__) |
||||||
|
# define NO_vsnprintf |
||||||
|
#endif |
||||||
|
|
||||||
|
#if defined(__MVS__) |
||||||
|
# define NO_vsnprintf |
||||||
|
# ifdef FAR |
||||||
|
# undef FAR |
||||||
|
# endif |
||||||
|
#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
@ -0,0 +1,29 @@ |
|||||||
|
/* gzclose.c -- zlib gzclose() function
|
||||||
|
* Copyright (C) 2004, 2010 Mark Adler |
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef OLD_GZIO |
||||||
|
|
||||||
|
#include "gzguts.h" |
||||||
|
|
||||||
|
/* gzclose() is in a separate file so that it is linked in only if it is used.
|
||||||
|
That way the other gzclose functions can be used instead to avoid linking in |
||||||
|
unneeded compression or decompression routines. */ |
||||||
|
int ZEXPORT gzclose(file) |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
#ifndef NO_GZCOMPRESS |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
if (file == NULL) |
||||||
|
return EOF; |
||||||
|
state = (gz_statep)file; |
||||||
|
|
||||||
|
return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); |
||||||
|
#else |
||||||
|
return gzclose_r(file); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
#endif /* !OLD_GZIO */ |
@ -0,0 +1,109 @@ |
|||||||
|
/* gzguts.h -- zlib internal header definitions for gz* operations
|
||||||
|
* Copyright (C) 2004, 2005, 2010 Mark Adler |
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifdef _LARGEFILE64_SOURCE |
||||||
|
# ifndef _LARGEFILE_SOURCE |
||||||
|
# define _LARGEFILE_SOURCE |
||||||
|
# endif |
||||||
|
# ifdef _FILE_OFFSET_BITS |
||||||
|
# undef _FILE_OFFSET_BITS |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
#define ZLIB_INTERNAL |
||||||
|
|
||||||
|
#include <stdio.h> |
||||||
|
#include <stdlib.h> |
||||||
|
#include <string.h> |
||||||
|
#include <fcntl.h> |
||||||
|
#include "zlib.h" |
||||||
|
|
||||||
|
#ifdef NO_DEFLATE /* for compatibility with old definition */ |
||||||
|
# define NO_GZCOMPRESS |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifdef WIN32 |
||||||
|
# include <io.h> |
||||||
|
# define vsnprintf _vsnprintf |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifndef local |
||||||
|
# define local static |
||||||
|
#endif |
||||||
|
/* compile with -Dlocal if your debugger can't find static symbols */ |
||||||
|
|
||||||
|
/* gz* functions always use library allocation functions */ |
||||||
|
#ifndef STDC |
||||||
|
extern voidp malloc OF((uInt size)); |
||||||
|
extern void free OF((voidpf ptr)); |
||||||
|
#endif |
||||||
|
|
||||||
|
/* get errno and strerror definition */ |
||||||
|
#if defined UNDER_CE && defined NO_ERRNO_H |
||||||
|
# define zstrerror(errnum) strwinerror((DWORD)errnum) |
||||||
|
#else |
||||||
|
# ifdef STDC |
||||||
|
# include <errno.h> |
||||||
|
# define zstrerror() strerror(errno) |
||||||
|
# else |
||||||
|
# define zstrerror() "stdio error (consult errno)" |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
/* MVS fdopen() */ |
||||||
|
#ifdef __MVS__ |
||||||
|
# pragma map (fdopen , "\174\174FDOPEN") |
||||||
|
FILE *fdopen(int, const char *); |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifdef _LARGEFILE64_SOURCE |
||||||
|
# define z_off64_t off64_t |
||||||
|
#else |
||||||
|
# define z_off64_t z_off_t |
||||||
|
#endif |
||||||
|
|
||||||
|
/* default i/o buffer size -- double this for output when reading */ |
||||||
|
#define GZBUFSIZE 8192 |
||||||
|
|
||||||
|
/* gzip modes, also provide a little integrity check on the passed structure */ |
||||||
|
#define GZ_NONE 0 |
||||||
|
#define GZ_READ 7247 |
||||||
|
#define GZ_WRITE 31153 |
||||||
|
#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ |
||||||
|
|
||||||
|
/* internal gzip file state data structure */ |
||||||
|
typedef struct { |
||||||
|
/* used for both reading and writing */ |
||||||
|
int mode; /* see gzip modes above */ |
||||||
|
int fd; /* file descriptor */ |
||||||
|
char *path; /* path or fd for error messages */ |
||||||
|
z_off64_t pos; /* current position in uncompressed data */ |
||||||
|
unsigned size; /* buffer size, zero if not allocated yet */ |
||||||
|
unsigned want; /* requested buffer size, default is GZBUFSIZE */ |
||||||
|
unsigned char *in; /* input buffer */ |
||||||
|
unsigned char *out; /* output buffer (double-sized when reading) */ |
||||||
|
unsigned char *next; /* next output data to deliver or write */ |
||||||
|
/* just for reading */ |
||||||
|
int how; /* 0: get header, 1: copy, 2: decompress */ |
||||||
|
unsigned have; /* amount of output data unused */ |
||||||
|
z_off64_t start; /* where the gzip data started, for rewinding */ |
||||||
|
z_off64_t raw; /* where the raw data started, for seeking */ |
||||||
|
int eof; /* true if end of input file reached */ |
||||||
|
/* just for writing */ |
||||||
|
int level; /* compression level */ |
||||||
|
int strategy; /* compression strategy */ |
||||||
|
/* seek request */ |
||||||
|
int seek; /* true if seek request pending */ |
||||||
|
z_off64_t skip; /* amount to skip (already rewound if backwards) */ |
||||||
|
/* error information */ |
||||||
|
int err; /* error code */ |
||||||
|
char *msg; /* error message */ |
||||||
|
/* zlib inflate or deflate stream */ |
||||||
|
z_stream strm; /* stream structure in-place (not a pointer) */ |
||||||
|
} gz_state; |
||||||
|
typedef gz_state FAR *gz_statep; |
||||||
|
|
||||||
|
/* shared functions */ |
||||||
|
ZEXTERN void ZEXPORT gz_error OF((gz_statep, int, char *)); |
@ -0,0 +1,513 @@ |
|||||||
|
/* gzlib.c -- zlib functions common to reading and writing gzip files
|
||||||
|
* Copyright (C) 2004, 2010 Mark Adler |
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef OLD_GZIO |
||||||
|
|
||||||
|
#include "gzguts.h" |
||||||
|
|
||||||
|
#ifdef _LARGEFILE64_SOURCE |
||||||
|
# define LSEEK lseek64 |
||||||
|
#else |
||||||
|
# define LSEEK lseek |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Local functions */ |
||||||
|
local void gz_reset OF((gz_statep)); |
||||||
|
local gzFile gz_open OF((const char *, int, const char *, int)); |
||||||
|
|
||||||
|
#if defined UNDER_CE && defined NO_ERRNO_H |
||||||
|
local char *strwinerror OF((DWORD error)); |
||||||
|
|
||||||
|
# include <windows.h> |
||||||
|
|
||||||
|
/* Map the Windows error number in ERROR to a locale-dependent error
|
||||||
|
message string and return a pointer to it. Typically, the values |
||||||
|
for ERROR come from GetLastError. |
||||||
|
|
||||||
|
The string pointed to shall not be modified by the application, |
||||||
|
but may be overwritten by a subsequent call to strwinerror |
||||||
|
|
||||||
|
The strwinerror function does not change the current setting |
||||||
|
of GetLastError. */ |
||||||
|
|
||||||
|
local char *strwinerror (error) |
||||||
|
DWORD error; |
||||||
|
{ |
||||||
|
static char buf[1024]; |
||||||
|
|
||||||
|
wchar_t *msgbuf; |
||||||
|
DWORD lasterr = GetLastError(); |
||||||
|
DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
||||||
|
| FORMAT_MESSAGE_ALLOCATE_BUFFER, |
||||||
|
NULL, |
||||||
|
error, |
||||||
|
0, /* Default language */ |
||||||
|
(LPVOID)&msgbuf, |
||||||
|
0, |
||||||
|
NULL); |
||||||
|
if (chars != 0) { |
||||||
|
/* If there is an \r\n appended, zap it. */ |
||||||
|
if (chars >= 2 |
||||||
|
&& msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { |
||||||
|
chars -= 2; |
||||||
|
msgbuf[chars] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
if (chars > sizeof (buf) - 1) { |
||||||
|
chars = sizeof (buf) - 1; |
||||||
|
msgbuf[chars] = 0; |
||||||
|
} |
||||||
|
|
||||||
|
wcstombs(buf, msgbuf, chars + 1); |
||||||
|
LocalFree(msgbuf); |
||||||
|
} |
||||||
|
else { |
||||||
|
sprintf(buf, "unknown win32 error (%ld)", error); |
||||||
|
} |
||||||
|
|
||||||
|
SetLastError(lasterr); |
||||||
|
return buf; |
||||||
|
} |
||||||
|
|
||||||
|
#endif /* UNDER_CE && NO_ERRNO_H */ |
||||||
|
|
||||||
|
/* Reset gzip file state */ |
||||||
|
local void gz_reset(state) |
||||||
|
gz_statep state; |
||||||
|
{ |
||||||
|
state->how = 0; /* look for gzip header */ |
||||||
|
if (state->mode == GZ_READ) { /* for reading ... */ |
||||||
|
state->have = 0; /* no output data available */ |
||||||
|
state->eof = 0; /* not at end of file */ |
||||||
|
} |
||||||
|
state->seek = 0; /* no seek request pending */ |
||||||
|
gz_error(state, Z_OK, NULL); /* clear error */ |
||||||
|
state->pos = 0; /* no uncompressed data yet */ |
||||||
|
state->strm.avail_in = 0; /* no input data yet */ |
||||||
|
} |
||||||
|
|
||||||
|
/* Open a gzip file either by name or file descriptor. */ |
||||||
|
local gzFile gz_open(path, fd, mode, use64) |
||||||
|
const char *path; |
||||||
|
int fd; |
||||||
|
const char *mode; |
||||||
|
int use64; |
||||||
|
{ |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* allocate gzFile structure to return */ |
||||||
|
state = malloc(sizeof(gz_state)); |
||||||
|
if (state == NULL) |
||||||
|
return NULL; |
||||||
|
state->size = 0; /* no buffers allocated yet */ |
||||||
|
state->want = GZBUFSIZE; /* requested buffer size */ |
||||||
|
state->msg = NULL; /* no error message yet */ |
||||||
|
|
||||||
|
/* interpret mode */ |
||||||
|
state->mode = GZ_NONE; |
||||||
|
state->level = Z_DEFAULT_COMPRESSION; |
||||||
|
state->strategy = Z_DEFAULT_STRATEGY; |
||||||
|
while (*mode) { |
||||||
|
if (*mode >= '0' && *mode <= '9') |
||||||
|
state->level = *mode - '0'; |
||||||
|
else |
||||||
|
switch (*mode) { |
||||||
|
case 'r': |
||||||
|
state->mode = GZ_READ; |
||||||
|
break; |
||||||
|
#ifndef NO_GZCOMPRESS |
||||||
|
case 'w': |
||||||
|
state->mode = GZ_WRITE; |
||||||
|
break; |
||||||
|
case 'a': |
||||||
|
state->mode = GZ_APPEND; |
||||||
|
break; |
||||||
|
#endif |
||||||
|
case '+': /* can't read and write at the same time */ |
||||||
|
free(state); |
||||||
|
return NULL; |
||||||
|
case 'b': /* ignore -- will request binary anyway */ |
||||||
|
break; |
||||||
|
case 'f': |
||||||
|
state->strategy = Z_FILTERED; |
||||||
|
break; |
||||||
|
case 'h': |
||||||
|
state->strategy = Z_HUFFMAN_ONLY; |
||||||
|
break; |
||||||
|
case 'R': |
||||||
|
state->strategy = Z_RLE; |
||||||
|
break; |
||||||
|
case 'F': |
||||||
|
state->strategy = Z_FIXED; |
||||||
|
default: /* could consider as an error, but just ignore */ |
||||||
|
; |
||||||
|
} |
||||||
|
mode++; |
||||||
|
} |
||||||
|
|
||||||
|
/* must provide an "r", "w", or "a" */ |
||||||
|
if (state->mode == GZ_NONE) { |
||||||
|
free(state); |
||||||
|
return NULL; |
||||||
|
} |
||||||
|
|
||||||
|
/* open the file with the appropriate mode (or just use fd) */ |
||||||
|
state->fd = fd != -1 ? fd : |
||||||
|
open(path, |
||||||
|
#ifdef O_LARGEFILE |
||||||
|
(use64 ? O_LARGEFILE : 0) | |
||||||
|
#endif |
||||||
|
#ifdef O_BINARY |
||||||
|
O_BINARY | |
||||||
|
#endif |
||||||
|
(state->mode == GZ_READ ? |
||||||
|
O_RDONLY : |
||||||
|
(O_WRONLY | O_CREAT | ( |
||||||
|
state->mode == GZ_WRITE ? |
||||||
|
O_TRUNC : |
||||||
|
O_APPEND))), |
||||||
|
0666); |
||||||
|
if (state->fd == -1) { |
||||||
|
free(state); |
||||||
|
return NULL; |
||||||
|
} |
||||||
|
if (state->mode == GZ_APPEND) |
||||||
|
state->mode = GZ_WRITE; /* simplify later checks */ |
||||||
|
|
||||||
|
/* save the path name for error messages */ |
||||||
|
state->path = malloc(strlen(path) + 1); |
||||||
|
strcpy(state->path, path); |
||||||
|
|
||||||
|
/* save the current position for rewinding (only if reading) */ |
||||||
|
if (state->mode == GZ_READ) { |
||||||
|
state->start = LSEEK(state->fd, 0, SEEK_CUR); |
||||||
|
if (state->start == -1) state->start = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* initialize stream */ |
||||||
|
gz_reset(state); |
||||||
|
|
||||||
|
/* return stream */ |
||||||
|
return (gzFile)state; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
gzFile ZEXPORT gzopen(path, mode) |
||||||
|
const char *path; |
||||||
|
const char *mode; |
||||||
|
{ |
||||||
|
return gz_open(path, -1, mode, 0); |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
gzFile ZEXPORT gzopen64(path, mode) |
||||||
|
const char *path; |
||||||
|
const char *mode; |
||||||
|
{ |
||||||
|
return gz_open(path, -1, mode, 1); |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
gzFile ZEXPORT gzdopen(fd, mode) |
||||||
|
int fd; |
||||||
|
const char *mode; |
||||||
|
{ |
||||||
|
char path[46]; /* allow up to 128-bit integers, so don't worry --
|
||||||
|
the sprintf() is safe */ |
||||||
|
|
||||||
|
if (fd < 0) |
||||||
|
return NULL; |
||||||
|
sprintf(path, "<fd:%d>", fd); /* for error messages */ |
||||||
|
return gz_open(path, fd, mode, 1); |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzbuffer(file, size) |
||||||
|
gzFile file; |
||||||
|
unsigned size; |
||||||
|
{ |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure and check integrity */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
if (state->mode != GZ_READ && state->mode != GZ_WRITE) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* make sure we haven't already allocated memory */ |
||||||
|
if (state->size != 0) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* check and set requested size */ |
||||||
|
if (size == 0) |
||||||
|
return -1; |
||||||
|
state->want = size; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzrewind(file) |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
|
||||||
|
/* check that we're reading and that there's no error */ |
||||||
|
if (state->mode != GZ_READ || state->err != Z_OK) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* back up and start over */ |
||||||
|
if (LSEEK(state->fd, state->start, SEEK_SET) == -1) |
||||||
|
return -1; |
||||||
|
gz_reset(state); |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
z_off64_t ZEXPORT gzseek64(file, offset, whence) |
||||||
|
gzFile file; |
||||||
|
z_off64_t offset; |
||||||
|
int whence; |
||||||
|
{ |
||||||
|
unsigned n; |
||||||
|
z_off64_t ret; |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure and check integrity */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
if (state->mode != GZ_READ && state->mode != GZ_WRITE) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* check that there's no error */ |
||||||
|
if (state->err != Z_OK) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* can only seek from start or relative to current position */ |
||||||
|
if (whence != SEEK_SET && whence != SEEK_CUR) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* normalize offset to a SEEK_CUR specification */ |
||||||
|
if (whence == SEEK_SET) |
||||||
|
offset -= state->pos; |
||||||
|
|
||||||
|
/* if within raw area while reading, just go there */ |
||||||
|
if (state->mode == GZ_READ && state->how == 1 && |
||||||
|
state->pos + offset >= state->raw) { |
||||||
|
ret = LSEEK(state->fd, offset, SEEK_CUR); |
||||||
|
if (ret == -1) |
||||||
|
return -1; |
||||||
|
state->have = 0; |
||||||
|
state->eof = 0; |
||||||
|
state->seek = 0; |
||||||
|
gz_error(state, Z_OK, NULL); |
||||||
|
state->strm.avail_in = 0; |
||||||
|
state->pos += offset; |
||||||
|
return state->pos; |
||||||
|
} |
||||||
|
|
||||||
|
/* calculate skip amount, rewinding if needed for back seek when reading */ |
||||||
|
if (offset < 0) { |
||||||
|
if (state->mode != GZ_READ) /* writing -- can't go backwards */ |
||||||
|
return -1; |
||||||
|
offset += state->pos; |
||||||
|
if (offset < 0) /* before start of file! */ |
||||||
|
return -1; |
||||||
|
if (gzrewind(file) == -1) /* rewind, then skip to offset */ |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* if reading, skip what's in output buffer (one less gz_getc() check) */ |
||||||
|
if (state->mode == GZ_READ) { |
||||||
|
n = state->have > offset ? (unsigned)offset : state->have; |
||||||
|
state->have -= n; |
||||||
|
state->next += n; |
||||||
|
state->pos += n; |
||||||
|
offset -= n; |
||||||
|
} |
||||||
|
|
||||||
|
/* request skip (if not zero) */ |
||||||
|
if (offset) { |
||||||
|
state->seek = 1; |
||||||
|
state->skip = offset; |
||||||
|
} |
||||||
|
return state->pos + offset; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
z_off_t ZEXPORT gzseek(file, offset, whence) |
||||||
|
gzFile file; |
||||||
|
z_off_t offset; |
||||||
|
int whence; |
||||||
|
{ |
||||||
|
z_off64_t ret; |
||||||
|
|
||||||
|
ret = gzseek64(file, (z_off64_t)offset, whence); |
||||||
|
return ret == (z_off_t)ret ? (z_off_t)ret : -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
z_off64_t ZEXPORT gztell64(file) |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure and check integrity */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
if (state->mode != GZ_READ && state->mode != GZ_WRITE) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* return position */ |
||||||
|
return state->pos + (state->seek ? state->skip : 0); |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
z_off_t ZEXPORT gztell(file) |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
z_off64_t ret; |
||||||
|
|
||||||
|
ret = gztell64(file); |
||||||
|
return ret == (z_off_t)ret ? (z_off_t)ret : -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
z_off64_t ZEXPORT gzoffset64(file) |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
z_off64_t offset; |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure and check integrity */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
if (state->mode != GZ_READ && state->mode != GZ_WRITE) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* compute and return effective offset in file */ |
||||||
|
offset = LSEEK(state->fd, 0, SEEK_CUR); |
||||||
|
if (offset == -1) |
||||||
|
return -1; |
||||||
|
if (state->mode == GZ_READ) /* reading */ |
||||||
|
offset -= state->strm.avail_in; /* don't count buffered input */ |
||||||
|
return offset; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
z_off_t ZEXPORT gzoffset(file) |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
z_off64_t ret; |
||||||
|
|
||||||
|
ret = gzoffset64(file); |
||||||
|
return ret == (z_off_t)ret ? (z_off_t)ret : -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzeof(file) |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure and check integrity */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
if (state->mode != GZ_READ && state->mode != GZ_WRITE) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* return end-of-file state */ |
||||||
|
return state->mode == GZ_READ ? (state->eof && state->have == 0) : 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
const char * ZEXPORT gzerror(file, errnum) |
||||||
|
gzFile file; |
||||||
|
int *errnum; |
||||||
|
{ |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure and check integrity */ |
||||||
|
if (file == NULL) |
||||||
|
return NULL; |
||||||
|
state = (gz_statep)file; |
||||||
|
if (state->mode != GZ_READ && state->mode != GZ_WRITE) |
||||||
|
return NULL; |
||||||
|
|
||||||
|
/* return error information */ |
||||||
|
*errnum = state->err; |
||||||
|
return state->msg == NULL ? "" : state->msg; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
void ZEXPORT gzclearerr(file) |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure and check integrity */ |
||||||
|
if (file == NULL) |
||||||
|
return; |
||||||
|
state = (gz_statep)file; |
||||||
|
if (state->mode != GZ_READ && state->mode != GZ_WRITE) |
||||||
|
return; |
||||||
|
|
||||||
|
/* clear error and end-of-file */ |
||||||
|
if (state->mode == GZ_READ) |
||||||
|
state->eof = 0; |
||||||
|
gz_error(state, Z_OK, NULL); |
||||||
|
} |
||||||
|
|
||||||
|
/* Create an error message in allocated memory and set state->err and
|
||||||
|
state->msg accordingly. Free any previous error message already there. Do |
||||||
|
not try to free or allocate space if the error is Z_MEM_ERROR (out of |
||||||
|
memory). Simply save the error message as a static string. If there is |
||||||
|
an allocation failure constructing the error message, then convert the |
||||||
|
error to out of memory. */ |
||||||
|
void ZEXPORT gz_error(state, err, msg) |
||||||
|
gz_statep state; |
||||||
|
int err; |
||||||
|
char *msg; |
||||||
|
{ |
||||||
|
/* free previously allocated message and clear */ |
||||||
|
if (state->msg != NULL) { |
||||||
|
if (state->err != Z_MEM_ERROR) |
||||||
|
free(state->msg); |
||||||
|
state->msg = NULL; |
||||||
|
} |
||||||
|
|
||||||
|
/* set error code, and if no message, then done */ |
||||||
|
state->err = err; |
||||||
|
if (msg == NULL) |
||||||
|
return; |
||||||
|
|
||||||
|
/* for an out of memory error, save as static string */ |
||||||
|
if (err == Z_MEM_ERROR) { |
||||||
|
state->msg = msg; |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
/* construct error message with path */ |
||||||
|
if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { |
||||||
|
state->err = Z_MEM_ERROR; |
||||||
|
state->msg = "out of memory"; |
||||||
|
return; |
||||||
|
} |
||||||
|
strcpy(state->msg, state->path); |
||||||
|
strcat(state->msg, ": "); |
||||||
|
strcat(state->msg, msg); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
#endif /* !OLD_GZIO */ |
@ -0,0 +1,632 @@ |
|||||||
|
/* gzread.c -- zlib functions for reading gzip files
|
||||||
|
* Copyright (C) 2004, 2005, 2010 Mark Adler |
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef OLD_GZIO |
||||||
|
|
||||||
|
#include "gzguts.h" |
||||||
|
|
||||||
|
/* Local functions */ |
||||||
|
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); |
||||||
|
local int gz_avail OF((gz_statep)); |
||||||
|
local int gz_next4 OF((gz_statep, unsigned long *)); |
||||||
|
local int gz_head OF((gz_statep)); |
||||||
|
local int gz_decomp OF((gz_statep)); |
||||||
|
local int gz_make OF((gz_statep)); |
||||||
|
local int gz_skip OF((gz_statep, z_off_t)); |
||||||
|
|
||||||
|
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
|
||||||
|
state->fd, and update state->eof, state->err, and state->msg as appropriate. |
||||||
|
This function needs to loop on read(), since read() is not guaranteed to |
||||||
|
read the number of bytes requested, depending on the type of descriptor. */ |
||||||
|
local int gz_load(state, buf, len, have) |
||||||
|
gz_statep state; |
||||||
|
unsigned char *buf; |
||||||
|
unsigned len; |
||||||
|
unsigned *have; |
||||||
|
{ |
||||||
|
int ret; |
||||||
|
|
||||||
|
*have = 0; |
||||||
|
do { |
||||||
|
ret = read(state->fd, buf + *have, len - *have); |
||||||
|
if (ret <= 0) |
||||||
|
break; |
||||||
|
*have += ret; |
||||||
|
} while (*have < len); |
||||||
|
if (ret < 0) { |
||||||
|
gz_error(state, Z_ERRNO, zstrerror()); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
if (ret == 0) |
||||||
|
state->eof = 1; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* Load up input buffer and set eof flag if last data loaded -- return -1 on
|
||||||
|
error, 0 otherwise. Note that the eof flag is set when the end of the input |
||||||
|
file is reached, even though there may be unused data in the buffer. Once |
||||||
|
that data has been used, no more attempts will be made to read the file. |
||||||
|
gz_avail() assumes that strm->avail_in == 0. */ |
||||||
|
local int gz_avail(state) |
||||||
|
gz_statep state; |
||||||
|
{ |
||||||
|
z_streamp strm = &(state->strm); |
||||||
|
|
||||||
|
if (state->err != Z_OK) |
||||||
|
return -1; |
||||||
|
if (state->eof == 0) { |
||||||
|
if (gz_load(state, state->in, state->size, &(strm->avail_in)) == -1) |
||||||
|
return -1; |
||||||
|
strm->next_in = state->in; |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* Get next byte from input, or -1 if end or error. */ |
||||||
|
#define NEXT() ((strm->avail_in == 0 && gz_avail(state) == -1) ? -1 : \ |
||||||
|
(strm->avail_in == 0 ? -1 : \
|
||||||
|
(strm->avail_in--, *(strm->next_in)++))) |
||||||
|
|
||||||
|
/* Get a four-byte little-endian integer and return 0 on success and the
|
||||||
|
value in *ret. Otherwise -1 is returned and *ret is not modified. */ |
||||||
|
local int gz_next4(state, ret) |
||||||
|
gz_statep state; |
||||||
|
unsigned long *ret; |
||||||
|
{ |
||||||
|
int ch; |
||||||
|
unsigned long val; |
||||||
|
z_streamp strm = &(state->strm); |
||||||
|
|
||||||
|
val = NEXT(); |
||||||
|
val += (unsigned)NEXT() << 8; |
||||||
|
val += (unsigned long)NEXT() << 16; |
||||||
|
ch = NEXT(); |
||||||
|
if (ch == -1) |
||||||
|
return -1; |
||||||
|
val += (unsigned long)ch << 24; |
||||||
|
*ret = val; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* Look for gzip header, set up for inflate or copy. state->have must be zero.
|
||||||
|
If this is the first time in, allocate required memory. state->how will be |
||||||
|
left unchanged if there is no more input data available, will be set to 1 if |
||||||
|
there is no gzip header and direct copying will be performned, or it will be |
||||||
|
set to 2 for decompression, and the gzip header will be skipped so that the |
||||||
|
next available input data is the raw deflate stream. If direct copying, |
||||||
|
then leftover input data from the input buffer will be copied to the output |
||||||
|
buffer. In that case, all further file reads will be directly to either the |
||||||
|
output buffer or a user buffer. If decompressing, the inflate state and the |
||||||
|
check value will be initialized. gz_head() will return 0 on success or -1 |
||||||
|
on failure. Failures may include read errors or gzip header errors. */ |
||||||
|
local int gz_head(state) |
||||||
|
gz_statep state; |
||||||
|
{ |
||||||
|
z_streamp strm = &(state->strm); |
||||||
|
int flags; |
||||||
|
unsigned len; |
||||||
|
|
||||||
|
/* allocate read buffers and inflate memory */ |
||||||
|
if (state->size == 0) { |
||||||
|
/* allocate buffers */ |
||||||
|
state->in = malloc(state->want); |
||||||
|
state->out = malloc(state->want << 1); |
||||||
|
if (state->in == NULL || state->out == NULL) { |
||||||
|
if (state->out != NULL) |
||||||
|
free(state->out); |
||||||
|
if (state->in != NULL) |
||||||
|
free(state->in); |
||||||
|
gz_error(state, Z_MEM_ERROR, "out of memory"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
state->size = state->want; |
||||||
|
|
||||||
|
/* allocate inflate memory */ |
||||||
|
state->strm.zalloc = Z_NULL; |
||||||
|
state->strm.zfree = Z_NULL; |
||||||
|
state->strm.opaque = Z_NULL; |
||||||
|
state->strm.avail_in = 0; |
||||||
|
state->strm.next_in = Z_NULL; |
||||||
|
if (inflateInit2(&(state->strm), -15) != Z_OK) { /* raw inflate */ |
||||||
|
free(state->out); |
||||||
|
free(state->in); |
||||||
|
state->size = 0; |
||||||
|
gz_error(state, Z_MEM_ERROR, "out of memory"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/* get some data in the input buffer */ |
||||||
|
if (strm->avail_in == 0) { |
||||||
|
if (gz_avail(state) == -1) |
||||||
|
return -1; |
||||||
|
if (strm->avail_in == 0) |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* look for the gzip magic header bytes 31 and 139 */ |
||||||
|
if (strm->next_in[0] == 31) { |
||||||
|
strm->avail_in--; |
||||||
|
strm->next_in++; |
||||||
|
if (strm->avail_in == 0 && gz_avail(state) == -1) |
||||||
|
return -1; |
||||||
|
if (strm->avail_in && strm->next_in[0] == 139) { |
||||||
|
/* we have a gzip header, woo hoo! */ |
||||||
|
strm->avail_in--; |
||||||
|
strm->next_in++; |
||||||
|
|
||||||
|
/* skip rest of header */ |
||||||
|
if (NEXT() != 8) { /* compression method */ |
||||||
|
gz_error(state, Z_DATA_ERROR, "unknown compression method"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
flags = NEXT(); |
||||||
|
if (flags & 0xe0) { /* reserved flag bits */ |
||||||
|
gz_error(state, Z_DATA_ERROR, "unknown header flags set"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
NEXT(); /* modification time */ |
||||||
|
NEXT(); |
||||||
|
NEXT(); |
||||||
|
NEXT(); |
||||||
|
NEXT(); /* extra flags */ |
||||||
|
NEXT(); /* operating system */ |
||||||
|
if (flags & 4) { /* extra field */ |
||||||
|
len = (unsigned)NEXT(); |
||||||
|
len += (unsigned)NEXT() << 8; |
||||||
|
while (len--) |
||||||
|
if (NEXT() < 0) |
||||||
|
break; |
||||||
|
} |
||||||
|
if (flags & 8) /* file name */ |
||||||
|
while (NEXT() > 0) |
||||||
|
; |
||||||
|
if (flags & 16) /* comment */ |
||||||
|
while (NEXT() > 0) |
||||||
|
; |
||||||
|
if (flags & 2) { /* header crc */ |
||||||
|
NEXT(); |
||||||
|
NEXT(); |
||||||
|
} |
||||||
|
|
||||||
|
/* set up for decompression */ |
||||||
|
inflateReset(strm); |
||||||
|
strm->adler = crc32(0L, Z_NULL, 0); |
||||||
|
state->how = 2; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
else { |
||||||
|
/* not a gzip file -- save first byte (31) and fall to raw i/o */ |
||||||
|
state->out[0] = 31; |
||||||
|
state->have = 1; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/* doing raw i/o, save start of raw data for seeking, copy any leftover
|
||||||
|
input to output -- this assumes that the output buffer is larger than |
||||||
|
the input buffer */ |
||||||
|
state->raw = state->pos; |
||||||
|
state->next = state->out; |
||||||
|
if (strm->avail_in) { |
||||||
|
memcpy(state->next + state->have, strm->next_in, strm->avail_in); |
||||||
|
state->have += strm->avail_in; |
||||||
|
strm->avail_in = 0; |
||||||
|
} |
||||||
|
state->how = 1; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* Decompress from input to the provided next_out and avail_out in the state.
|
||||||
|
If the end of the compressed data is reached, then verify the gzip trailer |
||||||
|
check value and length (modulo 2^32). state->have and state->next are |
||||||
|
set to point to the just decompressed data, and the crc is updated. If the |
||||||
|
trailer is verified, state->how is reset to zero to look for the next gzip |
||||||
|
stream or raw data, once state->have is depleted. Returns 0 on success, -1 |
||||||
|
on failure. Failures may include invalid compressed data or a failed gzip |
||||||
|
trailer verification. */ |
||||||
|
local int gz_decomp(state) |
||||||
|
gz_statep state; |
||||||
|
{ |
||||||
|
int ret; |
||||||
|
unsigned had; |
||||||
|
unsigned long crc, len; |
||||||
|
z_streamp strm = &(state->strm); |
||||||
|
|
||||||
|
/* fill output buffer up to end of deflate stream */ |
||||||
|
had = strm->avail_out; |
||||||
|
do { |
||||||
|
/* get more input for inflate() */ |
||||||
|
if (strm->avail_in == 0 && gz_avail(state) == -1) |
||||||
|
return -1; |
||||||
|
if (strm->avail_in == 0) { |
||||||
|
gz_error(state, Z_DATA_ERROR, "unexpected end of file"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* decompress and handle errors */ |
||||||
|
ret = inflate(strm, Z_NO_FLUSH); |
||||||
|
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) { |
||||||
|
gz_error(state, Z_STREAM_ERROR, |
||||||
|
"internal error: inflate stream corrupt"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
if (ret == Z_MEM_ERROR) { |
||||||
|
gz_error(state, Z_MEM_ERROR, "out of memory"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
if (ret == Z_DATA_ERROR) { /* deflate stream invalid */ |
||||||
|
gz_error(state, Z_DATA_ERROR, |
||||||
|
strm->msg == NULL ? "compressed data error" : strm->msg); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
} while (strm->avail_out && ret != Z_STREAM_END); |
||||||
|
|
||||||
|
/* update available output and crc check value */ |
||||||
|
state->have = had - strm->avail_out; |
||||||
|
state->next = strm->next_out - state->have; |
||||||
|
strm->adler = crc32(strm->adler, state->next, state->have); |
||||||
|
|
||||||
|
/* check gzip trailer if at end of deflate stream */ |
||||||
|
if (ret == Z_STREAM_END) { |
||||||
|
if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) { |
||||||
|
gz_error(state, Z_DATA_ERROR, "unexpected end of file"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
if (crc != strm->adler) { |
||||||
|
gz_error(state, Z_DATA_ERROR, "incorrect data check"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
if (len != (strm->total_out & 0xffffffffL)) { |
||||||
|
gz_error(state, Z_DATA_ERROR, "incorrect length check"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
state->how = 0; /* ready for next stream, once have is 0 */ |
||||||
|
} |
||||||
|
|
||||||
|
/* good decompression */ |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* Make data and put in the output buffer. Assumes that state->have == 0.
|
||||||
|
Data is either copied from the input file or decompressed from the input |
||||||
|
file depending on state->how. If state->how is zero, then a gzip header is |
||||||
|
looked for (and skipped if found) to determine wither to copy or decompress. |
||||||
|
Returns -1 on error, otherwise 0. gz_make() will leave state->have non-zero |
||||||
|
unless the end of the input file has been reached and all data has been |
||||||
|
processed. */ |
||||||
|
local int gz_make(state) |
||||||
|
gz_statep state; |
||||||
|
{ |
||||||
|
z_streamp strm = &(state->strm); |
||||||
|
|
||||||
|
if (state->how == 0) { /* look for gzip header */ |
||||||
|
if (gz_head(state) == -1) |
||||||
|
return -1; |
||||||
|
if (state->have) /* got some data from gz_head() */ |
||||||
|
return 0; |
||||||
|
} |
||||||
|
if (state->how == 1) { /* straight copy */ |
||||||
|
if (gz_load(state, state->out, state->size << 1, &(state->have)) == -1) |
||||||
|
return -1; |
||||||
|
state->next = state->out; |
||||||
|
} |
||||||
|
else if (state->how == 2) { /* decompress */ |
||||||
|
strm->avail_out = state->size << 1; |
||||||
|
strm->next_out = state->out; |
||||||
|
if (gz_decomp(state) == -1) |
||||||
|
return -1; |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ |
||||||
|
local int gz_skip(state, len) |
||||||
|
gz_statep state; |
||||||
|
z_off_t len; |
||||||
|
{ |
||||||
|
unsigned n; |
||||||
|
|
||||||
|
/* skip over len bytes or reach end-of-file, whichever comes first */ |
||||||
|
while (len) |
||||||
|
/* skip over whatever is in output buffer */ |
||||||
|
if (state->have) { |
||||||
|
n = state->have > len ? (unsigned)len : state->have; |
||||||
|
state->have -= n; |
||||||
|
state->next += n; |
||||||
|
state->pos += n; |
||||||
|
len -= n; |
||||||
|
} |
||||||
|
|
||||||
|
/* output buffer empty -- return if we're at the end of the input */ |
||||||
|
else if (state->eof && state->strm.avail_in == 0) |
||||||
|
break; |
||||||
|
|
||||||
|
/* need more data to skip -- load up output buffer */ |
||||||
|
else { |
||||||
|
/* get more output, looking for header if required */ |
||||||
|
if (gz_make(state) == -1) |
||||||
|
return -1; |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzread(file, buf, len) |
||||||
|
gzFile file; |
||||||
|
voidp buf; |
||||||
|
unsigned len; |
||||||
|
{ |
||||||
|
unsigned got, n; |
||||||
|
gz_statep state; |
||||||
|
z_streamp strm; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
strm = &(state->strm); |
||||||
|
|
||||||
|
/* check that we're reading and that there's no error */ |
||||||
|
if (state->mode != GZ_READ || state->err != Z_OK) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* process a skip request */ |
||||||
|
if (state->seek) { |
||||||
|
state->seek = 0; |
||||||
|
if (gz_skip(state, state->skip) == -1) |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* get len bytes to buf, or less than len if at the end */ |
||||||
|
got = 0; |
||||||
|
while (len) { |
||||||
|
|
||||||
|
/* first just try copying data from the output buffer */ |
||||||
|
if (state->have) { |
||||||
|
n = state->have > len ? len : state->have; |
||||||
|
memcpy(buf, state->next, n); |
||||||
|
state->next += n; |
||||||
|
state->have -= n; |
||||||
|
} |
||||||
|
|
||||||
|
/* output buffer empty -- return if we're at the end of the input */ |
||||||
|
else if (state->eof && strm->avail_in == 0) |
||||||
|
break; |
||||||
|
|
||||||
|
/* need output data -- for small len or new stream load up our output
|
||||||
|
buffer */ |
||||||
|
else if (state->how == 0 || len < (state->size << 1)) { |
||||||
|
/* get more output, looking for header if required */ |
||||||
|
if (gz_make(state) == -1) |
||||||
|
return -1; |
||||||
|
continue; /* no progress yet -- go back to memcpy() above */ |
||||||
|
} |
||||||
|
|
||||||
|
/* large len -- read directly into user buffer */ |
||||||
|
else if (state->how == 1) { /* read directly */ |
||||||
|
if (gz_load(state, buf, len, &n) == -1) |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* large len -- decompress directly into user buffer */ |
||||||
|
else { /* state->how == 2 */ |
||||||
|
strm->avail_out = len; |
||||||
|
strm->next_out = buf; |
||||||
|
if (gz_decomp(state) == -1) |
||||||
|
return -1; |
||||||
|
n = state->have; |
||||||
|
state->have = 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* update progress */ |
||||||
|
len -= n; |
||||||
|
buf += n; |
||||||
|
got += n; |
||||||
|
state->pos += n; |
||||||
|
} |
||||||
|
|
||||||
|
/* return number of bytes read into user buffer */ |
||||||
|
return (int)got; /* len had better fit in int -- interface flaw */ |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzgetc(file) |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
int ret; |
||||||
|
unsigned char buf[1]; |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
|
||||||
|
/* check that we're reading and that there's no error */ |
||||||
|
if (state->mode != GZ_READ || state->err != Z_OK) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* try output buffer */ |
||||||
|
if (state->have) { |
||||||
|
state->have--; |
||||||
|
state->pos++; |
||||||
|
return *(state->next)++; |
||||||
|
} |
||||||
|
|
||||||
|
/* nothing there -- try gzread() */ |
||||||
|
ret = gzread(file, buf, 1); |
||||||
|
return ret < 1 ? -1 : buf[0]; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzungetc(c, file) |
||||||
|
int c; |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
|
||||||
|
/* check that we're reading and that there's no error */ |
||||||
|
if (state->mode != GZ_READ || state->err != Z_OK) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* process a skip request */ |
||||||
|
if (state->seek) { |
||||||
|
state->seek = 0; |
||||||
|
if (gz_skip(state, state->skip) == -1) |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* can't push EOF */ |
||||||
|
if (c < 0) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* if output buffer empty, put byte at end (allows more pushing) */ |
||||||
|
if (state->have == 0) { |
||||||
|
state->have = 1; |
||||||
|
state->next = state->out + (state->size << 1) - 1; |
||||||
|
state->next[0] = c; |
||||||
|
state->pos--; |
||||||
|
return c; |
||||||
|
} |
||||||
|
|
||||||
|
/* if no room, give up (must have already done a gz_ungetc()) */ |
||||||
|
if (state->have == (state->size << 1)) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* slide output data if needed and insert byte before existing data */ |
||||||
|
if (state->next == state->out) { |
||||||
|
unsigned char *src = state->out + state->have; |
||||||
|
unsigned char *dest = state->out + (state->size << 1); |
||||||
|
while (src > state->out) |
||||||
|
*--dest = *--src; |
||||||
|
state->next = dest; |
||||||
|
} |
||||||
|
state->have++; |
||||||
|
state->next--; |
||||||
|
state->next[0] = c; |
||||||
|
state->pos--; |
||||||
|
return c; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
char * ZEXPORT gzgets(file, buf, len) |
||||||
|
gzFile file; |
||||||
|
char *buf; |
||||||
|
int len; |
||||||
|
{ |
||||||
|
unsigned left, n; |
||||||
|
char *str; |
||||||
|
unsigned char *eol; |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return NULL; |
||||||
|
state = (gz_statep)file; |
||||||
|
|
||||||
|
/* check that we're reading and that there's no error */ |
||||||
|
if (state->mode != GZ_READ || state->err != Z_OK) |
||||||
|
return NULL; |
||||||
|
|
||||||
|
/* process a skip request */ |
||||||
|
if (state->seek) { |
||||||
|
state->seek = 0; |
||||||
|
if (gz_skip(state, state->skip) == -1) |
||||||
|
return NULL; |
||||||
|
} |
||||||
|
|
||||||
|
/* check for a dumb length */ |
||||||
|
if (len < 2) |
||||||
|
return NULL; |
||||||
|
|
||||||
|
/* copy output bytes up to new line or len - 1, whichever comes first --
|
||||||
|
append a terminating zero to the string (we don't check for a zero in |
||||||
|
the contents, let the user worry about that) */ |
||||||
|
str = buf; |
||||||
|
left = (unsigned)len - 1; |
||||||
|
do { |
||||||
|
/* assure that something is in the output buffer */ |
||||||
|
if (state->have == 0) { |
||||||
|
if (gz_make(state) == -1) |
||||||
|
return NULL; /* error */ |
||||||
|
if (state->have == 0) { /* end of file */ |
||||||
|
if (buf == str) /* got bupkus */ |
||||||
|
return NULL; |
||||||
|
break; /* got something -- return it */ |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/* look for end-of-line in current output buffer */ |
||||||
|
n = state->have > left ? left : state->have; |
||||||
|
eol = memchr(state->next, '\n', n); |
||||||
|
if (eol != NULL) |
||||||
|
n = (eol - state->next) + 1; |
||||||
|
|
||||||
|
/* copy through end-of-line, or remainder if not found */ |
||||||
|
memcpy(buf, state->next, n); |
||||||
|
state->have -= n; |
||||||
|
state->next += n; |
||||||
|
state->pos += n; |
||||||
|
left -= n; |
||||||
|
buf += n; |
||||||
|
} while (left && eol == NULL); |
||||||
|
|
||||||
|
/* found end-of-line or out of space -- terminate string and return it */ |
||||||
|
buf[0] = 0; |
||||||
|
return str; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzdirect(file) |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return 0; |
||||||
|
state = (gz_statep)file; |
||||||
|
|
||||||
|
/* check that we're reading */ |
||||||
|
if (state->mode != GZ_READ) |
||||||
|
return 0; |
||||||
|
|
||||||
|
/* return true if reading without decompression */ |
||||||
|
return state->how == 1; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzclose_r(file) |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return Z_STREAM_ERROR; |
||||||
|
state = (gz_statep)file; |
||||||
|
|
||||||
|
/* check that we're reading */ |
||||||
|
if (state->mode != GZ_READ) |
||||||
|
return Z_STREAM_ERROR; |
||||||
|
|
||||||
|
/* free memory and close file */ |
||||||
|
if (state->size) { |
||||||
|
inflateEnd(&(state->strm)); |
||||||
|
free(state->out); |
||||||
|
free(state->in); |
||||||
|
} |
||||||
|
gz_error(state, Z_OK, NULL); |
||||||
|
close(state->fd); |
||||||
|
free(state); |
||||||
|
return Z_OK; |
||||||
|
} |
||||||
|
|
||||||
|
#endif /* !OLD_GZIO */ |
@ -0,0 +1,529 @@ |
|||||||
|
/* gzwrite.c -- zlib functions for writing gzip files
|
||||||
|
* Copyright (C) 2004, 2005, 2010 Mark Adler |
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef OLD_GZIO |
||||||
|
|
||||||
|
#include "gzguts.h" |
||||||
|
|
||||||
|
/* Local functions */ |
||||||
|
local int gz_init OF((gz_statep)); |
||||||
|
local int gz_comp OF((gz_statep, int)); |
||||||
|
local int gz_zero OF((gz_statep, z_off_t)); |
||||||
|
|
||||||
|
/* Initialize state for writing a gzip file. Mark initialization by setting
|
||||||
|
state->size to non-zero. Return -1 on failure or 0 on success. */ |
||||||
|
local int gz_init(state) |
||||||
|
gz_statep state; |
||||||
|
{ |
||||||
|
int ret; |
||||||
|
z_streamp strm = &(state->strm); |
||||||
|
|
||||||
|
/* check version of zlib -- need 1.2.1 or later for gzip deflate() */ |
||||||
|
#ifdef ZLIB_VERNUM |
||||||
|
if (ZLIB_VERNUM < 0x1210) |
||||||
|
#endif |
||||||
|
{ |
||||||
|
gz_error(state, Z_VERSION_ERROR, "need zlib 1.2.1 or later"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* allocate input and output buffers */ |
||||||
|
state->in = malloc(state->want); |
||||||
|
state->out = malloc(state->want); |
||||||
|
if (state->in == NULL || state->out == NULL) { |
||||||
|
if (state->out != NULL) |
||||||
|
free(state->out); |
||||||
|
if (state->in != NULL) |
||||||
|
free(state->in); |
||||||
|
gz_error(state, Z_MEM_ERROR, "out of memory"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* allocate deflate memory, set up for gzip compression */ |
||||||
|
strm->zalloc = Z_NULL; |
||||||
|
strm->zfree = Z_NULL; |
||||||
|
strm->opaque = Z_NULL; |
||||||
|
ret = deflateInit2(strm, state->level, Z_DEFLATED, |
||||||
|
15 + 16, 8, state->strategy); |
||||||
|
if (ret != Z_OK) { |
||||||
|
free(state->in); |
||||||
|
gz_error(state, Z_MEM_ERROR, "out of memory"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* mark state as initialized */ |
||||||
|
state->size = state->want; |
||||||
|
|
||||||
|
/* initialize write buffer */ |
||||||
|
strm->avail_out = state->size; |
||||||
|
strm->next_out = state->out; |
||||||
|
state->next = strm->next_out; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* Compress whatever is at avail_in and next_in and write to the output file.
|
||||||
|
Return -1 if there is an error writing to the output file, otherwise 0. |
||||||
|
flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, |
||||||
|
then the deflate() state is reset to start a new gzip stream. */ |
||||||
|
local int gz_comp(state, flush) |
||||||
|
gz_statep state; |
||||||
|
int flush; |
||||||
|
{ |
||||||
|
int ret; |
||||||
|
unsigned have; |
||||||
|
z_streamp strm = &(state->strm); |
||||||
|
|
||||||
|
/* allocate memory if this is the first time through */ |
||||||
|
if (state->size == 0 && gz_init(state) == -1) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* run deflate() on provided input until it produces no more output */ |
||||||
|
ret = Z_OK; |
||||||
|
do { |
||||||
|
/* write out current buffer contents if full, or if flushing, but if
|
||||||
|
doing Z_FINISH then don't write until we get to Z_STREAM_END */ |
||||||
|
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && |
||||||
|
(flush != Z_FINISH || ret == Z_STREAM_END))) { |
||||||
|
have = strm->next_out - state->next; |
||||||
|
if (have && write(state->fd, state->next, have) != have) { |
||||||
|
gz_error(state, Z_ERRNO, zstrerror()); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
if (strm->avail_out == 0) { |
||||||
|
strm->avail_out = state->size; |
||||||
|
strm->next_out = state->out; |
||||||
|
} |
||||||
|
state->next = strm->next_out; |
||||||
|
} |
||||||
|
|
||||||
|
/* compress */ |
||||||
|
have = strm->avail_out; |
||||||
|
ret = deflate(strm, flush); |
||||||
|
if (ret == Z_STREAM_ERROR) { |
||||||
|
gz_error(state, Z_STREAM_ERROR, |
||||||
|
"internal error: deflate stream corrupt"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
have -= strm->avail_out; |
||||||
|
} while (have); |
||||||
|
|
||||||
|
/* if that completed a deflate stream, allow another to start */ |
||||||
|
if (flush == Z_FINISH) |
||||||
|
deflateReset(strm); |
||||||
|
|
||||||
|
/* all done, no errors */ |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* Compress len zeros to output. Return -1 on error, 0 on success. */ |
||||||
|
local int gz_zero(state, len) |
||||||
|
gz_statep state; |
||||||
|
z_off_t len; |
||||||
|
{ |
||||||
|
int first; |
||||||
|
unsigned n; |
||||||
|
z_streamp strm = &(state->strm); |
||||||
|
|
||||||
|
/* consume whatever's left in the input buffer */ |
||||||
|
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* compress len zeros */ |
||||||
|
first = 1; |
||||||
|
while (len) { |
||||||
|
n = len < state->size ? (unsigned)len : state->size; |
||||||
|
if (first) { |
||||||
|
memset(state->in, 0, n); |
||||||
|
first = 0; |
||||||
|
} |
||||||
|
strm->avail_in = n; |
||||||
|
strm->next_in = state->in; |
||||||
|
state->pos += n; |
||||||
|
if (gz_comp(state, Z_NO_FLUSH) == -1) |
||||||
|
return -1; |
||||||
|
len -= n; |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzwrite(file, buf, len) |
||||||
|
gzFile file; |
||||||
|
voidpc buf; |
||||||
|
unsigned len; |
||||||
|
{ |
||||||
|
unsigned put = len; |
||||||
|
unsigned n; |
||||||
|
gz_statep state; |
||||||
|
z_streamp strm; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
strm = &(state->strm); |
||||||
|
|
||||||
|
/* check that we're writing and that there's no error */ |
||||||
|
if (state->mode != GZ_WRITE || state->err != Z_OK) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* allocate memory if this is the first time through */ |
||||||
|
if (state->size == 0 && gz_init(state) == -1) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* check for seek request */ |
||||||
|
if (state->seek) { |
||||||
|
state->seek = 0; |
||||||
|
if (gz_zero(state, state->skip) == -1) |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* for small len, copy to input buffer, otherwise compress directly */ |
||||||
|
if (len < state->size) { |
||||||
|
/* copy to input buffer, compress when full */ |
||||||
|
while (len) { |
||||||
|
if (strm->avail_in == 0) |
||||||
|
strm->next_in = state->in; |
||||||
|
n = state->size - strm->avail_in; |
||||||
|
if (n > len) |
||||||
|
n = len; |
||||||
|
memcpy(strm->next_in + strm->avail_in, buf, n); |
||||||
|
strm->avail_in += n; |
||||||
|
state->pos += n; |
||||||
|
buf += n; |
||||||
|
len -= n; |
||||||
|
if (len && gz_comp(state, Z_NO_FLUSH) == -1) |
||||||
|
return -1; |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
/* consume whatever's left in the input buffer */ |
||||||
|
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* directly compress user buffer to file */ |
||||||
|
strm->avail_in = len; |
||||||
|
strm->next_in = (voidp)buf; |
||||||
|
state->pos += len; |
||||||
|
if (gz_comp(state, Z_NO_FLUSH) == -1) |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* input was all buffered or compressed */ |
||||||
|
return (int)put; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzputc(file, c) |
||||||
|
gzFile file; |
||||||
|
int c; |
||||||
|
{ |
||||||
|
unsigned char buf[1]; |
||||||
|
gz_statep state; |
||||||
|
z_streamp strm; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
strm = &(state->strm); |
||||||
|
|
||||||
|
/* check that we're writing and that there's no error */ |
||||||
|
if (state->mode != GZ_WRITE || state->err != Z_OK) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* check for seek request */ |
||||||
|
if (state->seek) { |
||||||
|
state->seek = 0; |
||||||
|
if (gz_zero(state, state->skip) == -1) |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* try writing to input buffer for speed (state->size == 0 if buffer not
|
||||||
|
initialized) */ |
||||||
|
if (strm->avail_in < state->size) { |
||||||
|
if (strm->avail_in == 0) |
||||||
|
strm->next_in = state->in; |
||||||
|
strm->next_in[strm->avail_in++] = c; |
||||||
|
state->pos++; |
||||||
|
return c; |
||||||
|
} |
||||||
|
|
||||||
|
/* no room in buffer or not initialized, use gz_write() */ |
||||||
|
buf[0] = c; |
||||||
|
if (gzwrite(file, buf, 1) != 1) |
||||||
|
return -1; |
||||||
|
return c; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzputs(file, str) |
||||||
|
gzFile file; |
||||||
|
const char *str; |
||||||
|
{ |
||||||
|
/* write string */ |
||||||
|
return gzwrite(file, str, strlen(str)); |
||||||
|
} |
||||||
|
|
||||||
|
#ifdef STDC |
||||||
|
#include <stdarg.h> |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORTVA gzprintf (gzFile file, const char *format, ...) |
||||||
|
{ |
||||||
|
int size, len; |
||||||
|
gz_statep state; |
||||||
|
z_streamp strm; |
||||||
|
va_list va; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
strm = &(state->strm); |
||||||
|
|
||||||
|
/* check that we're writing and that there's no error */ |
||||||
|
if (state->mode != GZ_WRITE || state->err != Z_OK) |
||||||
|
return 0; |
||||||
|
|
||||||
|
/* make sure we have some buffer space */ |
||||||
|
if (state->size == 0 && gz_init(state) == -1) |
||||||
|
return 0; |
||||||
|
|
||||||
|
/* check for seek request */ |
||||||
|
if (state->seek) { |
||||||
|
state->seek = 0; |
||||||
|
if (gz_zero(state, state->skip) == -1) |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* consume whatever's left in the input buffer */ |
||||||
|
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) |
||||||
|
return 0; |
||||||
|
|
||||||
|
/* do the printf() into the input buffer, put length in len */ |
||||||
|
size = (int)(state->size); |
||||||
|
state->in[size - 1] = 0; |
||||||
|
va_start(va, format); |
||||||
|
#ifdef NO_vsnprintf |
||||||
|
# ifdef HAS_vsprintf_void |
||||||
|
(void)vsprintf(state->in, format, va); |
||||||
|
va_end(va); |
||||||
|
for (len = 0; len < state->in; len++) |
||||||
|
if (state->in[len] == 0) break; |
||||||
|
# else |
||||||
|
len = vsprintf(state->in, format, va); |
||||||
|
va_end(va); |
||||||
|
# endif |
||||||
|
#else |
||||||
|
# ifdef HAS_vsnprintf_void |
||||||
|
(void)vsnprintf(state->in, size, format, va); |
||||||
|
va_end(va); |
||||||
|
len = strlen(state->in); |
||||||
|
# else |
||||||
|
len = vsnprintf((char *)(state->in), size, format, va); |
||||||
|
va_end(va); |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
/* check that printf() results fit in buffer */ |
||||||
|
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) |
||||||
|
return 0; |
||||||
|
|
||||||
|
/* write out result of printf() */ |
||||||
|
strm->avail_in = (unsigned)len; |
||||||
|
strm->next_in = state->in; |
||||||
|
state->pos += len; |
||||||
|
if (gz_comp(state, Z_NO_FLUSH) == -1) |
||||||
|
return 0; |
||||||
|
return len; |
||||||
|
} |
||||||
|
|
||||||
|
#else /* !STDC */ |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, |
||||||
|
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||||||
|
gzFile file; |
||||||
|
const char *format; |
||||||
|
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, |
||||||
|
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; |
||||||
|
{ |
||||||
|
int size, len; |
||||||
|
gz_statep state; |
||||||
|
z_streamp strm; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
strm = &(state->strm); |
||||||
|
|
||||||
|
/* check that we're writing and that there's no error */ |
||||||
|
if (state->mode != GZ_WRITE || state->err != Z_OK) |
||||||
|
return 0; |
||||||
|
|
||||||
|
/* make sure we have some buffer space */ |
||||||
|
if (state->size == 0 && gz_init(state) == -1) |
||||||
|
return 0; |
||||||
|
|
||||||
|
/* check for seek request */ |
||||||
|
if (state->seek) { |
||||||
|
state->seek = 0; |
||||||
|
if (gz_zero(state, state->skip) == -1) |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/* consume whatever's left in the input buffer */ |
||||||
|
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) |
||||||
|
return 0; |
||||||
|
|
||||||
|
/* do the printf() into the input buffer, put length in len */ |
||||||
|
size = (int)(state->size); |
||||||
|
state->in[size - 1] = 0; |
||||||
|
#ifdef NO_snprintf |
||||||
|
# ifdef HAS_sprintf_void |
||||||
|
sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8, |
||||||
|
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); |
||||||
|
for (len = 0; len < size; len++) |
||||||
|
if (state->in[len] == 0) break; |
||||||
|
# else |
||||||
|
len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8, |
||||||
|
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); |
||||||
|
# endif |
||||||
|
#else |
||||||
|
# ifdef HAS_snprintf_void |
||||||
|
snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8, |
||||||
|
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); |
||||||
|
len = strlen(state->in); |
||||||
|
# else |
||||||
|
len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8, |
||||||
|
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); |
||||||
|
# endif |
||||||
|
#endif |
||||||
|
|
||||||
|
/* check that printf() results fit in buffer */ |
||||||
|
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) |
||||||
|
return 0; |
||||||
|
|
||||||
|
/* write out result of printf() */ |
||||||
|
strm->avail_in = (unsigned)len; |
||||||
|
strm->next_in = state->in; |
||||||
|
state->pos += len; |
||||||
|
if (gz_comp(state, Z_NO_FLUSH) == -1) |
||||||
|
return 0; |
||||||
|
return len; |
||||||
|
} |
||||||
|
|
||||||
|
#endif |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzflush(file, flush) |
||||||
|
gzFile file; |
||||||
|
int flush; |
||||||
|
{ |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return -1; |
||||||
|
state = (gz_statep)file; |
||||||
|
|
||||||
|
/* check that we're writing and that there's no error */ |
||||||
|
if (state->mode != GZ_WRITE|| state->err != Z_OK) |
||||||
|
|
||||||
|
/* check flush parameter */ |
||||||
|
if (flush < 0 || flush > Z_FINISH) |
||||||
|
return Z_STREAM_ERROR; |
||||||
|
|
||||||
|
/* check for seek request */ |
||||||
|
if (state->seek) { |
||||||
|
state->seek = 0; |
||||||
|
if (gz_zero(state, state->skip) == -1) |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* compress remaining data with requested flush */ |
||||||
|
gz_comp(state, flush); |
||||||
|
return state->err; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzsetparams(file, level, strategy) |
||||||
|
gzFile file; |
||||||
|
int level; |
||||||
|
int strategy; |
||||||
|
{ |
||||||
|
gz_statep state; |
||||||
|
z_streamp strm; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return Z_STREAM_ERROR; |
||||||
|
state = (gz_statep)file; |
||||||
|
strm = &(state->strm); |
||||||
|
|
||||||
|
/* check that we're writing and that there's no error */ |
||||||
|
if (state->mode != GZ_WRITE || state->err != Z_OK) |
||||||
|
return Z_STREAM_ERROR; |
||||||
|
|
||||||
|
/* if no change is requested, then do nothing */ |
||||||
|
if (level == state->level && strategy == state->strategy) |
||||||
|
return Z_OK; |
||||||
|
|
||||||
|
/* check for seek request */ |
||||||
|
if (state->seek) { |
||||||
|
state->seek = 0; |
||||||
|
if (gz_zero(state, state->skip) == -1) |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* change compression parameters for subsequent input */ |
||||||
|
if (state->size) { |
||||||
|
/* flush previous input with previous parameters before changing */ |
||||||
|
if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) |
||||||
|
return state->err; |
||||||
|
deflateParams(strm, level, strategy); |
||||||
|
} |
||||||
|
state->level = level; |
||||||
|
state->strategy = strategy; |
||||||
|
return Z_OK; |
||||||
|
} |
||||||
|
|
||||||
|
/* -- see zlib.h -- */ |
||||||
|
int ZEXPORT gzclose_w(file) |
||||||
|
gzFile file; |
||||||
|
{ |
||||||
|
int ret; |
||||||
|
gz_statep state; |
||||||
|
|
||||||
|
/* get internal structure */ |
||||||
|
if (file == NULL) |
||||||
|
return Z_STREAM_ERROR; |
||||||
|
state = (gz_statep)file; |
||||||
|
|
||||||
|
/* check that we're writing */ |
||||||
|
if (state->mode != GZ_WRITE) |
||||||
|
return Z_STREAM_ERROR; |
||||||
|
|
||||||
|
/* check for seek request */ |
||||||
|
if (state->seek) { |
||||||
|
state->seek = 0; |
||||||
|
if (gz_zero(state, state->skip) == -1) |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
/* flush, free memory, and close file */ |
||||||
|
ret = gz_comp(state, Z_FINISH); |
||||||
|
deflateEnd(&(state->strm)); |
||||||
|
free(state->out); |
||||||
|
free(state->in); |
||||||
|
ret += close(state->fd); |
||||||
|
gz_error(state, Z_OK, NULL); |
||||||
|
free(state); |
||||||
|
return ret ? Z_ERRNO : Z_OK; |
||||||
|
} |
||||||
|
|
||||||
|
#endif /* !OLD_GZIO */ |
@ -0,0 +1,141 @@ |
|||||||
|
# Makefile for zlib, derived from Makefile.dj2.
|
||||||
|
# Modified for mingw32 by C. Spieler, 6/16/98.
|
||||||
|
# Updated for zlib 1.2.x by Christian Spieler and Cosmin Truta, Mar-2003.
|
||||||
|
# Last updated: 1-Aug-2003.
|
||||||
|
# Tested under Cygwin and MinGW.
|
||||||
|
|
||||||
|
# Copyright (C) 1995-2003 Jean-loup Gailly.
|
||||||
|
# For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
|
||||||
|
# To compile, or to compile and test, type:
|
||||||
|
#
|
||||||
|
# make -fmakefile.gcc; make test testdll -fmakefile.gcc
|
||||||
|
#
|
||||||
|
# To use the asm code, type:
|
||||||
|
# cp contrib/asm?86/match.S ./match.S
|
||||||
|
# make LOC=-DASMV OBJA=match.o -fmakefile.gcc
|
||||||
|
#
|
||||||
|
# To install libz.a, zconf.h and zlib.h in the system directories, type:
|
||||||
|
#
|
||||||
|
# make install -fmakefile.gcc
|
||||||
|
|
||||||
|
# Note:
|
||||||
|
# If the platform is *not* MinGW (e.g. it is Cygwin or UWIN),
|
||||||
|
# the DLL name should be changed from "zlib1.dll".
|
||||||
|
|
||||||
|
STATICLIB = libz.a
|
||||||
|
SHAREDLIB = zlib1.dll
|
||||||
|
IMPLIB = libzdll.a
|
||||||
|
|
||||||
|
#LOC = -DASMV
|
||||||
|
#LOC = -DDEBUG -g
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
CFLAGS = $(LOC) -O3 -Wall
|
||||||
|
|
||||||
|
AS = $(CC)
|
||||||
|
ASFLAGS = $(LOC) -Wall
|
||||||
|
|
||||||
|
LD = $(CC)
|
||||||
|
LDFLAGS = $(LOC) -s
|
||||||
|
|
||||||
|
AR = ar
|
||||||
|
ARFLAGS = rcs
|
||||||
|
|
||||||
|
RC = windres
|
||||||
|
RCFLAGS = --define GCC_WINDRES
|
||||||
|
|
||||||
|
CP = cp -fp
|
||||||
|
# If GNU install is available, replace $(CP) with install.
|
||||||
|
INSTALL = $(CP)
|
||||||
|
RM = rm -f
|
||||||
|
|
||||||
|
prefix = /usr/local
|
||||||
|
exec_prefix = $(prefix)
|
||||||
|
|
||||||
|
OBJS = adler32.o compress.o crc32.o deflate.o gzio.o infback.o \
|
||||||
|
inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
|
||||||
|
OBJA =
|
||||||
|
|
||||||
|
all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example minigzip example_d minigzip_d |
||||||
|
|
||||||
|
test: example minigzip |
||||||
|
./example
|
||||||
|
echo hello world | ./minigzip | ./minigzip -d
|
||||||
|
|
||||||
|
testdll: example_d minigzip_d |
||||||
|
./example_d
|
||||||
|
echo hello world | ./minigzip_d | ./minigzip_d -d
|
||||||
|
|
||||||
|
.c.o: |
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
.S.o: |
||||||
|
$(AS) $(ASFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
$(STATICLIB): $(OBJS) $(OBJA) |
||||||
|
$(AR) $(ARFLAGS) $@ $(OBJS) $(OBJA)
|
||||||
|
|
||||||
|
$(IMPLIB): $(SHAREDLIB) |
||||||
|
|
||||||
|
$(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlibrc.o |
||||||
|
dllwrap --driver-name $(CC) --def win32/zlib.def \
|
||||||
|
--implib $(IMPLIB) -o $@ $(OBJS) $(OBJA) zlibrc.o
|
||||||
|
strip $@
|
||||||
|
|
||||||
|
example: example.o $(STATICLIB) |
||||||
|
$(LD) $(LDFLAGS) -o $@ example.o $(STATICLIB)
|
||||||
|
|
||||||
|
minigzip: minigzip.o $(STATICLIB) |
||||||
|
$(LD) $(LDFLAGS) -o $@ minigzip.o $(STATICLIB)
|
||||||
|
|
||||||
|
example_d: example.o $(IMPLIB) |
||||||
|
$(LD) $(LDFLAGS) -o $@ example.o $(IMPLIB)
|
||||||
|
|
||||||
|
minigzip_d: minigzip.o $(IMPLIB) |
||||||
|
$(LD) $(LDFLAGS) -o $@ minigzip.o $(IMPLIB)
|
||||||
|
|
||||||
|
zlibrc.o: win32/zlib1.rc |
||||||
|
$(RC) $(RCFLAGS) -o $@ win32/zlib1.rc
|
||||||
|
|
||||||
|
|
||||||
|
# INCLUDE_PATH and LIBRARY_PATH must be set.
|
||||||
|
|
||||||
|
.PHONY: install uninstall clean |
||||||
|
|
||||||
|
install: zlib.h zconf.h $(LIB) |
||||||
|
-@if not exist $(INCLUDE_PATH)/nul mkdir $(INCLUDE_PATH)
|
||||||
|
-@if not exist $(LIBRARY_PATH)/nul mkdir $(LIBRARY_PATH)
|
||||||
|
-$(INSTALL) zlib.h $(INCLUDE_PATH)
|
||||||
|
-$(INSTALL) zconf.h $(INCLUDE_PATH)
|
||||||
|
-$(INSTALL) $(STATICLIB) $(LIBRARY_PATH)
|
||||||
|
-$(INSTALL) $(IMPLIB) $(LIBRARY_PATH)
|
||||||
|
|
||||||
|
uninstall: |
||||||
|
-$(RM) $(INCLUDE_PATH)/zlib.h
|
||||||
|
-$(RM) $(INCLUDE_PATH)/zconf.h
|
||||||
|
-$(RM) $(LIBRARY_PATH)/$(STATICLIB)
|
||||||
|
-$(RM) $(LIBRARY_PATH)/$(IMPLIB)
|
||||||
|
|
||||||
|
clean: |
||||||
|
-$(RM) $(STATICLIB)
|
||||||
|
-$(RM) $(SHAREDLIB)
|
||||||
|
-$(RM) $(IMPLIB)
|
||||||
|
-$(RM) *.o
|
||||||
|
-$(RM) *.exe
|
||||||
|
-$(RM) foo.gz
|
||||||
|
|
||||||
|
adler32.o: zlib.h zconf.h |
||||||
|
compress.o: zlib.h zconf.h |
||||||
|
crc32.o: crc32.h zlib.h zconf.h |
||||||
|
deflate.o: deflate.h zutil.h zlib.h zconf.h |
||||||
|
example.o: zlib.h zconf.h |
||||||
|
gzio.o: zutil.h zlib.h zconf.h |
||||||
|
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h |
||||||
|
inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h |
||||||
|
infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h |
||||||
|
inftrees.o: zutil.h zlib.h zconf.h inftrees.h |
||||||
|
minigzip.o: zlib.h zconf.h |
||||||
|
trees.o: deflate.h zutil.h zlib.h zconf.h trees.h |
||||||
|
uncompr.o: zlib.h zconf.h |
||||||
|
zutil.o: zutil.h zlib.h zconf.h |
@ -0,0 +1,16 @@ |
|||||||
|
/* zlibdefs.h -- compile-time definitions for the zlib compression library |
||||||
|
* Copyright (C) 1995-2006 Jean-loup Gailly. |
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h |
||||||
|
*/ |
||||||
|
|
||||||
|
#cmakedefine HAVE_UNISTD_H |
||||||
|
#ifdef HAVE_UNISTD_H |
||||||
|
#include <sys/types.h> /* for off_t */ |
||||||
|
#include <unistd.h> /* for SEEK_* and off_t */ |
||||||
|
#ifdef VMS |
||||||
|
# include <unixio.h> /* for off_t */ |
||||||
|
#endif |
||||||
|
#ifndef z_off_t |
||||||
|
# define z_off_t off_t |
||||||
|
#endif |
||||||
|
#endif |
Loading…
Reference in new issue