replace zlib with zlib-ng on windows
This commit is contained in:
1 parent
612f910b9c
commit
2891983cde
94 files changed
+29596
-16103
No files matched your search
@@ -0,0 +1,27 @@
|
||||
codecov:
|
||||
max_report_age: off
|
||||
notify:
|
||||
wait_for_ci: false
|
||||
require_ci_to_pass: false
|
||||
comment:
|
||||
require_base: false
|
||||
require_head: false
|
||||
coverage:
|
||||
status:
|
||||
project:
|
||||
default:
|
||||
threshold: 0.07
|
||||
fixes:
|
||||
- '/home/actions-runner/_work/zlib-ng/zlib-ng::'
|
||||
- '/home/actions-runner/_work/zlib-ng/zlib-ng/build/::'
|
||||
ignore:
|
||||
- usr/include/.*
|
||||
- /usr/include/.*
|
||||
- /build/usr/include/.*
|
||||
- usr/lib/.*
|
||||
- /usr/lib/.*
|
||||
- /build/usr/lib/.*
|
||||
- usr/lib64/.*
|
||||
- /usr/lib64/.*
|
||||
- /build/usr/lib64/.*
|
||||
- _deps/**/*
|
||||
@@ -0,0 +1 @@
|
||||
disable=SC2140,SC2086,SC2046,SC2015,SC1097,SC1035,SC1036,SC1007,SC2154,SC2155,SC2000,SC2034,SC2016,SC1091,SC1090,SC2212,SC2143,SC2129,SC2102,SC2069,SC1041,SC1042,SC1044,SC1046,SC1119,SC1110,SC1111,SC1112,SC1102,SC1105,SC1101,SC1004,SC1003,SC1012,SC2068,SC2065,SC2064,SC2063,SC2059,SC2053,SC2048,SC2044,SC2032,SC2031,SC2030,SC2029,SC2025,SC2024,SC2022,SC2018,SC2019,SC2017,SC2014,SC2013,SC2012,SC2009,SC2001,SC2098,SC2096,SC2094,SC2091,SC2092,SC2088,SC2087,SC2076,SC2072,SC2071,SC2223,SC2221,SC2222,SC2217,SC2207,SC2206,SC2205,SC2190,SC2188,SC2187,SC2185,SC2179,SC2178,SC2174,SC2168,SC2167,SC2163,SC2161,SC2160,SC2153,SC2150,SC2148,SC2147,SC2146,SC2142,SC2139,SC2126,SC2123,SC2120,SC2119,SC2117,SC2114,SC1117,SC2164,SC1083,SC2004,SC2125,SC2128,SC2011,SC1008,SC1019,SC2093,SC1132,SC1129,SC2236,SC2237,SC2231,SC2230,SC2229,SC2106,SC2102,SC2243,SC2244,SC2245,SC2247,SC2248,SC2249,SC2250,SC2251,SC2252,SC2181
|
||||
+1414
-125
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,373 @@
|
||||
##
|
||||
# THIS IS AN UNMAINTAINED COPY OF THE ORIGINAL FILE DISTRIBUTED WITH ZLIB 1.2.11
|
||||
##
|
||||
|
||||
|
||||
|
||||
|
||||
Frequently Asked Questions about zlib
|
||||
|
||||
|
||||
If your question is not there, please check the zlib home page
|
||||
https://zlib.net/ which may have more recent information.
|
||||
The latest zlib FAQ is at https://zlib.net/zlib_faq.html
|
||||
|
||||
|
||||
1. Is zlib Y2K-compliant?
|
||||
|
||||
Yes. zlib doesn't handle dates.
|
||||
|
||||
2. Where can I get a Windows DLL version?
|
||||
|
||||
The zlib sources can be compiled without change to produce a DLL. See the
|
||||
file win32/DLL_FAQ.txt in the zlib distribution.
|
||||
|
||||
3. Where can I get a Visual Basic interface to zlib?
|
||||
|
||||
See
|
||||
* https://marknelson.us/1997/01/01/zlib-engine/
|
||||
* win32/DLL_FAQ.txt in the zlib distribution
|
||||
|
||||
4. compress() returns Z_BUF_ERROR.
|
||||
|
||||
Make sure that before the call of compress(), the length of the compressed
|
||||
buffer is equal to the available size of the compressed buffer and not
|
||||
zero. For Visual Basic, check that this parameter is passed by reference
|
||||
("as any"), not by value ("as long").
|
||||
|
||||
5. deflate() or inflate() returns Z_BUF_ERROR.
|
||||
|
||||
Before making the call, make sure that avail_in and avail_out are not zero.
|
||||
When setting the parameter flush equal to Z_FINISH, also make sure that
|
||||
avail_out is big enough to allow processing all pending input. Note that a
|
||||
Z_BUF_ERROR is not fatal--another call to deflate() or inflate() can be
|
||||
made with more input or output space. A Z_BUF_ERROR may in fact be
|
||||
unavoidable depending on how the functions are used, since it is not
|
||||
possible to tell whether or not there is more output pending when
|
||||
strm.avail_out returns with zero. See https://zlib.net/zlib_how.html for a
|
||||
heavily annotated example.
|
||||
|
||||
6. Where's the zlib documentation (man pages, etc.)?
|
||||
|
||||
It's in zlib.h . Examples of zlib usage are in the files test/example.c
|
||||
and test/minigzip.c, with more in examples/ .
|
||||
|
||||
7. Why don't you use GNU autoconf or libtool or ...?
|
||||
|
||||
Because we would like to keep zlib as a very small and simple package.
|
||||
zlib is rather portable and doesn't need much configuration.
|
||||
|
||||
8. I found a bug in zlib.
|
||||
|
||||
Most of the time, such problems are due to an incorrect usage of zlib.
|
||||
Please try to reproduce the problem with a small program and send the
|
||||
corresponding source to us at zlib@gzip.org . Do not send multi-megabyte
|
||||
data files without prior agreement.
|
||||
|
||||
9. Why do I get "undefined reference to gzputc"?
|
||||
|
||||
If "make test" produces something like
|
||||
|
||||
example.o(.text+0x154): undefined reference to `gzputc'
|
||||
|
||||
check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
|
||||
/usr/X11R6/lib. Remove any old versions, then do "make install".
|
||||
|
||||
10. I need a Delphi interface to zlib.
|
||||
|
||||
See the contrib/delphi directory in the zlib distribution.
|
||||
|
||||
11. Can zlib handle .zip archives?
|
||||
|
||||
Not by itself, no. See the directory contrib/minizip in the zlib
|
||||
distribution.
|
||||
|
||||
12. Can zlib handle .Z files?
|
||||
|
||||
No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt
|
||||
the code of uncompress on your own.
|
||||
|
||||
13. How can I make a Unix shared library?
|
||||
|
||||
By default a shared (and a static) library is built for Unix. So:
|
||||
|
||||
make distclean
|
||||
./configure
|
||||
make
|
||||
|
||||
14. How do I install a shared zlib library on Unix?
|
||||
|
||||
After the above, then:
|
||||
|
||||
make install
|
||||
|
||||
However, many flavors of Unix come with a shared zlib already installed.
|
||||
Before going to the trouble of compiling a shared version of zlib and
|
||||
trying to install it, you may want to check if it's already there! If you
|
||||
can #include <zlib.h>, it's there. The -lz option will probably link to
|
||||
it. You can check the version at the top of zlib.h or with the
|
||||
ZLIB_VERSION symbol defined in zlib.h .
|
||||
|
||||
15. I have a question about OttoPDF.
|
||||
|
||||
We are not the authors of OttoPDF. The real author is on the OttoPDF web
|
||||
site: Joel Hainley, jhainley@myndkryme.com.
|
||||
|
||||
16. Can zlib decode Flate data in an Adobe PDF file?
|
||||
|
||||
Yes. See https://www.pdflib.com/ . To modify PDF forms, see
|
||||
https://sourceforge.net/projects/acroformtool/ .
|
||||
|
||||
17. Why am I getting this "register_frame_info not found" error on Solaris?
|
||||
|
||||
After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib
|
||||
generates an error such as:
|
||||
|
||||
ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so:
|
||||
symbol __register_frame_info: referenced symbol not found
|
||||
|
||||
The symbol __register_frame_info is not part of zlib, it is generated by
|
||||
the C compiler (cc or gcc). You must recompile applications using zlib
|
||||
which have this problem. This problem is specific to Solaris. See
|
||||
http://www.sunfreeware.com/ for Solaris versions of zlib and applications
|
||||
using zlib.
|
||||
|
||||
18. Why does gzip give an error on a file I make with compress/deflate?
|
||||
|
||||
The compress and deflate functions produce data in the zlib format, which
|
||||
is different and incompatible with the gzip format. The gz* functions in
|
||||
zlib on the other hand use the gzip format. Both the zlib and gzip formats
|
||||
use the same compressed data format internally, but have different headers
|
||||
and trailers around the compressed data.
|
||||
|
||||
19. Ok, so why are there two different formats?
|
||||
|
||||
The gzip format was designed to retain the directory information about a
|
||||
single file, such as the name and last modification date. The zlib format
|
||||
on the other hand was designed for in-memory and communication channel
|
||||
applications, and has a much more compact header and trailer and uses a
|
||||
faster integrity check than gzip.
|
||||
|
||||
20. Well that's nice, but how do I make a gzip file in memory?
|
||||
|
||||
You can request that deflate write the gzip format instead of the zlib
|
||||
format using deflateInit2(). You can also request that inflate decode the
|
||||
gzip format using inflateInit2(). Read zlib.h for more details.
|
||||
|
||||
21. Is zlib thread-safe?
|
||||
|
||||
Yes. However any library routines that zlib uses and any application-
|
||||
provided memory allocation routines must also be thread-safe. zlib's gz*
|
||||
functions use stdio library routines, and most of zlib's functions use the
|
||||
library memory allocation routines by default. zlib's *Init* functions
|
||||
allow for the application to provide custom memory allocation routines.
|
||||
|
||||
Of course, you should only operate on any given zlib or gzip stream from a
|
||||
single thread at a time.
|
||||
|
||||
22. Can I use zlib in my commercial application?
|
||||
|
||||
Yes. Please read the license in zlib.h.
|
||||
|
||||
23. Is zlib under the GNU license?
|
||||
|
||||
No. Please read the license in zlib.h.
|
||||
|
||||
24. The license says that altered source versions must be "plainly marked". So
|
||||
what exactly do I need to do to meet that requirement?
|
||||
|
||||
You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h. In
|
||||
particular, the final version number needs to be changed to "f", and an
|
||||
identification string should be appended to ZLIB_VERSION. Version numbers
|
||||
x.x.x.f are reserved for modifications to zlib by others than the zlib
|
||||
maintainers. For example, if the version of the base zlib you are altering
|
||||
is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and
|
||||
ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3". You can also
|
||||
update the version strings in deflate.c and inftrees.c.
|
||||
|
||||
For altered source distributions, you should also note the origin and
|
||||
nature of the changes in zlib.h, as well as in ChangeLog and README, along
|
||||
with the dates of the alterations. The origin should include at least your
|
||||
name (or your company's name), and an email address to contact for help or
|
||||
issues with the library.
|
||||
|
||||
Note that distributing a compiled zlib library along with zlib.h and
|
||||
zconf.h is also a source distribution, and so you should change
|
||||
ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes
|
||||
in zlib.h as you would for a full source distribution.
|
||||
|
||||
25. Will zlib work on a big-endian or little-endian architecture, and can I
|
||||
exchange compressed data between them?
|
||||
|
||||
Yes and yes.
|
||||
|
||||
26. Will zlib work on a 64-bit machine?
|
||||
|
||||
Yes. It has been tested on 64-bit machines, and has no dependence on any
|
||||
data types being limited to 32-bits in length. If you have any
|
||||
difficulties, please provide a complete problem report to zlib@gzip.org
|
||||
|
||||
27. Will zlib decompress data from the PKWare Data Compression Library?
|
||||
|
||||
No. The PKWare DCL uses a completely different compressed data format than
|
||||
does PKZIP and zlib. However, you can look in zlib's contrib/blast
|
||||
directory for a possible solution to your problem.
|
||||
|
||||
28. Can I access data randomly in a compressed stream?
|
||||
|
||||
No, not without some preparation. If when compressing you periodically use
|
||||
Z_FULL_FLUSH, carefully write all the pending data at those points, and
|
||||
keep an index of those locations, then you can start decompression at those
|
||||
points. You have to be careful to not use Z_FULL_FLUSH too often, since it
|
||||
can significantly degrade compression. Alternatively, you can scan a
|
||||
deflate stream once to generate an index, and then use that index for
|
||||
random access. See examples/zran.c .
|
||||
|
||||
29. Does zlib work on MVS, OS/390, CICS, etc.?
|
||||
|
||||
It has in the past, but we have not heard of any recent evidence. There
|
||||
were working ports of zlib 1.1.4 to MVS, but those links no longer work.
|
||||
If you know of recent, successful applications of zlib on these operating
|
||||
systems, please let us know. Thanks.
|
||||
|
||||
30. Is there some simpler, easier to read version of inflate I can look at to
|
||||
understand the deflate format?
|
||||
|
||||
First off, you should read RFC 1951. Second, yes. Look in zlib's
|
||||
contrib/puff directory.
|
||||
|
||||
31. Does zlib infringe on any patents?
|
||||
|
||||
As far as we know, no. In fact, that was originally the whole point behind
|
||||
zlib. Look here for some more information:
|
||||
|
||||
https://www.gzip.org/#faq11
|
||||
|
||||
32. Can zlib work with greater than 4 GB of data?
|
||||
|
||||
Yes. inflate() and deflate() will process any amount of data correctly.
|
||||
Each call of inflate() or deflate() is limited to input and output chunks
|
||||
of the maximum value that can be stored in the compiler's "unsigned int"
|
||||
type, but there is no limit to the number of chunks. Note however that the
|
||||
strm.total_in and strm_total_out counters may be limited to 4 GB. These
|
||||
counters are provided as a convenience and are not used internally by
|
||||
inflate() or deflate(). The application can easily set up its own counters
|
||||
updated after each call of inflate() or deflate() to count beyond 4 GB.
|
||||
compress() and uncompress() may be limited to 4 GB, since they operate in a
|
||||
single call. gzseek() and gztell() may be limited to 4 GB depending on how
|
||||
zlib is compiled. See the zlibCompileFlags() function in zlib.h.
|
||||
|
||||
The word "may" appears several times above since there is a 4 GB limit only
|
||||
if the compiler's "long" type is 32 bits. If the compiler's "long" type is
|
||||
64 bits, then the limit is 16 exabytes.
|
||||
|
||||
33. Does zlib have any security vulnerabilities?
|
||||
|
||||
The only one that we are aware of is potentially in gzprintf(). If zlib is
|
||||
compiled to use sprintf() or vsprintf(), then there is no protection
|
||||
against a buffer overflow of an 8K string space (or other value as set by
|
||||
gzbuffer()), other than the caller of gzprintf() assuring that the output
|
||||
will not exceed 8K. On the other hand, if zlib is compiled to use
|
||||
snprintf() or vsnprintf(), which should normally be the case, then there is
|
||||
no vulnerability. The ./configure script will display warnings if an
|
||||
insecure variation of sprintf() will be used by gzprintf(). Also the
|
||||
zlibCompileFlags() function will return information on what variant of
|
||||
sprintf() is used by gzprintf().
|
||||
|
||||
If you don't have snprintf() or vsnprintf() and would like one, you can
|
||||
find a portable implementation here:
|
||||
|
||||
https://www.ijs.si/software/snprintf/
|
||||
|
||||
Note that you should be using the most recent version of zlib. Versions
|
||||
1.1.3 and before were subject to a double-free vulnerability, and versions
|
||||
1.2.1 and 1.2.2 were subject to an access exception when decompressing
|
||||
invalid compressed data.
|
||||
|
||||
34. Is there a Java version of zlib?
|
||||
|
||||
Probably what you want is to use zlib in Java. zlib is already included
|
||||
as part of the Java SDK in the java.util.zip package. If you really want
|
||||
a version of zlib written in the Java language, look on the zlib home
|
||||
page for links: https://zlib.net/ .
|
||||
|
||||
35. I get this or that compiler or source-code scanner warning when I crank it
|
||||
up to maximally-pedantic. Can't you guys write proper code?
|
||||
|
||||
Many years ago, we gave up attempting to avoid warnings on every compiler
|
||||
in the universe. It just got to be a waste of time, and some compilers
|
||||
were downright silly as well as contradicted each other. So now, we simply
|
||||
make sure that the code always works.
|
||||
|
||||
36. Valgrind (or some similar memory access checker) says that deflate is
|
||||
performing a conditional jump that depends on an uninitialized value.
|
||||
Isn't that a bug?
|
||||
|
||||
No. That is intentional for performance reasons, and the output of deflate
|
||||
is not affected. This only started showing up recently since zlib 1.2.x
|
||||
uses malloc() by default for allocations, whereas earlier versions used
|
||||
calloc(), which zeros out the allocated memory. Even though the code was
|
||||
correct, versions 1.2.4 and later was changed to not stimulate these
|
||||
checkers.
|
||||
|
||||
37. Will zlib read the (insert any ancient or arcane format here) compressed
|
||||
data format?
|
||||
|
||||
Probably not. Look in the comp.compression FAQ for pointers to various
|
||||
formats and associated software.
|
||||
|
||||
38. How can I encrypt/decrypt zip files with zlib?
|
||||
|
||||
zlib doesn't support encryption. The original PKZIP encryption is very
|
||||
weak and can be broken with freely available programs. To get strong
|
||||
encryption, use GnuPG, https://www.gnupg.org/ , which already includes zlib
|
||||
compression. For PKZIP compatible "encryption", look at
|
||||
http://infozip.sourceforge.net/
|
||||
|
||||
39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
|
||||
|
||||
"gzip" is the gzip format, and "deflate" is the zlib format. They should
|
||||
probably have called the second one "zlib" instead to avoid confusion with
|
||||
the raw deflate compressed data format. While the HTTP 1.1 RFC 2616
|
||||
correctly points to the zlib specification in RFC 1950 for the "deflate"
|
||||
transfer encoding, there have been reports of servers and browsers that
|
||||
incorrectly produce or expect raw deflate data per the deflate
|
||||
specification in RFC 1951, most notably Microsoft. So even though the
|
||||
"deflate" transfer encoding using the zlib format would be the more
|
||||
efficient approach (and in fact exactly what the zlib format was designed
|
||||
for), using the "gzip" transfer encoding is probably more reliable due to
|
||||
an unfortunate choice of name on the part of the HTTP 1.1 authors.
|
||||
|
||||
Bottom line: use the gzip format for HTTP 1.1 encoding.
|
||||
|
||||
40. Does zlib support the new "Deflate64" format introduced by PKWare?
|
||||
|
||||
No. PKWare has apparently decided to keep that format proprietary, since
|
||||
they have not documented it as they have previous compression formats. In
|
||||
any case, the compression improvements are so modest compared to other more
|
||||
modern approaches, that it's not worth the effort to implement.
|
||||
|
||||
41. I'm having a problem with the zip functions in zlib, can you help?
|
||||
|
||||
There are no zip functions in zlib. You are probably using minizip by
|
||||
Giles Vollant, which is found in the contrib directory of zlib. It is not
|
||||
part of zlib. In fact none of the stuff in contrib is part of zlib. The
|
||||
files in there are not supported by the zlib authors. You need to contact
|
||||
the authors of the respective contribution for help.
|
||||
|
||||
42. The match.asm code in contrib is under the GNU General Public License.
|
||||
Since it's part of zlib, doesn't that mean that all of zlib falls under the
|
||||
GNU GPL?
|
||||
|
||||
No. The files in contrib are not part of zlib. They were contributed by
|
||||
other authors and are provided as a convenience to the user within the zlib
|
||||
distribution. Each item in contrib has its own license.
|
||||
|
||||
43. Is zlib subject to export controls? What is its ECCN?
|
||||
|
||||
zlib is not subject to export controls, and so is classified as EAR99.
|
||||
|
||||
44. Can you please sign these lengthy legal documents and fax them back to us
|
||||
so that we can use your software in our product?
|
||||
|
||||
No. Go away. Shoo.
|
||||
@@ -0,0 +1,36 @@
|
||||
Contents
|
||||
--------
|
||||
|
||||
| Name | Description |
|
||||
|:-----------------|:---------------------------------------------------------------|
|
||||
| arch/ | Architecture-specific code |
|
||||
| doc/ | Documentation for formats and algorithms |
|
||||
| test/example.c | Zlib usages examples for build testing |
|
||||
| test/minigzip.c | Minimal gzip-like functionality for build testing |
|
||||
| test/infcover.c | Inflate code coverage for build testing |
|
||||
| win32/ | Shared library version resources for Windows |
|
||||
| CMakeLists.txt | Cmake build script |
|
||||
| configure | Bash configure/build script |
|
||||
| adler32.c | Compute the Adler-32 checksum of a data stream |
|
||||
| chunkset.* | Inline functions to copy small data chunks |
|
||||
| compress.c | Compress a memory buffer |
|
||||
| deflate.* | Compress data using the deflate algorithm |
|
||||
| deflate_fast.c | Compress data using the deflate algorithm with fast strategy |
|
||||
| deflate_medium.c | Compress data using the deflate algorithm with medium strategy |
|
||||
| deflate_slow.c | Compress data using the deflate algorithm with slow strategy |
|
||||
| functable.* | Struct containing function pointers to optimized functions |
|
||||
| gzguts.h | Internal definitions for gzip operations |
|
||||
| gzlib.c | Functions common to reading and writing gzip files |
|
||||
| gzread.c | Read gzip files |
|
||||
| gzwrite.c | Write gzip files |
|
||||
| infback.* | Inflate using a callback interface |
|
||||
| inflate.* | Decompress data |
|
||||
| inffast.* | Decompress data with speed optimizations |
|
||||
| inffixed_tbl.h | Table for decoding fixed codes |
|
||||
| inftrees.h | Generate Huffman trees for efficient decoding |
|
||||
| trees.* | Output deflated data using Huffman coding |
|
||||
| uncompr.c | Decompress a memory buffer |
|
||||
| zconf.h.cmakein | zconf.h template for cmake |
|
||||
| zendian.h | BYTE_ORDER for endian tests |
|
||||
| zlib.map | Linux symbol information |
|
||||
| zlib.pc.in | Pkg-config template |
|
||||
@@ -0,0 +1,19 @@
|
||||
(C) 1995-2024 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
@@ -0,0 +1,411 @@
|
||||
# Makefile for zlib
|
||||
# Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
|
||||
# For conditions of distribution and use, see copyright notice in zlib.h
|
||||
|
||||
# To compile and test, type:
|
||||
# ./configure; make test
|
||||
# Normally configure builds both a static and a shared library.
|
||||
# If you want to build just a static library, use: ./configure --static
|
||||
|
||||
# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
|
||||
# make install
|
||||
# To install in $HOME instead of /usr/local, use:
|
||||
# make install prefix=$HOME
|
||||
|
||||
CC=cc
|
||||
|
||||
CFLAGS=-O
|
||||
#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
|
||||
#CFLAGS=-g -DZLIB_DEBUG
|
||||
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
|
||||
# -Wstrict-prototypes -Wmissing-prototypes
|
||||
|
||||
SFLAGS=-O
|
||||
LDFLAGS=-L.
|
||||
LIBNAME1=libz-ng
|
||||
LIBNAME2=zlib-ng
|
||||
SUFFIX=-ng
|
||||
TEST_LIBS=$(LIBNAME1).a
|
||||
LDSHARED=$(CC)
|
||||
LDSHAREDFLAGS=-shared
|
||||
LDVERSIONSCRIPT=
|
||||
|
||||
VER=2.2.4
|
||||
VER1=2
|
||||
|
||||
STATICLIB=$(LIBNAME1).a
|
||||
SHAREDLIB=$(LIBNAME1).so
|
||||
SHAREDLIBV=$(LIBNAME1).so.$(VER)
|
||||
SHAREDLIBM=$(LIBNAME1).so.$(VER1)
|
||||
IMPORTLIB=
|
||||
SHAREDTARGET=$(LIBNAME1).so.$(VER)
|
||||
PKGFILE=$(LIBNAME2).pc
|
||||
|
||||
LIBS=$(STATICLIB) $(SHAREDTARGET)
|
||||
|
||||
AR=ar
|
||||
ARFLAGS=rc
|
||||
DEFFILE=
|
||||
RC=
|
||||
RCFLAGS=
|
||||
RCOBJS=
|
||||
STRIP=
|
||||
RANLIB=ranlib
|
||||
LDCONFIG=ldconfig
|
||||
LDSHAREDLIBC=
|
||||
EXE=
|
||||
|
||||
SRCDIR=.
|
||||
INCLUDES=-I$(SRCDIR)
|
||||
|
||||
BUILDDIR=.
|
||||
|
||||
ARCHDIR=arch/generic
|
||||
ARCH_STATIC_OBJS=
|
||||
ARCH_SHARED_OBJS=
|
||||
|
||||
prefix = /usr/local
|
||||
exec_prefix = ${prefix}
|
||||
bindir = ${exec_prefix}/bin
|
||||
libdir = ${exec_prefix}/lib
|
||||
sharedlibdir = ${libdir}
|
||||
includedir = ${prefix}/include
|
||||
mandir = ${prefix}/share/man
|
||||
man3dir = ${mandir}/man3
|
||||
pkgconfigdir = ${libdir}/pkgconfig
|
||||
|
||||
OBJZ = \
|
||||
arch/generic/adler32_c.o \
|
||||
arch/generic/adler32_fold_c.o \
|
||||
arch/generic/chunkset_c.o \
|
||||
arch/generic/compare256_c.o \
|
||||
arch/generic/crc32_braid_c.o \
|
||||
arch/generic/crc32_c.o \
|
||||
arch/generic/crc32_fold_c.o \
|
||||
arch/generic/slide_hash_c.o \
|
||||
adler32.o \
|
||||
compress.o \
|
||||
crc32.o \
|
||||
crc32_braid_comb.o \
|
||||
deflate.o \
|
||||
deflate_fast.o \
|
||||
deflate_huff.o \
|
||||
deflate_medium.o \
|
||||
deflate_quick.o \
|
||||
deflate_rle.o \
|
||||
deflate_slow.o \
|
||||
deflate_stored.o \
|
||||
functable.o \
|
||||
infback.o \
|
||||
inflate.o \
|
||||
inftrees.o \
|
||||
insert_string.o \
|
||||
insert_string_roll.o \
|
||||
trees.o \
|
||||
uncompr.o \
|
||||
zutil.o \
|
||||
arch/generic/crc32_chorba_c.o \
|
||||
cpu_features.o \
|
||||
$(ARCH_STATIC_OBJS)
|
||||
|
||||
OBJG = \
|
||||
gzlib.o \
|
||||
gzread.o \
|
||||
gzwrite.o
|
||||
|
||||
TESTOBJG =
|
||||
OBJC = $(OBJZ) $(OBJG)
|
||||
|
||||
PIC_OBJZ = \
|
||||
arch/generic/adler32_c.lo \
|
||||
arch/generic/adler32_fold_c.lo \
|
||||
arch/generic/chunkset_c.lo \
|
||||
arch/generic/compare256_c.lo \
|
||||
arch/generic/crc32_braid_c.lo \
|
||||
arch/generic/crc32_c.lo \
|
||||
arch/generic/crc32_fold_c.lo \
|
||||
arch/generic/slide_hash_c.lo \
|
||||
adler32.lo \
|
||||
compress.lo \
|
||||
crc32.lo \
|
||||
crc32_braid_comb.lo \
|
||||
deflate.lo \
|
||||
deflate_fast.lo \
|
||||
deflate_huff.lo \
|
||||
deflate_medium.lo \
|
||||
deflate_quick.lo \
|
||||
deflate_rle.lo \
|
||||
deflate_slow.lo \
|
||||
deflate_stored.lo \
|
||||
functable.lo \
|
||||
infback.lo \
|
||||
inflate.lo \
|
||||
inftrees.lo \
|
||||
insert_string.lo \
|
||||
insert_string_roll.lo \
|
||||
trees.lo \
|
||||
uncompr.lo \
|
||||
zutil.lo \
|
||||
arch/generic/crc32_chorba_c.lo \
|
||||
cpu_features.lo \
|
||||
$(ARCH_SHARED_OBJS)
|
||||
|
||||
PIC_OBJG = \
|
||||
gzlib.lo \
|
||||
gzread.lo \
|
||||
gzwrite.lo
|
||||
|
||||
PIC_TESTOBJG =
|
||||
PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG)
|
||||
|
||||
OBJS = $(OBJC)
|
||||
|
||||
PIC_OBJS = $(PIC_OBJC)
|
||||
|
||||
all: static shared
|
||||
|
||||
static: example$(EXE) minigzip$(EXE) makefixed$(EXE) maketrees$(EXE) makecrct$(EXE)
|
||||
|
||||
shared: examplesh$(EXE) minigzipsh$(EXE)
|
||||
|
||||
check: test
|
||||
|
||||
.SECONDARY:
|
||||
|
||||
$(ARCHDIR)/%.o: $(SRCDIR)/$(ARCHDIR)/%.c
|
||||
$(MAKE) -C $(ARCHDIR) $(notdir $@)
|
||||
|
||||
$(ARCHDIR)/%.lo: $(SRCDIR)/$(ARCHDIR)/%.c
|
||||
$(MAKE) -C $(ARCHDIR) $(notdir $@)
|
||||
|
||||
arch/generic/%.o: $(SRCDIR)/arch/generic/%.c
|
||||
$(MAKE) -C arch/generic $(notdir $@)
|
||||
|
||||
arch/generic/%.lo: $(SRCDIR)/arch/generic/%.c
|
||||
$(MAKE) -C arch/generic $(notdir $@)
|
||||
|
||||
%.o: $(ARCHDIR)/%.o
|
||||
-cp $< $@
|
||||
|
||||
%.lo: $(ARCHDIR)/%.lo
|
||||
-cp $< $@
|
||||
|
||||
test: all
|
||||
$(MAKE) -C test
|
||||
|
||||
infcover.o: $(SRCDIR)/test/infcover.c zlib$(SUFFIX).h zconf$(SUFFIX).h zlib_name_mangling$(SUFFIX).h
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/test/infcover.c
|
||||
|
||||
infcover$(EXE): infcover.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ infcover.o $(STATICLIB)
|
||||
ifneq ($(STRIP),)
|
||||
$(STRIP) $@
|
||||
endif
|
||||
|
||||
cover: infcover$(EXE)
|
||||
rm -f *.gcda
|
||||
./infcover
|
||||
gcov inf*.c
|
||||
|
||||
$(STATICLIB): $(OBJS)
|
||||
$(AR) $(ARFLAGS) $@ $(OBJS)
|
||||
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
|
||||
|
||||
example.o:
|
||||
$(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $(SRCDIR)/test/example.c
|
||||
|
||||
minigzip.o:
|
||||
$(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $(SRCDIR)/test/minigzip.c
|
||||
|
||||
makefixed.o:
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/tools/makefixed.c
|
||||
|
||||
maketrees.o:
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/tools/maketrees.c
|
||||
|
||||
makecrct.o:
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/tools/makecrct.c
|
||||
|
||||
zlibrc.o: $(SRCDIR)/win32/zlib$(SUFFIX)1.rc
|
||||
$(RC) $(RCFLAGS) -o $@ $(SRCDIR)/win32/zlib$(SUFFIX)1.rc
|
||||
|
||||
.SUFFIXES: .lo
|
||||
|
||||
%.o: $(SRCDIR)/%.c
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
|
||||
|
||||
%.lo: $(SRCDIR)/%.c
|
||||
$(CC) $(SFLAGS) -DPIC $(INCLUDES) -c -o $@ $<
|
||||
|
||||
gzlib.o: $(SRCDIR)/gzlib.c
|
||||
$(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $<
|
||||
|
||||
gzlib.lo: $(SRCDIR)/gzlib.c
|
||||
$(CC) $(SFLAGS) -DPIC -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $<
|
||||
|
||||
gzread.o: gzread.c
|
||||
$(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $<
|
||||
|
||||
gzread.lo: gzread.c
|
||||
$(CC) $(SFLAGS) -DPIC -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $<
|
||||
|
||||
gzwrite.o: $(SRCDIR)/gzwrite.c
|
||||
$(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $<
|
||||
|
||||
gzwrite.lo: $(SRCDIR)/gzwrite.c
|
||||
$(CC) $(SFLAGS) -DPIC -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $<
|
||||
|
||||
$(SHAREDTARGET): $(PIC_OBJS) $(DEFFILE) $(RCOBJS)
|
||||
ifneq ($(SHAREDTARGET),)
|
||||
$(LDSHARED) $(CFLAGS) $(LDSHAREDFLAGS) $(LDVERSIONSCRIPT) $(LDFLAGS) -o $@ $(DEFFILE) $(PIC_OBJS) $(RCOBJS) $(LDSHAREDLIBC)
|
||||
ifneq ($(STRIP),)
|
||||
$(STRIP) $@
|
||||
endif
|
||||
ifneq ($(SHAREDLIB),$(SHAREDTARGET))
|
||||
rm -f $(SHAREDLIB) $(SHAREDLIBM)
|
||||
ln -s $@ $(SHAREDLIB)
|
||||
ln -s $@ $(SHAREDLIBM)
|
||||
endif
|
||||
endif
|
||||
|
||||
example$(EXE): example.o $(TESTOBJG) $(STATICLIB)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ example.o $(TESTOBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
|
||||
ifneq ($(STRIP),)
|
||||
$(STRIP) $@
|
||||
endif
|
||||
|
||||
minigzip$(EXE): minigzip.o $(TESTOBJG) $(STATICLIB)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip.o $(TESTOBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
|
||||
ifneq ($(STRIP),)
|
||||
$(STRIP) $@
|
||||
endif
|
||||
|
||||
minigzipsh$(EXE): minigzip.o $(PIC_TESTOBJG) $(SHAREDTARGET)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip.o $(PIC_TESTOBJG) $(SHAREDLIB) $(LDSHAREDLIBC)
|
||||
ifneq ($(STRIP),)
|
||||
$(STRIP) $@
|
||||
endif
|
||||
|
||||
|
||||
examplesh$(EXE): example.o $(PIC_TESTOBJG) $(SHAREDTARGET)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ example.o $(PIC_TESTOBJG) $(SHAREDLIB) $(LDSHAREDLIBC)
|
||||
ifneq ($(STRIP),)
|
||||
$(STRIP) $@
|
||||
endif
|
||||
|
||||
makefixed$(EXE): makefixed.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ makefixed.o $(TEST_LIBS) $(LDSHAREDLIBC)
|
||||
ifneq ($(STRIP),)
|
||||
$(STRIP) $@
|
||||
endif
|
||||
|
||||
maketrees$(EXE): maketrees.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ maketrees.o $(TEST_LIBS) $(LDSHAREDLIBC)
|
||||
ifneq ($(STRIP),)
|
||||
$(STRIP) $@
|
||||
endif
|
||||
|
||||
makecrct$(EXE): makecrct.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ makecrct.o $(TEST_LIBS) $(LDSHAREDLIBC)
|
||||
ifneq ($(STRIP),)
|
||||
$(STRIP) $@
|
||||
endif
|
||||
|
||||
install-shared: $(SHAREDTARGET)
|
||||
ifneq ($(SHAREDTARGET),)
|
||||
-@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi
|
||||
rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDTARGET)
|
||||
cp $(SHAREDTARGET) $(DESTDIR)$(sharedlibdir)
|
||||
chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDTARGET)
|
||||
ifneq ($(SHAREDLIB),$(SHAREDTARGET))
|
||||
rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM)
|
||||
ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB)
|
||||
ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM)
|
||||
($(LDCONFIG) || true) >/dev/null 2>&1
|
||||
# ldconfig is for Linux
|
||||
endif
|
||||
ifneq ($(IMPORTLIB),)
|
||||
cp $(IMPORTLIB) $(DESTDIR)$(sharedlibdir)
|
||||
chmod 644 $(DESTDIR)$(sharedlibdir)/$(IMPORTLIB)
|
||||
endif
|
||||
endif
|
||||
|
||||
install-static: $(STATICLIB)
|
||||
-@if [ ! -d $(DESTDIR)$(libdir) ]; then mkdir -p $(DESTDIR)$(libdir); fi
|
||||
rm -f $(DESTDIR)$(libdir)/$(STATICLIB)
|
||||
cp $(STATICLIB) $(DESTDIR)$(libdir)
|
||||
chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB)
|
||||
-@($(RANLIB) $(DESTDIR)$(libdir)/$(STATICLIB) || true) >/dev/null 2>&1
|
||||
# The ranlib in install-static is needed on NeXTSTEP which checks file times
|
||||
|
||||
install-libs: install-shared install-static
|
||||
-@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi
|
||||
-@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
|
||||
rm -f $(DESTDIR)$(pkgconfigdir)/$(PKGFILE)
|
||||
cp $(PKGFILE) $(DESTDIR)$(pkgconfigdir)
|
||||
chmod 644 $(DESTDIR)$(pkgconfigdir)/$(PKGFILE)
|
||||
|
||||
install: install-libs
|
||||
-@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi
|
||||
rm -f $(DESTDIR)$(includedir)/zlib$(SUFFIX).h $(DESTDIR)$(includedir)/zconf$(SUFFIX).h $(DESTDIR)$(includedir)/zlib_name_mangling$(SUFFIX).h
|
||||
cp zlib$(SUFFIX).h $(DESTDIR)$(includedir)/zlib$(SUFFIX).h
|
||||
cp zconf$(SUFFIX).h $(DESTDIR)$(includedir)/zconf$(SUFFIX).h
|
||||
cp zlib_name_mangling$(SUFFIX).h $(DESTDIR)$(includedir)/zlib_name_mangling$(SUFFIX).h
|
||||
chmod 644 $(DESTDIR)$(includedir)/zlib$(SUFFIX).h $(DESTDIR)$(includedir)/zconf$(SUFFIX).h $(DESTDIR)$(includedir)/zlib_name_mangling$(SUFFIX).h
|
||||
|
||||
uninstall-static:
|
||||
cd $(DESTDIR)$(libdir) && rm -f $(STATICLIB)
|
||||
|
||||
uninstall-shared:
|
||||
ifneq ($(SHAREDLIB),)
|
||||
cd $(DESTDIR)$(sharedlibdir) && rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM)
|
||||
endif
|
||||
ifneq ($(IMPORTLIB),)
|
||||
cd $(DESTDIR)$(sharedlibdir) && rm -f $(IMPORTLIB)
|
||||
endif
|
||||
|
||||
uninstall: uninstall-static uninstall-shared
|
||||
cd $(DESTDIR)$(includedir) && rm -f zlib$(SUFFIX).h zconf$(SUFFIX).h zlib_name_mangling$(SUFFIX).h
|
||||
cd $(DESTDIR)$(pkgconfigdir) && rm -f $(PKGFILE)
|
||||
|
||||
mostlyclean: clean
|
||||
clean:
|
||||
@if [ -f $(ARCHDIR)/Makefile ]; then $(MAKE) -C $(ARCHDIR) clean; fi
|
||||
@if [ -f arch/generic/Makefile ]; then $(MAKE) -C arch/generic clean; fi
|
||||
@if [ -f test/Makefile ]; then $(MAKE) -C test clean; fi
|
||||
rm -f *.o *.lo *~ \
|
||||
example$(EXE) minigzip$(EXE) minigzipsh$(EXE) \
|
||||
infcover makefixed$(EXE) maketrees$(EXE) makecrct$(EXE) \
|
||||
$(STATICLIB) $(IMPORTLIB) $(SHAREDLIB) $(SHAREDLIBV) $(SHAREDLIBM) \
|
||||
foo.gz so_locations \
|
||||
_match.s maketree
|
||||
rm -rf objs
|
||||
rm -f *.gcda *.gcno *.gcov
|
||||
rm -f a.out a.exe
|
||||
rm -f *._h
|
||||
rm -rf btmp1 btmp2 pkgtmp1 pkgtmp2
|
||||
|
||||
maintainer-clean: distclean
|
||||
distclean: clean
|
||||
@if [ -f $(ARCHDIR)/Makefile ]; then $(MAKE) -C $(ARCHDIR) distclean; fi
|
||||
@if [ -f test/Makefile ]; then $(MAKE) -C test distclean; fi
|
||||
rm -f $(PKGFILE) configure.log zconf.h zconf.h.cmakein zlib$(SUFFIX).h zlib_name_mangling$(SUFFIX).h *.pc gzread.c
|
||||
-@rm -f .DS_Store
|
||||
# Reset Makefile if building inside source tree
|
||||
@if [ -f Makefile.in ]; then \
|
||||
printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile ; \
|
||||
printf '\ndistclean:\n\t$(MAKE) -f Makefile.in distclean\n' >> Makefile ; \
|
||||
touch -r $(SRCDIR)/Makefile.in Makefile ; fi
|
||||
# Reset zconf.h and zconf.h.cmakein if building inside source tree
|
||||
@if [ -f zconf.h.in ]; then \
|
||||
cp -p $(SRCDIR)/zconf.h.in zconf.h ; \
|
||||
grep -v '^#cmakedefine' $(SRCDIR)/zconf.h.in > zconf.h.cmakein &&\
|
||||
touch -r $(SRCDIR)/zconf.h.in zconf.h.cmakein ; fi
|
||||
# Cleanup these files if building outside source tree
|
||||
@if [ ! -f README.md ]; then rm -f Makefile; fi
|
||||
# Remove arch and test directory if building outside source tree
|
||||
@if [ ! -f $(ARCHDIR)/Makefile.in ]; then rm -rf arch; fi
|
||||
@if [ ! -f test/Makefile.in ]; then rm -rf test; fi
|
||||
|
||||
tags:
|
||||
etags $(SRCDIR)/*.[ch]
|
||||
@@ -0,0 +1,111 @@
|
||||
Porting applications to use zlib-ng
|
||||
===================================
|
||||
|
||||
Zlib-ng can be used/compiled in two different modes, that require some
|
||||
consideration by the application developer.
|
||||
|
||||
Changes from zlib affecting native and compat modes
|
||||
---------------------------------------------------
|
||||
Zlib-ng is not as conservative with memory allocation as Zlib is.
|
||||
|
||||
Where Zlib's inflate will allocate a lower amount of memory depending on
|
||||
compression level and window size, zlib-ng will always allocate the maximum
|
||||
amount of memory and possibly leave parts of it unused.
|
||||
Zlib-ng's deflate will however allocate a lower amount of memory depending
|
||||
on compression level and window size.
|
||||
|
||||
Zlib-ng also allocates one "big" buffer instead of doing multiple smaller
|
||||
allocations. This is faster, can lead to better cache locality and reduces
|
||||
space lost to alignment padding.
|
||||
|
||||
At the time of writing, by default zlib-ng allocates the following amounts
|
||||
of memory on a 64-bit system (except on S390x that requires ~4KiB more):
|
||||
- Deflate: 350.272 Bytes
|
||||
- Inflate: 42.112 Bytes
|
||||
|
||||
**Advantages:**
|
||||
- All memory is allocated during DeflateInit or InflateInit functions,
|
||||
leaving the actual deflate/inflate functions free from allocations.
|
||||
- Zlib-ng can only fail from memory allocation errors during init.
|
||||
- Time spent doing memory allocation systemcalls is all done during init,
|
||||
allowing applications to do prepare this before doing latency-sensitive
|
||||
deflate/inflate later.
|
||||
- Can reduce wasted memory due to buffer alignment padding both by OS and zlib-ng.
|
||||
- Potentially improved memory locality.
|
||||
|
||||
**Disadvantages:**
|
||||
- Zlib-ng allocates a little more memory than zlib does.
|
||||
|
||||
zlib-compat mode
|
||||
----------------
|
||||
Zlib-ng can be compiled in zlib-compat mode, suitable for zlib-replacement
|
||||
in a single application or system-wide.
|
||||
|
||||
Please note that zlib-ng in zlib-compat mode tries to maintain both API and
|
||||
ABI compatibility with the original zlib. Any issues regarding compatibility
|
||||
can be reported as bugs.
|
||||
|
||||
In certain instances you may not be able to simply replace the zlib library/dll
|
||||
files and expect the application to work. The application may need to be
|
||||
recompiled against the zlib-ng headers and libs to ensure full compatibility.
|
||||
|
||||
It is also possible for the deflate output stream to differ from the original
|
||||
zlib due to algorithmic differences between the two libraries. Any tests or
|
||||
applications that depend on the exact length of the deflate stream being a
|
||||
certain value will need to be updated.
|
||||
|
||||
**Advantages:**
|
||||
- Easy to port to, since it only requires a recompile of the application and
|
||||
no changes to the application code.
|
||||
|
||||
**Disadvantages:**
|
||||
- Can conflict with a system-installed zlib, as that can often be linked in
|
||||
by another library you are linking into your application. This can cause
|
||||
crashes or incorrect output.
|
||||
- If your application is pre-allocating a memory buffer and you are providing
|
||||
deflate/inflate init with your own allocator that allocates from that buffer
|
||||
(looking at you nginx), you should be aware that zlib-ng needs to allocate
|
||||
more memory than stock zlib needs. The same problem exists with Intel’s and
|
||||
Cloudflare’s zlib forks. Doing this is not recommended since it makes it
|
||||
very hard to maintain compatibility over time.
|
||||
|
||||
**Build Considerations:**
|
||||
- Compile against the *zlib.h* provided by zlib-ng
|
||||
- Configuration header is named *zconf.h*
|
||||
- Static library is *libz.a* on Unix and macOS, or *zlib.lib* on Windows
|
||||
- Shared library is *libz.so* on Unix, *libz.dylib* on macOS, or *zlib1.dll*
|
||||
on Windows
|
||||
- Type `z_size_t` is *unsigned __int64* on 64-bit Windows, and *unsigned long* on 32-bit Windows, Unix and macOS
|
||||
- Type `z_uintmax_t` is *unsigned long* in zlib-compat mode, and *size_t* with zlib-ng API
|
||||
|
||||
zlib-ng native mode
|
||||
-------------------
|
||||
Zlib-ng in native mode is suitable for co-existing with the standard zlib
|
||||
library, allowing applications to implement support and testing separately.
|
||||
|
||||
The zlib-ng native has implemented some modernization and simplifications
|
||||
in its API, intended to make life easier for application developers.
|
||||
|
||||
**Advantages:**
|
||||
- Does not conflict with other zlib implementations, and can co-exist as a
|
||||
system library along with zlib.
|
||||
- In certain places zlib-ng native uses more appropriate data types, removing
|
||||
the need for some workarounds in the API compared to zlib.
|
||||
|
||||
**Disadvantages:**
|
||||
- Requires minor changes to applications to use the prefixed zlib-ng
|
||||
function calls and structs. Usually this means a small prefix `zng_` has to be added.
|
||||
|
||||
**Build Considerations:**
|
||||
- Compile against *zlib-ng.h*
|
||||
- Configuration header is named *zconf-ng.h*
|
||||
- Static library is *libz-ng.a* on Unix and macOS, or *zlib-ng.lib* on Windows
|
||||
- Shared library is *libz-ng.so* on Unix, *libz-ng.dylib* on macOS, or
|
||||
*zlib-ng2.dll* on Windows
|
||||
- Type `z_size_t` is *size_t*
|
||||
|
||||
zlib-ng compile-time detection
|
||||
------------------------------
|
||||
|
||||
To distinguish zlib-ng from other zlib implementations at compile-time check for the
|
||||
existence of `ZLIBNG_VERSION` defined in the zlib header.
|
||||
@@ -0,0 +1,228 @@
|
||||
| CI | Stable | Develop |
|
||||
|:---|:-------|:--------|
|
||||
| GitHub Actions | [](https://github.com/zlib-ng/zlib-ng/actions/workflows/cmake.yml?query=branch%3Astable) <br> [](https://github.com/zlib-ng/zlib-ng/actions/workflows/configure.yml?query=branch%3Astable) <br> [](https://github.com/zlib-ng/zlib-ng/actions/workflows/nmake.yml?query=branch%3Astable) | [](https://github.com/zlib-ng/zlib-ng/actions/workflows/cmake.yml?query=branch%3Adevelop) <br> [](https://github.com/zlib-ng/zlib-ng/actions/workflows/configure.yml?query=branch%3Adevelop) <br> [](https://github.com/zlib-ng/zlib-ng/actions/workflows/nmake.yml?query=branch%3Adevelop) |
|
||||
| CodeFactor | [](https://www.codefactor.io/repository/github/zlib-ng/zlib-ng/overview/stable) | [](https://www.codefactor.io/repository/github/zlib-ng/zlib-ng/overview/develop) |
|
||||
| OSS-Fuzz | [](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:zlib-ng) | [](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:zlib-ng) |
|
||||
| Codecov | [](https://codecov.io/github/zlib-ng/zlib-ng/tree/stable) | [](https://codecov.io/github/zlib-ng/zlib-ng/tree/develop) |
|
||||
|
||||
## zlib-ng
|
||||
*zlib data compression library for the next generation systems*
|
||||
|
||||
Maintained by Hans Kristian Rosbach
|
||||
aka Dead2 (zlib-ng àt circlestorm dót org)
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Zlib compatible API with support for dual-linking
|
||||
* Modernized native API based on zlib API for ease of porting
|
||||
* Modern C11 syntax and a clean code layout
|
||||
* Deflate medium and quick algorithms based on Intel’s zlib fork
|
||||
* Support for CPU intrinsics when available
|
||||
* Adler32 implementation using SSSE3, AVX2, AVX512, AVX512-VNNI, Neon, VMX & VSX
|
||||
* CRC32-B implementation using PCLMULQDQ, VPCLMULQDQ, ARMv8, & IBM Z
|
||||
* Slide hash implementations using SSE2, AVX2, ARMv6, Neon, VMX & VSX
|
||||
* Compare256 implementations using SSE2, AVX2, Neon, POWER9 & RVV
|
||||
* Inflate chunk copying using SSE2, SSSE3, AVX, Neon & VSX
|
||||
* Support for hardware-accelerated deflate using IBM Z DFLTCC
|
||||
* Safe unaligned memory read/writes and large bit buffer improvements
|
||||
* Includes improvements from Cloudflare and Intel forks
|
||||
* Configure, CMake, and NMake build system support
|
||||
* Comprehensive set of CMake unit tests
|
||||
* Code sanitizers, fuzzing, and coverage
|
||||
* GitHub Actions continuous integration on Windows, macOS, and Linux
|
||||
* Emulated CI for ARM, AARCH64, PPC, PPC64, RISCV, SPARC64, S390x using qemu
|
||||
|
||||
|
||||
History
|
||||
-------
|
||||
|
||||
The motivation for this fork was seeing several 3rd party contributions with new optimizations not getting
|
||||
implemented into the official zlib repository.
|
||||
|
||||
Mark Adler has been maintaining zlib for a very long time, and he has done a great job and hopefully he will continue
|
||||
for a long time yet. The idea of zlib-ng is not to replace zlib, but to co-exist as a drop-in replacement with a
|
||||
lower threshold for code change.
|
||||
|
||||
zlib has a long history and is incredibly portable, even supporting many systems that predate the Internet.<br>
|
||||
That is great, but it can complicate further development and maintainability. The zlib code contains many workarounds
|
||||
for really old compilers or to accommodate systems with limitations such as operating in a 16-bit environment.
|
||||
|
||||
Many of these workarounds are only maintenance burdens, some of them are pretty huge code-wise. With many workarounds
|
||||
cluttered throughout the code, it makes it harder for new programmers with an idea/interest for zlib to contribute.
|
||||
|
||||
I decided to make a fork, merge all the Intel optimizations, some of the Cloudflare optimizations, plus a couple other
|
||||
smaller patches. Then started cleaning out workarounds, various dead code, all contrib and example code.<br>
|
||||
The result is a better performing and easier to maintain zlib-ng.
|
||||
|
||||
A lot of improvements have gone into zlib-ng since its start, and numerous people and companies have contributed both
|
||||
small and big improvements, or valuable testing.
|
||||
|
||||
|
||||
Build
|
||||
-----
|
||||
<sup>Please read LICENSE.md, it is very simple and very liberal.</sup>
|
||||
|
||||
There are two ways to build zlib-ng:
|
||||
|
||||
### Cmake
|
||||
|
||||
To build zlib-ng using the cross-platform makefile generator cmake.
|
||||
|
||||
```
|
||||
cmake .
|
||||
cmake --build . --config Release
|
||||
ctest --verbose -C Release
|
||||
```
|
||||
|
||||
Alternatively, you can use the cmake configuration GUI tool ccmake:
|
||||
|
||||
```
|
||||
ccmake .
|
||||
```
|
||||
|
||||
### Configure
|
||||
|
||||
To build zlib-ng using the bash configure script:
|
||||
|
||||
```
|
||||
./configure
|
||||
make
|
||||
make test
|
||||
```
|
||||
|
||||
Build Options
|
||||
-------------
|
||||
|
||||
| CMake | configure | Description | Default |
|
||||
|:---------------------------|:-------------------------|:------------------------------------------------------------------------------------|---------|
|
||||
| ZLIB_COMPAT | --zlib-compat | Compile with zlib compatible API | OFF |
|
||||
| ZLIB_ENABLE_TESTS | | Build test binaries | ON |
|
||||
| WITH_GZFILEOP | --without-gzfileops | Compile with support for gzFile related functions | ON |
|
||||
| WITH_OPTIM | --without-optimizations | Build with optimisations | ON |
|
||||
| WITH_NEW_STRATEGIES | --without-new-strategies | Use new strategies | ON |
|
||||
| WITH_NATIVE_INSTRUCTIONS | | Compiles with full instruction set supported on this host (gcc/clang -march=native) | OFF |
|
||||
| WITH_RUNTIME_CPU_DETECTION | | Compiles with runtime CPU detection | ON |
|
||||
| WITH_SANITIZER | | Build with sanitizer (memory, address, undefined) | OFF |
|
||||
| WITH_GTEST | | Build gtest_zlib | ON |
|
||||
| WITH_FUZZERS | | Build test/fuzz | OFF |
|
||||
| WITH_BENCHMARKS | | Build test/benchmarks | OFF |
|
||||
| WITH_MAINTAINER_WARNINGS | | Build with project maintainer warnings | OFF |
|
||||
| WITH_CODE_COVERAGE | | Enable code coverage reporting | OFF |
|
||||
|
||||
|
||||
Install
|
||||
-------
|
||||
|
||||
WARNING: We do not recommend manually installing unless you really know what you are doing, because this can
|
||||
potentially override the system default zlib library, and any incompatibility or wrong configuration of zlib-ng
|
||||
can make the whole system unusable, requiring recovery or reinstall.
|
||||
If you still want a manual install, we recommend using the /opt/ path prefix.
|
||||
|
||||
For Linux distros, an alternative way to use zlib-ng (if compiled in zlib-compat mode) instead of zlib, is through
|
||||
the use of the _LD_PRELOAD_ environment variable. If the program is dynamically linked with zlib, then the program
|
||||
will temporarily attempt to use zlib-ng instead, without risking system-wide instability.
|
||||
|
||||
```
|
||||
LD_PRELOAD=/opt/zlib-ng/libz.so.1.2.13.zlib-ng /usr/bin/program
|
||||
```
|
||||
|
||||
### Cmake
|
||||
|
||||
To install zlib-ng system-wide using cmake:
|
||||
|
||||
```sh or powershell
|
||||
cmake --build . --target install
|
||||
```
|
||||
|
||||
### Configure
|
||||
|
||||
To install zlib-ng system-wide using the configure script:
|
||||
|
||||
```sh
|
||||
make install
|
||||
```
|
||||
|
||||
### CPack
|
||||
|
||||
After building with cmake, an installation package can be created using cpack. By default a tgz package is created,
|
||||
but you can append `-G <format>` to each command to generate alternative packages types (TGZ, ZIP, RPM, DEB). To easily
|
||||
create a rpm or deb package, you would use `-G RPM` or `-G DEB` respectively.
|
||||
|
||||
```sh or powershell
|
||||
cd build
|
||||
cpack --config CPackConfig.cmake
|
||||
cpack --config CPackSourceConfig.cmake
|
||||
```
|
||||
|
||||
### Vcpkg
|
||||
|
||||
Alternatively, you can build and install zlib-ng using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
|
||||
|
||||
```sh or powershell
|
||||
git clone https://github.com/Microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
./bootstrap-vcpkg.sh # "./bootstrap-vcpkg.bat" for powershell
|
||||
./vcpkg integrate install
|
||||
./vcpkg install zlib-ng
|
||||
```
|
||||
|
||||
The zlib-ng port in vcpkg is kept up to date by Microsoft team members and community contributors.
|
||||
If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
Zlib-ng is aiming to be open to contributions, and we would be delighted to receive pull requests on github.
|
||||
Help with testing and reviewing pull requests etc is also very much appreciated.
|
||||
|
||||
Please check the Wiki for more info: [Contributing](https://github.com/zlib-ng/zlib-ng/wiki/Contributing)
|
||||
|
||||
Acknowledgments
|
||||
----------------
|
||||
|
||||
Thanks go out to all the people and companies who have taken the time to contribute
|
||||
code reviews, testing and/or patches. Zlib-ng would not have been nearly as good without you.
|
||||
|
||||
The deflate format used by zlib was defined by Phil Katz.<br>
|
||||
The deflate and zlib specifications were written by L. Peter Deutsch.
|
||||
|
||||
zlib was originally created by Jean-loup Gailly (compression) and Mark Adler (decompression).
|
||||
|
||||
|
||||
Advanced Build Options
|
||||
----------------------
|
||||
|
||||
| CMake | configure | Description | Default |
|
||||
|:--------------------------------|:----------------------|:--------------------------------------------------------------------|------------------------|
|
||||
| FORCE_SSE2 | --force-sse2 | Skip runtime check for SSE2 instructions (Always on for x86_64) | OFF (x86) |
|
||||
| WITH_AVX2 | | Build with AVX2 intrinsics | ON |
|
||||
| WITH_AVX512 | | Build with AVX512 intrinsics | ON |
|
||||
| WITH_AVX512VNNI | | Build with AVX512VNNI intrinsics | ON |
|
||||
| WITH_SSE2 | | Build with SSE2 intrinsics | ON |
|
||||
| WITH_SSSE3 | | Build with SSSE3 intrinsics | ON |
|
||||
| WITH_SSE42 | | Build with SSE42 intrinsics | ON |
|
||||
| WITH_PCLMULQDQ | | Build with PCLMULQDQ intrinsics | ON |
|
||||
| WITH_VPCLMULQDQ | --without-vpclmulqdq | Build with VPCLMULQDQ intrinsics | ON |
|
||||
| WITH_ARMV8 | --without-armv8 | Build with ARMv8 intrinsics | ON |
|
||||
| WITH_NEON | --without-neon | Build with NEON intrinsics | ON |
|
||||
| WITH_ARMV6 | --without-armv6 | Build with ARMv6 intrinsics | ON |
|
||||
| WITH_ALTIVEC | --without-altivec | Build with AltiVec (VMX) intrinsics | ON |
|
||||
| WITH_POWER8 | --without-power8 | Build with POWER8 optimisations | ON |
|
||||
| WITH_RVV | | Build with RVV intrinsics | ON |
|
||||
| WITH_CRC32_VX | --without-crc32-vx | Build with vectorized CRC32 on IBM Z | ON |
|
||||
| WITH_DFLTCC_DEFLATE | --with-dfltcc-deflate | Build with DFLTCC intrinsics for compression on IBM Z | OFF |
|
||||
| WITH_DFLTCC_INFLATE | --with-dfltcc-inflate | Build with DFLTCC intrinsics for decompression on IBM Z | OFF |
|
||||
| WITH_INFLATE_STRICT | | Build with strict inflate distance checking | OFF |
|
||||
| WITH_INFLATE_ALLOW_INVALID_DIST | | Build with zero fill for inflate invalid distances | OFF |
|
||||
| INSTALL_UTILS | | Copy minigzip and minideflate during install | OFF |
|
||||
| ZLIBNG_ENABLE_TESTS | | Test zlib-ng specific API | ON |
|
||||
|
||||
|
||||
Related Projects
|
||||
----------------
|
||||
|
||||
* Fork of the popular minizip https://github.com/zlib-ng/minizip-ng
|
||||
* Python tool to benchmark minigzip/minideflate https://github.com/zlib-ng/deflatebench
|
||||
* Python tool to benchmark pigz https://github.com/zlib-ng/pigzbench
|
||||
* 3rd party patches for zlib-ng compatibility https://github.com/zlib-ng/patches
|
||||
+33
-128
@@ -3,148 +3,47 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
#include "zbuild.h"
|
||||
#include "functable.h"
|
||||
#include "adler32_p.h"
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
#define BASE 65521U /* largest prime smaller than 65536 */
|
||||
#define NMAX 5552
|
||||
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||
|
||||
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
|
||||
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
|
||||
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
|
||||
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
||||
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
||||
|
||||
/* use NO_DIVIDE if your processor does not do division in hardware --
|
||||
try it both ways to see which is faster */
|
||||
#ifdef NO_DIVIDE
|
||||
/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
|
||||
(thank you to John Reiser for pointing this out) */
|
||||
# define CHOP(a) \
|
||||
do { \
|
||||
unsigned long tmp = a >> 16; \
|
||||
a &= 0xffffUL; \
|
||||
a += (tmp << 4) - tmp; \
|
||||
} while (0)
|
||||
# define MOD28(a) \
|
||||
do { \
|
||||
CHOP(a); \
|
||||
if (a >= BASE) a -= BASE; \
|
||||
} while (0)
|
||||
# define MOD(a) \
|
||||
do { \
|
||||
CHOP(a); \
|
||||
MOD28(a); \
|
||||
} while (0)
|
||||
# define MOD63(a) \
|
||||
do { /* this assumes a is not negative */ \
|
||||
z_off64_t tmp = a >> 32; \
|
||||
a &= 0xffffffffL; \
|
||||
a += (tmp << 8) - (tmp << 5) + tmp; \
|
||||
tmp = a >> 16; \
|
||||
a &= 0xffffL; \
|
||||
a += (tmp << 4) - tmp; \
|
||||
tmp = a >> 16; \
|
||||
a &= 0xffffL; \
|
||||
a += (tmp << 4) - tmp; \
|
||||
if (a >= BASE) a -= BASE; \
|
||||
} while (0)
|
||||
#ifdef ZLIB_COMPAT
|
||||
unsigned long Z_EXPORT PREFIX(adler32_z)(unsigned long adler, const unsigned char *buf, size_t len) {
|
||||
return (unsigned long)FUNCTABLE_CALL(adler32)((uint32_t)adler, buf, len);
|
||||
}
|
||||
#else
|
||||
# define MOD(a) a %= BASE
|
||||
# define MOD28(a) a %= BASE
|
||||
# define MOD63(a) a %= BASE
|
||||
uint32_t Z_EXPORT PREFIX(adler32_z)(uint32_t adler, const unsigned char *buf, size_t len) {
|
||||
return FUNCTABLE_CALL(adler32)(adler, buf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
|
||||
unsigned long sum2;
|
||||
unsigned n;
|
||||
|
||||
/* split Adler-32 into component sums */
|
||||
sum2 = (adler >> 16) & 0xffff;
|
||||
adler &= 0xffff;
|
||||
|
||||
/* in case user likes doing a byte at a time, keep it fast */
|
||||
if (len == 1) {
|
||||
adler += buf[0];
|
||||
if (adler >= BASE)
|
||||
adler -= BASE;
|
||||
sum2 += adler;
|
||||
if (sum2 >= BASE)
|
||||
sum2 -= BASE;
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
/* initial Adler-32 value (deferred check for len == 1 speed) */
|
||||
if (buf == Z_NULL)
|
||||
return 1L;
|
||||
|
||||
/* in case short lengths are provided, keep it somewhat fast */
|
||||
if (len < 16) {
|
||||
while (len--) {
|
||||
adler += *buf++;
|
||||
sum2 += adler;
|
||||
}
|
||||
if (adler >= BASE)
|
||||
adler -= BASE;
|
||||
MOD28(sum2); /* only added so many BASE's */
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
/* do length NMAX blocks -- requires just one modulo operation */
|
||||
while (len >= NMAX) {
|
||||
len -= NMAX;
|
||||
n = NMAX / 16; /* NMAX is divisible by 16 */
|
||||
do {
|
||||
DO16(buf); /* 16 sums unrolled */
|
||||
buf += 16;
|
||||
} while (--n);
|
||||
MOD(adler);
|
||||
MOD(sum2);
|
||||
}
|
||||
|
||||
/* do remaining bytes (less than NMAX, still just one modulo) */
|
||||
if (len) { /* avoid modulos if none remaining */
|
||||
while (len >= 16) {
|
||||
len -= 16;
|
||||
DO16(buf);
|
||||
buf += 16;
|
||||
}
|
||||
while (len--) {
|
||||
adler += *buf++;
|
||||
sum2 += adler;
|
||||
}
|
||||
MOD(adler);
|
||||
MOD(sum2);
|
||||
}
|
||||
|
||||
/* return recombined sums */
|
||||
return adler | (sum2 << 16);
|
||||
#ifdef ZLIB_COMPAT
|
||||
unsigned long Z_EXPORT PREFIX(adler32)(unsigned long adler, const unsigned char *buf, unsigned int len) {
|
||||
return (unsigned long)FUNCTABLE_CALL(adler32)((uint32_t)adler, buf, len);
|
||||
}
|
||||
#else
|
||||
uint32_t Z_EXPORT PREFIX(adler32)(uint32_t adler, const unsigned char *buf, uint32_t len) {
|
||||
return FUNCTABLE_CALL(adler32)(adler, buf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
|
||||
return adler32_z(adler, buf, len);
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
|
||||
unsigned long sum1;
|
||||
unsigned long sum2;
|
||||
static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len2) {
|
||||
uint32_t sum1;
|
||||
uint32_t sum2;
|
||||
unsigned rem;
|
||||
|
||||
/* for negative len, return invalid adler32 as a clue for debugging */
|
||||
if (len2 < 0)
|
||||
return 0xffffffffUL;
|
||||
return 0xffffffff;
|
||||
|
||||
/* the derivation of this formula is left as an exercise for the reader */
|
||||
MOD63(len2); /* assumes len2 >= 0 */
|
||||
len2 %= BASE; /* assumes len2 >= 0 */
|
||||
rem = (unsigned)len2;
|
||||
sum1 = adler1 & 0xffff;
|
||||
sum2 = rem * sum1;
|
||||
MOD(sum2);
|
||||
sum2 %= BASE;
|
||||
sum1 += (adler2 & 0xffff) + BASE - 1;
|
||||
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
|
||||
if (sum1 >= BASE) sum1 -= BASE;
|
||||
@@ -155,10 +54,16 @@ local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) {
|
||||
return adler32_combine_(adler1, adler2, len2);
|
||||
#ifdef ZLIB_COMPAT
|
||||
unsigned long Z_EXPORT PREFIX(adler32_combine)(unsigned long adler1, unsigned long adler2, z_off_t len2) {
|
||||
return (unsigned long)adler32_combine_((uint32_t)adler1, (uint32_t)adler2, len2);
|
||||
}
|
||||
|
||||
uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) {
|
||||
unsigned long Z_EXPORT PREFIX4(adler32_combine)(unsigned long adler1, unsigned long adler2, z_off64_t len2) {
|
||||
return (unsigned long)adler32_combine_((uint32_t)adler1, (uint32_t)adler2, len2);
|
||||
}
|
||||
#else
|
||||
uint32_t Z_EXPORT PREFIX4(adler32_combine)(uint32_t adler1, uint32_t adler2, z_off64_t len2) {
|
||||
return adler32_combine_(adler1, adler2, len2);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,70 @@
|
||||
/* adler32_p.h -- Private inline functions and macros shared with
|
||||
* different computation of the Adler-32 checksum
|
||||
* of a data stream.
|
||||
* Copyright (C) 1995-2011, 2016 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef ADLER32_P_H
|
||||
#define ADLER32_P_H
|
||||
|
||||
#define BASE 65521U /* largest prime smaller than 65536 */
|
||||
#define NMAX 5552
|
||||
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||
|
||||
#define ADLER_DO1(sum1, sum2, buf, i) {(sum1) += buf[(i)]; (sum2) += (sum1);}
|
||||
#define ADLER_DO2(sum1, sum2, buf, i) {ADLER_DO1(sum1, sum2, buf, i); ADLER_DO1(sum1, sum2, buf, i+1);}
|
||||
#define ADLER_DO4(sum1, sum2, buf, i) {ADLER_DO2(sum1, sum2, buf, i); ADLER_DO2(sum1, sum2, buf, i+2);}
|
||||
#define ADLER_DO8(sum1, sum2, buf, i) {ADLER_DO4(sum1, sum2, buf, i); ADLER_DO4(sum1, sum2, buf, i+4);}
|
||||
#define ADLER_DO16(sum1, sum2, buf) {ADLER_DO8(sum1, sum2, buf, 0); ADLER_DO8(sum1, sum2, buf, 8);}
|
||||
|
||||
static inline uint32_t adler32_len_1(uint32_t adler, const uint8_t *buf, uint32_t sum2) {
|
||||
adler += buf[0];
|
||||
adler %= BASE;
|
||||
sum2 += adler;
|
||||
sum2 %= BASE;
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
static inline uint32_t adler32_len_16(uint32_t adler, const uint8_t *buf, size_t len, uint32_t sum2) {
|
||||
while (len) {
|
||||
--len;
|
||||
adler += *buf++;
|
||||
sum2 += adler;
|
||||
}
|
||||
adler %= BASE;
|
||||
sum2 %= BASE; /* only added so many BASE's */
|
||||
/* return recombined sums */
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
static inline uint32_t adler32_copy_len_16(uint32_t adler, const uint8_t *buf, uint8_t *dst, size_t len, uint32_t sum2) {
|
||||
while (len--) {
|
||||
*dst = *buf++;
|
||||
adler += *dst++;
|
||||
sum2 += adler;
|
||||
}
|
||||
adler %= BASE;
|
||||
sum2 %= BASE; /* only added so many BASE's */
|
||||
/* return recombined sums */
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
static inline uint32_t adler32_len_64(uint32_t adler, const uint8_t *buf, size_t len, uint32_t sum2) {
|
||||
#ifdef UNROLL_MORE
|
||||
while (len >= 16) {
|
||||
len -= 16;
|
||||
ADLER_DO16(adler, sum2, buf);
|
||||
buf += 16;
|
||||
#else
|
||||
while (len >= 8) {
|
||||
len -= 8;
|
||||
ADLER_DO8(adler, sum2, buf, 0);
|
||||
buf += 8;
|
||||
#endif
|
||||
}
|
||||
/* Process tail (len < 16). */
|
||||
return adler32_len_16(adler, buf, len, sum2);
|
||||
}
|
||||
|
||||
#endif /* ADLER32_P_H */
|
||||
@@ -0,0 +1,29 @@
|
||||
/* arch_functions.h -- Arch-specific function prototypes.
|
||||
* Copyright (C) 2017 Hans Kristian Rosbach
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef CPU_FUNCTIONS_H_
|
||||
#define CPU_FUNCTIONS_H_
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "zutil.h"
|
||||
#include "crc32.h"
|
||||
#include "deflate.h"
|
||||
#include "fallback_builtins.h"
|
||||
|
||||
#include "arch/generic/generic_functions.h"
|
||||
|
||||
#if defined(X86_FEATURES)
|
||||
# include "arch/x86/x86_functions.h"
|
||||
#elif defined(ARM_FEATURES)
|
||||
# include "arch/arm/arm_functions.h"
|
||||
#elif defined(PPC_FEATURES) || defined(POWER_FEATURES)
|
||||
# include "arch/power/power_functions.h"
|
||||
#elif defined(S390_FEATURES)
|
||||
# include "arch/s390/s390_functions.h"
|
||||
#elif defined(RISCV_FEATURES)
|
||||
# include "arch/riscv/riscv_functions.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,283 @@
|
||||
/* chunkset_tpl.h -- inline functions to copy small data chunks.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Returns the chunk size */
|
||||
Z_INTERNAL uint32_t CHUNKSIZE(void) {
|
||||
return sizeof(chunk_t);
|
||||
}
|
||||
|
||||
/* Behave like memcpy, but assume that it's OK to overwrite at least
|
||||
chunk_t bytes of output even if the length is shorter than this,
|
||||
that the length is non-zero, and that `from` lags `out` by at least
|
||||
sizeof chunk_t bytes (or that they don't overlap at all or simply that
|
||||
the distance is less than the length of the copy).
|
||||
|
||||
Aside from better memory bus utilisation, this means that short copies
|
||||
(chunk_t bytes or fewer) will fall straight through the loop
|
||||
without iteration, which will hopefully make the branch prediction more
|
||||
reliable. */
|
||||
#ifndef HAVE_CHUNKCOPY
|
||||
static inline uint8_t* CHUNKCOPY(uint8_t *out, uint8_t const *from, unsigned len) {
|
||||
Assert(len > 0, "chunkcopy should never have a length 0");
|
||||
chunk_t chunk;
|
||||
int32_t align = ((len - 1) % sizeof(chunk_t)) + 1;
|
||||
loadchunk(from, &chunk);
|
||||
storechunk(out, &chunk);
|
||||
out += align;
|
||||
from += align;
|
||||
len -= align;
|
||||
while (len > 0) {
|
||||
loadchunk(from, &chunk);
|
||||
storechunk(out, &chunk);
|
||||
out += sizeof(chunk_t);
|
||||
from += sizeof(chunk_t);
|
||||
len -= sizeof(chunk_t);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Perform short copies until distance can be rewritten as being at least
|
||||
sizeof chunk_t.
|
||||
|
||||
This assumes that it's OK to overwrite at least the first
|
||||
2*sizeof(chunk_t) bytes of output even if the copy is shorter than this.
|
||||
This assumption holds because inflate_fast() starts every iteration with at
|
||||
least 258 bytes of output space available (258 being the maximum length
|
||||
output from a single token; see inflate_fast()'s assumptions below). */
|
||||
#ifndef HAVE_CHUNKUNROLL
|
||||
static inline uint8_t* CHUNKUNROLL(uint8_t *out, unsigned *dist, unsigned *len) {
|
||||
unsigned char const *from = out - *dist;
|
||||
chunk_t chunk;
|
||||
while (*dist < *len && *dist < sizeof(chunk_t)) {
|
||||
loadchunk(from, &chunk);
|
||||
storechunk(out, &chunk);
|
||||
out += *dist;
|
||||
*len -= *dist;
|
||||
*dist += *dist;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_CHUNK_MAG
|
||||
/* Loads a magazine to feed into memory of the pattern */
|
||||
static inline chunk_t GET_CHUNK_MAG(uint8_t *buf, uint32_t *chunk_rem, uint32_t dist) {
|
||||
/* This code takes string of length dist from "from" and repeats
|
||||
* it for as many times as can fit in a chunk_t (vector register) */
|
||||
uint64_t cpy_dist;
|
||||
uint64_t bytes_remaining = sizeof(chunk_t);
|
||||
chunk_t chunk_load;
|
||||
uint8_t *cur_chunk = (uint8_t *)&chunk_load;
|
||||
while (bytes_remaining) {
|
||||
cpy_dist = MIN(dist, bytes_remaining);
|
||||
memcpy(cur_chunk, buf, (size_t)cpy_dist);
|
||||
bytes_remaining -= cpy_dist;
|
||||
cur_chunk += cpy_dist;
|
||||
/* This allows us to bypass an expensive integer division since we're effectively
|
||||
* counting in this loop, anyway */
|
||||
*chunk_rem = (uint32_t)cpy_dist;
|
||||
}
|
||||
|
||||
return chunk_load;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_HALF_CHUNK) && !defined(HAVE_HALFCHUNKCOPY)
|
||||
static inline uint8_t* HALFCHUNKCOPY(uint8_t *out, uint8_t const *from, unsigned len) {
|
||||
halfchunk_t chunk;
|
||||
int32_t align = ((len - 1) % sizeof(halfchunk_t)) + 1;
|
||||
loadhalfchunk(from, &chunk);
|
||||
storehalfchunk(out, &chunk);
|
||||
out += align;
|
||||
from += align;
|
||||
len -= align;
|
||||
while (len > 0) {
|
||||
loadhalfchunk(from, &chunk);
|
||||
storehalfchunk(out, &chunk);
|
||||
out += sizeof(halfchunk_t);
|
||||
from += sizeof(halfchunk_t);
|
||||
len -= sizeof(halfchunk_t);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Copy DIST bytes from OUT - DIST into OUT + DIST * k, for 0 <= k < LEN/DIST.
|
||||
Return OUT + LEN. */
|
||||
static inline uint8_t* CHUNKMEMSET(uint8_t *out, uint8_t *from, unsigned len) {
|
||||
/* Debug performance related issues when len < sizeof(uint64_t):
|
||||
Assert(len >= sizeof(uint64_t), "chunkmemset should be called on larger chunks"); */
|
||||
Assert(from != out, "chunkmemset cannot have a distance 0");
|
||||
|
||||
chunk_t chunk_load;
|
||||
uint32_t chunk_mod = 0;
|
||||
uint32_t adv_amount;
|
||||
int64_t sdist = out - from;
|
||||
uint64_t dist = llabs(sdist);
|
||||
|
||||
/* We are supporting the case for when we are reading bytes from ahead in the buffer.
|
||||
* We now have to handle this, though it wasn't _quite_ clear if this rare circumstance
|
||||
* always needed to be handled here or if we're just now seeing it because we are
|
||||
* dispatching to this function, more */
|
||||
if (sdist < 0 && dist < len) {
|
||||
#ifdef HAVE_MASKED_READWRITE
|
||||
/* We can still handle this case if we can mitigate over writing _and_ we
|
||||
* fit the entirety of the copy length with one load */
|
||||
if (len <= sizeof(chunk_t)) {
|
||||
/* Tempting to add a goto to the block below but hopefully most compilers
|
||||
* collapse these identical code segments as one label to jump to */
|
||||
return CHUNKCOPY(out, from, len);
|
||||
}
|
||||
#endif
|
||||
/* Here the memmove semantics match perfectly, as when this happens we are
|
||||
* effectively sliding down the contents of memory by dist bytes */
|
||||
memmove(out, from, len);
|
||||
return out + len;
|
||||
}
|
||||
|
||||
if (dist == 1) {
|
||||
memset(out, *from, len);
|
||||
return out + len;
|
||||
} else if (dist >= sizeof(chunk_t)) {
|
||||
return CHUNKCOPY(out, from, len);
|
||||
}
|
||||
|
||||
/* Only AVX2+ as there's 128 bit vectors and 256 bit. We allow for shorter vector
|
||||
* lengths because they serve to allow more cases to fall into chunkcopy, as the
|
||||
* distance of the shorter length is still deemed a safe distance. We rewrite this
|
||||
* here rather than calling the ssse3 variant directly now because doing so required
|
||||
* dispatching to another function and broke inlining for this function entirely. We
|
||||
* also can merge an assert and some remainder peeling behavior into the same code blocks,
|
||||
* making the code a little smaller. */
|
||||
#ifdef HAVE_HALF_CHUNK
|
||||
if (len <= sizeof(halfchunk_t)) {
|
||||
if (dist >= sizeof(halfchunk_t))
|
||||
return HALFCHUNKCOPY(out, from, len);
|
||||
|
||||
if ((dist % 2) != 0 || dist == 6) {
|
||||
halfchunk_t halfchunk_load = GET_HALFCHUNK_MAG(from, &chunk_mod, (unsigned)dist);
|
||||
|
||||
if (len == sizeof(halfchunk_t)) {
|
||||
storehalfchunk(out, &halfchunk_load);
|
||||
len -= sizeof(halfchunk_t);
|
||||
out += sizeof(halfchunk_t);
|
||||
}
|
||||
|
||||
chunk_load = halfchunk2whole(&halfchunk_load);
|
||||
goto rem_bytes;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CHUNKMEMSET_2
|
||||
if (dist == 2) {
|
||||
chunkmemset_2(from, &chunk_load);
|
||||
} else
|
||||
#endif
|
||||
#ifdef HAVE_CHUNKMEMSET_4
|
||||
if (dist == 4) {
|
||||
chunkmemset_4(from, &chunk_load);
|
||||
} else
|
||||
#endif
|
||||
#ifdef HAVE_CHUNKMEMSET_8
|
||||
if (dist == 8) {
|
||||
chunkmemset_8(from, &chunk_load);
|
||||
} else
|
||||
#endif
|
||||
#ifdef HAVE_CHUNKMEMSET_16
|
||||
if (dist == 16) {
|
||||
chunkmemset_16(from, &chunk_load);
|
||||
} else
|
||||
#endif
|
||||
chunk_load = GET_CHUNK_MAG(from, &chunk_mod, (unsigned)dist);
|
||||
|
||||
adv_amount = sizeof(chunk_t) - chunk_mod;
|
||||
|
||||
while (len >= (2 * sizeof(chunk_t))) {
|
||||
storechunk(out, &chunk_load);
|
||||
storechunk(out + adv_amount, &chunk_load);
|
||||
out += 2 * adv_amount;
|
||||
len -= 2 * adv_amount;
|
||||
}
|
||||
|
||||
/* If we don't have a "dist" length that divides evenly into a vector
|
||||
* register, we can write the whole vector register but we need only
|
||||
* advance by the amount of the whole string that fits in our chunk_t.
|
||||
* If we do divide evenly into the vector length, adv_amount = chunk_t size*/
|
||||
while (len >= sizeof(chunk_t)) {
|
||||
storechunk(out, &chunk_load);
|
||||
len -= adv_amount;
|
||||
out += adv_amount;
|
||||
}
|
||||
|
||||
#ifdef HAVE_HALF_CHUNK
|
||||
rem_bytes:
|
||||
#endif
|
||||
if (len) {
|
||||
memcpy(out, &chunk_load, len);
|
||||
out += len;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
Z_INTERNAL uint8_t* CHUNKMEMSET_SAFE(uint8_t *out, uint8_t *from, unsigned len, unsigned left) {
|
||||
#if OPTIMAL_CMP < 32
|
||||
static const uint32_t align_mask = 7;
|
||||
#elif OPTIMAL_CMP == 32
|
||||
static const uint32_t align_mask = 3;
|
||||
#endif
|
||||
|
||||
len = MIN(len, left);
|
||||
|
||||
#if OPTIMAL_CMP < 64
|
||||
while (((uintptr_t)out & align_mask) && (len > 0)) {
|
||||
*out++ = *from++;
|
||||
--len;
|
||||
--left;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MASKED_READWRITE
|
||||
if (UNLIKELY(left < sizeof(chunk_t))) {
|
||||
while (len > 0) {
|
||||
*out++ = *from++;
|
||||
--len;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (len)
|
||||
out = CHUNKMEMSET(out, from, len);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline uint8_t *CHUNKCOPY_SAFE(uint8_t *out, uint8_t *from, uint64_t len, uint8_t *safe)
|
||||
{
|
||||
if (out == from)
|
||||
return out + len;
|
||||
|
||||
uint64_t safelen = (safe - out);
|
||||
len = MIN(len, safelen);
|
||||
|
||||
#ifndef HAVE_MASKED_READWRITE
|
||||
uint64_t from_dist = (uint64_t)llabs(safe - from);
|
||||
if (UNLIKELY(from_dist < sizeof(chunk_t) || safelen < sizeof(chunk_t))) {
|
||||
while (len--) {
|
||||
*out++ = *from++;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
return CHUNKMEMSET(out, from, (unsigned)len);
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/* compare256_rle.h -- 256 byte run-length encoding comparison
|
||||
* Copyright (C) 2022 Nathan Moinvaziri
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "zmemory.h"
|
||||
#include "fallback_builtins.h"
|
||||
|
||||
typedef uint32_t (*compare256_rle_func)(const uint8_t* src0, const uint8_t* src1);
|
||||
|
||||
/* 8-bit integer comparison */
|
||||
static inline uint32_t compare256_rle_8(const uint8_t *src0, const uint8_t *src1) {
|
||||
uint32_t len = 0;
|
||||
|
||||
do {
|
||||
if (*src0 != *src1)
|
||||
return len;
|
||||
src1 += 1, len += 1;
|
||||
if (*src0 != *src1)
|
||||
return len;
|
||||
src1 += 1, len += 1;
|
||||
if (*src0 != *src1)
|
||||
return len;
|
||||
src1 += 1, len += 1;
|
||||
if (*src0 != *src1)
|
||||
return len;
|
||||
src1 += 1, len += 1;
|
||||
if (*src0 != *src1)
|
||||
return len;
|
||||
src1 += 1, len += 1;
|
||||
if (*src0 != *src1)
|
||||
return len;
|
||||
src1 += 1, len += 1;
|
||||
if (*src0 != *src1)
|
||||
return len;
|
||||
src1 += 1, len += 1;
|
||||
if (*src0 != *src1)
|
||||
return len;
|
||||
src1 += 1, len += 1;
|
||||
} while (len < 256);
|
||||
|
||||
return 256;
|
||||
}
|
||||
|
||||
/* 16-bit integer comparison */
|
||||
static inline uint32_t compare256_rle_16(const uint8_t *src0, const uint8_t *src1) {
|
||||
uint32_t len = 0;
|
||||
uint16_t src0_cmp;
|
||||
|
||||
src0_cmp = zng_memread_2(src0);
|
||||
|
||||
do {
|
||||
if (src0_cmp != zng_memread_2(src1))
|
||||
return len + (*src0 == *src1);
|
||||
src1 += 2, len += 2;
|
||||
if (src0_cmp != zng_memread_2(src1))
|
||||
return len + (*src0 == *src1);
|
||||
src1 += 2, len += 2;
|
||||
if (src0_cmp != zng_memread_2(src1))
|
||||
return len + (*src0 == *src1);
|
||||
src1 += 2, len += 2;
|
||||
if (src0_cmp != zng_memread_2(src1))
|
||||
return len + (*src0 == *src1);
|
||||
src1 += 2, len += 2;
|
||||
} while (len < 256);
|
||||
|
||||
return 256;
|
||||
}
|
||||
|
||||
#ifdef HAVE_BUILTIN_CTZ
|
||||
/* 32-bit integer comparison */
|
||||
static inline uint32_t compare256_rle_32(const uint8_t *src0, const uint8_t *src1) {
|
||||
uint32_t sv, len = 0;
|
||||
uint16_t src0_cmp;
|
||||
|
||||
src0_cmp = zng_memread_2(src0);
|
||||
sv = ((uint32_t)src0_cmp << 16) | src0_cmp;
|
||||
|
||||
do {
|
||||
uint32_t mv, diff;
|
||||
|
||||
mv = zng_memread_4(src1);
|
||||
|
||||
diff = sv ^ mv;
|
||||
if (diff) {
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
uint32_t match_byte = __builtin_ctz(diff) / 8;
|
||||
#else
|
||||
uint32_t match_byte = __builtin_clz(diff) / 8;
|
||||
#endif
|
||||
return len + match_byte;
|
||||
}
|
||||
|
||||
src1 += 4, len += 4;
|
||||
} while (len < 256);
|
||||
|
||||
return 256;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_BUILTIN_CTZLL
|
||||
/* 64-bit integer comparison */
|
||||
static inline uint32_t compare256_rle_64(const uint8_t *src0, const uint8_t *src1) {
|
||||
uint32_t src0_cmp32, len = 0;
|
||||
uint16_t src0_cmp;
|
||||
uint64_t sv;
|
||||
|
||||
src0_cmp = zng_memread_2(src0);
|
||||
src0_cmp32 = ((uint32_t)src0_cmp << 16) | src0_cmp;
|
||||
sv = ((uint64_t)src0_cmp32 << 32) | src0_cmp32;
|
||||
|
||||
do {
|
||||
uint64_t mv, diff;
|
||||
|
||||
mv = zng_memread_8(src1);
|
||||
|
||||
diff = sv ^ mv;
|
||||
if (diff) {
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
uint64_t match_byte = __builtin_ctzll(diff) / 8;
|
||||
#else
|
||||
uint64_t match_byte = __builtin_clzll(diff) / 8;
|
||||
#endif
|
||||
return len + (uint32_t)match_byte;
|
||||
}
|
||||
|
||||
src1 += 8, len += 8;
|
||||
} while (len < 256);
|
||||
|
||||
return 256;
|
||||
}
|
||||
#endif
|
||||
+48
-25
@@ -3,10 +3,19 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
#include "zbuild.h"
|
||||
#include "zutil.h"
|
||||
|
||||
#define ZLIB_INTERNAL
|
||||
#include "zlib.h"
|
||||
/* ===========================================================================
|
||||
* Architecture-specific hooks.
|
||||
*/
|
||||
#ifdef S390_DFLTCC_DEFLATE
|
||||
# include "arch/s390/dfltcc_common.h"
|
||||
#else
|
||||
/* Returns the upper bound on compressed data length based on uncompressed data length, assuming default settings.
|
||||
* Zero means that arch-specific deflation code behaves identically to the regular zlib-ng algorithms. */
|
||||
# define DEFLATE_BOUND_COMPLEN(source_len) 0
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
Compresses the source buffer into the destination buffer. The level
|
||||
@@ -19,57 +28,71 @@
|
||||
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||
Z_STREAM_ERROR if the level parameter is invalid.
|
||||
*/
|
||||
int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||
uLong sourceLen, int level) {
|
||||
z_stream stream;
|
||||
int Z_EXPORT PREFIX(compress2)(unsigned char *dest, z_uintmax_t *destLen, const unsigned char *source,
|
||||
z_uintmax_t sourceLen, int level) {
|
||||
PREFIX3(stream) stream;
|
||||
int err;
|
||||
const uInt max = (uInt)-1;
|
||||
uLong left;
|
||||
const unsigned int max = (unsigned int)-1;
|
||||
z_size_t left;
|
||||
|
||||
left = *destLen;
|
||||
*destLen = 0;
|
||||
|
||||
stream.zalloc = (alloc_func)0;
|
||||
stream.zfree = (free_func)0;
|
||||
stream.opaque = (voidpf)0;
|
||||
stream.zalloc = NULL;
|
||||
stream.zfree = NULL;
|
||||
stream.opaque = NULL;
|
||||
|
||||
err = deflateInit(&stream, level);
|
||||
if (err != Z_OK) return err;
|
||||
err = PREFIX(deflateInit)(&stream, level);
|
||||
if (err != Z_OK)
|
||||
return err;
|
||||
|
||||
stream.next_out = dest;
|
||||
stream.avail_out = 0;
|
||||
stream.next_in = (z_const Bytef *)source;
|
||||
stream.next_in = (z_const unsigned char *)source;
|
||||
stream.avail_in = 0;
|
||||
|
||||
do {
|
||||
if (stream.avail_out == 0) {
|
||||
stream.avail_out = left > (uLong)max ? max : (uInt)left;
|
||||
stream.avail_out = left > (unsigned long)max ? max : (unsigned int)left;
|
||||
left -= stream.avail_out;
|
||||
}
|
||||
if (stream.avail_in == 0) {
|
||||
stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen;
|
||||
stream.avail_in = sourceLen > (unsigned long)max ? max : (unsigned int)sourceLen;
|
||||
sourceLen -= stream.avail_in;
|
||||
}
|
||||
err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
|
||||
err = PREFIX(deflate)(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
|
||||
} while (err == Z_OK);
|
||||
|
||||
*destLen = stream.total_out;
|
||||
deflateEnd(&stream);
|
||||
PREFIX(deflateEnd)(&stream);
|
||||
return err == Z_STREAM_END ? Z_OK : err;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
*/
|
||||
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||
uLong sourceLen) {
|
||||
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
|
||||
int Z_EXPORT PREFIX(compress)(unsigned char *dest, z_uintmax_t *destLen, const unsigned char *source, z_uintmax_t sourceLen) {
|
||||
return PREFIX(compress2)(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
If the default memLevel or windowBits for deflateInit() is changed, then
|
||||
If the default memLevel or windowBits for deflateInit() is changed, then
|
||||
this function needs to be updated.
|
||||
*/
|
||||
uLong ZEXPORT compressBound(uLong sourceLen) {
|
||||
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
|
||||
(sourceLen >> 25) + 13;
|
||||
z_uintmax_t Z_EXPORT PREFIX(compressBound)(z_uintmax_t sourceLen) {
|
||||
z_uintmax_t complen = DEFLATE_BOUND_COMPLEN(sourceLen);
|
||||
|
||||
if (complen > 0)
|
||||
/* Architecture-specific code provided an upper bound. */
|
||||
return complen + ZLIB_WRAPLEN;
|
||||
|
||||
#ifndef NO_QUICK_STRATEGY
|
||||
return sourceLen /* The source size itself */
|
||||
+ (sourceLen == 0 ? 1 : 0) /* Always at least one byte for any input */
|
||||
+ (sourceLen < 9 ? 1 : 0) /* One extra byte for lengths less than 9 */
|
||||
+ DEFLATE_QUICK_OVERHEAD(sourceLen) /* Source encoding overhead, padded to next full byte */
|
||||
+ DEFLATE_BLOCK_OVERHEAD /* Deflate block overhead bytes */
|
||||
+ ZLIB_WRAPLEN; /* zlib wrapper */
|
||||
#else
|
||||
return sourceLen + (sourceLen >> 4) + 7 + ZLIB_WRAPLEN;
|
||||
#endif
|
||||
}
|
||||
+1921
-511
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,23 @@
|
||||
/* cpu_features.c -- CPU architecture feature check
|
||||
* Copyright (C) 2017 Hans Kristian Rosbach
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "cpu_features.h"
|
||||
#include <string.h>
|
||||
|
||||
Z_INTERNAL void cpu_check_features(struct cpu_features *features) {
|
||||
memset(features, 0, sizeof(struct cpu_features));
|
||||
#if defined(X86_FEATURES)
|
||||
x86_check_features(&features->x86);
|
||||
#elif defined(ARM_FEATURES)
|
||||
arm_check_features(&features->arm);
|
||||
#elif defined(PPC_FEATURES) || defined(POWER_FEATURES)
|
||||
power_check_features(&features->power);
|
||||
#elif defined(S390_FEATURES)
|
||||
s390_check_features(&features->s390);
|
||||
#elif defined(RISCV_FEATURES)
|
||||
riscv_check_features(&features->riscv);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/* cpu_features.h -- CPU architecture feature check
|
||||
* Copyright (C) 2017 Hans Kristian Rosbach
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef CPU_FEATURES_H_
|
||||
#define CPU_FEATURES_H_
|
||||
|
||||
#ifndef DISABLE_RUNTIME_CPU_DETECTION
|
||||
|
||||
#if defined(X86_FEATURES)
|
||||
# include "arch/x86/x86_features.h"
|
||||
#elif defined(ARM_FEATURES)
|
||||
# include "arch/arm/arm_features.h"
|
||||
#elif defined(PPC_FEATURES) || defined(POWER_FEATURES)
|
||||
# include "arch/power/power_features.h"
|
||||
#elif defined(S390_FEATURES)
|
||||
# include "arch/s390/s390_features.h"
|
||||
#elif defined(RISCV_FEATURES)
|
||||
# include "arch/riscv/riscv_features.h"
|
||||
#endif
|
||||
|
||||
struct cpu_features {
|
||||
#if defined(X86_FEATURES)
|
||||
struct x86_cpu_features x86;
|
||||
#elif defined(ARM_FEATURES)
|
||||
struct arm_cpu_features arm;
|
||||
#elif defined(PPC_FEATURES) || defined(POWER_FEATURES)
|
||||
struct power_cpu_features power;
|
||||
#elif defined(S390_FEATURES)
|
||||
struct s390_cpu_features s390;
|
||||
#elif defined(RISCV_FEATURES)
|
||||
struct riscv_cpu_features riscv;
|
||||
#else
|
||||
char empty;
|
||||
#endif
|
||||
};
|
||||
|
||||
void cpu_check_features(struct cpu_features *features);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+23
-1030
File diff suppressed because it is too large.
Load diff
+17
-9440
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,56 @@
|
||||
/* crc32_braid_comb.c -- compute the CRC-32 of a data stream
|
||||
* Copyright (C) 1995-2022 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "crc32_braid_p.h"
|
||||
#include "crc32_braid_tbl.h"
|
||||
#include "crc32_braid_comb_p.h"
|
||||
|
||||
/* ========================================================================= */
|
||||
static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2) {
|
||||
return multmodp(x2nmodp(len2, 3), crc1) ^ crc2;
|
||||
}
|
||||
static uint32_t crc32_combine_gen_(z_off64_t len2) {
|
||||
return x2nmodp(len2, 3);
|
||||
}
|
||||
static uint32_t crc32_combine_op_(uint32_t crc1, uint32_t crc2, const uint32_t op) {
|
||||
return multmodp(op, crc1) ^ crc2;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
#ifdef ZLIB_COMPAT
|
||||
unsigned long Z_EXPORT PREFIX(crc32_combine)(unsigned long crc1, unsigned long crc2, z_off_t len2) {
|
||||
return (unsigned long)crc32_combine_((uint32_t)crc1, (uint32_t)crc2, len2);
|
||||
}
|
||||
unsigned long Z_EXPORT PREFIX4(crc32_combine)(unsigned long crc1, unsigned long crc2, z_off64_t len2) {
|
||||
return (unsigned long)crc32_combine_((uint32_t)crc1, (uint32_t)crc2, len2);
|
||||
}
|
||||
unsigned long Z_EXPORT PREFIX(crc32_combine_gen)(z_off_t len2) {
|
||||
return crc32_combine_gen_(len2);
|
||||
}
|
||||
unsigned long Z_EXPORT PREFIX4(crc32_combine_gen)(z_off64_t len2) {
|
||||
return crc32_combine_gen_(len2);
|
||||
}
|
||||
unsigned long Z_EXPORT PREFIX(crc32_combine_op)(unsigned long crc1, unsigned long crc2, const unsigned long op) {
|
||||
return (unsigned long)crc32_combine_op_((uint32_t)crc1, (uint32_t)crc2, (uint32_t)op);
|
||||
}
|
||||
#else
|
||||
uint32_t Z_EXPORT PREFIX4(crc32_combine)(uint32_t crc1, uint32_t crc2, z_off64_t len2) {
|
||||
return crc32_combine_(crc1, crc2, len2);
|
||||
}
|
||||
uint32_t Z_EXPORT PREFIX(crc32_combine_gen)(z_off64_t len2) {
|
||||
return crc32_combine_gen_(len2);
|
||||
}
|
||||
uint32_t Z_EXPORT PREFIX(crc32_combine_op)(uint32_t crc1, uint32_t crc2, const uint32_t op) {
|
||||
return crc32_combine_op_(crc1, crc2, op);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ========================================================================= */
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef CRC32_BRAID_COMB_P_H_
|
||||
#define CRC32_BRAID_COMB_P_H_
|
||||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
static uint32_t multmodp(uint32_t a, uint32_t b) {
|
||||
uint32_t m, p;
|
||||
|
||||
m = (uint32_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.
|
||||
*/
|
||||
static uint32_t x2nmodp(z_off64_t n, unsigned k) {
|
||||
uint32_t p;
|
||||
|
||||
p = (uint32_t)1 << 31; /* x^0 == 1 */
|
||||
while (n) {
|
||||
if (n & 1)
|
||||
p = multmodp(x2n_table[k & 31], p);
|
||||
n >>= 1;
|
||||
k++;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
#endif /* CRC32_BRAID_COMB_P_H_ */
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef CRC32_BRAID_P_H_
|
||||
#define CRC32_BRAID_P_H_
|
||||
|
||||
#include "zendian.h"
|
||||
|
||||
/* Define BRAID_N, valid range is 1..6 */
|
||||
#define BRAID_N 5
|
||||
|
||||
/* Define BRAID_W and the associated z_word_t type. If BRAID_W is not defined, then a braided
|
||||
calculation is not used, and the associated tables and code are not compiled.
|
||||
*/
|
||||
#if defined(__x86_64__) || defined(_M_AMD64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__powerpc64__)
|
||||
# define BRAID_W 8
|
||||
typedef uint64_t z_word_t;
|
||||
#else
|
||||
# define BRAID_W 4
|
||||
typedef uint32_t z_word_t;
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define ZSWAPWORD(word) (word)
|
||||
# define BRAID_TABLE crc_braid_table
|
||||
#elif BYTE_ORDER == BIG_ENDIAN
|
||||
# if BRAID_W == 8
|
||||
# define ZSWAPWORD(word) ZSWAP64(word)
|
||||
# elif BRAID_W == 4
|
||||
# define ZSWAPWORD(word) ZSWAP32(word)
|
||||
# endif
|
||||
# define BRAID_TABLE crc_braid_big_table
|
||||
#else
|
||||
# error "No endian defined"
|
||||
#endif
|
||||
|
||||
#define CRC_DO1 c = crc_table[(c ^ *buf++) & 0xff] ^ (c >> 8)
|
||||
#define CRC_DO8 CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1
|
||||
|
||||
/* CRC polynomial. */
|
||||
#define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */
|
||||
|
||||
#endif /* CRC32_BRAID_P_H_ */
|
||||
File diff suppressed because it is too large.
Load diff
+813
-1439
File diff suppressed because it is too large.
Load diff
+272
-193
@@ -1,5 +1,7 @@
|
||||
#ifndef DEFLATE_H_
|
||||
#define DEFLATE_H_
|
||||
/* deflate.h -- internal compression state
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly
|
||||
* Copyright (C) 1995-2016 Jean-loup Gailly
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -8,12 +10,15 @@
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef DEFLATE_H
|
||||
#define DEFLATE_H
|
||||
|
||||
#include "zutil.h"
|
||||
#include "zendian.h"
|
||||
#include "zmemory.h"
|
||||
#include "crc32.h"
|
||||
|
||||
#ifdef S390_DFLTCC_DEFLATE
|
||||
# include "arch/s390/dfltcc_common.h"
|
||||
# define HAVE_ARCH_DEFLATE_STATE
|
||||
#endif
|
||||
|
||||
/* define NO_GZIP when compiling if you want to disable gzip header and
|
||||
trailer creation by deflate(). NO_GZIP would be used to avoid linking in
|
||||
@@ -25,7 +30,9 @@
|
||||
|
||||
/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at
|
||||
the cost of a larger memory footprint */
|
||||
/* #define LIT_MEM */
|
||||
#ifndef NO_LIT_MEM
|
||||
# define LIT_MEM
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
* Internal compression state.
|
||||
@@ -49,36 +56,47 @@
|
||||
#define HEAP_SIZE (2*L_CODES+1)
|
||||
/* maximum heap size */
|
||||
|
||||
#define MAX_BITS 15
|
||||
/* All codes must not exceed MAX_BITS bits */
|
||||
|
||||
#define Buf_size 16
|
||||
#define BIT_BUF_SIZE 64
|
||||
/* size of bit buffer in bi_buf */
|
||||
|
||||
#define INIT_STATE 42 /* zlib header -> BUSY_STATE */
|
||||
#define END_BLOCK 256
|
||||
/* end of block literal code */
|
||||
|
||||
#define INIT_STATE 1 /* zlib header -> BUSY_STATE */
|
||||
#ifdef GZIP
|
||||
# define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */
|
||||
# define GZIP_STATE 4 /* gzip header -> BUSY_STATE | EXTRA_STATE */
|
||||
# define EXTRA_STATE 5 /* gzip extra block -> NAME_STATE */
|
||||
# define NAME_STATE 6 /* gzip file name -> COMMENT_STATE */
|
||||
# define COMMENT_STATE 7 /* gzip comment -> HCRC_STATE */
|
||||
# define HCRC_STATE 8 /* gzip header CRC -> BUSY_STATE */
|
||||
#endif
|
||||
#define BUSY_STATE 2 /* deflate -> FINISH_STATE */
|
||||
#define FINISH_STATE 3 /* stream complete */
|
||||
#ifdef GZIP
|
||||
# define MAX_STATE HCRC_STATE
|
||||
#else
|
||||
# define MAX_STATE FINISH_STATE
|
||||
#endif
|
||||
#define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */
|
||||
#define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */
|
||||
#define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */
|
||||
#define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
|
||||
#define BUSY_STATE 113 /* deflate -> FINISH_STATE */
|
||||
#define FINISH_STATE 666 /* stream complete */
|
||||
/* Stream status */
|
||||
|
||||
#define HASH_BITS 16u /* log2(HASH_SIZE) */
|
||||
#ifndef HASH_SIZE
|
||||
# define HASH_SIZE 65536u /* number of elements in hash table */
|
||||
#endif
|
||||
#define HASH_MASK (HASH_SIZE - 1u) /* HASH_SIZE-1 */
|
||||
|
||||
|
||||
/* Data structure describing a single value and its code string. */
|
||||
typedef struct ct_data_s {
|
||||
union {
|
||||
ush freq; /* frequency count */
|
||||
ush code; /* bit string */
|
||||
uint16_t freq; /* frequency count */
|
||||
uint16_t code; /* bit string */
|
||||
} fc;
|
||||
union {
|
||||
ush dad; /* father node in Huffman tree */
|
||||
ush len; /* length of bit string */
|
||||
uint16_t dad; /* father node in Huffman tree */
|
||||
uint16_t len; /* length of bit string */
|
||||
} dl;
|
||||
} FAR ct_data;
|
||||
} ct_data;
|
||||
|
||||
#define Freq fc.freq
|
||||
#define Code fc.code
|
||||
@@ -88,100 +106,123 @@ typedef struct ct_data_s {
|
||||
typedef struct static_tree_desc_s static_tree_desc;
|
||||
|
||||
typedef struct tree_desc_s {
|
||||
ct_data *dyn_tree; /* the dynamic tree */
|
||||
int max_code; /* largest code with non zero frequency */
|
||||
const static_tree_desc *stat_desc; /* the corresponding static tree */
|
||||
} FAR tree_desc;
|
||||
ct_data *dyn_tree; /* the dynamic tree */
|
||||
int max_code; /* largest code with non zero frequency */
|
||||
const static_tree_desc *stat_desc; /* the corresponding static tree */
|
||||
} tree_desc;
|
||||
|
||||
typedef ush Pos;
|
||||
typedef Pos FAR Posf;
|
||||
typedef unsigned IPos;
|
||||
typedef uint16_t Pos;
|
||||
|
||||
/* A Pos is an index in the character window. We use short instead of int to
|
||||
* save space in the various tables. IPos is used only for parameter passing.
|
||||
* save space in the various tables.
|
||||
*/
|
||||
/* Type definitions for hash callbacks */
|
||||
typedef struct internal_state deflate_state;
|
||||
|
||||
typedef struct internal_state {
|
||||
z_streamp strm; /* pointer back to this zlib stream */
|
||||
int status; /* as the name implies */
|
||||
Bytef *pending_buf; /* output still pending */
|
||||
ulg pending_buf_size; /* size of pending_buf */
|
||||
Bytef *pending_out; /* next pending byte to output to the stream */
|
||||
ulg pending; /* nb of bytes in the pending buffer */
|
||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
||||
gz_headerp gzhead; /* gzip header information to write */
|
||||
ulg gzindex; /* where in extra, name, or comment */
|
||||
Byte method; /* can only be DEFLATED */
|
||||
int last_flush; /* value of flush param for previous deflate call */
|
||||
typedef uint32_t (* update_hash_cb) (uint32_t h, uint32_t val);
|
||||
typedef void (* insert_string_cb) (deflate_state *const s, uint32_t str, uint32_t count);
|
||||
typedef Pos (* quick_insert_string_cb)(deflate_state *const s, uint32_t str);
|
||||
|
||||
uint32_t update_hash (uint32_t h, uint32_t val);
|
||||
void insert_string (deflate_state *const s, uint32_t str, uint32_t count);
|
||||
Pos quick_insert_string (deflate_state *const s, uint32_t str);
|
||||
|
||||
uint32_t update_hash_roll (uint32_t h, uint32_t val);
|
||||
void insert_string_roll (deflate_state *const s, uint32_t str, uint32_t count);
|
||||
Pos quick_insert_string_roll(deflate_state *const s, uint32_t str);
|
||||
|
||||
/* Struct for memory allocation handling */
|
||||
typedef struct deflate_allocs_s {
|
||||
char *buf_start;
|
||||
free_func zfree;
|
||||
deflate_state *state;
|
||||
unsigned char *window;
|
||||
unsigned char *pending_buf;
|
||||
Pos *prev;
|
||||
Pos *head;
|
||||
} deflate_allocs;
|
||||
|
||||
struct ALIGNED_(64) internal_state {
|
||||
PREFIX3(stream) *strm; /* pointer back to this zlib stream */
|
||||
unsigned char *pending_buf; /* output still pending */
|
||||
unsigned char *pending_out; /* next pending byte to output to the stream */
|
||||
uint32_t pending_buf_size; /* size of pending_buf */
|
||||
uint32_t pending; /* nb of bytes in the pending buffer */
|
||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
||||
uint32_t gzindex; /* where in extra, name, or comment */
|
||||
PREFIX(gz_headerp) gzhead; /* gzip header information to write */
|
||||
int status; /* as the name implies */
|
||||
int last_flush; /* value of flush param for previous deflate call */
|
||||
int reproducible; /* Whether reproducible compression results are required. */
|
||||
|
||||
int block_open;
|
||||
/* Whether or not a block is currently open for the QUICK deflation scheme.
|
||||
* This is set to 1 if there is an active block, or 0 if the block was just closed.
|
||||
*/
|
||||
|
||||
/* used by deflate.c: */
|
||||
|
||||
uInt w_size; /* LZ77 window size (32K by default) */
|
||||
uInt w_bits; /* log2(w_size) (8..16) */
|
||||
uInt w_mask; /* w_size - 1 */
|
||||
unsigned int w_size; /* LZ77 window size (32K by default) */
|
||||
unsigned int w_bits; /* log2(w_size) (8..16) */
|
||||
unsigned int w_mask; /* w_size - 1 */
|
||||
unsigned int lookahead; /* number of valid bytes ahead in window */
|
||||
|
||||
Bytef *window;
|
||||
unsigned int high_water;
|
||||
/* High water mark offset in window for initialized bytes -- bytes above
|
||||
* this are set to zero in order to avoid memory check warnings when
|
||||
* longest match routines access bytes past the input. This is then
|
||||
* updated to the new high water mark.
|
||||
*/
|
||||
|
||||
unsigned int window_size;
|
||||
/* Actual size of window: 2*wSize, except when the user input buffer
|
||||
* is directly used as sliding window.
|
||||
*/
|
||||
|
||||
unsigned char *window;
|
||||
/* Sliding window. Input bytes are read into the second half of the window,
|
||||
* and move to the first half later to keep a dictionary of at least wSize
|
||||
* bytes. With this organization, matches are limited to a distance of
|
||||
* wSize-MAX_MATCH bytes, but this ensures that IO is always
|
||||
* wSize-STD_MAX_MATCH bytes, but this ensures that IO is always
|
||||
* performed with a length multiple of the block size. Also, it limits
|
||||
* the window size to 64K, which is quite useful on MSDOS.
|
||||
* To do: use the user input buffer as sliding window.
|
||||
*/
|
||||
|
||||
ulg window_size;
|
||||
/* Actual size of window: 2*wSize, except when the user input buffer
|
||||
* is directly used as sliding window.
|
||||
*/
|
||||
|
||||
Posf *prev;
|
||||
Pos *prev;
|
||||
/* Link to older string with same hash index. To limit the size of this
|
||||
* array to 64K, this link is maintained only for the last 32K strings.
|
||||
* An index in this array is thus a window index modulo 32K.
|
||||
*/
|
||||
|
||||
Posf *head; /* Heads of the hash chains or NIL. */
|
||||
Pos *head; /* Heads of the hash chains or 0. */
|
||||
|
||||
uInt ins_h; /* hash index of string to be inserted */
|
||||
uInt hash_size; /* number of elements in hash table */
|
||||
uInt hash_bits; /* log2(hash_size) */
|
||||
uInt hash_mask; /* hash_size-1 */
|
||||
uint32_t ins_h; /* hash index of string to be inserted */
|
||||
|
||||
uInt hash_shift;
|
||||
/* Number of bits by which ins_h must be shifted at each input
|
||||
* step. It must be such that after MIN_MATCH steps, the oldest
|
||||
* byte no longer takes part in the hash key, that is:
|
||||
* hash_shift * MIN_MATCH >= hash_bits
|
||||
*/
|
||||
|
||||
long block_start;
|
||||
int block_start;
|
||||
/* Window position at the beginning of the current output block. Gets
|
||||
* negative when the window is moved backwards.
|
||||
*/
|
||||
|
||||
uInt match_length; /* length of best match */
|
||||
IPos prev_match; /* previous match */
|
||||
int match_available; /* set if previous match exists */
|
||||
uInt strstart; /* start of string to insert */
|
||||
uInt match_start; /* start of matching string */
|
||||
uInt lookahead; /* number of valid bytes ahead in window */
|
||||
unsigned int match_length; /* length of best match */
|
||||
Pos prev_match; /* previous match */
|
||||
int match_available; /* set if previous match exists */
|
||||
unsigned int strstart; /* start of string to insert */
|
||||
unsigned int match_start; /* start of matching string */
|
||||
|
||||
uInt prev_length;
|
||||
unsigned int prev_length;
|
||||
/* Length of the best match at previous step. Matches not greater than this
|
||||
* are discarded. This is used in the lazy match evaluation.
|
||||
*/
|
||||
|
||||
uInt max_chain_length;
|
||||
/* To speed up deflation, hash chains are never searched beyond this
|
||||
* length. A higher limit improves compression ratio but degrades the
|
||||
* speed.
|
||||
unsigned int max_chain_length;
|
||||
/* To speed up deflation, hash chains are never searched beyond this length.
|
||||
* A higher limit improves compression ratio but degrades the speed.
|
||||
*/
|
||||
|
||||
uInt max_lazy_match;
|
||||
/* Attempt to find a better match only when the current match is strictly
|
||||
* smaller than this value. This mechanism is used only for compression
|
||||
* levels >= 4.
|
||||
unsigned int max_lazy_match;
|
||||
/* Attempt to find a better match only when the current match is strictly smaller
|
||||
* than this value. This mechanism is used only for compression levels >= 4.
|
||||
*/
|
||||
# define max_insert_length max_lazy_match
|
||||
/* Insert new strings in the hash table only if the match length is not
|
||||
@@ -189,14 +230,26 @@ typedef struct internal_state {
|
||||
* max_insert_length is used only for compression levels <= 3.
|
||||
*/
|
||||
|
||||
update_hash_cb update_hash;
|
||||
insert_string_cb insert_string;
|
||||
quick_insert_string_cb quick_insert_string;
|
||||
/* Hash function callbacks that can be configured depending on the deflate
|
||||
* algorithm being used */
|
||||
|
||||
int level; /* compression level (1..9) */
|
||||
int strategy; /* favor or force Huffman coding*/
|
||||
|
||||
uInt good_match;
|
||||
unsigned int good_match;
|
||||
/* Use a faster search when the previous match is longer than this */
|
||||
|
||||
int nice_match; /* Stop searching when current match exceeds this */
|
||||
|
||||
#if defined(_M_IX86) || defined(_M_ARM)
|
||||
int padding[2];
|
||||
#endif
|
||||
|
||||
struct crc32_fold_s ALIGNED_(16) crc_fold;
|
||||
|
||||
/* used by trees.c: */
|
||||
/* Didn't use ct_data typedef below to suppress compiler warning */
|
||||
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
|
||||
@@ -207,7 +260,7 @@ typedef struct internal_state {
|
||||
struct tree_desc_s d_desc; /* desc. for distance tree */
|
||||
struct tree_desc_s bl_desc; /* desc. for bit length tree */
|
||||
|
||||
ush bl_count[MAX_BITS+1];
|
||||
uint16_t bl_count[MAX_BITS+1];
|
||||
/* number of codes at each bit length for an optimal tree */
|
||||
|
||||
int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
|
||||
@@ -217,20 +270,11 @@ typedef struct internal_state {
|
||||
* The same heap array is used to build all trees.
|
||||
*/
|
||||
|
||||
uch depth[2*L_CODES+1];
|
||||
unsigned char depth[2*L_CODES+1];
|
||||
/* Depth of each subtree used as tie breaker for trees of equal frequency
|
||||
*/
|
||||
|
||||
#ifdef LIT_MEM
|
||||
# define LIT_BUFS 5
|
||||
ushf *d_buf; /* buffer for distances */
|
||||
uchf *l_buf; /* buffer for literals/lengths */
|
||||
#else
|
||||
# define LIT_BUFS 4
|
||||
uchf *sym_buf; /* buffer for distances and literals/lengths */
|
||||
#endif
|
||||
|
||||
uInt lit_bufsize;
|
||||
unsigned int lit_bufsize;
|
||||
/* Size of match buffer for literals/lengths. There are 4 reasons for
|
||||
* limiting lit_bufsize to 64K:
|
||||
* - frequencies can be kept in 16 bit counters
|
||||
@@ -250,128 +294,163 @@ typedef struct internal_state {
|
||||
* - I can't count above 4
|
||||
*/
|
||||
|
||||
uInt sym_next; /* running index in symbol buffer */
|
||||
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 */
|
||||
uInt matches; /* number of string matches in current block */
|
||||
uInt insert; /* bytes at end of window left to insert */
|
||||
|
||||
#ifdef ZLIB_DEBUG
|
||||
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
|
||||
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
|
||||
#ifdef LIT_MEM
|
||||
# define LIT_BUFS 5
|
||||
uint16_t *d_buf; /* buffer for distances */
|
||||
unsigned char *l_buf; /* buffer for literals/lengths */
|
||||
#else
|
||||
# define LIT_BUFS 4
|
||||
unsigned char *sym_buf; /* buffer for distances and literals/lengths */
|
||||
#endif
|
||||
|
||||
ush bi_buf;
|
||||
/* Output buffer. bits are inserted starting at the bottom (least
|
||||
* significant bits).
|
||||
*/
|
||||
int bi_valid;
|
||||
/* Number of valid bits in bi_buf. All bits above the last valid bit
|
||||
* are always zero.
|
||||
*/
|
||||
unsigned int sym_next; /* running index in symbol buffer */
|
||||
unsigned int sym_end; /* symbol table full when sym_next reaches this */
|
||||
|
||||
ulg high_water;
|
||||
/* High water mark offset in window for initialized bytes -- bytes above
|
||||
* this are set to zero in order to avoid memory check warnings when
|
||||
* longest match routines access bytes past the input. This is then
|
||||
* updated to the new high water mark.
|
||||
*/
|
||||
unsigned long opt_len; /* bit length of current block with optimal trees */
|
||||
unsigned long static_len; /* bit length of current block with static trees */
|
||||
unsigned int matches; /* number of string matches in current block */
|
||||
unsigned int insert; /* bytes at end of window left to insert */
|
||||
|
||||
} FAR deflate_state;
|
||||
/* compressed_len and bits_sent are only used if ZLIB_DEBUG is defined */
|
||||
unsigned long compressed_len; /* total bit length of compressed file mod 2^32 */
|
||||
unsigned long bits_sent; /* bit length of compressed data sent mod 2^32 */
|
||||
|
||||
deflate_allocs *alloc_bufs;
|
||||
|
||||
#ifdef HAVE_ARCH_DEFLATE_STATE
|
||||
arch_deflate_state arch; /* architecture-specific extensions */
|
||||
#endif
|
||||
|
||||
uint64_t bi_buf;
|
||||
/* Output buffer. bits are inserted starting at the bottom (least significant bits). */
|
||||
|
||||
int32_t bi_valid;
|
||||
/* Number of valid bits in bi_buf. All bits above the last valid bit are always zero. */
|
||||
|
||||
/* Reserved for future use and alignment purposes */
|
||||
int32_t reserved[19];
|
||||
#if defined(_M_IX86) || defined(_M_ARM)
|
||||
int32_t padding2[4];
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
need_more, /* block not completed, need more input or more output */
|
||||
block_done, /* block flush performed */
|
||||
finish_started, /* finish started, need only more output at next deflate */
|
||||
finish_done /* finish done, accept no more input or output */
|
||||
} block_state;
|
||||
|
||||
/* Output a byte on the stream.
|
||||
* IN assertion: there is enough room in pending_buf.
|
||||
*/
|
||||
#define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
|
||||
#define put_byte(s, c) { \
|
||||
s->pending_buf[s->pending++] = (unsigned char)(c); \
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Output a short LSB first on the stream.
|
||||
* IN assertion: there is enough room in pending_buf.
|
||||
*/
|
||||
static inline void put_short(deflate_state *s, uint16_t w) {
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
w = ZSWAP16(w);
|
||||
#endif
|
||||
zng_memwrite_2(&s->pending_buf[s->pending], w);
|
||||
s->pending += 2;
|
||||
}
|
||||
|
||||
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
|
||||
/* ===========================================================================
|
||||
* Output a short MSB first on the stream.
|
||||
* IN assertion: there is enough room in pending_buf.
|
||||
*/
|
||||
static inline void put_short_msb(deflate_state *s, uint16_t w) {
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
w = ZSWAP16(w);
|
||||
#endif
|
||||
zng_memwrite_2(&s->pending_buf[s->pending], w);
|
||||
s->pending += 2;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Output a 32-bit unsigned int LSB first on the stream.
|
||||
* IN assertion: there is enough room in pending_buf.
|
||||
*/
|
||||
static inline void put_uint32(deflate_state *s, uint32_t dw) {
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
dw = ZSWAP32(dw);
|
||||
#endif
|
||||
zng_memwrite_4(&s->pending_buf[s->pending], dw);
|
||||
s->pending += 4;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Output a 32-bit unsigned int MSB first on the stream.
|
||||
* IN assertion: there is enough room in pending_buf.
|
||||
*/
|
||||
static inline void put_uint32_msb(deflate_state *s, uint32_t dw) {
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
dw = ZSWAP32(dw);
|
||||
#endif
|
||||
zng_memwrite_4(&s->pending_buf[s->pending], dw);
|
||||
s->pending += 4;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Output a 64-bit unsigned int LSB first on the stream.
|
||||
* IN assertion: there is enough room in pending_buf.
|
||||
*/
|
||||
static inline void put_uint64(deflate_state *s, uint64_t lld) {
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
lld = ZSWAP64(lld);
|
||||
#endif
|
||||
zng_memwrite_8(&s->pending_buf[s->pending], lld);
|
||||
s->pending += 8;
|
||||
}
|
||||
|
||||
#define MIN_LOOKAHEAD (STD_MAX_MATCH + STD_MIN_MATCH + 1)
|
||||
/* Minimum amount of lookahead, except at the end of the input file.
|
||||
* See deflate.c for comments about the MIN_MATCH+1.
|
||||
* See deflate.c for comments about the STD_MIN_MATCH+1.
|
||||
*/
|
||||
|
||||
#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
|
||||
#define MAX_DIST(s) ((s)->w_size - MIN_LOOKAHEAD)
|
||||
/* In order to simplify the code, particularly on 16 bit machines, match
|
||||
* distances are limited to MAX_DIST instead of WSIZE.
|
||||
*/
|
||||
|
||||
#define WIN_INIT MAX_MATCH
|
||||
#define WIN_INIT STD_MAX_MATCH
|
||||
/* Number of bytes after end of data in window to initialize in order to avoid
|
||||
memory checker errors from longest match routines */
|
||||
|
||||
/* in trees.c */
|
||||
void ZLIB_INTERNAL _tr_init(deflate_state *s);
|
||||
int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
|
||||
void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
|
||||
ulg stored_len, int last);
|
||||
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
|
||||
void ZLIB_INTERNAL _tr_align(deflate_state *s);
|
||||
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
|
||||
ulg stored_len, int last);
|
||||
|
||||
#define d_code(dist) \
|
||||
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
|
||||
void Z_INTERNAL PREFIX(fill_window)(deflate_state *s);
|
||||
void Z_INTERNAL slide_hash_c(deflate_state *s);
|
||||
|
||||
/* in trees.c */
|
||||
void Z_INTERNAL zng_tr_init(deflate_state *s);
|
||||
void Z_INTERNAL zng_tr_flush_block(deflate_state *s, char *buf, uint32_t stored_len, int last);
|
||||
void Z_INTERNAL zng_tr_flush_bits(deflate_state *s);
|
||||
void Z_INTERNAL zng_tr_align(deflate_state *s);
|
||||
void Z_INTERNAL zng_tr_stored_block(deflate_state *s, char *buf, uint32_t stored_len, int last);
|
||||
uint16_t Z_INTERNAL PREFIX(bi_reverse)(unsigned code, int len);
|
||||
void Z_INTERNAL PREFIX(flush_pending)(PREFIX3(streamp) strm);
|
||||
#define d_code(dist) ((dist) < 256 ? zng_dist_code[dist] : zng_dist_code[256+((dist)>>7)])
|
||||
/* Mapping from a distance to a distance code. dist is the distance - 1 and
|
||||
* must not have side effects. _dist_code[256] and _dist_code[257] are never
|
||||
* must not have side effects. zng_dist_code[256] and zng_dist_code[257] are never
|
||||
* used.
|
||||
*/
|
||||
|
||||
#ifndef ZLIB_DEBUG
|
||||
/* Inline versions of _tr_tally for speed: */
|
||||
|
||||
#if defined(GEN_TREES_H) || !defined(STDC)
|
||||
extern uch ZLIB_INTERNAL _length_code[];
|
||||
extern uch ZLIB_INTERNAL _dist_code[];
|
||||
/* Bit buffer and compress bits calculation debugging */
|
||||
#ifdef ZLIB_DEBUG
|
||||
# define cmpr_bits_add(s, len) s->compressed_len += (len)
|
||||
# define cmpr_bits_align(s) s->compressed_len = (s->compressed_len + 7) & ~7L
|
||||
# define sent_bits_add(s, bits) s->bits_sent += (bits)
|
||||
# define sent_bits_align(s) s->bits_sent = (s->bits_sent + 7) & ~7L
|
||||
#else
|
||||
extern const uch ZLIB_INTERNAL _length_code[];
|
||||
extern const uch ZLIB_INTERNAL _dist_code[];
|
||||
# define cmpr_bits_add(s, len) Z_UNUSED(len)
|
||||
# define cmpr_bits_align(s)
|
||||
# define sent_bits_add(s, bits) Z_UNUSED(bits)
|
||||
# define sent_bits_align(s)
|
||||
#endif
|
||||
|
||||
#ifdef LIT_MEM
|
||||
# define _tr_tally_lit(s, c, flush) \
|
||||
{ uch cc = (c); \
|
||||
s->d_buf[s->sym_next] = 0; \
|
||||
s->l_buf[s->sym_next++] = cc; \
|
||||
s->dyn_ltree[cc].Freq++; \
|
||||
flush = (s->sym_next == s->sym_end); \
|
||||
}
|
||||
# define _tr_tally_dist(s, distance, length, flush) \
|
||||
{ uch len = (uch)(length); \
|
||||
ush dist = (ush)(distance); \
|
||||
s->d_buf[s->sym_next] = dist; \
|
||||
s->l_buf[s->sym_next++] = len; \
|
||||
dist--; \
|
||||
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
|
||||
s->dyn_dtree[d_code(dist)].Freq++; \
|
||||
flush = (s->sym_next == s->sym_end); \
|
||||
}
|
||||
#else
|
||||
# define _tr_tally_lit(s, c, flush) \
|
||||
{ uch cc = (c); \
|
||||
s->sym_buf[s->sym_next++] = 0; \
|
||||
s->sym_buf[s->sym_next++] = 0; \
|
||||
s->sym_buf[s->sym_next++] = cc; \
|
||||
s->dyn_ltree[cc].Freq++; \
|
||||
flush = (s->sym_next == s->sym_end); \
|
||||
}
|
||||
# define _tr_tally_dist(s, distance, length, flush) \
|
||||
{ uch len = (uch)(length); \
|
||||
ush dist = (ush)(distance); \
|
||||
s->sym_buf[s->sym_next++] = (uch)dist; \
|
||||
s->sym_buf[s->sym_next++] = (uch)(dist >> 8); \
|
||||
s->sym_buf[s->sym_next++] = len; \
|
||||
dist--; \
|
||||
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
|
||||
s->dyn_dtree[d_code(dist)].Freq++; \
|
||||
flush = (s->sym_next == s->sym_end); \
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
|
||||
# define _tr_tally_dist(s, distance, length, flush) \
|
||||
flush = _tr_tally(s, distance, length)
|
||||
#endif
|
||||
|
||||
#endif /* DEFLATE_H */
|
||||
#endif /* DEFLATE_H_ */
|
||||
@@ -0,0 +1,104 @@
|
||||
/* deflate_fast.c -- compress data using the fast strategy of deflation algorithm
|
||||
*
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "deflate.h"
|
||||
#include "deflate_p.h"
|
||||
#include "functable.h"
|
||||
|
||||
/* ===========================================================================
|
||||
* Compress as much as possible from the input stream, return the current
|
||||
* block state.
|
||||
* This function does not perform lazy evaluation of matches and inserts
|
||||
* new strings in the dictionary only for unmatched strings or for short
|
||||
* matches. It is used only for the fast compression options.
|
||||
*/
|
||||
Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
|
||||
Pos hash_head; /* head of the hash chain */
|
||||
int bflush = 0; /* set if current block must be flushed */
|
||||
int64_t dist;
|
||||
uint32_t match_len = 0;
|
||||
|
||||
for (;;) {
|
||||
/* Make sure that we always have enough lookahead, except
|
||||
* at the end of the input file. We need STD_MAX_MATCH bytes
|
||||
* for the next match, plus WANT_MIN_MATCH bytes to insert the
|
||||
* string following the next match.
|
||||
*/
|
||||
if (s->lookahead < MIN_LOOKAHEAD) {
|
||||
PREFIX(fill_window)(s);
|
||||
if (UNLIKELY(s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH)) {
|
||||
return need_more;
|
||||
}
|
||||
if (UNLIKELY(s->lookahead == 0))
|
||||
break; /* flush the current block */
|
||||
}
|
||||
|
||||
/* Insert the string window[strstart .. strstart+2] in the
|
||||
* dictionary, and set hash_head to the head of the hash chain:
|
||||
*/
|
||||
if (s->lookahead >= WANT_MIN_MATCH) {
|
||||
hash_head = quick_insert_string(s, s->strstart);
|
||||
dist = (int64_t)s->strstart - hash_head;
|
||||
|
||||
/* Find the longest match, discarding those <= prev_length.
|
||||
* At this point we have always match length < WANT_MIN_MATCH
|
||||
*/
|
||||
if (dist <= MAX_DIST(s) && dist > 0 && hash_head != 0) {
|
||||
/* To simplify the code, we prevent matches with the string
|
||||
* of window index 0 (in particular we have to avoid a match
|
||||
* of the string with itself at the start of the input file).
|
||||
*/
|
||||
match_len = FUNCTABLE_CALL(longest_match)(s, hash_head);
|
||||
/* longest_match() sets match_start */
|
||||
}
|
||||
}
|
||||
|
||||
if (match_len >= WANT_MIN_MATCH) {
|
||||
Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t");
|
||||
Assert(s->match_start <= UINT16_MAX, "match_start should fit in uint16_t");
|
||||
check_match(s, (Pos)s->strstart, (Pos)s->match_start, match_len);
|
||||
|
||||
bflush = zng_tr_tally_dist(s, s->strstart - s->match_start, match_len - STD_MIN_MATCH);
|
||||
|
||||
s->lookahead -= match_len;
|
||||
|
||||
/* Insert new strings in the hash table only if the match length
|
||||
* is not too large. This saves time but degrades compression.
|
||||
*/
|
||||
if (match_len <= s->max_insert_length && s->lookahead >= WANT_MIN_MATCH) {
|
||||
match_len--; /* string at strstart already in table */
|
||||
s->strstart++;
|
||||
|
||||
insert_string(s, s->strstart, match_len);
|
||||
s->strstart += match_len;
|
||||
} else {
|
||||
s->strstart += match_len;
|
||||
quick_insert_string(s, s->strstart + 2 - STD_MIN_MATCH);
|
||||
|
||||
/* If lookahead < STD_MIN_MATCH, ins_h is garbage, but it does not
|
||||
* matter since it will be recomputed at next deflate call.
|
||||
*/
|
||||
}
|
||||
match_len = 0;
|
||||
} else {
|
||||
/* No match, output a literal byte */
|
||||
bflush = zng_tr_tally_lit(s, s->window[s->strstart]);
|
||||
s->lookahead--;
|
||||
s->strstart++;
|
||||
}
|
||||
if (UNLIKELY(bflush))
|
||||
FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
s->insert = s->strstart < (STD_MIN_MATCH - 1) ? s->strstart : (STD_MIN_MATCH - 1);
|
||||
if (UNLIKELY(flush == Z_FINISH)) {
|
||||
FLUSH_BLOCK(s, 1);
|
||||
return finish_done;
|
||||
}
|
||||
if (UNLIKELY(s->sym_next))
|
||||
FLUSH_BLOCK(s, 0);
|
||||
return block_done;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/* deflate_huff.c -- compress data using huffman encoding only strategy
|
||||
*
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "deflate.h"
|
||||
#include "deflate_p.h"
|
||||
#include "functable.h"
|
||||
|
||||
/* ===========================================================================
|
||||
* For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
|
||||
* (It will be regenerated if this run of deflate switches away from Huffman.)
|
||||
*/
|
||||
Z_INTERNAL block_state deflate_huff(deflate_state *s, int flush) {
|
||||
int bflush = 0; /* set if current block must be flushed */
|
||||
|
||||
for (;;) {
|
||||
/* Make sure that we have a literal to write. */
|
||||
if (s->lookahead == 0) {
|
||||
PREFIX(fill_window)(s);
|
||||
if (s->lookahead == 0) {
|
||||
if (flush == Z_NO_FLUSH)
|
||||
return need_more;
|
||||
break; /* flush the current block */
|
||||
}
|
||||
}
|
||||
|
||||
/* Output a literal byte */
|
||||
bflush = zng_tr_tally_lit(s, s->window[s->strstart]);
|
||||
s->lookahead--;
|
||||
s->strstart++;
|
||||
if (bflush)
|
||||
FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
s->insert = 0;
|
||||
if (flush == Z_FINISH) {
|
||||
FLUSH_BLOCK(s, 1);
|
||||
return finish_done;
|
||||
}
|
||||
if (s->sym_next)
|
||||
FLUSH_BLOCK(s, 0);
|
||||
return block_done;
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
/* deflate_medium.c -- The deflate_medium deflate strategy
|
||||
*
|
||||
* Copyright (C) 2013 Intel Corporation. All rights reserved.
|
||||
* Authors:
|
||||
* Arjan van de Ven <arjan@linux.intel.com>
|
||||
*
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
#ifndef NO_MEDIUM_STRATEGY
|
||||
#include "zbuild.h"
|
||||
#include "deflate.h"
|
||||
#include "deflate_p.h"
|
||||
#include "functable.h"
|
||||
|
||||
struct match {
|
||||
uint16_t match_start;
|
||||
uint16_t match_length;
|
||||
uint16_t strstart;
|
||||
uint16_t orgstart;
|
||||
};
|
||||
|
||||
static int emit_match(deflate_state *s, struct match match) {
|
||||
int bflush = 0;
|
||||
|
||||
/* matches that are not long enough we need to emit as literals */
|
||||
if (match.match_length < WANT_MIN_MATCH) {
|
||||
while (match.match_length) {
|
||||
bflush += zng_tr_tally_lit(s, s->window[match.strstart]);
|
||||
s->lookahead--;
|
||||
match.strstart++;
|
||||
match.match_length--;
|
||||
}
|
||||
return bflush;
|
||||
}
|
||||
|
||||
check_match(s, match.strstart, match.match_start, match.match_length);
|
||||
|
||||
bflush += zng_tr_tally_dist(s, match.strstart - match.match_start, match.match_length - STD_MIN_MATCH);
|
||||
|
||||
s->lookahead -= match.match_length;
|
||||
return bflush;
|
||||
}
|
||||
|
||||
static void insert_match(deflate_state *s, struct match match) {
|
||||
if (UNLIKELY(s->lookahead <= (unsigned int)(match.match_length + WANT_MIN_MATCH)))
|
||||
return;
|
||||
|
||||
/* string at strstart already in table */
|
||||
match.strstart++;
|
||||
match.match_length--;
|
||||
|
||||
/* matches that are not long enough we need to emit as literals */
|
||||
if (LIKELY(match.match_length < WANT_MIN_MATCH - 1)) {
|
||||
if (UNLIKELY(match.match_length > 0)) {
|
||||
if (match.strstart >= match.orgstart) {
|
||||
if (match.strstart + match.match_length - 1 >= match.orgstart) {
|
||||
insert_string(s, match.strstart, match.match_length);
|
||||
} else {
|
||||
insert_string(s, match.strstart, match.orgstart - match.strstart + 1);
|
||||
}
|
||||
match.strstart += match.match_length;
|
||||
match.match_length = 0;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Insert into hash table. */
|
||||
if (LIKELY(match.strstart >= match.orgstart)) {
|
||||
if (LIKELY(match.strstart + match.match_length - 1 >= match.orgstart)) {
|
||||
insert_string(s, match.strstart, match.match_length);
|
||||
} else {
|
||||
insert_string(s, match.strstart, match.orgstart - match.strstart + 1);
|
||||
}
|
||||
} else if (match.orgstart < match.strstart + match.match_length) {
|
||||
insert_string(s, match.orgstart, match.strstart + match.match_length - match.orgstart);
|
||||
}
|
||||
match.strstart += match.match_length;
|
||||
match.match_length = 0;
|
||||
}
|
||||
|
||||
static void fizzle_matches(deflate_state *s, struct match *current, struct match *next) {
|
||||
Pos limit;
|
||||
unsigned char *match, *orig;
|
||||
int changed = 0;
|
||||
struct match c, n;
|
||||
/* step zero: sanity checks */
|
||||
|
||||
if (current->match_length <= 1)
|
||||
return;
|
||||
|
||||
if (UNLIKELY(current->match_length > 1 + next->match_start))
|
||||
return;
|
||||
|
||||
if (UNLIKELY(current->match_length > 1 + next->strstart))
|
||||
return;
|
||||
|
||||
match = s->window - current->match_length + 1 + next->match_start;
|
||||
orig = s->window - current->match_length + 1 + next->strstart;
|
||||
|
||||
/* quick exit check.. if this fails then don't bother with anything else */
|
||||
if (LIKELY(*match != *orig))
|
||||
return;
|
||||
|
||||
c = *current;
|
||||
n = *next;
|
||||
|
||||
/* step one: try to move the "next" match to the left as much as possible */
|
||||
limit = next->strstart > MAX_DIST(s) ? next->strstart - (Pos)MAX_DIST(s) : 0;
|
||||
|
||||
match = s->window + n.match_start - 1;
|
||||
orig = s->window + n.strstart - 1;
|
||||
|
||||
while (*match == *orig) {
|
||||
if (UNLIKELY(c.match_length < 1))
|
||||
break;
|
||||
if (UNLIKELY(n.strstart <= limit))
|
||||
break;
|
||||
if (UNLIKELY(n.match_length >= 256))
|
||||
break;
|
||||
if (UNLIKELY(n.match_start <= 1))
|
||||
break;
|
||||
|
||||
n.strstart--;
|
||||
n.match_start--;
|
||||
n.match_length++;
|
||||
c.match_length--;
|
||||
match--;
|
||||
orig--;
|
||||
changed++;
|
||||
}
|
||||
|
||||
if (!changed)
|
||||
return;
|
||||
|
||||
if (c.match_length <= 1 && n.match_length != 2) {
|
||||
n.orgstart++;
|
||||
*current = c;
|
||||
*next = n;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
|
||||
/* Align the first struct to start on a new cacheline, this allows us to fit both structs in one cacheline */
|
||||
ALIGNED_(16) struct match current_match;
|
||||
struct match next_match;
|
||||
|
||||
/* For levels below 5, don't check the next position for a better match */
|
||||
int early_exit = s->level < 5;
|
||||
|
||||
memset(¤t_match, 0, sizeof(struct match));
|
||||
memset(&next_match, 0, sizeof(struct match));
|
||||
|
||||
for (;;) {
|
||||
Pos hash_head = 0; /* head of the hash chain */
|
||||
int bflush = 0; /* set if current block must be flushed */
|
||||
int64_t dist;
|
||||
|
||||
/* Make sure that we always have enough lookahead, except
|
||||
* at the end of the input file. We need STD_MAX_MATCH bytes
|
||||
* for the next match, plus WANT_MIN_MATCH bytes to insert the
|
||||
* string following the next current_match.
|
||||
*/
|
||||
if (s->lookahead < MIN_LOOKAHEAD) {
|
||||
PREFIX(fill_window)(s);
|
||||
if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
|
||||
return need_more;
|
||||
}
|
||||
if (UNLIKELY(s->lookahead == 0))
|
||||
break; /* flush the current block */
|
||||
next_match.match_length = 0;
|
||||
}
|
||||
|
||||
/* Insert the string window[strstart .. strstart+2] in the
|
||||
* dictionary, and set hash_head to the head of the hash chain:
|
||||
*/
|
||||
|
||||
/* If we already have a future match from a previous round, just use that */
|
||||
if (!early_exit && next_match.match_length > 0) {
|
||||
current_match = next_match;
|
||||
next_match.match_length = 0;
|
||||
} else {
|
||||
hash_head = 0;
|
||||
if (s->lookahead >= WANT_MIN_MATCH) {
|
||||
hash_head = quick_insert_string(s, s->strstart);
|
||||
}
|
||||
|
||||
current_match.strstart = (uint16_t)s->strstart;
|
||||
current_match.orgstart = current_match.strstart;
|
||||
|
||||
/* Find the longest match, discarding those <= prev_length.
|
||||
* At this point we have always match_length < WANT_MIN_MATCH
|
||||
*/
|
||||
|
||||
dist = (int64_t)s->strstart - hash_head;
|
||||
if (dist <= MAX_DIST(s) && dist > 0 && hash_head != 0) {
|
||||
/* To simplify the code, we prevent matches with the string
|
||||
* of window index 0 (in particular we have to avoid a match
|
||||
* of the string with itself at the start of the input file).
|
||||
*/
|
||||
current_match.match_length = (uint16_t)FUNCTABLE_CALL(longest_match)(s, hash_head);
|
||||
current_match.match_start = (uint16_t)s->match_start;
|
||||
if (UNLIKELY(current_match.match_length < WANT_MIN_MATCH))
|
||||
current_match.match_length = 1;
|
||||
if (UNLIKELY(current_match.match_start >= current_match.strstart)) {
|
||||
/* this can happen due to some restarts */
|
||||
current_match.match_length = 1;
|
||||
}
|
||||
} else {
|
||||
/* Set up the match to be a 1 byte literal */
|
||||
current_match.match_start = 0;
|
||||
current_match.match_length = 1;
|
||||
}
|
||||
}
|
||||
|
||||
insert_match(s, current_match);
|
||||
|
||||
/* now, look ahead one */
|
||||
if (LIKELY(!early_exit && s->lookahead > MIN_LOOKAHEAD && (uint32_t)(current_match.strstart + current_match.match_length) < (s->window_size - MIN_LOOKAHEAD))) {
|
||||
s->strstart = current_match.strstart + current_match.match_length;
|
||||
hash_head = quick_insert_string(s, s->strstart);
|
||||
|
||||
next_match.strstart = (uint16_t)s->strstart;
|
||||
next_match.orgstart = next_match.strstart;
|
||||
|
||||
/* Find the longest match, discarding those <= prev_length.
|
||||
* At this point we have always match_length < WANT_MIN_MATCH
|
||||
*/
|
||||
|
||||
dist = (int64_t)s->strstart - hash_head;
|
||||
if (dist <= MAX_DIST(s) && dist > 0 && hash_head != 0) {
|
||||
/* To simplify the code, we prevent matches with the string
|
||||
* of window index 0 (in particular we have to avoid a match
|
||||
* of the string with itself at the start of the input file).
|
||||
*/
|
||||
next_match.match_length = (uint16_t)FUNCTABLE_CALL(longest_match)(s, hash_head);
|
||||
next_match.match_start = (uint16_t)s->match_start;
|
||||
if (UNLIKELY(next_match.match_start >= next_match.strstart)) {
|
||||
/* this can happen due to some restarts */
|
||||
next_match.match_length = 1;
|
||||
}
|
||||
if (next_match.match_length < WANT_MIN_MATCH)
|
||||
next_match.match_length = 1;
|
||||
else
|
||||
fizzle_matches(s, ¤t_match, &next_match);
|
||||
} else {
|
||||
/* Set up the match to be a 1 byte literal */
|
||||
next_match.match_start = 0;
|
||||
next_match.match_length = 1;
|
||||
}
|
||||
|
||||
s->strstart = current_match.strstart;
|
||||
} else {
|
||||
next_match.match_length = 0;
|
||||
}
|
||||
|
||||
/* now emit the current match */
|
||||
bflush = emit_match(s, current_match);
|
||||
|
||||
/* move the "cursor" forward */
|
||||
s->strstart += current_match.match_length;
|
||||
|
||||
if (UNLIKELY(bflush))
|
||||
FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
s->insert = s->strstart < (STD_MIN_MATCH - 1) ? s->strstart : (STD_MIN_MATCH - 1);
|
||||
if (flush == Z_FINISH) {
|
||||
FLUSH_BLOCK(s, 1);
|
||||
return finish_done;
|
||||
}
|
||||
if (UNLIKELY(s->sym_next))
|
||||
FLUSH_BLOCK(s, 0);
|
||||
|
||||
return block_done;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,128 @@
|
||||
/* deflate_p.h -- Private inline functions and macros shared with more than
|
||||
* one deflate method
|
||||
*
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DEFLATE_P_H
|
||||
#define DEFLATE_P_H
|
||||
|
||||
/* Forward declare common non-inlined functions declared in deflate.c */
|
||||
|
||||
#ifdef ZLIB_DEBUG
|
||||
/* ===========================================================================
|
||||
* Check that the match at match_start is indeed a match.
|
||||
*/
|
||||
static inline void check_match(deflate_state *s, Pos start, Pos match, int length) {
|
||||
/* check that the match length is valid*/
|
||||
if (length < STD_MIN_MATCH || length > STD_MAX_MATCH) {
|
||||
fprintf(stderr, " start %u, match %u, length %d\n", start, match, length);
|
||||
z_error("invalid match length");
|
||||
}
|
||||
/* check that the match isn't at the same position as the start string */
|
||||
if (match == start) {
|
||||
fprintf(stderr, " start %u, match %u, length %d\n", start, match, length);
|
||||
z_error("invalid match position");
|
||||
}
|
||||
/* check that the match is indeed a match */
|
||||
if (memcmp(s->window + match, s->window + start, length) != 0) {
|
||||
int32_t i = 0;
|
||||
fprintf(stderr, " start %u, match %u, length %d\n", start, match, length);
|
||||
do {
|
||||
fprintf(stderr, " %03d: match [%02x] start [%02x]\n", i++,
|
||||
s->window[match++], s->window[start++]);
|
||||
} while (--length != 0);
|
||||
z_error("invalid match");
|
||||
}
|
||||
if (z_verbose > 1) {
|
||||
fprintf(stderr, "\\[%u,%d]", start-match, length);
|
||||
do {
|
||||
putc(s->window[start++], stderr);
|
||||
} while (--length != 0);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define check_match(s, start, match, length)
|
||||
#endif
|
||||
|
||||
Z_INTERNAL void PREFIX(flush_pending)(PREFIX3(stream) *strm);
|
||||
Z_INTERNAL unsigned PREFIX(read_buf)(PREFIX3(stream) *strm, unsigned char *buf, unsigned size);
|
||||
|
||||
/* ===========================================================================
|
||||
* Save the match info and tally the frequency counts. Return true if
|
||||
* the current block must be flushed.
|
||||
*/
|
||||
|
||||
extern const unsigned char Z_INTERNAL zng_length_code[];
|
||||
extern const unsigned char Z_INTERNAL zng_dist_code[];
|
||||
|
||||
static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) {
|
||||
/* c is the unmatched char */
|
||||
#ifdef LIT_MEM
|
||||
s->d_buf[s->sym_next] = 0;
|
||||
s->l_buf[s->sym_next++] = c;
|
||||
#else
|
||||
s->sym_buf[s->sym_next++] = 0;
|
||||
s->sym_buf[s->sym_next++] = 0;
|
||||
s->sym_buf[s->sym_next++] = c;
|
||||
#endif
|
||||
s->dyn_ltree[c].Freq++;
|
||||
Tracevv((stderr, "%c", c));
|
||||
Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal");
|
||||
return (s->sym_next == s->sym_end);
|
||||
}
|
||||
|
||||
static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t len) {
|
||||
/* dist: distance of matched string */
|
||||
/* len: match length-STD_MIN_MATCH */
|
||||
#ifdef LIT_MEM
|
||||
Assert(dist <= UINT16_MAX, "dist should fit in uint16_t");
|
||||
Assert(len <= UINT8_MAX, "len should fit in uint8_t");
|
||||
s->d_buf[s->sym_next] = (uint16_t)dist;
|
||||
s->l_buf[s->sym_next++] = (uint8_t)len;
|
||||
#else
|
||||
s->sym_buf[s->sym_next++] = (uint8_t)(dist);
|
||||
s->sym_buf[s->sym_next++] = (uint8_t)(dist >> 8);
|
||||
s->sym_buf[s->sym_next++] = (uint8_t)len;
|
||||
#endif
|
||||
s->matches++;
|
||||
dist--;
|
||||
Assert(dist < MAX_DIST(s) && (uint16_t)d_code(dist) < (uint16_t)D_CODES,
|
||||
"zng_tr_tally: bad match");
|
||||
|
||||
s->dyn_ltree[zng_length_code[len] + LITERALS + 1].Freq++;
|
||||
s->dyn_dtree[d_code(dist)].Freq++;
|
||||
return (s->sym_next == s->sym_end);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Flush the current block, with given end-of-file flag.
|
||||
* IN assertion: strstart is set to the end of the current match.
|
||||
*/
|
||||
#define FLUSH_BLOCK_ONLY(s, last) { \
|
||||
zng_tr_flush_block(s, (s->block_start >= 0 ? \
|
||||
(char *)&s->window[(unsigned)s->block_start] : \
|
||||
NULL), \
|
||||
(uint32_t)((int)s->strstart - s->block_start), \
|
||||
(last)); \
|
||||
s->block_start = (int)s->strstart; \
|
||||
PREFIX(flush_pending)(s->strm); \
|
||||
}
|
||||
|
||||
/* Same but force premature exit if necessary. */
|
||||
#define FLUSH_BLOCK(s, last) { \
|
||||
FLUSH_BLOCK_ONLY(s, last); \
|
||||
if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
|
||||
}
|
||||
|
||||
/* Maximum stored block length in deflate format (not including header). */
|
||||
#define MAX_STORED 65535
|
||||
|
||||
/* Compression function. Returns the block state after the call. */
|
||||
typedef block_state (*compress_func) (deflate_state *s, int flush);
|
||||
/* Match function. Returns the longest match. */
|
||||
typedef uint32_t (*match_func) (deflate_state *const s, Pos cur_match);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* The deflate_quick deflate strategy, designed to be used when cycles are
|
||||
* at a premium.
|
||||
*
|
||||
* Copyright (C) 2013 Intel Corporation. All rights reserved.
|
||||
* Authors:
|
||||
* Wajdi Feghali <wajdi.k.feghali@intel.com>
|
||||
* Jim Guilford <james.guilford@intel.com>
|
||||
* Vinodh Gopal <vinodh.gopal@intel.com>
|
||||
* Erdinc Ozturk <erdinc.ozturk@intel.com>
|
||||
* Jim Kukunas <james.t.kukunas@linux.intel.com>
|
||||
*
|
||||
* Portions are Copyright (C) 2016 12Sided Technology, LLC.
|
||||
* Author:
|
||||
* Phil Vachon <pvachon@12sidedtech.com>
|
||||
*
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "zmemory.h"
|
||||
#include "deflate.h"
|
||||
#include "deflate_p.h"
|
||||
#include "functable.h"
|
||||
#include "trees_emit.h"
|
||||
|
||||
extern const ct_data static_ltree[L_CODES+2];
|
||||
extern const ct_data static_dtree[D_CODES];
|
||||
|
||||
#define QUICK_START_BLOCK(s, last) { \
|
||||
zng_tr_emit_tree(s, STATIC_TREES, last); \
|
||||
s->block_open = 1 + (int)last; \
|
||||
s->block_start = (int)s->strstart; \
|
||||
}
|
||||
|
||||
#define QUICK_END_BLOCK(s, last) { \
|
||||
if (s->block_open) { \
|
||||
zng_tr_emit_end_block(s, static_ltree, last); \
|
||||
s->block_open = 0; \
|
||||
s->block_start = (int)s->strstart; \
|
||||
PREFIX(flush_pending)(s->strm); \
|
||||
if (s->strm->avail_out == 0) \
|
||||
return (last) ? finish_started : need_more; \
|
||||
} \
|
||||
}
|
||||
|
||||
Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) {
|
||||
Pos hash_head;
|
||||
int64_t dist;
|
||||
unsigned match_len, last;
|
||||
|
||||
|
||||
last = (flush == Z_FINISH) ? 1 : 0;
|
||||
if (UNLIKELY(last && s->block_open != 2)) {
|
||||
/* Emit end of previous block */
|
||||
QUICK_END_BLOCK(s, 0);
|
||||
/* Emit start of last block */
|
||||
QUICK_START_BLOCK(s, last);
|
||||
} else if (UNLIKELY(s->block_open == 0 && s->lookahead > 0)) {
|
||||
/* Start new block only when we have lookahead data, so that if no
|
||||
input data is given an empty block will not be written */
|
||||
QUICK_START_BLOCK(s, last);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (UNLIKELY(s->pending + ((BIT_BUF_SIZE + 7) >> 3) >= s->pending_buf_size)) {
|
||||
PREFIX(flush_pending)(s->strm);
|
||||
if (s->strm->avail_out == 0) {
|
||||
return (last && s->strm->avail_in == 0 && s->bi_valid == 0 && s->block_open == 0) ? finish_started : need_more;
|
||||
}
|
||||
}
|
||||
|
||||
if (UNLIKELY(s->lookahead < MIN_LOOKAHEAD)) {
|
||||
PREFIX(fill_window)(s);
|
||||
if (UNLIKELY(s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH)) {
|
||||
return need_more;
|
||||
}
|
||||
if (UNLIKELY(s->lookahead == 0))
|
||||
break;
|
||||
|
||||
if (UNLIKELY(s->block_open == 0)) {
|
||||
/* Start new block when we have lookahead data, so that if no
|
||||
input data is given an empty block will not be written */
|
||||
QUICK_START_BLOCK(s, last);
|
||||
}
|
||||
}
|
||||
|
||||
if (LIKELY(s->lookahead >= WANT_MIN_MATCH)) {
|
||||
hash_head = quick_insert_string(s, s->strstart);
|
||||
dist = (int64_t)s->strstart - hash_head;
|
||||
|
||||
if (dist <= MAX_DIST(s) && dist > 0) {
|
||||
const uint8_t *str_start = s->window + s->strstart;
|
||||
const uint8_t *match_start = s->window + hash_head;
|
||||
|
||||
if (zng_memcmp_2(str_start, match_start) == 0) {
|
||||
match_len = FUNCTABLE_CALL(compare256)(str_start+2, match_start+2) + 2;
|
||||
|
||||
if (match_len >= WANT_MIN_MATCH) {
|
||||
if (UNLIKELY(match_len > s->lookahead))
|
||||
match_len = s->lookahead;
|
||||
if (UNLIKELY(match_len > STD_MAX_MATCH))
|
||||
match_len = STD_MAX_MATCH;
|
||||
|
||||
Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t");
|
||||
check_match(s, (Pos)s->strstart, hash_head, match_len);
|
||||
|
||||
zng_tr_emit_dist(s, static_ltree, static_dtree, match_len - STD_MIN_MATCH, (uint32_t)dist);
|
||||
s->lookahead -= match_len;
|
||||
s->strstart += match_len;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zng_tr_emit_lit(s, static_ltree, s->window[s->strstart]);
|
||||
s->strstart++;
|
||||
s->lookahead--;
|
||||
}
|
||||
|
||||
s->insert = s->strstart < (STD_MIN_MATCH - 1) ? s->strstart : (STD_MIN_MATCH - 1);
|
||||
if (UNLIKELY(last)) {
|
||||
QUICK_END_BLOCK(s, 1);
|
||||
return finish_done;
|
||||
}
|
||||
|
||||
QUICK_END_BLOCK(s, 0);
|
||||
return block_done;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/* deflate_rle.c -- compress data using RLE strategy of deflation algorithm
|
||||
*
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "deflate.h"
|
||||
#include "deflate_p.h"
|
||||
#include "functable.h"
|
||||
#include "compare256_rle.h"
|
||||
|
||||
#if OPTIMAL_CMP == 8
|
||||
# define compare256_rle compare256_rle_8
|
||||
#elif defined(HAVE_BUILTIN_CTZLL)
|
||||
# define compare256_rle compare256_rle_64
|
||||
#elif defined(HAVE_BUILTIN_CTZ)
|
||||
# define compare256_rle compare256_rle_32
|
||||
#else
|
||||
# define compare256_rle compare256_rle_16
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
* For Z_RLE, simply look for runs of bytes, generate matches only of distance
|
||||
* one. Do not maintain a hash table. (It will be regenerated if this run of
|
||||
* deflate switches away from Z_RLE.)
|
||||
*/
|
||||
Z_INTERNAL block_state deflate_rle(deflate_state *s, int flush) {
|
||||
int bflush = 0; /* set if current block must be flushed */
|
||||
unsigned char *scan; /* scan goes up to strend for length of run */
|
||||
uint32_t match_len = 0;
|
||||
|
||||
for (;;) {
|
||||
/* Make sure that we always have enough lookahead, except
|
||||
* at the end of the input file. We need STD_MAX_MATCH bytes
|
||||
* for the longest run, plus one for the unrolled loop.
|
||||
*/
|
||||
if (s->lookahead <= STD_MAX_MATCH) {
|
||||
PREFIX(fill_window)(s);
|
||||
if (s->lookahead <= STD_MAX_MATCH && flush == Z_NO_FLUSH)
|
||||
return need_more;
|
||||
if (s->lookahead == 0)
|
||||
break; /* flush the current block */
|
||||
}
|
||||
|
||||
/* See how many times the previous byte repeats */
|
||||
if (s->lookahead >= STD_MIN_MATCH && s->strstart > 0) {
|
||||
scan = s->window + s->strstart - 1;
|
||||
if (scan[0] == scan[1] && scan[1] == scan[2]) {
|
||||
match_len = compare256_rle(scan, scan+3)+2;
|
||||
match_len = MIN(match_len, s->lookahead);
|
||||
match_len = MIN(match_len, STD_MAX_MATCH);
|
||||
}
|
||||
Assert(scan+match_len <= s->window + s->window_size - 1, "wild scan");
|
||||
}
|
||||
|
||||
/* Emit match if have run of STD_MIN_MATCH or longer, else emit literal */
|
||||
if (match_len >= STD_MIN_MATCH) {
|
||||
Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t");
|
||||
check_match(s, (Pos)s->strstart, (Pos)(s->strstart - 1), match_len);
|
||||
|
||||
bflush = zng_tr_tally_dist(s, 1, match_len - STD_MIN_MATCH);
|
||||
|
||||
s->lookahead -= match_len;
|
||||
s->strstart += match_len;
|
||||
match_len = 0;
|
||||
} else {
|
||||
/* No match, output a literal byte */
|
||||
bflush = zng_tr_tally_lit(s, s->window[s->strstart]);
|
||||
s->lookahead--;
|
||||
s->strstart++;
|
||||
}
|
||||
if (bflush)
|
||||
FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
s->insert = 0;
|
||||
if (flush == Z_FINISH) {
|
||||
FLUSH_BLOCK(s, 1);
|
||||
return finish_done;
|
||||
}
|
||||
if (s->sym_next)
|
||||
FLUSH_BLOCK(s, 0);
|
||||
return block_done;
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/* deflate_slow.c -- compress data using the slow strategy of deflation algorithm
|
||||
*
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "deflate.h"
|
||||
#include "deflate_p.h"
|
||||
#include "functable.h"
|
||||
|
||||
/* ===========================================================================
|
||||
* Same as deflate_medium, but achieves better compression. We use a lazy
|
||||
* evaluation for matches: a match is finally adopted only if there is
|
||||
* no better match at the next window position.
|
||||
*/
|
||||
Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
|
||||
Pos hash_head; /* head of hash chain */
|
||||
int bflush; /* set if current block must be flushed */
|
||||
int64_t dist;
|
||||
uint32_t match_len;
|
||||
match_func longest_match;
|
||||
|
||||
if (s->max_chain_length <= 1024)
|
||||
longest_match = FUNCTABLE_FPTR(longest_match);
|
||||
else
|
||||
longest_match = FUNCTABLE_FPTR(longest_match_slow);
|
||||
|
||||
/* Process the input block. */
|
||||
for (;;) {
|
||||
/* Make sure that we always have enough lookahead, except
|
||||
* at the end of the input file. We need STD_MAX_MATCH bytes
|
||||
* for the next match, plus WANT_MIN_MATCH bytes to insert the
|
||||
* string following the next match.
|
||||
*/
|
||||
if (s->lookahead < MIN_LOOKAHEAD) {
|
||||
PREFIX(fill_window)(s);
|
||||
if (UNLIKELY(s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH)) {
|
||||
return need_more;
|
||||
}
|
||||
if (UNLIKELY(s->lookahead == 0))
|
||||
break; /* flush the current block */
|
||||
}
|
||||
|
||||
/* Insert the string window[strstart .. strstart+2] in the
|
||||
* dictionary, and set hash_head to the head of the hash chain:
|
||||
*/
|
||||
hash_head = 0;
|
||||
if (LIKELY(s->lookahead >= WANT_MIN_MATCH)) {
|
||||
hash_head = s->quick_insert_string(s, s->strstart);
|
||||
}
|
||||
|
||||
/* Find the longest match, discarding those <= prev_length.
|
||||
*/
|
||||
s->prev_match = (Pos)s->match_start;
|
||||
match_len = STD_MIN_MATCH - 1;
|
||||
dist = (int64_t)s->strstart - hash_head;
|
||||
|
||||
if (dist <= MAX_DIST(s) && dist > 0 && s->prev_length < s->max_lazy_match && hash_head != 0) {
|
||||
/* To simplify the code, we prevent matches with the string
|
||||
* of window index 0 (in particular we have to avoid a match
|
||||
* of the string with itself at the start of the input file).
|
||||
*/
|
||||
match_len = longest_match(s, hash_head);
|
||||
/* longest_match() sets match_start */
|
||||
|
||||
if (match_len <= 5 && (s->strategy == Z_FILTERED)) {
|
||||
/* If prev_match is also WANT_MIN_MATCH, match_start is garbage
|
||||
* but we will ignore the current match anyway.
|
||||
*/
|
||||
match_len = STD_MIN_MATCH - 1;
|
||||
}
|
||||
}
|
||||
/* If there was a match at the previous step and the current
|
||||
* match is not better, output the previous match:
|
||||
*/
|
||||
if (s->prev_length >= STD_MIN_MATCH && match_len <= s->prev_length) {
|
||||
unsigned int max_insert = s->strstart + s->lookahead - STD_MIN_MATCH;
|
||||
/* Do not insert strings in hash table beyond this. */
|
||||
|
||||
Assert((s->strstart-1) <= UINT16_MAX, "strstart-1 should fit in uint16_t");
|
||||
check_match(s, (Pos)(s->strstart - 1), s->prev_match, s->prev_length);
|
||||
|
||||
bflush = zng_tr_tally_dist(s, s->strstart -1 - s->prev_match, s->prev_length - STD_MIN_MATCH);
|
||||
|
||||
/* Insert in hash table all strings up to the end of the match.
|
||||
* strstart-1 and strstart are already inserted. If there is not
|
||||
* enough lookahead, the last two strings are not inserted in
|
||||
* the hash table.
|
||||
*/
|
||||
s->prev_length -= 1;
|
||||
s->lookahead -= s->prev_length;
|
||||
|
||||
unsigned int mov_fwd = s->prev_length - 1;
|
||||
if (max_insert > s->strstart) {
|
||||
unsigned int insert_cnt = mov_fwd;
|
||||
if (UNLIKELY(insert_cnt > max_insert - s->strstart))
|
||||
insert_cnt = max_insert - s->strstart;
|
||||
s->insert_string(s, s->strstart + 1, insert_cnt);
|
||||
}
|
||||
s->prev_length = 0;
|
||||
s->match_available = 0;
|
||||
s->strstart += mov_fwd + 1;
|
||||
|
||||
if (UNLIKELY(bflush))
|
||||
FLUSH_BLOCK(s, 0);
|
||||
|
||||
} else if (s->match_available) {
|
||||
/* If there was no match at the previous position, output a
|
||||
* single literal. If there was a match but the current match
|
||||
* is longer, truncate the previous match to a single literal.
|
||||
*/
|
||||
bflush = zng_tr_tally_lit(s, s->window[s->strstart-1]);
|
||||
if (UNLIKELY(bflush))
|
||||
FLUSH_BLOCK_ONLY(s, 0);
|
||||
s->prev_length = match_len;
|
||||
s->strstart++;
|
||||
s->lookahead--;
|
||||
if (UNLIKELY(s->strm->avail_out == 0))
|
||||
return need_more;
|
||||
} else {
|
||||
/* There is no previous match to compare with, wait for
|
||||
* the next step to decide.
|
||||
*/
|
||||
s->prev_length = match_len;
|
||||
s->match_available = 1;
|
||||
s->strstart++;
|
||||
s->lookahead--;
|
||||
}
|
||||
}
|
||||
Assert(flush != Z_NO_FLUSH, "no flush?");
|
||||
if (UNLIKELY(s->match_available)) {
|
||||
Z_UNUSED(zng_tr_tally_lit(s, s->window[s->strstart-1]));
|
||||
s->match_available = 0;
|
||||
}
|
||||
s->insert = s->strstart < (STD_MIN_MATCH - 1) ? s->strstart : (STD_MIN_MATCH - 1);
|
||||
if (UNLIKELY(flush == Z_FINISH)) {
|
||||
FLUSH_BLOCK(s, 1);
|
||||
return finish_done;
|
||||
}
|
||||
if (UNLIKELY(s->sym_next))
|
||||
FLUSH_BLOCK(s, 0);
|
||||
return block_done;
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
/* deflate_stored.c -- store data without compression using deflation algorithm
|
||||
*
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "deflate.h"
|
||||
#include "deflate_p.h"
|
||||
#include "functable.h"
|
||||
|
||||
/* ===========================================================================
|
||||
* Copy without compression as much as possible from the input stream, return
|
||||
* the current block state.
|
||||
*
|
||||
* In case deflateParams() is used to later switch to a non-zero compression
|
||||
* level, s->matches (otherwise unused when storing) keeps track of the number
|
||||
* of hash table slides to perform. If s->matches is 1, then one hash table
|
||||
* slide will be done when switching. If s->matches is 2, the maximum value
|
||||
* allowed here, then the hash table will be cleared, since two or more slides
|
||||
* is the same as a clear.
|
||||
*
|
||||
* deflate_stored() is written to minimize the number of times an input byte is
|
||||
* copied. It is most efficient with large input and output buffers, which
|
||||
* maximizes the opportunities to have a single copy from next_in to next_out.
|
||||
*/
|
||||
Z_INTERNAL block_state deflate_stored(deflate_state *s, int flush) {
|
||||
/* Smallest worthy block size when not flushing or finishing. By default
|
||||
* this is 32K. This can be as small as 507 bytes for memLevel == 1. For
|
||||
* large input and output buffers, the stored block size will be larger.
|
||||
*/
|
||||
unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size);
|
||||
|
||||
/* Copy as many min_block or larger stored blocks directly to next_out as
|
||||
* possible. If flushing, copy the remaining available input to next_out as
|
||||
* stored blocks, if there is enough space.
|
||||
*/
|
||||
unsigned len, left, have, last = 0;
|
||||
unsigned used = s->strm->avail_in;
|
||||
do {
|
||||
/* Set len to the maximum size block that we can copy directly with the
|
||||
* available input data and output space. Set left to how much of that
|
||||
* would be copied from what's left in the window.
|
||||
*/
|
||||
len = MAX_STORED; /* maximum deflate stored block length */
|
||||
have = (s->bi_valid + 42) >> 3; /* number of header bytes */
|
||||
if (s->strm->avail_out < have) /* need room for header */
|
||||
break;
|
||||
/* maximum stored block length that will fit in avail_out: */
|
||||
have = s->strm->avail_out - have;
|
||||
left = (int)s->strstart - s->block_start; /* bytes left in window */
|
||||
if (len > (unsigned long)left + s->strm->avail_in)
|
||||
len = left + s->strm->avail_in; /* limit len to the input */
|
||||
len = MIN(len, have); /* limit len to the output */
|
||||
|
||||
/* If the stored block would be less than min_block in length, or if
|
||||
* unable to copy all of the available input when flushing, then try
|
||||
* copying to the window and the pending buffer instead. Also don't
|
||||
* write an empty block when flushing -- deflate() does that.
|
||||
*/
|
||||
if (len < min_block && ((len == 0 && flush != Z_FINISH) || flush == Z_NO_FLUSH || len != left + s->strm->avail_in))
|
||||
break;
|
||||
|
||||
/* Make a dummy stored block in pending to get the header bytes,
|
||||
* including any pending bits. This also updates the debugging counts.
|
||||
*/
|
||||
last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0;
|
||||
zng_tr_stored_block(s, (char *)0, 0L, last);
|
||||
|
||||
/* Replace the lengths in the dummy stored block with len. */
|
||||
s->pending -= 4;
|
||||
put_short(s, (uint16_t)len);
|
||||
put_short(s, (uint16_t)~len);
|
||||
|
||||
/* Write the stored block header bytes. */
|
||||
PREFIX(flush_pending)(s->strm);
|
||||
|
||||
/* Update debugging counts for the data about to be copied. */
|
||||
cmpr_bits_add(s, len << 3);
|
||||
sent_bits_add(s, len << 3);
|
||||
|
||||
/* Copy uncompressed bytes from the window to next_out. */
|
||||
if (left) {
|
||||
left = MIN(left, len);
|
||||
memcpy(s->strm->next_out, s->window + s->block_start, left);
|
||||
s->strm->next_out += left;
|
||||
s->strm->avail_out -= left;
|
||||
s->strm->total_out += left;
|
||||
s->block_start += (int)left;
|
||||
len -= left;
|
||||
}
|
||||
|
||||
/* Copy uncompressed bytes directly from next_in to next_out, updating
|
||||
* the check value.
|
||||
*/
|
||||
if (len) {
|
||||
PREFIX(read_buf)(s->strm, s->strm->next_out, len);
|
||||
s->strm->next_out += len;
|
||||
s->strm->avail_out -= len;
|
||||
s->strm->total_out += len;
|
||||
}
|
||||
} while (last == 0);
|
||||
|
||||
/* Update the sliding window with the last s->w_size bytes of the copied
|
||||
* data, or append all of the copied data to the existing window if less
|
||||
* than s->w_size bytes were copied. Also update the number of bytes to
|
||||
* insert in the hash tables, in the event that deflateParams() switches to
|
||||
* a non-zero compression level.
|
||||
*/
|
||||
used -= s->strm->avail_in; /* number of input bytes directly copied */
|
||||
if (used) {
|
||||
/* If any input was used, then no unused input remains in the window,
|
||||
* therefore s->block_start == s->strstart.
|
||||
*/
|
||||
if (used >= s->w_size) { /* supplant the previous history */
|
||||
s->matches = 2; /* clear hash */
|
||||
memcpy(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) {
|
||||
/* Slide the window down. */
|
||||
s->strstart -= s->w_size;
|
||||
memcpy(s->window, s->window + s->w_size, s->strstart);
|
||||
if (s->matches < 2)
|
||||
s->matches++; /* add a pending slide_hash() */
|
||||
s->insert = MIN(s->insert, s->strstart);
|
||||
}
|
||||
memcpy(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 = (int)s->strstart;
|
||||
}
|
||||
s->high_water = MAX(s->high_water, s->strstart);
|
||||
|
||||
/* If the last block was written to next_out, then done. */
|
||||
if (last)
|
||||
return finish_done;
|
||||
|
||||
/* If flushing and all input has been consumed, then done. */
|
||||
if (flush != Z_NO_FLUSH && flush != Z_FINISH && s->strm->avail_in == 0 && (int)s->strstart == s->block_start)
|
||||
return block_done;
|
||||
|
||||
/* Fill the window with any remaining input. */
|
||||
have = s->window_size - s->strstart;
|
||||
if (s->strm->avail_in > have && s->block_start >= (int)s->w_size) {
|
||||
/* Slide the window down. */
|
||||
s->block_start -= (int)s->w_size;
|
||||
s->strstart -= s->w_size;
|
||||
memcpy(s->window, s->window + s->w_size, s->strstart);
|
||||
if (s->matches < 2)
|
||||
s->matches++; /* add a pending slide_hash() */
|
||||
have += s->w_size; /* more space now */
|
||||
s->insert = MIN(s->insert, s->strstart);
|
||||
}
|
||||
|
||||
have = MIN(have, s->strm->avail_in);
|
||||
if (have) {
|
||||
PREFIX(read_buf)(s->strm, s->window + s->strstart, have);
|
||||
s->strstart += have;
|
||||
s->insert += MIN(have, s->w_size - s->insert);
|
||||
}
|
||||
s->high_water = MAX(s->high_water, s->strstart);
|
||||
|
||||
/* There was not enough avail_out to write a complete worthy or flushed
|
||||
* stored block to next_out. Write a stored block to pending instead, if we
|
||||
* have enough input for a worthy block, or if flushing and there is enough
|
||||
* room for the remaining input as a stored block in the pending buffer.
|
||||
*/
|
||||
have = (s->bi_valid + 42) >> 3; /* number of header bytes */
|
||||
/* maximum stored block length that will fit in pending: */
|
||||
have = MIN(s->pending_buf_size - have, MAX_STORED);
|
||||
min_block = MIN(have, s->w_size);
|
||||
left = (int)s->strstart - s->block_start;
|
||||
if (left >= min_block || ((left || flush == Z_FINISH) && flush != Z_NO_FLUSH && s->strm->avail_in == 0 && left <= have)) {
|
||||
len = MIN(left, have);
|
||||
last = flush == Z_FINISH && s->strm->avail_in == 0 && len == left ? 1 : 0;
|
||||
zng_tr_stored_block(s, (char *)s->window + s->block_start, len, last);
|
||||
s->block_start += (int)len;
|
||||
PREFIX(flush_pending)(s->strm);
|
||||
}
|
||||
|
||||
/* We've done all we can with the available input and output. */
|
||||
return last ? finish_started : need_more;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef FALLBACK_BUILTINS_H
|
||||
#define FALLBACK_BUILTINS_H
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM64EC)
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
/* This is not a general purpose replacement for __builtin_ctz. The function expects that value is != 0.
|
||||
* Because of that assumption trailing_zero is not initialized and the return value is not checked.
|
||||
* Tzcnt and bsf give identical results except when input value is 0, therefore this can not be allowed.
|
||||
* If tzcnt instruction is not supported, the cpu will itself execute bsf instead.
|
||||
* Performance tzcnt/bsf is identical on Intel cpu, tzcnt is faster than bsf on AMD cpu.
|
||||
*/
|
||||
static __forceinline int __builtin_ctz(unsigned int value) {
|
||||
Assert(value != 0, "Invalid input value: 0");
|
||||
# if defined(X86_FEATURES) && !(_MSC_VER < 1700)
|
||||
return (int)_tzcnt_u32(value);
|
||||
# else
|
||||
unsigned long trailing_zero;
|
||||
_BitScanForward(&trailing_zero, value);
|
||||
return (int)trailing_zero;
|
||||
# endif
|
||||
}
|
||||
#define HAVE_BUILTIN_CTZ
|
||||
|
||||
#ifdef _M_AMD64
|
||||
/* This is not a general purpose replacement for __builtin_ctzll. The function expects that value is != 0.
|
||||
* Because of that assumption trailing_zero is not initialized and the return value is not checked.
|
||||
*/
|
||||
static __forceinline int __builtin_ctzll(unsigned long long value) {
|
||||
Assert(value != 0, "Invalid input value: 0");
|
||||
# if defined(X86_FEATURES) && !(_MSC_VER < 1700)
|
||||
return (int)_tzcnt_u64(value);
|
||||
# else
|
||||
unsigned long trailing_zero;
|
||||
_BitScanForward64(&trailing_zero, value);
|
||||
return (int)trailing_zero;
|
||||
# endif
|
||||
}
|
||||
#define HAVE_BUILTIN_CTZLL
|
||||
#endif // Microsoft AMD64
|
||||
|
||||
#endif // Microsoft AMD64/IA64/x86/ARM/ARM64 test
|
||||
#endif // _MSC_VER & !clang
|
||||
|
||||
#endif // include guard FALLBACK_BUILTINS_H
|
||||
@@ -0,0 +1,363 @@
|
||||
/* functable.c -- Choose relevant optimized functions at runtime
|
||||
* Copyright (C) 2017 Hans Kristian Rosbach
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
#ifndef DISABLE_RUNTIME_CPU_DETECTION
|
||||
|
||||
#include "zbuild.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# include <intrin.h>
|
||||
#endif
|
||||
|
||||
#include "functable.h"
|
||||
#include "cpu_features.h"
|
||||
#include "arch_functions.h"
|
||||
|
||||
/* Platform has pointer size atomic store */
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
# define FUNCTABLE_ASSIGN(VAR, FUNC_NAME) \
|
||||
__atomic_store(&(functable.FUNC_NAME), &(VAR.FUNC_NAME), __ATOMIC_SEQ_CST)
|
||||
# define FUNCTABLE_BARRIER() __atomic_thread_fence(__ATOMIC_SEQ_CST)
|
||||
#elif defined(_MSC_VER)
|
||||
# define FUNCTABLE_ASSIGN(VAR, FUNC_NAME) \
|
||||
_InterlockedExchangePointer((void * volatile *)&(functable.FUNC_NAME), (void *)(VAR.FUNC_NAME))
|
||||
# if defined(_M_ARM) || defined(_M_ARM64)
|
||||
# define FUNCTABLE_BARRIER() do { \
|
||||
_ReadWriteBarrier(); \
|
||||
__dmb(0xB); /* _ARM_BARRIER_ISH */ \
|
||||
_ReadWriteBarrier(); \
|
||||
} while (0)
|
||||
# else
|
||||
# define FUNCTABLE_BARRIER() _ReadWriteBarrier()
|
||||
# endif
|
||||
#else
|
||||
# warning Unable to detect atomic intrinsic support.
|
||||
# define FUNCTABLE_ASSIGN(VAR, FUNC_NAME) \
|
||||
*((void * volatile *)&(functable.FUNC_NAME)) = (void *)(VAR.FUNC_NAME)
|
||||
# define FUNCTABLE_BARRIER() do { /* Empty */ } while (0)
|
||||
#endif
|
||||
|
||||
static void force_init_empty(void) {
|
||||
// empty
|
||||
}
|
||||
|
||||
static void init_functable(void) {
|
||||
struct functable_s ft;
|
||||
struct cpu_features cf;
|
||||
|
||||
cpu_check_features(&cf);
|
||||
|
||||
// Generic code
|
||||
ft.force_init = &force_init_empty;
|
||||
ft.adler32 = &adler32_c;
|
||||
ft.adler32_fold_copy = &adler32_fold_copy_c;
|
||||
ft.chunkmemset_safe = &chunkmemset_safe_c;
|
||||
ft.chunksize = &chunksize_c;
|
||||
ft.crc32 = &crc32_c;
|
||||
ft.crc32_fold = &crc32_fold_c;
|
||||
ft.crc32_fold_copy = &crc32_fold_copy_c;
|
||||
ft.crc32_fold_final = &crc32_fold_final_c;
|
||||
ft.crc32_fold_reset = &crc32_fold_reset_c;
|
||||
ft.inflate_fast = &inflate_fast_c;
|
||||
ft.slide_hash = &slide_hash_c;
|
||||
ft.longest_match = &longest_match_c;
|
||||
ft.longest_match_slow = &longest_match_slow_c;
|
||||
ft.compare256 = &compare256_c;
|
||||
|
||||
// Select arch-optimized functions
|
||||
|
||||
// X86 - SSE2
|
||||
#ifdef X86_SSE2
|
||||
# if !defined(__x86_64__) && !defined(_M_X64) && !defined(X86_NOCHECK_SSE2)
|
||||
if (cf.x86.has_sse2)
|
||||
# endif
|
||||
{
|
||||
ft.chunkmemset_safe = &chunkmemset_safe_sse2;
|
||||
ft.chunksize = &chunksize_sse2;
|
||||
ft.inflate_fast = &inflate_fast_sse2;
|
||||
ft.slide_hash = &slide_hash_sse2;
|
||||
# ifdef HAVE_BUILTIN_CTZ
|
||||
ft.compare256 = &compare256_sse2;
|
||||
ft.longest_match = &longest_match_sse2;
|
||||
ft.longest_match_slow = &longest_match_slow_sse2;
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
// X86 - SSSE3
|
||||
#ifdef X86_SSSE3
|
||||
if (cf.x86.has_ssse3) {
|
||||
ft.adler32 = &adler32_ssse3;
|
||||
ft.chunkmemset_safe = &chunkmemset_safe_ssse3;
|
||||
ft.inflate_fast = &inflate_fast_ssse3;
|
||||
}
|
||||
#endif
|
||||
// X86 - SSE4.2
|
||||
#ifdef X86_SSE42
|
||||
if (cf.x86.has_sse42) {
|
||||
ft.adler32_fold_copy = &adler32_fold_copy_sse42;
|
||||
}
|
||||
#endif
|
||||
// X86 - PCLMUL
|
||||
#ifdef X86_PCLMULQDQ_CRC
|
||||
if (cf.x86.has_pclmulqdq) {
|
||||
ft.crc32 = &crc32_pclmulqdq;
|
||||
ft.crc32_fold = &crc32_fold_pclmulqdq;
|
||||
ft.crc32_fold_copy = &crc32_fold_pclmulqdq_copy;
|
||||
ft.crc32_fold_final = &crc32_fold_pclmulqdq_final;
|
||||
ft.crc32_fold_reset = &crc32_fold_pclmulqdq_reset;
|
||||
}
|
||||
#endif
|
||||
// X86 - AVX
|
||||
#ifdef X86_AVX2
|
||||
/* BMI2 support is all but implicit with AVX2 but let's sanity check this just in case. Enabling BMI2 allows for
|
||||
* flagless shifts, resulting in fewer flag stalls for the pipeline, and allows us to set destination registers
|
||||
* for the shift results as an operand, eliminating several register-register moves when the original value needs
|
||||
* to remain intact. They also allow for a count operand that isn't the CL register, avoiding contention there */
|
||||
if (cf.x86.has_avx2 && cf.x86.has_bmi2) {
|
||||
ft.adler32 = &adler32_avx2;
|
||||
ft.adler32_fold_copy = &adler32_fold_copy_avx2;
|
||||
ft.chunkmemset_safe = &chunkmemset_safe_avx2;
|
||||
ft.chunksize = &chunksize_avx2;
|
||||
ft.inflate_fast = &inflate_fast_avx2;
|
||||
ft.slide_hash = &slide_hash_avx2;
|
||||
# ifdef HAVE_BUILTIN_CTZ
|
||||
ft.compare256 = &compare256_avx2;
|
||||
ft.longest_match = &longest_match_avx2;
|
||||
ft.longest_match_slow = &longest_match_slow_avx2;
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
// X86 - AVX512 (F,DQ,BW,Vl)
|
||||
#ifdef X86_AVX512
|
||||
if (cf.x86.has_avx512_common) {
|
||||
ft.adler32 = &adler32_avx512;
|
||||
ft.adler32_fold_copy = &adler32_fold_copy_avx512;
|
||||
ft.chunkmemset_safe = &chunkmemset_safe_avx512;
|
||||
ft.chunksize = &chunksize_avx512;
|
||||
ft.inflate_fast = &inflate_fast_avx512;
|
||||
}
|
||||
#endif
|
||||
#ifdef X86_AVX512VNNI
|
||||
if (cf.x86.has_avx512vnni) {
|
||||
ft.adler32 = &adler32_avx512_vnni;
|
||||
ft.adler32_fold_copy = &adler32_fold_copy_avx512_vnni;
|
||||
}
|
||||
#endif
|
||||
// X86 - VPCLMULQDQ
|
||||
#ifdef X86_VPCLMULQDQ_CRC
|
||||
if (cf.x86.has_pclmulqdq && cf.x86.has_avx512_common && cf.x86.has_vpclmulqdq) {
|
||||
ft.crc32 = &crc32_vpclmulqdq;
|
||||
ft.crc32_fold = &crc32_fold_vpclmulqdq;
|
||||
ft.crc32_fold_copy = &crc32_fold_vpclmulqdq_copy;
|
||||
ft.crc32_fold_final = &crc32_fold_vpclmulqdq_final;
|
||||
ft.crc32_fold_reset = &crc32_fold_vpclmulqdq_reset;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// ARM - SIMD
|
||||
#ifdef ARM_SIMD
|
||||
# ifndef ARM_NOCHECK_SIMD
|
||||
if (cf.arm.has_simd)
|
||||
# endif
|
||||
{
|
||||
ft.slide_hash = &slide_hash_armv6;
|
||||
}
|
||||
#endif
|
||||
// ARM - NEON
|
||||
#ifdef ARM_NEON
|
||||
# ifndef ARM_NOCHECK_NEON
|
||||
if (cf.arm.has_neon)
|
||||
# endif
|
||||
{
|
||||
ft.adler32 = &adler32_neon;
|
||||
ft.adler32_fold_copy = &adler32_fold_copy_neon;
|
||||
ft.chunkmemset_safe = &chunkmemset_safe_neon;
|
||||
ft.chunksize = &chunksize_neon;
|
||||
ft.inflate_fast = &inflate_fast_neon;
|
||||
ft.slide_hash = &slide_hash_neon;
|
||||
# ifdef HAVE_BUILTIN_CTZLL
|
||||
ft.compare256 = &compare256_neon;
|
||||
ft.longest_match = &longest_match_neon;
|
||||
ft.longest_match_slow = &longest_match_slow_neon;
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
// ARM - CRC32
|
||||
#ifdef ARM_CRC32
|
||||
if (cf.arm.has_crc32) {
|
||||
ft.crc32 = &crc32_armv8;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Power - VMX
|
||||
#ifdef PPC_VMX
|
||||
if (cf.power.has_altivec) {
|
||||
ft.adler32 = &adler32_vmx;
|
||||
ft.slide_hash = &slide_hash_vmx;
|
||||
}
|
||||
#endif
|
||||
// Power8 - VSX
|
||||
#ifdef POWER8_VSX
|
||||
if (cf.power.has_arch_2_07) {
|
||||
ft.adler32 = &adler32_power8;
|
||||
ft.chunkmemset_safe = &chunkmemset_safe_power8;
|
||||
ft.chunksize = &chunksize_power8;
|
||||
ft.inflate_fast = &inflate_fast_power8;
|
||||
ft.slide_hash = &slide_hash_power8;
|
||||
}
|
||||
#endif
|
||||
#ifdef POWER8_VSX_CRC32
|
||||
if (cf.power.has_arch_2_07)
|
||||
ft.crc32 = &crc32_power8;
|
||||
#endif
|
||||
// Power9
|
||||
#ifdef POWER9
|
||||
if (cf.power.has_arch_3_00) {
|
||||
ft.compare256 = &compare256_power9;
|
||||
ft.longest_match = &longest_match_power9;
|
||||
ft.longest_match_slow = &longest_match_slow_power9;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// RISCV - RVV
|
||||
#ifdef RISCV_RVV
|
||||
if (cf.riscv.has_rvv) {
|
||||
ft.adler32 = &adler32_rvv;
|
||||
ft.adler32_fold_copy = &adler32_fold_copy_rvv;
|
||||
ft.chunkmemset_safe = &chunkmemset_safe_rvv;
|
||||
ft.chunksize = &chunksize_rvv;
|
||||
ft.compare256 = &compare256_rvv;
|
||||
ft.inflate_fast = &inflate_fast_rvv;
|
||||
ft.longest_match = &longest_match_rvv;
|
||||
ft.longest_match_slow = &longest_match_slow_rvv;
|
||||
ft.slide_hash = &slide_hash_rvv;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// S390
|
||||
#ifdef S390_CRC32_VX
|
||||
if (cf.s390.has_vx)
|
||||
ft.crc32 = crc32_s390_vx;
|
||||
#endif
|
||||
|
||||
// Assign function pointers individually for atomic operation
|
||||
FUNCTABLE_ASSIGN(ft, force_init);
|
||||
FUNCTABLE_ASSIGN(ft, adler32);
|
||||
FUNCTABLE_ASSIGN(ft, adler32_fold_copy);
|
||||
FUNCTABLE_ASSIGN(ft, chunkmemset_safe);
|
||||
FUNCTABLE_ASSIGN(ft, chunksize);
|
||||
FUNCTABLE_ASSIGN(ft, compare256);
|
||||
FUNCTABLE_ASSIGN(ft, crc32);
|
||||
FUNCTABLE_ASSIGN(ft, crc32_fold);
|
||||
FUNCTABLE_ASSIGN(ft, crc32_fold_copy);
|
||||
FUNCTABLE_ASSIGN(ft, crc32_fold_final);
|
||||
FUNCTABLE_ASSIGN(ft, crc32_fold_reset);
|
||||
FUNCTABLE_ASSIGN(ft, inflate_fast);
|
||||
FUNCTABLE_ASSIGN(ft, longest_match);
|
||||
FUNCTABLE_ASSIGN(ft, longest_match_slow);
|
||||
FUNCTABLE_ASSIGN(ft, slide_hash);
|
||||
|
||||
// Memory barrier for weak memory order CPUs
|
||||
FUNCTABLE_BARRIER();
|
||||
}
|
||||
|
||||
/* stub functions */
|
||||
static void force_init_stub(void) {
|
||||
init_functable();
|
||||
}
|
||||
|
||||
static uint32_t adler32_stub(uint32_t adler, const uint8_t* buf, size_t len) {
|
||||
init_functable();
|
||||
return functable.adler32(adler, buf, len);
|
||||
}
|
||||
|
||||
static uint32_t adler32_fold_copy_stub(uint32_t adler, uint8_t* dst, const uint8_t* src, size_t len) {
|
||||
init_functable();
|
||||
return functable.adler32_fold_copy(adler, dst, src, len);
|
||||
}
|
||||
|
||||
static uint8_t* chunkmemset_safe_stub(uint8_t* out, uint8_t *from, unsigned len, unsigned left) {
|
||||
init_functable();
|
||||
return functable.chunkmemset_safe(out, from, len, left);
|
||||
}
|
||||
|
||||
static uint32_t chunksize_stub(void) {
|
||||
init_functable();
|
||||
return functable.chunksize();
|
||||
}
|
||||
|
||||
static uint32_t compare256_stub(const uint8_t* src0, const uint8_t* src1) {
|
||||
init_functable();
|
||||
return functable.compare256(src0, src1);
|
||||
}
|
||||
|
||||
static uint32_t crc32_stub(uint32_t crc, const uint8_t* buf, size_t len) {
|
||||
init_functable();
|
||||
return functable.crc32(crc, buf, len);
|
||||
}
|
||||
|
||||
static void crc32_fold_stub(crc32_fold* crc, const uint8_t* src, size_t len, uint32_t init_crc) {
|
||||
init_functable();
|
||||
functable.crc32_fold(crc, src, len, init_crc);
|
||||
}
|
||||
|
||||
static void crc32_fold_copy_stub(crc32_fold* crc, uint8_t* dst, const uint8_t* src, size_t len) {
|
||||
init_functable();
|
||||
functable.crc32_fold_copy(crc, dst, src, len);
|
||||
}
|
||||
|
||||
static uint32_t crc32_fold_final_stub(crc32_fold* crc) {
|
||||
init_functable();
|
||||
return functable.crc32_fold_final(crc);
|
||||
}
|
||||
|
||||
static uint32_t crc32_fold_reset_stub(crc32_fold* crc) {
|
||||
init_functable();
|
||||
return functable.crc32_fold_reset(crc);
|
||||
}
|
||||
|
||||
static void inflate_fast_stub(PREFIX3(stream) *strm, uint32_t start) {
|
||||
init_functable();
|
||||
functable.inflate_fast(strm, start);
|
||||
}
|
||||
|
||||
static uint32_t longest_match_stub(deflate_state* const s, Pos cur_match) {
|
||||
init_functable();
|
||||
return functable.longest_match(s, cur_match);
|
||||
}
|
||||
|
||||
static uint32_t longest_match_slow_stub(deflate_state* const s, Pos cur_match) {
|
||||
init_functable();
|
||||
return functable.longest_match_slow(s, cur_match);
|
||||
}
|
||||
|
||||
static void slide_hash_stub(deflate_state* s) {
|
||||
init_functable();
|
||||
functable.slide_hash(s);
|
||||
}
|
||||
|
||||
/* functable init */
|
||||
Z_INTERNAL struct functable_s functable = {
|
||||
force_init_stub,
|
||||
adler32_stub,
|
||||
adler32_fold_copy_stub,
|
||||
chunkmemset_safe_stub,
|
||||
chunksize_stub,
|
||||
compare256_stub,
|
||||
crc32_stub,
|
||||
crc32_fold_stub,
|
||||
crc32_fold_copy_stub,
|
||||
crc32_fold_final_stub,
|
||||
crc32_fold_reset_stub,
|
||||
inflate_fast_stub,
|
||||
longest_match_stub,
|
||||
longest_match_slow_stub,
|
||||
slide_hash_stub,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
/* functable.h -- Struct containing function pointers to optimized functions
|
||||
* Copyright (C) 2017 Hans Kristian Rosbach
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef FUNCTABLE_H_
|
||||
#define FUNCTABLE_H_
|
||||
|
||||
#include "deflate.h"
|
||||
#include "crc32.h"
|
||||
|
||||
#ifdef DISABLE_RUNTIME_CPU_DETECTION
|
||||
|
||||
# include "arch_functions.h"
|
||||
|
||||
/* When compiling with native instructions it is not necessary to use functable.
|
||||
* Instead we use native_ macro indicating the best available variant of arch-specific
|
||||
* functions for the current platform.
|
||||
*/
|
||||
# define FUNCTABLE_INIT ((void)0)
|
||||
# define FUNCTABLE_CALL(name) native_ ## name
|
||||
# define FUNCTABLE_FPTR(name) &native_ ## name
|
||||
|
||||
#else
|
||||
|
||||
struct functable_s {
|
||||
void (* force_init) (void);
|
||||
uint32_t (* adler32) (uint32_t adler, const uint8_t *buf, size_t len);
|
||||
uint32_t (* adler32_fold_copy) (uint32_t adler, uint8_t *dst, const uint8_t *src, size_t len);
|
||||
uint8_t* (* chunkmemset_safe) (uint8_t *out, uint8_t *from, unsigned len, unsigned left);
|
||||
uint32_t (* chunksize) (void);
|
||||
uint32_t (* compare256) (const uint8_t *src0, const uint8_t *src1);
|
||||
uint32_t (* crc32) (uint32_t crc, const uint8_t *buf, size_t len);
|
||||
void (* crc32_fold) (struct crc32_fold_s *crc, const uint8_t *src, size_t len, uint32_t init_crc);
|
||||
void (* crc32_fold_copy) (struct crc32_fold_s *crc, uint8_t *dst, const uint8_t *src, size_t len);
|
||||
uint32_t (* crc32_fold_final) (struct crc32_fold_s *crc);
|
||||
uint32_t (* crc32_fold_reset) (struct crc32_fold_s *crc);
|
||||
void (* inflate_fast) (PREFIX3(stream) *strm, uint32_t start);
|
||||
uint32_t (* longest_match) (deflate_state *const s, Pos cur_match);
|
||||
uint32_t (* longest_match_slow) (deflate_state *const s, Pos cur_match);
|
||||
void (* slide_hash) (deflate_state *s);
|
||||
};
|
||||
|
||||
Z_INTERNAL extern struct functable_s functable;
|
||||
|
||||
|
||||
/* Explicitly indicate functions are conditionally dispatched.
|
||||
*/
|
||||
# define FUNCTABLE_INIT functable.force_init()
|
||||
# define FUNCTABLE_CALL(name) functable.name
|
||||
# define FUNCTABLE_FPTR(name) functable.name
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+38
-106
@@ -1,3 +1,5 @@
|
||||
#ifndef GZGUTS_H_
|
||||
#define GZGUTS_H_
|
||||
/* gzguts.h -- zlib internal header definitions for gz* operations
|
||||
* Copyright (C) 2004-2024 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
@@ -11,34 +13,32 @@
|
||||
# undef _TIME_BITS
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_HIDDEN
|
||||
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
||||
#if defined(HAVE_VISIBILITY_INTERNAL)
|
||||
# define Z_INTERNAL __attribute__((visibility ("internal")))
|
||||
#elif defined(HAVE_VISIBILITY_HIDDEN)
|
||||
# define Z_INTERNAL __attribute__((visibility ("hidden")))
|
||||
#else
|
||||
# define ZLIB_INTERNAL
|
||||
# define Z_INTERNAL
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "zlib.h"
|
||||
#ifdef STDC
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#ifndef _POSIX_SOURCE
|
||||
# define _POSIX_SOURCE
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#if defined(ZLIB_COMPAT)
|
||||
# include "zlib.h"
|
||||
#else
|
||||
# include "zlib-ng.h"
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
|
||||
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <io.h>
|
||||
# define WIDECHAR
|
||||
#endif
|
||||
|
||||
@@ -49,98 +49,28 @@
|
||||
# define close _close
|
||||
#endif
|
||||
|
||||
#ifdef NO_DEFLATE /* for compatibility with old definition */
|
||||
# define NO_GZCOMPRESS
|
||||
#endif
|
||||
|
||||
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
|
||||
# ifndef HAVE_VSNPRINTF
|
||||
# define HAVE_VSNPRINTF
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VSNPRINTF
|
||||
# ifdef MSDOS
|
||||
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
||||
but for now we just assume it doesn't. */
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef __TURBOC__
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef WIN32
|
||||
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
||||
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
|
||||
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
#if !defined(STDC99) && !defined(__CYGWIN__) && !defined(__MINGW__) && defined(_WIN32)
|
||||
# if !defined(vsnprintf)
|
||||
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
# endif
|
||||
# ifdef __SASC
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef VMS
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef __OS400__
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
# ifdef __MVS__
|
||||
# define NO_vsnprintf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* unlike snprintf (which is required in C99), _snprintf does not guarantee
|
||||
null termination of the result -- however this is only used in gzlib.c where
|
||||
the result is assured to fit in the space provided */
|
||||
null termination of the result -- however this is only used in gzlib.c
|
||||
where the result is assured to fit in the space provided */
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#ifndef local
|
||||
# define local static
|
||||
#endif
|
||||
/* since "static" is used to mean two completely different things in C, we
|
||||
define "local" for the non-static meaning of "static", for readability
|
||||
(compile with -Dlocal if your debugger can't find static symbols) */
|
||||
|
||||
/* gz* functions always use library allocation functions */
|
||||
#ifndef STDC
|
||||
extern voidp malloc(uInt size);
|
||||
extern void free(voidpf ptr);
|
||||
#endif
|
||||
|
||||
/* get errno and strerror definition */
|
||||
#if defined UNDER_CE
|
||||
# include <windows.h>
|
||||
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
|
||||
#ifndef NO_STRERROR
|
||||
# include <errno.h>
|
||||
# define zstrerror() strerror(errno)
|
||||
#else
|
||||
# ifndef NO_STRERROR
|
||||
# include <errno.h>
|
||||
# define zstrerror() strerror(errno)
|
||||
# else
|
||||
# define zstrerror() "stdio error (consult errno)"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* provide prototypes for these when building zlib without LFS */
|
||||
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
|
||||
ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
|
||||
ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
|
||||
ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
|
||||
ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
|
||||
# define zstrerror() "stdio error (consult errno)"
|
||||
#endif
|
||||
|
||||
/* default memLevel */
|
||||
@@ -152,7 +82,9 @@
|
||||
|
||||
/* default i/o buffer size -- double this for output when reading (this and
|
||||
twice this must be able to fit in an unsigned type) */
|
||||
#define GZBUFSIZE 8192
|
||||
#ifndef GZBUFSIZE
|
||||
# define GZBUFSIZE 131072
|
||||
#endif
|
||||
|
||||
/* gzip modes, also provide a little integrity check on the passed structure */
|
||||
#define GZ_NONE 0
|
||||
@@ -197,18 +129,18 @@ typedef struct {
|
||||
int err; /* error code */
|
||||
char *msg; /* error message */
|
||||
/* zlib inflate or deflate stream */
|
||||
z_stream strm; /* stream structure in-place (not a pointer) */
|
||||
PREFIX3(stream) strm; /* stream structure in-place (not a pointer) */
|
||||
} gz_state;
|
||||
typedef gz_state FAR *gz_statep;
|
||||
typedef gz_state *gz_statep;
|
||||
|
||||
/* shared functions */
|
||||
void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
|
||||
#if defined UNDER_CE
|
||||
char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
|
||||
void Z_INTERNAL gz_error(gz_state *, int, const char *);
|
||||
#ifdef ZLIB_COMPAT
|
||||
unsigned Z_INTERNAL gz_intmax(void);
|
||||
#endif
|
||||
|
||||
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
|
||||
value -- needed when comparing unsigned to z_off64_t, which is signed
|
||||
(possible z_off64_t types off_t, off64_t, and long are all signed) */
|
||||
unsigned ZLIB_INTERNAL gz_intmax(void);
|
||||
#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
|
||||
#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
|
||||
|
||||
#endif /* GZGUTS_H_ */
|
||||
+100
-151
@@ -3,9 +3,11 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "zutil_p.h"
|
||||
#include "gzguts.h"
|
||||
|
||||
#if defined(_WIN32) && !defined(__BORLANDC__)
|
||||
#if defined(_WIN32)
|
||||
# define LSEEK _lseeki64
|
||||
#else
|
||||
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
||||
@@ -15,58 +17,12 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined UNDER_CE
|
||||
|
||||
/* Map the Windows error number in ERROR to a locale-dependent error message
|
||||
string and return a pointer to it. Typically, the values for ERROR come
|
||||
from GetLastError.
|
||||
|
||||
The string pointed to shall not be modified by the application, but may be
|
||||
overwritten by a subsequent call to gz_strwinerror
|
||||
|
||||
The gz_strwinerror function does not change the current setting of
|
||||
GetLastError. */
|
||||
char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
|
||||
static char buf[1024];
|
||||
|
||||
wchar_t *msgbuf;
|
||||
DWORD lasterr = GetLastError();
|
||||
DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
|
||||
| FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||
NULL,
|
||||
error,
|
||||
0, /* Default language */
|
||||
(LPVOID)&msgbuf,
|
||||
0,
|
||||
NULL);
|
||||
if (chars != 0) {
|
||||
/* If there is an \r\n appended, zap it. */
|
||||
if (chars >= 2
|
||||
&& msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
|
||||
chars -= 2;
|
||||
msgbuf[chars] = 0;
|
||||
}
|
||||
|
||||
if (chars > sizeof (buf) - 1) {
|
||||
chars = sizeof (buf) - 1;
|
||||
msgbuf[chars] = 0;
|
||||
}
|
||||
|
||||
wcstombs(buf, msgbuf, chars + 1);
|
||||
LocalFree(msgbuf);
|
||||
}
|
||||
else {
|
||||
sprintf(buf, "unknown win32 error (%ld)", error);
|
||||
}
|
||||
|
||||
SetLastError(lasterr);
|
||||
return buf;
|
||||
}
|
||||
|
||||
#endif /* UNDER_CE */
|
||||
/* Local functions */
|
||||
static void gz_reset(gz_state *);
|
||||
static gzFile gz_open(const void *, int, const char *);
|
||||
|
||||
/* Reset gzip file state */
|
||||
local void gz_reset(gz_statep state) {
|
||||
static void gz_reset(gz_state *state) {
|
||||
state->x.have = 0; /* no output data available */
|
||||
if (state->mode == GZ_READ) { /* for reading ... */
|
||||
state->eof = 0; /* not at end of file */
|
||||
@@ -82,9 +38,9 @@ local void gz_reset(gz_statep state) {
|
||||
}
|
||||
|
||||
/* Open a gzip file either by name or file descriptor. */
|
||||
local gzFile gz_open(const void *path, int fd, const char *mode) {
|
||||
gz_statep state;
|
||||
z_size_t len;
|
||||
static gzFile gz_open(const void *path, int fd, const char *mode) {
|
||||
gz_state *state;
|
||||
size_t len;
|
||||
int oflag;
|
||||
#ifdef O_CLOEXEC
|
||||
int cloexec = 0;
|
||||
@@ -98,7 +54,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
|
||||
return NULL;
|
||||
|
||||
/* allocate gzFile structure to return */
|
||||
state = (gz_statep)malloc(sizeof(gz_state));
|
||||
state = (gz_state *)zng_alloc(sizeof(gz_state));
|
||||
if (state == NULL)
|
||||
return NULL;
|
||||
state->size = 0; /* no buffers allocated yet */
|
||||
@@ -111,9 +67,9 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
|
||||
state->strategy = Z_DEFAULT_STRATEGY;
|
||||
state->direct = 0;
|
||||
while (*mode) {
|
||||
if (*mode >= '0' && *mode <= '9')
|
||||
if (*mode >= '0' && *mode <= '9') {
|
||||
state->level = *mode - '0';
|
||||
else
|
||||
} else {
|
||||
switch (*mode) {
|
||||
case 'r':
|
||||
state->mode = GZ_READ;
|
||||
@@ -127,7 +83,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
|
||||
break;
|
||||
#endif
|
||||
case '+': /* can't read and write at the same time */
|
||||
free(state);
|
||||
zng_free(state);
|
||||
return NULL;
|
||||
case 'b': /* ignore -- will request binary anyway */
|
||||
break;
|
||||
@@ -157,21 +113,22 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
|
||||
state->direct = 1;
|
||||
break;
|
||||
default: /* could consider as an error, but just ignore */
|
||||
;
|
||||
{}
|
||||
}
|
||||
}
|
||||
mode++;
|
||||
}
|
||||
|
||||
/* must provide an "r", "w", or "a" */
|
||||
if (state->mode == GZ_NONE) {
|
||||
free(state);
|
||||
zng_free(state);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* can't force transparent read */
|
||||
if (state->mode == GZ_READ) {
|
||||
if (state->direct) {
|
||||
free(state);
|
||||
zng_free(state);
|
||||
return NULL;
|
||||
}
|
||||
state->direct = 1; /* for empty file */
|
||||
@@ -180,31 +137,27 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
|
||||
/* save the path name for error messages */
|
||||
#ifdef WIDECHAR
|
||||
if (fd == -2) {
|
||||
len = wcstombs(NULL, path, 0);
|
||||
if (len == (z_size_t)-1)
|
||||
len = wcstombs(NULL, (const wchar_t *)path, 0);
|
||||
if (len == (size_t)-1)
|
||||
len = 0;
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif
|
||||
len = strlen((const char *)path);
|
||||
state->path = (char *)malloc(len + 1);
|
||||
if (state->path == NULL) {
|
||||
free(state);
|
||||
zng_free(state);
|
||||
return NULL;
|
||||
}
|
||||
#ifdef WIDECHAR
|
||||
if (fd == -2)
|
||||
if (len)
|
||||
wcstombs(state->path, path, len + 1);
|
||||
else
|
||||
if (len) {
|
||||
wcstombs(state->path, (const wchar_t *)path, len + 1);
|
||||
} else {
|
||||
*(state->path) = 0;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||
(void)snprintf(state->path, len + 1, "%s", (const char *)path);
|
||||
#else
|
||||
strcpy(state->path, path);
|
||||
#endif
|
||||
|
||||
/* compute the flags for open() */
|
||||
oflag =
|
||||
@@ -229,13 +182,15 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
|
||||
|
||||
/* open the file with the appropriate flags (or just use fd) */
|
||||
state->fd = fd > -1 ? fd : (
|
||||
#ifdef WIDECHAR
|
||||
fd == -2 ? _wopen(path, oflag, 0666) :
|
||||
#if defined(_WIN32)
|
||||
fd == -2 ? _wopen((const wchar_t *)path, oflag, 0666) :
|
||||
#elif __CYGWIN__
|
||||
fd == -2 ? open(state->path, oflag, 0666) :
|
||||
#endif
|
||||
open((const char *)path, oflag, 0666));
|
||||
if (state->fd == -1) {
|
||||
free(state->path);
|
||||
free(state);
|
||||
zng_free(state);
|
||||
return NULL;
|
||||
}
|
||||
if (state->mode == GZ_APPEND) {
|
||||
@@ -257,27 +212,24 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
gzFile ZEXPORT gzopen(const char *path, const char *mode) {
|
||||
gzFile Z_EXPORT PREFIX(gzopen)(const char *path, const char *mode) {
|
||||
return gz_open(path, -1, mode);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
gzFile ZEXPORT gzopen64(const char *path, const char *mode) {
|
||||
#ifdef ZLIB_COMPAT
|
||||
gzFile Z_EXPORT PREFIX4(gzopen)(const char *path, const char *mode) {
|
||||
return gz_open(path, -1, mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
gzFile ZEXPORT gzdopen(int fd, const char *mode) {
|
||||
gzFile Z_EXPORT PREFIX(gzdopen)(int fd, const char *mode) {
|
||||
char *path; /* identifier for error messages */
|
||||
gzFile gz;
|
||||
|
||||
if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
|
||||
return NULL;
|
||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||
(void)snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd);
|
||||
#else
|
||||
sprintf(path, "<fd:%d>", fd); /* for debugging */
|
||||
#endif
|
||||
(void)snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */
|
||||
gz = gz_open(path, fd, mode);
|
||||
free(path);
|
||||
return gz;
|
||||
@@ -285,19 +237,33 @@ gzFile ZEXPORT gzdopen(int fd, const char *mode) {
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
#ifdef WIDECHAR
|
||||
gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode) {
|
||||
gzFile Z_EXPORT PREFIX(gzopen_w)(const wchar_t *path, const char *mode) {
|
||||
return gz_open(path, -2, mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
int Z_EXPORT PREFIX(gzclose)(gzFile file) {
|
||||
#ifndef NO_GZCOMPRESS
|
||||
gz_state *state;
|
||||
|
||||
if (file == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
state = (gz_state *)file;
|
||||
|
||||
return state->mode == GZ_READ ? PREFIX(gzclose_r)(file) : PREFIX(gzclose_w)(file);
|
||||
#else
|
||||
return PREFIX(gzclose_r)(file);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzbuffer(gzFile file, unsigned size) {
|
||||
gz_statep state;
|
||||
int Z_EXPORT PREFIX(gzbuffer)(gzFile file, unsigned size) {
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return -1;
|
||||
|
||||
@@ -315,17 +281,16 @@ int ZEXPORT gzbuffer(gzFile file, unsigned size) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzrewind(gzFile file) {
|
||||
gz_statep state;
|
||||
int Z_EXPORT PREFIX(gzrewind)(gzFile file) {
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* check that we're reading and that there's no error */
|
||||
if (state->mode != GZ_READ ||
|
||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return -1;
|
||||
|
||||
/* back up and start over */
|
||||
@@ -336,15 +301,15 @@ int ZEXPORT gzrewind(gzFile file) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
|
||||
z_off64_t Z_EXPORT PREFIX4(gzseek)(gzFile file, z_off64_t offset, int whence) {
|
||||
unsigned n;
|
||||
z_off64_t ret;
|
||||
gz_statep state;
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return -1;
|
||||
|
||||
@@ -364,8 +329,7 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
|
||||
state->seek = 0;
|
||||
|
||||
/* if within raw area while reading, just go there */
|
||||
if (state->mode == GZ_READ && state->how == COPY &&
|
||||
state->x.pos + offset >= 0) {
|
||||
if (state->mode == GZ_READ && state->how == COPY && state->x.pos + offset >= 0) {
|
||||
ret = LSEEK(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR);
|
||||
if (ret == -1)
|
||||
return -1;
|
||||
@@ -386,14 +350,13 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
|
||||
offset += state->x.pos;
|
||||
if (offset < 0) /* before start of file! */
|
||||
return -1;
|
||||
if (gzrewind(file) == -1) /* rewind, then skip to offset */
|
||||
if (PREFIX(gzrewind)(file) == -1) /* rewind, then skip to offset */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* if reading, skip what's in output buffer (one less gzgetc() check) */
|
||||
if (state->mode == GZ_READ) {
|
||||
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
|
||||
(unsigned)offset : state->x.have;
|
||||
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ? (unsigned)offset : state->x.have;
|
||||
state->x.have -= n;
|
||||
state->x.next += n;
|
||||
state->x.pos += n;
|
||||
@@ -409,21 +372,23 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) {
|
||||
#ifdef ZLIB_COMPAT
|
||||
z_off_t Z_EXPORT PREFIX(gzseek)(gzFile file, z_off_t offset, int whence) {
|
||||
z_off64_t ret;
|
||||
|
||||
ret = gzseek64(file, (z_off64_t)offset, whence);
|
||||
ret = PREFIX4(gzseek)(file, (z_off64_t)offset, whence);
|
||||
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off64_t ZEXPORT gztell64(gzFile file) {
|
||||
gz_statep state;
|
||||
z_off64_t Z_EXPORT PREFIX4(gztell)(gzFile file) {
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return -1;
|
||||
|
||||
@@ -432,22 +397,25 @@ z_off64_t ZEXPORT gztell64(gzFile file) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off_t ZEXPORT gztell(gzFile file) {
|
||||
#ifdef ZLIB_COMPAT
|
||||
z_off_t Z_EXPORT PREFIX(gztell)(gzFile file) {
|
||||
|
||||
z_off64_t ret;
|
||||
|
||||
ret = gztell64(file);
|
||||
ret = PREFIX4(gztell)(file);
|
||||
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off64_t ZEXPORT gzoffset64(gzFile file) {
|
||||
z_off64_t Z_EXPORT PREFIX4(gzoffset)(gzFile file) {
|
||||
z_off64_t offset;
|
||||
gz_statep state;
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return -1;
|
||||
|
||||
@@ -461,21 +429,23 @@ z_off64_t ZEXPORT gzoffset64(gzFile file) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_off_t ZEXPORT gzoffset(gzFile file) {
|
||||
#ifdef ZLIB_COMPAT
|
||||
z_off_t Z_EXPORT PREFIX(gzoffset)(gzFile file) {
|
||||
z_off64_t ret;
|
||||
|
||||
ret = gzoffset64(file);
|
||||
ret = PREFIX4(gzoffset)(file);
|
||||
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzeof(gzFile file) {
|
||||
gz_statep state;
|
||||
int Z_EXPORT PREFIX(gzeof)(gzFile file) {
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return 0;
|
||||
|
||||
@@ -484,31 +454,30 @@ int ZEXPORT gzeof(gzFile file) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
const char * ZEXPORT gzerror(gzFile file, int *errnum) {
|
||||
gz_statep state;
|
||||
const char * Z_EXPORT PREFIX(gzerror)(gzFile file, int *errnum) {
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return NULL;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return NULL;
|
||||
|
||||
/* return error information */
|
||||
if (errnum != NULL)
|
||||
*errnum = state->err;
|
||||
return state->err == Z_MEM_ERROR ? "out of memory" :
|
||||
(state->msg == NULL ? "" : state->msg);
|
||||
return state->err == Z_MEM_ERROR ? "out of memory" : (state->msg == NULL ? "" : state->msg);
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
void ZEXPORT gzclearerr(gzFile file) {
|
||||
gz_statep state;
|
||||
void Z_EXPORT PREFIX(gzclearerr)(gzFile file) {
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure and check integrity */
|
||||
if (file == NULL)
|
||||
return;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
|
||||
return;
|
||||
|
||||
@@ -526,7 +495,7 @@ void ZEXPORT gzclearerr(gzFile file) {
|
||||
memory). Simply save the error message as a static string. If there is an
|
||||
allocation failure constructing the error message, then convert the error to
|
||||
out of memory. */
|
||||
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
|
||||
void Z_INTERNAL gz_error(gz_state *state, int err, const char *msg) {
|
||||
/* free previously allocated message and clear */
|
||||
if (state->msg != NULL) {
|
||||
if (state->err != Z_MEM_ERROR)
|
||||
@@ -548,35 +517,15 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
|
||||
return;
|
||||
|
||||
/* construct error message with path */
|
||||
if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
|
||||
NULL) {
|
||||
if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
|
||||
state->err = Z_MEM_ERROR;
|
||||
return;
|
||||
}
|
||||
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
|
||||
(void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
|
||||
"%s%s%s", state->path, ": ", msg);
|
||||
#else
|
||||
strcpy(state->msg, state->path);
|
||||
strcat(state->msg, ": ");
|
||||
strcat(state->msg, msg);
|
||||
#endif
|
||||
(void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3, "%s%s%s", state->path, ": ", msg);
|
||||
}
|
||||
|
||||
/* portably return maximum value for an int (when limits.h presumed not
|
||||
available) -- we need to do this to cover cases where 2's complement not
|
||||
used, since C standard permits 1's complement and sign-bit representations,
|
||||
otherwise we could just use ((unsigned)-1) >> 1 */
|
||||
unsigned ZLIB_INTERNAL gz_intmax(void) {
|
||||
#ifdef INT_MAX
|
||||
#ifdef ZLIB_COMPAT
|
||||
unsigned Z_INTERNAL gz_intmax(void) {
|
||||
return INT_MAX;
|
||||
#else
|
||||
unsigned p = 1, q;
|
||||
do {
|
||||
q = p;
|
||||
p <<= 1;
|
||||
p++;
|
||||
} while (p > q);
|
||||
return q >> 1;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,606 @@
|
||||
/* gzread.c -- zlib functions for reading gzip files
|
||||
* Copyright (C) 2004-2017 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "zutil_p.h"
|
||||
#include "gzguts.h"
|
||||
|
||||
/* Local functions */
|
||||
static int gz_load(gz_state *, unsigned char *, unsigned, unsigned *);
|
||||
static int gz_avail(gz_state *);
|
||||
static int gz_look(gz_state *);
|
||||
static int gz_decomp(gz_state *);
|
||||
static int gz_fetch(gz_state *);
|
||||
static int gz_skip(gz_state *, z_off64_t);
|
||||
static size_t gz_read(gz_state *, void *, size_t);
|
||||
|
||||
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
|
||||
state->fd, and update state->eof, state->err, and state->msg as appropriate.
|
||||
This function needs to loop on read(), since read() is not guaranteed to
|
||||
read the number of bytes requested, depending on the type of descriptor. */
|
||||
static int gz_load(gz_state *state, unsigned char *buf, unsigned len, unsigned *have) {
|
||||
ssize_t ret;
|
||||
|
||||
*have = 0;
|
||||
do {
|
||||
ret = read(state->fd, buf + *have, len - *have);
|
||||
if (ret <= 0)
|
||||
break;
|
||||
*have += (unsigned)ret;
|
||||
} while (*have < len);
|
||||
if (ret < 0) {
|
||||
gz_error(state, Z_ERRNO, zstrerror());
|
||||
return -1;
|
||||
}
|
||||
if (ret == 0)
|
||||
state->eof = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Load up input buffer and set eof flag if last data loaded -- return -1 on
|
||||
error, 0 otherwise. Note that the eof flag is set when the end of the input
|
||||
file is reached, even though there may be unused data in the buffer. Once
|
||||
that data has been used, no more attempts will be made to read the file.
|
||||
If strm->avail_in != 0, then the current data is moved to the beginning of
|
||||
the input buffer, and then the remainder of the buffer is loaded with the
|
||||
available data from the input file. */
|
||||
static int gz_avail(gz_state *state) {
|
||||
unsigned got;
|
||||
PREFIX3(stream) *strm = &(state->strm);
|
||||
|
||||
if (state->err != Z_OK && state->err != Z_BUF_ERROR)
|
||||
return -1;
|
||||
if (state->eof == 0) {
|
||||
if (strm->avail_in) { /* copy what's there to the start */
|
||||
unsigned char *p = state->in;
|
||||
unsigned const char *q = strm->next_in;
|
||||
unsigned n = strm->avail_in;
|
||||
do {
|
||||
*p++ = *q++;
|
||||
} while (--n);
|
||||
}
|
||||
if (gz_load(state, state->in + strm->avail_in, state->size - strm->avail_in, &got) == -1)
|
||||
return -1;
|
||||
strm->avail_in += got;
|
||||
strm->next_in = state->in;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Look for gzip header, set up for inflate or copy. state->x.have must be 0.
|
||||
If this is the first time in, allocate required memory. state->how will be
|
||||
left unchanged if there is no more input data available, will be set to COPY
|
||||
if there is no gzip header and direct copying will be performed, or it will
|
||||
be set to GZIP for decompression. If direct copying, then leftover input
|
||||
data from the input buffer will be copied to the output buffer. In that
|
||||
case, all further file reads will be directly to either the output buffer or
|
||||
a user buffer. If decompressing, the inflate state will be initialized.
|
||||
gz_look() will return 0 on success or -1 on failure. */
|
||||
static int gz_look(gz_state *state) {
|
||||
PREFIX3(stream) *strm = &(state->strm);
|
||||
|
||||
/* allocate read buffers and inflate memory */
|
||||
if (state->size == 0) {
|
||||
/* allocate buffers */
|
||||
state->in = (unsigned char *)zng_alloc(state->want);
|
||||
state->out = (unsigned char *)zng_alloc(state->want << 1);
|
||||
if (state->in == NULL || state->out == NULL) {
|
||||
zng_free(state->out);
|
||||
zng_free(state->in);
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
state->size = state->want;
|
||||
|
||||
/* allocate inflate memory */
|
||||
state->strm.zalloc = NULL;
|
||||
state->strm.zfree = NULL;
|
||||
state->strm.opaque = NULL;
|
||||
state->strm.avail_in = 0;
|
||||
state->strm.next_in = NULL;
|
||||
if (PREFIX(inflateInit2)(&(state->strm), MAX_WBITS + 16) != Z_OK) { /* gunzip */
|
||||
zng_free(state->out);
|
||||
zng_free(state->in);
|
||||
state->size = 0;
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* get at least the magic bytes in the input buffer */
|
||||
if (strm->avail_in < 2) {
|
||||
if (gz_avail(state) == -1)
|
||||
return -1;
|
||||
if (strm->avail_in == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* look for gzip magic bytes -- if there, do gzip decoding (note: there is
|
||||
a logical dilemma here when considering the case of a partially written
|
||||
gzip file, to wit, if a single 31 byte is written, then we cannot tell
|
||||
whether this is a single-byte file, or just a partially written gzip
|
||||
file -- for here we assume that if a gzip file is being written, then
|
||||
the header will be written in a single operation, so that reading a
|
||||
single byte is sufficient indication that it is not a gzip file) */
|
||||
if (strm->avail_in > 1 &&
|
||||
strm->next_in[0] == 31 && strm->next_in[1] == 139) {
|
||||
PREFIX(inflateReset)(strm);
|
||||
state->how = GZIP;
|
||||
state->direct = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* no gzip header -- if we were decoding gzip before, then this is trailing
|
||||
garbage. Ignore the trailing garbage and finish. */
|
||||
if (state->direct == 0) {
|
||||
strm->avail_in = 0;
|
||||
state->eof = 1;
|
||||
state->x.have = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* doing raw i/o, copy any leftover input to output -- this assumes that
|
||||
the output buffer is larger than the input buffer, which also assures
|
||||
space for gzungetc() */
|
||||
state->x.next = state->out;
|
||||
memcpy(state->x.next, strm->next_in, strm->avail_in);
|
||||
state->x.have = strm->avail_in;
|
||||
strm->avail_in = 0;
|
||||
state->how = COPY;
|
||||
state->direct = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Decompress from input to the provided next_out and avail_out in the state.
|
||||
On return, state->x.have and state->x.next point to the just decompressed
|
||||
data. If the gzip stream completes, state->how is reset to LOOK to look for
|
||||
the next gzip stream or raw data, once state->x.have is depleted. Returns 0
|
||||
on success, -1 on failure. */
|
||||
static int gz_decomp(gz_state *state) {
|
||||
int ret = Z_OK;
|
||||
unsigned had;
|
||||
PREFIX3(stream) *strm = &(state->strm);
|
||||
|
||||
/* fill output buffer up to end of deflate stream */
|
||||
had = strm->avail_out;
|
||||
do {
|
||||
/* get more input for inflate() */
|
||||
if (strm->avail_in == 0 && gz_avail(state) == -1)
|
||||
return -1;
|
||||
if (strm->avail_in == 0) {
|
||||
gz_error(state, Z_BUF_ERROR, "unexpected end of file");
|
||||
break;
|
||||
}
|
||||
|
||||
/* decompress and handle errors */
|
||||
ret = PREFIX(inflate)(strm, Z_NO_FLUSH);
|
||||
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
|
||||
gz_error(state, Z_STREAM_ERROR, "internal error: inflate stream corrupt");
|
||||
return -1;
|
||||
}
|
||||
if (ret == Z_MEM_ERROR) {
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
if (ret == Z_DATA_ERROR) { /* deflate stream invalid */
|
||||
gz_error(state, Z_DATA_ERROR, strm->msg == NULL ? "compressed data error" : strm->msg);
|
||||
return -1;
|
||||
}
|
||||
} while (strm->avail_out && ret != Z_STREAM_END);
|
||||
|
||||
/* update available output */
|
||||
state->x.have = had - strm->avail_out;
|
||||
state->x.next = strm->next_out - state->x.have;
|
||||
|
||||
/* if the gzip stream completed successfully, look for another */
|
||||
if (ret == Z_STREAM_END)
|
||||
state->how = LOOK;
|
||||
|
||||
/* good decompression */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Fetch data and put it in the output buffer. Assumes state->x.have is 0.
|
||||
Data is either copied from the input file or decompressed from the input
|
||||
file depending on state->how. If state->how is LOOK, then a gzip header is
|
||||
looked for to determine whether to copy or decompress. Returns -1 on error,
|
||||
otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
|
||||
end of the input file has been reached and all data has been processed. */
|
||||
static int gz_fetch(gz_state *state) {
|
||||
PREFIX3(stream) *strm = &(state->strm);
|
||||
|
||||
do {
|
||||
switch (state->how) {
|
||||
case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */
|
||||
if (gz_look(state) == -1)
|
||||
return -1;
|
||||
if (state->how == LOOK)
|
||||
return 0;
|
||||
break;
|
||||
case COPY: /* -> COPY */
|
||||
if (gz_load(state, state->out, state->size << 1, &(state->x.have))
|
||||
== -1)
|
||||
return -1;
|
||||
state->x.next = state->out;
|
||||
return 0;
|
||||
case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */
|
||||
strm->avail_out = state->size << 1;
|
||||
strm->next_out = state->out;
|
||||
if (gz_decomp(state) == -1)
|
||||
return -1;
|
||||
}
|
||||
} while (state->x.have == 0 && (!state->eof || strm->avail_in));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */
|
||||
static int gz_skip(gz_state *state, z_off64_t len) {
|
||||
unsigned n;
|
||||
|
||||
/* skip over len bytes or reach end-of-file, whichever comes first */
|
||||
while (len)
|
||||
/* skip over whatever is in output buffer */
|
||||
if (state->x.have) {
|
||||
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
|
||||
(unsigned)len : state->x.have;
|
||||
state->x.have -= n;
|
||||
state->x.next += n;
|
||||
state->x.pos += n;
|
||||
len -= n;
|
||||
} else if (state->eof && state->strm.avail_in == 0) {
|
||||
/* output buffer empty -- return if we're at the end of the input */
|
||||
break;
|
||||
} else {
|
||||
/* need more data to skip -- load up output buffer */
|
||||
/* get more output, looking for header if required */
|
||||
if (gz_fetch(state) == -1)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Read len bytes into buf from file, or less than len up to the end of the
|
||||
input. Return the number of bytes read. If zero is returned, either the
|
||||
end of file was reached, or there was an error. state->err must be
|
||||
consulted in that case to determine which. */
|
||||
static size_t gz_read(gz_state *state, void *buf, size_t len) {
|
||||
size_t got;
|
||||
unsigned n;
|
||||
|
||||
/* if len is zero, avoid unnecessary operations */
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
/* process a skip request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_skip(state, state->skip) == -1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get len bytes to buf, or less than len if at the end */
|
||||
got = 0;
|
||||
do {
|
||||
/* set n to the maximum amount of len that fits in an unsigned int */
|
||||
n = (unsigned)-1;
|
||||
if (n > len)
|
||||
n = (unsigned)len;
|
||||
|
||||
/* first just try copying data from the output buffer */
|
||||
if (state->x.have) {
|
||||
if (state->x.have < n)
|
||||
n = state->x.have;
|
||||
memcpy(buf, state->x.next, n);
|
||||
state->x.next += n;
|
||||
state->x.have -= n;
|
||||
}
|
||||
|
||||
/* output buffer empty -- return if we're at the end of the input */
|
||||
else if (state->eof && state->strm.avail_in == 0) {
|
||||
state->past = 1; /* tried to read past end */
|
||||
break;
|
||||
}
|
||||
|
||||
/* need output data -- for small len or new stream load up our output
|
||||
buffer */
|
||||
else if (state->how == LOOK || n < (state->size << 1)) {
|
||||
/* get more output, looking for header if required */
|
||||
if (gz_fetch(state) == -1)
|
||||
return 0;
|
||||
continue; /* no progress yet -- go back to copy above */
|
||||
/* the copy above assures that we will leave with space in the
|
||||
output buffer, allowing at least one gzungetc() to succeed */
|
||||
}
|
||||
|
||||
/* large len -- read directly into user buffer */
|
||||
else if (state->how == COPY) { /* read directly */
|
||||
if (gz_load(state, (unsigned char *)buf, n, &n) == -1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* large len -- decompress directly into user buffer */
|
||||
else { /* state->how == GZIP */
|
||||
state->strm.avail_out = n;
|
||||
state->strm.next_out = (unsigned char *)buf;
|
||||
if (gz_decomp(state) == -1)
|
||||
return 0;
|
||||
n = state->x.have;
|
||||
state->x.have = 0;
|
||||
}
|
||||
|
||||
/* update progress */
|
||||
len -= n;
|
||||
buf = (char *)buf + n;
|
||||
got += n;
|
||||
state->x.pos += n;
|
||||
} while (len);
|
||||
|
||||
/* return number of bytes read into user buffer */
|
||||
return got;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int Z_EXPORT PREFIX(gzread)(gzFile file, void *buf, unsigned len) {
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ ||
|
||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return -1;
|
||||
|
||||
/* since an int is returned, make sure len fits in one, otherwise return
|
||||
with an error (this avoids a flaw in the interface) */
|
||||
if ((int)len < 0) {
|
||||
gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* read len or fewer bytes to buf */
|
||||
len = (unsigned)gz_read(state, buf, len);
|
||||
|
||||
/* check for an error */
|
||||
if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR)
|
||||
return -1;
|
||||
|
||||
/* return the number of bytes read (this is assured to fit in an int) */
|
||||
return (int)len;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
size_t Z_EXPORT PREFIX(gzfread)(void *buf, size_t size, size_t nitems, gzFile file) {
|
||||
size_t len;
|
||||
gz_state *state;
|
||||
|
||||
/* Exit early if size is zero, also prevents potential division by zero */
|
||||
if (size == 0)
|
||||
return 0;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ ||
|
||||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return 0;
|
||||
|
||||
/* compute bytes to read -- error on overflow */
|
||||
if (size && SIZE_MAX / size < nitems) {
|
||||
gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
|
||||
return 0;
|
||||
}
|
||||
len = nitems * size;
|
||||
|
||||
/* read len or fewer bytes to buf, return the number of full items read */
|
||||
return len ? gz_read(state, buf, len) / size : 0;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
#undef @ZLIB_SYMBOL_PREFIX@gzgetc
|
||||
#undef @ZLIB_SYMBOL_PREFIX@zng_gzgetc
|
||||
int Z_EXPORT PREFIX(gzgetc)(gzFile file) {
|
||||
unsigned char buf[1];
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return -1;
|
||||
|
||||
/* try output buffer (no need to check for skip request) */
|
||||
if (state->x.have) {
|
||||
state->x.have--;
|
||||
state->x.pos++;
|
||||
return *(state->x.next)++;
|
||||
}
|
||||
|
||||
/* nothing there -- try gz_read() */
|
||||
return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
|
||||
}
|
||||
|
||||
#ifdef ZLIB_COMPAT
|
||||
int Z_EXPORT PREFIX(gzgetc_)(gzFile file) {
|
||||
return PREFIX(gzgetc)(file);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int Z_EXPORT PREFIX(gzungetc)(int c, gzFile file) {
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* in case this was just opened, set up the input buffer */
|
||||
if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
|
||||
(void)gz_look(state);
|
||||
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return -1;
|
||||
|
||||
/* process a skip request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_skip(state, state->skip) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* can't push EOF */
|
||||
if (c < 0)
|
||||
return -1;
|
||||
|
||||
/* if output buffer empty, put byte at end (allows more pushing) */
|
||||
if (state->x.have == 0) {
|
||||
state->x.have = 1;
|
||||
state->x.next = state->out + (state->size << 1) - 1;
|
||||
state->x.next[0] = (unsigned char)c;
|
||||
state->x.pos--;
|
||||
state->past = 0;
|
||||
return c;
|
||||
}
|
||||
|
||||
/* if no room, give up (must have already done a gzungetc()) */
|
||||
if (state->x.have == (state->size << 1)) {
|
||||
gz_error(state, Z_DATA_ERROR, "out of room to push characters");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* slide output data if needed and insert byte before existing data */
|
||||
if (state->x.next == state->out) {
|
||||
unsigned char *src = state->out + state->x.have;
|
||||
unsigned char *dest = state->out + (state->size << 1);
|
||||
while (src > state->out)
|
||||
*--dest = *--src;
|
||||
state->x.next = dest;
|
||||
}
|
||||
state->x.have++;
|
||||
state->x.next--;
|
||||
state->x.next[0] = (unsigned char)c;
|
||||
state->x.pos--;
|
||||
state->past = 0;
|
||||
return c;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
char * Z_EXPORT PREFIX(gzgets)(gzFile file, char *buf, int len) {
|
||||
unsigned left, n;
|
||||
char *str;
|
||||
unsigned char *eol;
|
||||
gz_state *state;
|
||||
|
||||
/* check parameters and get internal structure */
|
||||
if (file == NULL || buf == NULL || len < 1)
|
||||
return NULL;
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* check that we're reading and that there's no (serious) error */
|
||||
if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
|
||||
return NULL;
|
||||
|
||||
/* process a skip request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_skip(state, state->skip) == -1)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* copy output bytes up to new line or len - 1, whichever comes first --
|
||||
append a terminating zero to the string (we don't check for a zero in
|
||||
the contents, let the user worry about that) */
|
||||
str = buf;
|
||||
left = (unsigned)len - 1;
|
||||
if (left) {
|
||||
do {
|
||||
/* assure that something is in the output buffer */
|
||||
if (state->x.have == 0 && gz_fetch(state) == -1)
|
||||
return NULL; /* error */
|
||||
if (state->x.have == 0) { /* end of file */
|
||||
state->past = 1; /* read past end */
|
||||
break; /* return what we have */
|
||||
}
|
||||
|
||||
/* look for end-of-line in current output buffer */
|
||||
n = state->x.have > left ? left : state->x.have;
|
||||
eol = (unsigned char *)memchr(state->x.next, '\n', n);
|
||||
if (eol != NULL)
|
||||
n = (unsigned)(eol - state->x.next) + 1;
|
||||
|
||||
/* copy through end-of-line, or remainder if not found */
|
||||
memcpy(buf, state->x.next, n);
|
||||
state->x.have -= n;
|
||||
state->x.next += n;
|
||||
state->x.pos += n;
|
||||
left -= n;
|
||||
buf += n;
|
||||
} while (left && eol == NULL);
|
||||
}
|
||||
|
||||
/* return terminated string, or if nothing, end of file */
|
||||
if (buf == str)
|
||||
return NULL;
|
||||
buf[0] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int Z_EXPORT PREFIX(gzdirect)(gzFile file) {
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* if the state is not known, but we can find out, then do so (this is
|
||||
mainly for right after a gzopen() or gzdopen()) */
|
||||
if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
|
||||
(void)gz_look(state);
|
||||
|
||||
/* return 1 if transparent, 0 if processing a gzip stream */
|
||||
return state->direct;
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int Z_EXPORT PREFIX(gzclose_r)(gzFile file) {
|
||||
int ret, err;
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* check that we're reading */
|
||||
if (state->mode != GZ_READ)
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
/* free memory and close file */
|
||||
if (state->size) {
|
||||
PREFIX(inflateEnd)(&(state->strm));
|
||||
zng_free(state->out);
|
||||
zng_free(state->in);
|
||||
}
|
||||
err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
|
||||
gz_error(state, Z_OK, NULL);
|
||||
free(state->path);
|
||||
ret = close(state->fd);
|
||||
zng_free(state);
|
||||
return ret ? Z_ERRNO : err;
|
||||
}
|
||||
+88
-193
@@ -3,41 +3,50 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "zutil_p.h"
|
||||
#include <stdarg.h>
|
||||
#include "gzguts.h"
|
||||
|
||||
/* Local functions */
|
||||
static int gz_init(gz_state *);
|
||||
static int gz_comp(gz_state *, int);
|
||||
static int gz_zero(gz_state *, z_off64_t);
|
||||
static size_t gz_write(gz_state *, void const *, size_t);
|
||||
|
||||
/* Initialize state for writing a gzip file. Mark initialization by setting
|
||||
state->size to non-zero. Return -1 on a memory allocation failure, or 0 on
|
||||
success. */
|
||||
local int gz_init(gz_statep state) {
|
||||
static int gz_init(gz_state *state) {
|
||||
int ret;
|
||||
z_streamp strm = &(state->strm);
|
||||
PREFIX3(stream) *strm = &(state->strm);
|
||||
|
||||
/* allocate input buffer (double size for gzprintf) */
|
||||
state->in = (unsigned char *)malloc(state->want << 1);
|
||||
state->in = (unsigned char *)zng_alloc(state->want << 1);
|
||||
if (state->in == NULL) {
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
memset(state->in, 0, state->want << 1);
|
||||
|
||||
/* only need output buffer and deflate state if compressing */
|
||||
if (!state->direct) {
|
||||
/* allocate output buffer */
|
||||
state->out = (unsigned char *)malloc(state->want);
|
||||
state->out = (unsigned char *)zng_alloc(state->want);
|
||||
if (state->out == NULL) {
|
||||
free(state->in);
|
||||
zng_free(state->in);
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* allocate deflate memory, set up for gzip compression */
|
||||
strm->zalloc = Z_NULL;
|
||||
strm->zfree = Z_NULL;
|
||||
strm->opaque = Z_NULL;
|
||||
ret = deflateInit2(strm, state->level, Z_DEFLATED,
|
||||
MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
|
||||
strm->zalloc = NULL;
|
||||
strm->zfree = NULL;
|
||||
strm->opaque = NULL;
|
||||
ret = PREFIX(deflateInit2)(strm, state->level, Z_DEFLATED, MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
|
||||
if (ret != Z_OK) {
|
||||
free(state->out);
|
||||
free(state->in);
|
||||
zng_free(state->out);
|
||||
zng_free(state->in);
|
||||
gz_error(state, Z_MEM_ERROR, "out of memory");
|
||||
return -1;
|
||||
}
|
||||
@@ -62,10 +71,11 @@ local int gz_init(gz_statep state) {
|
||||
deflate() flush value. If flush is Z_FINISH, then the deflate() state is
|
||||
reset to start a new gzip stream. If gz->direct is true, then simply write
|
||||
to the output file without compressing, and ignore flush. */
|
||||
local int gz_comp(gz_statep state, int flush) {
|
||||
int ret, writ;
|
||||
unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
|
||||
z_streamp strm = &(state->strm);
|
||||
static int gz_comp(gz_state *state, int flush) {
|
||||
int ret;
|
||||
ssize_t got;
|
||||
unsigned have;
|
||||
PREFIX3(stream) *strm = &(state->strm);
|
||||
|
||||
/* allocate memory if this is the first time through */
|
||||
if (state->size == 0 && gz_init(state) == -1)
|
||||
@@ -73,16 +83,12 @@ local int gz_comp(gz_statep state, int flush) {
|
||||
|
||||
/* write directly if requested */
|
||||
if (state->direct) {
|
||||
while (strm->avail_in) {
|
||||
put = strm->avail_in > max ? max : strm->avail_in;
|
||||
writ = write(state->fd, strm->next_in, put);
|
||||
if (writ < 0) {
|
||||
gz_error(state, Z_ERRNO, zstrerror());
|
||||
return -1;
|
||||
}
|
||||
strm->avail_in -= (unsigned)writ;
|
||||
strm->next_in += writ;
|
||||
got = write(state->fd, strm->next_in, strm->avail_in);
|
||||
if (got < 0 || (unsigned)got != strm->avail_in) {
|
||||
gz_error(state, Z_ERRNO, zstrerror());
|
||||
return -1;
|
||||
}
|
||||
strm->avail_in = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -91,7 +97,7 @@ local int gz_comp(gz_statep state, int flush) {
|
||||
/* don't start a new gzip member unless there is data to write */
|
||||
if (strm->avail_in == 0)
|
||||
return 0;
|
||||
deflateReset(strm);
|
||||
PREFIX(deflateReset)(strm);
|
||||
state->reset = 0;
|
||||
}
|
||||
|
||||
@@ -100,31 +106,25 @@ local int gz_comp(gz_statep state, int flush) {
|
||||
do {
|
||||
/* write out current buffer contents if full, or if flushing, but if
|
||||
doing Z_FINISH then don't write until we get to Z_STREAM_END */
|
||||
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
|
||||
(flush != Z_FINISH || ret == Z_STREAM_END))) {
|
||||
while (strm->next_out > state->x.next) {
|
||||
put = strm->next_out - state->x.next > (int)max ? max :
|
||||
(unsigned)(strm->next_out - state->x.next);
|
||||
writ = write(state->fd, state->x.next, put);
|
||||
if (writ < 0) {
|
||||
gz_error(state, Z_ERRNO, zstrerror());
|
||||
return -1;
|
||||
}
|
||||
state->x.next += writ;
|
||||
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && (flush != Z_FINISH || ret == Z_STREAM_END))) {
|
||||
have = (unsigned)(strm->next_out - state->x.next);
|
||||
if (have && ((got = write(state->fd, state->x.next, (unsigned long)have)) < 0 || (unsigned)got != have)) {
|
||||
gz_error(state, Z_ERRNO, zstrerror());
|
||||
return -1;
|
||||
}
|
||||
if (strm->avail_out == 0) {
|
||||
strm->avail_out = state->size;
|
||||
strm->next_out = state->out;
|
||||
state->x.next = state->out;
|
||||
}
|
||||
state->x.next = strm->next_out;
|
||||
}
|
||||
|
||||
/* compress */
|
||||
have = strm->avail_out;
|
||||
ret = deflate(strm, flush);
|
||||
ret = PREFIX(deflate)(strm, flush);
|
||||
if (ret == Z_STREAM_ERROR) {
|
||||
gz_error(state, Z_STREAM_ERROR,
|
||||
"internal error: deflate stream corrupt");
|
||||
gz_error(state, Z_STREAM_ERROR, "internal error: deflate stream corrupt");
|
||||
return -1;
|
||||
}
|
||||
have -= strm->avail_out;
|
||||
@@ -133,17 +133,16 @@ local int gz_comp(gz_statep state, int flush) {
|
||||
/* if that completed a deflate stream, allow another to start */
|
||||
if (flush == Z_FINISH)
|
||||
state->reset = 1;
|
||||
|
||||
/* all done, no errors */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Compress len zeros to output. Return -1 on a write error or memory
|
||||
allocation failure by gz_comp(), or 0 on success. */
|
||||
local int gz_zero(gz_statep state, z_off64_t len) {
|
||||
static int gz_zero(gz_state *state, z_off64_t len) {
|
||||
int first;
|
||||
unsigned n;
|
||||
z_streamp strm = &(state->strm);
|
||||
PREFIX3(stream) *strm = &(state->strm);
|
||||
|
||||
/* consume whatever's left in the input buffer */
|
||||
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
@@ -152,8 +151,7 @@ local int gz_zero(gz_statep state, z_off64_t len) {
|
||||
/* compress len zeros (len guaranteed > 0) */
|
||||
first = 1;
|
||||
while (len) {
|
||||
n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
|
||||
(unsigned)len : state->size;
|
||||
n = GT_OFF(state->size) || (z_off64_t)state->size > len ? (unsigned)len : state->size;
|
||||
if (first) {
|
||||
memset(state->in, 0, n);
|
||||
first = 0;
|
||||
@@ -170,8 +168,8 @@ local int gz_zero(gz_statep state, z_off64_t len) {
|
||||
|
||||
/* Write len bytes from buf to file. Return the number of bytes written. If
|
||||
the returned value is less than len, then there was an error. */
|
||||
local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
|
||||
z_size_t put = len;
|
||||
static size_t gz_write(gz_state *state, void const *buf, size_t len) {
|
||||
size_t put = len;
|
||||
|
||||
/* if len is zero, avoid unnecessary operations */
|
||||
if (len == 0)
|
||||
@@ -209,14 +207,13 @@ local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
|
||||
if (len && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
} while (len);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* consume whatever's left in the input buffer */
|
||||
if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return 0;
|
||||
|
||||
/* directly compress user buffer to file */
|
||||
state->strm.next_in = (z_const Bytef *)buf;
|
||||
state->strm.next_in = (z_const unsigned char *) buf;
|
||||
do {
|
||||
unsigned n = (unsigned)-1;
|
||||
if (n > len)
|
||||
@@ -234,13 +231,13 @@ local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len) {
|
||||
gz_statep state;
|
||||
int Z_EXPORT PREFIX(gzwrite)(gzFile file, void const *buf, unsigned len) {
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
@@ -258,15 +255,18 @@ int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems,
|
||||
gzFile file) {
|
||||
z_size_t len;
|
||||
gz_statep state;
|
||||
size_t Z_EXPORT PREFIX(gzfwrite)(void const *buf, size_t size, size_t nitems, gzFile file) {
|
||||
size_t len;
|
||||
gz_state *state;
|
||||
|
||||
/* Exit early if size is zero, also prevents potential division by zero */
|
||||
if (size == 0)
|
||||
return 0;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
@@ -274,7 +274,7 @@ z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems,
|
||||
|
||||
/* compute bytes to read -- error on overflow */
|
||||
len = nitems * size;
|
||||
if (size && len / size != nitems) {
|
||||
if (len / size != nitems) {
|
||||
gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
|
||||
return 0;
|
||||
}
|
||||
@@ -284,16 +284,16 @@ z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems,
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzputc(gzFile file, int c) {
|
||||
int Z_EXPORT PREFIX(gzputc)(gzFile file, int c) {
|
||||
unsigned have;
|
||||
unsigned char buf[1];
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
gz_state *state;
|
||||
PREFIX3(stream) *strm;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
@@ -329,14 +329,14 @@ int ZEXPORT gzputc(gzFile file, int c) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzputs(gzFile file, const char *s) {
|
||||
z_size_t len, put;
|
||||
gz_statep state;
|
||||
int Z_EXPORT PREFIX(gzputs)(gzFile file, const char *s) {
|
||||
size_t len, put;
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
@@ -352,21 +352,18 @@ int ZEXPORT gzputs(gzFile file, const char *s) {
|
||||
return put < len ? -1 : (int)len;
|
||||
}
|
||||
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
#include <stdarg.h>
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
|
||||
int Z_EXPORTVA PREFIX(gzvprintf)(gzFile file, const char *format, va_list va) {
|
||||
int len;
|
||||
unsigned left;
|
||||
char *next;
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
gz_state *state;
|
||||
PREFIX3(stream) *strm;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
@@ -391,22 +388,7 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
|
||||
strm->next_in = state->in;
|
||||
next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
|
||||
next[state->size - 1] = 0;
|
||||
#ifdef NO_vsnprintf
|
||||
# ifdef HAS_vsprintf_void
|
||||
(void)vsprintf(next, format, va);
|
||||
for (len = 0; len < state->size; len++)
|
||||
if (next[len] == 0) break;
|
||||
# else
|
||||
len = vsprintf(next, format, va);
|
||||
# endif
|
||||
#else
|
||||
# ifdef HAS_vsnprintf_void
|
||||
(void)vsnprintf(next, state->size, format, va);
|
||||
len = strlen(next);
|
||||
# else
|
||||
len = vsnprintf(next, state->size, format, va);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* check that printf() results fit in buffer */
|
||||
if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
|
||||
@@ -427,111 +409,24 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
|
||||
return len;
|
||||
}
|
||||
|
||||
int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) {
|
||||
int Z_EXPORTVA PREFIX(gzprintf)(gzFile file, const char *format, ...) {
|
||||
va_list va;
|
||||
int ret;
|
||||
|
||||
va_start(va, format);
|
||||
ret = gzvprintf(file, format, va);
|
||||
ret = PREFIX(gzvprintf)(file, format, va);
|
||||
va_end(va);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else /* !STDC && !Z_HAVE_STDARG_H */
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3,
|
||||
int a4, int a5, int a6, int a7, int a8, int a9, int a10,
|
||||
int a11, int a12, int a13, int a14, int a15, int a16,
|
||||
int a17, int a18, int a19, int a20) {
|
||||
unsigned len, left;
|
||||
char *next;
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
int Z_EXPORT PREFIX(gzflush)(gzFile file, int flush) {
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
state = (gz_statep)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that can really pass pointer in ints */
|
||||
if (sizeof(int) != sizeof(void *))
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
return Z_STREAM_ERROR;
|
||||
|
||||
/* make sure we have some buffer space */
|
||||
if (state->size == 0 && gz_init(state) == -1)
|
||||
return state->error;
|
||||
|
||||
/* check for seek request */
|
||||
if (state->seek) {
|
||||
state->seek = 0;
|
||||
if (gz_zero(state, state->skip) == -1)
|
||||
return state->error;
|
||||
}
|
||||
|
||||
/* do the printf() into the input buffer, put length in len -- the input
|
||||
buffer is double-sized just for this function, so there is guaranteed to
|
||||
be state->size bytes available after the current contents */
|
||||
if (strm->avail_in == 0)
|
||||
strm->next_in = state->in;
|
||||
next = (char *)(strm->next_in + strm->avail_in);
|
||||
next[state->size - 1] = 0;
|
||||
#ifdef NO_snprintf
|
||||
# ifdef HAS_sprintf_void
|
||||
sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
|
||||
a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
for (len = 0; len < size; len++)
|
||||
if (next[len] == 0)
|
||||
break;
|
||||
# else
|
||||
len = sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
|
||||
a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
# endif
|
||||
#else
|
||||
# ifdef HAS_snprintf_void
|
||||
snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, a9,
|
||||
a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
len = strlen(next);
|
||||
# else
|
||||
len = snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* check that printf() results fit in buffer */
|
||||
if (len == 0 || len >= state->size || next[state->size - 1] != 0)
|
||||
return 0;
|
||||
|
||||
/* update buffer and position, compress first half if past that */
|
||||
strm->avail_in += len;
|
||||
state->x.pos += len;
|
||||
if (strm->avail_in >= state->size) {
|
||||
left = strm->avail_in - state->size;
|
||||
strm->avail_in = state->size;
|
||||
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
||||
return state->err;
|
||||
memmove(state->in, state->in + state->size, left);
|
||||
strm->next_in = state->in;
|
||||
strm->avail_in = left;
|
||||
}
|
||||
return (int)len;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzflush(gzFile file, int flush) {
|
||||
gz_statep state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
||||
@@ -554,14 +449,14 @@ int ZEXPORT gzflush(gzFile file, int flush) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
|
||||
gz_statep state;
|
||||
z_streamp strm;
|
||||
int Z_EXPORT PREFIX(gzsetparams)(gzFile file, int level, int strategy) {
|
||||
gz_state *state;
|
||||
PREFIX3(stream) *strm;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
strm = &(state->strm);
|
||||
|
||||
/* check that we're writing and that there's no error */
|
||||
@@ -584,7 +479,7 @@ int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
|
||||
/* flush previous input with previous parameters before changing */
|
||||
if (strm->avail_in && gz_comp(state, Z_BLOCK) == -1)
|
||||
return state->err;
|
||||
deflateParams(strm, level, strategy);
|
||||
PREFIX(deflateParams)(strm, level, strategy);
|
||||
}
|
||||
state->level = level;
|
||||
state->strategy = strategy;
|
||||
@@ -592,14 +487,14 @@ int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
|
||||
}
|
||||
|
||||
/* -- see zlib.h -- */
|
||||
int ZEXPORT gzclose_w(gzFile file) {
|
||||
int Z_EXPORT PREFIX(gzclose_w)(gzFile file) {
|
||||
int ret = Z_OK;
|
||||
gz_statep state;
|
||||
gz_state *state;
|
||||
|
||||
/* get internal structure */
|
||||
if (file == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
state = (gz_statep)file;
|
||||
state = (gz_state *)file;
|
||||
|
||||
/* check that we're writing */
|
||||
if (state->mode != GZ_WRITE)
|
||||
@@ -617,15 +512,15 @@ int ZEXPORT gzclose_w(gzFile file) {
|
||||
ret = state->err;
|
||||
if (state->size) {
|
||||
if (!state->direct) {
|
||||
(void)deflateEnd(&(state->strm));
|
||||
free(state->out);
|
||||
(void)PREFIX(deflateEnd)(&(state->strm));
|
||||
zng_free(state->out);
|
||||
}
|
||||
free(state->in);
|
||||
zng_free(state->in);
|
||||
}
|
||||
gz_error(state, Z_OK, NULL);
|
||||
free(state->path);
|
||||
if (close(state->fd) == -1)
|
||||
ret = Z_ERRNO;
|
||||
free(state);
|
||||
zng_free(state);
|
||||
return ret;
|
||||
}
|
||||
+151
-256
@@ -10,140 +10,77 @@
|
||||
inflate_fast() can be used with either inflate.c or infback.c.
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "inflate.h"
|
||||
#include "inffast.h"
|
||||
#include "inflate_p.h"
|
||||
#include "functable.h"
|
||||
|
||||
/* Avoid conflicts with zlib.h macros */
|
||||
#ifdef ZLIB_COMPAT
|
||||
# undef inflateBackInit
|
||||
#endif
|
||||
|
||||
/*
|
||||
strm provides memory allocation functions in zalloc and zfree, or
|
||||
Z_NULL to use the library memory allocation functions.
|
||||
NULL to use the library memory allocation functions.
|
||||
|
||||
windowBits is in the range 8..15, and window is a user-supplied
|
||||
window and output buffer that is 2**windowBits bytes.
|
||||
*/
|
||||
int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
|
||||
unsigned char FAR *window, const char *version,
|
||||
int stream_size) {
|
||||
struct inflate_state FAR *state;
|
||||
|
||||
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
|
||||
stream_size != (int)(sizeof(z_stream)))
|
||||
return Z_VERSION_ERROR;
|
||||
if (strm == Z_NULL || window == Z_NULL ||
|
||||
windowBits < 8 || windowBits > 15)
|
||||
This function is hidden in ZLIB_COMPAT builds.
|
||||
*/
|
||||
int32_t ZNG_CONDEXPORT PREFIX(inflateBackInit)(PREFIX3(stream) *strm, int32_t windowBits, uint8_t *window) {
|
||||
struct inflate_state *state;
|
||||
|
||||
if (strm == NULL || window == NULL || windowBits < MIN_WBITS || windowBits > MAX_WBITS)
|
||||
return Z_STREAM_ERROR;
|
||||
strm->msg = Z_NULL; /* in case we return an error */
|
||||
if (strm->zalloc == (alloc_func)0) {
|
||||
#ifdef Z_SOLO
|
||||
return Z_STREAM_ERROR;
|
||||
#else
|
||||
strm->zalloc = zcalloc;
|
||||
strm->opaque = (voidpf)0;
|
||||
#endif
|
||||
strm->msg = NULL; /* in case we return an error */
|
||||
if (strm->zalloc == NULL) {
|
||||
strm->zalloc = PREFIX(zcalloc);
|
||||
strm->opaque = NULL;
|
||||
}
|
||||
if (strm->zfree == (free_func)0)
|
||||
#ifdef Z_SOLO
|
||||
return Z_STREAM_ERROR;
|
||||
#else
|
||||
strm->zfree = zcfree;
|
||||
#endif
|
||||
state = (struct inflate_state FAR *)ZALLOC(strm, 1,
|
||||
sizeof(struct inflate_state));
|
||||
if (state == Z_NULL) return Z_MEM_ERROR;
|
||||
if (strm->zfree == NULL)
|
||||
strm->zfree = PREFIX(zcfree);
|
||||
|
||||
inflate_allocs *alloc_bufs = alloc_inflate(strm);
|
||||
if (alloc_bufs == NULL)
|
||||
return Z_MEM_ERROR;
|
||||
|
||||
state = alloc_bufs->state;
|
||||
state->alloc_bufs = alloc_bufs;
|
||||
Tracev((stderr, "inflate: allocated\n"));
|
||||
strm->state = (struct internal_state FAR *)state;
|
||||
state->dmax = 32768U;
|
||||
state->wbits = (uInt)windowBits;
|
||||
|
||||
strm->state = (struct internal_state *)state;
|
||||
state->wbits = (unsigned int)windowBits;
|
||||
state->wsize = 1U << windowBits;
|
||||
state->wbufsize = 1U << windowBits;
|
||||
state->window = window;
|
||||
state->wnext = 0;
|
||||
state->whave = 0;
|
||||
state->chunksize = FUNCTABLE_CALL(chunksize)();
|
||||
#ifdef INFLATE_STRICT
|
||||
state->dmax = 32768U;
|
||||
#endif
|
||||
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||
state->sane = 1;
|
||||
#endif
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
Return state with length and distance decoding tables and index sizes set to
|
||||
fixed code decoding. Normally this returns fixed tables from inffixed.h.
|
||||
If BUILDFIXED is defined, then instead this routine builds the tables the
|
||||
first time it's called, and returns those tables the first time and
|
||||
thereafter. This reduces the size of the code by about 2K bytes, in
|
||||
exchange for a little execution time. However, BUILDFIXED should not be
|
||||
used for threaded applications, since the rewriting of the tables and virgin
|
||||
may not be thread-safe.
|
||||
*/
|
||||
local void fixedtables(struct inflate_state FAR *state) {
|
||||
#ifdef BUILDFIXED
|
||||
static int virgin = 1;
|
||||
static code *lenfix, *distfix;
|
||||
static code fixed[544];
|
||||
|
||||
/* build fixed huffman tables if first call (may not be thread safe) */
|
||||
if (virgin) {
|
||||
unsigned sym, bits;
|
||||
static code *next;
|
||||
|
||||
/* literal/length table */
|
||||
sym = 0;
|
||||
while (sym < 144) state->lens[sym++] = 8;
|
||||
while (sym < 256) state->lens[sym++] = 9;
|
||||
while (sym < 280) state->lens[sym++] = 7;
|
||||
while (sym < 288) state->lens[sym++] = 8;
|
||||
next = fixed;
|
||||
lenfix = next;
|
||||
bits = 9;
|
||||
inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
|
||||
|
||||
/* distance table */
|
||||
sym = 0;
|
||||
while (sym < 32) state->lens[sym++] = 5;
|
||||
distfix = next;
|
||||
bits = 5;
|
||||
inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
|
||||
|
||||
/* do this just once */
|
||||
virgin = 0;
|
||||
}
|
||||
#else /* !BUILDFIXED */
|
||||
# include "inffixed.h"
|
||||
#endif /* BUILDFIXED */
|
||||
state->lencode = lenfix;
|
||||
state->lenbits = 9;
|
||||
state->distcode = distfix;
|
||||
state->distbits = 5;
|
||||
/* Function used by zlib.h and zlib-ng version 2.0 macros */
|
||||
int32_t Z_EXPORT PREFIX(inflateBackInit_)(PREFIX3(stream) *strm, int32_t windowBits, uint8_t *window,
|
||||
const char *version, int32_t stream_size) {
|
||||
if (CHECK_VER_STSIZE(version, stream_size))
|
||||
return Z_VERSION_ERROR;
|
||||
return PREFIX(inflateBackInit)(strm, windowBits, window);
|
||||
}
|
||||
|
||||
/* Macros for inflateBack(): */
|
||||
|
||||
/* Load returned state from inflate_fast() */
|
||||
#define LOAD() \
|
||||
do { \
|
||||
put = strm->next_out; \
|
||||
left = strm->avail_out; \
|
||||
next = strm->next_in; \
|
||||
have = strm->avail_in; \
|
||||
hold = state->hold; \
|
||||
bits = state->bits; \
|
||||
} while (0)
|
||||
|
||||
/* Set state from registers for inflate_fast() */
|
||||
#define RESTORE() \
|
||||
do { \
|
||||
strm->next_out = put; \
|
||||
strm->avail_out = left; \
|
||||
strm->next_in = next; \
|
||||
strm->avail_in = have; \
|
||||
state->hold = hold; \
|
||||
state->bits = bits; \
|
||||
} while (0)
|
||||
|
||||
/* Clear the input bit accumulator */
|
||||
#define INITBITS() \
|
||||
do { \
|
||||
hold = 0; \
|
||||
bits = 0; \
|
||||
} while (0)
|
||||
/*
|
||||
Private macros for inflateBack()
|
||||
Look in inflate_p.h for macros shared with inflate()
|
||||
*/
|
||||
|
||||
/* Assure that some input is available. If input is requested, but denied,
|
||||
then return a Z_BUF_ERROR from inflateBack(). */
|
||||
@@ -152,7 +89,7 @@ local void fixedtables(struct inflate_state FAR *state) {
|
||||
if (have == 0) { \
|
||||
have = in(in_desc, &next); \
|
||||
if (have == 0) { \
|
||||
next = Z_NULL; \
|
||||
next = NULL; \
|
||||
ret = Z_BUF_ERROR; \
|
||||
goto inf_leave; \
|
||||
} \
|
||||
@@ -165,37 +102,10 @@ local void fixedtables(struct inflate_state FAR *state) {
|
||||
do { \
|
||||
PULL(); \
|
||||
have--; \
|
||||
hold += (unsigned long)(*next++) << bits; \
|
||||
hold += ((uint64_t)(*next++) << bits); \
|
||||
bits += 8; \
|
||||
} while (0)
|
||||
|
||||
/* Assure that there are at least n bits in the bit accumulator. If there is
|
||||
not enough available input to do that, then return from inflateBack() with
|
||||
an error. */
|
||||
#define NEEDBITS(n) \
|
||||
do { \
|
||||
while (bits < (unsigned)(n)) \
|
||||
PULLBYTE(); \
|
||||
} while (0)
|
||||
|
||||
/* Return the low n bits of the bit accumulator (n < 16) */
|
||||
#define BITS(n) \
|
||||
((unsigned)hold & ((1U << (n)) - 1))
|
||||
|
||||
/* Remove n bits from the bit accumulator */
|
||||
#define DROPBITS(n) \
|
||||
do { \
|
||||
hold >>= (n); \
|
||||
bits -= (unsigned)(n); \
|
||||
} while (0)
|
||||
|
||||
/* Remove zero to seven bits as needed to go to a byte boundary */
|
||||
#define BYTEBITS() \
|
||||
do { \
|
||||
hold >>= bits & 7; \
|
||||
bits -= bits & 7; \
|
||||
} while (0)
|
||||
|
||||
/* Assure that some output space is available, by writing out the window
|
||||
if it's full. If the write fails, return from inflateBack() with a
|
||||
Z_BUF_ERROR. */
|
||||
@@ -232,42 +142,41 @@ local void fixedtables(struct inflate_state FAR *state) {
|
||||
|
||||
in() should return zero on failure. out() should return non-zero on
|
||||
failure. If either in() or out() fails, than inflateBack() returns a
|
||||
Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it
|
||||
was in() or out() that caused in the error. Otherwise, inflateBack()
|
||||
Z_BUF_ERROR. strm->next_in can be checked for NULL to see whether it
|
||||
was in() or out() that caused in the error. Otherwise, inflateBack()
|
||||
returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
|
||||
error, or Z_MEM_ERROR if it could not allocate memory for the state.
|
||||
inflateBack() can also return Z_STREAM_ERROR if the input parameters
|
||||
are not correct, i.e. strm is Z_NULL or the state was not initialized.
|
||||
are not correct, i.e. strm is NULL or the state was not initialized.
|
||||
*/
|
||||
int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
out_func out, void FAR *out_desc) {
|
||||
struct inflate_state FAR *state;
|
||||
z_const unsigned char FAR *next; /* next input */
|
||||
unsigned char FAR *put; /* next output */
|
||||
unsigned have, left; /* available input and output */
|
||||
unsigned long hold; /* bit buffer */
|
||||
unsigned bits; /* bits in bit buffer */
|
||||
unsigned copy; /* number of stored or match bytes to copy */
|
||||
unsigned char FAR *from; /* where to copy match bytes from */
|
||||
code here; /* current decoding table entry */
|
||||
code last; /* parent table entry */
|
||||
unsigned len; /* length to copy for repeats, bits to drop */
|
||||
int ret; /* return code */
|
||||
static const unsigned short order[19] = /* permutation of code lengths */
|
||||
int32_t Z_EXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc, out_func out, void *out_desc) {
|
||||
struct inflate_state *state;
|
||||
z_const unsigned char *next; /* next input */
|
||||
unsigned char *put; /* next output */
|
||||
unsigned have, left; /* available input and output */
|
||||
uint64_t hold; /* bit buffer */
|
||||
unsigned bits; /* bits in bit buffer */
|
||||
unsigned copy; /* number of stored or match bytes to copy */
|
||||
unsigned char *from; /* where to copy match bytes from */
|
||||
code here; /* current decoding table entry */
|
||||
code last; /* parent table entry */
|
||||
unsigned len; /* length to copy for repeats, bits to drop */
|
||||
int32_t ret; /* return code */
|
||||
static const uint16_t order[19] = /* permutation of code lengths */
|
||||
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||
|
||||
/* Check that the strm exists and that the state was initialized */
|
||||
if (strm == Z_NULL || strm->state == Z_NULL)
|
||||
if (strm == NULL || strm->state == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
state = (struct inflate_state FAR *)strm->state;
|
||||
state = (struct inflate_state *)strm->state;
|
||||
|
||||
/* Reset the state */
|
||||
strm->msg = Z_NULL;
|
||||
strm->msg = NULL;
|
||||
state->mode = TYPE;
|
||||
state->last = 0;
|
||||
state->whave = 0;
|
||||
next = strm->next_in;
|
||||
have = next != Z_NULL ? strm->avail_in : 0;
|
||||
have = next != NULL ? strm->avail_in : 0;
|
||||
hold = 0;
|
||||
bits = 0;
|
||||
put = state->window;
|
||||
@@ -288,24 +197,20 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
DROPBITS(1);
|
||||
switch (BITS(2)) {
|
||||
case 0: /* stored block */
|
||||
Tracev((stderr, "inflate: stored block%s\n",
|
||||
state->last ? " (last)" : ""));
|
||||
Tracev((stderr, "inflate: stored block%s\n", state->last ? " (last)" : ""));
|
||||
state->mode = STORED;
|
||||
break;
|
||||
case 1: /* fixed block */
|
||||
fixedtables(state);
|
||||
Tracev((stderr, "inflate: fixed codes block%s\n",
|
||||
state->last ? " (last)" : ""));
|
||||
PREFIX(fixedtables)(state);
|
||||
Tracev((stderr, "inflate: fixed codes block%s\n", state->last ? " (last)" : ""));
|
||||
state->mode = LEN; /* decode codes */
|
||||
break;
|
||||
case 2: /* dynamic block */
|
||||
Tracev((stderr, "inflate: dynamic codes block%s\n",
|
||||
state->last ? " (last)" : ""));
|
||||
Tracev((stderr, "inflate: dynamic codes block%s\n", state->last ? " (last)" : ""));
|
||||
state->mode = TABLE;
|
||||
break;
|
||||
case 3:
|
||||
strm->msg = (char *)"invalid block type";
|
||||
state->mode = BAD;
|
||||
SET_BAD("invalid block type");
|
||||
}
|
||||
DROPBITS(2);
|
||||
break;
|
||||
@@ -315,13 +220,11 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
BYTEBITS(); /* go to byte boundary */
|
||||
NEEDBITS(32);
|
||||
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
|
||||
strm->msg = (char *)"invalid stored block lengths";
|
||||
state->mode = BAD;
|
||||
SET_BAD("invalid stored block lengths");
|
||||
break;
|
||||
}
|
||||
state->length = (unsigned)hold & 0xffff;
|
||||
Tracev((stderr, "inflate: stored length %u\n",
|
||||
state->length));
|
||||
state->length = (uint16_t)hold;
|
||||
Tracev((stderr, "inflate: stored length %u\n", state->length));
|
||||
INITBITS();
|
||||
|
||||
/* copy stored block from input to output */
|
||||
@@ -329,9 +232,9 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
copy = state->length;
|
||||
PULL();
|
||||
ROOM();
|
||||
if (copy > have) copy = have;
|
||||
if (copy > left) copy = left;
|
||||
zmemcpy(put, next, copy);
|
||||
copy = MIN(copy, have);
|
||||
copy = MIN(copy, left);
|
||||
memcpy(put, next, copy);
|
||||
have -= copy;
|
||||
next += copy;
|
||||
left -= copy;
|
||||
@@ -353,67 +256,60 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
DROPBITS(4);
|
||||
#ifndef PKZIP_BUG_WORKAROUND
|
||||
if (state->nlen > 286 || state->ndist > 30) {
|
||||
strm->msg = (char *)"too many length or distance symbols";
|
||||
state->mode = BAD;
|
||||
SET_BAD("too many length or distance symbols");
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
Tracev((stderr, "inflate: table sizes ok\n"));
|
||||
state->have = 0;
|
||||
|
||||
/* get code length code lengths (not a typo) */
|
||||
state->have = 0;
|
||||
while (state->have < state->ncode) {
|
||||
NEEDBITS(3);
|
||||
state->lens[order[state->have++]] = (unsigned short)BITS(3);
|
||||
state->lens[order[state->have++]] = (uint16_t)BITS(3);
|
||||
DROPBITS(3);
|
||||
}
|
||||
while (state->have < 19)
|
||||
state->lens[order[state->have++]] = 0;
|
||||
state->next = state->codes;
|
||||
state->lencode = (code const FAR *)(state->next);
|
||||
state->lencode = (const code *)(state->next);
|
||||
state->lenbits = 7;
|
||||
ret = inflate_table(CODES, state->lens, 19, &(state->next),
|
||||
&(state->lenbits), state->work);
|
||||
ret = zng_inflate_table(CODES, state->lens, 19, &(state->next), &(state->lenbits), state->work);
|
||||
if (ret) {
|
||||
strm->msg = (char *)"invalid code lengths set";
|
||||
state->mode = BAD;
|
||||
SET_BAD("invalid code lengths set");
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: code lengths ok\n"));
|
||||
state->have = 0;
|
||||
|
||||
/* get length and distance code code lengths */
|
||||
state->have = 0;
|
||||
while (state->have < state->nlen + state->ndist) {
|
||||
for (;;) {
|
||||
here = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
if (here.bits <= bits) break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if (here.val < 16) {
|
||||
DROPBITS(here.bits);
|
||||
state->lens[state->have++] = here.val;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (here.val == 16) {
|
||||
NEEDBITS(here.bits + 2);
|
||||
DROPBITS(here.bits);
|
||||
if (state->have == 0) {
|
||||
strm->msg = (char *)"invalid bit length repeat";
|
||||
state->mode = BAD;
|
||||
SET_BAD("invalid bit length repeat");
|
||||
break;
|
||||
}
|
||||
len = (unsigned)(state->lens[state->have - 1]);
|
||||
len = state->lens[state->have - 1];
|
||||
copy = 3 + BITS(2);
|
||||
DROPBITS(2);
|
||||
}
|
||||
else if (here.val == 17) {
|
||||
} else if (here.val == 17) {
|
||||
NEEDBITS(here.bits + 3);
|
||||
DROPBITS(here.bits);
|
||||
len = 0;
|
||||
copy = 3 + BITS(3);
|
||||
DROPBITS(3);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
NEEDBITS(here.bits + 7);
|
||||
DROPBITS(here.bits);
|
||||
len = 0;
|
||||
@@ -421,58 +317,57 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
DROPBITS(7);
|
||||
}
|
||||
if (state->have + copy > state->nlen + state->ndist) {
|
||||
strm->msg = (char *)"invalid bit length repeat";
|
||||
state->mode = BAD;
|
||||
SET_BAD("invalid bit length repeat");
|
||||
break;
|
||||
}
|
||||
while (copy--)
|
||||
state->lens[state->have++] = (unsigned short)len;
|
||||
while (copy) {
|
||||
--copy;
|
||||
state->lens[state->have++] = (uint16_t)len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* handle error breaks in while */
|
||||
if (state->mode == BAD) break;
|
||||
if (state->mode == BAD)
|
||||
break;
|
||||
|
||||
/* check for end-of-block code (better have one) */
|
||||
if (state->lens[256] == 0) {
|
||||
strm->msg = (char *)"invalid code -- missing end-of-block";
|
||||
state->mode = BAD;
|
||||
SET_BAD("invalid code -- missing end-of-block");
|
||||
break;
|
||||
}
|
||||
|
||||
/* build code tables -- note: do not change the lenbits or distbits
|
||||
values here (9 and 6) without reading the comments in inftrees.h
|
||||
values here (10 and 9) without reading the comments in inftrees.h
|
||||
concerning the ENOUGH constants, which depend on those values */
|
||||
state->next = state->codes;
|
||||
state->lencode = (code const FAR *)(state->next);
|
||||
state->lenbits = 9;
|
||||
ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
|
||||
&(state->lenbits), state->work);
|
||||
state->lencode = (const code *)(state->next);
|
||||
state->lenbits = 10;
|
||||
ret = zng_inflate_table(LENS, state->lens, state->nlen, &(state->next), &(state->lenbits), state->work);
|
||||
if (ret) {
|
||||
strm->msg = (char *)"invalid literal/lengths set";
|
||||
state->mode = BAD;
|
||||
SET_BAD("invalid literal/lengths set");
|
||||
break;
|
||||
}
|
||||
state->distcode = (code const FAR *)(state->next);
|
||||
state->distbits = 6;
|
||||
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
|
||||
&(state->next), &(state->distbits), state->work);
|
||||
state->distcode = (const code *)(state->next);
|
||||
state->distbits = 9;
|
||||
ret = zng_inflate_table(DISTS, state->lens + state->nlen, state->ndist,
|
||||
&(state->next), &(state->distbits), state->work);
|
||||
if (ret) {
|
||||
strm->msg = (char *)"invalid distances set";
|
||||
state->mode = BAD;
|
||||
SET_BAD("invalid distances set");
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: codes ok\n"));
|
||||
state->mode = LEN;
|
||||
/* fallthrough */
|
||||
Z_FALLTHROUGH;
|
||||
|
||||
case LEN:
|
||||
/* use inflate_fast() if we have enough input and output */
|
||||
if (have >= 6 && left >= 258) {
|
||||
if (have >= INFLATE_FAST_MIN_HAVE &&
|
||||
left >= INFLATE_FAST_MIN_LEFT) {
|
||||
RESTORE();
|
||||
if (state->whave < state->wsize)
|
||||
state->whave = state->wsize - left;
|
||||
inflate_fast(strm, state->wsize);
|
||||
FUNCTABLE_CALL(inflate_fast)(strm, state->wsize);
|
||||
LOAD();
|
||||
break;
|
||||
}
|
||||
@@ -480,24 +375,25 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
/* get a literal, length, or end-of-block code */
|
||||
for (;;) {
|
||||
here = state->lencode[BITS(state->lenbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
if (here.bits <= bits)
|
||||
break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if (here.op && (here.op & 0xf0) == 0) {
|
||||
last = here;
|
||||
for (;;) {
|
||||
here = state->lencode[last.val +
|
||||
(BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)(last.bits + here.bits) <= bits) break;
|
||||
here = state->lencode[last.val + (BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)last.bits + (unsigned)here.bits <= bits)
|
||||
break;
|
||||
PULLBYTE();
|
||||
}
|
||||
DROPBITS(last.bits);
|
||||
}
|
||||
DROPBITS(here.bits);
|
||||
state->length = (unsigned)here.val;
|
||||
state->length = here.val;
|
||||
|
||||
/* process literal */
|
||||
if (here.op == 0) {
|
||||
if ((int)(here.op) == 0) {
|
||||
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", here.val));
|
||||
@@ -517,14 +413,13 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
|
||||
/* invalid code */
|
||||
if (here.op & 64) {
|
||||
strm->msg = (char *)"invalid literal/length code";
|
||||
state->mode = BAD;
|
||||
SET_BAD("invalid literal/length code");
|
||||
break;
|
||||
}
|
||||
|
||||
/* length code -- get extra bits, if any */
|
||||
state->extra = (unsigned)(here.op) & 15;
|
||||
if (state->extra != 0) {
|
||||
state->extra = (here.op & MAX_BITS);
|
||||
if (state->extra) {
|
||||
NEEDBITS(state->extra);
|
||||
state->length += BITS(state->extra);
|
||||
DROPBITS(state->extra);
|
||||
@@ -534,40 +429,40 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
/* get distance code */
|
||||
for (;;) {
|
||||
here = state->distcode[BITS(state->distbits)];
|
||||
if ((unsigned)(here.bits) <= bits) break;
|
||||
if (here.bits <= bits)
|
||||
break;
|
||||
PULLBYTE();
|
||||
}
|
||||
if ((here.op & 0xf0) == 0) {
|
||||
last = here;
|
||||
for (;;) {
|
||||
here = state->distcode[last.val +
|
||||
(BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)(last.bits + here.bits) <= bits) break;
|
||||
here = state->distcode[last.val + (BITS(last.bits + last.op) >> last.bits)];
|
||||
if ((unsigned)last.bits + (unsigned)here.bits <= bits)
|
||||
break;
|
||||
PULLBYTE();
|
||||
}
|
||||
DROPBITS(last.bits);
|
||||
}
|
||||
DROPBITS(here.bits);
|
||||
if (here.op & 64) {
|
||||
strm->msg = (char *)"invalid distance code";
|
||||
state->mode = BAD;
|
||||
SET_BAD("invalid distance code");
|
||||
break;
|
||||
}
|
||||
state->offset = (unsigned)here.val;
|
||||
state->offset = here.val;
|
||||
state->extra = (here.op & MAX_BITS);
|
||||
|
||||
/* get distance extra bits, if any */
|
||||
state->extra = (unsigned)(here.op) & 15;
|
||||
if (state->extra != 0) {
|
||||
if (state->extra) {
|
||||
NEEDBITS(state->extra);
|
||||
state->offset += BITS(state->extra);
|
||||
DROPBITS(state->extra);
|
||||
}
|
||||
if (state->offset > state->wsize - (state->whave < state->wsize ?
|
||||
left : 0)) {
|
||||
strm->msg = (char *)"invalid distance too far back";
|
||||
state->mode = BAD;
|
||||
#ifdef INFLATE_STRICT
|
||||
if (state->offset > state->wsize - (state->whave < state->wsize ? left : 0)) {
|
||||
SET_BAD("invalid distance too far back");
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
Tracevv((stderr, "inflate: distance %u\n", state->offset));
|
||||
|
||||
/* copy match from window to output */
|
||||
@@ -577,12 +472,11 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
if (copy < left) {
|
||||
from = put + copy;
|
||||
copy = left - copy;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
from = put - state->offset;
|
||||
copy = left;
|
||||
}
|
||||
if (copy > state->length) copy = state->length;
|
||||
copy = MIN(copy, state->length);
|
||||
state->length -= copy;
|
||||
left -= copy;
|
||||
do {
|
||||
@@ -600,8 +494,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
ret = Z_DATA_ERROR;
|
||||
goto inf_leave;
|
||||
|
||||
default:
|
||||
/* can't happen, but makes compilers happy */
|
||||
default: /* can't happen, but makes compilers happy */
|
||||
ret = Z_STREAM_ERROR;
|
||||
goto inf_leave;
|
||||
}
|
||||
@@ -609,20 +502,22 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
|
||||
/* Write leftover output and return unused input */
|
||||
inf_leave:
|
||||
if (left < state->wsize) {
|
||||
if (out(out_desc, state->window, state->wsize - left) &&
|
||||
ret == Z_STREAM_END)
|
||||
if (out(out_desc, state->window, state->wsize - left) && (ret == Z_STREAM_END)) {
|
||||
ret = Z_BUF_ERROR;
|
||||
}
|
||||
}
|
||||
strm->next_in = next;
|
||||
strm->avail_in = have;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZEXPORT inflateBackEnd(z_streamp strm) {
|
||||
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
|
||||
int32_t Z_EXPORT PREFIX(inflateBackEnd)(PREFIX3(stream) *strm) {
|
||||
if (strm == NULL || strm->state == NULL || strm->zfree == NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
ZFREE(strm, strm->state);
|
||||
strm->state = Z_NULL;
|
||||
|
||||
/* Free allocated buffers */
|
||||
free_inflate(strm);
|
||||
|
||||
Tracev((stderr, "inflate: end\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
/* inffast.c -- fast decoding
|
||||
* Copyright (C) 1995-2017 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "zendian.h"
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "inflate.h"
|
||||
#include "inflate_p.h"
|
||||
#include "functable.h"
|
||||
|
||||
/*
|
||||
Decode literal, length, and distance codes and write out the resulting
|
||||
literal and match bytes until either not enough input or output is
|
||||
available, an end-of-block is encountered, or a data error is encountered.
|
||||
When large enough input and output buffers are supplied to inflate(), for
|
||||
example, a 16K input buffer and a 64K output buffer, more than 95% of the
|
||||
inflate execution time is spent in this routine.
|
||||
|
||||
Entry assumptions:
|
||||
|
||||
state->mode == LEN
|
||||
strm->avail_in >= INFLATE_FAST_MIN_HAVE
|
||||
strm->avail_out >= INFLATE_FAST_MIN_LEFT
|
||||
start >= strm->avail_out
|
||||
state->bits < 8
|
||||
|
||||
On return, state->mode is one of:
|
||||
|
||||
LEN -- ran out of enough output space or enough available input
|
||||
TYPE -- reached end of block code, inflate() to interpret next block
|
||||
BAD -- error in block data
|
||||
|
||||
Notes:
|
||||
|
||||
- The maximum input bits used by a length/distance pair is 15 bits for the
|
||||
length code, 5 bits for the length extra, 15 bits for the distance code,
|
||||
and 13 bits for the distance extra. This totals 48 bits, or six bytes.
|
||||
Therefore if strm->avail_in >= 6, then there is enough input to avoid
|
||||
checking for available input while decoding.
|
||||
|
||||
- On some architectures, it can be significantly faster (e.g. up to 1.2x
|
||||
faster on x86_64) to load from strm->next_in 64 bits, or 8 bytes, at a
|
||||
time, so INFLATE_FAST_MIN_HAVE == 8.
|
||||
|
||||
- The maximum bytes that a single length/distance pair can output is 258
|
||||
bytes, which is the maximum length that can be coded. inflate_fast()
|
||||
requires strm->avail_out >= 258 for each loop to avoid checking for
|
||||
output space.
|
||||
*/
|
||||
void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) {
|
||||
/* start: inflate()'s starting value for strm->avail_out */
|
||||
struct inflate_state *state;
|
||||
z_const unsigned char *in; /* local strm->next_in */
|
||||
const unsigned char *last; /* have enough input while in < last */
|
||||
unsigned char *out; /* local strm->next_out */
|
||||
unsigned char *beg; /* inflate()'s initial strm->next_out */
|
||||
unsigned char *end; /* while out < end, enough space available */
|
||||
unsigned char *safe; /* can use chunkcopy provided out < safe */
|
||||
unsigned char *window; /* allocated sliding window, if wsize != 0 */
|
||||
unsigned wsize; /* window size or zero if not using window */
|
||||
unsigned whave; /* valid bytes in the window */
|
||||
unsigned wnext; /* window write index */
|
||||
|
||||
/* hold is a local copy of strm->hold. By default, hold satisfies the same
|
||||
invariants that strm->hold does, namely that (hold >> bits) == 0. This
|
||||
invariant is kept by loading bits into hold one byte at a time, like:
|
||||
|
||||
hold |= next_byte_of_input << bits; in++; bits += 8;
|
||||
|
||||
If we need to ensure that bits >= 15 then this code snippet is simply
|
||||
repeated. Over one iteration of the outermost do/while loop, this
|
||||
happens up to six times (48 bits of input), as described in the NOTES
|
||||
above.
|
||||
|
||||
However, on some little endian architectures, it can be significantly
|
||||
faster to load 64 bits once instead of 8 bits six times:
|
||||
|
||||
if (bits <= 16) {
|
||||
hold |= next_8_bytes_of_input << bits; in += 6; bits += 48;
|
||||
}
|
||||
|
||||
Unlike the simpler one byte load, shifting the next_8_bytes_of_input
|
||||
by bits will overflow and lose those high bits, up to 2 bytes' worth.
|
||||
The conservative estimate is therefore that we have read only 6 bytes
|
||||
(48 bits). Again, as per the NOTES above, 48 bits is sufficient for the
|
||||
rest of the iteration, and we will not need to load another 8 bytes.
|
||||
|
||||
Inside this function, we no longer satisfy (hold >> bits) == 0, but
|
||||
this is not problematic, even if that overflow does not land on an 8 bit
|
||||
byte boundary. Those excess bits will eventually shift down lower as the
|
||||
Huffman decoder consumes input, and when new input bits need to be loaded
|
||||
into the bits variable, the same input bits will be or'ed over those
|
||||
existing bits. A bitwise or is idempotent: (a | b | b) equals (a | b).
|
||||
Note that we therefore write that load operation as "hold |= etc" and not
|
||||
"hold += etc".
|
||||
|
||||
Outside that loop, at the end of the function, hold is bitwise and'ed
|
||||
with (1<<bits)-1 to drop those excess bits so that, on function exit, we
|
||||
keep the invariant that (state->hold >> state->bits) == 0.
|
||||
*/
|
||||
unsigned bits; /* local strm->bits */
|
||||
uint64_t hold; /* local strm->hold */
|
||||
unsigned lmask; /* mask for first level of length codes */
|
||||
unsigned dmask; /* mask for first level of distance codes */
|
||||
code const *lcode; /* local strm->lencode */
|
||||
code const *dcode; /* local strm->distcode */
|
||||
const code *here; /* retrieved table entry */
|
||||
unsigned op; /* code bits, operation, extra bits, or */
|
||||
/* window position, window bytes to copy */
|
||||
unsigned len; /* match length, unused bytes */
|
||||
unsigned char *from; /* where to copy match from */
|
||||
unsigned dist; /* match distance */
|
||||
unsigned extra_safe; /* copy chunks safely in all cases */
|
||||
|
||||
/* copy state to local variables */
|
||||
state = (struct inflate_state *)strm->state;
|
||||
in = strm->next_in;
|
||||
last = in + (strm->avail_in - (INFLATE_FAST_MIN_HAVE - 1));
|
||||
out = strm->next_out;
|
||||
beg = out - (start - strm->avail_out);
|
||||
end = out + (strm->avail_out - (INFLATE_FAST_MIN_LEFT - 1));
|
||||
safe = out + strm->avail_out;
|
||||
wsize = state->wsize;
|
||||
whave = state->whave;
|
||||
wnext = state->wnext;
|
||||
window = state->window;
|
||||
hold = state->hold;
|
||||
bits = state->bits;
|
||||
lcode = state->lencode;
|
||||
dcode = state->distcode;
|
||||
lmask = (1U << state->lenbits) - 1;
|
||||
dmask = (1U << state->distbits) - 1;
|
||||
|
||||
/* Detect if out and window point to the same memory allocation. In this instance it is
|
||||
necessary to use safe chunk copy functions to prevent overwriting the window. If the
|
||||
window is overwritten then future matches with far distances will fail to copy correctly. */
|
||||
extra_safe = (wsize != 0 && out >= window && out + INFLATE_FAST_MIN_LEFT <= window + state->wbufsize);
|
||||
|
||||
#define REFILL() do { \
|
||||
hold |= load_64_bits(in, bits); \
|
||||
in += 7; \
|
||||
in -= ((bits >> 3) & 7); \
|
||||
bits |= 56; \
|
||||
} while (0)
|
||||
|
||||
/* decode literals and length/distances until end-of-block or not enough
|
||||
input data or output space */
|
||||
do {
|
||||
REFILL();
|
||||
here = lcode + (hold & lmask);
|
||||
if (here->op == 0) {
|
||||
*out++ = (unsigned char)(here->val);
|
||||
DROPBITS(here->bits);
|
||||
here = lcode + (hold & lmask);
|
||||
if (here->op == 0) {
|
||||
*out++ = (unsigned char)(here->val);
|
||||
DROPBITS(here->bits);
|
||||
here = lcode + (hold & lmask);
|
||||
}
|
||||
}
|
||||
dolen:
|
||||
DROPBITS(here->bits);
|
||||
op = here->op;
|
||||
if (op == 0) { /* literal */
|
||||
Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", here->val));
|
||||
*out++ = (unsigned char)(here->val);
|
||||
} else if (op & 16) { /* length base */
|
||||
len = here->val;
|
||||
op &= MAX_BITS; /* number of extra bits */
|
||||
len += BITS(op);
|
||||
DROPBITS(op);
|
||||
Tracevv((stderr, "inflate: length %u\n", len));
|
||||
here = dcode + (hold & dmask);
|
||||
if (bits < MAX_BITS + MAX_DIST_EXTRA_BITS) {
|
||||
REFILL();
|
||||
}
|
||||
dodist:
|
||||
DROPBITS(here->bits);
|
||||
op = here->op;
|
||||
if (op & 16) { /* distance base */
|
||||
dist = here->val;
|
||||
op &= MAX_BITS; /* number of extra bits */
|
||||
dist += BITS(op);
|
||||
#ifdef INFLATE_STRICT
|
||||
if (dist > state->dmax) {
|
||||
SET_BAD("invalid distance too far back");
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
DROPBITS(op);
|
||||
Tracevv((stderr, "inflate: distance %u\n", dist));
|
||||
op = (unsigned)(out - beg); /* max distance in output */
|
||||
if (dist > op) { /* see if copy from window */
|
||||
op = dist - op; /* distance back in window */
|
||||
if (op > whave) {
|
||||
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||
if (state->sane) {
|
||||
SET_BAD("invalid distance too far back");
|
||||
break;
|
||||
}
|
||||
if (len <= op - whave) {
|
||||
do {
|
||||
*out++ = 0;
|
||||
} while (--len);
|
||||
continue;
|
||||
}
|
||||
len -= op - whave;
|
||||
do {
|
||||
*out++ = 0;
|
||||
} while (--op > whave);
|
||||
if (op == 0) {
|
||||
from = out - dist;
|
||||
do {
|
||||
*out++ = *from++;
|
||||
} while (--len);
|
||||
continue;
|
||||
}
|
||||
#else
|
||||
SET_BAD("invalid distance too far back");
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
from = window;
|
||||
if (wnext == 0) { /* very common case */
|
||||
from += wsize - op;
|
||||
} else if (wnext >= op) { /* contiguous in window */
|
||||
from += wnext - op;
|
||||
} else { /* wrap around window */
|
||||
op -= wnext;
|
||||
from += wsize - op;
|
||||
if (op < len) { /* some from end of window */
|
||||
len -= op;
|
||||
out = CHUNKCOPY_SAFE(out, from, op, safe);
|
||||
from = window; /* more from start of window */
|
||||
op = wnext;
|
||||
/* This (rare) case can create a situation where
|
||||
the first chunkcopy below must be checked.
|
||||
*/
|
||||
}
|
||||
}
|
||||
if (op < len) { /* still need some from output */
|
||||
len -= op;
|
||||
if (!extra_safe) {
|
||||
out = CHUNKCOPY_SAFE(out, from, op, safe);
|
||||
out = CHUNKUNROLL(out, &dist, &len);
|
||||
out = CHUNKCOPY_SAFE(out, out - dist, len, safe);
|
||||
} else {
|
||||
out = chunkcopy_safe(out, from, op, safe);
|
||||
out = chunkcopy_safe(out, out - dist, len, safe);
|
||||
}
|
||||
} else {
|
||||
#ifndef HAVE_MASKED_READWRITE
|
||||
if (extra_safe)
|
||||
out = chunkcopy_safe(out, from, len, safe);
|
||||
else
|
||||
#endif
|
||||
out = CHUNKCOPY_SAFE(out, from, len, safe);
|
||||
}
|
||||
#ifndef HAVE_MASKED_READWRITE
|
||||
} else if (extra_safe) {
|
||||
/* Whole reference is in range of current output. */
|
||||
out = chunkcopy_safe(out, out - dist, len, safe);
|
||||
#endif
|
||||
} else {
|
||||
/* Whole reference is in range of current output. No range checks are
|
||||
necessary because we start with room for at least 258 bytes of output,
|
||||
so unroll and roundoff operations can write beyond `out+len` so long
|
||||
as they stay within 258 bytes of `out`.
|
||||
*/
|
||||
if (dist >= len || dist >= state->chunksize)
|
||||
out = CHUNKCOPY(out, out - dist, len);
|
||||
else
|
||||
out = CHUNKMEMSET(out, out - dist, len);
|
||||
}
|
||||
} else if ((op & 64) == 0) { /* 2nd level distance code */
|
||||
here = dcode + here->val + BITS(op);
|
||||
goto dodist;
|
||||
} else {
|
||||
SET_BAD("invalid distance code");
|
||||
break;
|
||||
}
|
||||
} else if ((op & 64) == 0) { /* 2nd level length code */
|
||||
here = lcode + here->val + BITS(op);
|
||||
goto dolen;
|
||||
} else if (op & 32) { /* end-of-block */
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
state->mode = TYPE;
|
||||
break;
|
||||
} else {
|
||||
SET_BAD("invalid literal/length code");
|
||||
break;
|
||||
}
|
||||
} while (in < last && out < end);
|
||||
|
||||
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
|
||||
len = bits >> 3;
|
||||
in -= len;
|
||||
bits -= len << 3;
|
||||
hold &= (UINT64_C(1) << bits) - 1;
|
||||
|
||||
/* update state and return */
|
||||
strm->next_in = in;
|
||||
strm->next_out = out;
|
||||
strm->avail_in = (unsigned)(in < last ? (INFLATE_FAST_MIN_HAVE - 1) + (last - in)
|
||||
: (INFLATE_FAST_MIN_HAVE - 1) - (in - last));
|
||||
strm->avail_out = (unsigned)(out < end ? (INFLATE_FAST_MIN_LEFT - 1) + (end - out)
|
||||
: (INFLATE_FAST_MIN_LEFT - 1) - (out - end));
|
||||
|
||||
Assert(bits <= 32, "Remaining bits greater than 32");
|
||||
state->hold = (uint32_t)hold;
|
||||
state->bits = bits;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
|
||||
- Using bit fields for code structure
|
||||
- Different op definition to avoid & for extra bits (do & for table bits)
|
||||
- Three separate decoding do-loops for direct, window, and wnext == 0
|
||||
- Special case for distance > 1 copies to do overlapped load and store copy
|
||||
- Explicit branch predictions (based on measured branch probabilities)
|
||||
- Deferring match copy and interspersed it with decoding subsequent codes
|
||||
- Swapping literal/length else
|
||||
- Swapping window/direct else
|
||||
- Larger unrolled copy loops (three is about right)
|
||||
- Moving len -= 3 statement into middle of loop
|
||||
*/
|
||||
@@ -0,0 +1,94 @@
|
||||
/* inffixed_tbl.h -- table for decoding fixed codes
|
||||
* Generated automatically by makefixed().
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications.
|
||||
* It is part of the implementation of this library and is
|
||||
* subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
static const code lenfix[512] = {
|
||||
{96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
|
||||
{0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
|
||||
{0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
|
||||
{0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
|
||||
{0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
|
||||
{21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
|
||||
{0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
|
||||
{0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
|
||||
{18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
|
||||
{0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
|
||||
{0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
|
||||
{0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
|
||||
{20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
|
||||
{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
|
||||
{0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
|
||||
{0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
|
||||
{16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
|
||||
{0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
|
||||
{0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
|
||||
{0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
|
||||
{0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
|
||||
{0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
|
||||
{0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
|
||||
{0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
|
||||
{17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
|
||||
{0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
|
||||
{0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
|
||||
{0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
|
||||
{19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
|
||||
{0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
|
||||
{0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
|
||||
{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
|
||||
{16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
|
||||
{0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
|
||||
{0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
|
||||
{0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
|
||||
{0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
|
||||
{20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
|
||||
{0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
|
||||
{0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
|
||||
{17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
|
||||
{0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
|
||||
{0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
|
||||
{0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
|
||||
{20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
|
||||
{0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
|
||||
{0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
|
||||
{0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
|
||||
{16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
|
||||
{0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
|
||||
{0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
|
||||
{0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
|
||||
{0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
|
||||
{0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
|
||||
{0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
|
||||
{0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
|
||||
{16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
|
||||
{0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
|
||||
{0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
|
||||
{0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
|
||||
{19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
|
||||
{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
|
||||
{0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
|
||||
{0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
|
||||
{16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
|
||||
{0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
|
||||
{0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
|
||||
{0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
|
||||
{0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
|
||||
{64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
|
||||
{0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
|
||||
{0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
|
||||
{18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
|
||||
{0,9,255}
|
||||
};
|
||||
|
||||
static const code distfix[32] = {
|
||||
{16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
|
||||
{21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
|
||||
{18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
|
||||
{19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
|
||||
{16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
|
||||
{22,5,193},{64,5,0}
|
||||
};
|
||||
+628
-692
File diff suppressed because it is too large.
Load diff
+73
-27
@@ -8,10 +8,19 @@
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* define NO_GZIP when compiling if you want to disable gzip header and
|
||||
trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
|
||||
the crc code when it is not needed. For shared libraries, gzip decoding
|
||||
should be left enabled. */
|
||||
#ifndef INFLATE_H_
|
||||
#define INFLATE_H_
|
||||
|
||||
#include "crc32.h"
|
||||
|
||||
#ifdef S390_DFLTCC_INFLATE
|
||||
# include "arch/s390/dfltcc_common.h"
|
||||
# define HAVE_ARCH_INFLATE_STATE
|
||||
#endif
|
||||
|
||||
/* define NO_GZIP when compiling if you want to disable gzip header and trailer decoding by inflate().
|
||||
NO_GZIP would be used to avoid linking in the crc code when it is not needed.
|
||||
For shared libraries, gzip decoding should be left enabled. */
|
||||
#ifndef NO_GZIP
|
||||
# define GUNZIP
|
||||
#endif
|
||||
@@ -48,14 +57,13 @@ typedef enum {
|
||||
LENGTH, /* i: waiting for 32-bit length (gzip) */
|
||||
DONE, /* finished check, done -- remain here until reset */
|
||||
BAD, /* got a data error -- remain here until reset */
|
||||
MEM, /* got an inflate() memory error -- remain here until reset */
|
||||
SYNC /* looking for synchronization bytes to restart inflate() */
|
||||
} inflate_mode;
|
||||
|
||||
/*
|
||||
State transitions between above modes -
|
||||
|
||||
(most modes can go to BAD or MEM on error -- not shown for clarity)
|
||||
(most modes can go to BAD on error -- not shown for clarity)
|
||||
|
||||
Process header:
|
||||
HEAD -> (gzip) or (zlib) or (raw)
|
||||
@@ -76,11 +84,20 @@ typedef enum {
|
||||
Process trailer:
|
||||
CHECK -> LENGTH -> DONE
|
||||
*/
|
||||
typedef struct inflate_state inflate_state;
|
||||
|
||||
/* Struct for memory allocation handling */
|
||||
typedef struct inflate_allocs_s {
|
||||
char *buf_start;
|
||||
free_func zfree;
|
||||
inflate_state *state;
|
||||
unsigned char *window;
|
||||
} inflate_allocs;
|
||||
|
||||
/* State maintained between inflate() calls -- approximately 7K bytes, not
|
||||
including the allocated sliding window, which is up to 32K bytes. */
|
||||
struct inflate_state {
|
||||
z_streamp strm; /* pointer back to this zlib stream */
|
||||
struct ALIGNED_(64) inflate_state {
|
||||
PREFIX3(stream) *strm; /* pointer back to this zlib stream */
|
||||
inflate_mode mode; /* current inflate mode */
|
||||
int last; /* true if processing last block */
|
||||
int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
|
||||
@@ -88,39 +105,68 @@ struct inflate_state {
|
||||
int havedict; /* true if dictionary provided */
|
||||
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 was; /* initial length of match, for inflateMark */
|
||||
unsigned long check; /* protected copy of check value */
|
||||
unsigned long total; /* protected copy of output count */
|
||||
gz_headerp head; /* where to save gzip header information */
|
||||
PREFIX(gz_headerp) head; /* where to save gzip header information */
|
||||
int back; /* bits back of last unprocessed length/lit */
|
||||
|
||||
/* sliding window */
|
||||
unsigned wbits; /* log base 2 of requested window size */
|
||||
unsigned wsize; /* window size or zero if not using window */
|
||||
unsigned whave; /* valid bytes in the window */
|
||||
unsigned wnext; /* window write index */
|
||||
unsigned char FAR *window; /* allocated sliding window, if needed */
|
||||
uint32_t wsize; /* window size or zero if not using window */
|
||||
uint32_t wbufsize; /* real size of the allocated window buffer, including padding */
|
||||
uint32_t whave; /* valid bytes in the window */
|
||||
uint32_t wnext; /* window write index */
|
||||
unsigned char *window; /* allocated sliding window, if needed */
|
||||
uint32_t chunksize; /* size of memory copying chunk */
|
||||
|
||||
/* bit accumulator */
|
||||
unsigned long hold; /* input bit accumulator */
|
||||
uint64_t hold; /* input bit accumulator */
|
||||
unsigned bits; /* number of bits in "in" */
|
||||
/* fixed and dynamic code tables */
|
||||
unsigned lenbits; /* index bits for lencode */
|
||||
code const *lencode; /* starting table for length/literal codes */
|
||||
code const *distcode; /* starting table for distance codes */
|
||||
unsigned distbits; /* index bits for distcode */
|
||||
/* for string and stored block copying */
|
||||
unsigned length; /* literal or length of data to copy */
|
||||
uint32_t length; /* literal or length of data to copy */
|
||||
unsigned offset; /* distance back to copy string from */
|
||||
/* for table and code decoding */
|
||||
unsigned extra; /* extra bits needed */
|
||||
/* fixed and dynamic code tables */
|
||||
code const FAR *lencode; /* starting table for length/literal codes */
|
||||
code const FAR *distcode; /* starting table for distance codes */
|
||||
unsigned lenbits; /* index bits for lencode */
|
||||
unsigned distbits; /* index bits for distcode */
|
||||
/* dynamic table building */
|
||||
unsigned ncode; /* number of code length code lengths */
|
||||
unsigned nlen; /* number of length code lengths */
|
||||
unsigned ndist; /* number of distance code lengths */
|
||||
unsigned have; /* number of code lengths in lens[] */
|
||||
code FAR *next; /* next available space in codes[] */
|
||||
unsigned short lens[320]; /* temporary storage for code lengths */
|
||||
unsigned short work[288]; /* work area for code table building */
|
||||
uint32_t have; /* number of code lengths in lens[] */
|
||||
code *next; /* next available space in codes[] */
|
||||
|
||||
#if defined(_M_IX86) || defined(_M_ARM)
|
||||
uint32_t padding[1];
|
||||
#endif
|
||||
struct crc32_fold_s ALIGNED_(16) crc_fold;
|
||||
|
||||
uint16_t lens[320]; /* temporary storage for code lengths */
|
||||
uint16_t work[288]; /* work area for code table building */
|
||||
code codes[ENOUGH]; /* space for code tables */
|
||||
|
||||
inflate_allocs *alloc_bufs; /* struct for handling memory allocations */
|
||||
|
||||
#ifdef INFLATE_STRICT
|
||||
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
|
||||
#endif
|
||||
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
|
||||
int sane; /* if false, allow invalid distance too far */
|
||||
int back; /* bits back of last unprocessed length/lit */
|
||||
unsigned was; /* initial length of match */
|
||||
#endif
|
||||
#ifdef HAVE_ARCH_INFLATE_STATE
|
||||
arch_inflate_state arch; /* architecture-specific extensions */
|
||||
#endif
|
||||
#if defined(_M_IX86) || defined(_M_ARM)
|
||||
int padding2[8];
|
||||
#endif
|
||||
};
|
||||
|
||||
void Z_INTERNAL PREFIX(fixedtables)(struct inflate_state *state);
|
||||
Z_INTERNAL inflate_allocs* alloc_inflate(PREFIX3(stream) *strm);
|
||||
Z_INTERNAL void free_inflate(PREFIX3(stream) *strm);
|
||||
|
||||
#endif /* INFLATE_H_ */
|
||||
@@ -0,0 +1,215 @@
|
||||
/* inflate_p.h -- Private inline functions and macros shared with more than one deflate method
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef INFLATE_P_H
|
||||
#define INFLATE_P_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "zmemory.h"
|
||||
|
||||
/* Architecture-specific hooks. */
|
||||
#ifdef S390_DFLTCC_INFLATE
|
||||
# include "arch/s390/dfltcc_inflate.h"
|
||||
/* DFLTCC instructions require window to be page-aligned */
|
||||
# define PAD_WINDOW PAD_4096
|
||||
# define WINDOW_PAD_SIZE 4096
|
||||
# define HINT_ALIGNED_WINDOW HINT_ALIGNED_4096
|
||||
#else
|
||||
# define PAD_WINDOW PAD_64
|
||||
# define WINDOW_PAD_SIZE 64
|
||||
# define HINT_ALIGNED_WINDOW HINT_ALIGNED_64
|
||||
/* Adjust the window size for the arch-specific inflate code. */
|
||||
# define INFLATE_ADJUST_WINDOW_SIZE(n) (n)
|
||||
/* Invoked at the end of inflateResetKeep(). Useful for initializing arch-specific extension blocks. */
|
||||
# define INFLATE_RESET_KEEP_HOOK(strm) do {} while (0)
|
||||
/* Invoked at the beginning of inflatePrime(). Useful for updating arch-specific buffers. */
|
||||
# define INFLATE_PRIME_HOOK(strm, bits, value) do {} while (0)
|
||||
/* Invoked at the beginning of each block. Useful for plugging arch-specific inflation code. */
|
||||
# define INFLATE_TYPEDO_HOOK(strm, flush) do {} while (0)
|
||||
/* Returns whether zlib-ng should compute a checksum. Set to 0 if arch-specific inflation code already does that. */
|
||||
# define INFLATE_NEED_CHECKSUM(strm) 1
|
||||
/* Returns whether zlib-ng should update a window. Set to 0 if arch-specific inflation code already does that. */
|
||||
# define INFLATE_NEED_UPDATEWINDOW(strm) 1
|
||||
/* Invoked at the beginning of inflateMark(). Useful for updating arch-specific pointers and offsets. */
|
||||
# define INFLATE_MARK_HOOK(strm) do {} while (0)
|
||||
/* Invoked at the beginning of inflateSyncPoint(). Useful for performing arch-specific state checks. */
|
||||
# define INFLATE_SYNC_POINT_HOOK(strm) do {} while (0)
|
||||
/* Invoked at the beginning of inflateSetDictionary(). Useful for checking arch-specific window data. */
|
||||
# define INFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
|
||||
/* Invoked at the beginning of inflateGetDictionary(). Useful for adjusting arch-specific window data. */
|
||||
# define INFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Macros shared by inflate() and inflateBack()
|
||||
*/
|
||||
|
||||
/* check function to use adler32() for zlib or crc32() for gzip */
|
||||
#ifdef GUNZIP
|
||||
# define UPDATE(check, buf, len) \
|
||||
(state->flags ? PREFIX(crc32)(check, buf, len) : FUNCTABLE_CALL(adler32)(check, buf, len))
|
||||
#else
|
||||
# define UPDATE(check, buf, len) FUNCTABLE_CALL(adler32)(check, buf, len)
|
||||
#endif
|
||||
|
||||
/* check macros for header crc */
|
||||
#ifdef GUNZIP
|
||||
# define CRC2(check, word) \
|
||||
do { \
|
||||
hbuf[0] = (unsigned char)(word); \
|
||||
hbuf[1] = (unsigned char)((word) >> 8); \
|
||||
check = PREFIX(crc32)(check, hbuf, 2); \
|
||||
} while (0)
|
||||
|
||||
# define CRC4(check, word) \
|
||||
do { \
|
||||
hbuf[0] = (unsigned char)(word); \
|
||||
hbuf[1] = (unsigned char)((word) >> 8); \
|
||||
hbuf[2] = (unsigned char)((word) >> 16); \
|
||||
hbuf[3] = (unsigned char)((word) >> 24); \
|
||||
check = PREFIX(crc32)(check, hbuf, 4); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/* Load registers with state in inflate() for speed */
|
||||
#define LOAD() \
|
||||
do { \
|
||||
put = strm->next_out; \
|
||||
left = strm->avail_out; \
|
||||
next = strm->next_in; \
|
||||
have = strm->avail_in; \
|
||||
hold = state->hold; \
|
||||
bits = state->bits; \
|
||||
} while (0)
|
||||
|
||||
/* Restore state from registers in inflate() */
|
||||
#define RESTORE() \
|
||||
do { \
|
||||
strm->next_out = put; \
|
||||
strm->avail_out = left; \
|
||||
strm->next_in = (z_const unsigned char *)next; \
|
||||
strm->avail_in = have; \
|
||||
state->hold = hold; \
|
||||
state->bits = bits; \
|
||||
} while (0)
|
||||
|
||||
/* Clear the input bit accumulator */
|
||||
#define INITBITS() \
|
||||
do { \
|
||||
hold = 0; \
|
||||
bits = 0; \
|
||||
} while (0)
|
||||
|
||||
/* Ensure that there is at least n bits in the bit accumulator. If there is
|
||||
not enough available input to do that, then return from inflate()/inflateBack(). */
|
||||
#define NEEDBITS(n) \
|
||||
do { \
|
||||
while (bits < (unsigned)(n)) \
|
||||
PULLBYTE(); \
|
||||
} while (0)
|
||||
|
||||
/* Return the low n bits of the bit accumulator (n < 16) */
|
||||
#define BITS(n) \
|
||||
(hold & ((1U << (unsigned)(n)) - 1))
|
||||
|
||||
/* Remove n bits from the bit accumulator */
|
||||
#define DROPBITS(n) \
|
||||
do { \
|
||||
hold >>= (n); \
|
||||
bits -= (unsigned)(n); \
|
||||
} while (0)
|
||||
|
||||
/* Remove zero to seven bits as needed to go to a byte boundary */
|
||||
#define BYTEBITS() \
|
||||
do { \
|
||||
hold >>= bits & 7; \
|
||||
bits -= bits & 7; \
|
||||
} while (0)
|
||||
|
||||
/* Set mode=BAD and prepare error message */
|
||||
#define SET_BAD(errmsg) \
|
||||
do { \
|
||||
state->mode = BAD; \
|
||||
strm->msg = (char *)errmsg; \
|
||||
} while (0)
|
||||
|
||||
#define INFLATE_FAST_MIN_HAVE 15
|
||||
#define INFLATE_FAST_MIN_LEFT 260
|
||||
|
||||
/* Load 64 bits from IN and place the bytes at offset BITS in the result. */
|
||||
static inline uint64_t load_64_bits(const unsigned char *in, unsigned bits) {
|
||||
uint64_t chunk = zng_memread_8(in);
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
return chunk << bits;
|
||||
#else
|
||||
return ZSWAP64(chunk) << bits;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Behave like chunkcopy, but avoid writing beyond of legal output. */
|
||||
static inline uint8_t* chunkcopy_safe(uint8_t *out, uint8_t *from, uint64_t len, uint8_t *safe) {
|
||||
uint64_t safelen = safe - out;
|
||||
len = MIN(len, safelen);
|
||||
int32_t olap_src = from >= out && from < out + len;
|
||||
int32_t olap_dst = out >= from && out < from + len;
|
||||
uint64_t tocopy;
|
||||
|
||||
/* For all cases without overlap, memcpy is ideal */
|
||||
if (!(olap_src || olap_dst)) {
|
||||
memcpy(out, from, (size_t)len);
|
||||
return out + len;
|
||||
}
|
||||
|
||||
/* Complete overlap: Source == destination */
|
||||
if (out == from) {
|
||||
return out + len;
|
||||
}
|
||||
|
||||
/* We are emulating a self-modifying copy loop here. To do this in a way that doesn't produce undefined behavior,
|
||||
* we have to get a bit clever. First if the overlap is such that src falls between dst and dst+len, we can do the
|
||||
* initial bulk memcpy of the nonoverlapping region. Then, we can leverage the size of this to determine the safest
|
||||
* atomic memcpy size we can pick such that we have non-overlapping regions. This effectively becomes a safe look
|
||||
* behind or lookahead distance. */
|
||||
uint64_t non_olap_size = llabs(from - out); // llabs vs labs for compatibility with windows
|
||||
|
||||
/* So this doesn't give use a worst case scenario of function calls in a loop,
|
||||
* we want to instead break this down into copy blocks of fixed lengths
|
||||
*
|
||||
* TODO: The memcpy calls aren't inlined on architectures with strict memory alignment
|
||||
*/
|
||||
while (len) {
|
||||
tocopy = MIN(non_olap_size, len);
|
||||
len -= tocopy;
|
||||
|
||||
while (tocopy >= 16) {
|
||||
memcpy(out, from, 16);
|
||||
out += 16;
|
||||
from += 16;
|
||||
tocopy -= 16;
|
||||
}
|
||||
|
||||
if (tocopy >= 8) {
|
||||
memcpy(out, from, 8);
|
||||
out += 8;
|
||||
from += 8;
|
||||
tocopy -= 8;
|
||||
}
|
||||
|
||||
if (tocopy >= 4) {
|
||||
memcpy(out, from, 4);
|
||||
out += 4;
|
||||
from += 4;
|
||||
tocopy -= 4;
|
||||
}
|
||||
|
||||
while (tocopy--) {
|
||||
*out++ = *from++;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
#endif
|
||||
+37
-41
@@ -3,13 +3,11 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
|
||||
#define MAXBITS 15
|
||||
|
||||
const char inflate_copyright[] =
|
||||
" inflate 1.3.1 Copyright 1995-2024 Mark Adler ";
|
||||
const char PREFIX(inflate_copyright)[] = " inflate 1.3.1 Copyright 1995-2024 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
|
||||
@@ -29,9 +27,8 @@ const char inflate_copyright[] =
|
||||
table index bits. It will differ if the request is greater than the
|
||||
longest code or if it is less than the shortest code.
|
||||
*/
|
||||
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
unsigned codes, code FAR * FAR *table,
|
||||
unsigned FAR *bits, unsigned short FAR *work) {
|
||||
int Z_INTERNAL zng_inflate_table(codetype type, uint16_t *lens, unsigned codes,
|
||||
code * *table, unsigned *bits, uint16_t *work) {
|
||||
unsigned len; /* a code's length in bits */
|
||||
unsigned sym; /* index of code symbols */
|
||||
unsigned min, max; /* minimum and maximum code lengths */
|
||||
@@ -46,23 +43,23 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
unsigned low; /* low bits for current root entry */
|
||||
unsigned mask; /* mask for low root bits */
|
||||
code here; /* table entry for duplication */
|
||||
code FAR *next; /* next available space in table */
|
||||
const unsigned short FAR *base; /* base value table to use */
|
||||
const unsigned short FAR *extra; /* extra bits table to use */
|
||||
code *next; /* next available space in table */
|
||||
const uint16_t *base; /* base value table to use */
|
||||
const uint16_t *extra; /* extra bits table to use */
|
||||
unsigned match; /* use base and extra for symbol >= match */
|
||||
unsigned short count[MAXBITS+1]; /* number of codes of each length */
|
||||
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
|
||||
static const unsigned short lbase[31] = { /* Length codes 257..285 base */
|
||||
uint16_t count[MAX_BITS+1]; /* number of codes of each length */
|
||||
uint16_t offs[MAX_BITS+1]; /* offsets in table for each length */
|
||||
static const uint16_t lbase[31] = { /* Length codes 257..285 base */
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
|
||||
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
|
||||
static const uint16_t 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, 203, 77};
|
||||
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
|
||||
static const uint16_t 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,
|
||||
8193, 12289, 16385, 24577, 0, 0};
|
||||
static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
|
||||
static const uint16_t dext[32] = { /* Distance codes 0..29 extra */
|
||||
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
|
||||
23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
|
||||
28, 28, 29, 29, 64, 64};
|
||||
@@ -99,20 +96,20 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
*/
|
||||
|
||||
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
|
||||
for (len = 0; len <= MAXBITS; len++)
|
||||
for (len = 0; len <= MAX_BITS; len++)
|
||||
count[len] = 0;
|
||||
for (sym = 0; sym < codes; sym++)
|
||||
count[lens[sym]]++;
|
||||
|
||||
/* bound code lengths, force root to be within code lengths */
|
||||
root = *bits;
|
||||
for (max = MAXBITS; max >= 1; max--)
|
||||
for (max = MAX_BITS; max >= 1; max--)
|
||||
if (count[max] != 0) break;
|
||||
if (root > max) root = max;
|
||||
if (max == 0) { /* no symbols to code at all */
|
||||
root = MIN(root, max);
|
||||
if (UNLIKELY(max == 0)) { /* no symbols to code at all */
|
||||
here.op = (unsigned char)64; /* invalid code marker */
|
||||
here.bits = (unsigned char)1;
|
||||
here.val = (unsigned short)0;
|
||||
here.val = (uint16_t)0;
|
||||
*(*table)++ = here; /* make a table to force an error */
|
||||
*(*table)++ = here;
|
||||
*bits = 1;
|
||||
@@ -120,11 +117,11 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
}
|
||||
for (min = 1; min < max; min++)
|
||||
if (count[min] != 0) break;
|
||||
if (root < min) root = min;
|
||||
root = MAX(root, min);
|
||||
|
||||
/* check for an over-subscribed or incomplete set of lengths */
|
||||
left = 1;
|
||||
for (len = 1; len <= MAXBITS; len++) {
|
||||
for (len = 1; len <= MAX_BITS; len++) {
|
||||
left <<= 1;
|
||||
left -= count[len];
|
||||
if (left < 0) return -1; /* over-subscribed */
|
||||
@@ -134,12 +131,12 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
|
||||
/* generate offsets into symbol table for each length for sorting */
|
||||
offs[1] = 0;
|
||||
for (len = 1; len < MAXBITS; len++)
|
||||
for (len = 1; len < MAX_BITS; len++)
|
||||
offs[len + 1] = offs[len] + count[len];
|
||||
|
||||
/* sort symbols by length, by symbol order within each length */
|
||||
for (sym = 0; sym < codes; sym++)
|
||||
if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
|
||||
if (lens[sym] != 0) work[offs[lens[sym]]++] = (uint16_t)sym;
|
||||
|
||||
/*
|
||||
Create and fill in decoding tables. In this loop, the table being
|
||||
@@ -209,15 +206,13 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
for (;;) {
|
||||
/* create table entry */
|
||||
here.bits = (unsigned char)(len - drop);
|
||||
if (work[sym] + 1U < match) {
|
||||
here.op = (unsigned char)0;
|
||||
here.val = work[sym];
|
||||
}
|
||||
else if (work[sym] >= match) {
|
||||
if (LIKELY(work[sym] >= match)) {
|
||||
here.op = (unsigned char)(extra[work[sym] - match]);
|
||||
here.val = base[work[sym] - match];
|
||||
}
|
||||
else {
|
||||
} else if (work[sym] + 1U < match) {
|
||||
here.op = (unsigned char)0;
|
||||
here.val = work[sym];
|
||||
} else {
|
||||
here.op = (unsigned char)(32 + 64); /* end of block */
|
||||
here.val = 0;
|
||||
}
|
||||
@@ -238,14 +233,15 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
if (incr != 0) {
|
||||
huff &= incr - 1;
|
||||
huff += incr;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
huff = 0;
|
||||
}
|
||||
|
||||
/* go to next symbol, update count, len */
|
||||
sym++;
|
||||
if (--(count[len]) == 0) {
|
||||
if (len == max) break;
|
||||
if (len == max)
|
||||
break;
|
||||
len = lens[work[sym]];
|
||||
}
|
||||
|
||||
@@ -263,32 +259,32 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
left = (int)(1 << curr);
|
||||
while (curr + drop < max) {
|
||||
left -= count[curr + drop];
|
||||
if (left <= 0) break;
|
||||
if (left <= 0)
|
||||
break;
|
||||
curr++;
|
||||
left <<= 1;
|
||||
}
|
||||
|
||||
/* check for enough space */
|
||||
used += 1U << curr;
|
||||
if ((type == LENS && used > ENOUGH_LENS) ||
|
||||
(type == DISTS && used > ENOUGH_DISTS))
|
||||
if ((type == LENS && used > ENOUGH_LENS) || (type == DISTS && used > ENOUGH_DISTS))
|
||||
return 1;
|
||||
|
||||
/* point entry in root table to sub-table */
|
||||
low = huff & mask;
|
||||
(*table)[low].op = (unsigned char)curr;
|
||||
(*table)[low].bits = (unsigned char)root;
|
||||
(*table)[low].val = (unsigned short)(next - *table);
|
||||
(*table)[low].val = (uint16_t)(next - *table);
|
||||
}
|
||||
}
|
||||
|
||||
/* fill in remaining table entry if code is incomplete (guaranteed to have
|
||||
at most one remaining entry, since if the code is incomplete, the
|
||||
maximum code length that was allowed to get this far is one bit) */
|
||||
if (huff != 0) {
|
||||
if (UNLIKELY(huff != 0)) {
|
||||
here.op = (unsigned char)64; /* invalid code marker */
|
||||
here.bits = (unsigned char)(len - drop);
|
||||
here.val = (unsigned short)0;
|
||||
here.val = (uint16_t)0;
|
||||
next[huff] = here;
|
||||
}
|
||||
|
||||
|
||||
+17
-13
@@ -1,5 +1,8 @@
|
||||
#ifndef INFTREES_H_
|
||||
#define INFTREES_H_
|
||||
|
||||
/* inftrees.h -- header to use inftrees.c
|
||||
* Copyright (C) 1995-2005, 2010 Mark Adler
|
||||
* Copyright (C) 1995-2022 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@@ -22,9 +25,9 @@
|
||||
of a literal, the base length or distance, or the offset from
|
||||
the current table to the next table. Each entry is four bytes. */
|
||||
typedef struct {
|
||||
unsigned char op; /* operation, extra bits, table bits */
|
||||
unsigned char bits; /* bits in this part of the code */
|
||||
unsigned short val; /* offset in table or code value */
|
||||
unsigned char op; /* operation, extra bits, table bits */
|
||||
unsigned char bits; /* bits in this part of the code */
|
||||
uint16_t val; /* offset in table or code value */
|
||||
} code;
|
||||
|
||||
/* op values as set by inflate_table():
|
||||
@@ -36,17 +39,17 @@ typedef struct {
|
||||
*/
|
||||
|
||||
/* Maximum size of the dynamic table. The maximum number of code structures is
|
||||
1444, which is the sum of 852 for literal/length codes and 592 for distance
|
||||
1924, which is the sum of 1332 for literal/length codes and 592 for distance
|
||||
codes. These values were found by exhaustive searches using the program
|
||||
examples/enough.c found in the zlib distribution. The arguments to that
|
||||
examples/enough.c found in the zlib distributions. The arguments to that
|
||||
program are the number of symbols, the initial root table size, and the
|
||||
maximum bit length of a code. "enough 286 9 15" for literal/length codes
|
||||
returns 852, and "enough 30 6 15" for distance codes returns 592. The
|
||||
initial root table size (9 or 6) is found in the fifth argument of the
|
||||
maximum bit length of a code. "enough 286 10 15" for literal/length codes
|
||||
returns 1332, and "enough 30 9 15" for distance codes returns 592.
|
||||
The initial root table size (10 or 9) is found in the fifth argument of the
|
||||
inflate_table() calls in inflate.c and infback.c. If the root table size is
|
||||
changed, then these maximum sizes would be need to be recalculated and
|
||||
updated. */
|
||||
#define ENOUGH_LENS 852
|
||||
#define ENOUGH_LENS 1332
|
||||
#define ENOUGH_DISTS 592
|
||||
#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
|
||||
|
||||
@@ -57,6 +60,7 @@ typedef enum {
|
||||
DISTS
|
||||
} codetype;
|
||||
|
||||
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
|
||||
unsigned codes, code FAR * FAR *table,
|
||||
unsigned FAR *bits, unsigned short FAR *work);
|
||||
int Z_INTERNAL zng_inflate_table (codetype type, uint16_t *lens, unsigned codes,
|
||||
code * *table, unsigned *bits, uint16_t *work);
|
||||
|
||||
#endif /* INFTREES_H_ */
|
||||
@@ -0,0 +1,21 @@
|
||||
/* insert_string.c -- insert_string integer hash variant
|
||||
*
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "deflate.h"
|
||||
|
||||
#define HASH_SLIDE 16
|
||||
|
||||
#define HASH_CALC(h, val) h = ((val * 2654435761U) >> HASH_SLIDE);
|
||||
#define HASH_CALC_VAR h
|
||||
#define HASH_CALC_VAR_INIT uint32_t h = 0
|
||||
|
||||
#define UPDATE_HASH update_hash
|
||||
#define INSERT_STRING insert_string
|
||||
#define QUICK_INSERT_STRING quick_insert_string
|
||||
|
||||
#include "insert_string_tpl.h"
|
||||
@@ -0,0 +1,24 @@
|
||||
/* insert_string_roll.c -- insert_string rolling hash variant
|
||||
*
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*
|
||||
*/
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "deflate.h"
|
||||
|
||||
#define HASH_SLIDE 5
|
||||
|
||||
#define HASH_CALC(h, val) h = ((h << HASH_SLIDE) ^ ((uint8_t)val))
|
||||
#define HASH_CALC_VAR s->ins_h
|
||||
#define HASH_CALC_VAR_INIT
|
||||
#define HASH_CALC_READ val = strstart[0]
|
||||
#define HASH_CALC_MASK (32768u - 1u)
|
||||
#define HASH_CALC_OFFSET (STD_MIN_MATCH-1)
|
||||
|
||||
#define UPDATE_HASH update_hash_roll
|
||||
#define INSERT_STRING insert_string_roll
|
||||
#define QUICK_INSERT_STRING quick_insert_string_roll
|
||||
|
||||
#include "insert_string_tpl.h"
|
||||
@@ -0,0 +1,106 @@
|
||||
#ifndef INSERT_STRING_H_
|
||||
#define INSERT_STRING_H_
|
||||
|
||||
/* insert_string_tpl.h -- Private insert_string functions shared with more than
|
||||
* one insert string implementation
|
||||
*
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
*
|
||||
* Copyright (C) 2013 Intel Corporation. All rights reserved.
|
||||
* Authors:
|
||||
* Wajdi Feghali <wajdi.k.feghali@intel.com>
|
||||
* Jim Guilford <james.guilford@intel.com>
|
||||
* Vinodh Gopal <vinodh.gopal@intel.com>
|
||||
* Erdinc Ozturk <erdinc.ozturk@intel.com>
|
||||
* Jim Kukunas <james.t.kukunas@linux.intel.com>
|
||||
*
|
||||
* Portions are Copyright (C) 2016 12Sided Technology, LLC.
|
||||
* Author:
|
||||
* Phil Vachon <pvachon@12sidedtech.com>
|
||||
*
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*
|
||||
*/
|
||||
|
||||
#include "zmemory.h"
|
||||
|
||||
#ifndef HASH_CALC_OFFSET
|
||||
# define HASH_CALC_OFFSET 0
|
||||
#endif
|
||||
#ifndef HASH_CALC_MASK
|
||||
# define HASH_CALC_MASK HASH_MASK
|
||||
#endif
|
||||
#ifndef HASH_CALC_READ
|
||||
# if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define HASH_CALC_READ \
|
||||
val = zng_memread_4(strstart);
|
||||
# else
|
||||
# define HASH_CALC_READ \
|
||||
val = ZSWAP32(zng_memread_4(strstart));
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
* Update a hash value with the given input byte
|
||||
* IN assertion: all calls to UPDATE_HASH are made with consecutive
|
||||
* input characters, so that a running hash key can be computed from the
|
||||
* previous key instead of complete recalculation each time.
|
||||
*/
|
||||
Z_INTERNAL uint32_t UPDATE_HASH(uint32_t h, uint32_t val) {
|
||||
HASH_CALC(h, val);
|
||||
return h & HASH_CALC_MASK;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Quick insert string str in the dictionary and set match_head to the previous head
|
||||
* of the hash chain (the most recent string with same hash key). Return
|
||||
* the previous length of the hash chain.
|
||||
*/
|
||||
Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) {
|
||||
Pos head;
|
||||
uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
|
||||
uint32_t val, hm;
|
||||
|
||||
HASH_CALC_VAR_INIT;
|
||||
HASH_CALC_READ;
|
||||
HASH_CALC(HASH_CALC_VAR, val);
|
||||
HASH_CALC_VAR &= HASH_CALC_MASK;
|
||||
hm = HASH_CALC_VAR;
|
||||
|
||||
head = s->head[hm];
|
||||
if (LIKELY(head != str)) {
|
||||
s->prev[str & s->w_mask] = head;
|
||||
s->head[hm] = (Pos)str;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Insert string str in the dictionary and set match_head to the previous head
|
||||
* of the hash chain (the most recent string with same hash key). Return
|
||||
* the previous length of the hash chain.
|
||||
* IN assertion: all calls to INSERT_STRING are made with consecutive
|
||||
* input characters and the first STD_MIN_MATCH bytes of str are valid
|
||||
* (except for the last STD_MIN_MATCH-1 bytes of the input file).
|
||||
*/
|
||||
Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) {
|
||||
uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
|
||||
uint8_t *strend = strstart + count;
|
||||
|
||||
for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) {
|
||||
uint32_t val, hm;
|
||||
|
||||
HASH_CALC_VAR_INIT;
|
||||
HASH_CALC_READ;
|
||||
HASH_CALC(HASH_CALC_VAR, val);
|
||||
HASH_CALC_VAR &= HASH_CALC_MASK;
|
||||
hm = HASH_CALC_VAR;
|
||||
|
||||
Pos head = s->head[hm];
|
||||
if (LIKELY(head != idx)) {
|
||||
s->prev[idx & s->w_mask] = head;
|
||||
s->head[hm] = idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,250 @@
|
||||
/* match_tpl.h -- find longest match template for compare256 variants
|
||||
*
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*
|
||||
* Portions copyright (C) 2014-2021 Konstantin Nosov
|
||||
* Fast-zlib optimized longest_match
|
||||
* https://github.com/gildor2/fast_zlib
|
||||
*/
|
||||
|
||||
#ifndef MATCH_TPL_H
|
||||
#define MATCH_TPL_H
|
||||
|
||||
#define EARLY_EXIT_TRIGGER_LEVEL 5
|
||||
|
||||
#endif
|
||||
|
||||
/* Set match_start to the longest match starting at the given string and
|
||||
* return its length. Matches shorter or equal to prev_length are discarded,
|
||||
* in which case the result is equal to prev_length and match_start is garbage.
|
||||
*
|
||||
* IN assertions: cur_match is the head of the hash chain for the current
|
||||
* string (strstart) and its distance is <= MAX_DIST, and prev_length >=1
|
||||
* OUT assertion: the match length is not greater than s->lookahead
|
||||
*
|
||||
* The LONGEST_MATCH_SLOW variant spends more time to attempt to find longer
|
||||
* matches once a match has already been found.
|
||||
*/
|
||||
Z_INTERNAL uint32_t LONGEST_MATCH(deflate_state *const s, Pos cur_match) {
|
||||
unsigned int strstart = s->strstart;
|
||||
const unsigned wmask = s->w_mask;
|
||||
unsigned char *window = s->window;
|
||||
unsigned char *scan = window + strstart;
|
||||
Z_REGISTER unsigned char *mbase_start = window;
|
||||
Z_REGISTER unsigned char *mbase_end;
|
||||
const Pos *prev = s->prev;
|
||||
Pos limit;
|
||||
#ifdef LONGEST_MATCH_SLOW
|
||||
Pos limit_base;
|
||||
#else
|
||||
int32_t early_exit;
|
||||
#endif
|
||||
uint32_t chain_length, nice_match, best_len, offset;
|
||||
uint32_t lookahead = s->lookahead;
|
||||
Pos match_offset = 0;
|
||||
uint64_t scan_start;
|
||||
uint64_t scan_end;
|
||||
|
||||
#define GOTO_NEXT_CHAIN \
|
||||
if (--chain_length && (cur_match = prev[cur_match & wmask]) > limit) \
|
||||
continue; \
|
||||
return best_len;
|
||||
|
||||
/* The code is optimized for STD_MAX_MATCH-2 multiple of 16. */
|
||||
Assert(STD_MAX_MATCH == 258, "Code too clever");
|
||||
|
||||
best_len = s->prev_length ? s->prev_length : STD_MIN_MATCH-1;
|
||||
|
||||
/* Calculate read offset which should only extend an extra byte
|
||||
* to find the next best match length.
|
||||
*/
|
||||
offset = best_len-1;
|
||||
if (best_len >= sizeof(uint32_t)) {
|
||||
offset -= 2;
|
||||
if (best_len >= sizeof(uint64_t))
|
||||
offset -= 4;
|
||||
}
|
||||
|
||||
scan_start = zng_memread_8(scan);
|
||||
scan_end = zng_memread_8(scan+offset);
|
||||
mbase_end = (mbase_start+offset);
|
||||
|
||||
/* Do not waste too much time if we already have a good match */
|
||||
chain_length = s->max_chain_length;
|
||||
if (best_len >= s->good_match)
|
||||
chain_length >>= 2;
|
||||
nice_match = (uint32_t)s->nice_match;
|
||||
|
||||
/* Stop when cur_match becomes <= limit. To simplify the code,
|
||||
* we prevent matches with the string of window index 0
|
||||
*/
|
||||
limit = strstart > MAX_DIST(s) ? (Pos)(strstart - MAX_DIST(s)) : 0;
|
||||
#ifdef LONGEST_MATCH_SLOW
|
||||
limit_base = limit;
|
||||
if (best_len >= STD_MIN_MATCH) {
|
||||
/* We're continuing search (lazy evaluation). */
|
||||
uint32_t i, hash;
|
||||
Pos pos;
|
||||
|
||||
/* Find a most distant chain starting from scan with index=1 (index=0 corresponds
|
||||
* to cur_match). We cannot use s->prev[strstart+1,...] immediately, because
|
||||
* these strings are not yet inserted into the hash table.
|
||||
*/
|
||||
hash = s->update_hash(0, scan[1]);
|
||||
hash = s->update_hash(hash, scan[2]);
|
||||
|
||||
for (i = 3; i <= best_len; i++) {
|
||||
hash = s->update_hash(hash, scan[i]);
|
||||
|
||||
/* If we're starting with best_len >= 3, we can use offset search. */
|
||||
pos = s->head[hash];
|
||||
if (pos < cur_match) {
|
||||
match_offset = (Pos)(i - 2);
|
||||
cur_match = pos;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update offset-dependent variables */
|
||||
limit = limit_base+match_offset;
|
||||
if (cur_match <= limit)
|
||||
goto break_matching;
|
||||
mbase_start -= match_offset;
|
||||
mbase_end -= match_offset;
|
||||
}
|
||||
#else
|
||||
early_exit = s->level < EARLY_EXIT_TRIGGER_LEVEL;
|
||||
#endif
|
||||
Assert((unsigned long)strstart <= s->window_size - MIN_LOOKAHEAD, "need lookahead");
|
||||
for (;;) {
|
||||
if (cur_match >= strstart)
|
||||
break;
|
||||
|
||||
/* Skip to next match if the match length cannot increase or if the match length is
|
||||
* less than 2. Note that the checks below for insufficient lookahead only occur
|
||||
* occasionally for performance reasons.
|
||||
* Therefore uninitialized memory will be accessed and conditional jumps will be made
|
||||
* that depend on those values. However the length of the match is limited to the
|
||||
* lookahead, so the output of deflate is not affected by the uninitialized values.
|
||||
*/
|
||||
if (best_len < sizeof(uint32_t)) {
|
||||
for (;;) {
|
||||
if (zng_memcmp_2(mbase_end+cur_match, &scan_end) == 0 &&
|
||||
zng_memcmp_2(mbase_start+cur_match, &scan_start) == 0)
|
||||
break;
|
||||
GOTO_NEXT_CHAIN;
|
||||
}
|
||||
} else if (best_len >= sizeof(uint64_t)) {
|
||||
for (;;) {
|
||||
if (zng_memcmp_8(mbase_end+cur_match, &scan_end) == 0 &&
|
||||
zng_memcmp_8(mbase_start+cur_match, &scan_start) == 0)
|
||||
break;
|
||||
GOTO_NEXT_CHAIN;
|
||||
}
|
||||
} else {
|
||||
for (;;) {
|
||||
if (zng_memcmp_4(mbase_end+cur_match, &scan_end) == 0 &&
|
||||
zng_memcmp_4(mbase_start+cur_match, &scan_start) == 0)
|
||||
break;
|
||||
GOTO_NEXT_CHAIN;
|
||||
}
|
||||
}
|
||||
uint32_t len = COMPARE256(scan+2, mbase_start+cur_match+2) + 2;
|
||||
Assert(scan+len <= window+(unsigned)(s->window_size-1), "wild scan");
|
||||
|
||||
if (len > best_len) {
|
||||
uint32_t match_start = cur_match - match_offset;
|
||||
s->match_start = match_start;
|
||||
|
||||
/* Do not look for matches beyond the end of the input. */
|
||||
if (len > lookahead)
|
||||
return lookahead;
|
||||
best_len = len;
|
||||
if (best_len >= nice_match)
|
||||
return best_len;
|
||||
|
||||
offset = best_len-1;
|
||||
if (best_len >= sizeof(uint32_t)) {
|
||||
offset -= 2;
|
||||
if (best_len >= sizeof(uint64_t))
|
||||
offset -= 4;
|
||||
}
|
||||
|
||||
scan_end = zng_memread_8(scan+offset);
|
||||
|
||||
#ifdef LONGEST_MATCH_SLOW
|
||||
/* Look for a better string offset */
|
||||
if (UNLIKELY(len > STD_MIN_MATCH && match_start + len < strstart)) {
|
||||
Pos pos, next_pos;
|
||||
uint32_t i, hash;
|
||||
unsigned char *scan_endstr;
|
||||
|
||||
/* Go back to offset 0 */
|
||||
cur_match -= match_offset;
|
||||
match_offset = 0;
|
||||
next_pos = cur_match;
|
||||
for (i = 0; i <= len - STD_MIN_MATCH; i++) {
|
||||
pos = prev[(cur_match + i) & wmask];
|
||||
if (pos < next_pos) {
|
||||
/* Hash chain is more distant, use it */
|
||||
if (pos <= limit_base + i)
|
||||
goto break_matching;
|
||||
next_pos = pos;
|
||||
match_offset = (Pos)i;
|
||||
}
|
||||
}
|
||||
/* Switch cur_match to next_pos chain */
|
||||
cur_match = next_pos;
|
||||
|
||||
/* Try hash head at len-(STD_MIN_MATCH-1) position to see if we could get
|
||||
* a better cur_match at the end of string. Using (STD_MIN_MATCH-1) lets
|
||||
* us include one more byte into hash - the byte which will be checked
|
||||
* in main loop now, and which allows to grow match by 1.
|
||||
*/
|
||||
scan_endstr = scan + len - (STD_MIN_MATCH+1);
|
||||
|
||||
hash = s->update_hash(0, scan_endstr[0]);
|
||||
hash = s->update_hash(hash, scan_endstr[1]);
|
||||
hash = s->update_hash(hash, scan_endstr[2]);
|
||||
|
||||
pos = s->head[hash];
|
||||
if (pos < cur_match) {
|
||||
match_offset = (Pos)(len - (STD_MIN_MATCH+1));
|
||||
if (pos <= limit_base + match_offset)
|
||||
goto break_matching;
|
||||
cur_match = pos;
|
||||
}
|
||||
|
||||
/* Update offset-dependent variables */
|
||||
limit = limit_base+match_offset;
|
||||
mbase_start = window-match_offset;
|
||||
mbase_end = (mbase_start+offset);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
mbase_end = (mbase_start+offset);
|
||||
}
|
||||
#ifndef LONGEST_MATCH_SLOW
|
||||
else if (UNLIKELY(early_exit)) {
|
||||
/* The probability of finding a match later if we here is pretty low, so for
|
||||
* performance it's best to outright stop here for the lower compression levels
|
||||
*/
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
GOTO_NEXT_CHAIN;
|
||||
}
|
||||
return best_len;
|
||||
|
||||
#ifdef LONGEST_MATCH_SLOW
|
||||
break_matching:
|
||||
|
||||
if (best_len < s->lookahead)
|
||||
return best_len;
|
||||
|
||||
return s->lookahead;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef LONGEST_MATCH_SLOW
|
||||
#undef LONGEST_MATCH
|
||||
+384
-683
File diff suppressed because it is too large.
Load diff
+33
-121
@@ -1,128 +1,40 @@
|
||||
/* header created automatically with -DGEN_TREES_H */
|
||||
#ifndef TREES_H_
|
||||
#define TREES_H_
|
||||
|
||||
local const ct_data static_ltree[L_CODES+2] = {
|
||||
{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
|
||||
{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
|
||||
{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
|
||||
{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
|
||||
{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
|
||||
{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
|
||||
{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
|
||||
{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
|
||||
{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
|
||||
{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
|
||||
{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
|
||||
{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
|
||||
{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
|
||||
{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
|
||||
{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
|
||||
{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
|
||||
{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
|
||||
{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
|
||||
{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
|
||||
{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
|
||||
{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
|
||||
{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
|
||||
{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
|
||||
{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
|
||||
{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
|
||||
{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
|
||||
{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
|
||||
{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
|
||||
{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
|
||||
{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
|
||||
{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
|
||||
{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
|
||||
{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
|
||||
{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
|
||||
{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
|
||||
{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
|
||||
{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
|
||||
{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
|
||||
{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
|
||||
{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
|
||||
{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
|
||||
{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
|
||||
{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
|
||||
{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
|
||||
{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
|
||||
{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
|
||||
{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
|
||||
{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
|
||||
{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
|
||||
{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
|
||||
{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
|
||||
{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
|
||||
{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
|
||||
{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
|
||||
{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
|
||||
{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
|
||||
{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
|
||||
{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
|
||||
};
|
||||
/* Constants */
|
||||
|
||||
local const ct_data static_dtree[D_CODES] = {
|
||||
{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
|
||||
{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
|
||||
{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
|
||||
{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
|
||||
{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
|
||||
{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
|
||||
};
|
||||
#define DIST_CODE_LEN 512
|
||||
/* see definition of array dist_code in trees.c */
|
||||
|
||||
const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {
|
||||
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
|
||||
18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
|
||||
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
|
||||
};
|
||||
#define MAX_BL_BITS 7
|
||||
/* Bit length codes must not exceed MAX_BL_BITS bits */
|
||||
|
||||
const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
|
||||
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
||||
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
|
||||
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
|
||||
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
|
||||
};
|
||||
#define REP_3_6 16
|
||||
/* repeat previous bit length 3-6 times (2 bits of repeat count) */
|
||||
|
||||
local const int base_length[LENGTH_CODES] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
|
||||
64, 80, 96, 112, 128, 160, 192, 224, 0
|
||||
};
|
||||
#define REPZ_3_10 17
|
||||
/* repeat a zero length 3-10 times (3 bits of repeat count) */
|
||||
|
||||
local const int base_dist[D_CODES] = {
|
||||
0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
|
||||
32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
|
||||
1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
|
||||
};
|
||||
#define REPZ_11_138 18
|
||||
/* repeat a zero length 11-138 times (7 bits of repeat count) */
|
||||
|
||||
static const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
|
||||
= {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
|
||||
|
||||
static const int extra_dbits[D_CODES] /* extra bits for each distance code */
|
||||
= {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
|
||||
|
||||
static const int extra_blbits[BL_CODES] /* extra bits for each bit length code */
|
||||
= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
|
||||
|
||||
static const unsigned char bl_order[BL_CODES]
|
||||
= {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
|
||||
/* The lengths of the bit length codes are sent in order of decreasing
|
||||
* probability, to avoid transmitting the lengths for unused bit length codes.
|
||||
*/
|
||||
|
||||
|
||||
/* Function definitions */
|
||||
void gen_codes (ct_data *tree, int max_code, uint16_t *bl_count);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,231 @@
|
||||
#ifndef TREES_EMIT_H_
|
||||
#define TREES_EMIT_H_
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "trees.h"
|
||||
|
||||
#ifdef ZLIB_DEBUG
|
||||
# include <ctype.h>
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* trees.h */
|
||||
extern Z_INTERNAL const ct_data static_ltree[L_CODES+2];
|
||||
extern Z_INTERNAL const ct_data static_dtree[D_CODES];
|
||||
|
||||
extern const unsigned char Z_INTERNAL zng_dist_code[DIST_CODE_LEN];
|
||||
extern const unsigned char Z_INTERNAL zng_length_code[STD_MAX_MATCH-STD_MIN_MATCH+1];
|
||||
|
||||
extern Z_INTERNAL const int base_length[LENGTH_CODES];
|
||||
extern Z_INTERNAL const int base_dist[D_CODES];
|
||||
|
||||
/* Bit buffer and deflate code stderr tracing */
|
||||
#ifdef ZLIB_DEBUG
|
||||
# define send_bits_trace(s, value, length) { \
|
||||
Tracevv((stderr, " l %2d v %4llx ", (int)(length), (long long)(value))); \
|
||||
Assert(length > 0 && length <= BIT_BUF_SIZE, "invalid length"); \
|
||||
}
|
||||
# define send_code_trace(s, c) \
|
||||
if (z_verbose > 2) { \
|
||||
fprintf(stderr, "\ncd %3d ", (c)); \
|
||||
}
|
||||
#else
|
||||
# define send_bits_trace(s, value, length)
|
||||
# define send_code_trace(s, c)
|
||||
#endif
|
||||
|
||||
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
|
||||
* (64 - bi_valid) bits from value, leaving (width - (64-bi_valid))
|
||||
* unused bits in value.
|
||||
*
|
||||
* NOTE: Static analyzers can't evaluate value of total_bits, so we
|
||||
* also need to make sure bi_valid is within acceptable range,
|
||||
* otherwise the shifts will overflow.
|
||||
*/
|
||||
#define send_bits(s, t_val, t_len, bi_buf, bi_valid) {\
|
||||
uint64_t val = (uint64_t)t_val;\
|
||||
uint32_t len = (uint32_t)t_len;\
|
||||
uint32_t total_bits = bi_valid + len;\
|
||||
send_bits_trace(s, val, len);\
|
||||
sent_bits_add(s, len);\
|
||||
if (total_bits < BIT_BUF_SIZE && bi_valid < BIT_BUF_SIZE) {\
|
||||
bi_buf |= val << bi_valid;\
|
||||
bi_valid = total_bits;\
|
||||
} else if (bi_valid >= BIT_BUF_SIZE) {\
|
||||
put_uint64(s, bi_buf);\
|
||||
bi_buf = val;\
|
||||
bi_valid = len;\
|
||||
} else {\
|
||||
bi_buf |= val << bi_valid;\
|
||||
put_uint64(s, bi_buf);\
|
||||
bi_buf = val >> (BIT_BUF_SIZE - bi_valid);\
|
||||
bi_valid = total_bits - BIT_BUF_SIZE;\
|
||||
}\
|
||||
}
|
||||
|
||||
/* Send a code of the given tree. c and tree must not have side effects */
|
||||
#ifdef ZLIB_DEBUG
|
||||
# define send_code(s, c, tree, bi_buf, bi_valid) { \
|
||||
send_code_trace(s, c); \
|
||||
send_bits(s, tree[c].Code, tree[c].Len, bi_buf, bi_valid); \
|
||||
}
|
||||
#else
|
||||
# define send_code(s, c, tree, bi_buf, bi_valid) \
|
||||
send_bits(s, tree[c].Code, tree[c].Len, bi_buf, bi_valid)
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
* Flush the bit buffer and align the output on a byte boundary
|
||||
*/
|
||||
static void bi_windup(deflate_state *s) {
|
||||
if (s->bi_valid > 56) {
|
||||
put_uint64(s, s->bi_buf);
|
||||
} else {
|
||||
if (s->bi_valid > 24) {
|
||||
put_uint32(s, (uint32_t)s->bi_buf);
|
||||
s->bi_buf >>= 32;
|
||||
s->bi_valid -= 32;
|
||||
}
|
||||
if (s->bi_valid > 8) {
|
||||
put_short(s, (uint16_t)s->bi_buf);
|
||||
s->bi_buf >>= 16;
|
||||
s->bi_valid -= 16;
|
||||
}
|
||||
if (s->bi_valid > 0) {
|
||||
put_byte(s, s->bi_buf);
|
||||
}
|
||||
}
|
||||
s->bi_buf = 0;
|
||||
s->bi_valid = 0;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Emit literal code
|
||||
*/
|
||||
static inline uint32_t zng_emit_lit(deflate_state *s, const ct_data *ltree, unsigned c) {
|
||||
uint32_t bi_valid = s->bi_valid;
|
||||
uint64_t bi_buf = s->bi_buf;
|
||||
|
||||
send_code(s, c, ltree, bi_buf, bi_valid);
|
||||
|
||||
s->bi_valid = bi_valid;
|
||||
s->bi_buf = bi_buf;
|
||||
|
||||
Tracecv(isgraph(c & 0xff), (stderr, " '%c' ", c));
|
||||
|
||||
return ltree[c].Len;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Emit match distance/length code
|
||||
*/
|
||||
static inline uint32_t zng_emit_dist(deflate_state *s, const ct_data *ltree, const ct_data *dtree,
|
||||
uint32_t lc, uint32_t dist) {
|
||||
uint32_t c, extra;
|
||||
uint8_t code;
|
||||
uint64_t match_bits;
|
||||
uint32_t match_bits_len;
|
||||
uint32_t bi_valid = s->bi_valid;
|
||||
uint64_t bi_buf = s->bi_buf;
|
||||
|
||||
/* Send the length code, len is the match length - STD_MIN_MATCH */
|
||||
code = zng_length_code[lc];
|
||||
c = code+LITERALS+1;
|
||||
Assert(c < L_CODES, "bad l_code");
|
||||
send_code_trace(s, c);
|
||||
|
||||
match_bits = ltree[c].Code;
|
||||
match_bits_len = ltree[c].Len;
|
||||
extra = extra_lbits[code];
|
||||
if (extra != 0) {
|
||||
lc -= base_length[code];
|
||||
match_bits |= ((uint64_t)lc << match_bits_len);
|
||||
match_bits_len += extra;
|
||||
}
|
||||
|
||||
dist--; /* dist is now the match distance - 1 */
|
||||
code = d_code(dist);
|
||||
Assert(code < D_CODES, "bad d_code");
|
||||
send_code_trace(s, code);
|
||||
|
||||
/* Send the distance code */
|
||||
match_bits |= ((uint64_t)dtree[code].Code << match_bits_len);
|
||||
match_bits_len += dtree[code].Len;
|
||||
extra = extra_dbits[code];
|
||||
if (extra != 0) {
|
||||
dist -= base_dist[code];
|
||||
match_bits |= ((uint64_t)dist << match_bits_len);
|
||||
match_bits_len += extra;
|
||||
}
|
||||
|
||||
send_bits(s, match_bits, match_bits_len, bi_buf, bi_valid);
|
||||
|
||||
s->bi_valid = bi_valid;
|
||||
s->bi_buf = bi_buf;
|
||||
|
||||
return match_bits_len;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Emit end block
|
||||
*/
|
||||
static inline void zng_emit_end_block(deflate_state *s, const ct_data *ltree, const int last) {
|
||||
uint32_t bi_valid = s->bi_valid;
|
||||
uint64_t bi_buf = s->bi_buf;
|
||||
send_code(s, END_BLOCK, ltree, bi_buf, bi_valid);
|
||||
s->bi_valid = bi_valid;
|
||||
s->bi_buf = bi_buf;
|
||||
Tracev((stderr, "\n+++ Emit End Block: Last: %u Pending: %u Total Out: %" PRIu64 "\n",
|
||||
last, s->pending, (uint64_t)s->strm->total_out));
|
||||
Z_UNUSED(last);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Emit literal and count bits
|
||||
*/
|
||||
static inline void zng_tr_emit_lit(deflate_state *s, const ct_data *ltree, unsigned c) {
|
||||
cmpr_bits_add(s, zng_emit_lit(s, ltree, c));
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Emit match and count bits
|
||||
*/
|
||||
static inline void zng_tr_emit_dist(deflate_state *s, const ct_data *ltree, const ct_data *dtree,
|
||||
uint32_t lc, uint32_t dist) {
|
||||
cmpr_bits_add(s, zng_emit_dist(s, ltree, dtree, lc, dist));
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Emit start of block
|
||||
*/
|
||||
static inline void zng_tr_emit_tree(deflate_state *s, int type, const int last) {
|
||||
uint32_t bi_valid = s->bi_valid;
|
||||
uint64_t bi_buf = s->bi_buf;
|
||||
uint32_t header_bits = (type << 1) + last;
|
||||
send_bits(s, header_bits, 3, bi_buf, bi_valid);
|
||||
cmpr_bits_add(s, 3);
|
||||
s->bi_valid = bi_valid;
|
||||
s->bi_buf = bi_buf;
|
||||
Tracev((stderr, "\n--- Emit Tree: Last: %u\n", last));
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Align bit buffer on a byte boundary and count bits
|
||||
*/
|
||||
static inline void zng_tr_emit_align(deflate_state *s) {
|
||||
bi_windup(s); /* align on byte boundary */
|
||||
sent_bits_align(s);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Emit an end block and align bit buffer if last block
|
||||
*/
|
||||
static inline void zng_tr_emit_end_block(deflate_state *s, const ct_data *ltree, const int last) {
|
||||
zng_emit_end_block(s, ltree, last);
|
||||
cmpr_bits_add(s, 7);
|
||||
if (last)
|
||||
zng_tr_emit_align(s);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,132 @@
|
||||
#ifndef TREES_TBL_H_
|
||||
#define TREES_TBL_H_
|
||||
|
||||
/* header created automatically with maketrees.c */
|
||||
|
||||
Z_INTERNAL const ct_data static_ltree[L_CODES+2] = {
|
||||
{{ 12},{8}}, {{140},{8}}, {{ 76},{8}}, {{204},{8}}, {{ 44},{8}},
|
||||
{{172},{8}}, {{108},{8}}, {{236},{8}}, {{ 28},{8}}, {{156},{8}},
|
||||
{{ 92},{8}}, {{220},{8}}, {{ 60},{8}}, {{188},{8}}, {{124},{8}},
|
||||
{{252},{8}}, {{ 2},{8}}, {{130},{8}}, {{ 66},{8}}, {{194},{8}},
|
||||
{{ 34},{8}}, {{162},{8}}, {{ 98},{8}}, {{226},{8}}, {{ 18},{8}},
|
||||
{{146},{8}}, {{ 82},{8}}, {{210},{8}}, {{ 50},{8}}, {{178},{8}},
|
||||
{{114},{8}}, {{242},{8}}, {{ 10},{8}}, {{138},{8}}, {{ 74},{8}},
|
||||
{{202},{8}}, {{ 42},{8}}, {{170},{8}}, {{106},{8}}, {{234},{8}},
|
||||
{{ 26},{8}}, {{154},{8}}, {{ 90},{8}}, {{218},{8}}, {{ 58},{8}},
|
||||
{{186},{8}}, {{122},{8}}, {{250},{8}}, {{ 6},{8}}, {{134},{8}},
|
||||
{{ 70},{8}}, {{198},{8}}, {{ 38},{8}}, {{166},{8}}, {{102},{8}},
|
||||
{{230},{8}}, {{ 22},{8}}, {{150},{8}}, {{ 86},{8}}, {{214},{8}},
|
||||
{{ 54},{8}}, {{182},{8}}, {{118},{8}}, {{246},{8}}, {{ 14},{8}},
|
||||
{{142},{8}}, {{ 78},{8}}, {{206},{8}}, {{ 46},{8}}, {{174},{8}},
|
||||
{{110},{8}}, {{238},{8}}, {{ 30},{8}}, {{158},{8}}, {{ 94},{8}},
|
||||
{{222},{8}}, {{ 62},{8}}, {{190},{8}}, {{126},{8}}, {{254},{8}},
|
||||
{{ 1},{8}}, {{129},{8}}, {{ 65},{8}}, {{193},{8}}, {{ 33},{8}},
|
||||
{{161},{8}}, {{ 97},{8}}, {{225},{8}}, {{ 17},{8}}, {{145},{8}},
|
||||
{{ 81},{8}}, {{209},{8}}, {{ 49},{8}}, {{177},{8}}, {{113},{8}},
|
||||
{{241},{8}}, {{ 9},{8}}, {{137},{8}}, {{ 73},{8}}, {{201},{8}},
|
||||
{{ 41},{8}}, {{169},{8}}, {{105},{8}}, {{233},{8}}, {{ 25},{8}},
|
||||
{{153},{8}}, {{ 89},{8}}, {{217},{8}}, {{ 57},{8}}, {{185},{8}},
|
||||
{{121},{8}}, {{249},{8}}, {{ 5},{8}}, {{133},{8}}, {{ 69},{8}},
|
||||
{{197},{8}}, {{ 37},{8}}, {{165},{8}}, {{101},{8}}, {{229},{8}},
|
||||
{{ 21},{8}}, {{149},{8}}, {{ 85},{8}}, {{213},{8}}, {{ 53},{8}},
|
||||
{{181},{8}}, {{117},{8}}, {{245},{8}}, {{ 13},{8}}, {{141},{8}},
|
||||
{{ 77},{8}}, {{205},{8}}, {{ 45},{8}}, {{173},{8}}, {{109},{8}},
|
||||
{{237},{8}}, {{ 29},{8}}, {{157},{8}}, {{ 93},{8}}, {{221},{8}},
|
||||
{{ 61},{8}}, {{189},{8}}, {{125},{8}}, {{253},{8}}, {{ 19},{9}},
|
||||
{{275},{9}}, {{147},{9}}, {{403},{9}}, {{ 83},{9}}, {{339},{9}},
|
||||
{{211},{9}}, {{467},{9}}, {{ 51},{9}}, {{307},{9}}, {{179},{9}},
|
||||
{{435},{9}}, {{115},{9}}, {{371},{9}}, {{243},{9}}, {{499},{9}},
|
||||
{{ 11},{9}}, {{267},{9}}, {{139},{9}}, {{395},{9}}, {{ 75},{9}},
|
||||
{{331},{9}}, {{203},{9}}, {{459},{9}}, {{ 43},{9}}, {{299},{9}},
|
||||
{{171},{9}}, {{427},{9}}, {{107},{9}}, {{363},{9}}, {{235},{9}},
|
||||
{{491},{9}}, {{ 27},{9}}, {{283},{9}}, {{155},{9}}, {{411},{9}},
|
||||
{{ 91},{9}}, {{347},{9}}, {{219},{9}}, {{475},{9}}, {{ 59},{9}},
|
||||
{{315},{9}}, {{187},{9}}, {{443},{9}}, {{123},{9}}, {{379},{9}},
|
||||
{{251},{9}}, {{507},{9}}, {{ 7},{9}}, {{263},{9}}, {{135},{9}},
|
||||
{{391},{9}}, {{ 71},{9}}, {{327},{9}}, {{199},{9}}, {{455},{9}},
|
||||
{{ 39},{9}}, {{295},{9}}, {{167},{9}}, {{423},{9}}, {{103},{9}},
|
||||
{{359},{9}}, {{231},{9}}, {{487},{9}}, {{ 23},{9}}, {{279},{9}},
|
||||
{{151},{9}}, {{407},{9}}, {{ 87},{9}}, {{343},{9}}, {{215},{9}},
|
||||
{{471},{9}}, {{ 55},{9}}, {{311},{9}}, {{183},{9}}, {{439},{9}},
|
||||
{{119},{9}}, {{375},{9}}, {{247},{9}}, {{503},{9}}, {{ 15},{9}},
|
||||
{{271},{9}}, {{143},{9}}, {{399},{9}}, {{ 79},{9}}, {{335},{9}},
|
||||
{{207},{9}}, {{463},{9}}, {{ 47},{9}}, {{303},{9}}, {{175},{9}},
|
||||
{{431},{9}}, {{111},{9}}, {{367},{9}}, {{239},{9}}, {{495},{9}},
|
||||
{{ 31},{9}}, {{287},{9}}, {{159},{9}}, {{415},{9}}, {{ 95},{9}},
|
||||
{{351},{9}}, {{223},{9}}, {{479},{9}}, {{ 63},{9}}, {{319},{9}},
|
||||
{{191},{9}}, {{447},{9}}, {{127},{9}}, {{383},{9}}, {{255},{9}},
|
||||
{{511},{9}}, {{ 0},{7}}, {{ 64},{7}}, {{ 32},{7}}, {{ 96},{7}},
|
||||
{{ 16},{7}}, {{ 80},{7}}, {{ 48},{7}}, {{112},{7}}, {{ 8},{7}},
|
||||
{{ 72},{7}}, {{ 40},{7}}, {{104},{7}}, {{ 24},{7}}, {{ 88},{7}},
|
||||
{{ 56},{7}}, {{120},{7}}, {{ 4},{7}}, {{ 68},{7}}, {{ 36},{7}},
|
||||
{{100},{7}}, {{ 20},{7}}, {{ 84},{7}}, {{ 52},{7}}, {{116},{7}},
|
||||
{{ 3},{8}}, {{131},{8}}, {{ 67},{8}}, {{195},{8}}, {{ 35},{8}},
|
||||
{{163},{8}}, {{ 99},{8}}, {{227},{8}}
|
||||
};
|
||||
|
||||
Z_INTERNAL const ct_data static_dtree[D_CODES] = {
|
||||
{{ 0},{5}}, {{16},{5}}, {{ 8},{5}}, {{24},{5}}, {{ 4},{5}},
|
||||
{{20},{5}}, {{12},{5}}, {{28},{5}}, {{ 2},{5}}, {{18},{5}},
|
||||
{{10},{5}}, {{26},{5}}, {{ 6},{5}}, {{22},{5}}, {{14},{5}},
|
||||
{{30},{5}}, {{ 1},{5}}, {{17},{5}}, {{ 9},{5}}, {{25},{5}},
|
||||
{{ 5},{5}}, {{21},{5}}, {{13},{5}}, {{29},{5}}, {{ 3},{5}},
|
||||
{{19},{5}}, {{11},{5}}, {{27},{5}}, {{ 7},{5}}, {{23},{5}}
|
||||
};
|
||||
|
||||
const unsigned char Z_INTERNAL zng_dist_code[DIST_CODE_LEN] = {
|
||||
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
|
||||
18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
|
||||
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
|
||||
};
|
||||
|
||||
const unsigned char Z_INTERNAL zng_length_code[STD_MAX_MATCH-STD_MIN_MATCH+1] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
|
||||
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
||||
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
|
||||
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
|
||||
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
|
||||
};
|
||||
|
||||
Z_INTERNAL const int base_length[LENGTH_CODES] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
|
||||
64, 80, 96, 112, 128, 160, 192, 224, 0
|
||||
};
|
||||
|
||||
Z_INTERNAL const int base_dist[D_CODES] = {
|
||||
0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
|
||||
32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
|
||||
1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
|
||||
};
|
||||
|
||||
#endif /* TREES_TBL_H_ */
|
||||
+21
-26
@@ -1,12 +1,10 @@
|
||||
/* uncompr.c -- decompress a memory buffer
|
||||
* Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
|
||||
* Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#define ZLIB_INTERNAL
|
||||
#include "zlib.h"
|
||||
#include "zbuild.h"
|
||||
#include "zutil.h"
|
||||
|
||||
/* ===========================================================================
|
||||
Decompresses the source buffer into the destination buffer. *sourceLen is
|
||||
@@ -24,31 +22,29 @@
|
||||
Z_DATA_ERROR if the input data was corrupted, including if the input data is
|
||||
an incomplete zlib stream.
|
||||
*/
|
||||
int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||
uLong *sourceLen) {
|
||||
z_stream stream;
|
||||
int Z_EXPORT PREFIX(uncompress2)(unsigned char *dest, z_uintmax_t *destLen, const unsigned char *source, z_uintmax_t *sourceLen) {
|
||||
PREFIX3(stream) stream;
|
||||
int err;
|
||||
const uInt max = (uInt)-1;
|
||||
uLong len, left;
|
||||
Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
|
||||
const unsigned int max = (unsigned int)-1;
|
||||
z_uintmax_t len, left;
|
||||
unsigned char buf[1]; /* for detection of incomplete stream when *destLen == 0 */
|
||||
|
||||
len = *sourceLen;
|
||||
if (*destLen) {
|
||||
left = *destLen;
|
||||
*destLen = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
left = 1;
|
||||
dest = buf;
|
||||
}
|
||||
|
||||
stream.next_in = (z_const Bytef *)source;
|
||||
stream.next_in = (z_const unsigned char *)source;
|
||||
stream.avail_in = 0;
|
||||
stream.zalloc = (alloc_func)0;
|
||||
stream.zfree = (free_func)0;
|
||||
stream.opaque = (voidpf)0;
|
||||
stream.zalloc = NULL;
|
||||
stream.zfree = NULL;
|
||||
stream.opaque = NULL;
|
||||
|
||||
err = inflateInit(&stream);
|
||||
err = PREFIX(inflateInit)(&stream);
|
||||
if (err != Z_OK) return err;
|
||||
|
||||
stream.next_out = dest;
|
||||
@@ -56,30 +52,29 @@ int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||
|
||||
do {
|
||||
if (stream.avail_out == 0) {
|
||||
stream.avail_out = left > (uLong)max ? max : (uInt)left;
|
||||
stream.avail_out = left > (unsigned long)max ? max : (unsigned int)left;
|
||||
left -= stream.avail_out;
|
||||
}
|
||||
if (stream.avail_in == 0) {
|
||||
stream.avail_in = len > (uLong)max ? max : (uInt)len;
|
||||
stream.avail_in = len > (unsigned long)max ? max : (unsigned int)len;
|
||||
len -= stream.avail_in;
|
||||
}
|
||||
err = inflate(&stream, Z_NO_FLUSH);
|
||||
err = PREFIX(inflate)(&stream, Z_NO_FLUSH);
|
||||
} while (err == Z_OK);
|
||||
|
||||
*sourceLen -= len + stream.avail_in;
|
||||
if (dest != buf)
|
||||
*destLen = stream.total_out;
|
||||
*destLen = (z_size_t)stream.total_out;
|
||||
else if (stream.total_out && err == Z_BUF_ERROR)
|
||||
left = 1;
|
||||
|
||||
inflateEnd(&stream);
|
||||
PREFIX(inflateEnd)(&stream);
|
||||
return err == Z_STREAM_END ? Z_OK :
|
||||
err == Z_NEED_DICT ? Z_DATA_ERROR :
|
||||
err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
|
||||
err;
|
||||
}
|
||||
|
||||
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
|
||||
uLong sourceLen) {
|
||||
return uncompress2(dest, destLen, source, &sourceLen);
|
||||
int Z_EXPORT PREFIX(uncompress)(unsigned char *dest, z_uintmax_t *destLen, const unsigned char *source, z_uintmax_t sourceLen) {
|
||||
return PREFIX(uncompress2)(dest, destLen, source, &sourceLen);
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
# Makefile for zlib using Microsoft (Visual) C
|
||||
# zlib is copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
#
|
||||
# Usage:
|
||||
# nmake -f win32/Makefile.a64 (standard build)
|
||||
# nmake -f win32/Makefile.a64 LOC=-DFOO (nonstandard build)
|
||||
|
||||
# The toplevel directory of the source tree.
|
||||
#
|
||||
TOP = .
|
||||
|
||||
# optional build flags
|
||||
LOC =
|
||||
|
||||
# variables
|
||||
STATICLIB = zlib.lib
|
||||
SHAREDLIB = zlib1.dll
|
||||
IMPLIB = zdll.lib
|
||||
SYMBOL_PREFIX =
|
||||
|
||||
CC = cl
|
||||
LD = link
|
||||
AR = lib
|
||||
RC = rc
|
||||
CP = copy /y
|
||||
INCLUDES = -I$(TOP) -I$(TOP)/arch/arm -I$(TOP)/arch/generic
|
||||
CFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC) $(INCLUDES)
|
||||
WFLAGS = \
|
||||
-D_ARM64_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1 \
|
||||
-D_CRT_SECURE_NO_DEPRECATE \
|
||||
-D_CRT_NONSTDC_NO_DEPRECATE \
|
||||
-DARM_FEATURES \
|
||||
-DARM_NEON_HASLD4 \
|
||||
#
|
||||
LDFLAGS = -nologo -debug -incremental:no -opt:ref -manifest
|
||||
ARFLAGS = -nologo
|
||||
RCFLAGS = /dARM64 /r
|
||||
DEFFILE = zlib.def
|
||||
RCFILE = zlib1.rc
|
||||
RESFILE = zlib1.res
|
||||
WITH_GZFILEOP = yes
|
||||
ZLIB_COMPAT =
|
||||
SUFFIX =
|
||||
|
||||
OBJS = \
|
||||
adler32.obj \
|
||||
adler32_c.obj \
|
||||
adler32_fold_c.obj \
|
||||
arm_features.obj \
|
||||
chunkset_c.obj \
|
||||
compare256_c.obj \
|
||||
compress.obj \
|
||||
cpu_features.obj \
|
||||
crc32.obj \
|
||||
crc32_braid_c.obj \
|
||||
crc32_braid_comb.obj \
|
||||
crc32_c.obj \
|
||||
crc32_chorba_c.obj \
|
||||
crc32_fold_c.obj \
|
||||
deflate.obj \
|
||||
deflate_fast.obj \
|
||||
deflate_huff.obj \
|
||||
deflate_medium.obj \
|
||||
deflate_quick.obj \
|
||||
deflate_rle.obj \
|
||||
deflate_slow.obj \
|
||||
deflate_stored.obj \
|
||||
functable.obj \
|
||||
infback.obj \
|
||||
inflate.obj \
|
||||
inftrees.obj \
|
||||
insert_string.obj \
|
||||
insert_string_roll.obj \
|
||||
slide_hash_c.obj \
|
||||
trees.obj \
|
||||
uncompr.obj \
|
||||
zutil.obj \
|
||||
#
|
||||
!if "$(ZLIB_COMPAT)" != ""
|
||||
WITH_GZFILEOP = yes
|
||||
WFLAGS = $(WFLAGS) -DZLIB_COMPAT
|
||||
DEFFILE = zlibcompat.def
|
||||
!else
|
||||
STATICLIB = zlib-ng.lib
|
||||
SHAREDLIB = zlib-ng1.dll
|
||||
IMPLIB = zngdll.lib
|
||||
DEFFILE = zlib-ng.def
|
||||
RCFILE = zlib-ng1.rc
|
||||
RESFILE = zlib-ng1.res
|
||||
SUFFIX = -ng
|
||||
!endif
|
||||
|
||||
!if "$(WITH_GZFILEOP)" != ""
|
||||
WFLAGS = $(WFLAGS) -DWITH_GZFILEOP
|
||||
OBJS = $(OBJS) gzlib.obj gzread.obj gzwrite.obj
|
||||
!endif
|
||||
|
||||
WFLAGS = $(WFLAGS) \
|
||||
-DARM_CRC32 \
|
||||
-D__ARM_NEON__=1 \
|
||||
-DARM_NEON \
|
||||
-DARM_NOCHECK_NEON \
|
||||
#
|
||||
OBJS = $(OBJS) crc32_armv8.obj adler32_neon.obj chunkset_neon.obj compare256_neon.obj slide_hash_neon.obj
|
||||
|
||||
# targets
|
||||
all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) \
|
||||
example.exe minigzip.exe example_d.exe minigzip_d.exe
|
||||
|
||||
!if "$(SYMBOL_PREFIX)" != ""
|
||||
zlib_name_mangling$(SUFFIX).h: zlib_name_mangling$(SUFFIX).h.in
|
||||
cscript $(TOP)\win32\replace.vbs $(TOP)\zlib_name_mangling$(SUFFIX).h.in zlib_name_mangling$(SUFFIX).h "@ZLIB_SYMBOL_PREFIX@" "$(SYMBOL_PREFIX)"
|
||||
!else
|
||||
zlib_name_mangling$(SUFFIX).h: zlib_name_mangling.h.empty
|
||||
$(CP) $(TOP)\zlib_name_mangling.h.empty zlib_name_mangling$(SUFFIX).h
|
||||
!endif
|
||||
|
||||
zlib$(SUFFIX).h: zlib$(SUFFIX).h.in
|
||||
cscript $(TOP)\win32\replace.vbs $(TOP)\zlib$(SUFFIX).h.in zlib$(SUFFIX).h "@ZLIB_SYMBOL_PREFIX@" "$(SYMBOL_PREFIX)"
|
||||
|
||||
gzread.c: gzread.c.in
|
||||
cscript $(TOP)\win32\replace.vbs $(TOP)\gzread.c.in gzread.c "@ZLIB_SYMBOL_PREFIX@" "$(SYMBOL_PREFIX)"
|
||||
|
||||
zconf: $(TOP)/zconf$(SUFFIX).h.in $(TOP)/zlib$(SUFFIX).h $(TOP)/zlib_name_mangling$(SUFFIX).h
|
||||
$(CP) $(TOP)\zconf$(SUFFIX).h.in $(TOP)\zconf$(SUFFIX).h
|
||||
|
||||
$(TOP)/win32/$(DEFFILE): $(TOP)/win32/$(DEFFILE).in
|
||||
cscript $(TOP)\win32\replace.vbs $(TOP)/win32/$(DEFFILE).in $(TOP)/win32/$(DEFFILE) "@ZLIB_SYMBOL_PREFIX@" "$(SYMBOL_PREFIX)"
|
||||
|
||||
$(STATICLIB): zconf $(OBJS)
|
||||
$(AR) $(ARFLAGS) -out:$@ $(OBJS)
|
||||
|
||||
$(IMPLIB): $(SHAREDLIB)
|
||||
|
||||
$(SHAREDLIB): zconf $(TOP)/win32/$(DEFFILE) $(OBJS) $(RESFILE)
|
||||
$(LD) $(LDFLAGS) -def:$(TOP)/win32/$(DEFFILE) -dll -implib:$(IMPLIB) \
|
||||
-out:$@ -base:0x55A4C0000 $(OBJS) $(RESFILE)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;2
|
||||
|
||||
example.exe: example.obj gzlib2.obj gzread2.obj gzwrite2.obj $(STATICLIB)
|
||||
$(LD) $(LDFLAGS) example.obj gzlib2.obj gzread2.obj gzwrite2.obj $(STATICLIB)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
minigzip.exe: minigzip.obj gzlib2.obj gzread2.obj gzwrite2.obj $(STATICLIB)
|
||||
$(LD) $(LDFLAGS) minigzip.obj gzlib2.obj gzread2.obj gzwrite2.obj $(STATICLIB)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
example_d.exe: example.obj gzlib2.obj gzread2.obj gzwrite2.obj $(IMPLIB)
|
||||
$(LD) $(LDFLAGS) -out:$@ example.obj gzlib2.obj gzread2.obj gzwrite2.obj $(IMPLIB)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
minigzip_d.exe: minigzip.obj gzlib2.obj gzread2.obj gzwrite2.obj $(IMPLIB)
|
||||
$(LD) $(LDFLAGS) -out:$@ minigzip.obj gzlib2.obj gzread2.obj gzwrite2.obj $(IMPLIB)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
{$(TOP)}.c.obj:
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) $<
|
||||
|
||||
gzlib2.obj: gzlib.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) -DWITH_GZFILEOP -Fogzlib2.obj gzlib.c
|
||||
|
||||
gzread2.obj: gzread.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) -DWITH_GZFILEOP -Fogzread2.obj gzread.c
|
||||
|
||||
gzwrite2.obj: gzwrite.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) -DWITH_GZFILEOP -Fogzwrite2.obj gzwrite.c
|
||||
|
||||
{$(TOP)/arch/arm}.c.obj:
|
||||
$(CC) -c -I$(TOP) $(WFLAGS) $(CFLAGS) $<
|
||||
|
||||
{$(TOP)/arch/generic}.c.obj:
|
||||
$(CC) -c -I$(TOP) $(WFLAGS) $(CFLAGS) $<
|
||||
|
||||
{$(TOP)/test}.c.obj:
|
||||
$(CC) -c -I$(TOP) $(WFLAGS) $(CFLAGS) -DWITH_GZFILEOP $<
|
||||
|
||||
$(TOP)/zconf$(SUFFIX).h: zconf
|
||||
|
||||
adler32.obj: $(TOP)/adler32.c $(TOP)/zbuild.h $(TOP)/functable.h $(TOP)/adler32_p.h
|
||||
adler32_c.obj: $(TOP)/arch/generic/adler32_c.c $(TOP)/zbuild.h $(TOP)/functable.h $(TOP)/adler32_p.h
|
||||
adler32_fold_c.obj: $(TOP)/arch/generic/adler32_fold_c.c $(TOP)/zbuild.h $(TOP)/functable.h
|
||||
chunkset_c.obj: $(TOP)/arch/generic/chunkset_c.c $(TOP)/zbuild.h $(TOP)/chunkset_tpl.h $(TOP)/inffast_tpl.h
|
||||
compare256_c.obj: $(TOP)/arch/generic/compare256_c.c $(TOP)/zbuild.h $(TOP)/zmemory.h $(TOP)/deflate.h $(TOP)/fallback_builtins.h $(TOP)/match_tpl.h
|
||||
compress.obj: $(TOP)/compress.c $(TOP)/zbuild.h $(TOP)/zutil.h
|
||||
cpu_features.obj: $(TOP)/cpu_features.c $(TOP)/cpu_features.h $(TOP)/zbuild.h
|
||||
crc32.obj: $(TOP)/crc32.c $(TOP)/zbuild.h $(TOP)/functable.h $(TOP)/crc32_braid_tbl.h
|
||||
crc32_braid_c.obj: $(TOP)/arch/generic/crc32_braid_c.c $(TOP)/zbuild.h $(TOP)/crc32_braid_p.h $(TOP)/crc32_braid_tbl.h
|
||||
crc32_braid_comb.obj: $(TOP)/crc32_braid_comb.c $(TOP)/zutil.h $(TOP)/crc32_braid_p.h $(TOP)/crc32_braid_tbl.h $(TOP)/crc32_braid_comb_p.h
|
||||
crc32_c.obj: $(TOP)/arch/generic/crc32_c.c $(TOP)/zbuild.h $(TOP)/crc32_braid_p.h
|
||||
crc32_chorba_c.obj: $(TOP)/arch/generic/crc32_chorba_c.c $(TOP)/zbuild.h $(TOP)/crc32_braid_p.h $(TOP)/crc32_braid_tbl.h
|
||||
crc32_fold_c.obj: $(TOP)/arch/generic/crc32_fold_c.c $(TOP)/zbuild.h $(TOP)/crc32.h $(TOP)/functable.h $(TOP)/zutil.h
|
||||
deflate.obj: $(TOP)/deflate.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_fast.obj: $(TOP)/deflate_fast.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_huff.obj: $(TOP)/deflate_huff.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_medium.obj: $(TOP)/deflate_medium.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_quick.obj: $(TOP)/deflate_quick.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h $(TOP)/trees_emit.h $(TOP)/zmemory.h
|
||||
deflate_rle.obj: $(TOP)/deflate_rle.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h $(TOP)/compare256_rle.h
|
||||
deflate_slow.obj: $(TOP)/deflate_slow.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_stored.obj: $(TOP)/deflate_stored.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
functable.obj: $(TOP)/functable.c $(TOP)/zbuild.h $(TOP)/functable.h $(TOP)/cpu_features.h $(TOP)/arch/arm/arm_features.h $(TOP)/arch_functions.h
|
||||
gzlib.obj: $(TOP)/gzlib.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
gzread.obj: $(TOP)/gzread.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
gzwrite.obj: $(TOP)/gzwrite.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
infback.obj: $(TOP)/infback.c $(TOP)/zbuild.h $(TOP)/zutil.h $(TOP)/inftrees.h $(TOP)/inflate.h $(TOP)/inflate_p.h $(TOP)/functable.h
|
||||
inflate.obj: $(TOP)/inflate.c $(TOP)/zbuild.h $(TOP)/zutil.h $(TOP)/inftrees.h $(TOP)/inflate.h $(TOP)/inflate_p.h $(TOP)/functable.h $(TOP)/inffixed_tbl.h
|
||||
inftrees.obj: $(TOP)/inftrees.c $(TOP)/zbuild.h $(TOP)/zutil.h $(TOP)/inftrees.h
|
||||
insert_string.obj: $(TOP)/insert_string.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/insert_string_tpl.h
|
||||
insert_string_roll.obj: $(TOP)/insert_string_roll.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/insert_string_tpl.h
|
||||
slide_hash_c.obj: $(TOP)/arch/generic/slide_hash_c.c $(TOP)/zbuild.h $(TOP)/deflate.h
|
||||
slide_hash_neon.obj: $(TOP)/arch/arm/slide_hash_neon.c $(TOP)/arch/arm/neon_intrins.h $(TOP)/zbuild.h $(TOP)/deflate.h
|
||||
trees.obj: $(TOP)/trees.c $(TOP)/trees.h $(TOP)/trees_emit.h $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/trees_tbl.h
|
||||
uncompr.obj: $(TOP)/uncompr.c $(TOP)/zbuild.h $(TOP)/zutil.h
|
||||
zutil.obj: $(TOP)/zutil.c $(TOP)/zbuild.h $(TOP)/zutil.h $(TOP)/zutil_p.h
|
||||
|
||||
$(RESFILE): $(TOP)/win32/$(RCFILE)
|
||||
$(RC) $(RCFLAGS) /fo$@ $(TOP)/win32/$(RCFILE)
|
||||
|
||||
# testing
|
||||
test: example.exe minigzip.exe
|
||||
example
|
||||
echo hello world | minigzip | minigzip -d
|
||||
|
||||
testdll: example_d.exe minigzip_d.exe
|
||||
example_d
|
||||
echo hello world | minigzip_d | minigzip_d -d
|
||||
|
||||
example.obj: $(TOP)/test/example.c $(TOP)/zbuild.h $(TOP)/zlib$(SUFFIX).h $(TOP)/deflate.h $(TOP)/test/test_shared_ng.h
|
||||
|
||||
minigzip.obj: $(TOP)/test/minigzip.c $(TOP)/zbuild.h $(TOP)/zlib$(SUFFIX).h
|
||||
|
||||
|
||||
# cleanup
|
||||
clean:
|
||||
-del $(STATICLIB)
|
||||
-del $(SHAREDLIB)
|
||||
-del $(IMPLIB)
|
||||
-del *.obj
|
||||
-del *.res
|
||||
-del *.exp
|
||||
-del *.exe
|
||||
-del *.pdb
|
||||
-del *.manifest
|
||||
|
||||
distclean: clean
|
||||
-del zconf$(SUFFIX).h
|
||||
-del zlib$(SUFFIX).h
|
||||
-del zlib_name_mangling$(SUFFIX).h
|
||||
-del $(TOP)\win32\zlib.def
|
||||
-del $(TOP)\win32\zlibcompat.def
|
||||
-del $(TOP)\win32\zlib-ng.def
|
||||
-del gzread.c
|
||||
@@ -0,0 +1,276 @@
|
||||
# Makefile for zlib using Microsoft (Visual) C
|
||||
# zlib is copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
#
|
||||
# Usage:
|
||||
# nmake -f win32/Makefile.arm (standard build)
|
||||
# nmake -f win32/Makefile.arm LOC=-DFOO (nonstandard build)
|
||||
|
||||
# The toplevel directory of the source tree.
|
||||
#
|
||||
TOP = .
|
||||
|
||||
# optional build flags
|
||||
LOC =
|
||||
|
||||
# variables
|
||||
STATICLIB = zlib.lib
|
||||
SHAREDLIB = zlib1.dll
|
||||
IMPLIB = zdll.lib
|
||||
SYMBOL_PREFIX =
|
||||
|
||||
CC = cl
|
||||
LD = link
|
||||
AR = lib
|
||||
RC = rc
|
||||
CP = copy /y
|
||||
INCLUDES = -I$(TOP) -I$(TOP)/arch/arm -I$(TOP)/arch/generic
|
||||
CFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC) $(INCLUDES)
|
||||
WFLAGS = \
|
||||
-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1 \
|
||||
-D_CRT_SECURE_NO_DEPRECATE \
|
||||
-D_CRT_NONSTDC_NO_DEPRECATE \
|
||||
-DARM_FEATURES \
|
||||
-DARM_NEON_HASLD4 \
|
||||
#
|
||||
LDFLAGS = -nologo -debug -incremental:no -opt:ref -manifest
|
||||
ARFLAGS = -nologo
|
||||
RCFLAGS = /dARM /r
|
||||
DEFFILE = zlib.def
|
||||
RCFILE = zlib1.rc
|
||||
RESFILE = zlib1.res
|
||||
WITH_GZFILEOP = yes
|
||||
ZLIB_COMPAT =
|
||||
WITH_ARMV8 =
|
||||
WITH_NEON =
|
||||
WITH_ARMV6 =
|
||||
WITH_VFPV3 =
|
||||
NEON_ARCH = /arch:VFPv4
|
||||
SUFFIX =
|
||||
|
||||
OBJS = \
|
||||
adler32.obj \
|
||||
adler32_c.obj \
|
||||
adler32_fold_c.obj \
|
||||
arm_features.obj \
|
||||
chunkset_c.obj \
|
||||
compare256_c.obj \
|
||||
compress.obj \
|
||||
cpu_features.obj \
|
||||
crc32.obj \
|
||||
crc32_braid_c.obj \
|
||||
crc32_braid_comb.obj \
|
||||
crc32_c.obj \
|
||||
crc32_chorba_c.obj \
|
||||
crc32_fold_c.obj \
|
||||
deflate.obj \
|
||||
deflate_fast.obj \
|
||||
deflate_huff.obj \
|
||||
deflate_medium.obj \
|
||||
deflate_quick.obj \
|
||||
deflate_rle.obj \
|
||||
deflate_slow.obj \
|
||||
deflate_stored.obj \
|
||||
functable.obj \
|
||||
infback.obj \
|
||||
inflate.obj \
|
||||
inftrees.obj \
|
||||
insert_string.obj \
|
||||
insert_string_roll.obj \
|
||||
slide_hash_c.obj \
|
||||
trees.obj \
|
||||
uncompr.obj \
|
||||
zutil.obj \
|
||||
#
|
||||
!if "$(ZLIB_COMPAT)" != ""
|
||||
WITH_GZFILEOP = yes
|
||||
WFLAGS = $(WFLAGS) -DZLIB_COMPAT
|
||||
DEFFILE = zlibcompat.def
|
||||
!else
|
||||
STATICLIB = zlib-ng.lib
|
||||
SHAREDLIB = zlib-ng1.dll
|
||||
IMPLIB = zngdll.lib
|
||||
DEFFILE = zlib-ng.def
|
||||
RCFILE = zlib-ng1.rc
|
||||
RESFILE = zlib-ng1.res
|
||||
SUFFIX = -ng
|
||||
!endif
|
||||
|
||||
!if "$(WITH_GZFILEOP)" != ""
|
||||
WFLAGS = $(WFLAGS) -DWITH_GZFILEOP
|
||||
OBJS = $(OBJS) gzlib.obj gzread.obj gzwrite.obj
|
||||
!endif
|
||||
|
||||
!if "$(WITH_ARMV8)" != ""
|
||||
WFLAGS = $(WFLAGS) -DARM_CRC32
|
||||
OBJS = $(OBJS) crc32_armv8.obj
|
||||
!endif
|
||||
!if "$(WITH_VFPV3)" != ""
|
||||
NEON_ARCH = /arch:VFPv3
|
||||
!endif
|
||||
!if "$(WITH_NEON)" != ""
|
||||
CFLAGS = $(CFLAGS) $(NEON_ARCH)
|
||||
WFLAGS = $(WFLAGS) \
|
||||
-D__ARM_NEON__=1 \
|
||||
-DARM_NEON \
|
||||
-DARM_NOCHECK_NEON \
|
||||
#
|
||||
OBJS = $(OBJS) adler32_neon.obj chunkset_neon.obj compare256_neon.obj slide_hash_neon.obj
|
||||
!endif
|
||||
!if "$(WITH_ARMV6)" != ""
|
||||
WFLAGS = $(WFLAGS) \
|
||||
-DARM_SIMD \
|
||||
-DARM_NOCHECK_SIMD \
|
||||
#
|
||||
OBJS = $(OBJS) slide_hash_armv6.obj
|
||||
!endif
|
||||
|
||||
# targets
|
||||
all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) \
|
||||
example.exe minigzip.exe example_d.exe minigzip_d.exe
|
||||
|
||||
!if "$(SYMBOL_PREFIX)" != ""
|
||||
zlib_name_mangling$(SUFFIX).h: zlib_name_mangling$(SUFFIX).h.in
|
||||
cscript $(TOP)\win32\replace.vbs $(TOP)\zlib_name_mangling$(SUFFIX).h.in zlib_name_mangling$(SUFFIX).h "@ZLIB_SYMBOL_PREFIX@" "$(SYMBOL_PREFIX)"
|
||||
!else
|
||||
zlib_name_mangling$(SUFFIX).h: zlib_name_mangling.h.empty
|
||||
$(CP) $(TOP)\zlib_name_mangling.h.empty zlib_name_mangling$(SUFFIX).h
|
||||
!endif
|
||||
|
||||
zlib$(SUFFIX).h: zlib$(SUFFIX).h.in
|
||||
cscript $(TOP)\win32\replace.vbs $(TOP)\zlib$(SUFFIX).h.in zlib$(SUFFIX).h "@ZLIB_SYMBOL_PREFIX@" "$(SYMBOL_PREFIX)"
|
||||
|
||||
gzread.c: gzread.c.in
|
||||
cscript $(TOP)\win32\replace.vbs $(TOP)\gzread.c.in gzread.c "@ZLIB_SYMBOL_PREFIX@" "$(SYMBOL_PREFIX)"
|
||||
|
||||
zconf: $(TOP)/zconf$(SUFFIX).h.in $(TOP)/zlib$(SUFFIX).h $(TOP)/zlib_name_mangling$(SUFFIX).h
|
||||
$(CP) $(TOP)\zconf$(SUFFIX).h.in $(TOP)\zconf$(SUFFIX).h
|
||||
|
||||
$(TOP)/win32/$(DEFFILE): $(TOP)/win32/$(DEFFILE).in
|
||||
cscript $(TOP)\win32\replace.vbs $(TOP)/win32/$(DEFFILE).in $(TOP)/win32/$(DEFFILE) "@ZLIB_SYMBOL_PREFIX@" "$(SYMBOL_PREFIX)"
|
||||
|
||||
$(STATICLIB): zconf $(OBJS)
|
||||
$(AR) $(ARFLAGS) -out:$@ $(OBJS)
|
||||
|
||||
$(IMPLIB): $(SHAREDLIB)
|
||||
|
||||
$(SHAREDLIB): zconf $(TOP)/win32/$(DEFFILE) $(OBJS) $(RESFILE)
|
||||
$(LD) $(LDFLAGS) -def:$(TOP)/win32/$(DEFFILE) -dll -implib:$(IMPLIB) \
|
||||
-out:$@ -base:0x5A4C0000 $(OBJS) $(RESFILE)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;2
|
||||
|
||||
example.exe: example.obj gzlib2.obj gzread2.obj gzwrite2.obj $(STATICLIB)
|
||||
$(LD) $(LDFLAGS) example.obj gzlib2.obj gzread2.obj gzwrite2.obj $(STATICLIB)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
minigzip.exe: minigzip.obj gzlib2.obj gzread2.obj gzwrite2.obj $(STATICLIB)
|
||||
$(LD) $(LDFLAGS) minigzip.obj gzlib2.obj gzread2.obj gzwrite2.obj $(STATICLIB)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
example_d.exe: example.obj gzlib2.obj gzread2.obj gzwrite2.obj $(IMPLIB)
|
||||
$(LD) $(LDFLAGS) -out:$@ example.obj gzlib2.obj gzread2.obj gzwrite2.obj $(IMPLIB)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
minigzip_d.exe: minigzip.obj gzlib2.obj gzread2.obj gzwrite2.obj $(IMPLIB)
|
||||
$(LD) $(LDFLAGS) -out:$@ minigzip.obj gzlib2.obj gzread2.obj gzwrite2.obj $(IMPLIB)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
{$(TOP)}.c.obj:
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) $<
|
||||
|
||||
gzlib2.obj: gzlib.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) -DWITH_GZFILEOP -Fogzlib2.obj gzlib.c
|
||||
|
||||
gzread2.obj: gzread.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) -DWITH_GZFILEOP -Fogzread2.obj gzread.c
|
||||
|
||||
gzwrite2.obj: gzwrite.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) -DWITH_GZFILEOP -Fogzwrite2.obj gzwrite.c
|
||||
|
||||
{$(TOP)/arch/arm}.c.obj:
|
||||
$(CC) -c -I$(TOP) $(WFLAGS) $(CFLAGS) $<
|
||||
|
||||
{$(TOP)/arch/generic}.c.obj:
|
||||
$(CC) -c -I$(TOP) $(WFLAGS) $(CFLAGS) $<
|
||||
|
||||
{$(TOP)/test}.c.obj:
|
||||
$(CC) -c -I$(TOP) $(WFLAGS) $(CFLAGS) -DWITH_GZFILEOP $<
|
||||
|
||||
$(TOP)/zconf$(SUFFIX).h: zconf
|
||||
|
||||
adler32.obj: $(TOP)/adler32.c $(TOP)/zbuild.h $(TOP)/functable.h $(TOP)/adler32_p.h
|
||||
adler32_c.obj: $(TOP)/arch/generic/adler32_c.c $(TOP)/zbuild.h $(TOP)/functable.h $(TOP)/adler32_p.h
|
||||
adler32_fold_c.obj: $(TOP)/arch/generic/adler32_fold_c.c $(TOP)/zbuild.h $(TOP)/functable.h
|
||||
chunkset_c.obj: $(TOP)/arch/generic/chunkset_c.c $(TOP)/zbuild.h $(TOP)/chunkset_tpl.h $(TOP)/inffast_tpl.h
|
||||
compare256_c.obj: $(TOP)/arch/generic/compare256_c.c $(TOP)/zbuild.h $(TOP)/zmemory.h $(TOP)/deflate.h $(TOP)/fallback_builtins.h $(TOP)/match_tpl.h
|
||||
compress.obj: $(TOP)/compress.c $(TOP)/zbuild.h $(TOP)/zutil.h
|
||||
cpu_features.obj: $(TOP)/cpu_features.c $(TOP)/cpu_features.h $(TOP)/zbuild.h
|
||||
crc32.obj: $(TOP)/crc32.c $(TOP)/zbuild.h $(TOP)/functable.h $(TOP)/crc32_braid_tbl.h
|
||||
crc32_braid_c.obj: $(TOP)/arch/generic/crc32_braid_c.c $(TOP)/zbuild.h $(TOP)/crc32_braid_p.h $(TOP)/crc32_braid_tbl.h
|
||||
crc32_braid_comb.obj: $(TOP)/crc32_braid_comb.c $(TOP)/zutil.h $(TOP)/crc32_braid_p.h $(TOP)/crc32_braid_tbl.h $(TOP)/crc32_braid_comb_p.h
|
||||
crc32_c.obj: $(TOP)/arch/generic/crc32_c.c $(TOP)/zbuild.h $(TOP)/crc32_braid_p.h
|
||||
crc32_chorba_c.obj: $(TOP)/arch/generic/crc32_chorba_c.c $(TOP)/zbuild.h $(TOP)/crc32_braid_p.h $(TOP)/crc32_braid_tbl.h
|
||||
crc32_fold_c.obj: $(TOP)/arch/generic/crc32_fold_c.c $(TOP)/zbuild.h $(TOP)/crc32.h $(TOP)/functable.h $(TOP)/zutil.h
|
||||
deflate.obj: $(TOP)/deflate.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_fast.obj: $(TOP)/deflate_fast.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_huff.obj: $(TOP)/deflate_huff.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_medium.obj: $(TOP)/deflate_medium.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_quick.obj: $(TOP)/deflate_quick.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h $(TOP)/trees_emit.h $(TOP)/zmemory.h
|
||||
deflate_rle.obj: $(TOP)/deflate_rle.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h $(TOP)/compare256_rle.h
|
||||
deflate_slow.obj: $(TOP)/deflate_slow.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_stored.obj: $(TOP)/deflate_stored.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
functable.obj: $(TOP)/functable.c $(TOP)/zbuild.h $(TOP)/functable.h $(TOP)/cpu_features.h $(TOP)/arch/arm/arm_features.h $(TOP)/arch_functions.h
|
||||
gzlib.obj: $(TOP)/gzlib.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
gzread.obj: $(TOP)/gzread.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
gzwrite.obj: $(TOP)/gzwrite.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
infback.obj: $(TOP)/infback.c $(TOP)/zbuild.h $(TOP)/zutil.h $(TOP)/inftrees.h $(TOP)/inflate.h $(TOP)/inflate_p.h $(TOP)/functable.h
|
||||
inflate.obj: $(TOP)/inflate.c $(TOP)/zbuild.h $(TOP)/zutil.h $(TOP)/inftrees.h $(TOP)/inflate.h $(TOP)/inflate_p.h $(TOP)/functable.h $(TOP)/inffixed_tbl.h
|
||||
inftrees.obj: $(TOP)/inftrees.c $(TOP)/zbuild.h $(TOP)/zutil.h $(TOP)/inftrees.h
|
||||
insert_string.obj: $(TOP)/insert_string.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/insert_string_tpl.h
|
||||
insert_string_roll.obj: $(TOP)/insert_string_roll.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/insert_string_tpl.h
|
||||
slide_hash_c.obj: $(TOP)/arch/generic/slide_hash_c.c $(TOP)/zbuild.h $(TOP)/deflate.h
|
||||
trees.obj: $(TOP)/trees.c $(TOP)/trees.h $(TOP)/trees_emit.h $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/trees_tbl.h
|
||||
uncompr.obj: $(TOP)/uncompr.c $(TOP)/zbuild.h $(TOP)/zutil.h
|
||||
zutil.obj: $(TOP)/zutil.c $(TOP)/zbuild.h $(TOP)/zutil.h $(TOP)/zutil_p.h
|
||||
|
||||
$(RESFILE): $(TOP)/win32/$(RCFILE)
|
||||
$(RC) $(RCFLAGS) /fo$@ $(TOP)/win32/$(RCFILE)
|
||||
|
||||
# testing
|
||||
test: example.exe minigzip.exe
|
||||
example
|
||||
echo hello world | minigzip | minigzip -d
|
||||
|
||||
testdll: example_d.exe minigzip_d.exe
|
||||
example_d
|
||||
echo hello world | minigzip_d | minigzip_d -d
|
||||
|
||||
example.obj: $(TOP)/test/example.c $(TOP)/zbuild.h $(TOP)/zlib$(SUFFIX).h $(TOP)/deflate.h $(TOP)/test/test_shared_ng.h
|
||||
|
||||
minigzip.obj: $(TOP)/test/minigzip.c $(TOP)/zbuild.h $(TOP)/zlib$(SUFFIX).h
|
||||
|
||||
|
||||
# cleanup
|
||||
clean:
|
||||
-del $(STATICLIB)
|
||||
-del $(SHAREDLIB)
|
||||
-del $(IMPLIB)
|
||||
-del *.obj
|
||||
-del *.res
|
||||
-del *.exp
|
||||
-del *.exe
|
||||
-del *.pdb
|
||||
-del *.manifest
|
||||
|
||||
distclean: clean
|
||||
-del zconf$(SUFFIX).h
|
||||
-del zlib$(SUFFIX).h
|
||||
-del zlib_name_mangling$(SUFFIX).h
|
||||
-del $(TOP)\win32\zlib.def
|
||||
-del $(TOP)\win32\zlibcompat.def
|
||||
-del $(TOP)\win32\zlib-ng.def
|
||||
-del gzread.c
|
||||
+216
-79
@@ -1,5 +1,5 @@
|
||||
# Makefile for zlib using Microsoft (Visual) C
|
||||
# zlib is copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
|
||||
# zlib is copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
#
|
||||
# Usage:
|
||||
# nmake -f win32/Makefile.msc (standard build)
|
||||
@@ -16,127 +16,250 @@ LOC =
|
||||
STATICLIB = zlib.lib
|
||||
SHAREDLIB = zlib1.dll
|
||||
IMPLIB = zdll.lib
|
||||
SYMBOL_PREFIX =
|
||||
|
||||
CC = cl
|
||||
AS = ml
|
||||
CXX = cl
|
||||
LD = link
|
||||
AR = lib
|
||||
RC = rc
|
||||
CFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC)
|
||||
WFLAGS = -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE
|
||||
ASFLAGS = -coff -Zi $(LOC)
|
||||
LDFLAGS = -nologo -debug -incremental:no -opt:ref
|
||||
CP = copy /y
|
||||
INCLUDES = -I$(TOP) -I$(TOP)/arch/x86 -I$(TOP)/arch/generic
|
||||
CFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC) $(INCLUDES)
|
||||
CXXFLAGS = -nologo -EHsc -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC) $(INCLUDES)
|
||||
WFLAGS = \
|
||||
-D_CRT_SECURE_NO_DEPRECATE \
|
||||
-D_CRT_NONSTDC_NO_DEPRECATE \
|
||||
-DX86_FEATURES \
|
||||
-DX86_PCLMULQDQ_CRC \
|
||||
-DX86_SSE2 \
|
||||
-DX86_SSE42 \
|
||||
-DX86_SSSE3 \
|
||||
-DX86_AVX2
|
||||
|
||||
LDFLAGS = -nologo -debug -incremental:no -opt:ref -manifest
|
||||
ARFLAGS = -nologo
|
||||
RCFLAGS = /dWIN32 /r
|
||||
DEFFILE = zlib.def
|
||||
RCFILE = zlib1.rc
|
||||
RESFILE = zlib1.res
|
||||
WITH_GZFILEOP = yes
|
||||
ZLIB_COMPAT =
|
||||
SUFFIX =
|
||||
|
||||
OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj \
|
||||
gzwrite.obj infback.obj inflate.obj inftrees.obj inffast.obj trees.obj uncompr.obj zutil.obj
|
||||
OBJA =
|
||||
OBJS = \
|
||||
adler32.obj \
|
||||
adler32_c.obj \
|
||||
adler32_avx2.obj \
|
||||
adler32_avx512.obj \
|
||||
adler32_avx512_vnni.obj \
|
||||
adler32_sse42.obj \
|
||||
adler32_ssse3.obj \
|
||||
adler32_fold_c.obj \
|
||||
chunkset_c.obj \
|
||||
chunkset_avx2.obj \
|
||||
chunkset_sse2.obj \
|
||||
chunkset_ssse3.obj \
|
||||
compare256_c.obj \
|
||||
compare256_avx2.obj \
|
||||
compare256_sse2.obj \
|
||||
compress.obj \
|
||||
cpu_features.obj \
|
||||
crc32.obj \
|
||||
crc32_braid_c.obj \
|
||||
crc32_braid_comb.obj \
|
||||
crc32_c.obj \
|
||||
crc32_chorba_c.obj \
|
||||
crc32_fold_c.obj \
|
||||
crc32_pclmulqdq.obj \
|
||||
deflate.obj \
|
||||
deflate_fast.obj \
|
||||
deflate_huff.obj \
|
||||
deflate_medium.obj \
|
||||
deflate_quick.obj \
|
||||
deflate_rle.obj \
|
||||
deflate_slow.obj \
|
||||
deflate_stored.obj \
|
||||
functable.obj \
|
||||
infback.obj \
|
||||
inflate.obj \
|
||||
inftrees.obj \
|
||||
insert_string.obj \
|
||||
insert_string_roll.obj \
|
||||
slide_hash_c.obj \
|
||||
slide_hash_avx2.obj \
|
||||
slide_hash_sse2.obj \
|
||||
trees.obj \
|
||||
uncompr.obj \
|
||||
zutil.obj \
|
||||
x86_features.obj \
|
||||
#
|
||||
!if "$(ZLIB_COMPAT)" != ""
|
||||
WITH_GZFILEOP = yes
|
||||
WFLAGS = $(WFLAGS) -DZLIB_COMPAT
|
||||
DEFFILE = zlibcompat.def
|
||||
!else
|
||||
STATICLIB = zlib-ng.lib
|
||||
SHAREDLIB = zlib-ng1.dll
|
||||
IMPLIB = zngdll.lib
|
||||
DEFFILE = zlib-ng.def
|
||||
RCFILE = zlib-ng1.rc
|
||||
RESFILE = zlib-ng1.res
|
||||
SUFFIX = -ng
|
||||
!endif
|
||||
|
||||
!if "$(WITH_GZFILEOP)" != ""
|
||||
WFLAGS = $(WFLAGS) -DWITH_GZFILEOP
|
||||
OBJS = $(OBJS) gzlib.obj gzread.obj gzwrite.obj
|
||||
!endif
|
||||
|
||||
# targets
|
||||
all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) \
|
||||
example.exe minigzip.exe example_d.exe minigzip_d.exe
|
||||
|
||||
$(STATICLIB): $(OBJS) $(OBJA)
|
||||
$(AR) $(ARFLAGS) -out:$@ $(OBJS) $(OBJA)
|
||||
!if "$(SYMBOL_PREFIX)" != ""
|
||||
zlib_name_mangling$(SUFFIX).h: zlib_name_mangling$(SUFFIX).h.in
|
||||
cscript $(TOP)\win32\replace.vbs $(TOP)\zlib_name_mangling$(SUFFIX).h.in zlib_name_mangling$(SUFFIX).h "@ZLIB_SYMBOL_PREFIX@" "$(SYMBOL_PREFIX)"
|
||||
!else
|
||||
zlib_name_mangling$(SUFFIX).h: zlib_name_mangling.h.empty
|
||||
$(CP) $(TOP)\zlib_name_mangling.h.empty zlib_name_mangling$(SUFFIX).h
|
||||
!endif
|
||||
|
||||
zlib$(SUFFIX).h: zlib$(SUFFIX).h.in
|
||||
cscript $(TOP)\win32\replace.vbs $(TOP)\zlib$(SUFFIX).h.in zlib$(SUFFIX).h "@ZLIB_SYMBOL_PREFIX@" "$(SYMBOL_PREFIX)"
|
||||
|
||||
gzread.c: gzread.c.in
|
||||
cscript $(TOP)\win32\replace.vbs $(TOP)\gzread.c.in gzread.c "@ZLIB_SYMBOL_PREFIX@" "$(SYMBOL_PREFIX)"
|
||||
|
||||
zconf: $(TOP)/zconf$(SUFFIX).h.in $(TOP)/zlib$(SUFFIX).h $(TOP)/zlib_name_mangling$(SUFFIX).h
|
||||
$(CP) $(TOP)\zconf$(SUFFIX).h.in $(TOP)\zconf$(SUFFIX).h
|
||||
|
||||
$(TOP)/win32/$(DEFFILE): $(TOP)/win32/$(DEFFILE).in
|
||||
cscript $(TOP)\win32\replace.vbs $(TOP)/win32/$(DEFFILE).in $(TOP)/win32/$(DEFFILE) "@ZLIB_SYMBOL_PREFIX@" "$(SYMBOL_PREFIX)"
|
||||
|
||||
$(STATICLIB): zconf $(OBJS)
|
||||
$(AR) $(ARFLAGS) -out:$@ $(OBJS)
|
||||
|
||||
$(IMPLIB): $(SHAREDLIB)
|
||||
|
||||
$(SHAREDLIB): $(TOP)/win32/zlib.def $(OBJS) $(OBJA) zlib1.res
|
||||
$(LD) $(LDFLAGS) -def:$(TOP)/win32/zlib.def -dll -implib:$(IMPLIB) \
|
||||
-out:$@ -base:0x5A4C0000 $(OBJS) $(OBJA) zlib1.res
|
||||
$(SHAREDLIB): zconf $(TOP)/win32/$(DEFFILE) $(OBJS) $(RESFILE)
|
||||
$(LD) $(LDFLAGS) -def:$(TOP)/win32/$(DEFFILE) -dll -implib:$(IMPLIB) \
|
||||
-out:$@ $(OBJS) $(RESFILE)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;2
|
||||
|
||||
example.exe: example.obj $(STATICLIB)
|
||||
$(LD) $(LDFLAGS) example.obj $(STATICLIB)
|
||||
depcheck.exe: depcheck.obj
|
||||
$(LD) $(LDFLAGS) depcheck.obj
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
minigzip.exe: minigzip.obj $(STATICLIB)
|
||||
$(LD) $(LDFLAGS) minigzip.obj $(STATICLIB)
|
||||
example.exe: example.obj gzlib2.obj gzread2.obj gzwrite2.obj $(STATICLIB)
|
||||
$(LD) $(LDFLAGS) example.obj gzlib2.obj gzread2.obj gzwrite2.obj $(STATICLIB)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
example_d.exe: example.obj $(IMPLIB)
|
||||
$(LD) $(LDFLAGS) -out:$@ example.obj $(IMPLIB)
|
||||
minigzip.exe: minigzip.obj gzlib2.obj gzread2.obj gzwrite2.obj $(STATICLIB)
|
||||
$(LD) $(LDFLAGS) minigzip.obj gzlib2.obj gzread2.obj gzwrite2.obj $(STATICLIB)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
minigzip_d.exe: minigzip.obj $(IMPLIB)
|
||||
$(LD) $(LDFLAGS) -out:$@ minigzip.obj $(IMPLIB)
|
||||
example_d.exe: example.obj gzlib2.obj gzread2.obj gzwrite2.obj $(IMPLIB)
|
||||
$(LD) $(LDFLAGS) -out:$@ example.obj gzlib2.obj gzread2.obj gzwrite2.obj $(IMPLIB)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
minigzip_d.exe: minigzip.obj gzlib2.obj gzread2.obj gzwrite2.obj $(IMPLIB)
|
||||
$(LD) $(LDFLAGS) -out:$@ minigzip.obj gzlib2.obj gzread2.obj gzwrite2.obj $(IMPLIB)
|
||||
if exist $@.manifest \
|
||||
mt -nologo -manifest $@.manifest -outputresource:$@;1
|
||||
|
||||
{$(TOP)}.c.obj:
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) $<
|
||||
|
||||
{$(TOP)/test}.c.obj:
|
||||
gzlib2.obj: gzlib.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) -DWITH_GZFILEOP -Fogzlib2.obj gzlib.c
|
||||
|
||||
gzread2.obj: gzread.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) -DWITH_GZFILEOP -Fogzread2.obj gzread.c
|
||||
|
||||
gzwrite2.obj: gzwrite.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) -DWITH_GZFILEOP -Fogzwrite2.obj gzwrite.c
|
||||
|
||||
{$(TOP)/arch/x86}.c.obj:
|
||||
$(CC) -c -I$(TOP) $(WFLAGS) $(CFLAGS) $<
|
||||
|
||||
{$(TOP)/contrib/masmx64}.c.obj:
|
||||
$(CC) -c $(WFLAGS) $(CFLAGS) $<
|
||||
{$(TOP)/arch/generic}.c.obj:
|
||||
$(CC) -c -I$(TOP) $(WFLAGS) $(CFLAGS) $<
|
||||
|
||||
{$(TOP)/contrib/masmx64}.asm.obj:
|
||||
$(AS) -c $(ASFLAGS) $<
|
||||
{$(TOP)/test}.c.obj:
|
||||
$(CC) -c -I$(TOP) $(WFLAGS) $(CFLAGS) -DWITH_GZFILEOP $<
|
||||
|
||||
{$(TOP)/contrib/masmx86}.asm.obj:
|
||||
$(AS) -c $(ASFLAGS) $<
|
||||
$(TOP)/zconf$(SUFFIX).h: zconf
|
||||
|
||||
adler32.obj: $(TOP)/adler32.c $(TOP)/zlib.h $(TOP)/zconf.h
|
||||
{$(TOP)/win32}.cpp.obj:
|
||||
$(CXX) -c -I$(TOP) $(WFLAGS) $(CXXFLAGS) $<
|
||||
|
||||
compress.obj: $(TOP)/compress.c $(TOP)/zlib.h $(TOP)/zconf.h
|
||||
adler32.obj: $(TOP)/adler32.c $(TOP)/zbuild.h $(TOP)/functable.h $(TOP)/adler32_p.h
|
||||
adler32_c.obj: $(TOP)/arch/generic/adler32_c.c $(TOP)/zbuild.h $(TOP)/functable.h $(TOP)/adler32_p.h
|
||||
adler32_avx2.obj: $(TOP)/arch/x86/adler32_avx2.c $(TOP)/zbuild.h $(TOP)/adler32_p.h $(TOP)/arch/x86/adler32_avx2_p.h $(TOP)/arch/x86/x86_intrins.h
|
||||
adler32_avx512.obj: $(TOP)/arch/x86/adler32_avx512.c $(TOP)/zbuild.h $(TOP)/arch_functions.h $(TOP)/adler32_p.h $(TOP)/arch/x86/adler32_avx512_p.h $(TOP)/arch/x86/x86_intrins.h
|
||||
adler32_avx512_vnni.obj: $(TOP)/arch/x86/adler32_avx512_vnni.c $(TOP)/zbuild.h $(TOP)/arch_functions.h $(TOP)/adler32_p.h $(TOP)/arch/x86/adler32_avx512_p.h \
|
||||
$(TOP)/arch/x86/adler32_avx2_p.h $(TOP)/arch/x86/x86_intrins.h
|
||||
adler32_sse42.obj: $(TOP)/arch/x86/adler32_sse42.c $(TOP)/zbuild.h $(TOP)/adler32_p.h \
|
||||
$(TOP)/arch/x86/adler32_ssse3_p.h
|
||||
adler32_ssse3.obj: $(TOP)/arch/x86/adler32_ssse3.c $(TOP)/zbuild.h $(TOP)/adler32_p.h \
|
||||
$(TOP)/arch/x86/adler32_ssse3_p.h
|
||||
adler32_fold_c.obj: $(TOP)/arch/generic/adler32_fold_c.c $(TOP)/zbuild.h $(TOP)/functable.h
|
||||
chunkset_c.obj: $(TOP)/arch/generic/chunkset_c.c $(TOP)/zbuild.h $(TOP)/chunkset_tpl.h $(TOP)/inffast_tpl.h
|
||||
chunkset_avx2.obj: $(TOP)/arch/x86/chunkset_avx2.c $(TOP)/zbuild.h $(TOP)/chunkset_tpl.h $(TOP)/inffast_tpl.h $(TOP)/arch/generic/chunk_permute_table.h
|
||||
chunkset_sse2.obj: $(TOP)/arch/x86/chunkset_sse2.c $(TOP)/zbuild.h $(TOP)/chunkset_tpl.h $(TOP)/inffast_tpl.h
|
||||
chunkset_ssse3.obj: $(TOP)/arch/x86/chunkset_ssse3.c $(TOP)/zbuild.h $(TOP)/chunkset_tpl.h $(TOP)/inffast_tpl.h $(TOP)/arch/generic/chunk_permute_table.h
|
||||
compare256_c.obj: $(TOP)/arch/generic/compare256_c.c $(TOP)/zbuild.h $(TOP)/zmemory.h $(TOP)/deflate.h $(TOP)/fallback_builtins.h $(TOP)/match_tpl.h
|
||||
compare256_avx2.obj: $(TOP)/arch/x86/compare256_avx2.c $(TOP)/zbuild.h $(TOP)/zmemory.h $(TOP)/deflate.h $(TOP)/fallback_builtins.h $(TOP)/match_tpl.h
|
||||
compare256_sse2.obj: $(TOP)/arch/x86/compare256_sse2.c $(TOP)/zbuild.h $(TOP)/zmemory.h $(TOP)/deflate.h $(TOP)/fallback_builtins.h $(TOP)/match_tpl.h
|
||||
compress.obj: $(TOP)/compress.c $(TOP)/zbuild.h $(TOP)/zutil.h
|
||||
cpu_features.obj: $(TOP)/cpu_features.c $(TOP)/cpu_features.h $(TOP)/zbuild.h
|
||||
crc32.obj: $(TOP)/crc32.c $(TOP)/zbuild.h $(TOP)/functable.h $(TOP)/crc32_braid_tbl.h
|
||||
crc32_braid_c.obj: $(TOP)/arch/generic/crc32_braid_c.c $(TOP)/zbuild.h $(TOP)/crc32_braid_p.h $(TOP)/crc32_braid_tbl.h
|
||||
crc32_braid_comb.obj: $(TOP)/crc32_braid_comb.c $(TOP)/zutil.h $(TOP)/crc32_braid_p.h $(TOP)/crc32_braid_tbl.h $(TOP)/crc32_braid_comb_p.h
|
||||
crc32_c.obj: $(TOP)/arch/generic/crc32_c.c $(TOP)/zbuild.h $(TOP)/crc32_braid_p.h
|
||||
crc32_chorba_c.obj: $(TOP)/arch/generic/crc32_chorba_c.c $(TOP)/zbuild.h $(TOP)/crc32_braid_p.h $(TOP)/crc32_braid_tbl.h
|
||||
crc32_fold_c.obj: $(TOP)/arch/generic/crc32_fold_c.c $(TOP)/zbuild.h $(TOP)/crc32.h $(TOP)/functable.h $(TOP)/zutil.h
|
||||
crc32_pclmulqdq.obj: $(TOP)/arch/x86/crc32_pclmulqdq.c $(TOP)/arch/x86/crc32_pclmulqdq_tpl.h
|
||||
deflate.obj: $(TOP)/deflate.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_fast.obj: $(TOP)/deflate_fast.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_huff.obj: $(TOP)/deflate_huff.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_medium.obj: $(TOP)/deflate_medium.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_quick.obj: $(TOP)/deflate_quick.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h $(TOP)/trees_emit.h $(TOP)/zmemory.h
|
||||
deflate_rle.obj: $(TOP)/deflate_rle.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h $(TOP)/compare256_rle.h
|
||||
deflate_slow.obj: $(TOP)/deflate_slow.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
deflate_stored.obj: $(TOP)/deflate_stored.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/deflate_p.h $(TOP)/functable.h
|
||||
functable.obj: $(TOP)/functable.c $(TOP)/zbuild.h $(TOP)/functable.h $(TOP)/cpu_features.h $(TOP)/arch/x86/x86_features.h $(TOP)/arch_functions.h
|
||||
gzlib.obj: $(TOP)/gzlib.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
gzread.obj: $(TOP)/gzread.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
gzwrite.obj: $(TOP)/gzwrite.c $(TOP)/zbuild.h $(TOP)/gzguts.h $(TOP)/zutil_p.h
|
||||
infback.obj: $(TOP)/infback.c $(TOP)/zbuild.h $(TOP)/zutil.h $(TOP)/inftrees.h $(TOP)/inflate.h $(TOP)/inflate_p.h $(TOP)/functable.h
|
||||
inflate.obj: $(TOP)/inflate.c $(TOP)/zbuild.h $(TOP)/zutil.h $(TOP)/inftrees.h $(TOP)/inflate.h $(TOP)/inflate_p.h $(TOP)/functable.h $(TOP)/inffixed_tbl.h
|
||||
inftrees.obj: $(TOP)/inftrees.c $(TOP)/zbuild.h $(TOP)/zutil.h $(TOP)/inftrees.h
|
||||
insert_string.obj: $(TOP)/insert_string.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/insert_string_tpl.h
|
||||
insert_string_roll.obj: $(TOP)/insert_string_roll.c $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/insert_string_tpl.h
|
||||
slide_hash_c.obj: $(TOP)/arch/generic/slide_hash_c.c $(TOP)/zbuild.h $(TOP)/deflate.h
|
||||
slide_hash_avx2.obj: $(TOP)/arch/x86/slide_hash_avx2.c $(TOP)/zbuild.h $(TOP)/deflate.h
|
||||
slide_hash_sse2.obj: $(TOP)/arch/x86/slide_hash_sse2.c $(TOP)/zbuild.h $(TOP)/deflate.h
|
||||
trees.obj: $(TOP)/trees.c $(TOP)/trees.h $(TOP)/trees_emit.h $(TOP)/zbuild.h $(TOP)/deflate.h $(TOP)/trees_tbl.h
|
||||
uncompr.obj: $(TOP)/uncompr.c $(TOP)/zbuild.h $(TOP)/zutil.h
|
||||
zutil.obj: $(TOP)/zutil.c $(TOP)/zbuild.h $(TOP)/zutil.h $(TOP)/zutil_p.h
|
||||
|
||||
crc32.obj: $(TOP)/crc32.c $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/crc32.h
|
||||
|
||||
deflate.obj: $(TOP)/deflate.c $(TOP)/deflate.h $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h
|
||||
|
||||
gzclose.obj: $(TOP)/gzclose.c $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/gzguts.h
|
||||
|
||||
gzlib.obj: $(TOP)/gzlib.c $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/gzguts.h
|
||||
|
||||
gzread.obj: $(TOP)/gzread.c $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/gzguts.h
|
||||
|
||||
gzwrite.obj: $(TOP)/gzwrite.c $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/gzguts.h
|
||||
|
||||
infback.obj: $(TOP)/infback.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/inftrees.h $(TOP)/inflate.h \
|
||||
$(TOP)/inffast.h $(TOP)/inffixed.h
|
||||
|
||||
inffast.obj: $(TOP)/inffast.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/inftrees.h $(TOP)/inflate.h \
|
||||
$(TOP)/inffast.h
|
||||
|
||||
inflate.obj: $(TOP)/inflate.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/inftrees.h $(TOP)/inflate.h \
|
||||
$(TOP)/inffast.h $(TOP)/inffixed.h
|
||||
|
||||
inftrees.obj: $(TOP)/inftrees.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/inftrees.h
|
||||
|
||||
trees.obj: $(TOP)/trees.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/deflate.h $(TOP)/trees.h
|
||||
|
||||
uncompr.obj: $(TOP)/uncompr.c $(TOP)/zlib.h $(TOP)/zconf.h
|
||||
|
||||
zutil.obj: $(TOP)/zutil.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h
|
||||
|
||||
gvmat64.obj: $(TOP)/contrib\masmx64\gvmat64.asm
|
||||
|
||||
inffasx64.obj: $(TOP)/contrib\masmx64\inffasx64.asm
|
||||
|
||||
inffas8664.obj: $(TOP)/contrib\masmx64\inffas8664.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h \
|
||||
$(TOP)/inftrees.h $(TOP)/inflate.h $(TOP)/inffast.h
|
||||
|
||||
inffas32.obj: $(TOP)/contrib\masmx86\inffas32.asm
|
||||
|
||||
match686.obj: $(TOP)/contrib\masmx86\match686.asm
|
||||
|
||||
example.obj: $(TOP)/test/example.c $(TOP)/zlib.h $(TOP)/zconf.h
|
||||
|
||||
minigzip.obj: $(TOP)/test/minigzip.c $(TOP)/zlib.h $(TOP)/zconf.h
|
||||
|
||||
zlib1.res: $(TOP)/win32/zlib1.rc
|
||||
$(RC) $(RCFLAGS) /fo$@ $(TOP)/win32/zlib1.rc
|
||||
$(RESFILE): $(TOP)/win32/$(RCFILE)
|
||||
$(RC) $(RCFLAGS) /fo$@ $(TOP)/win32/$(RCFILE)
|
||||
|
||||
# testing
|
||||
test: example.exe minigzip.exe
|
||||
depcheck: depcheck.exe
|
||||
depcheck win32\Makefile.msc .
|
||||
depcheck win32\Makefile.arm .
|
||||
depcheck win32\Makefile.a64 .
|
||||
|
||||
test: example.exe minigzip.exe depcheck
|
||||
example
|
||||
echo hello world | minigzip | minigzip -d
|
||||
|
||||
@@ -144,6 +267,12 @@ testdll: example_d.exe minigzip_d.exe
|
||||
example_d
|
||||
echo hello world | minigzip_d | minigzip_d -d
|
||||
|
||||
depcheck.obj: $(TOP)/win32/depcheck.cpp
|
||||
|
||||
example.obj: $(TOP)/test/example.c $(TOP)/zbuild.h $(TOP)/zlib$(SUFFIX).h $(TOP)/deflate.h $(TOP)/test/test_shared_ng.h
|
||||
|
||||
minigzip.obj: $(TOP)/test/minigzip.c $(TOP)/zbuild.h $(TOP)/zlib$(SUFFIX).h
|
||||
|
||||
|
||||
# cleanup
|
||||
clean:
|
||||
@@ -156,4 +285,12 @@ clean:
|
||||
-del *.exe
|
||||
-del *.pdb
|
||||
-del *.manifest
|
||||
-del foo.gz
|
||||
|
||||
distclean: clean
|
||||
-del zconf$(SUFFIX).h
|
||||
-del zlib$(SUFFIX).h
|
||||
-del zlib_name_mangling$(SUFFIX).h
|
||||
-del $(TOP)\win32\zlib.def
|
||||
-del $(TOP)\win32\zlibcompat.def
|
||||
-del $(TOP)\win32\zlib-ng.def
|
||||
-del gzread.c
|
||||
@@ -0,0 +1,321 @@
|
||||
/* depcheck.cpp - Dependency checker for NMake Makefiles
|
||||
* Copyright (c) 2024 Mika T. Lindqvist
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 3) {
|
||||
printf("Usage: depcheck Makefile <top_directory>\n");
|
||||
return -1;
|
||||
}
|
||||
std::filebuf fb;
|
||||
if (fb.open (argv[1],std::ios::in)) {
|
||||
std::istream is(&fb);
|
||||
std::string makefile = argv[1];
|
||||
std::string l, tmp, tmp2;
|
||||
while (is) {
|
||||
std::getline(is, l);
|
||||
while (l.back() == '\\') {
|
||||
std::getline(is, tmp);
|
||||
l.replace(l.length() - 1, 1, tmp);
|
||||
}
|
||||
size_t pos = l.find("obj:");
|
||||
if (pos != std::string::npos) {
|
||||
std::string objfile = l.substr(0, pos+3);
|
||||
printf("File: %s\n", objfile.c_str());
|
||||
std::vector<std::string> files;
|
||||
std::stringstream ss(l.substr(pos+4));
|
||||
while(getline(ss, tmp, ' ')){
|
||||
if (tmp != "" && tmp != "/") {
|
||||
files.push_back(tmp);
|
||||
}
|
||||
}
|
||||
for (auto it = files.begin(); it != files.end(); ++it) {
|
||||
printf("Dependency: %s\n", (*it).c_str());
|
||||
}
|
||||
if (!files.empty()) {
|
||||
std::filebuf fb2;
|
||||
std::string src = files[0];
|
||||
size_t pos2 = src.find("$(TOP)");
|
||||
if (pos2 != std::string::npos) {
|
||||
src.replace(pos2, 6, argv[2]);
|
||||
}
|
||||
printf("Source: %s\n", src.c_str());
|
||||
if (fb2.open(src.c_str(),std::ios::in)) {
|
||||
std::istream is2(&fb2);
|
||||
std::vector<std::string> includes;
|
||||
while (is2) {
|
||||
std::getline(is2, l);
|
||||
pos = l.find("#");
|
||||
if (pos != std::string::npos) {
|
||||
pos2 = l.find("include");
|
||||
size_t pos3 = l.find("\"");
|
||||
if (pos2 != std::string::npos && pos3 != std::string::npos && pos2 > pos && pos3 > pos2) {
|
||||
tmp = l.substr(pos3 + 1);
|
||||
pos2 = tmp.find("\"");
|
||||
if (pos2 != std::string::npos) {
|
||||
tmp = tmp.substr(0, pos2);
|
||||
}
|
||||
pos2 = tmp.find("../");
|
||||
if (pos2 != std::string::npos) {
|
||||
tmp = tmp.substr(3);
|
||||
}
|
||||
printf("Line: %s\n", tmp.c_str());
|
||||
int found = 0;
|
||||
for (size_t i = 1; i < files.size(); i++) {
|
||||
pos3 = files[i].find("$(SUFFIX)");
|
||||
if (pos3 != std::string::npos) {
|
||||
tmp2 = files[i].substr(0, pos3).append(files[i].substr(pos3 + 9));
|
||||
printf("Comparing dependency \"%s\" and \"%s\"\n", tmp2.c_str(), tmp.c_str());
|
||||
if (tmp2 == tmp) {
|
||||
printf("Dependency %s OK\n", tmp.c_str());
|
||||
found = 1;
|
||||
includes.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
printf("Comparing dependency \"%s\" and \"$(TOP)/%s\"\n", tmp2.c_str(), tmp.c_str());
|
||||
if (tmp2 == std::string("$(TOP)/").append(tmp)) {
|
||||
printf("Dependency %s OK\n", tmp.c_str());
|
||||
found = 1;
|
||||
includes.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
|
||||
tmp2 = files[i].substr(0, pos3).append("-ng").append(files[i].substr(pos3 + 9));
|
||||
printf("Comparing dependency \"%s\" and \"%s\"\n", tmp2.c_str(), tmp.c_str());
|
||||
if (tmp2 == tmp) {
|
||||
printf("Dependency %s OK\n", tmp.c_str());
|
||||
found = 1;
|
||||
includes.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
printf("Comparing dependency \"%s\" and \"$(TOP)/%s\"\n", tmp2.c_str(), tmp.c_str());
|
||||
if (tmp2 == std::string("$(TOP)/").append(tmp)) {
|
||||
printf("Dependency %s OK\n", tmp.c_str());
|
||||
found = 1;
|
||||
includes.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
printf("Comparing dependency \"%s\" and \"%s\"\n", files[i].c_str(), tmp.c_str());
|
||||
if (files[i] == tmp) {
|
||||
printf("Dependency %s OK\n", tmp.c_str());
|
||||
found = 1;
|
||||
includes.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
printf("Comparing dependency \"%s\" and \"$(TOP)/%s\"\n", files[i].c_str(), tmp.c_str());
|
||||
if (files[i] == std::string("$(TOP)/").append(tmp)) {
|
||||
printf("Dependency %s OK\n", tmp.c_str());
|
||||
found = 1;
|
||||
includes.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
printf("Comparing dependency \"%s\" and \"$(TOP)/arch/%s\"\n", files[i].c_str(), tmp.c_str());
|
||||
if (files[i] == std::string("$(TOP)/arch/").append(tmp)) {
|
||||
printf("Dependency %s OK\n", tmp.c_str());
|
||||
found = 1;
|
||||
includes.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
printf("Comparing dependency \"%s\" and \"$(TOP)/arch/generic/%s\"\n", files[i].c_str(), tmp.c_str());
|
||||
if (files[i] == std::string("$(TOP)/arch/generic/").append(tmp)) {
|
||||
printf("Dependency %s OK\n", tmp.c_str());
|
||||
found = 1;
|
||||
includes.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
printf("Comparing dependency \"%s\" and \"$(TOP)/arch/arm/%s\"\n", files[i].c_str(), tmp.c_str());
|
||||
if (files[i] == std::string("$(TOP)/arch/arm/").append(tmp)) {
|
||||
printf("Dependency %s OK\n", tmp.c_str());
|
||||
found = 1;
|
||||
includes.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
printf("Comparing dependency \"%s\" and \"$(TOP)/arch/x86/%s\"\n", files[i].c_str(), tmp.c_str());
|
||||
if (files[i] == std::string("$(TOP)/arch/x86/").append(tmp)) {
|
||||
printf("Dependency %s OK\n", tmp.c_str());
|
||||
found = 1;
|
||||
includes.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
printf("Comparing dependency \"%s\" and \"$(TOP)/test/%s\"\n", files[i].c_str(), tmp.c_str());
|
||||
if (files[i] == std::string("$(TOP)/test/").append(tmp)) {
|
||||
printf("Dependency %s OK\n", tmp.c_str());
|
||||
found = 1;
|
||||
includes.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Skip irrelevant dependencies
|
||||
if (tmp.substr(0, 9) == "arch/s390") found = 1;
|
||||
if (tmp == "zlib-ng.h" && std::find(includes.begin(), includes.end(), "zlib.h") != includes.end()) found = 1;
|
||||
if (found == 0) {
|
||||
printf("%s: Dependency %s missing for %s!\n", makefile.c_str(), tmp.c_str(), objfile.c_str());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t i = 1; i < files.size(); i++) {
|
||||
int found = 0;
|
||||
tmp = files[i];
|
||||
printf("Dependency: %s\n", tmp.c_str());
|
||||
pos2 = tmp.find("$(TOP)");
|
||||
if (pos2 != std::string::npos) {
|
||||
tmp = tmp.substr(7);
|
||||
}
|
||||
for (size_t j = 0; j < includes.size(); j++) {
|
||||
pos2 = tmp.find("$(SUFFIX)");
|
||||
if (pos2 != std::string::npos) {
|
||||
std::string tmp1 = tmp.substr(0, pos2).append(tmp.substr(pos2 + 9));
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"%s\"\n", j, includes.size(), tmp1.c_str(), includes[j].c_str());
|
||||
if (tmp1 == includes[j]) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"arch/%s\"\n", j, includes.size(), tmp1.c_str(), includes[j].c_str());
|
||||
if (tmp1 == std::string("arch/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"arch/generic/%s\"\n", j, includes.size(), tmp1.c_str(), includes[j].c_str());
|
||||
if (tmp1 == std::string("arch/generic/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"arch/arm/%s\"\n", j, includes.size(), tmp1.c_str(), includes[j].c_str());
|
||||
if (tmp1 == std::string("arch/arm/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"arch/x86/%s\"\n", j, includes.size(), tmp1.c_str(), includes[j].c_str());
|
||||
if (tmp1 == std::string("arch/x86/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"test/%s\"\n", j, includes.size(), tmp1.c_str(), includes[j].c_str());
|
||||
if (tmp1 == std::string("test/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
tmp1 = tmp.substr(0, pos2).append("-ng").append(tmp.substr(pos2 + 9));
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"%s\"\n", j, includes.size(), tmp1.c_str(), includes[j].c_str());
|
||||
if (tmp1 == includes[j]) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"arch/%s\"\n", j, includes.size(), tmp1.c_str(), includes[j].c_str());
|
||||
if (tmp1 == std::string("arch/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"arch/generic/%s\"\n", j, includes.size(), tmp1.c_str(), includes[j].c_str());
|
||||
if (tmp1 == std::string("arch/generic/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"arch/arm/%s\"\n", j, includes.size(), tmp1.c_str(), includes[j].c_str());
|
||||
if (tmp1 == std::string("arch/arm/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"arch/x86/%s\"\n", j, includes.size(), tmp1.c_str(), includes[j].c_str());
|
||||
if (tmp1 == std::string("arch/x86/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"test/%s\"\n", j, includes.size(), tmp1.c_str(), includes[j].c_str());
|
||||
if (tmp1 == std::string("test/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"%s\"\n", j, includes.size(), tmp.c_str(), includes[j].c_str());
|
||||
if (tmp == includes[j]) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"arch/%s\"\n", j, includes.size(), tmp.c_str(), includes[j].c_str());
|
||||
if (tmp == std::string("arch/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"arch/generic/%s\"\n", j, includes.size(), tmp.c_str(), includes[j].c_str());
|
||||
if (tmp == std::string("arch/generic/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"arch/arm/%s\"\n", j, includes.size(), tmp.c_str(), includes[j].c_str());
|
||||
if (tmp == std::string("arch/arm/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"arch/x86/%s\"\n", j, includes.size(), tmp.c_str(), includes[j].c_str());
|
||||
if (tmp == std::string("arch/x86/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
printf("[%zd/%zd] Comparing dependency \"%s\" and \"test/%s\"\n", j, includes.size(), tmp.c_str(), includes[j].c_str());
|
||||
if (tmp == std::string("test/").append(includes[j])) {
|
||||
printf("Dependency %s OK\n", files[i].c_str());
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Skip indirect dependencies
|
||||
if (tmp.find("arm_features.h") != std::string::npos
|
||||
&& std::find(includes.begin(), includes.end(), "cpu_features.h") != includes.end()
|
||||
&& (makefile.find(".arm") != std::string::npos
|
||||
|| makefile.find(".a64") != std::string::npos)) found = 1;
|
||||
if (tmp.find("x86_features.h") != std::string::npos
|
||||
&& std::find(includes.begin(), includes.end(), "cpu_features.h") != includes.end()
|
||||
&& makefile.find(".msc") != std::string::npos) found = 1;
|
||||
//
|
||||
if (tmp.find("generic_functions.h") != std::string::npos
|
||||
&& std::find(includes.begin(), includes.end(), "arch_functions.h") != includes.end()) found = 1;
|
||||
if (tmp.find("arm_functions.h") != std::string::npos
|
||||
&& std::find(includes.begin(), includes.end(), "arch_functions.h") != includes.end()
|
||||
&& (makefile.find(".arm") != std::string::npos
|
||||
|| makefile.find(".a64") != std::string::npos)) found = 1;
|
||||
if (tmp.find("x86_functions.h") != std::string::npos
|
||||
&& std::find(includes.begin(), includes.end(), "arch_functions.h") != includes.end()
|
||||
&& makefile.find(".msc") != std::string::npos) found = 1;
|
||||
if (found == 0) {
|
||||
printf("%s: Dependency %s not needed for %s\n", makefile.c_str(), files[i].c_str(), objfile.c_str());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
fb2.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fb.close();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
strInputFileName = Wscript.Arguments(0)
|
||||
strOutputFileName = Wscript.Arguments(1)
|
||||
strOldText = Wscript.Arguments(2)
|
||||
strNewText = Wscript.Arguments(3)
|
||||
|
||||
Set objFSO = CreateObject("Scripting.FileSystemObject")
|
||||
Set objFile = objFSO.OpenTextFile(strInputFileName, 1)
|
||||
|
||||
strText = objFile.ReadAll
|
||||
objFile.Close
|
||||
strNewText = Replace(strText, strOldText, strNewText)
|
||||
|
||||
Set objFile = objFSO.OpenTextFile(strOutputFileName, 2, True)
|
||||
objFile.Write strNewText
|
||||
objFile.Close
|
||||
@@ -0,0 +1,206 @@
|
||||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef ZCONF_H
|
||||
#define ZCONF_H
|
||||
|
||||
#include "zlib_name_mangling.h"
|
||||
|
||||
#if !defined(_WIN32) && defined(__WIN32__)
|
||||
# define _WIN32
|
||||
#endif
|
||||
|
||||
/* Clang macro for detecting declspec support
|
||||
* https://clang.llvm.org/docs/LanguageExtensions.html#has-declspec-attribute
|
||||
*/
|
||||
#ifndef __has_declspec_attribute
|
||||
# define __has_declspec_attribute(x) 0
|
||||
#endif
|
||||
|
||||
#if defined(ZLIB_CONST) && !defined(z_const)
|
||||
# define z_const const
|
||||
#else
|
||||
# define z_const
|
||||
#endif
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# define MAX_MEM_LEVEL 9
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
||||
* created by gzip. (Files created by minigzip can still be extracted by
|
||||
* gzip.)
|
||||
*/
|
||||
#ifndef MIN_WBITS
|
||||
# define MIN_WBITS 8 /* 256 LZ77 window */
|
||||
#endif
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
|
||||
/* The memory requirements for deflate are (in bytes):
|
||||
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# define OF(args) args
|
||||
#endif
|
||||
|
||||
#ifdef ZLIB_INTERNAL
|
||||
# define Z_INTERNAL ZLIB_INTERNAL
|
||||
#endif
|
||||
|
||||
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
||||
* This is not mandatory, but it offers a little performance increase.
|
||||
*/
|
||||
#if defined(ZLIB_DLL) && (defined(_WIN32) || (__has_declspec_attribute(dllexport) && __has_declspec_attribute(dllimport)))
|
||||
# ifdef Z_INTERNAL
|
||||
# define Z_EXTERN extern __declspec(dllexport)
|
||||
# else
|
||||
# define Z_EXTERN extern __declspec(dllimport)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
||||
* define ZLIB_WINAPI.
|
||||
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
|
||||
*/
|
||||
#if defined(ZLIB_WINAPI) && defined(_WIN32)
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# endif
|
||||
# include <windows.h>
|
||||
/* No need for _export, use ZLIB.DEF instead. */
|
||||
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
||||
# define Z_EXPORT WINAPI
|
||||
# define Z_EXPORTVA WINAPIV
|
||||
#endif
|
||||
|
||||
#ifndef Z_EXTERN
|
||||
# define Z_EXTERN extern
|
||||
#endif
|
||||
#ifndef Z_EXPORT
|
||||
# define Z_EXPORT
|
||||
#endif
|
||||
#ifndef Z_EXPORTVA
|
||||
# define Z_EXPORTVA
|
||||
#endif
|
||||
|
||||
/* Conditional exports */
|
||||
#define ZNG_CONDEXPORT Z_INTERNAL
|
||||
|
||||
/* For backwards compatibility */
|
||||
|
||||
#ifndef ZEXTERN
|
||||
# define ZEXTERN Z_EXTERN
|
||||
#endif
|
||||
#ifndef ZEXPORT
|
||||
# define ZEXPORT Z_EXPORT
|
||||
#endif
|
||||
#ifndef ZEXPORTVA
|
||||
# define ZEXPORTVA Z_EXPORTVA
|
||||
#endif
|
||||
#ifndef FAR
|
||||
# define FAR
|
||||
#endif
|
||||
|
||||
/* Legacy zlib typedefs for backwards compatibility. Don't assume stdint.h is defined. */
|
||||
typedef unsigned char Byte;
|
||||
typedef Byte Bytef;
|
||||
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
typedef char charf;
|
||||
typedef int intf;
|
||||
typedef uInt uIntf;
|
||||
typedef uLong uLongf;
|
||||
|
||||
typedef void const *voidpc;
|
||||
typedef void *voidpf;
|
||||
typedef void *voidp;
|
||||
|
||||
typedef unsigned int z_crc_t;
|
||||
|
||||
#if 1 /* was set to #if 1 by configure/cmake/etc */
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
|
||||
#ifdef NEED_PTRDIFF_T /* may be set to #if 1 by configure/cmake/etc */
|
||||
typedef PTRDIFF_TYPE ptrdiff_t;
|
||||
#endif
|
||||
|
||||
#include <sys/types.h> /* for off_t */
|
||||
|
||||
#include <stddef.h> /* for wchar_t and NULL */
|
||||
|
||||
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
|
||||
* "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
|
||||
* though the former does not conform to the LFS document), but considering
|
||||
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
|
||||
* equivalently requesting no 64-bit operations
|
||||
*/
|
||||
#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
|
||||
# undef _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
|
||||
# ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
|
||||
# define Z_LFS64
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
|
||||
# define Z_LARGE64
|
||||
#endif
|
||||
|
||||
#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
|
||||
# define Z_WANT64
|
||||
#endif
|
||||
|
||||
#if !defined(SEEK_SET)
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
#endif
|
||||
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||
# define z_off64_t off64_t
|
||||
#else
|
||||
# if defined(__MSYS__)
|
||||
# define z_off64_t _off64_t
|
||||
# elif defined(_WIN32) && !defined(__GNUC__)
|
||||
# define z_off64_t __int64
|
||||
# else
|
||||
# define z_off64_t z_off_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef size_t z_size_t;
|
||||
|
||||
#endif /* ZCONF_H */
|
||||
@@ -0,0 +1,60 @@
|
||||
; zlib-ng data compression library
|
||||
EXPORTS
|
||||
; basic functions
|
||||
@ZLIB_SYMBOL_PREFIX@zlibng_version
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflate
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateEnd
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateInit
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateInit2
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflate
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateEnd
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateInit
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateInit2
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateBackInit
|
||||
; advanced functions
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateSetDictionary
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateGetDictionary
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateCopy
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateReset
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateParams
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateTune
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateBound
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflatePending
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflatePrime
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateSetHeader
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateSetParams
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateGetParams
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateSetDictionary
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateGetDictionary
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateSync
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateCopy
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateReset
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateReset2
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflatePrime
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateMark
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateGetHeader
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateBack
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateBackEnd
|
||||
@ZLIB_SYMBOL_PREFIX@zng_zlibCompileFlags
|
||||
; utility functions
|
||||
@ZLIB_SYMBOL_PREFIX@zng_compress
|
||||
@ZLIB_SYMBOL_PREFIX@zng_compress2
|
||||
@ZLIB_SYMBOL_PREFIX@zng_compressBound
|
||||
@ZLIB_SYMBOL_PREFIX@zng_uncompress
|
||||
@ZLIB_SYMBOL_PREFIX@zng_uncompress2
|
||||
; checksum functions
|
||||
@ZLIB_SYMBOL_PREFIX@zng_adler32
|
||||
@ZLIB_SYMBOL_PREFIX@zng_adler32_z
|
||||
@ZLIB_SYMBOL_PREFIX@zng_crc32
|
||||
@ZLIB_SYMBOL_PREFIX@zng_crc32_z
|
||||
@ZLIB_SYMBOL_PREFIX@zng_adler32_combine
|
||||
@ZLIB_SYMBOL_PREFIX@zng_crc32_combine
|
||||
; various hacks, don't look :)
|
||||
@ZLIB_SYMBOL_PREFIX@zng_zError
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateSyncPoint
|
||||
@ZLIB_SYMBOL_PREFIX@zng_get_crc_table
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateUndermine
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateValidate
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateCodesUsed
|
||||
@ZLIB_SYMBOL_PREFIX@zng_inflateResetKeep
|
||||
@ZLIB_SYMBOL_PREFIX@zng_deflateResetKeep
|
||||
@@ -0,0 +1,36 @@
|
||||
#include <winver.h>
|
||||
#include "zlib-ng.h"
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION ZLIBNG_VER_MAJOR,ZLIBNG_VER_MINOR,ZLIBNG_VER_REVISION,0
|
||||
PRODUCTVERSION ZLIBNG_VER_MAJOR,ZLIBNG_VER_MINOR,ZLIBNG_VER_REVISION,0
|
||||
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 1
|
||||
#else
|
||||
FILEFLAGS 0
|
||||
#endif
|
||||
FILEOS VOS__WINDOWS32
|
||||
FILETYPE VFT_DLL
|
||||
FILESUBTYPE 0 // not used
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904E4"
|
||||
//language ID = U.S. English, char set = Windows, Multilingual
|
||||
BEGIN
|
||||
VALUE "FileDescription", "zlib data compression library\0"
|
||||
VALUE "FileVersion", ZLIBNG_VERSION "\0"
|
||||
VALUE "InternalName", "zlib-ng1.dll\0"
|
||||
VALUE "LegalCopyright", "(C) 1995-2024 Jean-loup Gailly & Mark Adler\0"
|
||||
VALUE "OriginalFilename", "zlib-ng1.dll\0"
|
||||
VALUE "ProductName", "zlib\0"
|
||||
VALUE "ProductVersion", ZLIBNG_VERSION "\0"
|
||||
VALUE "Comments", "For more information visit https://www.zlib.net/\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0409, 1252
|
||||
END
|
||||
END
|
||||
@@ -0,0 +1,64 @@
|
||||
; zlib data compression library
|
||||
EXPORTS
|
||||
; basic functions
|
||||
@ZLIB_SYMBOL_PREFIX@zlibVersion
|
||||
@ZLIB_SYMBOL_PREFIX@deflate
|
||||
@ZLIB_SYMBOL_PREFIX@deflateEnd
|
||||
@ZLIB_SYMBOL_PREFIX@inflate
|
||||
@ZLIB_SYMBOL_PREFIX@inflateEnd
|
||||
; advanced functions
|
||||
@ZLIB_SYMBOL_PREFIX@deflateSetDictionary
|
||||
@ZLIB_SYMBOL_PREFIX@deflateGetDictionary
|
||||
@ZLIB_SYMBOL_PREFIX@deflateCopy
|
||||
@ZLIB_SYMBOL_PREFIX@deflateReset
|
||||
@ZLIB_SYMBOL_PREFIX@deflateParams
|
||||
@ZLIB_SYMBOL_PREFIX@deflateTune
|
||||
@ZLIB_SYMBOL_PREFIX@deflateBound
|
||||
@ZLIB_SYMBOL_PREFIX@deflatePending
|
||||
@ZLIB_SYMBOL_PREFIX@deflatePrime
|
||||
@ZLIB_SYMBOL_PREFIX@deflateSetHeader
|
||||
@ZLIB_SYMBOL_PREFIX@inflateSetDictionary
|
||||
@ZLIB_SYMBOL_PREFIX@inflateGetDictionary
|
||||
@ZLIB_SYMBOL_PREFIX@inflateSync
|
||||
@ZLIB_SYMBOL_PREFIX@inflateCopy
|
||||
@ZLIB_SYMBOL_PREFIX@inflateReset
|
||||
@ZLIB_SYMBOL_PREFIX@inflateReset2
|
||||
@ZLIB_SYMBOL_PREFIX@inflatePrime
|
||||
@ZLIB_SYMBOL_PREFIX@inflateMark
|
||||
@ZLIB_SYMBOL_PREFIX@inflateGetHeader
|
||||
@ZLIB_SYMBOL_PREFIX@inflateBack
|
||||
@ZLIB_SYMBOL_PREFIX@inflateBackEnd
|
||||
@ZLIB_SYMBOL_PREFIX@zlibCompileFlags
|
||||
; utility functions
|
||||
@ZLIB_SYMBOL_PREFIX@compress
|
||||
@ZLIB_SYMBOL_PREFIX@compress2
|
||||
@ZLIB_SYMBOL_PREFIX@compressBound
|
||||
@ZLIB_SYMBOL_PREFIX@uncompress
|
||||
@ZLIB_SYMBOL_PREFIX@uncompress2
|
||||
; large file functions
|
||||
@ZLIB_SYMBOL_PREFIX@adler32_combine64
|
||||
@ZLIB_SYMBOL_PREFIX@crc32_combine64
|
||||
@ZLIB_SYMBOL_PREFIX@crc32_combine_gen64
|
||||
; checksum functions
|
||||
@ZLIB_SYMBOL_PREFIX@adler32
|
||||
@ZLIB_SYMBOL_PREFIX@adler32_z
|
||||
@ZLIB_SYMBOL_PREFIX@crc32
|
||||
@ZLIB_SYMBOL_PREFIX@crc32_z
|
||||
@ZLIB_SYMBOL_PREFIX@adler32_combine
|
||||
@ZLIB_SYMBOL_PREFIX@crc32_combine
|
||||
@ZLIB_SYMBOL_PREFIX@crc32_combine_gen
|
||||
@ZLIB_SYMBOL_PREFIX@crc32_combine_op
|
||||
; various hacks, don't look :)
|
||||
@ZLIB_SYMBOL_PREFIX@deflateInit_
|
||||
@ZLIB_SYMBOL_PREFIX@deflateInit2_
|
||||
@ZLIB_SYMBOL_PREFIX@inflateInit_
|
||||
@ZLIB_SYMBOL_PREFIX@inflateInit2_
|
||||
@ZLIB_SYMBOL_PREFIX@inflateBackInit_
|
||||
@ZLIB_SYMBOL_PREFIX@zError
|
||||
@ZLIB_SYMBOL_PREFIX@inflateSyncPoint
|
||||
@ZLIB_SYMBOL_PREFIX@get_crc_table
|
||||
@ZLIB_SYMBOL_PREFIX@inflateUndermine
|
||||
@ZLIB_SYMBOL_PREFIX@inflateValidate
|
||||
@ZLIB_SYMBOL_PREFIX@inflateCodesUsed
|
||||
@ZLIB_SYMBOL_PREFIX@inflateResetKeep
|
||||
@ZLIB_SYMBOL_PREFIX@deflateResetKeep
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,11 +1,7 @@
|
||||
#include <winver.h>
|
||||
#include "../zlib.h"
|
||||
#include "zlib.h"
|
||||
|
||||
#ifdef GCC_WINDRES
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
#else
|
||||
VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
|
||||
#endif
|
||||
FILEVERSION ZLIB_VER_MAJOR,ZLIB_VER_MINOR,ZLIB_VER_REVISION,0
|
||||
PRODUCTVERSION ZLIB_VER_MAJOR,ZLIB_VER_MINOR,ZLIB_VER_REVISION,0
|
||||
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
|
||||
@@ -26,11 +22,11 @@ BEGIN
|
||||
VALUE "FileDescription", "zlib data compression library\0"
|
||||
VALUE "FileVersion", ZLIB_VERSION "\0"
|
||||
VALUE "InternalName", "zlib1.dll\0"
|
||||
VALUE "LegalCopyright", "(C) 1995-2022 Jean-loup Gailly & Mark Adler\0"
|
||||
VALUE "LegalCopyright", "(C) 1995-2024 Jean-loup Gailly & Mark Adler\0"
|
||||
VALUE "OriginalFilename", "zlib1.dll\0"
|
||||
VALUE "ProductName", "zlib\0"
|
||||
VALUE "ProductVersion", ZLIB_VERSION "\0"
|
||||
VALUE "Comments", "For more information visit http://www.zlib.net/\0"
|
||||
VALUE "Comments", "For more information visit https://www.zlib.net/\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/* zlib_name_mangling.h has been automatically generated from
|
||||
* zlib_name_mangling.h.empty because ZLIB_SYMBOL_PREFIX was NOT set.
|
||||
*/
|
||||
|
||||
#ifndef ZLIB_NAME_MANGLING_H
|
||||
#define ZLIB_NAME_MANGLING_H
|
||||
|
||||
#endif /* ZLIB_NAME_MANGLING_H */
|
||||
@@ -0,0 +1,97 @@
|
||||
; zlib data compression library
|
||||
EXPORTS
|
||||
; basic functions
|
||||
@ZLIB_SYMBOL_PREFIX@zlibVersion
|
||||
@ZLIB_SYMBOL_PREFIX@deflate
|
||||
@ZLIB_SYMBOL_PREFIX@deflateEnd
|
||||
@ZLIB_SYMBOL_PREFIX@inflate
|
||||
@ZLIB_SYMBOL_PREFIX@inflateEnd
|
||||
; advanced functions
|
||||
@ZLIB_SYMBOL_PREFIX@deflateSetDictionary
|
||||
@ZLIB_SYMBOL_PREFIX@deflateGetDictionary
|
||||
@ZLIB_SYMBOL_PREFIX@deflateCopy
|
||||
@ZLIB_SYMBOL_PREFIX@deflateReset
|
||||
@ZLIB_SYMBOL_PREFIX@deflateParams
|
||||
@ZLIB_SYMBOL_PREFIX@deflateTune
|
||||
@ZLIB_SYMBOL_PREFIX@deflateBound
|
||||
@ZLIB_SYMBOL_PREFIX@deflatePending
|
||||
@ZLIB_SYMBOL_PREFIX@deflatePrime
|
||||
@ZLIB_SYMBOL_PREFIX@deflateSetHeader
|
||||
@ZLIB_SYMBOL_PREFIX@inflateSetDictionary
|
||||
@ZLIB_SYMBOL_PREFIX@inflateGetDictionary
|
||||
@ZLIB_SYMBOL_PREFIX@inflateSync
|
||||
@ZLIB_SYMBOL_PREFIX@inflateCopy
|
||||
@ZLIB_SYMBOL_PREFIX@inflateReset
|
||||
@ZLIB_SYMBOL_PREFIX@inflateReset2
|
||||
@ZLIB_SYMBOL_PREFIX@inflatePrime
|
||||
@ZLIB_SYMBOL_PREFIX@inflateMark
|
||||
@ZLIB_SYMBOL_PREFIX@inflateGetHeader
|
||||
@ZLIB_SYMBOL_PREFIX@inflateBack
|
||||
@ZLIB_SYMBOL_PREFIX@inflateBackEnd
|
||||
@ZLIB_SYMBOL_PREFIX@zlibCompileFlags
|
||||
; utility functions
|
||||
@ZLIB_SYMBOL_PREFIX@compress
|
||||
@ZLIB_SYMBOL_PREFIX@compress2
|
||||
@ZLIB_SYMBOL_PREFIX@compressBound
|
||||
@ZLIB_SYMBOL_PREFIX@uncompress
|
||||
@ZLIB_SYMBOL_PREFIX@uncompress2
|
||||
@ZLIB_SYMBOL_PREFIX@gzopen
|
||||
@ZLIB_SYMBOL_PREFIX@gzdopen
|
||||
@ZLIB_SYMBOL_PREFIX@gzbuffer
|
||||
@ZLIB_SYMBOL_PREFIX@gzsetparams
|
||||
@ZLIB_SYMBOL_PREFIX@gzread
|
||||
@ZLIB_SYMBOL_PREFIX@gzfread
|
||||
@ZLIB_SYMBOL_PREFIX@gzwrite
|
||||
@ZLIB_SYMBOL_PREFIX@gzfwrite
|
||||
@ZLIB_SYMBOL_PREFIX@gzprintf
|
||||
@ZLIB_SYMBOL_PREFIX@gzvprintf
|
||||
@ZLIB_SYMBOL_PREFIX@gzputs
|
||||
@ZLIB_SYMBOL_PREFIX@gzgets
|
||||
@ZLIB_SYMBOL_PREFIX@gzputc
|
||||
@ZLIB_SYMBOL_PREFIX@gzgetc
|
||||
@ZLIB_SYMBOL_PREFIX@gzungetc
|
||||
@ZLIB_SYMBOL_PREFIX@gzflush
|
||||
@ZLIB_SYMBOL_PREFIX@gzseek
|
||||
@ZLIB_SYMBOL_PREFIX@gzrewind
|
||||
@ZLIB_SYMBOL_PREFIX@gztell
|
||||
@ZLIB_SYMBOL_PREFIX@gzoffset
|
||||
@ZLIB_SYMBOL_PREFIX@gzeof
|
||||
@ZLIB_SYMBOL_PREFIX@gzdirect
|
||||
@ZLIB_SYMBOL_PREFIX@gzclose
|
||||
@ZLIB_SYMBOL_PREFIX@gzclose_r
|
||||
@ZLIB_SYMBOL_PREFIX@gzclose_w
|
||||
@ZLIB_SYMBOL_PREFIX@gzerror
|
||||
@ZLIB_SYMBOL_PREFIX@gzclearerr
|
||||
; large file functions
|
||||
@ZLIB_SYMBOL_PREFIX@gzopen64
|
||||
@ZLIB_SYMBOL_PREFIX@gzseek64
|
||||
@ZLIB_SYMBOL_PREFIX@gztell64
|
||||
@ZLIB_SYMBOL_PREFIX@gzoffset64
|
||||
@ZLIB_SYMBOL_PREFIX@adler32_combine64
|
||||
@ZLIB_SYMBOL_PREFIX@crc32_combine64
|
||||
@ZLIB_SYMBOL_PREFIX@crc32_combine_gen64
|
||||
; checksum functions
|
||||
@ZLIB_SYMBOL_PREFIX@adler32
|
||||
@ZLIB_SYMBOL_PREFIX@adler32_z
|
||||
@ZLIB_SYMBOL_PREFIX@crc32
|
||||
@ZLIB_SYMBOL_PREFIX@crc32_z
|
||||
@ZLIB_SYMBOL_PREFIX@adler32_combine
|
||||
@ZLIB_SYMBOL_PREFIX@crc32_combine
|
||||
@ZLIB_SYMBOL_PREFIX@crc32_combine_gen
|
||||
@ZLIB_SYMBOL_PREFIX@crc32_combine_op
|
||||
; various hacks, don't look :)
|
||||
@ZLIB_SYMBOL_PREFIX@deflateInit_
|
||||
@ZLIB_SYMBOL_PREFIX@deflateInit2_
|
||||
@ZLIB_SYMBOL_PREFIX@inflateInit_
|
||||
@ZLIB_SYMBOL_PREFIX@inflateInit2_
|
||||
@ZLIB_SYMBOL_PREFIX@inflateBackInit_
|
||||
@ZLIB_SYMBOL_PREFIX@gzgetc_
|
||||
@ZLIB_SYMBOL_PREFIX@zError
|
||||
@ZLIB_SYMBOL_PREFIX@inflateSyncPoint
|
||||
@ZLIB_SYMBOL_PREFIX@get_crc_table
|
||||
@ZLIB_SYMBOL_PREFIX@inflateUndermine
|
||||
@ZLIB_SYMBOL_PREFIX@inflateValidate
|
||||
@ZLIB_SYMBOL_PREFIX@inflateCodesUsed
|
||||
@ZLIB_SYMBOL_PREFIX@inflateResetKeep
|
||||
@ZLIB_SYMBOL_PREFIX@deflateResetKeep
|
||||
@ZLIB_SYMBOL_PREFIX@gzopen_w
|
||||
@@ -0,0 +1,353 @@
|
||||
#ifndef _ZBUILD_H
|
||||
#define _ZBUILD_H
|
||||
|
||||
#define _POSIX_SOURCE 1 /* fileno */
|
||||
#ifndef _POSIX_C_SOURCE
|
||||
# define _POSIX_C_SOURCE 200809L /* snprintf, posix_memalign, strdup */
|
||||
#endif
|
||||
#ifndef _ISOC11_SOURCE
|
||||
# define _ISOC11_SOURCE 1 /* aligned_alloc */
|
||||
#endif
|
||||
#ifdef __OpenBSD__
|
||||
# define _BSD_SOURCE 1
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Determine compiler version of C Standard */
|
||||
#ifdef __STDC_VERSION__
|
||||
# if __STDC_VERSION__ >= 199901L
|
||||
# ifndef STDC99
|
||||
# define STDC99
|
||||
# endif
|
||||
# endif
|
||||
# if __STDC_VERSION__ >= 201112L
|
||||
# ifndef STDC11
|
||||
# define STDC11
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef Z_HAS_ATTRIBUTE
|
||||
# if defined(__has_attribute)
|
||||
# define Z_HAS_ATTRIBUTE(a) __has_attribute(a)
|
||||
# else
|
||||
# define Z_HAS_ATTRIBUTE(a) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef Z_FALLTHROUGH
|
||||
# if Z_HAS_ATTRIBUTE(__fallthrough__) || (defined(__GNUC__) && (__GNUC__ >= 7))
|
||||
# define Z_FALLTHROUGH __attribute__((__fallthrough__))
|
||||
# else
|
||||
# define Z_FALLTHROUGH do {} while(0) /* fallthrough */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef Z_TARGET
|
||||
# if Z_HAS_ATTRIBUTE(__target__)
|
||||
# define Z_TARGET(x) __attribute__((__target__(x)))
|
||||
# else
|
||||
# define Z_TARGET(x)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* This has to be first include that defines any types */
|
||||
#if defined(_MSC_VER)
|
||||
# if defined(_WIN64)
|
||||
typedef __int64 ssize_t;
|
||||
# else
|
||||
typedef long ssize_t;
|
||||
# endif
|
||||
|
||||
# if defined(_WIN64)
|
||||
#define SSIZE_MAX _I64_MAX
|
||||
# else
|
||||
#define SSIZE_MAX LONG_MAX
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* A forced inline decorator */
|
||||
#if defined(_MSC_VER)
|
||||
# define Z_FORCEINLINE __forceinline
|
||||
#elif defined(__GNUC__)
|
||||
# define Z_FORCEINLINE inline __attribute__((always_inline))
|
||||
#else
|
||||
/* It won't actually force inlining but it will suggest it */
|
||||
# define Z_FORCEINLINE inline
|
||||
#endif
|
||||
|
||||
/* MS Visual Studio does not allow inline in C, only C++.
|
||||
But it provides __inline instead, so use that. */
|
||||
#if defined(_MSC_VER) && !defined(inline) && !defined(__cplusplus)
|
||||
# define inline __inline
|
||||
#endif
|
||||
|
||||
#if defined(ZLIB_COMPAT)
|
||||
# define PREFIX(x) x
|
||||
# define PREFIX2(x) ZLIB_ ## x
|
||||
# define PREFIX3(x) z_ ## x
|
||||
# define PREFIX4(x) x ## 64
|
||||
# define zVersion zlibVersion
|
||||
#else
|
||||
# define PREFIX(x) zng_ ## x
|
||||
# define PREFIX2(x) ZLIBNG_ ## x
|
||||
# define PREFIX3(x) zng_ ## x
|
||||
# define PREFIX4(x) zng_ ## x
|
||||
# define zVersion zlibng_version
|
||||
# define z_size_t size_t
|
||||
#endif
|
||||
|
||||
/* In zlib-compat some functions and types use unsigned long, but zlib-ng use size_t */
|
||||
#if defined(ZLIB_COMPAT)
|
||||
# define z_uintmax_t unsigned long
|
||||
#else
|
||||
# define z_uintmax_t size_t
|
||||
#endif
|
||||
|
||||
/* Minimum of a and b. */
|
||||
#define MIN(a, b) ((a) > (b) ? (b) : (a))
|
||||
/* Maximum of a and b. */
|
||||
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
||||
/* Ignore unused variable warning */
|
||||
#define Z_UNUSED(var) (void)(var)
|
||||
|
||||
#if defined(HAVE_VISIBILITY_INTERNAL)
|
||||
# define Z_INTERNAL __attribute__((visibility ("internal")))
|
||||
#elif defined(HAVE_VISIBILITY_HIDDEN)
|
||||
# define Z_INTERNAL __attribute__((visibility ("hidden")))
|
||||
#else
|
||||
# define Z_INTERNAL
|
||||
#endif
|
||||
|
||||
/* Symbol versioning helpers, allowing multiple versions of a function to exist.
|
||||
* Functions using this must also be added to zlib-ng.map for each version.
|
||||
* Double @@ means this is the default for newly compiled applications to link against.
|
||||
* Single @ means this is kept for backwards compatibility.
|
||||
* This is only used for Zlib-ng native API, and only on platforms supporting this.
|
||||
*/
|
||||
#if defined(HAVE_SYMVER)
|
||||
# define ZSYMVER(func,alias,ver) __asm__(".symver " func ", " alias "@ZLIB_NG_" ver);
|
||||
# define ZSYMVER_DEF(func,alias,ver) __asm__(".symver " func ", " alias "@@ZLIB_NG_" ver);
|
||||
#else
|
||||
# define ZSYMVER(func,alias,ver)
|
||||
# define ZSYMVER_DEF(func,alias,ver)
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
# define Z_REGISTER register
|
||||
#else
|
||||
# define Z_REGISTER
|
||||
#endif
|
||||
|
||||
/* Reverse the bytes in a value. Use compiler intrinsics when
|
||||
possible to take advantage of hardware implementations. */
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1300)
|
||||
# include <stdlib.h>
|
||||
# pragma intrinsic(_byteswap_ulong)
|
||||
# define ZSWAP16(q) _byteswap_ushort(q)
|
||||
# define ZSWAP32(q) _byteswap_ulong(q)
|
||||
# define ZSWAP64(q) _byteswap_uint64(q)
|
||||
|
||||
#elif defined(__clang__) || (defined(__GNUC__) && \
|
||||
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))
|
||||
# define ZSWAP16(q) __builtin_bswap16(q)
|
||||
# define ZSWAP32(q) __builtin_bswap32(q)
|
||||
# define ZSWAP64(q) __builtin_bswap64(q)
|
||||
|
||||
#elif defined(__GNUC__) && (__GNUC__ >= 2) && defined(__linux__)
|
||||
# include <byteswap.h>
|
||||
# define ZSWAP16(q) bswap_16(q)
|
||||
# define ZSWAP32(q) bswap_32(q)
|
||||
# define ZSWAP64(q) bswap_64(q)
|
||||
|
||||
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
|
||||
# include <sys/endian.h>
|
||||
# define ZSWAP16(q) bswap16(q)
|
||||
# define ZSWAP32(q) bswap32(q)
|
||||
# define ZSWAP64(q) bswap64(q)
|
||||
#elif defined(__OpenBSD__)
|
||||
# include <sys/endian.h>
|
||||
# define ZSWAP16(q) swap16(q)
|
||||
# define ZSWAP32(q) swap32(q)
|
||||
# define ZSWAP64(q) swap64(q)
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
/* ICC does not provide a two byte swap. */
|
||||
# define ZSWAP16(q) ((((q) & 0xff) << 8) | (((q) & 0xff00) >> 8))
|
||||
# define ZSWAP32(q) _bswap(q)
|
||||
# define ZSWAP64(q) _bswap64(q)
|
||||
|
||||
#else
|
||||
# define ZSWAP16(q) ((((q) & 0xff) << 8) | (((q) & 0xff00) >> 8))
|
||||
# define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
|
||||
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
|
||||
# define ZSWAP64(q) \
|
||||
(((q & 0xFF00000000000000u) >> 56u) | \
|
||||
((q & 0x00FF000000000000u) >> 40u) | \
|
||||
((q & 0x0000FF0000000000u) >> 24u) | \
|
||||
((q & 0x000000FF00000000u) >> 8u) | \
|
||||
((q & 0x00000000FF000000u) << 8u) | \
|
||||
((q & 0x0000000000FF0000u) << 24u) | \
|
||||
((q & 0x000000000000FF00u) << 40u) | \
|
||||
((q & 0x00000000000000FFu) << 56u))
|
||||
#endif
|
||||
|
||||
/* Only enable likely/unlikely if the compiler is known to support it */
|
||||
#if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__INTEL_COMPILER) || defined(__clang__)
|
||||
# define LIKELY_NULL(x) __builtin_expect((x) != 0, 0)
|
||||
# define LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
# define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
#else
|
||||
# define LIKELY_NULL(x) x
|
||||
# define LIKELY(x) x
|
||||
# define UNLIKELY(x) x
|
||||
#endif /* (un)likely */
|
||||
|
||||
#if defined(HAVE_ATTRIBUTE_ALIGNED)
|
||||
# define ALIGNED_(x) __attribute__ ((aligned(x)))
|
||||
#elif defined(_MSC_VER)
|
||||
# define ALIGNED_(x) __declspec(align(x))
|
||||
#else
|
||||
/* TODO: Define ALIGNED_ for your compiler */
|
||||
# define ALIGNED_(x)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_BUILTIN_ASSUME_ALIGNED
|
||||
# define HINT_ALIGNED(p,n) __builtin_assume_aligned((void *)(p),(n))
|
||||
#else
|
||||
# define HINT_ALIGNED(p,n) (p)
|
||||
#endif
|
||||
#define HINT_ALIGNED_16(p) HINT_ALIGNED((p),16)
|
||||
#define HINT_ALIGNED_64(p) HINT_ALIGNED((p),64)
|
||||
#define HINT_ALIGNED_4096(p) HINT_ALIGNED((p),4096)
|
||||
|
||||
/* PADSZ returns needed bytes to pad bpos to pad size
|
||||
* PAD_NN calculates pad size and adds it to bpos, returning the result.
|
||||
* All take an integer or a pointer as bpos input.
|
||||
*/
|
||||
#define PADSZ(bpos, pad) (((pad) - ((uintptr_t)(bpos) % (pad))) % (pad))
|
||||
#define PAD_16(bpos) ((bpos) + PADSZ((bpos),16))
|
||||
#define PAD_64(bpos) ((bpos) + PADSZ((bpos),64))
|
||||
#define PAD_4096(bpos) ((bpos) + PADSZ((bpos),4096))
|
||||
|
||||
/* Diagnostic functions */
|
||||
#ifdef ZLIB_DEBUG
|
||||
# include <stdio.h>
|
||||
extern int Z_INTERNAL z_verbose;
|
||||
extern void Z_INTERNAL z_error(const char *m);
|
||||
# define Assert(cond, msg) {int _cond = (cond); if (!_cond) z_error(msg);}
|
||||
# define Trace(x) {if (z_verbose >= 0) fprintf x;}
|
||||
# define Tracev(x) {if (z_verbose > 0) fprintf x;}
|
||||
# define Tracevv(x) {if (z_verbose > 1) fprintf x;}
|
||||
# define Tracec(c, x) {if (z_verbose > 0 && (c)) fprintf x;}
|
||||
# define Tracecv(c, x) {if (z_verbose > 1 && (c)) fprintf x;}
|
||||
#else
|
||||
# define Assert(cond, msg)
|
||||
# define Trace(x)
|
||||
# define Tracev(x)
|
||||
# define Tracevv(x)
|
||||
# define Tracec(c, x)
|
||||
# define Tracecv(c, x)
|
||||
#endif
|
||||
|
||||
/* OPTIMAL_CMP values determine the comparison width:
|
||||
* 64: Best for 64-bit architectures with unaligned access
|
||||
* 32: Best for 32-bit architectures with unaligned access
|
||||
* 16: Safe default for unknown architectures
|
||||
* 8: Safe fallback for architectures without unaligned access
|
||||
* Note: The unaligned access mentioned is cpu-support, this allows compiler or
|
||||
* separate unaligned intrinsics to utilize safe unaligned access, without
|
||||
* utilizing unaligned C pointers that are known to have undefined behavior.
|
||||
*/
|
||||
#if !defined(OPTIMAL_CMP)
|
||||
# if defined(__x86_64__) || defined(_M_X64) || defined(__amd64__) || defined(_M_AMD64)
|
||||
# define OPTIMAL_CMP 64
|
||||
# elif defined(__i386__) || defined(__i486__) || defined(__i586__) || \
|
||||
defined(__i686__) || defined(_X86_) || defined(_M_IX86)
|
||||
# define OPTIMAL_CMP 32
|
||||
# elif defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
|
||||
# if defined(__ARM_FEATURE_UNALIGNED) || defined(_WIN32)
|
||||
# define OPTIMAL_CMP 64
|
||||
# else
|
||||
# define OPTIMAL_CMP 8
|
||||
# endif
|
||||
# elif defined(__arm__) || defined(_M_ARM)
|
||||
# if defined(__ARM_FEATURE_UNALIGNED) || defined(_WIN32)
|
||||
# define OPTIMAL_CMP 32
|
||||
# else
|
||||
# define OPTIMAL_CMP 8
|
||||
# endif
|
||||
# elif defined(__powerpc64__) || defined(__ppc64__)
|
||||
# define OPTIMAL_CMP 64
|
||||
# elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)
|
||||
# define OPTIMAL_CMP 32
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(OPTIMAL_CMP)
|
||||
# define OPTIMAL_CMP 16
|
||||
#endif
|
||||
|
||||
#if defined(__has_feature)
|
||||
# if __has_feature(address_sanitizer)
|
||||
# define Z_ADDRESS_SANITIZER 1
|
||||
# endif
|
||||
#elif defined(__SANITIZE_ADDRESS__)
|
||||
# define Z_ADDRESS_SANITIZER 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
* __asan_loadN() and __asan_storeN() calls are inserted by compilers in order to check memory accesses.
|
||||
* They can be called manually too, with the following caveats:
|
||||
* gcc says: "warning: implicit declaration of function '...'"
|
||||
* g++ says: "error: new declaration '...' ambiguates built-in declaration '...'"
|
||||
* Accommodate both.
|
||||
*/
|
||||
#ifdef Z_ADDRESS_SANITIZER
|
||||
#ifndef __cplusplus
|
||||
void __asan_loadN(void *, long);
|
||||
void __asan_storeN(void *, long);
|
||||
#endif
|
||||
#else
|
||||
# define __asan_loadN(a, size) do { Z_UNUSED(a); Z_UNUSED(size); } while (0)
|
||||
# define __asan_storeN(a, size) do { Z_UNUSED(a); Z_UNUSED(size); } while (0)
|
||||
#endif
|
||||
|
||||
#if defined(__has_feature)
|
||||
# if __has_feature(memory_sanitizer)
|
||||
# define Z_MEMORY_SANITIZER 1
|
||||
# include <sanitizer/msan_interface.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef Z_MEMORY_SANITIZER
|
||||
# define __msan_check_mem_is_initialized(a, size) do { Z_UNUSED(a); Z_UNUSED(size); } while (0)
|
||||
# define __msan_unpoison(a, size) do { Z_UNUSED(a); Z_UNUSED(size); } while (0)
|
||||
#endif
|
||||
|
||||
/* Notify sanitizer runtime about an upcoming read access. */
|
||||
#define instrument_read(a, size) do { \
|
||||
void *__a = (void *)(a); \
|
||||
long __size = size; \
|
||||
__asan_loadN(__a, __size); \
|
||||
__msan_check_mem_is_initialized(__a, __size); \
|
||||
} while (0)
|
||||
|
||||
/* Notify sanitizer runtime about an upcoming write access. */
|
||||
#define instrument_write(a, size) do { \
|
||||
void *__a = (void *)(a); \
|
||||
long __size = size; \
|
||||
__asan_storeN(__a, __size); \
|
||||
} while (0)
|
||||
|
||||
/* Notify sanitizer runtime about an upcoming read/write access. */
|
||||
#define instrument_read_write(a, size) do { \
|
||||
void *__a = (void *)(a); \
|
||||
long __size = size; \
|
||||
__asan_storeN(__a, __size); \
|
||||
__msan_check_mem_is_initialized(__a, __size); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,176 @@
|
||||
/* zconf-ng.h -- configuration of the zlib-ng compression library
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef ZCONFNG_H
|
||||
#define ZCONFNG_H
|
||||
|
||||
#include "zlib_name_mangling-ng.h"
|
||||
|
||||
#if !defined(_WIN32) && defined(__WIN32__)
|
||||
# define _WIN32
|
||||
#endif
|
||||
|
||||
/* Clang macro for detecting declspec support
|
||||
* https://clang.llvm.org/docs/LanguageExtensions.html#has-declspec-attribute
|
||||
*/
|
||||
#ifndef __has_declspec_attribute
|
||||
# define __has_declspec_attribute(x) 0
|
||||
#endif
|
||||
|
||||
/* Always define z_const as const */
|
||||
#define z_const const
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# define MAX_MEM_LEVEL 9
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
||||
* created by gzip. (Files created by minigzip can still be extracted by
|
||||
* gzip.)
|
||||
*/
|
||||
#ifndef MIN_WBITS
|
||||
# define MIN_WBITS 8 /* 256 LZ77 window */
|
||||
#endif
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
|
||||
/* The memory requirements for deflate are (in bytes):
|
||||
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
#ifdef ZLIB_INTERNAL
|
||||
# define Z_INTERNAL ZLIB_INTERNAL
|
||||
#endif
|
||||
|
||||
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
||||
* This is not mandatory, but it offers a little performance increase.
|
||||
*/
|
||||
#if defined(ZLIB_DLL) && (defined(_WIN32) || (__has_declspec_attribute(dllexport) && __has_declspec_attribute(dllimport)))
|
||||
# ifdef Z_INTERNAL
|
||||
# define Z_EXTERN extern __declspec(dllexport)
|
||||
# else
|
||||
# define Z_EXTERN extern __declspec(dllimport)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
||||
* define ZLIB_WINAPI.
|
||||
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
|
||||
*/
|
||||
#if defined(ZLIB_WINAPI) && defined(_WIN32)
|
||||
# include <windows.h>
|
||||
/* No need for _export, use ZLIB.DEF instead. */
|
||||
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
||||
# define Z_EXPORT WINAPI
|
||||
# define Z_EXPORTVA WINAPIV
|
||||
#endif
|
||||
|
||||
#ifndef Z_EXTERN
|
||||
# define Z_EXTERN extern
|
||||
#endif
|
||||
#ifndef Z_EXPORT
|
||||
# define Z_EXPORT
|
||||
#endif
|
||||
#ifndef Z_EXPORTVA
|
||||
# define Z_EXPORTVA
|
||||
#endif
|
||||
|
||||
/* Conditional exports */
|
||||
#define ZNG_CONDEXPORT Z_EXPORT
|
||||
|
||||
/* Fallback for something that includes us. */
|
||||
typedef unsigned char Byte;
|
||||
typedef Byte Bytef;
|
||||
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
typedef char charf;
|
||||
typedef int intf;
|
||||
typedef uInt uIntf;
|
||||
typedef uLong uLongf;
|
||||
|
||||
typedef void const *voidpc;
|
||||
typedef void *voidpf;
|
||||
typedef void *voidp;
|
||||
|
||||
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by configure/cmake/etc */
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
|
||||
#ifdef NEED_PTRDIFF_T /* may be set to #if 1 by configure/cmake/etc */
|
||||
typedef PTRDIFF_TYPE ptrdiff_t;
|
||||
#endif
|
||||
|
||||
#include <sys/types.h> /* for off_t */
|
||||
|
||||
#include <stddef.h> /* for wchar_t and NULL */
|
||||
|
||||
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
|
||||
* "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
|
||||
* though the former does not conform to the LFS document), but considering
|
||||
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
|
||||
* equivalently requesting no 64-bit operations
|
||||
*/
|
||||
#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
|
||||
# undef _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
|
||||
# ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
|
||||
# define Z_LFS64
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
|
||||
# define Z_LARGE64
|
||||
#endif
|
||||
|
||||
#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
|
||||
# define Z_WANT64
|
||||
#endif
|
||||
|
||||
#if !defined(SEEK_SET) && defined(WITH_GZFILEOP)
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
#endif
|
||||
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||
# define z_off64_t off64_t
|
||||
#else
|
||||
# if defined(__MSYS__)
|
||||
# define z_off64_t _off64_t
|
||||
# elif defined(_WIN32) && !defined(__GNUC__)
|
||||
# define z_off64_t __int64
|
||||
# else
|
||||
# define z_off64_t z_off_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* ZCONFNG_H */
|
||||
+82
-419
@@ -3,235 +3,20 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef ZCONF_H
|
||||
#define ZCONF_H
|
||||
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
* Even better than compiling with -DZ_PREFIX would be to use configure to set
|
||||
* this permanently in zconf.h using "./configure --zprefix".
|
||||
#include "zlib_name_mangling.h"
|
||||
|
||||
#if !defined(_WIN32) && defined(__WIN32__)
|
||||
# define _WIN32
|
||||
#endif
|
||||
|
||||
/* Clang macro for detecting declspec support
|
||||
* https://clang.llvm.org/docs/LanguageExtensions.html#has-declspec-attribute
|
||||
*/
|
||||
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
|
||||
# define Z_PREFIX_SET
|
||||
|
||||
/* all linked symbols and init macros */
|
||||
# define _dist_code z__dist_code
|
||||
# define _length_code z__length_code
|
||||
# define _tr_align z__tr_align
|
||||
# define _tr_flush_bits z__tr_flush_bits
|
||||
# define _tr_flush_block z__tr_flush_block
|
||||
# define _tr_init z__tr_init
|
||||
# define _tr_stored_block z__tr_stored_block
|
||||
# define _tr_tally z__tr_tally
|
||||
# define adler32 z_adler32
|
||||
# define adler32_combine z_adler32_combine
|
||||
# define adler32_combine64 z_adler32_combine64
|
||||
# define adler32_z z_adler32_z
|
||||
# ifndef Z_SOLO
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# endif
|
||||
# define crc32 z_crc32
|
||||
# define crc32_combine z_crc32_combine
|
||||
# define crc32_combine64 z_crc32_combine64
|
||||
# define crc32_combine_gen z_crc32_combine_gen
|
||||
# define crc32_combine_gen64 z_crc32_combine_gen64
|
||||
# define crc32_combine_op z_crc32_combine_op
|
||||
# define crc32_z z_crc32_z
|
||||
# define deflate z_deflate
|
||||
# define deflateBound z_deflateBound
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define deflateGetDictionary z_deflateGetDictionary
|
||||
# define deflateInit z_deflateInit
|
||||
# define deflateInit2 z_deflateInit2
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflatePending z_deflatePending
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateResetKeep z_deflateResetKeep
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateSetHeader z_deflateSetHeader
|
||||
# define deflateTune z_deflateTune
|
||||
# define deflate_copyright z_deflate_copyright
|
||||
# define get_crc_table z_get_crc_table
|
||||
# ifndef Z_SOLO
|
||||
# define gz_error z_gz_error
|
||||
# define gz_intmax z_gz_intmax
|
||||
# define gz_strwinerror z_gz_strwinerror
|
||||
# define gzbuffer z_gzbuffer
|
||||
# define gzclearerr z_gzclearerr
|
||||
# define gzclose z_gzclose
|
||||
# define gzclose_r z_gzclose_r
|
||||
# define gzclose_w z_gzclose_w
|
||||
# define gzdirect z_gzdirect
|
||||
# define gzdopen z_gzdopen
|
||||
# define gzeof z_gzeof
|
||||
# define gzerror z_gzerror
|
||||
# define gzflush z_gzflush
|
||||
# define gzfread z_gzfread
|
||||
# define gzfwrite z_gzfwrite
|
||||
# define gzgetc z_gzgetc
|
||||
# define gzgetc_ z_gzgetc_
|
||||
# define gzgets z_gzgets
|
||||
# define gzoffset z_gzoffset
|
||||
# define gzoffset64 z_gzoffset64
|
||||
# define gzopen z_gzopen
|
||||
# define gzopen64 z_gzopen64
|
||||
# ifdef _WIN32
|
||||
# define gzopen_w z_gzopen_w
|
||||
# endif
|
||||
# define gzprintf z_gzprintf
|
||||
# define gzputc z_gzputc
|
||||
# define gzputs z_gzputs
|
||||
# define gzread z_gzread
|
||||
# define gzrewind z_gzrewind
|
||||
# define gzseek z_gzseek
|
||||
# define gzseek64 z_gzseek64
|
||||
# define gzsetparams z_gzsetparams
|
||||
# define gztell z_gztell
|
||||
# define gztell64 z_gztell64
|
||||
# define gzungetc z_gzungetc
|
||||
# define gzvprintf z_gzvprintf
|
||||
# define gzwrite z_gzwrite
|
||||
# endif
|
||||
# define inflate z_inflate
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
# define inflateBackInit z_inflateBackInit
|
||||
# define inflateBackInit_ z_inflateBackInit_
|
||||
# define inflateCodesUsed z_inflateCodesUsed
|
||||
# define inflateCopy z_inflateCopy
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define inflateGetDictionary z_inflateGetDictionary
|
||||
# define inflateGetHeader z_inflateGetHeader
|
||||
# define inflateInit z_inflateInit
|
||||
# define inflateInit2 z_inflateInit2
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflateMark z_inflateMark
|
||||
# define inflatePrime z_inflatePrime
|
||||
# define inflateReset z_inflateReset
|
||||
# define inflateReset2 z_inflateReset2
|
||||
# define inflateResetKeep z_inflateResetKeep
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateUndermine z_inflateUndermine
|
||||
# define inflateValidate z_inflateValidate
|
||||
# define inflate_copyright z_inflate_copyright
|
||||
# define inflate_fast z_inflate_fast
|
||||
# define inflate_table z_inflate_table
|
||||
# ifndef Z_SOLO
|
||||
# define uncompress z_uncompress
|
||||
# define uncompress2 z_uncompress2
|
||||
# endif
|
||||
# define zError z_zError
|
||||
# ifndef Z_SOLO
|
||||
# define zcalloc z_zcalloc
|
||||
# define zcfree z_zcfree
|
||||
# endif
|
||||
# define zlibCompileFlags z_zlibCompileFlags
|
||||
# define zlibVersion z_zlibVersion
|
||||
|
||||
/* all zlib typedefs in zlib.h and zconf.h */
|
||||
# define Byte z_Byte
|
||||
# define Bytef z_Bytef
|
||||
# define alloc_func z_alloc_func
|
||||
# define charf z_charf
|
||||
# define free_func z_free_func
|
||||
# ifndef Z_SOLO
|
||||
# define gzFile z_gzFile
|
||||
# endif
|
||||
# define gz_header z_gz_header
|
||||
# define gz_headerp z_gz_headerp
|
||||
# define in_func z_in_func
|
||||
# define intf z_intf
|
||||
# define out_func z_out_func
|
||||
# define uInt z_uInt
|
||||
# define uIntf z_uIntf
|
||||
# define uLong z_uLong
|
||||
# define uLongf z_uLongf
|
||||
# define voidp z_voidp
|
||||
# define voidpc z_voidpc
|
||||
# define voidpf z_voidpf
|
||||
|
||||
/* all zlib structs in zlib.h and zconf.h */
|
||||
# define gz_header_s z_gz_header_s
|
||||
# define internal_state z_internal_state
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||
# define MSDOS
|
||||
#endif
|
||||
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
|
||||
# define OS2
|
||||
#endif
|
||||
#if defined(_WINDOWS) && !defined(WINDOWS)
|
||||
# define WINDOWS
|
||||
#endif
|
||||
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
|
||||
# ifndef WIN32
|
||||
# define WIN32
|
||||
# endif
|
||||
#endif
|
||||
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
|
||||
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
|
||||
# ifndef SYS16BIT
|
||||
# define SYS16BIT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||
* than 64k bytes at a time (needed on systems with 16-bit int).
|
||||
*/
|
||||
#ifdef SYS16BIT
|
||||
# define MAXSEG_64K
|
||||
#endif
|
||||
#ifdef MSDOS
|
||||
# define UNALIGNED_OK
|
||||
#endif
|
||||
|
||||
#ifdef __STDC_VERSION__
|
||||
# ifndef STDC
|
||||
# define STDC
|
||||
# endif
|
||||
# if __STDC_VERSION__ >= 199901L
|
||||
# ifndef STDC99
|
||||
# define STDC99
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
|
||||
# define STDC
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#ifndef STDC
|
||||
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
||||
# define const /* note: need a more gentle solution here */
|
||||
# endif
|
||||
#ifndef __has_declspec_attribute
|
||||
# define __has_declspec_attribute(x) 0
|
||||
#endif
|
||||
|
||||
#if defined(ZLIB_CONST) && !defined(z_const)
|
||||
@@ -240,32 +25,9 @@
|
||||
# define z_const
|
||||
#endif
|
||||
|
||||
#ifdef Z_SOLO
|
||||
# ifdef _WIN64
|
||||
typedef unsigned long long z_size_t;
|
||||
# else
|
||||
typedef unsigned long z_size_t;
|
||||
# endif
|
||||
#else
|
||||
# define z_longlong long long
|
||||
# if defined(NO_SIZE_T)
|
||||
typedef unsigned NO_SIZE_T z_size_t;
|
||||
# elif defined(STDC)
|
||||
# include <stddef.h>
|
||||
typedef size_t z_size_t;
|
||||
# else
|
||||
typedef unsigned long z_size_t;
|
||||
# endif
|
||||
# undef z_longlong
|
||||
#endif
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# ifdef MAXSEG_64K
|
||||
# define MAX_MEM_LEVEL 8
|
||||
# else
|
||||
# define MAX_MEM_LEVEL 9
|
||||
# endif
|
||||
# define MAX_MEM_LEVEL 9
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||
@@ -273,6 +35,9 @@
|
||||
* created by gzip. (Files created by minigzip can still be extracted by
|
||||
* gzip.)
|
||||
*/
|
||||
#ifndef MIN_WBITS
|
||||
# define MIN_WBITS 8 /* 256 LZ77 window */
|
||||
#endif
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
@@ -290,174 +55,100 @@
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
/* Type declarations */
|
||||
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# ifdef STDC
|
||||
# define OF(args) args
|
||||
# else
|
||||
# define OF(args) ()
|
||||
# endif
|
||||
# define OF(args) args
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
||||
* just define FAR to be empty.
|
||||
#ifdef ZLIB_INTERNAL
|
||||
# define Z_INTERNAL ZLIB_INTERNAL
|
||||
#endif
|
||||
|
||||
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
||||
* This is not mandatory, but it offers a little performance increase.
|
||||
*/
|
||||
#ifdef SYS16BIT
|
||||
# if defined(M_I86SM) || defined(M_I86MM)
|
||||
/* MSC small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef _MSC_VER
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
# endif
|
||||
# if (defined(__SMALL__) || defined(__MEDIUM__))
|
||||
/* Turbo C small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef __BORLANDC__
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
#if defined(ZLIB_DLL) && (defined(_WIN32) || (__has_declspec_attribute(dllexport) && __has_declspec_attribute(dllimport)))
|
||||
# ifdef Z_INTERNAL
|
||||
# define Z_EXTERN extern __declspec(dllexport)
|
||||
# else
|
||||
# define Z_EXTERN extern __declspec(dllimport)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(WINDOWS) || defined(WIN32)
|
||||
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
||||
* This is not mandatory, but it offers a little performance increase.
|
||||
*/
|
||||
# ifdef ZLIB_DLL
|
||||
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
|
||||
# ifdef ZLIB_INTERNAL
|
||||
# define ZEXTERN extern __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXTERN extern __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
# endif /* ZLIB_DLL */
|
||||
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
||||
* define ZLIB_WINAPI.
|
||||
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
|
||||
*/
|
||||
# ifdef ZLIB_WINAPI
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# endif
|
||||
# include <windows.h>
|
||||
/* No need for _export, use ZLIB.DEF instead. */
|
||||
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
||||
# define ZEXPORT WINAPI
|
||||
# ifdef WIN32
|
||||
# define ZEXPORTVA WINAPIV
|
||||
# else
|
||||
# define ZEXPORTVA FAR CDECL
|
||||
# endif
|
||||
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
||||
* define ZLIB_WINAPI.
|
||||
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
|
||||
*/
|
||||
#if defined(ZLIB_WINAPI) && defined(_WIN32)
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# endif
|
||||
# include <windows.h>
|
||||
/* No need for _export, use ZLIB.DEF instead. */
|
||||
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
||||
# define Z_EXPORT WINAPI
|
||||
# define Z_EXPORTVA WINAPIV
|
||||
#endif
|
||||
|
||||
#if defined (__BEOS__)
|
||||
# ifdef ZLIB_DLL
|
||||
# ifdef ZLIB_INTERNAL
|
||||
# define ZEXPORT __declspec(dllexport)
|
||||
# define ZEXPORTVA __declspec(dllexport)
|
||||
# else
|
||||
# define ZEXPORT __declspec(dllimport)
|
||||
# define ZEXPORTVA __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
#ifndef Z_EXTERN
|
||||
# define Z_EXTERN extern
|
||||
#endif
|
||||
#ifndef Z_EXPORT
|
||||
# define Z_EXPORT
|
||||
#endif
|
||||
#ifndef Z_EXPORTVA
|
||||
# define Z_EXPORTVA
|
||||
#endif
|
||||
|
||||
/* Conditional exports */
|
||||
#define ZNG_CONDEXPORT Z_INTERNAL
|
||||
|
||||
/* For backwards compatibility */
|
||||
|
||||
#ifndef ZEXTERN
|
||||
# define ZEXTERN extern
|
||||
# define ZEXTERN Z_EXTERN
|
||||
#endif
|
||||
#ifndef ZEXPORT
|
||||
# define ZEXPORT
|
||||
# define ZEXPORT Z_EXPORT
|
||||
#endif
|
||||
#ifndef ZEXPORTVA
|
||||
# define ZEXPORTVA
|
||||
# define ZEXPORTVA Z_EXPORTVA
|
||||
#endif
|
||||
|
||||
#ifndef FAR
|
||||
# define FAR
|
||||
#endif
|
||||
|
||||
#if !defined(__MACTYPES__)
|
||||
typedef unsigned char Byte; /* 8 bits */
|
||||
#endif
|
||||
/* Legacy zlib typedefs for backwards compatibility. Don't assume stdint.h is defined. */
|
||||
typedef unsigned char Byte;
|
||||
typedef Byte Bytef;
|
||||
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
#ifdef SMALL_MEDIUM
|
||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||
# define Bytef Byte FAR
|
||||
#else
|
||||
typedef Byte FAR Bytef;
|
||||
#endif
|
||||
typedef char FAR charf;
|
||||
typedef int FAR intf;
|
||||
typedef uInt FAR uIntf;
|
||||
typedef uLong FAR uLongf;
|
||||
typedef char charf;
|
||||
typedef int intf;
|
||||
typedef uInt uIntf;
|
||||
typedef uLong uLongf;
|
||||
|
||||
#ifdef STDC
|
||||
typedef void const *voidpc;
|
||||
typedef void FAR *voidpf;
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef Byte const *voidpc;
|
||||
typedef Byte FAR *voidpf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
typedef void const *voidpc;
|
||||
typedef void *voidpf;
|
||||
typedef void *voidp;
|
||||
|
||||
#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
|
||||
# include <limits.h>
|
||||
# if (UINT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned
|
||||
# elif (ULONG_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned long
|
||||
# elif (USHRT_MAX == 0xffffffffUL)
|
||||
# define Z_U4 unsigned short
|
||||
# endif
|
||||
#endif
|
||||
typedef unsigned int z_crc_t;
|
||||
|
||||
#ifdef Z_U4
|
||||
typedef Z_U4 z_crc_t;
|
||||
#else
|
||||
typedef unsigned long z_crc_t;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
|
||||
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by configure/cmake/etc */
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_STDARG_H
|
||||
#ifdef NEED_PTRDIFF_T /* may be set to #if 1 by configure/cmake/etc */
|
||||
typedef PTRDIFF_TYPE ptrdiff_t;
|
||||
#endif
|
||||
|
||||
#ifdef STDC
|
||||
# ifndef Z_SOLO
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# endif
|
||||
#endif
|
||||
#include <sys/types.h> /* for off_t */
|
||||
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# ifndef Z_SOLO
|
||||
# include <stdarg.h> /* for va_list */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifndef Z_SOLO
|
||||
# include <stddef.h> /* for wchar_t */
|
||||
# endif
|
||||
#endif
|
||||
#include <stddef.h> /* for wchar_t and NULL */
|
||||
|
||||
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
|
||||
* "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
|
||||
@@ -469,25 +160,10 @@ typedef uLong FAR uLongf;
|
||||
# undef _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#ifndef Z_HAVE_UNISTD_H
|
||||
# ifdef __WATCOMC__
|
||||
# define Z_HAVE_UNISTD_H
|
||||
# endif
|
||||
#endif
|
||||
#ifndef Z_HAVE_UNISTD_H
|
||||
# if defined(_LARGEFILE64_SOURCE) && !defined(_WIN32)
|
||||
# define Z_HAVE_UNISTD_H
|
||||
# endif
|
||||
#endif
|
||||
#ifndef Z_SOLO
|
||||
# if defined(Z_HAVE_UNISTD_H)
|
||||
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
# endif
|
||||
#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
|
||||
# ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -503,7 +179,7 @@ typedef uLong FAR uLongf;
|
||||
# define Z_WANT64
|
||||
#endif
|
||||
|
||||
#if !defined(SEEK_SET) && !defined(Z_SOLO)
|
||||
#if !defined(SEEK_SET)
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
@@ -516,28 +192,15 @@ typedef uLong FAR uLongf;
|
||||
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||
# define z_off64_t off64_t
|
||||
#else
|
||||
# if defined(_WIN32) && !defined(__GNUC__)
|
||||
# if defined(__MSYS__)
|
||||
# define z_off64_t _off64_t
|
||||
# elif defined(_WIN32) && !defined(__GNUC__)
|
||||
# define z_off64_t __int64
|
||||
# else
|
||||
# define z_off64_t z_off_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
#if defined(__MVS__)
|
||||
#pragma map(deflateInit_,"DEIN")
|
||||
#pragma map(deflateInit2_,"DEIN2")
|
||||
#pragma map(deflateEnd,"DEEND")
|
||||
#pragma map(deflateBound,"DEBND")
|
||||
#pragma map(inflateInit_,"ININ")
|
||||
#pragma map(inflateInit2_,"ININ2")
|
||||
#pragma map(inflateEnd,"INEND")
|
||||
#pragma map(inflateSync,"INSY")
|
||||
#pragma map(inflateSetDictionary,"INSEDI")
|
||||
#pragma map(compressBound,"CMBND")
|
||||
#pragma map(inflate_table,"INTABL")
|
||||
#pragma map(inflate_fast,"INFA")
|
||||
#pragma map(inflate_copyright,"INCOPY")
|
||||
#endif
|
||||
typedef size_t z_size_t;
|
||||
|
||||
#endif /* ZCONF_H */
|
||||
@@ -0,0 +1,60 @@
|
||||
/* zendian.h -- define BYTE_ORDER for endian tests
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef ENDIAN_H_
|
||||
#define ENDIAN_H_
|
||||
|
||||
/* First check whether the compiler knows the target __BYTE_ORDER__. */
|
||||
#if defined(__BYTE_ORDER__)
|
||||
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
# if !defined(LITTLE_ENDIAN)
|
||||
# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
|
||||
# endif
|
||||
# if !defined(BYTE_ORDER)
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
# endif
|
||||
# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
# if !defined(BIG_ENDIAN)
|
||||
# define BIG_ENDIAN __ORDER_BIG_ENDIAN__
|
||||
# endif
|
||||
# if !defined(BYTE_ORDER)
|
||||
# define BYTE_ORDER BIG_ENDIAN
|
||||
# endif
|
||||
# endif
|
||||
#elif defined(__MINGW32__)
|
||||
# include <sys/param.h>
|
||||
#elif defined(_WIN32)
|
||||
# define LITTLE_ENDIAN 1234
|
||||
# define BIG_ENDIAN 4321
|
||||
# if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined (_M_ARM) || defined (_M_ARM64) || defined (_M_ARM64EC)
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
# else
|
||||
# error Unknown endianness!
|
||||
# endif
|
||||
#elif defined(__linux__)
|
||||
# include <endian.h>
|
||||
#elif defined(__APPLE__)
|
||||
# include <machine/endian.h>
|
||||
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__)
|
||||
# include <sys/endian.h>
|
||||
#elif defined(__sun) || defined(sun)
|
||||
# include <sys/byteorder.h>
|
||||
# if !defined(LITTLE_ENDIAN)
|
||||
# define LITTLE_ENDIAN 4321
|
||||
# endif
|
||||
# if !defined(BIG_ENDIAN)
|
||||
# define BIG_ENDIAN 1234
|
||||
# endif
|
||||
# if !defined(BYTE_ORDER)
|
||||
# if defined(_BIG_ENDIAN)
|
||||
# define BYTE_ORDER BIG_ENDIAN
|
||||
# else
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
# include <endian.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
set(ZLIB_VERSION @ZLIB_HEADER_VERSION@)
|
||||
|
||||
@PACKAGE_INIT@
|
||||
|
||||
set_and_check(ZLIB_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
|
||||
set(ZLIB_INCLUDE_DIRS "${ZLIB_INCLUDE_DIR}")
|
||||
set_and_check(ZLIB_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@")
|
||||
set(ZLIB_LIBRARIES ZLIB::ZLIB)
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/ZLIB.cmake")
|
||||
|
||||
check_required_components(ZLIB)
|
||||
@@ -0,0 +1,10 @@
|
||||
set(zlib-ng_VERSION @ZLIBNG_HEADER_VERSION@)
|
||||
|
||||
@PACKAGE_INIT@
|
||||
|
||||
set_and_check(zlib-ng_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
|
||||
set_and_check(zlib-ng_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@")
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/zlib-ng.cmake")
|
||||
|
||||
check_required_components(zlib-ng)
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,111 @@
|
||||
ZLIB_NG_2.1.0 {
|
||||
global:
|
||||
zng_deflateInit;
|
||||
zng_deflateInit2;
|
||||
zng_inflateBackInit;
|
||||
zng_inflateInit;
|
||||
zng_inflateInit2;
|
||||
zlibng_version;
|
||||
};
|
||||
|
||||
ZLIB_NG_2.0.0 {
|
||||
global:
|
||||
zng_adler32;
|
||||
zng_adler32_combine;
|
||||
zng_adler32_z;
|
||||
zng_compress;
|
||||
zng_compress2;
|
||||
zng_compressBound;
|
||||
zng_crc32;
|
||||
zng_crc32_combine;
|
||||
zng_crc32_combine_gen;
|
||||
zng_crc32_combine_op;
|
||||
zng_crc32_z;
|
||||
zng_deflate;
|
||||
zng_deflateBound;
|
||||
zng_deflateCopy;
|
||||
zng_deflateEnd;
|
||||
zng_deflateGetDictionary;
|
||||
zng_deflateGetParams;
|
||||
zng_deflateInit_;
|
||||
zng_deflateInit2_;
|
||||
zng_deflateParams;
|
||||
zng_deflatePending;
|
||||
zng_deflatePrime;
|
||||
zng_deflateReset;
|
||||
zng_deflateResetKeep;
|
||||
zng_deflateSetDictionary;
|
||||
zng_deflateSetHeader;
|
||||
zng_deflateSetParams;
|
||||
zng_deflateTune;
|
||||
zng_get_crc_table;
|
||||
zng_inflate;
|
||||
zng_inflateBack;
|
||||
zng_inflateBackEnd;
|
||||
zng_inflateBackInit_;
|
||||
zng_inflateCodesUsed;
|
||||
zng_inflateCopy;
|
||||
zng_inflateEnd;
|
||||
zng_inflateGetDictionary;
|
||||
zng_inflateGetHeader;
|
||||
zng_inflateInit_;
|
||||
zng_inflateInit2_;
|
||||
zng_inflateMark;
|
||||
zng_inflatePrime;
|
||||
zng_inflateReset;
|
||||
zng_inflateReset2;
|
||||
zng_inflateResetKeep;
|
||||
zng_inflateSetDictionary;
|
||||
zng_inflateSync;
|
||||
zng_inflateSyncPoint;
|
||||
zng_inflateUndermine;
|
||||
zng_inflateValidate;
|
||||
zng_uncompress;
|
||||
zng_uncompress2;
|
||||
zng_zError;
|
||||
zng_zlibCompileFlags;
|
||||
zng_vstring;
|
||||
local:
|
||||
zng_deflate_copyright;
|
||||
zng_inflate_copyright;
|
||||
zng_zcalloc;
|
||||
zng_zcfree;
|
||||
zng_z_errmsg;
|
||||
gz_error;
|
||||
_*;
|
||||
};
|
||||
|
||||
ZLIB_NG_GZ_2.0.0 {
|
||||
global:
|
||||
zng_gzbuffer;
|
||||
zng_gzclearerr;
|
||||
zng_gzclose;
|
||||
zng_gzclose_r;
|
||||
zng_gzclose_w;
|
||||
zng_gzdirect;
|
||||
zng_gzdopen;
|
||||
zng_gzeof;
|
||||
zng_gzerror;
|
||||
zng_gzflush;
|
||||
zng_gzfread;
|
||||
zng_gzfwrite;
|
||||
zng_gzgetc;
|
||||
zng_gzgets;
|
||||
zng_gzoffset;
|
||||
zng_gzopen;
|
||||
zng_gzprintf;
|
||||
zng_gzputc;
|
||||
zng_gzputs;
|
||||
zng_gzread;
|
||||
zng_gzrewind;
|
||||
zng_gzseek;
|
||||
zng_gzsetparams;
|
||||
zng_gztell;
|
||||
zng_gzungetc;
|
||||
zng_gzvprintf;
|
||||
zng_gzwrite;
|
||||
};
|
||||
|
||||
FAIL {
|
||||
local: *;
|
||||
};
|
||||
+1859
File diff suppressed because it is too large.
Load diff
+3
-5
@@ -9,8 +9,6 @@ ZLIB_1.2.0 {
|
||||
local:
|
||||
deflate_copyright;
|
||||
inflate_copyright;
|
||||
inflate_fast;
|
||||
inflate_table;
|
||||
zcalloc;
|
||||
zcfree;
|
||||
z_errmsg;
|
||||
@@ -94,7 +92,7 @@ ZLIB_1.2.9 {
|
||||
} ZLIB_1.2.7.1;
|
||||
|
||||
ZLIB_1.2.12 {
|
||||
crc32_combine_gen;
|
||||
crc32_combine_gen64;
|
||||
crc32_combine_op;
|
||||
crc32_combine_gen;
|
||||
crc32_combine_gen64;
|
||||
crc32_combine_op;
|
||||
} ZLIB_1.2.9;
|
||||
@@ -1,13 +1,14 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=@CMAKE_INSTALL_PREFIX@
|
||||
libdir=@INSTALL_LIB_DIR@
|
||||
sharedlibdir=@INSTALL_LIB_DIR@
|
||||
includedir=@INSTALL_INC_DIR@
|
||||
exec_prefix=${prefix}
|
||||
symbol_prefix=@ZLIB_SYMBOL_PREFIX@
|
||||
libdir=@PC_LIB_INSTALL_DIR@
|
||||
sharedlibdir=${libdir}
|
||||
includedir=@PC_INC_INSTALL_DIR@
|
||||
|
||||
Name: zlib
|
||||
Description: zlib compression library
|
||||
Version: @VERSION@
|
||||
Name: zlib@SUFFIX@
|
||||
Description: zlib-ng compression library
|
||||
Version: @ZLIB_FULL_VERSION@
|
||||
|
||||
Requires:
|
||||
Libs: -L${libdir} -L${sharedlibdir} -lz
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} -L${sharedlibdir} -lz@SUFFIX@
|
||||
Cflags: -I${includedir} @PKG_CONFIG_CFLAGS@
|
||||
@@ -1,13 +1,14 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
symbol_prefix=@symbol_prefix@
|
||||
libdir=@libdir@
|
||||
sharedlibdir=@sharedlibdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: zlib
|
||||
Description: zlib compression library
|
||||
Name: zlib@SUFFIX@
|
||||
Description: zlib-ng compression library
|
||||
Version: @VERSION@
|
||||
|
||||
Requires:
|
||||
Libs: -L${libdir} -L${sharedlibdir} -lz
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} -L${sharedlibdir} -lz@SUFFIX@
|
||||
Cflags: -I${includedir} @PKG_CONFIG_CFLAGS@
|
||||
@@ -0,0 +1,178 @@
|
||||
/* zlib_name_mangling.h has been automatically generated from
|
||||
* zlib_name_mangling.h.in because ZLIB_SYMBOL_PREFIX was set.
|
||||
*/
|
||||
|
||||
#ifndef ZLIB_NAME_MANGLING_H
|
||||
#define ZLIB_NAME_MANGLING_H
|
||||
|
||||
/* all linked symbols and init macros */
|
||||
#define zng__dist_code @ZLIB_SYMBOL_PREFIX@zng__dist_code
|
||||
#define zng__length_code @ZLIB_SYMBOL_PREFIX@zng__length_code
|
||||
#define zng__tr_align @ZLIB_SYMBOL_PREFIX@zng__tr_align
|
||||
#define zng__tr_flush_bits @ZLIB_SYMBOL_PREFIX@zng__tr_flush_bits
|
||||
#define zng__tr_flush_block @ZLIB_SYMBOL_PREFIX@zng__tr_flush_block
|
||||
#define zng__tr_init @ZLIB_SYMBOL_PREFIX@zng__tr_init
|
||||
#define zng__tr_stored_block @ZLIB_SYMBOL_PREFIX@zng__tr_stored_block
|
||||
#define zng__tr_tally @ZLIB_SYMBOL_PREFIX@zng__tr_tally
|
||||
#define zng_adler32 @ZLIB_SYMBOL_PREFIX@zng_adler32
|
||||
#define zng_adler32_combine @ZLIB_SYMBOL_PREFIX@zng_adler32_combine
|
||||
#define zng_adler32_combine64 @ZLIB_SYMBOL_PREFIX@zng_adler32_combine64
|
||||
#define zng_adler32_z @ZLIB_SYMBOL_PREFIX@zng_adler32_z
|
||||
#define zng_compress @ZLIB_SYMBOL_PREFIX@zng_compress
|
||||
#define zng_compress2 @ZLIB_SYMBOL_PREFIX@zng_compress2
|
||||
#define zng_compressBound @ZLIB_SYMBOL_PREFIX@zng_compressBound
|
||||
#define zng_crc32 @ZLIB_SYMBOL_PREFIX@zng_crc32
|
||||
#define zng_crc32_combine @ZLIB_SYMBOL_PREFIX@zng_crc32_combine
|
||||
#define zng_crc32_combine64 @ZLIB_SYMBOL_PREFIX@zng_crc32_combine64
|
||||
#define zng_crc32_combine_gen @ZLIB_SYMBOL_PREFIX@zng_crc32_combine_gen
|
||||
#define zng_crc32_combine_gen64 @ZLIB_SYMBOL_PREFIX@zng_crc32_combine_gen64
|
||||
#define zng_crc32_combine_op @ZLIB_SYMBOL_PREFIX@zng_crc32_combine_op
|
||||
#define zng_crc32_z @ZLIB_SYMBOL_PREFIX@zng_crc32_z
|
||||
#define zng_deflate @ZLIB_SYMBOL_PREFIX@zng_deflate
|
||||
#define zng_deflateBound @ZLIB_SYMBOL_PREFIX@zng_deflateBound
|
||||
#define zng_deflateCopy @ZLIB_SYMBOL_PREFIX@zng_deflateCopy
|
||||
#define zng_deflateEnd @ZLIB_SYMBOL_PREFIX@zng_deflateEnd
|
||||
#define zng_deflateGetDictionary @ZLIB_SYMBOL_PREFIX@zng_deflateGetDictionary
|
||||
#define zng_deflateInit @ZLIB_SYMBOL_PREFIX@zng_deflateInit
|
||||
#define zng_deflateInit2 @ZLIB_SYMBOL_PREFIX@zng_deflateInit2
|
||||
#define zng_deflateInit2_ @ZLIB_SYMBOL_PREFIX@zng_deflateInit2_
|
||||
#define zng_deflateInit_ @ZLIB_SYMBOL_PREFIX@zng_deflateInit_
|
||||
#define zng_deflateParams @ZLIB_SYMBOL_PREFIX@zng_deflateParams
|
||||
#define zng_deflatePending @ZLIB_SYMBOL_PREFIX@zng_deflatePending
|
||||
#define zng_deflatePrime @ZLIB_SYMBOL_PREFIX@zng_deflatePrime
|
||||
#define zng_deflateReset @ZLIB_SYMBOL_PREFIX@zng_deflateReset
|
||||
#define zng_deflateResetKeep @ZLIB_SYMBOL_PREFIX@zng_deflateResetKeep
|
||||
#define zng_deflateSetDictionary @ZLIB_SYMBOL_PREFIX@zng_deflateSetDictionary
|
||||
#define zng_deflateSetHeader @ZLIB_SYMBOL_PREFIX@zng_deflateSetHeader
|
||||
#define zng_deflateTune @ZLIB_SYMBOL_PREFIX@zng_deflateTune
|
||||
#define zng_deflate_copyright @ZLIB_SYMBOL_PREFIX@zng_deflate_copyright
|
||||
#define zng_fill_window @ZLIB_SYMBOL_PREFIX@zng_fill_window
|
||||
#define zng_fixedtables @ZLIB_SYMBOL_PREFIX@zng_fixedtables
|
||||
#define zng_flush_pending @ZLIB_SYMBOL_PREFIX@zng_flush_pending
|
||||
#define zng_get_crc_table @ZLIB_SYMBOL_PREFIX@zng_get_crc_table
|
||||
#ifdef WITH_GZFILEOP
|
||||
# define zng_gz_error @ZLIB_SYMBOL_PREFIX@zng_gz_error
|
||||
# define zng_gz_strwinerror @ZLIB_SYMBOL_PREFIX@zng_gz_strwinerror
|
||||
# define zng_gzbuffer @ZLIB_SYMBOL_PREFIX@zng_gzbuffer
|
||||
# define zng_gzclearerr @ZLIB_SYMBOL_PREFIX@zng_gzclearerr
|
||||
# define zng_gzclose @ZLIB_SYMBOL_PREFIX@zng_gzclose
|
||||
# define zng_gzclose_r @ZLIB_SYMBOL_PREFIX@zng_gzclose_r
|
||||
# define zng_gzclose_w @ZLIB_SYMBOL_PREFIX@zng_gzclose_w
|
||||
# define zng_gzdirect @ZLIB_SYMBOL_PREFIX@zng_gzdirect
|
||||
# define zng_gzdopen @ZLIB_SYMBOL_PREFIX@zng_gzdopen
|
||||
# define zng_gzeof @ZLIB_SYMBOL_PREFIX@zng_gzeof
|
||||
# define zng_gzerror @ZLIB_SYMBOL_PREFIX@zng_gzerror
|
||||
# define zng_gzflush @ZLIB_SYMBOL_PREFIX@zng_gzflush
|
||||
# define zng_gzfread @ZLIB_SYMBOL_PREFIX@zng_gzfread
|
||||
# define zng_gzfwrite @ZLIB_SYMBOL_PREFIX@zng_gzfwrite
|
||||
# define zng_gzgetc @ZLIB_SYMBOL_PREFIX@zng_gzgetc
|
||||
# define zng_gzgetc_ @ZLIB_SYMBOL_PREFIX@zng_gzgetc_
|
||||
# define zng_gzgets @ZLIB_SYMBOL_PREFIX@zng_gzgets
|
||||
# define zng_gzoffset @ZLIB_SYMBOL_PREFIX@zng_gzoffset
|
||||
# define zng_gzoffset64 @ZLIB_SYMBOL_PREFIX@zng_gzoffset64
|
||||
# define zng_gzopen @ZLIB_SYMBOL_PREFIX@zng_gzopen
|
||||
# define zng_gzopen64 @ZLIB_SYMBOL_PREFIX@zng_gzopen64
|
||||
# ifdef _WIN32
|
||||
# define zng_gzopen_w @ZLIB_SYMBOL_PREFIX@zng_gzopen_w
|
||||
# endif
|
||||
# define zng_gzprintf @ZLIB_SYMBOL_PREFIX@zng_gzprintf
|
||||
# define zng_gzputc @ZLIB_SYMBOL_PREFIX@zng_gzputc
|
||||
# define zng_gzputs @ZLIB_SYMBOL_PREFIX@zng_gzputs
|
||||
# define zng_gzread @ZLIB_SYMBOL_PREFIX@zng_gzread
|
||||
# define zng_gzrewind @ZLIB_SYMBOL_PREFIX@zng_gzrewind
|
||||
# define zng_gzseek @ZLIB_SYMBOL_PREFIX@zng_gzseek
|
||||
# define zng_gzseek64 @ZLIB_SYMBOL_PREFIX@zng_gzseek64
|
||||
# define zng_gzsetparams @ZLIB_SYMBOL_PREFIX@zng_gzsetparams
|
||||
# define zng_gztell @ZLIB_SYMBOL_PREFIX@zng_gztell
|
||||
# define zng_gztell64 @ZLIB_SYMBOL_PREFIX@zng_gztell64
|
||||
# define zng_gzungetc @ZLIB_SYMBOL_PREFIX@zng_gzungetc
|
||||
# define zng_gzvprintf @ZLIB_SYMBOL_PREFIX@zng_gzvprintf
|
||||
# define zng_gzwrite @ZLIB_SYMBOL_PREFIX@zng_gzwrite
|
||||
#endif
|
||||
#define zng_inflate @ZLIB_SYMBOL_PREFIX@zng_inflate
|
||||
#define zng_inflateBack @ZLIB_SYMBOL_PREFIX@zng_inflateBack
|
||||
#define zng_inflateBackEnd @ZLIB_SYMBOL_PREFIX@zng_inflateBackEnd
|
||||
#define zng_inflateBackInit @ZLIB_SYMBOL_PREFIX@zng_inflateBackInit
|
||||
#define zng_inflateBackInit_ @ZLIB_SYMBOL_PREFIX@zng_inflateBackInit_
|
||||
#define zng_inflateCodesUsed @ZLIB_SYMBOL_PREFIX@zng_inflateCodesUsed
|
||||
#define zng_inflateCopy @ZLIB_SYMBOL_PREFIX@zng_inflateCopy
|
||||
#define zng_inflateEnd @ZLIB_SYMBOL_PREFIX@zng_inflateEnd
|
||||
#define zng_inflateGetDictionary @ZLIB_SYMBOL_PREFIX@zng_inflateGetDictionary
|
||||
#define zng_inflateGetHeader @ZLIB_SYMBOL_PREFIX@zng_inflateGetHeader
|
||||
#define zng_inflateInit @ZLIB_SYMBOL_PREFIX@zng_inflateInit
|
||||
#define zng_inflateInit2 @ZLIB_SYMBOL_PREFIX@zng_inflateInit2
|
||||
#define zng_inflateInit2_ @ZLIB_SYMBOL_PREFIX@zng_inflateInit2_
|
||||
#define zng_inflateInit_ @ZLIB_SYMBOL_PREFIX@zng_inflateInit_
|
||||
#define zng_inflateMark @ZLIB_SYMBOL_PREFIX@zng_inflateMark
|
||||
#define zng_inflatePrime @ZLIB_SYMBOL_PREFIX@zng_inflatePrime
|
||||
#define zng_inflateReset @ZLIB_SYMBOL_PREFIX@zng_inflateReset
|
||||
#define zng_inflateReset2 @ZLIB_SYMBOL_PREFIX@zng_inflateReset2
|
||||
#define zng_inflateResetKeep @ZLIB_SYMBOL_PREFIX@zng_inflateResetKeep
|
||||
#define zng_inflateSetDictionary @ZLIB_SYMBOL_PREFIX@zng_inflateSetDictionary
|
||||
#define zng_inflateSync @ZLIB_SYMBOL_PREFIX@zng_inflateSync
|
||||
#define zng_inflateSyncPoint @ZLIB_SYMBOL_PREFIX@zng_inflateSyncPoint
|
||||
#define zng_inflateUndermine @ZLIB_SYMBOL_PREFIX@zng_inflateUndermine
|
||||
#define zng_inflateValidate @ZLIB_SYMBOL_PREFIX@zng_inflateValidate
|
||||
#define zng_inflate_copyright @ZLIB_SYMBOL_PREFIX@zng_inflate_copyright
|
||||
#define zng_inflate_ensure_window @ZLIB_SYMBOL_PREFIX@zng_inflate_ensure_window
|
||||
#define zng_inflate_fast @ZLIB_SYMBOL_PREFIX@zng_inflate_fast
|
||||
#define zng_inflate_table @ZLIB_SYMBOL_PREFIX@zng_inflate_table
|
||||
#define zng_read_buf @ZLIB_SYMBOL_PREFIX@zng_read_buf
|
||||
#define zng_uncompress @ZLIB_SYMBOL_PREFIX@zng_uncompress
|
||||
#define zng_uncompress2 @ZLIB_SYMBOL_PREFIX@zng_uncompress2
|
||||
#define zng_zError @ZLIB_SYMBOL_PREFIX@zng_zError
|
||||
#define zng_zcalloc @ZLIB_SYMBOL_PREFIX@zng_zcalloc
|
||||
#define zng_zcfree @ZLIB_SYMBOL_PREFIX@zng_zcfree
|
||||
#define zng_zlibCompileFlags @ZLIB_SYMBOL_PREFIX@zng_zlibCompileFlags
|
||||
#define zng_zlibVersion @ZLIB_SYMBOL_PREFIX@zng_zlibVersion
|
||||
|
||||
/* all zlib typedefs in zlib.h and zconf.h */
|
||||
#define Byte @ZLIB_SYMBOL_PREFIX@Byte
|
||||
#define Bytef @ZLIB_SYMBOL_PREFIX@Bytef
|
||||
#define alloc_func @ZLIB_SYMBOL_PREFIX@alloc_func
|
||||
#define charf @ZLIB_SYMBOL_PREFIX@charf
|
||||
#define free_func @ZLIB_SYMBOL_PREFIX@free_func
|
||||
#ifdef WITH_GZFILEOP
|
||||
# define gzFile @ZLIB_SYMBOL_PREFIX@gzFile
|
||||
#endif
|
||||
#define gz_header @ZLIB_SYMBOL_PREFIX@gz_header
|
||||
#define gz_headerp @ZLIB_SYMBOL_PREFIX@gz_headerp
|
||||
#define in_func @ZLIB_SYMBOL_PREFIX@in_func
|
||||
#define intf @ZLIB_SYMBOL_PREFIX@intf
|
||||
#define out_func @ZLIB_SYMBOL_PREFIX@out_func
|
||||
#define uInt @ZLIB_SYMBOL_PREFIX@uInt
|
||||
#define uIntf @ZLIB_SYMBOL_PREFIX@uIntf
|
||||
#define uLong @ZLIB_SYMBOL_PREFIX@uLong
|
||||
#define uLongf @ZLIB_SYMBOL_PREFIX@uLongf
|
||||
#define voidp @ZLIB_SYMBOL_PREFIX@voidp
|
||||
#define voidpc @ZLIB_SYMBOL_PREFIX@voidpc
|
||||
#define voidpf @ZLIB_SYMBOL_PREFIX@voidpf
|
||||
|
||||
/* all zlib structs in zlib.h and zconf.h */
|
||||
#define zng_gz_header_s @ZLIB_SYMBOL_PREFIX@zng_gz_header_s
|
||||
#define internal_state @ZLIB_SYMBOL_PREFIX@internal_state
|
||||
|
||||
/* zlib-ng specific symbols */
|
||||
#define zng_deflate_param @ZLIB_SYMBOL_PREFIX@zng_deflate_param
|
||||
#define zng_deflate_param_value @ZLIB_SYMBOL_PREFIX@zng_deflate_param_value
|
||||
#define zng_deflateSetParams @ZLIB_SYMBOL_PREFIX@zng_deflateSetParams
|
||||
#define zng_deflateGetParams @ZLIB_SYMBOL_PREFIX@zng_deflateGetParams
|
||||
|
||||
#define zlibng_version @ZLIB_SYMBOL_PREFIX@zlibng_version
|
||||
#define zng_vstring @ZLIB_SYMBOL_PREFIX@zng_vstring
|
||||
#define zng_zError @ZLIB_SYMBOL_PREFIX@zng_zError
|
||||
|
||||
#define zng_alloc_aligned @ZLIB_SYMBOL_PREFIX@zng_alloc_aligned
|
||||
#define zng_free_aligned @ZLIB_SYMBOL_PREFIX@zng_free_aligned
|
||||
#define zng_get_crc_table @ZLIB_SYMBOL_PREFIX@zng_get_crc_table
|
||||
#define zng_inflateSyncPoint @ZLIB_SYMBOL_PREFIX@zng_inflateSyncPoint
|
||||
#define zng_inflateUndermine @ZLIB_SYMBOL_PREFIX@zng_inflateUndermine
|
||||
#define zng_inflateValidate @ZLIB_SYMBOL_PREFIX@zng_inflateValidate
|
||||
#define zng_inflateCodesUsed @ZLIB_SYMBOL_PREFIX@zng_inflateCodesUsed
|
||||
#define zng_inflateResetKeep @ZLIB_SYMBOL_PREFIX@zng_inflateResetKeep
|
||||
#define zng_deflateResetKeep @ZLIB_SYMBOL_PREFIX@zng_deflateResetKeep
|
||||
|
||||
#define zng_gzopen_w @ZLIB_SYMBOL_PREFIX@zng_gzopen_w
|
||||
#define zng_gzvprintf @ZLIB_SYMBOL_PREFIX@zng_gzvprintf
|
||||
|
||||
#endif /* ZLIB_NAME_MANGLING_H */
|
||||
@@ -0,0 +1,8 @@
|
||||
/* zlib_name_mangling.h has been automatically generated from
|
||||
* zlib_name_mangling.h.empty because ZLIB_SYMBOL_PREFIX was NOT set.
|
||||
*/
|
||||
|
||||
#ifndef ZLIB_NAME_MANGLING_H
|
||||
#define ZLIB_NAME_MANGLING_H
|
||||
|
||||
#endif /* ZLIB_NAME_MANGLING_H */
|
||||
@@ -0,0 +1,170 @@
|
||||
/* zlib_name_mangling.h has been automatically generated from
|
||||
* zlib_name_mangling.h.in because ZLIB_SYMBOL_PREFIX was set.
|
||||
*/
|
||||
|
||||
#ifndef ZLIB_NAME_MANGLING_H
|
||||
#define ZLIB_NAME_MANGLING_H
|
||||
|
||||
/* all linked symbols and init macros */
|
||||
#define _dist_code @ZLIB_SYMBOL_PREFIX@_dist_code
|
||||
#define _length_code @ZLIB_SYMBOL_PREFIX@_length_code
|
||||
#define _tr_align @ZLIB_SYMBOL_PREFIX@_tr_align
|
||||
#define _tr_flush_bits @ZLIB_SYMBOL_PREFIX@_tr_flush_bits
|
||||
#define _tr_flush_block @ZLIB_SYMBOL_PREFIX@_tr_flush_block
|
||||
#define _tr_init @ZLIB_SYMBOL_PREFIX@_tr_init
|
||||
#define _tr_stored_block @ZLIB_SYMBOL_PREFIX@_tr_stored_block
|
||||
#define _tr_tally @ZLIB_SYMBOL_PREFIX@_tr_tally
|
||||
#define adler32 @ZLIB_SYMBOL_PREFIX@adler32
|
||||
#define adler32_combine @ZLIB_SYMBOL_PREFIX@adler32_combine
|
||||
#define adler32_combine64 @ZLIB_SYMBOL_PREFIX@adler32_combine64
|
||||
#define adler32_z @ZLIB_SYMBOL_PREFIX@adler32_z
|
||||
#ifndef Z_SOLO
|
||||
# define compress @ZLIB_SYMBOL_PREFIX@compress
|
||||
# define compress2 @ZLIB_SYMBOL_PREFIX@compress2
|
||||
# define compressBound @ZLIB_SYMBOL_PREFIX@compressBound
|
||||
#endif
|
||||
#define crc32 @ZLIB_SYMBOL_PREFIX@crc32
|
||||
#define crc32_combine @ZLIB_SYMBOL_PREFIX@crc32_combine
|
||||
#define crc32_combine64 @ZLIB_SYMBOL_PREFIX@crc32_combine64
|
||||
#define crc32_combine_gen @ZLIB_SYMBOL_PREFIX@crc32_combine_gen
|
||||
#define crc32_combine_gen64 @ZLIB_SYMBOL_PREFIX@crc32_combine_gen64
|
||||
#define crc32_combine_op @ZLIB_SYMBOL_PREFIX@crc32_combine_op
|
||||
#define crc32_z @ZLIB_SYMBOL_PREFIX@crc32_z
|
||||
#define deflate @ZLIB_SYMBOL_PREFIX@deflate
|
||||
#define deflateBound @ZLIB_SYMBOL_PREFIX@deflateBound
|
||||
#define deflateCopy @ZLIB_SYMBOL_PREFIX@deflateCopy
|
||||
#define deflateEnd @ZLIB_SYMBOL_PREFIX@deflateEnd
|
||||
#define deflateGetDictionary @ZLIB_SYMBOL_PREFIX@deflateGetDictionary
|
||||
#define deflateInit @ZLIB_SYMBOL_PREFIX@deflateInit
|
||||
#define deflateInit2 @ZLIB_SYMBOL_PREFIX@deflateInit2
|
||||
#define deflateInit2_ @ZLIB_SYMBOL_PREFIX@deflateInit2_
|
||||
#define deflateInit_ @ZLIB_SYMBOL_PREFIX@deflateInit_
|
||||
#define deflateParams @ZLIB_SYMBOL_PREFIX@deflateParams
|
||||
#define deflatePending @ZLIB_SYMBOL_PREFIX@deflatePending
|
||||
#define deflatePrime @ZLIB_SYMBOL_PREFIX@deflatePrime
|
||||
#define deflateReset @ZLIB_SYMBOL_PREFIX@deflateReset
|
||||
#define deflateResetKeep @ZLIB_SYMBOL_PREFIX@deflateResetKeep
|
||||
#define deflateSetDictionary @ZLIB_SYMBOL_PREFIX@deflateSetDictionary
|
||||
#define deflateSetHeader @ZLIB_SYMBOL_PREFIX@deflateSetHeader
|
||||
#define deflateTune @ZLIB_SYMBOL_PREFIX@deflateTune
|
||||
#define deflate_copyright @ZLIB_SYMBOL_PREFIX@deflate_copyright
|
||||
#define fill_window @ZLIB_SYMBOL_PREFIX@fill_window
|
||||
#define fixedtables @ZLIB_SYMBOL_PREFIX@fixedtables
|
||||
#define flush_pending @ZLIB_SYMBOL_PREFIX@flush_pending
|
||||
#define get_crc_table @ZLIB_SYMBOL_PREFIX@get_crc_table
|
||||
#ifndef Z_SOLO
|
||||
# define gz_error @ZLIB_SYMBOL_PREFIX@gz_error
|
||||
# define gz_strwinerror @ZLIB_SYMBOL_PREFIX@gz_strwinerror
|
||||
# define gzbuffer @ZLIB_SYMBOL_PREFIX@gzbuffer
|
||||
# define gzclearerr @ZLIB_SYMBOL_PREFIX@gzclearerr
|
||||
# define gzclose @ZLIB_SYMBOL_PREFIX@gzclose
|
||||
# define gzclose_r @ZLIB_SYMBOL_PREFIX@gzclose_r
|
||||
# define gzclose_w @ZLIB_SYMBOL_PREFIX@gzclose_w
|
||||
# define gzdirect @ZLIB_SYMBOL_PREFIX@gzdirect
|
||||
# define gzdopen @ZLIB_SYMBOL_PREFIX@gzdopen
|
||||
# define gzeof @ZLIB_SYMBOL_PREFIX@gzeof
|
||||
# define gzerror @ZLIB_SYMBOL_PREFIX@gzerror
|
||||
# define gzflush @ZLIB_SYMBOL_PREFIX@gzflush
|
||||
# define gzfread @ZLIB_SYMBOL_PREFIX@gzfread
|
||||
# define gzfwrite @ZLIB_SYMBOL_PREFIX@gzfwrite
|
||||
# define gzgetc @ZLIB_SYMBOL_PREFIX@gzgetc
|
||||
# define gzgetc_ @ZLIB_SYMBOL_PREFIX@gzgetc_
|
||||
# define gzgets @ZLIB_SYMBOL_PREFIX@gzgets
|
||||
# define gzoffset @ZLIB_SYMBOL_PREFIX@gzoffset
|
||||
# define gzoffset64 @ZLIB_SYMBOL_PREFIX@gzoffset64
|
||||
# define gzopen @ZLIB_SYMBOL_PREFIX@gzopen
|
||||
# define gzopen64 @ZLIB_SYMBOL_PREFIX@gzopen64
|
||||
# ifdef _WIN32
|
||||
# define gzopen_w @ZLIB_SYMBOL_PREFIX@gzopen_w
|
||||
# endif
|
||||
# define gzprintf @ZLIB_SYMBOL_PREFIX@gzprintf
|
||||
# define gzputc @ZLIB_SYMBOL_PREFIX@gzputc
|
||||
# define gzputs @ZLIB_SYMBOL_PREFIX@gzputs
|
||||
# define gzread @ZLIB_SYMBOL_PREFIX@gzread
|
||||
# define gzrewind @ZLIB_SYMBOL_PREFIX@gzrewind
|
||||
# define gzseek @ZLIB_SYMBOL_PREFIX@gzseek
|
||||
# define gzseek64 @ZLIB_SYMBOL_PREFIX@gzseek64
|
||||
# define gzsetparams @ZLIB_SYMBOL_PREFIX@gzsetparams
|
||||
# define gztell @ZLIB_SYMBOL_PREFIX@gztell
|
||||
# define gztell64 @ZLIB_SYMBOL_PREFIX@gztell64
|
||||
# define gzungetc @ZLIB_SYMBOL_PREFIX@gzungetc
|
||||
# define gzvprintf @ZLIB_SYMBOL_PREFIX@gzvprintf
|
||||
# define gzwrite @ZLIB_SYMBOL_PREFIX@gzwrite
|
||||
#endif
|
||||
#define inflate @ZLIB_SYMBOL_PREFIX@inflate
|
||||
#define inflateBack @ZLIB_SYMBOL_PREFIX@inflateBack
|
||||
#define inflateBackEnd @ZLIB_SYMBOL_PREFIX@inflateBackEnd
|
||||
#define inflateBackInit @ZLIB_SYMBOL_PREFIX@inflateBackInit
|
||||
#define inflateBackInit_ @ZLIB_SYMBOL_PREFIX@inflateBackInit_
|
||||
#define inflateCodesUsed @ZLIB_SYMBOL_PREFIX@inflateCodesUsed
|
||||
#define inflateCopy @ZLIB_SYMBOL_PREFIX@inflateCopy
|
||||
#define inflateEnd @ZLIB_SYMBOL_PREFIX@inflateEnd
|
||||
#define inflateGetDictionary @ZLIB_SYMBOL_PREFIX@inflateGetDictionary
|
||||
#define inflateGetHeader @ZLIB_SYMBOL_PREFIX@inflateGetHeader
|
||||
#define inflateInit @ZLIB_SYMBOL_PREFIX@inflateInit
|
||||
#define inflateInit2 @ZLIB_SYMBOL_PREFIX@inflateInit2
|
||||
#define inflateInit2_ @ZLIB_SYMBOL_PREFIX@inflateInit2_
|
||||
#define inflateInit_ @ZLIB_SYMBOL_PREFIX@inflateInit_
|
||||
#define inflateMark @ZLIB_SYMBOL_PREFIX@inflateMark
|
||||
#define inflatePrime @ZLIB_SYMBOL_PREFIX@inflatePrime
|
||||
#define inflateReset @ZLIB_SYMBOL_PREFIX@inflateReset
|
||||
#define inflateReset2 @ZLIB_SYMBOL_PREFIX@inflateReset2
|
||||
#define inflateResetKeep @ZLIB_SYMBOL_PREFIX@inflateResetKeep
|
||||
#define inflateSetDictionary @ZLIB_SYMBOL_PREFIX@inflateSetDictionary
|
||||
#define inflateSync @ZLIB_SYMBOL_PREFIX@inflateSync
|
||||
#define inflateSyncPoint @ZLIB_SYMBOL_PREFIX@inflateSyncPoint
|
||||
#define inflateUndermine @ZLIB_SYMBOL_PREFIX@inflateUndermine
|
||||
#define inflateValidate @ZLIB_SYMBOL_PREFIX@inflateValidate
|
||||
#define inflate_copyright @ZLIB_SYMBOL_PREFIX@inflate_copyright
|
||||
#define inflate_ensure_window @ZLIB_SYMBOL_PREFIX@inflate_ensure_window
|
||||
#define inflate_fast @ZLIB_SYMBOL_PREFIX@inflate_fast
|
||||
#define inflate_table @ZLIB_SYMBOL_PREFIX@inflate_table
|
||||
#define read_buf @ZLIB_SYMBOL_PREFIX@read_buf
|
||||
#ifndef Z_SOLO
|
||||
# define uncompress @ZLIB_SYMBOL_PREFIX@uncompress
|
||||
# define uncompress2 @ZLIB_SYMBOL_PREFIX@uncompress2
|
||||
#endif
|
||||
#define zError @ZLIB_SYMBOL_PREFIX@zError
|
||||
#ifndef Z_SOLO
|
||||
# define zcalloc @ZLIB_SYMBOL_PREFIX@zcalloc
|
||||
# define zcfree @ZLIB_SYMBOL_PREFIX@zcfree
|
||||
#endif
|
||||
#define zlibCompileFlags @ZLIB_SYMBOL_PREFIX@zlibCompileFlags
|
||||
#define zlibVersion @ZLIB_SYMBOL_PREFIX@zlibVersion
|
||||
|
||||
/* all zlib typedefs in zlib.h and zconf.h */
|
||||
#define Byte @ZLIB_SYMBOL_PREFIX@Byte
|
||||
#define Bytef @ZLIB_SYMBOL_PREFIX@Bytef
|
||||
#define alloc_func @ZLIB_SYMBOL_PREFIX@alloc_func
|
||||
#define charf @ZLIB_SYMBOL_PREFIX@charf
|
||||
#define free_func @ZLIB_SYMBOL_PREFIX@free_func
|
||||
#ifndef Z_SOLO
|
||||
# define gzFile @ZLIB_SYMBOL_PREFIX@gzFile
|
||||
#endif
|
||||
#define gz_header @ZLIB_SYMBOL_PREFIX@gz_header
|
||||
#define gz_headerp @ZLIB_SYMBOL_PREFIX@gz_headerp
|
||||
#define in_func @ZLIB_SYMBOL_PREFIX@in_func
|
||||
#define intf @ZLIB_SYMBOL_PREFIX@intf
|
||||
#define out_func @ZLIB_SYMBOL_PREFIX@out_func
|
||||
#define uInt @ZLIB_SYMBOL_PREFIX@uInt
|
||||
#define uIntf @ZLIB_SYMBOL_PREFIX@uIntf
|
||||
#define uLong @ZLIB_SYMBOL_PREFIX@uLong
|
||||
#define uLongf @ZLIB_SYMBOL_PREFIX@uLongf
|
||||
#define voidp @ZLIB_SYMBOL_PREFIX@voidp
|
||||
#define voidpc @ZLIB_SYMBOL_PREFIX@voidpc
|
||||
#define voidpf @ZLIB_SYMBOL_PREFIX@voidpf
|
||||
|
||||
/* all zlib structs in zlib.h and zconf.h */
|
||||
#define gz_header_s @ZLIB_SYMBOL_PREFIX@gz_header_s
|
||||
#define internal_state @ZLIB_SYMBOL_PREFIX@internal_state
|
||||
|
||||
/* all zlib structs in zutil.h */
|
||||
#define z_errmsg @ZLIB_SYMBOL_PREFIX@z_errmsg
|
||||
#define z_vstring @ZLIB_SYMBOL_PREFIX@z_vstring
|
||||
#define zlibng_version @ZLIB_SYMBOL_PREFIX@zlibng_version
|
||||
|
||||
/* zlib-ng specific symbols */
|
||||
#define zng_alloc_aligned @ZLIB_SYMBOL_PREFIX@zng_alloc_aligned
|
||||
#define zng_free_aligned @ZLIB_SYMBOL_PREFIX@zng_free_aligned
|
||||
|
||||
#endif /* ZLIB_NAME_MANGLING_H */
|
||||
@@ -0,0 +1,99 @@
|
||||
/* zmemory.h -- Private inline functions used internally in zlib-ng
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef _ZMEMORY_H
|
||||
#define _ZMEMORY_H
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 4)
|
||||
# define HAVE_MAY_ALIAS
|
||||
#endif
|
||||
|
||||
static inline uint16_t zng_memread_2(const void *ptr) {
|
||||
#if defined(HAVE_MAY_ALIAS)
|
||||
typedef struct { uint16_t val; } __attribute__ ((__packed__, __may_alias__)) unaligned_uint16_t;
|
||||
return ((const unaligned_uint16_t *)ptr)->val;
|
||||
#else
|
||||
uint16_t val;
|
||||
memcpy(&val, ptr, sizeof(val));
|
||||
return val;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t zng_memread_4(const void *ptr) {
|
||||
#if defined(HAVE_MAY_ALIAS)
|
||||
typedef struct { uint32_t val; } __attribute__ ((__packed__, __may_alias__)) unaligned_uint32_t;
|
||||
return ((const unaligned_uint32_t *)ptr)->val;
|
||||
#else
|
||||
uint32_t val;
|
||||
memcpy(&val, ptr, sizeof(val));
|
||||
return val;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint64_t zng_memread_8(const void *ptr) {
|
||||
#if defined(HAVE_MAY_ALIAS)
|
||||
typedef struct { uint64_t val; } __attribute__ ((__packed__, __may_alias__)) unaligned_uint64_t;
|
||||
return ((const unaligned_uint64_t *)ptr)->val;
|
||||
#else
|
||||
uint64_t val;
|
||||
memcpy(&val, ptr, sizeof(val));
|
||||
return val;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void zng_memwrite_2(void *ptr, uint16_t val) {
|
||||
#if defined(HAVE_MAY_ALIAS)
|
||||
typedef struct { uint16_t val; } __attribute__ ((__packed__, __may_alias__)) unaligned_uint16_t;
|
||||
((unaligned_uint16_t *)ptr)->val = val;
|
||||
#else
|
||||
memcpy(ptr, &val, sizeof(val));
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void zng_memwrite_4(void *ptr, uint32_t val) {
|
||||
#if defined(HAVE_MAY_ALIAS)
|
||||
typedef struct { uint32_t val; } __attribute__ ((__packed__, __may_alias__)) unaligned_uint32_t;
|
||||
((unaligned_uint32_t *)ptr)->val = val;
|
||||
#else
|
||||
memcpy(ptr, &val, sizeof(val));
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void zng_memwrite_8(void *ptr, uint64_t val) {
|
||||
#if defined(HAVE_MAY_ALIAS)
|
||||
typedef struct { uint64_t val; } __attribute__ ((__packed__, __may_alias__)) unaligned_uint64_t;
|
||||
((unaligned_uint64_t *)ptr)->val = val;
|
||||
#else
|
||||
memcpy(ptr, &val, sizeof(val));
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Use zng_memread_* instead of memcmp to avoid older compilers not converting memcmp
|
||||
calls to unaligned comparisons when unaligned access is supported. Use memcmp only when
|
||||
unaligned support is not available to avoid an extra call to memcpy. */
|
||||
static inline int32_t zng_memcmp_2(const void *src0, const void *src1) {
|
||||
#if defined(HAVE_MAY_ALIAS)
|
||||
return zng_memread_2(src0) != zng_memread_2(src1);
|
||||
#else
|
||||
return memcmp(src0, src1, 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int32_t zng_memcmp_4(const void *src0, const void *src1) {
|
||||
#if defined(HAVE_MAY_ALIAS)
|
||||
return zng_memread_4(src0) != zng_memread_4(src1);
|
||||
#else
|
||||
return memcmp(src0, src1, 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int32_t zng_memcmp_8(const void *src0, const void *src1) {
|
||||
#if defined(HAVE_MAY_ALIAS)
|
||||
return zng_memread_8(src0) != zng_memread_8(src1);
|
||||
#else
|
||||
return memcmp(src0, src1, 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
+28
-216
@@ -3,14 +3,11 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#include "zbuild.h"
|
||||
#include "zutil_p.h"
|
||||
#include "zutil.h"
|
||||
#ifndef Z_SOLO
|
||||
# include "gzguts.h"
|
||||
#endif
|
||||
|
||||
z_const char * const z_errmsg[10] = {
|
||||
z_const char * const PREFIX(z_errmsg)[10] = {
|
||||
(z_const char *)"need dictionary", /* Z_NEED_DICT 2 */
|
||||
(z_const char *)"stream end", /* Z_STREAM_END 1 */
|
||||
(z_const char *)"", /* Z_OK 0 */
|
||||
@@ -23,28 +20,36 @@ z_const char * const z_errmsg[10] = {
|
||||
(z_const char *)""
|
||||
};
|
||||
|
||||
const char PREFIX3(vstring)[] =
|
||||
" zlib-ng 2.2.4";
|
||||
|
||||
const char * ZEXPORT zlibVersion(void) {
|
||||
#ifdef ZLIB_COMPAT
|
||||
const char * Z_EXPORT zlibVersion(void) {
|
||||
return ZLIB_VERSION;
|
||||
}
|
||||
#else
|
||||
const char * Z_EXPORT zlibng_version(void) {
|
||||
return ZLIBNG_VERSION;
|
||||
}
|
||||
#endif
|
||||
|
||||
uLong ZEXPORT zlibCompileFlags(void) {
|
||||
uLong flags;
|
||||
unsigned long Z_EXPORT PREFIX(zlibCompileFlags)(void) {
|
||||
unsigned long flags;
|
||||
|
||||
flags = 0;
|
||||
switch ((int)(sizeof(uInt))) {
|
||||
switch ((int)(sizeof(unsigned int))) {
|
||||
case 2: break;
|
||||
case 4: flags += 1; break;
|
||||
case 8: flags += 2; break;
|
||||
default: flags += 3;
|
||||
}
|
||||
switch ((int)(sizeof(uLong))) {
|
||||
switch ((int)(sizeof(unsigned long))) {
|
||||
case 2: break;
|
||||
case 4: flags += 1 << 2; break;
|
||||
case 8: flags += 2 << 2; break;
|
||||
default: flags += 3 << 2;
|
||||
}
|
||||
switch ((int)(sizeof(voidpf))) {
|
||||
switch ((int)(sizeof(void *))) {
|
||||
case 2: break;
|
||||
case 4: flags += 1 << 4; break;
|
||||
case 8: flags += 2 << 4; break;
|
||||
@@ -59,20 +64,10 @@ uLong ZEXPORT zlibCompileFlags(void) {
|
||||
#ifdef ZLIB_DEBUG
|
||||
flags += 1 << 8;
|
||||
#endif
|
||||
/*
|
||||
#if defined(ASMV) || defined(ASMINF)
|
||||
flags += 1 << 9;
|
||||
#endif
|
||||
*/
|
||||
#ifdef ZLIB_WINAPI
|
||||
flags += 1 << 10;
|
||||
#endif
|
||||
#ifdef BUILDFIXED
|
||||
flags += 1 << 12;
|
||||
#endif
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
flags += 1 << 13;
|
||||
#endif
|
||||
/* Bit 13 reserved for DYNAMIC_CRC_TABLE */
|
||||
#ifdef NO_GZCOMPRESS
|
||||
flags += 1L << 16;
|
||||
#endif
|
||||
@@ -81,45 +76,18 @@ uLong ZEXPORT zlibCompileFlags(void) {
|
||||
#endif
|
||||
#ifdef PKZIP_BUG_WORKAROUND
|
||||
flags += 1L << 20;
|
||||
#endif
|
||||
#ifdef FASTEST
|
||||
flags += 1L << 21;
|
||||
#endif
|
||||
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||
# ifdef NO_vsnprintf
|
||||
flags += 1L << 25;
|
||||
# ifdef HAS_vsprintf_void
|
||||
flags += 1L << 26;
|
||||
# endif
|
||||
# else
|
||||
# ifdef HAS_vsnprintf_void
|
||||
flags += 1L << 26;
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
flags += 1L << 24;
|
||||
# ifdef NO_snprintf
|
||||
flags += 1L << 25;
|
||||
# ifdef HAS_sprintf_void
|
||||
flags += 1L << 26;
|
||||
# endif
|
||||
# else
|
||||
# ifdef HAS_snprintf_void
|
||||
flags += 1L << 26;
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
return flags;
|
||||
}
|
||||
|
||||
#ifdef ZLIB_DEBUG
|
||||
#include <stdlib.h>
|
||||
# include <stdlib.h>
|
||||
# ifndef verbose
|
||||
# define verbose 0
|
||||
# endif
|
||||
int ZLIB_INTERNAL z_verbose = verbose;
|
||||
int Z_INTERNAL z_verbose = verbose;
|
||||
|
||||
void ZLIB_INTERNAL z_error(char *m) {
|
||||
void Z_INTERNAL z_error(const char *m) {
|
||||
fprintf(stderr, "%s\n", m);
|
||||
exit(1);
|
||||
}
|
||||
@@ -128,172 +96,16 @@ void ZLIB_INTERNAL z_error(char *m) {
|
||||
/* exported to allow conversion of error code to string for compress() and
|
||||
* uncompress()
|
||||
*/
|
||||
const char * ZEXPORT zError(int err) {
|
||||
const char * Z_EXPORT PREFIX(zError)(int err) {
|
||||
return ERR_MSG(err);
|
||||
}
|
||||
|
||||
#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.
|
||||
*/
|
||||
int errno = 0;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MEMCPY
|
||||
|
||||
void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) {
|
||||
if (len == 0) return;
|
||||
do {
|
||||
*dest++ = *source++; /* ??? to be unrolled */
|
||||
} while (--len != 0);
|
||||
void Z_INTERNAL *PREFIX(zcalloc)(void *opaque, unsigned items, unsigned size) {
|
||||
Z_UNUSED(opaque);
|
||||
return zng_alloc((size_t)items * (size_t)size);
|
||||
}
|
||||
|
||||
int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) {
|
||||
uInt j;
|
||||
|
||||
for (j = 0; j < len; j++) {
|
||||
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
|
||||
}
|
||||
return 0;
|
||||
void Z_INTERNAL PREFIX(zcfree)(void *opaque, void *ptr) {
|
||||
Z_UNUSED(opaque);
|
||||
zng_free(ptr);
|
||||
}
|
||||
|
||||
void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) {
|
||||
if (len == 0) return;
|
||||
do {
|
||||
*dest++ = 0; /* ??? to be unrolled */
|
||||
} while (--len != 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef Z_SOLO
|
||||
|
||||
#ifdef SYS16BIT
|
||||
|
||||
#ifdef __TURBOC__
|
||||
/* Turbo C in 16-bit mode */
|
||||
|
||||
# define MY_ZCALLOC
|
||||
|
||||
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
|
||||
* and farmalloc(64K) returns a pointer with an offset of 8, so we
|
||||
* must fix the pointer. Warning: the pointer must be put back to its
|
||||
* original form in order to free it, use zcfree().
|
||||
*/
|
||||
|
||||
#define MAX_PTR 10
|
||||
/* 10*64K = 640K */
|
||||
|
||||
local int next_ptr = 0;
|
||||
|
||||
typedef struct ptr_table_s {
|
||||
voidpf org_ptr;
|
||||
voidpf new_ptr;
|
||||
} ptr_table;
|
||||
|
||||
local ptr_table table[MAX_PTR];
|
||||
/* This table is used to remember the original form of pointers
|
||||
* to large buffers (64K). Such pointers are normalized with a zero offset.
|
||||
* Since MSDOS is not a preemptive multitasking OS, this table is not
|
||||
* protected from concurrent access. This hack doesn't work anyway on
|
||||
* a protected system like OS/2. Use Microsoft C instead.
|
||||
*/
|
||||
|
||||
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
|
||||
voidpf buf;
|
||||
ulg bsize = (ulg)items*size;
|
||||
|
||||
(void)opaque;
|
||||
|
||||
/* If we allocate less than 65520 bytes, we assume that farmalloc
|
||||
* will return a usable pointer which doesn't have to be normalized.
|
||||
*/
|
||||
if (bsize < 65520L) {
|
||||
buf = farmalloc(bsize);
|
||||
if (*(ush*)&buf != 0) return buf;
|
||||
} else {
|
||||
buf = farmalloc(bsize + 16L);
|
||||
}
|
||||
if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
|
||||
table[next_ptr].org_ptr = buf;
|
||||
|
||||
/* Normalize the pointer to seg:0 */
|
||||
*((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
|
||||
*(ush*)&buf = 0;
|
||||
table[next_ptr++].new_ptr = buf;
|
||||
return buf;
|
||||
}
|
||||
|
||||
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
|
||||
int n;
|
||||
|
||||
(void)opaque;
|
||||
|
||||
if (*(ush*)&ptr != 0) { /* object < 64K */
|
||||
farfree(ptr);
|
||||
return;
|
||||
}
|
||||
/* Find the original pointer */
|
||||
for (n = 0; n < next_ptr; n++) {
|
||||
if (ptr != table[n].new_ptr) continue;
|
||||
|
||||
farfree(table[n].org_ptr);
|
||||
while (++n < next_ptr) {
|
||||
table[n-1] = table[n];
|
||||
}
|
||||
next_ptr--;
|
||||
return;
|
||||
}
|
||||
Assert(0, "zcfree: ptr not found");
|
||||
}
|
||||
|
||||
#endif /* __TURBOC__ */
|
||||
|
||||
|
||||
#ifdef M_I86
|
||||
/* Microsoft C in 16-bit mode */
|
||||
|
||||
# define MY_ZCALLOC
|
||||
|
||||
#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
|
||||
# define _halloc halloc
|
||||
# define _hfree hfree
|
||||
#endif
|
||||
|
||||
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) {
|
||||
(void)opaque;
|
||||
return _halloc((long)items, size);
|
||||
}
|
||||
|
||||
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
|
||||
(void)opaque;
|
||||
_hfree(ptr);
|
||||
}
|
||||
|
||||
#endif /* M_I86 */
|
||||
|
||||
#endif /* SYS16BIT */
|
||||
|
||||
|
||||
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
|
||||
|
||||
#ifndef STDC
|
||||
extern voidp malloc(uInt size);
|
||||
extern voidp calloc(uInt items, uInt size);
|
||||
extern void free(voidpf ptr);
|
||||
#endif
|
||||
|
||||
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
|
||||
(void)opaque;
|
||||
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
|
||||
(voidpf)calloc(items, size);
|
||||
}
|
||||
|
||||
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
|
||||
(void)opaque;
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
#endif /* MY_ZCALLOC */
|
||||
|
||||
#endif /* !Z_SOLO */
|
||||
+50
-164
@@ -1,3 +1,5 @@
|
||||
#ifndef ZUTIL_H_
|
||||
#define ZUTIL_H_
|
||||
/* zutil.h -- internal interface and configuration of the compression library
|
||||
* Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
@@ -8,58 +10,23 @@
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
#ifndef ZUTIL_H
|
||||
#define ZUTIL_H
|
||||
|
||||
#ifdef HAVE_HIDDEN
|
||||
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
||||
#include "zbuild.h"
|
||||
#ifdef ZLIB_COMPAT
|
||||
# include "zlib.h"
|
||||
#else
|
||||
# define ZLIB_INTERNAL
|
||||
# include "zlib-ng.h"
|
||||
#endif
|
||||
|
||||
#include "zlib.h"
|
||||
typedef unsigned char uch; /* Included for compatibility with external code only */
|
||||
typedef uint16_t ush; /* Included for compatibility with external code only */
|
||||
typedef unsigned long ulg;
|
||||
|
||||
#if defined(STDC) && !defined(Z_SOLO)
|
||||
# if !(defined(_WIN32_WCE) && defined(_MSC_VER))
|
||||
# include <stddef.h>
|
||||
# endif
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef local
|
||||
# define local static
|
||||
#endif
|
||||
/* since "static" is used to mean two completely different things in C, we
|
||||
define "local" for the non-static meaning of "static", for readability
|
||||
(compile with -Dlocal if your debugger can't find static symbols) */
|
||||
|
||||
typedef unsigned char uch;
|
||||
typedef uch FAR uchf;
|
||||
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 */
|
||||
extern z_const char * const PREFIX(z_errmsg)[10]; /* indexed by 2-zlib_error */
|
||||
/* (size given to avoid silly warnings with Visual C++) */
|
||||
|
||||
#define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)]
|
||||
#define ERR_MSG(err) PREFIX(z_errmsg)[(err) < -6 || (err) > 2 ? 9 : 2 - (err)]
|
||||
|
||||
#define ERR_RETURN(strm,err) \
|
||||
return (strm->msg = ERR_MSG(err), (err))
|
||||
#define ERR_RETURN(strm, err) return (strm->msg = ERR_MSG(err), (err))
|
||||
/* To be used only when the state is known to be valid */
|
||||
|
||||
/* common constants */
|
||||
@@ -69,6 +36,11 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
#endif
|
||||
/* default windowBits for decompression. MAX_WBITS is for compression only */
|
||||
|
||||
#define MAX_BITS 15
|
||||
/* all codes must not exceed MAX_BITS bits */
|
||||
#define MAX_DIST_EXTRA_BITS 13
|
||||
/* maximum number of extra distance bits */
|
||||
|
||||
#if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
#else
|
||||
@@ -81,41 +53,38 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
#define DYN_TREES 2
|
||||
/* The three kinds of block type */
|
||||
|
||||
#define MIN_MATCH 3
|
||||
#define MAX_MATCH 258
|
||||
/* The minimum and maximum match lengths */
|
||||
#define STD_MIN_MATCH 3
|
||||
#define STD_MAX_MATCH 258
|
||||
/* The minimum and maximum match lengths mandated by the deflate standard */
|
||||
|
||||
#define WANT_MIN_MATCH 4
|
||||
/* The minimum wanted match length, affects deflate_quick, deflate_fast, deflate_medium and deflate_slow */
|
||||
|
||||
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
|
||||
|
||||
/* target dependencies */
|
||||
#define ADLER32_INITIAL_VALUE 1 /* initial adler-32 hash value */
|
||||
#define CRC32_INITIAL_VALUE 0 /* initial crc-32 hash value */
|
||||
|
||||
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
|
||||
# define OS_CODE 0x00
|
||||
# ifndef Z_SOLO
|
||||
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
||||
# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||
/* Allow compilation with ANSI keywords only enabled */
|
||||
void _Cdecl farfree( void *block );
|
||||
void *_Cdecl farmalloc( unsigned long nbytes );
|
||||
# else
|
||||
# include <alloc.h>
|
||||
# endif
|
||||
# else /* MSC or DJGPP */
|
||||
# include <malloc.h>
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#define ZLIB_WRAPLEN 6 /* zlib format overhead */
|
||||
#define GZIP_WRAPLEN 18 /* gzip format overhead */
|
||||
|
||||
#define DEFLATE_HEADER_BITS 3
|
||||
#define DEFLATE_EOBS_BITS 15
|
||||
#define DEFLATE_PAD_BITS 6
|
||||
#define DEFLATE_BLOCK_OVERHEAD ((DEFLATE_HEADER_BITS + DEFLATE_EOBS_BITS + DEFLATE_PAD_BITS) >> 3)
|
||||
/* deflate block overhead: 3 bits for block start + 15 bits for block end + padding to nearest byte */
|
||||
|
||||
#define DEFLATE_QUICK_LIT_MAX_BITS 9
|
||||
#define DEFLATE_QUICK_OVERHEAD(x) ((x * (DEFLATE_QUICK_LIT_MAX_BITS - 8) + 7) >> 3)
|
||||
/* deflate_quick worst-case overhead: 9 bits per literal, round up to next byte (+7) */
|
||||
|
||||
|
||||
/* target dependencies */
|
||||
|
||||
#ifdef AMIGA
|
||||
# define OS_CODE 1
|
||||
#endif
|
||||
|
||||
#if defined(VAXC) || defined(VMS)
|
||||
# define OS_CODE 2
|
||||
# define F_OPEN(name, mode) \
|
||||
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
|
||||
#endif
|
||||
|
||||
#ifdef __370__
|
||||
# if __TARGET_LIB__ < 0x20000000
|
||||
# define OS_CODE 4
|
||||
@@ -132,9 +101,6 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
|
||||
#ifdef OS2
|
||||
# define OS_CODE 6
|
||||
# if defined(M_I86) && !defined(Z_SOLO)
|
||||
# include <malloc.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(MACOS)
|
||||
@@ -145,110 +111,30 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
# define OS_CODE 13
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
# define OS_CODE 10
|
||||
#endif
|
||||
|
||||
#ifdef _BEOS_
|
||||
# define OS_CODE 16
|
||||
#endif
|
||||
|
||||
#ifdef __TOS_OS400__
|
||||
# define OS_CODE 18
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
# define OS_CODE 19
|
||||
#endif
|
||||
|
||||
#if defined(__BORLANDC__) && !defined(MSDOS)
|
||||
#pragma warn -8004
|
||||
#pragma warn -8008
|
||||
#pragma warn -8066
|
||||
#endif
|
||||
|
||||
/* provide prototypes for these when building zlib without LFS */
|
||||
#if !defined(_WIN32) && \
|
||||
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
|
||||
ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
|
||||
ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
|
||||
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
|
||||
#endif
|
||||
|
||||
/* common defaults */
|
||||
|
||||
#ifndef OS_CODE
|
||||
# define OS_CODE 3 /* assume Unix */
|
||||
# define OS_CODE 3 /* assume Unix */
|
||||
#endif
|
||||
|
||||
#ifndef F_OPEN
|
||||
# define F_OPEN(name, mode) fopen((name), (mode))
|
||||
#endif
|
||||
/* macros */
|
||||
|
||||
/* functions */
|
||||
#define CHECK_VER_STSIZE(_ver,_stsize) ((_ver) == NULL || (_ver)[0] != PREFIX2(VERSION)[0] || (_stsize) != (int32_t)sizeof(PREFIX3(stream)))
|
||||
|
||||
#if defined(pyr) || defined(Z_SOLO)
|
||||
# define NO_MEMCPY
|
||||
#endif
|
||||
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
|
||||
/* Use our own functions for small and medium model with MSC <= 5.0.
|
||||
* You may have to use the same strategy for Borland C (untested).
|
||||
* The __SC__ check is for Symantec.
|
||||
*/
|
||||
# define NO_MEMCPY
|
||||
#endif
|
||||
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
|
||||
# define HAVE_MEMCPY
|
||||
#endif
|
||||
#ifdef HAVE_MEMCPY
|
||||
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
|
||||
# define zmemcpy _fmemcpy
|
||||
# define zmemcmp _fmemcmp
|
||||
# define zmemzero(dest, len) _fmemset(dest, 0, len)
|
||||
# else
|
||||
# define zmemcpy memcpy
|
||||
# define zmemcmp memcmp
|
||||
# define zmemzero(dest, len) memset(dest, 0, len)
|
||||
# endif
|
||||
#else
|
||||
void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
|
||||
int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
|
||||
void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
|
||||
#endif
|
||||
/* memory allocation functions */
|
||||
|
||||
/* Diagnostic functions */
|
||||
#ifdef ZLIB_DEBUG
|
||||
# include <stdio.h>
|
||||
extern int ZLIB_INTERNAL z_verbose;
|
||||
extern void ZLIB_INTERNAL z_error(char *m);
|
||||
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
||||
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
||||
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
||||
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
|
||||
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
|
||||
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
|
||||
#else
|
||||
# define Assert(cond,msg)
|
||||
# define Trace(x)
|
||||
# define Tracev(x)
|
||||
# define Tracevv(x)
|
||||
# define Tracec(c,x)
|
||||
# define Tracecv(c,x)
|
||||
#endif
|
||||
void Z_INTERNAL *PREFIX(zcalloc)(void *opaque, unsigned items, unsigned size);
|
||||
void Z_INTERNAL PREFIX(zcfree)(void *opaque, void *ptr);
|
||||
|
||||
#ifndef Z_SOLO
|
||||
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
|
||||
unsigned size);
|
||||
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
|
||||
#endif
|
||||
typedef void *zng_calloc_func(void *opaque, unsigned items, unsigned size);
|
||||
typedef void zng_cfree_func(void *opaque, void *ptr);
|
||||
|
||||
#define ZALLOC(strm, items, size) \
|
||||
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
||||
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
||||
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
||||
|
||||
/* Reverse the bytes in a 32-bit value */
|
||||
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
|
||||
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
|
||||
|
||||
#endif /* ZUTIL_H */
|
||||
#endif /* ZUTIL_H_ */
|
||||
@@ -0,0 +1,51 @@
|
||||
/* zutil_p.h -- Private inline functions used internally in zlib-ng
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#ifndef ZUTIL_P_H
|
||||
#define ZUTIL_P_H
|
||||
|
||||
#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_ALIGNED_ALLOC)
|
||||
# include <stdlib.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
# include <stdlib.h>
|
||||
# include <malloc_np.h>
|
||||
#elif defined(HAVE_MEMALIGN) || defined(HAVE__ALIGNED_MALLOC)
|
||||
# include <malloc.h>
|
||||
#else
|
||||
/* Fallback, when no other aligned allocation function was found */
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
/* Function to allocate 16 or 64-byte aligned memory */
|
||||
static inline void *zng_alloc(size_t size) {
|
||||
#ifdef HAVE_ALIGNED_ALLOC
|
||||
/* Size must be a multiple of alignment */
|
||||
size = (size + (64 - 1)) & ~(64 - 1);
|
||||
return (void *)aligned_alloc(64, size); /* Defined in C11 */
|
||||
#elif defined(HAVE_POSIX_MEMALIGN)
|
||||
void *ptr;
|
||||
return posix_memalign(&ptr, 64, size) ? NULL : ptr;
|
||||
#elif defined(HAVE__ALIGNED_MALLOC)
|
||||
/* Fallback: Use MSVC extensions: _aligned_malloc() / _aligned_free() */
|
||||
return (void *)_aligned_malloc(size, 64);
|
||||
#elif defined(HAVE_MEMALIGN)
|
||||
/* Fallback: Use deprecated GNU extension: memalign() */
|
||||
return (void *)memalign(64, size);
|
||||
#else
|
||||
/* Fallback: Use a normal allocation (On macOS, alignment is 16 bytes) */
|
||||
/* zlib-ng adjust allocations for [de]compression to be properly aligned */
|
||||
return (void *)malloc(size);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Function that can free aligned memory */
|
||||
static inline void zng_free(void *ptr) {
|
||||
#if defined(HAVE__ALIGNED_MALLOC) && !defined(HAVE_POSIX_MEMALIGN) && !defined(HAVE_ALIGNED_ALLOC)
|
||||
_aligned_free(ptr);
|
||||
#else
|
||||
free(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user