Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
f0cf45d3
Commit
f0cf45d3
authored
Jul 06, 2022
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zlib: updated bundled zlib to v1.2.12
parent
a0c5275c
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
1294 additions
and
523 deletions
+1294
-523
deps/zlib/adler32.c
+7
-0
deps/zlib/crc32.c
+969
-288
deps/zlib/crc32.h
+0
-0
deps/zlib/deflate.c
+78
-31
deps/zlib/deflate.h
+12
-15
deps/zlib/gzguts.h
+3
-2
deps/zlib/infback.c
+2
-1
deps/zlib/inffast.c
+14
-14
deps/zlib/inflate.c
+39
-8
deps/zlib/inflate.h
+3
-2
deps/zlib/inftrees.c
+3
-3
deps/zlib/trees.c
+27
-48
deps/zlib/zlib.h
+123
-100
deps/zlib/zutil.c
+2
-2
deps/zlib/zutil.h
+12
-9
No files found.
deps/zlib/adler32.c
View file @
f0cf45d3
...
...
@@ -177,3 +177,10 @@ uLong ZEXPORT adler32_combine(adler1, adler2, len2)
return
adler32_combine_
(
adler1
,
adler2
,
len2
);
}
uLong
ZEXPORT
adler32_combine64
(
adler1
,
adler2
,
len2
)
uLong
adler1
;
uLong
adler2
;
z_off64_t
len2
;
{
return
adler32_combine_
(
adler1
,
adler2
,
len2
);
}
deps/zlib/crc32.c
View file @
f0cf45d3
/* crc32.c -- compute the CRC-32 of a data stream
* Copyright (C) 1995-20
06, 2010, 2011, 2012, 2016
Mark Adler
* Copyright (C) 1995-20
22
Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
* CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
* tables for updating the shift register in one step with three exclusive-ors
* instead of four steps with four exclusive-ors. This results in about a
* factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
* This interleaved implementation of a CRC makes use of pipelined multiple
* arithmetic-logic units, commonly found in modern CPU cores. It is due to
* Kadatch and Jenkins (2010). See doc/crc-doc.1.0.pdf in this distribution.
*/
/* @(#) $Id$ */
...
...
@@ -14,11 +12,12 @@
/*
Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
protection on the static variables used to control the first-use generation
of the crc tables.
Therefore, if you #define DYNAMIC_CRC_TABLE, you should
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
first call get_crc_table() to initialize the tables before allowing more than
one thread to use crc32().
DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
MAKECRCH can be #defined to write out crc32.h. A main() routine is also
produced, so that this one source file can be compiled to an executable.
*/
#ifdef MAKECRCH
...
...
@@ -28,408 +27,1090 @@
# endif
/* !DYNAMIC_CRC_TABLE */
#endif
/* MAKECRCH */
#include "zutil.h"
/* for
STDC
and FAR definitions */
#include "zutil.h"
/* for
Z_U4, Z_U8, z_crc_t,
and FAR definitions */
/* Definitions for doing the crc four data bytes at a time. */
#if !defined(NOBYFOUR) && defined(Z_U4)
# define BYFOUR
/*
A CRC of a message is computed on N braids of words in the message, where
each word consists of W bytes (4 or 8). If N is 3, for example, then three
running sparse CRCs are calculated respectively on each braid, at these
indices in the array of words: 0, 3, 6, ..., 1, 4, 7, ..., and 2, 5, 8, ...
This is done starting at a word boundary, and continues until as many blocks
of N * W bytes as are available have been processed. The results are combined
into a single CRC at the end. For this code, N must be in the range 1..6 and
W must be 4 or 8. The upper limit on N can be increased if desired by adding
more #if blocks, extending the patterns apparent in the code. In addition,
crc32.h would need to be regenerated, if the maximum N value is increased.
N and W are chosen empirically by benchmarking the execution time on a given
processor. The choices for N and W below were based on testing on Intel Kaby
Lake i7, AMD Ryzen 7, ARM Cortex-A57, Sparc64-VII, PowerPC POWER9, and MIPS64
Octeon II processors. The Intel, AMD, and ARM processors were all fastest
with N=5, W=8. The Sparc, PowerPC, and MIPS64 were all fastest at N=5, W=4.
They were all tested with either gcc or clang, all using the -O3 optimization
level. Your mileage may vary.
*/
/* Define N */
#ifdef Z_TESTN
# define N Z_TESTN
#else
# define N 5
#endif
#if N < 1 || N > 6
# error N must be in 1..6
#endif
#ifdef BYFOUR
local
unsigned
long
crc32_little
OF
((
unsigned
long
,
const
unsigned
char
FAR
*
,
z_size_t
));
local
unsigned
long
crc32_big
OF
((
unsigned
long
,
const
unsigned
char
FAR
*
,
z_size_t
));
# define TBLS 8
/*
z_crc_t must be at least 32 bits. z_word_t must be at least as long as
z_crc_t. It is assumed here that z_word_t is either 32 bits or 64 bits, and
that bytes are eight bits.
*/
/*
Define W and the associated z_word_t type. If W is not defined, then a
braided calculation is not used, and the associated tables and code are not
compiled.
*/
#ifdef Z_TESTW
# if Z_TESTW-1 != -1
# define W Z_TESTW
# endif
#else
# define TBLS 1
#endif
/* BYFOUR */
# ifdef MAKECRCH
# define W 8
/* required for MAKECRCH */
# else
# if defined(__x86_64__) || defined(__aarch64__)
# define W 8
# else
# define W 4
# endif
# endif
#endif
#ifdef W
# if W == 8 && defined(Z_U8)
typedef
Z_U8
z_word_t
;
# elif defined(Z_U4)
# undef W
# define W 4
typedef
Z_U4
z_word_t
;
# else
# undef W
# endif
#endif
/* Local functions for crc concatenation */
local
unsigned
long
gf2_matrix_times
OF
((
unsigned
long
*
mat
,
unsigned
long
vec
));
local
void
gf2_matrix_square
OF
((
unsigned
long
*
square
,
unsigned
long
*
mat
));
local
uLong
crc32_combine_
OF
((
uLong
crc1
,
uLong
crc2
,
z_off64_t
len2
));
/* Local functions. */
local
z_crc_t
multmodp
OF
((
z_crc_t
a
,
z_crc_t
b
));
local
z_crc_t
x2nmodp
OF
((
z_off64_t
n
,
unsigned
k
));
/* If available, use the ARM processor CRC32 instruction. */
#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) && W == 8
# define ARMCRC32
#endif
#if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE))
/*
Swap the bytes in a z_word_t to convert between little and big endian. Any
self-respecting compiler will optimize this to a single machine byte-swap
instruction, if one is available. This assumes that word_t is either 32 bits
or 64 bits.
*/
local
z_word_t
byte_swap
(
word
)
z_word_t
word
;
{
# if W == 8
return
(
word
&
0xff00000000000000
)
>>
56
|
(
word
&
0xff000000000000
)
>>
40
|
(
word
&
0xff0000000000
)
>>
24
|
(
word
&
0xff00000000
)
>>
8
|
(
word
&
0xff000000
)
<<
8
|
(
word
&
0xff0000
)
<<
24
|
(
word
&
0xff00
)
<<
40
|
(
word
&
0xff
)
<<
56
;
# else
/* W == 4 */
return
(
word
&
0xff000000
)
>>
24
|
(
word
&
0xff0000
)
>>
8
|
(
word
&
0xff00
)
<<
8
|
(
word
&
0xff
)
<<
24
;
# endif
}
#endif
/* CRC polynomial. */
#define POLY 0xedb88320
/* p(x) reflected, with x^32 implied */
#ifdef DYNAMIC_CRC_TABLE
local
volatile
int
crc_table_empty
=
1
;
local
z_crc_t
FAR
crc_table
[
TBLS
][
256
];
local
z_crc_t
FAR
crc_table
[
256
]
;
local
z_crc_t
FAR
x2n_table
[
32
];
local
void
make_crc_table
OF
((
void
));
#ifdef W
local
z_word_t
FAR
crc_big_table
[
256
];
local
z_crc_t
FAR
crc_braid_table
[
W
][
256
];
local
z_word_t
FAR
crc_braid_big_table
[
W
][
256
];
local
void
braid
OF
((
z_crc_t
[][
256
],
z_word_t
[][
256
],
int
,
int
));
#endif
#ifdef MAKECRCH
local
void
write_table
OF
((
FILE
*
,
const
z_crc_t
FAR
*
));
local
void
write_table
OF
((
FILE
*
,
const
z_crc_t
FAR
*
,
int
));
local
void
write_table32hi
OF
((
FILE
*
,
const
z_word_t
FAR
*
,
int
));
local
void
write_table64
OF
((
FILE
*
,
const
z_word_t
FAR
*
,
int
));
#endif
/* MAKECRCH */
/*
Define a once() function depending on the availability of atomics. If this is
compiled with DYNAMIC_CRC_TABLE defined, and if CRCs will be computed in
multiple threads, and if atomics are not available, then get_crc_table() must
be called to initialize the tables and must return before any threads are
allowed to compute or combine CRCs.
*/
/* Definition of once functionality. */
typedef
struct
once_s
once_t
;
local
void
once
OF
((
once_t
*
,
void
(
*
)(
void
)));
/* Check for the availability of atomics. */
#if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \
!defined(__STDC_NO_ATOMICS__)
#include <stdatomic.h>
/* Structure for once(), which must be initialized with ONCE_INIT. */
struct
once_s
{
atomic_flag
begun
;
atomic_int
done
;
};
#define 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
ONCE_INIT.
*/
local
void
once
(
state
,
init
)
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 */
/* Structure for once(), which must be initialized with ONCE_INIT. */
struct
once_s
{
volatile
int
begun
;
volatile
int
done
;
};
#define ONCE_INIT {0, 0}
/* Test and set. Alas, not atomic, but tries to minimize the period of
vulnerability. */
local
int
test_and_set
OF
((
int
volatile
*
));
local
int
test_and_set
(
flag
)
int
volatile
*
flag
;
{
int
was
;
was
=
*
flag
;
*
flag
=
1
;
return
was
;
}
/* Run the provided init() function once. This is not thread-safe. */
local
void
once
(
state
,
init
)
once_t
*
state
;
void
(
*
init
)(
void
);
{
if
(
!
state
->
done
)
{
if
(
test_and_set
(
&
state
->
begun
))
while
(
!
state
->
done
)
;
else
{
init
();
state
->
done
=
1
;
}
}
}
#endif
/* State for once(). */
local
once_t
made
=
ONCE_INIT
;
/*
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
Polynomials over GF(2) are represented in binary, one bit per coefficient,
with the lowest powers in the most significant bit.
Then adding polynomials
with the lowest powers in the most significant bit. Then adding polynomials
is just exclusive-or, and multiplying a polynomial by x is a right shift by
one.
If we call the above polynomial p, and represent a byte as the
one. If we call the above polynomial p, and represent a byte as the
polynomial q, also with the lowest power in the most significant bit (so the
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
byte 0xb1 is the polynomial x^7+x^3+x
^2
+1), then the CRC is (q*x^32) mod p,
where a mod b means the remainder after dividing a by b.
This calculation is done using the shift-register method of multiplying and
taking the remainder.
The register is initialized to zero, and for each
taking the remainder. The register is initialized to zero, and for each
incoming bit, x^32 is added mod p to the register if the bit is a one (where
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
x (which is shifting right by one and adding x^32 mod p if the bit shifted
out is a one). We start with the highest power (least significant bit) of
q and repeat for all eight bits of q.
The first table is simply the CRC of all possible eight bit values. This is
all the information needed to generate CRCs on data a byte at a time for all
combinations of CRC register values and incoming bytes. The remaining tables
allow for word-at-a-time CRC calculation for both big-endian and little-
endian machines, where a word is four bytes.
*/
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by x
(which is shifting right by one and adding x^32 mod p if the bit shifted out
is a one). We start with the highest power (least significant bit) of q and
repeat for all eight bits of q.
The table is simply the CRC of all possible eight bit values. This is all the
information needed to generate CRCs on data a byte at a time for all
combinations of CRC register values and incoming bytes.
*/
local
void
make_crc_table
()
{
z_crc_t
c
;
int
n
,
k
;
z_crc_t
poly
;
/* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static
volatile
int
first
=
1
;
/* flag to limit concurrent making */
static
const
unsigned
char
p
[]
=
{
0
,
1
,
2
,
4
,
5
,
7
,
8
,
10
,
11
,
12
,
16
,
22
,
23
,
26
};
/* See if another task is already doing this (not thread-safe, but better
than nothing -- significantly reduces duration of vulnerability in
case the advice about DYNAMIC_CRC_TABLE is ignored) */
if
(
first
)
{
first
=
0
;
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
poly
=
0
;
for
(
n
=
0
;
n
<
(
int
)(
sizeof
(
p
)
/
sizeof
(
unsigned
char
));
n
++
)
poly
|=
(
z_crc_t
)
1
<<
(
31
-
p
[
n
]);
/* generate a crc for every 8-bit value */
for
(
n
=
0
;
n
<
256
;
n
++
)
{
c
=
(
z_crc_t
)
n
;
for
(
k
=
0
;
k
<
8
;
k
++
)
c
=
c
&
1
?
poly
^
(
c
>>
1
)
:
c
>>
1
;
crc_table
[
0
][
n
]
=
c
;
}
unsigned
i
,
j
,
n
;
z_crc_t
p
;
#ifdef BYFOUR
/* generate crc for each value followed by one, two, and three zeros,
and then the byte reversal of those as well as the first table */
for
(
n
=
0
;
n
<
256
;
n
++
)
{
c
=
crc_table
[
0
][
n
];
crc_table
[
4
][
n
]
=
ZSWAP32
(
c
);
for
(
k
=
1
;
k
<
4
;
k
++
)
{
c
=
crc_table
[
0
][
c
&
0xff
]
^
(
c
>>
8
);
crc_table
[
k
][
n
]
=
c
;
crc_table
[
k
+
4
][
n
]
=
ZSWAP32
(
c
);
}
}
#endif
/* BYFOUR */
crc_table_empty
=
0
;
}
else
{
/* not first */
/* wait for the other guy to finish (not efficient, but rare) */
while
(
crc_table_empty
)
;
/* initialize the CRC of bytes tables */
for
(
i
=
0
;
i
<
256
;
i
++
)
{
p
=
i
;
for
(
j
=
0
;
j
<
8
;
j
++
)
p
=
p
&
1
?
(
p
>>
1
)
^
POLY
:
p
>>
1
;
crc_table
[
i
]
=
p
;
#ifdef W
crc_big_table
[
i
]
=
byte_swap
(
p
);
#endif
}
/* initialize the x^2^n mod p(x) table */
p
=
(
z_crc_t
)
1
<<
30
;
/* x^1 */
x2n_table
[
0
]
=
p
;
for
(
n
=
1
;
n
<
32
;
n
++
)
x2n_table
[
n
]
=
p
=
multmodp
(
p
,
p
);
#ifdef W
/* initialize the braiding tables -- needs x2n_table[] */
braid
(
crc_braid_table
,
crc_braid_big_table
,
N
,
W
);
#endif
#ifdef MAKECRCH
/* write out CRC tables to crc32.h */
{
/*
The crc32.h header file contains tables for both 32-bit and 64-bit
z_word_t's, and so requires a 64-bit type be available. In that case,
z_word_t must be defined to be 64-bits. This code then also generates
and writes out the tables for the case that z_word_t is 32 bits.
*/
#if !defined(W) || W != 8
# error Need a 64-bit integer type in order to generate crc32.h.
#endif
FILE
*
out
;
int
k
,
n
;
z_crc_t
ltl
[
8
][
256
];
z_word_t
big
[
8
][
256
];
out
=
fopen
(
"crc32.h"
,
"w"
);
if
(
out
==
NULL
)
return
;
fprintf
(
out
,
"/* crc32.h -- tables for rapid CRC calculation
\n
"
);
fprintf
(
out
,
" * Generated automatically by crc32.c
\n
*/
\n\n
"
);
fprintf
(
out
,
"local const z_crc_t FAR "
);
fprintf
(
out
,
"crc_table[TBLS][256] =
\n
{
\n
{
\n
"
);
write_table
(
out
,
crc_table
[
0
]);
# ifdef BYFOUR
fprintf
(
out
,
"#ifdef BYFOUR
\n
"
);
for
(
k
=
1
;
k
<
8
;
k
++
)
{
fprintf
(
out
,
" },
\n
{
\n
"
);
write_table
(
out
,
crc_table
[
k
]);
/* write out little-endian CRC table to crc32.h */
fprintf
(
out
,
"/* crc32.h -- tables for rapid CRC calculation
\n
"
" * Generated automatically by crc32.c
\n
*/
\n
"
"
\n
"
"local const z_crc_t FAR crc_table[] = {
\n
"
" "
);
write_table
(
out
,
crc_table
,
256
);
fprintf
(
out
,
"};
\n
"
);
/* write out big-endian CRC table for 64-bit z_word_t to crc32.h */
fprintf
(
out
,
"
\n
"
"#ifdef W
\n
"
"
\n
"
"#if W == 8
\n
"
"
\n
"
"local const z_word_t FAR crc_big_table[] = {
\n
"
" "
);
write_table64
(
out
,
crc_big_table
,
256
);
fprintf
(
out
,
"};
\n
"
);
/* write out big-endian CRC table for 32-bit z_word_t to crc32.h */
fprintf
(
out
,
"
\n
"
"#else /* W == 4 */
\n
"
"
\n
"
"local const z_word_t FAR crc_big_table[] = {
\n
"
" "
);
write_table32hi
(
out
,
crc_big_table
,
256
);
fprintf
(
out
,
"};
\n
"
"
\n
"
"#endif
\n
"
);
/* write out braid tables for each value of N */
for
(
n
=
1
;
n
<=
6
;
n
++
)
{
fprintf
(
out
,
"
\n
"
"#if N == %d
\n
"
,
n
);
/* compute braid tables for this N and 64-bit word_t */
braid
(
ltl
,
big
,
n
,
8
);
/* write out braid tables for 64-bit z_word_t to crc32.h */
fprintf
(
out
,
"
\n
"
"#if W == 8
\n
"
"
\n
"
"local const z_crc_t FAR crc_braid_table[][256] = {
\n
"
);
for
(
k
=
0
;
k
<
8
;
k
++
)
{
fprintf
(
out
,
" {"
);
write_table
(
out
,
ltl
[
k
],
256
);
fprintf
(
out
,
"}%s"
,
k
<
7
?
",
\n
"
:
""
);
}
fprintf
(
out
,
"};
\n
"
"
\n
"
"local const z_word_t FAR crc_braid_big_table[][256] = {
\n
"
);
for
(
k
=
0
;
k
<
8
;
k
++
)
{
fprintf
(
out
,
" {"
);
write_table64
(
out
,
big
[
k
],
256
);
fprintf
(
out
,
"}%s"
,
k
<
7
?
",
\n
"
:
""
);
}
fprintf
(
out
,
"};
\n
"
);
/* compute braid tables for this N and 32-bit word_t */
braid
(
ltl
,
big
,
n
,
4
);
/* write out braid tables for 32-bit z_word_t to crc32.h */
fprintf
(
out
,
"
\n
"
"#else /* W == 4 */
\n
"
"
\n
"
"local const z_crc_t FAR crc_braid_table[][256] = {
\n
"
);
for
(
k
=
0
;
k
<
4
;
k
++
)
{
fprintf
(
out
,
" {"
);
write_table
(
out
,
ltl
[
k
],
256
);
fprintf
(
out
,
"}%s"
,
k
<
3
?
",
\n
"
:
""
);
}
fprintf
(
out
,
"};
\n
"
"
\n
"
"local const z_word_t FAR crc_braid_big_table[][256] = {
\n
"
);
for
(
k
=
0
;
k
<
4
;
k
++
)
{
fprintf
(
out
,
" {"
);
write_table32hi
(
out
,
big
[
k
],
256
);
fprintf
(
out
,
"}%s"
,
k
<
3
?
",
\n
"
:
""
);
}
fprintf
(
out
,
"};
\n
"
"
\n
"
"#endif
\n
"
"
\n
"
"#endif
\n
"
);
}
fprintf
(
out
,
"#endif
\n
"
);
# endif
/* BYFOUR */
fprintf
(
out
,
" }
\n
};
\n
"
);
fprintf
(
out
,
"
\n
"
"#endif
\n
"
);
/* write out zeros operator table to crc32.h */
fprintf
(
out
,
"
\n
"
"local const z_crc_t FAR x2n_table[] = {
\n
"
" "
);
write_table
(
out
,
x2n_table
,
32
);
fprintf
(
out
,
"};
\n
"
);
fclose
(
out
);
}
#endif
/* MAKECRCH */
}
#ifdef MAKECRCH
local
void
write_table
(
out
,
table
)
/*
Write the 32-bit values in table[0..k-1] to out, five per line in
hexadecimal separated by commas.
*/
local
void
write_table
(
out
,
table
,
k
)
FILE
*
out
;
const
z_crc_t
FAR
*
table
;
int
k
;
{
int
n
;
for
(
n
=
0
;
n
<
256
;
n
++
)
fprintf
(
out
,
"%s0x%08lx
UL%s"
,
n
%
5
?
""
:
" "
,
for
(
n
=
0
;
n
<
k
;
n
++
)
fprintf
(
out
,
"%s0x%08lx
%s"
,
n
==
0
||
n
%
5
?
""
:
" "
,
(
unsigned
long
)(
table
[
n
]),
n
==
255
?
"
\n
"
:
(
n
%
5
==
4
?
",
\n
"
:
", "
));
n
==
k
-
1
?
"
"
:
(
n
%
5
==
4
?
",
\n
"
:
", "
));
}
/*
Write the high 32-bits of each value in table[0..k-1] to out, five per line
in hexadecimal separated by commas.
*/
local
void
write_table32hi
(
out
,
table
,
k
)
FILE
*
out
;
const
z_word_t
FAR
*
table
;
int
k
;
{
int
n
;
for
(
n
=
0
;
n
<
k
;
n
++
)
fprintf
(
out
,
"%s0x%08lx%s"
,
n
==
0
||
n
%
5
?
""
:
" "
,
(
unsigned
long
)(
table
[
n
]
>>
32
),
n
==
k
-
1
?
""
:
(
n
%
5
==
4
?
",
\n
"
:
", "
));
}
/*
Write the 64-bit values in table[0..k-1] to out, three per line in
hexadecimal separated by commas. This assumes that if there is a 64-bit
type, then there is also a long long integer type, and it is at least 64
bits. If not, then the type cast and format string can be adjusted
accordingly.
*/
local
void
write_table64
(
out
,
table
,
k
)
FILE
*
out
;
const
z_word_t
FAR
*
table
;
int
k
;
{
int
n
;
for
(
n
=
0
;
n
<
k
;
n
++
)
fprintf
(
out
,
"%s0x%016llx%s"
,
n
==
0
||
n
%
3
?
""
:
" "
,
(
unsigned
long
long
)(
table
[
n
]),
n
==
k
-
1
?
""
:
(
n
%
3
==
2
?
",
\n
"
:
", "
));
}
/* Actually do the deed. */
int
main
()
{
make_crc_table
();
return
0
;
}
#endif
/* MAKECRCH */
#ifdef W
/*
Generate the little and big-endian braid tables for the given n and z_word_t
size w. Each array must have room for w blocks of 256 elements.
*/
local
void
braid
(
ltl
,
big
,
n
,
w
)
z_crc_t
ltl
[][
256
];
z_word_t
big
[][
256
];
int
n
;
int
w
;
{
int
k
;
z_crc_t
i
,
p
,
q
;
for
(
k
=
0
;
k
<
w
;
k
++
)
{
p
=
x2nmodp
((
n
*
w
+
3
-
k
)
<<
3
,
0
);
ltl
[
k
][
0
]
=
0
;
big
[
w
-
1
-
k
][
0
]
=
0
;
for
(
i
=
1
;
i
<
256
;
i
++
)
{
ltl
[
k
][
i
]
=
q
=
multmodp
(
i
<<
24
,
p
);
big
[
w
-
1
-
k
][
i
]
=
byte_swap
(
q
);
}
}
}
#endif
#else
/* !DYNAMIC_CRC_TABLE */
/* ========================================================================
* Tables of CRC-32s of all single-byte values, made by make_crc_table().
* Tables for byte-wise and braided CRC-32 calculations, and a table of powers
* of x for combining CRC-32s, all made by make_crc_table().
*/
#include "crc32.h"
#endif
/* DYNAMIC_CRC_TABLE */
/* ========================================================================
* Routines used for CRC calculation. Some are also required for the table
* generation above.
*/
/*
Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial,
reflected. For speed, this requires that a not be zero.
*/
local
z_crc_t
multmodp
(
a
,
b
)
z_crc_t
a
;
z_crc_t
b
;
{
z_crc_t
m
,
p
;
m
=
(
z_crc_t
)
1
<<
31
;
p
=
0
;
for
(;;)
{
if
(
a
&
m
)
{
p
^=
b
;
if
((
a
&
(
m
-
1
))
==
0
)
break
;
}
m
>>=
1
;
b
=
b
&
1
?
(
b
>>
1
)
^
POLY
:
b
>>
1
;
}
return
p
;
}
/*
Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been
initialized.
*/
local
z_crc_t
x2nmodp
(
n
,
k
)
z_off64_t
n
;
unsigned
k
;
{
z_crc_t
p
;
p
=
(
z_crc_t
)
1
<<
31
;
/* x^0 == 1 */
while
(
n
)
{
if
(
n
&
1
)
p
=
multmodp
(
x2n_table
[
k
&
31
],
p
);
n
>>=
1
;
k
++
;
}
return
p
;
}
/* =========================================================================
* This function can be used by asm versions of crc32()
* This function can be used by asm versions of crc32(), and to force the
* generation of the CRC tables in a threaded application.
*/
const
z_crc_t
FAR
*
ZEXPORT
get_crc_table
()
{
#ifdef DYNAMIC_CRC_TABLE
if
(
crc_table_empty
)
make_crc_table
();
once
(
&
made
,
make_crc_table
);
#endif
/* DYNAMIC_CRC_TABLE */
return
(
const
z_crc_t
FAR
*
)
crc_table
;
}
/* ========================================================================= */
#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
/* =========================================================================
* Use ARM machine instructions if available. This will compute the CRC about
* ten times faster than the braided calculation. This code does not check for
* the presence of the CRC instruction at run time. __ARM_FEATURE_CRC32 will
* only be defined if the compilation specifies an ARM processor architecture
* that has the instructions. For example, compiling with -march=armv8.1-a or
* -march=armv8-a+crc, or -march=native if the compile machine has the crc32
* instructions.
*/
#ifdef ARMCRC32
/*
Constants empirically determined to maximize speed. These values are from
measurements on a Cortex-A57. Your mileage may vary.
*/
#define Z_BATCH 3990
/* number of words in a batch */
#define Z_BATCH_ZEROS 0xa10d3d0c
/* computed from Z_BATCH = 3990 */
#define Z_BATCH_MIN 800
/* fewest words in a final batch */
/* ========================================================================= */
unsigned
long
ZEXPORT
crc32_z
(
crc
,
buf
,
len
)
unsigned
long
crc
;
const
unsigned
char
FAR
*
buf
;
z_size_t
len
;
{
if
(
buf
==
Z_NULL
)
return
0UL
;
z_crc_t
val
;
z_word_t
crc1
,
crc2
;
const
z_word_t
*
word
;
z_word_t
val0
,
val1
,
val2
;
z_size_t
last
,
last2
,
i
;
z_size_t
num
;
/* Return initial CRC, if requested. */
if
(
buf
==
Z_NULL
)
return
0
;
#ifdef DYNAMIC_CRC_TABLE
if
(
crc_table_empty
)
make_crc_table
();
once
(
&
made
,
make_crc_table
);
#endif
/* DYNAMIC_CRC_TABLE */
#ifdef BYFOUR
if
(
sizeof
(
void
*
)
==
sizeof
(
ptrdiff_t
))
{
z_crc_t
endian
;
/* Pre-condition the CRC */
crc
^=
0xffffffff
;
endian
=
1
;
if
(
*
((
unsigned
char
*
)(
&
endian
)))
return
crc32_little
(
crc
,
buf
,
len
)
;
else
return
crc32_big
(
crc
,
buf
,
len
);
/* Compute the CRC up to a word boundary. */
while
(
len
&&
((
z_size_t
)
buf
&
7
)
!=
0
)
{
len
--
;
val
=
*
buf
++
;
__asm__
volatile
(
"crc32b %w0, %w0, %w1"
:
"+r"
(
crc
)
:
"r"
(
val
)
);
}
#endif
/* BYFOUR */
crc
=
crc
^
0xffffffffUL
;
while
(
len
>=
8
)
{
DO8
;
len
-=
8
;
/* Prepare to compute the CRC on full 64-bit words word[0..num-1]. */
word
=
(
z_word_t
const
*
)
buf
;
num
=
len
>>
3
;
len
&=
7
;
/* Do three interleaved CRCs to realize the throughput of one crc32x
instruction per cycle. Each CRC is calcuated on Z_BATCH words. The three
CRCs are combined into a single CRC after each set of batches. */
while
(
num
>=
3
*
Z_BATCH
)
{
crc1
=
0
;
crc2
=
0
;
for
(
i
=
0
;
i
<
Z_BATCH
;
i
++
)
{
val0
=
word
[
i
];
val1
=
word
[
i
+
Z_BATCH
];
val2
=
word
[
i
+
2
*
Z_BATCH
];
__asm__
volatile
(
"crc32x %w0, %w0, %x1"
:
"+r"
(
crc
)
:
"r"
(
val0
));
__asm__
volatile
(
"crc32x %w0, %w0, %x1"
:
"+r"
(
crc1
)
:
"r"
(
val1
));
__asm__
volatile
(
"crc32x %w0, %w0, %x1"
:
"+r"
(
crc2
)
:
"r"
(
val2
));
}
word
+=
3
*
Z_BATCH
;
num
-=
3
*
Z_BATCH
;
crc
=
multmodp
(
Z_BATCH_ZEROS
,
crc
)
^
crc1
;
crc
=
multmodp
(
Z_BATCH_ZEROS
,
crc
)
^
crc2
;
}
if
(
len
)
do
{
DO1
;
}
while
(
--
len
);
return
crc
^
0xffffffffUL
;
}
/* ========================================================================= */
unsigned
long
ZEXPORT
crc32
(
crc
,
buf
,
len
)
unsigned
long
crc
;
const
unsigned
char
FAR
*
buf
;
uInt
len
;
{
return
crc32_z
(
crc
,
buf
,
len
);
/* Do one last smaller batch with the remaining words, if there are enough
to pay for the combination of CRCs. */
last
=
num
/
3
;
if
(
last
>=
Z_BATCH_MIN
)
{
last2
=
last
<<
1
;
crc1
=
0
;
crc2
=
0
;
for
(
i
=
0
;
i
<
last
;
i
++
)
{
val0
=
word
[
i
];
val1
=
word
[
i
+
last
];
val2
=
word
[
i
+
last2
];
__asm__
volatile
(
"crc32x %w0, %w0, %x1"
:
"+r"
(
crc
)
:
"r"
(
val0
));
__asm__
volatile
(
"crc32x %w0, %w0, %x1"
:
"+r"
(
crc1
)
:
"r"
(
val1
));
__asm__
volatile
(
"crc32x %w0, %w0, %x1"
:
"+r"
(
crc2
)
:
"r"
(
val2
));
}
word
+=
3
*
last
;
num
-=
3
*
last
;
val
=
x2nmodp
(
last
,
6
);
crc
=
multmodp
(
val
,
crc
)
^
crc1
;
crc
=
multmodp
(
val
,
crc
)
^
crc2
;
}
/* Compute the CRC on any remaining words. */
for
(
i
=
0
;
i
<
num
;
i
++
)
{
val0
=
word
[
i
];
__asm__
volatile
(
"crc32x %w0, %w0, %x1"
:
"+r"
(
crc
)
:
"r"
(
val0
));
}
word
+=
num
;
/* Complete the CRC on any remaining bytes. */
buf
=
(
const
unsigned
char
FAR
*
)
word
;
while
(
len
)
{
len
--
;
val
=
*
buf
++
;
__asm__
volatile
(
"crc32b %w0, %w0, %w1"
:
"+r"
(
crc
)
:
"r"
(
val
));
}
/* Return the CRC, post-conditioned. */
return
crc
^
0xffffffff
;
}
#ifdef BYFOUR
#else
#ifdef W
/*
This BYFOUR code accesses the passed unsigned char * buffer with a 32-bit
integer pointer type. This violates the strict aliasing rule, where a
compiler can assume, for optimization purposes, that two pointers to
fundamentally different types won't ever point to the same memory. This can
manifest as a problem only if one of the pointers is written to. This code
only reads from those pointers. So long as this code remains isolated in
this compilation unit, there won't be a problem. For this reason, this code
should not be copied and pasted into a compilation unit in which other code
writes to the buffer that is passed to these routines.
Return the CRC of the W bytes in the word_t data, taking the
least-significant byte of the word as the first byte of data, without any pre
or post conditioning. This is used to combine the CRCs of each braid.
*/
local
z_crc_t
crc_word
(
data
)
z_word_t
data
;
{
int
k
;
for
(
k
=
0
;
k
<
W
;
k
++
)
data
=
(
data
>>
8
)
^
crc_table
[
data
&
0xff
];
return
(
z_crc_t
)
data
;
}
/* ========================================================================= */
#define DOLIT4 c ^= *buf4++; \
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
local
z_word_t
crc_word_big
(
data
)
z_word_t
data
;
{
int
k
;
for
(
k
=
0
;
k
<
W
;
k
++
)
data
=
(
data
<<
8
)
^
crc_big_table
[(
data
>>
((
W
-
1
)
<<
3
))
&
0xff
];
return
data
;
}
#endif
/* ========================================================================= */
local
unsigned
long
crc32_little
(
crc
,
buf
,
len
)
unsigned
long
ZEXPORT
crc32_z
(
crc
,
buf
,
len
)
unsigned
long
crc
;
const
unsigned
char
FAR
*
buf
;
z_size_t
len
;
{
register
z_crc_t
c
;
register
const
z_crc_t
FAR
*
buf4
;
/* Return initial CRC, if requested. */
if
(
buf
==
Z_NULL
)
return
0
;
c
=
(
z_crc_t
)
crc
;
c
=
~
c
;
while
(
len
&&
((
ptrdiff_t
)
buf
&
3
))
{
c
=
crc_table
[
0
][(
c
^
*
buf
++
)
&
0xff
]
^
(
c
>>
8
);
len
--
;
}
#ifdef DYNAMIC_CRC_TABLE
once
(
&
made
,
make_crc_table
);
#endif
/* DYNAMIC_CRC_TABLE */
buf4
=
(
const
z_crc_t
FAR
*
)(
const
void
FAR
*
)
buf
;
while
(
len
>=
32
)
{
DOLIT32
;
len
-=
32
;
}
while
(
len
>=
4
)
{
DOLIT4
;
len
-=
4
;
}
buf
=
(
const
unsigned
char
FAR
*
)
buf4
;
/* Pre-condition the CRC */
crc
^=
0xffffffff
;
if
(
len
)
do
{
c
=
crc_table
[
0
][(
c
^
*
buf
++
)
&
0xff
]
^
(
c
>>
8
);
}
while
(
--
len
);
c
=
~
c
;
return
(
unsigned
long
)
c
;
}
#ifdef W
/* ========================================================================= */
#define DOBIG4 c ^= *buf4++; \
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
/* If provided enough bytes, do a braided CRC calculation. */
if
(
len
>=
N
*
W
+
W
-
1
)
{
z_size_t
blks
;
z_word_t
const
*
words
;
unsigned
endian
;
int
k
;
/* ========================================================================= */
local
unsigned
long
crc32_big
(
crc
,
buf
,
len
)
unsigned
long
crc
;
const
unsigned
char
FAR
*
buf
;
z_size_t
len
;
{
register
z_crc_t
c
;
register
const
z_crc_t
FAR
*
buf4
;
/* Compute the CRC up to a z_word_t boundary. */
while
(
len
&&
((
z_size_t
)
buf
&
(
W
-
1
))
!=
0
)
{
len
--
;
crc
=
(
crc
>>
8
)
^
crc_table
[(
crc
^
*
buf
++
)
&
0xff
];
}
c
=
ZSWAP32
((
z_crc_t
)
crc
);
c
=
~
c
;
while
(
len
&&
((
ptrdiff_t
)
buf
&
3
))
{
c
=
crc_table
[
4
][(
c
>>
24
)
^
*
buf
++
]
^
(
c
<<
8
);
len
--
;
/* Compute the CRC on as many N z_word_t blocks as are available. */
blks
=
len
/
(
N
*
W
);
len
-=
blks
*
N
*
W
;
words
=
(
z_word_t
const
*
)
buf
;
/* Do endian check at execution time instead of compile time, since ARM
processors can change the endianess at execution time. If the
compiler knows what the endianess will be, it can optimize out the
check and the unused branch. */
endian
=
1
;
if
(
*
(
unsigned
char
*
)
&
endian
)
{
/* Little endian. */
z_crc_t
crc0
;
z_word_t
word0
;
#if N > 1
z_crc_t
crc1
;
z_word_t
word1
;
#if N > 2
z_crc_t
crc2
;
z_word_t
word2
;
#if N > 3
z_crc_t
crc3
;
z_word_t
word3
;
#if N > 4
z_crc_t
crc4
;
z_word_t
word4
;
#if N > 5
z_crc_t
crc5
;
z_word_t
word5
;
#endif
#endif
#endif
#endif
#endif
/* Initialize the CRC for each braid. */
crc0
=
crc
;
#if N > 1
crc1
=
0
;
#if N > 2
crc2
=
0
;
#if N > 3
crc3
=
0
;
#if N > 4
crc4
=
0
;
#if N > 5
crc5
=
0
;
#endif
#endif
#endif
#endif
#endif
/*
Process the first blks-1 blocks, computing the CRCs on each braid
independently.
*/
while
(
--
blks
)
{
/* Load the word for each braid into registers. */
word0
=
crc0
^
words
[
0
];
#if N > 1
word1
=
crc1
^
words
[
1
];
#if N > 2
word2
=
crc2
^
words
[
2
];
#if N > 3
word3
=
crc3
^
words
[
3
];
#if N > 4
word4
=
crc4
^
words
[
4
];
#if N > 5
word5
=
crc5
^
words
[
5
];
#endif
#endif
#endif
#endif
#endif
words
+=
N
;
/* Compute and update the CRC for each word. The loop should
get unrolled. */
crc0
=
crc_braid_table
[
0
][
word0
&
0xff
];
#if N > 1
crc1
=
crc_braid_table
[
0
][
word1
&
0xff
];
#if N > 2
crc2
=
crc_braid_table
[
0
][
word2
&
0xff
];
#if N > 3
crc3
=
crc_braid_table
[
0
][
word3
&
0xff
];
#if N > 4
crc4
=
crc_braid_table
[
0
][
word4
&
0xff
];
#if N > 5
crc5
=
crc_braid_table
[
0
][
word5
&
0xff
];
#endif
#endif
#endif
#endif
#endif
for
(
k
=
1
;
k
<
W
;
k
++
)
{
crc0
^=
crc_braid_table
[
k
][(
word0
>>
(
k
<<
3
))
&
0xff
];
#if N > 1
crc1
^=
crc_braid_table
[
k
][(
word1
>>
(
k
<<
3
))
&
0xff
];
#if N > 2
crc2
^=
crc_braid_table
[
k
][(
word2
>>
(
k
<<
3
))
&
0xff
];
#if N > 3
crc3
^=
crc_braid_table
[
k
][(
word3
>>
(
k
<<
3
))
&
0xff
];
#if N > 4
crc4
^=
crc_braid_table
[
k
][(
word4
>>
(
k
<<
3
))
&
0xff
];
#if N > 5
crc5
^=
crc_braid_table
[
k
][(
word5
>>
(
k
<<
3
))
&
0xff
];
#endif
#endif
#endif
#endif
#endif
}
}
/*
Process the last block, combining the CRCs of the N braids at the
same time.
*/
crc
=
crc_word
(
crc0
^
words
[
0
]);
#if N > 1
crc
=
crc_word
(
crc1
^
words
[
1
]
^
crc
);
#if N > 2
crc
=
crc_word
(
crc2
^
words
[
2
]
^
crc
);
#if N > 3
crc
=
crc_word
(
crc3
^
words
[
3
]
^
crc
);
#if N > 4
crc
=
crc_word
(
crc4
^
words
[
4
]
^
crc
);
#if N > 5
crc
=
crc_word
(
crc5
^
words
[
5
]
^
crc
);
#endif
#endif
#endif
#endif
#endif
words
+=
N
;
}
else
{
/* Big endian. */
z_word_t
crc0
,
word0
,
comb
;
#if N > 1
z_word_t
crc1
,
word1
;
#if N > 2
z_word_t
crc2
,
word2
;
#if N > 3
z_word_t
crc3
,
word3
;
#if N > 4
z_word_t
crc4
,
word4
;
#if N > 5
z_word_t
crc5
,
word5
;
#endif
#endif
#endif
#endif
#endif
/* Initialize the CRC for each braid. */
crc0
=
byte_swap
(
crc
);
#if N > 1
crc1
=
0
;
#if N > 2
crc2
=
0
;
#if N > 3
crc3
=
0
;
#if N > 4
crc4
=
0
;
#if N > 5
crc5
=
0
;
#endif
#endif
#endif
#endif
#endif
/*
Process the first blks-1 blocks, computing the CRCs on each braid
independently.
*/
while
(
--
blks
)
{
/* Load the word for each braid into registers. */
word0
=
crc0
^
words
[
0
];
#if N > 1
word1
=
crc1
^
words
[
1
];
#if N > 2
word2
=
crc2
^
words
[
2
];
#if N > 3
word3
=
crc3
^
words
[
3
];
#if N > 4
word4
=
crc4
^
words
[
4
];
#if N > 5
word5
=
crc5
^
words
[
5
];
#endif
#endif
#endif
#endif
#endif
words
+=
N
;
/* Compute and update the CRC for each word. The loop should
get unrolled. */
crc0
=
crc_braid_big_table
[
0
][
word0
&
0xff
];
#if N > 1
crc1
=
crc_braid_big_table
[
0
][
word1
&
0xff
];
#if N > 2
crc2
=
crc_braid_big_table
[
0
][
word2
&
0xff
];
#if N > 3
crc3
=
crc_braid_big_table
[
0
][
word3
&
0xff
];
#if N > 4
crc4
=
crc_braid_big_table
[
0
][
word4
&
0xff
];
#if N > 5
crc5
=
crc_braid_big_table
[
0
][
word5
&
0xff
];
#endif
#endif
#endif
#endif
#endif
for
(
k
=
1
;
k
<
W
;
k
++
)
{
crc0
^=
crc_braid_big_table
[
k
][(
word0
>>
(
k
<<
3
))
&
0xff
];
#if N > 1
crc1
^=
crc_braid_big_table
[
k
][(
word1
>>
(
k
<<
3
))
&
0xff
];
#if N > 2
crc2
^=
crc_braid_big_table
[
k
][(
word2
>>
(
k
<<
3
))
&
0xff
];
#if N > 3
crc3
^=
crc_braid_big_table
[
k
][(
word3
>>
(
k
<<
3
))
&
0xff
];
#if N > 4
crc4
^=
crc_braid_big_table
[
k
][(
word4
>>
(
k
<<
3
))
&
0xff
];
#if N > 5
crc5
^=
crc_braid_big_table
[
k
][(
word5
>>
(
k
<<
3
))
&
0xff
];
#endif
#endif
#endif
#endif
#endif
}
}
/*
Process the last block, combining the CRCs of the N braids at the
same time.
*/
comb
=
crc_word_big
(
crc0
^
words
[
0
]);
#if N > 1
comb
=
crc_word_big
(
crc1
^
words
[
1
]
^
comb
);
#if N > 2
comb
=
crc_word_big
(
crc2
^
words
[
2
]
^
comb
);
#if N > 3
comb
=
crc_word_big
(
crc3
^
words
[
3
]
^
comb
);
#if N > 4
comb
=
crc_word_big
(
crc4
^
words
[
4
]
^
comb
);
#if N > 5
comb
=
crc_word_big
(
crc5
^
words
[
5
]
^
comb
);
#endif
#endif
#endif
#endif
#endif
words
+=
N
;
crc
=
byte_swap
(
comb
);
}
/*
Update the pointer to the remaining bytes to process.
*/
buf
=
(
unsigned
char
const
*
)
words
;
}
buf4
=
(
const
z_crc_t
FAR
*
)(
const
void
FAR
*
)
buf
;
while
(
len
>=
32
)
{
DOBIG32
;
len
-=
32
;
#endif
/* W */
/* Complete the computation of the CRC on any remaining bytes. */
while
(
len
>=
8
)
{
len
-=
8
;
crc
=
(
crc
>>
8
)
^
crc_table
[(
crc
^
*
buf
++
)
&
0xff
];
crc
=
(
crc
>>
8
)
^
crc_table
[(
crc
^
*
buf
++
)
&
0xff
];
crc
=
(
crc
>>
8
)
^
crc_table
[(
crc
^
*
buf
++
)
&
0xff
];
crc
=
(
crc
>>
8
)
^
crc_table
[(
crc
^
*
buf
++
)
&
0xff
];
crc
=
(
crc
>>
8
)
^
crc_table
[(
crc
^
*
buf
++
)
&
0xff
];
crc
=
(
crc
>>
8
)
^
crc_table
[(
crc
^
*
buf
++
)
&
0xff
];
crc
=
(
crc
>>
8
)
^
crc_table
[(
crc
^
*
buf
++
)
&
0xff
];
crc
=
(
crc
>>
8
)
^
crc_table
[(
crc
^
*
buf
++
)
&
0xff
];
}
while
(
len
>=
4
)
{
DOBIG4
;
len
-=
4
;
while
(
len
)
{
len
--
;
crc
=
(
crc
>>
8
)
^
crc_table
[(
crc
^
*
buf
++
)
&
0xff
]
;
}
buf
=
(
const
unsigned
char
FAR
*
)
buf4
;
if
(
len
)
do
{
c
=
crc_table
[
4
][(
c
>>
24
)
^
*
buf
++
]
^
(
c
<<
8
);
}
while
(
--
len
);
c
=
~
c
;
return
(
unsigned
long
)(
ZSWAP32
(
c
));
/* Return the CRC, post-conditioned. */
return
crc
^
0xffffffff
;
}
#endif
/* BYFOUR */
#define GF2_DIM 32
/* dimension of GF(2) vectors (length of CRC) */
#endif
/* ========================================================================= */
local
unsigned
long
gf2_matrix_times
(
mat
,
vec
)
unsigned
long
*
mat
;
unsigned
long
vec
;
unsigned
long
ZEXPORT
crc32
(
crc
,
buf
,
len
)
unsigned
long
crc
;
const
unsigned
char
FAR
*
buf
;
uInt
len
;
{
unsigned
long
sum
;
sum
=
0
;
while
(
vec
)
{
if
(
vec
&
1
)
sum
^=
*
mat
;
vec
>>=
1
;
mat
++
;
}
return
sum
;
return
crc32_z
(
crc
,
buf
,
len
);
}
/* ========================================================================= */
local
void
gf2_matrix_square
(
square
,
mat
)
unsigned
long
*
square
;
unsigned
long
*
mat
;
uLong
ZEXPORT
crc32_combine64
(
crc1
,
crc2
,
len2
)
uLong
crc1
;
uLong
crc2
;
z_off64_t
len2
;
{
int
n
;
for
(
n
=
0
;
n
<
GF2_DIM
;
n
++
)
square
[
n
]
=
gf2_matrix_times
(
mat
,
mat
[
n
])
;
#ifdef DYNAMIC_CRC_TABLE
once
(
&
made
,
make_crc_table
);
#endif
/* DYNAMIC_CRC_TABLE */
return
multmodp
(
x2nmodp
(
len2
,
3
),
crc1
)
^
crc2
;
}
/* ========================================================================= */
local
uLong
crc32_combine_
(
crc1
,
crc2
,
len2
)
uLong
ZEXPORT
crc32_combine
(
crc1
,
crc2
,
len2
)
uLong
crc1
;
uLong
crc2
;
z_off_t
len2
;
{
return
crc32_combine64
(
crc1
,
crc2
,
len2
);
}
/* ========================================================================= */
uLong
ZEXPORT
crc32_combine_gen64
(
len2
)
z_off64_t
len2
;
{
int
n
;
unsigned
long
row
;
unsigned
long
even
[
GF2_DIM
];
/* even-power-of-two zeros operator */
unsigned
long
odd
[
GF2_DIM
];
/* odd-power-of-two zeros operator */
/* degenerate case (also disallow negative lengths) */
if
(
len2
<=
0
)
return
crc1
;
/* put operator for one zero bit in odd */
odd
[
0
]
=
0xedb88320UL
;
/* CRC-32 polynomial */
row
=
1
;
for
(
n
=
1
;
n
<
GF2_DIM
;
n
++
)
{
odd
[
n
]
=
row
;
row
<<=
1
;
}
#ifdef DYNAMIC_CRC_TABLE
once
(
&
made
,
make_crc_table
);
#endif
/* DYNAMIC_CRC_TABLE */
return
x2nmodp
(
len2
,
3
);
}
/* put operator for two zero bits in even */
gf2_matrix_square
(
even
,
odd
);
/* put operator for four zero bits in odd */
gf2_matrix_square
(
odd
,
even
);
/* apply len2 zeros to crc1 (first square will put the operator for one
zero byte, eight zero bits, in even) */
do
{
/* apply zeros operator for this bit of len2 */
gf2_matrix_square
(
even
,
odd
);
if
(
len2
&
1
)
crc1
=
gf2_matrix_times
(
even
,
crc1
);
len2
>>=
1
;
/* if no more bits set, then done */
if
(
len2
==
0
)
break
;
/* another iteration of the loop with odd and even swapped */
gf2_matrix_square
(
odd
,
even
);
if
(
len2
&
1
)
crc1
=
gf2_matrix_times
(
odd
,
crc1
);
len2
>>=
1
;
/* if no more bits set, then done */
}
while
(
len2
!=
0
);
/* return combined crc */
crc1
^=
crc2
;
return
crc1
;
/* ========================================================================= */
uLong
ZEXPORT
crc32_combine_gen
(
len2
)
z_off_t
len2
;
{
return
crc32_combine_gen64
(
len2
);
}
/* ========================================================================= */
uLong
ZEXPORT
crc32_combine
(
crc1
,
crc2
,
len2
)
uLong
crc32_combine_op
(
crc1
,
crc2
,
op
)
uLong
crc1
;
uLong
crc2
;
z_off_t
len2
;
uLong
op
;
{
return
crc32_combine_
(
crc1
,
crc2
,
len2
)
;
return
multmodp
(
op
,
crc1
)
^
crc2
;
}
deps/zlib/crc32.h
View file @
f0cf45d3
This source diff could not be displayed because it is too large. You can
view the blob
instead.
deps/zlib/deflate.c
View file @
f0cf45d3
/* deflate.c -- compress data using the deflation algorithm
* Copyright (C) 1995-20
17
Jean-loup Gailly and Mark Adler
* Copyright (C) 1995-20
22
Jean-loup Gailly and Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
...
...
@@ -52,7 +52,7 @@
#include "deflate.h"
const
char
deflate_copyright
[]
=
" deflate 1.2.1
1 Copyright 1995-2017
Jean-loup Gailly and Mark Adler "
;
" deflate 1.2.1
2 Copyright 1995-2022
Jean-loup Gailly and Mark Adler "
;
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
...
...
@@ -190,8 +190,11 @@ local const config configuration_table[10] = {
* prev[] will be initialized on the fly.
*/
#define CLEAR_HASH(s) \
s->head[s->hash_size-1] = NIL; \
zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
do { \
s->head[s->hash_size-1] = NIL; \
zmemzero((Bytef *)s->head, \
(unsigned)(s->hash_size-1)*sizeof(*s->head)); \
} while (0)
/* ===========================================================================
* Slide the hash table when sliding the window down (could be avoided with 32
...
...
@@ -252,11 +255,6 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
int
wrap
=
1
;
static
const
char
my_version
[]
=
ZLIB_VERSION
;
ushf
*
overlay
;
/* We overlay pending_buf and d_buf+l_buf. This works since the average
* output size for (length,distance) codes is <= 24 bits.
*/
if
(
version
==
Z_NULL
||
version
[
0
]
!=
my_version
[
0
]
||
stream_size
!=
sizeof
(
z_stream
))
{
return
Z_VERSION_ERROR
;
...
...
@@ -320,16 +318,53 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
s
->
window
=
(
Bytef
*
)
ZALLOC
(
strm
,
s
->
w_size
,
2
*
sizeof
(
Byte
));
s
->
prev
=
(
Posf
*
)
ZALLOC
(
strm
,
s
->
w_size
,
sizeof
(
Pos
));
memset
(
s
->
prev
,
0
,
s
->
w_size
*
sizeof
(
Pos
));
s
->
head
=
(
Posf
*
)
ZALLOC
(
strm
,
s
->
hash_size
,
sizeof
(
Pos
));
s
->
high_water
=
0
;
/* nothing written to s->window yet */
s
->
lit_bufsize
=
1
<<
(
memLevel
+
6
);
/* 16K elements by default */
overlay
=
(
ushf
*
)
ZALLOC
(
strm
,
s
->
lit_bufsize
,
sizeof
(
ush
)
+
2
);
s
->
pending_buf
=
(
uchf
*
)
overlay
;
s
->
pending_buf_size
=
(
ulg
)
s
->
lit_bufsize
*
(
sizeof
(
ush
)
+
2L
);
/* We overlay pending_buf and sym_buf. This works since the average size
* for length/distance pairs over any compressed block is assured to be 31
* bits or less.
*
* Analysis: The longest fixed codes are a length code of 8 bits plus 5
* extra bits, for lengths 131 to 257. The longest fixed distance codes are
* 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest
* possible fixed-codes length/distance pair is then 31 bits total.
*
* sym_buf starts one-fourth of the way into pending_buf. So there are
* three bytes in sym_buf for every four bytes in pending_buf. Each symbol
* in sym_buf is three bytes -- two for the distance and one for the
* literal/length. As each symbol is consumed, the pointer to the next
* sym_buf value to read moves forward three bytes. From that symbol, up to
* 31 bits are written to pending_buf. The closest the written pending_buf
* bits gets to the next sym_buf symbol to read is just before the last
* code is written. At that time, 31*(n-2) bits have been written, just
* after 24*(n-2) bits have been consumed from sym_buf. sym_buf starts at
* 8*n bits into pending_buf. (Note that the symbol buffer fills when n-1
* symbols are written.) The closest the writing gets to what is unread is
* then n+14 bits. Here n is lit_bufsize, which is 16384 by default, and
* can range from 128 to 32768.
*
* Therefore, at a minimum, there are 142 bits of space between what is
* written and what is read in the overlain buffers, so the symbols cannot
* be overwritten by the compressed data. That space is actually 139 bits,
* due to the three-bit fixed-code block header.
*
* That covers the case where either Z_FIXED is specified, forcing fixed
* codes, or when the use of fixed codes is chosen, because that choice
* results in a smaller compressed block than dynamic codes. That latter
* condition then assures that the above analysis also covers all dynamic
* blocks. A dynamic-code block will only be chosen to be emitted if it has
* fewer bits than a fixed-code block would for the same set of symbols.
* Therefore its average symbol length is assured to be less than 31. So
* the compressed data for a dynamic block also cannot overwrite the
* symbols from which it is being constructed.
*/
s
->
pending_buf
=
(
uchf
*
)
ZALLOC
(
strm
,
s
->
lit_bufsize
,
4
);
s
->
pending_buf_size
=
(
ulg
)
s
->
lit_bufsize
*
4
;
if
(
s
->
window
==
Z_NULL
||
s
->
prev
==
Z_NULL
||
s
->
head
==
Z_NULL
||
s
->
pending_buf
==
Z_NULL
)
{
...
...
@@ -338,8 +373,12 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
deflateEnd
(
strm
);
return
Z_MEM_ERROR
;
}
s
->
d_buf
=
overlay
+
s
->
lit_bufsize
/
sizeof
(
ush
);
s
->
l_buf
=
s
->
pending_buf
+
(
1
+
sizeof
(
ush
))
*
s
->
lit_bufsize
;
s
->
sym_buf
=
s
->
pending_buf
+
s
->
lit_bufsize
;
s
->
sym_end
=
(
s
->
lit_bufsize
-
1
)
*
3
;
/* We avoid equality with lit_bufsize*3 because of wraparound at 64K
* on 16 bit machines and because stored blocks are restricted to
* 64K-1 bytes.
*/
s
->
level
=
level
;
s
->
strategy
=
strategy
;
...
...
@@ -489,13 +528,13 @@ int ZEXPORT deflateResetKeep (strm)
#ifdef GZIP
s
->
wrap
==
2
?
GZIP_STATE
:
#endif
s
->
wrap
?
INIT_STATE
:
BUSY
_STATE
;
INIT
_STATE
;
strm
->
adler
=
#ifdef GZIP
s
->
wrap
==
2
?
crc32
(
0L
,
Z_NULL
,
0
)
:
#endif
adler32
(
0L
,
Z_NULL
,
0
);
s
->
last_flush
=
Z_NO_FLUSH
;
s
->
last_flush
=
-
2
;
_tr_init
(
s
);
...
...
@@ -550,7 +589,8 @@ int ZEXPORT deflatePrime (strm, bits, value)
if
(
deflateStateCheck
(
strm
))
return
Z_STREAM_ERROR
;
s
=
strm
->
state
;
if
((
Bytef
*
)(
s
->
d_buf
)
<
s
->
pending_out
+
((
Buf_size
+
7
)
>>
3
))
if
(
bits
<
0
||
bits
>
16
||
s
->
sym_buf
<
s
->
pending_out
+
((
Buf_size
+
7
)
>>
3
))
return
Z_BUF_ERROR
;
do
{
put
=
Buf_size
-
s
->
bi_valid
;
...
...
@@ -588,12 +628,12 @@ int ZEXPORT deflateParams(strm, level, strategy)
func
=
configuration_table
[
s
->
level
].
func
;
if
((
strategy
!=
s
->
strategy
||
func
!=
configuration_table
[
level
].
func
)
&&
s
->
high_water
)
{
s
->
last_flush
!=
-
2
)
{
/* Flush the last buffer: */
int
err
=
deflate
(
strm
,
Z_BLOCK
);
if
(
err
==
Z_STREAM_ERROR
)
return
err
;
if
(
strm
->
avail_
out
==
0
)
if
(
strm
->
avail_
in
||
(
s
->
strstart
-
s
->
block_start
)
+
s
->
lookahead
)
return
Z_BUF_ERROR
;
}
if
(
s
->
level
!=
level
)
{
...
...
@@ -812,6 +852,8 @@ int ZEXPORT deflate (strm, flush)
}
/* Write the header */
if
(
s
->
status
==
INIT_STATE
&&
s
->
wrap
==
0
)
s
->
status
=
BUSY_STATE
;
if
(
s
->
status
==
INIT_STATE
)
{
/* zlib header */
uInt
header
=
(
Z_DEFLATED
+
((
s
->
w_bits
-
8
)
<<
4
))
<<
8
;
...
...
@@ -1109,7 +1151,6 @@ int ZEXPORT deflateCopy (dest, source)
#else
deflate_state
*
ds
;
deflate_state
*
ss
;
ushf
*
overlay
;
if
(
deflateStateCheck
(
source
)
||
dest
==
Z_NULL
)
{
...
...
@@ -1129,8 +1170,7 @@ int ZEXPORT deflateCopy (dest, source)
ds
->
window
=
(
Bytef
*
)
ZALLOC
(
dest
,
ds
->
w_size
,
2
*
sizeof
(
Byte
));
ds
->
prev
=
(
Posf
*
)
ZALLOC
(
dest
,
ds
->
w_size
,
sizeof
(
Pos
));
ds
->
head
=
(
Posf
*
)
ZALLOC
(
dest
,
ds
->
hash_size
,
sizeof
(
Pos
));
overlay
=
(
ushf
*
)
ZALLOC
(
dest
,
ds
->
lit_bufsize
,
sizeof
(
ush
)
+
2
);
ds
->
pending_buf
=
(
uchf
*
)
overlay
;
ds
->
pending_buf
=
(
uchf
*
)
ZALLOC
(
dest
,
ds
->
lit_bufsize
,
4
);
if
(
ds
->
window
==
Z_NULL
||
ds
->
prev
==
Z_NULL
||
ds
->
head
==
Z_NULL
||
ds
->
pending_buf
==
Z_NULL
)
{
...
...
@@ -1144,8 +1184,7 @@ int ZEXPORT deflateCopy (dest, source)
zmemcpy
(
ds
->
pending_buf
,
ss
->
pending_buf
,
(
uInt
)
ds
->
pending_buf_size
);
ds
->
pending_out
=
ds
->
pending_buf
+
(
ss
->
pending_out
-
ss
->
pending_buf
);
ds
->
d_buf
=
overlay
+
ds
->
lit_bufsize
/
sizeof
(
ush
);
ds
->
l_buf
=
ds
->
pending_buf
+
(
1
+
sizeof
(
ush
))
*
ds
->
lit_bufsize
;
ds
->
sym_buf
=
ds
->
pending_buf
+
ds
->
lit_bufsize
;
ds
->
l_desc
.
dyn_tree
=
ds
->
dyn_ltree
;
ds
->
d_desc
.
dyn_tree
=
ds
->
dyn_dtree
;
...
...
@@ -1514,6 +1553,8 @@ local void fill_window(s)
s
->
match_start
-=
wsize
;
s
->
strstart
-=
wsize
;
/* we now have strstart >= MAX_DIST */
s
->
block_start
-=
(
long
)
wsize
;
if
(
s
->
insert
>
s
->
strstart
)
s
->
insert
=
s
->
strstart
;
slide_hash
(
s
);
more
+=
wsize
;
}
...
...
@@ -1743,6 +1784,7 @@ local block_state deflate_stored(s, flush)
s
->
matches
=
2
;
/* clear hash */
zmemcpy
(
s
->
window
,
s
->
strm
->
next_in
-
s
->
w_size
,
s
->
w_size
);
s
->
strstart
=
s
->
w_size
;
s
->
insert
=
s
->
strstart
;
}
else
{
if
(
s
->
window_size
-
s
->
strstart
<=
used
)
{
...
...
@@ -1751,12 +1793,14 @@ local block_state deflate_stored(s, flush)
zmemcpy
(
s
->
window
,
s
->
window
+
s
->
w_size
,
s
->
strstart
);
if
(
s
->
matches
<
2
)
s
->
matches
++
;
/* add a pending slide_hash() */
if
(
s
->
insert
>
s
->
strstart
)
s
->
insert
=
s
->
strstart
;
}
zmemcpy
(
s
->
window
+
s
->
strstart
,
s
->
strm
->
next_in
-
used
,
used
);
s
->
strstart
+=
used
;
s
->
insert
+=
MIN
(
used
,
s
->
w_size
-
s
->
insert
);
}
s
->
block_start
=
s
->
strstart
;
s
->
insert
+=
MIN
(
used
,
s
->
w_size
-
s
->
insert
);
}
if
(
s
->
high_water
<
s
->
strstart
)
s
->
high_water
=
s
->
strstart
;
...
...
@@ -1771,7 +1815,7 @@ local block_state deflate_stored(s, flush)
return
block_done
;
/* Fill the window with any remaining input. */
have
=
s
->
window_size
-
s
->
strstart
-
1
;
have
=
s
->
window_size
-
s
->
strstart
;
if
(
s
->
strm
->
avail_in
>
have
&&
s
->
block_start
>=
(
long
)
s
->
w_size
)
{
/* Slide the window down. */
s
->
block_start
-=
s
->
w_size
;
...
...
@@ -1780,12 +1824,15 @@ local block_state deflate_stored(s, flush)
if
(
s
->
matches
<
2
)
s
->
matches
++
;
/* add a pending slide_hash() */
have
+=
s
->
w_size
;
/* more space now */
if
(
s
->
insert
>
s
->
strstart
)
s
->
insert
=
s
->
strstart
;
}
if
(
have
>
s
->
strm
->
avail_in
)
have
=
s
->
strm
->
avail_in
;
if
(
have
)
{
read_buf
(
s
->
strm
,
s
->
window
+
s
->
strstart
,
have
);
s
->
strstart
+=
have
;
s
->
insert
+=
MIN
(
have
,
s
->
w_size
-
s
->
insert
);
}
if
(
s
->
high_water
<
s
->
strstart
)
s
->
high_water
=
s
->
strstart
;
...
...
@@ -1913,7 +1960,7 @@ local block_state deflate_fast(s, flush)
FLUSH_BLOCK
(
s
,
1
);
return
finish_done
;
}
if
(
s
->
last_li
t
)
if
(
s
->
sym_nex
t
)
FLUSH_BLOCK
(
s
,
0
);
return
block_done
;
}
...
...
@@ -2044,7 +2091,7 @@ local block_state deflate_slow(s, flush)
FLUSH_BLOCK
(
s
,
1
);
return
finish_done
;
}
if
(
s
->
last_li
t
)
if
(
s
->
sym_nex
t
)
FLUSH_BLOCK
(
s
,
0
);
return
block_done
;
}
...
...
@@ -2119,7 +2166,7 @@ local block_state deflate_rle(s, flush)
FLUSH_BLOCK
(
s
,
1
);
return
finish_done
;
}
if
(
s
->
last_li
t
)
if
(
s
->
sym_nex
t
)
FLUSH_BLOCK
(
s
,
0
);
return
block_done
;
}
...
...
@@ -2158,7 +2205,7 @@ local block_state deflate_huff(s, flush)
FLUSH_BLOCK
(
s
,
1
);
return
finish_done
;
}
if
(
s
->
last_li
t
)
if
(
s
->
sym_nex
t
)
FLUSH_BLOCK
(
s
,
0
);
return
block_done
;
}
deps/zlib/deflate.h
View file @
f0cf45d3
/* deflate.h -- internal compression state
* Copyright (C) 1995-201
6
Jean-loup Gailly
* Copyright (C) 1995-201
8
Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
*/
...
...
@@ -217,7 +217,7 @@ typedef struct internal_state {
/* Depth of each subtree used as tie breaker for trees of equal frequency
*/
uchf
*
l_buf
;
/* buffer for literals or
lengths */
uchf
*
sym_buf
;
/* buffer for distances and literals/
lengths */
uInt
lit_bufsize
;
/* Size of match buffer for literals/lengths. There are 4 reasons for
...
...
@@ -239,13 +239,8 @@ typedef struct internal_state {
* - I can't count above 4
*/
uInt
last_lit
;
/* running index in l_buf */
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.
*/
uInt
sym_next
;
/* running index in sym_buf */
uInt
sym_end
;
/* symbol table full when sym_next reaches this */
ulg
opt_len
;
/* bit length of current block with optimal trees */
ulg
static_len
;
/* bit length of current block with static trees */
...
...
@@ -325,20 +320,22 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
# define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \
s->d_buf[s->last_lit] = 0; \
s->l_buf[s->last_lit++] = cc; \
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->
last_lit == s->lit_bufsize-1
); \
flush = (s->
sym_next == s->sym_end
); \
}
# define _tr_tally_dist(s, distance, length, flush) \
{ uch len = (uch)(length); \
ush dist = (ush)(distance); \
s->d_buf[s->last_lit] = dist; \
s->l_buf[s->last_lit++] = len; \
s->sym_buf[s->sym_next++] = dist; \
s->sym_buf[s->sym_next++] = 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->
last_lit == s->lit_bufsize-1
); \
flush = (s->
sym_next == s->sym_end
); \
}
#else
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
...
...
deps/zlib/gzguts.h
View file @
f0cf45d3
/* gzguts.h -- zlib internal header definitions for gz* operations
* Copyright (C) 2004
, 2005, 2010, 2011, 2012, 2013, 2016
Mark Adler
* Copyright (C) 2004
-2019
Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
...
...
@@ -39,7 +39,7 @@
# include <io.h>
#endif
#if defined(_WIN32)
|| defined(__CYGWIN__)
#if defined(_WIN32)
# define WIDECHAR
#endif
...
...
@@ -190,6 +190,7 @@ typedef struct {
/* just for writing */
int
level
;
/* compression level */
int
strategy
;
/* compression strategy */
int
reset
;
/* true if a reset is pending after a Z_FINISH */
/* seek request */
z_off64_t
skip
;
/* amount to skip (already rewound if backwards) */
int
seek
;
/* true if seek request pending */
...
...
deps/zlib/infback.c
View file @
f0cf45d3
/* infback.c -- inflate using a call-back interface
* Copyright (C) 1995-20
16
Mark Adler
* Copyright (C) 1995-20
22
Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
...
...
@@ -477,6 +477,7 @@ void FAR *out_desc;
}
Tracev
((
stderr
,
"inflate: codes ok
\n
"
));
state
->
mode
=
LEN
;
/* fallthrough */
case
LEN
:
/* use inflate_fast() if we have enough input and output */
...
...
deps/zlib/inffast.c
View file @
f0cf45d3
...
...
@@ -70,7 +70,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
code
const
FAR
*
dcode
;
/* local strm->distcode */
unsigned
lmask
;
/* mask for first level of length 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 */
/* window position, window bytes to copy */
unsigned
len
;
/* match length, unused bytes */
...
...
@@ -107,20 +107,20 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
hold
+=
(
unsigned
long
)(
*
in
++
)
<<
bits
;
bits
+=
8
;
}
here
=
lcode
[
hold
&
lmask
]
;
here
=
lcode
+
(
hold
&
lmask
)
;
dolen
:
op
=
(
unsigned
)(
here
.
bits
);
op
=
(
unsigned
)(
here
->
bits
);
hold
>>=
op
;
bits
-=
op
;
op
=
(
unsigned
)(
here
.
op
);
op
=
(
unsigned
)(
here
->
op
);
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 0x%02x
\n
"
,
here
.
val
));
*
out
++
=
(
unsigned
char
)(
here
.
val
);
"inflate: literal 0x%02x
\n
"
,
here
->
val
));
*
out
++
=
(
unsigned
char
)(
here
->
val
);
}
else
if
(
op
&
16
)
{
/* length base */
len
=
(
unsigned
)(
here
.
val
);
len
=
(
unsigned
)(
here
->
val
);
op
&=
15
;
/* number of extra bits */
if
(
op
)
{
if
(
bits
<
op
)
{
...
...
@@ -138,14 +138,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
hold
+=
(
unsigned
long
)(
*
in
++
)
<<
bits
;
bits
+=
8
;
}
here
=
dcode
[
hold
&
dmask
]
;
here
=
dcode
+
(
hold
&
dmask
)
;
dodist
:
op
=
(
unsigned
)(
here
.
bits
);
op
=
(
unsigned
)(
here
->
bits
);
hold
>>=
op
;
bits
-=
op
;
op
=
(
unsigned
)(
here
.
op
);
op
=
(
unsigned
)(
here
->
op
);
if
(
op
&
16
)
{
/* distance base */
dist
=
(
unsigned
)(
here
.
val
);
dist
=
(
unsigned
)(
here
->
val
);
op
&=
15
;
/* number of extra bits */
if
(
bits
<
op
)
{
hold
+=
(
unsigned
long
)(
*
in
++
)
<<
bits
;
...
...
@@ -264,7 +264,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
}
}
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
;
}
else
{
...
...
@@ -274,7 +274,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
}
}
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
;
}
else
if
(
op
&
32
)
{
/* end-of-block */
...
...
deps/zlib/inflate.c
View file @
f0cf45d3
/* inflate.c -- zlib decompression
* Copyright (C) 1995-20
16
Mark Adler
* Copyright (C) 1995-20
22
Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
...
...
@@ -130,6 +130,7 @@ z_streamp strm;
state
->
mode
=
HEAD
;
state
->
last
=
0
;
state
->
havedict
=
0
;
state
->
flags
=
-
1
;
state
->
dmax
=
32768U
;
state
->
head
=
Z_NULL
;
state
->
hold
=
0
;
...
...
@@ -447,10 +448,10 @@ unsigned copy;
/* check function to use adler32() for zlib or crc32() for gzip */
#ifdef GUNZIP
# define UPDATE(check, buf, len) \
# define UPDATE
_CHECK
(check, buf, len) \
(state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
#else
# define UPDATE(check, buf, len) adler32(check, buf, len)
# define UPDATE
_CHECK
(check, buf, len) adler32(check, buf, len)
#endif
/* check macros for header crc */
...
...
@@ -670,7 +671,6 @@ int flush;
state
->
mode
=
FLAGS
;
break
;
}
state
->
flags
=
0
;
/* expect zlib header */
if
(
state
->
head
!=
Z_NULL
)
state
->
head
->
done
=
-
1
;
if
(
!
(
state
->
wrap
&
1
)
||
/* check if zlib header allowed */
...
...
@@ -697,6 +697,7 @@ int flush;
break
;
}
state
->
dmax
=
1U
<<
len
;
state
->
flags
=
0
;
/* indicate zlib header */
Tracev
((
stderr
,
"inflate: zlib header ok
\n
"
));
strm
->
adler
=
state
->
check
=
adler32
(
0L
,
Z_NULL
,
0
);
state
->
mode
=
hold
&
0x200
?
DICTID
:
TYPE
;
...
...
@@ -722,6 +723,7 @@ int flush;
CRC2
(
state
->
check
,
hold
);
INITBITS
();
state
->
mode
=
TIME
;
/* fallthrough */
case
TIME
:
NEEDBITS
(
32
);
if
(
state
->
head
!=
Z_NULL
)
...
...
@@ -730,6 +732,7 @@ int flush;
CRC4
(
state
->
check
,
hold
);
INITBITS
();
state
->
mode
=
OS
;
/* fallthrough */
case
OS
:
NEEDBITS
(
16
);
if
(
state
->
head
!=
Z_NULL
)
{
...
...
@@ -740,6 +743,7 @@ int flush;
CRC2
(
state
->
check
,
hold
);
INITBITS
();
state
->
mode
=
EXLEN
;
/* fallthrough */
case
EXLEN
:
if
(
state
->
flags
&
0x0400
)
{
NEEDBITS
(
16
);
...
...
@@ -753,6 +757,7 @@ int flush;
else
if
(
state
->
head
!=
Z_NULL
)
state
->
head
->
extra
=
Z_NULL
;
state
->
mode
=
EXTRA
;
/* fallthrough */
case
EXTRA
:
if
(
state
->
flags
&
0x0400
)
{
copy
=
state
->
length
;
...
...
@@ -775,6 +780,7 @@ int flush;
}
state
->
length
=
0
;
state
->
mode
=
NAME
;
/* fallthrough */
case
NAME
:
if
(
state
->
flags
&
0x0800
)
{
if
(
have
==
0
)
goto
inf_leave
;
...
...
@@ -796,6 +802,7 @@ int flush;
state
->
head
->
name
=
Z_NULL
;
state
->
length
=
0
;
state
->
mode
=
COMMENT
;
/* fallthrough */
case
COMMENT
:
if
(
state
->
flags
&
0x1000
)
{
if
(
have
==
0
)
goto
inf_leave
;
...
...
@@ -816,6 +823,7 @@ int flush;
else
if
(
state
->
head
!=
Z_NULL
)
state
->
head
->
comment
=
Z_NULL
;
state
->
mode
=
HCRC
;
/* fallthrough */
case
HCRC
:
if
(
state
->
flags
&
0x0200
)
{
NEEDBITS
(
16
);
...
...
@@ -839,6 +847,7 @@ int flush;
strm
->
adler
=
state
->
check
=
ZSWAP32
(
hold
);
INITBITS
();
state
->
mode
=
DICT
;
/* fallthrough */
case
DICT
:
if
(
state
->
havedict
==
0
)
{
RESTORE
();
...
...
@@ -846,8 +855,10 @@ int flush;
}
strm
->
adler
=
state
->
check
=
adler32
(
0L
,
Z_NULL
,
0
);
state
->
mode
=
TYPE
;
/* fallthrough */
case
TYPE
:
if
(
flush
==
Z_BLOCK
||
flush
==
Z_TREES
)
goto
inf_leave
;
/* fallthrough */
case
TYPEDO
:
if
(
state
->
last
)
{
BYTEBITS
();
...
...
@@ -898,8 +909,10 @@ int flush;
INITBITS
();
state
->
mode
=
COPY_
;
if
(
flush
==
Z_TREES
)
goto
inf_leave
;
/* fallthrough */
case
COPY_
:
state
->
mode
=
COPY
;
/* fallthrough */
case
COPY
:
copy
=
state
->
length
;
if
(
copy
)
{
...
...
@@ -935,6 +948,7 @@ int flush;
Tracev
((
stderr
,
"inflate: table sizes ok
\n
"
));
state
->
have
=
0
;
state
->
mode
=
LENLENS
;
/* fallthrough */
case
LENLENS
:
while
(
state
->
have
<
state
->
ncode
)
{
NEEDBITS
(
3
);
...
...
@@ -956,6 +970,7 @@ int flush;
Tracev
((
stderr
,
"inflate: code lengths ok
\n
"
));
state
->
have
=
0
;
state
->
mode
=
CODELENS
;
/* fallthrough */
case
CODELENS
:
while
(
state
->
have
<
state
->
nlen
+
state
->
ndist
)
{
for
(;;)
{
...
...
@@ -1039,8 +1054,10 @@ int flush;
Tracev
((
stderr
,
"inflate: codes ok
\n
"
));
state
->
mode
=
LEN_
;
if
(
flush
==
Z_TREES
)
goto
inf_leave
;
/* fallthrough */
case
LEN_
:
state
->
mode
=
LEN
;
/* fallthrough */
case
LEN
:
if
(
have
>=
6
&&
left
>=
258
)
{
RESTORE
();
...
...
@@ -1090,6 +1107,7 @@ int flush;
}
state
->
extra
=
(
unsigned
)(
here
.
op
)
&
15
;
state
->
mode
=
LENEXT
;
/* fallthrough */
case
LENEXT
:
if
(
state
->
extra
)
{
NEEDBITS
(
state
->
extra
);
...
...
@@ -1100,6 +1118,7 @@ int flush;
Tracevv
((
stderr
,
"inflate: length %u
\n
"
,
state
->
length
));
state
->
was
=
state
->
length
;
state
->
mode
=
DIST
;
/* fallthrough */
case
DIST
:
for
(;;)
{
here
=
state
->
distcode
[
BITS
(
state
->
distbits
)];
...
...
@@ -1127,6 +1146,7 @@ int flush;
state
->
offset
=
(
unsigned
)
here
.
val
;
state
->
extra
=
(
unsigned
)(
here
.
op
)
&
15
;
state
->
mode
=
DISTEXT
;
/* fallthrough */
case
DISTEXT
:
if
(
state
->
extra
)
{
NEEDBITS
(
state
->
extra
);
...
...
@@ -1143,6 +1163,7 @@ int flush;
#endif
Tracevv
((
stderr
,
"inflate: distance %u
\n
"
,
state
->
offset
));
state
->
mode
=
MATCH
;
/* fallthrough */
case
MATCH
:
if
(
left
==
0
)
goto
inf_leave
;
copy
=
out
-
left
;
...
...
@@ -1202,7 +1223,7 @@ int flush;
state
->
total
+=
out
;
if
((
state
->
wrap
&
4
)
&&
out
)
strm
->
adler
=
state
->
check
=
UPDATE
(
state
->
check
,
put
-
out
,
out
);
UPDATE
_CHECK
(
state
->
check
,
put
-
out
,
out
);
out
=
left
;
if
((
state
->
wrap
&
4
)
&&
(
#ifdef GUNZIP
...
...
@@ -1218,10 +1239,11 @@ int flush;
}
#ifdef GUNZIP
state
->
mode
=
LENGTH
;
/* fallthrough */
case
LENGTH
:
if
(
state
->
wrap
&&
state
->
flags
)
{
NEEDBITS
(
32
);
if
(
hold
!=
(
state
->
total
&
0xffffffffUL
))
{
if
(
(
state
->
wrap
&
4
)
&&
hold
!=
(
state
->
total
&
0xffffffff
))
{
strm
->
msg
=
(
char
*
)
"incorrect length check"
;
state
->
mode
=
BAD
;
break
;
...
...
@@ -1231,6 +1253,7 @@ int flush;
}
#endif
state
->
mode
=
DONE
;
/* fallthrough */
case
DONE
:
ret
=
Z_STREAM_END
;
goto
inf_leave
;
...
...
@@ -1240,6 +1263,7 @@ int flush;
case
MEM
:
return
Z_MEM_ERROR
;
case
SYNC
:
/* fallthrough */
default
:
return
Z_STREAM_ERROR
;
}
...
...
@@ -1265,7 +1289,7 @@ int flush;
state
->
total
+=
out
;
if
((
state
->
wrap
&
4
)
&&
out
)
strm
->
adler
=
state
->
check
=
UPDATE
(
state
->
check
,
strm
->
next_out
-
out
,
out
);
UPDATE
_CHECK
(
state
->
check
,
strm
->
next_out
-
out
,
out
);
strm
->
data_type
=
(
int
)
state
->
bits
+
(
state
->
last
?
64
:
0
)
+
(
state
->
mode
==
TYPE
?
128
:
0
)
+
(
state
->
mode
==
LEN_
||
state
->
mode
==
COPY_
?
256
:
0
);
...
...
@@ -1401,6 +1425,7 @@ int ZEXPORT inflateSync(strm)
z_streamp
strm
;
{
unsigned
len
;
/* number of bytes to look at or looked at */
int
flags
;
/* temporary to save header status */
unsigned
long
in
,
out
;
/* temporary to save total_in and total_out */
unsigned
char
buf
[
4
];
/* to restore bit buffer to byte string */
struct
inflate_state
FAR
*
state
;
...
...
@@ -1433,9 +1458,15 @@ z_streamp strm;
/* return no joy or set up to restart inflate() on a new block */
if
(
state
->
have
!=
4
)
return
Z_DATA_ERROR
;
if
(
state
->
flags
==
-
1
)
state
->
wrap
=
0
;
/* if no header yet, treat as raw */
else
state
->
wrap
&=
~
4
;
/* no point in computing a check value now */
flags
=
state
->
flags
;
in
=
strm
->
total_in
;
out
=
strm
->
total_out
;
inflateReset
(
strm
);
strm
->
total_in
=
in
;
strm
->
total_out
=
out
;
state
->
flags
=
flags
;
state
->
mode
=
TYPE
;
return
Z_OK
;
}
...
...
@@ -1531,7 +1562,7 @@ int check;
if
(
inflateStateCheck
(
strm
))
return
Z_STREAM_ERROR
;
state
=
(
struct
inflate_state
FAR
*
)
strm
->
state
;
if
(
check
)
if
(
check
&&
state
->
wrap
)
state
->
wrap
|=
4
;
else
state
->
wrap
&=
~
4
;
...
...
deps/zlib/inflate.h
View file @
f0cf45d3
/* inflate.h -- internal inflate state definition
* Copyright (C) 1995-201
6
Mark Adler
* Copyright (C) 1995-201
9
Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
...
...
@@ -86,7 +86,8 @@ struct inflate_state {
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
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
long
check
;
/* protected copy of check value */
unsigned
long
total
;
/* protected copy of output count */
...
...
deps/zlib/inftrees.c
View file @
f0cf45d3
/* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-20
17
Mark Adler
* Copyright (C) 1995-20
22
Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
...
...
@@ -9,7 +9,7 @@
#define MAXBITS 15
const
char
inflate_copyright
[]
=
" inflate 1.2.1
1 Copyright 1995-2017
Mark Adler "
;
" inflate 1.2.1
2 Copyright 1995-2022
Mark Adler "
;
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
...
...
@@ -62,7 +62,7 @@ unsigned short FAR *work;
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 */
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
,
77
,
202
};
19
,
19
,
19
,
19
,
20
,
20
,
20
,
20
,
21
,
21
,
21
,
21
,
16
,
199
,
202
};
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
,
257
,
385
,
513
,
769
,
1025
,
1537
,
2049
,
3073
,
4097
,
6145
,
...
...
deps/zlib/trees.c
View file @
f0cf45d3
/* trees.c -- output deflated data using Huffman coding
* Copyright (C) 1995-20
17
Jean-loup Gailly
* Copyright (C) 1995-20
21
Jean-loup Gailly
* detect_data_type() function provided freely by Cosmin Truta, 2006
* For conditions of distribution and use, see copyright notice in zlib.h
*/
...
...
@@ -149,7 +149,7 @@ local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
local
void
compress_block
OF
((
deflate_state
*
s
,
const
ct_data
*
ltree
,
const
ct_data
*
dtree
));
local
int
detect_data_type
OF
((
deflate_state
*
s
));
local
unsigned
bi_reverse
OF
((
unsigned
value
,
int
length
));
local
unsigned
bi_reverse
OF
((
unsigned
code
,
int
len
));
local
void
bi_windup
OF
((
deflate_state
*
s
));
local
void
bi_flush
OF
((
deflate_state
*
s
));
...
...
@@ -416,7 +416,7 @@ local void init_block(s)
s
->
dyn_ltree
[
END_BLOCK
].
Freq
=
1
;
s
->
opt_len
=
s
->
static_len
=
0L
;
s
->
last_li
t
=
s
->
matches
=
0
;
s
->
sym_nex
t
=
s
->
matches
=
0
;
}
#define SMALLEST 1
...
...
@@ -870,7 +870,8 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
bi_windup
(
s
);
/* align on byte boundary */
put_short
(
s
,
(
ush
)
stored_len
);
put_short
(
s
,
(
ush
)
~
stored_len
);
zmemcpy
(
s
->
pending_buf
+
s
->
pending
,
(
Bytef
*
)
buf
,
stored_len
);
if
(
stored_len
)
zmemcpy
(
s
->
pending_buf
+
s
->
pending
,
(
Bytef
*
)
buf
,
stored_len
);
s
->
pending
+=
stored_len
;
#ifdef ZLIB_DEBUG
s
->
compressed_len
=
(
s
->
compressed_len
+
3
+
7
)
&
(
ulg
)
~
7L
;
...
...
@@ -947,7 +948,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
Tracev
((
stderr
,
"
\n
opt %lu(%lu) stat %lu(%lu) stored %lu lit %u "
,
opt_lenb
,
s
->
opt_len
,
static_lenb
,
s
->
static_len
,
stored_len
,
s
->
last_lit
));
s
->
sym_next
/
3
));
if
(
static_lenb
<=
opt_lenb
)
opt_lenb
=
static_lenb
;
...
...
@@ -1016,8 +1017,9 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
unsigned
dist
;
/* distance of matched string */
unsigned
lc
;
/* match length-MIN_MATCH or unmatched char (if dist==0) */
{
s
->
d_buf
[
s
->
last_lit
]
=
(
ush
)
dist
;
s
->
l_buf
[
s
->
last_lit
++
]
=
(
uch
)
lc
;
s
->
sym_buf
[
s
->
sym_next
++
]
=
dist
;
s
->
sym_buf
[
s
->
sym_next
++
]
=
dist
>>
8
;
s
->
sym_buf
[
s
->
sym_next
++
]
=
lc
;
if
(
dist
==
0
)
{
/* lc is the unmatched char */
s
->
dyn_ltree
[
lc
].
Freq
++
;
...
...
@@ -1032,30 +1034,7 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
s
->
dyn_ltree
[
_length_code
[
lc
]
+
LITERALS
+
1
].
Freq
++
;
s
->
dyn_dtree
[
d_code
(
dist
)].
Freq
++
;
}
#ifdef TRUNCATE_BLOCK
/* Try to guess if it is profitable to stop the current block here */
if
((
s
->
last_lit
&
0x1fff
)
==
0
&&
s
->
level
>
2
)
{
/* Compute an upper bound for the compressed length */
ulg
out_length
=
(
ulg
)
s
->
last_lit
*
8L
;
ulg
in_length
=
(
ulg
)((
long
)
s
->
strstart
-
s
->
block_start
);
int
dcode
;
for
(
dcode
=
0
;
dcode
<
D_CODES
;
dcode
++
)
{
out_length
+=
(
ulg
)
s
->
dyn_dtree
[
dcode
].
Freq
*
(
5L
+
extra_dbits
[
dcode
]);
}
out_length
>>=
3
;
Tracev
((
stderr
,
"
\n
last_lit %u, in %ld, out ~%ld(%ld%%) "
,
s
->
last_lit
,
in_length
,
out_length
,
100L
-
out_length
*
100L
/
in_length
));
if
(
s
->
matches
<
s
->
last_lit
/
2
&&
out_length
<
in_length
/
2
)
return
1
;
}
#endif
return
(
s
->
last_lit
==
s
->
lit_bufsize
-
1
);
/* We avoid equality with lit_bufsize because of wraparound at 64K
* on 16 bit machines and because stored blocks are restricted to
* 64K-1 bytes.
*/
return
(
s
->
sym_next
==
s
->
sym_end
);
}
/* ===========================================================================
...
...
@@ -1068,13 +1047,14 @@ local void compress_block(s, ltree, dtree)
{
unsigned
dist
;
/* distance of matched string */
int
lc
;
/* match length or unmatched char (if dist == 0) */
unsigned
lx
=
0
;
/* running index in l
_buf */
unsigned
sx
=
0
;
/* running index in sym
_buf */
unsigned
code
;
/* the code to send */
int
extra
;
/* number of extra bits to send */
if
(
s
->
last_lit
!=
0
)
do
{
dist
=
s
->
d_buf
[
lx
];
lc
=
s
->
l_buf
[
lx
++
];
if
(
s
->
sym_next
!=
0
)
do
{
dist
=
s
->
sym_buf
[
sx
++
]
&
0xff
;
dist
+=
(
unsigned
)(
s
->
sym_buf
[
sx
++
]
&
0xff
)
<<
8
;
lc
=
s
->
sym_buf
[
sx
++
];
if
(
dist
==
0
)
{
send_code
(
s
,
lc
,
ltree
);
/* send a literal byte */
Tracecv
(
isgraph
(
lc
),
(
stderr
,
" '%c' "
,
lc
));
...
...
@@ -1099,11 +1079,10 @@ local void compress_block(s, ltree, dtree)
}
}
/* literal or match pair ? */
/* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
Assert
((
uInt
)(
s
->
pending
)
<
s
->
lit_bufsize
+
2
*
lx
,
"pendingBuf overflow"
);
/* Check that the overlay between pending_buf and sym_buf is ok: */
Assert
(
s
->
pending
<
s
->
lit_bufsize
+
sx
,
"pendingBuf overflow"
);
}
while
(
lx
<
s
->
last_li
t
);
}
while
(
sx
<
s
->
sym_nex
t
);
send_code
(
s
,
END_BLOCK
,
ltree
);
}
...
...
@@ -1112,9 +1091,9 @@ local void compress_block(s, ltree, dtree)
* Check if the data type is TEXT or BINARY, using the following algorithm:
* - TEXT if the two conditions below are satisfied:
* a) There are no non-portable control characters belonging to the
* "bl
a
ck list" (0..6, 14..25, 28..31).
* "bl
o
ck list" (0..6, 14..25, 28..31).
* b) There is at least one printable character belonging to the
* "
white
list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
* "
allow
list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
* - BINARY otherwise.
* - The following partially-portable control characters form a
* "gray list" that is ignored in this detection algorithm:
...
...
@@ -1124,19 +1103,19 @@ local void compress_block(s, ltree, dtree)
local
int
detect_data_type
(
s
)
deflate_state
*
s
;
{
/* bl
ack_mask is the bit mask of bla
ck-listed bytes
/* bl
ock_mask is the bit mask of blo
ck-listed bytes
* set bits 0..6, 14..25, and 28..31
* 0xf3ffc07f = binary 11110011111111111100000001111111
*/
unsigned
long
bl
a
ck_mask
=
0xf3ffc07fUL
;
unsigned
long
bl
o
ck_mask
=
0xf3ffc07fUL
;
int
n
;
/* Check for non-textual ("bl
a
ck-listed") bytes. */
for
(
n
=
0
;
n
<=
31
;
n
++
,
bl
a
ck_mask
>>=
1
)
if
((
bl
a
ck_mask
&
1
)
&&
(
s
->
dyn_ltree
[
n
].
Freq
!=
0
))
/* Check for non-textual ("bl
o
ck-listed") bytes. */
for
(
n
=
0
;
n
<=
31
;
n
++
,
bl
o
ck_mask
>>=
1
)
if
((
bl
o
ck_mask
&
1
)
&&
(
s
->
dyn_ltree
[
n
].
Freq
!=
0
))
return
Z_BINARY
;
/* Check for textual ("
white
-listed") bytes. */
/* Check for textual ("
allow
-listed") bytes. */
if
(
s
->
dyn_ltree
[
9
].
Freq
!=
0
||
s
->
dyn_ltree
[
10
].
Freq
!=
0
||
s
->
dyn_ltree
[
13
].
Freq
!=
0
)
return
Z_TEXT
;
...
...
@@ -1144,7 +1123,7 @@ local int detect_data_type(s)
if
(
s
->
dyn_ltree
[
n
].
Freq
!=
0
)
return
Z_TEXT
;
/* There are no "bl
ack-listed" or "white
-listed" bytes:
/* There are no "bl
ock-listed" or "allow
-listed" bytes:
* this stream either is empty or has tolerated ("gray-listed") bytes only.
*/
return
Z_BINARY
;
...
...
deps/zlib/zlib.h
View file @
f0cf45d3
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.2.1
1, January 15th, 2017
version 1.2.1
2, March 11th, 2022
Copyright (C) 1995-20
17
Jean-loup Gailly and Mark Adler
Copyright (C) 1995-20
22
Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
...
...
@@ -37,11 +37,11 @@
extern
"C"
{
#endif
#define ZLIB_VERSION "1.2.1
1
"
#define ZLIB_VERNUM 0x12
b
0
#define ZLIB_VERSION "1.2.1
2
"
#define ZLIB_VERNUM 0x12
c
0
#define ZLIB_VER_MAJOR 1
#define ZLIB_VER_MINOR 2
#define ZLIB_VER_REVISION 1
1
#define ZLIB_VER_REVISION 1
2
#define ZLIB_VER_SUBREVISION 0
/*
...
...
@@ -543,8 +543,7 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
int strategy));
This is another version of deflateInit with more compression options. The
fields next_in, zalloc, zfree and opaque must be initialized before by the
caller.
fields zalloc, zfree and opaque must be initialized before by the caller.
The method parameter is the compression method. It must be Z_DEFLATED in
this version of the library.
...
...
@@ -712,11 +711,12 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
used to switch between compression and straight copy of the input data, or
to switch to a different kind of input data requiring a different strategy.
If the compression approach (which is a function of the level) or the
strategy is changed, and if any input has been consumed in a previous
deflate() call, then the input available so far is compressed with the old
level and strategy using deflate(strm, Z_BLOCK). There are three approaches
for the compression levels 0, 1..3, and 4..9 respectively. The new level
and strategy will take effect at the next call of deflate().
strategy is changed, and if there have been any deflate() calls since the
state was initialized or reset, then the input available so far is
compressed with the old level and strategy using deflate(strm, Z_BLOCK).
There are three approaches for the compression levels 0, 1..3, and 4..9
respectively. The new level and strategy will take effect at the next call
of deflate().
If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
not have enough output space to complete, then the parameter change will not
...
...
@@ -865,9 +865,11 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
detection, or add 16 to decode only the gzip format (the zlib format will
return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see
below), inflate() will not automatically decode concatenated gzip streams.
inflate() will return Z_STREAM_END at the end of the gzip stream. The state
would need to be reset to continue decoding a subsequent gzip stream.
below), inflate() will *not* automatically decode concatenated gzip members.
inflate() will return Z_STREAM_END at the end of the gzip member. The state
would need to be reset to continue decoding a subsequent gzip member. This
*must* be done if there is more data after a gzip member, in order for the
decompression to be compliant with the gzip standard (RFC 1952).
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
...
...
@@ -1302,14 +1304,14 @@ typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
/*
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
Open
s a gzip (.gz) file for reading or writing. The mode parameter is as
in fopen ("rb" or "wb") but can also include a compression level ("wb9") or
a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
for fixed code compression as in "wb9F". (See the description of
deflateInit2 for more information about the strategy parameter.) 'T' will
request transparent writing or appending with no compression and not using
the gzip format.
Open
the gzip (.gz) file at path for reading and decompressing, or
compressing and writing. The mode parameter is as in fopen ("rb" or "wb")
but can also include a compression level ("wb9") or a strategy: 'f' for
filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h",
'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression
as in "wb9F". (See the description of deflateInit2 for more information
about the strategy parameter.) 'T' will request transparent writing or
appending with no compression and not using
the gzip format.
"a" can be used instead of "w" to request that the gzip stream that will
be written be appended to the file. "+" will result in an error, since
...
...
@@ -1339,9 +1341,9 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
ZEXTERN
gzFile
ZEXPORT
gzdopen
OF
((
int
fd
,
const
char
*
mode
));
/*
gzdopen associates a gzFile with the file descriptor fd. File descriptors
are obtained from calls like open, dup, creat, pipe or fileno (if the file
has
been previously opened with fopen). The mode parameter is as in gzopen.
Associate a gzFile with the file descriptor fd. File descriptors are
obtained from calls like open, dup, creat, pipe or fileno (if the file has
been previously opened with fopen). The mode parameter is as in gzopen.
The next call of gzclose on the returned gzFile will also close the file
descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
...
...
@@ -1362,13 +1364,13 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
ZEXTERN
int
ZEXPORT
gzbuffer
OF
((
gzFile
file
,
unsigned
size
));
/*
Set the internal buffer size used by this library's functions
. The
default buffer size is 8192 bytes. This function must be called after
gzopen() or gzdopen(), and before any other calls that read or write th
e
file. The buffer memory allocation is always deferred to the first read or
write. Three times that size in buffer space is allocated. A larger buff
er
size of, for example, 64K or 128K bytes will noticeably increase the speed
of decompression (reading).
Set the internal buffer size used by this library's functions
for file to
size. The default buffer size is 8192 bytes. This function must be called
after gzopen() or gzdopen(), and before any other calls that read or writ
e
the file. The buffer memory allocation is always deferred to the first read
or write. Three times that size in buffer space is allocated. A larg
er
buffer size of, for example, 64K or 128K bytes will noticeably increase the
speed
of decompression (reading).
The new buffer size also affects the maximum length for gzprintf().
...
...
@@ -1378,9 +1380,9 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
ZEXTERN
int
ZEXPORT
gzsetparams
OF
((
gzFile
file
,
int
level
,
int
strategy
));
/*
Dynamically update the compression level
or strategy. See the description
of deflateInit2 for the meaning of these parameters. Previously provided
data is flushed before the parameter change
.
Dynamically update the compression level
and strategy for file. See the
description of deflateInit2 for the meaning of these parameters. Previously
provided data is flushed before applying the parameter changes
.
gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not
opened for writing, Z_ERRNO if there is an error writing the flushed data,
...
...
@@ -1389,7 +1391,7 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
ZEXTERN
int
ZEXPORT
gzread
OF
((
gzFile
file
,
voidp
buf
,
unsigned
len
));
/*
Read
s the given number of uncompressed bytes from the compressed file
. If
Read
and decompress up to len uncompressed bytes from file into buf
. If
the input file is not in gzip format, gzread copies the given number of
bytes into the buffer directly from the file.
...
...
@@ -1420,11 +1422,11 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
ZEXTERN
z_size_t
ZEXPORT
gzfread
OF
((
voidp
buf
,
z_size_t
size
,
z_size_t
nitems
,
gzFile
file
));
/*
Read
up to nitems items of size size from file to buf, otherwise operating
as gzread() does. This duplicates the interface of stdio's fread(), with
s
ize_t request and return types. If the library defines size_t, then
z_size_t is identical to size_t. If not, then z_size_t is an unsigned
integer type that can contain a pointer.
Read
and decompress up to nitems items of size size from file into buf,
otherwise operating as gzread() does. This duplicates the interface of
s
tdio's fread(), with size_t request and return types. If the library
defines size_t, then z_size_t is identical to size_t. If not, then z_size_t
i
s an unsigned i
nteger type that can contain a pointer.
gzfread() returns the number of full items read of size size, or zero if
the end of the file was reached and a full item could not be read, or if
...
...
@@ -1443,18 +1445,16 @@ ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems,
file, reseting and retrying on end-of-file, when size is not 1.
*/
ZEXTERN
int
ZEXPORT
gzwrite
OF
((
gzFile
file
,
voidpc
buf
,
unsigned
len
));
ZEXTERN
int
ZEXPORT
gzwrite
OF
((
gzFile
file
,
voidpc
buf
,
unsigned
len
));
/*
Writes the given number of uncompressed bytes into the compressed file.
gzwrite returns the number of uncompressed bytes written or 0 in case of
error.
Compress and write the len uncompressed bytes at buf to file. gzwrite
returns the number of uncompressed bytes written or 0 in case of error.
*/
ZEXTERN
z_size_t
ZEXPORT
gzfwrite
OF
((
voidpc
buf
,
z_size_t
size
,
z_size_t
nitems
,
gzFile
file
));
/*
gzfwrite() writes
nitems items of size size from buf to file, duplicating
Compress and write
nitems items of size size from buf to file, duplicating
the interface of stdio's fwrite(), with size_t request and return types. If
the library defines size_t, then z_size_t is identical to size_t. If not,
then z_size_t is an unsigned integer type that can contain a pointer.
...
...
@@ -1467,22 +1467,22 @@ ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size,
ZEXTERN
int
ZEXPORTVA
gzprintf
Z_ARG
((
gzFile
file
,
const
char
*
format
,
...));
/*
Convert
s, formats, and writes the arguments to the compressed
file under
control of the
format string
, as in fprintf. gzprintf returns the number of
Convert
, format, compress, and write the arguments (...) to
file under
control of the
string format
, as in fprintf. gzprintf returns the number of
uncompressed bytes actually written, or a negative zlib error code in case
of error. The number of uncompressed bytes written is limited to 8191, or
one less than the buffer size given to gzbuffer(). The caller should assure
that this limit is not exceeded. If it is exceeded, then gzprintf() will
return an error (0) with nothing written. In this case, there may also be a
buffer overflow with unpredictable consequences, which is possible only if
zlib was compiled with the insecure functions sprintf() or vsprintf()
zlib was compiled with the insecure functions sprintf() or vsprintf()
,
because the secure snprintf() or vsnprintf() functions were not available.
This can be determined using zlibCompileFlags().
*/
ZEXTERN
int
ZEXPORT
gzputs
OF
((
gzFile
file
,
const
char
*
s
));
/*
Writes the given null-terminated string to the compressed
file, excluding
Compress and write the given null-terminated string s to
file, excluding
the terminating null character.
gzputs returns the number of characters written, or -1 in case of error.
...
...
@@ -1490,11 +1490,12 @@ ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
ZEXTERN
char
*
ZEXPORT
gzgets
OF
((
gzFile
file
,
char
*
buf
,
int
len
));
/*
Reads bytes from the compressed file until len-1 characters are read, or a
newline character is read and transferred to buf, or an end-of-file
condition is encountered. If any characters are read or if len == 1, the
string is terminated with a null character. If no characters are read due
to an end-of-file or len < 1, then the buffer is left untouched.
Read and decompress bytes from file into buf, until len-1 characters are
read, or until a newline character is read and transferred to buf, or an
end-of-file condition is encountered. If any characters are read or if len
is one, the string is terminated with a null character. If no characters
are read due to an end-of-file or len is less than one, then the buffer is
left untouched.
gzgets returns buf which is a null-terminated string, or it returns NULL
for end-of-file or in case of error. If there was an error, the contents at
...
...
@@ -1503,13 +1504,13 @@ ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
ZEXTERN
int
ZEXPORT
gzputc
OF
((
gzFile
file
,
int
c
));
/*
Writes c, converted to an unsigned char, into the compressed
file. gzputc
Compress and write c, converted to an unsigned char, into
file. gzputc
returns the value that was written, or -1 in case of error.
*/
ZEXTERN
int
ZEXPORT
gzgetc
OF
((
gzFile
file
));
/*
Read
s one byte from the compressed
file. gzgetc returns this byte or -1
Read
and decompress one byte from
file. gzgetc returns this byte or -1
in case of end of file or error. This is implemented as a macro for speed.
As such, it does not do all of the checking the other functions do. I.e.
it does not check to see if file is NULL, nor whether the structure file
...
...
@@ -1518,8 +1519,8 @@ ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
ZEXTERN
int
ZEXPORT
gzungetc
OF
((
int
c
,
gzFile
file
));
/*
Push
one character back onto the stream to be read as the first character
on the next read. At least one character of push-back i
s allowed.
Push
c back onto the stream for file to be read as the first character on
the next read. At least one character of push-back is alway
s allowed.
gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
fail if c is -1, and may fail if a character has been pushed but not read
yet. If gzungetc is used immediately after gzopen or gzdopen, at least the
...
...
@@ -1530,9 +1531,9 @@ ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
ZEXTERN
int
ZEXPORT
gzflush
OF
((
gzFile
file
,
int
flush
));
/*
Flush
es all pending output into the compressed file. The parameter flush
is as in the deflate() function. The return value is the zlib error number
(see function
gzerror below). gzflush is only permitted when writing.
Flush
all pending output to file. The parameter flush is as in the
deflate() function. The return value is the zlib error number (see function
gzerror below). gzflush is only permitted when writing.
If the flush parameter is Z_FINISH, the remaining data is written and the
gzip stream is completed in the output. If gzwrite() is called again, a new
...
...
@@ -1547,8 +1548,8 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
z_off_t offset, int whence));
Set
s the starting position for the next gzread or gzwrite on the given
compressed
file. The offset represents a number of bytes in the
Set
the starting position to offset relative to whence for the next gzread
or gzwrite on
file. The offset represents a number of bytes in the
uncompressed data stream. The whence parameter is defined as in lseek(2);
the value SEEK_END is not supported.
...
...
@@ -1565,18 +1566,18 @@ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
ZEXTERN
int
ZEXPORT
gzrewind
OF
((
gzFile
file
));
/*
Rewind
s the given
file. This function is supported only for reading.
Rewind file. This function is supported only for reading.
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
.
*/
/*
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
Return
s the starting position for the next gzread or gzwrite on the given
compressed file. This position represents a number of bytes in the
uncompressed data stream, and is zero when starting, even if appending or
reading a gzip stream from
the middle of a file using gzdopen().
Return
the starting position for the next gzread or gzwrite on file.
This position represents a number of bytes in the uncompressed data stream,
and is zero when starting, even if appending or reading a gzip stream from
the middle of a file using gzdopen().
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
*/
...
...
@@ -1584,22 +1585,22 @@ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
/*
ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
Return
s the current offset in the file being read or written. This offset
includes the count of bytes that precede the gzip stream, for example when
appending or when using gzdopen() for reading. When reading, the offset
does not include as yet unused buffered input. This information can be used
for a progress indicator. On error, gzoffset() returns -1.
Return
the current compressed (actual) read or write offset of file. This
offset includes the count of bytes that precede the gzip stream, for example
when appending or when using gzdopen() for reading. When reading, the
offset does not include as yet unused buffered input. This information can
be used
for a progress indicator. On error, gzoffset() returns -1.
*/
ZEXTERN
int
ZEXPORT
gzeof
OF
((
gzFile
file
));
/*
Return
s true (1) if the end-of-file indicator has been set while reading,
false (0) otherwise. Note that the end-of-file indicator is set only if the
read tried to go past the end of the input, but came up short. Therefore,
just like feof(), gzeof() may return false even if there is no more data t
o
read, in the event that the last read request was for the exact number of
bytes remaining in the input file. This will happen if the input file size
is an exact multiple of the buffer size.
Return
true (1) if the end-of-file indicator for file has been set while
reading, false (0) otherwise. Note that the end-of-file indicator is set
only if the read tried to go past the end of the input, but came up short.
Therefore, just like feof(), gzeof() may return false even if there is n
o
more data to read, in the event that the last read request was for the exact
number of bytes remaining in the input file. This will happen if the input
file size
is an exact multiple of the buffer size.
If gzeof() returns true, then the read functions will return no more data,
unless the end-of-file indicator is reset by gzclearerr() and the input file
...
...
@@ -1608,7 +1609,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file));
ZEXTERN
int
ZEXPORT
gzdirect
OF
((
gzFile
file
));
/*
Return
s
true (1) if file is being copied directly while reading, or false
Return true (1) if file is being copied directly while reading, or false
(0) if file is a gzip stream being decompressed.
If the input file is empty, gzdirect() will return true, since the input
...
...
@@ -1629,8 +1630,8 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
ZEXTERN
int
ZEXPORT
gzclose
OF
((
gzFile
file
));
/*
Flush
es all pending output if necessary, closes the compressed
file and
deallocate
s
the (de)compression state. Note that once file is closed, you
Flush
all pending output for file, if necessary, close
file and
deallocate the (de)compression state. Note that once file is closed, you
cannot call gzerror with file, since its structures have been deallocated.
gzclose must not be called more than once on the same file, just as free
must not be called more than once on the same allocation.
...
...
@@ -1654,10 +1655,10 @@ ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
ZEXTERN
const
char
*
ZEXPORT
gzerror
OF
((
gzFile
file
,
int
*
errnum
));
/*
Return
s the error message for the last error which occurred on the given
compressed file. errnum is set to zlib error number. If an error occurred
in the file system and not in the compression library, errnum is set to
Z_ERRNO and the
application may consult errno to get the exact error code.
Return
the error message for the last error which occurred on file.
errnum is set to zlib error number. If an error occurred in the file system
and not in the compression library, errnum is set to Z_ERRNO and the
application may consult errno to get the exact error code.
The application must not modify the returned string. Future calls to
this function may invalidate the previously returned string. If file is
...
...
@@ -1670,7 +1671,7 @@ ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
ZEXTERN
void
ZEXPORT
gzclearerr
OF
((
gzFile
file
));
/*
Clear
s
the error and end-of-file flags for file. This is analogous to the
Clear the error and end-of-file flags for file. This is analogous to the
clearerr() function in stdio. This is useful for continuing to read a gzip
file that is being written concurrently.
*/
...
...
@@ -1688,8 +1689,9 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
ZEXTERN
uLong
ZEXPORT
adler32
OF
((
uLong
adler
,
const
Bytef
*
buf
,
uInt
len
));
/*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
return the updated checksum. If buf is Z_NULL, this function returns the
required initial value for the checksum.
return the updated checksum. An Adler-32 value is in the range of a 32-bit
unsigned integer. If buf is Z_NULL, this function returns the required
initial value for the checksum.
An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed
much faster.
...
...
@@ -1722,12 +1724,13 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
negative, the result has no meaning or utility.
*/
ZEXTERN
uLong
ZEXPORT
crc32
OF
((
uLong
crc
,
const
Bytef
*
buf
,
uInt
len
));
ZEXTERN
uLong
ZEXPORT
crc32
OF
((
uLong
crc
,
const
Bytef
*
buf
,
uInt
len
));
/*
Update a running CRC-32 with the bytes buf[0..len-1] and return the
updated CRC-32. If buf is Z_NULL, this function returns the required
initial value for the crc. Pre- and post-conditioning (one's complement) is
performed within this function so it shouldn't be done by the application.
updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer.
If buf is Z_NULL, this function returns the required initial value for the
crc. Pre- and post-conditioning (one's complement) is performed within this
function so it shouldn't be done by the application.
Usage example:
...
...
@@ -1739,7 +1742,7 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
if (crc != original_crc) error();
*/
ZEXTERN
uLong
ZEXPORT
crc32_z
OF
((
uLong
adler
,
const
Bytef
*
buf
,
ZEXTERN
uLong
ZEXPORT
crc32_z
OF
((
uLong
crc
,
const
Bytef
*
buf
,
z_size_t
len
));
/*
Same as crc32(), but with a size_t length.
...
...
@@ -1755,6 +1758,20 @@ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
len2.
*/
/*
ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2));
Return the operator corresponding to length len2, to be used with
crc32_combine_op().
*/
ZEXTERN
uLong
ZEXPORT
crc32_combine_op
OF
((
uLong
crc1
,
uLong
crc2
,
uLong
op
));
/*
Give the same result as crc32_combine(), using op in place of len2. op is
is generated from len2 by crc32_combine_gen(). This will be faster than
crc32_combine() if the generated op is used more than once.
*/
/* various hacks, don't look :) */
...
...
@@ -1842,6 +1859,7 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
ZEXTERN
z_off64_t
ZEXPORT
gzoffset64
OF
((
gzFile
));
ZEXTERN
uLong
ZEXPORT
adler32_combine64
OF
((
uLong
,
uLong
,
z_off64_t
));
ZEXTERN
uLong
ZEXPORT
crc32_combine64
OF
((
uLong
,
uLong
,
z_off64_t
));
ZEXTERN
uLong
ZEXPORT
crc32_combine_gen64
OF
((
z_off64_t
));
#endif
#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
...
...
@@ -1852,6 +1870,7 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
# define z_gzoffset z_gzoffset64
# define z_adler32_combine z_adler32_combine64
# define z_crc32_combine z_crc32_combine64
# define z_crc32_combine_gen z_crc32_combine_gen64
# else
# define gzopen gzopen64
# define gzseek gzseek64
...
...
@@ -1859,6 +1878,7 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
# define gzoffset gzoffset64
# define adler32_combine adler32_combine64
# define crc32_combine crc32_combine64
# define crc32_combine_gen crc32_combine_gen64
# endif
# ifndef Z_LARGE64
ZEXTERN
gzFile
ZEXPORT
gzopen64
OF
((
const
char
*
,
const
char
*
));
...
...
@@ -1867,6 +1887,7 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
ZEXTERN
z_off_t
ZEXPORT
gzoffset64
OF
((
gzFile
));
ZEXTERN
uLong
ZEXPORT
adler32_combine64
OF
((
uLong
,
uLong
,
z_off_t
));
ZEXTERN
uLong
ZEXPORT
crc32_combine64
OF
((
uLong
,
uLong
,
z_off_t
));
ZEXTERN
uLong
ZEXPORT
crc32_combine_gen64
OF
((
z_off_t
));
# endif
#else
ZEXTERN
gzFile
ZEXPORT
gzopen
OF
((
const
char
*
,
const
char
*
));
...
...
@@ -1875,12 +1896,14 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
ZEXTERN
z_off_t
ZEXPORT
gzoffset
OF
((
gzFile
));
ZEXTERN
uLong
ZEXPORT
adler32_combine
OF
((
uLong
,
uLong
,
z_off_t
));
ZEXTERN
uLong
ZEXPORT
crc32_combine
OF
((
uLong
,
uLong
,
z_off_t
));
ZEXTERN
uLong
ZEXPORT
crc32_combine_gen
OF
((
z_off_t
));
#endif
#else
/* Z_SOLO */
ZEXTERN
uLong
ZEXPORT
adler32_combine
OF
((
uLong
,
uLong
,
z_off_t
));
ZEXTERN
uLong
ZEXPORT
crc32_combine
OF
((
uLong
,
uLong
,
z_off_t
));
ZEXTERN
uLong
ZEXPORT
crc32_combine_gen
OF
((
z_off_t
));
#endif
/* !Z_SOLO */
...
...
@@ -1893,7 +1916,7 @@ ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int));
ZEXTERN
unsigned
long
ZEXPORT
inflateCodesUsed
OF
((
z_streamp
));
ZEXTERN
int
ZEXPORT
inflateResetKeep
OF
((
z_streamp
));
ZEXTERN
int
ZEXPORT
deflateResetKeep
OF
((
z_streamp
));
#if
(defined(_WIN32) || defined(__CYGWIN__)
) && !defined(Z_SOLO)
#if
defined(_WIN32
) && !defined(Z_SOLO)
ZEXTERN
gzFile
ZEXPORT
gzopen_w
OF
((
const
wchar_t
*
path
,
const
char
*
mode
));
#endif
...
...
deps/zlib/zutil.c
View file @
f0cf45d3
...
...
@@ -136,8 +136,8 @@ const char * ZEXPORT zError(err)
return
ERR_MSG
(
err
);
}
#if defined(_WIN32_WCE)
/* The Microsoft C Run-Time Library for Windows CE doesn't have
#if defined(_WIN32_WCE)
&& _WIN32_WCE < 0x800
/* The
older
Microsoft C Run-Time Library for Windows CE doesn't have
* errno. We define it as a global variable to simplify porting.
* Its value is always 0 and should not be used.
*/
...
...
deps/zlib/zutil.h
View file @
f0cf45d3
/* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-20
16
Jean-loup Gailly, Mark Adler
* Copyright (C) 1995-20
22
Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
...
...
@@ -29,10 +29,6 @@
# include <stdlib.h>
#endif
#ifdef Z_SOLO
typedef
long
ptrdiff_t
;
/* guess -- will be caught if guess is wrong */
#endif
#ifndef local
# define local static
#endif
...
...
@@ -46,6 +42,17 @@ typedef unsigned short ush;
typedef
ush
FAR
ushf
;
typedef
unsigned
long
ulg
;
#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 (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++) */
...
...
@@ -170,10 +177,6 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
# if defined(_WIN32_WCE)
# 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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment