Merge remote-tracking branch 'upstream/master' into yosys-experimental

This commit is contained in:
Miodrag Milanovic 2026-06-15 19:40:58 +02:00
commit 30c47da5c9
37 changed files with 15778 additions and 4747 deletions

View File

@ -146,21 +146,6 @@ static int Wln_FileNamesHasSv( char ** ppFileNames, int nFileNames )
return 1; return 1;
return 0; return 0;
} }
static void Wln_GiaTransferNamesIfMatch( Gia_Man_t * pGia, Gia_Man_t * pGiaNames )
{
if ( pGia == NULL || pGiaNames == NULL )
return;
if ( pGia->vNamesIn == NULL && pGiaNames->vNamesIn != NULL && Gia_ManCiNum(pGia) == Vec_PtrSize(pGiaNames->vNamesIn) )
{
pGia->vNamesIn = pGiaNames->vNamesIn;
pGiaNames->vNamesIn = NULL;
}
if ( pGia->vNamesOut == NULL && pGiaNames->vNamesOut != NULL && Gia_ManCoNum(pGia) == Vec_PtrSize(pGiaNames->vNamesOut) )
{
pGia->vNamesOut = pGiaNames->vNamesOut;
pGiaNames->vNamesOut = NULL;
}
}
int Wln_ConvertToRtl( char * pCommand, char * pFileTemp ) int Wln_ConvertToRtl( char * pCommand, char * pFileTemp )
{ {
#if defined(__wasm) #if defined(__wasm)
@ -263,35 +248,7 @@ Gia_Man_t * Wln_BlastSystemVerilog( char ** ppFileNames, int nFileNames, char *
} }
ABC_FREE( pCommand ); ABC_FREE( pCommand );
ABC_FREE( pFileNames ); ABC_FREE( pFileNames );
if ( nFileNames > 1 ) pGia = Gia_AigerRead( pFileTemp, 0, fSkipStrash, 0 );
{
extern Aig_Man_t * Abc_NtkToDar( Abc_Ntk_t * pNtk, int fExors, int fRegisters );
Aig_Man_t * pAig = NULL;
Gia_Man_t * pGiaNames = NULL;
Abc_Ntk_t * pNtk = Io_Read( pFileTemp, IO_FILE_AIGER, 1, 0 );
if ( pNtk == NULL )
{
printf( "Reading AIGER from file \"%s\" has failed.\n", pFileTemp );
ABC_FREE( pFileTemp );
return NULL;
}
pAig = Abc_NtkToDar( pNtk, 0, 1 );
Abc_NtkDelete( pNtk );
if ( pAig == NULL )
{
printf( "Converting the AIGER network into an internal AIG has failed.\n" );
ABC_FREE( pFileTemp );
return NULL;
}
pGia = fSkipStrash ? Gia_ManFromAigSimple(pAig) : Gia_ManFromAig(pAig);
Aig_ManStop( pAig );
pGiaNames = Gia_AigerRead( pFileTemp, 0, 1, 0 );
Wln_GiaTransferNamesIfMatch( pGia, pGiaNames );
if ( pGiaNames )
Gia_ManStop( pGiaNames );
}
else
pGia = Gia_AigerRead( pFileTemp, 0, fSkipStrash, 0 );
if ( pGia == NULL ) if ( pGia == NULL )
{ {
printf( "Converting to AIG has failed.\n" ); printf( "Converting to AIG has failed.\n" );

View File

@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression. lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007 bzip2/libbzip2 version 1.0.8 of 13 July 2019
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org> Copyright (C) 1996-2019 Julian Seward <jseward@acm.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file. README file.
@ -204,9 +204,9 @@ void fallbackQSort3 ( UInt32* fmap,
bhtab [ 0 .. 2+(nblock/32) ] destroyed bhtab [ 0 .. 2+(nblock/32) ] destroyed
*/ */
#define SET_BH(zz) bhtab[(zz) >> 5] |= (1 << ((zz) & 31)) #define SET_BH(zz) bhtab[(zz) >> 5] |= ((UInt32)1 << ((zz) & 31))
#define CLEAR_BH(zz) bhtab[(zz) >> 5] &= ~(1 << ((zz) & 31)) #define CLEAR_BH(zz) bhtab[(zz) >> 5] &= ~((UInt32)1 << ((zz) & 31))
#define ISSET_BH(zz) (bhtab[(zz) >> 5] & (1 << ((zz) & 31))) #define ISSET_BH(zz) (bhtab[(zz) >> 5] & ((UInt32)1 << ((zz) & 31)))
#define WORD_BH(zz) bhtab[(zz) >> 5] #define WORD_BH(zz) bhtab[(zz) >> 5]
#define UNALIGNED_BH(zz) ((zz) & 0x01f) #define UNALIGNED_BH(zz) ((zz) & 0x01f)
@ -276,7 +276,7 @@ void fallbackSort ( UInt32* fmap,
r = -1; r = -1;
while (1) { while (1) {
/*-- find the next non-singleton bucket --*/ /*-- find the next non-singleton bucket --*/
k = r + 1; k = r + 1;
while (ISSET_BH(k) && UNALIGNED_BH(k)) k++; while (ISSET_BH(k) && UNALIGNED_BH(k)) k++;
if (ISSET_BH(k)) { if (ISSET_BH(k)) {

View File

@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression. lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007 bzip2/libbzip2 version 1.0.8 of 13 July 2019
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org> Copyright (C) 1996-2019 Julian Seward <jseward@acm.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file. README file.
@ -54,12 +54,12 @@ void BZ2_bz__AssertH__fail ( int errcode )
fprintf(stderr, fprintf(stderr,
"\n\nbzip2/libbzip2: internal error number %d.\n" "\n\nbzip2/libbzip2: internal error number %d.\n"
"This is a bug in bzip2/libbzip2, %s.\n" "This is a bug in bzip2/libbzip2, %s.\n"
"Please report it to me at: jseward@bzip.org. If this happened\n" "Please report it to: bzip2-devel@sourceware.org. If this happened\n"
"when you were using some program which uses libbzip2 as a\n" "when you were using some program which uses libbzip2 as a\n"
"component, you should also report this bug to the author(s)\n" "component, you should also report this bug to the author(s)\n"
"of that program. Please make an effort to report this bug;\n" "of that program. Please make an effort to report this bug;\n"
"timely and accurate bug reports eventually lead to higher\n" "timely and accurate bug reports eventually lead to higher\n"
"quality software. Thanks. Julian Seward, 10 December 2007.\n\n", "quality software. Thanks.\n\n",
errcode, errcode,
BZ2_bzlibVersion() BZ2_bzlibVersion()
); );
@ -436,7 +436,7 @@ int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action )
return progress ? BZ_RUN_OK : BZ_PARAM_ERROR; return progress ? BZ_RUN_OK : BZ_PARAM_ERROR;
} }
else else
if (action == BZ_FLUSH) { if (action == BZ_FLUSH) {
s->avail_in_expect = strm->avail_in; s->avail_in_expect = strm->avail_in;
s->mode = BZ_M_FLUSHING; s->mode = BZ_M_FLUSHING;
goto preswitch; goto preswitch;

View File

@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression. lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007 bzip2/libbzip2 version 1.0.8 of 13 July 2019
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org> Copyright (C) 1996-2019 Julian Seward <jseward@acm.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file. README file.

View File

@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression. lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007 bzip2/libbzip2 version 1.0.8 of 13 July 2019
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org> Copyright (C) 1996-2019 Julian Seward <jseward@acm.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file. README file.
@ -38,7 +38,7 @@ ABC_NAMESPACE_HEADER_START
/*-- General stuff. --*/ /*-- General stuff. --*/
#define BZ_VERSION "1.0.5, 10-Dec-2007" #define BZ_VERSION "1.0.8, 13-Jul-2019"
typedef char Char; typedef char Char;
typedef unsigned char Bool; typedef unsigned char Bool;
@ -483,7 +483,7 @@ typedef
/*-- externs for decompression. --*/ /*-- externs for decompression. --*/
Int32 extern Int32
BZ2_indexIntoF ( Int32, Int32* ); BZ2_indexIntoF ( Int32, Int32* );
extern Int32 extern Int32

View File

@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression. lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007 bzip2/libbzip2 version 1.0.8 of 13 July 2019
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org> Copyright (C) 1996-2019 Julian Seward <jseward@acm.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file. README file.
@ -332,14 +332,14 @@ void sendMTFValues ( EState* s )
/*--- /*---
Set up an auxiliary length table which is used to fast-track Set up an auxiliary length table which is used to fast-track
the common case (nGroups == 6). the common case (nGroups == 6).
---*/ ---*/
if (nGroups == 6) { if (nGroups == 6) {
for (v = 0; v < alphaSize; v++) { for (v = 0; v < alphaSize; v++) {
s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v]; s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v]; s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
s->len_pack[v][2] = (s->len[5][v] << 16) | s->len[4][v]; s->len_pack[v][2] = (s->len[5][v] << 16) | s->len[4][v];
} }
} }
nSelectors = 0; nSelectors = 0;
@ -388,7 +388,7 @@ void sendMTFValues ( EState* s )
cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16; cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
} else { } else {
/*--- slow version which correctly handles all situations ---*/ /*--- slow version which correctly handles all situations ---*/
for (i = gs; i <= ge; i++) { for (i = gs; i <= ge; i++) {
UInt16 icv = mtfv[i]; UInt16 icv = mtfv[i];
for (t = 0; t < nGroups; t++) cost[t] += s->len[t][icv]; for (t = 0; t < nGroups; t++) cost[t] += s->len[t][icv];
@ -429,7 +429,7 @@ void sendMTFValues ( EState* s )
# undef BZ_ITUR # undef BZ_ITUR
} else { } else {
/*--- slow version which correctly handles all situations ---*/ /*--- slow version which correctly handles all situations ---*/
for (i = gs; i <= ge; i++) for (i = gs; i <= ge; i++)
s->rfreq[bt][ mtfv[i] ]++; s->rfreq[bt][ mtfv[i] ]++;
} }
@ -457,7 +457,7 @@ void sendMTFValues ( EState* s )
AssertH( nGroups < 8, 3002 ); AssertH( nGroups < 8, 3002 );
AssertH( nSelectors < 32768 && AssertH( nSelectors < 32768 &&
nSelectors <= (2 + (900000 / BZ_G_SIZE)), nSelectors <= BZ_MAX_SELECTORS,
3003 ); 3003 );
@ -582,7 +582,7 @@ void sendMTFValues ( EState* s )
# undef BZ_ITAH # undef BZ_ITAH
} else { } else {
/*--- slow version which correctly handles all situations ---*/ /*--- slow version which correctly handles all situations ---*/
for (i = gs; i <= ge; i++) { for (i = gs; i <= ge; i++) {
bsW ( s, bsW ( s,
s->len [s->selector[selCtr]] [mtfv[i]], s->len [s->selector[selCtr]] [mtfv[i]],

View File

@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression. lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007 bzip2/libbzip2 version 1.0.8 of 13 July 2019
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org> Copyright (C) 1996-2019 Julian Seward <jseward@acm.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file. README file.

View File

@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression. lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007 bzip2/libbzip2 version 1.0.8 of 13 July 2019
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org> Copyright (C) 1996-2019 Julian Seward <jseward@acm.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file. README file.
@ -292,7 +292,7 @@ Int32 BZ2_decompress ( DState* s )
/*--- Now the selectors ---*/ /*--- Now the selectors ---*/
GET_BITS(BZ_X_SELECTOR_1, nGroups, 3); GET_BITS(BZ_X_SELECTOR_1, nGroups, 3);
if (nGroups < 2 || nGroups > 6) RETURN(BZ_DATA_ERROR); if (nGroups < 2 || nGroups > BZ_N_GROUPS) RETURN(BZ_DATA_ERROR);
GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15); GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15);
if (nSelectors < 1) RETURN(BZ_DATA_ERROR); if (nSelectors < 1) RETURN(BZ_DATA_ERROR);
for (i = 0; i < nSelectors; i++) { for (i = 0; i < nSelectors; i++) {
@ -303,8 +303,14 @@ Int32 BZ2_decompress ( DState* s )
j++; j++;
if (j >= nGroups) RETURN(BZ_DATA_ERROR); if (j >= nGroups) RETURN(BZ_DATA_ERROR);
} }
s->selectorMtf[i] = j; /* Having more than BZ_MAX_SELECTORS doesn't make much sense
since they will never be used, but some implementations might
"round up" the number of selectors, so just ignore those. */
if (i < BZ_MAX_SELECTORS)
s->selectorMtf[i] = j;
} }
if (nSelectors > BZ_MAX_SELECTORS)
nSelectors = BZ_MAX_SELECTORS;
/*--- Undo the MTF values for the selectors. ---*/ /*--- Undo the MTF values for the selectors. ---*/
{ {
@ -388,6 +394,13 @@ Int32 BZ2_decompress ( DState* s )
es = -1; es = -1;
N = 1; N = 1;
do { do {
/* Check that N doesn't get too big, so that es doesn't
go negative. The maximum value that can be
RUNA/RUNB encoded is equal to the block size (post
the initial RLE), viz, 900k, so bounding N at 2
million should guard against overflow without
rejecting any legitimate inputs. */
if (N >= 2*1024*1024) RETURN(BZ_DATA_ERROR);
if (nextSym == BZ_RUNA) es = es + (0+1) * N; else if (nextSym == BZ_RUNA) es = es + (0+1) * N; else
if (nextSym == BZ_RUNB) es = es + (1+1) * N; if (nextSym == BZ_RUNB) es = es + (1+1) * N;
N = N * 2; N = N * 2;
@ -492,15 +505,28 @@ Int32 BZ2_decompress ( DState* s )
RETURN(BZ_DATA_ERROR); RETURN(BZ_DATA_ERROR);
/*-- Set up cftab to facilitate generation of T^(-1) --*/ /*-- Set up cftab to facilitate generation of T^(-1) --*/
/* Check: unzftab entries in range. */
for (i = 0; i <= 255; i++) {
if (s->unzftab[i] < 0 || s->unzftab[i] > nblock)
RETURN(BZ_DATA_ERROR);
}
/* Actually generate cftab. */
s->cftab[0] = 0; s->cftab[0] = 0;
for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1]; for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1]; for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
/* Check: cftab entries in range. */
for (i = 0; i <= 256; i++) { for (i = 0; i <= 256; i++) {
if (s->cftab[i] < 0 || s->cftab[i] > nblock) { if (s->cftab[i] < 0 || s->cftab[i] > nblock) {
/* s->cftab[i] can legitimately be == nblock */ /* s->cftab[i] can legitimately be == nblock */
RETURN(BZ_DATA_ERROR); RETURN(BZ_DATA_ERROR);
} }
} }
/* Check: cftab entries non-descending. */
for (i = 1; i <= 256; i++) {
if (s->cftab[i-1] > s->cftab[i]) {
RETURN(BZ_DATA_ERROR);
}
}
s->state_out_len = 0; s->state_out_len = 0;
s->state_out_ch = 0; s->state_out_ch = 0;

View File

@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression. lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007 bzip2/libbzip2 version 1.0.8 of 13 July 2019
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org> Copyright (C) 1996-2019 Julian Seward <jseward@acm.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file. README file.

View File

@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression. lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007 bzip2/libbzip2 version 1.0.8 of 13 July 2019
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org> Copyright (C) 1996-2019 Julian Seward <jseward@acm.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file. README file.

View File

@ -1,52 +1,51 @@
ZLIB DATA COMPRESSION LIBRARY ZLIB DATA COMPRESSION LIBRARY
zlib 1.2.5 is a general purpose data compression library. All the code is zlib 1.3.2 is a general purpose data compression library. All the code is
thread safe. The data format used by the zlib library is described by RFCs thread safe (though see the FAQ for caveats). The data format used by the zlib
(Request for Comments) 1950 to 1952 in the files library is described by RFCs (Request for Comments) 1950 to 1952 at
http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) https://datatracker.ietf.org/doc/html/rfc1950 (zlib format), rfc1951 (deflate
and rfc1952.txt (gzip format). format) and rfc1952 (gzip format).
All functions of the compression library are documented in the file zlib.h All functions of the compression library are documented in the file zlib.h
(volunteer to write man pages welcome, contact zlib@gzip.org). A usage example (volunteer to write man pages welcome, contact zlib@gzip.org). A usage example
of the library is given in the file example.c which also tests that the library of the library is given in the file test/example.c which also tests that
is working correctly. Another example is given in the file minigzip.c. The the library is working correctly. Another example is given in the file
compression library itself is composed of all source files except example.c and test/minigzip.c. The compression library itself is composed of all source
minigzip.c. files in the root directory.
To compile all files and run the test program, follow the instructions given at To compile all files and run the test program, follow the instructions given at
the top of Makefile.in. In short "./configure; make test", and if that goes the top of Makefile.in. In short "./configure; make test", and if that goes
well, "make install" should work for most flavors of Unix. For Windows, use one well, "make install" should work for most flavors of Unix. For Windows, use
of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use one of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use
make_vms.com. make_vms.com.
Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
<info@winimage.com> for the Windows DLL version. The zlib home page is <info@winimage.com> for the Windows DLL version. The zlib home page is
http://zlib.net/ . Before reporting a problem, please check this site to https://zlib.net/ . Before reporting a problem, please check this site to
verify that you have the latest version of zlib; otherwise get the latest verify that you have the latest version of zlib; otherwise get the latest
version and check whether the problem still exists or not. version and check whether the problem still exists or not.
PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help. PLEASE read the zlib FAQ https://zlib.net/zlib_faq.html before asking for help.
Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997 Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
issue of Dr. Dobb's Journal; a copy of the article is available at issue of Dr. Dobb's Journal; a copy of the article is available at
http://marknelson.us/1997/01/01/zlib-engine/ . https://zlib.net/nelson/ .
The changes made in version 1.2.5 are documented in the file ChangeLog. The changes made in version 1.3.2 are documented in the file ChangeLog.
Unsupported third party contributions are provided in directory contrib/ . Unsupported third party contributions are provided in directory contrib/ .
zlib is available in Java using the java.util.zip package, documented at zlib is available in Java using the java.util.zip package. Follow the API
http://java.sun.com/developer/technicalArticles/Programming/compression/ . Documentation link at: https://docs.oracle.com/search/?q=java.util.zip .
A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is available A Perl interface to zlib and bzip2 written by Paul Marquess <pmqs@cpan.org>
at CPAN (Comprehensive Perl Archive Network) sites, including can be found at https://github.com/pmqs/IO-Compress .
http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is
available in Python 1.5 and later versions, see available in Python 1.5 and later versions, see
http://www.python.org/doc/lib/module-zlib.html . https://docs.python.org/3/library/zlib.html .
zlib is built into tcl: http://wiki.tcl.tk/4610 . zlib is built into tcl: https://wiki.tcl-lang.org/page/zlib .
An experimental package to read and write files in .zip format, written on top An experimental package to read and write files in .zip format, written on top
of zlib by Gilles Vollant <info@winimage.com>, is available in the of zlib by Gilles Vollant <info@winimage.com>, is available in the
@ -64,15 +63,13 @@ Notes for some targets:
- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
when compiled with cc. when compiled with cc.
- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is - On Digital Unix 4.0D (formerly OSF/1) on AlphaServer, the cc option -std1 is
necessary to get gzprintf working correctly. This is done by configure. necessary to get gzprintf working correctly. This is done by configure.
- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
other compilers. Use "make test" to check your compiler. other compilers. Use "make test" to check your compiler.
- gzdopen is not supported on RISCOS or BEOS. - For PalmOs, see https://palmzlib.sourceforge.net/
- For PalmOs, see http://palmzlib.sourceforge.net/
Acknowledgments: Acknowledgments:
@ -84,7 +81,7 @@ Acknowledgments:
Copyright notice: Copyright notice:
(C) 1995-2010 Jean-loup Gailly and Mark Adler (C) 1995-2026 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -108,7 +105,10 @@ Copyright notice:
If you use the zlib library in a product, we would appreciate *not* receiving If you use the zlib library in a product, we would appreciate *not* receiving
lengthy legal documents to sign. The sources are provided for free but without lengthy legal documents to sign. The sources are provided for free but without
warranty of any kind. The library has been entirely written by Jean-loup warranty of any kind. The library has been entirely written by Jean-loup
Gailly and Mark Adler; it does not include third-party code. Gailly and Mark Adler; it does not include third-party code. We make all
contributions to and distributions of this project solely in our personal
capacity, and are not conveying any rights to any intellectual property of
any third parties.
If you redistribute modified sources, we would appreciate that you include in If you redistribute modified sources, we would appreciate that you include in
the file ChangeLog history information documenting your changes. Please read the file ChangeLog history information documenting your changes. Please read

View File

@ -1,5 +1,5 @@
/* adler32.c -- compute the Adler-32 checksum of a data stream /* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-2007 Mark Adler * Copyright (C) 1995-2011, 2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -14,11 +14,8 @@
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
#define local static
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2); #define BASE 65521U /* largest prime smaller than 65536 */
#define BASE 65521UL /* largest prime smaller than 65536 */
#define NMAX 5552 #define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
@ -28,44 +25,48 @@ local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8); #define DO16(buf) DO8(buf,0); DO8(buf,8);
/* use NO_DIVIDE if your processor does not do division in hardware */ /* use NO_DIVIDE if your processor does not do division in hardware --
try it both ways to see which is faster */
#ifdef NO_DIVIDE #ifdef NO_DIVIDE
# define MOD(a) \ /* note that this assumes BASE is 65521, where 65536 % 65521 == 15
(thank you to John Reiser for pointing this out) */
# define CHOP(a) \
do { \ do { \
if (a >= (BASE << 16)) a -= (BASE << 16); \ unsigned long tmp = a >> 16; \
if (a >= (BASE << 15)) a -= (BASE << 15); \ a &= 0xffffUL; \
if (a >= (BASE << 14)) a -= (BASE << 14); \ a += (tmp << 4) - tmp; \
if (a >= (BASE << 13)) a -= (BASE << 13); \ } while (0)
if (a >= (BASE << 12)) a -= (BASE << 12); \ # define MOD28(a) \
if (a >= (BASE << 11)) a -= (BASE << 11); \ do { \
if (a >= (BASE << 10)) a -= (BASE << 10); \ CHOP(a); \
if (a >= (BASE << 9)) a -= (BASE << 9); \
if (a >= (BASE << 8)) a -= (BASE << 8); \
if (a >= (BASE << 7)) a -= (BASE << 7); \
if (a >= (BASE << 6)) a -= (BASE << 6); \
if (a >= (BASE << 5)) a -= (BASE << 5); \
if (a >= (BASE << 4)) a -= (BASE << 4); \
if (a >= (BASE << 3)) a -= (BASE << 3); \
if (a >= (BASE << 2)) a -= (BASE << 2); \
if (a >= (BASE << 1)) a -= (BASE << 1); \
if (a >= BASE) a -= BASE; \ if (a >= BASE) a -= BASE; \
} while (0) } while (0)
# define MOD4(a) \ # define MOD(a) \
do { \ do { \
if (a >= (BASE << 4)) a -= (BASE << 4); \ CHOP(a); \
if (a >= (BASE << 3)) a -= (BASE << 3); \ MOD28(a); \
if (a >= (BASE << 2)) a -= (BASE << 2); \ } while (0)
if (a >= (BASE << 1)) a -= (BASE << 1); \ # define MOD63(a) \
do { /* this assumes a is not negative */ \
z_off64_t tmp = a >> 32; \
a &= 0xffffffffL; \
a += (tmp << 8) - (tmp << 5) + tmp; \
tmp = a >> 16; \
a &= 0xffffL; \
a += (tmp << 4) - tmp; \
tmp = a >> 16; \
a &= 0xffffL; \
a += (tmp << 4) - tmp; \
if (a >= BASE) a -= BASE; \ if (a >= BASE) a -= BASE; \
} while (0) } while (0)
#else #else
# define MOD(a) a %= BASE # define MOD(a) a %= BASE
# define MOD4(a) a %= BASE # define MOD28(a) a %= BASE
# define MOD63(a) a %= BASE
#endif #endif
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
{
unsigned long sum2; unsigned long sum2;
unsigned n; unsigned n;
@ -96,7 +97,7 @@ uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
} }
if (adler >= BASE) if (adler >= BASE)
adler -= BASE; adler -= BASE;
MOD4(sum2); /* only added so many BASE's */ MOD28(sum2); /* only added so many BASE's */
return adler | (sum2 << 16); return adler | (sum2 << 16);
} }
@ -132,14 +133,23 @@ uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
} }
/* ========================================================================= */ /* ========================================================================= */
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
{ return adler32_z(adler, buf, len);
}
/* ========================================================================= */
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
unsigned long sum1; unsigned long sum1;
unsigned long sum2; unsigned long sum2;
unsigned rem; unsigned rem;
/* for negative len, return invalid adler32 as a clue for debugging */
if (len2 < 0)
return 0xffffffffUL;
/* the derivation of this formula is left as an exercise for the reader */ /* the derivation of this formula is left as an exercise for the reader */
rem = (unsigned)(len2 % BASE); MOD63(len2); /* assumes len2 >= 0 */
rem = (unsigned)len2;
sum1 = adler1 & 0xffff; sum1 = adler1 & 0xffff;
sum2 = rem * sum1; sum2 = rem * sum1;
MOD(sum2); MOD(sum2);
@ -147,22 +157,19 @@ local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2)
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
if (sum1 >= BASE) sum1 -= BASE; if (sum1 >= BASE) sum1 -= BASE;
if (sum1 >= BASE) sum1 -= BASE; if (sum1 >= BASE) sum1 -= BASE;
if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
if (sum2 >= BASE) sum2 -= BASE; if (sum2 >= BASE) sum2 -= BASE;
return sum1 | (sum2 << 16); return sum1 | (sum2 << 16);
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) {
{
return adler32_combine_(adler1, adler2, len2); return adler32_combine_(adler1, adler2, len2);
} }
uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) {
{
return adler32_combine_(adler1, adler2, len2); return adler32_combine_(adler1, adler2, len2);
} }
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_END

View File

@ -1,15 +1,21 @@
/* compress.c -- compress a memory buffer /* compress.c -- compress a memory buffer
* Copyright (C) 1995-2005 Jean-loup Gailly. * Copyright (C) 1995-2026 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id$ */ /* @(#) $Id$ */
#define ZLIB_INTERNAL #define ZLIB_INTERNAL
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "misc/util/abc_global.h"
#include "zlib.h" #include "zlib.h"
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
/* =========================================================================== /* ===========================================================================
Compresses the source buffer into the destination buffer. The level Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte parameter has the same meaning as in deflateInit. sourceLen is the byte
@ -20,21 +26,22 @@ ABC_NAMESPACE_IMPL_START
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer, memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid. Z_STREAM_ERROR if the level parameter is invalid.
The _z versions of the functions take size_t length arguments.
*/ */
int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level) int ZEXPORT compress2_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
{ z_size_t sourceLen, int level) {
z_stream stream; z_stream stream;
int err; int err;
const uInt max = (uInt)-1;
z_size_t left;
stream.next_in = (Bytef*)source; if ((sourceLen > 0 && source == NULL) ||
stream.avail_in = (uInt)sourceLen; destLen == NULL || (*destLen > 0 && dest == NULL))
#ifdef MAXSEG_64K return Z_STREAM_ERROR;
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; left = *destLen;
#endif *destLen = 0;
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0; stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0; stream.zfree = (free_func)0;
@ -43,21 +50,45 @@ int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong
err = deflateInit(&stream, level); err = deflateInit(&stream, level);
if (err != Z_OK) return err; if (err != Z_OK) return err;
err = deflate(&stream, Z_FINISH); stream.next_out = dest;
if (err != Z_STREAM_END) { stream.avail_out = 0;
deflateEnd(&stream); stream.next_in = (z_const Bytef *)source;
return err == Z_OK ? Z_BUF_ERROR : err; stream.avail_in = 0;
}
*destLen = stream.total_out;
err = deflateEnd(&stream); do {
return err; if (stream.avail_out == 0) {
stream.avail_out = left > (z_size_t)max ? max : (uInt)left;
left -= stream.avail_out;
}
if (stream.avail_in == 0) {
stream.avail_in = sourceLen > (z_size_t)max ? max :
(uInt)sourceLen;
sourceLen -= stream.avail_in;
}
err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
} while (err == Z_OK);
*destLen = (z_size_t)(stream.next_out - dest);
deflateEnd(&stream);
return err == Z_STREAM_END ? Z_OK : err;
}
int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
uLong sourceLen, int level) {
int ret;
z_size_t got = *destLen;
ret = compress2_z(dest, &got, source, sourceLen, level);
*destLen = (uLong)got;
return ret;
} }
/* =========================================================================== /* ===========================================================================
*/ */
int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen) int ZEXPORT compress_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
{ z_size_t sourceLen) {
return compress2_z(dest, destLen, source, sourceLen,
Z_DEFAULT_COMPRESSION);
}
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
uLong sourceLen) {
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
} }
@ -65,12 +96,15 @@ int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong s
If the default memLevel or windowBits for deflateInit() is changed, then If the default memLevel or windowBits for deflateInit() is changed, then
this function needs to be updated. this function needs to be updated.
*/ */
uLong ZEXPORT compressBound (uLong sourceLen) z_size_t ZEXPORT compressBound_z(z_size_t sourceLen) {
{ z_size_t bound = sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13;
(sourceLen >> 25) + 13; return bound < sourceLen ? (z_size_t)-1 : bound;
}
uLong ZEXPORT compressBound(uLong sourceLen) {
z_size_t bound = compressBound_z(sourceLen);
return (uLong)bound != bound ? (uLong)-1 : (uLong)bound;
} }
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_END

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/* deflate.h -- internal compression state /* deflate.h -- internal compression state
* Copyright (C) 1995-2010 Jean-loup Gailly * Copyright (C) 1995-2026 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -17,6 +17,7 @@
ABC_NAMESPACE_HEADER_START ABC_NAMESPACE_HEADER_START
/* define NO_GZIP when compiling if you want to disable gzip header and /* define NO_GZIP when compiling if you want to disable gzip header and
trailer creation by deflate(). NO_GZIP would be used to avoid linking in trailer creation by deflate(). NO_GZIP would be used to avoid linking in
the crc code when it is not needed. For shared libraries, gzip encoding the crc code when it is not needed. For shared libraries, gzip encoding
@ -25,6 +26,10 @@ ABC_NAMESPACE_HEADER_START
# define GZIP # define GZIP
#endif #endif
/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at
the cost of a larger memory footprint */
/* #define LIT_MEM */
/* =========================================================================== /* ===========================================================================
* Internal compression state. * Internal compression state.
*/ */
@ -50,13 +55,19 @@ ABC_NAMESPACE_HEADER_START
#define MAX_BITS 15 #define MAX_BITS 15
/* All codes must not exceed MAX_BITS bits */ /* All codes must not exceed MAX_BITS bits */
#define INIT_STATE 42 #define Buf_size 16
#define EXTRA_STATE 69 /* size of bit buffer in bi_buf */
#define NAME_STATE 73
#define COMMENT_STATE 91 #define INIT_STATE 42 /* zlib header -> BUSY_STATE */
#define HCRC_STATE 103 #ifdef GZIP
#define BUSY_STATE 113 # define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */
#define FINISH_STATE 666 #endif
#define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */
#define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */
#define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */
#define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
#define BUSY_STATE 113 /* deflate -> FINISH_STATE */
#define FINISH_STATE 666 /* stream complete */
/* Stream status */ /* Stream status */
@ -82,7 +93,7 @@ typedef struct static_tree_desc_s static_tree_desc;
typedef struct tree_desc_s { typedef struct tree_desc_s {
ct_data *dyn_tree; /* the dynamic tree */ ct_data *dyn_tree; /* the dynamic tree */
int max_code; /* largest code with non zero frequency */ int max_code; /* largest code with non zero frequency */
static_tree_desc *stat_desc; /* the corresponding static tree */ const static_tree_desc *stat_desc; /* the corresponding static tree */
} FAR tree_desc; } FAR tree_desc;
typedef ush Pos; typedef ush Pos;
@ -99,11 +110,11 @@ typedef struct internal_state {
Bytef *pending_buf; /* output still pending */ Bytef *pending_buf; /* output still pending */
ulg pending_buf_size; /* size of pending_buf */ ulg pending_buf_size; /* size of pending_buf */
Bytef *pending_out; /* next pending byte to output to the stream */ Bytef *pending_out; /* next pending byte to output to the stream */
uInt pending; /* nb of bytes in the pending buffer */ ulg pending; /* nb of bytes in the pending buffer */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
gz_headerp gzhead; /* gzip header information to write */ gz_headerp gzhead; /* gzip header information to write */
uInt gzindex; /* where in extra, name, or comment */ ulg gzindex; /* where in extra, name, or comment */
Byte method; /* STORED (for zip only) or DEFLATED */ Byte method; /* can only be DEFLATED */
int last_flush; /* value of flush param for previous deflate call */ int last_flush; /* value of flush param for previous deflate call */
/* used by deflate.c: */ /* used by deflate.c: */
@ -190,7 +201,7 @@ typedef struct internal_state {
int nice_match; /* Stop searching when current match exceeds this */ int nice_match; /* Stop searching when current match exceeds this */
/* used by trees.c: */ /* used by trees.c: */
/* Didn't use ct_data typedef below to supress compiler warning */ /* Didn't use ct_data typedef below to suppress compiler warning */
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
@ -213,7 +224,14 @@ typedef struct internal_state {
/* Depth of each subtree used as tie breaker for trees of equal frequency /* Depth of each subtree used as tie breaker for trees of equal frequency
*/ */
uchf *l_buf; /* buffer for literals or lengths */ #ifdef LIT_MEM
# define LIT_BUFS 5
ushf *d_buf; /* buffer for distances */
uchf *l_buf; /* buffer for literals/lengths */
#else
# define LIT_BUFS 4
uchf *sym_buf; /* buffer for distances and literals/lengths */
#endif
uInt lit_bufsize; uInt lit_bufsize;
/* Size of match buffer for literals/lengths. There are 4 reasons for /* Size of match buffer for literals/lengths. There are 4 reasons for
@ -235,20 +253,15 @@ typedef struct internal_state {
* - I can't count above 4 * - I can't count above 4
*/ */
uInt last_lit; /* running index in l_buf */ uInt sym_next; /* running index in symbol buffer */
uInt sym_end; /* symbol table full when sym_next reaches this */
ushf *d_buf;
/* Buffer for distances. To simplify the code, d_buf and l_buf have
* the same number of elements. To use different lengths, an extra flag
* array would be necessary.
*/
ulg opt_len; /* bit length of current block with optimal trees */ ulg opt_len; /* bit length of current block with optimal trees */
ulg static_len; /* bit length of current block with static trees */ ulg static_len; /* bit length of current block with static trees */
uInt matches; /* number of string matches in current block */ uInt matches; /* number of string matches in current block */
int last_eob_len; /* bit length of EOB code for last block */ uInt insert; /* bytes at end of window left to insert */
#ifdef DEBUG #ifdef ZLIB_DEBUG
ulg compressed_len; /* total bit length of compressed file mod 2^32 */ ulg compressed_len; /* total bit length of compressed file mod 2^32 */
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
#endif #endif
@ -261,6 +274,9 @@ typedef struct internal_state {
/* Number of valid bits in bi_buf. All bits above the last valid bit /* Number of valid bits in bi_buf. All bits above the last valid bit
* are always zero. * are always zero.
*/ */
int bi_used;
/* Last number of used bits when going to a byte boundary.
*/
ulg high_water; ulg high_water;
/* High water mark offset in window for initialized bytes -- bytes above /* High water mark offset in window for initialized bytes -- bytes above
@ -269,12 +285,15 @@ typedef struct internal_state {
* updated to the new high water mark. * updated to the new high water mark.
*/ */
int slid;
/* True if the hash table has been slid since it was cleared. */
} FAR deflate_state; } FAR deflate_state;
/* Output a byte on the stream. /* Output a byte on the stream.
* IN assertion: there is enough room in pending_buf. * IN assertion: there is enough room in pending_buf.
*/ */
#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} #define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
@ -292,13 +311,14 @@ typedef struct internal_state {
memory checker errors from longest match routines */ memory checker errors from longest match routines */
/* in trees.c */ /* in trees.c */
void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); void ZLIB_INTERNAL _tr_init(deflate_state *s);
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
ulg stored_len, int last)); ulg stored_len, int last);
void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, void ZLIB_INTERNAL _tr_align(deflate_state *s);
ulg stored_len, int last)); void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
ulg stored_len, int last);
#define d_code(dist) \ #define d_code(dist) \
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
@ -307,7 +327,7 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
* used. * used.
*/ */
#ifndef DEBUG #ifndef ZLIB_DEBUG
/* Inline versions of _tr_tally for speed: */ /* Inline versions of _tr_tally for speed: */
#if defined(GEN_TREES_H) || !defined(STDC) #if defined(GEN_TREES_H) || !defined(STDC)
@ -318,29 +338,52 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
extern const uch ZLIB_INTERNAL _dist_code[]; extern const uch ZLIB_INTERNAL _dist_code[];
#endif #endif
#ifdef LIT_MEM
# define _tr_tally_lit(s, c, flush) \ # define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \ { uch cc = (c); \
s->d_buf[s->last_lit] = 0; \ s->d_buf[s->sym_next] = 0; \
s->l_buf[s->last_lit++] = cc; \ s->l_buf[s->sym_next++] = cc; \
s->dyn_ltree[cc].Freq++; \ s->dyn_ltree[cc].Freq++; \
flush = (s->last_lit == s->lit_bufsize-1); \ flush = (s->sym_next == s->sym_end); \
} }
# define _tr_tally_dist(s, distance, length, flush) \ # define _tr_tally_dist(s, distance, length, flush) \
{ uch len = (length); \ { uch len = (uch)(length); \
ush dist = (distance); \ ush dist = (ush)(distance); \
s->d_buf[s->last_lit] = dist; \ s->d_buf[s->sym_next] = dist; \
s->l_buf[s->last_lit++] = len; \ s->l_buf[s->sym_next++] = len; \
dist--; \ dist--; \
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
s->dyn_dtree[d_code(dist)].Freq++; \ s->dyn_dtree[d_code(dist)].Freq++; \
flush = (s->last_lit == s->lit_bufsize-1); \ flush = (s->sym_next == s->sym_end); \
} }
#else #else
# define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \
s->sym_buf[s->sym_next++] = 0; \
s->sym_buf[s->sym_next++] = 0; \
s->sym_buf[s->sym_next++] = cc; \
s->dyn_ltree[cc].Freq++; \
flush = (s->sym_next == s->sym_end); \
}
# define _tr_tally_dist(s, distance, length, flush) \
{ uch len = (uch)(length); \
ush dist = (ush)(distance); \
s->sym_buf[s->sym_next++] = (uch)dist; \
s->sym_buf[s->sym_next++] = (uch)(dist >> 8); \
s->sym_buf[s->sym_next++] = len; \
dist--; \
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
s->dyn_dtree[d_code(dist)].Freq++; \
flush = (s->sym_next == s->sym_end); \
}
#endif
#else
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
# define _tr_tally_dist(s, distance, length, flush) \ # define _tr_tally_dist(s, distance, length, flush) \
flush = _tr_tally(s, distance, length) flush = _tr_tally(s, distance, length)
#endif #endif
ABC_NAMESPACE_HEADER_END ABC_NAMESPACE_HEADER_END
#endif /* DEFLATE_H */ #endif /* DEFLATE_H */

View File

@ -12,11 +12,11 @@
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
/* gzclose() is in a separate file so that it is linked in only if it is used. /* 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 That way the other gzclose functions can be used instead to avoid linking in
unneeded compression or decompression routines. */ unneeded compression or decompression routines. */
int ZEXPORT gzclose(gzFile file) int ZEXPORT gzclose(gzFile file) {
{
#ifndef NO_GZCOMPRESS #ifndef NO_GZCOMPRESS
gz_statep state; gz_statep state;
@ -31,3 +31,4 @@ int ZEXPORT gzclose(gzFile file)
} }
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,5 @@
/* gzguts.h -- zlib internal header definitions for gz* operations /* gzguts.h -- zlib internal header definitions for gz* operations
* Copyright (C) 2004, 2005, 2010 Mark Adler * Copyright (C) 2004-2026 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -7,17 +7,28 @@
# ifndef _LARGEFILE_SOURCE # ifndef _LARGEFILE_SOURCE
# define _LARGEFILE_SOURCE 1 # define _LARGEFILE_SOURCE 1
# endif # endif
# ifdef _FILE_OFFSET_BITS # undef _FILE_OFFSET_BITS
# undef _FILE_OFFSET_BITS # undef _TIME_BITS
# endif
#endif #endif
#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) #ifdef HAVE_HIDDEN
# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
#else #else
# define ZLIB_INTERNAL # define ZLIB_INTERNAL
#endif #endif
#if defined(_WIN32)
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS
# endif
# ifndef _CRT_NONSTDC_NO_DEPRECATE
# define _CRT_NONSTDC_NO_DEPRECATE
# endif
#endif
#include <stdio.h> #include <stdio.h>
#include "zlib.h" #include "zlib.h"
#ifdef STDC #ifdef STDC
@ -25,26 +36,93 @@
# include <stdlib.h> # include <stdlib.h>
# include <limits.h> # include <limits.h>
#endif #endif
#ifndef _POSIX_C_SOURCE
# define _POSIX_C_SOURCE 200112L
#endif
#include <fcntl.h> #include <fcntl.h>
#ifdef _WIN32
# include <stddef.h>
#else
# include <unistd.h> /* for read, write, close, lseek */
#endif
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
# include <io.h>
# include <sys/stat.h>
#endif
#if defined(_WIN32) && !defined(WIDECHAR)
# define WIDECHAR
#endif
#ifdef NO_DEFLATE /* for compatibility with old definition */ #ifdef NO_DEFLATE /* for compatibility with old definition */
# define NO_GZCOMPRESS # define NO_GZCOMPRESS
#endif #endif
#ifdef _MSC_VER #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
# include <io.h> # ifndef HAVE_VSNPRINTF
# define vsnprintf _vsnprintf # define HAVE_VSNPRINTF
# endif
#endif
#if defined(__CYGWIN__)
# ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF
# endif
#endif
#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
# ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF
# endif
#endif
#ifndef HAVE_VSNPRINTF
# if !defined(NO_vsnprintf) && \
(defined(MSDOS) || defined(__TURBOC__) || defined(__SASC) || \
defined(VMS) || defined(__OS400) || defined(__MVS__))
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
but for now we just assume it doesn't. */
# define NO_vsnprintf
# endif
# ifdef WIN32
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
# ifndef vsnprintf
# define vsnprintf _vsnprintf
# endif
# endif
# elif !defined(__STDC_VERSION__) || __STDC_VERSION__-0 < 199901L
/* Otherwise if C89/90, assume no C99 snprintf() or vsnprintf() */
# ifndef NO_snprintf
# define NO_snprintf
# endif
# ifndef NO_vsnprintf
# define NO_vsnprintf
# endif
# endif
#endif
/* unlike snprintf (which is required in C99), _snprintf does not guarantee
null termination of the result -- however this is only used in gzlib.c where
the result is assured to fit in the space provided */
#if defined(_MSC_VER) && _MSC_VER < 1900
# define snprintf _snprintf
#endif #endif
#ifndef local #ifndef local
# define local static # define local static
#endif #endif
/* compile with -Dlocal if your debugger can't find static symbols */ /* since "static" is used to mean two completely different things in C, we
define "local" for the non-static meaning of "static", for readability
(compile with -Dlocal if your debugger can't find static symbols) */
/* gz* functions always use library allocation functions */ /* gz* functions always use library allocation functions */
#ifndef STDC #ifndef STDC
extern voidp malloc OF((uInt size)); extern voidp malloc(uInt size);
extern void free OF((voidpf ptr)); extern void free(voidpf ptr);
#endif #endif
/* get errno and strerror definition */ /* get errno and strerror definition */
@ -52,7 +130,7 @@
# include <windows.h> # include <windows.h>
# define zstrerror() gz_strwinerror((DWORD)GetLastError()) # define zstrerror() gz_strwinerror((DWORD)GetLastError())
#else #else
# ifdef STDC # ifndef NO_STRERROR
# include <errno.h> # include <errno.h>
# define zstrerror() strerror(errno) # define zstrerror() strerror(errno)
# else # else
@ -60,28 +138,27 @@
# endif # endif
#endif #endif
#include <stdio.h>
#include "misc/util/abc_global.h" #include "misc/util/abc_global.h"
ABC_NAMESPACE_HEADER_START ABC_NAMESPACE_HEADER_START
#ifdef _WIN32
#define open _open
#define close _close
#define lseek _lseek
#define read _read
#define write _write
#endif
/* provide prototypes for these when building zlib without LFS */ /* provide prototypes for these when building zlib without LFS */
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
#endif #endif
/* default i/o buffer size -- double this for output when reading */ /* default memLevel */
#if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
#else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
#endif
/* default i/o buffer size -- double this for output when reading (this and
twice this must be able to fit in an unsigned type) */
#define GZBUFSIZE 8192 #define GZBUFSIZE 8192
/* gzip modes, also provide a little integrity check on the passed structure */ /* gzip modes, also provide a little integrity check on the passed structure */
@ -97,29 +174,33 @@ ABC_NAMESPACE_HEADER_START
/* internal gzip file state data structure */ /* internal gzip file state data structure */
typedef struct { typedef struct {
/* exposed contents for gzgetc() macro */
struct gzFile_s x; /* "x" for exposed */
/* x.have: number of bytes available at x.next */
/* x.next: next output data to deliver or write */
/* x.pos: current position in uncompressed data */
/* used for both reading and writing */ /* used for both reading and writing */
int mode; /* see gzip modes above */ int mode; /* see gzip modes above */
int fd; /* file descriptor */ int fd; /* file descriptor */
char *path; /* path or fd for error messages */ 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 size; /* buffer size, zero if not allocated yet */
unsigned want; /* requested buffer size, default is GZBUFSIZE */ unsigned want; /* requested buffer size, default is GZBUFSIZE */
unsigned char *in; /* input buffer */ unsigned char *in; /* input buffer (double-sized when writing) */
unsigned char *out; /* output buffer (double-sized when reading) */ unsigned char *out; /* output buffer (double-sized when reading) */
unsigned char *next; /* next output data to deliver or write */ int direct; /* 0 if processing gzip, 1 if transparent */
/* just for reading */ /* just for reading */
unsigned have; /* amount of output data unused at next */ int junk; /* -1 = start, 1 = junk candidate, 0 = in gzip */
int eof; /* true if end of input file reached */
z_off64_t start; /* where the gzip data started, for rewinding */
z_off64_t raw; /* where the raw data started, for seeking */
int how; /* 0: get header, 1: copy, 2: decompress */ int how; /* 0: get header, 1: copy, 2: decompress */
int direct; /* true if last read direct, false if gzip */ int again; /* true if EAGAIN or EWOULDBLOCK on last i/o */
z_off64_t start; /* where the gzip data started, for rewinding */
int eof; /* true if end of input file reached */
int past; /* true if read requested past end */
/* just for writing */ /* just for writing */
int level; /* compression level */ int level; /* compression level */
int strategy; /* compression strategy */ int strategy; /* compression strategy */
int reset; /* true if a reset is pending after a Z_FINISH */
/* seek request */ /* seek request */
z_off64_t skip; /* amount to skip (already rewound if backwards) */ z_off64_t skip; /* amount to skip (already rewound if backwards) */
int seek; /* true if seek request pending */
/* error information */ /* error information */
int err; /* error code */ int err; /* error code */
char *msg; /* error message */ char *msg; /* error message */
@ -129,19 +210,15 @@ typedef struct {
typedef gz_state FAR *gz_statep; typedef gz_state FAR *gz_statep;
/* shared functions */ /* shared functions */
void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
#if defined UNDER_CE #if defined UNDER_CE
char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
#endif #endif
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
value -- needed when comparing unsigned to z_off64_t, which is signed value -- needed when comparing unsigned to z_off64_t, which is signed
(possible z_off64_t types off_t, off64_t, and long are all signed) */ (possible z_off64_t types off_t, off64_t, and long are all signed) */
#ifdef INT_MAX unsigned ZLIB_INTERNAL gz_intmax(void);
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) #define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
#else
unsigned ZLIB_INTERNAL gz_intmax OF((void));
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
#endif
ABC_NAMESPACE_HEADER_END ABC_NAMESPACE_HEADER_END

View File

@ -1,5 +1,5 @@
/* gzlib.c -- zlib functions common to reading and writing gzip files /* gzlib.c -- zlib functions common to reading and writing gzip files
* Copyright (C) 2004, 2010 Mark Adler * Copyright (C) 2004-2026 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -12,16 +12,17 @@
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
#if defined(__DJGPP__)
# define LSEEK llseek
#elif defined(_WIN32) && !defined(__BORLANDC__) && !defined(UNDER_CE)
# define LSEEK _lseeki64
#elif defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
# define LSEEK lseek64 # define LSEEK lseek64
#else #else
# define LSEEK lseek # define LSEEK lseek
#endif #endif
/* Local functions */
local void gz_reset OF((gz_statep));
local gzFile gz_open OF((const char *, int, const char *));
#if defined UNDER_CE #if defined UNDER_CE
/* Map the Windows error number in ERROR to a locale-dependent error message /* Map the Windows error number in ERROR to a locale-dependent error message
@ -33,8 +34,7 @@ local gzFile gz_open OF((const char *, int, const char *));
The gz_strwinerror function does not change the current setting of The gz_strwinerror function does not change the current setting of
GetLastError. */ GetLastError. */
char ZLIB_INTERNAL *gz_strwinerror (DWORD error) char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
{
static char buf[1024]; static char buf[1024];
wchar_t *msgbuf; wchar_t *msgbuf;
@ -60,7 +60,7 @@ char ZLIB_INTERNAL *gz_strwinerror (DWORD error)
msgbuf[chars] = 0; msgbuf[chars] = 0;
} }
wcstombs(buf, msgbuf, chars + 1); wcstombs(buf, msgbuf, chars + 1); /* assumes buf is big enough */
LocalFree(msgbuf); LocalFree(msgbuf);
} }
else { else {
@ -74,24 +74,35 @@ char ZLIB_INTERNAL *gz_strwinerror (DWORD error)
#endif /* UNDER_CE */ #endif /* UNDER_CE */
/* Reset gzip file state */ /* Reset gzip file state */
local void gz_reset(gz_statep state) local void gz_reset(gz_statep state) {
{ state->x.have = 0; /* no output data available */
if (state->mode == GZ_READ) { /* for reading ... */ if (state->mode == GZ_READ) { /* for reading ... */
state->have = 0; /* no output data available */
state->eof = 0; /* not at end of file */ state->eof = 0; /* not at end of file */
state->past = 0; /* have not read past end yet */
state->how = LOOK; /* look for gzip header */ state->how = LOOK; /* look for gzip header */
state->direct = 1; /* default for empty file */ state->junk = -1; /* mark first member */
} }
state->seek = 0; /* no seek request pending */ else /* for writing ... */
state->reset = 0; /* no deflateReset pending */
state->again = 0; /* no stalled i/o yet */
state->skip = 0; /* no seek request pending */
gz_error(state, Z_OK, NULL); /* clear error */ gz_error(state, Z_OK, NULL); /* clear error */
state->pos = 0; /* no uncompressed data yet */ state->x.pos = 0; /* no uncompressed data yet */
state->strm.avail_in = 0; /* no input data yet */ state->strm.avail_in = 0; /* no input data yet */
} }
/* Open a gzip file either by name or file descriptor. */ /* Open a gzip file either by name or file descriptor. */
local gzFile gz_open(const char *path, int fd, const char *mode) local gzFile gz_open(const void *path, int fd, const char *mode) {
{
gz_statep state; gz_statep state;
z_size_t len;
int oflag = 0;
#ifdef O_EXCL
int exclusive = 0;
#endif
/* check input */
if (path == NULL || mode == NULL)
return NULL;
/* allocate gzFile structure to return */ /* allocate gzFile structure to return */
state = (gz_statep)malloc(sizeof(gz_state)); state = (gz_statep)malloc(sizeof(gz_state));
@ -99,12 +110,14 @@ local gzFile gz_open(const char *path, int fd, const char *mode)
return NULL; return NULL;
state->size = 0; /* no buffers allocated yet */ state->size = 0; /* no buffers allocated yet */
state->want = GZBUFSIZE; /* requested buffer size */ state->want = GZBUFSIZE; /* requested buffer size */
state->err = Z_OK; /* no error yet */
state->msg = NULL; /* no error message yet */ state->msg = NULL; /* no error message yet */
/* interpret mode */ /* interpret mode */
state->mode = GZ_NONE; state->mode = GZ_NONE;
state->level = Z_DEFAULT_COMPRESSION; state->level = Z_DEFAULT_COMPRESSION;
state->strategy = Z_DEFAULT_STRATEGY; state->strategy = Z_DEFAULT_STRATEGY;
state->direct = 0;
while (*mode) { while (*mode) {
if (*mode >= '0' && *mode <= '9') if (*mode >= '0' && *mode <= '9')
state->level = *mode - '0'; state->level = *mode - '0';
@ -126,6 +139,16 @@ local gzFile gz_open(const char *path, int fd, const char *mode)
return NULL; return NULL;
case 'b': /* ignore -- will request binary anyway */ case 'b': /* ignore -- will request binary anyway */
break; break;
#ifdef O_CLOEXEC
case 'e':
oflag |= O_CLOEXEC;
break;
#endif
#ifdef O_EXCL
case 'x':
exclusive = 1;
break;
#endif
case 'f': case 'f':
state->strategy = Z_FILTERED; state->strategy = Z_FILTERED;
break; break;
@ -137,6 +160,18 @@ local gzFile gz_open(const char *path, int fd, const char *mode)
break; break;
case 'F': case 'F':
state->strategy = Z_FIXED; state->strategy = Z_FIXED;
break;
case 'G':
state->direct = -1;
break;
#ifdef O_NONBLOCK
case 'N':
oflag |= O_NONBLOCK;
break;
#endif
case 'T':
state->direct = 1;
break;
default: /* could consider as an error, but just ignore */ default: /* could consider as an error, but just ignore */
; ;
} }
@ -149,37 +184,100 @@ local gzFile gz_open(const char *path, int fd, const char *mode)
return NULL; return NULL;
} }
/* direct is 0, 1 if "T", or -1 if "G" (last "G" or "T" wins) */
if (state->mode == GZ_READ) {
if (state->direct == 1) {
/* can't force a transparent read */
free(state);
return NULL;
}
if (state->direct == 0)
/* default when reading is auto-detect of gzip vs. transparent --
start with a transparent assumption in case of an empty file */
state->direct = 1;
}
else if (state->direct == -1) {
/* "G" has no meaning when writing -- disallow it */
free(state);
return NULL;
}
/* if reading, direct == 1 for auto-detect, -1 for gzip only; if writing or
appending, direct == 0 for gzip, 1 for transparent (copy in to out) */
/* save the path name for error messages */ /* save the path name for error messages */
state->path = (char *)malloc(strlen(path) + 1); #ifdef WIDECHAR
if (fd == -2)
len = wcstombs(NULL, path, 0);
else
#endif
len = strlen((const char *)path);
state->path = (char *)malloc(len + 1);
if (state->path == NULL) { if (state->path == NULL) {
free(state); free(state);
return NULL; return NULL;
} }
strcpy(state->path, path); #ifdef WIDECHAR
if (fd == -2) {
if (len)
wcstombs(state->path, path, len + 1);
else
*(state->path) = 0;
}
else
#endif
{
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
(void)snprintf(state->path, len + 1, "%s", (const char *)path);
#else
strcpy(state->path, (const char *)path);
#endif
}
/* open the file with the appropriate mode (or just use fd) */ /* compute the flags for open() */
state->fd = fd != -1 ? fd : oflag |=
open(path,
#ifdef O_LARGEFILE #ifdef O_LARGEFILE
O_LARGEFILE | O_LARGEFILE |
#endif #endif
#ifdef O_BINARY #ifdef O_BINARY
O_BINARY | O_BINARY |
#endif #endif
(state->mode == GZ_READ ? (state->mode == GZ_READ ?
O_RDONLY : O_RDONLY :
(O_WRONLY | O_CREAT | ( (O_WRONLY | O_CREAT |
state->mode == GZ_WRITE ? #ifdef O_EXCL
O_TRUNC : (exclusive ? O_EXCL : 0) |
O_APPEND))), #endif
0666); (state->mode == GZ_WRITE ?
O_TRUNC :
O_APPEND)));
/* open the file with the appropriate flags (or just use fd) */
if (fd == -1)
state->fd = open((const char *)path, oflag, 0666);
#ifdef WIDECHAR
else if (fd == -2)
state->fd = _wopen(path, oflag, _S_IREAD | _S_IWRITE);
#endif
else {
#ifdef O_NONBLOCK
if (oflag & O_NONBLOCK)
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
#endif
#ifdef O_CLOEXEC
if (oflag & O_CLOEXEC)
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | O_CLOEXEC);
#endif
state->fd = fd;
}
if (state->fd == -1) { if (state->fd == -1) {
free(state->path); free(state->path);
free(state); free(state);
return NULL; return NULL;
} }
if (state->mode == GZ_APPEND) if (state->mode == GZ_APPEND) {
LSEEK(state->fd, 0, SEEK_END); /* so gzoffset() is correct */
state->mode = GZ_WRITE; /* simplify later checks */ state->mode = GZ_WRITE; /* simplify later checks */
}
/* save the current position for rewinding (only if reading) */ /* save the current position for rewinding (only if reading) */
if (state->mode == GZ_READ) { if (state->mode == GZ_READ) {
@ -195,34 +293,41 @@ local gzFile gz_open(const char *path, int fd, const char *mode)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
gzFile ZEXPORT gzopen(const char *path, const char *mode) gzFile ZEXPORT gzopen(const char *path, const char *mode) {
{
return gz_open(path, -1, mode); return gz_open(path, -1, mode);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
gzFile ZEXPORT gzopen64(const char *path, const char *mode) gzFile ZEXPORT gzopen64(const char *path, const char *mode) {
{
return gz_open(path, -1, mode); return gz_open(path, -1, mode);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
gzFile ZEXPORT gzdopen(int fd, const char *mode) gzFile ZEXPORT gzdopen(int fd, const char *mode) {
{
char *path; /* identifier for error messages */ char *path; /* identifier for error messages */
gzFile gz; gzFile gz;
if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL) if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
return NULL; return NULL;
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
(void)snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd);
#else
sprintf(path, "<fd:%d>", fd); /* for debugging */ sprintf(path, "<fd:%d>", fd); /* for debugging */
#endif
gz = gz_open(path, fd, mode); gz = gz_open(path, fd, mode);
free(path); free(path);
return gz; return gz;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzbuffer(gzFile file, unsigned size) #ifdef WIDECHAR
{ gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode) {
return gz_open(path, -2, mode);
}
#endif
/* -- see zlib.h -- */
int ZEXPORT gzbuffer(gzFile file, unsigned size) {
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@ -237,15 +342,16 @@ int ZEXPORT gzbuffer(gzFile file, unsigned size)
return -1; return -1;
/* check and set requested size */ /* check and set requested size */
if (size == 0) if ((size << 1) < size)
return -1; return -1; /* need to be able to double it */
if (size < 8)
size = 8; /* needed to behave well with flushing */
state->want = size; state->want = size;
return 0; return 0;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzrewind(gzFile file) int ZEXPORT gzrewind(gzFile file) {
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@ -254,7 +360,8 @@ int ZEXPORT gzrewind(gzFile file)
state = (gz_statep)file; state = (gz_statep)file;
/* check that we're reading and that there's no error */ /* check that we're reading and that there's no error */
if (state->mode != GZ_READ || state->err != Z_OK) if (state->mode != GZ_READ ||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
return -1; return -1;
/* back up and start over */ /* back up and start over */
@ -265,8 +372,7 @@ int ZEXPORT gzrewind(gzFile file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
{
unsigned n; unsigned n;
z_off64_t ret; z_off64_t ret;
gz_statep state; gz_statep state;
@ -279,7 +385,7 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence)
return -1; return -1;
/* check that there's no error */ /* check that there's no error */
if (state->err != Z_OK) if (state->err != Z_OK && state->err != Z_BUF_ERROR)
return -1; return -1;
/* can only seek from start or relative to current position */ /* can only seek from start or relative to current position */
@ -288,31 +394,33 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence)
/* normalize offset to a SEEK_CUR specification */ /* normalize offset to a SEEK_CUR specification */
if (whence == SEEK_SET) if (whence == SEEK_SET)
offset -= state->pos; offset -= state->x.pos;
else if (state->seek) else {
offset += state->skip; offset += state->past ? 0 : state->skip;
state->seek = 0; state->skip = 0;
}
/* if within raw area while reading, just go there */ /* if within raw area while reading, just go there */
if (state->mode == GZ_READ && state->how == COPY && if (state->mode == GZ_READ && state->how == COPY &&
state->pos + offset >= state->raw) { state->x.pos + offset >= 0) {
ret = LSEEK(state->fd, offset - state->have, SEEK_CUR); ret = LSEEK(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR);
if (ret == -1) if (ret == -1)
return -1; return -1;
state->have = 0; state->x.have = 0;
state->eof = 0; state->eof = 0;
state->seek = 0; state->past = 0;
state->skip = 0;
gz_error(state, Z_OK, NULL); gz_error(state, Z_OK, NULL);
state->strm.avail_in = 0; state->strm.avail_in = 0;
state->pos += offset; state->x.pos += offset;
return state->pos; return state->x.pos;
} }
/* calculate skip amount, rewinding if needed for back seek when reading */ /* calculate skip amount, rewinding if needed for back seek when reading */
if (offset < 0) { if (offset < 0) {
if (state->mode != GZ_READ) /* writing -- can't go backwards */ if (state->mode != GZ_READ) /* writing -- can't go backwards */
return -1; return -1;
offset += state->pos; offset += state->x.pos;
if (offset < 0) /* before start of file! */ if (offset < 0) /* before start of file! */
return -1; return -1;
if (gzrewind(file) == -1) /* rewind, then skip to offset */ if (gzrewind(file) == -1) /* rewind, then skip to offset */
@ -321,25 +429,21 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence)
/* if reading, skip what's in output buffer (one less gzgetc() check) */ /* if reading, skip what's in output buffer (one less gzgetc() check) */
if (state->mode == GZ_READ) { if (state->mode == GZ_READ) {
n = GT_OFF(state->have) || (z_off64_t)state->have > offset ? n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
(unsigned)offset : state->have; (unsigned)offset : state->x.have;
state->have -= n; state->x.have -= n;
state->next += n; state->x.next += n;
state->pos += n; state->x.pos += n;
offset -= n; offset -= n;
} }
/* request skip (if not zero) */ /* request skip (if not zero) */
if (offset) { state->skip = offset;
state->seek = 1; return state->x.pos + offset;
state->skip = offset;
}
return state->pos + offset;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) {
{
z_off64_t ret; z_off64_t ret;
ret = gzseek64(file, (z_off64_t)offset, whence); ret = gzseek64(file, (z_off64_t)offset, whence);
@ -347,8 +451,7 @@ z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off64_t ZEXPORT gztell64(gzFile file) z_off64_t ZEXPORT gztell64(gzFile file) {
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@ -359,12 +462,11 @@ z_off64_t ZEXPORT gztell64(gzFile file)
return -1; return -1;
/* return position */ /* return position */
return state->pos + (state->seek ? state->skip : 0); return state->x.pos + (state->past ? 0 : state->skip);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off_t ZEXPORT gztell(gzFile file) z_off_t ZEXPORT gztell(gzFile file) {
{
z_off64_t ret; z_off64_t ret;
ret = gztell64(file); ret = gztell64(file);
@ -372,8 +474,7 @@ z_off_t ZEXPORT gztell(gzFile file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off64_t ZEXPORT gzoffset64(gzFile file) z_off64_t ZEXPORT gzoffset64(gzFile file) {
{
z_off64_t offset; z_off64_t offset;
gz_statep state; gz_statep state;
@ -394,8 +495,7 @@ z_off64_t ZEXPORT gzoffset64(gzFile file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off_t ZEXPORT gzoffset(gzFile file) z_off_t ZEXPORT gzoffset(gzFile file) {
{
z_off64_t ret; z_off64_t ret;
ret = gzoffset64(file); ret = gzoffset64(file);
@ -403,8 +503,7 @@ z_off_t ZEXPORT gzoffset(gzFile file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzeof(gzFile file) int ZEXPORT gzeof(gzFile file) {
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@ -415,13 +514,11 @@ int ZEXPORT gzeof(gzFile file)
return 0; return 0;
/* return end-of-file state */ /* return end-of-file state */
return state->mode == GZ_READ ? return state->mode == GZ_READ ? state->past : 0;
(state->eof && state->strm.avail_in == 0 && state->have == 0) : 0;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
const char * ZEXPORT gzerror(gzFile file, int *errnum) const char * ZEXPORT gzerror(gzFile file, int *errnum) {
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@ -434,12 +531,12 @@ const char * ZEXPORT gzerror(gzFile file, int *errnum)
/* return error information */ /* return error information */
if (errnum != NULL) if (errnum != NULL)
*errnum = state->err; *errnum = state->err;
return state->msg == NULL ? "" : state->msg; return state->err == Z_MEM_ERROR ? "out of memory" :
(state->msg == NULL ? "" : state->msg);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
void ZEXPORT gzclearerr(gzFile file) void ZEXPORT gzclearerr(gzFile file) {
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@ -450,8 +547,10 @@ void ZEXPORT gzclearerr(gzFile file)
return; return;
/* clear error and end-of-file */ /* clear error and end-of-file */
if (state->mode == GZ_READ) if (state->mode == GZ_READ) {
state->eof = 0; state->eof = 0;
state->past = 0;
}
gz_error(state, Z_OK, NULL); gz_error(state, Z_OK, NULL);
} }
@ -461,8 +560,7 @@ void ZEXPORT gzclearerr(gzFile file)
memory). Simply save the error message as a static string. If there is an 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 allocation failure constructing the error message, then convert the error to
out of memory. */ out of memory. */
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
{
/* free previously allocated message and clear */ /* free previously allocated message and clear */
if (state->msg != NULL) { if (state->msg != NULL) {
if (state->err != Z_MEM_ERROR) if (state->err != Z_MEM_ERROR)
@ -470,48 +568,53 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
state->msg = NULL; state->msg = NULL;
} }
/* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
if (err != Z_OK && err != Z_BUF_ERROR && !state->again)
state->x.have = 0;
/* set error code, and if no message, then done */ /* set error code, and if no message, then done */
state->err = err; state->err = err;
if (msg == NULL) if (msg == NULL)
return; return;
/* for an out of memory error, save as static string */ /* for an out of memory error, return literal string when requested */
if (err == Z_MEM_ERROR) { if (err == Z_MEM_ERROR)
state->msg = (char *)msg;
return; return;
}
/* construct error message with path */ /* construct error message with path */
if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
NULL) {
state->err = Z_MEM_ERROR; state->err = Z_MEM_ERROR;
state->msg = (char *)"out of memory";
return; return;
} }
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
(void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
"%s%s%s", state->path, ": ", msg);
#else
strcpy(state->msg, state->path); strcpy(state->msg, state->path);
strcat(state->msg, ": "); strcat(state->msg, ": ");
strcat(state->msg, msg); strcat(state->msg, msg);
return; #endif
} }
#ifndef INT_MAX
/* portably return maximum value for an int (when limits.h presumed not /* portably return maximum value for an int (when limits.h presumed not
available) -- we need to do this to cover cases where 2's complement not available) -- we need to do this to cover cases where 2's complement not
used, since C standard permits 1's complement and sign-bit representations, used, since C standard permits 1's complement and sign-bit representations,
otherwise we could just use ((unsigned)-1) >> 1 */ otherwise we could just use ((unsigned)-1) >> 1 */
unsigned ZLIB_INTERNAL gz_intmax() unsigned ZLIB_INTERNAL gz_intmax(void) {
{ #ifdef INT_MAX
unsigned p, q; return INT_MAX;
#else
unsigned p = 1, q;
p = 1;
do { do {
q = p; q = p;
p <<= 1; p <<= 1;
p++; p++;
} while (p > q); } while (p > q);
return q >> 1; return q >> 1;
}
#endif #endif
}
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_END

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/* gzwrite.c -- zlib functions for writing gzip files /* gzwrite.c -- zlib functions for writing gzip files
* Copyright (C) 2004, 2005, 2010 Mark Adler * Copyright (C) 2004-2026 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -12,66 +12,102 @@
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
/* 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_off64_t));
/* Initialize state for writing a gzip file. Mark initialization by setting /* Initialize state for writing a gzip file. Mark initialization by setting
state->size to non-zero. Return -1 on failure or 0 on success. */ state->size to non-zero. Return -1 on a memory allocation failure, or 0 on
local int gz_init(gz_statep state) success. */
{ local int gz_init(gz_statep state) {
int ret; int ret;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
/* allocate input and output buffers */ /* allocate input buffer (double size for gzprintf) */
state->in = (unsigned char *)malloc(state->want); state->in = (unsigned char *)malloc(state->want << 1);
state->out = (unsigned char *)malloc(state->want); if (state->in == NULL) {
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"); gz_error(state, Z_MEM_ERROR, "out of memory");
return -1; return -1;
} }
/* allocate deflate memory, set up for gzip compression */ /* only need output buffer and deflate state if compressing */
strm->zalloc = Z_NULL; if (!state->direct) {
strm->zfree = Z_NULL; /* allocate output buffer */
strm->opaque = Z_NULL; state->out = (unsigned char *)malloc(state->want);
ret = deflateInit2(strm, state->level, Z_DEFLATED, if (state->out == NULL) {
15 + 16, 8, state->strategy); free(state->in);
if (ret != Z_OK) { gz_error(state, Z_MEM_ERROR, "out of memory");
free(state->in); return -1;
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,
MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
if (ret != Z_OK) {
free(state->out);
free(state->in);
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
strm->next_in = NULL;
} }
/* mark state as initialized */ /* mark state as initialized */
state->size = state->want; state->size = state->want;
/* initialize write buffer */ /* initialize write buffer if compressing */
strm->avail_out = state->size; if (!state->direct) {
strm->next_out = state->out; strm->avail_out = state->size;
state->next = strm->next_out; strm->next_out = state->out;
state->x.next = strm->next_out;
}
return 0; return 0;
} }
/* Compress whatever is at avail_in and next_in and write to the output file. /* 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. Return -1 if there is an error writing to the output file or if gz_init()
flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, fails to allocate memory, otherwise 0. flush is assumed to be a valid
then the deflate() state is reset to start a new gzip stream. */ deflate() flush value. If flush is Z_FINISH, then the deflate() state is
local int gz_comp(gz_statep state, int flush) reset to start a new gzip stream. If gz->direct is true, then simply write
{ to the output file without compressing, and ignore flush. */
int ret, got; local int gz_comp(gz_statep state, int flush) {
unsigned have; int ret, writ;
unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
/* allocate memory if this is the first time through */ /* allocate memory if this is the first time through */
if (state->size == 0 && gz_init(state) == -1) if (state->size == 0 && gz_init(state) == -1)
return -1; return -1;
/* write directly if requested */
if (state->direct) {
while (strm->avail_in) {
errno = 0;
state->again = 0;
put = strm->avail_in > max ? max : strm->avail_in;
writ = (int)write(state->fd, strm->next_in, put);
if (writ < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK)
state->again = 1;
gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
strm->avail_in -= (unsigned)writ;
strm->next_in += writ;
}
return 0;
}
/* check for a pending reset */
if (state->reset) {
/* don't start a new gzip member unless there is data to write and
we're not flushing */
if (strm->avail_in == 0 && flush == Z_NO_FLUSH)
return 0;
deflateReset(strm);
state->reset = 0;
}
/* run deflate() on provided input until it produces no more output */ /* run deflate() on provided input until it produces no more output */
ret = Z_OK; ret = Z_OK;
do { do {
@ -79,17 +115,25 @@ local int gz_comp(gz_statep state, int flush)
doing Z_FINISH then don't write until we get to Z_STREAM_END */ doing Z_FINISH then don't write until we get to Z_STREAM_END */
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
(flush != Z_FINISH || ret == Z_STREAM_END))) { (flush != Z_FINISH || ret == Z_STREAM_END))) {
have = (unsigned)(strm->next_out - state->next); while (strm->next_out > state->x.next) {
if (have && ((got = write(state->fd, state->next, have)) < 0 || errno = 0;
(unsigned)got != have)) { state->again = 0;
gz_error(state, Z_ERRNO, zstrerror()); put = strm->next_out - state->x.next > (int)max ? max :
return -1; (unsigned)(strm->next_out - state->x.next);
writ = (int)write(state->fd, state->x.next, put);
if (writ < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK)
state->again = 1;
gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
state->x.next += writ;
} }
if (strm->avail_out == 0) { if (strm->avail_out == 0) {
strm->avail_out = state->size; strm->avail_out = state->size;
strm->next_out = state->out; strm->next_out = state->out;
state->x.next = state->out;
} }
state->next = strm->next_out;
} }
/* compress */ /* compress */
@ -105,16 +149,18 @@ local int gz_comp(gz_statep state, int flush)
/* if that completed a deflate stream, allow another to start */ /* if that completed a deflate stream, allow another to start */
if (flush == Z_FINISH) if (flush == Z_FINISH)
deflateReset(strm); state->reset = 1;
/* all done, no errors */ /* all done, no errors */
return 0; return 0;
} }
/* Compress len zeros to output. Return -1 on error, 0 on success. */ /* Compress state->skip (> 0) zeros to output. Return -1 on a write error or
local int gz_zero(gz_statep state, z_off64_t len) memory allocation failure by gz_comp(), or 0 on success. state->skip is
{ updated with the number of successfully written zeros, in case there is a
int first; stall on a non-blocking write destination. */
local int gz_zero(gz_statep state) {
int first, ret;
unsigned n; unsigned n;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@ -122,49 +168,34 @@ local int gz_zero(gz_statep state, z_off64_t len)
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
return -1; return -1;
/* compress len zeros (len guaranteed > 0) */ /* compress state->skip zeros */
first = 1; first = 1;
while (len) { do {
n = GT_OFF(state->size) || (z_off64_t)state->size > len ? n = GT_OFF(state->size) || (z_off64_t)state->size > state->skip ?
(unsigned)len : state->size; (unsigned)state->skip : state->size;
if (first) { if (first) {
memset(state->in, 0, (size_t)n); memset(state->in, 0, n);
first = 0; first = 0;
} }
strm->avail_in = n; strm->avail_in = n;
strm->next_in = state->in; strm->next_in = state->in;
state->pos += n; ret = gz_comp(state, Z_NO_FLUSH);
if (gz_comp(state, Z_NO_FLUSH) == -1) n -= strm->avail_in;
state->x.pos += n;
state->skip -= n;
if (ret == -1)
return -1; return -1;
len -= n; } while (state->skip);
}
return 0; return 0;
} }
/* -- see zlib.h -- */ /* Write len bytes from buf to file. Return the number of bytes written. If
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len) the returned value is less than len, then there was an error. If the error
{ was a non-blocking stall, then the number of bytes consumed is returned.
unsigned put = len; For any other error, 0 is returned. */
unsigned n; local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
gz_statep state; z_size_t put = len;
z_streamp strm; int ret;
/* get internal structure */
if (file == NULL)
return 0;
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;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
if ((int)len < 0) {
gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
return 0;
}
/* if len is zero, avoid unnecessary operations */ /* if len is zero, avoid unnecessary operations */
if (len == 0) if (len == 0)
@ -175,50 +206,114 @@ int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
return 0; return 0;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->skip && gz_zero(state) == -1)
state->seek = 0; return 0;
if (gz_zero(state, state->skip) == -1)
return 0;
}
/* for small len, copy to input buffer, otherwise compress directly */ /* for small len, copy to input buffer, otherwise compress directly */
if (len < state->size) { if (len < state->size) {
/* copy to input buffer, compress when full */ /* copy to input buffer, compress when full */
do { for (;;) {
if (strm->avail_in == 0) unsigned have, copy;
strm->next_in = state->in;
n = state->size - strm->avail_in; if (state->strm.avail_in == 0)
if (n > len) state->strm.next_in = state->in;
n = len; have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
memcpy(strm->next_in + strm->avail_in, buf, n); state->in);
strm->avail_in += n; copy = state->size - have;
state->pos += n; if (copy > len)
buf = (char *)buf + n; copy = (unsigned)len;
len -= n; memcpy(state->in + have, buf, copy);
if (len && gz_comp(state, Z_NO_FLUSH) == -1) state->strm.avail_in += copy;
return 0; state->x.pos += copy;
} while (len); buf = (const char *)buf + copy;
len -= copy;
if (len == 0)
break;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return state->again ? put - len : 0;
}
} }
else { else {
/* consume whatever's left in the input buffer */ /* consume whatever's left in the input buffer */
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
return 0; return 0;
/* directly compress user buffer to file */ /* directly compress user buffer to file */
strm->avail_in = len; state->strm.next_in = (z_const Bytef *)buf;
strm->next_in = (unsigned char *)(voidp)buf; do {
state->pos += len; unsigned n = (unsigned)-1;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return 0; if (n > len)
n = (unsigned)len;
state->strm.avail_in = n;
ret = gz_comp(state, Z_NO_FLUSH);
n -= state->strm.avail_in;
state->x.pos += n;
len -= n;
if (ret == -1)
return state->again ? put - len : 0;
} while (len);
} }
/* input was all buffered or compressed (put will fit in int) */ /* input was all buffered or compressed */
return (int)put; return put;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzputc(gzFile file, int c) int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len) {
{ gz_statep state;
/* get internal structure */
if (file == NULL)
return 0;
state = (gz_statep)file;
/* check that we're writing and that there's no (serious) error */
if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
return 0;
gz_error(state, Z_OK, NULL);
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids a flaw in the interface) */
if ((int)len < 0) {
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return 0;
}
/* write len bytes from buf (the return value will fit in an int) */
return (int)gz_write(state, buf, len);
}
/* -- see zlib.h -- */
z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems,
gzFile file) {
z_size_t len;
gz_statep state;
/* get internal structure */
if (file == NULL)
return 0;
state = (gz_statep)file;
/* check that we're writing and that there's no (serious) error */
if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
return 0;
gz_error(state, Z_OK, NULL);
/* compute bytes to read -- error on overflow */
len = nitems * size;
if (size && len / size != nitems) {
gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
return 0;
}
/* write len bytes to buf, return the number of full items written */
return len ? gz_write(state, buf, len) / size : 0;
}
/* -- see zlib.h -- */
int ZEXPORT gzputc(gzFile file, int c) {
unsigned have;
unsigned char buf[1]; unsigned char buf[1];
gz_statep state; gz_statep state;
z_streamp strm; z_streamp strm;
@ -229,223 +324,320 @@ int ZEXPORT gzputc(gzFile file, int c)
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no (serious) error */
if (state->mode != GZ_WRITE || state->err != Z_OK) if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
return -1; return -1;
gz_error(state, Z_OK, NULL);
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->skip && gz_zero(state) == -1)
state->seek = 0; return -1;
if (gz_zero(state, state->skip) == -1)
return -1;
}
/* try writing to input buffer for speed (state->size == 0 if buffer not /* try writing to input buffer for speed (state->size == 0 if buffer not
initialized) */ initialized) */
if (strm->avail_in < state->size) { if (state->size) {
if (strm->avail_in == 0) if (strm->avail_in == 0)
strm->next_in = state->in; strm->next_in = state->in;
strm->next_in[strm->avail_in++] = c; have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
state->pos++; if (have < state->size) {
return c; state->in[have] = (unsigned char)c;
strm->avail_in++;
state->x.pos++;
return c & 0xff;
}
} }
/* no room in buffer or not initialized, use gz_write() */ /* no room in buffer or not initialized, use gz_write() */
buf[0] = c; buf[0] = (unsigned char)c;
if (gzwrite(file, buf, 1) != 1) if (gz_write(state, buf, 1) != 1)
return -1; return -1;
return c; return c & 0xff;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzputs(gzFile file, const char *str) int ZEXPORT gzputs(gzFile file, const char *s) {
{ z_size_t len, put;
int ret;
unsigned len;
/* write string */
len = (unsigned)strlen(str);
ret = gzwrite(file, str, len);
return ret == 0 && len != 0 ? -1 : ret;
}
#ifdef STDC
#include <stdarg.h>
/* -- see zlib.h -- */
int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
{
int size, len;
gz_statep state; gz_statep state;
z_streamp strm;
va_list va;
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
/* check that we're writing and that there's no (serious) error */
if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
return -1;
gz_error(state, Z_OK, NULL);
/* write string */
len = strlen(s);
if ((int)len < 0 || (unsigned)len != len) {
gz_error(state, Z_STREAM_ERROR, "string length does not fit in int");
return -1;
}
put = gz_write(state, s, len);
return len && put == 0 ? -1 : (int)put;
}
#if (((!defined(STDC) && !defined(Z_HAVE_STDARG_H)) || !defined(NO_vsnprintf)) && \
(defined(STDC) || defined(Z_HAVE_STDARG_H) || !defined(NO_snprintf))) || \
defined(ZLIB_INSECURE)
/* If the second half of the input buffer is occupied, write out the contents.
If there is any input remaining due to a non-blocking stall on write, move
it to the start of the buffer. Return true if this did not open up the
second half of the buffer. state->err should be checked after this to
handle a gz_comp() error. */
local int gz_vacate(gz_statep state) {
z_streamp strm;
strm = &(state->strm);
if (strm->next_in + strm->avail_in <= state->in + state->size)
return 0;
(void)gz_comp(state, Z_NO_FLUSH);
if (strm->avail_in == 0) {
strm->next_in = state->in;
return 0;
}
memmove(state->in, strm->next_in, strm->avail_in);
strm->next_in = state->in;
return strm->avail_in > state->size;
}
#endif
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
ABC_NAMESPACE_IMPL_END
#include <stdarg.h>
ABC_NAMESPACE_IMPL_START
/* -- see zlib.h -- */
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
#if defined(NO_vsnprintf) && !defined(ZLIB_INSECURE)
#warning "vsnprintf() not available -- gzprintf() stub returns Z_STREAM_ERROR"
#warning "you can recompile with ZLIB_INSECURE defined to use vsprintf()"
/* prevent use of insecure vsprintf(), unless purposefully requested */
(void)file, (void)format, (void)va;
return Z_STREAM_ERROR;
#else
int len, ret;
char *next;
gz_statep state;
z_streamp strm;
/* get internal structure */
if (file == NULL)
return Z_STREAM_ERROR;
state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no (serious) error */
if (state->mode != GZ_WRITE || state->err != Z_OK) if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
return 0; return Z_STREAM_ERROR;
gz_error(state, Z_OK, NULL);
/* make sure we have some buffer space */ /* make sure we have some buffer space */
if (state->size == 0 && gz_init(state) == -1) if (state->size == 0 && gz_init(state) == -1)
return 0; return state->err;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->skip && gz_zero(state) == -1)
state->seek = 0; return state->err;
if (gz_zero(state, state->skip) == -1)
return 0; /* do the printf() into the input buffer, put length in len -- the input
buffer is double-sized just for this function, so there should be
state->size bytes available after the current contents */
ret = gz_vacate(state);
if (state->err) {
if (ret && state->again) {
/* There was a non-blocking stall on write, resulting in the part
of the second half of the output buffer being occupied. Return
a Z_BUF_ERROR to let the application know that this gzprintf()
needs to be retried. */
gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf");
}
if (!state->again)
return state->err;
} }
if (strm->avail_in == 0)
/* consume whatever's left in the input buffer */ strm->next_in = state->in;
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
return 0; next[state->size - 1] = 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 NO_vsnprintf
# ifdef HAS_vsprintf_void # ifdef HAS_vsprintf_void
(void)vsprintf(state->in, format, va); (void)vsprintf(next, format, va);
va_end(va); for (len = 0; len < state->size; len++)
for (len = 0; len < size; len++) if (next[len] == 0) break;
if (state->in[len] == 0) break;
# else # else
len = vsprintf(state->in, format, va); len = vsprintf(next, format, va);
va_end(va);
# endif # endif
#else #else
# ifdef HAS_vsnprintf_void # ifdef HAS_vsnprintf_void
(void)vsnprintf(state->in, size, format, va); (void)vsnprintf(next, state->size, format, va);
va_end(va); len = strlen(next);
len = strlen(state->in);
# else # else
len = vsnprintf((char *)(state->in), size, format, va); len = vsnprintf(next, state->size, format, va);
va_end(va);
# endif # endif
#endif #endif
/* check that printf() results fit in buffer */ /* check that printf() results fit in buffer */
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
return 0; return 0;
/* update buffer and position, defer compression until needed */ /* update buffer and position */
strm->avail_in = (unsigned)len; strm->avail_in += (unsigned)len;
strm->next_in = state->in; state->x.pos += len;
state->pos += len;
/* write out buffer if more than half is occupied */
ret = gz_vacate(state);
if (state->err && !state->again)
return state->err;
return len; return len;
#endif
} }
#else /* !STDC */ int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) {
va_list va;
int ret;
va_start(va, format);
ret = gzvprintf(file, format, va);
va_end(va);
return ret;
}
#else /* !STDC && !Z_HAVE_STDARG_H */
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORTVA gzprintf (gzFile file, const char *format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3,
int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20) int a4, int a5, int a6, int a7, int a8, int a9, int a10,
{ int a11, int a12, int a13, int a14, int a15, int a16,
int size, len; int a17, int a18, int a19, int a20) {
#if defined(NO_snprintf) && !defined(ZLIB_INSECURE)
#warning "snprintf() not available -- gzprintf() stub returns Z_STREAM_ERROR"
#warning "you can recompile with ZLIB_INSECURE defined to use sprintf()"
/* prevent use of insecure sprintf(), unless purposefully requested */
(void)file, (void)format, (void)a1, (void)a2, (void)a3, (void)a4, (void)a5,
(void)a6, (void)a7, (void)a8, (void)a9, (void)a10, (void)a11, (void)a12,
(void)a13, (void)a14, (void)a15, (void)a16, (void)a17, (void)a18,
(void)a19, (void)a20;
return Z_STREAM_ERROR;
#else
int ret;
unsigned len, left;
char *next;
gz_statep state; gz_statep state;
z_streamp strm; z_streamp strm;
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return Z_STREAM_ERROR;
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
/* check that we're writing and that there's no error */ /* check that can really pass pointer in ints */
if (state->mode != GZ_WRITE || state->err != Z_OK) if (sizeof(int) != sizeof(void *))
return 0; return Z_STREAM_ERROR;
/* check that we're writing and that there's no (serious) error */
if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
return Z_STREAM_ERROR;
gz_error(state, Z_OK, NULL);
/* make sure we have some buffer space */ /* make sure we have some buffer space */
if (state->size == 0 && gz_init(state) == -1) if (state->size == 0 && gz_init(state) == -1)
return 0; return state->err;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->skip && gz_zero(state) == -1)
state->seek = 0; return state->err;
if (gz_zero(state, state->skip) == -1)
return 0; /* do the printf() into the input buffer, put length in len -- the input
buffer is double-sized just for this function, so there is guaranteed to
be state->size bytes available after the current contents */
ret = gz_vacate(state);
if (state->err) {
if (ret && state->again) {
/* There was a non-blocking stall on write, resulting in the part
of the second half of the output buffer being occupied. Return
a Z_BUF_ERROR to let the application know that this gzprintf()
needs to be retried. */
gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf");
}
if (!state->again)
return state->err;
} }
if (strm->avail_in == 0)
/* consume whatever's left in the input buffer */ strm->next_in = state->in;
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) next = (char *)(strm->next_in + strm->avail_in);
return 0; next[state->size - 1] = 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 NO_snprintf
# ifdef HAS_sprintf_void # ifdef HAS_sprintf_void
sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8, sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); a13, a14, a15, a16, a17, a18, a19, a20);
for (len = 0; len < size; len++) for (len = 0; len < size; len++)
if (state->in[len] == 0) break; if (next[len] == 0)
break;
# else # else
len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8, len = sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); a12, a13, a14, a15, a16, a17, a18, a19, a20);
# endif # endif
#else #else
# ifdef HAS_snprintf_void # ifdef HAS_snprintf_void
snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8, snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, a9,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
len = strlen(state->in); len = strlen(next);
# else # else
len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8, len = snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
# endif # endif
#endif #endif
/* check that printf() results fit in buffer */ /* check that printf() results fit in buffer */
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) if (len == 0 || len >= state->size || next[state->size - 1] != 0)
return 0; return 0;
/* update buffer and position, defer compression until needed */ /* update buffer and position, compress first half if past that */
strm->avail_in = (unsigned)len; strm->avail_in += len;
strm->next_in = state->in; state->x.pos += len;
state->pos += len;
return len; /* write out buffer if more than half is occupied */
ret = gz_vacate(state);
if (state->err && !state->again)
return state->err;
return (int)len;
#endif
} }
#endif #endif
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzflush(gzFile file, int flush) int ZEXPORT gzflush(gzFile file, int flush) {
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return Z_STREAM_ERROR;
state = (gz_statep)file; state = (gz_statep)file;
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no (serious) error */
if (state->mode != GZ_WRITE || state->err != Z_OK) if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again))
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
gz_error(state, Z_OK, NULL);
/* check flush parameter */ /* check flush parameter */
if (flush < 0 || flush > Z_FINISH) if (flush < 0 || flush > Z_FINISH)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->skip && gz_zero(state) == -1)
state->seek = 0; return state->err;
if (gz_zero(state, state->skip) == -1)
return -1;
}
/* compress remaining data with requested flush */ /* compress remaining data with requested flush */
gz_comp(state, flush); (void)gz_comp(state, flush);
return state->err; return state->err;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzsetparams(gzFile file, int level, int strategy) int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
{
gz_statep state; gz_statep state;
z_streamp strm; z_streamp strm;
@ -455,25 +647,24 @@ int ZEXPORT gzsetparams(gzFile file, int level, int strategy)
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
/* check that we're writing and that there's no error */ /* check that we're compressing and that there's no (serious) error */
if (state->mode != GZ_WRITE || state->err != Z_OK) if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again) ||
state->direct)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
gz_error(state, Z_OK, NULL);
/* if no change is requested, then do nothing */ /* if no change is requested, then do nothing */
if (level == state->level && strategy == state->strategy) if (level == state->level && strategy == state->strategy)
return Z_OK; return Z_OK;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->skip && gz_zero(state) == -1)
state->seek = 0; return state->err;
if (gz_zero(state, state->skip) == -1)
return -1;
}
/* change compression parameters for subsequent input */ /* change compression parameters for subsequent input */
if (state->size) { if (state->size) {
/* flush previous input with previous parameters before changing */ /* flush previous input with previous parameters before changing */
if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) if (strm->avail_in && gz_comp(state, Z_BLOCK) == -1)
return state->err; return state->err;
deflateParams(strm, level, strategy); deflateParams(strm, level, strategy);
} }
@ -483,9 +674,8 @@ int ZEXPORT gzsetparams(gzFile file, int level, int strategy)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzclose_w(gzFile file) int ZEXPORT gzclose_w(gzFile file) {
{ int ret = Z_OK;
int ret = 0;
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@ -498,23 +688,26 @@ int ZEXPORT gzclose_w(gzFile file)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->skip && gz_zero(state) == -1)
state->seek = 0; ret = state->err;
ret += gz_zero(state, state->skip);
}
/* flush, free memory, and close file */ /* flush, free memory, and close file */
ret += gz_comp(state, Z_FINISH); if (gz_comp(state, Z_FINISH) == -1)
(void)deflateEnd(&(state->strm)); ret = state->err;
free(state->out); if (state->size) {
free(state->in); if (!state->direct) {
(void)deflateEnd(&(state->strm));
free(state->out);
}
free(state->in);
}
gz_error(state, Z_OK, NULL); gz_error(state, Z_OK, NULL);
free(state->path); free(state->path);
ret += close(state->fd); if (close(state->fd) == -1)
ret = Z_ERRNO;
free(state); free(state);
return ret ? Z_ERRNO : Z_OK; return ret;
} }
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,5 @@
/* infback.c -- inflate using a call-back interface /* infback.c -- inflate using a call-back interface
* Copyright (C) 1995-2009 Mark Adler * Copyright (C) 1995-2026 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -22,8 +22,6 @@
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
/* function prototypes */
local void fixedtables OF((struct inflate_state FAR *state));
/* /*
strm provides memory allocation functions in zalloc and zfree, or strm provides memory allocation functions in zalloc and zfree, or
@ -32,8 +30,9 @@ local void fixedtables OF((struct inflate_state FAR *state));
windowBits is in the range 8..15, and window is a user-supplied windowBits is in the range 8..15, and window is a user-supplied
window and output buffer that is 2**windowBits bytes. window and output buffer that is 2**windowBits bytes.
*/ */
int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, unsigned char FAR *window, const char *version, int stream_size) int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
{ unsigned char FAR *window, const char *version,
int stream_size) {
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
@ -44,76 +43,34 @@ int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, unsigned char FAR *
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */ strm->msg = Z_NULL; /* in case we return an error */
if (strm->zalloc == (alloc_func)0) { if (strm->zalloc == (alloc_func)0) {
#ifdef Z_SOLO
return Z_STREAM_ERROR;
#else
strm->zalloc = zcalloc; strm->zalloc = zcalloc;
strm->opaque = (voidpf)0; strm->opaque = (voidpf)0;
#endif
} }
if (strm->zfree == (free_func)0) strm->zfree = zcfree; if (strm->zfree == (free_func)0)
#ifdef Z_SOLO
return Z_STREAM_ERROR;
#else
strm->zfree = zcfree;
#endif
state = (struct inflate_state FAR *)ZALLOC(strm, 1, state = (struct inflate_state FAR *)ZALLOC(strm, 1,
sizeof(struct inflate_state)); sizeof(struct inflate_state));
if (state == Z_NULL) return Z_MEM_ERROR; if (state == Z_NULL) return Z_MEM_ERROR;
Tracev((stderr, "inflate: allocated\n")); Tracev((stderr, "inflate: allocated\n"));
strm->state = (struct internal_state FAR *)state; strm->state = (struct internal_state FAR *)state;
state->dmax = 32768U; state->dmax = 32768U;
state->wbits = windowBits; state->wbits = (uInt)windowBits;
state->wsize = 1U << windowBits; state->wsize = 1U << windowBits;
state->window = window; state->window = window;
state->wnext = 0; state->wnext = 0;
state->whave = 0; state->whave = 0;
state->sane = 1;
return Z_OK; return Z_OK;
} }
/*
Return state with length and distance decoding tables and index sizes set to
fixed code decoding. Normally this returns fixed tables from inffixed.h.
If BUILDFIXED is defined, then instead this routine builds the tables the
first time it's called, and returns those tables the first time and
thereafter. This reduces the size of the code by about 2K bytes, in
exchange for a little execution time. However, BUILDFIXED should not be
used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe.
*/
local void fixedtables(struct inflate_state FAR *state)
{
#ifdef BUILDFIXED
static int virgin = 1;
static code *lenfix, *distfix;
static code fixed[544];
/* build fixed huffman tables if first call (may not be thread safe) */
if (virgin) {
unsigned sym, bits;
static code *next;
/* literal/length table */
sym = 0;
while (sym < 144) state->lens[sym++] = 8;
while (sym < 256) state->lens[sym++] = 9;
while (sym < 280) state->lens[sym++] = 7;
while (sym < 288) state->lens[sym++] = 8;
next = fixed;
lenfix = next;
bits = 9;
inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
/* distance table */
sym = 0;
while (sym < 32) state->lens[sym++] = 5;
distfix = next;
bits = 5;
inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
/* do this just once */
virgin = 0;
}
#else /* !BUILDFIXED */
# include "inffixed.h"
#endif /* BUILDFIXED */
state->lencode = lenfix;
state->lenbits = 9;
state->distcode = distfix;
state->distbits = 5;
}
/* Macros for inflateBack(): */ /* Macros for inflateBack(): */
/* Load returned state from inflate_fast() */ /* Load returned state from inflate_fast() */
@ -239,10 +196,10 @@ local void fixedtables(struct inflate_state FAR *state)
inflateBack() can also return Z_STREAM_ERROR if the input parameters inflateBack() can also return Z_STREAM_ERROR if the input parameters
are not correct, i.e. strm is Z_NULL or the state was not initialized. are not correct, i.e. strm is Z_NULL or the state was not initialized.
*/ */
int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func out, void FAR *out_desc) int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
{ out_func out, void FAR *out_desc) {
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned char FAR *next; /* next input */ z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */ unsigned char FAR *put; /* next output */
unsigned have, left; /* available input and output */ unsigned have, left; /* available input and output */
unsigned long hold; /* bit buffer */ unsigned long hold; /* bit buffer */
@ -293,7 +250,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
state->mode = STORED; state->mode = STORED;
break; break;
case 1: /* fixed block */ case 1: /* fixed block */
fixedtables(state); inflate_fixed(state);
Tracev((stderr, "inflate: fixed codes block%s\n", Tracev((stderr, "inflate: fixed codes block%s\n",
state->last ? " (last)" : "")); state->last ? " (last)" : ""));
state->mode = LEN; /* decode codes */ state->mode = LEN; /* decode codes */
@ -303,8 +260,8 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
state->last ? " (last)" : "")); state->last ? " (last)" : ""));
state->mode = TABLE; state->mode = TABLE;
break; break;
case 3: default:
strm->msg = (char *)"invalid block type"; strm->msg = (z_const char *)"invalid block type";
state->mode = BAD; state->mode = BAD;
} }
DROPBITS(2); DROPBITS(2);
@ -315,7 +272,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
BYTEBITS(); /* go to byte boundary */ BYTEBITS(); /* go to byte boundary */
NEEDBITS(32); NEEDBITS(32);
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
strm->msg = (char *)"invalid stored block lengths"; strm->msg = (z_const char *)"invalid stored block lengths";
state->mode = BAD; state->mode = BAD;
break; break;
} }
@ -353,7 +310,8 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
DROPBITS(4); DROPBITS(4);
#ifndef PKZIP_BUG_WORKAROUND #ifndef PKZIP_BUG_WORKAROUND
if (state->nlen > 286 || state->ndist > 30) { if (state->nlen > 286 || state->ndist > 30) {
strm->msg = (char *)"too many length or distance symbols"; strm->msg = (z_const char *)
"too many length or distance symbols";
state->mode = BAD; state->mode = BAD;
break; break;
} }
@ -375,7 +333,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
ret = inflate_table(CODES, state->lens, 19, &(state->next), ret = inflate_table(CODES, state->lens, 19, &(state->next),
&(state->lenbits), state->work); &(state->lenbits), state->work);
if (ret) { if (ret) {
strm->msg = (char *)"invalid code lengths set"; strm->msg = (z_const char *)"invalid code lengths set";
state->mode = BAD; state->mode = BAD;
break; break;
} }
@ -390,7 +348,6 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
PULLBYTE(); PULLBYTE();
} }
if (here.val < 16) { if (here.val < 16) {
NEEDBITS(here.bits);
DROPBITS(here.bits); DROPBITS(here.bits);
state->lens[state->have++] = here.val; state->lens[state->have++] = here.val;
} }
@ -399,7 +356,8 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
NEEDBITS(here.bits + 2); NEEDBITS(here.bits + 2);
DROPBITS(here.bits); DROPBITS(here.bits);
if (state->have == 0) { if (state->have == 0) {
strm->msg = (char *)"invalid bit length repeat"; strm->msg = (z_const char *)
"invalid bit length repeat";
state->mode = BAD; state->mode = BAD;
break; break;
} }
@ -422,7 +380,8 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
DROPBITS(7); DROPBITS(7);
} }
if (state->have + copy > state->nlen + state->ndist) { if (state->have + copy > state->nlen + state->ndist) {
strm->msg = (char *)"invalid bit length repeat"; strm->msg = (z_const char *)
"invalid bit length repeat";
state->mode = BAD; state->mode = BAD;
break; break;
} }
@ -436,7 +395,8 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
/* check for end-of-block code (better have one) */ /* check for end-of-block code (better have one) */
if (state->lens[256] == 0) { if (state->lens[256] == 0) {
strm->msg = (char *)"invalid code -- missing end-of-block"; strm->msg = (z_const char *)
"invalid code -- missing end-of-block";
state->mode = BAD; state->mode = BAD;
break; break;
} }
@ -450,7 +410,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
&(state->lenbits), state->work); &(state->lenbits), state->work);
if (ret) { if (ret) {
strm->msg = (char *)"invalid literal/lengths set"; strm->msg = (z_const char *)"invalid literal/lengths set";
state->mode = BAD; state->mode = BAD;
break; break;
} }
@ -459,12 +419,13 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
&(state->next), &(state->distbits), state->work); &(state->next), &(state->distbits), state->work);
if (ret) { if (ret) {
strm->msg = (char *)"invalid distances set"; strm->msg = (z_const char *)"invalid distances set";
state->mode = BAD; state->mode = BAD;
break; break;
} }
Tracev((stderr, "inflate: codes ok\n")); Tracev((stderr, "inflate: codes ok\n"));
state->mode = LEN; state->mode = LEN;
/* fallthrough */
case LEN: case LEN:
/* use inflate_fast() if we have enough input and output */ /* use inflate_fast() if we have enough input and output */
@ -517,7 +478,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
/* invalid code */ /* invalid code */
if (here.op & 64) { if (here.op & 64) {
strm->msg = (char *)"invalid literal/length code"; strm->msg = (z_const char *)"invalid literal/length code";
state->mode = BAD; state->mode = BAD;
break; break;
} }
@ -549,7 +510,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
} }
DROPBITS(here.bits); DROPBITS(here.bits);
if (here.op & 64) { if (here.op & 64) {
strm->msg = (char *)"invalid distance code"; strm->msg = (z_const char *)"invalid distance code";
state->mode = BAD; state->mode = BAD;
break; break;
} }
@ -564,7 +525,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
} }
if (state->offset > state->wsize - (state->whave < state->wsize ? if (state->offset > state->wsize - (state->whave < state->wsize ?
left : 0)) { left : 0)) {
strm->msg = (char *)"invalid distance too far back"; strm->msg = (z_const char *)"invalid distance too far back";
state->mode = BAD; state->mode = BAD;
break; break;
} }
@ -592,32 +553,33 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func
break; break;
case DONE: case DONE:
/* inflate stream terminated properly -- write leftover output */ /* inflate stream terminated properly */
ret = Z_STREAM_END; ret = Z_STREAM_END;
if (left < state->wsize) {
if (out(out_desc, state->window, state->wsize - left))
ret = Z_BUF_ERROR;
}
goto inf_leave; goto inf_leave;
case BAD: case BAD:
ret = Z_DATA_ERROR; ret = Z_DATA_ERROR;
goto inf_leave; goto inf_leave;
default: /* can't happen, but makes compilers happy */ default:
/* can't happen, but makes compilers happy */
ret = Z_STREAM_ERROR; ret = Z_STREAM_ERROR;
goto inf_leave; goto inf_leave;
} }
/* Return unused input */ /* Write leftover output and return unused input */
inf_leave: inf_leave:
if (left < state->wsize) {
if (out(out_desc, state->window, state->wsize - left) &&
ret == Z_STREAM_END)
ret = Z_BUF_ERROR;
}
strm->next_in = next; strm->next_in = next;
strm->avail_in = have; strm->avail_in = have;
return ret; return ret;
} }
int ZEXPORT inflateBackEnd(z_streamp strm) int ZEXPORT inflateBackEnd(z_streamp strm) {
{
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
ZFREE(strm, strm->state); ZFREE(strm, strm->state);
@ -626,6 +588,5 @@ int ZEXPORT inflateBackEnd(z_streamp strm)
return Z_OK; return Z_OK;
} }
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,5 @@
/* inffast.c -- fast decoding /* inffast.c -- fast decoding
* Copyright (C) 1995-2008, 2010 Mark Adler * Copyright (C) 1995-2026 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -15,26 +15,10 @@
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
#ifndef ASMINF
/* Allow machine dependent optimization for post-increment or pre-increment. #ifdef ASMINF
Based on testing to date, # pragma message("Assembler code may have bugs -- use at your own risk")
Pre-increment preferred for:
- PowerPC G3 (Adler)
- MIPS R5000 (Randers-Pehrson)
Post-increment preferred for:
- none
No measurable difference:
- Pentium III (Anderson)
- M68060 (Nikl)
*/
#ifdef POSTINC
# define OFF 0
# define PUP(a) *(a)++
#else #else
# define OFF 1
# define PUP(a) *++(a)
#endif
/* /*
Decode literal, length, and distance codes and write out the resulting Decode literal, length, and distance codes and write out the resulting
@ -71,11 +55,10 @@ ABC_NAMESPACE_IMPL_START
requires strm->avail_out >= 258 for each loop to avoid checking for requires strm->avail_out >= 258 for each loop to avoid checking for
output space. output space.
*/ */
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* inflate()'s starting value for strm->avail_out */ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned char FAR *in; /* local strm->next_in */ z_const unsigned char FAR *in; /* local strm->next_in */
unsigned char FAR *last; /* while in < last, enough input available */ z_const unsigned char FAR *last; /* have enough input while in < last */
unsigned char FAR *out; /* local strm->next_out */ unsigned char FAR *out; /* local strm->next_out */
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
unsigned char FAR *end; /* while out < end, enough space available */ unsigned char FAR *end; /* while out < end, enough space available */
@ -92,7 +75,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* inflate()'s
code const FAR *dcode; /* local strm->distcode */ code const FAR *dcode; /* local strm->distcode */
unsigned lmask; /* mask for first level of length codes */ unsigned lmask; /* mask for first level of length codes */
unsigned dmask; /* mask for first level of distance codes */ unsigned dmask; /* mask for first level of distance codes */
code here; /* retrieved table entry */ code const *here; /* retrieved table entry */
unsigned op; /* code bits, operation, extra bits, or */ unsigned op; /* code bits, operation, extra bits, or */
/* window position, window bytes to copy */ /* window position, window bytes to copy */
unsigned len; /* match length, unused bytes */ unsigned len; /* match length, unused bytes */
@ -101,9 +84,9 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* inflate()'s
/* copy state to local variables */ /* copy state to local variables */
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
in = strm->next_in - OFF; in = strm->next_in;
last = in + (strm->avail_in - 5); last = in + (strm->avail_in - 5);
out = strm->next_out - OFF; out = strm->next_out;
beg = out - (start - strm->avail_out); beg = out - (start - strm->avail_out);
end = out + (strm->avail_out - 257); end = out + (strm->avail_out - 257);
#ifdef INFLATE_STRICT #ifdef INFLATE_STRICT
@ -124,29 +107,29 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* inflate()'s
input data or output space */ input data or output space */
do { do {
if (bits < 15) { if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
} }
here = lcode[hold & lmask]; here = lcode + (hold & lmask);
dolen: dolen:
op = (unsigned)(here.bits); op = (unsigned)(here->bits);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(here.op); op = (unsigned)(here->op);
if (op == 0) { /* literal */ if (op == 0) { /* literal */
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
"inflate: literal '%c'\n" : "inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", here.val)); "inflate: literal 0x%02x\n", here->val));
PUP(out) = (unsigned char)(here.val); *out++ = (unsigned char)(here->val);
} }
else if (op & 16) { /* length base */ else if (op & 16) { /* length base */
len = (unsigned)(here.val); len = (unsigned)(here->val);
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (op) { if (op) {
if (bits < op) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
} }
len += (unsigned)hold & ((1U << op) - 1); len += (unsigned)hold & ((1U << op) - 1);
@ -155,32 +138,33 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* inflate()'s
} }
Tracevv((stderr, "inflate: length %u\n", len)); Tracevv((stderr, "inflate: length %u\n", len));
if (bits < 15) { if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
} }
here = dcode[hold & dmask]; here = dcode + (hold & dmask);
dodist: dodist:
op = (unsigned)(here.bits); op = (unsigned)(here->bits);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(here.op); op = (unsigned)(here->op);
if (op & 16) { /* distance base */ if (op & 16) { /* distance base */
dist = (unsigned)(here.val); dist = (unsigned)(here->val);
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (bits < op) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
if (bits < op) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
} }
} }
dist += (unsigned)hold & ((1U << op) - 1); dist += (unsigned)hold & ((1U << op) - 1);
#ifdef INFLATE_STRICT #ifdef INFLATE_STRICT
if (dist > dmax) { if (dist > dmax) {
strm->msg = (char *)"invalid distance too far back"; strm->msg = (z_const char *)
"invalid distance too far back";
state->mode = BAD; state->mode = BAD;
break; break;
} }
@ -193,38 +177,38 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* inflate()'s
op = dist - op; /* distance back in window */ op = dist - op; /* distance back in window */
if (op > whave) { if (op > whave) {
if (state->sane) { if (state->sane) {
strm->msg = strm->msg = (z_const char *)
(char *)"invalid distance too far back"; "invalid distance too far back";
state->mode = BAD; state->mode = BAD;
break; break;
} }
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
if (len <= op - whave) { if (len <= op - whave) {
do { do {
PUP(out) = 0; *out++ = 0;
} while (--len); } while (--len);
continue; continue;
} }
len -= op - whave; len -= op - whave;
do { do {
PUP(out) = 0; *out++ = 0;
} while (--op > whave); } while (--op > whave);
if (op == 0) { if (op == 0) {
from = out - dist; from = out - dist;
do { do {
PUP(out) = PUP(from); *out++ = *from++;
} while (--len); } while (--len);
continue; continue;
} }
#endif #endif
} }
from = window - OFF; from = window;
if (wnext == 0) { /* very common case */ if (wnext == 0) { /* very common case */
from += wsize - op; from += wsize - op;
if (op < len) { /* some from window */ if (op < len) { /* some from window */
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); *out++ = *from++;
} while (--op); } while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
@ -235,14 +219,14 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* inflate()'s
if (op < len) { /* some from end of window */ if (op < len) { /* some from end of window */
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); *out++ = *from++;
} while (--op); } while (--op);
from = window - OFF; from = window;
if (wnext < len) { /* some from start of window */ if (wnext < len) { /* some from start of window */
op = wnext; op = wnext;
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); *out++ = *from++;
} while (--op); } while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
@ -253,50 +237,50 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* inflate()'s
if (op < len) { /* some from window */ if (op < len) { /* some from window */
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); *out++ = *from++;
} while (--op); } while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
} }
while (len > 2) { while (len > 2) {
PUP(out) = PUP(from); *out++ = *from++;
PUP(out) = PUP(from); *out++ = *from++;
PUP(out) = PUP(from); *out++ = *from++;
len -= 3; len -= 3;
} }
if (len) { if (len) {
PUP(out) = PUP(from); *out++ = *from++;
if (len > 1) if (len > 1)
PUP(out) = PUP(from); *out++ = *from++;
} }
} }
else { else {
from = out - dist; /* copy direct from output */ from = out - dist; /* copy direct from output */
do { /* minimum length is three */ do { /* minimum length is three */
PUP(out) = PUP(from); *out++ = *from++;
PUP(out) = PUP(from); *out++ = *from++;
PUP(out) = PUP(from); *out++ = *from++;
len -= 3; len -= 3;
} while (len > 2); } while (len > 2);
if (len) { if (len) {
PUP(out) = PUP(from); *out++ = *from++;
if (len > 1) if (len > 1)
PUP(out) = PUP(from); *out++ = *from++;
} }
} }
} }
else if ((op & 64) == 0) { /* 2nd level distance code */ else if ((op & 64) == 0) { /* 2nd level distance code */
here = dcode[here.val + (hold & ((1U << op) - 1))]; here = dcode + here->val + (hold & ((1U << op) - 1));
goto dodist; goto dodist;
} }
else { else {
strm->msg = (char *)"invalid distance code"; strm->msg = (z_const char *)"invalid distance code";
state->mode = BAD; state->mode = BAD;
break; break;
} }
} }
else if ((op & 64) == 0) { /* 2nd level length code */ else if ((op & 64) == 0) { /* 2nd level length code */
here = lcode[here.val + (hold & ((1U << op) - 1))]; here = lcode + here->val + (hold & ((1U << op) - 1));
goto dolen; goto dolen;
} }
else if (op & 32) { /* end-of-block */ else if (op & 32) { /* end-of-block */
@ -305,7 +289,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* inflate()'s
break; break;
} }
else { else {
strm->msg = (char *)"invalid literal/length code"; strm->msg = (z_const char *)"invalid literal/length code";
state->mode = BAD; state->mode = BAD;
break; break;
} }
@ -318,8 +302,8 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* inflate()'s
hold &= (1U << bits) - 1; hold &= (1U << bits) - 1;
/* update state and return */ /* update state and return */
strm->next_in = in + OFF; strm->next_in = in;
strm->next_out = out + OFF; strm->next_out = out;
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
strm->avail_out = (unsigned)(out < end ? strm->avail_out = (unsigned)(out < end ?
257 + (end - out) : 257 - (out - end)); 257 + (end - out) : 257 - (out - end));
@ -344,8 +328,5 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* inflate()'s
#endif /* !ASMINF */ #endif /* !ASMINF */
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_END

View File

@ -3,13 +3,14 @@
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
ABC_NAMESPACE_HEADER_START
/* WARNING: this file should *not* be used by applications. It is /* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
ABC_NAMESPACE_HEADER_START void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start);
void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start));
ABC_NAMESPACE_HEADER_END ABC_NAMESPACE_HEADER_END

View File

@ -1,98 +1,94 @@
/* inffixed.h -- table for decoding fixed codes /* inffixed.h -- table for decoding fixed codes
* Generated automatically by makefixed(). * Generated automatically by makefixed().
*/ */
/* WARNING: this file should *not* be used by applications. It /* WARNING: this file should *not* be used by applications.
is part of the implementation of the compression library and It is part of the implementation of this library and is
is subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
//ABC_NAMESPACE_HEADER_START static const code lenfix[512] = {
{96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
{0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
{0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
{0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
{0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
{21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
{0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
{0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
{18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
{0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
{0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
{0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
{20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
{0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
{0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
{16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
{0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
{0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
{0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
{0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
{0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
{0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
{0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
{17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
{0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
{0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
{0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
{19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
{0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
{0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
{16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
{0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
{0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
{0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
{0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
{20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
{0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
{0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
{17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
{0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
{0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
{0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
{20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
{0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
{0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
{0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
{16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
{0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
{0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
{0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
{0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
{0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
{0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
{0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
{16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
{0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
{0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
{0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
{19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
{0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
{0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
{16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
{0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
{0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
{0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
{0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
{64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
{0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
{0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
{18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
{0,9,255}
};
static const code lenfix[512] = { static const code distfix[32] = {
{96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
{0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
{0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
{0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
{0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
{21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, {22,5,193},{64,5,0}
{0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, };
{0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
{18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
{0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
{0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
{0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
{20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
{0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
{0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
{16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
{0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
{0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
{0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
{0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
{0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
{0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
{0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
{17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
{0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
{0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
{0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
{19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
{0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
{0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
{16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
{0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
{0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
{0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
{0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
{20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
{0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
{0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
{17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
{0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
{0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
{0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
{20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
{0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
{0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
{0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
{16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
{0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
{0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
{0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
{0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
{0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
{0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
{0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
{16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
{0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
{0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
{0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
{19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
{0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
{0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
{16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
{0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
{0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
{0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
{0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
{64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
{0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
{0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
{18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
{0,9,255}
};
static const code distfix[32] = {
{16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
{21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
{18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
{19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
{16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
{22,5,193},{64,5,0}
};
//ABC_NAMESPACE_HEADER_END

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,16 @@
/* inflate.h -- internal inflate state definition /* inflate.h -- internal inflate state definition
* Copyright (C) 1995-2009 Mark Adler * Copyright (C) 1995-2019 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
ABC_NAMESPACE_HEADER_START
/* WARNING: this file should *not* be used by applications. It is /* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
ABC_NAMESPACE_HEADER_START
/* define NO_GZIP when compiling if you want to disable gzip header and /* define NO_GZIP when compiling if you want to disable gzip header and
trailer decoding by inflate(). NO_GZIP would be used to avoid linking in trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
the crc code when it is not needed. For shared libraries, gzip decoding the crc code when it is not needed. For shared libraries, gzip decoding
@ -20,7 +21,7 @@ ABC_NAMESPACE_HEADER_START
/* Possible inflate modes between inflate() calls */ /* Possible inflate modes between inflate() calls */
typedef enum { typedef enum {
HEAD, /* i: waiting for magic header */ HEAD = 16180, /* i: waiting for magic header */
FLAGS, /* i: waiting for method and flags (gzip) */ FLAGS, /* i: waiting for method and flags (gzip) */
TIME, /* i: waiting for modification time (gzip) */ TIME, /* i: waiting for modification time (gzip) */
OS, /* i: waiting for extra flags and operating system (gzip) */ OS, /* i: waiting for extra flags and operating system (gzip) */
@ -79,13 +80,17 @@ typedef enum {
CHECK -> LENGTH -> DONE CHECK -> LENGTH -> DONE
*/ */
/* state maintained between inflate() calls. Approximately 10K bytes. */ /* State maintained between inflate() calls -- approximately 7K bytes, not
including the allocated sliding window, which is up to 32K bytes. */
struct inflate_state { struct inflate_state {
z_streamp strm; /* pointer back to this zlib stream */
inflate_mode mode; /* current inflate mode */ inflate_mode mode; /* current inflate mode */
int last; /* true if processing last block */ int last; /* true if processing last block */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
bit 2 true to validate check value */
int havedict; /* true if dictionary provided */ int havedict; /* true if dictionary provided */
int flags; /* gzip header method and flags (0 if zlib) */ int flags; /* gzip header method and flags, 0 if zlib, or
-1 if raw or no header yet */
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
unsigned long check; /* protected copy of check value */ unsigned long check; /* protected copy of check value */
unsigned long total; /* protected copy of output count */ unsigned long total; /* protected copy of output count */
@ -98,7 +103,7 @@ struct inflate_state {
unsigned char FAR *window; /* allocated sliding window, if needed */ unsigned char FAR *window; /* allocated sliding window, if needed */
/* bit accumulator */ /* bit accumulator */
unsigned long hold; /* input bit accumulator */ unsigned long hold; /* input bit accumulator */
unsigned bits; /* number of bits in "in" */ unsigned bits; /* number of bits in hold */
/* for string and stored block copying */ /* for string and stored block copying */
unsigned length; /* literal or length of data to copy */ unsigned length; /* literal or length of data to copy */
unsigned offset; /* distance back to copy string from */ unsigned offset; /* distance back to copy string from */

View File

@ -1,8 +1,17 @@
/* inftrees.c -- generate Huffman trees for efficient decoding /* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2010 Mark Adler * Copyright (C) 1995-2026 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
#ifdef MAKEFIXED
# ifndef BUILDFIXED
# define BUILDFIXED
# endif
#endif
#ifdef BUILDFIXED
# define Z_ONCE
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -10,13 +19,19 @@
#include "zutil.h" #include "zutil.h"
#include "inftrees.h" #include "inftrees.h"
#include "inflate.h"
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
#ifndef NULL
# define NULL 0
#endif
#define MAXBITS 15 #define MAXBITS 15
const char inflate_copyright[] = const char inflate_copyright[] =
" inflate 1.2.5 Copyright 1995-2010 Mark Adler "; " inflate 1.3.2 Copyright 1995-2026 Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
@ -36,8 +51,9 @@ const char inflate_copyright[] =
table index bits. It will differ if the request is greater than the table index bits. It will differ if the request is greater than the
longest code or if it is less than the shortest code. longest code or if it is less than the shortest code.
*/ */
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR * FAR *table, unsigned FAR *bits, unsigned short FAR *work) int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
{ unsigned codes, code FAR * FAR *table,
unsigned FAR *bits, unsigned short FAR *work) {
unsigned len; /* a code's length in bits */ unsigned len; /* a code's length in bits */
unsigned sym; /* index of code symbols */ unsigned sym; /* index of code symbols */
unsigned min, max; /* minimum and maximum code lengths */ unsigned min, max; /* minimum and maximum code lengths */
@ -53,9 +69,9 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigne
unsigned mask; /* mask for low root bits */ unsigned mask; /* mask for low root bits */
code here; /* table entry for duplication */ code here; /* table entry for duplication */
code FAR *next; /* next available space in table */ code FAR *next; /* next available space in table */
const unsigned short FAR *base; /* base value table to use */ const unsigned short FAR *base = NULL; /* base value table to use */
const unsigned short FAR *extra; /* extra bits table to use */ const unsigned short FAR *extra = NULL; /* extra bits table to use */
int end; /* use base and extra for symbol > end */ unsigned match = 0; /* use base and extra for symbol >= match */
unsigned short count[MAXBITS+1]; /* number of codes of each length */ unsigned short count[MAXBITS+1]; /* number of codes of each length */
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
static const unsigned short lbase[31] = { /* Length codes 257..285 base */ static const unsigned short lbase[31] = { /* Length codes 257..285 base */
@ -63,7 +79,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigne
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */ static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 73, 195}; 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 75};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
@ -181,20 +197,16 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigne
/* set up for code type */ /* set up for code type */
switch (type) { switch (type) {
case CODES: case CODES:
base = extra = work; /* dummy value--not used */ match = 20;
end = 19;
break; break;
case LENS: case LENS:
base = lbase; base = lbase;
base -= 257;
extra = lext; extra = lext;
extra -= 257; match = 257;
end = 256;
break; break;
default: /* DISTS */ case DISTS:
base = dbase; base = dbase;
extra = dext; extra = dext;
end = -1;
} }
/* initialize state for loop */ /* initialize state for loop */
@ -209,21 +221,21 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigne
mask = used - 1; /* mask for comparing low */ mask = used - 1; /* mask for comparing low */
/* check available table space */ /* check available table space */
if ((type == LENS && used >= ENOUGH_LENS) || if ((type == LENS && used > ENOUGH_LENS) ||
(type == DISTS && used >= ENOUGH_DISTS)) (type == DISTS && used > ENOUGH_DISTS))
return 1; return 1;
/* process all codes and make table entries */ /* process all codes and make table entries */
for (;;) { for (;;) {
/* create table entry */ /* create table entry */
here.bits = (unsigned char)(len - drop); here.bits = (unsigned char)(len - drop);
if ((int)(work[sym]) < end) { if (work[sym] + 1U < match) {
here.op = (unsigned char)0; here.op = (unsigned char)0;
here.val = work[sym]; here.val = work[sym];
} }
else if ((int)(work[sym]) > end) { else if (work[sym] >= match) {
here.op = (unsigned char)(extra[work[sym]]); here.op = (unsigned char)(extra[work[sym] - match]);
here.val = base[work[sym]]; here.val = base[work[sym] - match];
} }
else { else {
here.op = (unsigned char)(32 + 64); /* end of block */ here.op = (unsigned char)(32 + 64); /* end of block */
@ -278,8 +290,8 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigne
/* check for enough space */ /* check for enough space */
used += 1U << curr; used += 1U << curr;
if ((type == LENS && used >= ENOUGH_LENS) || if ((type == LENS && used > ENOUGH_LENS) ||
(type == DISTS && used >= ENOUGH_DISTS)) (type == DISTS && used > ENOUGH_DISTS))
return 1; return 1;
/* point entry in root table to sub-table */ /* point entry in root table to sub-table */
@ -290,38 +302,14 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigne
} }
} }
/* /* fill in remaining table entry if code is incomplete (guaranteed to have
Fill in rest of table for incomplete codes. This loop is similar to the at most one remaining entry, since if the code is incomplete, the
loop above in incrementing huff for table indices. It is assumed that maximum code length that was allowed to get this far is one bit) */
len is equal to curr + drop, so there is no loop needed to increment if (huff != 0) {
through high index bits. When the current sub-table is filled, the loop here.op = (unsigned char)64; /* invalid code marker */
drops back to the root table to fill in any remaining entries there. here.bits = (unsigned char)(len - drop);
*/ here.val = (unsigned short)0;
here.op = (unsigned char)64; /* invalid code marker */ next[huff] = here;
here.bits = (unsigned char)(len - drop);
here.val = (unsigned short)0;
while (huff != 0) {
/* when done with sub-table, drop back to root table */
if (drop != 0 && (huff & mask) != low) {
drop = 0;
len = root;
next = *table;
here.bits = (unsigned char)len;
}
/* put invalid code marker in table */
next[huff >> drop] = here;
/* backwards increment the len-bit code huff */
incr = 1U << (len - 1);
while (huff & incr)
incr >>= 1;
if (incr != 0) {
huff &= incr - 1;
huff += incr;
}
else
huff = 0;
} }
/* set return parameters */ /* set return parameters */
@ -330,8 +318,117 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigne
return 0; return 0;
} }
#ifdef BUILDFIXED
/*
If this is compiled with BUILDFIXED defined, and if inflate will be used in
multiple threads, and if atomics are not available, then inflate() must be
called with a fixed block (e.g. 0x03 0x00) to initialize the tables and must
return before any other threads are allowed to call inflate.
*/
static code *lenfix, *distfix;
static code fixed[544];
/* State for z_once(). */
local z_once_t built = Z_ONCE_INIT;
local void buildtables(void) {
unsigned sym, bits;
static code *next;
unsigned short lens[288], work[288];
/* literal/length table */
sym = 0;
while (sym < 144) lens[sym++] = 8;
while (sym < 256) lens[sym++] = 9;
while (sym < 280) lens[sym++] = 7;
while (sym < 288) lens[sym++] = 8;
next = fixed;
lenfix = next;
bits = 9;
inflate_table(LENS, lens, 288, &(next), &(bits), work);
/* distance table */
sym = 0;
while (sym < 32) lens[sym++] = 5;
distfix = next;
bits = 5;
inflate_table(DISTS, lens, 32, &(next), &(bits), work);
}
#else /* !BUILDFIXED */
# include "inffixed.h"
#endif /* BUILDFIXED */
/*
Return state with length and distance decoding tables and index sizes set to
fixed code decoding. Normally this returns fixed tables from inffixed.h.
If BUILDFIXED is defined, then instead this routine builds the tables the
first time it's called, and returns those tables the first time and
thereafter. This reduces the size of the code by about 2K bytes, in
exchange for a little execution time. However, BUILDFIXED should not be
used for threaded applications if atomics are not available, as it will
not be thread-safe.
*/
void inflate_fixed(struct inflate_state FAR *state) {
#ifdef BUILDFIXED
z_once(&built, buildtables);
#endif /* BUILDFIXED */
state->lencode = lenfix;
state->lenbits = 9;
state->distcode = distfix;
state->distbits = 5;
}
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_END
#ifdef MAKEFIXED
#include <stdio.h>
/*
Write out the inffixed.h that will be #include'd above. Defining MAKEFIXED
also defines BUILDFIXED, so the tables are built on the fly. main() writes
those tables to stdout, which would directed to inffixed.h. Compile this
along with zutil.c:
cc -DMAKEFIXED -o fix inftrees.c zutil.c
./fix > inffixed.h
*/
int main(void) {
unsigned low, size;
struct inflate_state state;
inflate_fixed(&state);
puts("/* inffixed.h -- table for decoding fixed codes");
puts(" * Generated automatically by makefixed().");
puts(" */");
puts("");
puts("/* WARNING: this file should *not* be used by applications.");
puts(" It is part of the implementation of this library and is");
puts(" subject to change. Applications should only use zlib.h.");
puts(" */");
puts("");
size = 1U << 9;
printf("static const code lenfix[%u] = {", size);
low = 0;
for (;;) {
if ((low % 7) == 0) printf("\n ");
printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
state.lencode[low].bits, state.lencode[low].val);
if (++low == size) break;
putchar(',');
}
puts("\n};");
size = 1U << 5;
printf("\nstatic const code distfix[%u] = {", size);
low = 0;
for (;;) {
if ((low % 6) == 0) printf("\n ");
printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
state.distcode[low].val);
if (++low == size) break;
putchar(',');
}
puts("\n};");
return 0;
}
#endif /* MAKEFIXED */

View File

@ -1,15 +1,16 @@
/* inftrees.h -- header to use inftrees.c /* inftrees.h -- header to use inftrees.c
* Copyright (C) 1995-2005, 2010 Mark Adler * Copyright (C) 1995-2026 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
ABC_NAMESPACE_HEADER_START
/* WARNING: this file should *not* be used by applications. It is /* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
ABC_NAMESPACE_HEADER_START
/* Structure for decoding tables. Each entry provides either the /* Structure for decoding tables. Each entry provides either the
information needed to do the operation requested by the code that information needed to do the operation requested by the code that
indexed that table entry, or it provides a pointer to another indexed that table entry, or it provides a pointer to another
@ -40,11 +41,11 @@ typedef struct {
/* Maximum size of the dynamic table. The maximum number of code structures is /* Maximum size of the dynamic table. The maximum number of code structures is
1444, which is the sum of 852 for literal/length codes and 592 for distance 1444, which is the sum of 852 for literal/length codes and 592 for distance
codes. These values were found by exhaustive searches using the program codes. These values were found by exhaustive searches using the program
examples/enough.c found in the zlib distribtution. The arguments to that examples/enough.c found in the zlib distribution. The arguments to that
program are the number of symbols, the initial root table size, and the program are the number of symbols, the initial root table size, and the
maximum bit length of a code. "enough 286 9 15" for literal/length codes maximum bit length of a code. "enough 286 9 15" for literal/length codes
returns returns 852, and "enough 30 6 15" for distance codes returns 592. returns 852, and "enough 30 6 15" for distance codes returns 592. The
The initial root table size (9 or 6) is found in the fifth argument of the initial root table size (9 or 6) is found in the fifth argument of the
inflate_table() calls in inflate.c and infback.c. If the root table size is inflate_table() calls in inflate.c and infback.c. If the root table size is
changed, then these maximum sizes would be need to be recalculated and changed, then these maximum sizes would be need to be recalculated and
updated. */ updated. */
@ -59,8 +60,10 @@ typedef enum {
DISTS DISTS
} codetype; } codetype;
int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
unsigned codes, code FAR * FAR *table, unsigned codes, code FAR * FAR *table,
unsigned FAR *bits, unsigned short FAR *work)); unsigned FAR *bits, unsigned short FAR *work);
struct inflate_state;
void ZLIB_INTERNAL inflate_fixed(struct inflate_state FAR *state);
ABC_NAMESPACE_HEADER_END ABC_NAMESPACE_HEADER_END

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,5 @@
/* header created automatically with -DGEN_TREES_H */ /* header created automatically with -DGEN_TREES_H */
ABC_NAMESPACE_HEADER_START
local const ct_data static_ltree[L_CODES+2] = { local const ct_data static_ltree[L_CODES+2] = {
{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
@ -128,5 +126,3 @@ local const int base_dist[D_CODES] = {
1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
}; };
ABC_NAMESPACE_HEADER_END

View File

@ -1,67 +1,112 @@
/* uncompr.c -- decompress a memory buffer /* uncompr.c -- decompress a memory buffer
* Copyright (C) 1995-2003, 2010 Jean-loup Gailly. * Copyright (C) 1995-2026 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id$ */ /* @(#) $Id$ */
#define ZLIB_INTERNAL
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "misc/util/abc_global.h" #include "misc/util/abc_global.h"
#define ZLIB_INTERNAL
#include "zlib.h" #include "zlib.h"
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
/* ===========================================================================
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be large enough to hold the
entire uncompressed data. (The size of the uncompressed data must have
been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not /* ===========================================================================
enough memory, Z_BUF_ERROR if there was not enough room in the output Decompresses the source buffer into the destination buffer. *sourceLen is
buffer, or Z_DATA_ERROR if the input data was corrupted. the byte length of the source buffer. Upon entry, *destLen is the total size
of the destination buffer, which must be large enough to hold the entire
uncompressed data. (The size of the uncompressed data must have been saved
previously by the compressor and transmitted to the decompressor by some
mechanism outside the scope of this compression library.) Upon exit,
*destLen is the size of the decompressed data and *sourceLen is the number
of source bytes consumed. Upon return, source + *sourceLen points to the
first unused input byte.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
Z_DATA_ERROR if the input data was corrupted, including if the input data is
an incomplete zlib stream.
The _z versions of the functions take size_t length arguments.
*/ */
int ZEXPORT uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen) int ZEXPORT uncompress2_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
{ z_size_t *sourceLen) {
z_stream stream; z_stream stream;
int err; int err;
const uInt max = (uInt)-1;
z_size_t len, left;
stream.next_in = (Bytef*)source; if (sourceLen == NULL || (*sourceLen > 0 && source == NULL) ||
stream.avail_in = (uInt)sourceLen; destLen == NULL || (*destLen > 0 && dest == NULL))
/* Check for source > 64K on 16-bit machine: */ return Z_STREAM_ERROR;
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
stream.next_out = dest; len = *sourceLen;
stream.avail_out = (uInt)*destLen; left = *destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; if (left == 0 && dest == Z_NULL)
dest = (Bytef *)&stream.reserved; /* next_out cannot be NULL */
stream.next_in = (z_const Bytef *)source;
stream.avail_in = 0;
stream.zalloc = (alloc_func)0; stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0; stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
err = inflateInit(&stream); err = inflateInit(&stream);
if (err != Z_OK) return err; if (err != Z_OK) return err;
err = inflate(&stream, Z_FINISH); stream.next_out = dest;
if (err != Z_STREAM_END) { stream.avail_out = 0;
inflateEnd(&stream);
if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
return Z_DATA_ERROR;
return err;
}
*destLen = stream.total_out;
err = inflateEnd(&stream); do {
return err; if (stream.avail_out == 0) {
stream.avail_out = left > (z_size_t)max ? max : (uInt)left;
left -= stream.avail_out;
}
if (stream.avail_in == 0) {
stream.avail_in = len > (z_size_t)max ? max : (uInt)len;
len -= stream.avail_in;
}
err = inflate(&stream, Z_NO_FLUSH);
} while (err == Z_OK);
/* Set len and left to the unused input data and unused output space. Set
*sourceLen to the amount of input consumed. Set *destLen to the amount
of data produced. */
len += stream.avail_in;
left += stream.avail_out;
*sourceLen -= len;
*destLen -= left;
inflateEnd(&stream);
return err == Z_STREAM_END ? Z_OK :
err == Z_NEED_DICT ? Z_DATA_ERROR :
err == Z_BUF_ERROR && len == 0 ? Z_DATA_ERROR :
err;
}
int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
uLong *sourceLen) {
int ret;
z_size_t got = *destLen, used = *sourceLen;
ret = uncompress2_z(dest, &got, source, &used);
*sourceLen = (uLong)used;
*destLen = (uLong)got;
return ret;
}
int ZEXPORT uncompress_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
z_size_t sourceLen) {
z_size_t used = sourceLen;
return uncompress2_z(dest, destLen, source, &used);
}
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
uLong sourceLen) {
uLong used = sourceLen;
return uncompress2(dest, destLen, source, &used);
} }
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,5 @@
/* zconf.h -- configuration of the zlib compression library /* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2010 Jean-loup Gailly. * Copyright (C) 1995-2026 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -15,11 +15,13 @@
* this permanently in zconf.h using "./configure --zprefix". * this permanently in zconf.h using "./configure --zprefix".
*/ */
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
# define Z_PREFIX_SET
/* all linked symbols */ /* all linked symbols and init macros */
# define _dist_code z__dist_code # define _dist_code z__dist_code
# define _length_code z__length_code # define _length_code z__length_code
# define _tr_align z__tr_align # define _tr_align z__tr_align
# define _tr_flush_bits z__tr_flush_bits
# define _tr_flush_block z__tr_flush_block # define _tr_flush_block z__tr_flush_block
# define _tr_init z__tr_init # define _tr_init z__tr_init
# define _tr_stored_block z__tr_stored_block # define _tr_stored_block z__tr_stored_block
@ -27,81 +29,122 @@
# define adler32 z_adler32 # define adler32 z_adler32
# define adler32_combine z_adler32_combine # define adler32_combine z_adler32_combine
# define adler32_combine64 z_adler32_combine64 # define adler32_combine64 z_adler32_combine64
# define compress z_compress # define adler32_z z_adler32_z
# define compress2 z_compress2 # ifndef Z_SOLO
# define compressBound z_compressBound # define compress z_compress
# define compress2 z_compress2
# define compress_z z_compress_z
# define compress2_z z_compress2_z
# define compressBound z_compressBound
# define compressBound_z z_compressBound_z
# endif
# define crc32 z_crc32 # define crc32 z_crc32
# define crc32_combine z_crc32_combine # define crc32_combine z_crc32_combine
# define crc32_combine64 z_crc32_combine64 # define crc32_combine64 z_crc32_combine64
# define crc32_combine_gen z_crc32_combine_gen
# define crc32_combine_gen64 z_crc32_combine_gen64
# define crc32_combine_op z_crc32_combine_op
# define crc32_z z_crc32_z
# define deflate z_deflate # define deflate z_deflate
# define deflateBound z_deflateBound # define deflateBound z_deflateBound
# define deflateBound_z z_deflateBound_z
# define deflateCopy z_deflateCopy # define deflateCopy z_deflateCopy
# define deflateEnd z_deflateEnd # define deflateEnd z_deflateEnd
# define deflateGetDictionary z_deflateGetDictionary
# define deflateInit z_deflateInit
# define deflateInit2 z_deflateInit2
# define deflateInit2_ z_deflateInit2_ # define deflateInit2_ z_deflateInit2_
# define deflateInit_ z_deflateInit_ # define deflateInit_ z_deflateInit_
# define deflateParams z_deflateParams # define deflateParams z_deflateParams
# define deflatePending z_deflatePending
# define deflatePrime z_deflatePrime # define deflatePrime z_deflatePrime
# define deflateReset z_deflateReset # define deflateReset z_deflateReset
# define deflateResetKeep z_deflateResetKeep
# define deflateSetDictionary z_deflateSetDictionary # define deflateSetDictionary z_deflateSetDictionary
# define deflateSetHeader z_deflateSetHeader # define deflateSetHeader z_deflateSetHeader
# define deflateTune z_deflateTune # define deflateTune z_deflateTune
# define deflateUsed z_deflateUsed
# define deflate_copyright z_deflate_copyright # define deflate_copyright z_deflate_copyright
# define get_crc_table z_get_crc_table # define get_crc_table z_get_crc_table
# define gz_error z_gz_error # ifndef Z_SOLO
# define gz_intmax z_gz_intmax # define gz_error z_gz_error
# define gz_strwinerror z_gz_strwinerror # define gz_intmax z_gz_intmax
# define gzbuffer z_gzbuffer # define gz_strwinerror z_gz_strwinerror
# define gzclearerr z_gzclearerr # define gzbuffer z_gzbuffer
# define gzclose z_gzclose # define gzclearerr z_gzclearerr
# define gzclose_r z_gzclose_r # define gzclose z_gzclose
# define gzclose_w z_gzclose_w # define gzclose_r z_gzclose_r
# define gzdirect z_gzdirect # define gzclose_w z_gzclose_w
# define gzdopen z_gzdopen # define gzdirect z_gzdirect
# define gzeof z_gzeof # define gzdopen z_gzdopen
# define gzerror z_gzerror # define gzeof z_gzeof
# define gzflush z_gzflush # define gzerror z_gzerror
# define gzgetc z_gzgetc # define gzflush z_gzflush
# define gzgets z_gzgets # define gzfread z_gzfread
# define gzoffset z_gzoffset # define gzfwrite z_gzfwrite
# define gzoffset64 z_gzoffset64 # define gzgetc z_gzgetc
# define gzopen z_gzopen # define gzgetc_ z_gzgetc_
# define gzopen64 z_gzopen64 # define gzgets z_gzgets
# define gzprintf z_gzprintf # define gzoffset z_gzoffset
# define gzputc z_gzputc # define gzoffset64 z_gzoffset64
# define gzputs z_gzputs # define gzopen z_gzopen
# define gzread z_gzread # define gzopen64 z_gzopen64
# define gzrewind z_gzrewind # ifdef _WIN32
# define gzseek z_gzseek # define gzopen_w z_gzopen_w
# define gzseek64 z_gzseek64 # endif
# define gzsetparams z_gzsetparams # define gzprintf z_gzprintf
# define gztell z_gztell # define gzputc z_gzputc
# define gztell64 z_gztell64 # define gzputs z_gzputs
# define gzungetc z_gzungetc # define gzread z_gzread
# define gzwrite z_gzwrite # define gzrewind z_gzrewind
# define gzseek z_gzseek
# define gzseek64 z_gzseek64
# define gzsetparams z_gzsetparams
# define gztell z_gztell
# define gztell64 z_gztell64
# define gzungetc z_gzungetc
# define gzvprintf z_gzvprintf
# define gzwrite z_gzwrite
# endif
# define inflate z_inflate # define inflate z_inflate
# define inflateBack z_inflateBack # define inflateBack z_inflateBack
# define inflateBackEnd z_inflateBackEnd # define inflateBackEnd z_inflateBackEnd
# define inflateBackInit z_inflateBackInit
# define inflateBackInit_ z_inflateBackInit_ # define inflateBackInit_ z_inflateBackInit_
# define inflateCodesUsed z_inflateCodesUsed
# define inflateCopy z_inflateCopy # define inflateCopy z_inflateCopy
# define inflateEnd z_inflateEnd # define inflateEnd z_inflateEnd
# define inflateGetDictionary z_inflateGetDictionary
# define inflateGetHeader z_inflateGetHeader # define inflateGetHeader z_inflateGetHeader
# define inflateInit z_inflateInit
# define inflateInit2 z_inflateInit2
# define inflateInit2_ z_inflateInit2_ # define inflateInit2_ z_inflateInit2_
# define inflateInit_ z_inflateInit_ # define inflateInit_ z_inflateInit_
# define inflateMark z_inflateMark # define inflateMark z_inflateMark
# define inflatePrime z_inflatePrime # define inflatePrime z_inflatePrime
# define inflateReset z_inflateReset # define inflateReset z_inflateReset
# define inflateReset2 z_inflateReset2 # define inflateReset2 z_inflateReset2
# define inflateResetKeep z_inflateResetKeep
# define inflateSetDictionary z_inflateSetDictionary # define inflateSetDictionary z_inflateSetDictionary
# define inflateSync z_inflateSync # define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint # define inflateSyncPoint z_inflateSyncPoint
# define inflateUndermine z_inflateUndermine # define inflateUndermine z_inflateUndermine
# define inflateValidate z_inflateValidate
# define inflate_copyright z_inflate_copyright # define inflate_copyright z_inflate_copyright
# define inflate_fast z_inflate_fast # define inflate_fast z_inflate_fast
# define inflate_table z_inflate_table # define inflate_table z_inflate_table
# define uncompress z_uncompress # define inflate_fixed z_inflate_fixed
# ifndef Z_SOLO
# define uncompress z_uncompress
# define uncompress2 z_uncompress2
# define uncompress_z z_uncompress_z
# define uncompress2_z z_uncompress2_z
# endif
# define zError z_zError # define zError z_zError
# define zcalloc z_zcalloc # ifndef Z_SOLO
# define zcfree z_zcfree # define zcalloc z_zcalloc
# define zcfree z_zcfree
# endif
# define zlibCompileFlags z_zlibCompileFlags # define zlibCompileFlags z_zlibCompileFlags
# define zlibVersion z_zlibVersion # define zlibVersion z_zlibVersion
@ -111,7 +154,9 @@
# define alloc_func z_alloc_func # define alloc_func z_alloc_func
# define charf z_charf # define charf z_charf
# define free_func z_free_func # define free_func z_free_func
# define gzFile z_gzFile # ifndef Z_SOLO
# define gzFile z_gzFile
# endif
# define gz_header z_gz_header # define gz_header z_gz_header
# define gz_headerp z_gz_headerp # define gz_headerp z_gz_headerp
# define in_func z_in_func # define in_func z_in_func
@ -197,9 +242,31 @@
# endif # endif
#endif #endif
/* Some Mac compilers merge all .h files incorrectly: */ #ifndef z_const
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) # ifdef ZLIB_CONST
# define NO_DUMMY_DECL # define z_const const
# else
# define z_const
# endif
#endif
#ifdef Z_SOLO
# ifdef _WIN64
typedef unsigned long long z_size_t;
# else
typedef unsigned long z_size_t;
# endif
#else
# define z_longlong long long
# if defined(NO_SIZE_T)
typedef unsigned NO_SIZE_T z_size_t;
# elif defined(STDC)
# include <stddef.h>
typedef size_t z_size_t;
# else
typedef unsigned long z_size_t;
# endif
# undef z_longlong
#endif #endif
/* Maximum value for memLevel in deflateInit2 */ /* Maximum value for memLevel in deflateInit2 */
@ -229,7 +296,7 @@
Of course this will generally degrade compression (there's no free lunch). Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
for small objects. for small objects.
*/ */
@ -291,6 +358,9 @@
# ifdef FAR # ifdef FAR
# undef FAR # undef FAR
# endif # endif
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h> # include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */ /* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
@ -356,12 +426,47 @@ typedef uLong FAR uLongf;
typedef Byte *voidp; typedef Byte *voidp;
#endif #endif
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ #if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
# include <limits.h>
# if (UINT_MAX == 0xffffffffUL)
# define Z_U4 unsigned
# elif (ULONG_MAX == 0xffffffffUL)
# define Z_U4 unsigned long
# elif (USHRT_MAX == 0xffffffffUL)
# define Z_U4 unsigned short
# endif
#endif
#ifdef Z_U4
typedef Z_U4 z_crc_t;
#else
typedef unsigned long z_crc_t;
#endif
#if HAVE_UNISTD_H-0 /* may be set to #if 1 by ./configure */
# define Z_HAVE_UNISTD_H # define Z_HAVE_UNISTD_H
#endif #endif
#if HAVE_STDARG_H-0 /* may be set to #if 1 by ./configure */
# define Z_HAVE_STDARG_H
#endif
#ifdef STDC #ifdef STDC
# include <sys/types.h> /* for off_t */ # ifndef Z_SOLO
# include <sys/types.h> /* for off_t */
# endif
#endif
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
# ifndef Z_SOLO
# include <stdarg.h> /* for va_list */
# endif
#endif
#ifdef _WIN32
# ifndef Z_SOLO
# include <stddef.h> /* for wchar_t */
# endif
#endif #endif
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
@ -370,46 +475,62 @@ typedef uLong FAR uLongf;
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
* equivalently requesting no 64-bit operations * equivalently requesting no 64-bit operations
*/ */
#if -_LARGEFILE64_SOURCE - -1 == 1 #if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
# undef _LARGEFILE64_SOURCE # undef _LARGEFILE64_SOURCE
#endif #endif
#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) #ifndef Z_HAVE_UNISTD_H
# include <unistd.h> /* for SEEK_* and off_t */ # if defined(__WATCOMC__) || defined(__GO32__) || \
# ifdef VMS (defined(_LARGEFILE64_SOURCE) && !defined(_WIN32))
# include <unixio.h> /* for off_t */ # define Z_HAVE_UNISTD_H
# endif # endif
# ifndef z_off_t #endif
# define z_off_t off_t #ifndef Z_SOLO
# if defined(Z_HAVE_UNISTD_H)
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
# ifdef VMS
# include <unixio.h> /* for off_t */
# endif
# ifndef z_off_t
# define z_off_t off_t
# endif
# endif # endif
#endif #endif
ABC_NAMESPACE_HEADER_START #if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
# define Z_LFS64
#endif
#ifndef SEEK_SET #if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
# define Z_LARGE64
#endif
#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
# define Z_WANT64
#endif
#if !defined(SEEK_SET) && !defined(Z_SOLO)
# define SEEK_SET 0 /* Seek from beginning of file. */ # define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */ # define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif #endif
#ifndef z_off_t #ifndef z_off_t
# define z_off_t long # define z_off_t long long
#endif #endif
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 #if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t # define z_off64_t off64_t
#elif defined(__MINGW32__)
# define z_off64_t long long
#elif defined(_WIN32) && !defined(__GNUC__)
# define z_off64_t __int64
#elif defined(__GO32__)
# define z_off64_t offset_t
#else #else
# define z_off64_t z_off_t # define z_off64_t z_off_t
#endif #endif
#if defined(__OS400__)
# define NO_vsnprintf
#endif
#if defined(__MVS__)
# define NO_vsnprintf
#endif
/* MVS linker does not support external names larger than 8 bytes */ /* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__) #if defined(__MVS__)
#pragma map(deflateInit_,"DEIN") #pragma map(deflateInit_,"DEIN")
@ -427,6 +548,4 @@ ABC_NAMESPACE_HEADER_START
#pragma map(inflate_copyright,"INCOPY") #pragma map(inflate_copyright,"INCOPY")
#endif #endif
ABC_NAMESPACE_HEADER_END
#endif /* ZCONF_H */ #endif /* ZCONF_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/* zutil.c -- target dependent utility functions for the compression library /* zutil.c -- target dependent utility functions for the compression library
* Copyright (C) 1995-2005, 2010 Jean-loup Gailly. * Copyright (C) 1995-2026 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -12,34 +12,31 @@
#include "zutil.h" #include "zutil.h"
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
#ifndef Z_SOLO
#ifndef NO_DUMMY_DECL # include "gzguts.h"
struct internal_state {int dummy;}; /* for buggy compilers */
#endif #endif
const char * const z_errmsg[10] = { z_const char * const z_errmsg[10] = {
"need dictionary", /* Z_NEED_DICT 2 */ (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */
"stream end", /* Z_STREAM_END 1 */ (z_const char *)"stream end", /* Z_STREAM_END 1 */
"", /* Z_OK 0 */ (z_const char *)"", /* Z_OK 0 */
"file error", /* Z_ERRNO (-1) */ (z_const char *)"file error", /* Z_ERRNO (-1) */
"stream error", /* Z_STREAM_ERROR (-2) */ (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */
"data error", /* Z_DATA_ERROR (-3) */ (z_const char *)"data error", /* Z_DATA_ERROR (-3) */
"insufficient memory", /* Z_MEM_ERROR (-4) */ (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */
"buffer error", /* Z_BUF_ERROR (-5) */ (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */
"incompatible version",/* Z_VERSION_ERROR (-6) */ (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
""}; (z_const char *)""
};
const char * ZEXPORT zlibVersion() const char * ZEXPORT zlibVersion(void) {
{
return ZLIB_VERSION; return ZLIB_VERSION;
} }
uLong ZEXPORT zlibCompileFlags() uLong ZEXPORT zlibCompileFlags(void) {
{
uLong flags; uLong flags;
flags = 0; flags = 0;
@ -67,12 +64,14 @@ uLong ZEXPORT zlibCompileFlags()
case 8: flags += 2 << 6; break; case 8: flags += 2 << 6; break;
default: flags += 3 << 6; default: flags += 3 << 6;
} }
#ifdef DEBUG #ifdef ZLIB_DEBUG
flags += 1 << 8; flags += 1 << 8;
#endif #endif
/*
#if defined(ASMV) || defined(ASMINF) #if defined(ASMV) || defined(ASMINF)
flags += 1 << 9; flags += 1 << 9;
#endif #endif
*/
#ifdef ZLIB_WINAPI #ifdef ZLIB_WINAPI
flags += 1 << 10; flags += 1 << 10;
#endif #endif
@ -94,43 +93,49 @@ uLong ZEXPORT zlibCompileFlags()
#ifdef FASTEST #ifdef FASTEST
flags += 1L << 21; flags += 1L << 21;
#endif #endif
#ifdef STDC #if defined(STDC) || defined(Z_HAVE_STDARG_H)
# ifdef NO_vsnprintf # ifdef NO_vsnprintf
flags += 1L << 25; # ifdef ZLIB_INSECURE
# ifdef HAS_vsprintf_void flags += 1L << 25;
flags += 1L << 26; # else
# endif flags += 1L << 27;
# else # endif
# ifdef HAS_vsnprintf_void # ifdef HAS_vsprintf_void
flags += 1L << 26; flags += 1L << 26;
# endif # endif
# endif # else
# ifdef HAS_vsnprintf_void
flags += 1L << 26;
# endif
# endif
#else #else
flags += 1L << 24; flags += 1L << 24;
# ifdef NO_snprintf # ifdef NO_snprintf
flags += 1L << 25; # ifdef ZLIB_INSECURE
# ifdef HAS_sprintf_void flags += 1L << 25;
flags += 1L << 26; # else
# endif flags += 1L << 27;
# else # endif
# ifdef HAS_snprintf_void # ifdef HAS_sprintf_void
flags += 1L << 26; flags += 1L << 26;
# endif # endif
# endif # else
# ifdef HAS_snprintf_void
flags += 1L << 26;
# endif
# endif
#endif #endif
return flags; return flags;
} }
#ifdef DEBUG #ifdef ZLIB_DEBUG
#include <stdlib.h>
# ifndef verbose # ifndef verbose
# define verbose 0 # define verbose 0
# endif # endif
int ZLIB_INTERNAL z_verbose = verbose; int ZLIB_INTERNAL z_verbose = verbose;
void ZLIB_INTERNAL z_error (m) void ZLIB_INTERNAL z_error(char *m) {
char *m;
{
fprintf(stderr, "%s\n", m); fprintf(stderr, "%s\n", m);
exit(1); exit(1);
} }
@ -139,13 +144,12 @@ void ZLIB_INTERNAL z_error (m)
/* exported to allow conversion of error code to string for compress() and /* exported to allow conversion of error code to string for compress() and
* uncompress() * uncompress()
*/ */
const char * ZEXPORT zError(int err) const char * ZEXPORT zError(int err) {
{
return ERR_MSG(err); return ERR_MSG(err);
} }
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE) && _WIN32_WCE < 0x800
/* The Microsoft C Run-Time Library for Windows CE doesn't have /* The older Microsoft C Run-Time Library for Windows CE doesn't have
* errno. We define it as a global variable to simplify porting. * errno. We define it as a global variable to simplify porting.
* Its value is always 0 and should not be used. * Its value is always 0 and should not be used.
*/ */
@ -154,33 +158,37 @@ const char * ZEXPORT zError(int err)
#ifndef HAVE_MEMCPY #ifndef HAVE_MEMCPY
void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) void ZLIB_INTERNAL zmemcpy(void FAR *dst, const void FAR *src, z_size_t n) {
{ uchf *p = dst;
if (len == 0) return; const uchf *q = src;
do { while (n) {
*dest++ = *source++; /* ??? to be unrolled */ *p++ = *q++;
} while (--len != 0); n--;
}
} }
int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) int ZLIB_INTERNAL zmemcmp(const void FAR *s1, const void FAR *s2, z_size_t n) {
{ const uchf *p = s1, *q = s2;
uInt j; while (n) {
if (*p++ != *q++)
for (j = 0; j < len; j++) { return (int)p[-1] - (int)q[-1];
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; n--;
} }
return 0; return 0;
} }
void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) void ZLIB_INTERNAL zmemzero(void FAR *b, z_size_t len) {
{ uchf *p = b;
if (len == 0) return; if (len == 0) return;
do { while (len) {
*dest++ = 0; /* ??? to be unrolled */ *p++ = 0;
} while (--len != 0); len--;
}
} }
#endif #endif
#ifndef Z_SOLO
#ifdef SYS16BIT #ifdef SYS16BIT
@ -213,11 +221,12 @@ local ptr_table table[MAX_PTR];
* a protected system like OS/2. Use Microsoft C instead. * a protected system like OS/2. Use Microsoft C instead.
*/ */
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
{ voidpf buf;
voidpf buf = opaque; /* just to make some compilers happy */
ulg bsize = (ulg)items*size; ulg bsize = (ulg)items*size;
(void)opaque;
/* If we allocate less than 65520 bytes, we assume that farmalloc /* If we allocate less than 65520 bytes, we assume that farmalloc
* will return a usable pointer which doesn't have to be normalized. * will return a usable pointer which doesn't have to be normalized.
*/ */
@ -237,9 +246,11 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
return buf; return buf;
} }
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
{
int n; int n;
(void)opaque;
if (*(ush*)&ptr != 0) { /* object < 64K */ if (*(ush*)&ptr != 0) { /* object < 64K */
farfree(ptr); farfree(ptr);
return; return;
@ -255,7 +266,6 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
next_ptr--; next_ptr--;
return; return;
} }
ptr = opaque; /* just to make some compilers happy */
Assert(0, "zcfree: ptr not found"); Assert(0, "zcfree: ptr not found");
} }
@ -272,15 +282,13 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
# define _hfree hfree # define _hfree hfree
#endif #endif
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) {
{ (void)opaque;
if (opaque) opaque = 0; /* to make compiler happy */
return _halloc((long)items, size); return _halloc((long)items, size);
} }
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
{ (void)opaque;
if (opaque) opaque = 0; /* to make compiler happy */
_hfree(ptr); _hfree(ptr);
} }
@ -292,27 +300,25 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
#ifndef MY_ZCALLOC /* Any system without a special alloc function */ #ifndef MY_ZCALLOC /* Any system without a special alloc function */
#ifndef STDC #ifndef STDC
extern voidp malloc OF((uInt size)); extern voidp malloc(uInt size);
extern voidp calloc OF((uInt items, uInt size)); extern voidp calloc(uInt items, uInt size);
extern void free OF((voidpf ptr)); extern void free(voidpf ptr);
#endif #endif
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
{ (void)opaque;
if (opaque) items += size - size; /* make compiler happy */
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
(voidpf)calloc(items, size); (voidpf)calloc(items, size);
} }
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
{ (void)opaque;
free(ptr); free(ptr);
if (opaque) return; /* make compiler happy */
} }
#endif /* MY_ZCALLOC */ #endif /* MY_ZCALLOC */
#endif /* !Z_SOLO */
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_END

View File

@ -1,5 +1,5 @@
/* zutil.h -- internal interface and configuration of the compression library /* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-2010 Jean-loup Gailly. * Copyright (C) 1995-2026 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -13,7 +13,7 @@
#ifndef ZUTIL_H #ifndef ZUTIL_H
#define ZUTIL_H #define ZUTIL_H
#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) #ifdef HAVE_HIDDEN
# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
#else #else
# define ZLIB_INTERNAL # define ZLIB_INTERNAL
@ -21,7 +21,7 @@
#include "zlib.h" #include "zlib.h"
#ifdef STDC #if defined(STDC) && !defined(Z_SOLO)
# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) # if !(defined(_WIN32_WCE) && defined(_MSC_VER))
# include <stddef.h> # include <stddef.h>
# endif # endif
@ -29,12 +29,18 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif
ABC_NAMESPACE_HEADER_START
#ifndef local #ifndef local
# define local static # define local static
#endif #endif
/* compile with -Dlocal if your debugger can't find static symbols */ /* since "static" is used to mean two completely different things in C, we
define "local" for the non-static meaning of "static", for readability
(compile with -Dlocal if your debugger can't find static symbols) */
ABC_NAMESPACE_HEADER_START
extern const char deflate_copyright[];
extern const char inflate_copyright[];
extern const char inflate9_copyright[];
typedef unsigned char uch; typedef unsigned char uch;
typedef uch FAR uchf; typedef uch FAR uchf;
@ -42,17 +48,32 @@ typedef unsigned short ush;
typedef ush FAR ushf; typedef ush FAR ushf;
typedef unsigned long ulg; typedef unsigned long ulg;
extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ #if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
# include <limits.h>
# if (ULONG_MAX == 0xffffffffffffffff)
# define Z_U8 unsigned long
# elif (ULLONG_MAX == 0xffffffffffffffff)
# define Z_U8 unsigned long long
# elif (ULONG_LONG_MAX == 0xffffffffffffffff)
# define Z_U8 unsigned long long
# elif (UINT_MAX == 0xffffffffffffffff)
# define Z_U8 unsigned
# endif
#endif
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* (size given to avoid silly warnings with Visual C++) */ /* (size given to avoid silly warnings with Visual C++) */
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] #define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)]
#define ERR_RETURN(strm,err) \ #define ERR_RETURN(strm,err) \
return (strm->msg = (char*)ERR_MSG(err), (err)) return (strm->msg = ERR_MSG(err), (err))
/* To be used only when the state is known to be valid */ /* To be used only when the state is known to be valid */
/* common constants */ /* common constants */
#if MAX_WBITS < 9 || MAX_WBITS > 15
# error MAX_WBITS must be in 9..15
#endif
#ifndef DEF_WBITS #ifndef DEF_WBITS
# define DEF_WBITS MAX_WBITS # define DEF_WBITS MAX_WBITS
#endif #endif
@ -80,105 +101,93 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
# define OS_CODE 0x00 # define OS_CODE 0x00
# if defined(__TURBOC__) || defined(__BORLANDC__) # ifndef Z_SOLO
# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) # if defined(__TURBOC__) || defined(__BORLANDC__)
/* Allow compilation with ANSI keywords only enabled */ # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
void _Cdecl farfree( void *block ); /* Allow compilation with ANSI keywords only enabled */
void *_Cdecl farmalloc( unsigned long nbytes ); void _Cdecl farfree( void *block );
# else void *_Cdecl farmalloc( unsigned long nbytes );
ABC_NAMESPACE_HEADER_END # else
# include <alloc.h> # include <alloc.h>
ABC_NAMESPACE_HEADER_START # endif
# else /* MSC or DJGPP */
# include <malloc.h>
# endif # endif
# else /* MSC or DJGPP */
ABC_NAMESPACE_HEADER_END
# include <malloc.h>
ABC_NAMESPACE_HEADER_START
# endif # endif
#endif #endif
#ifdef AMIGA #ifdef AMIGA
# define OS_CODE 0x01 # define OS_CODE 1
#endif #endif
#if defined(VAXC) || defined(VMS) #if defined(VAXC) || defined(VMS)
# define OS_CODE 0x02 # define OS_CODE 2
# define F_OPEN(name, mode) \ # define F_OPEN(name, mode) \
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
#endif #endif
#ifdef __370__
# if __TARGET_LIB__ < 0x20000000
# define OS_CODE 4
# elif __TARGET_LIB__ < 0x40000000
# define OS_CODE 11
# else
# define OS_CODE 8
# endif
#endif
#if defined(ATARI) || defined(atarist) #if defined(ATARI) || defined(atarist)
# define OS_CODE 0x05 # define OS_CODE 5
#endif #endif
#ifdef OS2 #ifdef OS2
# define OS_CODE 0x06 # define OS_CODE 6
# ifdef M_I86 # if defined(M_I86) && !defined(Z_SOLO)
ABC_NAMESPACE_HEADER_END
# include <malloc.h> # include <malloc.h>
ABC_NAMESPACE_HEADER_START
# endif # endif
#endif #endif
#if defined(MACOS) || defined(TARGET_OS_MAC) #if defined(MACOS)
# define OS_CODE 0x07 # define OS_CODE 7
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
ABC_NAMESPACE_HEADER_END
# include <unix.h> /* for fdopen */
ABC_NAMESPACE_HEADER_START
# else
# ifndef fdopen
# define fdopen(fd,mode) NULL /* No fdopen() */
# endif
# endif
#endif #endif
#ifdef TOPS20 #if defined(__acorn) || defined(__riscos)
# define OS_CODE 0x0a # define OS_CODE 13
#endif #endif
#ifdef WIN32 #if defined(WIN32) && !defined(__CYGWIN__)
# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ # define OS_CODE 10
# define OS_CODE 0x0b
# endif
#endif #endif
#ifdef __50SERIES /* Prime/PRIMOS */ #ifdef _BEOS_
# define OS_CODE 0x0f # define OS_CODE 16
#endif #endif
#if defined(_BEOS_) || defined(RISCOS) #ifdef __TOS_OS400__
# define fdopen(fd,mode) NULL /* No fdopen() */ # define OS_CODE 18
#endif #endif
#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX #ifdef __APPLE__
# if defined(_WIN32_WCE) # define OS_CODE 19
# define fdopen(fd,mode) NULL /* No fdopen() */
# ifndef _PTRDIFF_T_DEFINED
typedef int ptrdiff_t;
# define _PTRDIFF_T_DEFINED
# endif
# else
# define fdopen(fd,type) _fdopen(fd,type)
# endif
#endif #endif
#if defined(__BORLANDC__) #if defined(__BORLANDC__) && !defined(MSDOS)
#pragma warn -8004 #pragma warn -8004
#pragma warn -8008 #pragma warn -8008
#pragma warn -8066 #pragma warn -8066
#endif #endif
/* provide prototypes for these when building zlib without LFS */ /* provide prototypes for these when building zlib without LFS */
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 #ifndef Z_LARGE64
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t);
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t);
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t);
#endif #endif
/* common defaults */ /* common defaults */
#ifndef OS_CODE #ifndef OS_CODE
# define OS_CODE 0x03 /* assume Unix */ # define OS_CODE 3 /* assume Unix */
#endif #endif
#ifndef F_OPEN #ifndef F_OPEN
@ -187,42 +196,7 @@ ABC_NAMESPACE_HEADER_START
/* functions */ /* functions */
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) #if defined(pyr) || defined(Z_SOLO)
# ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF
# endif
#endif
#if defined(__CYGWIN__)
# ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF
# endif
#endif
#ifndef HAVE_VSNPRINTF
# ifdef MSDOS
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
but for now we just assume it doesn't. */
# define NO_vsnprintf
# endif
# ifdef __TURBOC__
# define NO_vsnprintf
# endif
# ifdef WIN32
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
# define vsnprintf _vsnprintf
# endif
# endif
# endif
# ifdef __SASC
# define NO_vsnprintf
# endif
#endif
#ifdef VMS
# define NO_vsnprintf
#endif
#if defined(pyr)
# define NO_MEMCPY # define NO_MEMCPY
#endif #endif
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
@ -239,25 +213,23 @@ ABC_NAMESPACE_HEADER_START
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
# define zmemcpy _fmemcpy # define zmemcpy _fmemcpy
# define zmemcmp _fmemcmp # define zmemcmp _fmemcmp
# define zmemzero(dest, len) _fmemset(dest, 0, (size_t)len) # define zmemzero(dest, len) _fmemset(dest, 0, len)
# else # else
# define zmemcpy memcpy # define zmemcpy memcpy
# define zmemcmp memcmp # define zmemcmp memcmp
# define zmemzero(dest, len) memset(dest, 0, (size_t)len) # define zmemzero(dest, len) memset(dest, 0, len)
# endif # endif
#else #else
void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); void ZLIB_INTERNAL zmemcpy(void FAR *, const void FAR *, z_size_t);
int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); int ZLIB_INTERNAL zmemcmp(const void FAR *, const void FAR *, z_size_t);
void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); void ZLIB_INTERNAL zmemzero(void FAR *, z_size_t);
#endif #endif
/* Diagnostic functions */ /* Diagnostic functions */
#ifdef DEBUG #ifdef ZLIB_DEBUG
ABC_NAMESPACE_HEADER_END
# include <stdio.h> # include <stdio.h>
ABC_NAMESPACE_HEADER_START
extern int ZLIB_INTERNAL z_verbose; extern int ZLIB_INTERNAL z_verbose;
extern void ZLIB_INTERNAL z_error OF((char *m)); extern void ZLIB_INTERNAL z_error(char *m);
# define Assert(cond,msg) {if(!(cond)) z_error(msg);} # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
# define Trace(x) {if (z_verbose>=0) fprintf x ;} # define Trace(x) {if (z_verbose>=0) fprintf x ;}
# define Tracev(x) {if (z_verbose>0) fprintf x ;} # define Tracev(x) {if (z_verbose>0) fprintf x ;}
@ -273,16 +245,91 @@ ABC_NAMESPACE_HEADER_START
# define Tracecv(c,x) # define Tracecv(c,x)
#endif #endif
#ifndef Z_SOLO
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
unsigned size)); unsigned size);
void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
#endif
#define ZALLOC(strm, items, size) \ #define ZALLOC(strm, items, size) \
(*((strm)->zalloc))((strm)->opaque, (items), (size)) (*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
/* Reverse the bytes in a 32-bit value */
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
ABC_NAMESPACE_HEADER_END ABC_NAMESPACE_HEADER_END
#ifdef Z_ONCE
/*
Create a local z_once() function depending on the availability of atomics.
*/
/* Check for the availability of atomics. */
#if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \
!defined(__STDC_NO_ATOMICS__)
#include <stdatomic.h>
typedef struct {
atomic_flag begun;
atomic_int done;
} z_once_t;
#define Z_ONCE_INIT {ATOMIC_FLAG_INIT, 0}
/*
Run the provided init() function exactly once, even if multiple threads
invoke once() at the same time. The state must be a once_t initialized with
Z_ONCE_INIT.
*/
local void z_once(z_once_t *state, void (*init)(void)) {
if (!atomic_load(&state->done)) {
if (atomic_flag_test_and_set(&state->begun))
while (!atomic_load(&state->done))
;
else {
init();
atomic_store(&state->done, 1);
}
}
}
#else /* no atomics */
#warning zlib not thread-safe
typedef struct z_once_s {
volatile int begun;
volatile int done;
} z_once_t;
#define Z_ONCE_INIT {0, 0}
/* Test and set. Alas, not atomic, but tries to limit the period of
vulnerability. */
local int test_and_set(int volatile *flag) {
int was;
was = *flag;
*flag = 1;
return was;
}
/* Run the provided init() function once. This is not thread-safe. */
local void z_once(z_once_t *state, void (*init)(void)) {
if (!state->done) {
if (test_and_set(&state->begun))
while (!state->done)
;
else {
init();
state->done = 1;
}
}
}
#endif /* ?atomics */
#endif /* Z_ONCE */
#endif /* ZUTIL_H */ #endif /* ZUTIL_H */