Fossil SCM

Update the built-in zlib library to version 1.3.

drh 2023-08-20 18:07 trunk merge
Commit f1f1d6c4eb530fd3eb08663fdc0ab70f59b50fdee651ce0d844ebcdf38f10acb
83 files changed +2 -2 +19 -1 +1 -1 +8 -2 +9 -10 +5 -27 +5 -16 +16 -10 +1 -1 +1 -1 +2 -2 +3 -3 +1 -1 +1 -1 +6 -18 +8 -8 +6 -11 +3 -3 +1 -1 +1 -1 +4 -8 +18 -44 +19 -19 +19 -46 +4 -4 +22 -48 +24 -36 +1 -7 +196 -341 +68 -68 +137 -194 +153 -156 +1 -1 +1 -1 +28 -35 +1 -1 +4 -4 +1 -1 +4 -4 +1 -1 +4 -4 +1 -1 +4 -4 +1 -1 +4 -4 +1 -1 +86 -162 +234 -337 +8 -8 +1 -1 +15 -11 +439 -385 +41 -30 +1 -3 +11 -12 +26 -83 +20 -68 +19 -65 +7 -23 +1 -4 +1 -1 +30 -99 +6 -11 +3 -3 +1 -1 +4 -4 +5 -5 +23 -80 +3 -2 +50 -122 +2 -2 +225 -303 +4 -12 +2 -2 +6 -2 +6 -2 +6 -2 +3 -3 +191 -188 -152 +16 -44 +10 -10
~ compat/zlib/CMakeLists.txt ~ compat/zlib/ChangeLog ~ compat/zlib/FAQ ~ compat/zlib/Makefile.in ~ compat/zlib/README ~ compat/zlib/adler32.c ~ compat/zlib/compress.c ~ compat/zlib/configure ~ compat/zlib/contrib/delphi/ZLib.pas ~ compat/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs ~ compat/zlib/contrib/dotzlib/DotZLib/CodecBase.cs ~ compat/zlib/contrib/dotzlib/DotZLib/GZipStream.cs ~ compat/zlib/contrib/dotzlib/DotZLib/UnitTests.cs ~ compat/zlib/contrib/dotzlib/readme.txt ~ compat/zlib/contrib/infback9/infback9.c ~ compat/zlib/contrib/infback9/infback9.h ~ compat/zlib/contrib/infback9/inftree9.c ~ compat/zlib/contrib/infback9/inftree9.h ~ compat/zlib/contrib/minizip/MiniZip64_Changes.txt ~ compat/zlib/contrib/minizip/configure.ac ~ compat/zlib/contrib/minizip/crypt.h ~ compat/zlib/contrib/minizip/ioapi.c ~ compat/zlib/contrib/minizip/ioapi.h ~ compat/zlib/contrib/minizip/iowin32.c ~ compat/zlib/contrib/minizip/iowin32.h ~ compat/zlib/contrib/minizip/miniunz.c ~ compat/zlib/contrib/minizip/minizip.c ~ compat/zlib/contrib/minizip/mztools.c ~ compat/zlib/contrib/minizip/unzip.c ~ compat/zlib/contrib/minizip/unzip.h ~ compat/zlib/contrib/minizip/zip.c ~ compat/zlib/contrib/minizip/zip.h ~ compat/zlib/contrib/pascal/zlibpas.pas ~ compat/zlib/contrib/testzlib/testzlib.c ~ compat/zlib/contrib/untgz/untgz.c ~ compat/zlib/contrib/vstudio/readme.txt ~ compat/zlib/contrib/vstudio/vc10/zlib.rc ~ compat/zlib/contrib/vstudio/vc10/zlibvc.def ~ compat/zlib/contrib/vstudio/vc11/zlib.rc ~ compat/zlib/contrib/vstudio/vc11/zlibvc.def ~ compat/zlib/contrib/vstudio/vc12/zlib.rc ~ compat/zlib/contrib/vstudio/vc12/zlibvc.def ~ compat/zlib/contrib/vstudio/vc14/zlib.rc ~ compat/zlib/contrib/vstudio/vc14/zlibvc.def ~ compat/zlib/contrib/vstudio/vc9/zlib.rc ~ compat/zlib/contrib/vstudio/vc9/zlibvc.def ~ compat/zlib/crc32.c ~ compat/zlib/deflate.c ~ compat/zlib/deflate.h ~ compat/zlib/examples/fitblk.c ~ compat/zlib/examples/zlib_how.html ~ compat/zlib/examples/zran.c ~ compat/zlib/examples/zran.h ~ compat/zlib/gzclose.c ~ compat/zlib/gzguts.h ~ compat/zlib/gzlib.c ~ compat/zlib/gzread.c ~ compat/zlib/gzwrite.c ~ compat/zlib/infback.c ~ compat/zlib/inffast.c ~ compat/zlib/inffast.h ~ compat/zlib/inflate.c ~ compat/zlib/inftrees.c ~ compat/zlib/inftrees.h ~ compat/zlib/os400/README400 ~ compat/zlib/os400/zlib.inc ~ compat/zlib/qnx/package.qpg ~ compat/zlib/test/example.c ~ compat/zlib/test/infcover.c ~ compat/zlib/test/minigzip.c ~ compat/zlib/treebuild.xml ~ compat/zlib/trees.c ~ compat/zlib/uncompr.c ~ compat/zlib/win32/README-WIN32.txt ~ compat/zlib/zconf.h ~ compat/zlib/zconf.h.cmakein ~ compat/zlib/zconf.h.in ~ compat/zlib/zlib.3 ~ compat/zlib/zlib.3.pdf ~ compat/zlib/zlib.h - compat/zlib/zlib2ansi ~ compat/zlib/zutil.c ~ compat/zlib/zutil.h
--- compat/zlib/CMakeLists.txt
+++ compat/zlib/CMakeLists.txt
@@ -1,11 +1,11 @@
1
-cmake_minimum_required(VERSION 2.4.4)
1
+cmake_minimum_required(VERSION 2.4.4...3.15.0)
22
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
33
44
project(zlib C)
55
6
-set(VERSION "1.2.13")
6
+set(VERSION "1.3")
77
88
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
99
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
1010
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
1111
set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
1212
--- compat/zlib/CMakeLists.txt
+++ compat/zlib/CMakeLists.txt
@@ -1,11 +1,11 @@
1 cmake_minimum_required(VERSION 2.4.4)
2 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3
4 project(zlib C)
5
6 set(VERSION "1.2.13")
7
8 set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
9 set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
10 set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
11 set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
12
--- compat/zlib/CMakeLists.txt
+++ compat/zlib/CMakeLists.txt
@@ -1,11 +1,11 @@
1 cmake_minimum_required(VERSION 2.4.4...3.15.0)
2 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3
4 project(zlib C)
5
6 set(VERSION "1.3")
7
8 set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
9 set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
10 set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
11 set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
12
--- compat/zlib/ChangeLog
+++ compat/zlib/ChangeLog
@@ -1,8 +1,26 @@
11
22
ChangeLog file for zlib
33
4
+Changes in 1.3 (18 Aug 2023)
5
+- Remove K&R function definitions and zlib2ansi
6
+- Fix bug in deflateBound() for level 0 and memLevel 9
7
+- Fix bug when gzungetc() is used immediately after gzopen()
8
+- Fix bug when using gzflush() with a very small buffer
9
+- Fix crash when gzsetparams() attempted for transparent write
10
+- Fix test/example.c to work with FORCE_STORED
11
+- Rewrite of zran in examples (see zran.c version history)
12
+- Fix minizip to allow it to open an empty zip file
13
+- Fix reading disk number start on zip64 files in minizip
14
+- Fix logic error in minizip argument processing
15
+- Add minizip testing to Makefile
16
+- Read multiple bytes instead of byte-by-byte in minizip unzip.c
17
+- Add memory sanitizer to configure (--memory)
18
+- Various portability improvements
19
+- Various documentation improvements
20
+- Various spelling and typo corrections
21
+
422
Changes in 1.2.13 (13 Oct 2022)
523
- Fix configure issue that discarded provided CC definition
624
- Correct incorrect inputs provided to the CRC functions
725
- Repair prototypes and exporting of new CRC functions
826
- Fix inflateBack to detect invalid input with distances too far
@@ -1443,11 +1461,11 @@
14431461
- fixed typo in zconf.h (_GNUC__ => __GNUC__)
14441462
- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode)
14451463
- fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
14461464
- in fcalloc, normalize pointer if size > 65520 bytes
14471465
- don't use special fcalloc for 32 bit Borland C++
1448
-- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
1466
+- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc.
14491467
- use Z_BINARY instead of BINARY
14501468
- document that gzclose after gzdopen will close the file
14511469
- allow "a" as mode in gzopen
14521470
- fix error checking in gzread
14531471
- allow skipping .gz extra-field on pipes
14541472
--- compat/zlib/ChangeLog
+++ compat/zlib/ChangeLog
@@ -1,8 +1,26 @@
1
2 ChangeLog file for zlib
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4 Changes in 1.2.13 (13 Oct 2022)
5 - Fix configure issue that discarded provided CC definition
6 - Correct incorrect inputs provided to the CRC functions
7 - Repair prototypes and exporting of new CRC functions
8 - Fix inflateBack to detect invalid input with distances too far
@@ -1443,11 +1461,11 @@
1443 - fixed typo in zconf.h (_GNUC__ => __GNUC__)
1444 - check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode)
1445 - fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
1446 - in fcalloc, normalize pointer if size > 65520 bytes
1447 - don't use special fcalloc for 32 bit Borland C++
1448 - use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
1449 - use Z_BINARY instead of BINARY
1450 - document that gzclose after gzdopen will close the file
1451 - allow "a" as mode in gzopen
1452 - fix error checking in gzread
1453 - allow skipping .gz extra-field on pipes
1454
--- compat/zlib/ChangeLog
+++ compat/zlib/ChangeLog
@@ -1,8 +1,26 @@
1
2 ChangeLog file for zlib
3
4 Changes in 1.3 (18 Aug 2023)
5 - Remove K&R function definitions and zlib2ansi
6 - Fix bug in deflateBound() for level 0 and memLevel 9
7 - Fix bug when gzungetc() is used immediately after gzopen()
8 - Fix bug when using gzflush() with a very small buffer
9 - Fix crash when gzsetparams() attempted for transparent write
10 - Fix test/example.c to work with FORCE_STORED
11 - Rewrite of zran in examples (see zran.c version history)
12 - Fix minizip to allow it to open an empty zip file
13 - Fix reading disk number start on zip64 files in minizip
14 - Fix logic error in minizip argument processing
15 - Add minizip testing to Makefile
16 - Read multiple bytes instead of byte-by-byte in minizip unzip.c
17 - Add memory sanitizer to configure (--memory)
18 - Various portability improvements
19 - Various documentation improvements
20 - Various spelling and typo corrections
21
22 Changes in 1.2.13 (13 Oct 2022)
23 - Fix configure issue that discarded provided CC definition
24 - Correct incorrect inputs provided to the CRC functions
25 - Repair prototypes and exporting of new CRC functions
26 - Fix inflateBack to detect invalid input with distances too far
@@ -1443,11 +1461,11 @@
1461 - fixed typo in zconf.h (_GNUC__ => __GNUC__)
1462 - check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode)
1463 - fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
1464 - in fcalloc, normalize pointer if size > 65520 bytes
1465 - don't use special fcalloc for 32 bit Borland C++
1466 - use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc.
1467 - use Z_BINARY instead of BINARY
1468 - document that gzclose after gzdopen will close the file
1469 - allow "a" as mode in gzopen
1470 - fix error checking in gzread
1471 - allow skipping .gz extra-field on pipes
1472
+1 -1
--- compat/zlib/FAQ
+++ compat/zlib/FAQ
@@ -2,11 +2,11 @@
22
Frequently Asked Questions about zlib
33
44
55
If your question is not there, please check the zlib home page
66
http://zlib.net/ which may have more recent information.
7
-The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
7
+The latest zlib FAQ is at http://zlib.net/zlib_faq.html
88
99
1010
1. Is zlib Y2K-compliant?
1111
1212
Yes. zlib doesn't handle dates.
1313
--- compat/zlib/FAQ
+++ compat/zlib/FAQ
@@ -2,11 +2,11 @@
2 Frequently Asked Questions about zlib
3
4
5 If your question is not there, please check the zlib home page
6 http://zlib.net/ which may have more recent information.
7 The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
8
9
10 1. Is zlib Y2K-compliant?
11
12 Yes. zlib doesn't handle dates.
13
--- compat/zlib/FAQ
+++ compat/zlib/FAQ
@@ -2,11 +2,11 @@
2 Frequently Asked Questions about zlib
3
4
5 If your question is not there, please check the zlib home page
6 http://zlib.net/ which may have more recent information.
7 The latest zlib FAQ is at http://zlib.net/zlib_faq.html
8
9
10 1. Is zlib Y2K-compliant?
11
12 Yes. zlib doesn't handle dates.
13
--- compat/zlib/Makefile.in
+++ compat/zlib/Makefile.in
@@ -26,11 +26,11 @@
2626
LDSHARED=$(CC)
2727
CPP=$(CC) -E
2828
2929
STATICLIB=libz.a
3030
SHAREDLIB=libz.so
31
-SHAREDLIBV=libz.so.1.2.13
31
+SHAREDLIBV=libz.so.1.3
3232
SHAREDLIBM=libz.so.1
3333
LIBS=$(STATICLIB) $(SHAREDLIBV)
3434
3535
AR=ar
3636
ARFLAGS=rc
@@ -357,12 +357,18 @@
357357
rm $$TEMPFILE
358358
359359
zconf: $(SRCDIR)zconf.h.in
360360
cp -p $(SRCDIR)zconf.h.in zconf.h
361361
362
+minizip-test: static
363
+ cd contrib/minizip && { CFLAGS="$(CFLAGS)" $(MAKE) test ; cd ../.. ; }
364
+
365
+minizip-clean:
366
+ cd contrib/minizip && { $(MAKE) clean ; cd ../.. ; }
367
+
362368
mostlyclean: clean
363
-clean:
369
+clean: minizip-clean
364370
rm -f *.o *.lo *~ \
365371
example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
366372
example64$(EXE) minigzip64$(EXE) \
367373
infcover \
368374
libz.* foo.gz so_locations \
369375
--- compat/zlib/Makefile.in
+++ compat/zlib/Makefile.in
@@ -26,11 +26,11 @@
26 LDSHARED=$(CC)
27 CPP=$(CC) -E
28
29 STATICLIB=libz.a
30 SHAREDLIB=libz.so
31 SHAREDLIBV=libz.so.1.2.13
32 SHAREDLIBM=libz.so.1
33 LIBS=$(STATICLIB) $(SHAREDLIBV)
34
35 AR=ar
36 ARFLAGS=rc
@@ -357,12 +357,18 @@
357 rm $$TEMPFILE
358
359 zconf: $(SRCDIR)zconf.h.in
360 cp -p $(SRCDIR)zconf.h.in zconf.h
361
 
 
 
 
 
 
362 mostlyclean: clean
363 clean:
364 rm -f *.o *.lo *~ \
365 example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
366 example64$(EXE) minigzip64$(EXE) \
367 infcover \
368 libz.* foo.gz so_locations \
369
--- compat/zlib/Makefile.in
+++ compat/zlib/Makefile.in
@@ -26,11 +26,11 @@
26 LDSHARED=$(CC)
27 CPP=$(CC) -E
28
29 STATICLIB=libz.a
30 SHAREDLIB=libz.so
31 SHAREDLIBV=libz.so.1.3
32 SHAREDLIBM=libz.so.1
33 LIBS=$(STATICLIB) $(SHAREDLIBV)
34
35 AR=ar
36 ARFLAGS=rc
@@ -357,12 +357,18 @@
357 rm $$TEMPFILE
358
359 zconf: $(SRCDIR)zconf.h.in
360 cp -p $(SRCDIR)zconf.h.in zconf.h
361
362 minizip-test: static
363 cd contrib/minizip && { CFLAGS="$(CFLAGS)" $(MAKE) test ; cd ../.. ; }
364
365 minizip-clean:
366 cd contrib/minizip && { $(MAKE) clean ; cd ../.. ; }
367
368 mostlyclean: clean
369 clean: minizip-clean
370 rm -f *.o *.lo *~ \
371 example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
372 example64$(EXE) minigzip64$(EXE) \
373 infcover \
374 libz.* foo.gz so_locations \
375
--- compat/zlib/README
+++ compat/zlib/README
@@ -1,8 +1,8 @@
11
ZLIB DATA COMPRESSION LIBRARY
22
3
-zlib 1.2.13 is a general purpose data compression library. All the code is
3
+zlib 1.3 is a general purpose data compression library. All the code is
44
thread safe. The data format used by the zlib library is described by RFCs
55
(Request for Comments) 1950 to 1952 in the files
66
http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
77
rfc1952 (gzip format).
88
@@ -27,22 +27,21 @@
2727
2828
PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
2929
3030
Mark Nelson <[email protected]> wrote an article about zlib for the Jan. 1997
3131
issue of Dr. Dobb's Journal; a copy of the article is available at
32
-http://marknelson.us/1997/01/01/zlib-engine/ .
32
+https://marknelson.us/posts/1997/01/01/zlib-engine.html .
3333
34
-The changes made in version 1.2.13 are documented in the file ChangeLog.
34
+The changes made in version 1.3 are documented in the file ChangeLog.
3535
3636
Unsupported third party contributions are provided in directory contrib/ .
3737
38
-zlib is available in Java using the java.util.zip package, documented at
39
-http://java.sun.com/developer/technicalArticles/Programming/compression/ .
38
+zlib is available in Java using the java.util.zip package. Follow the API
39
+Documentation link at: https://docs.oracle.com/search/?q=java.util.zip .
4040
41
-A Perl interface to zlib written by Paul Marquess <[email protected]> is available
42
-at CPAN (Comprehensive Perl Archive Network) sites, including
43
-http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
41
+A Perl interface to zlib and bzip2 written by Paul Marquess <[email protected]>
42
+can be found at https://github.com/pmqs/IO-Compress .
4443
4544
A Python interface to zlib written by A.M. Kuchling <[email protected]> is
4645
available in Python 1.5 and later versions, see
4746
http://docs.python.org/library/zlib.html .
4847
@@ -62,11 +61,11 @@
6261
compiler flag). The compiler bug has been reported to SGI.
6362
6463
- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
6564
when compiled with cc.
6665
67
-- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
66
+- On Digital Unix 4.0D (formerly OSF/1) on AlphaServer, the cc option -std1 is
6867
necessary to get gzprintf working correctly. This is done by configure.
6968
7069
- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
7170
other compilers. Use "make test" to check your compiler.
7271
@@ -82,11 +81,11 @@
8281
people who reported problems and suggested various improvements in zlib; they
8382
are too numerous to cite here.
8483
8584
Copyright notice:
8685
87
- (C) 1995-2022 Jean-loup Gailly and Mark Adler
86
+ (C) 1995-2023 Jean-loup Gailly and Mark Adler
8887
8988
This software is provided 'as-is', without any express or implied
9089
warranty. In no event will the authors be held liable for any damages
9190
arising from the use of this software.
9291
9392
--- compat/zlib/README
+++ compat/zlib/README
@@ -1,8 +1,8 @@
1 ZLIB DATA COMPRESSION LIBRARY
2
3 zlib 1.2.13 is a general purpose data compression library. All the code is
4 thread safe. The data format used by the zlib library is described by RFCs
5 (Request for Comments) 1950 to 1952 in the files
6 http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
7 rfc1952 (gzip format).
8
@@ -27,22 +27,21 @@
27
28 PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
29
30 Mark Nelson <[email protected]> wrote an article about zlib for the Jan. 1997
31 issue of Dr. Dobb's Journal; a copy of the article is available at
32 http://marknelson.us/1997/01/01/zlib-engine/ .
33
34 The changes made in version 1.2.13 are documented in the file ChangeLog.
35
36 Unsupported third party contributions are provided in directory contrib/ .
37
38 zlib is available in Java using the java.util.zip package, documented at
39 http://java.sun.com/developer/technicalArticles/Programming/compression/ .
40
41 A Perl interface to zlib written by Paul Marquess <[email protected]> is available
42 at CPAN (Comprehensive Perl Archive Network) sites, including
43 http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
44
45 A Python interface to zlib written by A.M. Kuchling <[email protected]> is
46 available in Python 1.5 and later versions, see
47 http://docs.python.org/library/zlib.html .
48
@@ -62,11 +61,11 @@
62 compiler flag). The compiler bug has been reported to SGI.
63
64 - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
65 when compiled with cc.
66
67 - On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
68 necessary to get gzprintf working correctly. This is done by configure.
69
70 - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
71 other compilers. Use "make test" to check your compiler.
72
@@ -82,11 +81,11 @@
82 people who reported problems and suggested various improvements in zlib; they
83 are too numerous to cite here.
84
85 Copyright notice:
86
87 (C) 1995-2022 Jean-loup Gailly and Mark Adler
88
89 This software is provided 'as-is', without any express or implied
90 warranty. In no event will the authors be held liable for any damages
91 arising from the use of this software.
92
93
--- compat/zlib/README
+++ compat/zlib/README
@@ -1,8 +1,8 @@
1 ZLIB DATA COMPRESSION LIBRARY
2
3 zlib 1.3 is a general purpose data compression library. All the code is
4 thread safe. The data format used by the zlib library is described by RFCs
5 (Request for Comments) 1950 to 1952 in the files
6 http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
7 rfc1952 (gzip format).
8
@@ -27,22 +27,21 @@
27
28 PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
29
30 Mark Nelson <[email protected]> wrote an article about zlib for the Jan. 1997
31 issue of Dr. Dobb's Journal; a copy of the article is available at
32 https://marknelson.us/posts/1997/01/01/zlib-engine.html .
33
34 The changes made in version 1.3 are documented in the file ChangeLog.
35
36 Unsupported third party contributions are provided in directory contrib/ .
37
38 zlib is available in Java using the java.util.zip package. Follow the API
39 Documentation link at: https://docs.oracle.com/search/?q=java.util.zip .
40
41 A Perl interface to zlib and bzip2 written by Paul Marquess <[email protected]>
42 can be found at https://github.com/pmqs/IO-Compress .
 
43
44 A Python interface to zlib written by A.M. Kuchling <[email protected]> is
45 available in Python 1.5 and later versions, see
46 http://docs.python.org/library/zlib.html .
47
@@ -62,11 +61,11 @@
61 compiler flag). The compiler bug has been reported to SGI.
62
63 - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
64 when compiled with cc.
65
66 - On Digital Unix 4.0D (formerly OSF/1) on AlphaServer, the cc option -std1 is
67 necessary to get gzprintf working correctly. This is done by configure.
68
69 - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
70 other compilers. Use "make test" to check your compiler.
71
@@ -82,11 +81,11 @@
81 people who reported problems and suggested various improvements in zlib; they
82 are too numerous to cite here.
83
84 Copyright notice:
85
86 (C) 1995-2023 Jean-loup Gailly and Mark Adler
87
88 This software is provided 'as-is', without any express or implied
89 warranty. In no event will the authors be held liable for any damages
90 arising from the use of this software.
91
92
--- compat/zlib/adler32.c
+++ compat/zlib/adler32.c
@@ -5,12 +5,10 @@
55
66
/* @(#) $Id$ */
77
88
#include "zutil.h"
99
10
-local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
11
-
1210
#define BASE 65521U /* largest prime smaller than 65536 */
1311
#define NMAX 5552
1412
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
1513
1614
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
@@ -58,15 +56,11 @@
5856
# define MOD28(a) a %= BASE
5957
# define MOD63(a) a %= BASE
6058
#endif
6159
6260
/* ========================================================================= */
63
-uLong ZEXPORT adler32_z(adler, buf, len)
64
- uLong adler;
65
- const Bytef *buf;
66
- z_size_t len;
67
-{
61
+uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
6862
unsigned long sum2;
6963
unsigned n;
7064
7165
/* split Adler-32 into component sums */
7266
sum2 = (adler >> 16) & 0xffff;
@@ -129,24 +123,16 @@
129123
/* return recombined sums */
130124
return adler | (sum2 << 16);
131125
}
132126
133127
/* ========================================================================= */
134
-uLong ZEXPORT adler32(adler, buf, len)
135
- uLong adler;
136
- const Bytef *buf;
137
- uInt len;
138
-{
128
+uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
139129
return adler32_z(adler, buf, len);
140130
}
141131
142132
/* ========================================================================= */
143
-local uLong adler32_combine_(adler1, adler2, len2)
144
- uLong adler1;
145
- uLong adler2;
146
- z_off64_t len2;
147
-{
133
+local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
148134
unsigned long sum1;
149135
unsigned long sum2;
150136
unsigned rem;
151137
152138
/* for negative len, return invalid adler32 as a clue for debugging */
@@ -167,20 +153,12 @@
167153
if (sum2 >= BASE) sum2 -= BASE;
168154
return sum1 | (sum2 << 16);
169155
}
170156
171157
/* ========================================================================= */
172
-uLong ZEXPORT adler32_combine(adler1, adler2, len2)
173
- uLong adler1;
174
- uLong adler2;
175
- z_off_t len2;
176
-{
158
+uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) {
177159
return adler32_combine_(adler1, adler2, len2);
178160
}
179161
180
-uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
181
- uLong adler1;
182
- uLong adler2;
183
- z_off64_t len2;
184
-{
162
+uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) {
185163
return adler32_combine_(adler1, adler2, len2);
186164
}
187165
--- compat/zlib/adler32.c
+++ compat/zlib/adler32.c
@@ -5,12 +5,10 @@
5
6 /* @(#) $Id$ */
7
8 #include "zutil.h"
9
10 local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
11
12 #define BASE 65521U /* largest prime smaller than 65536 */
13 #define NMAX 5552
14 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
15
16 #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
@@ -58,15 +56,11 @@
58 # define MOD28(a) a %= BASE
59 # define MOD63(a) a %= BASE
60 #endif
61
62 /* ========================================================================= */
63 uLong ZEXPORT adler32_z(adler, buf, len)
64 uLong adler;
65 const Bytef *buf;
66 z_size_t len;
67 {
68 unsigned long sum2;
69 unsigned n;
70
71 /* split Adler-32 into component sums */
72 sum2 = (adler >> 16) & 0xffff;
@@ -129,24 +123,16 @@
129 /* return recombined sums */
130 return adler | (sum2 << 16);
131 }
132
133 /* ========================================================================= */
134 uLong ZEXPORT adler32(adler, buf, len)
135 uLong adler;
136 const Bytef *buf;
137 uInt len;
138 {
139 return adler32_z(adler, buf, len);
140 }
141
142 /* ========================================================================= */
143 local uLong adler32_combine_(adler1, adler2, len2)
144 uLong adler1;
145 uLong adler2;
146 z_off64_t len2;
147 {
148 unsigned long sum1;
149 unsigned long sum2;
150 unsigned rem;
151
152 /* for negative len, return invalid adler32 as a clue for debugging */
@@ -167,20 +153,12 @@
167 if (sum2 >= BASE) sum2 -= BASE;
168 return sum1 | (sum2 << 16);
169 }
170
171 /* ========================================================================= */
172 uLong ZEXPORT adler32_combine(adler1, adler2, len2)
173 uLong adler1;
174 uLong adler2;
175 z_off_t len2;
176 {
177 return adler32_combine_(adler1, adler2, len2);
178 }
179
180 uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
181 uLong adler1;
182 uLong adler2;
183 z_off64_t len2;
184 {
185 return adler32_combine_(adler1, adler2, len2);
186 }
187
--- compat/zlib/adler32.c
+++ compat/zlib/adler32.c
@@ -5,12 +5,10 @@
5
6 /* @(#) $Id$ */
7
8 #include "zutil.h"
9
 
 
10 #define BASE 65521U /* largest prime smaller than 65536 */
11 #define NMAX 5552
12 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
13
14 #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
@@ -58,15 +56,11 @@
56 # define MOD28(a) a %= BASE
57 # define MOD63(a) a %= BASE
58 #endif
59
60 /* ========================================================================= */
61 uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
 
 
 
 
62 unsigned long sum2;
63 unsigned n;
64
65 /* split Adler-32 into component sums */
66 sum2 = (adler >> 16) & 0xffff;
@@ -129,24 +123,16 @@
123 /* return recombined sums */
124 return adler | (sum2 << 16);
125 }
126
127 /* ========================================================================= */
128 uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
 
 
 
 
129 return adler32_z(adler, buf, len);
130 }
131
132 /* ========================================================================= */
133 local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
 
 
 
 
134 unsigned long sum1;
135 unsigned long sum2;
136 unsigned rem;
137
138 /* for negative len, return invalid adler32 as a clue for debugging */
@@ -167,20 +153,12 @@
153 if (sum2 >= BASE) sum2 -= BASE;
154 return sum1 | (sum2 << 16);
155 }
156
157 /* ========================================================================= */
158 uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) {
 
 
 
 
159 return adler32_combine_(adler1, adler2, len2);
160 }
161
162 uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) {
 
 
 
 
163 return adler32_combine_(adler1, adler2, len2);
164 }
165
--- compat/zlib/compress.c
+++ compat/zlib/compress.c
@@ -17,17 +17,12 @@
1717
1818
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1919
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
2020
Z_STREAM_ERROR if the level parameter is invalid.
2121
*/
22
-int ZEXPORT compress2(dest, destLen, source, sourceLen, level)
23
- Bytef *dest;
24
- uLongf *destLen;
25
- const Bytef *source;
26
- uLong sourceLen;
27
- int level;
28
-{
22
+int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
23
+ uLong sourceLen, int level) {
2924
z_stream stream;
3025
int err;
3126
const uInt max = (uInt)-1;
3227
uLong left;
3328
@@ -63,24 +58,18 @@
6358
return err == Z_STREAM_END ? Z_OK : err;
6459
}
6560
6661
/* ===========================================================================
6762
*/
68
-int ZEXPORT compress(dest, destLen, source, sourceLen)
69
- Bytef *dest;
70
- uLongf *destLen;
71
- const Bytef *source;
72
- uLong sourceLen;
73
-{
63
+int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
64
+ uLong sourceLen) {
7465
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
7566
}
7667
7768
/* ===========================================================================
7869
If the default memLevel or windowBits for deflateInit() is changed, then
7970
this function needs to be updated.
8071
*/
81
-uLong ZEXPORT compressBound(sourceLen)
82
- uLong sourceLen;
83
-{
72
+uLong ZEXPORT compressBound(uLong sourceLen) {
8473
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
8574
(sourceLen >> 25) + 13;
8675
}
8776
--- compat/zlib/compress.c
+++ compat/zlib/compress.c
@@ -17,17 +17,12 @@
17
18 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
19 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
20 Z_STREAM_ERROR if the level parameter is invalid.
21 */
22 int ZEXPORT compress2(dest, destLen, source, sourceLen, level)
23 Bytef *dest;
24 uLongf *destLen;
25 const Bytef *source;
26 uLong sourceLen;
27 int level;
28 {
29 z_stream stream;
30 int err;
31 const uInt max = (uInt)-1;
32 uLong left;
33
@@ -63,24 +58,18 @@
63 return err == Z_STREAM_END ? Z_OK : err;
64 }
65
66 /* ===========================================================================
67 */
68 int ZEXPORT compress(dest, destLen, source, sourceLen)
69 Bytef *dest;
70 uLongf *destLen;
71 const Bytef *source;
72 uLong sourceLen;
73 {
74 return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
75 }
76
77 /* ===========================================================================
78 If the default memLevel or windowBits for deflateInit() is changed, then
79 this function needs to be updated.
80 */
81 uLong ZEXPORT compressBound(sourceLen)
82 uLong sourceLen;
83 {
84 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
85 (sourceLen >> 25) + 13;
86 }
87
--- compat/zlib/compress.c
+++ compat/zlib/compress.c
@@ -17,17 +17,12 @@
17
18 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
19 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
20 Z_STREAM_ERROR if the level parameter is invalid.
21 */
22 int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
23 uLong sourceLen, int level) {
 
 
 
 
 
24 z_stream stream;
25 int err;
26 const uInt max = (uInt)-1;
27 uLong left;
28
@@ -63,24 +58,18 @@
58 return err == Z_STREAM_END ? Z_OK : err;
59 }
60
61 /* ===========================================================================
62 */
63 int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
64 uLong sourceLen) {
 
 
 
 
65 return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
66 }
67
68 /* ===========================================================================
69 If the default memLevel or windowBits for deflateInit() is changed, then
70 this function needs to be updated.
71 */
72 uLong ZEXPORT compressBound(uLong sourceLen) {
 
 
73 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
74 (sourceLen >> 25) + 13;
75 }
76
--- compat/zlib/configure
+++ compat/zlib/configure
@@ -42,12 +42,10 @@
4242
# destination name for static library
4343
STATICLIB=libz.a
4444
4545
# extract zlib version numbers from zlib.h
4646
VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < ${SRCDIR}zlib.h`
47
-VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < ${SRCDIR}zlib.h`
48
-VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
4947
VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
5048
5149
# establish commands for library building
5250
if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
5351
AR=${AR-"${CROSS_PREFIX}ar"}
@@ -88,11 +86,12 @@
8886
zconst=0
8987
build64=0
9088
gcc=0
9189
warn=0
9290
debug=0
93
-sanitize=0
91
+address=0
92
+memory=0
9493
old_cc="$CC"
9594
old_cflags="$CFLAGS"
9695
OBJC='$(OBJZ) $(OBJG)'
9796
PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
9897
@@ -100,11 +99,11 @@
10099
leave()
101100
{
102101
if test "$*" != "0"; then
103102
echo "** $0 aborting." | tee -a configure.log
104103
fi
105
- rm -f $test.[co] $test $test$shared_ext $test.gcno ./--version
104
+ rm -rf $test.[co] $test $test$shared_ext $test.gcno $test.dSYM ./--version
106105
echo -------------------- >> configure.log
107106
echo >> configure.log
108107
echo >> configure.log
109108
exit $1
110109
}
@@ -139,11 +138,13 @@
139138
--sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
140139
--localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
141140
-c* | --const) zconst=1; shift ;;
142141
-w* | --warn) warn=1; shift ;;
143142
-d* | --debug) debug=1; shift ;;
144
- --sanitize) sanitize=1; shift ;;
143
+ --sanitize) address=1; shift ;;
144
+ --address) address=1; shift ;;
145
+ --memory) memory=1; shift ;;
145146
*)
146147
echo "unknown option: $1" | tee -a configure.log
147148
echo "$0 --help for help" | tee -a configure.log
148149
leave 1;;
149150
esac
@@ -209,12 +210,15 @@
209210
CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -DZLIB_CONST"
210211
else
211212
CFLAGS="${CFLAGS} -Wall -Wextra"
212213
fi
213214
fi
214
- if test $sanitize -eq 1; then
215
- CFLAGS="${CFLAGS} -g -fsanitize=address"
215
+ if test $address -eq 1; then
216
+ CFLAGS="${CFLAGS} -g -fsanitize=address -fno-omit-frame-pointer"
217
+ fi
218
+ if test $memory -eq 1; then
219
+ CFLAGS="${CFLAGS} -g -fsanitize=memory -fno-omit-frame-pointer"
216220
fi
217221
if test $debug -eq 1; then
218222
CFLAGS="${CFLAGS} -DZLIB_DEBUG"
219223
SFLAGS="${SFLAGS} -DZLIB_DEBUG"
220224
fi
@@ -257,12 +261,14 @@
257261
Darwin* | darwin* | *-darwin*)
258262
shared_ext='.dylib'
259263
SHAREDLIB=libz$shared_ext
260264
SHAREDLIBV=libz.$VER$shared_ext
261265
SHAREDLIBM=libz.$VER1$shared_ext
262
- LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
263
- if libtool -V 2>&1 | grep Apple > /dev/null; then
266
+ LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER"}
267
+ if "${CROSS_PREFIX}libtool" -V 2>&1 | grep Apple > /dev/null; then
268
+ AR="${CROSS_PREFIX}libtool"
269
+ elif libtool -V 2>&1 | grep Apple > /dev/null; then
264270
AR="libtool"
265271
else
266272
AR="/usr/bin/libtool"
267273
fi
268274
ARFLAGS="-o" ;;
@@ -858,11 +864,11 @@
858864
echo mandir = $mandir >> configure.log
859865
echo prefix = $prefix >> configure.log
860866
echo sharedlibdir = $sharedlibdir >> configure.log
861867
echo uname = $uname >> configure.log
862868
863
-# udpate Makefile with the configure results
869
+# update Makefile with the configure results
864870
sed < ${SRCDIR}Makefile.in "
865871
/^CC *=/s#=.*#=$CC#
866872
/^CFLAGS *=/s#=.*#=$CFLAGS#
867873
/^SFLAGS *=/s#=.*#=$SFLAGS#
868874
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
869875
--- compat/zlib/configure
+++ compat/zlib/configure
@@ -42,12 +42,10 @@
42 # destination name for static library
43 STATICLIB=libz.a
44
45 # extract zlib version numbers from zlib.h
46 VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < ${SRCDIR}zlib.h`
47 VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < ${SRCDIR}zlib.h`
48 VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
49 VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
50
51 # establish commands for library building
52 if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
53 AR=${AR-"${CROSS_PREFIX}ar"}
@@ -88,11 +86,12 @@
88 zconst=0
89 build64=0
90 gcc=0
91 warn=0
92 debug=0
93 sanitize=0
 
94 old_cc="$CC"
95 old_cflags="$CFLAGS"
96 OBJC='$(OBJZ) $(OBJG)'
97 PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
98
@@ -100,11 +99,11 @@
100 leave()
101 {
102 if test "$*" != "0"; then
103 echo "** $0 aborting." | tee -a configure.log
104 fi
105 rm -f $test.[co] $test $test$shared_ext $test.gcno ./--version
106 echo -------------------- >> configure.log
107 echo >> configure.log
108 echo >> configure.log
109 exit $1
110 }
@@ -139,11 +138,13 @@
139 --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
140 --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
141 -c* | --const) zconst=1; shift ;;
142 -w* | --warn) warn=1; shift ;;
143 -d* | --debug) debug=1; shift ;;
144 --sanitize) sanitize=1; shift ;;
 
 
145 *)
146 echo "unknown option: $1" | tee -a configure.log
147 echo "$0 --help for help" | tee -a configure.log
148 leave 1;;
149 esac
@@ -209,12 +210,15 @@
209 CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -DZLIB_CONST"
210 else
211 CFLAGS="${CFLAGS} -Wall -Wextra"
212 fi
213 fi
214 if test $sanitize -eq 1; then
215 CFLAGS="${CFLAGS} -g -fsanitize=address"
 
 
 
216 fi
217 if test $debug -eq 1; then
218 CFLAGS="${CFLAGS} -DZLIB_DEBUG"
219 SFLAGS="${SFLAGS} -DZLIB_DEBUG"
220 fi
@@ -257,12 +261,14 @@
257 Darwin* | darwin* | *-darwin*)
258 shared_ext='.dylib'
259 SHAREDLIB=libz$shared_ext
260 SHAREDLIBV=libz.$VER$shared_ext
261 SHAREDLIBM=libz.$VER1$shared_ext
262 LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
263 if libtool -V 2>&1 | grep Apple > /dev/null; then
 
 
264 AR="libtool"
265 else
266 AR="/usr/bin/libtool"
267 fi
268 ARFLAGS="-o" ;;
@@ -858,11 +864,11 @@
858 echo mandir = $mandir >> configure.log
859 echo prefix = $prefix >> configure.log
860 echo sharedlibdir = $sharedlibdir >> configure.log
861 echo uname = $uname >> configure.log
862
863 # udpate Makefile with the configure results
864 sed < ${SRCDIR}Makefile.in "
865 /^CC *=/s#=.*#=$CC#
866 /^CFLAGS *=/s#=.*#=$CFLAGS#
867 /^SFLAGS *=/s#=.*#=$SFLAGS#
868 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
869
--- compat/zlib/configure
+++ compat/zlib/configure
@@ -42,12 +42,10 @@
42 # destination name for static library
43 STATICLIB=libz.a
44
45 # extract zlib version numbers from zlib.h
46 VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < ${SRCDIR}zlib.h`
 
 
47 VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
48
49 # establish commands for library building
50 if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
51 AR=${AR-"${CROSS_PREFIX}ar"}
@@ -88,11 +86,12 @@
86 zconst=0
87 build64=0
88 gcc=0
89 warn=0
90 debug=0
91 address=0
92 memory=0
93 old_cc="$CC"
94 old_cflags="$CFLAGS"
95 OBJC='$(OBJZ) $(OBJG)'
96 PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
97
@@ -100,11 +99,11 @@
99 leave()
100 {
101 if test "$*" != "0"; then
102 echo "** $0 aborting." | tee -a configure.log
103 fi
104 rm -rf $test.[co] $test $test$shared_ext $test.gcno $test.dSYM ./--version
105 echo -------------------- >> configure.log
106 echo >> configure.log
107 echo >> configure.log
108 exit $1
109 }
@@ -139,11 +138,13 @@
138 --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
139 --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
140 -c* | --const) zconst=1; shift ;;
141 -w* | --warn) warn=1; shift ;;
142 -d* | --debug) debug=1; shift ;;
143 --sanitize) address=1; shift ;;
144 --address) address=1; shift ;;
145 --memory) memory=1; shift ;;
146 *)
147 echo "unknown option: $1" | tee -a configure.log
148 echo "$0 --help for help" | tee -a configure.log
149 leave 1;;
150 esac
@@ -209,12 +210,15 @@
210 CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -DZLIB_CONST"
211 else
212 CFLAGS="${CFLAGS} -Wall -Wextra"
213 fi
214 fi
215 if test $address -eq 1; then
216 CFLAGS="${CFLAGS} -g -fsanitize=address -fno-omit-frame-pointer"
217 fi
218 if test $memory -eq 1; then
219 CFLAGS="${CFLAGS} -g -fsanitize=memory -fno-omit-frame-pointer"
220 fi
221 if test $debug -eq 1; then
222 CFLAGS="${CFLAGS} -DZLIB_DEBUG"
223 SFLAGS="${SFLAGS} -DZLIB_DEBUG"
224 fi
@@ -257,12 +261,14 @@
261 Darwin* | darwin* | *-darwin*)
262 shared_ext='.dylib'
263 SHAREDLIB=libz$shared_ext
264 SHAREDLIBV=libz.$VER$shared_ext
265 SHAREDLIBM=libz.$VER1$shared_ext
266 LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER"}
267 if "${CROSS_PREFIX}libtool" -V 2>&1 | grep Apple > /dev/null; then
268 AR="${CROSS_PREFIX}libtool"
269 elif libtool -V 2>&1 | grep Apple > /dev/null; then
270 AR="libtool"
271 else
272 AR="/usr/bin/libtool"
273 fi
274 ARFLAGS="-o" ;;
@@ -858,11 +864,11 @@
864 echo mandir = $mandir >> configure.log
865 echo prefix = $prefix >> configure.log
866 echo sharedlibdir = $sharedlibdir >> configure.log
867 echo uname = $uname >> configure.log
868
869 # update Makefile with the configure results
870 sed < ${SRCDIR}Makefile.in "
871 /^CC *=/s#=.*#=$CC#
872 /^CFLAGS *=/s#=.*#=$CFLAGS#
873 /^SFLAGS *=/s#=.*#=$SFLAGS#
874 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
875
--- compat/zlib/contrib/delphi/ZLib.pas
+++ compat/zlib/contrib/delphi/ZLib.pas
@@ -150,11 +150,11 @@
150150
BufSize = number of bytes in OutBuf }
151151
procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer;
152152
const OutBuf: Pointer; BufSize: Integer);
153153
154154
const
155
- zlib_version = '1.2.13';
155
+ zlib_version = '1.3.0';
156156
157157
type
158158
EZlibError = class(Exception);
159159
ECompressionError = class(EZlibError);
160160
EDecompressionError = class(EZlibError);
161161
--- compat/zlib/contrib/delphi/ZLib.pas
+++ compat/zlib/contrib/delphi/ZLib.pas
@@ -150,11 +150,11 @@
150 BufSize = number of bytes in OutBuf }
151 procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer;
152 const OutBuf: Pointer; BufSize: Integer);
153
154 const
155 zlib_version = '1.2.13';
156
157 type
158 EZlibError = class(Exception);
159 ECompressionError = class(EZlibError);
160 EDecompressionError = class(EZlibError);
161
--- compat/zlib/contrib/delphi/ZLib.pas
+++ compat/zlib/contrib/delphi/ZLib.pas
@@ -150,11 +150,11 @@
150 BufSize = number of bytes in OutBuf }
151 procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer;
152 const OutBuf: Pointer; BufSize: Integer);
153
154 const
155 zlib_version = '1.3.0';
156
157 type
158 EZlibError = class(Exception);
159 ECompressionError = class(EZlibError);
160 EDecompressionError = class(EZlibError);
161
--- compat/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs
+++ compat/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs
@@ -59,11 +59,11 @@
5959
/// <param name="offset">Where in <c>data</c> to start updating</param>
6060
/// <param name="count">The number of bytes from <c>data</c> to use</param>
6161
/// <exception cref="ArgumentException">The sum of offset and count is larger than the length of <c>data</c></exception>
6262
/// <exception cref="NullReferenceException"><c>data</c> is a null reference</exception>
6363
/// <exception cref="ArgumentOutOfRangeException">Offset or count is negative.</exception>
64
- /// <remarks>All the other <c>Update</c> methods are implmeneted in terms of this one.
64
+ /// <remarks>All the other <c>Update</c> methods are implemented in terms of this one.
6565
/// This is therefore the only method a derived class has to implement</remarks>
6666
public abstract void Update(byte[] data, int offset, int count);
6767
6868
/// <summary>
6969
/// Updates the current checksum with an array of bytes.
7070
--- compat/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs
+++ compat/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs
@@ -59,11 +59,11 @@
59 /// <param name="offset">Where in <c>data</c> to start updating</param>
60 /// <param name="count">The number of bytes from <c>data</c> to use</param>
61 /// <exception cref="ArgumentException">The sum of offset and count is larger than the length of <c>data</c></exception>
62 /// <exception cref="NullReferenceException"><c>data</c> is a null reference</exception>
63 /// <exception cref="ArgumentOutOfRangeException">Offset or count is negative.</exception>
64 /// <remarks>All the other <c>Update</c> methods are implmeneted in terms of this one.
65 /// This is therefore the only method a derived class has to implement</remarks>
66 public abstract void Update(byte[] data, int offset, int count);
67
68 /// <summary>
69 /// Updates the current checksum with an array of bytes.
70
--- compat/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs
+++ compat/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs
@@ -59,11 +59,11 @@
59 /// <param name="offset">Where in <c>data</c> to start updating</param>
60 /// <param name="count">The number of bytes from <c>data</c> to use</param>
61 /// <exception cref="ArgumentException">The sum of offset and count is larger than the length of <c>data</c></exception>
62 /// <exception cref="NullReferenceException"><c>data</c> is a null reference</exception>
63 /// <exception cref="ArgumentOutOfRangeException">Offset or count is negative.</exception>
64 /// <remarks>All the other <c>Update</c> methods are implemented in terms of this one.
65 /// This is therefore the only method a derived class has to implement</remarks>
66 public abstract void Update(byte[] data, int offset, int count);
67
68 /// <summary>
69 /// Updates the current checksum with an array of bytes.
70
--- compat/zlib/contrib/dotzlib/DotZLib/CodecBase.cs
+++ compat/zlib/contrib/dotzlib/DotZLib/CodecBase.cs
@@ -137,11 +137,11 @@
137137
/// Performs any codec specific cleanup
138138
/// </summary>
139139
/// <remarks>This must be implemented by a derived class</remarks>
140140
protected abstract void CleanUp();
141141
142
- // performs the release of the handles and calls the dereived CleanUp()
142
+ // performs the release of the handles and calls the derived CleanUp()
143143
private void CleanUp(bool isDisposing)
144144
{
145145
if (!_isDisposed)
146146
{
147147
CleanUp();
@@ -158,11 +158,11 @@
158158
#endregion
159159
160160
#region Helper methods
161161
162162
/// <summary>
163
- /// Copies a number of bytes to the internal codec buffer - ready for proccesing
163
+ /// Copies a number of bytes to the internal codec buffer - ready for processing
164164
/// </summary>
165165
/// <param name="data">The byte array that contains the data to copy</param>
166166
/// <param name="startIndex">The index of the first byte to copy</param>
167167
/// <param name="count">The number of bytes to copy from <c>data</c></param>
168168
protected void copyInput(byte[] data, int startIndex, int count)
169169
--- compat/zlib/contrib/dotzlib/DotZLib/CodecBase.cs
+++ compat/zlib/contrib/dotzlib/DotZLib/CodecBase.cs
@@ -137,11 +137,11 @@
137 /// Performs any codec specific cleanup
138 /// </summary>
139 /// <remarks>This must be implemented by a derived class</remarks>
140 protected abstract void CleanUp();
141
142 // performs the release of the handles and calls the dereived CleanUp()
143 private void CleanUp(bool isDisposing)
144 {
145 if (!_isDisposed)
146 {
147 CleanUp();
@@ -158,11 +158,11 @@
158 #endregion
159
160 #region Helper methods
161
162 /// <summary>
163 /// Copies a number of bytes to the internal codec buffer - ready for proccesing
164 /// </summary>
165 /// <param name="data">The byte array that contains the data to copy</param>
166 /// <param name="startIndex">The index of the first byte to copy</param>
167 /// <param name="count">The number of bytes to copy from <c>data</c></param>
168 protected void copyInput(byte[] data, int startIndex, int count)
169
--- compat/zlib/contrib/dotzlib/DotZLib/CodecBase.cs
+++ compat/zlib/contrib/dotzlib/DotZLib/CodecBase.cs
@@ -137,11 +137,11 @@
137 /// Performs any codec specific cleanup
138 /// </summary>
139 /// <remarks>This must be implemented by a derived class</remarks>
140 protected abstract void CleanUp();
141
142 // performs the release of the handles and calls the derived CleanUp()
143 private void CleanUp(bool isDisposing)
144 {
145 if (!_isDisposed)
146 {
147 CleanUp();
@@ -158,11 +158,11 @@
158 #endregion
159
160 #region Helper methods
161
162 /// <summary>
163 /// Copies a number of bytes to the internal codec buffer - ready for processing
164 /// </summary>
165 /// <param name="data">The byte array that contains the data to copy</param>
166 /// <param name="startIndex">The index of the first byte to copy</param>
167 /// <param name="count">The number of bytes to copy from <c>data</c></param>
168 protected void copyInput(byte[] data, int startIndex, int count)
169
--- compat/zlib/contrib/dotzlib/DotZLib/GZipStream.cs
+++ compat/zlib/contrib/dotzlib/DotZLib/GZipStream.cs
@@ -244,11 +244,11 @@
244244
{
245245
throw new NotSupportedException();
246246
}
247247
248248
/// <summary>
249
- /// Not suppported.
249
+ /// Not supported.
250250
/// </summary>
251251
/// <param name="offset"></param>
252252
/// <param name="origin"></param>
253253
/// <returns></returns>
254254
/// <exception cref="NotSupportedException">Always thrown</exception>
@@ -266,11 +266,11 @@
266266
{
267267
// left empty on purpose
268268
}
269269
270270
/// <summary>
271
- /// Gets/sets the current position in the <c>GZipStream</c>. Not suppported.
271
+ /// Gets/sets the current position in the <c>GZipStream</c>. Not supported.
272272
/// </summary>
273273
/// <remarks>In this implementation this property is not supported</remarks>
274274
/// <exception cref="NotSupportedException">Always thrown</exception>
275275
public override long Position
276276
{
@@ -283,11 +283,11 @@
283283
throw new NotSupportedException();
284284
}
285285
}
286286
287287
/// <summary>
288
- /// Gets the size of the stream. Not suppported.
288
+ /// Gets the size of the stream. Not supported.
289289
/// </summary>
290290
/// <remarks>In this implementation this property is not supported</remarks>
291291
/// <exception cref="NotSupportedException">Always thrown</exception>
292292
public override long Length
293293
{
294294
--- compat/zlib/contrib/dotzlib/DotZLib/GZipStream.cs
+++ compat/zlib/contrib/dotzlib/DotZLib/GZipStream.cs
@@ -244,11 +244,11 @@
244 {
245 throw new NotSupportedException();
246 }
247
248 /// <summary>
249 /// Not suppported.
250 /// </summary>
251 /// <param name="offset"></param>
252 /// <param name="origin"></param>
253 /// <returns></returns>
254 /// <exception cref="NotSupportedException">Always thrown</exception>
@@ -266,11 +266,11 @@
266 {
267 // left empty on purpose
268 }
269
270 /// <summary>
271 /// Gets/sets the current position in the <c>GZipStream</c>. Not suppported.
272 /// </summary>
273 /// <remarks>In this implementation this property is not supported</remarks>
274 /// <exception cref="NotSupportedException">Always thrown</exception>
275 public override long Position
276 {
@@ -283,11 +283,11 @@
283 throw new NotSupportedException();
284 }
285 }
286
287 /// <summary>
288 /// Gets the size of the stream. Not suppported.
289 /// </summary>
290 /// <remarks>In this implementation this property is not supported</remarks>
291 /// <exception cref="NotSupportedException">Always thrown</exception>
292 public override long Length
293 {
294
--- compat/zlib/contrib/dotzlib/DotZLib/GZipStream.cs
+++ compat/zlib/contrib/dotzlib/DotZLib/GZipStream.cs
@@ -244,11 +244,11 @@
244 {
245 throw new NotSupportedException();
246 }
247
248 /// <summary>
249 /// Not supported.
250 /// </summary>
251 /// <param name="offset"></param>
252 /// <param name="origin"></param>
253 /// <returns></returns>
254 /// <exception cref="NotSupportedException">Always thrown</exception>
@@ -266,11 +266,11 @@
266 {
267 // left empty on purpose
268 }
269
270 /// <summary>
271 /// Gets/sets the current position in the <c>GZipStream</c>. Not supported.
272 /// </summary>
273 /// <remarks>In this implementation this property is not supported</remarks>
274 /// <exception cref="NotSupportedException">Always thrown</exception>
275 public override long Position
276 {
@@ -283,11 +283,11 @@
283 throw new NotSupportedException();
284 }
285 }
286
287 /// <summary>
288 /// Gets the size of the stream. Not supported.
289 /// </summary>
290 /// <remarks>In this implementation this property is not supported</remarks>
291 /// <exception cref="NotSupportedException">Always thrown</exception>
292 public override long Length
293 {
294
--- compat/zlib/contrib/dotzlib/DotZLib/UnitTests.cs
+++ compat/zlib/contrib/dotzlib/DotZLib/UnitTests.cs
@@ -154,11 +154,11 @@
154154
#region Info tests
155155
[Test]
156156
public void Info_Version()
157157
{
158158
Info info = new Info();
159
- Assert.AreEqual("1.2.13", Info.Version);
159
+ Assert.AreEqual("1.3.0", Info.Version);
160160
Assert.AreEqual(32, info.SizeOfUInt);
161161
Assert.AreEqual(32, info.SizeOfULong);
162162
Assert.AreEqual(32, info.SizeOfPointer);
163163
Assert.AreEqual(32, info.SizeOfOffset);
164164
}
165165
--- compat/zlib/contrib/dotzlib/DotZLib/UnitTests.cs
+++ compat/zlib/contrib/dotzlib/DotZLib/UnitTests.cs
@@ -154,11 +154,11 @@
154 #region Info tests
155 [Test]
156 public void Info_Version()
157 {
158 Info info = new Info();
159 Assert.AreEqual("1.2.13", Info.Version);
160 Assert.AreEqual(32, info.SizeOfUInt);
161 Assert.AreEqual(32, info.SizeOfULong);
162 Assert.AreEqual(32, info.SizeOfPointer);
163 Assert.AreEqual(32, info.SizeOfOffset);
164 }
165
--- compat/zlib/contrib/dotzlib/DotZLib/UnitTests.cs
+++ compat/zlib/contrib/dotzlib/DotZLib/UnitTests.cs
@@ -154,11 +154,11 @@
154 #region Info tests
155 [Test]
156 public void Info_Version()
157 {
158 Info info = new Info();
159 Assert.AreEqual("1.3.0", Info.Version);
160 Assert.AreEqual(32, info.SizeOfUInt);
161 Assert.AreEqual(32, info.SizeOfULong);
162 Assert.AreEqual(32, info.SizeOfPointer);
163 Assert.AreEqual(32, info.SizeOfOffset);
164 }
165
--- compat/zlib/contrib/dotzlib/readme.txt
+++ compat/zlib/contrib/dotzlib/readme.txt
@@ -34,11 +34,11 @@
3434
2. Using NAnt:
3535
Open a command prompt with access to the build environment and run nant
3636
in the same directory as the DotZLib.build file.
3737
You can define 2 properties on the nant command-line to control the build:
3838
debug={true|false} to toggle between release/debug builds (default=true).
39
- nunit={true|false} to include or esclude unit tests (default=true).
39
+ nunit={true|false} to include or exclude unit tests (default=true).
4040
Also the target clean will remove binaries.
4141
Output file (DotZLib.dll) will be found in either ./DotZLib/bin/release
4242
or ./DotZLib/bin/debug, depending on whether you are building the release
4343
or debug version of the library.
4444
4545
--- compat/zlib/contrib/dotzlib/readme.txt
+++ compat/zlib/contrib/dotzlib/readme.txt
@@ -34,11 +34,11 @@
34 2. Using NAnt:
35 Open a command prompt with access to the build environment and run nant
36 in the same directory as the DotZLib.build file.
37 You can define 2 properties on the nant command-line to control the build:
38 debug={true|false} to toggle between release/debug builds (default=true).
39 nunit={true|false} to include or esclude unit tests (default=true).
40 Also the target clean will remove binaries.
41 Output file (DotZLib.dll) will be found in either ./DotZLib/bin/release
42 or ./DotZLib/bin/debug, depending on whether you are building the release
43 or debug version of the library.
44
45
--- compat/zlib/contrib/dotzlib/readme.txt
+++ compat/zlib/contrib/dotzlib/readme.txt
@@ -34,11 +34,11 @@
34 2. Using NAnt:
35 Open a command prompt with access to the build environment and run nant
36 in the same directory as the DotZLib.build file.
37 You can define 2 properties on the nant command-line to control the build:
38 debug={true|false} to toggle between release/debug builds (default=true).
39 nunit={true|false} to include or exclude unit tests (default=true).
40 Also the target clean will remove binaries.
41 Output file (DotZLib.dll) will be found in either ./DotZLib/bin/release
42 or ./DotZLib/bin/debug, depending on whether you are building the release
43 or debug version of the library.
44
45
--- compat/zlib/contrib/infback9/infback9.c
+++ compat/zlib/contrib/infback9/infback9.c
@@ -14,16 +14,12 @@
1414
strm provides memory allocation functions in zalloc and zfree, or
1515
Z_NULL to use the library memory allocation functions.
1616
1717
window is a user-supplied window and output buffer that is 64K bytes.
1818
*/
19
-int ZEXPORT inflateBack9Init_(strm, window, version, stream_size)
20
-z_stream FAR *strm;
21
-unsigned char FAR *window;
22
-const char *version;
23
-int stream_size;
24
-{
19
+int ZEXPORT inflateBack9Init_(z_stream FAR *strm, unsigned char FAR *window,
20
+ const char *version, int stream_size) {
2521
struct inflate_state FAR *state;
2622
2723
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
2824
stream_size != (int)(sizeof(z_stream)))
2925
return Z_VERSION_ERROR;
@@ -49,12 +45,11 @@
4945
decoding.
5046
*/
5147
#ifdef MAKEFIXED
5248
#include <stdio.h>
5349
54
-void makefixed9(void)
55
-{
50
+void makefixed9(void) {
5651
unsigned sym, bits, low, size;
5752
code *next, *lenfix, *distfix;
5853
struct inflate_state state;
5954
code fixed[544];
6055
@@ -212,17 +207,12 @@
212207
returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
213208
error, or Z_MEM_ERROR if it could not allocate memory for the state.
214209
inflateBack() can also return Z_STREAM_ERROR if the input parameters
215210
are not correct, i.e. strm is Z_NULL or the state was not initialized.
216211
*/
217
-int ZEXPORT inflateBack9(strm, in, in_desc, out, out_desc)
218
-z_stream FAR *strm;
219
-in_func in;
220
-void FAR *in_desc;
221
-out_func out;
222
-void FAR *out_desc;
223
-{
212
+int ZEXPORT inflateBack9(z_stream FAR *strm, in_func in, void FAR *in_desc,
213
+ out_func out, void FAR *out_desc) {
224214
struct inflate_state FAR *state;
225215
z_const unsigned char FAR *next; /* next input */
226216
unsigned char FAR *put; /* next output */
227217
unsigned have; /* available input */
228218
unsigned long left; /* available output */
@@ -601,15 +591,13 @@
601591
strm->next_in = next;
602592
strm->avail_in = have;
603593
return ret;
604594
}
605595
606
-int ZEXPORT inflateBack9End(strm)
607
-z_stream FAR *strm;
608
-{
596
+int ZEXPORT inflateBack9End(z_stream FAR *strm) {
609597
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
610598
return Z_STREAM_ERROR;
611599
ZFREE(strm, strm->state);
612600
strm->state = Z_NULL;
613601
Tracev((stderr, "inflate: end\n"));
614602
return Z_OK;
615603
}
616604
--- compat/zlib/contrib/infback9/infback9.c
+++ compat/zlib/contrib/infback9/infback9.c
@@ -14,16 +14,12 @@
14 strm provides memory allocation functions in zalloc and zfree, or
15 Z_NULL to use the library memory allocation functions.
16
17 window is a user-supplied window and output buffer that is 64K bytes.
18 */
19 int ZEXPORT inflateBack9Init_(strm, window, version, stream_size)
20 z_stream FAR *strm;
21 unsigned char FAR *window;
22 const char *version;
23 int stream_size;
24 {
25 struct inflate_state FAR *state;
26
27 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
28 stream_size != (int)(sizeof(z_stream)))
29 return Z_VERSION_ERROR;
@@ -49,12 +45,11 @@
49 decoding.
50 */
51 #ifdef MAKEFIXED
52 #include <stdio.h>
53
54 void makefixed9(void)
55 {
56 unsigned sym, bits, low, size;
57 code *next, *lenfix, *distfix;
58 struct inflate_state state;
59 code fixed[544];
60
@@ -212,17 +207,12 @@
212 returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
213 error, or Z_MEM_ERROR if it could not allocate memory for the state.
214 inflateBack() can also return Z_STREAM_ERROR if the input parameters
215 are not correct, i.e. strm is Z_NULL or the state was not initialized.
216 */
217 int ZEXPORT inflateBack9(strm, in, in_desc, out, out_desc)
218 z_stream FAR *strm;
219 in_func in;
220 void FAR *in_desc;
221 out_func out;
222 void FAR *out_desc;
223 {
224 struct inflate_state FAR *state;
225 z_const unsigned char FAR *next; /* next input */
226 unsigned char FAR *put; /* next output */
227 unsigned have; /* available input */
228 unsigned long left; /* available output */
@@ -601,15 +591,13 @@
601 strm->next_in = next;
602 strm->avail_in = have;
603 return ret;
604 }
605
606 int ZEXPORT inflateBack9End(strm)
607 z_stream FAR *strm;
608 {
609 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
610 return Z_STREAM_ERROR;
611 ZFREE(strm, strm->state);
612 strm->state = Z_NULL;
613 Tracev((stderr, "inflate: end\n"));
614 return Z_OK;
615 }
616
--- compat/zlib/contrib/infback9/infback9.c
+++ compat/zlib/contrib/infback9/infback9.c
@@ -14,16 +14,12 @@
14 strm provides memory allocation functions in zalloc and zfree, or
15 Z_NULL to use the library memory allocation functions.
16
17 window is a user-supplied window and output buffer that is 64K bytes.
18 */
19 int ZEXPORT inflateBack9Init_(z_stream FAR *strm, unsigned char FAR *window,
20 const char *version, int stream_size) {
 
 
 
 
21 struct inflate_state FAR *state;
22
23 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
24 stream_size != (int)(sizeof(z_stream)))
25 return Z_VERSION_ERROR;
@@ -49,12 +45,11 @@
45 decoding.
46 */
47 #ifdef MAKEFIXED
48 #include <stdio.h>
49
50 void makefixed9(void) {
 
51 unsigned sym, bits, low, size;
52 code *next, *lenfix, *distfix;
53 struct inflate_state state;
54 code fixed[544];
55
@@ -212,17 +207,12 @@
207 returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
208 error, or Z_MEM_ERROR if it could not allocate memory for the state.
209 inflateBack() can also return Z_STREAM_ERROR if the input parameters
210 are not correct, i.e. strm is Z_NULL or the state was not initialized.
211 */
212 int ZEXPORT inflateBack9(z_stream FAR *strm, in_func in, void FAR *in_desc,
213 out_func out, void FAR *out_desc) {
 
 
 
 
 
214 struct inflate_state FAR *state;
215 z_const unsigned char FAR *next; /* next input */
216 unsigned char FAR *put; /* next output */
217 unsigned have; /* available input */
218 unsigned long left; /* available output */
@@ -601,15 +591,13 @@
591 strm->next_in = next;
592 strm->avail_in = have;
593 return ret;
594 }
595
596 int ZEXPORT inflateBack9End(z_stream FAR *strm) {
 
 
597 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
598 return Z_STREAM_ERROR;
599 ZFREE(strm, strm->state);
600 strm->state = Z_NULL;
601 Tracev((stderr, "inflate: end\n"));
602 return Z_OK;
603 }
604
--- compat/zlib/contrib/infback9/infback9.h
+++ compat/zlib/contrib/infback9/infback9.h
@@ -18,18 +18,18 @@
1818
1919
#ifdef __cplusplus
2020
extern "C" {
2121
#endif
2222
23
-ZEXTERN int ZEXPORT inflateBack9 OF((z_stream FAR *strm,
24
- in_func in, void FAR *in_desc,
25
- out_func out, void FAR *out_desc));
26
-ZEXTERN int ZEXPORT inflateBack9End OF((z_stream FAR *strm));
27
-ZEXTERN int ZEXPORT inflateBack9Init_ OF((z_stream FAR *strm,
28
- unsigned char FAR *window,
29
- const char *version,
30
- int stream_size));
23
+ZEXTERN int ZEXPORT inflateBack9(z_stream FAR *strm,
24
+ in_func in, void FAR *in_desc,
25
+ out_func out, void FAR *out_desc);
26
+ZEXTERN int ZEXPORT inflateBack9End(z_stream FAR *strm);
27
+ZEXTERN int ZEXPORT inflateBack9Init_(z_stream FAR *strm,
28
+ unsigned char FAR *window,
29
+ const char *version,
30
+ int stream_size);
3131
#define inflateBack9Init(strm, window) \
3232
inflateBack9Init_((strm), (window), \
3333
ZLIB_VERSION, sizeof(z_stream))
3434
3535
#ifdef __cplusplus
3636
--- compat/zlib/contrib/infback9/infback9.h
+++ compat/zlib/contrib/infback9/infback9.h
@@ -18,18 +18,18 @@
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 ZEXTERN int ZEXPORT inflateBack9 OF((z_stream FAR *strm,
24 in_func in, void FAR *in_desc,
25 out_func out, void FAR *out_desc));
26 ZEXTERN int ZEXPORT inflateBack9End OF((z_stream FAR *strm));
27 ZEXTERN int ZEXPORT inflateBack9Init_ OF((z_stream FAR *strm,
28 unsigned char FAR *window,
29 const char *version,
30 int stream_size));
31 #define inflateBack9Init(strm, window) \
32 inflateBack9Init_((strm), (window), \
33 ZLIB_VERSION, sizeof(z_stream))
34
35 #ifdef __cplusplus
36
--- compat/zlib/contrib/infback9/infback9.h
+++ compat/zlib/contrib/infback9/infback9.h
@@ -18,18 +18,18 @@
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 ZEXTERN int ZEXPORT inflateBack9(z_stream FAR *strm,
24 in_func in, void FAR *in_desc,
25 out_func out, void FAR *out_desc);
26 ZEXTERN int ZEXPORT inflateBack9End(z_stream FAR *strm);
27 ZEXTERN int ZEXPORT inflateBack9Init_(z_stream FAR *strm,
28 unsigned char FAR *window,
29 const char *version,
30 int stream_size);
31 #define inflateBack9Init(strm, window) \
32 inflateBack9Init_((strm), (window), \
33 ZLIB_VERSION, sizeof(z_stream))
34
35 #ifdef __cplusplus
36
--- compat/zlib/contrib/infback9/inftree9.c
+++ compat/zlib/contrib/infback9/inftree9.c
@@ -1,17 +1,17 @@
11
/* inftree9.c -- generate Huffman trees for efficient decoding
2
- * Copyright (C) 1995-2022 Mark Adler
2
+ * Copyright (C) 1995-2023 Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55
66
#include "zutil.h"
77
#include "inftree9.h"
88
99
#define MAXBITS 15
1010
1111
const char inflate9_copyright[] =
12
- " inflate9 1.2.13 Copyright 1995-2022 Mark Adler ";
12
+ " inflate9 1.3 Copyright 1995-2023 Mark Adler ";
1313
/*
1414
If you use the zlib library in a product, an acknowledgment is welcome
1515
in the documentation of your product. If for some reason you cannot
1616
include such an acknowledgment, I would appreciate that you keep this
1717
copyright string in the executable of your product.
@@ -27,18 +27,13 @@
2727
on return points to the next available entry's address. bits is the
2828
requested root table index bits, and on return it is the actual root
2929
table index bits. It will differ if the request is greater than the
3030
longest code or if it is less than the shortest code.
3131
*/
32
-int inflate_table9(type, lens, codes, table, bits, work)
33
-codetype type;
34
-unsigned short FAR *lens;
35
-unsigned codes;
36
-code FAR * FAR *table;
37
-unsigned FAR *bits;
38
-unsigned short FAR *work;
39
-{
32
+int inflate_table9(codetype type, unsigned short FAR *lens, unsigned codes,
33
+ code FAR * FAR *table, unsigned FAR *bits,
34
+ unsigned short FAR *work) {
4035
unsigned len; /* a code's length in bits */
4136
unsigned sym; /* index of code symbols */
4237
unsigned min, max; /* minimum and maximum code lengths */
4338
unsigned root; /* number of index bits for root table */
4439
unsigned curr; /* number of index bits for current table */
@@ -62,11 +57,11 @@
6257
19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115,
6358
131, 163, 195, 227, 3, 0, 0};
6459
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
6560
128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
6661
130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132,
67
- 133, 133, 133, 133, 144, 194, 65};
62
+ 133, 133, 133, 133, 144, 198, 203};
6863
static const unsigned short dbase[32] = { /* Distance codes 0..31 base */
6964
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49,
7065
65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073,
7166
4097, 6145, 8193, 12289, 16385, 24577, 32769, 49153};
7267
static const unsigned short dext[32] = { /* Distance codes 0..31 extra */
7368
--- compat/zlib/contrib/infback9/inftree9.c
+++ compat/zlib/contrib/infback9/inftree9.c
@@ -1,17 +1,17 @@
1 /* inftree9.c -- generate Huffman trees for efficient decoding
2 * Copyright (C) 1995-2022 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 #include "zutil.h"
7 #include "inftree9.h"
8
9 #define MAXBITS 15
10
11 const char inflate9_copyright[] =
12 " inflate9 1.2.13 Copyright 1995-2022 Mark Adler ";
13 /*
14 If you use the zlib library in a product, an acknowledgment is welcome
15 in the documentation of your product. If for some reason you cannot
16 include such an acknowledgment, I would appreciate that you keep this
17 copyright string in the executable of your product.
@@ -27,18 +27,13 @@
27 on return points to the next available entry's address. bits is the
28 requested root table index bits, and on return it is the actual root
29 table index bits. It will differ if the request is greater than the
30 longest code or if it is less than the shortest code.
31 */
32 int inflate_table9(type, lens, codes, table, bits, work)
33 codetype type;
34 unsigned short FAR *lens;
35 unsigned codes;
36 code FAR * FAR *table;
37 unsigned FAR *bits;
38 unsigned short FAR *work;
39 {
40 unsigned len; /* a code's length in bits */
41 unsigned sym; /* index of code symbols */
42 unsigned min, max; /* minimum and maximum code lengths */
43 unsigned root; /* number of index bits for root table */
44 unsigned curr; /* number of index bits for current table */
@@ -62,11 +57,11 @@
62 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115,
63 131, 163, 195, 227, 3, 0, 0};
64 static const unsigned short lext[31] = { /* Length codes 257..285 extra */
65 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
66 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132,
67 133, 133, 133, 133, 144, 194, 65};
68 static const unsigned short dbase[32] = { /* Distance codes 0..31 base */
69 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49,
70 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073,
71 4097, 6145, 8193, 12289, 16385, 24577, 32769, 49153};
72 static const unsigned short dext[32] = { /* Distance codes 0..31 extra */
73
--- compat/zlib/contrib/infback9/inftree9.c
+++ compat/zlib/contrib/infback9/inftree9.c
@@ -1,17 +1,17 @@
1 /* inftree9.c -- generate Huffman trees for efficient decoding
2 * Copyright (C) 1995-2023 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 #include "zutil.h"
7 #include "inftree9.h"
8
9 #define MAXBITS 15
10
11 const char inflate9_copyright[] =
12 " inflate9 1.3 Copyright 1995-2023 Mark Adler ";
13 /*
14 If you use the zlib library in a product, an acknowledgment is welcome
15 in the documentation of your product. If for some reason you cannot
16 include such an acknowledgment, I would appreciate that you keep this
17 copyright string in the executable of your product.
@@ -27,18 +27,13 @@
27 on return points to the next available entry's address. bits is the
28 requested root table index bits, and on return it is the actual root
29 table index bits. It will differ if the request is greater than the
30 longest code or if it is less than the shortest code.
31 */
32 int inflate_table9(codetype type, unsigned short FAR *lens, unsigned codes,
33 code FAR * FAR *table, unsigned FAR *bits,
34 unsigned short FAR *work) {
 
 
 
 
 
35 unsigned len; /* a code's length in bits */
36 unsigned sym; /* index of code symbols */
37 unsigned min, max; /* minimum and maximum code lengths */
38 unsigned root; /* number of index bits for root table */
39 unsigned curr; /* number of index bits for current table */
@@ -62,11 +57,11 @@
57 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115,
58 131, 163, 195, 227, 3, 0, 0};
59 static const unsigned short lext[31] = { /* Length codes 257..285 extra */
60 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129,
61 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132,
62 133, 133, 133, 133, 144, 198, 203};
63 static const unsigned short dbase[32] = { /* Distance codes 0..31 base */
64 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49,
65 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073,
66 4097, 6145, 8193, 12289, 16385, 24577, 32769, 49153};
67 static const unsigned short dext[32] = { /* Distance codes 0..31 extra */
68
--- compat/zlib/contrib/infback9/inftree9.h
+++ compat/zlib/contrib/infback9/inftree9.h
@@ -54,8 +54,8 @@
5454
CODES,
5555
LENS,
5656
DISTS
5757
} codetype;
5858
59
-extern int inflate_table9 OF((codetype type, unsigned short FAR *lens,
60
- unsigned codes, code FAR * FAR *table,
61
- unsigned FAR *bits, unsigned short FAR *work));
59
+extern int inflate_table9(codetype type, unsigned short FAR *lens,
60
+ unsigned codes, code FAR * FAR *table,
61
+ unsigned FAR *bits, unsigned short FAR *work);
6262
--- compat/zlib/contrib/infback9/inftree9.h
+++ compat/zlib/contrib/infback9/inftree9.h
@@ -54,8 +54,8 @@
54 CODES,
55 LENS,
56 DISTS
57 } codetype;
58
59 extern int inflate_table9 OF((codetype type, unsigned short FAR *lens,
60 unsigned codes, code FAR * FAR *table,
61 unsigned FAR *bits, unsigned short FAR *work));
62
--- compat/zlib/contrib/infback9/inftree9.h
+++ compat/zlib/contrib/infback9/inftree9.h
@@ -54,8 +54,8 @@
54 CODES,
55 LENS,
56 DISTS
57 } codetype;
58
59 extern int inflate_table9(codetype type, unsigned short FAR *lens,
60 unsigned codes, code FAR * FAR *table,
61 unsigned FAR *bits, unsigned short FAR *work);
62
--- compat/zlib/contrib/minizip/MiniZip64_Changes.txt
+++ compat/zlib/contrib/minizip/MiniZip64_Changes.txt
@@ -1,6 +1,6 @@
11
2
-MiniZip 1.1 was derrived from MiniZip at version 1.01f
2
+MiniZip 1.1 was derived from MiniZip at version 1.01f
33
44
Change in 1.0 (Okt 2009)
55
- **TODO - Add history**
66
77
--- compat/zlib/contrib/minizip/MiniZip64_Changes.txt
+++ compat/zlib/contrib/minizip/MiniZip64_Changes.txt
@@ -1,6 +1,6 @@
1
2 MiniZip 1.1 was derrived from MiniZip at version 1.01f
3
4 Change in 1.0 (Okt 2009)
5 - **TODO - Add history**
6
7
--- compat/zlib/contrib/minizip/MiniZip64_Changes.txt
+++ compat/zlib/contrib/minizip/MiniZip64_Changes.txt
@@ -1,6 +1,6 @@
1
2 MiniZip 1.1 was derived from MiniZip at version 1.01f
3
4 Change in 1.0 (Okt 2009)
5 - **TODO - Add history**
6
7
--- compat/zlib/contrib/minizip/configure.ac
+++ compat/zlib/contrib/minizip/configure.ac
@@ -1,9 +1,9 @@
11
# -*- Autoconf -*-
22
# Process this file with autoconf to produce a configure script.
33
4
-AC_INIT([minizip], [1.2.13], [bugzilla.redhat.com])
4
+AC_INIT([minizip], [1.3.0], [bugzilla.redhat.com])
55
AC_CONFIG_SRCDIR([minizip.c])
66
AM_INIT_AUTOMAKE([foreign])
77
LT_INIT
88
99
AC_MSG_CHECKING([whether to build example programs])
1010
--- compat/zlib/contrib/minizip/configure.ac
+++ compat/zlib/contrib/minizip/configure.ac
@@ -1,9 +1,9 @@
1 # -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
3
4 AC_INIT([minizip], [1.2.13], [bugzilla.redhat.com])
5 AC_CONFIG_SRCDIR([minizip.c])
6 AM_INIT_AUTOMAKE([foreign])
7 LT_INIT
8
9 AC_MSG_CHECKING([whether to build example programs])
10
--- compat/zlib/contrib/minizip/configure.ac
+++ compat/zlib/contrib/minizip/configure.ac
@@ -1,9 +1,9 @@
1 # -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
3
4 AC_INIT([minizip], [1.3.0], [bugzilla.redhat.com])
5 AC_CONFIG_SRCDIR([minizip.c])
6 AM_INIT_AUTOMAKE([foreign])
7 LT_INIT
8
9 AC_MSG_CHECKING([whether to build example programs])
10
--- compat/zlib/contrib/minizip/crypt.h
+++ compat/zlib/contrib/minizip/crypt.h
@@ -30,12 +30,11 @@
3030
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
3131
3232
/***********************************************************************
3333
* Return the next byte in the pseudo-random sequence
3434
*/
35
-static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab)
36
-{
35
+static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) {
3736
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
3837
* unpredictable manner on 16-bit systems; not a problem
3938
* with any known compiler so far, though */
4039
4140
(void)pcrc_32_tab;
@@ -44,12 +43,11 @@
4443
}
4544
4645
/***********************************************************************
4746
* Update the encryption keys with the next byte of plain text
4847
*/
49
-static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c)
50
-{
48
+static int update_keys(unsigned long* pkeys, const z_crc_t* pcrc_32_tab, int c) {
5149
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
5250
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
5351
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
5452
{
5553
register int keyshift = (int)((*(pkeys+1)) >> 24);
@@ -61,12 +59,11 @@
6159
6260
/***********************************************************************
6361
* Initialize the encryption keys and the random header according to
6462
* the given password.
6563
*/
66
-static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab)
67
-{
64
+static void init_keys(const char* passwd, unsigned long* pkeys, const z_crc_t* pcrc_32_tab) {
6865
*(pkeys+0) = 305419896L;
6966
*(pkeys+1) = 591751049L;
7067
*(pkeys+2) = 878082192L;
7168
while (*passwd != '\0') {
7269
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
@@ -91,12 +88,11 @@
9188
static unsigned crypthead(const char* passwd, /* password string */
9289
unsigned char* buf, /* where to write header */
9390
int bufSize,
9491
unsigned long* pkeys,
9592
const z_crc_t* pcrc_32_tab,
96
- unsigned long crcForCrypting)
97
-{
93
+ unsigned long crcForCrypting) {
9894
unsigned n; /* index in random header */
9995
int t; /* temporary */
10096
int c; /* random byte */
10197
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
10298
static unsigned calls = 0; /* ensure different random header each time */
10399
--- compat/zlib/contrib/minizip/crypt.h
+++ compat/zlib/contrib/minizip/crypt.h
@@ -30,12 +30,11 @@
30 #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
31
32 /***********************************************************************
33 * Return the next byte in the pseudo-random sequence
34 */
35 static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab)
36 {
37 unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
38 * unpredictable manner on 16-bit systems; not a problem
39 * with any known compiler so far, though */
40
41 (void)pcrc_32_tab;
@@ -44,12 +43,11 @@
44 }
45
46 /***********************************************************************
47 * Update the encryption keys with the next byte of plain text
48 */
49 static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c)
50 {
51 (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
52 (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
53 (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
54 {
55 register int keyshift = (int)((*(pkeys+1)) >> 24);
@@ -61,12 +59,11 @@
61
62 /***********************************************************************
63 * Initialize the encryption keys and the random header according to
64 * the given password.
65 */
66 static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab)
67 {
68 *(pkeys+0) = 305419896L;
69 *(pkeys+1) = 591751049L;
70 *(pkeys+2) = 878082192L;
71 while (*passwd != '\0') {
72 update_keys(pkeys,pcrc_32_tab,(int)*passwd);
@@ -91,12 +88,11 @@
91 static unsigned crypthead(const char* passwd, /* password string */
92 unsigned char* buf, /* where to write header */
93 int bufSize,
94 unsigned long* pkeys,
95 const z_crc_t* pcrc_32_tab,
96 unsigned long crcForCrypting)
97 {
98 unsigned n; /* index in random header */
99 int t; /* temporary */
100 int c; /* random byte */
101 unsigned char header[RAND_HEAD_LEN-2]; /* random header */
102 static unsigned calls = 0; /* ensure different random header each time */
103
--- compat/zlib/contrib/minizip/crypt.h
+++ compat/zlib/contrib/minizip/crypt.h
@@ -30,12 +30,11 @@
30 #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
31
32 /***********************************************************************
33 * Return the next byte in the pseudo-random sequence
34 */
35 static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) {
 
36 unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
37 * unpredictable manner on 16-bit systems; not a problem
38 * with any known compiler so far, though */
39
40 (void)pcrc_32_tab;
@@ -44,12 +43,11 @@
43 }
44
45 /***********************************************************************
46 * Update the encryption keys with the next byte of plain text
47 */
48 static int update_keys(unsigned long* pkeys, const z_crc_t* pcrc_32_tab, int c) {
 
49 (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
50 (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
51 (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
52 {
53 register int keyshift = (int)((*(pkeys+1)) >> 24);
@@ -61,12 +59,11 @@
59
60 /***********************************************************************
61 * Initialize the encryption keys and the random header according to
62 * the given password.
63 */
64 static void init_keys(const char* passwd, unsigned long* pkeys, const z_crc_t* pcrc_32_tab) {
 
65 *(pkeys+0) = 305419896L;
66 *(pkeys+1) = 591751049L;
67 *(pkeys+2) = 878082192L;
68 while (*passwd != '\0') {
69 update_keys(pkeys,pcrc_32_tab,(int)*passwd);
@@ -91,12 +88,11 @@
88 static unsigned crypthead(const char* passwd, /* password string */
89 unsigned char* buf, /* where to write header */
90 int bufSize,
91 unsigned long* pkeys,
92 const z_crc_t* pcrc_32_tab,
93 unsigned long crcForCrypting) {
 
94 unsigned n; /* index in random header */
95 int t; /* temporary */
96 int c; /* random byte */
97 unsigned char header[RAND_HEAD_LEN-2]; /* random header */
98 static unsigned calls = 0; /* ensure different random header each time */
99
--- compat/zlib/contrib/minizip/ioapi.c
+++ compat/zlib/contrib/minizip/ioapi.c
@@ -12,11 +12,11 @@
1212
1313
#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
1414
#define _CRT_SECURE_NO_WARNINGS
1515
#endif
1616
17
-#if defined(__APPLE__) || defined(IOAPI_NO_64)
17
+#if defined(__APPLE__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
1818
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
1919
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
2020
#define FTELLO_FUNC(stream) ftello(stream)
2121
#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
2222
#else
@@ -26,22 +26,20 @@
2626
#endif
2727
2828
2929
#include "ioapi.h"
3030
31
-voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
32
-{
31
+voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc, const void*filename, int mode) {
3332
if (pfilefunc->zfile_func64.zopen64_file != NULL)
3433
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
3534
else
3635
{
3736
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
3837
}
3938
}
4039
41
-long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
42
-{
40
+long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) {
4341
if (pfilefunc->zfile_func64.zseek64_file != NULL)
4442
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
4543
else
4644
{
4745
uLong offsetTruncated = (uLong)offset;
@@ -50,12 +48,11 @@
5048
else
5149
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
5250
}
5351
}
5452
55
-ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
56
-{
53
+ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc, voidpf filestream) {
5754
if (pfilefunc->zfile_func64.zseek64_file != NULL)
5855
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
5956
else
6057
{
6158
uLong tell_uLong = (uLong)(*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
@@ -64,15 +61,13 @@
6461
else
6562
return tell_uLong;
6663
}
6764
}
6865
69
-void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
70
-{
66
+void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32, const zlib_filefunc_def* p_filefunc32) {
7167
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
7268
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
73
- p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
7469
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
7570
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
7671
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
7772
p_filefunc64_32->zfile_func64.zseek64_file = NULL;
7873
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
@@ -82,20 +77,11 @@
8277
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
8378
}
8479
8580
8681
87
-static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
88
-static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
89
-static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
90
-static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
91
-static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
92
-static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
93
-static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
94
-
95
-static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
96
-{
82
+static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char* filename, int mode) {
9783
FILE* file = NULL;
9884
const char* mode_fopen = NULL;
9985
(void)opaque;
10086
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
10187
mode_fopen = "rb";
@@ -109,12 +95,11 @@
10995
if ((filename!=NULL) && (mode_fopen != NULL))
11096
file = fopen(filename, mode_fopen);
11197
return file;
11298
}
11399
114
-static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
115
-{
100
+static voidpf ZCALLBACK fopen64_file_func(voidpf opaque, const void* filename, int mode) {
116101
FILE* file = NULL;
117102
const char* mode_fopen = NULL;
118103
(void)opaque;
119104
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
120105
mode_fopen = "rb";
@@ -129,45 +114,40 @@
129114
file = FOPEN_FUNC((const char*)filename, mode_fopen);
130115
return file;
131116
}
132117
133118
134
-static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
135
-{
119
+static uLong ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uLong size) {
136120
uLong ret;
137121
(void)opaque;
138122
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
139123
return ret;
140124
}
141125
142
-static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
143
-{
126
+static uLong ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void* buf, uLong size) {
144127
uLong ret;
145128
(void)opaque;
146129
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
147130
return ret;
148131
}
149132
150
-static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
151
-{
133
+static long ZCALLBACK ftell_file_func(voidpf opaque, voidpf stream) {
152134
long ret;
153135
(void)opaque;
154136
ret = ftell((FILE *)stream);
155137
return ret;
156138
}
157139
158140
159
-static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
160
-{
141
+static ZPOS64_T ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream) {
161142
ZPOS64_T ret;
162143
(void)opaque;
163144
ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream);
164145
return ret;
165146
}
166147
167
-static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
168
-{
148
+static long ZCALLBACK fseek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin) {
169149
int fseek_origin=0;
170150
long ret;
171151
(void)opaque;
172152
switch (origin)
173153
{
@@ -186,12 +166,11 @@
186166
if (fseek((FILE *)stream, (long)offset, fseek_origin) != 0)
187167
ret = -1;
188168
return ret;
189169
}
190170
191
-static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
192
-{
171
+static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) {
193172
int fseek_origin=0;
194173
long ret;
195174
(void)opaque;
196175
switch (origin)
197176
{
@@ -206,36 +185,32 @@
206185
break;
207186
default: return -1;
208187
}
209188
ret = 0;
210189
211
- if(FSEEKO_FUNC((FILE *)stream, (z_off_t)offset, fseek_origin) != 0)
190
+ if(FSEEKO_FUNC((FILE *)stream, (z_off64_t)offset, fseek_origin) != 0)
212191
ret = -1;
213192
214193
return ret;
215194
}
216195
217196
218
-static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
219
-{
197
+static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream) {
220198
int ret;
221199
(void)opaque;
222200
ret = fclose((FILE *)stream);
223201
return ret;
224202
}
225203
226
-static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
227
-{
204
+static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream) {
228205
int ret;
229206
(void)opaque;
230207
ret = ferror((FILE *)stream);
231208
return ret;
232209
}
233210
234
-void fill_fopen_filefunc (pzlib_filefunc_def)
235
- zlib_filefunc_def* pzlib_filefunc_def;
236
-{
211
+void fill_fopen_filefunc(zlib_filefunc_def* pzlib_filefunc_def) {
237212
pzlib_filefunc_def->zopen_file = fopen_file_func;
238213
pzlib_filefunc_def->zread_file = fread_file_func;
239214
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
240215
pzlib_filefunc_def->ztell_file = ftell_file_func;
241216
pzlib_filefunc_def->zseek_file = fseek_file_func;
@@ -242,16 +217,15 @@
242217
pzlib_filefunc_def->zclose_file = fclose_file_func;
243218
pzlib_filefunc_def->zerror_file = ferror_file_func;
244219
pzlib_filefunc_def->opaque = NULL;
245220
}
246221
247
-void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
248
-{
222
+void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def) {
249223
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
250224
pzlib_filefunc_def->zread_file = fread_file_func;
251225
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
252226
pzlib_filefunc_def->ztell64_file = ftell64_file_func;
253227
pzlib_filefunc_def->zseek64_file = fseek64_file_func;
254228
pzlib_filefunc_def->zclose_file = fclose_file_func;
255229
pzlib_filefunc_def->zerror_file = ferror_file_func;
256230
pzlib_filefunc_def->opaque = NULL;
257231
}
258232
--- compat/zlib/contrib/minizip/ioapi.c
+++ compat/zlib/contrib/minizip/ioapi.c
@@ -12,11 +12,11 @@
12
13 #if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
14 #define _CRT_SECURE_NO_WARNINGS
15 #endif
16
17 #if defined(__APPLE__) || defined(IOAPI_NO_64)
18 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
19 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
20 #define FTELLO_FUNC(stream) ftello(stream)
21 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
22 #else
@@ -26,22 +26,20 @@
26 #endif
27
28
29 #include "ioapi.h"
30
31 voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
32 {
33 if (pfilefunc->zfile_func64.zopen64_file != NULL)
34 return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
35 else
36 {
37 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
38 }
39 }
40
41 long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
42 {
43 if (pfilefunc->zfile_func64.zseek64_file != NULL)
44 return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
45 else
46 {
47 uLong offsetTruncated = (uLong)offset;
@@ -50,12 +48,11 @@
50 else
51 return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
52 }
53 }
54
55 ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
56 {
57 if (pfilefunc->zfile_func64.zseek64_file != NULL)
58 return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
59 else
60 {
61 uLong tell_uLong = (uLong)(*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
@@ -64,15 +61,13 @@
64 else
65 return tell_uLong;
66 }
67 }
68
69 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
70 {
71 p_filefunc64_32->zfile_func64.zopen64_file = NULL;
72 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
73 p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
74 p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
75 p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
76 p_filefunc64_32->zfile_func64.ztell64_file = NULL;
77 p_filefunc64_32->zfile_func64.zseek64_file = NULL;
78 p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
@@ -82,20 +77,11 @@
82 p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
83 }
84
85
86
87 static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
88 static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
89 static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
90 static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
91 static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
92 static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
93 static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
94
95 static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
96 {
97 FILE* file = NULL;
98 const char* mode_fopen = NULL;
99 (void)opaque;
100 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
101 mode_fopen = "rb";
@@ -109,12 +95,11 @@
109 if ((filename!=NULL) && (mode_fopen != NULL))
110 file = fopen(filename, mode_fopen);
111 return file;
112 }
113
114 static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
115 {
116 FILE* file = NULL;
117 const char* mode_fopen = NULL;
118 (void)opaque;
119 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
120 mode_fopen = "rb";
@@ -129,45 +114,40 @@
129 file = FOPEN_FUNC((const char*)filename, mode_fopen);
130 return file;
131 }
132
133
134 static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
135 {
136 uLong ret;
137 (void)opaque;
138 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
139 return ret;
140 }
141
142 static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
143 {
144 uLong ret;
145 (void)opaque;
146 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
147 return ret;
148 }
149
150 static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
151 {
152 long ret;
153 (void)opaque;
154 ret = ftell((FILE *)stream);
155 return ret;
156 }
157
158
159 static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
160 {
161 ZPOS64_T ret;
162 (void)opaque;
163 ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream);
164 return ret;
165 }
166
167 static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
168 {
169 int fseek_origin=0;
170 long ret;
171 (void)opaque;
172 switch (origin)
173 {
@@ -186,12 +166,11 @@
186 if (fseek((FILE *)stream, (long)offset, fseek_origin) != 0)
187 ret = -1;
188 return ret;
189 }
190
191 static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
192 {
193 int fseek_origin=0;
194 long ret;
195 (void)opaque;
196 switch (origin)
197 {
@@ -206,36 +185,32 @@
206 break;
207 default: return -1;
208 }
209 ret = 0;
210
211 if(FSEEKO_FUNC((FILE *)stream, (z_off_t)offset, fseek_origin) != 0)
212 ret = -1;
213
214 return ret;
215 }
216
217
218 static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
219 {
220 int ret;
221 (void)opaque;
222 ret = fclose((FILE *)stream);
223 return ret;
224 }
225
226 static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
227 {
228 int ret;
229 (void)opaque;
230 ret = ferror((FILE *)stream);
231 return ret;
232 }
233
234 void fill_fopen_filefunc (pzlib_filefunc_def)
235 zlib_filefunc_def* pzlib_filefunc_def;
236 {
237 pzlib_filefunc_def->zopen_file = fopen_file_func;
238 pzlib_filefunc_def->zread_file = fread_file_func;
239 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
240 pzlib_filefunc_def->ztell_file = ftell_file_func;
241 pzlib_filefunc_def->zseek_file = fseek_file_func;
@@ -242,16 +217,15 @@
242 pzlib_filefunc_def->zclose_file = fclose_file_func;
243 pzlib_filefunc_def->zerror_file = ferror_file_func;
244 pzlib_filefunc_def->opaque = NULL;
245 }
246
247 void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
248 {
249 pzlib_filefunc_def->zopen64_file = fopen64_file_func;
250 pzlib_filefunc_def->zread_file = fread_file_func;
251 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
252 pzlib_filefunc_def->ztell64_file = ftell64_file_func;
253 pzlib_filefunc_def->zseek64_file = fseek64_file_func;
254 pzlib_filefunc_def->zclose_file = fclose_file_func;
255 pzlib_filefunc_def->zerror_file = ferror_file_func;
256 pzlib_filefunc_def->opaque = NULL;
257 }
258
--- compat/zlib/contrib/minizip/ioapi.c
+++ compat/zlib/contrib/minizip/ioapi.c
@@ -12,11 +12,11 @@
12
13 #if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
14 #define _CRT_SECURE_NO_WARNINGS
15 #endif
16
17 #if defined(__APPLE__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
18 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
19 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
20 #define FTELLO_FUNC(stream) ftello(stream)
21 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
22 #else
@@ -26,22 +26,20 @@
26 #endif
27
28
29 #include "ioapi.h"
30
31 voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc, const void*filename, int mode) {
 
32 if (pfilefunc->zfile_func64.zopen64_file != NULL)
33 return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
34 else
35 {
36 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
37 }
38 }
39
40 long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) {
 
41 if (pfilefunc->zfile_func64.zseek64_file != NULL)
42 return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
43 else
44 {
45 uLong offsetTruncated = (uLong)offset;
@@ -50,12 +48,11 @@
48 else
49 return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
50 }
51 }
52
53 ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc, voidpf filestream) {
 
54 if (pfilefunc->zfile_func64.zseek64_file != NULL)
55 return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
56 else
57 {
58 uLong tell_uLong = (uLong)(*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
@@ -64,15 +61,13 @@
61 else
62 return tell_uLong;
63 }
64 }
65
66 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32, const zlib_filefunc_def* p_filefunc32) {
 
67 p_filefunc64_32->zfile_func64.zopen64_file = NULL;
68 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
 
69 p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
70 p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
71 p_filefunc64_32->zfile_func64.ztell64_file = NULL;
72 p_filefunc64_32->zfile_func64.zseek64_file = NULL;
73 p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
@@ -82,20 +77,11 @@
77 p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
78 }
79
80
81
82 static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char* filename, int mode) {
 
 
 
 
 
 
 
 
 
83 FILE* file = NULL;
84 const char* mode_fopen = NULL;
85 (void)opaque;
86 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
87 mode_fopen = "rb";
@@ -109,12 +95,11 @@
95 if ((filename!=NULL) && (mode_fopen != NULL))
96 file = fopen(filename, mode_fopen);
97 return file;
98 }
99
100 static voidpf ZCALLBACK fopen64_file_func(voidpf opaque, const void* filename, int mode) {
 
101 FILE* file = NULL;
102 const char* mode_fopen = NULL;
103 (void)opaque;
104 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
105 mode_fopen = "rb";
@@ -129,45 +114,40 @@
114 file = FOPEN_FUNC((const char*)filename, mode_fopen);
115 return file;
116 }
117
118
119 static uLong ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uLong size) {
 
120 uLong ret;
121 (void)opaque;
122 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
123 return ret;
124 }
125
126 static uLong ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void* buf, uLong size) {
 
127 uLong ret;
128 (void)opaque;
129 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
130 return ret;
131 }
132
133 static long ZCALLBACK ftell_file_func(voidpf opaque, voidpf stream) {
 
134 long ret;
135 (void)opaque;
136 ret = ftell((FILE *)stream);
137 return ret;
138 }
139
140
141 static ZPOS64_T ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream) {
 
142 ZPOS64_T ret;
143 (void)opaque;
144 ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream);
145 return ret;
146 }
147
148 static long ZCALLBACK fseek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin) {
 
149 int fseek_origin=0;
150 long ret;
151 (void)opaque;
152 switch (origin)
153 {
@@ -186,12 +166,11 @@
166 if (fseek((FILE *)stream, (long)offset, fseek_origin) != 0)
167 ret = -1;
168 return ret;
169 }
170
171 static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) {
 
172 int fseek_origin=0;
173 long ret;
174 (void)opaque;
175 switch (origin)
176 {
@@ -206,36 +185,32 @@
185 break;
186 default: return -1;
187 }
188 ret = 0;
189
190 if(FSEEKO_FUNC((FILE *)stream, (z_off64_t)offset, fseek_origin) != 0)
191 ret = -1;
192
193 return ret;
194 }
195
196
197 static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream) {
 
198 int ret;
199 (void)opaque;
200 ret = fclose((FILE *)stream);
201 return ret;
202 }
203
204 static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream) {
 
205 int ret;
206 (void)opaque;
207 ret = ferror((FILE *)stream);
208 return ret;
209 }
210
211 void fill_fopen_filefunc(zlib_filefunc_def* pzlib_filefunc_def) {
 
 
212 pzlib_filefunc_def->zopen_file = fopen_file_func;
213 pzlib_filefunc_def->zread_file = fread_file_func;
214 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
215 pzlib_filefunc_def->ztell_file = ftell_file_func;
216 pzlib_filefunc_def->zseek_file = fseek_file_func;
@@ -242,16 +217,15 @@
217 pzlib_filefunc_def->zclose_file = fclose_file_func;
218 pzlib_filefunc_def->zerror_file = ferror_file_func;
219 pzlib_filefunc_def->opaque = NULL;
220 }
221
222 void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def) {
 
223 pzlib_filefunc_def->zopen64_file = fopen64_file_func;
224 pzlib_filefunc_def->zread_file = fread_file_func;
225 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
226 pzlib_filefunc_def->ztell64_file = ftell64_file_func;
227 pzlib_filefunc_def->zseek64_file = fseek64_file_func;
228 pzlib_filefunc_def->zclose_file = fclose_file_func;
229 pzlib_filefunc_def->zerror_file = ferror_file_func;
230 pzlib_filefunc_def->opaque = NULL;
231 }
232
--- compat/zlib/contrib/minizip/ioapi.h
+++ compat/zlib/contrib/minizip/ioapi.h
@@ -48,11 +48,11 @@
4848
#if defined(USE_FILE32API)
4949
#define fopen64 fopen
5050
#define ftello64 ftell
5151
#define fseeko64 fseek
5252
#else
53
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
53
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
5454
#define fopen64 fopen
5555
#define ftello64 ftello
5656
#define fseeko64 fseeko
5757
#endif
5858
#ifdef _MSC_VER
@@ -80,11 +80,11 @@
8080
8181
#ifdef HAVE_MINIZIP64_CONF_H
8282
#include "mz64conf.h"
8383
#endif
8484
85
-/* a type choosen by DEFINE */
85
+/* a type chosen by DEFINE */
8686
#ifdef HAVE_64BIT_INT_CUSTOM
8787
typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
8888
#else
8989
#ifdef HAS_STDINT_H
9090
#include "stdint.h"
@@ -132,18 +132,18 @@
132132
#endif
133133
134134
135135
136136
137
-typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
138
-typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
139
-typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
140
-typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
141
-typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
142
-
143
-typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
144
-typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
137
+typedef voidpf (ZCALLBACK *open_file_func) (voidpf opaque, const char* filename, int mode);
138
+typedef uLong (ZCALLBACK *read_file_func) (voidpf opaque, voidpf stream, void* buf, uLong size);
139
+typedef uLong (ZCALLBACK *write_file_func) (voidpf opaque, voidpf stream, const void* buf, uLong size);
140
+typedef int (ZCALLBACK *close_file_func) (voidpf opaque, voidpf stream);
141
+typedef int (ZCALLBACK *testerror_file_func) (voidpf opaque, voidpf stream);
142
+
143
+typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream);
144
+typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uLong offset, int origin);
145145
146146
147147
/* here is the "old" 32 bits structure structure */
148148
typedef struct zlib_filefunc_def_s
149149
{
@@ -155,13 +155,13 @@
155155
close_file_func zclose_file;
156156
testerror_file_func zerror_file;
157157
voidpf opaque;
158158
} zlib_filefunc_def;
159159
160
-typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
161
-typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
162
-typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
160
+typedef ZPOS64_T (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream);
161
+typedef long (ZCALLBACK *seek64_file_func) (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin);
162
+typedef voidpf (ZCALLBACK *open64_file_func) (voidpf opaque, const void* filename, int mode);
163163
164164
typedef struct zlib_filefunc64_def_s
165165
{
166166
open64_file_func zopen64_file;
167167
read_file_func zread_file;
@@ -171,12 +171,12 @@
171171
close_file_func zclose_file;
172172
testerror_file_func zerror_file;
173173
voidpf opaque;
174174
} zlib_filefunc64_def;
175175
176
-void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
177
-void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
176
+void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def);
177
+void fill_fopen_filefunc(zlib_filefunc_def* pzlib_filefunc_def);
178178
179179
/* now internal definition, only for zip.c and unzip.h */
180180
typedef struct zlib_filefunc64_32_def_s
181181
{
182182
zlib_filefunc64_def zfile_func64;
@@ -191,15 +191,15 @@
191191
//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
192192
//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
193193
#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
194194
#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
195195
196
-voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
197
-long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
198
-ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
196
+voidpf call_zopen64(const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode);
197
+long call_zseek64(const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin);
198
+ZPOS64_T call_ztell64(const zlib_filefunc64_32_def* pfilefunc,voidpf filestream);
199199
200
-void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
200
+void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
201201
202202
#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
203203
#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
204204
#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
205205
206206
--- compat/zlib/contrib/minizip/ioapi.h
+++ compat/zlib/contrib/minizip/ioapi.h
@@ -48,11 +48,11 @@
48 #if defined(USE_FILE32API)
49 #define fopen64 fopen
50 #define ftello64 ftell
51 #define fseeko64 fseek
52 #else
53 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
54 #define fopen64 fopen
55 #define ftello64 ftello
56 #define fseeko64 fseeko
57 #endif
58 #ifdef _MSC_VER
@@ -80,11 +80,11 @@
80
81 #ifdef HAVE_MINIZIP64_CONF_H
82 #include "mz64conf.h"
83 #endif
84
85 /* a type choosen by DEFINE */
86 #ifdef HAVE_64BIT_INT_CUSTOM
87 typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
88 #else
89 #ifdef HAS_STDINT_H
90 #include "stdint.h"
@@ -132,18 +132,18 @@
132 #endif
133
134
135
136
137 typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
138 typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
139 typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
140 typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
141 typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
142
143 typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
144 typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
145
146
147 /* here is the "old" 32 bits structure structure */
148 typedef struct zlib_filefunc_def_s
149 {
@@ -155,13 +155,13 @@
155 close_file_func zclose_file;
156 testerror_file_func zerror_file;
157 voidpf opaque;
158 } zlib_filefunc_def;
159
160 typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
161 typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
162 typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
163
164 typedef struct zlib_filefunc64_def_s
165 {
166 open64_file_func zopen64_file;
167 read_file_func zread_file;
@@ -171,12 +171,12 @@
171 close_file_func zclose_file;
172 testerror_file_func zerror_file;
173 voidpf opaque;
174 } zlib_filefunc64_def;
175
176 void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
177 void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
178
179 /* now internal definition, only for zip.c and unzip.h */
180 typedef struct zlib_filefunc64_32_def_s
181 {
182 zlib_filefunc64_def zfile_func64;
@@ -191,15 +191,15 @@
191 //#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
192 //#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
193 #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
194 #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
195
196 voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
197 long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
198 ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
199
200 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
201
202 #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
203 #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
204 #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
205
206
--- compat/zlib/contrib/minizip/ioapi.h
+++ compat/zlib/contrib/minizip/ioapi.h
@@ -48,11 +48,11 @@
48 #if defined(USE_FILE32API)
49 #define fopen64 fopen
50 #define ftello64 ftell
51 #define fseeko64 fseek
52 #else
53 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
54 #define fopen64 fopen
55 #define ftello64 ftello
56 #define fseeko64 fseeko
57 #endif
58 #ifdef _MSC_VER
@@ -80,11 +80,11 @@
80
81 #ifdef HAVE_MINIZIP64_CONF_H
82 #include "mz64conf.h"
83 #endif
84
85 /* a type chosen by DEFINE */
86 #ifdef HAVE_64BIT_INT_CUSTOM
87 typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
88 #else
89 #ifdef HAS_STDINT_H
90 #include "stdint.h"
@@ -132,18 +132,18 @@
132 #endif
133
134
135
136
137 typedef voidpf (ZCALLBACK *open_file_func) (voidpf opaque, const char* filename, int mode);
138 typedef uLong (ZCALLBACK *read_file_func) (voidpf opaque, voidpf stream, void* buf, uLong size);
139 typedef uLong (ZCALLBACK *write_file_func) (voidpf opaque, voidpf stream, const void* buf, uLong size);
140 typedef int (ZCALLBACK *close_file_func) (voidpf opaque, voidpf stream);
141 typedef int (ZCALLBACK *testerror_file_func) (voidpf opaque, voidpf stream);
142
143 typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream);
144 typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uLong offset, int origin);
145
146
147 /* here is the "old" 32 bits structure structure */
148 typedef struct zlib_filefunc_def_s
149 {
@@ -155,13 +155,13 @@
155 close_file_func zclose_file;
156 testerror_file_func zerror_file;
157 voidpf opaque;
158 } zlib_filefunc_def;
159
160 typedef ZPOS64_T (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream);
161 typedef long (ZCALLBACK *seek64_file_func) (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin);
162 typedef voidpf (ZCALLBACK *open64_file_func) (voidpf opaque, const void* filename, int mode);
163
164 typedef struct zlib_filefunc64_def_s
165 {
166 open64_file_func zopen64_file;
167 read_file_func zread_file;
@@ -171,12 +171,12 @@
171 close_file_func zclose_file;
172 testerror_file_func zerror_file;
173 voidpf opaque;
174 } zlib_filefunc64_def;
175
176 void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def);
177 void fill_fopen_filefunc(zlib_filefunc_def* pzlib_filefunc_def);
178
179 /* now internal definition, only for zip.c and unzip.h */
180 typedef struct zlib_filefunc64_32_def_s
181 {
182 zlib_filefunc64_def zfile_func64;
@@ -191,15 +191,15 @@
191 //#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
192 //#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
193 #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
194 #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
195
196 voidpf call_zopen64(const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode);
197 long call_zseek64(const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin);
198 ZPOS64_T call_ztell64(const zlib_filefunc64_32_def* pfilefunc,voidpf filestream);
199
200 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
201
202 #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
203 #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
204 #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
205
206
--- compat/zlib/contrib/minizip/iowin32.c
+++ compat/zlib/contrib/minizip/iowin32.c
@@ -36,18 +36,10 @@
3636
#if WINAPI_FAMILY_ONE_PARTITION(WINAPI_FAMILY, WINAPI_PARTITION_APP)
3737
#define IOWIN32_USING_WINRT_API 1
3838
#endif
3939
#endif
4040
41
-voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode));
42
-uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
43
-uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
44
-ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream));
45
-long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
46
-int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream));
47
-int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream));
48
-
4941
typedef struct
5042
{
5143
HANDLE hf;
5244
int error;
5345
} WIN32FILE_IOWIN;
@@ -55,12 +47,11 @@
5547
5648
static void win32_translate_open_mode(int mode,
5749
DWORD* lpdwDesiredAccess,
5850
DWORD* lpdwCreationDisposition,
5951
DWORD* lpdwShareMode,
60
- DWORD* lpdwFlagsAndAttributes)
61
-{
52
+ DWORD* lpdwFlagsAndAttributes) {
6253
*lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
6354
6455
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
6556
{
6657
*lpdwDesiredAccess = GENERIC_READ;
@@ -77,12 +68,11 @@
7768
*lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
7869
*lpdwCreationDisposition = CREATE_ALWAYS;
7970
}
8071
}
8172
82
-static voidpf win32_build_iowin(HANDLE hFile)
83
-{
73
+static voidpf win32_build_iowin(HANDLE hFile) {
8474
voidpf ret=NULL;
8575
8676
if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
8777
{
8878
WIN32FILE_IOWIN w32fiow;
@@ -96,12 +86,11 @@
9686
*((WIN32FILE_IOWIN*)ret) = w32fiow;
9787
}
9888
return ret;
9989
}
10090
101
-voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode)
102
-{
91
+voidpf ZCALLBACK win32_open64_file_func(voidpf opaque, const void* filename, int mode) {
10392
const char* mode_fopen = NULL;
10493
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
10594
HANDLE hFile = NULL;
10695
10796
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
@@ -125,12 +114,11 @@
125114
126115
return win32_build_iowin(hFile);
127116
}
128117
129118
130
-voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode)
131
-{
119
+voidpf ZCALLBACK win32_open64_file_funcA(voidpf opaque, const void* filename, int mode) {
132120
const char* mode_fopen = NULL;
133121
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
134122
HANDLE hFile = NULL;
135123
136124
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
@@ -149,12 +137,11 @@
149137
150138
return win32_build_iowin(hFile);
151139
}
152140
153141
154
-voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
155
-{
142
+voidpf ZCALLBACK win32_open64_file_funcW(voidpf opaque, const void* filename, int mode) {
156143
const char* mode_fopen = NULL;
157144
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
158145
HANDLE hFile = NULL;
159146
160147
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
@@ -169,12 +156,11 @@
169156
170157
return win32_build_iowin(hFile);
171158
}
172159
173160
174
-voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode)
175
-{
161
+voidpf ZCALLBACK win32_open_file_func(voidpf opaque, const char* filename, int mode) {
176162
const char* mode_fopen = NULL;
177163
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
178164
HANDLE hFile = NULL;
179165
180166
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
@@ -198,12 +184,11 @@
198184
199185
return win32_build_iowin(hFile);
200186
}
201187
202188
203
-uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
204
-{
189
+uLong ZCALLBACK win32_read_file_func(voidpf opaque, voidpf stream, void* buf,uLong size) {
205190
uLong ret=0;
206191
HANDLE hFile = NULL;
207192
if (stream!=NULL)
208193
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
209194
@@ -220,12 +205,11 @@
220205
221206
return ret;
222207
}
223208
224209
225
-uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
226
-{
210
+uLong ZCALLBACK win32_write_file_func(voidpf opaque, voidpf stream, const void* buf, uLong size) {
227211
uLong ret=0;
228212
HANDLE hFile = NULL;
229213
if (stream!=NULL)
230214
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
231215
@@ -241,12 +225,11 @@
241225
}
242226
243227
return ret;
244228
}
245229
246
-static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod)
247
-{
230
+static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod) {
248231
#ifdef IOWIN32_USING_WINRT_API
249232
return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod);
250233
#else
251234
LONG lHigh = pos.HighPart;
252235
DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, dwMoveMethod);
@@ -261,12 +244,11 @@
261244
}
262245
return fOk;
263246
#endif
264247
}
265248
266
-long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
267
-{
249
+long ZCALLBACK win32_tell_file_func(voidpf opaque, voidpf stream) {
268250
long ret=-1;
269251
HANDLE hFile = NULL;
270252
if (stream!=NULL)
271253
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
272254
if (hFile != NULL)
@@ -284,12 +266,11 @@
284266
ret=(long)pos.LowPart;
285267
}
286268
return ret;
287269
}
288270
289
-ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
290
-{
271
+ZPOS64_T ZCALLBACK win32_tell64_file_func(voidpf opaque, voidpf stream) {
291272
ZPOS64_T ret= (ZPOS64_T)-1;
292273
HANDLE hFile = NULL;
293274
if (stream!=NULL)
294275
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
295276
@@ -309,12 +290,11 @@
309290
}
310291
return ret;
311292
}
312293
313294
314
-long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
315
-{
295
+long ZCALLBACK win32_seek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin) {
316296
DWORD dwMoveMethod=0xFFFFFFFF;
317297
HANDLE hFile = NULL;
318298
319299
long ret=-1;
320300
if (stream!=NULL)
@@ -347,12 +327,11 @@
347327
ret=0;
348328
}
349329
return ret;
350330
}
351331
352
-long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin)
353
-{
332
+long ZCALLBACK win32_seek64_file_func(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) {
354333
DWORD dwMoveMethod=0xFFFFFFFF;
355334
HANDLE hFile = NULL;
356335
long ret=-1;
357336
358337
if (stream!=NULL)
@@ -386,12 +365,11 @@
386365
ret=0;
387366
}
388367
return ret;
389368
}
390369
391
-int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream)
392
-{
370
+int ZCALLBACK win32_close_file_func(voidpf opaque, voidpf stream) {
393371
int ret=-1;
394372
395373
if (stream!=NULL)
396374
{
397375
HANDLE hFile;
@@ -404,22 +382,20 @@
404382
free(stream);
405383
}
406384
return ret;
407385
}
408386
409
-int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream)
410
-{
387
+int ZCALLBACK win32_error_file_func(voidpf opaque, voidpf stream) {
411388
int ret=-1;
412389
if (stream!=NULL)
413390
{
414391
ret = ((WIN32FILE_IOWIN*)stream) -> error;
415392
}
416393
return ret;
417394
}
418395
419
-void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
420
-{
396
+void fill_win32_filefunc(zlib_filefunc_def* pzlib_filefunc_def) {
421397
pzlib_filefunc_def->zopen_file = win32_open_file_func;
422398
pzlib_filefunc_def->zread_file = win32_read_file_func;
423399
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
424400
pzlib_filefunc_def->ztell_file = win32_tell_file_func;
425401
pzlib_filefunc_def->zseek_file = win32_seek_file_func;
@@ -426,12 +402,11 @@
426402
pzlib_filefunc_def->zclose_file = win32_close_file_func;
427403
pzlib_filefunc_def->zerror_file = win32_error_file_func;
428404
pzlib_filefunc_def->opaque = NULL;
429405
}
430406
431
-void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def)
432
-{
407
+void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def) {
433408
pzlib_filefunc_def->zopen64_file = win32_open64_file_func;
434409
pzlib_filefunc_def->zread_file = win32_read_file_func;
435410
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
436411
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
437412
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
@@ -439,12 +414,11 @@
439414
pzlib_filefunc_def->zerror_file = win32_error_file_func;
440415
pzlib_filefunc_def->opaque = NULL;
441416
}
442417
443418
444
-void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def)
445
-{
419
+void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def) {
446420
pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA;
447421
pzlib_filefunc_def->zread_file = win32_read_file_func;
448422
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
449423
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
450424
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
@@ -452,16 +426,15 @@
452426
pzlib_filefunc_def->zerror_file = win32_error_file_func;
453427
pzlib_filefunc_def->opaque = NULL;
454428
}
455429
456430
457
-void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def)
458
-{
431
+void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def) {
459432
pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
460433
pzlib_filefunc_def->zread_file = win32_read_file_func;
461434
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
462435
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
463436
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
464437
pzlib_filefunc_def->zclose_file = win32_close_file_func;
465438
pzlib_filefunc_def->zerror_file = win32_error_file_func;
466439
pzlib_filefunc_def->opaque = NULL;
467440
}
468441
--- compat/zlib/contrib/minizip/iowin32.c
+++ compat/zlib/contrib/minizip/iowin32.c
@@ -36,18 +36,10 @@
36 #if WINAPI_FAMILY_ONE_PARTITION(WINAPI_FAMILY, WINAPI_PARTITION_APP)
37 #define IOWIN32_USING_WINRT_API 1
38 #endif
39 #endif
40
41 voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode));
42 uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
43 uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
44 ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream));
45 long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
46 int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream));
47 int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream));
48
49 typedef struct
50 {
51 HANDLE hf;
52 int error;
53 } WIN32FILE_IOWIN;
@@ -55,12 +47,11 @@
55
56 static void win32_translate_open_mode(int mode,
57 DWORD* lpdwDesiredAccess,
58 DWORD* lpdwCreationDisposition,
59 DWORD* lpdwShareMode,
60 DWORD* lpdwFlagsAndAttributes)
61 {
62 *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
63
64 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
65 {
66 *lpdwDesiredAccess = GENERIC_READ;
@@ -77,12 +68,11 @@
77 *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
78 *lpdwCreationDisposition = CREATE_ALWAYS;
79 }
80 }
81
82 static voidpf win32_build_iowin(HANDLE hFile)
83 {
84 voidpf ret=NULL;
85
86 if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
87 {
88 WIN32FILE_IOWIN w32fiow;
@@ -96,12 +86,11 @@
96 *((WIN32FILE_IOWIN*)ret) = w32fiow;
97 }
98 return ret;
99 }
100
101 voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode)
102 {
103 const char* mode_fopen = NULL;
104 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
105 HANDLE hFile = NULL;
106
107 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
@@ -125,12 +114,11 @@
125
126 return win32_build_iowin(hFile);
127 }
128
129
130 voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode)
131 {
132 const char* mode_fopen = NULL;
133 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
134 HANDLE hFile = NULL;
135
136 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
@@ -149,12 +137,11 @@
149
150 return win32_build_iowin(hFile);
151 }
152
153
154 voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
155 {
156 const char* mode_fopen = NULL;
157 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
158 HANDLE hFile = NULL;
159
160 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
@@ -169,12 +156,11 @@
169
170 return win32_build_iowin(hFile);
171 }
172
173
174 voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode)
175 {
176 const char* mode_fopen = NULL;
177 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
178 HANDLE hFile = NULL;
179
180 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
@@ -198,12 +184,11 @@
198
199 return win32_build_iowin(hFile);
200 }
201
202
203 uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
204 {
205 uLong ret=0;
206 HANDLE hFile = NULL;
207 if (stream!=NULL)
208 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
209
@@ -220,12 +205,11 @@
220
221 return ret;
222 }
223
224
225 uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
226 {
227 uLong ret=0;
228 HANDLE hFile = NULL;
229 if (stream!=NULL)
230 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
231
@@ -241,12 +225,11 @@
241 }
242
243 return ret;
244 }
245
246 static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod)
247 {
248 #ifdef IOWIN32_USING_WINRT_API
249 return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod);
250 #else
251 LONG lHigh = pos.HighPart;
252 DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, dwMoveMethod);
@@ -261,12 +244,11 @@
261 }
262 return fOk;
263 #endif
264 }
265
266 long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
267 {
268 long ret=-1;
269 HANDLE hFile = NULL;
270 if (stream!=NULL)
271 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
272 if (hFile != NULL)
@@ -284,12 +266,11 @@
284 ret=(long)pos.LowPart;
285 }
286 return ret;
287 }
288
289 ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
290 {
291 ZPOS64_T ret= (ZPOS64_T)-1;
292 HANDLE hFile = NULL;
293 if (stream!=NULL)
294 hFile = ((WIN32FILE_IOWIN*)stream)->hf;
295
@@ -309,12 +290,11 @@
309 }
310 return ret;
311 }
312
313
314 long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
315 {
316 DWORD dwMoveMethod=0xFFFFFFFF;
317 HANDLE hFile = NULL;
318
319 long ret=-1;
320 if (stream!=NULL)
@@ -347,12 +327,11 @@
347 ret=0;
348 }
349 return ret;
350 }
351
352 long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin)
353 {
354 DWORD dwMoveMethod=0xFFFFFFFF;
355 HANDLE hFile = NULL;
356 long ret=-1;
357
358 if (stream!=NULL)
@@ -386,12 +365,11 @@
386 ret=0;
387 }
388 return ret;
389 }
390
391 int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream)
392 {
393 int ret=-1;
394
395 if (stream!=NULL)
396 {
397 HANDLE hFile;
@@ -404,22 +382,20 @@
404 free(stream);
405 }
406 return ret;
407 }
408
409 int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream)
410 {
411 int ret=-1;
412 if (stream!=NULL)
413 {
414 ret = ((WIN32FILE_IOWIN*)stream) -> error;
415 }
416 return ret;
417 }
418
419 void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
420 {
421 pzlib_filefunc_def->zopen_file = win32_open_file_func;
422 pzlib_filefunc_def->zread_file = win32_read_file_func;
423 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
424 pzlib_filefunc_def->ztell_file = win32_tell_file_func;
425 pzlib_filefunc_def->zseek_file = win32_seek_file_func;
@@ -426,12 +402,11 @@
426 pzlib_filefunc_def->zclose_file = win32_close_file_func;
427 pzlib_filefunc_def->zerror_file = win32_error_file_func;
428 pzlib_filefunc_def->opaque = NULL;
429 }
430
431 void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def)
432 {
433 pzlib_filefunc_def->zopen64_file = win32_open64_file_func;
434 pzlib_filefunc_def->zread_file = win32_read_file_func;
435 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
436 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
437 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
@@ -439,12 +414,11 @@
439 pzlib_filefunc_def->zerror_file = win32_error_file_func;
440 pzlib_filefunc_def->opaque = NULL;
441 }
442
443
444 void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def)
445 {
446 pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA;
447 pzlib_filefunc_def->zread_file = win32_read_file_func;
448 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
449 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
450 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
@@ -452,16 +426,15 @@
452 pzlib_filefunc_def->zerror_file = win32_error_file_func;
453 pzlib_filefunc_def->opaque = NULL;
454 }
455
456
457 void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def)
458 {
459 pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
460 pzlib_filefunc_def->zread_file = win32_read_file_func;
461 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
462 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
463 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
464 pzlib_filefunc_def->zclose_file = win32_close_file_func;
465 pzlib_filefunc_def->zerror_file = win32_error_file_func;
466 pzlib_filefunc_def->opaque = NULL;
467 }
468
--- compat/zlib/contrib/minizip/iowin32.c
+++ compat/zlib/contrib/minizip/iowin32.c
@@ -36,18 +36,10 @@
36 #if WINAPI_FAMILY_ONE_PARTITION(WINAPI_FAMILY, WINAPI_PARTITION_APP)
37 #define IOWIN32_USING_WINRT_API 1
38 #endif
39 #endif
40
 
 
 
 
 
 
 
 
41 typedef struct
42 {
43 HANDLE hf;
44 int error;
45 } WIN32FILE_IOWIN;
@@ -55,12 +47,11 @@
47
48 static void win32_translate_open_mode(int mode,
49 DWORD* lpdwDesiredAccess,
50 DWORD* lpdwCreationDisposition,
51 DWORD* lpdwShareMode,
52 DWORD* lpdwFlagsAndAttributes) {
 
53 *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
54
55 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
56 {
57 *lpdwDesiredAccess = GENERIC_READ;
@@ -77,12 +68,11 @@
68 *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
69 *lpdwCreationDisposition = CREATE_ALWAYS;
70 }
71 }
72
73 static voidpf win32_build_iowin(HANDLE hFile) {
 
74 voidpf ret=NULL;
75
76 if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
77 {
78 WIN32FILE_IOWIN w32fiow;
@@ -96,12 +86,11 @@
86 *((WIN32FILE_IOWIN*)ret) = w32fiow;
87 }
88 return ret;
89 }
90
91 voidpf ZCALLBACK win32_open64_file_func(voidpf opaque, const void* filename, int mode) {
 
92 const char* mode_fopen = NULL;
93 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
94 HANDLE hFile = NULL;
95
96 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
@@ -125,12 +114,11 @@
114
115 return win32_build_iowin(hFile);
116 }
117
118
119 voidpf ZCALLBACK win32_open64_file_funcA(voidpf opaque, const void* filename, int mode) {
 
120 const char* mode_fopen = NULL;
121 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
122 HANDLE hFile = NULL;
123
124 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
@@ -149,12 +137,11 @@
137
138 return win32_build_iowin(hFile);
139 }
140
141
142 voidpf ZCALLBACK win32_open64_file_funcW(voidpf opaque, const void* filename, int mode) {
 
143 const char* mode_fopen = NULL;
144 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
145 HANDLE hFile = NULL;
146
147 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
@@ -169,12 +156,11 @@
156
157 return win32_build_iowin(hFile);
158 }
159
160
161 voidpf ZCALLBACK win32_open_file_func(voidpf opaque, const char* filename, int mode) {
 
162 const char* mode_fopen = NULL;
163 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
164 HANDLE hFile = NULL;
165
166 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
@@ -198,12 +184,11 @@
184
185 return win32_build_iowin(hFile);
186 }
187
188
189 uLong ZCALLBACK win32_read_file_func(voidpf opaque, voidpf stream, void* buf,uLong size) {
 
190 uLong ret=0;
191 HANDLE hFile = NULL;
192 if (stream!=NULL)
193 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
194
@@ -220,12 +205,11 @@
205
206 return ret;
207 }
208
209
210 uLong ZCALLBACK win32_write_file_func(voidpf opaque, voidpf stream, const void* buf, uLong size) {
 
211 uLong ret=0;
212 HANDLE hFile = NULL;
213 if (stream!=NULL)
214 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
215
@@ -241,12 +225,11 @@
225 }
226
227 return ret;
228 }
229
230 static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod) {
 
231 #ifdef IOWIN32_USING_WINRT_API
232 return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod);
233 #else
234 LONG lHigh = pos.HighPart;
235 DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, dwMoveMethod);
@@ -261,12 +244,11 @@
244 }
245 return fOk;
246 #endif
247 }
248
249 long ZCALLBACK win32_tell_file_func(voidpf opaque, voidpf stream) {
 
250 long ret=-1;
251 HANDLE hFile = NULL;
252 if (stream!=NULL)
253 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
254 if (hFile != NULL)
@@ -284,12 +266,11 @@
266 ret=(long)pos.LowPart;
267 }
268 return ret;
269 }
270
271 ZPOS64_T ZCALLBACK win32_tell64_file_func(voidpf opaque, voidpf stream) {
 
272 ZPOS64_T ret= (ZPOS64_T)-1;
273 HANDLE hFile = NULL;
274 if (stream!=NULL)
275 hFile = ((WIN32FILE_IOWIN*)stream)->hf;
276
@@ -309,12 +290,11 @@
290 }
291 return ret;
292 }
293
294
295 long ZCALLBACK win32_seek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin) {
 
296 DWORD dwMoveMethod=0xFFFFFFFF;
297 HANDLE hFile = NULL;
298
299 long ret=-1;
300 if (stream!=NULL)
@@ -347,12 +327,11 @@
327 ret=0;
328 }
329 return ret;
330 }
331
332 long ZCALLBACK win32_seek64_file_func(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) {
 
333 DWORD dwMoveMethod=0xFFFFFFFF;
334 HANDLE hFile = NULL;
335 long ret=-1;
336
337 if (stream!=NULL)
@@ -386,12 +365,11 @@
365 ret=0;
366 }
367 return ret;
368 }
369
370 int ZCALLBACK win32_close_file_func(voidpf opaque, voidpf stream) {
 
371 int ret=-1;
372
373 if (stream!=NULL)
374 {
375 HANDLE hFile;
@@ -404,22 +382,20 @@
382 free(stream);
383 }
384 return ret;
385 }
386
387 int ZCALLBACK win32_error_file_func(voidpf opaque, voidpf stream) {
 
388 int ret=-1;
389 if (stream!=NULL)
390 {
391 ret = ((WIN32FILE_IOWIN*)stream) -> error;
392 }
393 return ret;
394 }
395
396 void fill_win32_filefunc(zlib_filefunc_def* pzlib_filefunc_def) {
 
397 pzlib_filefunc_def->zopen_file = win32_open_file_func;
398 pzlib_filefunc_def->zread_file = win32_read_file_func;
399 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
400 pzlib_filefunc_def->ztell_file = win32_tell_file_func;
401 pzlib_filefunc_def->zseek_file = win32_seek_file_func;
@@ -426,12 +402,11 @@
402 pzlib_filefunc_def->zclose_file = win32_close_file_func;
403 pzlib_filefunc_def->zerror_file = win32_error_file_func;
404 pzlib_filefunc_def->opaque = NULL;
405 }
406
407 void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def) {
 
408 pzlib_filefunc_def->zopen64_file = win32_open64_file_func;
409 pzlib_filefunc_def->zread_file = win32_read_file_func;
410 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
411 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
412 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
@@ -439,12 +414,11 @@
414 pzlib_filefunc_def->zerror_file = win32_error_file_func;
415 pzlib_filefunc_def->opaque = NULL;
416 }
417
418
419 void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def) {
 
420 pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA;
421 pzlib_filefunc_def->zread_file = win32_read_file_func;
422 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
423 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
424 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
@@ -452,16 +426,15 @@
426 pzlib_filefunc_def->zerror_file = win32_error_file_func;
427 pzlib_filefunc_def->opaque = NULL;
428 }
429
430
431 void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def) {
 
432 pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
433 pzlib_filefunc_def->zread_file = win32_read_file_func;
434 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
435 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
436 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
437 pzlib_filefunc_def->zclose_file = win32_close_file_func;
438 pzlib_filefunc_def->zerror_file = win32_error_file_func;
439 pzlib_filefunc_def->opaque = NULL;
440 }
441
--- compat/zlib/contrib/minizip/iowin32.h
+++ compat/zlib/contrib/minizip/iowin32.h
@@ -16,13 +16,13 @@
1616
1717
#ifdef __cplusplus
1818
extern "C" {
1919
#endif
2020
21
-void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
22
-void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def));
23
-void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def));
24
-void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def));
21
+void fill_win32_filefunc(zlib_filefunc_def* pzlib_filefunc_def);
22
+void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def);
23
+void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def);
24
+void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def);
2525
2626
#ifdef __cplusplus
2727
}
2828
#endif
2929
--- compat/zlib/contrib/minizip/iowin32.h
+++ compat/zlib/contrib/minizip/iowin32.h
@@ -16,13 +16,13 @@
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
22 void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def));
23 void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def));
24 void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def));
25
26 #ifdef __cplusplus
27 }
28 #endif
29
--- compat/zlib/contrib/minizip/iowin32.h
+++ compat/zlib/contrib/minizip/iowin32.h
@@ -16,13 +16,13 @@
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 void fill_win32_filefunc(zlib_filefunc_def* pzlib_filefunc_def);
22 void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def);
23 void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def);
24 void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def);
25
26 #ifdef __cplusplus
27 }
28 #endif
29
--- compat/zlib/contrib/minizip/miniunz.c
+++ compat/zlib/contrib/minizip/miniunz.c
@@ -25,11 +25,11 @@
2525
#ifndef _FILE_OFFSET_BIT
2626
#define _FILE_OFFSET_BIT 64
2727
#endif
2828
#endif
2929
30
-#ifdef __APPLE__
30
+#if defined(__APPLE__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
3131
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
3232
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
3333
#define FTELLO_FUNC(stream) ftello(stream)
3434
#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
3535
#else
@@ -79,15 +79,11 @@
7979
8080
/* change_file_date : change the date/time of a file
8181
filename : the filename of the file where date/time must be modified
8282
dosdate : the new date at the MSDos format (4 bytes)
8383
tmu_date : the SAME new date at the tm_unz format */
84
-static void change_file_date(filename,dosdate,tmu_date)
85
- const char *filename;
86
- uLong dosdate;
87
- tm_unz tmu_date;
88
-{
84
+static void change_file_date(const char *filename, uLong dosdate, tm_unz tmu_date) {
8985
#ifdef _WIN32
9086
HANDLE hFile;
9187
FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
9288
9389
hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,
@@ -113,35 +109,37 @@
113109
newdate.tm_year=tmu_date.tm_year ;
114110
newdate.tm_isdst=-1;
115111
116112
ut.actime=ut.modtime=mktime(&newdate);
117113
utime(filename,&ut);
114
+#else
115
+ (void)filename;
116
+ (void)dosdate;
117
+ (void)tmu_date;
118118
#endif
119119
#endif
120120
}
121121
122122
123123
/* mymkdir and change_file_date are not 100 % portable
124124
As I don't know well Unix, I wait feedback for the unix portion */
125125
126
-static int mymkdir(dirname)
127
- const char* dirname;
128
-{
126
+static int mymkdir(const char* dirname) {
129127
int ret=0;
130128
#ifdef _WIN32
131129
ret = _mkdir(dirname);
132130
#elif unix
133131
ret = mkdir (dirname,0775);
134132
#elif __APPLE__
135133
ret = mkdir (dirname,0775);
134
+#else
135
+ (void)dirname;
136136
#endif
137137
return ret;
138138
}
139139
140
-static int makedir (newdir)
141
- const char *newdir;
142
-{
140
+static int makedir(const char *newdir) {
143141
char *buffer ;
144142
char *p;
145143
size_t len = strlen(newdir);
146144
147145
if (len == 0)
@@ -185,30 +183,27 @@
185183
}
186184
free(buffer);
187185
return 1;
188186
}
189187
190
-static void do_banner()
191
-{
188
+static void do_banner(void) {
192189
printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n");
193190
printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
194191
}
195192
196
-static void do_help()
197
-{
193
+static void do_help(void) {
198194
printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \
199195
" -e Extract without pathname (junk paths)\n" \
200196
" -x Extract with pathname\n" \
201197
" -v list files\n" \
202198
" -l list files\n" \
203199
" -d directory to extract into\n" \
204200
" -o overwrite files without prompting\n" \
205
- " -p extract crypted file using password\n\n");
201
+ " -p extract encrypted file using password\n\n");
206202
}
207203
208
-static void Display64BitsSize(ZPOS64_T n, int size_char)
209
-{
204
+static void Display64BitsSize(ZPOS64_T n, int size_char) {
210205
/* to avoid compatibility problem , we do here the conversion */
211206
char number[21];
212207
int offset=19;
213208
int pos_string = 19;
214209
number[20]=0;
@@ -231,13 +226,11 @@
231226
}
232227
233228
printf("%s",&number[pos_string]);
234229
}
235230
236
-static int do_list(uf)
237
- unzFile uf;
238
-{
231
+static int do_list(unzFile uf) {
239232
uLong i;
240233
unz_global_info64 gi;
241234
int err;
242235
243236
err = unzGetGlobalInfo64(uf,&gi);
@@ -248,11 +241,11 @@
248241
for (i=0;i<gi.number_entry;i++)
249242
{
250243
char filename_inzip[256];
251244
unz_file_info64 file_info;
252245
uLong ratio=0;
253
- const char *string_method;
246
+ const char *string_method = "";
254247
char charCrypt=' ';
255248
err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
256249
if (err!=UNZ_OK)
257250
{
258251
printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
@@ -259,11 +252,11 @@
259252
break;
260253
}
261254
if (file_info.uncompressed_size>0)
262255
ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size);
263256
264
- /* display a '*' if the file is crypted */
257
+ /* display a '*' if the file is encrypted */
265258
if ((file_info.flag & 1) != 0)
266259
charCrypt='*';
267260
268261
if (file_info.compression_method==0)
269262
string_method="Stored";
@@ -309,16 +302,11 @@
309302
310303
return 0;
311304
}
312305
313306
314
-static int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
315
- unzFile uf;
316
- const int* popt_extract_without_path;
317
- int* popt_overwrite;
318
- const char* password;
319
-{
307
+static int do_extract_currentfile(unzFile uf, const int* popt_extract_without_path, int* popt_overwrite, const char* password) {
320308
char filename_inzip[256];
321309
char* filename_withoutpath;
322310
char* p;
323311
int err=UNZ_OK;
324312
FILE *fout=NULL;
@@ -471,16 +459,11 @@
471459
free(buf);
472460
return err;
473461
}
474462
475463
476
-static int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
477
- unzFile uf;
478
- int opt_extract_without_path;
479
- int opt_overwrite;
480
- const char* password;
481
-{
464
+static int do_extract(unzFile uf, int opt_extract_without_path, int opt_overwrite, const char* password) {
482465
uLong i;
483466
unz_global_info64 gi;
484467
int err;
485468
486469
err = unzGetGlobalInfo64(uf,&gi);
@@ -506,17 +489,11 @@
506489
}
507490
508491
return 0;
509492
}
510493
511
-static int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password)
512
- unzFile uf;
513
- const char* filename;
514
- int opt_extract_without_path;
515
- int opt_overwrite;
516
- const char* password;
517
-{
494
+static int do_extract_onefile(unzFile uf, const char* filename, int opt_extract_without_path, int opt_overwrite, const char* password) {
518495
if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
519496
{
520497
printf("file %s not found in the zipfile\n",filename);
521498
return 2;
522499
}
@@ -528,14 +505,11 @@
528505
else
529506
return 1;
530507
}
531508
532509
533
-int main(argc,argv)
534
- int argc;
535
- char *argv[];
536
-{
510
+int main(int argc, char *argv[]) {
537511
const char *zipfilename=NULL;
538512
const char *filename_to_extract=NULL;
539513
const char *password=NULL;
540514
char filename_try[MAXFILENAME+16] = "";
541515
int i;
@@ -604,11 +578,11 @@
604578
# ifdef USEWIN32IOAPI
605579
zlib_filefunc64_def ffunc;
606580
# endif
607581
608582
strncpy(filename_try, zipfilename,MAXFILENAME-1);
609
- /* strncpy doesnt append the trailing NULL, of the string is too long. */
583
+ /* strncpy doesn't append the trailing NULL, of the string is too long. */
610584
filename_try[ MAXFILENAME ] = '\0';
611585
612586
# ifdef USEWIN32IOAPI
613587
fill_win32_filefunc64A(&ffunc);
614588
uf = unzOpen2_64(zipfilename,&ffunc);
615589
--- compat/zlib/contrib/minizip/miniunz.c
+++ compat/zlib/contrib/minizip/miniunz.c
@@ -25,11 +25,11 @@
25 #ifndef _FILE_OFFSET_BIT
26 #define _FILE_OFFSET_BIT 64
27 #endif
28 #endif
29
30 #ifdef __APPLE__
31 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
32 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
33 #define FTELLO_FUNC(stream) ftello(stream)
34 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
35 #else
@@ -79,15 +79,11 @@
79
80 /* change_file_date : change the date/time of a file
81 filename : the filename of the file where date/time must be modified
82 dosdate : the new date at the MSDos format (4 bytes)
83 tmu_date : the SAME new date at the tm_unz format */
84 static void change_file_date(filename,dosdate,tmu_date)
85 const char *filename;
86 uLong dosdate;
87 tm_unz tmu_date;
88 {
89 #ifdef _WIN32
90 HANDLE hFile;
91 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
92
93 hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,
@@ -113,35 +109,37 @@
113 newdate.tm_year=tmu_date.tm_year ;
114 newdate.tm_isdst=-1;
115
116 ut.actime=ut.modtime=mktime(&newdate);
117 utime(filename,&ut);
 
 
 
 
118 #endif
119 #endif
120 }
121
122
123 /* mymkdir and change_file_date are not 100 % portable
124 As I don't know well Unix, I wait feedback for the unix portion */
125
126 static int mymkdir(dirname)
127 const char* dirname;
128 {
129 int ret=0;
130 #ifdef _WIN32
131 ret = _mkdir(dirname);
132 #elif unix
133 ret = mkdir (dirname,0775);
134 #elif __APPLE__
135 ret = mkdir (dirname,0775);
 
 
136 #endif
137 return ret;
138 }
139
140 static int makedir (newdir)
141 const char *newdir;
142 {
143 char *buffer ;
144 char *p;
145 size_t len = strlen(newdir);
146
147 if (len == 0)
@@ -185,30 +183,27 @@
185 }
186 free(buffer);
187 return 1;
188 }
189
190 static void do_banner()
191 {
192 printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n");
193 printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
194 }
195
196 static void do_help()
197 {
198 printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \
199 " -e Extract without pathname (junk paths)\n" \
200 " -x Extract with pathname\n" \
201 " -v list files\n" \
202 " -l list files\n" \
203 " -d directory to extract into\n" \
204 " -o overwrite files without prompting\n" \
205 " -p extract crypted file using password\n\n");
206 }
207
208 static void Display64BitsSize(ZPOS64_T n, int size_char)
209 {
210 /* to avoid compatibility problem , we do here the conversion */
211 char number[21];
212 int offset=19;
213 int pos_string = 19;
214 number[20]=0;
@@ -231,13 +226,11 @@
231 }
232
233 printf("%s",&number[pos_string]);
234 }
235
236 static int do_list(uf)
237 unzFile uf;
238 {
239 uLong i;
240 unz_global_info64 gi;
241 int err;
242
243 err = unzGetGlobalInfo64(uf,&gi);
@@ -248,11 +241,11 @@
248 for (i=0;i<gi.number_entry;i++)
249 {
250 char filename_inzip[256];
251 unz_file_info64 file_info;
252 uLong ratio=0;
253 const char *string_method;
254 char charCrypt=' ';
255 err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
256 if (err!=UNZ_OK)
257 {
258 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
@@ -259,11 +252,11 @@
259 break;
260 }
261 if (file_info.uncompressed_size>0)
262 ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size);
263
264 /* display a '*' if the file is crypted */
265 if ((file_info.flag & 1) != 0)
266 charCrypt='*';
267
268 if (file_info.compression_method==0)
269 string_method="Stored";
@@ -309,16 +302,11 @@
309
310 return 0;
311 }
312
313
314 static int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
315 unzFile uf;
316 const int* popt_extract_without_path;
317 int* popt_overwrite;
318 const char* password;
319 {
320 char filename_inzip[256];
321 char* filename_withoutpath;
322 char* p;
323 int err=UNZ_OK;
324 FILE *fout=NULL;
@@ -471,16 +459,11 @@
471 free(buf);
472 return err;
473 }
474
475
476 static int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
477 unzFile uf;
478 int opt_extract_without_path;
479 int opt_overwrite;
480 const char* password;
481 {
482 uLong i;
483 unz_global_info64 gi;
484 int err;
485
486 err = unzGetGlobalInfo64(uf,&gi);
@@ -506,17 +489,11 @@
506 }
507
508 return 0;
509 }
510
511 static int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password)
512 unzFile uf;
513 const char* filename;
514 int opt_extract_without_path;
515 int opt_overwrite;
516 const char* password;
517 {
518 if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
519 {
520 printf("file %s not found in the zipfile\n",filename);
521 return 2;
522 }
@@ -528,14 +505,11 @@
528 else
529 return 1;
530 }
531
532
533 int main(argc,argv)
534 int argc;
535 char *argv[];
536 {
537 const char *zipfilename=NULL;
538 const char *filename_to_extract=NULL;
539 const char *password=NULL;
540 char filename_try[MAXFILENAME+16] = "";
541 int i;
@@ -604,11 +578,11 @@
604 # ifdef USEWIN32IOAPI
605 zlib_filefunc64_def ffunc;
606 # endif
607
608 strncpy(filename_try, zipfilename,MAXFILENAME-1);
609 /* strncpy doesnt append the trailing NULL, of the string is too long. */
610 filename_try[ MAXFILENAME ] = '\0';
611
612 # ifdef USEWIN32IOAPI
613 fill_win32_filefunc64A(&ffunc);
614 uf = unzOpen2_64(zipfilename,&ffunc);
615
--- compat/zlib/contrib/minizip/miniunz.c
+++ compat/zlib/contrib/minizip/miniunz.c
@@ -25,11 +25,11 @@
25 #ifndef _FILE_OFFSET_BIT
26 #define _FILE_OFFSET_BIT 64
27 #endif
28 #endif
29
30 #if defined(__APPLE__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
31 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
32 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
33 #define FTELLO_FUNC(stream) ftello(stream)
34 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
35 #else
@@ -79,15 +79,11 @@
79
80 /* change_file_date : change the date/time of a file
81 filename : the filename of the file where date/time must be modified
82 dosdate : the new date at the MSDos format (4 bytes)
83 tmu_date : the SAME new date at the tm_unz format */
84 static void change_file_date(const char *filename, uLong dosdate, tm_unz tmu_date) {
 
 
 
 
85 #ifdef _WIN32
86 HANDLE hFile;
87 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
88
89 hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,
@@ -113,35 +109,37 @@
109 newdate.tm_year=tmu_date.tm_year ;
110 newdate.tm_isdst=-1;
111
112 ut.actime=ut.modtime=mktime(&newdate);
113 utime(filename,&ut);
114 #else
115 (void)filename;
116 (void)dosdate;
117 (void)tmu_date;
118 #endif
119 #endif
120 }
121
122
123 /* mymkdir and change_file_date are not 100 % portable
124 As I don't know well Unix, I wait feedback for the unix portion */
125
126 static int mymkdir(const char* dirname) {
 
 
127 int ret=0;
128 #ifdef _WIN32
129 ret = _mkdir(dirname);
130 #elif unix
131 ret = mkdir (dirname,0775);
132 #elif __APPLE__
133 ret = mkdir (dirname,0775);
134 #else
135 (void)dirname;
136 #endif
137 return ret;
138 }
139
140 static int makedir(const char *newdir) {
 
 
141 char *buffer ;
142 char *p;
143 size_t len = strlen(newdir);
144
145 if (len == 0)
@@ -185,30 +183,27 @@
183 }
184 free(buffer);
185 return 1;
186 }
187
188 static void do_banner(void) {
 
189 printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n");
190 printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
191 }
192
193 static void do_help(void) {
 
194 printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \
195 " -e Extract without pathname (junk paths)\n" \
196 " -x Extract with pathname\n" \
197 " -v list files\n" \
198 " -l list files\n" \
199 " -d directory to extract into\n" \
200 " -o overwrite files without prompting\n" \
201 " -p extract encrypted file using password\n\n");
202 }
203
204 static void Display64BitsSize(ZPOS64_T n, int size_char) {
 
205 /* to avoid compatibility problem , we do here the conversion */
206 char number[21];
207 int offset=19;
208 int pos_string = 19;
209 number[20]=0;
@@ -231,13 +226,11 @@
226 }
227
228 printf("%s",&number[pos_string]);
229 }
230
231 static int do_list(unzFile uf) {
 
 
232 uLong i;
233 unz_global_info64 gi;
234 int err;
235
236 err = unzGetGlobalInfo64(uf,&gi);
@@ -248,11 +241,11 @@
241 for (i=0;i<gi.number_entry;i++)
242 {
243 char filename_inzip[256];
244 unz_file_info64 file_info;
245 uLong ratio=0;
246 const char *string_method = "";
247 char charCrypt=' ';
248 err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
249 if (err!=UNZ_OK)
250 {
251 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
@@ -259,11 +252,11 @@
252 break;
253 }
254 if (file_info.uncompressed_size>0)
255 ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size);
256
257 /* display a '*' if the file is encrypted */
258 if ((file_info.flag & 1) != 0)
259 charCrypt='*';
260
261 if (file_info.compression_method==0)
262 string_method="Stored";
@@ -309,16 +302,11 @@
302
303 return 0;
304 }
305
306
307 static int do_extract_currentfile(unzFile uf, const int* popt_extract_without_path, int* popt_overwrite, const char* password) {
 
 
 
 
 
308 char filename_inzip[256];
309 char* filename_withoutpath;
310 char* p;
311 int err=UNZ_OK;
312 FILE *fout=NULL;
@@ -471,16 +459,11 @@
459 free(buf);
460 return err;
461 }
462
463
464 static int do_extract(unzFile uf, int opt_extract_without_path, int opt_overwrite, const char* password) {
 
 
 
 
 
465 uLong i;
466 unz_global_info64 gi;
467 int err;
468
469 err = unzGetGlobalInfo64(uf,&gi);
@@ -506,17 +489,11 @@
489 }
490
491 return 0;
492 }
493
494 static int do_extract_onefile(unzFile uf, const char* filename, int opt_extract_without_path, int opt_overwrite, const char* password) {
 
 
 
 
 
 
495 if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
496 {
497 printf("file %s not found in the zipfile\n",filename);
498 return 2;
499 }
@@ -528,14 +505,11 @@
505 else
506 return 1;
507 }
508
509
510 int main(int argc, char *argv[]) {
 
 
 
511 const char *zipfilename=NULL;
512 const char *filename_to_extract=NULL;
513 const char *password=NULL;
514 char filename_try[MAXFILENAME+16] = "";
515 int i;
@@ -604,11 +578,11 @@
578 # ifdef USEWIN32IOAPI
579 zlib_filefunc64_def ffunc;
580 # endif
581
582 strncpy(filename_try, zipfilename,MAXFILENAME-1);
583 /* strncpy doesn't append the trailing NULL, of the string is too long. */
584 filename_try[ MAXFILENAME ] = '\0';
585
586 # ifdef USEWIN32IOAPI
587 fill_win32_filefunc64A(&ffunc);
588 uf = unzOpen2_64(zipfilename,&ffunc);
589
--- compat/zlib/contrib/minizip/minizip.c
+++ compat/zlib/contrib/minizip/minizip.c
@@ -26,11 +26,11 @@
2626
#ifndef _FILE_OFFSET_BIT
2727
#define _FILE_OFFSET_BIT 64
2828
#endif
2929
#endif
3030
31
-#ifdef __APPLE__
31
+#if defined(__APPLE__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
3232
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
3333
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
3434
#define FTELLO_FUNC(stream) ftello(stream)
3535
#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
3636
#else
@@ -69,15 +69,13 @@
6969
7070
#define WRITEBUFFERSIZE (16384)
7171
#define MAXFILENAME (256)
7272
7373
#ifdef _WIN32
74
-static int filetime(f, tmzip, dt)
75
- const char *f; /* name of file to get info on */
76
- tm_zip *tmzip; /* return value: access, modific. and creation times */
77
- uLong *dt; /* dostime */
78
-{
74
+/* f: name of file to get info on, tmzip: return value: access,
75
+ modification and creation times, dt: dostime */
76
+static int filetime(const char *f, tm_zip *tmzip, uLong *dt) {
7977
int ret = 0;
8078
{
8179
FILETIME ftLocal;
8280
HANDLE hFind;
8381
WIN32_FIND_DATAA ff32;
@@ -93,15 +91,13 @@
9391
}
9492
return ret;
9593
}
9694
#else
9795
#if defined(unix) || defined(__APPLE__)
98
-static int filetime(f, tmzip, dt)
99
- const char *f; /* name of file to get info on */
100
- tm_zip *tmzip; /* return value: access, modific. and creation times */
101
- uLong *dt; /* dostime */
102
-{
96
+/* f: name of file to get info on, tmzip: return value: access,
97
+ modification and creation times, dt: dostime */
98
+static int filetime(const char *f, tm_zip *tmzip, uLong *dt) {
10399
(void)dt;
104100
int ret=0;
105101
struct stat s; /* results of stat() */
106102
struct tm* filedate;
107103
time_t tm_t=0;
@@ -112,11 +108,11 @@
112108
size_t len = strlen(f);
113109
if (len > MAXFILENAME)
114110
len = MAXFILENAME;
115111
116112
strncpy(name, f,MAXFILENAME-1);
117
- /* strncpy doesnt append the trailing NULL, of the string is too long. */
113
+ /* strncpy doesn't append the trailing NULL, of the string is too long. */
118114
name[ MAXFILENAME ] = '\0';
119115
120116
if (name[len - 1] == '/')
121117
name[len - 1] = '\0';
122118
/* not all systems allow stat'ing a file with / appended */
@@ -136,26 +132,25 @@
136132
tmzip->tm_year = filedate->tm_year;
137133
138134
return ret;
139135
}
140136
#else
141
-uLong filetime(f, tmzip, dt)
142
- const char *f; /* name of file to get info on */
143
- tm_zip *tmzip; /* return value: access, modific. and creation times */
144
- uLong *dt; /* dostime */
145
-{
137
+/* f: name of file to get info on, tmzip: return value: access,
138
+ modification and creation times, dt: dostime */
139
+static int filetime(const char *f, tm_zip *tmzip, uLong *dt) {
140
+ (void)f;
141
+ (void)tmzip;
142
+ (void)dt;
146143
return 0;
147144
}
148145
#endif
149146
#endif
150147
151148
152149
153150
154
-static int check_exist_file(filename)
155
- const char* filename;
156
-{
151
+static int check_exist_file(const char* filename) {
157152
FILE* ftestexist;
158153
int ret = 1;
159154
ftestexist = FOPEN_FUNC(filename,"rb");
160155
if (ftestexist==NULL)
161156
ret = 0;
@@ -162,18 +157,16 @@
162157
else
163158
fclose(ftestexist);
164159
return ret;
165160
}
166161
167
-static void do_banner()
168
-{
162
+static void do_banner(void) {
169163
printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
170164
printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
171165
}
172166
173
-static void do_help()
174
-{
167
+static void do_help(void) {
175168
printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
176169
" -o Overwrite existing file.zip\n" \
177170
" -a Append to existing file.zip\n" \
178171
" -0 Store only\n" \
179172
" -1 Compress faster\n" \
@@ -181,12 +174,11 @@
181174
" -j exclude path. store only the file name.\n\n");
182175
}
183176
184177
/* calculate the CRC32 of a file,
185178
because to encrypt a file, we need known the CRC32 of the file before */
186
-static int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)
187
-{
179
+static int getFileCrc(const char* filenameinzip, void* buf, unsigned long size_buf, unsigned long* result_crc) {
188180
unsigned long calculate_crc=0;
189181
int err=ZIP_OK;
190182
FILE * fin = FOPEN_FUNC(filenameinzip,"rb");
191183
192184
unsigned long size_read = 0;
@@ -220,22 +212,21 @@
220212
*result_crc=calculate_crc;
221213
printf("file %s crc %lx\n", filenameinzip, calculate_crc);
222214
return err;
223215
}
224216
225
-static int isLargeFile(const char* filename)
226
-{
217
+static int isLargeFile(const char* filename) {
227218
int largeFile = 0;
228219
ZPOS64_T pos = 0;
229220
FILE* pFile = FOPEN_FUNC(filename, "rb");
230221
231222
if(pFile != NULL)
232223
{
233224
FSEEKO_FUNC(pFile, 0, SEEK_END);
234225
pos = (ZPOS64_T)FTELLO_FUNC(pFile);
235226
236
- printf("File : %s is %lld bytes\n", filename, pos);
227
+ printf("File : %s is %llu bytes\n", filename, pos);
237228
238229
if(pos >= 0xffffffff)
239230
largeFile = 1;
240231
241232
fclose(pFile);
@@ -242,14 +233,11 @@
242233
}
243234
244235
return largeFile;
245236
}
246237
247
-int main(argc,argv)
248
- int argc;
249
- char *argv[];
250
-{
238
+int main(int argc, char *argv[]) {
251239
int i;
252240
int opt_overwrite=0;
253241
int opt_compress_level=Z_DEFAULT_COMPRESSION;
254242
int opt_exclude_path=0;
255243
int zipfilenamearg = 0;
@@ -321,11 +309,11 @@
321309
int i,len;
322310
int dot_found=0;
323311
324312
zipok = 1 ;
325313
strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
326
- /* strncpy doesnt append the trailing NULL, of the string is too long. */
314
+ /* strncpy doesn't append the trailing NULL, of the string is too long. */
327315
filename_try[ MAXFILENAME ] = '\0';
328316
329317
len=(int)strlen(filename_try);
330318
for (i=0;i<len;i++)
331319
if (filename_try[i]=='.')
@@ -391,14 +379,14 @@
391379
{
392380
if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) &&
393381
((argv[i][1]=='o') || (argv[i][1]=='O') ||
394382
(argv[i][1]=='a') || (argv[i][1]=='A') ||
395383
(argv[i][1]=='p') || (argv[i][1]=='P') ||
396
- ((argv[i][1]>='0') || (argv[i][1]<='9'))) &&
384
+ ((argv[i][1]>='0') && (argv[i][1]<='9'))) &&
397385
(strlen(argv[i]) == 2)))
398386
{
399
- FILE * fin;
387
+ FILE * fin = NULL;
400388
size_t size_read;
401389
const char* filenameinzip = argv[i];
402390
const char *savefilenameinzip;
403391
zip_fileinfo zi;
404392
unsigned long crcFile=0;
405393
--- compat/zlib/contrib/minizip/minizip.c
+++ compat/zlib/contrib/minizip/minizip.c
@@ -26,11 +26,11 @@
26 #ifndef _FILE_OFFSET_BIT
27 #define _FILE_OFFSET_BIT 64
28 #endif
29 #endif
30
31 #ifdef __APPLE__
32 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
33 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
34 #define FTELLO_FUNC(stream) ftello(stream)
35 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
36 #else
@@ -69,15 +69,13 @@
69
70 #define WRITEBUFFERSIZE (16384)
71 #define MAXFILENAME (256)
72
73 #ifdef _WIN32
74 static int filetime(f, tmzip, dt)
75 const char *f; /* name of file to get info on */
76 tm_zip *tmzip; /* return value: access, modific. and creation times */
77 uLong *dt; /* dostime */
78 {
79 int ret = 0;
80 {
81 FILETIME ftLocal;
82 HANDLE hFind;
83 WIN32_FIND_DATAA ff32;
@@ -93,15 +91,13 @@
93 }
94 return ret;
95 }
96 #else
97 #if defined(unix) || defined(__APPLE__)
98 static int filetime(f, tmzip, dt)
99 const char *f; /* name of file to get info on */
100 tm_zip *tmzip; /* return value: access, modific. and creation times */
101 uLong *dt; /* dostime */
102 {
103 (void)dt;
104 int ret=0;
105 struct stat s; /* results of stat() */
106 struct tm* filedate;
107 time_t tm_t=0;
@@ -112,11 +108,11 @@
112 size_t len = strlen(f);
113 if (len > MAXFILENAME)
114 len = MAXFILENAME;
115
116 strncpy(name, f,MAXFILENAME-1);
117 /* strncpy doesnt append the trailing NULL, of the string is too long. */
118 name[ MAXFILENAME ] = '\0';
119
120 if (name[len - 1] == '/')
121 name[len - 1] = '\0';
122 /* not all systems allow stat'ing a file with / appended */
@@ -136,26 +132,25 @@
136 tmzip->tm_year = filedate->tm_year;
137
138 return ret;
139 }
140 #else
141 uLong filetime(f, tmzip, dt)
142 const char *f; /* name of file to get info on */
143 tm_zip *tmzip; /* return value: access, modific. and creation times */
144 uLong *dt; /* dostime */
145 {
 
146 return 0;
147 }
148 #endif
149 #endif
150
151
152
153
154 static int check_exist_file(filename)
155 const char* filename;
156 {
157 FILE* ftestexist;
158 int ret = 1;
159 ftestexist = FOPEN_FUNC(filename,"rb");
160 if (ftestexist==NULL)
161 ret = 0;
@@ -162,18 +157,16 @@
162 else
163 fclose(ftestexist);
164 return ret;
165 }
166
167 static void do_banner()
168 {
169 printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
170 printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
171 }
172
173 static void do_help()
174 {
175 printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
176 " -o Overwrite existing file.zip\n" \
177 " -a Append to existing file.zip\n" \
178 " -0 Store only\n" \
179 " -1 Compress faster\n" \
@@ -181,12 +174,11 @@
181 " -j exclude path. store only the file name.\n\n");
182 }
183
184 /* calculate the CRC32 of a file,
185 because to encrypt a file, we need known the CRC32 of the file before */
186 static int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)
187 {
188 unsigned long calculate_crc=0;
189 int err=ZIP_OK;
190 FILE * fin = FOPEN_FUNC(filenameinzip,"rb");
191
192 unsigned long size_read = 0;
@@ -220,22 +212,21 @@
220 *result_crc=calculate_crc;
221 printf("file %s crc %lx\n", filenameinzip, calculate_crc);
222 return err;
223 }
224
225 static int isLargeFile(const char* filename)
226 {
227 int largeFile = 0;
228 ZPOS64_T pos = 0;
229 FILE* pFile = FOPEN_FUNC(filename, "rb");
230
231 if(pFile != NULL)
232 {
233 FSEEKO_FUNC(pFile, 0, SEEK_END);
234 pos = (ZPOS64_T)FTELLO_FUNC(pFile);
235
236 printf("File : %s is %lld bytes\n", filename, pos);
237
238 if(pos >= 0xffffffff)
239 largeFile = 1;
240
241 fclose(pFile);
@@ -242,14 +233,11 @@
242 }
243
244 return largeFile;
245 }
246
247 int main(argc,argv)
248 int argc;
249 char *argv[];
250 {
251 int i;
252 int opt_overwrite=0;
253 int opt_compress_level=Z_DEFAULT_COMPRESSION;
254 int opt_exclude_path=0;
255 int zipfilenamearg = 0;
@@ -321,11 +309,11 @@
321 int i,len;
322 int dot_found=0;
323
324 zipok = 1 ;
325 strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
326 /* strncpy doesnt append the trailing NULL, of the string is too long. */
327 filename_try[ MAXFILENAME ] = '\0';
328
329 len=(int)strlen(filename_try);
330 for (i=0;i<len;i++)
331 if (filename_try[i]=='.')
@@ -391,14 +379,14 @@
391 {
392 if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) &&
393 ((argv[i][1]=='o') || (argv[i][1]=='O') ||
394 (argv[i][1]=='a') || (argv[i][1]=='A') ||
395 (argv[i][1]=='p') || (argv[i][1]=='P') ||
396 ((argv[i][1]>='0') || (argv[i][1]<='9'))) &&
397 (strlen(argv[i]) == 2)))
398 {
399 FILE * fin;
400 size_t size_read;
401 const char* filenameinzip = argv[i];
402 const char *savefilenameinzip;
403 zip_fileinfo zi;
404 unsigned long crcFile=0;
405
--- compat/zlib/contrib/minizip/minizip.c
+++ compat/zlib/contrib/minizip/minizip.c
@@ -26,11 +26,11 @@
26 #ifndef _FILE_OFFSET_BIT
27 #define _FILE_OFFSET_BIT 64
28 #endif
29 #endif
30
31 #if defined(__APPLE__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
32 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
33 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
34 #define FTELLO_FUNC(stream) ftello(stream)
35 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
36 #else
@@ -69,15 +69,13 @@
69
70 #define WRITEBUFFERSIZE (16384)
71 #define MAXFILENAME (256)
72
73 #ifdef _WIN32
74 /* f: name of file to get info on, tmzip: return value: access,
75 modification and creation times, dt: dostime */
76 static int filetime(const char *f, tm_zip *tmzip, uLong *dt) {
 
 
77 int ret = 0;
78 {
79 FILETIME ftLocal;
80 HANDLE hFind;
81 WIN32_FIND_DATAA ff32;
@@ -93,15 +91,13 @@
91 }
92 return ret;
93 }
94 #else
95 #if defined(unix) || defined(__APPLE__)
96 /* f: name of file to get info on, tmzip: return value: access,
97 modification and creation times, dt: dostime */
98 static int filetime(const char *f, tm_zip *tmzip, uLong *dt) {
 
 
99 (void)dt;
100 int ret=0;
101 struct stat s; /* results of stat() */
102 struct tm* filedate;
103 time_t tm_t=0;
@@ -112,11 +108,11 @@
108 size_t len = strlen(f);
109 if (len > MAXFILENAME)
110 len = MAXFILENAME;
111
112 strncpy(name, f,MAXFILENAME-1);
113 /* strncpy doesn't append the trailing NULL, of the string is too long. */
114 name[ MAXFILENAME ] = '\0';
115
116 if (name[len - 1] == '/')
117 name[len - 1] = '\0';
118 /* not all systems allow stat'ing a file with / appended */
@@ -136,26 +132,25 @@
132 tmzip->tm_year = filedate->tm_year;
133
134 return ret;
135 }
136 #else
137 /* f: name of file to get info on, tmzip: return value: access,
138 modification and creation times, dt: dostime */
139 static int filetime(const char *f, tm_zip *tmzip, uLong *dt) {
140 (void)f;
141 (void)tmzip;
142 (void)dt;
143 return 0;
144 }
145 #endif
146 #endif
147
148
149
150
151 static int check_exist_file(const char* filename) {
 
 
152 FILE* ftestexist;
153 int ret = 1;
154 ftestexist = FOPEN_FUNC(filename,"rb");
155 if (ftestexist==NULL)
156 ret = 0;
@@ -162,18 +157,16 @@
157 else
158 fclose(ftestexist);
159 return ret;
160 }
161
162 static void do_banner(void) {
 
163 printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
164 printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
165 }
166
167 static void do_help(void) {
 
168 printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
169 " -o Overwrite existing file.zip\n" \
170 " -a Append to existing file.zip\n" \
171 " -0 Store only\n" \
172 " -1 Compress faster\n" \
@@ -181,12 +174,11 @@
174 " -j exclude path. store only the file name.\n\n");
175 }
176
177 /* calculate the CRC32 of a file,
178 because to encrypt a file, we need known the CRC32 of the file before */
179 static int getFileCrc(const char* filenameinzip, void* buf, unsigned long size_buf, unsigned long* result_crc) {
 
180 unsigned long calculate_crc=0;
181 int err=ZIP_OK;
182 FILE * fin = FOPEN_FUNC(filenameinzip,"rb");
183
184 unsigned long size_read = 0;
@@ -220,22 +212,21 @@
212 *result_crc=calculate_crc;
213 printf("file %s crc %lx\n", filenameinzip, calculate_crc);
214 return err;
215 }
216
217 static int isLargeFile(const char* filename) {
 
218 int largeFile = 0;
219 ZPOS64_T pos = 0;
220 FILE* pFile = FOPEN_FUNC(filename, "rb");
221
222 if(pFile != NULL)
223 {
224 FSEEKO_FUNC(pFile, 0, SEEK_END);
225 pos = (ZPOS64_T)FTELLO_FUNC(pFile);
226
227 printf("File : %s is %llu bytes\n", filename, pos);
228
229 if(pos >= 0xffffffff)
230 largeFile = 1;
231
232 fclose(pFile);
@@ -242,14 +233,11 @@
233 }
234
235 return largeFile;
236 }
237
238 int main(int argc, char *argv[]) {
 
 
 
239 int i;
240 int opt_overwrite=0;
241 int opt_compress_level=Z_DEFAULT_COMPRESSION;
242 int opt_exclude_path=0;
243 int zipfilenamearg = 0;
@@ -321,11 +309,11 @@
309 int i,len;
310 int dot_found=0;
311
312 zipok = 1 ;
313 strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
314 /* strncpy doesn't append the trailing NULL, of the string is too long. */
315 filename_try[ MAXFILENAME ] = '\0';
316
317 len=(int)strlen(filename_try);
318 for (i=0;i<len;i++)
319 if (filename_try[i]=='.')
@@ -391,14 +379,14 @@
379 {
380 if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) &&
381 ((argv[i][1]=='o') || (argv[i][1]=='O') ||
382 (argv[i][1]=='a') || (argv[i][1]=='A') ||
383 (argv[i][1]=='p') || (argv[i][1]=='P') ||
384 ((argv[i][1]>='0') && (argv[i][1]<='9'))) &&
385 (strlen(argv[i]) == 2)))
386 {
387 FILE * fin = NULL;
388 size_t size_read;
389 const char* filenameinzip = argv[i];
390 const char *savefilenameinzip;
391 zip_fileinfo zi;
392 unsigned long crcFile=0;
393
--- compat/zlib/contrib/minizip/mztools.c
+++ compat/zlib/contrib/minizip/mztools.c
@@ -25,17 +25,11 @@
2525
#define WRITE_32(buff, n) do { \
2626
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
2727
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
2828
} while(0)
2929
30
-extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
31
-const char* file;
32
-const char* fileOut;
33
-const char* fileOutTmp;
34
-uLong* nRecovered;
35
-uLong* bytesRecovered;
36
-{
30
+extern int ZEXPORT unzRepair(const char* file, const char* fileOut, const char* fileOutTmp, uLong* nRecovered, uLong* bytesRecovered) {
3731
int err = Z_OK;
3832
FILE* fpZip = fopen(file, "rb");
3933
FILE* fpOut = fopen(fileOut, "wb");
4034
FILE* fpOutCD = fopen(fileOutTmp, "wb");
4135
if (fpZip != NULL && fpOut != NULL) {
4236
--- compat/zlib/contrib/minizip/mztools.c
+++ compat/zlib/contrib/minizip/mztools.c
@@ -25,17 +25,11 @@
25 #define WRITE_32(buff, n) do { \
26 WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
27 WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
28 } while(0)
29
30 extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
31 const char* file;
32 const char* fileOut;
33 const char* fileOutTmp;
34 uLong* nRecovered;
35 uLong* bytesRecovered;
36 {
37 int err = Z_OK;
38 FILE* fpZip = fopen(file, "rb");
39 FILE* fpOut = fopen(fileOut, "wb");
40 FILE* fpOutCD = fopen(fileOutTmp, "wb");
41 if (fpZip != NULL && fpOut != NULL) {
42
--- compat/zlib/contrib/minizip/mztools.c
+++ compat/zlib/contrib/minizip/mztools.c
@@ -25,17 +25,11 @@
25 #define WRITE_32(buff, n) do { \
26 WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
27 WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
28 } while(0)
29
30 extern int ZEXPORT unzRepair(const char* file, const char* fileOut, const char* fileOutTmp, uLong* nRecovered, uLong* bytesRecovered) {
 
 
 
 
 
 
31 int err = Z_OK;
32 FILE* fpZip = fopen(file, "rb");
33 FILE* fpOut = fopen(fileOut, "wb");
34 FILE* fpOutCD = fopen(fileOutTmp, "wb");
35 if (fpZip != NULL && fpOut != NULL) {
36
--- compat/zlib/contrib/minizip/unzip.c
+++ compat/zlib/contrib/minizip/unzip.c
@@ -47,16 +47,16 @@
4747
2007-2008 - Even Rouault - Add unzip support for ZIP64
4848
4949
Copyright (C) 2007-2008 Even Rouault
5050
5151
52
- Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again).
52
+ Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again).
5353
Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
5454
should only read the compressed/uncompressed size from the Zip64 format if
5555
the size from normal header was 0xFFFFFFFF
56
- Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
57
- Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
56
+ Oct-2009 - Mathias Svensson - Applied some bug fixes from patches received from Gilles Vollant
57
+ Oct-2009 - Mathias Svensson - Applied support to unzip files with compression method BZIP2 (bzip2 lib is required)
5858
Patch created by Daniel Borca
5959
6060
Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
6161
6262
Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
@@ -75,12 +75,10 @@
7575
#include "zlib.h"
7676
#include "unzip.h"
7777
7878
#ifdef STDC
7979
# include <stddef.h>
80
-# include <string.h>
81
-# include <stdlib.h>
8280
#endif
8381
#ifdef NO_ERRNO_H
8482
extern int errno;
8583
#else
8684
# include <errno.h>
@@ -109,13 +107,10 @@
109107
#endif
110108
111109
#ifndef ALLOC
112110
# define ALLOC(size) (malloc(size))
113111
#endif
114
-#ifndef TRYFREE
115
-# define TRYFREE(p) { free(p);}
116
-#endif
117112
118113
#define SIZECENTRALDIRITEM (0x2e)
119114
#define SIZEZIPLOCALHEADER (0x1e)
120115
121116
@@ -151,11 +146,11 @@
151146
uLong crc32; /* crc32 of all data uncompressed */
152147
uLong crc32_wait; /* crc32 we must obtain after decompress all */
153148
ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
154149
ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
155150
zlib_filefunc64_32_def z_filefunc;
156
- voidpf filestream; /* io structore of the zipfile */
151
+ voidpf filestream; /* io structure of the zipfile */
157152
uLong compression_method; /* compression method (0==store) */
158153
ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
159154
int raw;
160155
} file_in_zip64_read_info_s;
161156
@@ -164,11 +159,11 @@
164159
*/
165160
typedef struct
166161
{
167162
zlib_filefunc64_32_def z_filefunc;
168163
int is64bitOpenFunction;
169
- voidpf filestream; /* io structore of the zipfile */
164
+ voidpf filestream; /* io structure of the zipfile */
170165
unz_global_info64 gi; /* public global information */
171166
ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
172167
ZPOS64_T num_file; /* number of the current file in the zipfile*/
173168
ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/
174169
ZPOS64_T current_file_ok; /* flag about the usability of the current file*/
@@ -194,162 +189,80 @@
194189
195190
196191
#ifndef NOUNCRYPT
197192
#include "crypt.h"
198193
#endif
194
+
199195
200196
/* ===========================================================================
201
- Read a byte from a gz_stream; update next_in and avail_in. Return EOF
202
- for end of file.
203
- IN assertion: the stream s has been successfully opened for reading.
197
+ Reads a long in LSB order from the given gz_stream. Sets
204198
*/
205199
206
-
207
-local int unz64local_getByte OF((
208
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
209
- voidpf filestream,
210
- int *pi));
211
-
212
-local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)
213
-{
214
- unsigned char c;
215
- int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
216
- if (err==1)
217
- {
218
- *pi = (int)c;
200
+local int unz64local_getShort(const zlib_filefunc64_32_def* pzlib_filefunc_def,
201
+ voidpf filestream,
202
+ uLong *pX) {
203
+ unsigned char c[2];
204
+ int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,2);
205
+ if (err==2)
206
+ {
207
+ *pX = c[0] | ((uLong)c[1] << 8);
208
+ return UNZ_OK;
209
+ }
210
+ else
211
+ {
212
+ *pX = 0;
213
+ if (ZERROR64(*pzlib_filefunc_def,filestream))
214
+ return UNZ_ERRNO;
215
+ else
216
+ return UNZ_EOF;
217
+ }
218
+}
219
+
220
+local int unz64local_getLong(const zlib_filefunc64_32_def* pzlib_filefunc_def,
221
+ voidpf filestream,
222
+ uLong *pX) {
223
+ unsigned char c[4];
224
+ int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,4);
225
+ if (err==4)
226
+ {
227
+ *pX = c[0] | ((uLong)c[1] << 8) | ((uLong)c[2] << 16) | ((uLong)c[3] << 24);
228
+ return UNZ_OK;
229
+ }
230
+ else
231
+ {
232
+ *pX = 0;
233
+ if (ZERROR64(*pzlib_filefunc_def,filestream))
234
+ return UNZ_ERRNO;
235
+ else
236
+ return UNZ_EOF;
237
+ }
238
+}
239
+
240
+
241
+local int unz64local_getLong64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
242
+ voidpf filestream,
243
+ ZPOS64_T *pX) {
244
+ unsigned char c[8];
245
+ int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,8);
246
+ if (err==8)
247
+ {
248
+ *pX = c[0] | ((ZPOS64_T)c[1] << 8) | ((ZPOS64_T)c[2] << 16) | ((ZPOS64_T)c[3] << 24)
249
+ | ((ZPOS64_T)c[4] << 32) | ((ZPOS64_T)c[5] << 40) | ((ZPOS64_T)c[6] << 48) | ((ZPOS64_T)c[7] << 56);
219250
return UNZ_OK;
220251
}
221252
else
222253
{
254
+ *pX = 0;
223255
if (ZERROR64(*pzlib_filefunc_def,filestream))
224256
return UNZ_ERRNO;
225257
else
226258
return UNZ_EOF;
227259
}
228260
}
229261
230
-
231
-/* ===========================================================================
232
- Reads a long in LSB order from the given gz_stream. Sets
233
-*/
234
-local int unz64local_getShort OF((
235
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
236
- voidpf filestream,
237
- uLong *pX));
238
-
239
-local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
240
- voidpf filestream,
241
- uLong *pX)
242
-{
243
- uLong x ;
244
- int i = 0;
245
- int err;
246
-
247
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
248
- x = (uLong)i;
249
-
250
- if (err==UNZ_OK)
251
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
252
- x |= ((uLong)i)<<8;
253
-
254
- if (err==UNZ_OK)
255
- *pX = x;
256
- else
257
- *pX = 0;
258
- return err;
259
-}
260
-
261
-local int unz64local_getLong OF((
262
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
263
- voidpf filestream,
264
- uLong *pX));
265
-
266
-local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
267
- voidpf filestream,
268
- uLong *pX)
269
-{
270
- uLong x ;
271
- int i = 0;
272
- int err;
273
-
274
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
275
- x = (uLong)i;
276
-
277
- if (err==UNZ_OK)
278
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
279
- x |= ((uLong)i)<<8;
280
-
281
- if (err==UNZ_OK)
282
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
283
- x |= ((uLong)i)<<16;
284
-
285
- if (err==UNZ_OK)
286
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
287
- x += ((uLong)i)<<24;
288
-
289
- if (err==UNZ_OK)
290
- *pX = x;
291
- else
292
- *pX = 0;
293
- return err;
294
-}
295
-
296
-local int unz64local_getLong64 OF((
297
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
298
- voidpf filestream,
299
- ZPOS64_T *pX));
300
-
301
-
302
-local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
303
- voidpf filestream,
304
- ZPOS64_T *pX)
305
-{
306
- ZPOS64_T x ;
307
- int i = 0;
308
- int err;
309
-
310
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
311
- x = (ZPOS64_T)i;
312
-
313
- if (err==UNZ_OK)
314
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
315
- x |= ((ZPOS64_T)i)<<8;
316
-
317
- if (err==UNZ_OK)
318
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
319
- x |= ((ZPOS64_T)i)<<16;
320
-
321
- if (err==UNZ_OK)
322
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
323
- x |= ((ZPOS64_T)i)<<24;
324
-
325
- if (err==UNZ_OK)
326
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
327
- x |= ((ZPOS64_T)i)<<32;
328
-
329
- if (err==UNZ_OK)
330
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
331
- x |= ((ZPOS64_T)i)<<40;
332
-
333
- if (err==UNZ_OK)
334
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
335
- x |= ((ZPOS64_T)i)<<48;
336
-
337
- if (err==UNZ_OK)
338
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
339
- x |= ((ZPOS64_T)i)<<56;
340
-
341
- if (err==UNZ_OK)
342
- *pX = x;
343
- else
344
- *pX = 0;
345
- return err;
346
-}
347
-
348262
/* My own strcmpi / strcasecmp */
349
-local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
350
-{
263
+local int strcmpcasenosensitive_internal(const char* fileName1, const char* fileName2) {
351264
for (;;)
352265
{
353266
char c1=*(fileName1++);
354267
char c2=*(fileName2++);
355268
if ((c1>='a') && (c1<='z'))
@@ -377,23 +290,21 @@
377290
#ifndef STRCMPCASENOSENTIVEFUNCTION
378291
#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
379292
#endif
380293
381294
/*
382
- Compare two filename (fileName1,fileName2).
383
- If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
384
- If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
295
+ Compare two filenames (fileName1,fileName2).
296
+ If iCaseSensitivity = 1, comparison is case sensitive (like strcmp)
297
+ If iCaseSensitivity = 2, comparison is not case sensitive (like strcmpi
385298
or strcasecmp)
386
- If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
299
+ If iCaseSensitivity = 0, case sensitivity is default of your operating system
387300
(like 1 on Unix, 2 on Windows)
388301
389302
*/
390303
extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
391
- const char* fileName2,
392
- int iCaseSensitivity)
393
-
394
-{
304
+ const char* fileName2,
305
+ int iCaseSensitivity) {
395306
if (iCaseSensitivity==0)
396307
iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
397308
398309
if (iCaseSensitivity==1)
399310
return strcmp(fileName1,fileName2);
@@ -403,35 +314,37 @@
403314
404315
#ifndef BUFREADCOMMENT
405316
#define BUFREADCOMMENT (0x400)
406317
#endif
407318
319
+#ifndef CENTRALDIRINVALID
320
+#define CENTRALDIRINVALID ((ZPOS64_T)(-1))
321
+#endif
322
+
408323
/*
409324
Locate the Central directory of a zipfile (at the end, just before
410325
the global comment)
411326
*/
412
-local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
413
-local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
414
-{
327
+local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) {
415328
unsigned char* buf;
416329
ZPOS64_T uSizeFile;
417330
ZPOS64_T uBackRead;
418331
ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
419
- ZPOS64_T uPosFound=0;
332
+ ZPOS64_T uPosFound=CENTRALDIRINVALID;
420333
421334
if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
422
- return 0;
335
+ return CENTRALDIRINVALID;
423336
424337
425338
uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
426339
427340
if (uMaxBack>uSizeFile)
428341
uMaxBack = uSizeFile;
429342
430343
buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
431344
if (buf==NULL)
432
- return 0;
345
+ return CENTRALDIRINVALID;
433346
434347
uBackRead = 4;
435348
while (uBackRead<uMaxBack)
436349
{
437350
uLong uReadSize;
@@ -457,49 +370,44 @@
457370
{
458371
uPosFound = uReadPos+(unsigned)i;
459372
break;
460373
}
461374
462
- if (uPosFound!=0)
375
+ if (uPosFound!=CENTRALDIRINVALID)
463376
break;
464377
}
465
- TRYFREE(buf);
378
+ free(buf);
466379
return uPosFound;
467380
}
468381
469382
470383
/*
471384
Locate the Central directory 64 of a zipfile (at the end, just before
472385
the global comment)
473386
*/
474
-local ZPOS64_T unz64local_SearchCentralDir64 OF((
475
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
476
- voidpf filestream));
477
-
478387
local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
479
- voidpf filestream)
480
-{
388
+ voidpf filestream) {
481389
unsigned char* buf;
482390
ZPOS64_T uSizeFile;
483391
ZPOS64_T uBackRead;
484392
ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
485
- ZPOS64_T uPosFound=0;
393
+ ZPOS64_T uPosFound=CENTRALDIRINVALID;
486394
uLong uL;
487395
ZPOS64_T relativeOffset;
488396
489397
if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
490
- return 0;
398
+ return CENTRALDIRINVALID;
491399
492400
493401
uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
494402
495403
if (uMaxBack>uSizeFile)
496404
uMaxBack = uSizeFile;
497405
498406
buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
499407
if (buf==NULL)
500
- return 0;
408
+ return CENTRALDIRINVALID;
501409
502410
uBackRead = 4;
503411
while (uBackRead<uMaxBack)
504412
{
505413
uLong uReadSize;
@@ -525,51 +433,51 @@
525433
{
526434
uPosFound = uReadPos+(unsigned)i;
527435
break;
528436
}
529437
530
- if (uPosFound!=0)
438
+ if (uPosFound!=CENTRALDIRINVALID)
531439
break;
532440
}
533
- TRYFREE(buf);
534
- if (uPosFound == 0)
535
- return 0;
441
+ free(buf);
442
+ if (uPosFound == CENTRALDIRINVALID)
443
+ return CENTRALDIRINVALID;
536444
537445
/* Zip64 end of central directory locator */
538446
if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
539
- return 0;
447
+ return CENTRALDIRINVALID;
540448
541449
/* the signature, already checked */
542450
if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
543
- return 0;
451
+ return CENTRALDIRINVALID;
544452
545453
/* number of the disk with the start of the zip64 end of central directory */
546454
if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
547
- return 0;
455
+ return CENTRALDIRINVALID;
548456
if (uL != 0)
549
- return 0;
457
+ return CENTRALDIRINVALID;
550458
551459
/* relative offset of the zip64 end of central directory record */
552460
if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
553
- return 0;
461
+ return CENTRALDIRINVALID;
554462
555463
/* total number of disks */
556464
if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
557
- return 0;
465
+ return CENTRALDIRINVALID;
558466
if (uL != 1)
559
- return 0;
467
+ return CENTRALDIRINVALID;
560468
561469
/* Goto end of central directory record */
562470
if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
563
- return 0;
471
+ return CENTRALDIRINVALID;
564472
565473
/* the signature */
566474
if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
567
- return 0;
475
+ return CENTRALDIRINVALID;
568476
569477
if (uL != 0x06064b50)
570
- return 0;
478
+ return CENTRALDIRINVALID;
571479
572480
return relativeOffset;
573481
}
574482
575483
/*
@@ -579,23 +487,22 @@
579487
If the zipfile cannot be opened (file doesn't exist or in not valid), the
580488
return value is NULL.
581489
Else, the return value is a unzFile Handle, usable with other function
582490
of this unzip package.
583491
*/
584
-local unzFile unzOpenInternal (const void *path,
585
- zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
586
- int is64bitOpenFunction)
587
-{
492
+local unzFile unzOpenInternal(const void *path,
493
+ zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
494
+ int is64bitOpenFunction) {
588495
unz64_s us;
589496
unz64_s *s;
590497
ZPOS64_T central_pos;
591498
uLong uL;
592499
593500
uLong number_disk; /* number of the current dist, used for
594
- spaning ZIP, unsupported, always 0*/
501
+ spanning ZIP, unsupported, always 0*/
595502
uLong number_disk_with_CD; /* number the the disk with central dir, used
596
- for spaning ZIP, unsupported, always 0*/
503
+ for spanning ZIP, unsupported, always 0*/
597504
ZPOS64_T number_entry_CD; /* total number of entries in
598505
the central dir
599506
(same than number_entry on nospan) */
600507
601508
int err=UNZ_OK;
@@ -619,11 +526,11 @@
619526
ZLIB_FILEFUNC_MODE_EXISTING);
620527
if (us.filestream==NULL)
621528
return NULL;
622529
623530
central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
624
- if (central_pos)
531
+ if (central_pos!=CENTRALDIRINVALID)
625532
{
626533
uLong uS;
627534
ZPOS64_T uL64;
628535
629536
us.isZip64 = 1;
@@ -681,11 +588,11 @@
681588
us.gi.size_comment = 0;
682589
}
683590
else
684591
{
685592
central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
686
- if (central_pos==0)
593
+ if (central_pos==CENTRALDIRINVALID)
687594
err=UNZ_ERRNO;
688595
689596
us.isZip64 = 0;
690597
691598
if (ZSEEK64(us.z_filefunc, us.filestream,
@@ -760,13 +667,12 @@
760667
}
761668
return (unzFile)s;
762669
}
763670
764671
765
-extern unzFile ZEXPORT unzOpen2 (const char *path,
766
- zlib_filefunc_def* pzlib_filefunc32_def)
767
-{
672
+extern unzFile ZEXPORT unzOpen2(const char *path,
673
+ zlib_filefunc_def* pzlib_filefunc32_def) {
768674
if (pzlib_filefunc32_def != NULL)
769675
{
770676
zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
771677
fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
772678
return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
@@ -773,13 +679,12 @@
773679
}
774680
else
775681
return unzOpenInternal(path, NULL, 0);
776682
}
777683
778
-extern unzFile ZEXPORT unzOpen2_64 (const void *path,
779
- zlib_filefunc64_def* pzlib_filefunc_def)
780
-{
684
+extern unzFile ZEXPORT unzOpen2_64(const void *path,
685
+ zlib_filefunc64_def* pzlib_filefunc_def) {
781686
if (pzlib_filefunc_def != NULL)
782687
{
783688
zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
784689
zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
785690
zlib_filefunc64_32_def_fill.ztell32_file = NULL;
@@ -788,57 +693,52 @@
788693
}
789694
else
790695
return unzOpenInternal(path, NULL, 1);
791696
}
792697
793
-extern unzFile ZEXPORT unzOpen (const char *path)
794
-{
698
+extern unzFile ZEXPORT unzOpen(const char *path) {
795699
return unzOpenInternal(path, NULL, 0);
796700
}
797701
798
-extern unzFile ZEXPORT unzOpen64 (const void *path)
799
-{
702
+extern unzFile ZEXPORT unzOpen64(const void *path) {
800703
return unzOpenInternal(path, NULL, 1);
801704
}
802705
803706
/*
804707
Close a ZipFile opened with unzOpen.
805708
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
806709
these files MUST be closed with unzCloseCurrentFile before call unzClose.
807710
return UNZ_OK if there is no problem. */
808
-extern int ZEXPORT unzClose (unzFile file)
809
-{
711
+extern int ZEXPORT unzClose(unzFile file) {
810712
unz64_s* s;
811713
if (file==NULL)
812714
return UNZ_PARAMERROR;
813715
s=(unz64_s*)file;
814716
815717
if (s->pfile_in_zip_read!=NULL)
816718
unzCloseCurrentFile(file);
817719
818720
ZCLOSE64(s->z_filefunc, s->filestream);
819
- TRYFREE(s);
721
+ free(s);
820722
return UNZ_OK;
821723
}
822724
823725
824726
/*
825727
Write info about the ZipFile in the *pglobal_info structure.
826728
No preparation of the structure is needed
827729
return UNZ_OK if there is no problem. */
828
-extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
829
-{
730
+extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64* pglobal_info) {
830731
unz64_s* s;
831732
if (file==NULL)
832733
return UNZ_PARAMERROR;
833734
s=(unz64_s*)file;
834735
*pglobal_info=s->gi;
835736
return UNZ_OK;
836737
}
837738
838
-extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
839
-{
739
+extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32) {
840740
unz64_s* s;
841741
if (file==NULL)
842742
return UNZ_PARAMERROR;
843743
s=(unz64_s*)file;
844744
/* to do : check if number_entry is not truncated */
@@ -845,14 +745,13 @@
845745
pglobal_info32->number_entry = (uLong)s->gi.number_entry;
846746
pglobal_info32->size_comment = s->gi.size_comment;
847747
return UNZ_OK;
848748
}
849749
/*
850
- Translate date/time from Dos format to tm_unz (readable more easilty)
750
+ Translate date/time from Dos format to tm_unz (readable more easily)
851751
*/
852
-local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
853
-{
752
+local void unz64local_DosDateToTmuDate(ZPOS64_T ulDosDate, tm_unz* ptm) {
854753
ZPOS64_T uDate;
855754
uDate = (ZPOS64_T)(ulDosDate>>16);
856755
ptm->tm_mday = (int)(uDate&0x1f) ;
857756
ptm->tm_mon = (int)((((uDate)&0x1E0)/0x20)-1) ;
858757
ptm->tm_year = (int)(((uDate&0x0FE00)/0x0200)+1980) ;
@@ -863,32 +762,20 @@
863762
}
864763
865764
/*
866765
Get Info about the current file in the zipfile, with internal only info
867766
*/
868
-local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
869
- unz_file_info64 *pfile_info,
870
- unz_file_info64_internal
871
- *pfile_info_internal,
872
- char *szFileName,
873
- uLong fileNameBufferSize,
874
- void *extraField,
875
- uLong extraFieldBufferSize,
876
- char *szComment,
877
- uLong commentBufferSize));
878
-
879
-local int unz64local_GetCurrentFileInfoInternal (unzFile file,
880
- unz_file_info64 *pfile_info,
881
- unz_file_info64_internal
882
- *pfile_info_internal,
883
- char *szFileName,
884
- uLong fileNameBufferSize,
885
- void *extraField,
886
- uLong extraFieldBufferSize,
887
- char *szComment,
888
- uLong commentBufferSize)
889
-{
767
+local int unz64local_GetCurrentFileInfoInternal(unzFile file,
768
+ unz_file_info64 *pfile_info,
769
+ unz_file_info64_internal
770
+ *pfile_info_internal,
771
+ char *szFileName,
772
+ uLong fileNameBufferSize,
773
+ void *extraField,
774
+ uLong extraFieldBufferSize,
775
+ char *szComment,
776
+ uLong commentBufferSize) {
890777
unz64_s* s;
891778
unz_file_info64 file_info;
892779
unz_file_info64_internal file_info_internal;
893780
int err=UNZ_OK;
894781
uLong uMagic;
@@ -1036,37 +923,35 @@
1036923
err=UNZ_ERRNO;
1037924
1038925
/* ZIP64 extra fields */
1039926
if (headerId == 0x0001)
1040927
{
1041
- uLong uL;
1042
-
1043
- if(file_info.uncompressed_size == MAXU32)
1044
- {
1045
- if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
1046
- err=UNZ_ERRNO;
1047
- }
1048
-
1049
- if(file_info.compressed_size == MAXU32)
1050
- {
1051
- if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
1052
- err=UNZ_ERRNO;
1053
- }
1054
-
1055
- if(file_info_internal.offset_curfile == MAXU32)
1056
- {
1057
- /* Relative Header offset */
1058
- if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
1059
- err=UNZ_ERRNO;
1060
- }
1061
-
1062
- if(file_info.disk_num_start == MAXU32)
1063
- {
1064
- /* Disk Start Number */
1065
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
1066
- err=UNZ_ERRNO;
1067
- }
928
+ if(file_info.uncompressed_size == MAXU32)
929
+ {
930
+ if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
931
+ err=UNZ_ERRNO;
932
+ }
933
+
934
+ if(file_info.compressed_size == MAXU32)
935
+ {
936
+ if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
937
+ err=UNZ_ERRNO;
938
+ }
939
+
940
+ if(file_info_internal.offset_curfile == MAXU32)
941
+ {
942
+ /* Relative Header offset */
943
+ if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
944
+ err=UNZ_ERRNO;
945
+ }
946
+
947
+ if(file_info.disk_num_start == 0xffff)
948
+ {
949
+ /* Disk Start Number */
950
+ if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
951
+ err=UNZ_ERRNO;
952
+ }
1068953
1069954
}
1070955
else
1071956
{
1072957
if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
@@ -1119,28 +1004,26 @@
11191004
/*
11201005
Write info about the ZipFile in the *pglobal_info structure.
11211006
No preparation of the structure is needed
11221007
return UNZ_OK if there is no problem.
11231008
*/
1124
-extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
1125
- unz_file_info64 * pfile_info,
1126
- char * szFileName, uLong fileNameBufferSize,
1127
- void *extraField, uLong extraFieldBufferSize,
1128
- char* szComment, uLong commentBufferSize)
1129
-{
1009
+extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file,
1010
+ unz_file_info64 * pfile_info,
1011
+ char * szFileName, uLong fileNameBufferSize,
1012
+ void *extraField, uLong extraFieldBufferSize,
1013
+ char* szComment, uLong commentBufferSize) {
11301014
return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
1131
- szFileName,fileNameBufferSize,
1132
- extraField,extraFieldBufferSize,
1133
- szComment,commentBufferSize);
1015
+ szFileName,fileNameBufferSize,
1016
+ extraField,extraFieldBufferSize,
1017
+ szComment,commentBufferSize);
11341018
}
11351019
1136
-extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
1137
- unz_file_info * pfile_info,
1138
- char * szFileName, uLong fileNameBufferSize,
1139
- void *extraField, uLong extraFieldBufferSize,
1140
- char* szComment, uLong commentBufferSize)
1141
-{
1020
+extern int ZEXPORT unzGetCurrentFileInfo(unzFile file,
1021
+ unz_file_info * pfile_info,
1022
+ char * szFileName, uLong fileNameBufferSize,
1023
+ void *extraField, uLong extraFieldBufferSize,
1024
+ char* szComment, uLong commentBufferSize) {
11421025
int err;
11431026
unz_file_info64 file_info64;
11441027
err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
11451028
szFileName,fileNameBufferSize,
11461029
extraField,extraFieldBufferSize,
@@ -1160,11 +1043,11 @@
11601043
11611044
pfile_info->disk_num_start = file_info64.disk_num_start;
11621045
pfile_info->internal_fa = file_info64.internal_fa;
11631046
pfile_info->external_fa = file_info64.external_fa;
11641047
1165
- pfile_info->tmu_date = file_info64.tmu_date,
1048
+ pfile_info->tmu_date = file_info64.tmu_date;
11661049
11671050
11681051
pfile_info->compressed_size = (uLong)file_info64.compressed_size;
11691052
pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
11701053
@@ -1173,12 +1056,11 @@
11731056
}
11741057
/*
11751058
Set the current file of the zipfile to the first file.
11761059
return UNZ_OK if there is no problem
11771060
*/
1178
-extern int ZEXPORT unzGoToFirstFile (unzFile file)
1179
-{
1061
+extern int ZEXPORT unzGoToFirstFile(unzFile file) {
11801062
int err=UNZ_OK;
11811063
unz64_s* s;
11821064
if (file==NULL)
11831065
return UNZ_PARAMERROR;
11841066
s=(unz64_s*)file;
@@ -1194,12 +1076,11 @@
11941076
/*
11951077
Set the current file of the zipfile to the next file.
11961078
return UNZ_OK if there is no problem
11971079
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
11981080
*/
1199
-extern int ZEXPORT unzGoToNextFile (unzFile file)
1200
-{
1081
+extern int ZEXPORT unzGoToNextFile(unzFile file) {
12011082
unz64_s* s;
12021083
int err;
12031084
12041085
if (file==NULL)
12051086
return UNZ_PARAMERROR;
@@ -1227,12 +1108,11 @@
12271108
12281109
return value :
12291110
UNZ_OK if the file is found. It becomes the current file.
12301111
UNZ_END_OF_LIST_OF_FILE if the file is not found
12311112
*/
1232
-extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
1233
-{
1113
+extern int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity) {
12341114
unz64_s* s;
12351115
int err;
12361116
12371117
/* We remember the 'current' position in the file so that we can jump
12381118
* back there if we fail.
@@ -1303,12 +1183,11 @@
13031183
ZPOS64_T pos_in_zip_directory; // offset in file
13041184
ZPOS64_T num_of_file; // # of file
13051185
} unz_file_pos;
13061186
*/
13071187
1308
-extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos)
1309
-{
1188
+extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) {
13101189
unz64_s* s;
13111190
13121191
if (file==NULL || file_pos==NULL)
13131192
return UNZ_PARAMERROR;
13141193
s=(unz64_s*)file;
@@ -1319,14 +1198,11 @@
13191198
file_pos->num_of_file = s->num_file;
13201199
13211200
return UNZ_OK;
13221201
}
13231202
1324
-extern int ZEXPORT unzGetFilePos(
1325
- unzFile file,
1326
- unz_file_pos* file_pos)
1327
-{
1203
+extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos* file_pos) {
13281204
unz64_file_pos file_pos64;
13291205
int err = unzGetFilePos64(file,&file_pos64);
13301206
if (err==UNZ_OK)
13311207
{
13321208
file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
@@ -1333,12 +1209,11 @@
13331209
file_pos->num_of_file = (uLong)file_pos64.num_of_file;
13341210
}
13351211
return err;
13361212
}
13371213
1338
-extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
1339
-{
1214
+extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) {
13401215
unz64_s* s;
13411216
int err;
13421217
13431218
if (file==NULL || file_pos==NULL)
13441219
return UNZ_PARAMERROR;
@@ -1355,14 +1230,11 @@
13551230
/* return results */
13561231
s->current_file_ok = (err == UNZ_OK);
13571232
return err;
13581233
}
13591234
1360
-extern int ZEXPORT unzGoToFilePos(
1361
- unzFile file,
1362
- unz_file_pos* file_pos)
1363
-{
1235
+extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos* file_pos) {
13641236
unz64_file_pos file_pos64;
13651237
if (file_pos == NULL)
13661238
return UNZ_PARAMERROR;
13671239
13681240
file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
@@ -1380,14 +1252,13 @@
13801252
Check the coherency of the local header and info in the end of central
13811253
directory about this file
13821254
store in *piSizeVar the size of extra info in local header
13831255
(filename and size of extra field data)
13841256
*/
1385
-local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
1386
- ZPOS64_T * poffset_local_extrafield,
1387
- uInt * psize_local_extrafield)
1388
-{
1257
+local int unz64local_CheckCurrentFileCoherencyHeader(unz64_s* s, uInt* piSizeVar,
1258
+ ZPOS64_T * poffset_local_extrafield,
1259
+ uInt * psize_local_extrafield) {
13891260
uLong uMagic,uData,uFlags;
13901261
uLong size_filename;
13911262
uLong size_extra_field;
13921263
int err=UNZ_OK;
13931264
@@ -1467,13 +1338,12 @@
14671338
14681339
/*
14691340
Open for reading data the current file in the zipfile.
14701341
If there is no error and the file is opened, the return value is UNZ_OK.
14711342
*/
1472
-extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
1473
- int* level, int raw, const char* password)
1474
-{
1343
+extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method,
1344
+ int* level, int raw, const char* password) {
14751345
int err=UNZ_OK;
14761346
uInt iSizeVar;
14771347
unz64_s* s;
14781348
file_in_zip64_read_info_s* pfile_in_zip_read_info;
14791349
ZPOS64_T offset_local_extrafield; /* offset of the local extra field */
@@ -1507,11 +1377,11 @@
15071377
pfile_in_zip_read_info->pos_local_extrafield=0;
15081378
pfile_in_zip_read_info->raw=raw;
15091379
15101380
if (pfile_in_zip_read_info->read_buffer==NULL)
15111381
{
1512
- TRYFREE(pfile_in_zip_read_info);
1382
+ free(pfile_in_zip_read_info);
15131383
return UNZ_INTERNALERROR;
15141384
}
15151385
15161386
pfile_in_zip_read_info->stream_initialised=0;
15171387
@@ -1564,12 +1434,12 @@
15641434
err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
15651435
if (err == Z_OK)
15661436
pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
15671437
else
15681438
{
1569
- TRYFREE(pfile_in_zip_read_info->read_buffer);
1570
- TRYFREE(pfile_in_zip_read_info);
1439
+ free(pfile_in_zip_read_info->read_buffer);
1440
+ free(pfile_in_zip_read_info);
15711441
return err;
15721442
}
15731443
#else
15741444
pfile_in_zip_read_info->raw=1;
15751445
#endif
@@ -1585,12 +1455,12 @@
15851455
err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
15861456
if (err == Z_OK)
15871457
pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
15881458
else
15891459
{
1590
- TRYFREE(pfile_in_zip_read_info->read_buffer);
1591
- TRYFREE(pfile_in_zip_read_info);
1460
+ free(pfile_in_zip_read_info->read_buffer);
1461
+ free(pfile_in_zip_read_info);
15921462
return err;
15931463
}
15941464
/* windowBits is passed < 0 to tell that there is no zlib header.
15951465
* Note that in this case inflate *requires* an extra "dummy" byte
15961466
* after the compressed stream in order to complete decompression and
@@ -1638,29 +1508,25 @@
16381508
16391509
16401510
return UNZ_OK;
16411511
}
16421512
1643
-extern int ZEXPORT unzOpenCurrentFile (unzFile file)
1644
-{
1513
+extern int ZEXPORT unzOpenCurrentFile(unzFile file) {
16451514
return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
16461515
}
16471516
1648
-extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password)
1649
-{
1517
+extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char* password) {
16501518
return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
16511519
}
16521520
1653
-extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
1654
-{
1521
+extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int* method, int* level, int raw) {
16551522
return unzOpenCurrentFile3(file, method, level, raw, NULL);
16561523
}
16571524
16581525
/** Addition for GDAL : START */
16591526
1660
-extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
1661
-{
1527
+extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file) {
16621528
unz64_s* s;
16631529
file_in_zip64_read_info_s* pfile_in_zip_read_info;
16641530
s=(unz64_s*)file;
16651531
if (file==NULL)
16661532
return 0; //UNZ_PARAMERROR;
@@ -1676,17 +1542,16 @@
16761542
/*
16771543
Read bytes from the current file.
16781544
buf contain buffer where data must be copied
16791545
len the size of buf.
16801546
1681
- return the number of byte copied if somes bytes are copied
1547
+ return the number of byte copied if some bytes are copied
16821548
return 0 if the end of file was reached
16831549
return <0 with error code if there is an error
16841550
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
16851551
*/
1686
-extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
1687
-{
1552
+extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len) {
16881553
int err=UNZ_OK;
16891554
uInt iRead = 0;
16901555
unz64_s* s;
16911556
file_in_zip64_read_info_s* pfile_in_zip_read_info;
16921557
if (file==NULL)
@@ -1889,12 +1754,11 @@
18891754
18901755
18911756
/*
18921757
Give the current position in uncompressed data
18931758
*/
1894
-extern z_off_t ZEXPORT unztell (unzFile file)
1895
-{
1759
+extern z_off_t ZEXPORT unztell(unzFile file) {
18961760
unz64_s* s;
18971761
file_in_zip64_read_info_s* pfile_in_zip_read_info;
18981762
if (file==NULL)
18991763
return UNZ_PARAMERROR;
19001764
s=(unz64_s*)file;
@@ -1904,12 +1768,11 @@
19041768
return UNZ_PARAMERROR;
19051769
19061770
return (z_off_t)pfile_in_zip_read_info->stream.total_out;
19071771
}
19081772
1909
-extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
1910
-{
1773
+extern ZPOS64_T ZEXPORT unztell64(unzFile file) {
19111774
19121775
unz64_s* s;
19131776
file_in_zip64_read_info_s* pfile_in_zip_read_info;
19141777
if (file==NULL)
19151778
return (ZPOS64_T)-1;
@@ -1924,12 +1787,11 @@
19241787
19251788
19261789
/*
19271790
return 1 if the end of file was reached, 0 elsewhere
19281791
*/
1929
-extern int ZEXPORT unzeof (unzFile file)
1930
-{
1792
+extern int ZEXPORT unzeof(unzFile file) {
19311793
unz64_s* s;
19321794
file_in_zip64_read_info_s* pfile_in_zip_read_info;
19331795
if (file==NULL)
19341796
return UNZ_PARAMERROR;
19351797
s=(unz64_s*)file;
@@ -1956,12 +1818,11 @@
19561818
if buf!=NULL, len is the size of the buffer, the extra header is copied in
19571819
buf.
19581820
the return value is the number of bytes copied in buf, or (if <0)
19591821
the error code
19601822
*/
1961
-extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
1962
-{
1823
+extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len) {
19631824
unz64_s* s;
19641825
file_in_zip64_read_info_s* pfile_in_zip_read_info;
19651826
uInt read_now;
19661827
ZPOS64_T size_to_read;
19671828
@@ -2004,12 +1865,11 @@
20041865
20051866
/*
20061867
Close the file in zip opened with unzOpenCurrentFile
20071868
Return UNZ_CRCERROR if all the file was read but the CRC is not good
20081869
*/
2009
-extern int ZEXPORT unzCloseCurrentFile (unzFile file)
2010
-{
1870
+extern int ZEXPORT unzCloseCurrentFile(unzFile file) {
20111871
int err=UNZ_OK;
20121872
20131873
unz64_s* s;
20141874
file_in_zip64_read_info_s* pfile_in_zip_read_info;
20151875
if (file==NULL)
@@ -2027,11 +1887,11 @@
20271887
if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
20281888
err=UNZ_CRCERROR;
20291889
}
20301890
20311891
2032
- TRYFREE(pfile_in_zip_read_info->read_buffer);
1892
+ free(pfile_in_zip_read_info->read_buffer);
20331893
pfile_in_zip_read_info->read_buffer = NULL;
20341894
if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
20351895
inflateEnd(&pfile_in_zip_read_info->stream);
20361896
#ifdef HAVE_BZIP2
20371897
else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
@@ -2038,11 +1898,11 @@
20381898
BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
20391899
#endif
20401900
20411901
20421902
pfile_in_zip_read_info->stream_initialised = 0;
2043
- TRYFREE(pfile_in_zip_read_info);
1903
+ free(pfile_in_zip_read_info);
20441904
20451905
s->pfile_in_zip_read=NULL;
20461906
20471907
return err;
20481908
}
@@ -2051,12 +1911,11 @@
20511911
/*
20521912
Get the global comment string of the ZipFile, in the szComment buffer.
20531913
uSizeBuf is the size of the szComment buffer.
20541914
return the number of byte copied or an error code <0
20551915
*/
2056
-extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
2057
-{
1916
+extern int ZEXPORT unzGetGlobalComment(unzFile file, char * szComment, uLong uSizeBuf) {
20581917
unz64_s* s;
20591918
uLong uReadThis ;
20601919
if (file==NULL)
20611920
return (int)UNZ_PARAMERROR;
20621921
s=(unz64_s*)file;
@@ -2079,12 +1938,11 @@
20791938
*(szComment+s->gi.size_comment)='\0';
20801939
return (int)uReadThis;
20811940
}
20821941
20831942
/* Additions by RX '2004 */
2084
-extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
2085
-{
1943
+extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) {
20861944
unz64_s* s;
20871945
20881946
if (file==NULL)
20891947
return 0; //UNZ_PARAMERROR;
20901948
s=(unz64_s*)file;
@@ -2094,22 +1952,20 @@
20941952
if (s->num_file==s->gi.number_entry)
20951953
return 0;
20961954
return s->pos_in_central_dir;
20971955
}
20981956
2099
-extern uLong ZEXPORT unzGetOffset (unzFile file)
2100
-{
1957
+extern uLong ZEXPORT unzGetOffset(unzFile file) {
21011958
ZPOS64_T offset64;
21021959
21031960
if (file==NULL)
21041961
return 0; //UNZ_PARAMERROR;
21051962
offset64 = unzGetOffset64(file);
21061963
return (uLong)offset64;
21071964
}
21081965
2109
-extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
2110
-{
1966
+extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) {
21111967
unz64_s* s;
21121968
int err;
21131969
21141970
if (file==NULL)
21151971
return UNZ_PARAMERROR;
@@ -2122,9 +1978,8 @@
21221978
NULL,0,NULL,0,NULL,0);
21231979
s->current_file_ok = (err == UNZ_OK);
21241980
return err;
21251981
}
21261982
2127
-extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
2128
-{
1983
+extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) {
21291984
return unzSetOffset64(file,pos);
21301985
}
21311986
--- compat/zlib/contrib/minizip/unzip.c
+++ compat/zlib/contrib/minizip/unzip.c
@@ -47,16 +47,16 @@
47 2007-2008 - Even Rouault - Add unzip support for ZIP64
48
49 Copyright (C) 2007-2008 Even Rouault
50
51
52 Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again).
53 Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
54 should only read the compressed/uncompressed size from the Zip64 format if
55 the size from normal header was 0xFFFFFFFF
56 Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
57 Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
58 Patch created by Daniel Borca
59
60 Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
61
62 Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
@@ -75,12 +75,10 @@
75 #include "zlib.h"
76 #include "unzip.h"
77
78 #ifdef STDC
79 # include <stddef.h>
80 # include <string.h>
81 # include <stdlib.h>
82 #endif
83 #ifdef NO_ERRNO_H
84 extern int errno;
85 #else
86 # include <errno.h>
@@ -109,13 +107,10 @@
109 #endif
110
111 #ifndef ALLOC
112 # define ALLOC(size) (malloc(size))
113 #endif
114 #ifndef TRYFREE
115 # define TRYFREE(p) { free(p);}
116 #endif
117
118 #define SIZECENTRALDIRITEM (0x2e)
119 #define SIZEZIPLOCALHEADER (0x1e)
120
121
@@ -151,11 +146,11 @@
151 uLong crc32; /* crc32 of all data uncompressed */
152 uLong crc32_wait; /* crc32 we must obtain after decompress all */
153 ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
154 ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
155 zlib_filefunc64_32_def z_filefunc;
156 voidpf filestream; /* io structore of the zipfile */
157 uLong compression_method; /* compression method (0==store) */
158 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
159 int raw;
160 } file_in_zip64_read_info_s;
161
@@ -164,11 +159,11 @@
164 */
165 typedef struct
166 {
167 zlib_filefunc64_32_def z_filefunc;
168 int is64bitOpenFunction;
169 voidpf filestream; /* io structore of the zipfile */
170 unz_global_info64 gi; /* public global information */
171 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
172 ZPOS64_T num_file; /* number of the current file in the zipfile*/
173 ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/
174 ZPOS64_T current_file_ok; /* flag about the usability of the current file*/
@@ -194,162 +189,80 @@
194
195
196 #ifndef NOUNCRYPT
197 #include "crypt.h"
198 #endif
 
199
200 /* ===========================================================================
201 Read a byte from a gz_stream; update next_in and avail_in. Return EOF
202 for end of file.
203 IN assertion: the stream s has been successfully opened for reading.
204 */
205
206
207 local int unz64local_getByte OF((
208 const zlib_filefunc64_32_def* pzlib_filefunc_def,
209 voidpf filestream,
210 int *pi));
211
212 local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)
213 {
214 unsigned char c;
215 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
216 if (err==1)
217 {
218 *pi = (int)c;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219 return UNZ_OK;
220 }
221 else
222 {
 
223 if (ZERROR64(*pzlib_filefunc_def,filestream))
224 return UNZ_ERRNO;
225 else
226 return UNZ_EOF;
227 }
228 }
229
230
231 /* ===========================================================================
232 Reads a long in LSB order from the given gz_stream. Sets
233 */
234 local int unz64local_getShort OF((
235 const zlib_filefunc64_32_def* pzlib_filefunc_def,
236 voidpf filestream,
237 uLong *pX));
238
239 local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
240 voidpf filestream,
241 uLong *pX)
242 {
243 uLong x ;
244 int i = 0;
245 int err;
246
247 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
248 x = (uLong)i;
249
250 if (err==UNZ_OK)
251 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
252 x |= ((uLong)i)<<8;
253
254 if (err==UNZ_OK)
255 *pX = x;
256 else
257 *pX = 0;
258 return err;
259 }
260
261 local int unz64local_getLong OF((
262 const zlib_filefunc64_32_def* pzlib_filefunc_def,
263 voidpf filestream,
264 uLong *pX));
265
266 local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
267 voidpf filestream,
268 uLong *pX)
269 {
270 uLong x ;
271 int i = 0;
272 int err;
273
274 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
275 x = (uLong)i;
276
277 if (err==UNZ_OK)
278 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
279 x |= ((uLong)i)<<8;
280
281 if (err==UNZ_OK)
282 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
283 x |= ((uLong)i)<<16;
284
285 if (err==UNZ_OK)
286 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
287 x += ((uLong)i)<<24;
288
289 if (err==UNZ_OK)
290 *pX = x;
291 else
292 *pX = 0;
293 return err;
294 }
295
296 local int unz64local_getLong64 OF((
297 const zlib_filefunc64_32_def* pzlib_filefunc_def,
298 voidpf filestream,
299 ZPOS64_T *pX));
300
301
302 local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
303 voidpf filestream,
304 ZPOS64_T *pX)
305 {
306 ZPOS64_T x ;
307 int i = 0;
308 int err;
309
310 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
311 x = (ZPOS64_T)i;
312
313 if (err==UNZ_OK)
314 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
315 x |= ((ZPOS64_T)i)<<8;
316
317 if (err==UNZ_OK)
318 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
319 x |= ((ZPOS64_T)i)<<16;
320
321 if (err==UNZ_OK)
322 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
323 x |= ((ZPOS64_T)i)<<24;
324
325 if (err==UNZ_OK)
326 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
327 x |= ((ZPOS64_T)i)<<32;
328
329 if (err==UNZ_OK)
330 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
331 x |= ((ZPOS64_T)i)<<40;
332
333 if (err==UNZ_OK)
334 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
335 x |= ((ZPOS64_T)i)<<48;
336
337 if (err==UNZ_OK)
338 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
339 x |= ((ZPOS64_T)i)<<56;
340
341 if (err==UNZ_OK)
342 *pX = x;
343 else
344 *pX = 0;
345 return err;
346 }
347
348 /* My own strcmpi / strcasecmp */
349 local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
350 {
351 for (;;)
352 {
353 char c1=*(fileName1++);
354 char c2=*(fileName2++);
355 if ((c1>='a') && (c1<='z'))
@@ -377,23 +290,21 @@
377 #ifndef STRCMPCASENOSENTIVEFUNCTION
378 #define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
379 #endif
380
381 /*
382 Compare two filename (fileName1,fileName2).
383 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
384 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
385 or strcasecmp)
386 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
387 (like 1 on Unix, 2 on Windows)
388
389 */
390 extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
391 const char* fileName2,
392 int iCaseSensitivity)
393
394 {
395 if (iCaseSensitivity==0)
396 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
397
398 if (iCaseSensitivity==1)
399 return strcmp(fileName1,fileName2);
@@ -403,35 +314,37 @@
403
404 #ifndef BUFREADCOMMENT
405 #define BUFREADCOMMENT (0x400)
406 #endif
407
 
 
 
 
408 /*
409 Locate the Central directory of a zipfile (at the end, just before
410 the global comment)
411 */
412 local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
413 local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
414 {
415 unsigned char* buf;
416 ZPOS64_T uSizeFile;
417 ZPOS64_T uBackRead;
418 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
419 ZPOS64_T uPosFound=0;
420
421 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
422 return 0;
423
424
425 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
426
427 if (uMaxBack>uSizeFile)
428 uMaxBack = uSizeFile;
429
430 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
431 if (buf==NULL)
432 return 0;
433
434 uBackRead = 4;
435 while (uBackRead<uMaxBack)
436 {
437 uLong uReadSize;
@@ -457,49 +370,44 @@
457 {
458 uPosFound = uReadPos+(unsigned)i;
459 break;
460 }
461
462 if (uPosFound!=0)
463 break;
464 }
465 TRYFREE(buf);
466 return uPosFound;
467 }
468
469
470 /*
471 Locate the Central directory 64 of a zipfile (at the end, just before
472 the global comment)
473 */
474 local ZPOS64_T unz64local_SearchCentralDir64 OF((
475 const zlib_filefunc64_32_def* pzlib_filefunc_def,
476 voidpf filestream));
477
478 local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
479 voidpf filestream)
480 {
481 unsigned char* buf;
482 ZPOS64_T uSizeFile;
483 ZPOS64_T uBackRead;
484 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
485 ZPOS64_T uPosFound=0;
486 uLong uL;
487 ZPOS64_T relativeOffset;
488
489 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
490 return 0;
491
492
493 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
494
495 if (uMaxBack>uSizeFile)
496 uMaxBack = uSizeFile;
497
498 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
499 if (buf==NULL)
500 return 0;
501
502 uBackRead = 4;
503 while (uBackRead<uMaxBack)
504 {
505 uLong uReadSize;
@@ -525,51 +433,51 @@
525 {
526 uPosFound = uReadPos+(unsigned)i;
527 break;
528 }
529
530 if (uPosFound!=0)
531 break;
532 }
533 TRYFREE(buf);
534 if (uPosFound == 0)
535 return 0;
536
537 /* Zip64 end of central directory locator */
538 if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
539 return 0;
540
541 /* the signature, already checked */
542 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
543 return 0;
544
545 /* number of the disk with the start of the zip64 end of central directory */
546 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
547 return 0;
548 if (uL != 0)
549 return 0;
550
551 /* relative offset of the zip64 end of central directory record */
552 if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
553 return 0;
554
555 /* total number of disks */
556 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
557 return 0;
558 if (uL != 1)
559 return 0;
560
561 /* Goto end of central directory record */
562 if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
563 return 0;
564
565 /* the signature */
566 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
567 return 0;
568
569 if (uL != 0x06064b50)
570 return 0;
571
572 return relativeOffset;
573 }
574
575 /*
@@ -579,23 +487,22 @@
579 If the zipfile cannot be opened (file doesn't exist or in not valid), the
580 return value is NULL.
581 Else, the return value is a unzFile Handle, usable with other function
582 of this unzip package.
583 */
584 local unzFile unzOpenInternal (const void *path,
585 zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
586 int is64bitOpenFunction)
587 {
588 unz64_s us;
589 unz64_s *s;
590 ZPOS64_T central_pos;
591 uLong uL;
592
593 uLong number_disk; /* number of the current dist, used for
594 spaning ZIP, unsupported, always 0*/
595 uLong number_disk_with_CD; /* number the the disk with central dir, used
596 for spaning ZIP, unsupported, always 0*/
597 ZPOS64_T number_entry_CD; /* total number of entries in
598 the central dir
599 (same than number_entry on nospan) */
600
601 int err=UNZ_OK;
@@ -619,11 +526,11 @@
619 ZLIB_FILEFUNC_MODE_EXISTING);
620 if (us.filestream==NULL)
621 return NULL;
622
623 central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
624 if (central_pos)
625 {
626 uLong uS;
627 ZPOS64_T uL64;
628
629 us.isZip64 = 1;
@@ -681,11 +588,11 @@
681 us.gi.size_comment = 0;
682 }
683 else
684 {
685 central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
686 if (central_pos==0)
687 err=UNZ_ERRNO;
688
689 us.isZip64 = 0;
690
691 if (ZSEEK64(us.z_filefunc, us.filestream,
@@ -760,13 +667,12 @@
760 }
761 return (unzFile)s;
762 }
763
764
765 extern unzFile ZEXPORT unzOpen2 (const char *path,
766 zlib_filefunc_def* pzlib_filefunc32_def)
767 {
768 if (pzlib_filefunc32_def != NULL)
769 {
770 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
771 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
772 return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
@@ -773,13 +679,12 @@
773 }
774 else
775 return unzOpenInternal(path, NULL, 0);
776 }
777
778 extern unzFile ZEXPORT unzOpen2_64 (const void *path,
779 zlib_filefunc64_def* pzlib_filefunc_def)
780 {
781 if (pzlib_filefunc_def != NULL)
782 {
783 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
784 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
785 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
@@ -788,57 +693,52 @@
788 }
789 else
790 return unzOpenInternal(path, NULL, 1);
791 }
792
793 extern unzFile ZEXPORT unzOpen (const char *path)
794 {
795 return unzOpenInternal(path, NULL, 0);
796 }
797
798 extern unzFile ZEXPORT unzOpen64 (const void *path)
799 {
800 return unzOpenInternal(path, NULL, 1);
801 }
802
803 /*
804 Close a ZipFile opened with unzOpen.
805 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
806 these files MUST be closed with unzCloseCurrentFile before call unzClose.
807 return UNZ_OK if there is no problem. */
808 extern int ZEXPORT unzClose (unzFile file)
809 {
810 unz64_s* s;
811 if (file==NULL)
812 return UNZ_PARAMERROR;
813 s=(unz64_s*)file;
814
815 if (s->pfile_in_zip_read!=NULL)
816 unzCloseCurrentFile(file);
817
818 ZCLOSE64(s->z_filefunc, s->filestream);
819 TRYFREE(s);
820 return UNZ_OK;
821 }
822
823
824 /*
825 Write info about the ZipFile in the *pglobal_info structure.
826 No preparation of the structure is needed
827 return UNZ_OK if there is no problem. */
828 extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
829 {
830 unz64_s* s;
831 if (file==NULL)
832 return UNZ_PARAMERROR;
833 s=(unz64_s*)file;
834 *pglobal_info=s->gi;
835 return UNZ_OK;
836 }
837
838 extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
839 {
840 unz64_s* s;
841 if (file==NULL)
842 return UNZ_PARAMERROR;
843 s=(unz64_s*)file;
844 /* to do : check if number_entry is not truncated */
@@ -845,14 +745,13 @@
845 pglobal_info32->number_entry = (uLong)s->gi.number_entry;
846 pglobal_info32->size_comment = s->gi.size_comment;
847 return UNZ_OK;
848 }
849 /*
850 Translate date/time from Dos format to tm_unz (readable more easilty)
851 */
852 local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
853 {
854 ZPOS64_T uDate;
855 uDate = (ZPOS64_T)(ulDosDate>>16);
856 ptm->tm_mday = (int)(uDate&0x1f) ;
857 ptm->tm_mon = (int)((((uDate)&0x1E0)/0x20)-1) ;
858 ptm->tm_year = (int)(((uDate&0x0FE00)/0x0200)+1980) ;
@@ -863,32 +762,20 @@
863 }
864
865 /*
866 Get Info about the current file in the zipfile, with internal only info
867 */
868 local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
869 unz_file_info64 *pfile_info,
870 unz_file_info64_internal
871 *pfile_info_internal,
872 char *szFileName,
873 uLong fileNameBufferSize,
874 void *extraField,
875 uLong extraFieldBufferSize,
876 char *szComment,
877 uLong commentBufferSize));
878
879 local int unz64local_GetCurrentFileInfoInternal (unzFile file,
880 unz_file_info64 *pfile_info,
881 unz_file_info64_internal
882 *pfile_info_internal,
883 char *szFileName,
884 uLong fileNameBufferSize,
885 void *extraField,
886 uLong extraFieldBufferSize,
887 char *szComment,
888 uLong commentBufferSize)
889 {
890 unz64_s* s;
891 unz_file_info64 file_info;
892 unz_file_info64_internal file_info_internal;
893 int err=UNZ_OK;
894 uLong uMagic;
@@ -1036,37 +923,35 @@
1036 err=UNZ_ERRNO;
1037
1038 /* ZIP64 extra fields */
1039 if (headerId == 0x0001)
1040 {
1041 uLong uL;
1042
1043 if(file_info.uncompressed_size == MAXU32)
1044 {
1045 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
1046 err=UNZ_ERRNO;
1047 }
1048
1049 if(file_info.compressed_size == MAXU32)
1050 {
1051 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
1052 err=UNZ_ERRNO;
1053 }
1054
1055 if(file_info_internal.offset_curfile == MAXU32)
1056 {
1057 /* Relative Header offset */
1058 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
1059 err=UNZ_ERRNO;
1060 }
1061
1062 if(file_info.disk_num_start == MAXU32)
1063 {
1064 /* Disk Start Number */
1065 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
1066 err=UNZ_ERRNO;
1067 }
1068
1069 }
1070 else
1071 {
1072 if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
@@ -1119,28 +1004,26 @@
1119 /*
1120 Write info about the ZipFile in the *pglobal_info structure.
1121 No preparation of the structure is needed
1122 return UNZ_OK if there is no problem.
1123 */
1124 extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
1125 unz_file_info64 * pfile_info,
1126 char * szFileName, uLong fileNameBufferSize,
1127 void *extraField, uLong extraFieldBufferSize,
1128 char* szComment, uLong commentBufferSize)
1129 {
1130 return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
1131 szFileName,fileNameBufferSize,
1132 extraField,extraFieldBufferSize,
1133 szComment,commentBufferSize);
1134 }
1135
1136 extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
1137 unz_file_info * pfile_info,
1138 char * szFileName, uLong fileNameBufferSize,
1139 void *extraField, uLong extraFieldBufferSize,
1140 char* szComment, uLong commentBufferSize)
1141 {
1142 int err;
1143 unz_file_info64 file_info64;
1144 err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
1145 szFileName,fileNameBufferSize,
1146 extraField,extraFieldBufferSize,
@@ -1160,11 +1043,11 @@
1160
1161 pfile_info->disk_num_start = file_info64.disk_num_start;
1162 pfile_info->internal_fa = file_info64.internal_fa;
1163 pfile_info->external_fa = file_info64.external_fa;
1164
1165 pfile_info->tmu_date = file_info64.tmu_date,
1166
1167
1168 pfile_info->compressed_size = (uLong)file_info64.compressed_size;
1169 pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
1170
@@ -1173,12 +1056,11 @@
1173 }
1174 /*
1175 Set the current file of the zipfile to the first file.
1176 return UNZ_OK if there is no problem
1177 */
1178 extern int ZEXPORT unzGoToFirstFile (unzFile file)
1179 {
1180 int err=UNZ_OK;
1181 unz64_s* s;
1182 if (file==NULL)
1183 return UNZ_PARAMERROR;
1184 s=(unz64_s*)file;
@@ -1194,12 +1076,11 @@
1194 /*
1195 Set the current file of the zipfile to the next file.
1196 return UNZ_OK if there is no problem
1197 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
1198 */
1199 extern int ZEXPORT unzGoToNextFile (unzFile file)
1200 {
1201 unz64_s* s;
1202 int err;
1203
1204 if (file==NULL)
1205 return UNZ_PARAMERROR;
@@ -1227,12 +1108,11 @@
1227
1228 return value :
1229 UNZ_OK if the file is found. It becomes the current file.
1230 UNZ_END_OF_LIST_OF_FILE if the file is not found
1231 */
1232 extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
1233 {
1234 unz64_s* s;
1235 int err;
1236
1237 /* We remember the 'current' position in the file so that we can jump
1238 * back there if we fail.
@@ -1303,12 +1183,11 @@
1303 ZPOS64_T pos_in_zip_directory; // offset in file
1304 ZPOS64_T num_of_file; // # of file
1305 } unz_file_pos;
1306 */
1307
1308 extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos)
1309 {
1310 unz64_s* s;
1311
1312 if (file==NULL || file_pos==NULL)
1313 return UNZ_PARAMERROR;
1314 s=(unz64_s*)file;
@@ -1319,14 +1198,11 @@
1319 file_pos->num_of_file = s->num_file;
1320
1321 return UNZ_OK;
1322 }
1323
1324 extern int ZEXPORT unzGetFilePos(
1325 unzFile file,
1326 unz_file_pos* file_pos)
1327 {
1328 unz64_file_pos file_pos64;
1329 int err = unzGetFilePos64(file,&file_pos64);
1330 if (err==UNZ_OK)
1331 {
1332 file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
@@ -1333,12 +1209,11 @@
1333 file_pos->num_of_file = (uLong)file_pos64.num_of_file;
1334 }
1335 return err;
1336 }
1337
1338 extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
1339 {
1340 unz64_s* s;
1341 int err;
1342
1343 if (file==NULL || file_pos==NULL)
1344 return UNZ_PARAMERROR;
@@ -1355,14 +1230,11 @@
1355 /* return results */
1356 s->current_file_ok = (err == UNZ_OK);
1357 return err;
1358 }
1359
1360 extern int ZEXPORT unzGoToFilePos(
1361 unzFile file,
1362 unz_file_pos* file_pos)
1363 {
1364 unz64_file_pos file_pos64;
1365 if (file_pos == NULL)
1366 return UNZ_PARAMERROR;
1367
1368 file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
@@ -1380,14 +1252,13 @@
1380 Check the coherency of the local header and info in the end of central
1381 directory about this file
1382 store in *piSizeVar the size of extra info in local header
1383 (filename and size of extra field data)
1384 */
1385 local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
1386 ZPOS64_T * poffset_local_extrafield,
1387 uInt * psize_local_extrafield)
1388 {
1389 uLong uMagic,uData,uFlags;
1390 uLong size_filename;
1391 uLong size_extra_field;
1392 int err=UNZ_OK;
1393
@@ -1467,13 +1338,12 @@
1467
1468 /*
1469 Open for reading data the current file in the zipfile.
1470 If there is no error and the file is opened, the return value is UNZ_OK.
1471 */
1472 extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
1473 int* level, int raw, const char* password)
1474 {
1475 int err=UNZ_OK;
1476 uInt iSizeVar;
1477 unz64_s* s;
1478 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1479 ZPOS64_T offset_local_extrafield; /* offset of the local extra field */
@@ -1507,11 +1377,11 @@
1507 pfile_in_zip_read_info->pos_local_extrafield=0;
1508 pfile_in_zip_read_info->raw=raw;
1509
1510 if (pfile_in_zip_read_info->read_buffer==NULL)
1511 {
1512 TRYFREE(pfile_in_zip_read_info);
1513 return UNZ_INTERNALERROR;
1514 }
1515
1516 pfile_in_zip_read_info->stream_initialised=0;
1517
@@ -1564,12 +1434,12 @@
1564 err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
1565 if (err == Z_OK)
1566 pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
1567 else
1568 {
1569 TRYFREE(pfile_in_zip_read_info->read_buffer);
1570 TRYFREE(pfile_in_zip_read_info);
1571 return err;
1572 }
1573 #else
1574 pfile_in_zip_read_info->raw=1;
1575 #endif
@@ -1585,12 +1455,12 @@
1585 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1586 if (err == Z_OK)
1587 pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
1588 else
1589 {
1590 TRYFREE(pfile_in_zip_read_info->read_buffer);
1591 TRYFREE(pfile_in_zip_read_info);
1592 return err;
1593 }
1594 /* windowBits is passed < 0 to tell that there is no zlib header.
1595 * Note that in this case inflate *requires* an extra "dummy" byte
1596 * after the compressed stream in order to complete decompression and
@@ -1638,29 +1508,25 @@
1638
1639
1640 return UNZ_OK;
1641 }
1642
1643 extern int ZEXPORT unzOpenCurrentFile (unzFile file)
1644 {
1645 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1646 }
1647
1648 extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password)
1649 {
1650 return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1651 }
1652
1653 extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
1654 {
1655 return unzOpenCurrentFile3(file, method, level, raw, NULL);
1656 }
1657
1658 /** Addition for GDAL : START */
1659
1660 extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
1661 {
1662 unz64_s* s;
1663 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1664 s=(unz64_s*)file;
1665 if (file==NULL)
1666 return 0; //UNZ_PARAMERROR;
@@ -1676,17 +1542,16 @@
1676 /*
1677 Read bytes from the current file.
1678 buf contain buffer where data must be copied
1679 len the size of buf.
1680
1681 return the number of byte copied if somes bytes are copied
1682 return 0 if the end of file was reached
1683 return <0 with error code if there is an error
1684 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
1685 */
1686 extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
1687 {
1688 int err=UNZ_OK;
1689 uInt iRead = 0;
1690 unz64_s* s;
1691 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1692 if (file==NULL)
@@ -1889,12 +1754,11 @@
1889
1890
1891 /*
1892 Give the current position in uncompressed data
1893 */
1894 extern z_off_t ZEXPORT unztell (unzFile file)
1895 {
1896 unz64_s* s;
1897 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1898 if (file==NULL)
1899 return UNZ_PARAMERROR;
1900 s=(unz64_s*)file;
@@ -1904,12 +1768,11 @@
1904 return UNZ_PARAMERROR;
1905
1906 return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1907 }
1908
1909 extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
1910 {
1911
1912 unz64_s* s;
1913 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1914 if (file==NULL)
1915 return (ZPOS64_T)-1;
@@ -1924,12 +1787,11 @@
1924
1925
1926 /*
1927 return 1 if the end of file was reached, 0 elsewhere
1928 */
1929 extern int ZEXPORT unzeof (unzFile file)
1930 {
1931 unz64_s* s;
1932 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1933 if (file==NULL)
1934 return UNZ_PARAMERROR;
1935 s=(unz64_s*)file;
@@ -1956,12 +1818,11 @@
1956 if buf!=NULL, len is the size of the buffer, the extra header is copied in
1957 buf.
1958 the return value is the number of bytes copied in buf, or (if <0)
1959 the error code
1960 */
1961 extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
1962 {
1963 unz64_s* s;
1964 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1965 uInt read_now;
1966 ZPOS64_T size_to_read;
1967
@@ -2004,12 +1865,11 @@
2004
2005 /*
2006 Close the file in zip opened with unzOpenCurrentFile
2007 Return UNZ_CRCERROR if all the file was read but the CRC is not good
2008 */
2009 extern int ZEXPORT unzCloseCurrentFile (unzFile file)
2010 {
2011 int err=UNZ_OK;
2012
2013 unz64_s* s;
2014 file_in_zip64_read_info_s* pfile_in_zip_read_info;
2015 if (file==NULL)
@@ -2027,11 +1887,11 @@
2027 if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
2028 err=UNZ_CRCERROR;
2029 }
2030
2031
2032 TRYFREE(pfile_in_zip_read_info->read_buffer);
2033 pfile_in_zip_read_info->read_buffer = NULL;
2034 if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
2035 inflateEnd(&pfile_in_zip_read_info->stream);
2036 #ifdef HAVE_BZIP2
2037 else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
@@ -2038,11 +1898,11 @@
2038 BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
2039 #endif
2040
2041
2042 pfile_in_zip_read_info->stream_initialised = 0;
2043 TRYFREE(pfile_in_zip_read_info);
2044
2045 s->pfile_in_zip_read=NULL;
2046
2047 return err;
2048 }
@@ -2051,12 +1911,11 @@
2051 /*
2052 Get the global comment string of the ZipFile, in the szComment buffer.
2053 uSizeBuf is the size of the szComment buffer.
2054 return the number of byte copied or an error code <0
2055 */
2056 extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
2057 {
2058 unz64_s* s;
2059 uLong uReadThis ;
2060 if (file==NULL)
2061 return (int)UNZ_PARAMERROR;
2062 s=(unz64_s*)file;
@@ -2079,12 +1938,11 @@
2079 *(szComment+s->gi.size_comment)='\0';
2080 return (int)uReadThis;
2081 }
2082
2083 /* Additions by RX '2004 */
2084 extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
2085 {
2086 unz64_s* s;
2087
2088 if (file==NULL)
2089 return 0; //UNZ_PARAMERROR;
2090 s=(unz64_s*)file;
@@ -2094,22 +1952,20 @@
2094 if (s->num_file==s->gi.number_entry)
2095 return 0;
2096 return s->pos_in_central_dir;
2097 }
2098
2099 extern uLong ZEXPORT unzGetOffset (unzFile file)
2100 {
2101 ZPOS64_T offset64;
2102
2103 if (file==NULL)
2104 return 0; //UNZ_PARAMERROR;
2105 offset64 = unzGetOffset64(file);
2106 return (uLong)offset64;
2107 }
2108
2109 extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
2110 {
2111 unz64_s* s;
2112 int err;
2113
2114 if (file==NULL)
2115 return UNZ_PARAMERROR;
@@ -2122,9 +1978,8 @@
2122 NULL,0,NULL,0,NULL,0);
2123 s->current_file_ok = (err == UNZ_OK);
2124 return err;
2125 }
2126
2127 extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
2128 {
2129 return unzSetOffset64(file,pos);
2130 }
2131
--- compat/zlib/contrib/minizip/unzip.c
+++ compat/zlib/contrib/minizip/unzip.c
@@ -47,16 +47,16 @@
47 2007-2008 - Even Rouault - Add unzip support for ZIP64
48
49 Copyright (C) 2007-2008 Even Rouault
50
51
52 Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again).
53 Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
54 should only read the compressed/uncompressed size from the Zip64 format if
55 the size from normal header was 0xFFFFFFFF
56 Oct-2009 - Mathias Svensson - Applied some bug fixes from patches received from Gilles Vollant
57 Oct-2009 - Mathias Svensson - Applied support to unzip files with compression method BZIP2 (bzip2 lib is required)
58 Patch created by Daniel Borca
59
60 Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
61
62 Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
@@ -75,12 +75,10 @@
75 #include "zlib.h"
76 #include "unzip.h"
77
78 #ifdef STDC
79 # include <stddef.h>
 
 
80 #endif
81 #ifdef NO_ERRNO_H
82 extern int errno;
83 #else
84 # include <errno.h>
@@ -109,13 +107,10 @@
107 #endif
108
109 #ifndef ALLOC
110 # define ALLOC(size) (malloc(size))
111 #endif
 
 
 
112
113 #define SIZECENTRALDIRITEM (0x2e)
114 #define SIZEZIPLOCALHEADER (0x1e)
115
116
@@ -151,11 +146,11 @@
146 uLong crc32; /* crc32 of all data uncompressed */
147 uLong crc32_wait; /* crc32 we must obtain after decompress all */
148 ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
149 ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
150 zlib_filefunc64_32_def z_filefunc;
151 voidpf filestream; /* io structure of the zipfile */
152 uLong compression_method; /* compression method (0==store) */
153 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
154 int raw;
155 } file_in_zip64_read_info_s;
156
@@ -164,11 +159,11 @@
159 */
160 typedef struct
161 {
162 zlib_filefunc64_32_def z_filefunc;
163 int is64bitOpenFunction;
164 voidpf filestream; /* io structure of the zipfile */
165 unz_global_info64 gi; /* public global information */
166 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
167 ZPOS64_T num_file; /* number of the current file in the zipfile*/
168 ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/
169 ZPOS64_T current_file_ok; /* flag about the usability of the current file*/
@@ -194,162 +189,80 @@
189
190
191 #ifndef NOUNCRYPT
192 #include "crypt.h"
193 #endif
194
195
196 /* ===========================================================================
197 Reads a long in LSB order from the given gz_stream. Sets
 
 
198 */
199
200 local int unz64local_getShort(const zlib_filefunc64_32_def* pzlib_filefunc_def,
201 voidpf filestream,
202 uLong *pX) {
203 unsigned char c[2];
204 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,2);
205 if (err==2)
206 {
207 *pX = c[0] | ((uLong)c[1] << 8);
208 return UNZ_OK;
209 }
210 else
211 {
212 *pX = 0;
213 if (ZERROR64(*pzlib_filefunc_def,filestream))
214 return UNZ_ERRNO;
215 else
216 return UNZ_EOF;
217 }
218 }
219
220 local int unz64local_getLong(const zlib_filefunc64_32_def* pzlib_filefunc_def,
221 voidpf filestream,
222 uLong *pX) {
223 unsigned char c[4];
224 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,4);
225 if (err==4)
226 {
227 *pX = c[0] | ((uLong)c[1] << 8) | ((uLong)c[2] << 16) | ((uLong)c[3] << 24);
228 return UNZ_OK;
229 }
230 else
231 {
232 *pX = 0;
233 if (ZERROR64(*pzlib_filefunc_def,filestream))
234 return UNZ_ERRNO;
235 else
236 return UNZ_EOF;
237 }
238 }
239
240
241 local int unz64local_getLong64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
242 voidpf filestream,
243 ZPOS64_T *pX) {
244 unsigned char c[8];
245 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,8);
246 if (err==8)
247 {
248 *pX = c[0] | ((ZPOS64_T)c[1] << 8) | ((ZPOS64_T)c[2] << 16) | ((ZPOS64_T)c[3] << 24)
249 | ((ZPOS64_T)c[4] << 32) | ((ZPOS64_T)c[5] << 40) | ((ZPOS64_T)c[6] << 48) | ((ZPOS64_T)c[7] << 56);
250 return UNZ_OK;
251 }
252 else
253 {
254 *pX = 0;
255 if (ZERROR64(*pzlib_filefunc_def,filestream))
256 return UNZ_ERRNO;
257 else
258 return UNZ_EOF;
259 }
260 }
261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262 /* My own strcmpi / strcasecmp */
263 local int strcmpcasenosensitive_internal(const char* fileName1, const char* fileName2) {
 
264 for (;;)
265 {
266 char c1=*(fileName1++);
267 char c2=*(fileName2++);
268 if ((c1>='a') && (c1<='z'))
@@ -377,23 +290,21 @@
290 #ifndef STRCMPCASENOSENTIVEFUNCTION
291 #define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
292 #endif
293
294 /*
295 Compare two filenames (fileName1,fileName2).
296 If iCaseSensitivity = 1, comparison is case sensitive (like strcmp)
297 If iCaseSensitivity = 2, comparison is not case sensitive (like strcmpi
298 or strcasecmp)
299 If iCaseSensitivity = 0, case sensitivity is default of your operating system
300 (like 1 on Unix, 2 on Windows)
301
302 */
303 extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
304 const char* fileName2,
305 int iCaseSensitivity) {
 
 
306 if (iCaseSensitivity==0)
307 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
308
309 if (iCaseSensitivity==1)
310 return strcmp(fileName1,fileName2);
@@ -403,35 +314,37 @@
314
315 #ifndef BUFREADCOMMENT
316 #define BUFREADCOMMENT (0x400)
317 #endif
318
319 #ifndef CENTRALDIRINVALID
320 #define CENTRALDIRINVALID ((ZPOS64_T)(-1))
321 #endif
322
323 /*
324 Locate the Central directory of a zipfile (at the end, just before
325 the global comment)
326 */
327 local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) {
 
 
328 unsigned char* buf;
329 ZPOS64_T uSizeFile;
330 ZPOS64_T uBackRead;
331 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
332 ZPOS64_T uPosFound=CENTRALDIRINVALID;
333
334 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
335 return CENTRALDIRINVALID;
336
337
338 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
339
340 if (uMaxBack>uSizeFile)
341 uMaxBack = uSizeFile;
342
343 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
344 if (buf==NULL)
345 return CENTRALDIRINVALID;
346
347 uBackRead = 4;
348 while (uBackRead<uMaxBack)
349 {
350 uLong uReadSize;
@@ -457,49 +370,44 @@
370 {
371 uPosFound = uReadPos+(unsigned)i;
372 break;
373 }
374
375 if (uPosFound!=CENTRALDIRINVALID)
376 break;
377 }
378 free(buf);
379 return uPosFound;
380 }
381
382
383 /*
384 Locate the Central directory 64 of a zipfile (at the end, just before
385 the global comment)
386 */
 
 
 
 
387 local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
388 voidpf filestream) {
 
389 unsigned char* buf;
390 ZPOS64_T uSizeFile;
391 ZPOS64_T uBackRead;
392 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
393 ZPOS64_T uPosFound=CENTRALDIRINVALID;
394 uLong uL;
395 ZPOS64_T relativeOffset;
396
397 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
398 return CENTRALDIRINVALID;
399
400
401 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
402
403 if (uMaxBack>uSizeFile)
404 uMaxBack = uSizeFile;
405
406 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
407 if (buf==NULL)
408 return CENTRALDIRINVALID;
409
410 uBackRead = 4;
411 while (uBackRead<uMaxBack)
412 {
413 uLong uReadSize;
@@ -525,51 +433,51 @@
433 {
434 uPosFound = uReadPos+(unsigned)i;
435 break;
436 }
437
438 if (uPosFound!=CENTRALDIRINVALID)
439 break;
440 }
441 free(buf);
442 if (uPosFound == CENTRALDIRINVALID)
443 return CENTRALDIRINVALID;
444
445 /* Zip64 end of central directory locator */
446 if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
447 return CENTRALDIRINVALID;
448
449 /* the signature, already checked */
450 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
451 return CENTRALDIRINVALID;
452
453 /* number of the disk with the start of the zip64 end of central directory */
454 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
455 return CENTRALDIRINVALID;
456 if (uL != 0)
457 return CENTRALDIRINVALID;
458
459 /* relative offset of the zip64 end of central directory record */
460 if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
461 return CENTRALDIRINVALID;
462
463 /* total number of disks */
464 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
465 return CENTRALDIRINVALID;
466 if (uL != 1)
467 return CENTRALDIRINVALID;
468
469 /* Goto end of central directory record */
470 if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
471 return CENTRALDIRINVALID;
472
473 /* the signature */
474 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
475 return CENTRALDIRINVALID;
476
477 if (uL != 0x06064b50)
478 return CENTRALDIRINVALID;
479
480 return relativeOffset;
481 }
482
483 /*
@@ -579,23 +487,22 @@
487 If the zipfile cannot be opened (file doesn't exist or in not valid), the
488 return value is NULL.
489 Else, the return value is a unzFile Handle, usable with other function
490 of this unzip package.
491 */
492 local unzFile unzOpenInternal(const void *path,
493 zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
494 int is64bitOpenFunction) {
 
495 unz64_s us;
496 unz64_s *s;
497 ZPOS64_T central_pos;
498 uLong uL;
499
500 uLong number_disk; /* number of the current dist, used for
501 spanning ZIP, unsupported, always 0*/
502 uLong number_disk_with_CD; /* number the the disk with central dir, used
503 for spanning ZIP, unsupported, always 0*/
504 ZPOS64_T number_entry_CD; /* total number of entries in
505 the central dir
506 (same than number_entry on nospan) */
507
508 int err=UNZ_OK;
@@ -619,11 +526,11 @@
526 ZLIB_FILEFUNC_MODE_EXISTING);
527 if (us.filestream==NULL)
528 return NULL;
529
530 central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
531 if (central_pos!=CENTRALDIRINVALID)
532 {
533 uLong uS;
534 ZPOS64_T uL64;
535
536 us.isZip64 = 1;
@@ -681,11 +588,11 @@
588 us.gi.size_comment = 0;
589 }
590 else
591 {
592 central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
593 if (central_pos==CENTRALDIRINVALID)
594 err=UNZ_ERRNO;
595
596 us.isZip64 = 0;
597
598 if (ZSEEK64(us.z_filefunc, us.filestream,
@@ -760,13 +667,12 @@
667 }
668 return (unzFile)s;
669 }
670
671
672 extern unzFile ZEXPORT unzOpen2(const char *path,
673 zlib_filefunc_def* pzlib_filefunc32_def) {
 
674 if (pzlib_filefunc32_def != NULL)
675 {
676 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
677 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
678 return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
@@ -773,13 +679,12 @@
679 }
680 else
681 return unzOpenInternal(path, NULL, 0);
682 }
683
684 extern unzFile ZEXPORT unzOpen2_64(const void *path,
685 zlib_filefunc64_def* pzlib_filefunc_def) {
 
686 if (pzlib_filefunc_def != NULL)
687 {
688 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
689 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
690 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
@@ -788,57 +693,52 @@
693 }
694 else
695 return unzOpenInternal(path, NULL, 1);
696 }
697
698 extern unzFile ZEXPORT unzOpen(const char *path) {
 
699 return unzOpenInternal(path, NULL, 0);
700 }
701
702 extern unzFile ZEXPORT unzOpen64(const void *path) {
 
703 return unzOpenInternal(path, NULL, 1);
704 }
705
706 /*
707 Close a ZipFile opened with unzOpen.
708 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
709 these files MUST be closed with unzCloseCurrentFile before call unzClose.
710 return UNZ_OK if there is no problem. */
711 extern int ZEXPORT unzClose(unzFile file) {
 
712 unz64_s* s;
713 if (file==NULL)
714 return UNZ_PARAMERROR;
715 s=(unz64_s*)file;
716
717 if (s->pfile_in_zip_read!=NULL)
718 unzCloseCurrentFile(file);
719
720 ZCLOSE64(s->z_filefunc, s->filestream);
721 free(s);
722 return UNZ_OK;
723 }
724
725
726 /*
727 Write info about the ZipFile in the *pglobal_info structure.
728 No preparation of the structure is needed
729 return UNZ_OK if there is no problem. */
730 extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64* pglobal_info) {
 
731 unz64_s* s;
732 if (file==NULL)
733 return UNZ_PARAMERROR;
734 s=(unz64_s*)file;
735 *pglobal_info=s->gi;
736 return UNZ_OK;
737 }
738
739 extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32) {
 
740 unz64_s* s;
741 if (file==NULL)
742 return UNZ_PARAMERROR;
743 s=(unz64_s*)file;
744 /* to do : check if number_entry is not truncated */
@@ -845,14 +745,13 @@
745 pglobal_info32->number_entry = (uLong)s->gi.number_entry;
746 pglobal_info32->size_comment = s->gi.size_comment;
747 return UNZ_OK;
748 }
749 /*
750 Translate date/time from Dos format to tm_unz (readable more easily)
751 */
752 local void unz64local_DosDateToTmuDate(ZPOS64_T ulDosDate, tm_unz* ptm) {
 
753 ZPOS64_T uDate;
754 uDate = (ZPOS64_T)(ulDosDate>>16);
755 ptm->tm_mday = (int)(uDate&0x1f) ;
756 ptm->tm_mon = (int)((((uDate)&0x1E0)/0x20)-1) ;
757 ptm->tm_year = (int)(((uDate&0x0FE00)/0x0200)+1980) ;
@@ -863,32 +762,20 @@
762 }
763
764 /*
765 Get Info about the current file in the zipfile, with internal only info
766 */
767 local int unz64local_GetCurrentFileInfoInternal(unzFile file,
768 unz_file_info64 *pfile_info,
769 unz_file_info64_internal
770 *pfile_info_internal,
771 char *szFileName,
772 uLong fileNameBufferSize,
773 void *extraField,
774 uLong extraFieldBufferSize,
775 char *szComment,
776 uLong commentBufferSize) {
 
 
 
 
 
 
 
 
 
 
 
 
777 unz64_s* s;
778 unz_file_info64 file_info;
779 unz_file_info64_internal file_info_internal;
780 int err=UNZ_OK;
781 uLong uMagic;
@@ -1036,37 +923,35 @@
923 err=UNZ_ERRNO;
924
925 /* ZIP64 extra fields */
926 if (headerId == 0x0001)
927 {
928 if(file_info.uncompressed_size == MAXU32)
929 {
930 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
931 err=UNZ_ERRNO;
932 }
933
934 if(file_info.compressed_size == MAXU32)
935 {
936 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
937 err=UNZ_ERRNO;
938 }
939
940 if(file_info_internal.offset_curfile == MAXU32)
941 {
942 /* Relative Header offset */
943 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
944 err=UNZ_ERRNO;
945 }
946
947 if(file_info.disk_num_start == 0xffff)
948 {
949 /* Disk Start Number */
950 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
951 err=UNZ_ERRNO;
952 }
 
 
953
954 }
955 else
956 {
957 if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
@@ -1119,28 +1004,26 @@
1004 /*
1005 Write info about the ZipFile in the *pglobal_info structure.
1006 No preparation of the structure is needed
1007 return UNZ_OK if there is no problem.
1008 */
1009 extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file,
1010 unz_file_info64 * pfile_info,
1011 char * szFileName, uLong fileNameBufferSize,
1012 void *extraField, uLong extraFieldBufferSize,
1013 char* szComment, uLong commentBufferSize) {
 
1014 return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
1015 szFileName,fileNameBufferSize,
1016 extraField,extraFieldBufferSize,
1017 szComment,commentBufferSize);
1018 }
1019
1020 extern int ZEXPORT unzGetCurrentFileInfo(unzFile file,
1021 unz_file_info * pfile_info,
1022 char * szFileName, uLong fileNameBufferSize,
1023 void *extraField, uLong extraFieldBufferSize,
1024 char* szComment, uLong commentBufferSize) {
 
1025 int err;
1026 unz_file_info64 file_info64;
1027 err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
1028 szFileName,fileNameBufferSize,
1029 extraField,extraFieldBufferSize,
@@ -1160,11 +1043,11 @@
1043
1044 pfile_info->disk_num_start = file_info64.disk_num_start;
1045 pfile_info->internal_fa = file_info64.internal_fa;
1046 pfile_info->external_fa = file_info64.external_fa;
1047
1048 pfile_info->tmu_date = file_info64.tmu_date;
1049
1050
1051 pfile_info->compressed_size = (uLong)file_info64.compressed_size;
1052 pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
1053
@@ -1173,12 +1056,11 @@
1056 }
1057 /*
1058 Set the current file of the zipfile to the first file.
1059 return UNZ_OK if there is no problem
1060 */
1061 extern int ZEXPORT unzGoToFirstFile(unzFile file) {
 
1062 int err=UNZ_OK;
1063 unz64_s* s;
1064 if (file==NULL)
1065 return UNZ_PARAMERROR;
1066 s=(unz64_s*)file;
@@ -1194,12 +1076,11 @@
1076 /*
1077 Set the current file of the zipfile to the next file.
1078 return UNZ_OK if there is no problem
1079 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
1080 */
1081 extern int ZEXPORT unzGoToNextFile(unzFile file) {
 
1082 unz64_s* s;
1083 int err;
1084
1085 if (file==NULL)
1086 return UNZ_PARAMERROR;
@@ -1227,12 +1108,11 @@
1108
1109 return value :
1110 UNZ_OK if the file is found. It becomes the current file.
1111 UNZ_END_OF_LIST_OF_FILE if the file is not found
1112 */
1113 extern int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity) {
 
1114 unz64_s* s;
1115 int err;
1116
1117 /* We remember the 'current' position in the file so that we can jump
1118 * back there if we fail.
@@ -1303,12 +1183,11 @@
1183 ZPOS64_T pos_in_zip_directory; // offset in file
1184 ZPOS64_T num_of_file; // # of file
1185 } unz_file_pos;
1186 */
1187
1188 extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) {
 
1189 unz64_s* s;
1190
1191 if (file==NULL || file_pos==NULL)
1192 return UNZ_PARAMERROR;
1193 s=(unz64_s*)file;
@@ -1319,14 +1198,11 @@
1198 file_pos->num_of_file = s->num_file;
1199
1200 return UNZ_OK;
1201 }
1202
1203 extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos* file_pos) {
 
 
 
1204 unz64_file_pos file_pos64;
1205 int err = unzGetFilePos64(file,&file_pos64);
1206 if (err==UNZ_OK)
1207 {
1208 file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
@@ -1333,12 +1209,11 @@
1209 file_pos->num_of_file = (uLong)file_pos64.num_of_file;
1210 }
1211 return err;
1212 }
1213
1214 extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) {
 
1215 unz64_s* s;
1216 int err;
1217
1218 if (file==NULL || file_pos==NULL)
1219 return UNZ_PARAMERROR;
@@ -1355,14 +1230,11 @@
1230 /* return results */
1231 s->current_file_ok = (err == UNZ_OK);
1232 return err;
1233 }
1234
1235 extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos* file_pos) {
 
 
 
1236 unz64_file_pos file_pos64;
1237 if (file_pos == NULL)
1238 return UNZ_PARAMERROR;
1239
1240 file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
@@ -1380,14 +1252,13 @@
1252 Check the coherency of the local header and info in the end of central
1253 directory about this file
1254 store in *piSizeVar the size of extra info in local header
1255 (filename and size of extra field data)
1256 */
1257 local int unz64local_CheckCurrentFileCoherencyHeader(unz64_s* s, uInt* piSizeVar,
1258 ZPOS64_T * poffset_local_extrafield,
1259 uInt * psize_local_extrafield) {
 
1260 uLong uMagic,uData,uFlags;
1261 uLong size_filename;
1262 uLong size_extra_field;
1263 int err=UNZ_OK;
1264
@@ -1467,13 +1338,12 @@
1338
1339 /*
1340 Open for reading data the current file in the zipfile.
1341 If there is no error and the file is opened, the return value is UNZ_OK.
1342 */
1343 extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method,
1344 int* level, int raw, const char* password) {
 
1345 int err=UNZ_OK;
1346 uInt iSizeVar;
1347 unz64_s* s;
1348 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1349 ZPOS64_T offset_local_extrafield; /* offset of the local extra field */
@@ -1507,11 +1377,11 @@
1377 pfile_in_zip_read_info->pos_local_extrafield=0;
1378 pfile_in_zip_read_info->raw=raw;
1379
1380 if (pfile_in_zip_read_info->read_buffer==NULL)
1381 {
1382 free(pfile_in_zip_read_info);
1383 return UNZ_INTERNALERROR;
1384 }
1385
1386 pfile_in_zip_read_info->stream_initialised=0;
1387
@@ -1564,12 +1434,12 @@
1434 err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
1435 if (err == Z_OK)
1436 pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
1437 else
1438 {
1439 free(pfile_in_zip_read_info->read_buffer);
1440 free(pfile_in_zip_read_info);
1441 return err;
1442 }
1443 #else
1444 pfile_in_zip_read_info->raw=1;
1445 #endif
@@ -1585,12 +1455,12 @@
1455 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1456 if (err == Z_OK)
1457 pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
1458 else
1459 {
1460 free(pfile_in_zip_read_info->read_buffer);
1461 free(pfile_in_zip_read_info);
1462 return err;
1463 }
1464 /* windowBits is passed < 0 to tell that there is no zlib header.
1465 * Note that in this case inflate *requires* an extra "dummy" byte
1466 * after the compressed stream in order to complete decompression and
@@ -1638,29 +1508,25 @@
1508
1509
1510 return UNZ_OK;
1511 }
1512
1513 extern int ZEXPORT unzOpenCurrentFile(unzFile file) {
 
1514 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1515 }
1516
1517 extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char* password) {
 
1518 return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1519 }
1520
1521 extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int* method, int* level, int raw) {
 
1522 return unzOpenCurrentFile3(file, method, level, raw, NULL);
1523 }
1524
1525 /** Addition for GDAL : START */
1526
1527 extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file) {
 
1528 unz64_s* s;
1529 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1530 s=(unz64_s*)file;
1531 if (file==NULL)
1532 return 0; //UNZ_PARAMERROR;
@@ -1676,17 +1542,16 @@
1542 /*
1543 Read bytes from the current file.
1544 buf contain buffer where data must be copied
1545 len the size of buf.
1546
1547 return the number of byte copied if some bytes are copied
1548 return 0 if the end of file was reached
1549 return <0 with error code if there is an error
1550 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
1551 */
1552 extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len) {
 
1553 int err=UNZ_OK;
1554 uInt iRead = 0;
1555 unz64_s* s;
1556 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1557 if (file==NULL)
@@ -1889,12 +1754,11 @@
1754
1755
1756 /*
1757 Give the current position in uncompressed data
1758 */
1759 extern z_off_t ZEXPORT unztell(unzFile file) {
 
1760 unz64_s* s;
1761 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1762 if (file==NULL)
1763 return UNZ_PARAMERROR;
1764 s=(unz64_s*)file;
@@ -1904,12 +1768,11 @@
1768 return UNZ_PARAMERROR;
1769
1770 return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1771 }
1772
1773 extern ZPOS64_T ZEXPORT unztell64(unzFile file) {
 
1774
1775 unz64_s* s;
1776 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1777 if (file==NULL)
1778 return (ZPOS64_T)-1;
@@ -1924,12 +1787,11 @@
1787
1788
1789 /*
1790 return 1 if the end of file was reached, 0 elsewhere
1791 */
1792 extern int ZEXPORT unzeof(unzFile file) {
 
1793 unz64_s* s;
1794 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1795 if (file==NULL)
1796 return UNZ_PARAMERROR;
1797 s=(unz64_s*)file;
@@ -1956,12 +1818,11 @@
1818 if buf!=NULL, len is the size of the buffer, the extra header is copied in
1819 buf.
1820 the return value is the number of bytes copied in buf, or (if <0)
1821 the error code
1822 */
1823 extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len) {
 
1824 unz64_s* s;
1825 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1826 uInt read_now;
1827 ZPOS64_T size_to_read;
1828
@@ -2004,12 +1865,11 @@
1865
1866 /*
1867 Close the file in zip opened with unzOpenCurrentFile
1868 Return UNZ_CRCERROR if all the file was read but the CRC is not good
1869 */
1870 extern int ZEXPORT unzCloseCurrentFile(unzFile file) {
 
1871 int err=UNZ_OK;
1872
1873 unz64_s* s;
1874 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1875 if (file==NULL)
@@ -2027,11 +1887,11 @@
1887 if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
1888 err=UNZ_CRCERROR;
1889 }
1890
1891
1892 free(pfile_in_zip_read_info->read_buffer);
1893 pfile_in_zip_read_info->read_buffer = NULL;
1894 if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
1895 inflateEnd(&pfile_in_zip_read_info->stream);
1896 #ifdef HAVE_BZIP2
1897 else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
@@ -2038,11 +1898,11 @@
1898 BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
1899 #endif
1900
1901
1902 pfile_in_zip_read_info->stream_initialised = 0;
1903 free(pfile_in_zip_read_info);
1904
1905 s->pfile_in_zip_read=NULL;
1906
1907 return err;
1908 }
@@ -2051,12 +1911,11 @@
1911 /*
1912 Get the global comment string of the ZipFile, in the szComment buffer.
1913 uSizeBuf is the size of the szComment buffer.
1914 return the number of byte copied or an error code <0
1915 */
1916 extern int ZEXPORT unzGetGlobalComment(unzFile file, char * szComment, uLong uSizeBuf) {
 
1917 unz64_s* s;
1918 uLong uReadThis ;
1919 if (file==NULL)
1920 return (int)UNZ_PARAMERROR;
1921 s=(unz64_s*)file;
@@ -2079,12 +1938,11 @@
1938 *(szComment+s->gi.size_comment)='\0';
1939 return (int)uReadThis;
1940 }
1941
1942 /* Additions by RX '2004 */
1943 extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) {
 
1944 unz64_s* s;
1945
1946 if (file==NULL)
1947 return 0; //UNZ_PARAMERROR;
1948 s=(unz64_s*)file;
@@ -2094,22 +1952,20 @@
1952 if (s->num_file==s->gi.number_entry)
1953 return 0;
1954 return s->pos_in_central_dir;
1955 }
1956
1957 extern uLong ZEXPORT unzGetOffset(unzFile file) {
 
1958 ZPOS64_T offset64;
1959
1960 if (file==NULL)
1961 return 0; //UNZ_PARAMERROR;
1962 offset64 = unzGetOffset64(file);
1963 return (uLong)offset64;
1964 }
1965
1966 extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) {
 
1967 unz64_s* s;
1968 int err;
1969
1970 if (file==NULL)
1971 return UNZ_PARAMERROR;
@@ -2122,9 +1978,8 @@
1978 NULL,0,NULL,0,NULL,0);
1979 s->current_file_ok = (err == UNZ_OK);
1980 return err;
1981 }
1982
1983 extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) {
 
1984 return unzSetOffset64(file,pos);
1985 }
1986
--- compat/zlib/contrib/minizip/unzip.h
+++ compat/zlib/contrib/minizip/unzip.h
@@ -148,25 +148,25 @@
148148
uLong external_fa; /* external file attributes 4 bytes */
149149
150150
tm_unz tmu_date;
151151
} unz_file_info;
152152
153
-extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
154
- const char* fileName2,
155
- int iCaseSensitivity));
153
+extern int ZEXPORT unzStringFileNameCompare(const char* fileName1,
154
+ const char* fileName2,
155
+ int iCaseSensitivity);
156156
/*
157
- Compare two filename (fileName1,fileName2).
158
- If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
159
- If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
157
+ Compare two filenames (fileName1,fileName2).
158
+ If iCaseSensitivity = 1, comparison is case sensitive (like strcmp)
159
+ If iCaseSensitivity = 2, comparison is not case sensitive (like strcmpi
160160
or strcasecmp)
161
- If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
161
+ If iCaseSensitivity = 0, case sensitivity is default of your operating system
162162
(like 1 on Unix, 2 on Windows)
163163
*/
164164
165165
166
-extern unzFile ZEXPORT unzOpen OF((const char *path));
167
-extern unzFile ZEXPORT unzOpen64 OF((const void *path));
166
+extern unzFile ZEXPORT unzOpen(const char *path);
167
+extern unzFile ZEXPORT unzOpen64(const void *path);
168168
/*
169169
Open a Zip file. path contain the full pathname (by example,
170170
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
171171
"zlib/zlib113.zip".
172172
If the zipfile cannot be opened (file don't exist or in not valid), the
@@ -179,45 +179,45 @@
179179
is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
180180
does not describe the reality
181181
*/
182182
183183
184
-extern unzFile ZEXPORT unzOpen2 OF((const char *path,
185
- zlib_filefunc_def* pzlib_filefunc_def));
184
+extern unzFile ZEXPORT unzOpen2(const char *path,
185
+ zlib_filefunc_def* pzlib_filefunc_def);
186186
/*
187187
Open a Zip file, like unzOpen, but provide a set of file low level API
188188
for read/write the zip file (see ioapi.h)
189189
*/
190190
191
-extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
192
- zlib_filefunc64_def* pzlib_filefunc_def));
191
+extern unzFile ZEXPORT unzOpen2_64(const void *path,
192
+ zlib_filefunc64_def* pzlib_filefunc_def);
193193
/*
194194
Open a Zip file, like unz64Open, but provide a set of file low level API
195195
for read/write the zip file (see ioapi.h)
196196
*/
197197
198
-extern int ZEXPORT unzClose OF((unzFile file));
198
+extern int ZEXPORT unzClose(unzFile file);
199199
/*
200200
Close a ZipFile opened with unzOpen.
201201
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
202202
these files MUST be closed with unzCloseCurrentFile before call unzClose.
203203
return UNZ_OK if there is no problem. */
204204
205
-extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
206
- unz_global_info *pglobal_info));
205
+extern int ZEXPORT unzGetGlobalInfo(unzFile file,
206
+ unz_global_info *pglobal_info);
207207
208
-extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
209
- unz_global_info64 *pglobal_info));
208
+extern int ZEXPORT unzGetGlobalInfo64(unzFile file,
209
+ unz_global_info64 *pglobal_info);
210210
/*
211211
Write info about the ZipFile in the *pglobal_info structure.
212212
No preparation of the structure is needed
213213
return UNZ_OK if there is no problem. */
214214
215215
216
-extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
217
- char *szComment,
218
- uLong uSizeBuf));
216
+extern int ZEXPORT unzGetGlobalComment(unzFile file,
217
+ char *szComment,
218
+ uLong uSizeBuf);
219219
/*
220220
Get the global comment string of the ZipFile, in the szComment buffer.
221221
uSizeBuf is the size of the szComment buffer.
222222
return the number of byte copied or an error code <0
223223
*/
@@ -224,26 +224,26 @@
224224
225225
226226
/***************************************************************************/
227227
/* Unzip package allow you browse the directory of the zipfile */
228228
229
-extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
229
+extern int ZEXPORT unzGoToFirstFile(unzFile file);
230230
/*
231231
Set the current file of the zipfile to the first file.
232232
return UNZ_OK if there is no problem
233233
*/
234234
235
-extern int ZEXPORT unzGoToNextFile OF((unzFile file));
235
+extern int ZEXPORT unzGoToNextFile(unzFile file);
236236
/*
237237
Set the current file of the zipfile to the next file.
238238
return UNZ_OK if there is no problem
239239
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
240240
*/
241241
242
-extern int ZEXPORT unzLocateFile OF((unzFile file,
243
- const char *szFileName,
244
- int iCaseSensitivity));
242
+extern int ZEXPORT unzLocateFile(unzFile file,
243
+ const char *szFileName,
244
+ int iCaseSensitivity);
245245
/*
246246
Try locate the file szFileName in the zipfile.
247247
For the iCaseSensitivity signification, see unzStringFileNameCompare
248248
249249
return value :
@@ -283,30 +283,30 @@
283283
unzFile file,
284284
const unz64_file_pos* file_pos);
285285
286286
/* ****************************************** */
287287
288
-extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
289
- unz_file_info64 *pfile_info,
290
- char *szFileName,
291
- uLong fileNameBufferSize,
292
- void *extraField,
293
- uLong extraFieldBufferSize,
294
- char *szComment,
295
- uLong commentBufferSize));
296
-
297
-extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
298
- unz_file_info *pfile_info,
299
- char *szFileName,
300
- uLong fileNameBufferSize,
301
- void *extraField,
302
- uLong extraFieldBufferSize,
303
- char *szComment,
304
- uLong commentBufferSize));
288
+extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file,
289
+ unz_file_info64 *pfile_info,
290
+ char *szFileName,
291
+ uLong fileNameBufferSize,
292
+ void *extraField,
293
+ uLong extraFieldBufferSize,
294
+ char *szComment,
295
+ uLong commentBufferSize);
296
+
297
+extern int ZEXPORT unzGetCurrentFileInfo(unzFile file,
298
+ unz_file_info *pfile_info,
299
+ char *szFileName,
300
+ uLong fileNameBufferSize,
301
+ void *extraField,
302
+ uLong extraFieldBufferSize,
303
+ char *szComment,
304
+ uLong commentBufferSize);
305305
/*
306306
Get Info about the current file
307
- if pfile_info!=NULL, the *pfile_info structure will contain somes info about
307
+ if pfile_info!=NULL, the *pfile_info structure will contain some info about
308308
the current file
309309
if szFileName!=NULL, the filemane string will be copied in szFileName
310310
(fileNameBufferSize is the size of the buffer)
311311
if extraField!=NULL, the extra field information will be copied in extraField
312312
(extraFieldBufferSize is the size of the buffer).
@@ -316,52 +316,52 @@
316316
*/
317317
318318
319319
/** Addition for GDAL : START */
320320
321
-extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
321
+extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file);
322322
323323
/** Addition for GDAL : END */
324324
325325
326326
/***************************************************************************/
327327
/* for reading the content of the current zipfile, you can open it, read data
328328
from it, and close it (you can close it before reading all the file)
329329
*/
330330
331
-extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
331
+extern int ZEXPORT unzOpenCurrentFile(unzFile file);
332332
/*
333333
Open for reading data the current file in the zipfile.
334334
If there is no error, the return value is UNZ_OK.
335335
*/
336336
337
-extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
338
- const char* password));
337
+extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file,
338
+ const char* password);
339339
/*
340340
Open for reading data the current file in the zipfile.
341341
password is a crypting password
342342
If there is no error, the return value is UNZ_OK.
343343
*/
344344
345
-extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
346
- int* method,
347
- int* level,
348
- int raw));
345
+extern int ZEXPORT unzOpenCurrentFile2(unzFile file,
346
+ int* method,
347
+ int* level,
348
+ int raw);
349349
/*
350350
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
351351
if raw==1
352352
*method will receive method of compression, *level will receive level of
353353
compression
354354
note : you can set level parameter as NULL (if you did not want known level,
355355
but you CANNOT set method parameter as NULL
356356
*/
357357
358
-extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
359
- int* method,
360
- int* level,
361
- int raw,
362
- const char* password));
358
+extern int ZEXPORT unzOpenCurrentFile3(unzFile file,
359
+ int* method,
360
+ int* level,
361
+ int raw,
362
+ const char* password);
363363
/*
364364
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
365365
if raw==1
366366
*method will receive method of compression, *level will receive level of
367367
compression
@@ -368,45 +368,45 @@
368368
note : you can set level parameter as NULL (if you did not want known level,
369369
but you CANNOT set method parameter as NULL
370370
*/
371371
372372
373
-extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
373
+extern int ZEXPORT unzCloseCurrentFile(unzFile file);
374374
/*
375375
Close the file in zip opened with unzOpenCurrentFile
376376
Return UNZ_CRCERROR if all the file was read but the CRC is not good
377377
*/
378378
379
-extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
380
- voidp buf,
381
- unsigned len));
379
+extern int ZEXPORT unzReadCurrentFile(unzFile file,
380
+ voidp buf,
381
+ unsigned len);
382382
/*
383383
Read bytes from the current file (opened by unzOpenCurrentFile)
384384
buf contain buffer where data must be copied
385385
len the size of buf.
386386
387
- return the number of byte copied if somes bytes are copied
387
+ return the number of byte copied if some bytes are copied
388388
return 0 if the end of file was reached
389389
return <0 with error code if there is an error
390390
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
391391
*/
392392
393
-extern z_off_t ZEXPORT unztell OF((unzFile file));
393
+extern z_off_t ZEXPORT unztell(unzFile file);
394394
395
-extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
395
+extern ZPOS64_T ZEXPORT unztell64(unzFile file);
396396
/*
397397
Give the current position in uncompressed data
398398
*/
399399
400
-extern int ZEXPORT unzeof OF((unzFile file));
400
+extern int ZEXPORT unzeof(unzFile file);
401401
/*
402402
return 1 if the end of file was reached, 0 elsewhere
403403
*/
404404
405
-extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
406
- voidp buf,
407
- unsigned len));
405
+extern int ZEXPORT unzGetLocalExtrafield(unzFile file,
406
+ voidp buf,
407
+ unsigned len);
408408
/*
409409
Read extra field from the current file (opened by unzOpenCurrentFile)
410410
This is the local-header version of the extra field (sometimes, there is
411411
more info in the local-header version than in the central-header)
412412
413413
--- compat/zlib/contrib/minizip/unzip.h
+++ compat/zlib/contrib/minizip/unzip.h
@@ -148,25 +148,25 @@
148 uLong external_fa; /* external file attributes 4 bytes */
149
150 tm_unz tmu_date;
151 } unz_file_info;
152
153 extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
154 const char* fileName2,
155 int iCaseSensitivity));
156 /*
157 Compare two filename (fileName1,fileName2).
158 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
159 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
160 or strcasecmp)
161 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
162 (like 1 on Unix, 2 on Windows)
163 */
164
165
166 extern unzFile ZEXPORT unzOpen OF((const char *path));
167 extern unzFile ZEXPORT unzOpen64 OF((const void *path));
168 /*
169 Open a Zip file. path contain the full pathname (by example,
170 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
171 "zlib/zlib113.zip".
172 If the zipfile cannot be opened (file don't exist or in not valid), the
@@ -179,45 +179,45 @@
179 is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
180 does not describe the reality
181 */
182
183
184 extern unzFile ZEXPORT unzOpen2 OF((const char *path,
185 zlib_filefunc_def* pzlib_filefunc_def));
186 /*
187 Open a Zip file, like unzOpen, but provide a set of file low level API
188 for read/write the zip file (see ioapi.h)
189 */
190
191 extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
192 zlib_filefunc64_def* pzlib_filefunc_def));
193 /*
194 Open a Zip file, like unz64Open, but provide a set of file low level API
195 for read/write the zip file (see ioapi.h)
196 */
197
198 extern int ZEXPORT unzClose OF((unzFile file));
199 /*
200 Close a ZipFile opened with unzOpen.
201 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
202 these files MUST be closed with unzCloseCurrentFile before call unzClose.
203 return UNZ_OK if there is no problem. */
204
205 extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
206 unz_global_info *pglobal_info));
207
208 extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
209 unz_global_info64 *pglobal_info));
210 /*
211 Write info about the ZipFile in the *pglobal_info structure.
212 No preparation of the structure is needed
213 return UNZ_OK if there is no problem. */
214
215
216 extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
217 char *szComment,
218 uLong uSizeBuf));
219 /*
220 Get the global comment string of the ZipFile, in the szComment buffer.
221 uSizeBuf is the size of the szComment buffer.
222 return the number of byte copied or an error code <0
223 */
@@ -224,26 +224,26 @@
224
225
226 /***************************************************************************/
227 /* Unzip package allow you browse the directory of the zipfile */
228
229 extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
230 /*
231 Set the current file of the zipfile to the first file.
232 return UNZ_OK if there is no problem
233 */
234
235 extern int ZEXPORT unzGoToNextFile OF((unzFile file));
236 /*
237 Set the current file of the zipfile to the next file.
238 return UNZ_OK if there is no problem
239 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
240 */
241
242 extern int ZEXPORT unzLocateFile OF((unzFile file,
243 const char *szFileName,
244 int iCaseSensitivity));
245 /*
246 Try locate the file szFileName in the zipfile.
247 For the iCaseSensitivity signification, see unzStringFileNameCompare
248
249 return value :
@@ -283,30 +283,30 @@
283 unzFile file,
284 const unz64_file_pos* file_pos);
285
286 /* ****************************************** */
287
288 extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
289 unz_file_info64 *pfile_info,
290 char *szFileName,
291 uLong fileNameBufferSize,
292 void *extraField,
293 uLong extraFieldBufferSize,
294 char *szComment,
295 uLong commentBufferSize));
296
297 extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
298 unz_file_info *pfile_info,
299 char *szFileName,
300 uLong fileNameBufferSize,
301 void *extraField,
302 uLong extraFieldBufferSize,
303 char *szComment,
304 uLong commentBufferSize));
305 /*
306 Get Info about the current file
307 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
308 the current file
309 if szFileName!=NULL, the filemane string will be copied in szFileName
310 (fileNameBufferSize is the size of the buffer)
311 if extraField!=NULL, the extra field information will be copied in extraField
312 (extraFieldBufferSize is the size of the buffer).
@@ -316,52 +316,52 @@
316 */
317
318
319 /** Addition for GDAL : START */
320
321 extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
322
323 /** Addition for GDAL : END */
324
325
326 /***************************************************************************/
327 /* for reading the content of the current zipfile, you can open it, read data
328 from it, and close it (you can close it before reading all the file)
329 */
330
331 extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
332 /*
333 Open for reading data the current file in the zipfile.
334 If there is no error, the return value is UNZ_OK.
335 */
336
337 extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
338 const char* password));
339 /*
340 Open for reading data the current file in the zipfile.
341 password is a crypting password
342 If there is no error, the return value is UNZ_OK.
343 */
344
345 extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
346 int* method,
347 int* level,
348 int raw));
349 /*
350 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
351 if raw==1
352 *method will receive method of compression, *level will receive level of
353 compression
354 note : you can set level parameter as NULL (if you did not want known level,
355 but you CANNOT set method parameter as NULL
356 */
357
358 extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
359 int* method,
360 int* level,
361 int raw,
362 const char* password));
363 /*
364 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
365 if raw==1
366 *method will receive method of compression, *level will receive level of
367 compression
@@ -368,45 +368,45 @@
368 note : you can set level parameter as NULL (if you did not want known level,
369 but you CANNOT set method parameter as NULL
370 */
371
372
373 extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
374 /*
375 Close the file in zip opened with unzOpenCurrentFile
376 Return UNZ_CRCERROR if all the file was read but the CRC is not good
377 */
378
379 extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
380 voidp buf,
381 unsigned len));
382 /*
383 Read bytes from the current file (opened by unzOpenCurrentFile)
384 buf contain buffer where data must be copied
385 len the size of buf.
386
387 return the number of byte copied if somes bytes are copied
388 return 0 if the end of file was reached
389 return <0 with error code if there is an error
390 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
391 */
392
393 extern z_off_t ZEXPORT unztell OF((unzFile file));
394
395 extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
396 /*
397 Give the current position in uncompressed data
398 */
399
400 extern int ZEXPORT unzeof OF((unzFile file));
401 /*
402 return 1 if the end of file was reached, 0 elsewhere
403 */
404
405 extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
406 voidp buf,
407 unsigned len));
408 /*
409 Read extra field from the current file (opened by unzOpenCurrentFile)
410 This is the local-header version of the extra field (sometimes, there is
411 more info in the local-header version than in the central-header)
412
413
--- compat/zlib/contrib/minizip/unzip.h
+++ compat/zlib/contrib/minizip/unzip.h
@@ -148,25 +148,25 @@
148 uLong external_fa; /* external file attributes 4 bytes */
149
150 tm_unz tmu_date;
151 } unz_file_info;
152
153 extern int ZEXPORT unzStringFileNameCompare(const char* fileName1,
154 const char* fileName2,
155 int iCaseSensitivity);
156 /*
157 Compare two filenames (fileName1,fileName2).
158 If iCaseSensitivity = 1, comparison is case sensitive (like strcmp)
159 If iCaseSensitivity = 2, comparison is not case sensitive (like strcmpi
160 or strcasecmp)
161 If iCaseSensitivity = 0, case sensitivity is default of your operating system
162 (like 1 on Unix, 2 on Windows)
163 */
164
165
166 extern unzFile ZEXPORT unzOpen(const char *path);
167 extern unzFile ZEXPORT unzOpen64(const void *path);
168 /*
169 Open a Zip file. path contain the full pathname (by example,
170 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
171 "zlib/zlib113.zip".
172 If the zipfile cannot be opened (file don't exist or in not valid), the
@@ -179,45 +179,45 @@
179 is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
180 does not describe the reality
181 */
182
183
184 extern unzFile ZEXPORT unzOpen2(const char *path,
185 zlib_filefunc_def* pzlib_filefunc_def);
186 /*
187 Open a Zip file, like unzOpen, but provide a set of file low level API
188 for read/write the zip file (see ioapi.h)
189 */
190
191 extern unzFile ZEXPORT unzOpen2_64(const void *path,
192 zlib_filefunc64_def* pzlib_filefunc_def);
193 /*
194 Open a Zip file, like unz64Open, but provide a set of file low level API
195 for read/write the zip file (see ioapi.h)
196 */
197
198 extern int ZEXPORT unzClose(unzFile file);
199 /*
200 Close a ZipFile opened with unzOpen.
201 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
202 these files MUST be closed with unzCloseCurrentFile before call unzClose.
203 return UNZ_OK if there is no problem. */
204
205 extern int ZEXPORT unzGetGlobalInfo(unzFile file,
206 unz_global_info *pglobal_info);
207
208 extern int ZEXPORT unzGetGlobalInfo64(unzFile file,
209 unz_global_info64 *pglobal_info);
210 /*
211 Write info about the ZipFile in the *pglobal_info structure.
212 No preparation of the structure is needed
213 return UNZ_OK if there is no problem. */
214
215
216 extern int ZEXPORT unzGetGlobalComment(unzFile file,
217 char *szComment,
218 uLong uSizeBuf);
219 /*
220 Get the global comment string of the ZipFile, in the szComment buffer.
221 uSizeBuf is the size of the szComment buffer.
222 return the number of byte copied or an error code <0
223 */
@@ -224,26 +224,26 @@
224
225
226 /***************************************************************************/
227 /* Unzip package allow you browse the directory of the zipfile */
228
229 extern int ZEXPORT unzGoToFirstFile(unzFile file);
230 /*
231 Set the current file of the zipfile to the first file.
232 return UNZ_OK if there is no problem
233 */
234
235 extern int ZEXPORT unzGoToNextFile(unzFile file);
236 /*
237 Set the current file of the zipfile to the next file.
238 return UNZ_OK if there is no problem
239 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
240 */
241
242 extern int ZEXPORT unzLocateFile(unzFile file,
243 const char *szFileName,
244 int iCaseSensitivity);
245 /*
246 Try locate the file szFileName in the zipfile.
247 For the iCaseSensitivity signification, see unzStringFileNameCompare
248
249 return value :
@@ -283,30 +283,30 @@
283 unzFile file,
284 const unz64_file_pos* file_pos);
285
286 /* ****************************************** */
287
288 extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file,
289 unz_file_info64 *pfile_info,
290 char *szFileName,
291 uLong fileNameBufferSize,
292 void *extraField,
293 uLong extraFieldBufferSize,
294 char *szComment,
295 uLong commentBufferSize);
296
297 extern int ZEXPORT unzGetCurrentFileInfo(unzFile file,
298 unz_file_info *pfile_info,
299 char *szFileName,
300 uLong fileNameBufferSize,
301 void *extraField,
302 uLong extraFieldBufferSize,
303 char *szComment,
304 uLong commentBufferSize);
305 /*
306 Get Info about the current file
307 if pfile_info!=NULL, the *pfile_info structure will contain some info about
308 the current file
309 if szFileName!=NULL, the filemane string will be copied in szFileName
310 (fileNameBufferSize is the size of the buffer)
311 if extraField!=NULL, the extra field information will be copied in extraField
312 (extraFieldBufferSize is the size of the buffer).
@@ -316,52 +316,52 @@
316 */
317
318
319 /** Addition for GDAL : START */
320
321 extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file);
322
323 /** Addition for GDAL : END */
324
325
326 /***************************************************************************/
327 /* for reading the content of the current zipfile, you can open it, read data
328 from it, and close it (you can close it before reading all the file)
329 */
330
331 extern int ZEXPORT unzOpenCurrentFile(unzFile file);
332 /*
333 Open for reading data the current file in the zipfile.
334 If there is no error, the return value is UNZ_OK.
335 */
336
337 extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file,
338 const char* password);
339 /*
340 Open for reading data the current file in the zipfile.
341 password is a crypting password
342 If there is no error, the return value is UNZ_OK.
343 */
344
345 extern int ZEXPORT unzOpenCurrentFile2(unzFile file,
346 int* method,
347 int* level,
348 int raw);
349 /*
350 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
351 if raw==1
352 *method will receive method of compression, *level will receive level of
353 compression
354 note : you can set level parameter as NULL (if you did not want known level,
355 but you CANNOT set method parameter as NULL
356 */
357
358 extern int ZEXPORT unzOpenCurrentFile3(unzFile file,
359 int* method,
360 int* level,
361 int raw,
362 const char* password);
363 /*
364 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
365 if raw==1
366 *method will receive method of compression, *level will receive level of
367 compression
@@ -368,45 +368,45 @@
368 note : you can set level parameter as NULL (if you did not want known level,
369 but you CANNOT set method parameter as NULL
370 */
371
372
373 extern int ZEXPORT unzCloseCurrentFile(unzFile file);
374 /*
375 Close the file in zip opened with unzOpenCurrentFile
376 Return UNZ_CRCERROR if all the file was read but the CRC is not good
377 */
378
379 extern int ZEXPORT unzReadCurrentFile(unzFile file,
380 voidp buf,
381 unsigned len);
382 /*
383 Read bytes from the current file (opened by unzOpenCurrentFile)
384 buf contain buffer where data must be copied
385 len the size of buf.
386
387 return the number of byte copied if some bytes are copied
388 return 0 if the end of file was reached
389 return <0 with error code if there is an error
390 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
391 */
392
393 extern z_off_t ZEXPORT unztell(unzFile file);
394
395 extern ZPOS64_T ZEXPORT unztell64(unzFile file);
396 /*
397 Give the current position in uncompressed data
398 */
399
400 extern int ZEXPORT unzeof(unzFile file);
401 /*
402 return 1 if the end of file was reached, 0 elsewhere
403 */
404
405 extern int ZEXPORT unzGetLocalExtrafield(unzFile file,
406 voidp buf,
407 unsigned len);
408 /*
409 Read extra field from the current file (opened by unzOpenCurrentFile)
410 This is the local-header version of the extra field (sometimes, there is
411 more info in the local-header version than in the central-header)
412
413
--- compat/zlib/contrib/minizip/zip.c
+++ compat/zlib/contrib/minizip/zip.c
@@ -12,11 +12,11 @@
1212
Changes
1313
Oct-2009 - Mathias Svensson - Remove old C style function prototypes
1414
Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives
1515
Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions.
1616
Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data
17
- It is used when recreting zip archive with RAW when deleting items from a zip.
17
+ It is used when recreating zip archive with RAW when deleting items from a zip.
1818
ZIP64 data is automatically added to items that needs it, and existing ZIP64 data need to be removed.
1919
Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required)
2020
Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
2121
2222
*/
@@ -23,18 +23,17 @@
2323
2424
2525
#include <stdio.h>
2626
#include <stdlib.h>
2727
#include <string.h>
28
+#include <stdint.h>
2829
#include <time.h>
2930
#include "zlib.h"
3031
#include "zip.h"
3132
3233
#ifdef STDC
3334
# include <stddef.h>
34
-# include <string.h>
35
-# include <stdlib.h>
3635
#endif
3736
#ifdef NO_ERRNO_H
3837
extern int errno;
3938
#else
4039
# include <errno.h>
@@ -45,11 +44,11 @@
4544
# define local static
4645
#endif
4746
/* compile with -Dlocal if your debugger can't find static symbols */
4847
4948
#ifndef VERSIONMADEBY
50
-# define VERSIONMADEBY (0x0) /* platform depedent */
49
+# define VERSIONMADEBY (0x0) /* platform dependent */
5150
#endif
5251
5352
#ifndef Z_BUFSIZE
5453
#define Z_BUFSIZE (64*1024) //(16384)
5554
#endif
@@ -59,13 +58,10 @@
5958
#endif
6059
6160
#ifndef ALLOC
6261
# define ALLOC(size) (malloc(size))
6362
#endif
64
-#ifndef TRYFREE
65
-# define TRYFREE(p) {if (p) free(p);}
66
-#endif
6763
6864
/*
6965
#define SIZECENTRALDIRITEM (0x2e)
7066
#define SIZEZIPLOCALHEADER (0x1e)
7167
*/
@@ -136,24 +132,24 @@
136132
137133
int stream_initialised; /* 1 is stream is initialised */
138134
uInt pos_in_buffered_data; /* last written byte in buffered_data */
139135
140136
ZPOS64_T pos_local_header; /* offset of the local header of the file
141
- currenty writing */
137
+ currently writing */
142138
char* central_header; /* central header data for the current file */
143139
uLong size_centralExtra;
144140
uLong size_centralheader; /* size of the central header for cur file */
145141
uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */
146142
uLong flag; /* flag of the file currently writing */
147143
148
- int method; /* compression method of file currenty wr.*/
144
+ int method; /* compression method of file currently wr.*/
149145
int raw; /* 1 for directly writing raw data */
150146
Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
151147
uLong dosDate;
152148
uLong crc32;
153149
int encrypt;
154
- int zip64; /* Add ZIP64 extened information in the extra field */
150
+ int zip64; /* Add ZIP64 extended information in the extra field */
155151
ZPOS64_T pos_zip64extrainfo;
156152
ZPOS64_T totalCompressedData;
157153
ZPOS64_T totalUncompressedData;
158154
#ifndef NOCRYPT
159155
unsigned long keys[3]; /* keys defining the pseudo-random sequence */
@@ -163,14 +159,14 @@
163159
} curfile64_info;
164160
165161
typedef struct
166162
{
167163
zlib_filefunc64_32_def z_filefunc;
168
- voidpf filestream; /* io structore of the zipfile */
164
+ voidpf filestream; /* io structure of the zipfile */
169165
linkedlist_data central_dir;/* datablock with central dir in construction*/
170166
int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
171
- curfile64_info ci; /* info on the file curretly writing */
167
+ curfile64_info ci; /* info on the file currently writing */
172168
173169
ZPOS64_T begin_pos; /* position of the beginning of the zipfile */
174170
ZPOS64_T add_position_when_writing_offset;
175171
ZPOS64_T number_entry;
176172
@@ -184,12 +180,11 @@
184180
#ifndef NOCRYPT
185181
#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
186182
#include "crypt.h"
187183
#endif
188184
189
-local linkedlist_datablock_internal* allocate_new_datablock()
190
-{
185
+local linkedlist_datablock_internal* allocate_new_datablock(void) {
191186
linkedlist_datablock_internal* ldi;
192187
ldi = (linkedlist_datablock_internal*)
193188
ALLOC(sizeof(linkedlist_datablock_internal));
194189
if (ldi!=NULL)
195190
{
@@ -198,34 +193,30 @@
198193
ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
199194
}
200195
return ldi;
201196
}
202197
203
-local void free_datablock(linkedlist_datablock_internal* ldi)
204
-{
198
+local void free_datablock(linkedlist_datablock_internal* ldi) {
205199
while (ldi!=NULL)
206200
{
207201
linkedlist_datablock_internal* ldinext = ldi->next_datablock;
208
- TRYFREE(ldi);
202
+ free(ldi);
209203
ldi = ldinext;
210204
}
211205
}
212206
213
-local void init_linkedlist(linkedlist_data* ll)
214
-{
207
+local void init_linkedlist(linkedlist_data* ll) {
215208
ll->first_block = ll->last_block = NULL;
216209
}
217210
218
-local void free_linkedlist(linkedlist_data* ll)
219
-{
211
+local void free_linkedlist(linkedlist_data* ll) {
220212
free_datablock(ll->first_block);
221213
ll->first_block = ll->last_block = NULL;
222214
}
223215
224216
225
-local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
226
-{
217
+local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) {
227218
linkedlist_datablock_internal* ldi;
228219
const unsigned char* from_copy;
229220
230221
if (ll==NULL)
231222
return ZIP_INTERNALERROR;
@@ -236,11 +227,11 @@
236227
if (ll->first_block == NULL)
237228
return ZIP_INTERNALERROR;
238229
}
239230
240231
ldi = ll->last_block;
241
- from_copy = (unsigned char*)buf;
232
+ from_copy = (const unsigned char*)buf;
242233
243234
while (len>0)
244235
{
245236
uInt copy_this;
246237
uInt i;
@@ -281,13 +272,11 @@
281272
/* ===========================================================================
282273
Inputs a long in LSB order to the given file
283274
nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T)
284275
*/
285276
286
-local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte));
287
-local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
288
-{
277
+local int zip64local_putValue(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte) {
289278
unsigned char buf[8];
290279
int n;
291280
for (n = 0; n < nbByte; n++)
292281
{
293282
buf[n] = (unsigned char)(x & 0xff);
@@ -305,13 +294,11 @@
305294
return ZIP_ERRNO;
306295
else
307296
return ZIP_OK;
308297
}
309298
310
-local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte));
311
-local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte)
312
-{
299
+local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte) {
313300
unsigned char* buf=(unsigned char*)dest;
314301
int n;
315302
for (n = 0; n < nbByte; n++) {
316303
buf[n] = (unsigned char)(x & 0xff);
317304
x >>= 8;
@@ -327,12 +314,11 @@
327314
}
328315
329316
/****************************************************************************/
330317
331318
332
-local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm)
333
-{
319
+local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm) {
334320
uLong year = (uLong)ptm->tm_year;
335321
if (year>=1980)
336322
year-=1980;
337323
else if (year>=80)
338324
year-=80;
@@ -342,14 +328,11 @@
342328
}
343329
344330
345331
/****************************************************************************/
346332
347
-local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi));
348
-
349
-local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi)
350
-{
333
+local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int* pi) {
351334
unsigned char c;
352335
int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
353336
if (err==1)
354337
{
355338
*pi = (int)c;
@@ -366,14 +349,11 @@
366349
367350
368351
/* ===========================================================================
369352
Reads a long in LSB order from the given gz_stream. Sets
370353
*/
371
-local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
372
-
373
-local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
374
-{
354
+local int zip64local_getShort(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) {
375355
uLong x ;
376356
int i = 0;
377357
int err;
378358
379359
err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
@@ -388,14 +368,11 @@
388368
else
389369
*pX = 0;
390370
return err;
391371
}
392372
393
-local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
394
-
395
-local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
396
-{
373
+local int zip64local_getLong(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) {
397374
uLong x ;
398375
int i = 0;
399376
int err;
400377
401378
err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
@@ -418,15 +395,12 @@
418395
else
419396
*pX = 0;
420397
return err;
421398
}
422399
423
-local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX));
424400
425
-
426
-local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
427
-{
401
+local int zip64local_getLong64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX) {
428402
ZPOS64_T x;
429403
int i = 0;
430404
int err;
431405
432406
err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
@@ -473,14 +447,11 @@
473447
#endif
474448
/*
475449
Locate the Central directory of a zipfile (at the end, just before
476450
the global comment)
477451
*/
478
-local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
479
-
480
-local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
481
-{
452
+local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) {
482453
unsigned char* buf;
483454
ZPOS64_T uSizeFile;
484455
ZPOS64_T uBackRead;
485456
ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
486457
ZPOS64_T uPosFound=0;
@@ -527,22 +498,19 @@
527498
}
528499
529500
if (uPosFound!=0)
530501
break;
531502
}
532
- TRYFREE(buf);
503
+ free(buf);
533504
return uPosFound;
534505
}
535506
536507
/*
537508
Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before
538509
the global comment)
539510
*/
540
-local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
541
-
542
-local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
543
-{
511
+local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) {
544512
unsigned char* buf;
545513
ZPOS64_T uSizeFile;
546514
ZPOS64_T uBackRead;
547515
ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
548516
ZPOS64_T uPosFound=0;
@@ -593,11 +561,11 @@
593561
594562
if (uPosFound!=0)
595563
break;
596564
}
597565
598
- TRYFREE(buf);
566
+ free(buf);
599567
if (uPosFound == 0)
600568
return 0;
601569
602570
/* Zip64 end of central directory locator */
603571
if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
@@ -635,24 +603,23 @@
635603
return 0;
636604
637605
return relativeOffset;
638606
}
639607
640
-local int LoadCentralDirectoryRecord(zip64_internal* pziinit)
641
-{
608
+local int LoadCentralDirectoryRecord(zip64_internal* pziinit) {
642609
int err=ZIP_OK;
643610
ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
644611
645612
ZPOS64_T size_central_dir; /* size of the central directory */
646613
ZPOS64_T offset_central_dir; /* offset of start of central directory */
647614
ZPOS64_T central_pos;
648615
uLong uL;
649616
650617
uLong number_disk; /* number of the current dist, used for
651
- spaning ZIP, unsupported, always 0*/
618
+ spanning ZIP, unsupported, always 0*/
652619
uLong number_disk_with_CD; /* number the the disk with central dir, used
653
- for spaning ZIP, unsupported, always 0*/
620
+ for spanning ZIP, unsupported, always 0*/
654621
ZPOS64_T number_entry;
655622
ZPOS64_T number_entry_CD; /* total number of entries in
656623
the central dir
657624
(same than number_entry on nospan) */
658625
uLong VersionMadeBy;
@@ -828,11 +795,11 @@
828795
if (err==ZIP_OK)
829796
err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);
830797
831798
size_central_dir_to_read-=read_this;
832799
}
833
- TRYFREE(buf_read);
800
+ free(buf_read);
834801
}
835802
pziinit->begin_pos = byte_before_the_zipfile;
836803
pziinit->number_entry = number_entry_CD;
837804
838805
if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
@@ -844,12 +811,11 @@
844811
845812
#endif /* !NO_ADDFILEINEXISTINGZIP*/
846813
847814
848815
/************************************************************/
849
-extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def)
850
-{
816
+extern zipFile ZEXPORT zipOpen3(const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def) {
851817
zip64_internal ziinit;
852818
zip64_internal* zi;
853819
int err=ZIP_OK;
854820
855821
ziinit.z_filefunc.zseek32_file = NULL;
@@ -903,24 +869,23 @@
903869
# endif /* !NO_ADDFILEINEXISTINGZIP*/
904870
905871
if (err != ZIP_OK)
906872
{
907873
# ifndef NO_ADDFILEINEXISTINGZIP
908
- TRYFREE(ziinit.globalcomment);
874
+ free(ziinit.globalcomment);
909875
# endif /* !NO_ADDFILEINEXISTINGZIP*/
910
- TRYFREE(zi);
876
+ free(zi);
911877
return NULL;
912878
}
913879
else
914880
{
915881
*zi = ziinit;
916882
return (zipFile)zi;
917883
}
918884
}
919885
920
-extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def)
921
-{
886
+extern zipFile ZEXPORT zipOpen2(const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def) {
922887
if (pzlib_filefunc32_def != NULL)
923888
{
924889
zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
925890
fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
926891
return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
@@ -927,12 +892,11 @@
927892
}
928893
else
929894
return zipOpen3(pathname, append, globalcomment, NULL);
930895
}
931896
932
-extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def)
933
-{
897
+extern zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def) {
934898
if (pzlib_filefunc_def != NULL)
935899
{
936900
zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
937901
zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
938902
zlib_filefunc64_32_def_fill.ztell32_file = NULL;
@@ -943,22 +907,19 @@
943907
return zipOpen3(pathname, append, globalcomment, NULL);
944908
}
945909
946910
947911
948
-extern zipFile ZEXPORT zipOpen (const char* pathname, int append)
949
-{
912
+extern zipFile ZEXPORT zipOpen(const char* pathname, int append) {
950913
return zipOpen3((const void*)pathname,append,NULL,NULL);
951914
}
952915
953
-extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append)
954
-{
916
+extern zipFile ZEXPORT zipOpen64(const void* pathname, int append) {
955917
return zipOpen3(pathname,append,NULL,NULL);
956918
}
957919
958
-local int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local)
959
-{
920
+local int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local) {
960921
/* write the local header */
961922
int err;
962923
uInt size_filename = (uInt)strlen(filename);
963924
uInt size_extrafield = size_extrafield_local;
964925
@@ -1050,18 +1011,17 @@
10501011
before calling this function it can be done with zipRemoveExtraInfoBlock
10511012
10521013
It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize
10531014
unnecessary allocations.
10541015
*/
1055
-extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1056
- const void* extrafield_local, uInt size_extrafield_local,
1057
- const void* extrafield_global, uInt size_extrafield_global,
1058
- const char* comment, int method, int level, int raw,
1059
- int windowBits,int memLevel, int strategy,
1060
- const char* password, uLong crcForCrypting,
1061
- uLong versionMadeBy, uLong flagBase, int zip64)
1062
-{
1016
+extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1017
+ const void* extrafield_local, uInt size_extrafield_local,
1018
+ const void* extrafield_global, uInt size_extrafield_global,
1019
+ const char* comment, int method, int level, int raw,
1020
+ int windowBits,int memLevel, int strategy,
1021
+ const char* password, uLong crcForCrypting,
1022
+ uLong versionMadeBy, uLong flagBase, int zip64) {
10631023
zip64_internal* zi;
10641024
uInt size_filename;
10651025
uInt size_comment;
10661026
uInt i;
10671027
int err = ZIP_OK;
@@ -1260,110 +1220,102 @@
12601220
if (err==Z_OK)
12611221
zi->in_opened_file_inzip = 1;
12621222
return err;
12631223
}
12641224
1265
-extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1266
- const void* extrafield_local, uInt size_extrafield_local,
1267
- const void* extrafield_global, uInt size_extrafield_global,
1268
- const char* comment, int method, int level, int raw,
1269
- int windowBits,int memLevel, int strategy,
1270
- const char* password, uLong crcForCrypting,
1271
- uLong versionMadeBy, uLong flagBase)
1272
-{
1273
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1274
- extrafield_local, size_extrafield_local,
1275
- extrafield_global, size_extrafield_global,
1276
- comment, method, level, raw,
1277
- windowBits, memLevel, strategy,
1278
- password, crcForCrypting, versionMadeBy, flagBase, 0);
1279
-}
1280
-
1281
-extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1282
- const void* extrafield_local, uInt size_extrafield_local,
1283
- const void* extrafield_global, uInt size_extrafield_global,
1284
- const char* comment, int method, int level, int raw,
1285
- int windowBits,int memLevel, int strategy,
1286
- const char* password, uLong crcForCrypting)
1287
-{
1288
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1289
- extrafield_local, size_extrafield_local,
1290
- extrafield_global, size_extrafield_global,
1291
- comment, method, level, raw,
1292
- windowBits, memLevel, strategy,
1293
- password, crcForCrypting, VERSIONMADEBY, 0, 0);
1225
+extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1226
+ const void* extrafield_local, uInt size_extrafield_local,
1227
+ const void* extrafield_global, uInt size_extrafield_global,
1228
+ const char* comment, int method, int level, int raw,
1229
+ int windowBits,int memLevel, int strategy,
1230
+ const char* password, uLong crcForCrypting,
1231
+ uLong versionMadeBy, uLong flagBase) {
1232
+ return zipOpenNewFileInZip4_64(file, filename, zipfi,
1233
+ extrafield_local, size_extrafield_local,
1234
+ extrafield_global, size_extrafield_global,
1235
+ comment, method, level, raw,
1236
+ windowBits, memLevel, strategy,
1237
+ password, crcForCrypting, versionMadeBy, flagBase, 0);
1238
+}
1239
+
1240
+extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1241
+ const void* extrafield_local, uInt size_extrafield_local,
1242
+ const void* extrafield_global, uInt size_extrafield_global,
1243
+ const char* comment, int method, int level, int raw,
1244
+ int windowBits,int memLevel, int strategy,
1245
+ const char* password, uLong crcForCrypting) {
1246
+ return zipOpenNewFileInZip4_64(file, filename, zipfi,
1247
+ extrafield_local, size_extrafield_local,
1248
+ extrafield_global, size_extrafield_global,
1249
+ comment, method, level, raw,
1250
+ windowBits, memLevel, strategy,
1251
+ password, crcForCrypting, VERSIONMADEBY, 0, 0);
12941252
}
12951253
12961254
extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
12971255
const void* extrafield_local, uInt size_extrafield_local,
12981256
const void* extrafield_global, uInt size_extrafield_global,
12991257
const char* comment, int method, int level, int raw,
13001258
int windowBits,int memLevel, int strategy,
1301
- const char* password, uLong crcForCrypting, int zip64)
1302
-{
1303
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1304
- extrafield_local, size_extrafield_local,
1305
- extrafield_global, size_extrafield_global,
1306
- comment, method, level, raw,
1307
- windowBits, memLevel, strategy,
1308
- password, crcForCrypting, VERSIONMADEBY, 0, zip64);
1259
+ const char* password, uLong crcForCrypting, int zip64) {
1260
+ return zipOpenNewFileInZip4_64(file, filename, zipfi,
1261
+ extrafield_local, size_extrafield_local,
1262
+ extrafield_global, size_extrafield_global,
1263
+ comment, method, level, raw,
1264
+ windowBits, memLevel, strategy,
1265
+ password, crcForCrypting, VERSIONMADEBY, 0, zip64);
13091266
}
13101267
13111268
extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi,
13121269
const void* extrafield_local, uInt size_extrafield_local,
13131270
const void* extrafield_global, uInt size_extrafield_global,
1314
- const char* comment, int method, int level, int raw)
1315
-{
1316
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1317
- extrafield_local, size_extrafield_local,
1318
- extrafield_global, size_extrafield_global,
1319
- comment, method, level, raw,
1320
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1321
- NULL, 0, VERSIONMADEBY, 0, 0);
1271
+ const char* comment, int method, int level, int raw) {
1272
+ return zipOpenNewFileInZip4_64(file, filename, zipfi,
1273
+ extrafield_local, size_extrafield_local,
1274
+ extrafield_global, size_extrafield_global,
1275
+ comment, method, level, raw,
1276
+ -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1277
+ NULL, 0, VERSIONMADEBY, 0, 0);
13221278
}
13231279
13241280
extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1325
- const void* extrafield_local, uInt size_extrafield_local,
1326
- const void* extrafield_global, uInt size_extrafield_global,
1327
- const char* comment, int method, int level, int raw, int zip64)
1328
-{
1329
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1330
- extrafield_local, size_extrafield_local,
1331
- extrafield_global, size_extrafield_global,
1332
- comment, method, level, raw,
1333
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1334
- NULL, 0, VERSIONMADEBY, 0, zip64);
1335
-}
1336
-
1337
-extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1338
- const void* extrafield_local, uInt size_extrafield_local,
1339
- const void*extrafield_global, uInt size_extrafield_global,
1340
- const char* comment, int method, int level, int zip64)
1341
-{
1342
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1343
- extrafield_local, size_extrafield_local,
1344
- extrafield_global, size_extrafield_global,
1345
- comment, method, level, 0,
1346
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1347
- NULL, 0, VERSIONMADEBY, 0, zip64);
1348
-}
1349
-
1350
-extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1351
- const void* extrafield_local, uInt size_extrafield_local,
1352
- const void*extrafield_global, uInt size_extrafield_global,
1353
- const char* comment, int method, int level)
1354
-{
1355
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1356
- extrafield_local, size_extrafield_local,
1357
- extrafield_global, size_extrafield_global,
1358
- comment, method, level, 0,
1359
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1360
- NULL, 0, VERSIONMADEBY, 0, 0);
1361
-}
1362
-
1363
-local int zip64FlushWriteBuffer(zip64_internal* zi)
1364
-{
1281
+ const void* extrafield_local, uInt size_extrafield_local,
1282
+ const void* extrafield_global, uInt size_extrafield_global,
1283
+ const char* comment, int method, int level, int raw, int zip64) {
1284
+ return zipOpenNewFileInZip4_64(file, filename, zipfi,
1285
+ extrafield_local, size_extrafield_local,
1286
+ extrafield_global, size_extrafield_global,
1287
+ comment, method, level, raw,
1288
+ -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1289
+ NULL, 0, VERSIONMADEBY, 0, zip64);
1290
+}
1291
+
1292
+extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1293
+ const void* extrafield_local, uInt size_extrafield_local,
1294
+ const void*extrafield_global, uInt size_extrafield_global,
1295
+ const char* comment, int method, int level, int zip64) {
1296
+ return zipOpenNewFileInZip4_64(file, filename, zipfi,
1297
+ extrafield_local, size_extrafield_local,
1298
+ extrafield_global, size_extrafield_global,
1299
+ comment, method, level, 0,
1300
+ -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1301
+ NULL, 0, VERSIONMADEBY, 0, zip64);
1302
+}
1303
+
1304
+extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1305
+ const void* extrafield_local, uInt size_extrafield_local,
1306
+ const void*extrafield_global, uInt size_extrafield_global,
1307
+ const char* comment, int method, int level) {
1308
+ return zipOpenNewFileInZip4_64(file, filename, zipfi,
1309
+ extrafield_local, size_extrafield_local,
1310
+ extrafield_global, size_extrafield_global,
1311
+ comment, method, level, 0,
1312
+ -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1313
+ NULL, 0, VERSIONMADEBY, 0, 0);
1314
+}
1315
+
1316
+local int zip64FlushWriteBuffer(zip64_internal* zi) {
13651317
int err=ZIP_OK;
13661318
13671319
if (zi->ci.encrypt != 0)
13681320
{
13691321
#ifndef NOCRYPT
@@ -1397,12 +1349,11 @@
13971349
zi->ci.pos_in_buffered_data = 0;
13981350
13991351
return err;
14001352
}
14011353
1402
-extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len)
1403
-{
1354
+extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void* buf, unsigned int len) {
14041355
zip64_internal* zi;
14051356
int err=ZIP_OK;
14061357
14071358
if (file == NULL)
14081359
return ZIP_PARAMERROR;
@@ -1448,11 +1399,11 @@
14481399
err = ZIP_OK;
14491400
}
14501401
else
14511402
#endif
14521403
{
1453
- zi->ci.stream.next_in = (Bytef*)buf;
1404
+ zi->ci.stream.next_in = (Bytef*)(uintptr_t)buf;
14541405
zi->ci.stream.avail_in = len;
14551406
14561407
while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
14571408
{
14581409
if (zi->ci.stream.avail_out == 0)
@@ -1499,17 +1450,15 @@
14991450
}
15001451
15011452
return err;
15021453
}
15031454
1504
-extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32)
1505
-{
1455
+extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uLong uncompressed_size, uLong crc32) {
15061456
return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
15071457
}
15081458
1509
-extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
1510
-{
1459
+extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_size, uLong crc32) {
15111460
zip64_internal* zi;
15121461
ZPOS64_T compressed_size;
15131462
uLong invalidValue = 0xffffffff;
15141463
unsigned datasize = 0;
15151464
int err=ZIP_OK;
@@ -1740,17 +1689,15 @@
17401689
zi->in_opened_file_inzip = 0;
17411690
17421691
return err;
17431692
}
17441693
1745
-extern int ZEXPORT zipCloseFileInZip (zipFile file)
1746
-{
1694
+extern int ZEXPORT zipCloseFileInZip(zipFile file) {
17471695
return zipCloseFileInZipRaw (file,0,0);
17481696
}
17491697
1750
-local int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip)
1751
-{
1698
+local int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip) {
17521699
int err = ZIP_OK;
17531700
ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writing_offset;
17541701
17551702
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4);
17561703
@@ -1767,12 +1714,11 @@
17671714
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4);
17681715
17691716
return err;
17701717
}
17711718
1772
-local int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
1773
-{
1719
+local int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) {
17741720
int err = ZIP_OK;
17751721
17761722
uLong Zip64DataSize = 44;
17771723
17781724
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4);
@@ -1806,12 +1752,12 @@
18061752
ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writing_offset;
18071753
err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8);
18081754
}
18091755
return err;
18101756
}
1811
-local int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
1812
-{
1757
+
1758
+local int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) {
18131759
int err = ZIP_OK;
18141760
18151761
/*signature*/
18161762
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
18171763
@@ -1854,12 +1800,11 @@
18541800
}
18551801
18561802
return err;
18571803
}
18581804
1859
-local int Write_GlobalComment(zip64_internal* zi, const char* global_comment)
1860
-{
1805
+local int Write_GlobalComment(zip64_internal* zi, const char* global_comment) {
18611806
int err = ZIP_OK;
18621807
uInt size_global_comment = 0;
18631808
18641809
if(global_comment != NULL)
18651810
size_global_comment = (uInt)strlen(global_comment);
@@ -1872,12 +1817,11 @@
18721817
err = ZIP_ERRNO;
18731818
}
18741819
return err;
18751820
}
18761821
1877
-extern int ZEXPORT zipClose (zipFile file, const char* global_comment)
1878
-{
1822
+extern int ZEXPORT zipClose(zipFile file, const char* global_comment) {
18791823
zip64_internal* zi;
18801824
int err = 0;
18811825
uLong size_centraldir = 0;
18821826
ZPOS64_T centraldir_pos_inzip;
18831827
ZPOS64_T pos;
@@ -1934,19 +1878,18 @@
19341878
if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0)
19351879
if (err == ZIP_OK)
19361880
err = ZIP_ERRNO;
19371881
19381882
#ifndef NO_ADDFILEINEXISTINGZIP
1939
- TRYFREE(zi->globalcomment);
1883
+ free(zi->globalcomment);
19401884
#endif
1941
- TRYFREE(zi);
1885
+ free(zi);
19421886
19431887
return err;
19441888
}
19451889
1946
-extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader)
1947
-{
1890
+extern int ZEXPORT zipRemoveExtraInfoBlock(char* pData, int* dataLen, short sHeader) {
19481891
char* p = pData;
19491892
int size = 0;
19501893
char* pNewHeader;
19511894
char* pTmp;
19521895
short header;
@@ -1994,9 +1937,9 @@
19941937
retVal = ZIP_OK;
19951938
}
19961939
else
19971940
retVal = ZIP_ERRNO;
19981941
1999
- TRYFREE(pNewHeader);
1942
+ free(pNewHeader);
20001943
20011944
return retVal;
20021945
}
20031946
--- compat/zlib/contrib/minizip/zip.c
+++ compat/zlib/contrib/minizip/zip.c
@@ -12,11 +12,11 @@
12 Changes
13 Oct-2009 - Mathias Svensson - Remove old C style function prototypes
14 Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives
15 Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions.
16 Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data
17 It is used when recreting zip archive with RAW when deleting items from a zip.
18 ZIP64 data is automatically added to items that needs it, and existing ZIP64 data need to be removed.
19 Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required)
20 Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
21
22 */
@@ -23,18 +23,17 @@
23
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
 
28 #include <time.h>
29 #include "zlib.h"
30 #include "zip.h"
31
32 #ifdef STDC
33 # include <stddef.h>
34 # include <string.h>
35 # include <stdlib.h>
36 #endif
37 #ifdef NO_ERRNO_H
38 extern int errno;
39 #else
40 # include <errno.h>
@@ -45,11 +44,11 @@
45 # define local static
46 #endif
47 /* compile with -Dlocal if your debugger can't find static symbols */
48
49 #ifndef VERSIONMADEBY
50 # define VERSIONMADEBY (0x0) /* platform depedent */
51 #endif
52
53 #ifndef Z_BUFSIZE
54 #define Z_BUFSIZE (64*1024) //(16384)
55 #endif
@@ -59,13 +58,10 @@
59 #endif
60
61 #ifndef ALLOC
62 # define ALLOC(size) (malloc(size))
63 #endif
64 #ifndef TRYFREE
65 # define TRYFREE(p) {if (p) free(p);}
66 #endif
67
68 /*
69 #define SIZECENTRALDIRITEM (0x2e)
70 #define SIZEZIPLOCALHEADER (0x1e)
71 */
@@ -136,24 +132,24 @@
136
137 int stream_initialised; /* 1 is stream is initialised */
138 uInt pos_in_buffered_data; /* last written byte in buffered_data */
139
140 ZPOS64_T pos_local_header; /* offset of the local header of the file
141 currenty writing */
142 char* central_header; /* central header data for the current file */
143 uLong size_centralExtra;
144 uLong size_centralheader; /* size of the central header for cur file */
145 uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */
146 uLong flag; /* flag of the file currently writing */
147
148 int method; /* compression method of file currenty wr.*/
149 int raw; /* 1 for directly writing raw data */
150 Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
151 uLong dosDate;
152 uLong crc32;
153 int encrypt;
154 int zip64; /* Add ZIP64 extened information in the extra field */
155 ZPOS64_T pos_zip64extrainfo;
156 ZPOS64_T totalCompressedData;
157 ZPOS64_T totalUncompressedData;
158 #ifndef NOCRYPT
159 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
@@ -163,14 +159,14 @@
163 } curfile64_info;
164
165 typedef struct
166 {
167 zlib_filefunc64_32_def z_filefunc;
168 voidpf filestream; /* io structore of the zipfile */
169 linkedlist_data central_dir;/* datablock with central dir in construction*/
170 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
171 curfile64_info ci; /* info on the file curretly writing */
172
173 ZPOS64_T begin_pos; /* position of the beginning of the zipfile */
174 ZPOS64_T add_position_when_writing_offset;
175 ZPOS64_T number_entry;
176
@@ -184,12 +180,11 @@
184 #ifndef NOCRYPT
185 #define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
186 #include "crypt.h"
187 #endif
188
189 local linkedlist_datablock_internal* allocate_new_datablock()
190 {
191 linkedlist_datablock_internal* ldi;
192 ldi = (linkedlist_datablock_internal*)
193 ALLOC(sizeof(linkedlist_datablock_internal));
194 if (ldi!=NULL)
195 {
@@ -198,34 +193,30 @@
198 ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
199 }
200 return ldi;
201 }
202
203 local void free_datablock(linkedlist_datablock_internal* ldi)
204 {
205 while (ldi!=NULL)
206 {
207 linkedlist_datablock_internal* ldinext = ldi->next_datablock;
208 TRYFREE(ldi);
209 ldi = ldinext;
210 }
211 }
212
213 local void init_linkedlist(linkedlist_data* ll)
214 {
215 ll->first_block = ll->last_block = NULL;
216 }
217
218 local void free_linkedlist(linkedlist_data* ll)
219 {
220 free_datablock(ll->first_block);
221 ll->first_block = ll->last_block = NULL;
222 }
223
224
225 local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
226 {
227 linkedlist_datablock_internal* ldi;
228 const unsigned char* from_copy;
229
230 if (ll==NULL)
231 return ZIP_INTERNALERROR;
@@ -236,11 +227,11 @@
236 if (ll->first_block == NULL)
237 return ZIP_INTERNALERROR;
238 }
239
240 ldi = ll->last_block;
241 from_copy = (unsigned char*)buf;
242
243 while (len>0)
244 {
245 uInt copy_this;
246 uInt i;
@@ -281,13 +272,11 @@
281 /* ===========================================================================
282 Inputs a long in LSB order to the given file
283 nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T)
284 */
285
286 local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte));
287 local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
288 {
289 unsigned char buf[8];
290 int n;
291 for (n = 0; n < nbByte; n++)
292 {
293 buf[n] = (unsigned char)(x & 0xff);
@@ -305,13 +294,11 @@
305 return ZIP_ERRNO;
306 else
307 return ZIP_OK;
308 }
309
310 local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte));
311 local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte)
312 {
313 unsigned char* buf=(unsigned char*)dest;
314 int n;
315 for (n = 0; n < nbByte; n++) {
316 buf[n] = (unsigned char)(x & 0xff);
317 x >>= 8;
@@ -327,12 +314,11 @@
327 }
328
329 /****************************************************************************/
330
331
332 local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm)
333 {
334 uLong year = (uLong)ptm->tm_year;
335 if (year>=1980)
336 year-=1980;
337 else if (year>=80)
338 year-=80;
@@ -342,14 +328,11 @@
342 }
343
344
345 /****************************************************************************/
346
347 local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi));
348
349 local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi)
350 {
351 unsigned char c;
352 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
353 if (err==1)
354 {
355 *pi = (int)c;
@@ -366,14 +349,11 @@
366
367
368 /* ===========================================================================
369 Reads a long in LSB order from the given gz_stream. Sets
370 */
371 local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
372
373 local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
374 {
375 uLong x ;
376 int i = 0;
377 int err;
378
379 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
@@ -388,14 +368,11 @@
388 else
389 *pX = 0;
390 return err;
391 }
392
393 local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
394
395 local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
396 {
397 uLong x ;
398 int i = 0;
399 int err;
400
401 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
@@ -418,15 +395,12 @@
418 else
419 *pX = 0;
420 return err;
421 }
422
423 local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX));
424
425
426 local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
427 {
428 ZPOS64_T x;
429 int i = 0;
430 int err;
431
432 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
@@ -473,14 +447,11 @@
473 #endif
474 /*
475 Locate the Central directory of a zipfile (at the end, just before
476 the global comment)
477 */
478 local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
479
480 local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
481 {
482 unsigned char* buf;
483 ZPOS64_T uSizeFile;
484 ZPOS64_T uBackRead;
485 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
486 ZPOS64_T uPosFound=0;
@@ -527,22 +498,19 @@
527 }
528
529 if (uPosFound!=0)
530 break;
531 }
532 TRYFREE(buf);
533 return uPosFound;
534 }
535
536 /*
537 Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before
538 the global comment)
539 */
540 local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
541
542 local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
543 {
544 unsigned char* buf;
545 ZPOS64_T uSizeFile;
546 ZPOS64_T uBackRead;
547 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
548 ZPOS64_T uPosFound=0;
@@ -593,11 +561,11 @@
593
594 if (uPosFound!=0)
595 break;
596 }
597
598 TRYFREE(buf);
599 if (uPosFound == 0)
600 return 0;
601
602 /* Zip64 end of central directory locator */
603 if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
@@ -635,24 +603,23 @@
635 return 0;
636
637 return relativeOffset;
638 }
639
640 local int LoadCentralDirectoryRecord(zip64_internal* pziinit)
641 {
642 int err=ZIP_OK;
643 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
644
645 ZPOS64_T size_central_dir; /* size of the central directory */
646 ZPOS64_T offset_central_dir; /* offset of start of central directory */
647 ZPOS64_T central_pos;
648 uLong uL;
649
650 uLong number_disk; /* number of the current dist, used for
651 spaning ZIP, unsupported, always 0*/
652 uLong number_disk_with_CD; /* number the the disk with central dir, used
653 for spaning ZIP, unsupported, always 0*/
654 ZPOS64_T number_entry;
655 ZPOS64_T number_entry_CD; /* total number of entries in
656 the central dir
657 (same than number_entry on nospan) */
658 uLong VersionMadeBy;
@@ -828,11 +795,11 @@
828 if (err==ZIP_OK)
829 err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);
830
831 size_central_dir_to_read-=read_this;
832 }
833 TRYFREE(buf_read);
834 }
835 pziinit->begin_pos = byte_before_the_zipfile;
836 pziinit->number_entry = number_entry_CD;
837
838 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
@@ -844,12 +811,11 @@
844
845 #endif /* !NO_ADDFILEINEXISTINGZIP*/
846
847
848 /************************************************************/
849 extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def)
850 {
851 zip64_internal ziinit;
852 zip64_internal* zi;
853 int err=ZIP_OK;
854
855 ziinit.z_filefunc.zseek32_file = NULL;
@@ -903,24 +869,23 @@
903 # endif /* !NO_ADDFILEINEXISTINGZIP*/
904
905 if (err != ZIP_OK)
906 {
907 # ifndef NO_ADDFILEINEXISTINGZIP
908 TRYFREE(ziinit.globalcomment);
909 # endif /* !NO_ADDFILEINEXISTINGZIP*/
910 TRYFREE(zi);
911 return NULL;
912 }
913 else
914 {
915 *zi = ziinit;
916 return (zipFile)zi;
917 }
918 }
919
920 extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def)
921 {
922 if (pzlib_filefunc32_def != NULL)
923 {
924 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
925 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
926 return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
@@ -927,12 +892,11 @@
927 }
928 else
929 return zipOpen3(pathname, append, globalcomment, NULL);
930 }
931
932 extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def)
933 {
934 if (pzlib_filefunc_def != NULL)
935 {
936 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
937 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
938 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
@@ -943,22 +907,19 @@
943 return zipOpen3(pathname, append, globalcomment, NULL);
944 }
945
946
947
948 extern zipFile ZEXPORT zipOpen (const char* pathname, int append)
949 {
950 return zipOpen3((const void*)pathname,append,NULL,NULL);
951 }
952
953 extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append)
954 {
955 return zipOpen3(pathname,append,NULL,NULL);
956 }
957
958 local int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local)
959 {
960 /* write the local header */
961 int err;
962 uInt size_filename = (uInt)strlen(filename);
963 uInt size_extrafield = size_extrafield_local;
964
@@ -1050,18 +1011,17 @@
1050 before calling this function it can be done with zipRemoveExtraInfoBlock
1051
1052 It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize
1053 unnecessary allocations.
1054 */
1055 extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1056 const void* extrafield_local, uInt size_extrafield_local,
1057 const void* extrafield_global, uInt size_extrafield_global,
1058 const char* comment, int method, int level, int raw,
1059 int windowBits,int memLevel, int strategy,
1060 const char* password, uLong crcForCrypting,
1061 uLong versionMadeBy, uLong flagBase, int zip64)
1062 {
1063 zip64_internal* zi;
1064 uInt size_filename;
1065 uInt size_comment;
1066 uInt i;
1067 int err = ZIP_OK;
@@ -1260,110 +1220,102 @@
1260 if (err==Z_OK)
1261 zi->in_opened_file_inzip = 1;
1262 return err;
1263 }
1264
1265 extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1266 const void* extrafield_local, uInt size_extrafield_local,
1267 const void* extrafield_global, uInt size_extrafield_global,
1268 const char* comment, int method, int level, int raw,
1269 int windowBits,int memLevel, int strategy,
1270 const char* password, uLong crcForCrypting,
1271 uLong versionMadeBy, uLong flagBase)
1272 {
1273 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1274 extrafield_local, size_extrafield_local,
1275 extrafield_global, size_extrafield_global,
1276 comment, method, level, raw,
1277 windowBits, memLevel, strategy,
1278 password, crcForCrypting, versionMadeBy, flagBase, 0);
1279 }
1280
1281 extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1282 const void* extrafield_local, uInt size_extrafield_local,
1283 const void* extrafield_global, uInt size_extrafield_global,
1284 const char* comment, int method, int level, int raw,
1285 int windowBits,int memLevel, int strategy,
1286 const char* password, uLong crcForCrypting)
1287 {
1288 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1289 extrafield_local, size_extrafield_local,
1290 extrafield_global, size_extrafield_global,
1291 comment, method, level, raw,
1292 windowBits, memLevel, strategy,
1293 password, crcForCrypting, VERSIONMADEBY, 0, 0);
1294 }
1295
1296 extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1297 const void* extrafield_local, uInt size_extrafield_local,
1298 const void* extrafield_global, uInt size_extrafield_global,
1299 const char* comment, int method, int level, int raw,
1300 int windowBits,int memLevel, int strategy,
1301 const char* password, uLong crcForCrypting, int zip64)
1302 {
1303 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1304 extrafield_local, size_extrafield_local,
1305 extrafield_global, size_extrafield_global,
1306 comment, method, level, raw,
1307 windowBits, memLevel, strategy,
1308 password, crcForCrypting, VERSIONMADEBY, 0, zip64);
1309 }
1310
1311 extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1312 const void* extrafield_local, uInt size_extrafield_local,
1313 const void* extrafield_global, uInt size_extrafield_global,
1314 const char* comment, int method, int level, int raw)
1315 {
1316 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1317 extrafield_local, size_extrafield_local,
1318 extrafield_global, size_extrafield_global,
1319 comment, method, level, raw,
1320 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1321 NULL, 0, VERSIONMADEBY, 0, 0);
1322 }
1323
1324 extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1325 const void* extrafield_local, uInt size_extrafield_local,
1326 const void* extrafield_global, uInt size_extrafield_global,
1327 const char* comment, int method, int level, int raw, int zip64)
1328 {
1329 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1330 extrafield_local, size_extrafield_local,
1331 extrafield_global, size_extrafield_global,
1332 comment, method, level, raw,
1333 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1334 NULL, 0, VERSIONMADEBY, 0, zip64);
1335 }
1336
1337 extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1338 const void* extrafield_local, uInt size_extrafield_local,
1339 const void*extrafield_global, uInt size_extrafield_global,
1340 const char* comment, int method, int level, int zip64)
1341 {
1342 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1343 extrafield_local, size_extrafield_local,
1344 extrafield_global, size_extrafield_global,
1345 comment, method, level, 0,
1346 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1347 NULL, 0, VERSIONMADEBY, 0, zip64);
1348 }
1349
1350 extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1351 const void* extrafield_local, uInt size_extrafield_local,
1352 const void*extrafield_global, uInt size_extrafield_global,
1353 const char* comment, int method, int level)
1354 {
1355 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1356 extrafield_local, size_extrafield_local,
1357 extrafield_global, size_extrafield_global,
1358 comment, method, level, 0,
1359 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1360 NULL, 0, VERSIONMADEBY, 0, 0);
1361 }
1362
1363 local int zip64FlushWriteBuffer(zip64_internal* zi)
1364 {
1365 int err=ZIP_OK;
1366
1367 if (zi->ci.encrypt != 0)
1368 {
1369 #ifndef NOCRYPT
@@ -1397,12 +1349,11 @@
1397 zi->ci.pos_in_buffered_data = 0;
1398
1399 return err;
1400 }
1401
1402 extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len)
1403 {
1404 zip64_internal* zi;
1405 int err=ZIP_OK;
1406
1407 if (file == NULL)
1408 return ZIP_PARAMERROR;
@@ -1448,11 +1399,11 @@
1448 err = ZIP_OK;
1449 }
1450 else
1451 #endif
1452 {
1453 zi->ci.stream.next_in = (Bytef*)buf;
1454 zi->ci.stream.avail_in = len;
1455
1456 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
1457 {
1458 if (zi->ci.stream.avail_out == 0)
@@ -1499,17 +1450,15 @@
1499 }
1500
1501 return err;
1502 }
1503
1504 extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32)
1505 {
1506 return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
1507 }
1508
1509 extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
1510 {
1511 zip64_internal* zi;
1512 ZPOS64_T compressed_size;
1513 uLong invalidValue = 0xffffffff;
1514 unsigned datasize = 0;
1515 int err=ZIP_OK;
@@ -1740,17 +1689,15 @@
1740 zi->in_opened_file_inzip = 0;
1741
1742 return err;
1743 }
1744
1745 extern int ZEXPORT zipCloseFileInZip (zipFile file)
1746 {
1747 return zipCloseFileInZipRaw (file,0,0);
1748 }
1749
1750 local int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip)
1751 {
1752 int err = ZIP_OK;
1753 ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writing_offset;
1754
1755 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4);
1756
@@ -1767,12 +1714,11 @@
1767 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4);
1768
1769 return err;
1770 }
1771
1772 local int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
1773 {
1774 int err = ZIP_OK;
1775
1776 uLong Zip64DataSize = 44;
1777
1778 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4);
@@ -1806,12 +1752,12 @@
1806 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writing_offset;
1807 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8);
1808 }
1809 return err;
1810 }
1811 local int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
1812 {
1813 int err = ZIP_OK;
1814
1815 /*signature*/
1816 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
1817
@@ -1854,12 +1800,11 @@
1854 }
1855
1856 return err;
1857 }
1858
1859 local int Write_GlobalComment(zip64_internal* zi, const char* global_comment)
1860 {
1861 int err = ZIP_OK;
1862 uInt size_global_comment = 0;
1863
1864 if(global_comment != NULL)
1865 size_global_comment = (uInt)strlen(global_comment);
@@ -1872,12 +1817,11 @@
1872 err = ZIP_ERRNO;
1873 }
1874 return err;
1875 }
1876
1877 extern int ZEXPORT zipClose (zipFile file, const char* global_comment)
1878 {
1879 zip64_internal* zi;
1880 int err = 0;
1881 uLong size_centraldir = 0;
1882 ZPOS64_T centraldir_pos_inzip;
1883 ZPOS64_T pos;
@@ -1934,19 +1878,18 @@
1934 if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0)
1935 if (err == ZIP_OK)
1936 err = ZIP_ERRNO;
1937
1938 #ifndef NO_ADDFILEINEXISTINGZIP
1939 TRYFREE(zi->globalcomment);
1940 #endif
1941 TRYFREE(zi);
1942
1943 return err;
1944 }
1945
1946 extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader)
1947 {
1948 char* p = pData;
1949 int size = 0;
1950 char* pNewHeader;
1951 char* pTmp;
1952 short header;
@@ -1994,9 +1937,9 @@
1994 retVal = ZIP_OK;
1995 }
1996 else
1997 retVal = ZIP_ERRNO;
1998
1999 TRYFREE(pNewHeader);
2000
2001 return retVal;
2002 }
2003
--- compat/zlib/contrib/minizip/zip.c
+++ compat/zlib/contrib/minizip/zip.c
@@ -12,11 +12,11 @@
12 Changes
13 Oct-2009 - Mathias Svensson - Remove old C style function prototypes
14 Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives
15 Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions.
16 Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data
17 It is used when recreating zip archive with RAW when deleting items from a zip.
18 ZIP64 data is automatically added to items that needs it, and existing ZIP64 data need to be removed.
19 Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required)
20 Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
21
22 */
@@ -23,18 +23,17 @@
23
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdint.h>
29 #include <time.h>
30 #include "zlib.h"
31 #include "zip.h"
32
33 #ifdef STDC
34 # include <stddef.h>
 
 
35 #endif
36 #ifdef NO_ERRNO_H
37 extern int errno;
38 #else
39 # include <errno.h>
@@ -45,11 +44,11 @@
44 # define local static
45 #endif
46 /* compile with -Dlocal if your debugger can't find static symbols */
47
48 #ifndef VERSIONMADEBY
49 # define VERSIONMADEBY (0x0) /* platform dependent */
50 #endif
51
52 #ifndef Z_BUFSIZE
53 #define Z_BUFSIZE (64*1024) //(16384)
54 #endif
@@ -59,13 +58,10 @@
58 #endif
59
60 #ifndef ALLOC
61 # define ALLOC(size) (malloc(size))
62 #endif
 
 
 
63
64 /*
65 #define SIZECENTRALDIRITEM (0x2e)
66 #define SIZEZIPLOCALHEADER (0x1e)
67 */
@@ -136,24 +132,24 @@
132
133 int stream_initialised; /* 1 is stream is initialised */
134 uInt pos_in_buffered_data; /* last written byte in buffered_data */
135
136 ZPOS64_T pos_local_header; /* offset of the local header of the file
137 currently writing */
138 char* central_header; /* central header data for the current file */
139 uLong size_centralExtra;
140 uLong size_centralheader; /* size of the central header for cur file */
141 uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */
142 uLong flag; /* flag of the file currently writing */
143
144 int method; /* compression method of file currently wr.*/
145 int raw; /* 1 for directly writing raw data */
146 Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
147 uLong dosDate;
148 uLong crc32;
149 int encrypt;
150 int zip64; /* Add ZIP64 extended information in the extra field */
151 ZPOS64_T pos_zip64extrainfo;
152 ZPOS64_T totalCompressedData;
153 ZPOS64_T totalUncompressedData;
154 #ifndef NOCRYPT
155 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
@@ -163,14 +159,14 @@
159 } curfile64_info;
160
161 typedef struct
162 {
163 zlib_filefunc64_32_def z_filefunc;
164 voidpf filestream; /* io structure of the zipfile */
165 linkedlist_data central_dir;/* datablock with central dir in construction*/
166 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
167 curfile64_info ci; /* info on the file currently writing */
168
169 ZPOS64_T begin_pos; /* position of the beginning of the zipfile */
170 ZPOS64_T add_position_when_writing_offset;
171 ZPOS64_T number_entry;
172
@@ -184,12 +180,11 @@
180 #ifndef NOCRYPT
181 #define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
182 #include "crypt.h"
183 #endif
184
185 local linkedlist_datablock_internal* allocate_new_datablock(void) {
 
186 linkedlist_datablock_internal* ldi;
187 ldi = (linkedlist_datablock_internal*)
188 ALLOC(sizeof(linkedlist_datablock_internal));
189 if (ldi!=NULL)
190 {
@@ -198,34 +193,30 @@
193 ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
194 }
195 return ldi;
196 }
197
198 local void free_datablock(linkedlist_datablock_internal* ldi) {
 
199 while (ldi!=NULL)
200 {
201 linkedlist_datablock_internal* ldinext = ldi->next_datablock;
202 free(ldi);
203 ldi = ldinext;
204 }
205 }
206
207 local void init_linkedlist(linkedlist_data* ll) {
 
208 ll->first_block = ll->last_block = NULL;
209 }
210
211 local void free_linkedlist(linkedlist_data* ll) {
 
212 free_datablock(ll->first_block);
213 ll->first_block = ll->last_block = NULL;
214 }
215
216
217 local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) {
 
218 linkedlist_datablock_internal* ldi;
219 const unsigned char* from_copy;
220
221 if (ll==NULL)
222 return ZIP_INTERNALERROR;
@@ -236,11 +227,11 @@
227 if (ll->first_block == NULL)
228 return ZIP_INTERNALERROR;
229 }
230
231 ldi = ll->last_block;
232 from_copy = (const unsigned char*)buf;
233
234 while (len>0)
235 {
236 uInt copy_this;
237 uInt i;
@@ -281,13 +272,11 @@
272 /* ===========================================================================
273 Inputs a long in LSB order to the given file
274 nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T)
275 */
276
277 local int zip64local_putValue(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte) {
 
 
278 unsigned char buf[8];
279 int n;
280 for (n = 0; n < nbByte; n++)
281 {
282 buf[n] = (unsigned char)(x & 0xff);
@@ -305,13 +294,11 @@
294 return ZIP_ERRNO;
295 else
296 return ZIP_OK;
297 }
298
299 local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte) {
 
 
300 unsigned char* buf=(unsigned char*)dest;
301 int n;
302 for (n = 0; n < nbByte; n++) {
303 buf[n] = (unsigned char)(x & 0xff);
304 x >>= 8;
@@ -327,12 +314,11 @@
314 }
315
316 /****************************************************************************/
317
318
319 local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm) {
 
320 uLong year = (uLong)ptm->tm_year;
321 if (year>=1980)
322 year-=1980;
323 else if (year>=80)
324 year-=80;
@@ -342,14 +328,11 @@
328 }
329
330
331 /****************************************************************************/
332
333 local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int* pi) {
 
 
 
334 unsigned char c;
335 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
336 if (err==1)
337 {
338 *pi = (int)c;
@@ -366,14 +349,11 @@
349
350
351 /* ===========================================================================
352 Reads a long in LSB order from the given gz_stream. Sets
353 */
354 local int zip64local_getShort(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) {
 
 
 
355 uLong x ;
356 int i = 0;
357 int err;
358
359 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
@@ -388,14 +368,11 @@
368 else
369 *pX = 0;
370 return err;
371 }
372
373 local int zip64local_getLong(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) {
 
 
 
374 uLong x ;
375 int i = 0;
376 int err;
377
378 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
@@ -418,15 +395,12 @@
395 else
396 *pX = 0;
397 return err;
398 }
399
 
400
401 local int zip64local_getLong64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX) {
 
 
402 ZPOS64_T x;
403 int i = 0;
404 int err;
405
406 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
@@ -473,14 +447,11 @@
447 #endif
448 /*
449 Locate the Central directory of a zipfile (at the end, just before
450 the global comment)
451 */
452 local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) {
 
 
 
453 unsigned char* buf;
454 ZPOS64_T uSizeFile;
455 ZPOS64_T uBackRead;
456 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
457 ZPOS64_T uPosFound=0;
@@ -527,22 +498,19 @@
498 }
499
500 if (uPosFound!=0)
501 break;
502 }
503 free(buf);
504 return uPosFound;
505 }
506
507 /*
508 Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before
509 the global comment)
510 */
511 local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) {
 
 
 
512 unsigned char* buf;
513 ZPOS64_T uSizeFile;
514 ZPOS64_T uBackRead;
515 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
516 ZPOS64_T uPosFound=0;
@@ -593,11 +561,11 @@
561
562 if (uPosFound!=0)
563 break;
564 }
565
566 free(buf);
567 if (uPosFound == 0)
568 return 0;
569
570 /* Zip64 end of central directory locator */
571 if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
@@ -635,24 +603,23 @@
603 return 0;
604
605 return relativeOffset;
606 }
607
608 local int LoadCentralDirectoryRecord(zip64_internal* pziinit) {
 
609 int err=ZIP_OK;
610 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
611
612 ZPOS64_T size_central_dir; /* size of the central directory */
613 ZPOS64_T offset_central_dir; /* offset of start of central directory */
614 ZPOS64_T central_pos;
615 uLong uL;
616
617 uLong number_disk; /* number of the current dist, used for
618 spanning ZIP, unsupported, always 0*/
619 uLong number_disk_with_CD; /* number the the disk with central dir, used
620 for spanning ZIP, unsupported, always 0*/
621 ZPOS64_T number_entry;
622 ZPOS64_T number_entry_CD; /* total number of entries in
623 the central dir
624 (same than number_entry on nospan) */
625 uLong VersionMadeBy;
@@ -828,11 +795,11 @@
795 if (err==ZIP_OK)
796 err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);
797
798 size_central_dir_to_read-=read_this;
799 }
800 free(buf_read);
801 }
802 pziinit->begin_pos = byte_before_the_zipfile;
803 pziinit->number_entry = number_entry_CD;
804
805 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
@@ -844,12 +811,11 @@
811
812 #endif /* !NO_ADDFILEINEXISTINGZIP*/
813
814
815 /************************************************************/
816 extern zipFile ZEXPORT zipOpen3(const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def) {
 
817 zip64_internal ziinit;
818 zip64_internal* zi;
819 int err=ZIP_OK;
820
821 ziinit.z_filefunc.zseek32_file = NULL;
@@ -903,24 +869,23 @@
869 # endif /* !NO_ADDFILEINEXISTINGZIP*/
870
871 if (err != ZIP_OK)
872 {
873 # ifndef NO_ADDFILEINEXISTINGZIP
874 free(ziinit.globalcomment);
875 # endif /* !NO_ADDFILEINEXISTINGZIP*/
876 free(zi);
877 return NULL;
878 }
879 else
880 {
881 *zi = ziinit;
882 return (zipFile)zi;
883 }
884 }
885
886 extern zipFile ZEXPORT zipOpen2(const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def) {
 
887 if (pzlib_filefunc32_def != NULL)
888 {
889 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
890 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
891 return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
@@ -927,12 +892,11 @@
892 }
893 else
894 return zipOpen3(pathname, append, globalcomment, NULL);
895 }
896
897 extern zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def) {
 
898 if (pzlib_filefunc_def != NULL)
899 {
900 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
901 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
902 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
@@ -943,22 +907,19 @@
907 return zipOpen3(pathname, append, globalcomment, NULL);
908 }
909
910
911
912 extern zipFile ZEXPORT zipOpen(const char* pathname, int append) {
 
913 return zipOpen3((const void*)pathname,append,NULL,NULL);
914 }
915
916 extern zipFile ZEXPORT zipOpen64(const void* pathname, int append) {
 
917 return zipOpen3(pathname,append,NULL,NULL);
918 }
919
920 local int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local) {
 
921 /* write the local header */
922 int err;
923 uInt size_filename = (uInt)strlen(filename);
924 uInt size_extrafield = size_extrafield_local;
925
@@ -1050,18 +1011,17 @@
1011 before calling this function it can be done with zipRemoveExtraInfoBlock
1012
1013 It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize
1014 unnecessary allocations.
1015 */
1016 extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1017 const void* extrafield_local, uInt size_extrafield_local,
1018 const void* extrafield_global, uInt size_extrafield_global,
1019 const char* comment, int method, int level, int raw,
1020 int windowBits,int memLevel, int strategy,
1021 const char* password, uLong crcForCrypting,
1022 uLong versionMadeBy, uLong flagBase, int zip64) {
 
1023 zip64_internal* zi;
1024 uInt size_filename;
1025 uInt size_comment;
1026 uInt i;
1027 int err = ZIP_OK;
@@ -1260,110 +1220,102 @@
1220 if (err==Z_OK)
1221 zi->in_opened_file_inzip = 1;
1222 return err;
1223 }
1224
1225 extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1226 const void* extrafield_local, uInt size_extrafield_local,
1227 const void* extrafield_global, uInt size_extrafield_global,
1228 const char* comment, int method, int level, int raw,
1229 int windowBits,int memLevel, int strategy,
1230 const char* password, uLong crcForCrypting,
1231 uLong versionMadeBy, uLong flagBase) {
1232 return zipOpenNewFileInZip4_64(file, filename, zipfi,
1233 extrafield_local, size_extrafield_local,
1234 extrafield_global, size_extrafield_global,
1235 comment, method, level, raw,
1236 windowBits, memLevel, strategy,
1237 password, crcForCrypting, versionMadeBy, flagBase, 0);
1238 }
1239
1240 extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1241 const void* extrafield_local, uInt size_extrafield_local,
1242 const void* extrafield_global, uInt size_extrafield_global,
1243 const char* comment, int method, int level, int raw,
1244 int windowBits,int memLevel, int strategy,
1245 const char* password, uLong crcForCrypting) {
1246 return zipOpenNewFileInZip4_64(file, filename, zipfi,
1247 extrafield_local, size_extrafield_local,
1248 extrafield_global, size_extrafield_global,
1249 comment, method, level, raw,
1250 windowBits, memLevel, strategy,
1251 password, crcForCrypting, VERSIONMADEBY, 0, 0);
 
 
1252 }
1253
1254 extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1255 const void* extrafield_local, uInt size_extrafield_local,
1256 const void* extrafield_global, uInt size_extrafield_global,
1257 const char* comment, int method, int level, int raw,
1258 int windowBits,int memLevel, int strategy,
1259 const char* password, uLong crcForCrypting, int zip64) {
1260 return zipOpenNewFileInZip4_64(file, filename, zipfi,
1261 extrafield_local, size_extrafield_local,
1262 extrafield_global, size_extrafield_global,
1263 comment, method, level, raw,
1264 windowBits, memLevel, strategy,
1265 password, crcForCrypting, VERSIONMADEBY, 0, zip64);
 
1266 }
1267
1268 extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1269 const void* extrafield_local, uInt size_extrafield_local,
1270 const void* extrafield_global, uInt size_extrafield_global,
1271 const char* comment, int method, int level, int raw) {
1272 return zipOpenNewFileInZip4_64(file, filename, zipfi,
1273 extrafield_local, size_extrafield_local,
1274 extrafield_global, size_extrafield_global,
1275 comment, method, level, raw,
1276 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1277 NULL, 0, VERSIONMADEBY, 0, 0);
 
1278 }
1279
1280 extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1281 const void* extrafield_local, uInt size_extrafield_local,
1282 const void* extrafield_global, uInt size_extrafield_global,
1283 const char* comment, int method, int level, int raw, int zip64) {
1284 return zipOpenNewFileInZip4_64(file, filename, zipfi,
1285 extrafield_local, size_extrafield_local,
1286 extrafield_global, size_extrafield_global,
1287 comment, method, level, raw,
1288 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1289 NULL, 0, VERSIONMADEBY, 0, zip64);
1290 }
1291
1292 extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1293 const void* extrafield_local, uInt size_extrafield_local,
1294 const void*extrafield_global, uInt size_extrafield_global,
1295 const char* comment, int method, int level, int zip64) {
1296 return zipOpenNewFileInZip4_64(file, filename, zipfi,
1297 extrafield_local, size_extrafield_local,
1298 extrafield_global, size_extrafield_global,
1299 comment, method, level, 0,
1300 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1301 NULL, 0, VERSIONMADEBY, 0, zip64);
1302 }
1303
1304 extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1305 const void* extrafield_local, uInt size_extrafield_local,
1306 const void*extrafield_global, uInt size_extrafield_global,
1307 const char* comment, int method, int level) {
1308 return zipOpenNewFileInZip4_64(file, filename, zipfi,
1309 extrafield_local, size_extrafield_local,
1310 extrafield_global, size_extrafield_global,
1311 comment, method, level, 0,
1312 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1313 NULL, 0, VERSIONMADEBY, 0, 0);
1314 }
1315
1316 local int zip64FlushWriteBuffer(zip64_internal* zi) {
 
 
 
 
1317 int err=ZIP_OK;
1318
1319 if (zi->ci.encrypt != 0)
1320 {
1321 #ifndef NOCRYPT
@@ -1397,12 +1349,11 @@
1349 zi->ci.pos_in_buffered_data = 0;
1350
1351 return err;
1352 }
1353
1354 extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void* buf, unsigned int len) {
 
1355 zip64_internal* zi;
1356 int err=ZIP_OK;
1357
1358 if (file == NULL)
1359 return ZIP_PARAMERROR;
@@ -1448,11 +1399,11 @@
1399 err = ZIP_OK;
1400 }
1401 else
1402 #endif
1403 {
1404 zi->ci.stream.next_in = (Bytef*)(uintptr_t)buf;
1405 zi->ci.stream.avail_in = len;
1406
1407 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
1408 {
1409 if (zi->ci.stream.avail_out == 0)
@@ -1499,17 +1450,15 @@
1450 }
1451
1452 return err;
1453 }
1454
1455 extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uLong uncompressed_size, uLong crc32) {
 
1456 return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
1457 }
1458
1459 extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_size, uLong crc32) {
 
1460 zip64_internal* zi;
1461 ZPOS64_T compressed_size;
1462 uLong invalidValue = 0xffffffff;
1463 unsigned datasize = 0;
1464 int err=ZIP_OK;
@@ -1740,17 +1689,15 @@
1689 zi->in_opened_file_inzip = 0;
1690
1691 return err;
1692 }
1693
1694 extern int ZEXPORT zipCloseFileInZip(zipFile file) {
 
1695 return zipCloseFileInZipRaw (file,0,0);
1696 }
1697
1698 local int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip) {
 
1699 int err = ZIP_OK;
1700 ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writing_offset;
1701
1702 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4);
1703
@@ -1767,12 +1714,11 @@
1714 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4);
1715
1716 return err;
1717 }
1718
1719 local int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) {
 
1720 int err = ZIP_OK;
1721
1722 uLong Zip64DataSize = 44;
1723
1724 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4);
@@ -1806,12 +1752,12 @@
1752 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writing_offset;
1753 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8);
1754 }
1755 return err;
1756 }
1757
1758 local int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) {
1759 int err = ZIP_OK;
1760
1761 /*signature*/
1762 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
1763
@@ -1854,12 +1800,11 @@
1800 }
1801
1802 return err;
1803 }
1804
1805 local int Write_GlobalComment(zip64_internal* zi, const char* global_comment) {
 
1806 int err = ZIP_OK;
1807 uInt size_global_comment = 0;
1808
1809 if(global_comment != NULL)
1810 size_global_comment = (uInt)strlen(global_comment);
@@ -1872,12 +1817,11 @@
1817 err = ZIP_ERRNO;
1818 }
1819 return err;
1820 }
1821
1822 extern int ZEXPORT zipClose(zipFile file, const char* global_comment) {
 
1823 zip64_internal* zi;
1824 int err = 0;
1825 uLong size_centraldir = 0;
1826 ZPOS64_T centraldir_pos_inzip;
1827 ZPOS64_T pos;
@@ -1934,19 +1878,18 @@
1878 if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0)
1879 if (err == ZIP_OK)
1880 err = ZIP_ERRNO;
1881
1882 #ifndef NO_ADDFILEINEXISTINGZIP
1883 free(zi->globalcomment);
1884 #endif
1885 free(zi);
1886
1887 return err;
1888 }
1889
1890 extern int ZEXPORT zipRemoveExtraInfoBlock(char* pData, int* dataLen, short sHeader) {
 
1891 char* p = pData;
1892 int size = 0;
1893 char* pNewHeader;
1894 char* pTmp;
1895 short header;
@@ -1994,9 +1937,9 @@
1937 retVal = ZIP_OK;
1938 }
1939 else
1940 retVal = ZIP_ERRNO;
1941
1942 free(pNewHeader);
1943
1944 return retVal;
1945 }
1946
--- compat/zlib/contrib/minizip/zip.h
+++ compat/zlib/contrib/minizip/zip.h
@@ -111,12 +111,12 @@
111111
112112
#define APPEND_STATUS_CREATE (0)
113113
#define APPEND_STATUS_CREATEAFTER (1)
114114
#define APPEND_STATUS_ADDINZIP (2)
115115
116
-extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
117
-extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
116
+extern zipFile ZEXPORT zipOpen(const char *pathname, int append);
117
+extern zipFile ZEXPORT zipOpen64(const void *pathname, int append);
118118
/*
119119
Create a zipfile.
120120
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
121121
an Unix computer "zlib/zlib113.zip".
122122
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
@@ -129,50 +129,50 @@
129129
of this zip package.
130130
*/
131131
132132
/* Note : there is no delete function into a zipfile.
133133
If you want delete file into a zipfile, you must open a zipfile, and create another
134
- Of couse, you can use RAW reading and writing to copy the file you did not want delte
135
-*/
136
-
137
-extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
138
- int append,
139
- zipcharpc* globalcomment,
140
- zlib_filefunc_def* pzlib_filefunc_def));
141
-
142
-extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
143
- int append,
144
- zipcharpc* globalcomment,
145
- zlib_filefunc64_def* pzlib_filefunc_def));
146
-
147
-extern zipFile ZEXPORT zipOpen3 OF((const void *pathname,
148
- int append,
149
- zipcharpc* globalcomment,
150
- zlib_filefunc64_32_def* pzlib_filefunc64_32_def));
151
-
152
-extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
153
- const char* filename,
154
- const zip_fileinfo* zipfi,
155
- const void* extrafield_local,
156
- uInt size_extrafield_local,
157
- const void* extrafield_global,
158
- uInt size_extrafield_global,
159
- const char* comment,
160
- int method,
161
- int level));
162
-
163
-extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
164
- const char* filename,
165
- const zip_fileinfo* zipfi,
166
- const void* extrafield_local,
167
- uInt size_extrafield_local,
168
- const void* extrafield_global,
169
- uInt size_extrafield_global,
170
- const char* comment,
171
- int method,
172
- int level,
173
- int zip64));
134
+ Of course, you can use RAW reading and writing to copy the file you did not want delete
135
+*/
136
+
137
+extern zipFile ZEXPORT zipOpen2(const char *pathname,
138
+ int append,
139
+ zipcharpc* globalcomment,
140
+ zlib_filefunc_def* pzlib_filefunc_def);
141
+
142
+extern zipFile ZEXPORT zipOpen2_64(const void *pathname,
143
+ int append,
144
+ zipcharpc* globalcomment,
145
+ zlib_filefunc64_def* pzlib_filefunc_def);
146
+
147
+extern zipFile ZEXPORT zipOpen3(const void *pathname,
148
+ int append,
149
+ zipcharpc* globalcomment,
150
+ zlib_filefunc64_32_def* pzlib_filefunc64_32_def);
151
+
152
+extern int ZEXPORT zipOpenNewFileInZip(zipFile file,
153
+ const char* filename,
154
+ const zip_fileinfo* zipfi,
155
+ const void* extrafield_local,
156
+ uInt size_extrafield_local,
157
+ const void* extrafield_global,
158
+ uInt size_extrafield_global,
159
+ const char* comment,
160
+ int method,
161
+ int level);
162
+
163
+extern int ZEXPORT zipOpenNewFileInZip64(zipFile file,
164
+ const char* filename,
165
+ const zip_fileinfo* zipfi,
166
+ const void* extrafield_local,
167
+ uInt size_extrafield_local,
168
+ const void* extrafield_global,
169
+ uInt size_extrafield_global,
170
+ const char* comment,
171
+ int method,
172
+ int level,
173
+ int zip64);
174174
175175
/*
176176
Open a file in the ZIP for writing.
177177
filename : the filename in zip (if NULL, '-' without quote will be used
178178
*zipfi contain supplemental information
@@ -187,164 +187,161 @@
187187
this MUST be '1' if the uncompressed size is >= 0xffffffff.
188188
189189
*/
190190
191191
192
-extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
193
- const char* filename,
194
- const zip_fileinfo* zipfi,
195
- const void* extrafield_local,
196
- uInt size_extrafield_local,
197
- const void* extrafield_global,
198
- uInt size_extrafield_global,
199
- const char* comment,
200
- int method,
201
- int level,
202
- int raw));
203
-
204
-
205
-extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
206
- const char* filename,
207
- const zip_fileinfo* zipfi,
208
- const void* extrafield_local,
209
- uInt size_extrafield_local,
210
- const void* extrafield_global,
211
- uInt size_extrafield_global,
212
- const char* comment,
213
- int method,
214
- int level,
215
- int raw,
216
- int zip64));
192
+extern int ZEXPORT zipOpenNewFileInZip2(zipFile file,
193
+ const char* filename,
194
+ const zip_fileinfo* zipfi,
195
+ const void* extrafield_local,
196
+ uInt size_extrafield_local,
197
+ const void* extrafield_global,
198
+ uInt size_extrafield_global,
199
+ const char* comment,
200
+ int method,
201
+ int level,
202
+ int raw);
203
+
204
+
205
+extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file,
206
+ const char* filename,
207
+ const zip_fileinfo* zipfi,
208
+ const void* extrafield_local,
209
+ uInt size_extrafield_local,
210
+ const void* extrafield_global,
211
+ uInt size_extrafield_global,
212
+ const char* comment,
213
+ int method,
214
+ int level,
215
+ int raw,
216
+ int zip64);
217217
/*
218218
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
219219
*/
220220
221
-extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
222
- const char* filename,
223
- const zip_fileinfo* zipfi,
224
- const void* extrafield_local,
225
- uInt size_extrafield_local,
226
- const void* extrafield_global,
227
- uInt size_extrafield_global,
228
- const char* comment,
229
- int method,
230
- int level,
231
- int raw,
232
- int windowBits,
233
- int memLevel,
234
- int strategy,
235
- const char* password,
236
- uLong crcForCrypting));
237
-
238
-extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
239
- const char* filename,
240
- const zip_fileinfo* zipfi,
241
- const void* extrafield_local,
242
- uInt size_extrafield_local,
243
- const void* extrafield_global,
244
- uInt size_extrafield_global,
245
- const char* comment,
246
- int method,
247
- int level,
248
- int raw,
249
- int windowBits,
250
- int memLevel,
251
- int strategy,
252
- const char* password,
253
- uLong crcForCrypting,
254
- int zip64
255
- ));
221
+extern int ZEXPORT zipOpenNewFileInZip3(zipFile file,
222
+ const char* filename,
223
+ const zip_fileinfo* zipfi,
224
+ const void* extrafield_local,
225
+ uInt size_extrafield_local,
226
+ const void* extrafield_global,
227
+ uInt size_extrafield_global,
228
+ const char* comment,
229
+ int method,
230
+ int level,
231
+ int raw,
232
+ int windowBits,
233
+ int memLevel,
234
+ int strategy,
235
+ const char* password,
236
+ uLong crcForCrypting);
237
+
238
+extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file,
239
+ const char* filename,
240
+ const zip_fileinfo* zipfi,
241
+ const void* extrafield_local,
242
+ uInt size_extrafield_local,
243
+ const void* extrafield_global,
244
+ uInt size_extrafield_global,
245
+ const char* comment,
246
+ int method,
247
+ int level,
248
+ int raw,
249
+ int windowBits,
250
+ int memLevel,
251
+ int strategy,
252
+ const char* password,
253
+ uLong crcForCrypting,
254
+ int zip64);
256255
257256
/*
258257
Same than zipOpenNewFileInZip2, except
259258
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
260259
password : crypting password (NULL for no crypting)
261260
crcForCrypting : crc of file to compress (needed for crypting)
262261
*/
263262
264
-extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
265
- const char* filename,
266
- const zip_fileinfo* zipfi,
267
- const void* extrafield_local,
268
- uInt size_extrafield_local,
269
- const void* extrafield_global,
270
- uInt size_extrafield_global,
271
- const char* comment,
272
- int method,
273
- int level,
274
- int raw,
275
- int windowBits,
276
- int memLevel,
277
- int strategy,
278
- const char* password,
279
- uLong crcForCrypting,
280
- uLong versionMadeBy,
281
- uLong flagBase
282
- ));
283
-
284
-
285
-extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
286
- const char* filename,
287
- const zip_fileinfo* zipfi,
288
- const void* extrafield_local,
289
- uInt size_extrafield_local,
290
- const void* extrafield_global,
291
- uInt size_extrafield_global,
292
- const char* comment,
293
- int method,
294
- int level,
295
- int raw,
296
- int windowBits,
297
- int memLevel,
298
- int strategy,
299
- const char* password,
300
- uLong crcForCrypting,
301
- uLong versionMadeBy,
302
- uLong flagBase,
303
- int zip64
304
- ));
263
+extern int ZEXPORT zipOpenNewFileInZip4(zipFile file,
264
+ const char* filename,
265
+ const zip_fileinfo* zipfi,
266
+ const void* extrafield_local,
267
+ uInt size_extrafield_local,
268
+ const void* extrafield_global,
269
+ uInt size_extrafield_global,
270
+ const char* comment,
271
+ int method,
272
+ int level,
273
+ int raw,
274
+ int windowBits,
275
+ int memLevel,
276
+ int strategy,
277
+ const char* password,
278
+ uLong crcForCrypting,
279
+ uLong versionMadeBy,
280
+ uLong flagBase);
281
+
282
+
283
+extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file,
284
+ const char* filename,
285
+ const zip_fileinfo* zipfi,
286
+ const void* extrafield_local,
287
+ uInt size_extrafield_local,
288
+ const void* extrafield_global,
289
+ uInt size_extrafield_global,
290
+ const char* comment,
291
+ int method,
292
+ int level,
293
+ int raw,
294
+ int windowBits,
295
+ int memLevel,
296
+ int strategy,
297
+ const char* password,
298
+ uLong crcForCrypting,
299
+ uLong versionMadeBy,
300
+ uLong flagBase,
301
+ int zip64);
305302
/*
306303
Same than zipOpenNewFileInZip4, except
307304
versionMadeBy : value for Version made by field
308305
flag : value for flag field (compression level info will be added)
309306
*/
310307
311308
312
-extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
313
- const void* buf,
314
- unsigned len));
309
+extern int ZEXPORT zipWriteInFileInZip(zipFile file,
310
+ const void* buf,
311
+ unsigned len);
315312
/*
316313
Write data in the zipfile
317314
*/
318315
319
-extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
316
+extern int ZEXPORT zipCloseFileInZip(zipFile file);
320317
/*
321318
Close the current file in the zipfile
322319
*/
323320
324
-extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
325
- uLong uncompressed_size,
326
- uLong crc32));
321
+extern int ZEXPORT zipCloseFileInZipRaw(zipFile file,
322
+ uLong uncompressed_size,
323
+ uLong crc32);
327324
328
-extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
329
- ZPOS64_T uncompressed_size,
330
- uLong crc32));
325
+extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file,
326
+ ZPOS64_T uncompressed_size,
327
+ uLong crc32);
331328
332329
/*
333330
Close the current file in the zipfile, for file opened with
334331
parameter raw=1 in zipOpenNewFileInZip2
335332
uncompressed_size and crc32 are value for the uncompressed size
336333
*/
337334
338
-extern int ZEXPORT zipClose OF((zipFile file,
339
- const char* global_comment));
335
+extern int ZEXPORT zipClose(zipFile file,
336
+ const char* global_comment);
340337
/*
341338
Close the zipfile
342339
*/
343340
344341
345
-extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
342
+extern int ZEXPORT zipRemoveExtraInfoBlock(char* pData, int* dataLen, short sHeader);
346343
/*
347344
zipRemoveExtraInfoBlock - Added by Mathias Svensson
348345
349346
Remove extra information block from a extra information data for the local file header or central directory header
350347
351348
--- compat/zlib/contrib/minizip/zip.h
+++ compat/zlib/contrib/minizip/zip.h
@@ -111,12 +111,12 @@
111
112 #define APPEND_STATUS_CREATE (0)
113 #define APPEND_STATUS_CREATEAFTER (1)
114 #define APPEND_STATUS_ADDINZIP (2)
115
116 extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
117 extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
118 /*
119 Create a zipfile.
120 pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
121 an Unix computer "zlib/zlib113.zip".
122 if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
@@ -129,50 +129,50 @@
129 of this zip package.
130 */
131
132 /* Note : there is no delete function into a zipfile.
133 If you want delete file into a zipfile, you must open a zipfile, and create another
134 Of couse, you can use RAW reading and writing to copy the file you did not want delte
135 */
136
137 extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
138 int append,
139 zipcharpc* globalcomment,
140 zlib_filefunc_def* pzlib_filefunc_def));
141
142 extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
143 int append,
144 zipcharpc* globalcomment,
145 zlib_filefunc64_def* pzlib_filefunc_def));
146
147 extern zipFile ZEXPORT zipOpen3 OF((const void *pathname,
148 int append,
149 zipcharpc* globalcomment,
150 zlib_filefunc64_32_def* pzlib_filefunc64_32_def));
151
152 extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
153 const char* filename,
154 const zip_fileinfo* zipfi,
155 const void* extrafield_local,
156 uInt size_extrafield_local,
157 const void* extrafield_global,
158 uInt size_extrafield_global,
159 const char* comment,
160 int method,
161 int level));
162
163 extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
164 const char* filename,
165 const zip_fileinfo* zipfi,
166 const void* extrafield_local,
167 uInt size_extrafield_local,
168 const void* extrafield_global,
169 uInt size_extrafield_global,
170 const char* comment,
171 int method,
172 int level,
173 int zip64));
174
175 /*
176 Open a file in the ZIP for writing.
177 filename : the filename in zip (if NULL, '-' without quote will be used
178 *zipfi contain supplemental information
@@ -187,164 +187,161 @@
187 this MUST be '1' if the uncompressed size is >= 0xffffffff.
188
189 */
190
191
192 extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
193 const char* filename,
194 const zip_fileinfo* zipfi,
195 const void* extrafield_local,
196 uInt size_extrafield_local,
197 const void* extrafield_global,
198 uInt size_extrafield_global,
199 const char* comment,
200 int method,
201 int level,
202 int raw));
203
204
205 extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
206 const char* filename,
207 const zip_fileinfo* zipfi,
208 const void* extrafield_local,
209 uInt size_extrafield_local,
210 const void* extrafield_global,
211 uInt size_extrafield_global,
212 const char* comment,
213 int method,
214 int level,
215 int raw,
216 int zip64));
217 /*
218 Same than zipOpenNewFileInZip, except if raw=1, we write raw file
219 */
220
221 extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
222 const char* filename,
223 const zip_fileinfo* zipfi,
224 const void* extrafield_local,
225 uInt size_extrafield_local,
226 const void* extrafield_global,
227 uInt size_extrafield_global,
228 const char* comment,
229 int method,
230 int level,
231 int raw,
232 int windowBits,
233 int memLevel,
234 int strategy,
235 const char* password,
236 uLong crcForCrypting));
237
238 extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
239 const char* filename,
240 const zip_fileinfo* zipfi,
241 const void* extrafield_local,
242 uInt size_extrafield_local,
243 const void* extrafield_global,
244 uInt size_extrafield_global,
245 const char* comment,
246 int method,
247 int level,
248 int raw,
249 int windowBits,
250 int memLevel,
251 int strategy,
252 const char* password,
253 uLong crcForCrypting,
254 int zip64
255 ));
256
257 /*
258 Same than zipOpenNewFileInZip2, except
259 windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
260 password : crypting password (NULL for no crypting)
261 crcForCrypting : crc of file to compress (needed for crypting)
262 */
263
264 extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
265 const char* filename,
266 const zip_fileinfo* zipfi,
267 const void* extrafield_local,
268 uInt size_extrafield_local,
269 const void* extrafield_global,
270 uInt size_extrafield_global,
271 const char* comment,
272 int method,
273 int level,
274 int raw,
275 int windowBits,
276 int memLevel,
277 int strategy,
278 const char* password,
279 uLong crcForCrypting,
280 uLong versionMadeBy,
281 uLong flagBase
282 ));
283
284
285 extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
286 const char* filename,
287 const zip_fileinfo* zipfi,
288 const void* extrafield_local,
289 uInt size_extrafield_local,
290 const void* extrafield_global,
291 uInt size_extrafield_global,
292 const char* comment,
293 int method,
294 int level,
295 int raw,
296 int windowBits,
297 int memLevel,
298 int strategy,
299 const char* password,
300 uLong crcForCrypting,
301 uLong versionMadeBy,
302 uLong flagBase,
303 int zip64
304 ));
305 /*
306 Same than zipOpenNewFileInZip4, except
307 versionMadeBy : value for Version made by field
308 flag : value for flag field (compression level info will be added)
309 */
310
311
312 extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
313 const void* buf,
314 unsigned len));
315 /*
316 Write data in the zipfile
317 */
318
319 extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
320 /*
321 Close the current file in the zipfile
322 */
323
324 extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
325 uLong uncompressed_size,
326 uLong crc32));
327
328 extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
329 ZPOS64_T uncompressed_size,
330 uLong crc32));
331
332 /*
333 Close the current file in the zipfile, for file opened with
334 parameter raw=1 in zipOpenNewFileInZip2
335 uncompressed_size and crc32 are value for the uncompressed size
336 */
337
338 extern int ZEXPORT zipClose OF((zipFile file,
339 const char* global_comment));
340 /*
341 Close the zipfile
342 */
343
344
345 extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
346 /*
347 zipRemoveExtraInfoBlock - Added by Mathias Svensson
348
349 Remove extra information block from a extra information data for the local file header or central directory header
350
351
--- compat/zlib/contrib/minizip/zip.h
+++ compat/zlib/contrib/minizip/zip.h
@@ -111,12 +111,12 @@
111
112 #define APPEND_STATUS_CREATE (0)
113 #define APPEND_STATUS_CREATEAFTER (1)
114 #define APPEND_STATUS_ADDINZIP (2)
115
116 extern zipFile ZEXPORT zipOpen(const char *pathname, int append);
117 extern zipFile ZEXPORT zipOpen64(const void *pathname, int append);
118 /*
119 Create a zipfile.
120 pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
121 an Unix computer "zlib/zlib113.zip".
122 if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
@@ -129,50 +129,50 @@
129 of this zip package.
130 */
131
132 /* Note : there is no delete function into a zipfile.
133 If you want delete file into a zipfile, you must open a zipfile, and create another
134 Of course, you can use RAW reading and writing to copy the file you did not want delete
135 */
136
137 extern zipFile ZEXPORT zipOpen2(const char *pathname,
138 int append,
139 zipcharpc* globalcomment,
140 zlib_filefunc_def* pzlib_filefunc_def);
141
142 extern zipFile ZEXPORT zipOpen2_64(const void *pathname,
143 int append,
144 zipcharpc* globalcomment,
145 zlib_filefunc64_def* pzlib_filefunc_def);
146
147 extern zipFile ZEXPORT zipOpen3(const void *pathname,
148 int append,
149 zipcharpc* globalcomment,
150 zlib_filefunc64_32_def* pzlib_filefunc64_32_def);
151
152 extern int ZEXPORT zipOpenNewFileInZip(zipFile file,
153 const char* filename,
154 const zip_fileinfo* zipfi,
155 const void* extrafield_local,
156 uInt size_extrafield_local,
157 const void* extrafield_global,
158 uInt size_extrafield_global,
159 const char* comment,
160 int method,
161 int level);
162
163 extern int ZEXPORT zipOpenNewFileInZip64(zipFile file,
164 const char* filename,
165 const zip_fileinfo* zipfi,
166 const void* extrafield_local,
167 uInt size_extrafield_local,
168 const void* extrafield_global,
169 uInt size_extrafield_global,
170 const char* comment,
171 int method,
172 int level,
173 int zip64);
174
175 /*
176 Open a file in the ZIP for writing.
177 filename : the filename in zip (if NULL, '-' without quote will be used
178 *zipfi contain supplemental information
@@ -187,164 +187,161 @@
187 this MUST be '1' if the uncompressed size is >= 0xffffffff.
188
189 */
190
191
192 extern int ZEXPORT zipOpenNewFileInZip2(zipFile file,
193 const char* filename,
194 const zip_fileinfo* zipfi,
195 const void* extrafield_local,
196 uInt size_extrafield_local,
197 const void* extrafield_global,
198 uInt size_extrafield_global,
199 const char* comment,
200 int method,
201 int level,
202 int raw);
203
204
205 extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file,
206 const char* filename,
207 const zip_fileinfo* zipfi,
208 const void* extrafield_local,
209 uInt size_extrafield_local,
210 const void* extrafield_global,
211 uInt size_extrafield_global,
212 const char* comment,
213 int method,
214 int level,
215 int raw,
216 int zip64);
217 /*
218 Same than zipOpenNewFileInZip, except if raw=1, we write raw file
219 */
220
221 extern int ZEXPORT zipOpenNewFileInZip3(zipFile file,
222 const char* filename,
223 const zip_fileinfo* zipfi,
224 const void* extrafield_local,
225 uInt size_extrafield_local,
226 const void* extrafield_global,
227 uInt size_extrafield_global,
228 const char* comment,
229 int method,
230 int level,
231 int raw,
232 int windowBits,
233 int memLevel,
234 int strategy,
235 const char* password,
236 uLong crcForCrypting);
237
238 extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file,
239 const char* filename,
240 const zip_fileinfo* zipfi,
241 const void* extrafield_local,
242 uInt size_extrafield_local,
243 const void* extrafield_global,
244 uInt size_extrafield_global,
245 const char* comment,
246 int method,
247 int level,
248 int raw,
249 int windowBits,
250 int memLevel,
251 int strategy,
252 const char* password,
253 uLong crcForCrypting,
254 int zip64);
 
255
256 /*
257 Same than zipOpenNewFileInZip2, except
258 windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
259 password : crypting password (NULL for no crypting)
260 crcForCrypting : crc of file to compress (needed for crypting)
261 */
262
263 extern int ZEXPORT zipOpenNewFileInZip4(zipFile file,
264 const char* filename,
265 const zip_fileinfo* zipfi,
266 const void* extrafield_local,
267 uInt size_extrafield_local,
268 const void* extrafield_global,
269 uInt size_extrafield_global,
270 const char* comment,
271 int method,
272 int level,
273 int raw,
274 int windowBits,
275 int memLevel,
276 int strategy,
277 const char* password,
278 uLong crcForCrypting,
279 uLong versionMadeBy,
280 uLong flagBase);
281
282
283 extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file,
284 const char* filename,
285 const zip_fileinfo* zipfi,
286 const void* extrafield_local,
287 uInt size_extrafield_local,
288 const void* extrafield_global,
289 uInt size_extrafield_global,
290 const char* comment,
291 int method,
292 int level,
293 int raw,
294 int windowBits,
295 int memLevel,
296 int strategy,
297 const char* password,
298 uLong crcForCrypting,
299 uLong versionMadeBy,
300 uLong flagBase,
301 int zip64);
 
 
302 /*
303 Same than zipOpenNewFileInZip4, except
304 versionMadeBy : value for Version made by field
305 flag : value for flag field (compression level info will be added)
306 */
307
308
309 extern int ZEXPORT zipWriteInFileInZip(zipFile file,
310 const void* buf,
311 unsigned len);
312 /*
313 Write data in the zipfile
314 */
315
316 extern int ZEXPORT zipCloseFileInZip(zipFile file);
317 /*
318 Close the current file in the zipfile
319 */
320
321 extern int ZEXPORT zipCloseFileInZipRaw(zipFile file,
322 uLong uncompressed_size,
323 uLong crc32);
324
325 extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file,
326 ZPOS64_T uncompressed_size,
327 uLong crc32);
328
329 /*
330 Close the current file in the zipfile, for file opened with
331 parameter raw=1 in zipOpenNewFileInZip2
332 uncompressed_size and crc32 are value for the uncompressed size
333 */
334
335 extern int ZEXPORT zipClose(zipFile file,
336 const char* global_comment);
337 /*
338 Close the zipfile
339 */
340
341
342 extern int ZEXPORT zipRemoveExtraInfoBlock(char* pData, int* dataLen, short sHeader);
343 /*
344 zipRemoveExtraInfoBlock - Added by Mathias Svensson
345
346 Remove extra information block from a extra information data for the local file header or central directory header
347
348
--- compat/zlib/contrib/pascal/zlibpas.pas
+++ compat/zlib/contrib/pascal/zlibpas.pas
@@ -8,11 +8,11 @@
88
unit zlibpas;
99
1010
interface
1111
1212
const
13
- ZLIB_VERSION = '1.2.13';
13
+ ZLIB_VERSION = '1.3.0';
1414
ZLIB_VERNUM = $12a0;
1515
1616
type
1717
alloc_func = function(opaque: Pointer; items, size: Integer): Pointer;
1818
cdecl;
1919
--- compat/zlib/contrib/pascal/zlibpas.pas
+++ compat/zlib/contrib/pascal/zlibpas.pas
@@ -8,11 +8,11 @@
8 unit zlibpas;
9
10 interface
11
12 const
13 ZLIB_VERSION = '1.2.13';
14 ZLIB_VERNUM = $12a0;
15
16 type
17 alloc_func = function(opaque: Pointer; items, size: Integer): Pointer;
18 cdecl;
19
--- compat/zlib/contrib/pascal/zlibpas.pas
+++ compat/zlib/contrib/pascal/zlibpas.pas
@@ -8,11 +8,11 @@
8 unit zlibpas;
9
10 interface
11
12 const
13 ZLIB_VERSION = '1.3.0';
14 ZLIB_VERNUM = $12a0;
15
16 type
17 alloc_func = function(opaque: Pointer; items, size: Integer): Pointer;
18 cdecl;
19
--- compat/zlib/contrib/testzlib/testzlib.c
+++ compat/zlib/contrib/testzlib/testzlib.c
@@ -167,11 +167,11 @@
167167
if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0)
168168
{
169169
printf("error reading %s\n",argv[1]);
170170
return 1;
171171
}
172
- else printf("file %s read, %u bytes\n",argv[1],lFileSize);
172
+ else printf("file %s read, %ld bytes\n",argv[1],lFileSize);
173173
174174
if (argc>=3)
175175
BlockSizeCompress=atol(argv[2]);
176176
177177
if (argc>=4)
178178
--- compat/zlib/contrib/testzlib/testzlib.c
+++ compat/zlib/contrib/testzlib/testzlib.c
@@ -167,11 +167,11 @@
167 if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0)
168 {
169 printf("error reading %s\n",argv[1]);
170 return 1;
171 }
172 else printf("file %s read, %u bytes\n",argv[1],lFileSize);
173
174 if (argc>=3)
175 BlockSizeCompress=atol(argv[2]);
176
177 if (argc>=4)
178
--- compat/zlib/contrib/testzlib/testzlib.c
+++ compat/zlib/contrib/testzlib/testzlib.c
@@ -167,11 +167,11 @@
167 if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0)
168 {
169 printf("error reading %s\n",argv[1]);
170 return 1;
171 }
172 else printf("file %s read, %ld bytes\n",argv[1],lFileSize);
173
174 if (argc>=3)
175 BlockSizeCompress=atol(argv[2]);
176
177 if (argc>=4)
178
--- compat/zlib/contrib/untgz/untgz.c
+++ compat/zlib/contrib/untgz/untgz.c
@@ -2,10 +2,26 @@
22
* untgz.c -- Display contents and extract files from a gzip'd TAR file
33
*
44
* written by Pedro A. Aranda Gutierrez <[email protected]>
55
* adaptation to Unix by Jean-loup Gailly <[email protected]>
66
* various fixes by Cosmin Truta <[email protected]>
7
+ *
8
+ * This software is provided 'as-is', without any express or implied
9
+ * warranty. In no event will the authors be held liable for any damages
10
+ * arising from the use of this software.
11
+ *
12
+ * Permission is granted to anyone to use this software for any purpose,
13
+ * including commercial applications, and to alter it and redistribute it
14
+ * freely, subject to the following restrictions:
15
+ *
16
+ * 1. The origin of this software must not be misrepresented; you must not
17
+ * claim that you wrote the original software. If you use this software
18
+ * in a product, an acknowledgment in the product documentation would be
19
+ * appreciated but is not required.
20
+ * 2. Altered source versions must be plainly marked as such, and must not be
21
+ * misrepresented as being the original software.
22
+ * 3. This notice may not be removed or altered from any source distribution.
723
*/
824
925
#include <stdio.h>
1026
#include <stdlib.h>
1127
#include <string.h>
@@ -12,19 +28,14 @@
1228
#include <time.h>
1329
#include <errno.h>
1430
1531
#include "zlib.h"
1632
17
-#ifdef unix
18
-# include <unistd.h>
19
-#else
33
+#ifdef _WIN32
2034
# include <direct.h>
2135
# include <io.h>
22
-#endif
23
-
24
-#ifdef WIN32
25
-#include <windows.h>
36
+# include <windows.h>
2637
# ifndef F_OK
2738
# define F_OK 0
2839
# endif
2940
# define mkdir(dirname,mode) _mkdir(dirname)
3041
# ifdef _MSC_VER
@@ -31,10 +42,12 @@
3142
# define access(path,mode) _access(path,mode)
3243
# define chmod(path,mode) _chmod(path,mode)
3344
# define strdup(str) _strdup(str)
3445
# endif
3546
#else
47
+# include <sys/stat.h>
48
+# include <unistd.h>
3649
# include <utime.h>
3750
#endif
3851
3952
4053
/* values used in typeflag field */
@@ -100,31 +113,17 @@
100113
time_t time;
101114
};
102115
103116
enum { TGZ_EXTRACT, TGZ_LIST, TGZ_INVALID };
104117
105
-char *TGZfname OF((const char *));
106
-void TGZnotfound OF((const char *));
107
-
108
-int getoct OF((char *, int));
109
-char *strtime OF((time_t *));
110
-int setfiletime OF((char *, time_t));
111
-void push_attr OF((struct attr_item **, char *, int, time_t));
112
-void restore_attr OF((struct attr_item **));
113
-
114
-int ExprMatch OF((char *, char *));
115
-
116
-int makedir OF((char *));
117
-int matchname OF((int, int, char **, char *));
118
-
119
-void error OF((const char *));
120
-int tar OF((gzFile, int, int, int, char **));
121
-
122
-void help OF((int));
123
-int main OF((int, char **));
124
-
125118
char *prog;
119
+
120
+void error(const char *msg)
121
+{
122
+ fprintf(stderr, "%s: %s\n", prog, msg);
123
+ exit(1);
124
+}
126125
127126
const char *TGZsuffix[] = { "\0", ".tar", ".tar.gz", ".taz", ".tgz", NULL };
128127
129128
/* return the file name of the TGZ archive */
130129
/* or NULL if it does not exist */
@@ -203,11 +202,11 @@
203202
204203
/* set file time */
205204
206205
int setfiletime (char *fname,time_t ftime)
207206
{
208
-#ifdef WIN32
207
+#ifdef _WIN32
209208
static int isWinNT = -1;
210209
SYSTEMTIME st;
211210
FILETIME locft, modft;
212211
struct tm *loctm;
213212
HANDLE hFile;
@@ -588,16 +587,10 @@
588587
" untgz -l file.tgz list archive contents\n"
589588
" untgz -h display this help\n");
590589
exit(exitval);
591590
}
592591
593
-void error(const char *msg)
594
-{
595
- fprintf(stderr, "%s: %s\n", prog, msg);
596
- exit(1);
597
-}
598
-
599592
600593
/* ============================================================ */
601594
602595
#if defined(WIN32) && defined(__GNUC__)
603596
int _CRT_glob = 0; /* disable argument globbing in MinGW */
@@ -606,11 +599,11 @@
606599
int main(int argc,char **argv)
607600
{
608601
int action = TGZ_EXTRACT;
609602
int arg = 1;
610603
char *TGZfile;
611
- gzFile *f;
604
+ gzFile f;
612605
613606
prog = strrchr(argv[0],'\\');
614607
if (prog == NULL)
615608
{
616609
prog = strrchr(argv[0],'/');
617610
--- compat/zlib/contrib/untgz/untgz.c
+++ compat/zlib/contrib/untgz/untgz.c
@@ -2,10 +2,26 @@
2 * untgz.c -- Display contents and extract files from a gzip'd TAR file
3 *
4 * written by Pedro A. Aranda Gutierrez <[email protected]>
5 * adaptation to Unix by Jean-loup Gailly <[email protected]>
6 * various fixes by Cosmin Truta <[email protected]>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7 */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
@@ -12,19 +28,14 @@
12 #include <time.h>
13 #include <errno.h>
14
15 #include "zlib.h"
16
17 #ifdef unix
18 # include <unistd.h>
19 #else
20 # include <direct.h>
21 # include <io.h>
22 #endif
23
24 #ifdef WIN32
25 #include <windows.h>
26 # ifndef F_OK
27 # define F_OK 0
28 # endif
29 # define mkdir(dirname,mode) _mkdir(dirname)
30 # ifdef _MSC_VER
@@ -31,10 +42,12 @@
31 # define access(path,mode) _access(path,mode)
32 # define chmod(path,mode) _chmod(path,mode)
33 # define strdup(str) _strdup(str)
34 # endif
35 #else
 
 
36 # include <utime.h>
37 #endif
38
39
40 /* values used in typeflag field */
@@ -100,31 +113,17 @@
100 time_t time;
101 };
102
103 enum { TGZ_EXTRACT, TGZ_LIST, TGZ_INVALID };
104
105 char *TGZfname OF((const char *));
106 void TGZnotfound OF((const char *));
107
108 int getoct OF((char *, int));
109 char *strtime OF((time_t *));
110 int setfiletime OF((char *, time_t));
111 void push_attr OF((struct attr_item **, char *, int, time_t));
112 void restore_attr OF((struct attr_item **));
113
114 int ExprMatch OF((char *, char *));
115
116 int makedir OF((char *));
117 int matchname OF((int, int, char **, char *));
118
119 void error OF((const char *));
120 int tar OF((gzFile, int, int, int, char **));
121
122 void help OF((int));
123 int main OF((int, char **));
124
125 char *prog;
 
 
 
 
 
 
126
127 const char *TGZsuffix[] = { "\0", ".tar", ".tar.gz", ".taz", ".tgz", NULL };
128
129 /* return the file name of the TGZ archive */
130 /* or NULL if it does not exist */
@@ -203,11 +202,11 @@
203
204 /* set file time */
205
206 int setfiletime (char *fname,time_t ftime)
207 {
208 #ifdef WIN32
209 static int isWinNT = -1;
210 SYSTEMTIME st;
211 FILETIME locft, modft;
212 struct tm *loctm;
213 HANDLE hFile;
@@ -588,16 +587,10 @@
588 " untgz -l file.tgz list archive contents\n"
589 " untgz -h display this help\n");
590 exit(exitval);
591 }
592
593 void error(const char *msg)
594 {
595 fprintf(stderr, "%s: %s\n", prog, msg);
596 exit(1);
597 }
598
599
600 /* ============================================================ */
601
602 #if defined(WIN32) && defined(__GNUC__)
603 int _CRT_glob = 0; /* disable argument globbing in MinGW */
@@ -606,11 +599,11 @@
606 int main(int argc,char **argv)
607 {
608 int action = TGZ_EXTRACT;
609 int arg = 1;
610 char *TGZfile;
611 gzFile *f;
612
613 prog = strrchr(argv[0],'\\');
614 if (prog == NULL)
615 {
616 prog = strrchr(argv[0],'/');
617
--- compat/zlib/contrib/untgz/untgz.c
+++ compat/zlib/contrib/untgz/untgz.c
@@ -2,10 +2,26 @@
2 * untgz.c -- Display contents and extract files from a gzip'd TAR file
3 *
4 * written by Pedro A. Aranda Gutierrez <[email protected]>
5 * adaptation to Unix by Jean-loup Gailly <[email protected]>
6 * various fixes by Cosmin Truta <[email protected]>
7 *
8 * This software is provided 'as-is', without any express or implied
9 * warranty. In no event will the authors be held liable for any damages
10 * arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose,
13 * including commercial applications, and to alter it and redistribute it
14 * freely, subject to the following restrictions:
15 *
16 * 1. The origin of this software must not be misrepresented; you must not
17 * claim that you wrote the original software. If you use this software
18 * in a product, an acknowledgment in the product documentation would be
19 * appreciated but is not required.
20 * 2. Altered source versions must be plainly marked as such, and must not be
21 * misrepresented as being the original software.
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
@@ -12,19 +28,14 @@
28 #include <time.h>
29 #include <errno.h>
30
31 #include "zlib.h"
32
33 #ifdef _WIN32
 
 
34 # include <direct.h>
35 # include <io.h>
36 # include <windows.h>
 
 
 
37 # ifndef F_OK
38 # define F_OK 0
39 # endif
40 # define mkdir(dirname,mode) _mkdir(dirname)
41 # ifdef _MSC_VER
@@ -31,10 +42,12 @@
42 # define access(path,mode) _access(path,mode)
43 # define chmod(path,mode) _chmod(path,mode)
44 # define strdup(str) _strdup(str)
45 # endif
46 #else
47 # include <sys/stat.h>
48 # include <unistd.h>
49 # include <utime.h>
50 #endif
51
52
53 /* values used in typeflag field */
@@ -100,31 +113,17 @@
113 time_t time;
114 };
115
116 enum { TGZ_EXTRACT, TGZ_LIST, TGZ_INVALID };
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118 char *prog;
119
120 void error(const char *msg)
121 {
122 fprintf(stderr, "%s: %s\n", prog, msg);
123 exit(1);
124 }
125
126 const char *TGZsuffix[] = { "\0", ".tar", ".tar.gz", ".taz", ".tgz", NULL };
127
128 /* return the file name of the TGZ archive */
129 /* or NULL if it does not exist */
@@ -203,11 +202,11 @@
202
203 /* set file time */
204
205 int setfiletime (char *fname,time_t ftime)
206 {
207 #ifdef _WIN32
208 static int isWinNT = -1;
209 SYSTEMTIME st;
210 FILETIME locft, modft;
211 struct tm *loctm;
212 HANDLE hFile;
@@ -588,16 +587,10 @@
587 " untgz -l file.tgz list archive contents\n"
588 " untgz -h display this help\n");
589 exit(exitval);
590 }
591
 
 
 
 
 
 
592
593 /* ============================================================ */
594
595 #if defined(WIN32) && defined(__GNUC__)
596 int _CRT_glob = 0; /* disable argument globbing in MinGW */
@@ -606,11 +599,11 @@
599 int main(int argc,char **argv)
600 {
601 int action = TGZ_EXTRACT;
602 int arg = 1;
603 char *TGZfile;
604 gzFile f;
605
606 prog = strrchr(argv[0],'\\');
607 if (prog == NULL)
608 {
609 prog = strrchr(argv[0],'/');
610
--- compat/zlib/contrib/vstudio/readme.txt
+++ compat/zlib/contrib/vstudio/readme.txt
@@ -1,6 +1,6 @@
1
-Building instructions for the DLL versions of Zlib 1.2.13
1
+Building instructions for the DLL versions of Zlib 1.3.0
22
========================================================
33
44
This directory contains projects that build zlib and minizip using
55
Microsoft Visual C++ 9.0/10.0.
66
77
--- compat/zlib/contrib/vstudio/readme.txt
+++ compat/zlib/contrib/vstudio/readme.txt
@@ -1,6 +1,6 @@
1 Building instructions for the DLL versions of Zlib 1.2.13
2 ========================================================
3
4 This directory contains projects that build zlib and minizip using
5 Microsoft Visual C++ 9.0/10.0.
6
7
--- compat/zlib/contrib/vstudio/readme.txt
+++ compat/zlib/contrib/vstudio/readme.txt
@@ -1,6 +1,6 @@
1 Building instructions for the DLL versions of Zlib 1.3.0
2 ========================================================
3
4 This directory contains projects that build zlib and minizip using
5 Microsoft Visual C++ 9.0/10.0.
6
7
--- compat/zlib/contrib/vstudio/vc10/zlib.rc
+++ compat/zlib/contrib/vstudio/vc10/zlib.rc
@@ -1,11 +1,11 @@
11
#include <windows.h>
22
33
#define IDR_VERSION1 1
44
IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5
- FILEVERSION 1, 2, 13, 0
6
- PRODUCTVERSION 1, 2, 13, 0
5
+ FILEVERSION 1, 3, 0, 0
6
+ PRODUCTVERSION 1, 3, 0, 0
77
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
88
FILEFLAGS 0
99
FILEOS VOS_DOS_WINDOWS32
1010
FILETYPE VFT_DLL
1111
FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
1515
BLOCK "040904E4"
1616
//language ID = U.S. English, char set = Windows, Multilingual
1717
1818
BEGIN
1919
VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20
- VALUE "FileVersion", "1.2.13\0"
20
+ VALUE "FileVersion", "1.3.0\0"
2121
VALUE "InternalName", "zlib\0"
2222
VALUE "OriginalFilename", "zlibwapi.dll\0"
2323
VALUE "ProductName", "ZLib.DLL\0"
2424
VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25
- VALUE "LegalCopyright", "(C) 1995-2022 Jean-loup Gailly & Mark Adler\0"
25
+ VALUE "LegalCopyright", "(C) 1995-2023 Jean-loup Gailly & Mark Adler\0"
2626
END
2727
END
2828
BLOCK "VarFileInfo"
2929
BEGIN
3030
VALUE "Translation", 0x0409, 1252
3131
END
3232
END
3333
--- compat/zlib/contrib/vstudio/vc10/zlib.rc
+++ compat/zlib/contrib/vstudio/vc10/zlib.rc
@@ -1,11 +1,11 @@
1 #include <windows.h>
2
3 #define IDR_VERSION1 1
4 IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1, 2, 13, 0
6 PRODUCTVERSION 1, 2, 13, 0
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32
10 FILETYPE VFT_DLL
11 FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
15 BLOCK "040904E4"
16 //language ID = U.S. English, char set = Windows, Multilingual
17
18 BEGIN
19 VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20 VALUE "FileVersion", "1.2.13\0"
21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlibwapi.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0"
24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25 VALUE "LegalCopyright", "(C) 1995-2022 Jean-loup Gailly & Mark Adler\0"
26 END
27 END
28 BLOCK "VarFileInfo"
29 BEGIN
30 VALUE "Translation", 0x0409, 1252
31 END
32 END
33
--- compat/zlib/contrib/vstudio/vc10/zlib.rc
+++ compat/zlib/contrib/vstudio/vc10/zlib.rc
@@ -1,11 +1,11 @@
1 #include <windows.h>
2
3 #define IDR_VERSION1 1
4 IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1, 3, 0, 0
6 PRODUCTVERSION 1, 3, 0, 0
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32
10 FILETYPE VFT_DLL
11 FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
15 BLOCK "040904E4"
16 //language ID = U.S. English, char set = Windows, Multilingual
17
18 BEGIN
19 VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20 VALUE "FileVersion", "1.3.0\0"
21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlibwapi.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0"
24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25 VALUE "LegalCopyright", "(C) 1995-2023 Jean-loup Gailly & Mark Adler\0"
26 END
27 END
28 BLOCK "VarFileInfo"
29 BEGIN
30 VALUE "Translation", 0x0409, 1252
31 END
32 END
33
--- compat/zlib/contrib/vstudio/vc10/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc10/zlibvc.def
@@ -1,9 +1,9 @@
11
LIBRARY
22
; zlib data compression and ZIP file I/O library
33
4
-VERSION 1.2
4
+VERSION 1.3
55
66
EXPORTS
77
adler32 @1
88
compress @2
99
crc32 @3
1010
--- compat/zlib/contrib/vstudio/vc10/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc10/zlibvc.def
@@ -1,9 +1,9 @@
1 LIBRARY
2 ; zlib data compression and ZIP file I/O library
3
4 VERSION 1.2
5
6 EXPORTS
7 adler32 @1
8 compress @2
9 crc32 @3
10
--- compat/zlib/contrib/vstudio/vc10/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc10/zlibvc.def
@@ -1,9 +1,9 @@
1 LIBRARY
2 ; zlib data compression and ZIP file I/O library
3
4 VERSION 1.3
5
6 EXPORTS
7 adler32 @1
8 compress @2
9 crc32 @3
10
--- compat/zlib/contrib/vstudio/vc11/zlib.rc
+++ compat/zlib/contrib/vstudio/vc11/zlib.rc
@@ -1,11 +1,11 @@
11
#include <windows.h>
22
33
#define IDR_VERSION1 1
44
IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5
- FILEVERSION 1, 2, 13, 0
6
- PRODUCTVERSION 1, 2, 13, 0
5
+ FILEVERSION 1, 3, 0, 0
6
+ PRODUCTVERSION 1, 3, 0, 0
77
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
88
FILEFLAGS 0
99
FILEOS VOS_DOS_WINDOWS32
1010
FILETYPE VFT_DLL
1111
FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
1515
BLOCK "040904E4"
1616
//language ID = U.S. English, char set = Windows, Multilingual
1717
1818
BEGIN
1919
VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20
- VALUE "FileVersion", "1.2.13\0"
20
+ VALUE "FileVersion", "1.3.0\0"
2121
VALUE "InternalName", "zlib\0"
2222
VALUE "OriginalFilename", "zlibwapi.dll\0"
2323
VALUE "ProductName", "ZLib.DLL\0"
2424
VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25
- VALUE "LegalCopyright", "(C) 1995-2022 Jean-loup Gailly & Mark Adler\0"
25
+ VALUE "LegalCopyright", "(C) 1995-2023 Jean-loup Gailly & Mark Adler\0"
2626
END
2727
END
2828
BLOCK "VarFileInfo"
2929
BEGIN
3030
VALUE "Translation", 0x0409, 1252
3131
END
3232
END
3333
--- compat/zlib/contrib/vstudio/vc11/zlib.rc
+++ compat/zlib/contrib/vstudio/vc11/zlib.rc
@@ -1,11 +1,11 @@
1 #include <windows.h>
2
3 #define IDR_VERSION1 1
4 IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1, 2, 13, 0
6 PRODUCTVERSION 1, 2, 13, 0
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32
10 FILETYPE VFT_DLL
11 FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
15 BLOCK "040904E4"
16 //language ID = U.S. English, char set = Windows, Multilingual
17
18 BEGIN
19 VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20 VALUE "FileVersion", "1.2.13\0"
21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlibwapi.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0"
24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25 VALUE "LegalCopyright", "(C) 1995-2022 Jean-loup Gailly & Mark Adler\0"
26 END
27 END
28 BLOCK "VarFileInfo"
29 BEGIN
30 VALUE "Translation", 0x0409, 1252
31 END
32 END
33
--- compat/zlib/contrib/vstudio/vc11/zlib.rc
+++ compat/zlib/contrib/vstudio/vc11/zlib.rc
@@ -1,11 +1,11 @@
1 #include <windows.h>
2
3 #define IDR_VERSION1 1
4 IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1, 3, 0, 0
6 PRODUCTVERSION 1, 3, 0, 0
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32
10 FILETYPE VFT_DLL
11 FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
15 BLOCK "040904E4"
16 //language ID = U.S. English, char set = Windows, Multilingual
17
18 BEGIN
19 VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20 VALUE "FileVersion", "1.3.0\0"
21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlibwapi.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0"
24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25 VALUE "LegalCopyright", "(C) 1995-2023 Jean-loup Gailly & Mark Adler\0"
26 END
27 END
28 BLOCK "VarFileInfo"
29 BEGIN
30 VALUE "Translation", 0x0409, 1252
31 END
32 END
33
--- compat/zlib/contrib/vstudio/vc11/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc11/zlibvc.def
@@ -1,9 +1,9 @@
11
LIBRARY
22
; zlib data compression and ZIP file I/O library
33
4
-VERSION 1.2
4
+VERSION 1.3
55
66
EXPORTS
77
adler32 @1
88
compress @2
99
crc32 @3
1010
--- compat/zlib/contrib/vstudio/vc11/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc11/zlibvc.def
@@ -1,9 +1,9 @@
1 LIBRARY
2 ; zlib data compression and ZIP file I/O library
3
4 VERSION 1.2
5
6 EXPORTS
7 adler32 @1
8 compress @2
9 crc32 @3
10
--- compat/zlib/contrib/vstudio/vc11/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc11/zlibvc.def
@@ -1,9 +1,9 @@
1 LIBRARY
2 ; zlib data compression and ZIP file I/O library
3
4 VERSION 1.3
5
6 EXPORTS
7 adler32 @1
8 compress @2
9 crc32 @3
10
--- compat/zlib/contrib/vstudio/vc12/zlib.rc
+++ compat/zlib/contrib/vstudio/vc12/zlib.rc
@@ -1,11 +1,11 @@
11
#include <windows.h>
22
33
#define IDR_VERSION1 1
44
IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5
- FILEVERSION 1, 2, 13, 0
6
- PRODUCTVERSION 1, 2, 13, 0
5
+ FILEVERSION 1, 3, 0, 0
6
+ PRODUCTVERSION 1, 3, 0, 0
77
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
88
FILEFLAGS 0
99
FILEOS VOS_DOS_WINDOWS32
1010
FILETYPE VFT_DLL
1111
FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
1515
BLOCK "040904E4"
1616
//language ID = U.S. English, char set = Windows, Multilingual
1717
1818
BEGIN
1919
VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20
- VALUE "FileVersion", "1.2.13\0"
20
+ VALUE "FileVersion", "1.3.0\0"
2121
VALUE "InternalName", "zlib\0"
2222
VALUE "OriginalFilename", "zlibwapi.dll\0"
2323
VALUE "ProductName", "ZLib.DLL\0"
2424
VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25
- VALUE "LegalCopyright", "(C) 1995-2022 Jean-loup Gailly & Mark Adler\0"
25
+ VALUE "LegalCopyright", "(C) 1995-2023 Jean-loup Gailly & Mark Adler\0"
2626
END
2727
END
2828
BLOCK "VarFileInfo"
2929
BEGIN
3030
VALUE "Translation", 0x0409, 1252
3131
END
3232
END
3333
--- compat/zlib/contrib/vstudio/vc12/zlib.rc
+++ compat/zlib/contrib/vstudio/vc12/zlib.rc
@@ -1,11 +1,11 @@
1 #include <windows.h>
2
3 #define IDR_VERSION1 1
4 IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1, 2, 13, 0
6 PRODUCTVERSION 1, 2, 13, 0
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32
10 FILETYPE VFT_DLL
11 FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
15 BLOCK "040904E4"
16 //language ID = U.S. English, char set = Windows, Multilingual
17
18 BEGIN
19 VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20 VALUE "FileVersion", "1.2.13\0"
21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlibwapi.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0"
24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25 VALUE "LegalCopyright", "(C) 1995-2022 Jean-loup Gailly & Mark Adler\0"
26 END
27 END
28 BLOCK "VarFileInfo"
29 BEGIN
30 VALUE "Translation", 0x0409, 1252
31 END
32 END
33
--- compat/zlib/contrib/vstudio/vc12/zlib.rc
+++ compat/zlib/contrib/vstudio/vc12/zlib.rc
@@ -1,11 +1,11 @@
1 #include <windows.h>
2
3 #define IDR_VERSION1 1
4 IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1, 3, 0, 0
6 PRODUCTVERSION 1, 3, 0, 0
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32
10 FILETYPE VFT_DLL
11 FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
15 BLOCK "040904E4"
16 //language ID = U.S. English, char set = Windows, Multilingual
17
18 BEGIN
19 VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20 VALUE "FileVersion", "1.3.0\0"
21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlibwapi.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0"
24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25 VALUE "LegalCopyright", "(C) 1995-2023 Jean-loup Gailly & Mark Adler\0"
26 END
27 END
28 BLOCK "VarFileInfo"
29 BEGIN
30 VALUE "Translation", 0x0409, 1252
31 END
32 END
33
--- compat/zlib/contrib/vstudio/vc12/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc12/zlibvc.def
@@ -1,9 +1,9 @@
11
LIBRARY
22
; zlib data compression and ZIP file I/O library
33
4
-VERSION 1.2
4
+VERSION 1.3
55
66
EXPORTS
77
adler32 @1
88
compress @2
99
crc32 @3
1010
--- compat/zlib/contrib/vstudio/vc12/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc12/zlibvc.def
@@ -1,9 +1,9 @@
1 LIBRARY
2 ; zlib data compression and ZIP file I/O library
3
4 VERSION 1.2
5
6 EXPORTS
7 adler32 @1
8 compress @2
9 crc32 @3
10
--- compat/zlib/contrib/vstudio/vc12/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc12/zlibvc.def
@@ -1,9 +1,9 @@
1 LIBRARY
2 ; zlib data compression and ZIP file I/O library
3
4 VERSION 1.3
5
6 EXPORTS
7 adler32 @1
8 compress @2
9 crc32 @3
10
--- compat/zlib/contrib/vstudio/vc14/zlib.rc
+++ compat/zlib/contrib/vstudio/vc14/zlib.rc
@@ -1,11 +1,11 @@
11
#include <windows.h>
22
33
#define IDR_VERSION1 1
44
IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5
- FILEVERSION 1, 2, 13, 0
6
- PRODUCTVERSION 1, 2, 13, 0
5
+ FILEVERSION 1, 3, 0, 0
6
+ PRODUCTVERSION 1, 3, 0, 0
77
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
88
FILEFLAGS 0
99
FILEOS VOS_DOS_WINDOWS32
1010
FILETYPE VFT_DLL
1111
FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
1515
BLOCK "040904E4"
1616
//language ID = U.S. English, char set = Windows, Multilingual
1717
1818
BEGIN
1919
VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20
- VALUE "FileVersion", "1.2.13\0"
20
+ VALUE "FileVersion", "1.3.0\0"
2121
VALUE "InternalName", "zlib\0"
2222
VALUE "OriginalFilename", "zlibwapi.dll\0"
2323
VALUE "ProductName", "ZLib.DLL\0"
2424
VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25
- VALUE "LegalCopyright", "(C) 1995-2022 Jean-loup Gailly & Mark Adler\0"
25
+ VALUE "LegalCopyright", "(C) 1995-2023 Jean-loup Gailly & Mark Adler\0"
2626
END
2727
END
2828
BLOCK "VarFileInfo"
2929
BEGIN
3030
VALUE "Translation", 0x0409, 1252
3131
END
3232
END
3333
--- compat/zlib/contrib/vstudio/vc14/zlib.rc
+++ compat/zlib/contrib/vstudio/vc14/zlib.rc
@@ -1,11 +1,11 @@
1 #include <windows.h>
2
3 #define IDR_VERSION1 1
4 IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1, 2, 13, 0
6 PRODUCTVERSION 1, 2, 13, 0
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32
10 FILETYPE VFT_DLL
11 FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
15 BLOCK "040904E4"
16 //language ID = U.S. English, char set = Windows, Multilingual
17
18 BEGIN
19 VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20 VALUE "FileVersion", "1.2.13\0"
21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlibwapi.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0"
24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25 VALUE "LegalCopyright", "(C) 1995-2022 Jean-loup Gailly & Mark Adler\0"
26 END
27 END
28 BLOCK "VarFileInfo"
29 BEGIN
30 VALUE "Translation", 0x0409, 1252
31 END
32 END
33
--- compat/zlib/contrib/vstudio/vc14/zlib.rc
+++ compat/zlib/contrib/vstudio/vc14/zlib.rc
@@ -1,11 +1,11 @@
1 #include <windows.h>
2
3 #define IDR_VERSION1 1
4 IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1, 3, 0, 0
6 PRODUCTVERSION 1, 3, 0, 0
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32
10 FILETYPE VFT_DLL
11 FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
15 BLOCK "040904E4"
16 //language ID = U.S. English, char set = Windows, Multilingual
17
18 BEGIN
19 VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20 VALUE "FileVersion", "1.3.0\0"
21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlibwapi.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0"
24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25 VALUE "LegalCopyright", "(C) 1995-2023 Jean-loup Gailly & Mark Adler\0"
26 END
27 END
28 BLOCK "VarFileInfo"
29 BEGIN
30 VALUE "Translation", 0x0409, 1252
31 END
32 END
33
--- compat/zlib/contrib/vstudio/vc14/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc14/zlibvc.def
@@ -1,9 +1,9 @@
11
LIBRARY
22
; zlib data compression and ZIP file I/O library
33
4
-VERSION 1.2
4
+VERSION 1.3
55
66
EXPORTS
77
adler32 @1
88
compress @2
99
crc32 @3
1010
--- compat/zlib/contrib/vstudio/vc14/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc14/zlibvc.def
@@ -1,9 +1,9 @@
1 LIBRARY
2 ; zlib data compression and ZIP file I/O library
3
4 VERSION 1.2
5
6 EXPORTS
7 adler32 @1
8 compress @2
9 crc32 @3
10
--- compat/zlib/contrib/vstudio/vc14/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc14/zlibvc.def
@@ -1,9 +1,9 @@
1 LIBRARY
2 ; zlib data compression and ZIP file I/O library
3
4 VERSION 1.3
5
6 EXPORTS
7 adler32 @1
8 compress @2
9 crc32 @3
10
--- compat/zlib/contrib/vstudio/vc9/zlib.rc
+++ compat/zlib/contrib/vstudio/vc9/zlib.rc
@@ -1,11 +1,11 @@
11
#include <windows.h>
22
33
#define IDR_VERSION1 1
44
IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5
- FILEVERSION 1, 2, 13, 0
6
- PRODUCTVERSION 1, 2, 13, 0
5
+ FILEVERSION 1, 3, 0, 0
6
+ PRODUCTVERSION 1, 3, 0, 0
77
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
88
FILEFLAGS 0
99
FILEOS VOS_DOS_WINDOWS32
1010
FILETYPE VFT_DLL
1111
FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
1515
BLOCK "040904E4"
1616
//language ID = U.S. English, char set = Windows, Multilingual
1717
1818
BEGIN
1919
VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20
- VALUE "FileVersion", "1.2.13\0"
20
+ VALUE "FileVersion", "1.3.0\0"
2121
VALUE "InternalName", "zlib\0"
2222
VALUE "OriginalFilename", "zlibwapi.dll\0"
2323
VALUE "ProductName", "ZLib.DLL\0"
2424
VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25
- VALUE "LegalCopyright", "(C) 1995-2022 Jean-loup Gailly & Mark Adler\0"
25
+ VALUE "LegalCopyright", "(C) 1995-2023 Jean-loup Gailly & Mark Adler\0"
2626
END
2727
END
2828
BLOCK "VarFileInfo"
2929
BEGIN
3030
VALUE "Translation", 0x0409, 1252
3131
END
3232
END
3333
--- compat/zlib/contrib/vstudio/vc9/zlib.rc
+++ compat/zlib/contrib/vstudio/vc9/zlib.rc
@@ -1,11 +1,11 @@
1 #include <windows.h>
2
3 #define IDR_VERSION1 1
4 IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1, 2, 13, 0
6 PRODUCTVERSION 1, 2, 13, 0
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32
10 FILETYPE VFT_DLL
11 FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
15 BLOCK "040904E4"
16 //language ID = U.S. English, char set = Windows, Multilingual
17
18 BEGIN
19 VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20 VALUE "FileVersion", "1.2.13\0"
21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlibwapi.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0"
24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25 VALUE "LegalCopyright", "(C) 1995-2022 Jean-loup Gailly & Mark Adler\0"
26 END
27 END
28 BLOCK "VarFileInfo"
29 BEGIN
30 VALUE "Translation", 0x0409, 1252
31 END
32 END
33
--- compat/zlib/contrib/vstudio/vc9/zlib.rc
+++ compat/zlib/contrib/vstudio/vc9/zlib.rc
@@ -1,11 +1,11 @@
1 #include <windows.h>
2
3 #define IDR_VERSION1 1
4 IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1, 3, 0, 0
6 PRODUCTVERSION 1, 3, 0, 0
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32
10 FILETYPE VFT_DLL
11 FILESUBTYPE 0 // not used
@@ -15,18 +15,18 @@
15 BLOCK "040904E4"
16 //language ID = U.S. English, char set = Windows, Multilingual
17
18 BEGIN
19 VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0"
20 VALUE "FileVersion", "1.3.0\0"
21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlibwapi.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0"
24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25 VALUE "LegalCopyright", "(C) 1995-2023 Jean-loup Gailly & Mark Adler\0"
26 END
27 END
28 BLOCK "VarFileInfo"
29 BEGIN
30 VALUE "Translation", 0x0409, 1252
31 END
32 END
33
--- compat/zlib/contrib/vstudio/vc9/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc9/zlibvc.def
@@ -1,9 +1,9 @@
11
LIBRARY
22
; zlib data compression and ZIP file I/O library
33
4
-VERSION 1.2
4
+VERSION 1.3
55
66
EXPORTS
77
adler32 @1
88
compress @2
99
crc32 @3
1010
--- compat/zlib/contrib/vstudio/vc9/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc9/zlibvc.def
@@ -1,9 +1,9 @@
1 LIBRARY
2 ; zlib data compression and ZIP file I/O library
3
4 VERSION 1.2
5
6 EXPORTS
7 adler32 @1
8 compress @2
9 crc32 @3
10
--- compat/zlib/contrib/vstudio/vc9/zlibvc.def
+++ compat/zlib/contrib/vstudio/vc9/zlibvc.def
@@ -1,9 +1,9 @@
1 LIBRARY
2 ; zlib data compression and ZIP file I/O library
3
4 VERSION 1.3
5
6 EXPORTS
7 adler32 @1
8 compress @2
9 crc32 @3
10
+86 -162
--- compat/zlib/crc32.c
+++ compat/zlib/crc32.c
@@ -101,33 +101,18 @@
101101
/* If available, use the ARM processor CRC32 instruction. */
102102
#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) && W == 8
103103
# define ARMCRC32
104104
#endif
105105
106
-/* Local functions. */
107
-local z_crc_t multmodp OF((z_crc_t a, z_crc_t b));
108
-local z_crc_t x2nmodp OF((z_off64_t n, unsigned k));
109
-
110
-#if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE))
111
- local z_word_t byte_swap OF((z_word_t word));
112
-#endif
113
-
114
-#if defined(W) && !defined(ARMCRC32)
115
- local z_crc_t crc_word OF((z_word_t data));
116
- local z_word_t crc_word_big OF((z_word_t data));
117
-#endif
118
-
119106
#if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE))
120107
/*
121108
Swap the bytes in a z_word_t to convert between little and big endian. Any
122109
self-respecting compiler will optimize this to a single machine byte-swap
123110
instruction, if one is available. This assumes that word_t is either 32 bits
124111
or 64 bits.
125112
*/
126
-local z_word_t byte_swap(word)
127
- z_word_t word;
128
-{
113
+local z_word_t byte_swap(z_word_t word) {
129114
# if W == 8
130115
return
131116
(word & 0xff00000000000000) >> 56 |
132117
(word & 0xff000000000000) >> 40 |
133118
(word & 0xff0000000000) >> 24 |
@@ -143,29 +128,82 @@
143128
(word & 0xff00) << 8 |
144129
(word & 0xff) << 24;
145130
# endif
146131
}
147132
#endif
133
+
134
+#ifdef DYNAMIC_CRC_TABLE
135
+/* =========================================================================
136
+ * Table of powers of x for combining CRC-32s, filled in by make_crc_table()
137
+ * below.
138
+ */
139
+ local z_crc_t FAR x2n_table[32];
140
+#else
141
+/* =========================================================================
142
+ * Tables for byte-wise and braided CRC-32 calculations, and a table of powers
143
+ * of x for combining CRC-32s, all made by make_crc_table().
144
+ */
145
+# include "crc32.h"
146
+#endif
148147
149148
/* CRC polynomial. */
150149
#define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */
150
+
151
+/*
152
+ Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial,
153
+ reflected. For speed, this requires that a not be zero.
154
+ */
155
+local z_crc_t multmodp(z_crc_t a, z_crc_t b) {
156
+ z_crc_t m, p;
157
+
158
+ m = (z_crc_t)1 << 31;
159
+ p = 0;
160
+ for (;;) {
161
+ if (a & m) {
162
+ p ^= b;
163
+ if ((a & (m - 1)) == 0)
164
+ break;
165
+ }
166
+ m >>= 1;
167
+ b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
168
+ }
169
+ return p;
170
+}
171
+
172
+/*
173
+ Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been
174
+ initialized.
175
+ */
176
+local z_crc_t x2nmodp(z_off64_t n, unsigned k) {
177
+ z_crc_t p;
178
+
179
+ p = (z_crc_t)1 << 31; /* x^0 == 1 */
180
+ while (n) {
181
+ if (n & 1)
182
+ p = multmodp(x2n_table[k & 31], p);
183
+ n >>= 1;
184
+ k++;
185
+ }
186
+ return p;
187
+}
151188
152189
#ifdef DYNAMIC_CRC_TABLE
153
-
190
+/* =========================================================================
191
+ * Build the tables for byte-wise and braided CRC-32 calculations, and a table
192
+ * of powers of x for combining CRC-32s.
193
+ */
154194
local z_crc_t FAR crc_table[256];
155
-local z_crc_t FAR x2n_table[32];
156
-local void make_crc_table OF((void));
157195
#ifdef W
158196
local z_word_t FAR crc_big_table[256];
159197
local z_crc_t FAR crc_braid_table[W][256];
160198
local z_word_t FAR crc_braid_big_table[W][256];
161
- local void braid OF((z_crc_t [][256], z_word_t [][256], int, int));
199
+ local void braid(z_crc_t [][256], z_word_t [][256], int, int);
162200
#endif
163201
#ifdef MAKECRCH
164
- local void write_table OF((FILE *, const z_crc_t FAR *, int));
165
- local void write_table32hi OF((FILE *, const z_word_t FAR *, int));
166
- local void write_table64 OF((FILE *, const z_word_t FAR *, int));
202
+ local void write_table(FILE *, const z_crc_t FAR *, int);
203
+ local void write_table32hi(FILE *, const z_word_t FAR *, int);
204
+ local void write_table64(FILE *, const z_word_t FAR *, int);
167205
#endif /* MAKECRCH */
168206
169207
/*
170208
Define a once() function depending on the availability of atomics. If this is
171209
compiled with DYNAMIC_CRC_TABLE defined, and if CRCs will be computed in
@@ -174,11 +212,10 @@
174212
allowed to compute or combine CRCs.
175213
*/
176214
177215
/* Definition of once functionality. */
178216
typedef struct once_s once_t;
179
-local void once OF((once_t *, void (*)(void)));
180217
181218
/* Check for the availability of atomics. */
182219
#if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \
183220
!defined(__STDC_NO_ATOMICS__)
184221
@@ -194,14 +231,11 @@
194231
/*
195232
Run the provided init() function exactly once, even if multiple threads
196233
invoke once() at the same time. The state must be a once_t initialized with
197234
ONCE_INIT.
198235
*/
199
-local void once(state, init)
200
- once_t *state;
201
- void (*init)(void);
202
-{
236
+local void once(once_t *state, void (*init)(void)) {
203237
if (!atomic_load(&state->done)) {
204238
if (atomic_flag_test_and_set(&state->begun))
205239
while (!atomic_load(&state->done))
206240
;
207241
else {
@@ -220,26 +254,20 @@
220254
};
221255
#define ONCE_INIT {0, 0}
222256
223257
/* Test and set. Alas, not atomic, but tries to minimize the period of
224258
vulnerability. */
225
-local int test_and_set OF((int volatile *));
226
-local int test_and_set(flag)
227
- int volatile *flag;
228
-{
259
+local int test_and_set(int volatile *flag) {
229260
int was;
230261
231262
was = *flag;
232263
*flag = 1;
233264
return was;
234265
}
235266
236267
/* Run the provided init() function once. This is not thread-safe. */
237
-local void once(state, init)
238
- once_t *state;
239
- void (*init)(void);
240
-{
268
+local void once(once_t *state, void (*init)(void)) {
241269
if (!state->done) {
242270
if (test_and_set(&state->begun))
243271
while (!state->done)
244272
;
245273
else {
@@ -277,12 +305,11 @@
277305
The table is simply the CRC of all possible eight bit values. This is all the
278306
information needed to generate CRCs on data a byte at a time for all
279307
combinations of CRC register values and incoming bytes.
280308
*/
281309
282
-local void make_crc_table()
283
-{
310
+local void make_crc_table(void) {
284311
unsigned i, j, n;
285312
z_crc_t p;
286313
287314
/* initialize the CRC of bytes tables */
288315
for (i = 0; i < 256; i++) {
@@ -445,15 +472,11 @@
445472
446473
/*
447474
Write the 32-bit values in table[0..k-1] to out, five per line in
448475
hexadecimal separated by commas.
449476
*/
450
-local void write_table(out, table, k)
451
- FILE *out;
452
- const z_crc_t FAR *table;
453
- int k;
454
-{
477
+local void write_table(FILE *out, const z_crc_t FAR *table, int k) {
455478
int n;
456479
457480
for (n = 0; n < k; n++)
458481
fprintf(out, "%s0x%08lx%s", n == 0 || n % 5 ? "" : " ",
459482
(unsigned long)(table[n]),
@@ -462,15 +485,11 @@
462485
463486
/*
464487
Write the high 32-bits of each value in table[0..k-1] to out, five per line
465488
in hexadecimal separated by commas.
466489
*/
467
-local void write_table32hi(out, table, k)
468
-FILE *out;
469
-const z_word_t FAR *table;
470
-int k;
471
-{
490
+local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) {
472491
int n;
473492
474493
for (n = 0; n < k; n++)
475494
fprintf(out, "%s0x%08lx%s", n == 0 || n % 5 ? "" : " ",
476495
(unsigned long)(table[n] >> 32),
@@ -482,26 +501,21 @@
482501
hexadecimal separated by commas. This assumes that if there is a 64-bit
483502
type, then there is also a long long integer type, and it is at least 64
484503
bits. If not, then the type cast and format string can be adjusted
485504
accordingly.
486505
*/
487
-local void write_table64(out, table, k)
488
- FILE *out;
489
- const z_word_t FAR *table;
490
- int k;
491
-{
506
+local void write_table64(FILE *out, const z_word_t FAR *table, int k) {
492507
int n;
493508
494509
for (n = 0; n < k; n++)
495510
fprintf(out, "%s0x%016llx%s", n == 0 || n % 3 ? "" : " ",
496511
(unsigned long long)(table[n]),
497512
n == k - 1 ? "" : (n % 3 == 2 ? ",\n" : ", "));
498513
}
499514
500515
/* Actually do the deed. */
501
-int main()
502
-{
516
+int main(void) {
503517
make_crc_table();
504518
return 0;
505519
}
506520
507521
#endif /* MAKECRCH */
@@ -509,16 +523,11 @@
509523
#ifdef W
510524
/*
511525
Generate the little and big-endian braid tables for the given n and z_word_t
512526
size w. Each array must have room for w blocks of 256 elements.
513527
*/
514
-local void braid(ltl, big, n, w)
515
- z_crc_t ltl[][256];
516
- z_word_t big[][256];
517
- int n;
518
- int w;
519
-{
528
+local void braid(z_crc_t ltl[][256], z_word_t big[][256], int n, int w) {
520529
int k;
521530
z_crc_t i, p, q;
522531
for (k = 0; k < w; k++) {
523532
p = x2nmodp((n * w + 3 - k) << 3, 0);
524533
ltl[k][0] = 0;
@@ -529,73 +538,17 @@
529538
}
530539
}
531540
}
532541
#endif
533542
534
-#else /* !DYNAMIC_CRC_TABLE */
535
-/* ========================================================================
536
- * Tables for byte-wise and braided CRC-32 calculations, and a table of powers
537
- * of x for combining CRC-32s, all made by make_crc_table().
538
- */
539
-#include "crc32.h"
540543
#endif /* DYNAMIC_CRC_TABLE */
541544
542
-/* ========================================================================
543
- * Routines used for CRC calculation. Some are also required for the table
544
- * generation above.
545
- */
546
-
547
-/*
548
- Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial,
549
- reflected. For speed, this requires that a not be zero.
550
- */
551
-local z_crc_t multmodp(a, b)
552
- z_crc_t a;
553
- z_crc_t b;
554
-{
555
- z_crc_t m, p;
556
-
557
- m = (z_crc_t)1 << 31;
558
- p = 0;
559
- for (;;) {
560
- if (a & m) {
561
- p ^= b;
562
- if ((a & (m - 1)) == 0)
563
- break;
564
- }
565
- m >>= 1;
566
- b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
567
- }
568
- return p;
569
-}
570
-
571
-/*
572
- Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been
573
- initialized.
574
- */
575
-local z_crc_t x2nmodp(n, k)
576
- z_off64_t n;
577
- unsigned k;
578
-{
579
- z_crc_t p;
580
-
581
- p = (z_crc_t)1 << 31; /* x^0 == 1 */
582
- while (n) {
583
- if (n & 1)
584
- p = multmodp(x2n_table[k & 31], p);
585
- n >>= 1;
586
- k++;
587
- }
588
- return p;
589
-}
590
-
591545
/* =========================================================================
592546
* This function can be used by asm versions of crc32(), and to force the
593547
* generation of the CRC tables in a threaded application.
594548
*/
595
-const z_crc_t FAR * ZEXPORT get_crc_table()
596
-{
549
+const z_crc_t FAR * ZEXPORT get_crc_table(void) {
597550
#ifdef DYNAMIC_CRC_TABLE
598551
once(&made, make_crc_table);
599552
#endif /* DYNAMIC_CRC_TABLE */
600553
return (const z_crc_t FAR *)crc_table;
601554
}
@@ -617,15 +570,12 @@
617570
*/
618571
#define Z_BATCH 3990 /* number of words in a batch */
619572
#define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */
620573
#define Z_BATCH_MIN 800 /* fewest words in a final batch */
621574
622
-unsigned long ZEXPORT crc32_z(crc, buf, len)
623
- unsigned long crc;
624
- const unsigned char FAR *buf;
625
- z_size_t len;
626
-{
575
+unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf,
576
+ z_size_t len) {
627577
z_crc_t val;
628578
z_word_t crc1, crc2;
629579
const z_word_t *word;
630580
z_word_t val0, val1, val2;
631581
z_size_t last, last2, i;
@@ -721,22 +671,18 @@
721671
/*
722672
Return the CRC of the W bytes in the word_t data, taking the
723673
least-significant byte of the word as the first byte of data, without any pre
724674
or post conditioning. This is used to combine the CRCs of each braid.
725675
*/
726
-local z_crc_t crc_word(data)
727
- z_word_t data;
728
-{
676
+local z_crc_t crc_word(z_word_t data) {
729677
int k;
730678
for (k = 0; k < W; k++)
731679
data = (data >> 8) ^ crc_table[data & 0xff];
732680
return (z_crc_t)data;
733681
}
734682
735
-local z_word_t crc_word_big(data)
736
- z_word_t data;
737
-{
683
+local z_word_t crc_word_big(z_word_t data) {
738684
int k;
739685
for (k = 0; k < W; k++)
740686
data = (data << 8) ^
741687
crc_big_table[(data >> ((W - 1) << 3)) & 0xff];
742688
return data;
@@ -743,15 +689,12 @@
743689
}
744690
745691
#endif
746692
747693
/* ========================================================================= */
748
-unsigned long ZEXPORT crc32_z(crc, buf, len)
749
- unsigned long crc;
750
- const unsigned char FAR *buf;
751
- z_size_t len;
752
-{
694
+unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf,
695
+ z_size_t len) {
753696
/* Return initial CRC, if requested. */
754697
if (buf == Z_NULL) return 0;
755698
756699
#ifdef DYNAMIC_CRC_TABLE
757700
once(&made, make_crc_table);
@@ -779,12 +722,12 @@
779722
blks = len / (N * W);
780723
len -= blks * N * W;
781724
words = (z_word_t const *)buf;
782725
783726
/* Do endian check at execution time instead of compile time, since ARM
784
- processors can change the endianess at execution time. If the
785
- compiler knows what the endianess will be, it can optimize out the
727
+ processors can change the endianness at execution time. If the
728
+ compiler knows what the endianness will be, it can optimize out the
786729
check and the unused branch. */
787730
endian = 1;
788731
if (*(unsigned char *)&endian) {
789732
/* Little endian. */
790733
@@ -1067,59 +1010,40 @@
10671010
}
10681011
10691012
#endif
10701013
10711014
/* ========================================================================= */
1072
-unsigned long ZEXPORT crc32(crc, buf, len)
1073
- unsigned long crc;
1074
- const unsigned char FAR *buf;
1075
- uInt len;
1076
-{
1015
+unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf,
1016
+ uInt len) {
10771017
return crc32_z(crc, buf, len);
10781018
}
10791019
10801020
/* ========================================================================= */
1081
-uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
1082
- uLong crc1;
1083
- uLong crc2;
1084
- z_off64_t len2;
1085
-{
1021
+uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) {
10861022
#ifdef DYNAMIC_CRC_TABLE
10871023
once(&made, make_crc_table);
10881024
#endif /* DYNAMIC_CRC_TABLE */
10891025
return multmodp(x2nmodp(len2, 3), crc1) ^ (crc2 & 0xffffffff);
10901026
}
10911027
10921028
/* ========================================================================= */
1093
-uLong ZEXPORT crc32_combine(crc1, crc2, len2)
1094
- uLong crc1;
1095
- uLong crc2;
1096
- z_off_t len2;
1097
-{
1029
+uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) {
10981030
return crc32_combine64(crc1, crc2, (z_off64_t)len2);
10991031
}
11001032
11011033
/* ========================================================================= */
1102
-uLong ZEXPORT crc32_combine_gen64(len2)
1103
- z_off64_t len2;
1104
-{
1034
+uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) {
11051035
#ifdef DYNAMIC_CRC_TABLE
11061036
once(&made, make_crc_table);
11071037
#endif /* DYNAMIC_CRC_TABLE */
11081038
return x2nmodp(len2, 3);
11091039
}
11101040
11111041
/* ========================================================================= */
1112
-uLong ZEXPORT crc32_combine_gen(len2)
1113
- z_off_t len2;
1114
-{
1042
+uLong ZEXPORT crc32_combine_gen(z_off_t len2) {
11151043
return crc32_combine_gen64((z_off64_t)len2);
11161044
}
11171045
11181046
/* ========================================================================= */
1119
-uLong ZEXPORT crc32_combine_op(crc1, crc2, op)
1120
- uLong crc1;
1121
- uLong crc2;
1122
- uLong op;
1123
-{
1047
+uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op) {
11241048
return multmodp(op, crc1) ^ (crc2 & 0xffffffff);
11251049
}
11261050
--- compat/zlib/crc32.c
+++ compat/zlib/crc32.c
@@ -101,33 +101,18 @@
101 /* If available, use the ARM processor CRC32 instruction. */
102 #if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) && W == 8
103 # define ARMCRC32
104 #endif
105
106 /* Local functions. */
107 local z_crc_t multmodp OF((z_crc_t a, z_crc_t b));
108 local z_crc_t x2nmodp OF((z_off64_t n, unsigned k));
109
110 #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE))
111 local z_word_t byte_swap OF((z_word_t word));
112 #endif
113
114 #if defined(W) && !defined(ARMCRC32)
115 local z_crc_t crc_word OF((z_word_t data));
116 local z_word_t crc_word_big OF((z_word_t data));
117 #endif
118
119 #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE))
120 /*
121 Swap the bytes in a z_word_t to convert between little and big endian. Any
122 self-respecting compiler will optimize this to a single machine byte-swap
123 instruction, if one is available. This assumes that word_t is either 32 bits
124 or 64 bits.
125 */
126 local z_word_t byte_swap(word)
127 z_word_t word;
128 {
129 # if W == 8
130 return
131 (word & 0xff00000000000000) >> 56 |
132 (word & 0xff000000000000) >> 40 |
133 (word & 0xff0000000000) >> 24 |
@@ -143,29 +128,82 @@
143 (word & 0xff00) << 8 |
144 (word & 0xff) << 24;
145 # endif
146 }
147 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
149 /* CRC polynomial. */
150 #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
152 #ifdef DYNAMIC_CRC_TABLE
153
 
 
 
154 local z_crc_t FAR crc_table[256];
155 local z_crc_t FAR x2n_table[32];
156 local void make_crc_table OF((void));
157 #ifdef W
158 local z_word_t FAR crc_big_table[256];
159 local z_crc_t FAR crc_braid_table[W][256];
160 local z_word_t FAR crc_braid_big_table[W][256];
161 local void braid OF((z_crc_t [][256], z_word_t [][256], int, int));
162 #endif
163 #ifdef MAKECRCH
164 local void write_table OF((FILE *, const z_crc_t FAR *, int));
165 local void write_table32hi OF((FILE *, const z_word_t FAR *, int));
166 local void write_table64 OF((FILE *, const z_word_t FAR *, int));
167 #endif /* MAKECRCH */
168
169 /*
170 Define a once() function depending on the availability of atomics. If this is
171 compiled with DYNAMIC_CRC_TABLE defined, and if CRCs will be computed in
@@ -174,11 +212,10 @@
174 allowed to compute or combine CRCs.
175 */
176
177 /* Definition of once functionality. */
178 typedef struct once_s once_t;
179 local void once OF((once_t *, void (*)(void)));
180
181 /* Check for the availability of atomics. */
182 #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \
183 !defined(__STDC_NO_ATOMICS__)
184
@@ -194,14 +231,11 @@
194 /*
195 Run the provided init() function exactly once, even if multiple threads
196 invoke once() at the same time. The state must be a once_t initialized with
197 ONCE_INIT.
198 */
199 local void once(state, init)
200 once_t *state;
201 void (*init)(void);
202 {
203 if (!atomic_load(&state->done)) {
204 if (atomic_flag_test_and_set(&state->begun))
205 while (!atomic_load(&state->done))
206 ;
207 else {
@@ -220,26 +254,20 @@
220 };
221 #define ONCE_INIT {0, 0}
222
223 /* Test and set. Alas, not atomic, but tries to minimize the period of
224 vulnerability. */
225 local int test_and_set OF((int volatile *));
226 local int test_and_set(flag)
227 int volatile *flag;
228 {
229 int was;
230
231 was = *flag;
232 *flag = 1;
233 return was;
234 }
235
236 /* Run the provided init() function once. This is not thread-safe. */
237 local void once(state, init)
238 once_t *state;
239 void (*init)(void);
240 {
241 if (!state->done) {
242 if (test_and_set(&state->begun))
243 while (!state->done)
244 ;
245 else {
@@ -277,12 +305,11 @@
277 The table is simply the CRC of all possible eight bit values. This is all the
278 information needed to generate CRCs on data a byte at a time for all
279 combinations of CRC register values and incoming bytes.
280 */
281
282 local void make_crc_table()
283 {
284 unsigned i, j, n;
285 z_crc_t p;
286
287 /* initialize the CRC of bytes tables */
288 for (i = 0; i < 256; i++) {
@@ -445,15 +472,11 @@
445
446 /*
447 Write the 32-bit values in table[0..k-1] to out, five per line in
448 hexadecimal separated by commas.
449 */
450 local void write_table(out, table, k)
451 FILE *out;
452 const z_crc_t FAR *table;
453 int k;
454 {
455 int n;
456
457 for (n = 0; n < k; n++)
458 fprintf(out, "%s0x%08lx%s", n == 0 || n % 5 ? "" : " ",
459 (unsigned long)(table[n]),
@@ -462,15 +485,11 @@
462
463 /*
464 Write the high 32-bits of each value in table[0..k-1] to out, five per line
465 in hexadecimal separated by commas.
466 */
467 local void write_table32hi(out, table, k)
468 FILE *out;
469 const z_word_t FAR *table;
470 int k;
471 {
472 int n;
473
474 for (n = 0; n < k; n++)
475 fprintf(out, "%s0x%08lx%s", n == 0 || n % 5 ? "" : " ",
476 (unsigned long)(table[n] >> 32),
@@ -482,26 +501,21 @@
482 hexadecimal separated by commas. This assumes that if there is a 64-bit
483 type, then there is also a long long integer type, and it is at least 64
484 bits. If not, then the type cast and format string can be adjusted
485 accordingly.
486 */
487 local void write_table64(out, table, k)
488 FILE *out;
489 const z_word_t FAR *table;
490 int k;
491 {
492 int n;
493
494 for (n = 0; n < k; n++)
495 fprintf(out, "%s0x%016llx%s", n == 0 || n % 3 ? "" : " ",
496 (unsigned long long)(table[n]),
497 n == k - 1 ? "" : (n % 3 == 2 ? ",\n" : ", "));
498 }
499
500 /* Actually do the deed. */
501 int main()
502 {
503 make_crc_table();
504 return 0;
505 }
506
507 #endif /* MAKECRCH */
@@ -509,16 +523,11 @@
509 #ifdef W
510 /*
511 Generate the little and big-endian braid tables for the given n and z_word_t
512 size w. Each array must have room for w blocks of 256 elements.
513 */
514 local void braid(ltl, big, n, w)
515 z_crc_t ltl[][256];
516 z_word_t big[][256];
517 int n;
518 int w;
519 {
520 int k;
521 z_crc_t i, p, q;
522 for (k = 0; k < w; k++) {
523 p = x2nmodp((n * w + 3 - k) << 3, 0);
524 ltl[k][0] = 0;
@@ -529,73 +538,17 @@
529 }
530 }
531 }
532 #endif
533
534 #else /* !DYNAMIC_CRC_TABLE */
535 /* ========================================================================
536 * Tables for byte-wise and braided CRC-32 calculations, and a table of powers
537 * of x for combining CRC-32s, all made by make_crc_table().
538 */
539 #include "crc32.h"
540 #endif /* DYNAMIC_CRC_TABLE */
541
542 /* ========================================================================
543 * Routines used for CRC calculation. Some are also required for the table
544 * generation above.
545 */
546
547 /*
548 Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial,
549 reflected. For speed, this requires that a not be zero.
550 */
551 local z_crc_t multmodp(a, b)
552 z_crc_t a;
553 z_crc_t b;
554 {
555 z_crc_t m, p;
556
557 m = (z_crc_t)1 << 31;
558 p = 0;
559 for (;;) {
560 if (a & m) {
561 p ^= b;
562 if ((a & (m - 1)) == 0)
563 break;
564 }
565 m >>= 1;
566 b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
567 }
568 return p;
569 }
570
571 /*
572 Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been
573 initialized.
574 */
575 local z_crc_t x2nmodp(n, k)
576 z_off64_t n;
577 unsigned k;
578 {
579 z_crc_t p;
580
581 p = (z_crc_t)1 << 31; /* x^0 == 1 */
582 while (n) {
583 if (n & 1)
584 p = multmodp(x2n_table[k & 31], p);
585 n >>= 1;
586 k++;
587 }
588 return p;
589 }
590
591 /* =========================================================================
592 * This function can be used by asm versions of crc32(), and to force the
593 * generation of the CRC tables in a threaded application.
594 */
595 const z_crc_t FAR * ZEXPORT get_crc_table()
596 {
597 #ifdef DYNAMIC_CRC_TABLE
598 once(&made, make_crc_table);
599 #endif /* DYNAMIC_CRC_TABLE */
600 return (const z_crc_t FAR *)crc_table;
601 }
@@ -617,15 +570,12 @@
617 */
618 #define Z_BATCH 3990 /* number of words in a batch */
619 #define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */
620 #define Z_BATCH_MIN 800 /* fewest words in a final batch */
621
622 unsigned long ZEXPORT crc32_z(crc, buf, len)
623 unsigned long crc;
624 const unsigned char FAR *buf;
625 z_size_t len;
626 {
627 z_crc_t val;
628 z_word_t crc1, crc2;
629 const z_word_t *word;
630 z_word_t val0, val1, val2;
631 z_size_t last, last2, i;
@@ -721,22 +671,18 @@
721 /*
722 Return the CRC of the W bytes in the word_t data, taking the
723 least-significant byte of the word as the first byte of data, without any pre
724 or post conditioning. This is used to combine the CRCs of each braid.
725 */
726 local z_crc_t crc_word(data)
727 z_word_t data;
728 {
729 int k;
730 for (k = 0; k < W; k++)
731 data = (data >> 8) ^ crc_table[data & 0xff];
732 return (z_crc_t)data;
733 }
734
735 local z_word_t crc_word_big(data)
736 z_word_t data;
737 {
738 int k;
739 for (k = 0; k < W; k++)
740 data = (data << 8) ^
741 crc_big_table[(data >> ((W - 1) << 3)) & 0xff];
742 return data;
@@ -743,15 +689,12 @@
743 }
744
745 #endif
746
747 /* ========================================================================= */
748 unsigned long ZEXPORT crc32_z(crc, buf, len)
749 unsigned long crc;
750 const unsigned char FAR *buf;
751 z_size_t len;
752 {
753 /* Return initial CRC, if requested. */
754 if (buf == Z_NULL) return 0;
755
756 #ifdef DYNAMIC_CRC_TABLE
757 once(&made, make_crc_table);
@@ -779,12 +722,12 @@
779 blks = len / (N * W);
780 len -= blks * N * W;
781 words = (z_word_t const *)buf;
782
783 /* Do endian check at execution time instead of compile time, since ARM
784 processors can change the endianess at execution time. If the
785 compiler knows what the endianess will be, it can optimize out the
786 check and the unused branch. */
787 endian = 1;
788 if (*(unsigned char *)&endian) {
789 /* Little endian. */
790
@@ -1067,59 +1010,40 @@
1067 }
1068
1069 #endif
1070
1071 /* ========================================================================= */
1072 unsigned long ZEXPORT crc32(crc, buf, len)
1073 unsigned long crc;
1074 const unsigned char FAR *buf;
1075 uInt len;
1076 {
1077 return crc32_z(crc, buf, len);
1078 }
1079
1080 /* ========================================================================= */
1081 uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
1082 uLong crc1;
1083 uLong crc2;
1084 z_off64_t len2;
1085 {
1086 #ifdef DYNAMIC_CRC_TABLE
1087 once(&made, make_crc_table);
1088 #endif /* DYNAMIC_CRC_TABLE */
1089 return multmodp(x2nmodp(len2, 3), crc1) ^ (crc2 & 0xffffffff);
1090 }
1091
1092 /* ========================================================================= */
1093 uLong ZEXPORT crc32_combine(crc1, crc2, len2)
1094 uLong crc1;
1095 uLong crc2;
1096 z_off_t len2;
1097 {
1098 return crc32_combine64(crc1, crc2, (z_off64_t)len2);
1099 }
1100
1101 /* ========================================================================= */
1102 uLong ZEXPORT crc32_combine_gen64(len2)
1103 z_off64_t len2;
1104 {
1105 #ifdef DYNAMIC_CRC_TABLE
1106 once(&made, make_crc_table);
1107 #endif /* DYNAMIC_CRC_TABLE */
1108 return x2nmodp(len2, 3);
1109 }
1110
1111 /* ========================================================================= */
1112 uLong ZEXPORT crc32_combine_gen(len2)
1113 z_off_t len2;
1114 {
1115 return crc32_combine_gen64((z_off64_t)len2);
1116 }
1117
1118 /* ========================================================================= */
1119 uLong ZEXPORT crc32_combine_op(crc1, crc2, op)
1120 uLong crc1;
1121 uLong crc2;
1122 uLong op;
1123 {
1124 return multmodp(op, crc1) ^ (crc2 & 0xffffffff);
1125 }
1126
--- compat/zlib/crc32.c
+++ compat/zlib/crc32.c
@@ -101,33 +101,18 @@
101 /* If available, use the ARM processor CRC32 instruction. */
102 #if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) && W == 8
103 # define ARMCRC32
104 #endif
105
 
 
 
 
 
 
 
 
 
 
 
 
 
106 #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE))
107 /*
108 Swap the bytes in a z_word_t to convert between little and big endian. Any
109 self-respecting compiler will optimize this to a single machine byte-swap
110 instruction, if one is available. This assumes that word_t is either 32 bits
111 or 64 bits.
112 */
113 local z_word_t byte_swap(z_word_t word) {
 
 
114 # if W == 8
115 return
116 (word & 0xff00000000000000) >> 56 |
117 (word & 0xff000000000000) >> 40 |
118 (word & 0xff0000000000) >> 24 |
@@ -143,29 +128,82 @@
128 (word & 0xff00) << 8 |
129 (word & 0xff) << 24;
130 # endif
131 }
132 #endif
133
134 #ifdef DYNAMIC_CRC_TABLE
135 /* =========================================================================
136 * Table of powers of x for combining CRC-32s, filled in by make_crc_table()
137 * below.
138 */
139 local z_crc_t FAR x2n_table[32];
140 #else
141 /* =========================================================================
142 * Tables for byte-wise and braided CRC-32 calculations, and a table of powers
143 * of x for combining CRC-32s, all made by make_crc_table().
144 */
145 # include "crc32.h"
146 #endif
147
148 /* CRC polynomial. */
149 #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */
150
151 /*
152 Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial,
153 reflected. For speed, this requires that a not be zero.
154 */
155 local z_crc_t multmodp(z_crc_t a, z_crc_t b) {
156 z_crc_t m, p;
157
158 m = (z_crc_t)1 << 31;
159 p = 0;
160 for (;;) {
161 if (a & m) {
162 p ^= b;
163 if ((a & (m - 1)) == 0)
164 break;
165 }
166 m >>= 1;
167 b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
168 }
169 return p;
170 }
171
172 /*
173 Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been
174 initialized.
175 */
176 local z_crc_t x2nmodp(z_off64_t n, unsigned k) {
177 z_crc_t p;
178
179 p = (z_crc_t)1 << 31; /* x^0 == 1 */
180 while (n) {
181 if (n & 1)
182 p = multmodp(x2n_table[k & 31], p);
183 n >>= 1;
184 k++;
185 }
186 return p;
187 }
188
189 #ifdef DYNAMIC_CRC_TABLE
190 /* =========================================================================
191 * Build the tables for byte-wise and braided CRC-32 calculations, and a table
192 * of powers of x for combining CRC-32s.
193 */
194 local z_crc_t FAR crc_table[256];
 
 
195 #ifdef W
196 local z_word_t FAR crc_big_table[256];
197 local z_crc_t FAR crc_braid_table[W][256];
198 local z_word_t FAR crc_braid_big_table[W][256];
199 local void braid(z_crc_t [][256], z_word_t [][256], int, int);
200 #endif
201 #ifdef MAKECRCH
202 local void write_table(FILE *, const z_crc_t FAR *, int);
203 local void write_table32hi(FILE *, const z_word_t FAR *, int);
204 local void write_table64(FILE *, const z_word_t FAR *, int);
205 #endif /* MAKECRCH */
206
207 /*
208 Define a once() function depending on the availability of atomics. If this is
209 compiled with DYNAMIC_CRC_TABLE defined, and if CRCs will be computed in
@@ -174,11 +212,10 @@
212 allowed to compute or combine CRCs.
213 */
214
215 /* Definition of once functionality. */
216 typedef struct once_s once_t;
 
217
218 /* Check for the availability of atomics. */
219 #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \
220 !defined(__STDC_NO_ATOMICS__)
221
@@ -194,14 +231,11 @@
231 /*
232 Run the provided init() function exactly once, even if multiple threads
233 invoke once() at the same time. The state must be a once_t initialized with
234 ONCE_INIT.
235 */
236 local void once(once_t *state, void (*init)(void)) {
 
 
 
237 if (!atomic_load(&state->done)) {
238 if (atomic_flag_test_and_set(&state->begun))
239 while (!atomic_load(&state->done))
240 ;
241 else {
@@ -220,26 +254,20 @@
254 };
255 #define ONCE_INIT {0, 0}
256
257 /* Test and set. Alas, not atomic, but tries to minimize the period of
258 vulnerability. */
259 local int test_and_set(int volatile *flag) {
 
 
 
260 int was;
261
262 was = *flag;
263 *flag = 1;
264 return was;
265 }
266
267 /* Run the provided init() function once. This is not thread-safe. */
268 local void once(once_t *state, void (*init)(void)) {
 
 
 
269 if (!state->done) {
270 if (test_and_set(&state->begun))
271 while (!state->done)
272 ;
273 else {
@@ -277,12 +305,11 @@
305 The table is simply the CRC of all possible eight bit values. This is all the
306 information needed to generate CRCs on data a byte at a time for all
307 combinations of CRC register values and incoming bytes.
308 */
309
310 local void make_crc_table(void) {
 
311 unsigned i, j, n;
312 z_crc_t p;
313
314 /* initialize the CRC of bytes tables */
315 for (i = 0; i < 256; i++) {
@@ -445,15 +472,11 @@
472
473 /*
474 Write the 32-bit values in table[0..k-1] to out, five per line in
475 hexadecimal separated by commas.
476 */
477 local void write_table(FILE *out, const z_crc_t FAR *table, int k) {
 
 
 
 
478 int n;
479
480 for (n = 0; n < k; n++)
481 fprintf(out, "%s0x%08lx%s", n == 0 || n % 5 ? "" : " ",
482 (unsigned long)(table[n]),
@@ -462,15 +485,11 @@
485
486 /*
487 Write the high 32-bits of each value in table[0..k-1] to out, five per line
488 in hexadecimal separated by commas.
489 */
490 local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) {
 
 
 
 
491 int n;
492
493 for (n = 0; n < k; n++)
494 fprintf(out, "%s0x%08lx%s", n == 0 || n % 5 ? "" : " ",
495 (unsigned long)(table[n] >> 32),
@@ -482,26 +501,21 @@
501 hexadecimal separated by commas. This assumes that if there is a 64-bit
502 type, then there is also a long long integer type, and it is at least 64
503 bits. If not, then the type cast and format string can be adjusted
504 accordingly.
505 */
506 local void write_table64(FILE *out, const z_word_t FAR *table, int k) {
 
 
 
 
507 int n;
508
509 for (n = 0; n < k; n++)
510 fprintf(out, "%s0x%016llx%s", n == 0 || n % 3 ? "" : " ",
511 (unsigned long long)(table[n]),
512 n == k - 1 ? "" : (n % 3 == 2 ? ",\n" : ", "));
513 }
514
515 /* Actually do the deed. */
516 int main(void) {
 
517 make_crc_table();
518 return 0;
519 }
520
521 #endif /* MAKECRCH */
@@ -509,16 +523,11 @@
523 #ifdef W
524 /*
525 Generate the little and big-endian braid tables for the given n and z_word_t
526 size w. Each array must have room for w blocks of 256 elements.
527 */
528 local void braid(z_crc_t ltl[][256], z_word_t big[][256], int n, int w) {
 
 
 
 
 
529 int k;
530 z_crc_t i, p, q;
531 for (k = 0; k < w; k++) {
532 p = x2nmodp((n * w + 3 - k) << 3, 0);
533 ltl[k][0] = 0;
@@ -529,73 +538,17 @@
538 }
539 }
540 }
541 #endif
542
 
 
 
 
 
 
543 #endif /* DYNAMIC_CRC_TABLE */
544
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
545 /* =========================================================================
546 * This function can be used by asm versions of crc32(), and to force the
547 * generation of the CRC tables in a threaded application.
548 */
549 const z_crc_t FAR * ZEXPORT get_crc_table(void) {
 
550 #ifdef DYNAMIC_CRC_TABLE
551 once(&made, make_crc_table);
552 #endif /* DYNAMIC_CRC_TABLE */
553 return (const z_crc_t FAR *)crc_table;
554 }
@@ -617,15 +570,12 @@
570 */
571 #define Z_BATCH 3990 /* number of words in a batch */
572 #define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */
573 #define Z_BATCH_MIN 800 /* fewest words in a final batch */
574
575 unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf,
576 z_size_t len) {
 
 
 
577 z_crc_t val;
578 z_word_t crc1, crc2;
579 const z_word_t *word;
580 z_word_t val0, val1, val2;
581 z_size_t last, last2, i;
@@ -721,22 +671,18 @@
671 /*
672 Return the CRC of the W bytes in the word_t data, taking the
673 least-significant byte of the word as the first byte of data, without any pre
674 or post conditioning. This is used to combine the CRCs of each braid.
675 */
676 local z_crc_t crc_word(z_word_t data) {
 
 
677 int k;
678 for (k = 0; k < W; k++)
679 data = (data >> 8) ^ crc_table[data & 0xff];
680 return (z_crc_t)data;
681 }
682
683 local z_word_t crc_word_big(z_word_t data) {
 
 
684 int k;
685 for (k = 0; k < W; k++)
686 data = (data << 8) ^
687 crc_big_table[(data >> ((W - 1) << 3)) & 0xff];
688 return data;
@@ -743,15 +689,12 @@
689 }
690
691 #endif
692
693 /* ========================================================================= */
694 unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf,
695 z_size_t len) {
 
 
 
696 /* Return initial CRC, if requested. */
697 if (buf == Z_NULL) return 0;
698
699 #ifdef DYNAMIC_CRC_TABLE
700 once(&made, make_crc_table);
@@ -779,12 +722,12 @@
722 blks = len / (N * W);
723 len -= blks * N * W;
724 words = (z_word_t const *)buf;
725
726 /* Do endian check at execution time instead of compile time, since ARM
727 processors can change the endianness at execution time. If the
728 compiler knows what the endianness will be, it can optimize out the
729 check and the unused branch. */
730 endian = 1;
731 if (*(unsigned char *)&endian) {
732 /* Little endian. */
733
@@ -1067,59 +1010,40 @@
1010 }
1011
1012 #endif
1013
1014 /* ========================================================================= */
1015 unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf,
1016 uInt len) {
 
 
 
1017 return crc32_z(crc, buf, len);
1018 }
1019
1020 /* ========================================================================= */
1021 uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) {
 
 
 
 
1022 #ifdef DYNAMIC_CRC_TABLE
1023 once(&made, make_crc_table);
1024 #endif /* DYNAMIC_CRC_TABLE */
1025 return multmodp(x2nmodp(len2, 3), crc1) ^ (crc2 & 0xffffffff);
1026 }
1027
1028 /* ========================================================================= */
1029 uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) {
 
 
 
 
1030 return crc32_combine64(crc1, crc2, (z_off64_t)len2);
1031 }
1032
1033 /* ========================================================================= */
1034 uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) {
 
 
1035 #ifdef DYNAMIC_CRC_TABLE
1036 once(&made, make_crc_table);
1037 #endif /* DYNAMIC_CRC_TABLE */
1038 return x2nmodp(len2, 3);
1039 }
1040
1041 /* ========================================================================= */
1042 uLong ZEXPORT crc32_combine_gen(z_off_t len2) {
 
 
1043 return crc32_combine_gen64((z_off64_t)len2);
1044 }
1045
1046 /* ========================================================================= */
1047 uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op) {
 
 
 
 
1048 return multmodp(op, crc1) ^ (crc2 & 0xffffffff);
1049 }
1050
+234 -337
--- compat/zlib/deflate.c
+++ compat/zlib/deflate.c
@@ -1,7 +1,7 @@
11
/* deflate.c -- compress data using the deflation algorithm
2
- * Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
2
+ * Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55
66
/*
77
* ALGORITHM
@@ -50,51 +50,35 @@
5050
/* @(#) $Id$ */
5151
5252
#include "deflate.h"
5353
5454
const char deflate_copyright[] =
55
- " deflate 1.2.13 Copyright 1995-2022 Jean-loup Gailly and Mark Adler ";
55
+ " deflate 1.3 Copyright 1995-2023 Jean-loup Gailly and Mark Adler ";
5656
/*
5757
If you use the zlib library in a product, an acknowledgment is welcome
5858
in the documentation of your product. If for some reason you cannot
5959
include such an acknowledgment, I would appreciate that you keep this
6060
copyright string in the executable of your product.
6161
*/
6262
63
-/* ===========================================================================
64
- * Function prototypes.
65
- */
6663
typedef enum {
6764
need_more, /* block not completed, need more input or more output */
6865
block_done, /* block flush performed */
6966
finish_started, /* finish started, need only more output at next deflate */
7067
finish_done /* finish done, accept no more input or output */
7168
} block_state;
7269
73
-typedef block_state (*compress_func) OF((deflate_state *s, int flush));
70
+typedef block_state (*compress_func)(deflate_state *s, int flush);
7471
/* Compression function. Returns the block state after the call. */
7572
76
-local int deflateStateCheck OF((z_streamp strm));
77
-local void slide_hash OF((deflate_state *s));
78
-local void fill_window OF((deflate_state *s));
79
-local block_state deflate_stored OF((deflate_state *s, int flush));
80
-local block_state deflate_fast OF((deflate_state *s, int flush));
73
+local block_state deflate_stored(deflate_state *s, int flush);
74
+local block_state deflate_fast(deflate_state *s, int flush);
8175
#ifndef FASTEST
82
-local block_state deflate_slow OF((deflate_state *s, int flush));
83
-#endif
84
-local block_state deflate_rle OF((deflate_state *s, int flush));
85
-local block_state deflate_huff OF((deflate_state *s, int flush));
86
-local void lm_init OF((deflate_state *s));
87
-local void putShortMSB OF((deflate_state *s, uInt b));
88
-local void flush_pending OF((z_streamp strm));
89
-local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
90
-local uInt longest_match OF((deflate_state *s, IPos cur_match));
91
-
92
-#ifdef ZLIB_DEBUG
93
-local void check_match OF((deflate_state *s, IPos start, IPos match,
94
- int length));
95
-#endif
76
+local block_state deflate_slow(deflate_state *s, int flush);
77
+#endif
78
+local block_state deflate_rle(deflate_state *s, int flush);
79
+local block_state deflate_huff(deflate_state *s, int flush);
9680
9781
/* ===========================================================================
9882
* Local data
9983
*/
10084
@@ -193,13 +177,16 @@
193177
/* ===========================================================================
194178
* Slide the hash table when sliding the window down (could be avoided with 32
195179
* bit values at the expense of memory usage). We slide even when level == 0 to
196180
* keep the hash table consistent if we switch back to level > 0 later.
197181
*/
198
-local void slide_hash(s)
199
- deflate_state *s;
200
-{
182
+#if defined(__has_feature)
183
+# if __has_feature(memory_sanitizer)
184
+ __attribute__((no_sanitize("memory")))
185
+# endif
186
+#endif
187
+local void slide_hash(deflate_state *s) {
201188
unsigned n, m;
202189
Posf *p;
203190
uInt wsize = s->w_size;
204191
205192
n = s->hash_size;
@@ -218,35 +205,182 @@
218205
* its value will never be used.
219206
*/
220207
} while (--n);
221208
#endif
222209
}
210
+
211
+/* ===========================================================================
212
+ * Read a new buffer from the current input stream, update the adler32
213
+ * and total number of bytes read. All deflate() input goes through
214
+ * this function so some applications may wish to modify it to avoid
215
+ * allocating a large strm->next_in buffer and copying from it.
216
+ * (See also flush_pending()).
217
+ */
218
+local unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size) {
219
+ unsigned len = strm->avail_in;
220
+
221
+ if (len > size) len = size;
222
+ if (len == 0) return 0;
223
+
224
+ strm->avail_in -= len;
225
+
226
+ zmemcpy(buf, strm->next_in, len);
227
+ if (strm->state->wrap == 1) {
228
+ strm->adler = adler32(strm->adler, buf, len);
229
+ }
230
+#ifdef GZIP
231
+ else if (strm->state->wrap == 2) {
232
+ strm->adler = crc32(strm->adler, buf, len);
233
+ }
234
+#endif
235
+ strm->next_in += len;
236
+ strm->total_in += len;
237
+
238
+ return len;
239
+}
240
+
241
+/* ===========================================================================
242
+ * Fill the window when the lookahead becomes insufficient.
243
+ * Updates strstart and lookahead.
244
+ *
245
+ * IN assertion: lookahead < MIN_LOOKAHEAD
246
+ * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
247
+ * At least one byte has been read, or avail_in == 0; reads are
248
+ * performed for at least two bytes (required for the zip translate_eol
249
+ * option -- not supported here).
250
+ */
251
+local void fill_window(deflate_state *s) {
252
+ unsigned n;
253
+ unsigned more; /* Amount of free space at the end of the window. */
254
+ uInt wsize = s->w_size;
255
+
256
+ Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
257
+
258
+ do {
259
+ more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
260
+
261
+ /* Deal with !@#$% 64K limit: */
262
+ if (sizeof(int) <= 2) {
263
+ if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
264
+ more = wsize;
265
+
266
+ } else if (more == (unsigned)(-1)) {
267
+ /* Very unlikely, but possible on 16 bit machine if
268
+ * strstart == 0 && lookahead == 1 (input done a byte at time)
269
+ */
270
+ more--;
271
+ }
272
+ }
273
+
274
+ /* If the window is almost full and there is insufficient lookahead,
275
+ * move the upper half to the lower one to make room in the upper half.
276
+ */
277
+ if (s->strstart >= wsize + MAX_DIST(s)) {
278
+
279
+ zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more);
280
+ s->match_start -= wsize;
281
+ s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
282
+ s->block_start -= (long) wsize;
283
+ if (s->insert > s->strstart)
284
+ s->insert = s->strstart;
285
+ slide_hash(s);
286
+ more += wsize;
287
+ }
288
+ if (s->strm->avail_in == 0) break;
289
+
290
+ /* If there was no sliding:
291
+ * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
292
+ * more == window_size - lookahead - strstart
293
+ * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
294
+ * => more >= window_size - 2*WSIZE + 2
295
+ * In the BIG_MEM or MMAP case (not yet supported),
296
+ * window_size == input_size + MIN_LOOKAHEAD &&
297
+ * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
298
+ * Otherwise, window_size == 2*WSIZE so more >= 2.
299
+ * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
300
+ */
301
+ Assert(more >= 2, "more < 2");
302
+
303
+ n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
304
+ s->lookahead += n;
305
+
306
+ /* Initialize the hash value now that we have some input: */
307
+ if (s->lookahead + s->insert >= MIN_MATCH) {
308
+ uInt str = s->strstart - s->insert;
309
+ s->ins_h = s->window[str];
310
+ UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
311
+#if MIN_MATCH != 3
312
+ Call UPDATE_HASH() MIN_MATCH-3 more times
313
+#endif
314
+ while (s->insert) {
315
+ UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
316
+#ifndef FASTEST
317
+ s->prev[str & s->w_mask] = s->head[s->ins_h];
318
+#endif
319
+ s->head[s->ins_h] = (Pos)str;
320
+ str++;
321
+ s->insert--;
322
+ if (s->lookahead + s->insert < MIN_MATCH)
323
+ break;
324
+ }
325
+ }
326
+ /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
327
+ * but this is not important since only literal bytes will be emitted.
328
+ */
329
+
330
+ } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
331
+
332
+ /* If the WIN_INIT bytes after the end of the current data have never been
333
+ * written, then zero those bytes in order to avoid memory check reports of
334
+ * the use of uninitialized (or uninitialised as Julian writes) bytes by
335
+ * the longest match routines. Update the high water mark for the next
336
+ * time through here. WIN_INIT is set to MAX_MATCH since the longest match
337
+ * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
338
+ */
339
+ if (s->high_water < s->window_size) {
340
+ ulg curr = s->strstart + (ulg)(s->lookahead);
341
+ ulg init;
342
+
343
+ if (s->high_water < curr) {
344
+ /* Previous high water mark below current data -- zero WIN_INIT
345
+ * bytes or up to end of window, whichever is less.
346
+ */
347
+ init = s->window_size - curr;
348
+ if (init > WIN_INIT)
349
+ init = WIN_INIT;
350
+ zmemzero(s->window + curr, (unsigned)init);
351
+ s->high_water = curr + init;
352
+ }
353
+ else if (s->high_water < (ulg)curr + WIN_INIT) {
354
+ /* High water mark at or above current data, but below current data
355
+ * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
356
+ * to end of window, whichever is less.
357
+ */
358
+ init = (ulg)curr + WIN_INIT - s->high_water;
359
+ if (init > s->window_size - s->high_water)
360
+ init = s->window_size - s->high_water;
361
+ zmemzero(s->window + s->high_water, (unsigned)init);
362
+ s->high_water += init;
363
+ }
364
+ }
365
+
366
+ Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
367
+ "not enough room for search");
368
+}
223369
224370
/* ========================================================================= */
225
-int ZEXPORT deflateInit_(strm, level, version, stream_size)
226
- z_streamp strm;
227
- int level;
228
- const char *version;
229
- int stream_size;
230
-{
371
+int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version,
372
+ int stream_size) {
231373
return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
232374
Z_DEFAULT_STRATEGY, version, stream_size);
233375
/* To do: ignore strm->next_in if we use it as window */
234376
}
235377
236378
/* ========================================================================= */
237
-int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
238
- version, stream_size)
239
- z_streamp strm;
240
- int level;
241
- int method;
242
- int windowBits;
243
- int memLevel;
244
- int strategy;
245
- const char *version;
246
- int stream_size;
247
-{
379
+int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
380
+ int windowBits, int memLevel, int strategy,
381
+ const char *version, int stream_size) {
248382
deflate_state *s;
249383
int wrap = 1;
250384
static const char my_version[] = ZLIB_VERSION;
251385
252386
if (version == Z_NULL || version[0] != my_version[0] ||
@@ -384,13 +518,11 @@
384518
}
385519
386520
/* =========================================================================
387521
* Check for a valid deflate stream state. Return 0 if ok, 1 if not.
388522
*/
389
-local int deflateStateCheck(strm)
390
- z_streamp strm;
391
-{
523
+local int deflateStateCheck(z_streamp strm) {
392524
deflate_state *s;
393525
if (strm == Z_NULL ||
394526
strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
395527
return 1;
396528
s = strm->state;
@@ -407,15 +539,12 @@
407539
return 1;
408540
return 0;
409541
}
410542
411543
/* ========================================================================= */
412
-int ZEXPORT deflateSetDictionary(strm, dictionary, dictLength)
413
- z_streamp strm;
414
- const Bytef *dictionary;
415
- uInt dictLength;
416
-{
544
+int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
545
+ uInt dictLength) {
417546
deflate_state *s;
418547
uInt str, n;
419548
int wrap;
420549
unsigned avail;
421550
z_const unsigned char *next;
@@ -476,15 +605,12 @@
476605
s->wrap = wrap;
477606
return Z_OK;
478607
}
479608
480609
/* ========================================================================= */
481
-int ZEXPORT deflateGetDictionary(strm, dictionary, dictLength)
482
- z_streamp strm;
483
- Bytef *dictionary;
484
- uInt *dictLength;
485
-{
610
+int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary,
611
+ uInt *dictLength) {
486612
deflate_state *s;
487613
uInt len;
488614
489615
if (deflateStateCheck(strm))
490616
return Z_STREAM_ERROR;
@@ -498,13 +624,11 @@
498624
*dictLength = len;
499625
return Z_OK;
500626
}
501627
502628
/* ========================================================================= */
503
-int ZEXPORT deflateResetKeep(strm)
504
- z_streamp strm;
505
-{
629
+int ZEXPORT deflateResetKeep(z_streamp strm) {
506630
deflate_state *s;
507631
508632
if (deflateStateCheck(strm)) {
509633
return Z_STREAM_ERROR;
510634
}
@@ -534,54 +658,65 @@
534658
535659
_tr_init(s);
536660
537661
return Z_OK;
538662
}
663
+
664
+/* ===========================================================================
665
+ * Initialize the "longest match" routines for a new zlib stream
666
+ */
667
+local void lm_init(deflate_state *s) {
668
+ s->window_size = (ulg)2L*s->w_size;
669
+
670
+ CLEAR_HASH(s);
671
+
672
+ /* Set the default configuration parameters:
673
+ */
674
+ s->max_lazy_match = configuration_table[s->level].max_lazy;
675
+ s->good_match = configuration_table[s->level].good_length;
676
+ s->nice_match = configuration_table[s->level].nice_length;
677
+ s->max_chain_length = configuration_table[s->level].max_chain;
678
+
679
+ s->strstart = 0;
680
+ s->block_start = 0L;
681
+ s->lookahead = 0;
682
+ s->insert = 0;
683
+ s->match_length = s->prev_length = MIN_MATCH-1;
684
+ s->match_available = 0;
685
+ s->ins_h = 0;
686
+}
539687
540688
/* ========================================================================= */
541
-int ZEXPORT deflateReset(strm)
542
- z_streamp strm;
543
-{
689
+int ZEXPORT deflateReset(z_streamp strm) {
544690
int ret;
545691
546692
ret = deflateResetKeep(strm);
547693
if (ret == Z_OK)
548694
lm_init(strm->state);
549695
return ret;
550696
}
551697
552698
/* ========================================================================= */
553
-int ZEXPORT deflateSetHeader(strm, head)
554
- z_streamp strm;
555
- gz_headerp head;
556
-{
699
+int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) {
557700
if (deflateStateCheck(strm) || strm->state->wrap != 2)
558701
return Z_STREAM_ERROR;
559702
strm->state->gzhead = head;
560703
return Z_OK;
561704
}
562705
563706
/* ========================================================================= */
564
-int ZEXPORT deflatePending(strm, pending, bits)
565
- unsigned *pending;
566
- int *bits;
567
- z_streamp strm;
568
-{
707
+int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) {
569708
if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
570709
if (pending != Z_NULL)
571710
*pending = strm->state->pending;
572711
if (bits != Z_NULL)
573712
*bits = strm->state->bi_valid;
574713
return Z_OK;
575714
}
576715
577716
/* ========================================================================= */
578
-int ZEXPORT deflatePrime(strm, bits, value)
579
- z_streamp strm;
580
- int bits;
581
- int value;
582
-{
717
+int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) {
583718
deflate_state *s;
584719
int put;
585720
586721
if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
587722
s = strm->state;
@@ -600,15 +735,11 @@
600735
} while (bits);
601736
return Z_OK;
602737
}
603738
604739
/* ========================================================================= */
605
-int ZEXPORT deflateParams(strm, level, strategy)
606
- z_streamp strm;
607
- int level;
608
- int strategy;
609
-{
740
+int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) {
610741
deflate_state *s;
611742
compress_func func;
612743
613744
if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
614745
s = strm->state;
@@ -649,17 +780,12 @@
649780
s->strategy = strategy;
650781
return Z_OK;
651782
}
652783
653784
/* ========================================================================= */
654
-int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
655
- z_streamp strm;
656
- int good_length;
657
- int max_lazy;
658
- int nice_length;
659
- int max_chain;
660
-{
785
+int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy,
786
+ int nice_length, int max_chain) {
661787
deflate_state *s;
662788
663789
if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
664790
s = strm->state;
665791
s->good_match = (uInt)good_length;
@@ -691,14 +817,11 @@
691817
* per 8-bit byte, plus 10 bits for every block. The smallest block size for
692818
* which this can occur is 255 (memLevel == 2).
693819
*
694820
* Shifts are used to approximate divisions, for speed.
695821
*/
696
-uLong ZEXPORT deflateBound(strm, sourceLen)
697
- z_streamp strm;
698
- uLong sourceLen;
699
-{
822
+uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) {
700823
deflate_state *s;
701824
uLong fixedlen, storelen, wraplen;
702825
703826
/* upper bound for fixed blocks with 9-bit literals and length 255
704827
(memLevel == 2, which is the lowest that may not use stored blocks) --
@@ -750,11 +873,12 @@
750873
wraplen = 6;
751874
}
752875
753876
/* if not default parameters, return one of the conservative bounds */
754877
if (s->w_bits != 15 || s->hash_bits != 8 + 7)
755
- return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen;
878
+ return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) +
879
+ wraplen;
756880
757881
/* default settings: return tight bound for that case -- ~0.03% overhead
758882
plus a small constant */
759883
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
760884
(sourceLen >> 25) + 13 - 6 + wraplen;
@@ -763,14 +887,11 @@
763887
/* =========================================================================
764888
* Put a short in the pending buffer. The 16-bit value is put in MSB order.
765889
* IN assertion: the stream state is correct and there is enough room in
766890
* pending_buf.
767891
*/
768
-local void putShortMSB(s, b)
769
- deflate_state *s;
770
- uInt b;
771
-{
892
+local void putShortMSB(deflate_state *s, uInt b) {
772893
put_byte(s, (Byte)(b >> 8));
773894
put_byte(s, (Byte)(b & 0xff));
774895
}
775896
776897
/* =========================================================================
@@ -777,13 +898,11 @@
777898
* Flush as much pending output as possible. All deflate() output, except for
778899
* some deflate_stored() output, goes through this function so some
779900
* applications may wish to modify it to avoid allocating a large
780901
* strm->next_out buffer and copying into it. (See also read_buf()).
781902
*/
782
-local void flush_pending(strm)
783
- z_streamp strm;
784
-{
903
+local void flush_pending(z_streamp strm) {
785904
unsigned len;
786905
deflate_state *s = strm->state;
787906
788907
_tr_flush_bits(s);
789908
len = s->pending;
@@ -810,14 +929,11 @@
810929
strm->adler = crc32(strm->adler, s->pending_buf + (beg), \
811930
s->pending - (beg)); \
812931
} while (0)
813932
814933
/* ========================================================================= */
815
-int ZEXPORT deflate(strm, flush)
816
- z_streamp strm;
817
- int flush;
818
-{
934
+int ZEXPORT deflate(z_streamp strm, int flush) {
819935
int old_flush; /* value of flush param for previous deflate call */
820936
deflate_state *s;
821937
822938
if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) {
823939
return Z_STREAM_ERROR;
@@ -1125,13 +1241,11 @@
11251241
if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
11261242
return s->pending != 0 ? Z_OK : Z_STREAM_END;
11271243
}
11281244
11291245
/* ========================================================================= */
1130
-int ZEXPORT deflateEnd(strm)
1131
- z_streamp strm;
1132
-{
1246
+int ZEXPORT deflateEnd(z_streamp strm) {
11331247
int status;
11341248
11351249
if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
11361250
11371251
status = strm->state->status;
@@ -1151,15 +1265,14 @@
11511265
/* =========================================================================
11521266
* Copy the source state to the destination state.
11531267
* To simplify the source, this is not supported for 16-bit MSDOS (which
11541268
* doesn't have enough memory anyway to duplicate compression states).
11551269
*/
1156
-int ZEXPORT deflateCopy(dest, source)
1157
- z_streamp dest;
1158
- z_streamp source;
1159
-{
1270
+int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
11601271
#ifdef MAXSEG_64K
1272
+ (void)dest;
1273
+ (void)source;
11611274
return Z_STREAM_ERROR;
11621275
#else
11631276
deflate_state *ds;
11641277
deflate_state *ss;
11651278
@@ -1203,70 +1316,10 @@
12031316
12041317
return Z_OK;
12051318
#endif /* MAXSEG_64K */
12061319
}
12071320
1208
-/* ===========================================================================
1209
- * Read a new buffer from the current input stream, update the adler32
1210
- * and total number of bytes read. All deflate() input goes through
1211
- * this function so some applications may wish to modify it to avoid
1212
- * allocating a large strm->next_in buffer and copying from it.
1213
- * (See also flush_pending()).
1214
- */
1215
-local unsigned read_buf(strm, buf, size)
1216
- z_streamp strm;
1217
- Bytef *buf;
1218
- unsigned size;
1219
-{
1220
- unsigned len = strm->avail_in;
1221
-
1222
- if (len > size) len = size;
1223
- if (len == 0) return 0;
1224
-
1225
- strm->avail_in -= len;
1226
-
1227
- zmemcpy(buf, strm->next_in, len);
1228
- if (strm->state->wrap == 1) {
1229
- strm->adler = adler32(strm->adler, buf, len);
1230
- }
1231
-#ifdef GZIP
1232
- else if (strm->state->wrap == 2) {
1233
- strm->adler = crc32(strm->adler, buf, len);
1234
- }
1235
-#endif
1236
- strm->next_in += len;
1237
- strm->total_in += len;
1238
-
1239
- return len;
1240
-}
1241
-
1242
-/* ===========================================================================
1243
- * Initialize the "longest match" routines for a new zlib stream
1244
- */
1245
-local void lm_init(s)
1246
- deflate_state *s;
1247
-{
1248
- s->window_size = (ulg)2L*s->w_size;
1249
-
1250
- CLEAR_HASH(s);
1251
-
1252
- /* Set the default configuration parameters:
1253
- */
1254
- s->max_lazy_match = configuration_table[s->level].max_lazy;
1255
- s->good_match = configuration_table[s->level].good_length;
1256
- s->nice_match = configuration_table[s->level].nice_length;
1257
- s->max_chain_length = configuration_table[s->level].max_chain;
1258
-
1259
- s->strstart = 0;
1260
- s->block_start = 0L;
1261
- s->lookahead = 0;
1262
- s->insert = 0;
1263
- s->match_length = s->prev_length = MIN_MATCH-1;
1264
- s->match_available = 0;
1265
- s->ins_h = 0;
1266
-}
1267
-
12681321
#ifndef FASTEST
12691322
/* ===========================================================================
12701323
* Set match_start to the longest match starting at the given string and
12711324
* return its length. Matches shorter or equal to prev_length are discarded,
12721325
* in which case the result is equal to prev_length and match_start is
@@ -1273,14 +1326,11 @@
12731326
* garbage.
12741327
* IN assertions: cur_match is the head of the hash chain for the current
12751328
* string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
12761329
* OUT assertion: the match length is not greater than s->lookahead.
12771330
*/
1278
-local uInt longest_match(s, cur_match)
1279
- deflate_state *s;
1280
- IPos cur_match; /* current match */
1281
-{
1331
+local uInt longest_match(deflate_state *s, IPos cur_match) {
12821332
unsigned chain_length = s->max_chain_length;/* max hash chain length */
12831333
register Bytef *scan = s->window + s->strstart; /* current string */
12841334
register Bytef *match; /* matched string */
12851335
register int len; /* length of current match */
12861336
int best_len = (int)s->prev_length; /* best match length so far */
@@ -1424,14 +1474,11 @@
14241474
#else /* FASTEST */
14251475
14261476
/* ---------------------------------------------------------------------------
14271477
* Optimized version for FASTEST only
14281478
*/
1429
-local uInt longest_match(s, cur_match)
1430
- deflate_state *s;
1431
- IPos cur_match; /* current match */
1432
-{
1479
+local uInt longest_match(deflate_state *s, IPos cur_match) {
14331480
register Bytef *scan = s->window + s->strstart; /* current string */
14341481
register Bytef *match; /* matched string */
14351482
register int len; /* length of current match */
14361483
register Bytef *strend = s->window + s->strstart + MAX_MATCH;
14371484
@@ -1488,15 +1535,11 @@
14881535
/* result of memcmp for equal strings */
14891536
14901537
/* ===========================================================================
14911538
* Check that the match at match_start is indeed a match.
14921539
*/
1493
-local void check_match(s, start, match, length)
1494
- deflate_state *s;
1495
- IPos start, match;
1496
- int length;
1497
-{
1540
+local void check_match(deflate_state *s, IPos start, IPos match, int length) {
14981541
/* check that the match is indeed a match */
14991542
if (zmemcmp(s->window + match,
15001543
s->window + start, length) != EQUAL) {
15011544
fprintf(stderr, " start %u, match %u, length %d\n",
15021545
start, match, length);
@@ -1512,141 +1555,10 @@
15121555
}
15131556
#else
15141557
# define check_match(s, start, match, length)
15151558
#endif /* ZLIB_DEBUG */
15161559
1517
-/* ===========================================================================
1518
- * Fill the window when the lookahead becomes insufficient.
1519
- * Updates strstart and lookahead.
1520
- *
1521
- * IN assertion: lookahead < MIN_LOOKAHEAD
1522
- * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
1523
- * At least one byte has been read, or avail_in == 0; reads are
1524
- * performed for at least two bytes (required for the zip translate_eol
1525
- * option -- not supported here).
1526
- */
1527
-local void fill_window(s)
1528
- deflate_state *s;
1529
-{
1530
- unsigned n;
1531
- unsigned more; /* Amount of free space at the end of the window. */
1532
- uInt wsize = s->w_size;
1533
-
1534
- Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
1535
-
1536
- do {
1537
- more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
1538
-
1539
- /* Deal with !@#$% 64K limit: */
1540
- if (sizeof(int) <= 2) {
1541
- if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
1542
- more = wsize;
1543
-
1544
- } else if (more == (unsigned)(-1)) {
1545
- /* Very unlikely, but possible on 16 bit machine if
1546
- * strstart == 0 && lookahead == 1 (input done a byte at time)
1547
- */
1548
- more--;
1549
- }
1550
- }
1551
-
1552
- /* If the window is almost full and there is insufficient lookahead,
1553
- * move the upper half to the lower one to make room in the upper half.
1554
- */
1555
- if (s->strstart >= wsize + MAX_DIST(s)) {
1556
-
1557
- zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more);
1558
- s->match_start -= wsize;
1559
- s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
1560
- s->block_start -= (long) wsize;
1561
- if (s->insert > s->strstart)
1562
- s->insert = s->strstart;
1563
- slide_hash(s);
1564
- more += wsize;
1565
- }
1566
- if (s->strm->avail_in == 0) break;
1567
-
1568
- /* If there was no sliding:
1569
- * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
1570
- * more == window_size - lookahead - strstart
1571
- * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
1572
- * => more >= window_size - 2*WSIZE + 2
1573
- * In the BIG_MEM or MMAP case (not yet supported),
1574
- * window_size == input_size + MIN_LOOKAHEAD &&
1575
- * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
1576
- * Otherwise, window_size == 2*WSIZE so more >= 2.
1577
- * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
1578
- */
1579
- Assert(more >= 2, "more < 2");
1580
-
1581
- n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
1582
- s->lookahead += n;
1583
-
1584
- /* Initialize the hash value now that we have some input: */
1585
- if (s->lookahead + s->insert >= MIN_MATCH) {
1586
- uInt str = s->strstart - s->insert;
1587
- s->ins_h = s->window[str];
1588
- UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
1589
-#if MIN_MATCH != 3
1590
- Call UPDATE_HASH() MIN_MATCH-3 more times
1591
-#endif
1592
- while (s->insert) {
1593
- UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
1594
-#ifndef FASTEST
1595
- s->prev[str & s->w_mask] = s->head[s->ins_h];
1596
-#endif
1597
- s->head[s->ins_h] = (Pos)str;
1598
- str++;
1599
- s->insert--;
1600
- if (s->lookahead + s->insert < MIN_MATCH)
1601
- break;
1602
- }
1603
- }
1604
- /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
1605
- * but this is not important since only literal bytes will be emitted.
1606
- */
1607
-
1608
- } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
1609
-
1610
- /* If the WIN_INIT bytes after the end of the current data have never been
1611
- * written, then zero those bytes in order to avoid memory check reports of
1612
- * the use of uninitialized (or uninitialised as Julian writes) bytes by
1613
- * the longest match routines. Update the high water mark for the next
1614
- * time through here. WIN_INIT is set to MAX_MATCH since the longest match
1615
- * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
1616
- */
1617
- if (s->high_water < s->window_size) {
1618
- ulg curr = s->strstart + (ulg)(s->lookahead);
1619
- ulg init;
1620
-
1621
- if (s->high_water < curr) {
1622
- /* Previous high water mark below current data -- zero WIN_INIT
1623
- * bytes or up to end of window, whichever is less.
1624
- */
1625
- init = s->window_size - curr;
1626
- if (init > WIN_INIT)
1627
- init = WIN_INIT;
1628
- zmemzero(s->window + curr, (unsigned)init);
1629
- s->high_water = curr + init;
1630
- }
1631
- else if (s->high_water < (ulg)curr + WIN_INIT) {
1632
- /* High water mark at or above current data, but below current data
1633
- * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
1634
- * to end of window, whichever is less.
1635
- */
1636
- init = (ulg)curr + WIN_INIT - s->high_water;
1637
- if (init > s->window_size - s->high_water)
1638
- init = s->window_size - s->high_water;
1639
- zmemzero(s->window + s->high_water, (unsigned)init);
1640
- s->high_water += init;
1641
- }
1642
- }
1643
-
1644
- Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
1645
- "not enough room for search");
1646
-}
1647
-
16481560
/* ===========================================================================
16491561
* Flush the current block, with given end-of-file flag.
16501562
* IN assertion: strstart is set to the end of the current match.
16511563
*/
16521564
#define FLUSH_BLOCK_ONLY(s, last) { \
@@ -1685,14 +1597,11 @@
16851597
*
16861598
* deflate_stored() is written to minimize the number of times an input byte is
16871599
* copied. It is most efficient with large input and output buffers, which
16881600
* maximizes the opportunities to have a single copy from next_in to next_out.
16891601
*/
1690
-local block_state deflate_stored(s, flush)
1691
- deflate_state *s;
1692
- int flush;
1693
-{
1602
+local block_state deflate_stored(deflate_state *s, int flush) {
16941603
/* Smallest worthy block size when not flushing or finishing. By default
16951604
* this is 32K. This can be as small as 507 bytes for memLevel == 1. For
16961605
* large input and output buffers, the stored block size will be larger.
16971606
*/
16981607
unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size);
@@ -1872,14 +1781,11 @@
18721781
* block state.
18731782
* This function does not perform lazy evaluation of matches and inserts
18741783
* new strings in the dictionary only for unmatched strings or for short
18751784
* matches. It is used only for the fast compression options.
18761785
*/
1877
-local block_state deflate_fast(s, flush)
1878
- deflate_state *s;
1879
- int flush;
1880
-{
1786
+local block_state deflate_fast(deflate_state *s, int flush) {
18811787
IPos hash_head; /* head of the hash chain */
18821788
int bflush; /* set if current block must be flushed */
18831789
18841790
for (;;) {
18851791
/* Make sure that we always have enough lookahead, except
@@ -1974,14 +1880,11 @@
19741880
/* ===========================================================================
19751881
* Same as above, but achieves better compression. We use a lazy
19761882
* evaluation for matches: a match is finally adopted only if there is
19771883
* no better match at the next window position.
19781884
*/
1979
-local block_state deflate_slow(s, flush)
1980
- deflate_state *s;
1981
- int flush;
1982
-{
1885
+local block_state deflate_slow(deflate_state *s, int flush) {
19831886
IPos hash_head; /* head of hash chain */
19841887
int bflush; /* set if current block must be flushed */
19851888
19861889
/* Process the input block. */
19871890
for (;;) {
@@ -2105,14 +2008,11 @@
21052008
/* ===========================================================================
21062009
* For Z_RLE, simply look for runs of bytes, generate matches only of distance
21072010
* one. Do not maintain a hash table. (It will be regenerated if this run of
21082011
* deflate switches away from Z_RLE.)
21092012
*/
2110
-local block_state deflate_rle(s, flush)
2111
- deflate_state *s;
2112
- int flush;
2113
-{
2013
+local block_state deflate_rle(deflate_state *s, int flush) {
21142014
int bflush; /* set if current block must be flushed */
21152015
uInt prev; /* byte at distance one to match */
21162016
Bytef *scan, *strend; /* scan goes up to strend for length of run */
21172017
21182018
for (;;) {
@@ -2179,14 +2079,11 @@
21792079
21802080
/* ===========================================================================
21812081
* For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
21822082
* (It will be regenerated if this run of deflate switches away from Huffman.)
21832083
*/
2184
-local block_state deflate_huff(s, flush)
2185
- deflate_state *s;
2186
- int flush;
2187
-{
2084
+local block_state deflate_huff(deflate_state *s, int flush) {
21882085
int bflush; /* set if current block must be flushed */
21892086
21902087
for (;;) {
21912088
/* Make sure that we have a literal to write. */
21922089
if (s->lookahead == 0) {
21932090
--- compat/zlib/deflate.c
+++ compat/zlib/deflate.c
@@ -1,7 +1,7 @@
1 /* deflate.c -- compress data using the deflation algorithm
2 * Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 /*
7 * ALGORITHM
@@ -50,51 +50,35 @@
50 /* @(#) $Id$ */
51
52 #include "deflate.h"
53
54 const char deflate_copyright[] =
55 " deflate 1.2.13 Copyright 1995-2022 Jean-loup Gailly and Mark Adler ";
56 /*
57 If you use the zlib library in a product, an acknowledgment is welcome
58 in the documentation of your product. If for some reason you cannot
59 include such an acknowledgment, I would appreciate that you keep this
60 copyright string in the executable of your product.
61 */
62
63 /* ===========================================================================
64 * Function prototypes.
65 */
66 typedef enum {
67 need_more, /* block not completed, need more input or more output */
68 block_done, /* block flush performed */
69 finish_started, /* finish started, need only more output at next deflate */
70 finish_done /* finish done, accept no more input or output */
71 } block_state;
72
73 typedef block_state (*compress_func) OF((deflate_state *s, int flush));
74 /* Compression function. Returns the block state after the call. */
75
76 local int deflateStateCheck OF((z_streamp strm));
77 local void slide_hash OF((deflate_state *s));
78 local void fill_window OF((deflate_state *s));
79 local block_state deflate_stored OF((deflate_state *s, int flush));
80 local block_state deflate_fast OF((deflate_state *s, int flush));
81 #ifndef FASTEST
82 local block_state deflate_slow OF((deflate_state *s, int flush));
83 #endif
84 local block_state deflate_rle OF((deflate_state *s, int flush));
85 local block_state deflate_huff OF((deflate_state *s, int flush));
86 local void lm_init OF((deflate_state *s));
87 local void putShortMSB OF((deflate_state *s, uInt b));
88 local void flush_pending OF((z_streamp strm));
89 local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
90 local uInt longest_match OF((deflate_state *s, IPos cur_match));
91
92 #ifdef ZLIB_DEBUG
93 local void check_match OF((deflate_state *s, IPos start, IPos match,
94 int length));
95 #endif
96
97 /* ===========================================================================
98 * Local data
99 */
100
@@ -193,13 +177,16 @@
193 /* ===========================================================================
194 * Slide the hash table when sliding the window down (could be avoided with 32
195 * bit values at the expense of memory usage). We slide even when level == 0 to
196 * keep the hash table consistent if we switch back to level > 0 later.
197 */
198 local void slide_hash(s)
199 deflate_state *s;
200 {
 
 
 
201 unsigned n, m;
202 Posf *p;
203 uInt wsize = s->w_size;
204
205 n = s->hash_size;
@@ -218,35 +205,182 @@
218 * its value will never be used.
219 */
220 } while (--n);
221 #endif
222 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
224 /* ========================================================================= */
225 int ZEXPORT deflateInit_(strm, level, version, stream_size)
226 z_streamp strm;
227 int level;
228 const char *version;
229 int stream_size;
230 {
231 return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
232 Z_DEFAULT_STRATEGY, version, stream_size);
233 /* To do: ignore strm->next_in if we use it as window */
234 }
235
236 /* ========================================================================= */
237 int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
238 version, stream_size)
239 z_streamp strm;
240 int level;
241 int method;
242 int windowBits;
243 int memLevel;
244 int strategy;
245 const char *version;
246 int stream_size;
247 {
248 deflate_state *s;
249 int wrap = 1;
250 static const char my_version[] = ZLIB_VERSION;
251
252 if (version == Z_NULL || version[0] != my_version[0] ||
@@ -384,13 +518,11 @@
384 }
385
386 /* =========================================================================
387 * Check for a valid deflate stream state. Return 0 if ok, 1 if not.
388 */
389 local int deflateStateCheck(strm)
390 z_streamp strm;
391 {
392 deflate_state *s;
393 if (strm == Z_NULL ||
394 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
395 return 1;
396 s = strm->state;
@@ -407,15 +539,12 @@
407 return 1;
408 return 0;
409 }
410
411 /* ========================================================================= */
412 int ZEXPORT deflateSetDictionary(strm, dictionary, dictLength)
413 z_streamp strm;
414 const Bytef *dictionary;
415 uInt dictLength;
416 {
417 deflate_state *s;
418 uInt str, n;
419 int wrap;
420 unsigned avail;
421 z_const unsigned char *next;
@@ -476,15 +605,12 @@
476 s->wrap = wrap;
477 return Z_OK;
478 }
479
480 /* ========================================================================= */
481 int ZEXPORT deflateGetDictionary(strm, dictionary, dictLength)
482 z_streamp strm;
483 Bytef *dictionary;
484 uInt *dictLength;
485 {
486 deflate_state *s;
487 uInt len;
488
489 if (deflateStateCheck(strm))
490 return Z_STREAM_ERROR;
@@ -498,13 +624,11 @@
498 *dictLength = len;
499 return Z_OK;
500 }
501
502 /* ========================================================================= */
503 int ZEXPORT deflateResetKeep(strm)
504 z_streamp strm;
505 {
506 deflate_state *s;
507
508 if (deflateStateCheck(strm)) {
509 return Z_STREAM_ERROR;
510 }
@@ -534,54 +658,65 @@
534
535 _tr_init(s);
536
537 return Z_OK;
538 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
539
540 /* ========================================================================= */
541 int ZEXPORT deflateReset(strm)
542 z_streamp strm;
543 {
544 int ret;
545
546 ret = deflateResetKeep(strm);
547 if (ret == Z_OK)
548 lm_init(strm->state);
549 return ret;
550 }
551
552 /* ========================================================================= */
553 int ZEXPORT deflateSetHeader(strm, head)
554 z_streamp strm;
555 gz_headerp head;
556 {
557 if (deflateStateCheck(strm) || strm->state->wrap != 2)
558 return Z_STREAM_ERROR;
559 strm->state->gzhead = head;
560 return Z_OK;
561 }
562
563 /* ========================================================================= */
564 int ZEXPORT deflatePending(strm, pending, bits)
565 unsigned *pending;
566 int *bits;
567 z_streamp strm;
568 {
569 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
570 if (pending != Z_NULL)
571 *pending = strm->state->pending;
572 if (bits != Z_NULL)
573 *bits = strm->state->bi_valid;
574 return Z_OK;
575 }
576
577 /* ========================================================================= */
578 int ZEXPORT deflatePrime(strm, bits, value)
579 z_streamp strm;
580 int bits;
581 int value;
582 {
583 deflate_state *s;
584 int put;
585
586 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
587 s = strm->state;
@@ -600,15 +735,11 @@
600 } while (bits);
601 return Z_OK;
602 }
603
604 /* ========================================================================= */
605 int ZEXPORT deflateParams(strm, level, strategy)
606 z_streamp strm;
607 int level;
608 int strategy;
609 {
610 deflate_state *s;
611 compress_func func;
612
613 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
614 s = strm->state;
@@ -649,17 +780,12 @@
649 s->strategy = strategy;
650 return Z_OK;
651 }
652
653 /* ========================================================================= */
654 int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
655 z_streamp strm;
656 int good_length;
657 int max_lazy;
658 int nice_length;
659 int max_chain;
660 {
661 deflate_state *s;
662
663 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
664 s = strm->state;
665 s->good_match = (uInt)good_length;
@@ -691,14 +817,11 @@
691 * per 8-bit byte, plus 10 bits for every block. The smallest block size for
692 * which this can occur is 255 (memLevel == 2).
693 *
694 * Shifts are used to approximate divisions, for speed.
695 */
696 uLong ZEXPORT deflateBound(strm, sourceLen)
697 z_streamp strm;
698 uLong sourceLen;
699 {
700 deflate_state *s;
701 uLong fixedlen, storelen, wraplen;
702
703 /* upper bound for fixed blocks with 9-bit literals and length 255
704 (memLevel == 2, which is the lowest that may not use stored blocks) --
@@ -750,11 +873,12 @@
750 wraplen = 6;
751 }
752
753 /* if not default parameters, return one of the conservative bounds */
754 if (s->w_bits != 15 || s->hash_bits != 8 + 7)
755 return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen;
 
756
757 /* default settings: return tight bound for that case -- ~0.03% overhead
758 plus a small constant */
759 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
760 (sourceLen >> 25) + 13 - 6 + wraplen;
@@ -763,14 +887,11 @@
763 /* =========================================================================
764 * Put a short in the pending buffer. The 16-bit value is put in MSB order.
765 * IN assertion: the stream state is correct and there is enough room in
766 * pending_buf.
767 */
768 local void putShortMSB(s, b)
769 deflate_state *s;
770 uInt b;
771 {
772 put_byte(s, (Byte)(b >> 8));
773 put_byte(s, (Byte)(b & 0xff));
774 }
775
776 /* =========================================================================
@@ -777,13 +898,11 @@
777 * Flush as much pending output as possible. All deflate() output, except for
778 * some deflate_stored() output, goes through this function so some
779 * applications may wish to modify it to avoid allocating a large
780 * strm->next_out buffer and copying into it. (See also read_buf()).
781 */
782 local void flush_pending(strm)
783 z_streamp strm;
784 {
785 unsigned len;
786 deflate_state *s = strm->state;
787
788 _tr_flush_bits(s);
789 len = s->pending;
@@ -810,14 +929,11 @@
810 strm->adler = crc32(strm->adler, s->pending_buf + (beg), \
811 s->pending - (beg)); \
812 } while (0)
813
814 /* ========================================================================= */
815 int ZEXPORT deflate(strm, flush)
816 z_streamp strm;
817 int flush;
818 {
819 int old_flush; /* value of flush param for previous deflate call */
820 deflate_state *s;
821
822 if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) {
823 return Z_STREAM_ERROR;
@@ -1125,13 +1241,11 @@
1125 if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
1126 return s->pending != 0 ? Z_OK : Z_STREAM_END;
1127 }
1128
1129 /* ========================================================================= */
1130 int ZEXPORT deflateEnd(strm)
1131 z_streamp strm;
1132 {
1133 int status;
1134
1135 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
1136
1137 status = strm->state->status;
@@ -1151,15 +1265,14 @@
1151 /* =========================================================================
1152 * Copy the source state to the destination state.
1153 * To simplify the source, this is not supported for 16-bit MSDOS (which
1154 * doesn't have enough memory anyway to duplicate compression states).
1155 */
1156 int ZEXPORT deflateCopy(dest, source)
1157 z_streamp dest;
1158 z_streamp source;
1159 {
1160 #ifdef MAXSEG_64K
 
 
1161 return Z_STREAM_ERROR;
1162 #else
1163 deflate_state *ds;
1164 deflate_state *ss;
1165
@@ -1203,70 +1316,10 @@
1203
1204 return Z_OK;
1205 #endif /* MAXSEG_64K */
1206 }
1207
1208 /* ===========================================================================
1209 * Read a new buffer from the current input stream, update the adler32
1210 * and total number of bytes read. All deflate() input goes through
1211 * this function so some applications may wish to modify it to avoid
1212 * allocating a large strm->next_in buffer and copying from it.
1213 * (See also flush_pending()).
1214 */
1215 local unsigned read_buf(strm, buf, size)
1216 z_streamp strm;
1217 Bytef *buf;
1218 unsigned size;
1219 {
1220 unsigned len = strm->avail_in;
1221
1222 if (len > size) len = size;
1223 if (len == 0) return 0;
1224
1225 strm->avail_in -= len;
1226
1227 zmemcpy(buf, strm->next_in, len);
1228 if (strm->state->wrap == 1) {
1229 strm->adler = adler32(strm->adler, buf, len);
1230 }
1231 #ifdef GZIP
1232 else if (strm->state->wrap == 2) {
1233 strm->adler = crc32(strm->adler, buf, len);
1234 }
1235 #endif
1236 strm->next_in += len;
1237 strm->total_in += len;
1238
1239 return len;
1240 }
1241
1242 /* ===========================================================================
1243 * Initialize the "longest match" routines for a new zlib stream
1244 */
1245 local void lm_init(s)
1246 deflate_state *s;
1247 {
1248 s->window_size = (ulg)2L*s->w_size;
1249
1250 CLEAR_HASH(s);
1251
1252 /* Set the default configuration parameters:
1253 */
1254 s->max_lazy_match = configuration_table[s->level].max_lazy;
1255 s->good_match = configuration_table[s->level].good_length;
1256 s->nice_match = configuration_table[s->level].nice_length;
1257 s->max_chain_length = configuration_table[s->level].max_chain;
1258
1259 s->strstart = 0;
1260 s->block_start = 0L;
1261 s->lookahead = 0;
1262 s->insert = 0;
1263 s->match_length = s->prev_length = MIN_MATCH-1;
1264 s->match_available = 0;
1265 s->ins_h = 0;
1266 }
1267
1268 #ifndef FASTEST
1269 /* ===========================================================================
1270 * Set match_start to the longest match starting at the given string and
1271 * return its length. Matches shorter or equal to prev_length are discarded,
1272 * in which case the result is equal to prev_length and match_start is
@@ -1273,14 +1326,11 @@
1273 * garbage.
1274 * IN assertions: cur_match is the head of the hash chain for the current
1275 * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
1276 * OUT assertion: the match length is not greater than s->lookahead.
1277 */
1278 local uInt longest_match(s, cur_match)
1279 deflate_state *s;
1280 IPos cur_match; /* current match */
1281 {
1282 unsigned chain_length = s->max_chain_length;/* max hash chain length */
1283 register Bytef *scan = s->window + s->strstart; /* current string */
1284 register Bytef *match; /* matched string */
1285 register int len; /* length of current match */
1286 int best_len = (int)s->prev_length; /* best match length so far */
@@ -1424,14 +1474,11 @@
1424 #else /* FASTEST */
1425
1426 /* ---------------------------------------------------------------------------
1427 * Optimized version for FASTEST only
1428 */
1429 local uInt longest_match(s, cur_match)
1430 deflate_state *s;
1431 IPos cur_match; /* current match */
1432 {
1433 register Bytef *scan = s->window + s->strstart; /* current string */
1434 register Bytef *match; /* matched string */
1435 register int len; /* length of current match */
1436 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
1437
@@ -1488,15 +1535,11 @@
1488 /* result of memcmp for equal strings */
1489
1490 /* ===========================================================================
1491 * Check that the match at match_start is indeed a match.
1492 */
1493 local void check_match(s, start, match, length)
1494 deflate_state *s;
1495 IPos start, match;
1496 int length;
1497 {
1498 /* check that the match is indeed a match */
1499 if (zmemcmp(s->window + match,
1500 s->window + start, length) != EQUAL) {
1501 fprintf(stderr, " start %u, match %u, length %d\n",
1502 start, match, length);
@@ -1512,141 +1555,10 @@
1512 }
1513 #else
1514 # define check_match(s, start, match, length)
1515 #endif /* ZLIB_DEBUG */
1516
1517 /* ===========================================================================
1518 * Fill the window when the lookahead becomes insufficient.
1519 * Updates strstart and lookahead.
1520 *
1521 * IN assertion: lookahead < MIN_LOOKAHEAD
1522 * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
1523 * At least one byte has been read, or avail_in == 0; reads are
1524 * performed for at least two bytes (required for the zip translate_eol
1525 * option -- not supported here).
1526 */
1527 local void fill_window(s)
1528 deflate_state *s;
1529 {
1530 unsigned n;
1531 unsigned more; /* Amount of free space at the end of the window. */
1532 uInt wsize = s->w_size;
1533
1534 Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
1535
1536 do {
1537 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
1538
1539 /* Deal with !@#$% 64K limit: */
1540 if (sizeof(int) <= 2) {
1541 if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
1542 more = wsize;
1543
1544 } else if (more == (unsigned)(-1)) {
1545 /* Very unlikely, but possible on 16 bit machine if
1546 * strstart == 0 && lookahead == 1 (input done a byte at time)
1547 */
1548 more--;
1549 }
1550 }
1551
1552 /* If the window is almost full and there is insufficient lookahead,
1553 * move the upper half to the lower one to make room in the upper half.
1554 */
1555 if (s->strstart >= wsize + MAX_DIST(s)) {
1556
1557 zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more);
1558 s->match_start -= wsize;
1559 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
1560 s->block_start -= (long) wsize;
1561 if (s->insert > s->strstart)
1562 s->insert = s->strstart;
1563 slide_hash(s);
1564 more += wsize;
1565 }
1566 if (s->strm->avail_in == 0) break;
1567
1568 /* If there was no sliding:
1569 * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
1570 * more == window_size - lookahead - strstart
1571 * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
1572 * => more >= window_size - 2*WSIZE + 2
1573 * In the BIG_MEM or MMAP case (not yet supported),
1574 * window_size == input_size + MIN_LOOKAHEAD &&
1575 * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
1576 * Otherwise, window_size == 2*WSIZE so more >= 2.
1577 * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
1578 */
1579 Assert(more >= 2, "more < 2");
1580
1581 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
1582 s->lookahead += n;
1583
1584 /* Initialize the hash value now that we have some input: */
1585 if (s->lookahead + s->insert >= MIN_MATCH) {
1586 uInt str = s->strstart - s->insert;
1587 s->ins_h = s->window[str];
1588 UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
1589 #if MIN_MATCH != 3
1590 Call UPDATE_HASH() MIN_MATCH-3 more times
1591 #endif
1592 while (s->insert) {
1593 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
1594 #ifndef FASTEST
1595 s->prev[str & s->w_mask] = s->head[s->ins_h];
1596 #endif
1597 s->head[s->ins_h] = (Pos)str;
1598 str++;
1599 s->insert--;
1600 if (s->lookahead + s->insert < MIN_MATCH)
1601 break;
1602 }
1603 }
1604 /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
1605 * but this is not important since only literal bytes will be emitted.
1606 */
1607
1608 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
1609
1610 /* If the WIN_INIT bytes after the end of the current data have never been
1611 * written, then zero those bytes in order to avoid memory check reports of
1612 * the use of uninitialized (or uninitialised as Julian writes) bytes by
1613 * the longest match routines. Update the high water mark for the next
1614 * time through here. WIN_INIT is set to MAX_MATCH since the longest match
1615 * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
1616 */
1617 if (s->high_water < s->window_size) {
1618 ulg curr = s->strstart + (ulg)(s->lookahead);
1619 ulg init;
1620
1621 if (s->high_water < curr) {
1622 /* Previous high water mark below current data -- zero WIN_INIT
1623 * bytes or up to end of window, whichever is less.
1624 */
1625 init = s->window_size - curr;
1626 if (init > WIN_INIT)
1627 init = WIN_INIT;
1628 zmemzero(s->window + curr, (unsigned)init);
1629 s->high_water = curr + init;
1630 }
1631 else if (s->high_water < (ulg)curr + WIN_INIT) {
1632 /* High water mark at or above current data, but below current data
1633 * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
1634 * to end of window, whichever is less.
1635 */
1636 init = (ulg)curr + WIN_INIT - s->high_water;
1637 if (init > s->window_size - s->high_water)
1638 init = s->window_size - s->high_water;
1639 zmemzero(s->window + s->high_water, (unsigned)init);
1640 s->high_water += init;
1641 }
1642 }
1643
1644 Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
1645 "not enough room for search");
1646 }
1647
1648 /* ===========================================================================
1649 * Flush the current block, with given end-of-file flag.
1650 * IN assertion: strstart is set to the end of the current match.
1651 */
1652 #define FLUSH_BLOCK_ONLY(s, last) { \
@@ -1685,14 +1597,11 @@
1685 *
1686 * deflate_stored() is written to minimize the number of times an input byte is
1687 * copied. It is most efficient with large input and output buffers, which
1688 * maximizes the opportunities to have a single copy from next_in to next_out.
1689 */
1690 local block_state deflate_stored(s, flush)
1691 deflate_state *s;
1692 int flush;
1693 {
1694 /* Smallest worthy block size when not flushing or finishing. By default
1695 * this is 32K. This can be as small as 507 bytes for memLevel == 1. For
1696 * large input and output buffers, the stored block size will be larger.
1697 */
1698 unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size);
@@ -1872,14 +1781,11 @@
1872 * block state.
1873 * This function does not perform lazy evaluation of matches and inserts
1874 * new strings in the dictionary only for unmatched strings or for short
1875 * matches. It is used only for the fast compression options.
1876 */
1877 local block_state deflate_fast(s, flush)
1878 deflate_state *s;
1879 int flush;
1880 {
1881 IPos hash_head; /* head of the hash chain */
1882 int bflush; /* set if current block must be flushed */
1883
1884 for (;;) {
1885 /* Make sure that we always have enough lookahead, except
@@ -1974,14 +1880,11 @@
1974 /* ===========================================================================
1975 * Same as above, but achieves better compression. We use a lazy
1976 * evaluation for matches: a match is finally adopted only if there is
1977 * no better match at the next window position.
1978 */
1979 local block_state deflate_slow(s, flush)
1980 deflate_state *s;
1981 int flush;
1982 {
1983 IPos hash_head; /* head of hash chain */
1984 int bflush; /* set if current block must be flushed */
1985
1986 /* Process the input block. */
1987 for (;;) {
@@ -2105,14 +2008,11 @@
2105 /* ===========================================================================
2106 * For Z_RLE, simply look for runs of bytes, generate matches only of distance
2107 * one. Do not maintain a hash table. (It will be regenerated if this run of
2108 * deflate switches away from Z_RLE.)
2109 */
2110 local block_state deflate_rle(s, flush)
2111 deflate_state *s;
2112 int flush;
2113 {
2114 int bflush; /* set if current block must be flushed */
2115 uInt prev; /* byte at distance one to match */
2116 Bytef *scan, *strend; /* scan goes up to strend for length of run */
2117
2118 for (;;) {
@@ -2179,14 +2079,11 @@
2179
2180 /* ===========================================================================
2181 * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
2182 * (It will be regenerated if this run of deflate switches away from Huffman.)
2183 */
2184 local block_state deflate_huff(s, flush)
2185 deflate_state *s;
2186 int flush;
2187 {
2188 int bflush; /* set if current block must be flushed */
2189
2190 for (;;) {
2191 /* Make sure that we have a literal to write. */
2192 if (s->lookahead == 0) {
2193
--- compat/zlib/deflate.c
+++ compat/zlib/deflate.c
@@ -1,7 +1,7 @@
1 /* deflate.c -- compress data using the deflation algorithm
2 * Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 /*
7 * ALGORITHM
@@ -50,51 +50,35 @@
50 /* @(#) $Id$ */
51
52 #include "deflate.h"
53
54 const char deflate_copyright[] =
55 " deflate 1.3 Copyright 1995-2023 Jean-loup Gailly and Mark Adler ";
56 /*
57 If you use the zlib library in a product, an acknowledgment is welcome
58 in the documentation of your product. If for some reason you cannot
59 include such an acknowledgment, I would appreciate that you keep this
60 copyright string in the executable of your product.
61 */
62
 
 
 
63 typedef enum {
64 need_more, /* block not completed, need more input or more output */
65 block_done, /* block flush performed */
66 finish_started, /* finish started, need only more output at next deflate */
67 finish_done /* finish done, accept no more input or output */
68 } block_state;
69
70 typedef block_state (*compress_func)(deflate_state *s, int flush);
71 /* Compression function. Returns the block state after the call. */
72
73 local block_state deflate_stored(deflate_state *s, int flush);
74 local block_state deflate_fast(deflate_state *s, int flush);
 
 
 
75 #ifndef FASTEST
76 local block_state deflate_slow(deflate_state *s, int flush);
77 #endif
78 local block_state deflate_rle(deflate_state *s, int flush);
79 local block_state deflate_huff(deflate_state *s, int flush);
 
 
 
 
 
 
 
 
 
 
80
81 /* ===========================================================================
82 * Local data
83 */
84
@@ -193,13 +177,16 @@
177 /* ===========================================================================
178 * Slide the hash table when sliding the window down (could be avoided with 32
179 * bit values at the expense of memory usage). We slide even when level == 0 to
180 * keep the hash table consistent if we switch back to level > 0 later.
181 */
182 #if defined(__has_feature)
183 # if __has_feature(memory_sanitizer)
184 __attribute__((no_sanitize("memory")))
185 # endif
186 #endif
187 local void slide_hash(deflate_state *s) {
188 unsigned n, m;
189 Posf *p;
190 uInt wsize = s->w_size;
191
192 n = s->hash_size;
@@ -218,35 +205,182 @@
205 * its value will never be used.
206 */
207 } while (--n);
208 #endif
209 }
210
211 /* ===========================================================================
212 * Read a new buffer from the current input stream, update the adler32
213 * and total number of bytes read. All deflate() input goes through
214 * this function so some applications may wish to modify it to avoid
215 * allocating a large strm->next_in buffer and copying from it.
216 * (See also flush_pending()).
217 */
218 local unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size) {
219 unsigned len = strm->avail_in;
220
221 if (len > size) len = size;
222 if (len == 0) return 0;
223
224 strm->avail_in -= len;
225
226 zmemcpy(buf, strm->next_in, len);
227 if (strm->state->wrap == 1) {
228 strm->adler = adler32(strm->adler, buf, len);
229 }
230 #ifdef GZIP
231 else if (strm->state->wrap == 2) {
232 strm->adler = crc32(strm->adler, buf, len);
233 }
234 #endif
235 strm->next_in += len;
236 strm->total_in += len;
237
238 return len;
239 }
240
241 /* ===========================================================================
242 * Fill the window when the lookahead becomes insufficient.
243 * Updates strstart and lookahead.
244 *
245 * IN assertion: lookahead < MIN_LOOKAHEAD
246 * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
247 * At least one byte has been read, or avail_in == 0; reads are
248 * performed for at least two bytes (required for the zip translate_eol
249 * option -- not supported here).
250 */
251 local void fill_window(deflate_state *s) {
252 unsigned n;
253 unsigned more; /* Amount of free space at the end of the window. */
254 uInt wsize = s->w_size;
255
256 Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
257
258 do {
259 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
260
261 /* Deal with !@#$% 64K limit: */
262 if (sizeof(int) <= 2) {
263 if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
264 more = wsize;
265
266 } else if (more == (unsigned)(-1)) {
267 /* Very unlikely, but possible on 16 bit machine if
268 * strstart == 0 && lookahead == 1 (input done a byte at time)
269 */
270 more--;
271 }
272 }
273
274 /* If the window is almost full and there is insufficient lookahead,
275 * move the upper half to the lower one to make room in the upper half.
276 */
277 if (s->strstart >= wsize + MAX_DIST(s)) {
278
279 zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more);
280 s->match_start -= wsize;
281 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
282 s->block_start -= (long) wsize;
283 if (s->insert > s->strstart)
284 s->insert = s->strstart;
285 slide_hash(s);
286 more += wsize;
287 }
288 if (s->strm->avail_in == 0) break;
289
290 /* If there was no sliding:
291 * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
292 * more == window_size - lookahead - strstart
293 * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
294 * => more >= window_size - 2*WSIZE + 2
295 * In the BIG_MEM or MMAP case (not yet supported),
296 * window_size == input_size + MIN_LOOKAHEAD &&
297 * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
298 * Otherwise, window_size == 2*WSIZE so more >= 2.
299 * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
300 */
301 Assert(more >= 2, "more < 2");
302
303 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
304 s->lookahead += n;
305
306 /* Initialize the hash value now that we have some input: */
307 if (s->lookahead + s->insert >= MIN_MATCH) {
308 uInt str = s->strstart - s->insert;
309 s->ins_h = s->window[str];
310 UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
311 #if MIN_MATCH != 3
312 Call UPDATE_HASH() MIN_MATCH-3 more times
313 #endif
314 while (s->insert) {
315 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
316 #ifndef FASTEST
317 s->prev[str & s->w_mask] = s->head[s->ins_h];
318 #endif
319 s->head[s->ins_h] = (Pos)str;
320 str++;
321 s->insert--;
322 if (s->lookahead + s->insert < MIN_MATCH)
323 break;
324 }
325 }
326 /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
327 * but this is not important since only literal bytes will be emitted.
328 */
329
330 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
331
332 /* If the WIN_INIT bytes after the end of the current data have never been
333 * written, then zero those bytes in order to avoid memory check reports of
334 * the use of uninitialized (or uninitialised as Julian writes) bytes by
335 * the longest match routines. Update the high water mark for the next
336 * time through here. WIN_INIT is set to MAX_MATCH since the longest match
337 * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
338 */
339 if (s->high_water < s->window_size) {
340 ulg curr = s->strstart + (ulg)(s->lookahead);
341 ulg init;
342
343 if (s->high_water < curr) {
344 /* Previous high water mark below current data -- zero WIN_INIT
345 * bytes or up to end of window, whichever is less.
346 */
347 init = s->window_size - curr;
348 if (init > WIN_INIT)
349 init = WIN_INIT;
350 zmemzero(s->window + curr, (unsigned)init);
351 s->high_water = curr + init;
352 }
353 else if (s->high_water < (ulg)curr + WIN_INIT) {
354 /* High water mark at or above current data, but below current data
355 * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
356 * to end of window, whichever is less.
357 */
358 init = (ulg)curr + WIN_INIT - s->high_water;
359 if (init > s->window_size - s->high_water)
360 init = s->window_size - s->high_water;
361 zmemzero(s->window + s->high_water, (unsigned)init);
362 s->high_water += init;
363 }
364 }
365
366 Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
367 "not enough room for search");
368 }
369
370 /* ========================================================================= */
371 int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version,
372 int stream_size) {
 
 
 
 
373 return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
374 Z_DEFAULT_STRATEGY, version, stream_size);
375 /* To do: ignore strm->next_in if we use it as window */
376 }
377
378 /* ========================================================================= */
379 int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
380 int windowBits, int memLevel, int strategy,
381 const char *version, int stream_size) {
 
 
 
 
 
 
 
 
382 deflate_state *s;
383 int wrap = 1;
384 static const char my_version[] = ZLIB_VERSION;
385
386 if (version == Z_NULL || version[0] != my_version[0] ||
@@ -384,13 +518,11 @@
518 }
519
520 /* =========================================================================
521 * Check for a valid deflate stream state. Return 0 if ok, 1 if not.
522 */
523 local int deflateStateCheck(z_streamp strm) {
 
 
524 deflate_state *s;
525 if (strm == Z_NULL ||
526 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
527 return 1;
528 s = strm->state;
@@ -407,15 +539,12 @@
539 return 1;
540 return 0;
541 }
542
543 /* ========================================================================= */
544 int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
545 uInt dictLength) {
 
 
 
546 deflate_state *s;
547 uInt str, n;
548 int wrap;
549 unsigned avail;
550 z_const unsigned char *next;
@@ -476,15 +605,12 @@
605 s->wrap = wrap;
606 return Z_OK;
607 }
608
609 /* ========================================================================= */
610 int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary,
611 uInt *dictLength) {
 
 
 
612 deflate_state *s;
613 uInt len;
614
615 if (deflateStateCheck(strm))
616 return Z_STREAM_ERROR;
@@ -498,13 +624,11 @@
624 *dictLength = len;
625 return Z_OK;
626 }
627
628 /* ========================================================================= */
629 int ZEXPORT deflateResetKeep(z_streamp strm) {
 
 
630 deflate_state *s;
631
632 if (deflateStateCheck(strm)) {
633 return Z_STREAM_ERROR;
634 }
@@ -534,54 +658,65 @@
658
659 _tr_init(s);
660
661 return Z_OK;
662 }
663
664 /* ===========================================================================
665 * Initialize the "longest match" routines for a new zlib stream
666 */
667 local void lm_init(deflate_state *s) {
668 s->window_size = (ulg)2L*s->w_size;
669
670 CLEAR_HASH(s);
671
672 /* Set the default configuration parameters:
673 */
674 s->max_lazy_match = configuration_table[s->level].max_lazy;
675 s->good_match = configuration_table[s->level].good_length;
676 s->nice_match = configuration_table[s->level].nice_length;
677 s->max_chain_length = configuration_table[s->level].max_chain;
678
679 s->strstart = 0;
680 s->block_start = 0L;
681 s->lookahead = 0;
682 s->insert = 0;
683 s->match_length = s->prev_length = MIN_MATCH-1;
684 s->match_available = 0;
685 s->ins_h = 0;
686 }
687
688 /* ========================================================================= */
689 int ZEXPORT deflateReset(z_streamp strm) {
 
 
690 int ret;
691
692 ret = deflateResetKeep(strm);
693 if (ret == Z_OK)
694 lm_init(strm->state);
695 return ret;
696 }
697
698 /* ========================================================================= */
699 int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) {
 
 
 
700 if (deflateStateCheck(strm) || strm->state->wrap != 2)
701 return Z_STREAM_ERROR;
702 strm->state->gzhead = head;
703 return Z_OK;
704 }
705
706 /* ========================================================================= */
707 int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) {
 
 
 
 
708 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
709 if (pending != Z_NULL)
710 *pending = strm->state->pending;
711 if (bits != Z_NULL)
712 *bits = strm->state->bi_valid;
713 return Z_OK;
714 }
715
716 /* ========================================================================= */
717 int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) {
 
 
 
 
718 deflate_state *s;
719 int put;
720
721 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
722 s = strm->state;
@@ -600,15 +735,11 @@
735 } while (bits);
736 return Z_OK;
737 }
738
739 /* ========================================================================= */
740 int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) {
 
 
 
 
741 deflate_state *s;
742 compress_func func;
743
744 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
745 s = strm->state;
@@ -649,17 +780,12 @@
780 s->strategy = strategy;
781 return Z_OK;
782 }
783
784 /* ========================================================================= */
785 int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy,
786 int nice_length, int max_chain) {
 
 
 
 
 
787 deflate_state *s;
788
789 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
790 s = strm->state;
791 s->good_match = (uInt)good_length;
@@ -691,14 +817,11 @@
817 * per 8-bit byte, plus 10 bits for every block. The smallest block size for
818 * which this can occur is 255 (memLevel == 2).
819 *
820 * Shifts are used to approximate divisions, for speed.
821 */
822 uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) {
 
 
 
823 deflate_state *s;
824 uLong fixedlen, storelen, wraplen;
825
826 /* upper bound for fixed blocks with 9-bit literals and length 255
827 (memLevel == 2, which is the lowest that may not use stored blocks) --
@@ -750,11 +873,12 @@
873 wraplen = 6;
874 }
875
876 /* if not default parameters, return one of the conservative bounds */
877 if (s->w_bits != 15 || s->hash_bits != 8 + 7)
878 return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) +
879 wraplen;
880
881 /* default settings: return tight bound for that case -- ~0.03% overhead
882 plus a small constant */
883 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
884 (sourceLen >> 25) + 13 - 6 + wraplen;
@@ -763,14 +887,11 @@
887 /* =========================================================================
888 * Put a short in the pending buffer. The 16-bit value is put in MSB order.
889 * IN assertion: the stream state is correct and there is enough room in
890 * pending_buf.
891 */
892 local void putShortMSB(deflate_state *s, uInt b) {
 
 
 
893 put_byte(s, (Byte)(b >> 8));
894 put_byte(s, (Byte)(b & 0xff));
895 }
896
897 /* =========================================================================
@@ -777,13 +898,11 @@
898 * Flush as much pending output as possible. All deflate() output, except for
899 * some deflate_stored() output, goes through this function so some
900 * applications may wish to modify it to avoid allocating a large
901 * strm->next_out buffer and copying into it. (See also read_buf()).
902 */
903 local void flush_pending(z_streamp strm) {
 
 
904 unsigned len;
905 deflate_state *s = strm->state;
906
907 _tr_flush_bits(s);
908 len = s->pending;
@@ -810,14 +929,11 @@
929 strm->adler = crc32(strm->adler, s->pending_buf + (beg), \
930 s->pending - (beg)); \
931 } while (0)
932
933 /* ========================================================================= */
934 int ZEXPORT deflate(z_streamp strm, int flush) {
 
 
 
935 int old_flush; /* value of flush param for previous deflate call */
936 deflate_state *s;
937
938 if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) {
939 return Z_STREAM_ERROR;
@@ -1125,13 +1241,11 @@
1241 if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
1242 return s->pending != 0 ? Z_OK : Z_STREAM_END;
1243 }
1244
1245 /* ========================================================================= */
1246 int ZEXPORT deflateEnd(z_streamp strm) {
 
 
1247 int status;
1248
1249 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
1250
1251 status = strm->state->status;
@@ -1151,15 +1265,14 @@
1265 /* =========================================================================
1266 * Copy the source state to the destination state.
1267 * To simplify the source, this is not supported for 16-bit MSDOS (which
1268 * doesn't have enough memory anyway to duplicate compression states).
1269 */
1270 int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
 
 
 
1271 #ifdef MAXSEG_64K
1272 (void)dest;
1273 (void)source;
1274 return Z_STREAM_ERROR;
1275 #else
1276 deflate_state *ds;
1277 deflate_state *ss;
1278
@@ -1203,70 +1316,10 @@
1316
1317 return Z_OK;
1318 #endif /* MAXSEG_64K */
1319 }
1320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1321 #ifndef FASTEST
1322 /* ===========================================================================
1323 * Set match_start to the longest match starting at the given string and
1324 * return its length. Matches shorter or equal to prev_length are discarded,
1325 * in which case the result is equal to prev_length and match_start is
@@ -1273,14 +1326,11 @@
1326 * garbage.
1327 * IN assertions: cur_match is the head of the hash chain for the current
1328 * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
1329 * OUT assertion: the match length is not greater than s->lookahead.
1330 */
1331 local uInt longest_match(deflate_state *s, IPos cur_match) {
 
 
 
1332 unsigned chain_length = s->max_chain_length;/* max hash chain length */
1333 register Bytef *scan = s->window + s->strstart; /* current string */
1334 register Bytef *match; /* matched string */
1335 register int len; /* length of current match */
1336 int best_len = (int)s->prev_length; /* best match length so far */
@@ -1424,14 +1474,11 @@
1474 #else /* FASTEST */
1475
1476 /* ---------------------------------------------------------------------------
1477 * Optimized version for FASTEST only
1478 */
1479 local uInt longest_match(deflate_state *s, IPos cur_match) {
 
 
 
1480 register Bytef *scan = s->window + s->strstart; /* current string */
1481 register Bytef *match; /* matched string */
1482 register int len; /* length of current match */
1483 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
1484
@@ -1488,15 +1535,11 @@
1535 /* result of memcmp for equal strings */
1536
1537 /* ===========================================================================
1538 * Check that the match at match_start is indeed a match.
1539 */
1540 local void check_match(deflate_state *s, IPos start, IPos match, int length) {
 
 
 
 
1541 /* check that the match is indeed a match */
1542 if (zmemcmp(s->window + match,
1543 s->window + start, length) != EQUAL) {
1544 fprintf(stderr, " start %u, match %u, length %d\n",
1545 start, match, length);
@@ -1512,141 +1555,10 @@
1555 }
1556 #else
1557 # define check_match(s, start, match, length)
1558 #endif /* ZLIB_DEBUG */
1559
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1560 /* ===========================================================================
1561 * Flush the current block, with given end-of-file flag.
1562 * IN assertion: strstart is set to the end of the current match.
1563 */
1564 #define FLUSH_BLOCK_ONLY(s, last) { \
@@ -1685,14 +1597,11 @@
1597 *
1598 * deflate_stored() is written to minimize the number of times an input byte is
1599 * copied. It is most efficient with large input and output buffers, which
1600 * maximizes the opportunities to have a single copy from next_in to next_out.
1601 */
1602 local block_state deflate_stored(deflate_state *s, int flush) {
 
 
 
1603 /* Smallest worthy block size when not flushing or finishing. By default
1604 * this is 32K. This can be as small as 507 bytes for memLevel == 1. For
1605 * large input and output buffers, the stored block size will be larger.
1606 */
1607 unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size);
@@ -1872,14 +1781,11 @@
1781 * block state.
1782 * This function does not perform lazy evaluation of matches and inserts
1783 * new strings in the dictionary only for unmatched strings or for short
1784 * matches. It is used only for the fast compression options.
1785 */
1786 local block_state deflate_fast(deflate_state *s, int flush) {
 
 
 
1787 IPos hash_head; /* head of the hash chain */
1788 int bflush; /* set if current block must be flushed */
1789
1790 for (;;) {
1791 /* Make sure that we always have enough lookahead, except
@@ -1974,14 +1880,11 @@
1880 /* ===========================================================================
1881 * Same as above, but achieves better compression. We use a lazy
1882 * evaluation for matches: a match is finally adopted only if there is
1883 * no better match at the next window position.
1884 */
1885 local block_state deflate_slow(deflate_state *s, int flush) {
 
 
 
1886 IPos hash_head; /* head of hash chain */
1887 int bflush; /* set if current block must be flushed */
1888
1889 /* Process the input block. */
1890 for (;;) {
@@ -2105,14 +2008,11 @@
2008 /* ===========================================================================
2009 * For Z_RLE, simply look for runs of bytes, generate matches only of distance
2010 * one. Do not maintain a hash table. (It will be regenerated if this run of
2011 * deflate switches away from Z_RLE.)
2012 */
2013 local block_state deflate_rle(deflate_state *s, int flush) {
 
 
 
2014 int bflush; /* set if current block must be flushed */
2015 uInt prev; /* byte at distance one to match */
2016 Bytef *scan, *strend; /* scan goes up to strend for length of run */
2017
2018 for (;;) {
@@ -2179,14 +2079,11 @@
2079
2080 /* ===========================================================================
2081 * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
2082 * (It will be regenerated if this run of deflate switches away from Huffman.)
2083 */
2084 local block_state deflate_huff(deflate_state *s, int flush) {
 
 
 
2085 int bflush; /* set if current block must be flushed */
2086
2087 for (;;) {
2088 /* Make sure that we have a literal to write. */
2089 if (s->lookahead == 0) {
2090
--- compat/zlib/deflate.h
+++ compat/zlib/deflate.h
@@ -289,18 +289,18 @@
289289
#define WIN_INIT MAX_MATCH
290290
/* Number of bytes after end of data in window to initialize in order to avoid
291291
memory checker errors from longest match routines */
292292
293293
/* in trees.c */
294
-void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
295
-int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
296
-void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
297
- ulg stored_len, int last));
298
-void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
299
-void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
300
-void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
301
- ulg stored_len, int last));
294
+void ZLIB_INTERNAL _tr_init(deflate_state *s);
295
+int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
296
+void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
297
+ ulg stored_len, int last);
298
+void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
299
+void ZLIB_INTERNAL _tr_align(deflate_state *s);
300
+void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
301
+ ulg stored_len, int last);
302302
303303
#define d_code(dist) \
304304
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
305305
/* Mapping from a distance to a distance code. dist is the distance - 1 and
306306
* must not have side effects. _dist_code[256] and _dist_code[257] are never
307307
--- compat/zlib/deflate.h
+++ compat/zlib/deflate.h
@@ -289,18 +289,18 @@
289 #define WIN_INIT MAX_MATCH
290 /* Number of bytes after end of data in window to initialize in order to avoid
291 memory checker errors from longest match routines */
292
293 /* in trees.c */
294 void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
295 int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
296 void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
297 ulg stored_len, int last));
298 void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
299 void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
300 void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
301 ulg stored_len, int last));
302
303 #define d_code(dist) \
304 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
305 /* Mapping from a distance to a distance code. dist is the distance - 1 and
306 * must not have side effects. _dist_code[256] and _dist_code[257] are never
307
--- compat/zlib/deflate.h
+++ compat/zlib/deflate.h
@@ -289,18 +289,18 @@
289 #define WIN_INIT MAX_MATCH
290 /* Number of bytes after end of data in window to initialize in order to avoid
291 memory checker errors from longest match routines */
292
293 /* in trees.c */
294 void ZLIB_INTERNAL _tr_init(deflate_state *s);
295 int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
296 void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
297 ulg stored_len, int last);
298 void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
299 void ZLIB_INTERNAL _tr_align(deflate_state *s);
300 void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
301 ulg stored_len, int last);
302
303 #define d_code(dist) \
304 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
305 /* Mapping from a distance to a distance code. dist is the distance - 1 and
306 * must not have side effects. _dist_code[256] and _dist_code[257] are never
307
--- compat/zlib/examples/fitblk.c
+++ compat/zlib/examples/fitblk.c
@@ -196,11 +196,11 @@
196196
def.next_out = tmp;
197197
ret = recompress(&inf, &def);
198198
if (ret == Z_MEM_ERROR)
199199
quit("out of memory");
200200
201
- /* set up for next reocmpression */
201
+ /* set up for next recompression */
202202
ret = inflateReset(&inf);
203203
assert(ret != Z_STREAM_ERROR);
204204
ret = deflateReset(&def);
205205
assert(ret != Z_STREAM_ERROR);
206206
207207
--- compat/zlib/examples/fitblk.c
+++ compat/zlib/examples/fitblk.c
@@ -196,11 +196,11 @@
196 def.next_out = tmp;
197 ret = recompress(&inf, &def);
198 if (ret == Z_MEM_ERROR)
199 quit("out of memory");
200
201 /* set up for next reocmpression */
202 ret = inflateReset(&inf);
203 assert(ret != Z_STREAM_ERROR);
204 ret = deflateReset(&def);
205 assert(ret != Z_STREAM_ERROR);
206
207
--- compat/zlib/examples/fitblk.c
+++ compat/zlib/examples/fitblk.c
@@ -196,11 +196,11 @@
196 def.next_out = tmp;
197 ret = recompress(&inf, &def);
198 if (ret == Z_MEM_ERROR)
199 quit("out of memory");
200
201 /* set up for next recompression */
202 ret = inflateReset(&inf);
203 assert(ret != Z_STREAM_ERROR);
204 ret = deflateReset(&def);
205 assert(ret != Z_STREAM_ERROR);
206
207
--- compat/zlib/examples/zlib_how.html
+++ compat/zlib/examples/zlib_how.html
@@ -1,12 +1,12 @@
1
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
2
- "http://www.w3.org/TR/REC-html40/loose.dtd">
1
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2
+ "http://www.w3.org/TR/html4/loose.dtd">
33
<html>
44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
66
<title>zlib Usage Example</title>
7
-<!-- Copyright (c) 2004, 2005 Mark Adler. -->
7
+<!-- Copyright (c) 2004-2023 Mark Adler. -->
88
</head>
99
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#00A000">
1010
<h2 align="center"> zlib Usage Example </h2>
1111
We often get questions about how the <tt>deflate()</tt> and <tt>inflate()</tt> functions should be used.
1212
Users wonder when they should provide more input, when they should use more output,
@@ -15,11 +15,11 @@
1515
would like further edification, below is an annotated example in C of simple routines to compress and decompress
1616
from an input file to an output file using <tt>deflate()</tt> and <tt>inflate()</tt> respectively. The
1717
annotations are interspersed between lines of the code. So please read between the lines.
1818
We hope this helps explain some of the intricacies of <em>zlib</em>.
1919
<p>
20
-Without further adieu, here is the program <a href="zpipe.c"><tt>zpipe.c</tt></a>:
20
+Without further ado, here is the program <a href="zpipe.c"><tt>zpipe.c</tt></a>:
2121
<pre><b>
2222
/* zpipe.c: example of proper use of zlib's inflate() and deflate()
2323
Not copyrighted -- provided to the public domain
2424
Version 1.4 11 December 2005 Mark Adler */
2525
@@ -153,17 +153,15 @@
153153
/* compress until end of file */
154154
do {
155155
</b></pre>
156156
We start off by reading data from the input file. The number of bytes read is put directly
157157
into <tt>avail_in</tt>, and a pointer to those bytes is put into <tt>next_in</tt>. We also
158
-check to see if end-of-file on the input has been reached. If we are at the end of file, then <tt>flush</tt> is set to the
158
+check to see if end-of-file on the input has been reached using feof().
159
+If we are at the end of file, then <tt>flush</tt> is set to the
159160
<em>zlib</em> constant <tt>Z_FINISH</tt>, which is later passed to <tt>deflate()</tt> to
160
-indicate that this is the last chunk of input data to compress. We need to use <tt>feof()</tt>
161
-to check for end-of-file as opposed to seeing if fewer than <tt>CHUNK</tt> bytes have been read. The
162
-reason is that if the input file length is an exact multiple of <tt>CHUNK</tt>, we will miss
163
-the fact that we got to the end-of-file, and not know to tell <tt>deflate()</tt> to finish
164
-up the compressed stream. If we are not yet at the end of the input, then the <em>zlib</em>
161
+indicate that this is the last chunk of input data to compress.
162
+If we are not yet at the end of the input, then the <em>zlib</em>
165163
constant <tt>Z_NO_FLUSH</tt> will be passed to <tt>deflate</tt> to indicate that we are still
166164
in the middle of the uncompressed data.
167165
<p>
168166
If there is an error in reading from the input file, the process is aborted with
169167
<tt>deflateEnd()</tt> being called to free the allocated <em>zlib</em> state before returning
@@ -538,8 +536,14 @@
538536
return 1;
539537
}
540538
}
541539
</b></pre>
542540
<hr>
543
-<i>Copyright (c) 2004, 2005 by Mark Adler<br>Last modified 11 December 2005</i>
541
+<i>Last modified 24 January 2023<br>
542
+Copyright &#169; 2004-2023 Mark Adler</i><br>
543
+<a rel="license" href="http://creativecommons.org/licenses/by-nd/4.0/">
544
+<img alt="Creative Commons License" style="border-width:0"
545
+src="https://i.creativecommons.org/l/by-nd/4.0/88x31.png"></a>
546
+<a rel="license" href="http://creativecommons.org/licenses/by-nd/4.0/">
547
+Creative Commons Attribution-NoDerivatives 4.0 International License</a>.
544548
</body>
545549
</html>
546550
--- compat/zlib/examples/zlib_how.html
+++ compat/zlib/examples/zlib_how.html
@@ -1,12 +1,12 @@
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
2 "http://www.w3.org/TR/REC-html40/loose.dtd">
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6 <title>zlib Usage Example</title>
7 <!-- Copyright (c) 2004, 2005 Mark Adler. -->
8 </head>
9 <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#00A000">
10 <h2 align="center"> zlib Usage Example </h2>
11 We often get questions about how the <tt>deflate()</tt> and <tt>inflate()</tt> functions should be used.
12 Users wonder when they should provide more input, when they should use more output,
@@ -15,11 +15,11 @@
15 would like further edification, below is an annotated example in C of simple routines to compress and decompress
16 from an input file to an output file using <tt>deflate()</tt> and <tt>inflate()</tt> respectively. The
17 annotations are interspersed between lines of the code. So please read between the lines.
18 We hope this helps explain some of the intricacies of <em>zlib</em>.
19 <p>
20 Without further adieu, here is the program <a href="zpipe.c"><tt>zpipe.c</tt></a>:
21 <pre><b>
22 /* zpipe.c: example of proper use of zlib's inflate() and deflate()
23 Not copyrighted -- provided to the public domain
24 Version 1.4 11 December 2005 Mark Adler */
25
@@ -153,17 +153,15 @@
153 /* compress until end of file */
154 do {
155 </b></pre>
156 We start off by reading data from the input file. The number of bytes read is put directly
157 into <tt>avail_in</tt>, and a pointer to those bytes is put into <tt>next_in</tt>. We also
158 check to see if end-of-file on the input has been reached. If we are at the end of file, then <tt>flush</tt> is set to the
 
159 <em>zlib</em> constant <tt>Z_FINISH</tt>, which is later passed to <tt>deflate()</tt> to
160 indicate that this is the last chunk of input data to compress. We need to use <tt>feof()</tt>
161 to check for end-of-file as opposed to seeing if fewer than <tt>CHUNK</tt> bytes have been read. The
162 reason is that if the input file length is an exact multiple of <tt>CHUNK</tt>, we will miss
163 the fact that we got to the end-of-file, and not know to tell <tt>deflate()</tt> to finish
164 up the compressed stream. If we are not yet at the end of the input, then the <em>zlib</em>
165 constant <tt>Z_NO_FLUSH</tt> will be passed to <tt>deflate</tt> to indicate that we are still
166 in the middle of the uncompressed data.
167 <p>
168 If there is an error in reading from the input file, the process is aborted with
169 <tt>deflateEnd()</tt> being called to free the allocated <em>zlib</em> state before returning
@@ -538,8 +536,14 @@
538 return 1;
539 }
540 }
541 </b></pre>
542 <hr>
543 <i>Copyright (c) 2004, 2005 by Mark Adler<br>Last modified 11 December 2005</i>
 
 
 
 
 
 
544 </body>
545 </html>
546
--- compat/zlib/examples/zlib_how.html
+++ compat/zlib/examples/zlib_how.html
@@ -1,12 +1,12 @@
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6 <title>zlib Usage Example</title>
7 <!-- Copyright (c) 2004-2023 Mark Adler. -->
8 </head>
9 <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#00A000">
10 <h2 align="center"> zlib Usage Example </h2>
11 We often get questions about how the <tt>deflate()</tt> and <tt>inflate()</tt> functions should be used.
12 Users wonder when they should provide more input, when they should use more output,
@@ -15,11 +15,11 @@
15 would like further edification, below is an annotated example in C of simple routines to compress and decompress
16 from an input file to an output file using <tt>deflate()</tt> and <tt>inflate()</tt> respectively. The
17 annotations are interspersed between lines of the code. So please read between the lines.
18 We hope this helps explain some of the intricacies of <em>zlib</em>.
19 <p>
20 Without further ado, here is the program <a href="zpipe.c"><tt>zpipe.c</tt></a>:
21 <pre><b>
22 /* zpipe.c: example of proper use of zlib's inflate() and deflate()
23 Not copyrighted -- provided to the public domain
24 Version 1.4 11 December 2005 Mark Adler */
25
@@ -153,17 +153,15 @@
153 /* compress until end of file */
154 do {
155 </b></pre>
156 We start off by reading data from the input file. The number of bytes read is put directly
157 into <tt>avail_in</tt>, and a pointer to those bytes is put into <tt>next_in</tt>. We also
158 check to see if end-of-file on the input has been reached using feof().
159 If we are at the end of file, then <tt>flush</tt> is set to the
160 <em>zlib</em> constant <tt>Z_FINISH</tt>, which is later passed to <tt>deflate()</tt> to
161 indicate that this is the last chunk of input data to compress.
162 If we are not yet at the end of the input, then the <em>zlib</em>
 
 
 
163 constant <tt>Z_NO_FLUSH</tt> will be passed to <tt>deflate</tt> to indicate that we are still
164 in the middle of the uncompressed data.
165 <p>
166 If there is an error in reading from the input file, the process is aborted with
167 <tt>deflateEnd()</tt> being called to free the allocated <em>zlib</em> state before returning
@@ -538,8 +536,14 @@
536 return 1;
537 }
538 }
539 </b></pre>
540 <hr>
541 <i>Last modified 24 January 2023<br>
542 Copyright &#169; 2004-2023 Mark Adler</i><br>
543 <a rel="license" href="http://creativecommons.org/licenses/by-nd/4.0/">
544 <img alt="Creative Commons License" style="border-width:0"
545 src="https://i.creativecommons.org/l/by-nd/4.0/88x31.png"></a>
546 <a rel="license" href="http://creativecommons.org/licenses/by-nd/4.0/">
547 Creative Commons Attribution-NoDerivatives 4.0 International License</a>.
548 </body>
549 </html>
550
--- compat/zlib/examples/zran.c
+++ compat/zlib/examples/zran.c
@@ -1,452 +1,505 @@
1
-/* zran.c -- example of zlib/gzip stream indexing and random access
2
- * Copyright (C) 2005, 2012, 2018 Mark Adler
1
+/* zran.c -- example of deflate stream indexing and random access
2
+ * Copyright (C) 2005, 2012, 2018, 2023 Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
4
- * Version 1.2 14 Oct 2018 Mark Adler */
4
+ * Version 1.4 13 Apr 2023 Mark Adler */
55
66
/* Version History:
77
1.0 29 May 2005 First version
88
1.1 29 Sep 2012 Fix memory reallocation error
99
1.2 14 Oct 2018 Handle gzip streams with multiple members
1010
Add a header file to facilitate usage in applications
11
- */
12
-
13
-/* Illustrate the use of Z_BLOCK, inflatePrime(), and inflateSetDictionary()
14
- for random access of a compressed file. A file containing a zlib or gzip
15
- stream is provided on the command line. The compressed stream is decoded in
16
- its entirety, and an index built with access points about every SPAN bytes
17
- in the uncompressed output. The compressed file is left open, and can then
18
- be read randomly, having to decompress on the average SPAN/2 uncompressed
19
- bytes before getting to the desired block of data.
20
-
21
- An access point can be created at the start of any deflate block, by saving
22
- the starting file offset and bit of that block, and the 32K bytes of
23
- uncompressed data that precede that block. Also the uncompressed offset of
24
- that block is saved to provide a reference for locating a desired starting
25
- point in the uncompressed stream. deflate_index_build() works by
26
- decompressing the input zlib or gzip stream a block at a time, and at the
27
- end of each block deciding if enough uncompressed data has gone by to
28
- justify the creation of a new access point. If so, that point is saved in a
29
- data structure that grows as needed to accommodate the points.
30
-
31
- To use the index, an offset in the uncompressed data is provided, for which
32
- the latest access point at or preceding that offset is located in the index.
33
- The input file is positioned to the specified location in the index, and if
34
- necessary the first few bits of the compressed data is read from the file.
35
- inflate is initialized with those bits and the 32K of uncompressed data, and
36
- the decompression then proceeds until the desired offset in the file is
37
- reached. Then the decompression continues to read the desired uncompressed
38
- data from the file.
39
-
40
- Another approach would be to generate the index on demand. In that case,
41
- requests for random access reads from the compressed data would try to use
42
- the index, but if a read far enough past the end of the index is required,
43
- then further index entries would be generated and added.
44
-
45
- There is some fair bit of overhead to starting inflation for the random
46
- access, mainly copying the 32K byte dictionary. So if small pieces of the
47
- file are being accessed, it would make sense to implement a cache to hold
48
- some lookahead and avoid many calls to deflate_index_extract() for small
49
- lengths.
50
-
51
- Another way to build an index would be to use inflateCopy(). That would
52
- not be constrained to have access points at block boundaries, but requires
53
- more memory per access point, and also cannot be saved to file due to the
54
- use of pointers in the state. The approach here allows for storage of the
55
- index in a file.
56
- */
11
+ 1.3 18 Feb 2023 Permit raw deflate streams as well as zlib and gzip
12
+ Permit crossing gzip member boundaries when extracting
13
+ Support a size_t size when extracting (was an int)
14
+ Do a binary search over the index for an access point
15
+ Expose the access point type to enable save and load
16
+ 1.4 13 Apr 2023 Add a NOPRIME define to not use inflatePrime()
17
+ */
18
+
19
+// Illustrate the use of Z_BLOCK, inflatePrime(), and inflateSetDictionary()
20
+// for random access of a compressed file. A file containing a raw deflate
21
+// stream is provided on the command line. The compressed stream is decoded in
22
+// its entirety, and an index built with access points about every SPAN bytes
23
+// in the uncompressed output. The compressed file is left open, and can then
24
+// be read randomly, having to decompress on the average SPAN/2 uncompressed
25
+// bytes before getting to the desired block of data.
26
+//
27
+// An access point can be created at the start of any deflate block, by saving
28
+// the starting file offset and bit of that block, and the 32K bytes of
29
+// uncompressed data that precede that block. Also the uncompressed offset of
30
+// that block is saved to provide a reference for locating a desired starting
31
+// point in the uncompressed stream. deflate_index_build() decompresses the
32
+// input raw deflate stream a block at a time, and at the end of each block
33
+// decides if enough uncompressed data has gone by to justify the creation of a
34
+// new access point. If so, that point is saved in a data structure that grows
35
+// as needed to accommodate the points.
36
+//
37
+// To use the index, an offset in the uncompressed data is provided, for which
38
+// the latest access point at or preceding that offset is located in the index.
39
+// The input file is positioned to the specified location in the index, and if
40
+// necessary the first few bits of the compressed data is read from the file.
41
+// inflate is initialized with those bits and the 32K of uncompressed data, and
42
+// decompression then proceeds until the desired offset in the file is reached.
43
+// Then decompression continues to read the requested uncompressed data from
44
+// the file.
45
+//
46
+// There is some fair bit of overhead to starting inflation for the random
47
+// access, mainly copying the 32K byte dictionary. If small pieces of the file
48
+// are being accessed, it would make sense to implement a cache to hold some
49
+// lookahead to avoid many calls to deflate_index_extract() for small lengths.
50
+//
51
+// Another way to build an index would be to use inflateCopy(). That would not
52
+// be constrained to have access points at block boundaries, but would require
53
+// more memory per access point, and could not be saved to a file due to the
54
+// use of pointers in the state. The approach here allows for storage of the
55
+// index in a file.
5756
5857
#include <stdio.h>
5958
#include <stdlib.h>
6059
#include <string.h>
60
+#include <limits.h>
6161
#include "zlib.h"
6262
#include "zran.h"
6363
64
-#define WINSIZE 32768U /* sliding window size */
65
-#define CHUNK 16384 /* file input buffer size */
66
-
67
-/* Access point entry. */
68
-struct point {
69
- off_t out; /* corresponding offset in uncompressed data */
70
- off_t in; /* offset in input file of first full byte */
71
- int bits; /* number of bits (1-7) from byte at in-1, or 0 */
72
- unsigned char window[WINSIZE]; /* preceding 32K of uncompressed data */
73
-};
74
-
75
-/* See comments in zran.h. */
76
-void deflate_index_free(struct deflate_index *index)
77
-{
64
+#define WINSIZE 32768U // sliding window size
65
+#define CHUNK 16384 // file input buffer size
66
+
67
+// See comments in zran.h.
68
+void deflate_index_free(struct deflate_index *index) {
7869
if (index != NULL) {
7970
free(index->list);
8071
free(index);
8172
}
8273
}
8374
84
-/* Add an entry to the access point list. If out of memory, deallocate the
85
- existing list and return NULL. index->gzip is the allocated size of the
86
- index in point entries, until it is time for deflate_index_build() to
87
- return, at which point gzip is set to indicate a gzip file or not.
88
- */
89
-static struct deflate_index *addpoint(struct deflate_index *index, int bits,
90
- off_t in, off_t out, unsigned left,
91
- unsigned char *window)
92
-{
93
- struct point *next;
94
-
95
- /* if list is empty, create it (start with eight points) */
75
+// Add an access point to the list. If out of memory, deallocate the existing
76
+// list and return NULL. index->mode is temporarily the allocated number of
77
+// access points, until it is time for deflate_index_build() to return. Then
78
+// index->mode is set to the mode of inflation.
79
+static struct deflate_index *add_point(struct deflate_index *index, int bits,
80
+ off_t in, off_t out, unsigned left,
81
+ unsigned char *window) {
9682
if (index == NULL) {
83
+ // The list is empty. Create it, starting with eight access points.
9784
index = malloc(sizeof(struct deflate_index));
98
- if (index == NULL) return NULL;
99
- index->list = malloc(sizeof(struct point) << 3);
85
+ if (index == NULL)
86
+ return NULL;
87
+ index->have = 0;
88
+ index->mode = 8;
89
+ index->list = malloc(sizeof(point_t) * index->mode);
10090
if (index->list == NULL) {
10191
free(index);
10292
return NULL;
10393
}
104
- index->gzip = 8;
105
- index->have = 0;
10694
}
10795
108
- /* if list is full, make it bigger */
109
- else if (index->have == index->gzip) {
110
- index->gzip <<= 1;
111
- next = realloc(index->list, sizeof(struct point) * index->gzip);
96
+ else if (index->have == index->mode) {
97
+ // The list is full. Make it bigger.
98
+ index->mode <<= 1;
99
+ point_t *next = realloc(index->list, sizeof(point_t) * index->mode);
112100
if (next == NULL) {
113101
deflate_index_free(index);
114102
return NULL;
115103
}
116104
index->list = next;
117105
}
118106
119
- /* fill in entry and increment how many we have */
120
- next = (struct point *)(index->list) + index->have;
121
- next->bits = bits;
122
- next->in = in;
107
+ // Fill in the access point and increment how many we have.
108
+ point_t *next = (point_t *)(index->list) + index->have++;
109
+ if (index->have < 0) {
110
+ // Overflowed the int!
111
+ deflate_index_free(index);
112
+ return NULL;
113
+ }
123114
next->out = out;
115
+ next->in = in;
116
+ next->bits = bits;
124117
if (left)
125118
memcpy(next->window, window + WINSIZE - left, left);
126119
if (left < WINSIZE)
127120
memcpy(next->window + left, window, WINSIZE - left);
128
- index->have++;
129121
130
- /* return list, possibly reallocated */
122
+ // Return the index, which may have been newly allocated or destroyed.
131123
return index;
132124
}
133125
134
-/* See comments in zran.h. */
135
-int deflate_index_build(FILE *in, off_t span, struct deflate_index **built)
136
-{
137
- int ret;
138
- int gzip = 0; /* true if reading a gzip file */
139
- off_t totin, totout; /* our own total counters to avoid 4GB limit */
140
- off_t last; /* totout value of last access point */
141
- struct deflate_index *index; /* access points being generated */
142
- z_stream strm;
143
- unsigned char input[CHUNK];
144
- unsigned char window[WINSIZE];
145
-
146
- /* initialize inflate */
147
- strm.zalloc = Z_NULL;
148
- strm.zfree = Z_NULL;
149
- strm.opaque = Z_NULL;
150
- strm.avail_in = 0;
151
- strm.next_in = Z_NULL;
152
- ret = inflateInit2(&strm, 47); /* automatic zlib or gzip decoding */
153
- if (ret != Z_OK)
154
- return ret;
155
-
156
- /* inflate the input, maintain a sliding window, and build an index -- this
157
- also validates the integrity of the compressed data using the check
158
- information in the gzip or zlib stream */
159
- totin = totout = last = 0;
160
- index = NULL; /* will be allocated by first addpoint() */
161
- strm.avail_out = 0;
162
- do {
163
- /* get some compressed data from input file */
164
- strm.avail_in = fread(input, 1, CHUNK, in);
165
- if (ferror(in)) {
166
- ret = Z_ERRNO;
167
- goto deflate_index_build_error;
168
- }
169
- if (strm.avail_in == 0) {
170
- ret = Z_DATA_ERROR;
171
- goto deflate_index_build_error;
172
- }
173
- strm.next_in = input;
174
-
175
- /* check for a gzip stream */
176
- if (totin == 0 && strm.avail_in >= 3 &&
177
- input[0] == 31 && input[1] == 139 && input[2] == 8)
178
- gzip = 1;
179
-
180
- /* process all of that, or until end of stream */
181
- do {
182
- /* reset sliding window if necessary */
183
- if (strm.avail_out == 0) {
184
- strm.avail_out = WINSIZE;
185
- strm.next_out = window;
186
- }
187
-
188
- /* inflate until out of input, output, or at end of block --
189
- update the total input and output counters */
190
- totin += strm.avail_in;
191
- totout += strm.avail_out;
192
- ret = inflate(&strm, Z_BLOCK); /* return at end of block */
193
- totin -= strm.avail_in;
194
- totout -= strm.avail_out;
195
- if (ret == Z_NEED_DICT)
196
- ret = Z_DATA_ERROR;
197
- if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR)
198
- goto deflate_index_build_error;
199
- if (ret == Z_STREAM_END) {
200
- if (gzip &&
201
- (strm.avail_in || ungetc(getc(in), in) != EOF)) {
202
- ret = inflateReset(&strm);
203
- if (ret != Z_OK)
204
- goto deflate_index_build_error;
205
- continue;
206
- }
207
- break;
208
- }
209
-
210
- /* if at end of block, consider adding an index entry (note that if
211
- data_type indicates an end-of-block, then all of the
212
- uncompressed data from that block has been delivered, and none
213
- of the compressed data after that block has been consumed,
214
- except for up to seven bits) -- the totout == 0 provides an
215
- entry point after the zlib or gzip header, and assures that the
216
- index always has at least one access point; we avoid creating an
217
- access point after the last block by checking bit 6 of data_type
218
- */
219
- if ((strm.data_type & 128) && !(strm.data_type & 64) &&
220
- (totout == 0 || totout - last > span)) {
221
- index = addpoint(index, strm.data_type & 7, totin,
222
- totout, strm.avail_out, window);
223
- if (index == NULL) {
224
- ret = Z_MEM_ERROR;
225
- goto deflate_index_build_error;
226
- }
227
- last = totout;
228
- }
229
- } while (strm.avail_in != 0);
230
- } while (ret != Z_STREAM_END);
231
-
232
- /* clean up and return index (release unused entries in list) */
233
- (void)inflateEnd(&strm);
234
- index->list = realloc(index->list, sizeof(struct point) * index->have);
235
- index->gzip = gzip;
236
- index->length = totout;
237
- *built = index;
238
- return index->have;
239
-
240
- /* return error */
241
- deflate_index_build_error:
242
- (void)inflateEnd(&strm);
243
- deflate_index_free(index);
244
- return ret;
245
-}
246
-
247
-/* See comments in zran.h. */
248
-int deflate_index_extract(FILE *in, struct deflate_index *index, off_t offset,
249
- unsigned char *buf, int len)
250
-{
251
- int ret, skip;
252
- z_stream strm;
253
- struct point *here;
254
- unsigned char input[CHUNK];
255
- unsigned char discard[WINSIZE];
256
-
257
- /* proceed only if something reasonable to do */
258
- if (len < 0)
259
- return 0;
260
-
261
- /* find where in stream to start */
262
- here = index->list;
263
- ret = index->have;
264
- while (--ret && here[1].out <= offset)
265
- here++;
266
-
267
- /* initialize file and inflate state to start there */
268
- strm.zalloc = Z_NULL;
269
- strm.zfree = Z_NULL;
270
- strm.opaque = Z_NULL;
271
- strm.avail_in = 0;
272
- strm.next_in = Z_NULL;
273
- ret = inflateInit2(&strm, -15); /* raw inflate */
274
- if (ret != Z_OK)
275
- return ret;
276
- ret = fseeko(in, here->in - (here->bits ? 1 : 0), SEEK_SET);
277
- if (ret == -1)
278
- goto deflate_index_extract_ret;
279
- if (here->bits) {
280
- ret = getc(in);
281
- if (ret == -1) {
282
- ret = ferror(in) ? Z_ERRNO : Z_DATA_ERROR;
283
- goto deflate_index_extract_ret;
284
- }
285
- (void)inflatePrime(&strm, here->bits, ret >> (8 - here->bits));
286
- }
287
- (void)inflateSetDictionary(&strm, here->window, WINSIZE);
288
-
289
- /* skip uncompressed bytes until offset reached, then satisfy request */
290
- offset -= here->out;
291
- strm.avail_in = 0;
292
- skip = 1; /* while skipping to offset */
293
- do {
294
- /* define where to put uncompressed data, and how much */
295
- if (offset > WINSIZE) { /* skip WINSIZE bytes */
296
- strm.avail_out = WINSIZE;
297
- strm.next_out = discard;
298
- offset -= WINSIZE;
299
- }
300
- else if (offset > 0) { /* last skip */
301
- strm.avail_out = (unsigned)offset;
302
- strm.next_out = discard;
303
- offset = 0;
304
- }
305
- else if (skip) { /* at offset now */
306
- strm.avail_out = len;
307
- strm.next_out = buf;
308
- skip = 0; /* only do this once */
309
- }
310
-
311
- /* uncompress until avail_out filled, or end of stream */
312
- do {
313
- if (strm.avail_in == 0) {
314
- strm.avail_in = fread(input, 1, CHUNK, in);
315
- if (ferror(in)) {
316
- ret = Z_ERRNO;
317
- goto deflate_index_extract_ret;
318
- }
319
- if (strm.avail_in == 0) {
320
- ret = Z_DATA_ERROR;
321
- goto deflate_index_extract_ret;
322
- }
323
- strm.next_in = input;
324
- }
325
- ret = inflate(&strm, Z_NO_FLUSH); /* normal inflate */
326
- if (ret == Z_NEED_DICT)
327
- ret = Z_DATA_ERROR;
328
- if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR)
329
- goto deflate_index_extract_ret;
330
- if (ret == Z_STREAM_END) {
331
- /* the raw deflate stream has ended */
332
- if (index->gzip == 0)
333
- /* this is a zlib stream that has ended -- done */
334
- break;
335
-
336
- /* near the end of a gzip member, which might be followed by
337
- another gzip member -- skip the gzip trailer and see if
338
- there is more input after it */
339
- if (strm.avail_in < 8) {
340
- fseeko(in, 8 - strm.avail_in, SEEK_CUR);
341
- strm.avail_in = 0;
342
- }
343
- else {
344
- strm.avail_in -= 8;
345
- strm.next_in += 8;
346
- }
347
- if (strm.avail_in == 0 && ungetc(getc(in), in) == EOF)
348
- /* the input ended after the gzip trailer -- done */
349
- break;
350
-
351
- /* there is more input, so another gzip member should follow --
352
- validate and skip the gzip header */
353
- ret = inflateReset2(&strm, 31);
354
- if (ret != Z_OK)
355
- goto deflate_index_extract_ret;
356
- do {
357
- if (strm.avail_in == 0) {
358
- strm.avail_in = fread(input, 1, CHUNK, in);
359
- if (ferror(in)) {
360
- ret = Z_ERRNO;
361
- goto deflate_index_extract_ret;
362
- }
363
- if (strm.avail_in == 0) {
364
- ret = Z_DATA_ERROR;
365
- goto deflate_index_extract_ret;
366
- }
367
- strm.next_in = input;
368
- }
369
- ret = inflate(&strm, Z_BLOCK);
370
- if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR)
371
- goto deflate_index_extract_ret;
372
- } while ((strm.data_type & 128) == 0);
373
-
374
- /* set up to continue decompression of the raw deflate stream
375
- that follows the gzip header */
376
- ret = inflateReset2(&strm, -15);
377
- if (ret != Z_OK)
378
- goto deflate_index_extract_ret;
379
- }
380
-
381
- /* continue to process the available input before reading more */
382
- } while (strm.avail_out != 0);
383
-
384
- if (ret == Z_STREAM_END)
385
- /* reached the end of the compressed data -- return the data that
386
- was available, possibly less than requested */
387
- break;
388
-
389
- /* do until offset reached and requested data read */
390
- } while (skip);
391
-
392
- /* compute the number of uncompressed bytes read after the offset */
393
- ret = skip ? 0 : len - strm.avail_out;
394
-
395
- /* clean up and return the bytes read, or the negative error */
396
- deflate_index_extract_ret:
397
- (void)inflateEnd(&strm);
398
- return ret;
126
+// Decompression modes. These are the inflateInit2() windowBits parameter.
127
+#define RAW -15
128
+#define ZLIB 15
129
+#define GZIP 31
130
+
131
+// See comments in zran.h.
132
+int deflate_index_build(FILE *in, off_t span, struct deflate_index **built) {
133
+ // Set up inflation state.
134
+ z_stream strm = {0}; // inflate engine (gets fired up later)
135
+ unsigned char buf[CHUNK]; // input buffer
136
+ unsigned char win[WINSIZE] = {0}; // output sliding window
137
+ off_t totin = 0; // total bytes read from input
138
+ off_t totout = 0; // total bytes uncompressed
139
+ int mode = 0; // mode: RAW, ZLIB, or GZIP (0 => not set yet)
140
+
141
+ // Decompress from in, generating access points along the way.
142
+ int ret; // the return value from zlib, or Z_ERRNO
143
+ off_t last; // last access point uncompressed offset
144
+ struct deflate_index *index = NULL; // list of access points
145
+ do {
146
+ // Assure available input, at least until reaching EOF.
147
+ if (strm.avail_in == 0) {
148
+ strm.avail_in = fread(buf, 1, sizeof(buf), in);
149
+ totin += strm.avail_in;
150
+ strm.next_in = buf;
151
+ if (strm.avail_in < sizeof(buf) && ferror(in)) {
152
+ ret = Z_ERRNO;
153
+ break;
154
+ }
155
+
156
+ if (mode == 0) {
157
+ // At the start of the input -- determine the type. Assume raw
158
+ // if it is neither zlib nor gzip. This could in theory result
159
+ // in a false positive for zlib, but in practice the fill bits
160
+ // after a stored block are always zeros, so a raw stream won't
161
+ // start with an 8 in the low nybble.
162
+ mode = strm.avail_in == 0 ? RAW : // empty -- will fail
163
+ (strm.next_in[0] & 0xf) == 8 ? ZLIB :
164
+ strm.next_in[0] == 0x1f ? GZIP :
165
+ /* else */ RAW;
166
+ ret = inflateInit2(&strm, mode);
167
+ if (ret != Z_OK)
168
+ break;
169
+ }
170
+ }
171
+
172
+ // Assure available output. This rotates the output through, for use as
173
+ // a sliding window on the uncompressed data.
174
+ if (strm.avail_out == 0) {
175
+ strm.avail_out = sizeof(win);
176
+ strm.next_out = win;
177
+ }
178
+
179
+ if (mode == RAW && index == NULL)
180
+ // We skip the inflate() call at the start of raw deflate data in
181
+ // order generate an access point there. Set data_type to imitate
182
+ // the end of a header.
183
+ strm.data_type = 0x80;
184
+ else {
185
+ // Inflate and update the number of uncompressed bytes.
186
+ unsigned before = strm.avail_out;
187
+ ret = inflate(&strm, Z_BLOCK);
188
+ totout += before - strm.avail_out;
189
+ }
190
+
191
+ if ((strm.data_type & 0xc0) == 0x80 &&
192
+ (index == NULL || totout - last >= span)) {
193
+ // We are at the end of a header or a non-last deflate block, so we
194
+ // can add an access point here. Furthermore, we are either at the
195
+ // very start for the first access point, or there has been span or
196
+ // more uncompressed bytes since the last access point, so we want
197
+ // to add an access point here.
198
+ index = add_point(index, strm.data_type & 7, totin - strm.avail_in,
199
+ totout, strm.avail_out, win);
200
+ if (index == NULL) {
201
+ ret = Z_MEM_ERROR;
202
+ break;
203
+ }
204
+ last = totout;
205
+ }
206
+
207
+ if (ret == Z_STREAM_END && mode == GZIP &&
208
+ (strm.avail_in || ungetc(getc(in), in) != EOF))
209
+ // There is more input after the end of a gzip member. Reset the
210
+ // inflate state to read another gzip member. On success, this will
211
+ // set ret to Z_OK to continue decompressing.
212
+ ret = inflateReset2(&strm, GZIP);
213
+
214
+ // Keep going until Z_STREAM_END or error. If the compressed data ends
215
+ // prematurely without a file read error, Z_BUF_ERROR is returned.
216
+ } while (ret == Z_OK);
217
+ inflateEnd(&strm);
218
+
219
+ if (ret != Z_STREAM_END) {
220
+ // An error was encountered. Discard the index and return a negative
221
+ // error code.
222
+ deflate_index_free(index);
223
+ return ret == Z_NEED_DICT ? Z_DATA_ERROR : ret;
224
+ }
225
+
226
+ // Shrink the index to only the occupied access points and return it.
227
+ index->mode = mode;
228
+ index->length = totout;
229
+ point_t *list = realloc(index->list, sizeof(point_t) * index->have);
230
+ if (list == NULL) {
231
+ // Seems like a realloc() to make something smaller should always work,
232
+ // but just in case.
233
+ deflate_index_free(index);
234
+ return Z_MEM_ERROR;
235
+ }
236
+ index->list = list;
237
+ *built = index;
238
+ return index->have;
239
+}
240
+
241
+#ifdef NOPRIME
242
+// Support zlib versions before 1.2.3 (July 2005), or incomplete zlib clones
243
+// that do not have inflatePrime().
244
+
245
+# define INFLATEPRIME inflatePreface
246
+
247
+// Append the low bits bits of value to in[] at bit position *have, updating
248
+// *have. value must be zero above its low bits bits. bits must be positive.
249
+// This assumes that any bits above the *have bits in the last byte are zeros.
250
+// That assumption is preserved on return, as any bits above *have + bits in
251
+// the last byte written will be set to zeros.
252
+static inline void append_bits(unsigned value, int bits,
253
+ unsigned char *in, int *have) {
254
+ in += *have >> 3; // where the first bits from value will go
255
+ int k = *have & 7; // the number of bits already there
256
+ *have += bits;
257
+ if (k)
258
+ *in |= value << k; // write value above the low k bits
259
+ else
260
+ *in = value;
261
+ k = 8 - k; // the number of bits just appended
262
+ while (bits > k) {
263
+ value >>= k; // drop the bits appended
264
+ bits -= k;
265
+ k = 8; // now at a byte boundary
266
+ *++in = value;
267
+ }
268
+}
269
+
270
+// Insert enough bits in the form of empty deflate blocks in front of the the
271
+// low bits bits of value, in order to bring the sequence to a byte boundary.
272
+// Then feed that to inflate(). This does what inflatePrime() does, except that
273
+// a negative value of bits is not supported. bits must be in 0..16. If the
274
+// arguments are invalid, Z_STREAM_ERROR is returned. Otherwise the return
275
+// value from inflate() is returned.
276
+static int inflatePreface(z_stream *strm, int bits, int value) {
277
+ // Check input.
278
+ if (strm == Z_NULL || bits < 0 || bits > 16)
279
+ return Z_STREAM_ERROR;
280
+ if (bits == 0)
281
+ return Z_OK;
282
+ value &= (2 << (bits - 1)) - 1;
283
+
284
+ // An empty dynamic block with an odd number of bits (95). The high bit of
285
+ // the last byte is unused.
286
+ static const unsigned char dyn[] = {
287
+ 4, 0xe0, 0x81, 8, 0, 0, 0, 0, 0x20, 0xa8, 0xab, 0x1f
288
+ };
289
+ const int dynlen = 95; // number of bits in the block
290
+
291
+ // Build an input buffer for inflate that is a multiple of eight bits in
292
+ // length, and that ends with the low bits bits of value.
293
+ unsigned char in[(dynlen + 3 * 10 + 16 + 7) / 8];
294
+ int have = 0;
295
+ if (bits & 1) {
296
+ // Insert an empty dynamic block to get to an odd number of bits, so
297
+ // when bits bits from value are appended, we are at an even number of
298
+ // bits.
299
+ memcpy(in, dyn, sizeof(dyn));
300
+ have = dynlen;
301
+ }
302
+ while ((have + bits) & 7)
303
+ // Insert empty fixed blocks until appending bits bits would put us on
304
+ // a byte boundary. This will insert at most three fixed blocks.
305
+ append_bits(2, 10, in, &have);
306
+
307
+ // Append the bits bits from value, which takes us to a byte boundary.
308
+ append_bits(value, bits, in, &have);
309
+
310
+ // Deliver the input to inflate(). There is no output space provided, but
311
+ // inflate() can't get stuck waiting on output not ingesting all of the
312
+ // provided input. The reason is that there will be at most 16 bits of
313
+ // input from value after the empty deflate blocks (which themselves
314
+ // generate no output). At least ten bits are needed to generate the first
315
+ // output byte from a fixed block. The last two bytes of the buffer have to
316
+ // be ingested in order to get ten bits, which is the most that value can
317
+ // occupy.
318
+ strm->avail_in = have >> 3;
319
+ strm->next_in = in;
320
+ strm->avail_out = 0;
321
+ strm->next_out = in; // not used, but can't be NULL
322
+ return inflate(strm, Z_NO_FLUSH);
323
+}
324
+
325
+#else
326
+# define INFLATEPRIME inflatePrime
327
+#endif
328
+
329
+// See comments in zran.h.
330
+ptrdiff_t deflate_index_extract(FILE *in, struct deflate_index *index,
331
+ off_t offset, unsigned char *buf, size_t len) {
332
+ // Do a quick sanity check on the index.
333
+ if (index == NULL || index->have < 1 || index->list[0].out != 0)
334
+ return Z_STREAM_ERROR;
335
+
336
+ // If nothing to extract, return zero bytes extracted.
337
+ if (len == 0 || offset < 0 || offset >= index->length)
338
+ return 0;
339
+
340
+ // Find the access point closest to but not after offset.
341
+ int lo = -1, hi = index->have;
342
+ point_t *point = index->list;
343
+ while (hi - lo > 1) {
344
+ int mid = (lo + hi) >> 1;
345
+ if (offset < point[mid].out)
346
+ hi = mid;
347
+ else
348
+ lo = mid;
349
+ }
350
+ point += lo;
351
+
352
+ // Initialize the input file and prime the inflate engine to start there.
353
+ int ret = fseeko(in, point->in - (point->bits ? 1 : 0), SEEK_SET);
354
+ if (ret == -1)
355
+ return Z_ERRNO;
356
+ int ch = 0;
357
+ if (point->bits && (ch = getc(in)) == EOF)
358
+ return ferror(in) ? Z_ERRNO : Z_BUF_ERROR;
359
+ z_stream strm = {0};
360
+ ret = inflateInit2(&strm, RAW);
361
+ if (ret != Z_OK)
362
+ return ret;
363
+ if (point->bits)
364
+ INFLATEPRIME(&strm, point->bits, ch >> (8 - point->bits));
365
+ inflateSetDictionary(&strm, point->window, WINSIZE);
366
+
367
+ // Skip uncompressed bytes until offset reached, then satisfy request.
368
+ unsigned char input[CHUNK];
369
+ unsigned char discard[WINSIZE];
370
+ offset -= point->out; // number of bytes to skip to get to offset
371
+ size_t left = len; // number of bytes left to read after offset
372
+ do {
373
+ if (offset) {
374
+ // Discard up to offset uncompressed bytes.
375
+ strm.avail_out = offset < WINSIZE ? (unsigned)offset : WINSIZE;
376
+ strm.next_out = discard;
377
+ }
378
+ else {
379
+ // Uncompress up to left bytes into buf.
380
+ strm.avail_out = left < UINT_MAX ? (unsigned)left : UINT_MAX;
381
+ strm.next_out = buf + len - left;
382
+ }
383
+
384
+ // Uncompress, setting got to the number of bytes uncompressed.
385
+ if (strm.avail_in == 0) {
386
+ // Assure available input.
387
+ strm.avail_in = fread(input, 1, CHUNK, in);
388
+ if (strm.avail_in < CHUNK && ferror(in)) {
389
+ ret = Z_ERRNO;
390
+ break;
391
+ }
392
+ strm.next_in = input;
393
+ }
394
+ unsigned got = strm.avail_out;
395
+ ret = inflate(&strm, Z_NO_FLUSH);
396
+ got -= strm.avail_out;
397
+
398
+ // Update the appropriate count.
399
+ if (offset)
400
+ offset -= got;
401
+ else
402
+ left -= got;
403
+
404
+ // If we're at the end of a gzip member and there's more to read,
405
+ // continue to the next gzip member.
406
+ if (ret == Z_STREAM_END && index->mode == GZIP) {
407
+ // Discard the gzip trailer.
408
+ unsigned drop = 8; // length of gzip trailer
409
+ if (strm.avail_in >= drop) {
410
+ strm.avail_in -= drop;
411
+ strm.next_in += drop;
412
+ }
413
+ else {
414
+ // Read and discard the remainder of the gzip trailer.
415
+ drop -= strm.avail_in;
416
+ strm.avail_in = 0;
417
+ do {
418
+ if (getc(in) == EOF)
419
+ // The input does not have a complete trailer.
420
+ return ferror(in) ? Z_ERRNO : Z_BUF_ERROR;
421
+ } while (--drop);
422
+ }
423
+
424
+ if (strm.avail_in || ungetc(getc(in), in) != EOF) {
425
+ // There's more after the gzip trailer. Use inflate to skip the
426
+ // gzip header and resume the raw inflate there.
427
+ inflateReset2(&strm, GZIP);
428
+ do {
429
+ if (strm.avail_in == 0) {
430
+ strm.avail_in = fread(input, 1, CHUNK, in);
431
+ if (strm.avail_in < CHUNK && ferror(in)) {
432
+ ret = Z_ERRNO;
433
+ break;
434
+ }
435
+ strm.next_in = input;
436
+ }
437
+ strm.avail_out = WINSIZE;
438
+ strm.next_out = discard;
439
+ ret = inflate(&strm, Z_BLOCK); // stop at end of header
440
+ } while (ret == Z_OK && (strm.data_type & 0x80) == 0);
441
+ if (ret != Z_OK)
442
+ break;
443
+ inflateReset2(&strm, RAW);
444
+ }
445
+ }
446
+
447
+ // Continue until we have the requested data, the deflate data has
448
+ // ended, or an error is encountered.
449
+ } while (ret == Z_OK && left);
450
+ inflateEnd(&strm);
451
+
452
+ // Return the number of uncompressed bytes read into buf, or the error.
453
+ return ret == Z_OK || ret == Z_STREAM_END ? len - left : ret;
399454
}
400455
401456
#ifdef TEST
402457
403
-#define SPAN 1048576L /* desired distance between access points */
404
-#define LEN 16384 /* number of bytes to extract */
405
-
406
-/* Demonstrate the use of deflate_index_build() and deflate_index_extract() by
407
- processing the file provided on the command line, and extracting LEN bytes
408
- from 2/3rds of the way through the uncompressed output, writing that to
409
- stdout. An offset can be provided as the second argument, in which case the
410
- data is extracted from there instead. */
411
-int main(int argc, char **argv)
412
-{
413
- int len;
414
- off_t offset = -1;
415
- FILE *in;
416
- struct deflate_index *index = NULL;
417
- unsigned char buf[LEN];
418
-
419
- /* open input file */
420
- if (argc < 2 || argc > 3) {
421
- fprintf(stderr, "usage: zran file.gz [offset]\n");
458
+#define SPAN 1048576L // desired distance between access points
459
+#define LEN 16384 // number of bytes to extract
460
+
461
+// Demonstrate the use of deflate_index_build() and deflate_index_extract() by
462
+// processing the file provided on the command line, and extracting LEN bytes
463
+// from 2/3rds of the way through the uncompressed output, writing that to
464
+// stdout. An offset can be provided as the second argument, in which case the
465
+// data is extracted from there instead.
466
+int main(int argc, char **argv) {
467
+ // Open the input file.
468
+ if (argc < 2 || argc > 3) {
469
+ fprintf(stderr, "usage: zran file.raw [offset]\n");
422470
return 1;
423471
}
424
- in = fopen(argv[1], "rb");
472
+ FILE *in = fopen(argv[1], "rb");
425473
if (in == NULL) {
426474
fprintf(stderr, "zran: could not open %s for reading\n", argv[1]);
427475
return 1;
428476
}
429477
430
- /* get optional offset */
478
+ // Get optional offset.
479
+ off_t offset = -1;
431480
if (argc == 3) {
432481
char *end;
433482
offset = strtoll(argv[2], &end, 10);
434483
if (*end || offset < 0) {
435484
fprintf(stderr, "zran: %s is not a valid offset\n", argv[2]);
436485
return 1;
437486
}
438487
}
439488
440
- /* build index */
441
- len = deflate_index_build(in, SPAN, &index);
489
+ // Build index.
490
+ struct deflate_index *index = NULL;
491
+ int len = deflate_index_build(in, SPAN, &index);
442492
if (len < 0) {
443493
fclose(in);
444494
switch (len) {
445495
case Z_MEM_ERROR:
446496
fprintf(stderr, "zran: out of memory\n");
447497
break;
498
+ case Z_BUF_ERROR:
499
+ fprintf(stderr, "zran: %s ended prematurely\n", argv[1]);
500
+ break;
448501
case Z_DATA_ERROR:
449502
fprintf(stderr, "zran: compressed data error in %s\n", argv[1]);
450503
break;
451504
case Z_ERRNO:
452505
fprintf(stderr, "zran: read error on %s\n", argv[1]);
@@ -456,24 +509,25 @@
456509
}
457510
return 1;
458511
}
459512
fprintf(stderr, "zran: built index with %d access points\n", len);
460513
461
- /* use index by reading some bytes from an arbitrary offset */
514
+ // Use index by reading some bytes from an arbitrary offset.
515
+ unsigned char buf[LEN];
462516
if (offset == -1)
463
- offset = (index->length << 1) / 3;
464
- len = deflate_index_extract(in, index, offset, buf, LEN);
465
- if (len < 0)
517
+ offset = ((index->length + 1) << 1) / 3;
518
+ ptrdiff_t got = deflate_index_extract(in, index, offset, buf, LEN);
519
+ if (got < 0)
466520
fprintf(stderr, "zran: extraction failed: %s error\n",
467
- len == Z_MEM_ERROR ? "out of memory" : "input corrupted");
521
+ got == Z_MEM_ERROR ? "out of memory" : "input corrupted");
468522
else {
469
- fwrite(buf, 1, len, stdout);
470
- fprintf(stderr, "zran: extracted %d bytes at %llu\n", len, offset);
523
+ fwrite(buf, 1, got, stdout);
524
+ fprintf(stderr, "zran: extracted %ld bytes at %lld\n", got, offset);
471525
}
472526
473
- /* clean up and exit */
527
+ // Clean up and exit.
474528
deflate_index_free(index);
475529
fclose(in);
476530
return 0;
477531
}
478532
479533
#endif
480534
--- compat/zlib/examples/zran.c
+++ compat/zlib/examples/zran.c
@@ -1,452 +1,505 @@
1 /* zran.c -- example of zlib/gzip stream indexing and random access
2 * Copyright (C) 2005, 2012, 2018 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 * Version 1.2 14 Oct 2018 Mark Adler */
5
6 /* Version History:
7 1.0 29 May 2005 First version
8 1.1 29 Sep 2012 Fix memory reallocation error
9 1.2 14 Oct 2018 Handle gzip streams with multiple members
10 Add a header file to facilitate usage in applications
11 */
12
13 /* Illustrate the use of Z_BLOCK, inflatePrime(), and inflateSetDictionary()
14 for random access of a compressed file. A file containing a zlib or gzip
15 stream is provided on the command line. The compressed stream is decoded in
16 its entirety, and an index built with access points about every SPAN bytes
17 in the uncompressed output. The compressed file is left open, and can then
18 be read randomly, having to decompress on the average SPAN/2 uncompressed
19 bytes before getting to the desired block of data.
20
21 An access point can be created at the start of any deflate block, by saving
22 the starting file offset and bit of that block, and the 32K bytes of
23 uncompressed data that precede that block. Also the uncompressed offset of
24 that block is saved to provide a reference for locating a desired starting
25 point in the uncompressed stream. deflate_index_build() works by
26 decompressing the input zlib or gzip stream a block at a time, and at the
27 end of each block deciding if enough uncompressed data has gone by to
28 justify the creation of a new access point. If so, that point is saved in a
29 data structure that grows as needed to accommodate the points.
30
31 To use the index, an offset in the uncompressed data is provided, for which
32 the latest access point at or preceding that offset is located in the index.
33 The input file is positioned to the specified location in the index, and if
34 necessary the first few bits of the compressed data is read from the file.
35 inflate is initialized with those bits and the 32K of uncompressed data, and
36 the decompression then proceeds until the desired offset in the file is
37 reached. Then the decompression continues to read the desired uncompressed
38 data from the file.
39
40 Another approach would be to generate the index on demand. In that case,
41 requests for random access reads from the compressed data would try to use
42 the index, but if a read far enough past the end of the index is required,
43 then further index entries would be generated and added.
44
45 There is some fair bit of overhead to starting inflation for the random
46 access, mainly copying the 32K byte dictionary. So if small pieces of the
47 file are being accessed, it would make sense to implement a cache to hold
48 some lookahead and avoid many calls to deflate_index_extract() for small
49 lengths.
50
51 Another way to build an index would be to use inflateCopy(). That would
52 not be constrained to have access points at block boundaries, but requires
53 more memory per access point, and also cannot be saved to file due to the
54 use of pointers in the state. The approach here allows for storage of the
55 index in a file.
56 */
57
58 #include <stdio.h>
59 #include <stdlib.h>
60 #include <string.h>
 
61 #include "zlib.h"
62 #include "zran.h"
63
64 #define WINSIZE 32768U /* sliding window size */
65 #define CHUNK 16384 /* file input buffer size */
66
67 /* Access point entry. */
68 struct point {
69 off_t out; /* corresponding offset in uncompressed data */
70 off_t in; /* offset in input file of first full byte */
71 int bits; /* number of bits (1-7) from byte at in-1, or 0 */
72 unsigned char window[WINSIZE]; /* preceding 32K of uncompressed data */
73 };
74
75 /* See comments in zran.h. */
76 void deflate_index_free(struct deflate_index *index)
77 {
78 if (index != NULL) {
79 free(index->list);
80 free(index);
81 }
82 }
83
84 /* Add an entry to the access point list. If out of memory, deallocate the
85 existing list and return NULL. index->gzip is the allocated size of the
86 index in point entries, until it is time for deflate_index_build() to
87 return, at which point gzip is set to indicate a gzip file or not.
88 */
89 static struct deflate_index *addpoint(struct deflate_index *index, int bits,
90 off_t in, off_t out, unsigned left,
91 unsigned char *window)
92 {
93 struct point *next;
94
95 /* if list is empty, create it (start with eight points) */
96 if (index == NULL) {
 
97 index = malloc(sizeof(struct deflate_index));
98 if (index == NULL) return NULL;
99 index->list = malloc(sizeof(struct point) << 3);
 
 
 
100 if (index->list == NULL) {
101 free(index);
102 return NULL;
103 }
104 index->gzip = 8;
105 index->have = 0;
106 }
107
108 /* if list is full, make it bigger */
109 else if (index->have == index->gzip) {
110 index->gzip <<= 1;
111 next = realloc(index->list, sizeof(struct point) * index->gzip);
112 if (next == NULL) {
113 deflate_index_free(index);
114 return NULL;
115 }
116 index->list = next;
117 }
118
119 /* fill in entry and increment how many we have */
120 next = (struct point *)(index->list) + index->have;
121 next->bits = bits;
122 next->in = in;
 
 
 
123 next->out = out;
 
 
124 if (left)
125 memcpy(next->window, window + WINSIZE - left, left);
126 if (left < WINSIZE)
127 memcpy(next->window + left, window, WINSIZE - left);
128 index->have++;
129
130 /* return list, possibly reallocated */
131 return index;
132 }
133
134 /* See comments in zran.h. */
135 int deflate_index_build(FILE *in, off_t span, struct deflate_index **built)
136 {
137 int ret;
138 int gzip = 0; /* true if reading a gzip file */
139 off_t totin, totout; /* our own total counters to avoid 4GB limit */
140 off_t last; /* totout value of last access point */
141 struct deflate_index *index; /* access points being generated */
142 z_stream strm;
143 unsigned char input[CHUNK];
144 unsigned char window[WINSIZE];
145
146 /* initialize inflate */
147 strm.zalloc = Z_NULL;
148 strm.zfree = Z_NULL;
149 strm.opaque = Z_NULL;
150 strm.avail_in = 0;
151 strm.next_in = Z_NULL;
152 ret = inflateInit2(&strm, 47); /* automatic zlib or gzip decoding */
153 if (ret != Z_OK)
154 return ret;
155
156 /* inflate the input, maintain a sliding window, and build an index -- this
157 also validates the integrity of the compressed data using the check
158 information in the gzip or zlib stream */
159 totin = totout = last = 0;
160 index = NULL; /* will be allocated by first addpoint() */
161 strm.avail_out = 0;
162 do {
163 /* get some compressed data from input file */
164 strm.avail_in = fread(input, 1, CHUNK, in);
165 if (ferror(in)) {
166 ret = Z_ERRNO;
167 goto deflate_index_build_error;
168 }
169 if (strm.avail_in == 0) {
170 ret = Z_DATA_ERROR;
171 goto deflate_index_build_error;
172 }
173 strm.next_in = input;
174
175 /* check for a gzip stream */
176 if (totin == 0 && strm.avail_in >= 3 &&
177 input[0] == 31 && input[1] == 139 && input[2] == 8)
178 gzip = 1;
179
180 /* process all of that, or until end of stream */
181 do {
182 /* reset sliding window if necessary */
183 if (strm.avail_out == 0) {
184 strm.avail_out = WINSIZE;
185 strm.next_out = window;
186 }
187
188 /* inflate until out of input, output, or at end of block --
189 update the total input and output counters */
190 totin += strm.avail_in;
191 totout += strm.avail_out;
192 ret = inflate(&strm, Z_BLOCK); /* return at end of block */
193 totin -= strm.avail_in;
194 totout -= strm.avail_out;
195 if (ret == Z_NEED_DICT)
196 ret = Z_DATA_ERROR;
197 if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR)
198 goto deflate_index_build_error;
199 if (ret == Z_STREAM_END) {
200 if (gzip &&
201 (strm.avail_in || ungetc(getc(in), in) != EOF)) {
202 ret = inflateReset(&strm);
203 if (ret != Z_OK)
204 goto deflate_index_build_error;
205 continue;
206 }
207 break;
208 }
209
210 /* if at end of block, consider adding an index entry (note that if
211 data_type indicates an end-of-block, then all of the
212 uncompressed data from that block has been delivered, and none
213 of the compressed data after that block has been consumed,
214 except for up to seven bits) -- the totout == 0 provides an
215 entry point after the zlib or gzip header, and assures that the
216 index always has at least one access point; we avoid creating an
217 access point after the last block by checking bit 6 of data_type
218 */
219 if ((strm.data_type & 128) && !(strm.data_type & 64) &&
220 (totout == 0 || totout - last > span)) {
221 index = addpoint(index, strm.data_type & 7, totin,
222 totout, strm.avail_out, window);
223 if (index == NULL) {
224 ret = Z_MEM_ERROR;
225 goto deflate_index_build_error;
226 }
227 last = totout;
228 }
229 } while (strm.avail_in != 0);
230 } while (ret != Z_STREAM_END);
231
232 /* clean up and return index (release unused entries in list) */
233 (void)inflateEnd(&strm);
234 index->list = realloc(index->list, sizeof(struct point) * index->have);
235 index->gzip = gzip;
236 index->length = totout;
237 *built = index;
238 return index->have;
239
240 /* return error */
241 deflate_index_build_error:
242 (void)inflateEnd(&strm);
243 deflate_index_free(index);
244 return ret;
245 }
246
247 /* See comments in zran.h. */
248 int deflate_index_extract(FILE *in, struct deflate_index *index, off_t offset,
249 unsigned char *buf, int len)
250 {
251 int ret, skip;
252 z_stream strm;
253 struct point *here;
254 unsigned char input[CHUNK];
255 unsigned char discard[WINSIZE];
256
257 /* proceed only if something reasonable to do */
258 if (len < 0)
259 return 0;
260
261 /* find where in stream to start */
262 here = index->list;
263 ret = index->have;
264 while (--ret && here[1].out <= offset)
265 here++;
266
267 /* initialize file and inflate state to start there */
268 strm.zalloc = Z_NULL;
269 strm.zfree = Z_NULL;
270 strm.opaque = Z_NULL;
271 strm.avail_in = 0;
272 strm.next_in = Z_NULL;
273 ret = inflateInit2(&strm, -15); /* raw inflate */
274 if (ret != Z_OK)
275 return ret;
276 ret = fseeko(in, here->in - (here->bits ? 1 : 0), SEEK_SET);
277 if (ret == -1)
278 goto deflate_index_extract_ret;
279 if (here->bits) {
280 ret = getc(in);
281 if (ret == -1) {
282 ret = ferror(in) ? Z_ERRNO : Z_DATA_ERROR;
283 goto deflate_index_extract_ret;
284 }
285 (void)inflatePrime(&strm, here->bits, ret >> (8 - here->bits));
286 }
287 (void)inflateSetDictionary(&strm, here->window, WINSIZE);
288
289 /* skip uncompressed bytes until offset reached, then satisfy request */
290 offset -= here->out;
291 strm.avail_in = 0;
292 skip = 1; /* while skipping to offset */
293 do {
294 /* define where to put uncompressed data, and how much */
295 if (offset > WINSIZE) { /* skip WINSIZE bytes */
296 strm.avail_out = WINSIZE;
297 strm.next_out = discard;
298 offset -= WINSIZE;
299 }
300 else if (offset > 0) { /* last skip */
301 strm.avail_out = (unsigned)offset;
302 strm.next_out = discard;
303 offset = 0;
304 }
305 else if (skip) { /* at offset now */
306 strm.avail_out = len;
307 strm.next_out = buf;
308 skip = 0; /* only do this once */
309 }
310
311 /* uncompress until avail_out filled, or end of stream */
312 do {
313 if (strm.avail_in == 0) {
314 strm.avail_in = fread(input, 1, CHUNK, in);
315 if (ferror(in)) {
316 ret = Z_ERRNO;
317 goto deflate_index_extract_ret;
318 }
319 if (strm.avail_in == 0) {
320 ret = Z_DATA_ERROR;
321 goto deflate_index_extract_ret;
322 }
323 strm.next_in = input;
324 }
325 ret = inflate(&strm, Z_NO_FLUSH); /* normal inflate */
326 if (ret == Z_NEED_DICT)
327 ret = Z_DATA_ERROR;
328 if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR)
329 goto deflate_index_extract_ret;
330 if (ret == Z_STREAM_END) {
331 /* the raw deflate stream has ended */
332 if (index->gzip == 0)
333 /* this is a zlib stream that has ended -- done */
334 break;
335
336 /* near the end of a gzip member, which might be followed by
337 another gzip member -- skip the gzip trailer and see if
338 there is more input after it */
339 if (strm.avail_in < 8) {
340 fseeko(in, 8 - strm.avail_in, SEEK_CUR);
341 strm.avail_in = 0;
342 }
343 else {
344 strm.avail_in -= 8;
345 strm.next_in += 8;
346 }
347 if (strm.avail_in == 0 && ungetc(getc(in), in) == EOF)
348 /* the input ended after the gzip trailer -- done */
349 break;
350
351 /* there is more input, so another gzip member should follow --
352 validate and skip the gzip header */
353 ret = inflateReset2(&strm, 31);
354 if (ret != Z_OK)
355 goto deflate_index_extract_ret;
356 do {
357 if (strm.avail_in == 0) {
358 strm.avail_in = fread(input, 1, CHUNK, in);
359 if (ferror(in)) {
360 ret = Z_ERRNO;
361 goto deflate_index_extract_ret;
362 }
363 if (strm.avail_in == 0) {
364 ret = Z_DATA_ERROR;
365 goto deflate_index_extract_ret;
366 }
367 strm.next_in = input;
368 }
369 ret = inflate(&strm, Z_BLOCK);
370 if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR)
371 goto deflate_index_extract_ret;
372 } while ((strm.data_type & 128) == 0);
373
374 /* set up to continue decompression of the raw deflate stream
375 that follows the gzip header */
376 ret = inflateReset2(&strm, -15);
377 if (ret != Z_OK)
378 goto deflate_index_extract_ret;
379 }
380
381 /* continue to process the available input before reading more */
382 } while (strm.avail_out != 0);
383
384 if (ret == Z_STREAM_END)
385 /* reached the end of the compressed data -- return the data that
386 was available, possibly less than requested */
387 break;
388
389 /* do until offset reached and requested data read */
390 } while (skip);
391
392 /* compute the number of uncompressed bytes read after the offset */
393 ret = skip ? 0 : len - strm.avail_out;
394
395 /* clean up and return the bytes read, or the negative error */
396 deflate_index_extract_ret:
397 (void)inflateEnd(&strm);
398 return ret;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399 }
400
401 #ifdef TEST
402
403 #define SPAN 1048576L /* desired distance between access points */
404 #define LEN 16384 /* number of bytes to extract */
405
406 /* Demonstrate the use of deflate_index_build() and deflate_index_extract() by
407 processing the file provided on the command line, and extracting LEN bytes
408 from 2/3rds of the way through the uncompressed output, writing that to
409 stdout. An offset can be provided as the second argument, in which case the
410 data is extracted from there instead. */
411 int main(int argc, char **argv)
412 {
413 int len;
414 off_t offset = -1;
415 FILE *in;
416 struct deflate_index *index = NULL;
417 unsigned char buf[LEN];
418
419 /* open input file */
420 if (argc < 2 || argc > 3) {
421 fprintf(stderr, "usage: zran file.gz [offset]\n");
422 return 1;
423 }
424 in = fopen(argv[1], "rb");
425 if (in == NULL) {
426 fprintf(stderr, "zran: could not open %s for reading\n", argv[1]);
427 return 1;
428 }
429
430 /* get optional offset */
 
431 if (argc == 3) {
432 char *end;
433 offset = strtoll(argv[2], &end, 10);
434 if (*end || offset < 0) {
435 fprintf(stderr, "zran: %s is not a valid offset\n", argv[2]);
436 return 1;
437 }
438 }
439
440 /* build index */
441 len = deflate_index_build(in, SPAN, &index);
 
442 if (len < 0) {
443 fclose(in);
444 switch (len) {
445 case Z_MEM_ERROR:
446 fprintf(stderr, "zran: out of memory\n");
447 break;
 
 
 
448 case Z_DATA_ERROR:
449 fprintf(stderr, "zran: compressed data error in %s\n", argv[1]);
450 break;
451 case Z_ERRNO:
452 fprintf(stderr, "zran: read error on %s\n", argv[1]);
@@ -456,24 +509,25 @@
456 }
457 return 1;
458 }
459 fprintf(stderr, "zran: built index with %d access points\n", len);
460
461 /* use index by reading some bytes from an arbitrary offset */
 
462 if (offset == -1)
463 offset = (index->length << 1) / 3;
464 len = deflate_index_extract(in, index, offset, buf, LEN);
465 if (len < 0)
466 fprintf(stderr, "zran: extraction failed: %s error\n",
467 len == Z_MEM_ERROR ? "out of memory" : "input corrupted");
468 else {
469 fwrite(buf, 1, len, stdout);
470 fprintf(stderr, "zran: extracted %d bytes at %llu\n", len, offset);
471 }
472
473 /* clean up and exit */
474 deflate_index_free(index);
475 fclose(in);
476 return 0;
477 }
478
479 #endif
480
--- compat/zlib/examples/zran.c
+++ compat/zlib/examples/zran.c
@@ -1,452 +1,505 @@
1 /* zran.c -- example of deflate stream indexing and random access
2 * Copyright (C) 2005, 2012, 2018, 2023 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 * Version 1.4 13 Apr 2023 Mark Adler */
5
6 /* Version History:
7 1.0 29 May 2005 First version
8 1.1 29 Sep 2012 Fix memory reallocation error
9 1.2 14 Oct 2018 Handle gzip streams with multiple members
10 Add a header file to facilitate usage in applications
11 1.3 18 Feb 2023 Permit raw deflate streams as well as zlib and gzip
12 Permit crossing gzip member boundaries when extracting
13 Support a size_t size when extracting (was an int)
14 Do a binary search over the index for an access point
15 Expose the access point type to enable save and load
16 1.4 13 Apr 2023 Add a NOPRIME define to not use inflatePrime()
17 */
18
19 // Illustrate the use of Z_BLOCK, inflatePrime(), and inflateSetDictionary()
20 // for random access of a compressed file. A file containing a raw deflate
21 // stream is provided on the command line. The compressed stream is decoded in
22 // its entirety, and an index built with access points about every SPAN bytes
23 // in the uncompressed output. The compressed file is left open, and can then
24 // be read randomly, having to decompress on the average SPAN/2 uncompressed
25 // bytes before getting to the desired block of data.
26 //
27 // An access point can be created at the start of any deflate block, by saving
28 // the starting file offset and bit of that block, and the 32K bytes of
29 // uncompressed data that precede that block. Also the uncompressed offset of
30 // that block is saved to provide a reference for locating a desired starting
31 // point in the uncompressed stream. deflate_index_build() decompresses the
32 // input raw deflate stream a block at a time, and at the end of each block
33 // decides if enough uncompressed data has gone by to justify the creation of a
34 // new access point. If so, that point is saved in a data structure that grows
35 // as needed to accommodate the points.
36 //
37 // To use the index, an offset in the uncompressed data is provided, for which
38 // the latest access point at or preceding that offset is located in the index.
39 // The input file is positioned to the specified location in the index, and if
40 // necessary the first few bits of the compressed data is read from the file.
41 // inflate is initialized with those bits and the 32K of uncompressed data, and
42 // decompression then proceeds until the desired offset in the file is reached.
43 // Then decompression continues to read the requested uncompressed data from
44 // the file.
45 //
46 // There is some fair bit of overhead to starting inflation for the random
47 // access, mainly copying the 32K byte dictionary. If small pieces of the file
48 // are being accessed, it would make sense to implement a cache to hold some
49 // lookahead to avoid many calls to deflate_index_extract() for small lengths.
50 //
51 // Another way to build an index would be to use inflateCopy(). That would not
52 // be constrained to have access points at block boundaries, but would require
53 // more memory per access point, and could not be saved to a file due to the
54 // use of pointers in the state. The approach here allows for storage of the
55 // index in a file.
 
56
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <string.h>
60 #include <limits.h>
61 #include "zlib.h"
62 #include "zran.h"
63
64 #define WINSIZE 32768U // sliding window size
65 #define CHUNK 16384 // file input buffer size
66
67 // See comments in zran.h.
68 void deflate_index_free(struct deflate_index *index) {
 
 
 
 
 
 
 
 
 
69 if (index != NULL) {
70 free(index->list);
71 free(index);
72 }
73 }
74
75 // Add an access point to the list. If out of memory, deallocate the existing
76 // list and return NULL. index->mode is temporarily the allocated number of
77 // access points, until it is time for deflate_index_build() to return. Then
78 // index->mode is set to the mode of inflation.
79 static struct deflate_index *add_point(struct deflate_index *index, int bits,
80 off_t in, off_t out, unsigned left,
81 unsigned char *window) {
 
 
 
 
 
82 if (index == NULL) {
83 // The list is empty. Create it, starting with eight access points.
84 index = malloc(sizeof(struct deflate_index));
85 if (index == NULL)
86 return NULL;
87 index->have = 0;
88 index->mode = 8;
89 index->list = malloc(sizeof(point_t) * index->mode);
90 if (index->list == NULL) {
91 free(index);
92 return NULL;
93 }
 
 
94 }
95
96 else if (index->have == index->mode) {
97 // The list is full. Make it bigger.
98 index->mode <<= 1;
99 point_t *next = realloc(index->list, sizeof(point_t) * index->mode);
100 if (next == NULL) {
101 deflate_index_free(index);
102 return NULL;
103 }
104 index->list = next;
105 }
106
107 // Fill in the access point and increment how many we have.
108 point_t *next = (point_t *)(index->list) + index->have++;
109 if (index->have < 0) {
110 // Overflowed the int!
111 deflate_index_free(index);
112 return NULL;
113 }
114 next->out = out;
115 next->in = in;
116 next->bits = bits;
117 if (left)
118 memcpy(next->window, window + WINSIZE - left, left);
119 if (left < WINSIZE)
120 memcpy(next->window + left, window, WINSIZE - left);
 
121
122 // Return the index, which may have been newly allocated or destroyed.
123 return index;
124 }
125
126 // Decompression modes. These are the inflateInit2() windowBits parameter.
127 #define RAW -15
128 #define ZLIB 15
129 #define GZIP 31
130
131 // See comments in zran.h.
132 int deflate_index_build(FILE *in, off_t span, struct deflate_index **built) {
133 // Set up inflation state.
134 z_stream strm = {0}; // inflate engine (gets fired up later)
135 unsigned char buf[CHUNK]; // input buffer
136 unsigned char win[WINSIZE] = {0}; // output sliding window
137 off_t totin = 0; // total bytes read from input
138 off_t totout = 0; // total bytes uncompressed
139 int mode = 0; // mode: RAW, ZLIB, or GZIP (0 => not set yet)
140
141 // Decompress from in, generating access points along the way.
142 int ret; // the return value from zlib, or Z_ERRNO
143 off_t last; // last access point uncompressed offset
144 struct deflate_index *index = NULL; // list of access points
145 do {
146 // Assure available input, at least until reaching EOF.
147 if (strm.avail_in == 0) {
148 strm.avail_in = fread(buf, 1, sizeof(buf), in);
149 totin += strm.avail_in;
150 strm.next_in = buf;
151 if (strm.avail_in < sizeof(buf) && ferror(in)) {
152 ret = Z_ERRNO;
153 break;
154 }
155
156 if (mode == 0) {
157 // At the start of the input -- determine the type. Assume raw
158 // if it is neither zlib nor gzip. This could in theory result
159 // in a false positive for zlib, but in practice the fill bits
160 // after a stored block are always zeros, so a raw stream won't
161 // start with an 8 in the low nybble.
162 mode = strm.avail_in == 0 ? RAW : // empty -- will fail
163 (strm.next_in[0] & 0xf) == 8 ? ZLIB :
164 strm.next_in[0] == 0x1f ? GZIP :
165 /* else */ RAW;
166 ret = inflateInit2(&strm, mode);
167 if (ret != Z_OK)
168 break;
169 }
170 }
171
172 // Assure available output. This rotates the output through, for use as
173 // a sliding window on the uncompressed data.
174 if (strm.avail_out == 0) {
175 strm.avail_out = sizeof(win);
176 strm.next_out = win;
177 }
178
179 if (mode == RAW && index == NULL)
180 // We skip the inflate() call at the start of raw deflate data in
181 // order generate an access point there. Set data_type to imitate
182 // the end of a header.
183 strm.data_type = 0x80;
184 else {
185 // Inflate and update the number of uncompressed bytes.
186 unsigned before = strm.avail_out;
187 ret = inflate(&strm, Z_BLOCK);
188 totout += before - strm.avail_out;
189 }
190
191 if ((strm.data_type & 0xc0) == 0x80 &&
192 (index == NULL || totout - last >= span)) {
193 // We are at the end of a header or a non-last deflate block, so we
194 // can add an access point here. Furthermore, we are either at the
195 // very start for the first access point, or there has been span or
196 // more uncompressed bytes since the last access point, so we want
197 // to add an access point here.
198 index = add_point(index, strm.data_type & 7, totin - strm.avail_in,
199 totout, strm.avail_out, win);
200 if (index == NULL) {
201 ret = Z_MEM_ERROR;
202 break;
203 }
204 last = totout;
205 }
206
207 if (ret == Z_STREAM_END && mode == GZIP &&
208 (strm.avail_in || ungetc(getc(in), in) != EOF))
209 // There is more input after the end of a gzip member. Reset the
210 // inflate state to read another gzip member. On success, this will
211 // set ret to Z_OK to continue decompressing.
212 ret = inflateReset2(&strm, GZIP);
213
214 // Keep going until Z_STREAM_END or error. If the compressed data ends
215 // prematurely without a file read error, Z_BUF_ERROR is returned.
216 } while (ret == Z_OK);
217 inflateEnd(&strm);
218
219 if (ret != Z_STREAM_END) {
220 // An error was encountered. Discard the index and return a negative
221 // error code.
222 deflate_index_free(index);
223 return ret == Z_NEED_DICT ? Z_DATA_ERROR : ret;
224 }
225
226 // Shrink the index to only the occupied access points and return it.
227 index->mode = mode;
228 index->length = totout;
229 point_t *list = realloc(index->list, sizeof(point_t) * index->have);
230 if (list == NULL) {
231 // Seems like a realloc() to make something smaller should always work,
232 // but just in case.
233 deflate_index_free(index);
234 return Z_MEM_ERROR;
235 }
236 index->list = list;
237 *built = index;
238 return index->have;
239 }
240
241 #ifdef NOPRIME
242 // Support zlib versions before 1.2.3 (July 2005), or incomplete zlib clones
243 // that do not have inflatePrime().
244
245 # define INFLATEPRIME inflatePreface
246
247 // Append the low bits bits of value to in[] at bit position *have, updating
248 // *have. value must be zero above its low bits bits. bits must be positive.
249 // This assumes that any bits above the *have bits in the last byte are zeros.
250 // That assumption is preserved on return, as any bits above *have + bits in
251 // the last byte written will be set to zeros.
252 static inline void append_bits(unsigned value, int bits,
253 unsigned char *in, int *have) {
254 in += *have >> 3; // where the first bits from value will go
255 int k = *have & 7; // the number of bits already there
256 *have += bits;
257 if (k)
258 *in |= value << k; // write value above the low k bits
259 else
260 *in = value;
261 k = 8 - k; // the number of bits just appended
262 while (bits > k) {
263 value >>= k; // drop the bits appended
264 bits -= k;
265 k = 8; // now at a byte boundary
266 *++in = value;
267 }
268 }
269
270 // Insert enough bits in the form of empty deflate blocks in front of the the
271 // low bits bits of value, in order to bring the sequence to a byte boundary.
272 // Then feed that to inflate(). This does what inflatePrime() does, except that
273 // a negative value of bits is not supported. bits must be in 0..16. If the
274 // arguments are invalid, Z_STREAM_ERROR is returned. Otherwise the return
275 // value from inflate() is returned.
276 static int inflatePreface(z_stream *strm, int bits, int value) {
277 // Check input.
278 if (strm == Z_NULL || bits < 0 || bits > 16)
279 return Z_STREAM_ERROR;
280 if (bits == 0)
281 return Z_OK;
282 value &= (2 << (bits - 1)) - 1;
283
284 // An empty dynamic block with an odd number of bits (95). The high bit of
285 // the last byte is unused.
286 static const unsigned char dyn[] = {
287 4, 0xe0, 0x81, 8, 0, 0, 0, 0, 0x20, 0xa8, 0xab, 0x1f
288 };
289 const int dynlen = 95; // number of bits in the block
290
291 // Build an input buffer for inflate that is a multiple of eight bits in
292 // length, and that ends with the low bits bits of value.
293 unsigned char in[(dynlen + 3 * 10 + 16 + 7) / 8];
294 int have = 0;
295 if (bits & 1) {
296 // Insert an empty dynamic block to get to an odd number of bits, so
297 // when bits bits from value are appended, we are at an even number of
298 // bits.
299 memcpy(in, dyn, sizeof(dyn));
300 have = dynlen;
301 }
302 while ((have + bits) & 7)
303 // Insert empty fixed blocks until appending bits bits would put us on
304 // a byte boundary. This will insert at most three fixed blocks.
305 append_bits(2, 10, in, &have);
306
307 // Append the bits bits from value, which takes us to a byte boundary.
308 append_bits(value, bits, in, &have);
309
310 // Deliver the input to inflate(). There is no output space provided, but
311 // inflate() can't get stuck waiting on output not ingesting all of the
312 // provided input. The reason is that there will be at most 16 bits of
313 // input from value after the empty deflate blocks (which themselves
314 // generate no output). At least ten bits are needed to generate the first
315 // output byte from a fixed block. The last two bytes of the buffer have to
316 // be ingested in order to get ten bits, which is the most that value can
317 // occupy.
318 strm->avail_in = have >> 3;
319 strm->next_in = in;
320 strm->avail_out = 0;
321 strm->next_out = in; // not used, but can't be NULL
322 return inflate(strm, Z_NO_FLUSH);
323 }
324
325 #else
326 # define INFLATEPRIME inflatePrime
327 #endif
328
329 // See comments in zran.h.
330 ptrdiff_t deflate_index_extract(FILE *in, struct deflate_index *index,
331 off_t offset, unsigned char *buf, size_t len) {
332 // Do a quick sanity check on the index.
333 if (index == NULL || index->have < 1 || index->list[0].out != 0)
334 return Z_STREAM_ERROR;
335
336 // If nothing to extract, return zero bytes extracted.
337 if (len == 0 || offset < 0 || offset >= index->length)
338 return 0;
339
340 // Find the access point closest to but not after offset.
341 int lo = -1, hi = index->have;
342 point_t *point = index->list;
343 while (hi - lo > 1) {
344 int mid = (lo + hi) >> 1;
345 if (offset < point[mid].out)
346 hi = mid;
347 else
348 lo = mid;
349 }
350 point += lo;
351
352 // Initialize the input file and prime the inflate engine to start there.
353 int ret = fseeko(in, point->in - (point->bits ? 1 : 0), SEEK_SET);
354 if (ret == -1)
355 return Z_ERRNO;
356 int ch = 0;
357 if (point->bits && (ch = getc(in)) == EOF)
358 return ferror(in) ? Z_ERRNO : Z_BUF_ERROR;
359 z_stream strm = {0};
360 ret = inflateInit2(&strm, RAW);
361 if (ret != Z_OK)
362 return ret;
363 if (point->bits)
364 INFLATEPRIME(&strm, point->bits, ch >> (8 - point->bits));
365 inflateSetDictionary(&strm, point->window, WINSIZE);
366
367 // Skip uncompressed bytes until offset reached, then satisfy request.
368 unsigned char input[CHUNK];
369 unsigned char discard[WINSIZE];
370 offset -= point->out; // number of bytes to skip to get to offset
371 size_t left = len; // number of bytes left to read after offset
372 do {
373 if (offset) {
374 // Discard up to offset uncompressed bytes.
375 strm.avail_out = offset < WINSIZE ? (unsigned)offset : WINSIZE;
376 strm.next_out = discard;
377 }
378 else {
379 // Uncompress up to left bytes into buf.
380 strm.avail_out = left < UINT_MAX ? (unsigned)left : UINT_MAX;
381 strm.next_out = buf + len - left;
382 }
383
384 // Uncompress, setting got to the number of bytes uncompressed.
385 if (strm.avail_in == 0) {
386 // Assure available input.
387 strm.avail_in = fread(input, 1, CHUNK, in);
388 if (strm.avail_in < CHUNK && ferror(in)) {
389 ret = Z_ERRNO;
390 break;
391 }
392 strm.next_in = input;
393 }
394 unsigned got = strm.avail_out;
395 ret = inflate(&strm, Z_NO_FLUSH);
396 got -= strm.avail_out;
397
398 // Update the appropriate count.
399 if (offset)
400 offset -= got;
401 else
402 left -= got;
403
404 // If we're at the end of a gzip member and there's more to read,
405 // continue to the next gzip member.
406 if (ret == Z_STREAM_END && index->mode == GZIP) {
407 // Discard the gzip trailer.
408 unsigned drop = 8; // length of gzip trailer
409 if (strm.avail_in >= drop) {
410 strm.avail_in -= drop;
411 strm.next_in += drop;
412 }
413 else {
414 // Read and discard the remainder of the gzip trailer.
415 drop -= strm.avail_in;
416 strm.avail_in = 0;
417 do {
418 if (getc(in) == EOF)
419 // The input does not have a complete trailer.
420 return ferror(in) ? Z_ERRNO : Z_BUF_ERROR;
421 } while (--drop);
422 }
423
424 if (strm.avail_in || ungetc(getc(in), in) != EOF) {
425 // There's more after the gzip trailer. Use inflate to skip the
426 // gzip header and resume the raw inflate there.
427 inflateReset2(&strm, GZIP);
428 do {
429 if (strm.avail_in == 0) {
430 strm.avail_in = fread(input, 1, CHUNK, in);
431 if (strm.avail_in < CHUNK && ferror(in)) {
432 ret = Z_ERRNO;
433 break;
434 }
435 strm.next_in = input;
436 }
437 strm.avail_out = WINSIZE;
438 strm.next_out = discard;
439 ret = inflate(&strm, Z_BLOCK); // stop at end of header
440 } while (ret == Z_OK && (strm.data_type & 0x80) == 0);
441 if (ret != Z_OK)
442 break;
443 inflateReset2(&strm, RAW);
444 }
445 }
446
447 // Continue until we have the requested data, the deflate data has
448 // ended, or an error is encountered.
449 } while (ret == Z_OK && left);
450 inflateEnd(&strm);
451
452 // Return the number of uncompressed bytes read into buf, or the error.
453 return ret == Z_OK || ret == Z_STREAM_END ? len - left : ret;
454 }
455
456 #ifdef TEST
457
458 #define SPAN 1048576L // desired distance between access points
459 #define LEN 16384 // number of bytes to extract
460
461 // Demonstrate the use of deflate_index_build() and deflate_index_extract() by
462 // processing the file provided on the command line, and extracting LEN bytes
463 // from 2/3rds of the way through the uncompressed output, writing that to
464 // stdout. An offset can be provided as the second argument, in which case the
465 // data is extracted from there instead.
466 int main(int argc, char **argv) {
467 // Open the input file.
468 if (argc < 2 || argc > 3) {
469 fprintf(stderr, "usage: zran file.raw [offset]\n");
 
 
 
 
 
 
 
470 return 1;
471 }
472 FILE *in = fopen(argv[1], "rb");
473 if (in == NULL) {
474 fprintf(stderr, "zran: could not open %s for reading\n", argv[1]);
475 return 1;
476 }
477
478 // Get optional offset.
479 off_t offset = -1;
480 if (argc == 3) {
481 char *end;
482 offset = strtoll(argv[2], &end, 10);
483 if (*end || offset < 0) {
484 fprintf(stderr, "zran: %s is not a valid offset\n", argv[2]);
485 return 1;
486 }
487 }
488
489 // Build index.
490 struct deflate_index *index = NULL;
491 int len = deflate_index_build(in, SPAN, &index);
492 if (len < 0) {
493 fclose(in);
494 switch (len) {
495 case Z_MEM_ERROR:
496 fprintf(stderr, "zran: out of memory\n");
497 break;
498 case Z_BUF_ERROR:
499 fprintf(stderr, "zran: %s ended prematurely\n", argv[1]);
500 break;
501 case Z_DATA_ERROR:
502 fprintf(stderr, "zran: compressed data error in %s\n", argv[1]);
503 break;
504 case Z_ERRNO:
505 fprintf(stderr, "zran: read error on %s\n", argv[1]);
@@ -456,24 +509,25 @@
509 }
510 return 1;
511 }
512 fprintf(stderr, "zran: built index with %d access points\n", len);
513
514 // Use index by reading some bytes from an arbitrary offset.
515 unsigned char buf[LEN];
516 if (offset == -1)
517 offset = ((index->length + 1) << 1) / 3;
518 ptrdiff_t got = deflate_index_extract(in, index, offset, buf, LEN);
519 if (got < 0)
520 fprintf(stderr, "zran: extraction failed: %s error\n",
521 got == Z_MEM_ERROR ? "out of memory" : "input corrupted");
522 else {
523 fwrite(buf, 1, got, stdout);
524 fprintf(stderr, "zran: extracted %ld bytes at %lld\n", got, offset);
525 }
526
527 // Clean up and exit.
528 deflate_index_free(index);
529 fclose(in);
530 return 0;
531 }
532
533 #endif
534
--- compat/zlib/examples/zran.h
+++ compat/zlib/examples/zran.h
@@ -1,40 +1,51 @@
1
-/* zran.h -- example of zlib/gzip stream indexing and random access
2
- * Copyright (C) 2005, 2012, 2018 Mark Adler
1
+/* zran.h -- example of deflated stream indexing and random access
2
+ * Copyright (C) 2005, 2012, 2018, 2023 Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
4
- * Version 1.2 14 Oct 2018 Mark Adler */
4
+ * Version 1.3 18 Feb 2023 Mark Adler */
55
66
#include <stdio.h>
77
#include "zlib.h"
88
9
-/* Access point list. */
9
+// Access point.
10
+typedef struct point {
11
+ off_t out; // offset in uncompressed data
12
+ off_t in; // offset in compressed file of first full byte
13
+ int bits; // 0, or number of bits (1-7) from byte at in-1
14
+ unsigned char window[32768]; // preceding 32K of uncompressed data
15
+} point_t;
16
+
17
+// Access point list.
1018
struct deflate_index {
11
- int have; /* number of list entries */
12
- int gzip; /* 1 if the index is of a gzip file, 0 if it is of a
13
- zlib stream */
14
- off_t length; /* total length of uncompressed data */
15
- void *list; /* allocated list of entries */
19
+ int have; // number of access points in list
20
+ int mode; // -15 for raw, 15 for zlib, or 31 for gzip
21
+ off_t length; // total length of uncompressed data
22
+ point_t *list; // allocated list of access points
1623
};
1724
18
-/* Make one entire pass through a zlib or gzip compressed stream and build an
19
- index, with access points about every span bytes of uncompressed output.
20
- gzip files with multiple members are indexed in their entirety. span should
21
- be chosen to balance the speed of random access against the memory
22
- requirements of the list, about 32K bytes per access point. The return value
23
- is the number of access points on success (>= 1), Z_MEM_ERROR for out of
24
- memory, Z_DATA_ERROR for an error in the input file, or Z_ERRNO for a file
25
- read error. On success, *built points to the resulting index. */
25
+// Make one pass through a zlib, gzip, or raw deflate compressed stream and
26
+// build an index, with access points about every span bytes of uncompressed
27
+// output. gzip files with multiple members are fully indexed. span should be
28
+// chosen to balance the speed of random access against the memory requirements
29
+// of the list, which is about 32K bytes per access point. The return value is
30
+// the number of access points on success (>= 1), Z_MEM_ERROR for out of
31
+// memory, Z_BUF_ERROR for a premature end of input, Z_DATA_ERROR for a format
32
+// or verification error in the input file, or Z_ERRNO for a file read error.
33
+// On success, *built points to the resulting index.
2634
int deflate_index_build(FILE *in, off_t span, struct deflate_index **built);
2735
28
-/* Deallocate an index built by deflate_index_build() */
29
-void deflate_index_free(struct deflate_index *index);
30
-
31
-/* Use the index to read len bytes from offset into buf. Return bytes read or
32
- negative for error (Z_DATA_ERROR or Z_MEM_ERROR). If data is requested past
33
- the end of the uncompressed data, then deflate_index_extract() will return a
34
- value less than len, indicating how much was actually read into buf. This
35
- function should not return a data error unless the file was modified since
36
- the index was generated, since deflate_index_build() validated all of the
37
- input. deflate_index_extract() will return Z_ERRNO if there is an error on
38
- reading or seeking the input file. */
39
-int deflate_index_extract(FILE *in, struct deflate_index *index, off_t offset,
40
- unsigned char *buf, int len);
36
+// Use the index to read len bytes from offset into buf. Return the number of
37
+// bytes read or a negative error code. If data is requested past the end of
38
+// the uncompressed data, then deflate_index_extract() will return a value less
39
+// than len, indicating how much was actually read into buf. If given a valid
40
+// index, this function should not return an error unless the file was modified
41
+// somehow since the index was generated, given that deflate_index_build() had
42
+// validated all of the input. If nevertheless there is a failure, Z_BUF_ERROR
43
+// is returned if the compressed data ends prematurely, Z_DATA_ERROR if the
44
+// deflate compressed data is not valid, Z_MEM_ERROR if out of memory,
45
+// Z_STREAM_ERROR if the index is not valid, or Z_ERRNO if there is an error
46
+// reading or seeking on the input file.
47
+ptrdiff_t deflate_index_extract(FILE *in, struct deflate_index *index,
48
+ off_t offset, unsigned char *buf, size_t len);
49
+
50
+// Deallocate an index built by deflate_index_build().
51
+void deflate_index_free(struct deflate_index *index);
4152
--- compat/zlib/examples/zran.h
+++ compat/zlib/examples/zran.h
@@ -1,40 +1,51 @@
1 /* zran.h -- example of zlib/gzip stream indexing and random access
2 * Copyright (C) 2005, 2012, 2018 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 * Version 1.2 14 Oct 2018 Mark Adler */
5
6 #include <stdio.h>
7 #include "zlib.h"
8
9 /* Access point list. */
 
 
 
 
 
 
 
 
10 struct deflate_index {
11 int have; /* number of list entries */
12 int gzip; /* 1 if the index is of a gzip file, 0 if it is of a
13 zlib stream */
14 off_t length; /* total length of uncompressed data */
15 void *list; /* allocated list of entries */
16 };
17
18 /* Make one entire pass through a zlib or gzip compressed stream and build an
19 index, with access points about every span bytes of uncompressed output.
20 gzip files with multiple members are indexed in their entirety. span should
21 be chosen to balance the speed of random access against the memory
22 requirements of the list, about 32K bytes per access point. The return value
23 is the number of access points on success (>= 1), Z_MEM_ERROR for out of
24 memory, Z_DATA_ERROR for an error in the input file, or Z_ERRNO for a file
25 read error. On success, *built points to the resulting index. */
 
26 int deflate_index_build(FILE *in, off_t span, struct deflate_index **built);
27
28 /* Deallocate an index built by deflate_index_build() */
29 void deflate_index_free(struct deflate_index *index);
30
31 /* Use the index to read len bytes from offset into buf. Return bytes read or
32 negative for error (Z_DATA_ERROR or Z_MEM_ERROR). If data is requested past
33 the end of the uncompressed data, then deflate_index_extract() will return a
34 value less than len, indicating how much was actually read into buf. This
35 function should not return a data error unless the file was modified since
36 the index was generated, since deflate_index_build() validated all of the
37 input. deflate_index_extract() will return Z_ERRNO if there is an error on
38 reading or seeking the input file. */
39 int deflate_index_extract(FILE *in, struct deflate_index *index, off_t offset,
40 unsigned char *buf, int len);
 
 
 
41
--- compat/zlib/examples/zran.h
+++ compat/zlib/examples/zran.h
@@ -1,40 +1,51 @@
1 /* zran.h -- example of deflated stream indexing and random access
2 * Copyright (C) 2005, 2012, 2018, 2023 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 * Version 1.3 18 Feb 2023 Mark Adler */
5
6 #include <stdio.h>
7 #include "zlib.h"
8
9 // Access point.
10 typedef struct point {
11 off_t out; // offset in uncompressed data
12 off_t in; // offset in compressed file of first full byte
13 int bits; // 0, or number of bits (1-7) from byte at in-1
14 unsigned char window[32768]; // preceding 32K of uncompressed data
15 } point_t;
16
17 // Access point list.
18 struct deflate_index {
19 int have; // number of access points in list
20 int mode; // -15 for raw, 15 for zlib, or 31 for gzip
21 off_t length; // total length of uncompressed data
22 point_t *list; // allocated list of access points
 
23 };
24
25 // Make one pass through a zlib, gzip, or raw deflate compressed stream and
26 // build an index, with access points about every span bytes of uncompressed
27 // output. gzip files with multiple members are fully indexed. span should be
28 // chosen to balance the speed of random access against the memory requirements
29 // of the list, which is about 32K bytes per access point. The return value is
30 // the number of access points on success (>= 1), Z_MEM_ERROR for out of
31 // memory, Z_BUF_ERROR for a premature end of input, Z_DATA_ERROR for a format
32 // or verification error in the input file, or Z_ERRNO for a file read error.
33 // On success, *built points to the resulting index.
34 int deflate_index_build(FILE *in, off_t span, struct deflate_index **built);
35
36 // Use the index to read len bytes from offset into buf. Return the number of
37 // bytes read or a negative error code. If data is requested past the end of
38 // the uncompressed data, then deflate_index_extract() will return a value less
39 // than len, indicating how much was actually read into buf. If given a valid
40 // index, this function should not return an error unless the file was modified
41 // somehow since the index was generated, given that deflate_index_build() had
42 // validated all of the input. If nevertheless there is a failure, Z_BUF_ERROR
43 // is returned if the compressed data ends prematurely, Z_DATA_ERROR if the
44 // deflate compressed data is not valid, Z_MEM_ERROR if out of memory,
45 // Z_STREAM_ERROR if the index is not valid, or Z_ERRNO if there is an error
46 // reading or seeking on the input file.
47 ptrdiff_t deflate_index_extract(FILE *in, struct deflate_index *index,
48 off_t offset, unsigned char *buf, size_t len);
49
50 // Deallocate an index built by deflate_index_build().
51 void deflate_index_free(struct deflate_index *index);
52
--- compat/zlib/gzclose.c
+++ compat/zlib/gzclose.c
@@ -6,13 +6,11 @@
66
#include "gzguts.h"
77
88
/* gzclose() is in a separate file so that it is linked in only if it is used.
99
That way the other gzclose functions can be used instead to avoid linking in
1010
unneeded compression or decompression routines. */
11
-int ZEXPORT gzclose(file)
12
- gzFile file;
13
-{
11
+int ZEXPORT gzclose(gzFile file) {
1412
#ifndef NO_GZCOMPRESS
1513
gz_statep state;
1614
1715
if (file == NULL)
1816
return Z_STREAM_ERROR;
1917
--- compat/zlib/gzclose.c
+++ compat/zlib/gzclose.c
@@ -6,13 +6,11 @@
6 #include "gzguts.h"
7
8 /* gzclose() is in a separate file so that it is linked in only if it is used.
9 That way the other gzclose functions can be used instead to avoid linking in
10 unneeded compression or decompression routines. */
11 int ZEXPORT gzclose(file)
12 gzFile file;
13 {
14 #ifndef NO_GZCOMPRESS
15 gz_statep state;
16
17 if (file == NULL)
18 return Z_STREAM_ERROR;
19
--- compat/zlib/gzclose.c
+++ compat/zlib/gzclose.c
@@ -6,13 +6,11 @@
6 #include "gzguts.h"
7
8 /* gzclose() is in a separate file so that it is linked in only if it is used.
9 That way the other gzclose functions can be used instead to avoid linking in
10 unneeded compression or decompression routines. */
11 int ZEXPORT gzclose(gzFile file) {
 
 
12 #ifndef NO_GZCOMPRESS
13 gz_statep state;
14
15 if (file == NULL)
16 return Z_STREAM_ERROR;
17
--- compat/zlib/gzguts.h
+++ compat/zlib/gzguts.h
@@ -5,13 +5,12 @@
55
66
#ifdef _LARGEFILE64_SOURCE
77
# ifndef _LARGEFILE_SOURCE
88
# define _LARGEFILE_SOURCE 1
99
# endif
10
-# ifdef _FILE_OFFSET_BITS
11
-# undef _FILE_OFFSET_BITS
12
-# endif
10
+# undef _FILE_OFFSET_BITS
11
+# undef _TIME_BITS
1312
#endif
1413
1514
#ifdef HAVE_HIDDEN
1615
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
1716
#else
@@ -117,12 +116,12 @@
117116
define "local" for the non-static meaning of "static", for readability
118117
(compile with -Dlocal if your debugger can't find static symbols) */
119118
120119
/* gz* functions always use library allocation functions */
121120
#ifndef STDC
122
- extern voidp malloc OF((uInt size));
123
- extern void free OF((voidpf ptr));
121
+ extern voidp malloc(uInt size);
122
+ extern void free(voidpf ptr);
124123
#endif
125124
126125
/* get errno and strerror definition */
127126
#if defined UNDER_CE
128127
# include <windows.h>
@@ -136,14 +135,14 @@
136135
# endif
137136
#endif
138137
139138
/* provide prototypes for these when building zlib without LFS */
140139
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
141
- ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
142
- ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
143
- ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
144
- ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
140
+ ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
141
+ ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
142
+ ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
143
+ ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
145144
#endif
146145
147146
/* default memLevel */
148147
#if MAX_MEM_LEVEL >= 8
149148
# define DEF_MEM_LEVEL 8
@@ -201,19 +200,19 @@
201200
z_stream strm; /* stream structure in-place (not a pointer) */
202201
} gz_state;
203202
typedef gz_state FAR *gz_statep;
204203
205204
/* shared functions */
206
-void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
205
+void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
207206
#if defined UNDER_CE
208
-char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
207
+char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
209208
#endif
210209
211210
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
212211
value -- needed when comparing unsigned to z_off64_t, which is signed
213212
(possible z_off64_t types off_t, off64_t, and long are all signed) */
214213
#ifdef INT_MAX
215214
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
216215
#else
217
-unsigned ZLIB_INTERNAL gz_intmax OF((void));
216
+unsigned ZLIB_INTERNAL gz_intmax(void);
218217
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
219218
#endif
220219
--- compat/zlib/gzguts.h
+++ compat/zlib/gzguts.h
@@ -5,13 +5,12 @@
5
6 #ifdef _LARGEFILE64_SOURCE
7 # ifndef _LARGEFILE_SOURCE
8 # define _LARGEFILE_SOURCE 1
9 # endif
10 # ifdef _FILE_OFFSET_BITS
11 # undef _FILE_OFFSET_BITS
12 # endif
13 #endif
14
15 #ifdef HAVE_HIDDEN
16 # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
17 #else
@@ -117,12 +116,12 @@
117 define "local" for the non-static meaning of "static", for readability
118 (compile with -Dlocal if your debugger can't find static symbols) */
119
120 /* gz* functions always use library allocation functions */
121 #ifndef STDC
122 extern voidp malloc OF((uInt size));
123 extern void free OF((voidpf ptr));
124 #endif
125
126 /* get errno and strerror definition */
127 #if defined UNDER_CE
128 # include <windows.h>
@@ -136,14 +135,14 @@
136 # endif
137 #endif
138
139 /* provide prototypes for these when building zlib without LFS */
140 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
141 ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
142 ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
143 ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
144 ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
145 #endif
146
147 /* default memLevel */
148 #if MAX_MEM_LEVEL >= 8
149 # define DEF_MEM_LEVEL 8
@@ -201,19 +200,19 @@
201 z_stream strm; /* stream structure in-place (not a pointer) */
202 } gz_state;
203 typedef gz_state FAR *gz_statep;
204
205 /* shared functions */
206 void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
207 #if defined UNDER_CE
208 char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
209 #endif
210
211 /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
212 value -- needed when comparing unsigned to z_off64_t, which is signed
213 (possible z_off64_t types off_t, off64_t, and long are all signed) */
214 #ifdef INT_MAX
215 # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
216 #else
217 unsigned ZLIB_INTERNAL gz_intmax OF((void));
218 # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
219 #endif
220
--- compat/zlib/gzguts.h
+++ compat/zlib/gzguts.h
@@ -5,13 +5,12 @@
5
6 #ifdef _LARGEFILE64_SOURCE
7 # ifndef _LARGEFILE_SOURCE
8 # define _LARGEFILE_SOURCE 1
9 # endif
10 # undef _FILE_OFFSET_BITS
11 # undef _TIME_BITS
 
12 #endif
13
14 #ifdef HAVE_HIDDEN
15 # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
16 #else
@@ -117,12 +116,12 @@
116 define "local" for the non-static meaning of "static", for readability
117 (compile with -Dlocal if your debugger can't find static symbols) */
118
119 /* gz* functions always use library allocation functions */
120 #ifndef STDC
121 extern voidp malloc(uInt size);
122 extern void free(voidpf ptr);
123 #endif
124
125 /* get errno and strerror definition */
126 #if defined UNDER_CE
127 # include <windows.h>
@@ -136,14 +135,14 @@
135 # endif
136 #endif
137
138 /* provide prototypes for these when building zlib without LFS */
139 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
140 ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
141 ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
142 ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
143 ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
144 #endif
145
146 /* default memLevel */
147 #if MAX_MEM_LEVEL >= 8
148 # define DEF_MEM_LEVEL 8
@@ -201,19 +200,19 @@
200 z_stream strm; /* stream structure in-place (not a pointer) */
201 } gz_state;
202 typedef gz_state FAR *gz_statep;
203
204 /* shared functions */
205 void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
206 #if defined UNDER_CE
207 char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
208 #endif
209
210 /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
211 value -- needed when comparing unsigned to z_off64_t, which is signed
212 (possible z_off64_t types off_t, off64_t, and long are all signed) */
213 #ifdef INT_MAX
214 # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
215 #else
216 unsigned ZLIB_INTERNAL gz_intmax(void);
217 # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
218 #endif
219
--- compat/zlib/gzlib.c
+++ compat/zlib/gzlib.c
@@ -13,14 +13,10 @@
1313
#else
1414
# define LSEEK lseek
1515
#endif
1616
#endif
1717
18
-/* Local functions */
19
-local void gz_reset OF((gz_statep));
20
-local gzFile gz_open OF((const void *, int, const char *));
21
-
2218
#if defined UNDER_CE
2319
2420
/* Map the Windows error number in ERROR to a locale-dependent error message
2521
string and return a pointer to it. Typically, the values for ERROR come
2622
from GetLastError.
@@ -28,13 +24,11 @@
2824
The string pointed to shall not be modified by the application, but may be
2925
overwritten by a subsequent call to gz_strwinerror
3026
3127
The gz_strwinerror function does not change the current setting of
3228
GetLastError. */
33
-char ZLIB_INTERNAL *gz_strwinerror(error)
34
- DWORD error;
35
-{
29
+char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
3630
static char buf[1024];
3731
3832
wchar_t *msgbuf;
3933
DWORD lasterr = GetLastError();
4034
DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
@@ -70,13 +64,11 @@
7064
}
7165
7266
#endif /* UNDER_CE */
7367
7468
/* Reset gzip file state */
75
-local void gz_reset(state)
76
- gz_statep state;
77
-{
69
+local void gz_reset(gz_statep state) {
7870
state->x.have = 0; /* no output data available */
7971
if (state->mode == GZ_READ) { /* for reading ... */
8072
state->eof = 0; /* not at end of file */
8173
state->past = 0; /* have not read past end yet */
8274
state->how = LOOK; /* look for gzip header */
@@ -88,15 +80,11 @@
8880
state->x.pos = 0; /* no uncompressed data yet */
8981
state->strm.avail_in = 0; /* no input data yet */
9082
}
9183
9284
/* Open a gzip file either by name or file descriptor. */
93
-local gzFile gz_open(path, fd, mode)
94
- const void *path;
95
- int fd;
96
- const char *mode;
97
-{
85
+local gzFile gz_open(const void *path, int fd, const char *mode) {
9886
gz_statep state;
9987
z_size_t len;
10088
int oflag;
10189
#ifdef O_CLOEXEC
10290
int cloexec = 0;
@@ -267,30 +255,21 @@
267255
/* return stream */
268256
return (gzFile)state;
269257
}
270258
271259
/* -- see zlib.h -- */
272
-gzFile ZEXPORT gzopen(path, mode)
273
- const char *path;
274
- const char *mode;
275
-{
260
+gzFile ZEXPORT gzopen(const char *path, const char *mode) {
261
+ return gz_open(path, -1, mode);
262
+}
263
+
264
+/* -- see zlib.h -- */
265
+gzFile ZEXPORT gzopen64(const char *path, const char *mode) {
276266
return gz_open(path, -1, mode);
277267
}
278268
279269
/* -- see zlib.h -- */
280
-gzFile ZEXPORT gzopen64(path, mode)
281
- const char *path;
282
- const char *mode;
283
-{
284
- return gz_open(path, -1, mode);
285
-}
286
-
287
-/* -- see zlib.h -- */
288
-gzFile ZEXPORT gzdopen(fd, mode)
289
- int fd;
290
- const char *mode;
291
-{
270
+gzFile ZEXPORT gzdopen(int fd, const char *mode) {
292271
char *path; /* identifier for error messages */
293272
gzFile gz;
294273
295274
if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
296275
return NULL;
@@ -304,23 +283,17 @@
304283
return gz;
305284
}
306285
307286
/* -- see zlib.h -- */
308287
#ifdef WIDECHAR
309
-gzFile ZEXPORT gzopen_w(path, mode)
310
- const wchar_t *path;
311
- const char *mode;
312
-{
288
+gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode) {
313289
return gz_open(path, -2, mode);
314290
}
315291
#endif
316292
317293
/* -- see zlib.h -- */
318
-int ZEXPORT gzbuffer(file, size)
319
- gzFile file;
320
- unsigned size;
321
-{
294
+int ZEXPORT gzbuffer(gzFile file, unsigned size) {
322295
gz_statep state;
323296
324297
/* get internal structure and check integrity */
325298
if (file == NULL)
326299
return -1;
@@ -333,20 +306,18 @@
333306
return -1;
334307
335308
/* check and set requested size */
336309
if ((size << 1) < size)
337310
return -1; /* need to be able to double it */
338
- if (size < 2)
339
- size = 2; /* need two bytes to check magic header */
311
+ if (size < 8)
312
+ size = 8; /* needed to behave well with flushing */
340313
state->want = size;
341314
return 0;
342315
}
343316
344317
/* -- see zlib.h -- */
345
-int ZEXPORT gzrewind(file)
346
- gzFile file;
347
-{
318
+int ZEXPORT gzrewind(gzFile file) {
348319
gz_statep state;
349320
350321
/* get internal structure */
351322
if (file == NULL)
352323
return -1;
@@ -363,15 +334,11 @@
363334
gz_reset(state);
364335
return 0;
365336
}
366337
367338
/* -- see zlib.h -- */
368
-z_off64_t ZEXPORT gzseek64(file, offset, whence)
369
- gzFile file;
370
- z_off64_t offset;
371
- int whence;
372
-{
339
+z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
373340
unsigned n;
374341
z_off64_t ret;
375342
gz_statep state;
376343
377344
/* get internal structure and check integrity */
@@ -440,25 +407,19 @@
440407
}
441408
return state->x.pos + offset;
442409
}
443410
444411
/* -- see zlib.h -- */
445
-z_off_t ZEXPORT gzseek(file, offset, whence)
446
- gzFile file;
447
- z_off_t offset;
448
- int whence;
449
-{
412
+z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) {
450413
z_off64_t ret;
451414
452415
ret = gzseek64(file, (z_off64_t)offset, whence);
453416
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
454417
}
455418
456419
/* -- see zlib.h -- */
457
-z_off64_t ZEXPORT gztell64(file)
458
- gzFile file;
459
-{
420
+z_off64_t ZEXPORT gztell64(gzFile file) {
460421
gz_statep state;
461422
462423
/* get internal structure and check integrity */
463424
if (file == NULL)
464425
return -1;
@@ -469,23 +430,19 @@
469430
/* return position */
470431
return state->x.pos + (state->seek ? state->skip : 0);
471432
}
472433
473434
/* -- see zlib.h -- */
474
-z_off_t ZEXPORT gztell(file)
475
- gzFile file;
476
-{
435
+z_off_t ZEXPORT gztell(gzFile file) {
477436
z_off64_t ret;
478437
479438
ret = gztell64(file);
480439
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
481440
}
482441
483442
/* -- see zlib.h -- */
484
-z_off64_t ZEXPORT gzoffset64(file)
485
- gzFile file;
486
-{
443
+z_off64_t ZEXPORT gzoffset64(gzFile file) {
487444
z_off64_t offset;
488445
gz_statep state;
489446
490447
/* get internal structure and check integrity */
491448
if (file == NULL)
@@ -502,23 +459,19 @@
502459
offset -= state->strm.avail_in; /* don't count buffered input */
503460
return offset;
504461
}
505462
506463
/* -- see zlib.h -- */
507
-z_off_t ZEXPORT gzoffset(file)
508
- gzFile file;
509
-{
464
+z_off_t ZEXPORT gzoffset(gzFile file) {
510465
z_off64_t ret;
511466
512467
ret = gzoffset64(file);
513468
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
514469
}
515470
516471
/* -- see zlib.h -- */
517
-int ZEXPORT gzeof(file)
518
- gzFile file;
519
-{
472
+int ZEXPORT gzeof(gzFile file) {
520473
gz_statep state;
521474
522475
/* get internal structure and check integrity */
523476
if (file == NULL)
524477
return 0;
@@ -529,14 +482,11 @@
529482
/* return end-of-file state */
530483
return state->mode == GZ_READ ? state->past : 0;
531484
}
532485
533486
/* -- see zlib.h -- */
534
-const char * ZEXPORT gzerror(file, errnum)
535
- gzFile file;
536
- int *errnum;
537
-{
487
+const char * ZEXPORT gzerror(gzFile file, int *errnum) {
538488
gz_statep state;
539489
540490
/* get internal structure and check integrity */
541491
if (file == NULL)
542492
return NULL;
@@ -550,13 +500,11 @@
550500
return state->err == Z_MEM_ERROR ? "out of memory" :
551501
(state->msg == NULL ? "" : state->msg);
552502
}
553503
554504
/* -- see zlib.h -- */
555
-void ZEXPORT gzclearerr(file)
556
- gzFile file;
557
-{
505
+void ZEXPORT gzclearerr(gzFile file) {
558506
gz_statep state;
559507
560508
/* get internal structure and check integrity */
561509
if (file == NULL)
562510
return;
@@ -576,15 +524,11 @@
576524
state->msg accordingly. Free any previous error message already there. Do
577525
not try to free or allocate space if the error is Z_MEM_ERROR (out of
578526
memory). Simply save the error message as a static string. If there is an
579527
allocation failure constructing the error message, then convert the error to
580528
out of memory. */
581
-void ZLIB_INTERNAL gz_error(state, err, msg)
582
- gz_statep state;
583
- int err;
584
- const char *msg;
585
-{
529
+void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
586530
/* free previously allocated message and clear */
587531
if (state->msg != NULL) {
588532
if (state->err != Z_MEM_ERROR)
589533
free(state->msg);
590534
state->msg = NULL;
@@ -622,12 +566,11 @@
622566
#ifndef INT_MAX
623567
/* portably return maximum value for an int (when limits.h presumed not
624568
available) -- we need to do this to cover cases where 2's complement not
625569
used, since C standard permits 1's complement and sign-bit representations,
626570
otherwise we could just use ((unsigned)-1) >> 1 */
627
-unsigned ZLIB_INTERNAL gz_intmax()
628
-{
571
+unsigned ZLIB_INTERNAL gz_intmax(void) {
629572
unsigned p, q;
630573
631574
p = 1;
632575
do {
633576
q = p;
634577
--- compat/zlib/gzlib.c
+++ compat/zlib/gzlib.c
@@ -13,14 +13,10 @@
13 #else
14 # define LSEEK lseek
15 #endif
16 #endif
17
18 /* Local functions */
19 local void gz_reset OF((gz_statep));
20 local gzFile gz_open OF((const void *, int, const char *));
21
22 #if defined UNDER_CE
23
24 /* Map the Windows error number in ERROR to a locale-dependent error message
25 string and return a pointer to it. Typically, the values for ERROR come
26 from GetLastError.
@@ -28,13 +24,11 @@
28 The string pointed to shall not be modified by the application, but may be
29 overwritten by a subsequent call to gz_strwinerror
30
31 The gz_strwinerror function does not change the current setting of
32 GetLastError. */
33 char ZLIB_INTERNAL *gz_strwinerror(error)
34 DWORD error;
35 {
36 static char buf[1024];
37
38 wchar_t *msgbuf;
39 DWORD lasterr = GetLastError();
40 DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
@@ -70,13 +64,11 @@
70 }
71
72 #endif /* UNDER_CE */
73
74 /* Reset gzip file state */
75 local void gz_reset(state)
76 gz_statep state;
77 {
78 state->x.have = 0; /* no output data available */
79 if (state->mode == GZ_READ) { /* for reading ... */
80 state->eof = 0; /* not at end of file */
81 state->past = 0; /* have not read past end yet */
82 state->how = LOOK; /* look for gzip header */
@@ -88,15 +80,11 @@
88 state->x.pos = 0; /* no uncompressed data yet */
89 state->strm.avail_in = 0; /* no input data yet */
90 }
91
92 /* Open a gzip file either by name or file descriptor. */
93 local gzFile gz_open(path, fd, mode)
94 const void *path;
95 int fd;
96 const char *mode;
97 {
98 gz_statep state;
99 z_size_t len;
100 int oflag;
101 #ifdef O_CLOEXEC
102 int cloexec = 0;
@@ -267,30 +255,21 @@
267 /* return stream */
268 return (gzFile)state;
269 }
270
271 /* -- see zlib.h -- */
272 gzFile ZEXPORT gzopen(path, mode)
273 const char *path;
274 const char *mode;
275 {
 
 
276 return gz_open(path, -1, mode);
277 }
278
279 /* -- see zlib.h -- */
280 gzFile ZEXPORT gzopen64(path, mode)
281 const char *path;
282 const char *mode;
283 {
284 return gz_open(path, -1, mode);
285 }
286
287 /* -- see zlib.h -- */
288 gzFile ZEXPORT gzdopen(fd, mode)
289 int fd;
290 const char *mode;
291 {
292 char *path; /* identifier for error messages */
293 gzFile gz;
294
295 if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
296 return NULL;
@@ -304,23 +283,17 @@
304 return gz;
305 }
306
307 /* -- see zlib.h -- */
308 #ifdef WIDECHAR
309 gzFile ZEXPORT gzopen_w(path, mode)
310 const wchar_t *path;
311 const char *mode;
312 {
313 return gz_open(path, -2, mode);
314 }
315 #endif
316
317 /* -- see zlib.h -- */
318 int ZEXPORT gzbuffer(file, size)
319 gzFile file;
320 unsigned size;
321 {
322 gz_statep state;
323
324 /* get internal structure and check integrity */
325 if (file == NULL)
326 return -1;
@@ -333,20 +306,18 @@
333 return -1;
334
335 /* check and set requested size */
336 if ((size << 1) < size)
337 return -1; /* need to be able to double it */
338 if (size < 2)
339 size = 2; /* need two bytes to check magic header */
340 state->want = size;
341 return 0;
342 }
343
344 /* -- see zlib.h -- */
345 int ZEXPORT gzrewind(file)
346 gzFile file;
347 {
348 gz_statep state;
349
350 /* get internal structure */
351 if (file == NULL)
352 return -1;
@@ -363,15 +334,11 @@
363 gz_reset(state);
364 return 0;
365 }
366
367 /* -- see zlib.h -- */
368 z_off64_t ZEXPORT gzseek64(file, offset, whence)
369 gzFile file;
370 z_off64_t offset;
371 int whence;
372 {
373 unsigned n;
374 z_off64_t ret;
375 gz_statep state;
376
377 /* get internal structure and check integrity */
@@ -440,25 +407,19 @@
440 }
441 return state->x.pos + offset;
442 }
443
444 /* -- see zlib.h -- */
445 z_off_t ZEXPORT gzseek(file, offset, whence)
446 gzFile file;
447 z_off_t offset;
448 int whence;
449 {
450 z_off64_t ret;
451
452 ret = gzseek64(file, (z_off64_t)offset, whence);
453 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
454 }
455
456 /* -- see zlib.h -- */
457 z_off64_t ZEXPORT gztell64(file)
458 gzFile file;
459 {
460 gz_statep state;
461
462 /* get internal structure and check integrity */
463 if (file == NULL)
464 return -1;
@@ -469,23 +430,19 @@
469 /* return position */
470 return state->x.pos + (state->seek ? state->skip : 0);
471 }
472
473 /* -- see zlib.h -- */
474 z_off_t ZEXPORT gztell(file)
475 gzFile file;
476 {
477 z_off64_t ret;
478
479 ret = gztell64(file);
480 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
481 }
482
483 /* -- see zlib.h -- */
484 z_off64_t ZEXPORT gzoffset64(file)
485 gzFile file;
486 {
487 z_off64_t offset;
488 gz_statep state;
489
490 /* get internal structure and check integrity */
491 if (file == NULL)
@@ -502,23 +459,19 @@
502 offset -= state->strm.avail_in; /* don't count buffered input */
503 return offset;
504 }
505
506 /* -- see zlib.h -- */
507 z_off_t ZEXPORT gzoffset(file)
508 gzFile file;
509 {
510 z_off64_t ret;
511
512 ret = gzoffset64(file);
513 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
514 }
515
516 /* -- see zlib.h -- */
517 int ZEXPORT gzeof(file)
518 gzFile file;
519 {
520 gz_statep state;
521
522 /* get internal structure and check integrity */
523 if (file == NULL)
524 return 0;
@@ -529,14 +482,11 @@
529 /* return end-of-file state */
530 return state->mode == GZ_READ ? state->past : 0;
531 }
532
533 /* -- see zlib.h -- */
534 const char * ZEXPORT gzerror(file, errnum)
535 gzFile file;
536 int *errnum;
537 {
538 gz_statep state;
539
540 /* get internal structure and check integrity */
541 if (file == NULL)
542 return NULL;
@@ -550,13 +500,11 @@
550 return state->err == Z_MEM_ERROR ? "out of memory" :
551 (state->msg == NULL ? "" : state->msg);
552 }
553
554 /* -- see zlib.h -- */
555 void ZEXPORT gzclearerr(file)
556 gzFile file;
557 {
558 gz_statep state;
559
560 /* get internal structure and check integrity */
561 if (file == NULL)
562 return;
@@ -576,15 +524,11 @@
576 state->msg accordingly. Free any previous error message already there. Do
577 not try to free or allocate space if the error is Z_MEM_ERROR (out of
578 memory). Simply save the error message as a static string. If there is an
579 allocation failure constructing the error message, then convert the error to
580 out of memory. */
581 void ZLIB_INTERNAL gz_error(state, err, msg)
582 gz_statep state;
583 int err;
584 const char *msg;
585 {
586 /* free previously allocated message and clear */
587 if (state->msg != NULL) {
588 if (state->err != Z_MEM_ERROR)
589 free(state->msg);
590 state->msg = NULL;
@@ -622,12 +566,11 @@
622 #ifndef INT_MAX
623 /* portably return maximum value for an int (when limits.h presumed not
624 available) -- we need to do this to cover cases where 2's complement not
625 used, since C standard permits 1's complement and sign-bit representations,
626 otherwise we could just use ((unsigned)-1) >> 1 */
627 unsigned ZLIB_INTERNAL gz_intmax()
628 {
629 unsigned p, q;
630
631 p = 1;
632 do {
633 q = p;
634
--- compat/zlib/gzlib.c
+++ compat/zlib/gzlib.c
@@ -13,14 +13,10 @@
13 #else
14 # define LSEEK lseek
15 #endif
16 #endif
17
 
 
 
 
18 #if defined UNDER_CE
19
20 /* Map the Windows error number in ERROR to a locale-dependent error message
21 string and return a pointer to it. Typically, the values for ERROR come
22 from GetLastError.
@@ -28,13 +24,11 @@
24 The string pointed to shall not be modified by the application, but may be
25 overwritten by a subsequent call to gz_strwinerror
26
27 The gz_strwinerror function does not change the current setting of
28 GetLastError. */
29 char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
 
 
30 static char buf[1024];
31
32 wchar_t *msgbuf;
33 DWORD lasterr = GetLastError();
34 DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
@@ -70,13 +64,11 @@
64 }
65
66 #endif /* UNDER_CE */
67
68 /* Reset gzip file state */
69 local void gz_reset(gz_statep state) {
 
 
70 state->x.have = 0; /* no output data available */
71 if (state->mode == GZ_READ) { /* for reading ... */
72 state->eof = 0; /* not at end of file */
73 state->past = 0; /* have not read past end yet */
74 state->how = LOOK; /* look for gzip header */
@@ -88,15 +80,11 @@
80 state->x.pos = 0; /* no uncompressed data yet */
81 state->strm.avail_in = 0; /* no input data yet */
82 }
83
84 /* Open a gzip file either by name or file descriptor. */
85 local gzFile gz_open(const void *path, int fd, const char *mode) {
 
 
 
 
86 gz_statep state;
87 z_size_t len;
88 int oflag;
89 #ifdef O_CLOEXEC
90 int cloexec = 0;
@@ -267,30 +255,21 @@
255 /* return stream */
256 return (gzFile)state;
257 }
258
259 /* -- see zlib.h -- */
260 gzFile ZEXPORT gzopen(const char *path, const char *mode) {
261 return gz_open(path, -1, mode);
262 }
263
264 /* -- see zlib.h -- */
265 gzFile ZEXPORT gzopen64(const char *path, const char *mode) {
266 return gz_open(path, -1, mode);
267 }
268
269 /* -- see zlib.h -- */
270 gzFile ZEXPORT gzdopen(int fd, const char *mode) {
 
 
 
 
 
 
 
 
 
 
 
271 char *path; /* identifier for error messages */
272 gzFile gz;
273
274 if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
275 return NULL;
@@ -304,23 +283,17 @@
283 return gz;
284 }
285
286 /* -- see zlib.h -- */
287 #ifdef WIDECHAR
288 gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode) {
 
 
 
289 return gz_open(path, -2, mode);
290 }
291 #endif
292
293 /* -- see zlib.h -- */
294 int ZEXPORT gzbuffer(gzFile file, unsigned size) {
 
 
 
295 gz_statep state;
296
297 /* get internal structure and check integrity */
298 if (file == NULL)
299 return -1;
@@ -333,20 +306,18 @@
306 return -1;
307
308 /* check and set requested size */
309 if ((size << 1) < size)
310 return -1; /* need to be able to double it */
311 if (size < 8)
312 size = 8; /* needed to behave well with flushing */
313 state->want = size;
314 return 0;
315 }
316
317 /* -- see zlib.h -- */
318 int ZEXPORT gzrewind(gzFile file) {
 
 
319 gz_statep state;
320
321 /* get internal structure */
322 if (file == NULL)
323 return -1;
@@ -363,15 +334,11 @@
334 gz_reset(state);
335 return 0;
336 }
337
338 /* -- see zlib.h -- */
339 z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
 
 
 
 
340 unsigned n;
341 z_off64_t ret;
342 gz_statep state;
343
344 /* get internal structure and check integrity */
@@ -440,25 +407,19 @@
407 }
408 return state->x.pos + offset;
409 }
410
411 /* -- see zlib.h -- */
412 z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) {
 
 
 
 
413 z_off64_t ret;
414
415 ret = gzseek64(file, (z_off64_t)offset, whence);
416 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
417 }
418
419 /* -- see zlib.h -- */
420 z_off64_t ZEXPORT gztell64(gzFile file) {
 
 
421 gz_statep state;
422
423 /* get internal structure and check integrity */
424 if (file == NULL)
425 return -1;
@@ -469,23 +430,19 @@
430 /* return position */
431 return state->x.pos + (state->seek ? state->skip : 0);
432 }
433
434 /* -- see zlib.h -- */
435 z_off_t ZEXPORT gztell(gzFile file) {
 
 
436 z_off64_t ret;
437
438 ret = gztell64(file);
439 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
440 }
441
442 /* -- see zlib.h -- */
443 z_off64_t ZEXPORT gzoffset64(gzFile file) {
 
 
444 z_off64_t offset;
445 gz_statep state;
446
447 /* get internal structure and check integrity */
448 if (file == NULL)
@@ -502,23 +459,19 @@
459 offset -= state->strm.avail_in; /* don't count buffered input */
460 return offset;
461 }
462
463 /* -- see zlib.h -- */
464 z_off_t ZEXPORT gzoffset(gzFile file) {
 
 
465 z_off64_t ret;
466
467 ret = gzoffset64(file);
468 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
469 }
470
471 /* -- see zlib.h -- */
472 int ZEXPORT gzeof(gzFile file) {
 
 
473 gz_statep state;
474
475 /* get internal structure and check integrity */
476 if (file == NULL)
477 return 0;
@@ -529,14 +482,11 @@
482 /* return end-of-file state */
483 return state->mode == GZ_READ ? state->past : 0;
484 }
485
486 /* -- see zlib.h -- */
487 const char * ZEXPORT gzerror(gzFile file, int *errnum) {
 
 
 
488 gz_statep state;
489
490 /* get internal structure and check integrity */
491 if (file == NULL)
492 return NULL;
@@ -550,13 +500,11 @@
500 return state->err == Z_MEM_ERROR ? "out of memory" :
501 (state->msg == NULL ? "" : state->msg);
502 }
503
504 /* -- see zlib.h -- */
505 void ZEXPORT gzclearerr(gzFile file) {
 
 
506 gz_statep state;
507
508 /* get internal structure and check integrity */
509 if (file == NULL)
510 return;
@@ -576,15 +524,11 @@
524 state->msg accordingly. Free any previous error message already there. Do
525 not try to free or allocate space if the error is Z_MEM_ERROR (out of
526 memory). Simply save the error message as a static string. If there is an
527 allocation failure constructing the error message, then convert the error to
528 out of memory. */
529 void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
 
 
 
 
530 /* free previously allocated message and clear */
531 if (state->msg != NULL) {
532 if (state->err != Z_MEM_ERROR)
533 free(state->msg);
534 state->msg = NULL;
@@ -622,12 +566,11 @@
566 #ifndef INT_MAX
567 /* portably return maximum value for an int (when limits.h presumed not
568 available) -- we need to do this to cover cases where 2's complement not
569 used, since C standard permits 1's complement and sign-bit representations,
570 otherwise we could just use ((unsigned)-1) >> 1 */
571 unsigned ZLIB_INTERNAL gz_intmax(void) {
 
572 unsigned p, q;
573
574 p = 1;
575 do {
576 q = p;
577
--- compat/zlib/gzread.c
+++ compat/zlib/gzread.c
@@ -3,29 +3,16 @@
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55
66
#include "gzguts.h"
77
8
-/* Local functions */
9
-local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
10
-local int gz_avail OF((gz_statep));
11
-local int gz_look OF((gz_statep));
12
-local int gz_decomp OF((gz_statep));
13
-local int gz_fetch OF((gz_statep));
14
-local int gz_skip OF((gz_statep, z_off64_t));
15
-local z_size_t gz_read OF((gz_statep, voidp, z_size_t));
16
-
178
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
189
state->fd, and update state->eof, state->err, and state->msg as appropriate.
1910
This function needs to loop on read(), since read() is not guaranteed to
2011
read the number of bytes requested, depending on the type of descriptor. */
21
-local int gz_load(state, buf, len, have)
22
- gz_statep state;
23
- unsigned char *buf;
24
- unsigned len;
25
- unsigned *have;
26
-{
12
+local int gz_load(gz_statep state, unsigned char *buf, unsigned len,
13
+ unsigned *have) {
2714
int ret;
2815
unsigned get, max = ((unsigned)-1 >> 2) + 1;
2916
3017
*have = 0;
3118
do {
@@ -51,13 +38,11 @@
5138
file is reached, even though there may be unused data in the buffer. Once
5239
that data has been used, no more attempts will be made to read the file.
5340
If strm->avail_in != 0, then the current data is moved to the beginning of
5441
the input buffer, and then the remainder of the buffer is loaded with the
5542
available data from the input file. */
56
-local int gz_avail(state)
57
- gz_statep state;
58
-{
43
+local int gz_avail(gz_statep state) {
5944
unsigned got;
6045
z_streamp strm = &(state->strm);
6146
6247
if (state->err != Z_OK && state->err != Z_BUF_ERROR)
6348
return -1;
@@ -86,13 +71,11 @@
8671
be set to GZIP for decompression. If direct copying, then leftover input
8772
data from the input buffer will be copied to the output buffer. In that
8873
case, all further file reads will be directly to either the output buffer or
8974
a user buffer. If decompressing, the inflate state will be initialized.
9075
gz_look() will return 0 on success or -1 on failure. */
91
-local int gz_look(state)
92
- gz_statep state;
93
-{
76
+local int gz_look(gz_statep state) {
9477
z_streamp strm = &(state->strm);
9578
9679
/* allocate read buffers and inflate memory */
9780
if (state->size == 0) {
9881
/* allocate buffers */
@@ -168,13 +151,11 @@
168151
/* Decompress from input to the provided next_out and avail_out in the state.
169152
On return, state->x.have and state->x.next point to the just decompressed
170153
data. If the gzip stream completes, state->how is reset to LOOK to look for
171154
the next gzip stream or raw data, once state->x.have is depleted. Returns 0
172155
on success, -1 on failure. */
173
-local int gz_decomp(state)
174
- gz_statep state;
175
-{
156
+local int gz_decomp(gz_statep state) {
176157
int ret = Z_OK;
177158
unsigned had;
178159
z_streamp strm = &(state->strm);
179160
180161
/* fill output buffer up to end of deflate stream */
@@ -222,13 +203,11 @@
222203
Data is either copied from the input file or decompressed from the input
223204
file depending on state->how. If state->how is LOOK, then a gzip header is
224205
looked for to determine whether to copy or decompress. Returns -1 on error,
225206
otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
226207
end of the input file has been reached and all data has been processed. */
227
-local int gz_fetch(state)
228
- gz_statep state;
229
-{
208
+local int gz_fetch(gz_statep state) {
230209
z_streamp strm = &(state->strm);
231210
232211
do {
233212
switch(state->how) {
234213
case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */
@@ -252,14 +231,11 @@
252231
} while (state->x.have == 0 && (!state->eof || strm->avail_in));
253232
return 0;
254233
}
255234
256235
/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */
257
-local int gz_skip(state, len)
258
- gz_statep state;
259
- z_off64_t len;
260
-{
236
+local int gz_skip(gz_statep state, z_off64_t len) {
261237
unsigned n;
262238
263239
/* skip over len bytes or reach end-of-file, whichever comes first */
264240
while (len)
265241
/* skip over whatever is in output buffer */
@@ -287,15 +263,11 @@
287263
288264
/* Read len bytes into buf from file, or less than len up to the end of the
289265
input. Return the number of bytes read. If zero is returned, either the
290266
end of file was reached, or there was an error. state->err must be
291267
consulted in that case to determine which. */
292
-local z_size_t gz_read(state, buf, len)
293
- gz_statep state;
294
- voidp buf;
295
- z_size_t len;
296
-{
268
+local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) {
297269
z_size_t got;
298270
unsigned n;
299271
300272
/* if len is zero, avoid unnecessary operations */
301273
if (len == 0)
@@ -368,15 +340,11 @@
368340
/* return number of bytes read into user buffer */
369341
return got;
370342
}
371343
372344
/* -- see zlib.h -- */
373
-int ZEXPORT gzread(file, buf, len)
374
- gzFile file;
375
- voidp buf;
376
- unsigned len;
377
-{
345
+int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) {
378346
gz_statep state;
379347
380348
/* get internal structure */
381349
if (file == NULL)
382350
return -1;
@@ -404,16 +372,11 @@
404372
/* return the number of bytes read (this is assured to fit in an int) */
405373
return (int)len;
406374
}
407375
408376
/* -- see zlib.h -- */
409
-z_size_t ZEXPORT gzfread(buf, size, nitems, file)
410
- voidp buf;
411
- z_size_t size;
412
- z_size_t nitems;
413
- gzFile file;
414
-{
377
+z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, gzFile file) {
415378
z_size_t len;
416379
gz_statep state;
417380
418381
/* get internal structure */
419382
if (file == NULL)
@@ -440,13 +403,11 @@
440403
#ifdef Z_PREFIX_SET
441404
# undef z_gzgetc
442405
#else
443406
# undef gzgetc
444407
#endif
445
-int ZEXPORT gzgetc(file)
446
- gzFile file;
447
-{
408
+int ZEXPORT gzgetc(gzFile file) {
448409
unsigned char buf[1];
449410
gz_statep state;
450411
451412
/* get internal structure */
452413
if (file == NULL)
@@ -467,27 +428,26 @@
467428
468429
/* nothing there -- try gz_read() */
469430
return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
470431
}
471432
472
-int ZEXPORT gzgetc_(file)
473
-gzFile file;
474
-{
433
+int ZEXPORT gzgetc_(gzFile file) {
475434
return gzgetc(file);
476435
}
477436
478437
/* -- see zlib.h -- */
479
-int ZEXPORT gzungetc(c, file)
480
- int c;
481
- gzFile file;
482
-{
438
+int ZEXPORT gzungetc(int c, gzFile file) {
483439
gz_statep state;
484440
485441
/* get internal structure */
486442
if (file == NULL)
487443
return -1;
488444
state = (gz_statep)file;
445
+
446
+ /* in case this was just opened, set up the input buffer */
447
+ if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
448
+ (void)gz_look(state);
489449
490450
/* check that we're reading and that there's no (serious) error */
491451
if (state->mode != GZ_READ ||
492452
(state->err != Z_OK && state->err != Z_BUF_ERROR))
493453
return -1;
@@ -534,15 +494,11 @@
534494
state->past = 0;
535495
return c;
536496
}
537497
538498
/* -- see zlib.h -- */
539
-char * ZEXPORT gzgets(file, buf, len)
540
- gzFile file;
541
- char *buf;
542
- int len;
543
-{
499
+char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
544500
unsigned left, n;
545501
char *str;
546502
unsigned char *eol;
547503
gz_statep state;
548504
@@ -598,13 +554,11 @@
598554
buf[0] = 0;
599555
return str;
600556
}
601557
602558
/* -- see zlib.h -- */
603
-int ZEXPORT gzdirect(file)
604
- gzFile file;
605
-{
559
+int ZEXPORT gzdirect(gzFile file) {
606560
gz_statep state;
607561
608562
/* get internal structure */
609563
if (file == NULL)
610564
return 0;
@@ -618,13 +572,11 @@
618572
/* return 1 if transparent, 0 if processing a gzip stream */
619573
return state->direct;
620574
}
621575
622576
/* -- see zlib.h -- */
623
-int ZEXPORT gzclose_r(file)
624
- gzFile file;
625
-{
577
+int ZEXPORT gzclose_r(gzFile file) {
626578
int ret, err;
627579
gz_statep state;
628580
629581
/* get internal structure */
630582
if (file == NULL)
631583
--- compat/zlib/gzread.c
+++ compat/zlib/gzread.c
@@ -3,29 +3,16 @@
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 #include "gzguts.h"
7
8 /* Local functions */
9 local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
10 local int gz_avail OF((gz_statep));
11 local int gz_look OF((gz_statep));
12 local int gz_decomp OF((gz_statep));
13 local int gz_fetch OF((gz_statep));
14 local int gz_skip OF((gz_statep, z_off64_t));
15 local z_size_t gz_read OF((gz_statep, voidp, z_size_t));
16
17 /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
18 state->fd, and update state->eof, state->err, and state->msg as appropriate.
19 This function needs to loop on read(), since read() is not guaranteed to
20 read the number of bytes requested, depending on the type of descriptor. */
21 local int gz_load(state, buf, len, have)
22 gz_statep state;
23 unsigned char *buf;
24 unsigned len;
25 unsigned *have;
26 {
27 int ret;
28 unsigned get, max = ((unsigned)-1 >> 2) + 1;
29
30 *have = 0;
31 do {
@@ -51,13 +38,11 @@
51 file is reached, even though there may be unused data in the buffer. Once
52 that data has been used, no more attempts will be made to read the file.
53 If strm->avail_in != 0, then the current data is moved to the beginning of
54 the input buffer, and then the remainder of the buffer is loaded with the
55 available data from the input file. */
56 local int gz_avail(state)
57 gz_statep state;
58 {
59 unsigned got;
60 z_streamp strm = &(state->strm);
61
62 if (state->err != Z_OK && state->err != Z_BUF_ERROR)
63 return -1;
@@ -86,13 +71,11 @@
86 be set to GZIP for decompression. If direct copying, then leftover input
87 data from the input buffer will be copied to the output buffer. In that
88 case, all further file reads will be directly to either the output buffer or
89 a user buffer. If decompressing, the inflate state will be initialized.
90 gz_look() will return 0 on success or -1 on failure. */
91 local int gz_look(state)
92 gz_statep state;
93 {
94 z_streamp strm = &(state->strm);
95
96 /* allocate read buffers and inflate memory */
97 if (state->size == 0) {
98 /* allocate buffers */
@@ -168,13 +151,11 @@
168 /* Decompress from input to the provided next_out and avail_out in the state.
169 On return, state->x.have and state->x.next point to the just decompressed
170 data. If the gzip stream completes, state->how is reset to LOOK to look for
171 the next gzip stream or raw data, once state->x.have is depleted. Returns 0
172 on success, -1 on failure. */
173 local int gz_decomp(state)
174 gz_statep state;
175 {
176 int ret = Z_OK;
177 unsigned had;
178 z_streamp strm = &(state->strm);
179
180 /* fill output buffer up to end of deflate stream */
@@ -222,13 +203,11 @@
222 Data is either copied from the input file or decompressed from the input
223 file depending on state->how. If state->how is LOOK, then a gzip header is
224 looked for to determine whether to copy or decompress. Returns -1 on error,
225 otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
226 end of the input file has been reached and all data has been processed. */
227 local int gz_fetch(state)
228 gz_statep state;
229 {
230 z_streamp strm = &(state->strm);
231
232 do {
233 switch(state->how) {
234 case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */
@@ -252,14 +231,11 @@
252 } while (state->x.have == 0 && (!state->eof || strm->avail_in));
253 return 0;
254 }
255
256 /* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */
257 local int gz_skip(state, len)
258 gz_statep state;
259 z_off64_t len;
260 {
261 unsigned n;
262
263 /* skip over len bytes or reach end-of-file, whichever comes first */
264 while (len)
265 /* skip over whatever is in output buffer */
@@ -287,15 +263,11 @@
287
288 /* Read len bytes into buf from file, or less than len up to the end of the
289 input. Return the number of bytes read. If zero is returned, either the
290 end of file was reached, or there was an error. state->err must be
291 consulted in that case to determine which. */
292 local z_size_t gz_read(state, buf, len)
293 gz_statep state;
294 voidp buf;
295 z_size_t len;
296 {
297 z_size_t got;
298 unsigned n;
299
300 /* if len is zero, avoid unnecessary operations */
301 if (len == 0)
@@ -368,15 +340,11 @@
368 /* return number of bytes read into user buffer */
369 return got;
370 }
371
372 /* -- see zlib.h -- */
373 int ZEXPORT gzread(file, buf, len)
374 gzFile file;
375 voidp buf;
376 unsigned len;
377 {
378 gz_statep state;
379
380 /* get internal structure */
381 if (file == NULL)
382 return -1;
@@ -404,16 +372,11 @@
404 /* return the number of bytes read (this is assured to fit in an int) */
405 return (int)len;
406 }
407
408 /* -- see zlib.h -- */
409 z_size_t ZEXPORT gzfread(buf, size, nitems, file)
410 voidp buf;
411 z_size_t size;
412 z_size_t nitems;
413 gzFile file;
414 {
415 z_size_t len;
416 gz_statep state;
417
418 /* get internal structure */
419 if (file == NULL)
@@ -440,13 +403,11 @@
440 #ifdef Z_PREFIX_SET
441 # undef z_gzgetc
442 #else
443 # undef gzgetc
444 #endif
445 int ZEXPORT gzgetc(file)
446 gzFile file;
447 {
448 unsigned char buf[1];
449 gz_statep state;
450
451 /* get internal structure */
452 if (file == NULL)
@@ -467,27 +428,26 @@
467
468 /* nothing there -- try gz_read() */
469 return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
470 }
471
472 int ZEXPORT gzgetc_(file)
473 gzFile file;
474 {
475 return gzgetc(file);
476 }
477
478 /* -- see zlib.h -- */
479 int ZEXPORT gzungetc(c, file)
480 int c;
481 gzFile file;
482 {
483 gz_statep state;
484
485 /* get internal structure */
486 if (file == NULL)
487 return -1;
488 state = (gz_statep)file;
 
 
 
 
489
490 /* check that we're reading and that there's no (serious) error */
491 if (state->mode != GZ_READ ||
492 (state->err != Z_OK && state->err != Z_BUF_ERROR))
493 return -1;
@@ -534,15 +494,11 @@
534 state->past = 0;
535 return c;
536 }
537
538 /* -- see zlib.h -- */
539 char * ZEXPORT gzgets(file, buf, len)
540 gzFile file;
541 char *buf;
542 int len;
543 {
544 unsigned left, n;
545 char *str;
546 unsigned char *eol;
547 gz_statep state;
548
@@ -598,13 +554,11 @@
598 buf[0] = 0;
599 return str;
600 }
601
602 /* -- see zlib.h -- */
603 int ZEXPORT gzdirect(file)
604 gzFile file;
605 {
606 gz_statep state;
607
608 /* get internal structure */
609 if (file == NULL)
610 return 0;
@@ -618,13 +572,11 @@
618 /* return 1 if transparent, 0 if processing a gzip stream */
619 return state->direct;
620 }
621
622 /* -- see zlib.h -- */
623 int ZEXPORT gzclose_r(file)
624 gzFile file;
625 {
626 int ret, err;
627 gz_statep state;
628
629 /* get internal structure */
630 if (file == NULL)
631
--- compat/zlib/gzread.c
+++ compat/zlib/gzread.c
@@ -3,29 +3,16 @@
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 #include "gzguts.h"
7
 
 
 
 
 
 
 
 
 
8 /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
9 state->fd, and update state->eof, state->err, and state->msg as appropriate.
10 This function needs to loop on read(), since read() is not guaranteed to
11 read the number of bytes requested, depending on the type of descriptor. */
12 local int gz_load(gz_statep state, unsigned char *buf, unsigned len,
13 unsigned *have) {
 
 
 
 
14 int ret;
15 unsigned get, max = ((unsigned)-1 >> 2) + 1;
16
17 *have = 0;
18 do {
@@ -51,13 +38,11 @@
38 file is reached, even though there may be unused data in the buffer. Once
39 that data has been used, no more attempts will be made to read the file.
40 If strm->avail_in != 0, then the current data is moved to the beginning of
41 the input buffer, and then the remainder of the buffer is loaded with the
42 available data from the input file. */
43 local int gz_avail(gz_statep state) {
 
 
44 unsigned got;
45 z_streamp strm = &(state->strm);
46
47 if (state->err != Z_OK && state->err != Z_BUF_ERROR)
48 return -1;
@@ -86,13 +71,11 @@
71 be set to GZIP for decompression. If direct copying, then leftover input
72 data from the input buffer will be copied to the output buffer. In that
73 case, all further file reads will be directly to either the output buffer or
74 a user buffer. If decompressing, the inflate state will be initialized.
75 gz_look() will return 0 on success or -1 on failure. */
76 local int gz_look(gz_statep state) {
 
 
77 z_streamp strm = &(state->strm);
78
79 /* allocate read buffers and inflate memory */
80 if (state->size == 0) {
81 /* allocate buffers */
@@ -168,13 +151,11 @@
151 /* Decompress from input to the provided next_out and avail_out in the state.
152 On return, state->x.have and state->x.next point to the just decompressed
153 data. If the gzip stream completes, state->how is reset to LOOK to look for
154 the next gzip stream or raw data, once state->x.have is depleted. Returns 0
155 on success, -1 on failure. */
156 local int gz_decomp(gz_statep state) {
 
 
157 int ret = Z_OK;
158 unsigned had;
159 z_streamp strm = &(state->strm);
160
161 /* fill output buffer up to end of deflate stream */
@@ -222,13 +203,11 @@
203 Data is either copied from the input file or decompressed from the input
204 file depending on state->how. If state->how is LOOK, then a gzip header is
205 looked for to determine whether to copy or decompress. Returns -1 on error,
206 otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
207 end of the input file has been reached and all data has been processed. */
208 local int gz_fetch(gz_statep state) {
 
 
209 z_streamp strm = &(state->strm);
210
211 do {
212 switch(state->how) {
213 case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */
@@ -252,14 +231,11 @@
231 } while (state->x.have == 0 && (!state->eof || strm->avail_in));
232 return 0;
233 }
234
235 /* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */
236 local int gz_skip(gz_statep state, z_off64_t len) {
 
 
 
237 unsigned n;
238
239 /* skip over len bytes or reach end-of-file, whichever comes first */
240 while (len)
241 /* skip over whatever is in output buffer */
@@ -287,15 +263,11 @@
263
264 /* Read len bytes into buf from file, or less than len up to the end of the
265 input. Return the number of bytes read. If zero is returned, either the
266 end of file was reached, or there was an error. state->err must be
267 consulted in that case to determine which. */
268 local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) {
 
 
 
 
269 z_size_t got;
270 unsigned n;
271
272 /* if len is zero, avoid unnecessary operations */
273 if (len == 0)
@@ -368,15 +340,11 @@
340 /* return number of bytes read into user buffer */
341 return got;
342 }
343
344 /* -- see zlib.h -- */
345 int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) {
 
 
 
 
346 gz_statep state;
347
348 /* get internal structure */
349 if (file == NULL)
350 return -1;
@@ -404,16 +372,11 @@
372 /* return the number of bytes read (this is assured to fit in an int) */
373 return (int)len;
374 }
375
376 /* -- see zlib.h -- */
377 z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, gzFile file) {
 
 
 
 
 
378 z_size_t len;
379 gz_statep state;
380
381 /* get internal structure */
382 if (file == NULL)
@@ -440,13 +403,11 @@
403 #ifdef Z_PREFIX_SET
404 # undef z_gzgetc
405 #else
406 # undef gzgetc
407 #endif
408 int ZEXPORT gzgetc(gzFile file) {
 
 
409 unsigned char buf[1];
410 gz_statep state;
411
412 /* get internal structure */
413 if (file == NULL)
@@ -467,27 +428,26 @@
428
429 /* nothing there -- try gz_read() */
430 return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
431 }
432
433 int ZEXPORT gzgetc_(gzFile file) {
 
 
434 return gzgetc(file);
435 }
436
437 /* -- see zlib.h -- */
438 int ZEXPORT gzungetc(int c, gzFile file) {
 
 
 
439 gz_statep state;
440
441 /* get internal structure */
442 if (file == NULL)
443 return -1;
444 state = (gz_statep)file;
445
446 /* in case this was just opened, set up the input buffer */
447 if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
448 (void)gz_look(state);
449
450 /* check that we're reading and that there's no (serious) error */
451 if (state->mode != GZ_READ ||
452 (state->err != Z_OK && state->err != Z_BUF_ERROR))
453 return -1;
@@ -534,15 +494,11 @@
494 state->past = 0;
495 return c;
496 }
497
498 /* -- see zlib.h -- */
499 char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
 
 
 
 
500 unsigned left, n;
501 char *str;
502 unsigned char *eol;
503 gz_statep state;
504
@@ -598,13 +554,11 @@
554 buf[0] = 0;
555 return str;
556 }
557
558 /* -- see zlib.h -- */
559 int ZEXPORT gzdirect(gzFile file) {
 
 
560 gz_statep state;
561
562 /* get internal structure */
563 if (file == NULL)
564 return 0;
@@ -618,13 +572,11 @@
572 /* return 1 if transparent, 0 if processing a gzip stream */
573 return state->direct;
574 }
575
576 /* -- see zlib.h -- */
577 int ZEXPORT gzclose_r(gzFile file) {
 
 
578 int ret, err;
579 gz_statep state;
580
581 /* get internal structure */
582 if (file == NULL)
583
--- compat/zlib/gzwrite.c
+++ compat/zlib/gzwrite.c
@@ -3,22 +3,14 @@
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55
66
#include "gzguts.h"
77
8
-/* Local functions */
9
-local int gz_init OF((gz_statep));
10
-local int gz_comp OF((gz_statep, int));
11
-local int gz_zero OF((gz_statep, z_off64_t));
12
-local z_size_t gz_write OF((gz_statep, voidpc, z_size_t));
13
-
148
/* Initialize state for writing a gzip file. Mark initialization by setting
159
state->size to non-zero. Return -1 on a memory allocation failure, or 0 on
1610
success. */
17
-local int gz_init(state)
18
- gz_statep state;
19
-{
11
+local int gz_init(gz_statep state) {
2012
int ret;
2113
z_streamp strm = &(state->strm);
2214
2315
/* allocate input buffer (double size for gzprintf) */
2416
state->in = (unsigned char *)malloc(state->want << 1);
@@ -68,14 +60,11 @@
6860
Return -1 if there is an error writing to the output file or if gz_init()
6961
fails to allocate memory, otherwise 0. flush is assumed to be a valid
7062
deflate() flush value. If flush is Z_FINISH, then the deflate() state is
7163
reset to start a new gzip stream. If gz->direct is true, then simply write
7264
to the output file without compressing, and ignore flush. */
73
-local int gz_comp(state, flush)
74
- gz_statep state;
75
- int flush;
76
-{
65
+local int gz_comp(gz_statep state, int flush) {
7766
int ret, writ;
7867
unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
7968
z_streamp strm = &(state->strm);
8069
8170
/* allocate memory if this is the first time through */
@@ -149,14 +138,11 @@
149138
return 0;
150139
}
151140
152141
/* Compress len zeros to output. Return -1 on a write error or memory
153142
allocation failure by gz_comp(), or 0 on success. */
154
-local int gz_zero(state, len)
155
- gz_statep state;
156
- z_off64_t len;
157
-{
143
+local int gz_zero(gz_statep state, z_off64_t len) {
158144
int first;
159145
unsigned n;
160146
z_streamp strm = &(state->strm);
161147
162148
/* consume whatever's left in the input buffer */
@@ -182,15 +168,11 @@
182168
return 0;
183169
}
184170
185171
/* Write len bytes from buf to file. Return the number of bytes written. If
186172
the returned value is less than len, then there was an error. */
187
-local z_size_t gz_write(state, buf, len)
188
- gz_statep state;
189
- voidpc buf;
190
- z_size_t len;
191
-{
173
+local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
192174
z_size_t put = len;
193175
194176
/* if len is zero, avoid unnecessary operations */
195177
if (len == 0)
196178
return 0;
@@ -250,15 +232,11 @@
250232
/* input was all buffered or compressed */
251233
return put;
252234
}
253235
254236
/* -- see zlib.h -- */
255
-int ZEXPORT gzwrite(file, buf, len)
256
- gzFile file;
257
- voidpc buf;
258
- unsigned len;
259
-{
237
+int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len) {
260238
gz_statep state;
261239
262240
/* get internal structure */
263241
if (file == NULL)
264242
return 0;
@@ -278,16 +256,12 @@
278256
/* write len bytes from buf (the return value will fit in an int) */
279257
return (int)gz_write(state, buf, len);
280258
}
281259
282260
/* -- see zlib.h -- */
283
-z_size_t ZEXPORT gzfwrite(buf, size, nitems, file)
284
- voidpc buf;
285
- z_size_t size;
286
- z_size_t nitems;
287
- gzFile file;
288
-{
261
+z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems,
262
+ gzFile file) {
289263
z_size_t len;
290264
gz_statep state;
291265
292266
/* get internal structure */
293267
if (file == NULL)
@@ -308,14 +282,11 @@
308282
/* write len bytes to buf, return the number of full items written */
309283
return len ? gz_write(state, buf, len) / size : 0;
310284
}
311285
312286
/* -- see zlib.h -- */
313
-int ZEXPORT gzputc(file, c)
314
- gzFile file;
315
- int c;
316
-{
287
+int ZEXPORT gzputc(gzFile file, int c) {
317288
unsigned have;
318289
unsigned char buf[1];
319290
gz_statep state;
320291
z_streamp strm;
321292
@@ -356,14 +327,11 @@
356327
return -1;
357328
return c & 0xff;
358329
}
359330
360331
/* -- see zlib.h -- */
361
-int ZEXPORT gzputs(file, s)
362
- gzFile file;
363
- const char *s;
364
-{
332
+int ZEXPORT gzputs(gzFile file, const char *s) {
365333
z_size_t len, put;
366334
gz_statep state;
367335
368336
/* get internal structure */
369337
if (file == NULL)
@@ -386,12 +354,11 @@
386354
387355
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
388356
#include <stdarg.h>
389357
390358
/* -- see zlib.h -- */
391
-int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
392
-{
359
+int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
393360
int len;
394361
unsigned left;
395362
char *next;
396363
gz_statep state;
397364
z_streamp strm;
@@ -458,12 +425,11 @@
458425
strm->avail_in = left;
459426
}
460427
return len;
461428
}
462429
463
-int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
464
-{
430
+int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) {
465431
va_list va;
466432
int ret;
467433
468434
va_start(va, format);
469435
ret = gzvprintf(file, format, va);
@@ -472,17 +438,14 @@
472438
}
473439
474440
#else /* !STDC && !Z_HAVE_STDARG_H */
475441
476442
/* -- see zlib.h -- */
477
-int ZEXPORTVA gzprintf(file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
478
- a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
479
- gzFile file;
480
- const char *format;
481
- int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
482
- a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
483
-{
443
+int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3,
444
+ int a4, int a5, int a6, int a7, int a8, int a9, int a10,
445
+ int a11, int a12, int a13, int a14, int a15, int a16,
446
+ int a17, int a18, int a19, int a20) {
484447
unsigned len, left;
485448
char *next;
486449
gz_statep state;
487450
z_streamp strm;
488451
@@ -560,14 +523,11 @@
560523
}
561524
562525
#endif
563526
564527
/* -- see zlib.h -- */
565
-int ZEXPORT gzflush(file, flush)
566
- gzFile file;
567
- int flush;
568
-{
528
+int ZEXPORT gzflush(gzFile file, int flush) {
569529
gz_statep state;
570530
571531
/* get internal structure */
572532
if (file == NULL)
573533
return Z_STREAM_ERROR;
@@ -592,15 +552,11 @@
592552
(void)gz_comp(state, flush);
593553
return state->err;
594554
}
595555
596556
/* -- see zlib.h -- */
597
-int ZEXPORT gzsetparams(file, level, strategy)
598
- gzFile file;
599
- int level;
600
- int strategy;
601
-{
557
+int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
602558
gz_statep state;
603559
z_streamp strm;
604560
605561
/* get internal structure */
606562
if (file == NULL)
@@ -607,11 +563,11 @@
607563
return Z_STREAM_ERROR;
608564
state = (gz_statep)file;
609565
strm = &(state->strm);
610566
611567
/* check that we're writing and that there's no error */
612
- if (state->mode != GZ_WRITE || state->err != Z_OK)
568
+ if (state->mode != GZ_WRITE || state->err != Z_OK || state->direct)
613569
return Z_STREAM_ERROR;
614570
615571
/* if no change is requested, then do nothing */
616572
if (level == state->level && strategy == state->strategy)
617573
return Z_OK;
@@ -634,13 +590,11 @@
634590
state->strategy = strategy;
635591
return Z_OK;
636592
}
637593
638594
/* -- see zlib.h -- */
639
-int ZEXPORT gzclose_w(file)
640
- gzFile file;
641
-{
595
+int ZEXPORT gzclose_w(gzFile file) {
642596
int ret = Z_OK;
643597
gz_statep state;
644598
645599
/* get internal structure */
646600
if (file == NULL)
647601
--- compat/zlib/gzwrite.c
+++ compat/zlib/gzwrite.c
@@ -3,22 +3,14 @@
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 #include "gzguts.h"
7
8 /* Local functions */
9 local int gz_init OF((gz_statep));
10 local int gz_comp OF((gz_statep, int));
11 local int gz_zero OF((gz_statep, z_off64_t));
12 local z_size_t gz_write OF((gz_statep, voidpc, z_size_t));
13
14 /* Initialize state for writing a gzip file. Mark initialization by setting
15 state->size to non-zero. Return -1 on a memory allocation failure, or 0 on
16 success. */
17 local int gz_init(state)
18 gz_statep state;
19 {
20 int ret;
21 z_streamp strm = &(state->strm);
22
23 /* allocate input buffer (double size for gzprintf) */
24 state->in = (unsigned char *)malloc(state->want << 1);
@@ -68,14 +60,11 @@
68 Return -1 if there is an error writing to the output file or if gz_init()
69 fails to allocate memory, otherwise 0. flush is assumed to be a valid
70 deflate() flush value. If flush is Z_FINISH, then the deflate() state is
71 reset to start a new gzip stream. If gz->direct is true, then simply write
72 to the output file without compressing, and ignore flush. */
73 local int gz_comp(state, flush)
74 gz_statep state;
75 int flush;
76 {
77 int ret, writ;
78 unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
79 z_streamp strm = &(state->strm);
80
81 /* allocate memory if this is the first time through */
@@ -149,14 +138,11 @@
149 return 0;
150 }
151
152 /* Compress len zeros to output. Return -1 on a write error or memory
153 allocation failure by gz_comp(), or 0 on success. */
154 local int gz_zero(state, len)
155 gz_statep state;
156 z_off64_t len;
157 {
158 int first;
159 unsigned n;
160 z_streamp strm = &(state->strm);
161
162 /* consume whatever's left in the input buffer */
@@ -182,15 +168,11 @@
182 return 0;
183 }
184
185 /* Write len bytes from buf to file. Return the number of bytes written. If
186 the returned value is less than len, then there was an error. */
187 local z_size_t gz_write(state, buf, len)
188 gz_statep state;
189 voidpc buf;
190 z_size_t len;
191 {
192 z_size_t put = len;
193
194 /* if len is zero, avoid unnecessary operations */
195 if (len == 0)
196 return 0;
@@ -250,15 +232,11 @@
250 /* input was all buffered or compressed */
251 return put;
252 }
253
254 /* -- see zlib.h -- */
255 int ZEXPORT gzwrite(file, buf, len)
256 gzFile file;
257 voidpc buf;
258 unsigned len;
259 {
260 gz_statep state;
261
262 /* get internal structure */
263 if (file == NULL)
264 return 0;
@@ -278,16 +256,12 @@
278 /* write len bytes from buf (the return value will fit in an int) */
279 return (int)gz_write(state, buf, len);
280 }
281
282 /* -- see zlib.h -- */
283 z_size_t ZEXPORT gzfwrite(buf, size, nitems, file)
284 voidpc buf;
285 z_size_t size;
286 z_size_t nitems;
287 gzFile file;
288 {
289 z_size_t len;
290 gz_statep state;
291
292 /* get internal structure */
293 if (file == NULL)
@@ -308,14 +282,11 @@
308 /* write len bytes to buf, return the number of full items written */
309 return len ? gz_write(state, buf, len) / size : 0;
310 }
311
312 /* -- see zlib.h -- */
313 int ZEXPORT gzputc(file, c)
314 gzFile file;
315 int c;
316 {
317 unsigned have;
318 unsigned char buf[1];
319 gz_statep state;
320 z_streamp strm;
321
@@ -356,14 +327,11 @@
356 return -1;
357 return c & 0xff;
358 }
359
360 /* -- see zlib.h -- */
361 int ZEXPORT gzputs(file, s)
362 gzFile file;
363 const char *s;
364 {
365 z_size_t len, put;
366 gz_statep state;
367
368 /* get internal structure */
369 if (file == NULL)
@@ -386,12 +354,11 @@
386
387 #if defined(STDC) || defined(Z_HAVE_STDARG_H)
388 #include <stdarg.h>
389
390 /* -- see zlib.h -- */
391 int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
392 {
393 int len;
394 unsigned left;
395 char *next;
396 gz_statep state;
397 z_streamp strm;
@@ -458,12 +425,11 @@
458 strm->avail_in = left;
459 }
460 return len;
461 }
462
463 int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
464 {
465 va_list va;
466 int ret;
467
468 va_start(va, format);
469 ret = gzvprintf(file, format, va);
@@ -472,17 +438,14 @@
472 }
473
474 #else /* !STDC && !Z_HAVE_STDARG_H */
475
476 /* -- see zlib.h -- */
477 int ZEXPORTVA gzprintf(file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
478 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
479 gzFile file;
480 const char *format;
481 int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
482 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
483 {
484 unsigned len, left;
485 char *next;
486 gz_statep state;
487 z_streamp strm;
488
@@ -560,14 +523,11 @@
560 }
561
562 #endif
563
564 /* -- see zlib.h -- */
565 int ZEXPORT gzflush(file, flush)
566 gzFile file;
567 int flush;
568 {
569 gz_statep state;
570
571 /* get internal structure */
572 if (file == NULL)
573 return Z_STREAM_ERROR;
@@ -592,15 +552,11 @@
592 (void)gz_comp(state, flush);
593 return state->err;
594 }
595
596 /* -- see zlib.h -- */
597 int ZEXPORT gzsetparams(file, level, strategy)
598 gzFile file;
599 int level;
600 int strategy;
601 {
602 gz_statep state;
603 z_streamp strm;
604
605 /* get internal structure */
606 if (file == NULL)
@@ -607,11 +563,11 @@
607 return Z_STREAM_ERROR;
608 state = (gz_statep)file;
609 strm = &(state->strm);
610
611 /* check that we're writing and that there's no error */
612 if (state->mode != GZ_WRITE || state->err != Z_OK)
613 return Z_STREAM_ERROR;
614
615 /* if no change is requested, then do nothing */
616 if (level == state->level && strategy == state->strategy)
617 return Z_OK;
@@ -634,13 +590,11 @@
634 state->strategy = strategy;
635 return Z_OK;
636 }
637
638 /* -- see zlib.h -- */
639 int ZEXPORT gzclose_w(file)
640 gzFile file;
641 {
642 int ret = Z_OK;
643 gz_statep state;
644
645 /* get internal structure */
646 if (file == NULL)
647
--- compat/zlib/gzwrite.c
+++ compat/zlib/gzwrite.c
@@ -3,22 +3,14 @@
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 #include "gzguts.h"
7
 
 
 
 
 
 
8 /* Initialize state for writing a gzip file. Mark initialization by setting
9 state->size to non-zero. Return -1 on a memory allocation failure, or 0 on
10 success. */
11 local int gz_init(gz_statep state) {
 
 
12 int ret;
13 z_streamp strm = &(state->strm);
14
15 /* allocate input buffer (double size for gzprintf) */
16 state->in = (unsigned char *)malloc(state->want << 1);
@@ -68,14 +60,11 @@
60 Return -1 if there is an error writing to the output file or if gz_init()
61 fails to allocate memory, otherwise 0. flush is assumed to be a valid
62 deflate() flush value. If flush is Z_FINISH, then the deflate() state is
63 reset to start a new gzip stream. If gz->direct is true, then simply write
64 to the output file without compressing, and ignore flush. */
65 local int gz_comp(gz_statep state, int flush) {
 
 
 
66 int ret, writ;
67 unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
68 z_streamp strm = &(state->strm);
69
70 /* allocate memory if this is the first time through */
@@ -149,14 +138,11 @@
138 return 0;
139 }
140
141 /* Compress len zeros to output. Return -1 on a write error or memory
142 allocation failure by gz_comp(), or 0 on success. */
143 local int gz_zero(gz_statep state, z_off64_t len) {
 
 
 
144 int first;
145 unsigned n;
146 z_streamp strm = &(state->strm);
147
148 /* consume whatever's left in the input buffer */
@@ -182,15 +168,11 @@
168 return 0;
169 }
170
171 /* Write len bytes from buf to file. Return the number of bytes written. If
172 the returned value is less than len, then there was an error. */
173 local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
 
 
 
 
174 z_size_t put = len;
175
176 /* if len is zero, avoid unnecessary operations */
177 if (len == 0)
178 return 0;
@@ -250,15 +232,11 @@
232 /* input was all buffered or compressed */
233 return put;
234 }
235
236 /* -- see zlib.h -- */
237 int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len) {
 
 
 
 
238 gz_statep state;
239
240 /* get internal structure */
241 if (file == NULL)
242 return 0;
@@ -278,16 +256,12 @@
256 /* write len bytes from buf (the return value will fit in an int) */
257 return (int)gz_write(state, buf, len);
258 }
259
260 /* -- see zlib.h -- */
261 z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems,
262 gzFile file) {
 
 
 
 
263 z_size_t len;
264 gz_statep state;
265
266 /* get internal structure */
267 if (file == NULL)
@@ -308,14 +282,11 @@
282 /* write len bytes to buf, return the number of full items written */
283 return len ? gz_write(state, buf, len) / size : 0;
284 }
285
286 /* -- see zlib.h -- */
287 int ZEXPORT gzputc(gzFile file, int c) {
 
 
 
288 unsigned have;
289 unsigned char buf[1];
290 gz_statep state;
291 z_streamp strm;
292
@@ -356,14 +327,11 @@
327 return -1;
328 return c & 0xff;
329 }
330
331 /* -- see zlib.h -- */
332 int ZEXPORT gzputs(gzFile file, const char *s) {
 
 
 
333 z_size_t len, put;
334 gz_statep state;
335
336 /* get internal structure */
337 if (file == NULL)
@@ -386,12 +354,11 @@
354
355 #if defined(STDC) || defined(Z_HAVE_STDARG_H)
356 #include <stdarg.h>
357
358 /* -- see zlib.h -- */
359 int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
 
360 int len;
361 unsigned left;
362 char *next;
363 gz_statep state;
364 z_streamp strm;
@@ -458,12 +425,11 @@
425 strm->avail_in = left;
426 }
427 return len;
428 }
429
430 int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) {
 
431 va_list va;
432 int ret;
433
434 va_start(va, format);
435 ret = gzvprintf(file, format, va);
@@ -472,17 +438,14 @@
438 }
439
440 #else /* !STDC && !Z_HAVE_STDARG_H */
441
442 /* -- see zlib.h -- */
443 int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3,
444 int a4, int a5, int a6, int a7, int a8, int a9, int a10,
445 int a11, int a12, int a13, int a14, int a15, int a16,
446 int a17, int a18, int a19, int a20) {
 
 
 
447 unsigned len, left;
448 char *next;
449 gz_statep state;
450 z_streamp strm;
451
@@ -560,14 +523,11 @@
523 }
524
525 #endif
526
527 /* -- see zlib.h -- */
528 int ZEXPORT gzflush(gzFile file, int flush) {
 
 
 
529 gz_statep state;
530
531 /* get internal structure */
532 if (file == NULL)
533 return Z_STREAM_ERROR;
@@ -592,15 +552,11 @@
552 (void)gz_comp(state, flush);
553 return state->err;
554 }
555
556 /* -- see zlib.h -- */
557 int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
 
 
 
 
558 gz_statep state;
559 z_streamp strm;
560
561 /* get internal structure */
562 if (file == NULL)
@@ -607,11 +563,11 @@
563 return Z_STREAM_ERROR;
564 state = (gz_statep)file;
565 strm = &(state->strm);
566
567 /* check that we're writing and that there's no error */
568 if (state->mode != GZ_WRITE || state->err != Z_OK || state->direct)
569 return Z_STREAM_ERROR;
570
571 /* if no change is requested, then do nothing */
572 if (level == state->level && strategy == state->strategy)
573 return Z_OK;
@@ -634,13 +590,11 @@
590 state->strategy = strategy;
591 return Z_OK;
592 }
593
594 /* -- see zlib.h -- */
595 int ZEXPORT gzclose_w(gzFile file) {
 
 
596 int ret = Z_OK;
597 gz_statep state;
598
599 /* get internal structure */
600 if (file == NULL)
601
--- compat/zlib/infback.c
+++ compat/zlib/infback.c
@@ -13,27 +13,20 @@
1313
#include "zutil.h"
1414
#include "inftrees.h"
1515
#include "inflate.h"
1616
#include "inffast.h"
1717
18
-/* function prototypes */
19
-local void fixedtables OF((struct inflate_state FAR *state));
20
-
2118
/*
2219
strm provides memory allocation functions in zalloc and zfree, or
2320
Z_NULL to use the library memory allocation functions.
2421
2522
windowBits is in the range 8..15, and window is a user-supplied
2623
window and output buffer that is 2**windowBits bytes.
2724
*/
28
-int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
29
-z_streamp strm;
30
-int windowBits;
31
-unsigned char FAR *window;
32
-const char *version;
33
-int stream_size;
34
-{
25
+int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
26
+ unsigned char FAR *window, const char *version,
27
+ int stream_size) {
3528
struct inflate_state FAR *state;
3629
3730
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
3831
stream_size != (int)(sizeof(z_stream)))
3932
return Z_VERSION_ERROR;
@@ -78,13 +71,11 @@
7871
thereafter. This reduces the size of the code by about 2K bytes, in
7972
exchange for a little execution time. However, BUILDFIXED should not be
8073
used for threaded applications, since the rewriting of the tables and virgin
8174
may not be thread-safe.
8275
*/
83
-local void fixedtables(state)
84
-struct inflate_state FAR *state;
85
-{
76
+local void fixedtables(struct inflate_state FAR *state) {
8677
#ifdef BUILDFIXED
8778
static int virgin = 1;
8879
static code *lenfix, *distfix;
8980
static code fixed[544];
9081
@@ -246,17 +237,12 @@
246237
returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
247238
error, or Z_MEM_ERROR if it could not allocate memory for the state.
248239
inflateBack() can also return Z_STREAM_ERROR if the input parameters
249240
are not correct, i.e. strm is Z_NULL or the state was not initialized.
250241
*/
251
-int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
252
-z_streamp strm;
253
-in_func in;
254
-void FAR *in_desc;
255
-out_func out;
256
-void FAR *out_desc;
257
-{
242
+int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
243
+ out_func out, void FAR *out_desc) {
258244
struct inflate_state FAR *state;
259245
z_const unsigned char FAR *next; /* next input */
260246
unsigned char FAR *put; /* next output */
261247
unsigned have, left; /* available input and output */
262248
unsigned long hold; /* bit buffer */
@@ -630,15 +616,13 @@
630616
strm->next_in = next;
631617
strm->avail_in = have;
632618
return ret;
633619
}
634620
635
-int ZEXPORT inflateBackEnd(strm)
636
-z_streamp strm;
637
-{
621
+int ZEXPORT inflateBackEnd(z_streamp strm) {
638622
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
639623
return Z_STREAM_ERROR;
640624
ZFREE(strm, strm->state);
641625
strm->state = Z_NULL;
642626
Tracev((stderr, "inflate: end\n"));
643627
return Z_OK;
644628
}
645629
--- compat/zlib/infback.c
+++ compat/zlib/infback.c
@@ -13,27 +13,20 @@
13 #include "zutil.h"
14 #include "inftrees.h"
15 #include "inflate.h"
16 #include "inffast.h"
17
18 /* function prototypes */
19 local void fixedtables OF((struct inflate_state FAR *state));
20
21 /*
22 strm provides memory allocation functions in zalloc and zfree, or
23 Z_NULL to use the library memory allocation functions.
24
25 windowBits is in the range 8..15, and window is a user-supplied
26 window and output buffer that is 2**windowBits bytes.
27 */
28 int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
29 z_streamp strm;
30 int windowBits;
31 unsigned char FAR *window;
32 const char *version;
33 int stream_size;
34 {
35 struct inflate_state FAR *state;
36
37 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
38 stream_size != (int)(sizeof(z_stream)))
39 return Z_VERSION_ERROR;
@@ -78,13 +71,11 @@
78 thereafter. This reduces the size of the code by about 2K bytes, in
79 exchange for a little execution time. However, BUILDFIXED should not be
80 used for threaded applications, since the rewriting of the tables and virgin
81 may not be thread-safe.
82 */
83 local void fixedtables(state)
84 struct inflate_state FAR *state;
85 {
86 #ifdef BUILDFIXED
87 static int virgin = 1;
88 static code *lenfix, *distfix;
89 static code fixed[544];
90
@@ -246,17 +237,12 @@
246 returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
247 error, or Z_MEM_ERROR if it could not allocate memory for the state.
248 inflateBack() can also return Z_STREAM_ERROR if the input parameters
249 are not correct, i.e. strm is Z_NULL or the state was not initialized.
250 */
251 int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
252 z_streamp strm;
253 in_func in;
254 void FAR *in_desc;
255 out_func out;
256 void FAR *out_desc;
257 {
258 struct inflate_state FAR *state;
259 z_const unsigned char FAR *next; /* next input */
260 unsigned char FAR *put; /* next output */
261 unsigned have, left; /* available input and output */
262 unsigned long hold; /* bit buffer */
@@ -630,15 +616,13 @@
630 strm->next_in = next;
631 strm->avail_in = have;
632 return ret;
633 }
634
635 int ZEXPORT inflateBackEnd(strm)
636 z_streamp strm;
637 {
638 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
639 return Z_STREAM_ERROR;
640 ZFREE(strm, strm->state);
641 strm->state = Z_NULL;
642 Tracev((stderr, "inflate: end\n"));
643 return Z_OK;
644 }
645
--- compat/zlib/infback.c
+++ compat/zlib/infback.c
@@ -13,27 +13,20 @@
13 #include "zutil.h"
14 #include "inftrees.h"
15 #include "inflate.h"
16 #include "inffast.h"
17
 
 
 
18 /*
19 strm provides memory allocation functions in zalloc and zfree, or
20 Z_NULL to use the library memory allocation functions.
21
22 windowBits is in the range 8..15, and window is a user-supplied
23 window and output buffer that is 2**windowBits bytes.
24 */
25 int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
26 unsigned char FAR *window, const char *version,
27 int stream_size) {
 
 
 
 
28 struct inflate_state FAR *state;
29
30 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
31 stream_size != (int)(sizeof(z_stream)))
32 return Z_VERSION_ERROR;
@@ -78,13 +71,11 @@
71 thereafter. This reduces the size of the code by about 2K bytes, in
72 exchange for a little execution time. However, BUILDFIXED should not be
73 used for threaded applications, since the rewriting of the tables and virgin
74 may not be thread-safe.
75 */
76 local void fixedtables(struct inflate_state FAR *state) {
 
 
77 #ifdef BUILDFIXED
78 static int virgin = 1;
79 static code *lenfix, *distfix;
80 static code fixed[544];
81
@@ -246,17 +237,12 @@
237 returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
238 error, or Z_MEM_ERROR if it could not allocate memory for the state.
239 inflateBack() can also return Z_STREAM_ERROR if the input parameters
240 are not correct, i.e. strm is Z_NULL or the state was not initialized.
241 */
242 int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
243 out_func out, void FAR *out_desc) {
 
 
 
 
 
244 struct inflate_state FAR *state;
245 z_const unsigned char FAR *next; /* next input */
246 unsigned char FAR *put; /* next output */
247 unsigned have, left; /* available input and output */
248 unsigned long hold; /* bit buffer */
@@ -630,15 +616,13 @@
616 strm->next_in = next;
617 strm->avail_in = have;
618 return ret;
619 }
620
621 int ZEXPORT inflateBackEnd(z_streamp strm) {
 
 
622 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
623 return Z_STREAM_ERROR;
624 ZFREE(strm, strm->state);
625 strm->state = Z_NULL;
626 Tracev((stderr, "inflate: end\n"));
627 return Z_OK;
628 }
629
--- compat/zlib/inffast.c
+++ compat/zlib/inffast.c
@@ -45,14 +45,11 @@
4545
- The maximum bytes that a single length/distance pair can output is 258
4646
bytes, which is the maximum length that can be coded. inflate_fast()
4747
requires strm->avail_out >= 258 for each loop to avoid checking for
4848
output space.
4949
*/
50
-void ZLIB_INTERNAL inflate_fast(strm, start)
51
-z_streamp strm;
52
-unsigned start; /* inflate()'s starting value for strm->avail_out */
53
-{
50
+void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
5451
struct inflate_state FAR *state;
5552
z_const unsigned char FAR *in; /* local strm->next_in */
5653
z_const unsigned char FAR *last; /* have enough input while in < last */
5754
unsigned char FAR *out; /* local strm->next_out */
5855
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
5956
--- compat/zlib/inffast.c
+++ compat/zlib/inffast.c
@@ -45,14 +45,11 @@
45 - The maximum bytes that a single length/distance pair can output is 258
46 bytes, which is the maximum length that can be coded. inflate_fast()
47 requires strm->avail_out >= 258 for each loop to avoid checking for
48 output space.
49 */
50 void ZLIB_INTERNAL inflate_fast(strm, start)
51 z_streamp strm;
52 unsigned start; /* inflate()'s starting value for strm->avail_out */
53 {
54 struct inflate_state FAR *state;
55 z_const unsigned char FAR *in; /* local strm->next_in */
56 z_const unsigned char FAR *last; /* have enough input while in < last */
57 unsigned char FAR *out; /* local strm->next_out */
58 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
59
--- compat/zlib/inffast.c
+++ compat/zlib/inffast.c
@@ -45,14 +45,11 @@
45 - The maximum bytes that a single length/distance pair can output is 258
46 bytes, which is the maximum length that can be coded. inflate_fast()
47 requires strm->avail_out >= 258 for each loop to avoid checking for
48 output space.
49 */
50 void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
 
 
 
51 struct inflate_state FAR *state;
52 z_const unsigned char FAR *in; /* local strm->next_in */
53 z_const unsigned char FAR *last; /* have enough input while in < last */
54 unsigned char FAR *out; /* local strm->next_out */
55 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
56
--- compat/zlib/inffast.h
+++ compat/zlib/inffast.h
@@ -6,6 +6,6 @@
66
/* WARNING: this file should *not* be used by applications. It is
77
part of the implementation of the compression library and is
88
subject to change. Applications should only use zlib.h.
99
*/
1010
11
-void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start));
11
+void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start);
1212
--- compat/zlib/inffast.h
+++ compat/zlib/inffast.h
@@ -6,6 +6,6 @@
6 /* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11 void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start));
12
--- compat/zlib/inffast.h
+++ compat/zlib/inffast.h
@@ -6,6 +6,6 @@
6 /* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11 void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start);
12
--- compat/zlib/inflate.c
+++ compat/zlib/inflate.c
@@ -89,24 +89,11 @@
8989
# ifndef BUILDFIXED
9090
# define BUILDFIXED
9191
# endif
9292
#endif
9393
94
-/* function prototypes */
95
-local int inflateStateCheck OF((z_streamp strm));
96
-local void fixedtables OF((struct inflate_state FAR *state));
97
-local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
98
- unsigned copy));
99
-#ifdef BUILDFIXED
100
- void makefixed OF((void));
101
-#endif
102
-local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
103
- unsigned len));
104
-
105
-local int inflateStateCheck(strm)
106
-z_streamp strm;
107
-{
94
+local int inflateStateCheck(z_streamp strm) {
10895
struct inflate_state FAR *state;
10996
if (strm == Z_NULL ||
11097
strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
11198
return 1;
11299
state = (struct inflate_state FAR *)strm->state;
@@ -114,13 +101,11 @@
114101
state->mode < HEAD || state->mode > SYNC)
115102
return 1;
116103
return 0;
117104
}
118105
119
-int ZEXPORT inflateResetKeep(strm)
120
-z_streamp strm;
121
-{
106
+int ZEXPORT inflateResetKeep(z_streamp strm) {
122107
struct inflate_state FAR *state;
123108
124109
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
125110
state = (struct inflate_state FAR *)strm->state;
126111
strm->total_in = strm->total_out = state->total = 0;
@@ -140,13 +125,11 @@
140125
state->back = -1;
141126
Tracev((stderr, "inflate: reset\n"));
142127
return Z_OK;
143128
}
144129
145
-int ZEXPORT inflateReset(strm)
146
-z_streamp strm;
147
-{
130
+int ZEXPORT inflateReset(z_streamp strm) {
148131
struct inflate_state FAR *state;
149132
150133
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
151134
state = (struct inflate_state FAR *)strm->state;
152135
state->wsize = 0;
@@ -153,14 +136,11 @@
153136
state->whave = 0;
154137
state->wnext = 0;
155138
return inflateResetKeep(strm);
156139
}
157140
158
-int ZEXPORT inflateReset2(strm, windowBits)
159
-z_streamp strm;
160
-int windowBits;
161
-{
141
+int ZEXPORT inflateReset2(z_streamp strm, int windowBits) {
162142
int wrap;
163143
struct inflate_state FAR *state;
164144
165145
/* get the state */
166146
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -193,16 +173,12 @@
193173
state->wrap = wrap;
194174
state->wbits = (unsigned)windowBits;
195175
return inflateReset(strm);
196176
}
197177
198
-int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
199
-z_streamp strm;
200
-int windowBits;
201
-const char *version;
202
-int stream_size;
203
-{
178
+int ZEXPORT inflateInit2_(z_streamp strm, int windowBits,
179
+ const char *version, int stream_size) {
204180
int ret;
205181
struct inflate_state FAR *state;
206182
207183
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
208184
stream_size != (int)(sizeof(z_stream)))
@@ -237,26 +213,21 @@
237213
strm->state = Z_NULL;
238214
}
239215
return ret;
240216
}
241217
242
-int ZEXPORT inflateInit_(strm, version, stream_size)
243
-z_streamp strm;
244
-const char *version;
245
-int stream_size;
246
-{
218
+int ZEXPORT inflateInit_(z_streamp strm, const char *version,
219
+ int stream_size) {
247220
return inflateInit2_(strm, DEF_WBITS, version, stream_size);
248221
}
249222
250
-int ZEXPORT inflatePrime(strm, bits, value)
251
-z_streamp strm;
252
-int bits;
253
-int value;
254
-{
223
+int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) {
255224
struct inflate_state FAR *state;
256225
257226
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
227
+ if (bits == 0)
228
+ return Z_OK;
258229
state = (struct inflate_state FAR *)strm->state;
259230
if (bits < 0) {
260231
state->hold = 0;
261232
state->bits = 0;
262233
return Z_OK;
@@ -276,13 +247,11 @@
276247
thereafter. This reduces the size of the code by about 2K bytes, in
277248
exchange for a little execution time. However, BUILDFIXED should not be
278249
used for threaded applications, since the rewriting of the tables and virgin
279250
may not be thread-safe.
280251
*/
281
-local void fixedtables(state)
282
-struct inflate_state FAR *state;
283
-{
252
+local void fixedtables(struct inflate_state FAR *state) {
284253
#ifdef BUILDFIXED
285254
static int virgin = 1;
286255
static code *lenfix, *distfix;
287256
static code fixed[544];
288257
@@ -340,11 +309,11 @@
340309
341310
Then that can be linked with zlib built with MAKEFIXED defined and run:
342311
343312
a.out > inffixed.h
344313
*/
345
-void makefixed()
314
+void makefixed(void)
346315
{
347316
unsigned low, size;
348317
struct inflate_state state;
349318
350319
fixedtables(&state);
@@ -394,15 +363,11 @@
394363
advantage, since only the last 32K of output is copied to the sliding window
395364
upon return from inflate(), and since all distances after the first 32K of
396365
output will fall in the output data, making match copies simpler and faster.
397366
The advantage may be dependent on the size of the processor's data caches.
398367
*/
399
-local int updatewindow(strm, end, copy)
400
-z_streamp strm;
401
-const Bytef *end;
402
-unsigned copy;
403
-{
368
+local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) {
404369
struct inflate_state FAR *state;
405370
unsigned dist;
406371
407372
state = (struct inflate_state FAR *)strm->state;
408373
@@ -620,14 +585,11 @@
620585
stream available. So the only thing the flush parameter actually does is:
621586
when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
622587
will return Z_BUF_ERROR if it has not reached the end of the stream.
623588
*/
624589
625
-int ZEXPORT inflate(strm, flush)
626
-z_streamp strm;
627
-int flush;
628
-{
590
+int ZEXPORT inflate(z_streamp strm, int flush) {
629591
struct inflate_state FAR *state;
630592
z_const unsigned char FAR *next; /* next input */
631593
unsigned char FAR *put; /* next output */
632594
unsigned have, left; /* available input and output */
633595
unsigned long hold; /* bit buffer */
@@ -1299,13 +1261,11 @@
12991261
if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
13001262
ret = Z_BUF_ERROR;
13011263
return ret;
13021264
}
13031265
1304
-int ZEXPORT inflateEnd(strm)
1305
-z_streamp strm;
1306
-{
1266
+int ZEXPORT inflateEnd(z_streamp strm) {
13071267
struct inflate_state FAR *state;
13081268
if (inflateStateCheck(strm))
13091269
return Z_STREAM_ERROR;
13101270
state = (struct inflate_state FAR *)strm->state;
13111271
if (state->window != Z_NULL) ZFREE(strm, state->window);
@@ -1313,15 +1273,12 @@
13131273
strm->state = Z_NULL;
13141274
Tracev((stderr, "inflate: end\n"));
13151275
return Z_OK;
13161276
}
13171277
1318
-int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength)
1319
-z_streamp strm;
1320
-Bytef *dictionary;
1321
-uInt *dictLength;
1322
-{
1278
+int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary,
1279
+ uInt *dictLength) {
13231280
struct inflate_state FAR *state;
13241281
13251282
/* check state */
13261283
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
13271284
state = (struct inflate_state FAR *)strm->state;
@@ -1336,15 +1293,12 @@
13361293
if (dictLength != Z_NULL)
13371294
*dictLength = state->whave;
13381295
return Z_OK;
13391296
}
13401297
1341
-int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
1342
-z_streamp strm;
1343
-const Bytef *dictionary;
1344
-uInt dictLength;
1345
-{
1298
+int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
1299
+ uInt dictLength) {
13461300
struct inflate_state FAR *state;
13471301
unsigned long dictid;
13481302
int ret;
13491303
13501304
/* check state */
@@ -1371,14 +1325,11 @@
13711325
state->havedict = 1;
13721326
Tracev((stderr, "inflate: dictionary set\n"));
13731327
return Z_OK;
13741328
}
13751329
1376
-int ZEXPORT inflateGetHeader(strm, head)
1377
-z_streamp strm;
1378
-gz_headerp head;
1379
-{
1330
+int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) {
13801331
struct inflate_state FAR *state;
13811332
13821333
/* check state */
13831334
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
13841335
state = (struct inflate_state FAR *)strm->state;
@@ -1399,15 +1350,12 @@
13991350
pattern. If *have is less than four, then the pattern has not been found
14001351
yet and the return value is len. In the latter case, syncsearch() can be
14011352
called again with more data and the *have state. *have is initialized to
14021353
zero for the first call.
14031354
*/
1404
-local unsigned syncsearch(have, buf, len)
1405
-unsigned FAR *have;
1406
-const unsigned char FAR *buf;
1407
-unsigned len;
1408
-{
1355
+local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf,
1356
+ unsigned len) {
14091357
unsigned got;
14101358
unsigned next;
14111359
14121360
got = *have;
14131361
next = 0;
@@ -1422,13 +1370,11 @@
14221370
}
14231371
*have = got;
14241372
return next;
14251373
}
14261374
1427
-int ZEXPORT inflateSync(strm)
1428
-z_streamp strm;
1429
-{
1375
+int ZEXPORT inflateSync(z_streamp strm) {
14301376
unsigned len; /* number of bytes to look at or looked at */
14311377
int flags; /* temporary to save header status */
14321378
unsigned long in, out; /* temporary to save total_in and total_out */
14331379
unsigned char buf[4]; /* to restore bit buffer to byte string */
14341380
struct inflate_state FAR *state;
@@ -1480,24 +1426,19 @@
14801426
implementation to provide an additional safety check. PPP uses
14811427
Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored
14821428
block. When decompressing, PPP checks that at the end of input packet,
14831429
inflate is waiting for these length bytes.
14841430
*/
1485
-int ZEXPORT inflateSyncPoint(strm)
1486
-z_streamp strm;
1487
-{
1431
+int ZEXPORT inflateSyncPoint(z_streamp strm) {
14881432
struct inflate_state FAR *state;
14891433
14901434
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
14911435
state = (struct inflate_state FAR *)strm->state;
14921436
return state->mode == STORED && state->bits == 0;
14931437
}
14941438
1495
-int ZEXPORT inflateCopy(dest, source)
1496
-z_streamp dest;
1497
-z_streamp source;
1498
-{
1439
+int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
14991440
struct inflate_state FAR *state;
15001441
struct inflate_state FAR *copy;
15011442
unsigned char FAR *window;
15021443
unsigned wsize;
15031444
@@ -1537,14 +1478,11 @@
15371478
copy->window = window;
15381479
dest->state = (struct internal_state FAR *)copy;
15391480
return Z_OK;
15401481
}
15411482
1542
-int ZEXPORT inflateUndermine(strm, subvert)
1543
-z_streamp strm;
1544
-int subvert;
1545
-{
1483
+int ZEXPORT inflateUndermine(z_streamp strm, int subvert) {
15461484
struct inflate_state FAR *state;
15471485
15481486
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
15491487
state = (struct inflate_state FAR *)strm->state;
15501488
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
@@ -1555,14 +1493,11 @@
15551493
state->sane = 1;
15561494
return Z_DATA_ERROR;
15571495
#endif
15581496
}
15591497
1560
-int ZEXPORT inflateValidate(strm, check)
1561
-z_streamp strm;
1562
-int check;
1563
-{
1498
+int ZEXPORT inflateValidate(z_streamp strm, int check) {
15641499
struct inflate_state FAR *state;
15651500
15661501
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
15671502
state = (struct inflate_state FAR *)strm->state;
15681503
if (check && state->wrap)
@@ -1570,13 +1505,11 @@
15701505
else
15711506
state->wrap &= ~4;
15721507
return Z_OK;
15731508
}
15741509
1575
-long ZEXPORT inflateMark(strm)
1576
-z_streamp strm;
1577
-{
1510
+long ZEXPORT inflateMark(z_streamp strm) {
15781511
struct inflate_state FAR *state;
15791512
15801513
if (inflateStateCheck(strm))
15811514
return -(1L << 16);
15821515
state = (struct inflate_state FAR *)strm->state;
@@ -1583,13 +1516,11 @@
15831516
return (long)(((unsigned long)((long)state->back)) << 16) +
15841517
(state->mode == COPY ? state->length :
15851518
(state->mode == MATCH ? state->was - state->length : 0));
15861519
}
15871520
1588
-unsigned long ZEXPORT inflateCodesUsed(strm)
1589
-z_streamp strm;
1590
-{
1521
+unsigned long ZEXPORT inflateCodesUsed(z_streamp strm) {
15911522
struct inflate_state FAR *state;
15921523
if (inflateStateCheck(strm)) return (unsigned long)-1;
15931524
state = (struct inflate_state FAR *)strm->state;
15941525
return (unsigned long)(state->next - state->codes);
15951526
}
15961527
--- compat/zlib/inflate.c
+++ compat/zlib/inflate.c
@@ -89,24 +89,11 @@
89 # ifndef BUILDFIXED
90 # define BUILDFIXED
91 # endif
92 #endif
93
94 /* function prototypes */
95 local int inflateStateCheck OF((z_streamp strm));
96 local void fixedtables OF((struct inflate_state FAR *state));
97 local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
98 unsigned copy));
99 #ifdef BUILDFIXED
100 void makefixed OF((void));
101 #endif
102 local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
103 unsigned len));
104
105 local int inflateStateCheck(strm)
106 z_streamp strm;
107 {
108 struct inflate_state FAR *state;
109 if (strm == Z_NULL ||
110 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
111 return 1;
112 state = (struct inflate_state FAR *)strm->state;
@@ -114,13 +101,11 @@
114 state->mode < HEAD || state->mode > SYNC)
115 return 1;
116 return 0;
117 }
118
119 int ZEXPORT inflateResetKeep(strm)
120 z_streamp strm;
121 {
122 struct inflate_state FAR *state;
123
124 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
125 state = (struct inflate_state FAR *)strm->state;
126 strm->total_in = strm->total_out = state->total = 0;
@@ -140,13 +125,11 @@
140 state->back = -1;
141 Tracev((stderr, "inflate: reset\n"));
142 return Z_OK;
143 }
144
145 int ZEXPORT inflateReset(strm)
146 z_streamp strm;
147 {
148 struct inflate_state FAR *state;
149
150 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
151 state = (struct inflate_state FAR *)strm->state;
152 state->wsize = 0;
@@ -153,14 +136,11 @@
153 state->whave = 0;
154 state->wnext = 0;
155 return inflateResetKeep(strm);
156 }
157
158 int ZEXPORT inflateReset2(strm, windowBits)
159 z_streamp strm;
160 int windowBits;
161 {
162 int wrap;
163 struct inflate_state FAR *state;
164
165 /* get the state */
166 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -193,16 +173,12 @@
193 state->wrap = wrap;
194 state->wbits = (unsigned)windowBits;
195 return inflateReset(strm);
196 }
197
198 int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
199 z_streamp strm;
200 int windowBits;
201 const char *version;
202 int stream_size;
203 {
204 int ret;
205 struct inflate_state FAR *state;
206
207 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
208 stream_size != (int)(sizeof(z_stream)))
@@ -237,26 +213,21 @@
237 strm->state = Z_NULL;
238 }
239 return ret;
240 }
241
242 int ZEXPORT inflateInit_(strm, version, stream_size)
243 z_streamp strm;
244 const char *version;
245 int stream_size;
246 {
247 return inflateInit2_(strm, DEF_WBITS, version, stream_size);
248 }
249
250 int ZEXPORT inflatePrime(strm, bits, value)
251 z_streamp strm;
252 int bits;
253 int value;
254 {
255 struct inflate_state FAR *state;
256
257 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
 
 
258 state = (struct inflate_state FAR *)strm->state;
259 if (bits < 0) {
260 state->hold = 0;
261 state->bits = 0;
262 return Z_OK;
@@ -276,13 +247,11 @@
276 thereafter. This reduces the size of the code by about 2K bytes, in
277 exchange for a little execution time. However, BUILDFIXED should not be
278 used for threaded applications, since the rewriting of the tables and virgin
279 may not be thread-safe.
280 */
281 local void fixedtables(state)
282 struct inflate_state FAR *state;
283 {
284 #ifdef BUILDFIXED
285 static int virgin = 1;
286 static code *lenfix, *distfix;
287 static code fixed[544];
288
@@ -340,11 +309,11 @@
340
341 Then that can be linked with zlib built with MAKEFIXED defined and run:
342
343 a.out > inffixed.h
344 */
345 void makefixed()
346 {
347 unsigned low, size;
348 struct inflate_state state;
349
350 fixedtables(&state);
@@ -394,15 +363,11 @@
394 advantage, since only the last 32K of output is copied to the sliding window
395 upon return from inflate(), and since all distances after the first 32K of
396 output will fall in the output data, making match copies simpler and faster.
397 The advantage may be dependent on the size of the processor's data caches.
398 */
399 local int updatewindow(strm, end, copy)
400 z_streamp strm;
401 const Bytef *end;
402 unsigned copy;
403 {
404 struct inflate_state FAR *state;
405 unsigned dist;
406
407 state = (struct inflate_state FAR *)strm->state;
408
@@ -620,14 +585,11 @@
620 stream available. So the only thing the flush parameter actually does is:
621 when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
622 will return Z_BUF_ERROR if it has not reached the end of the stream.
623 */
624
625 int ZEXPORT inflate(strm, flush)
626 z_streamp strm;
627 int flush;
628 {
629 struct inflate_state FAR *state;
630 z_const unsigned char FAR *next; /* next input */
631 unsigned char FAR *put; /* next output */
632 unsigned have, left; /* available input and output */
633 unsigned long hold; /* bit buffer */
@@ -1299,13 +1261,11 @@
1299 if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
1300 ret = Z_BUF_ERROR;
1301 return ret;
1302 }
1303
1304 int ZEXPORT inflateEnd(strm)
1305 z_streamp strm;
1306 {
1307 struct inflate_state FAR *state;
1308 if (inflateStateCheck(strm))
1309 return Z_STREAM_ERROR;
1310 state = (struct inflate_state FAR *)strm->state;
1311 if (state->window != Z_NULL) ZFREE(strm, state->window);
@@ -1313,15 +1273,12 @@
1313 strm->state = Z_NULL;
1314 Tracev((stderr, "inflate: end\n"));
1315 return Z_OK;
1316 }
1317
1318 int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength)
1319 z_streamp strm;
1320 Bytef *dictionary;
1321 uInt *dictLength;
1322 {
1323 struct inflate_state FAR *state;
1324
1325 /* check state */
1326 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1327 state = (struct inflate_state FAR *)strm->state;
@@ -1336,15 +1293,12 @@
1336 if (dictLength != Z_NULL)
1337 *dictLength = state->whave;
1338 return Z_OK;
1339 }
1340
1341 int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
1342 z_streamp strm;
1343 const Bytef *dictionary;
1344 uInt dictLength;
1345 {
1346 struct inflate_state FAR *state;
1347 unsigned long dictid;
1348 int ret;
1349
1350 /* check state */
@@ -1371,14 +1325,11 @@
1371 state->havedict = 1;
1372 Tracev((stderr, "inflate: dictionary set\n"));
1373 return Z_OK;
1374 }
1375
1376 int ZEXPORT inflateGetHeader(strm, head)
1377 z_streamp strm;
1378 gz_headerp head;
1379 {
1380 struct inflate_state FAR *state;
1381
1382 /* check state */
1383 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1384 state = (struct inflate_state FAR *)strm->state;
@@ -1399,15 +1350,12 @@
1399 pattern. If *have is less than four, then the pattern has not been found
1400 yet and the return value is len. In the latter case, syncsearch() can be
1401 called again with more data and the *have state. *have is initialized to
1402 zero for the first call.
1403 */
1404 local unsigned syncsearch(have, buf, len)
1405 unsigned FAR *have;
1406 const unsigned char FAR *buf;
1407 unsigned len;
1408 {
1409 unsigned got;
1410 unsigned next;
1411
1412 got = *have;
1413 next = 0;
@@ -1422,13 +1370,11 @@
1422 }
1423 *have = got;
1424 return next;
1425 }
1426
1427 int ZEXPORT inflateSync(strm)
1428 z_streamp strm;
1429 {
1430 unsigned len; /* number of bytes to look at or looked at */
1431 int flags; /* temporary to save header status */
1432 unsigned long in, out; /* temporary to save total_in and total_out */
1433 unsigned char buf[4]; /* to restore bit buffer to byte string */
1434 struct inflate_state FAR *state;
@@ -1480,24 +1426,19 @@
1480 implementation to provide an additional safety check. PPP uses
1481 Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored
1482 block. When decompressing, PPP checks that at the end of input packet,
1483 inflate is waiting for these length bytes.
1484 */
1485 int ZEXPORT inflateSyncPoint(strm)
1486 z_streamp strm;
1487 {
1488 struct inflate_state FAR *state;
1489
1490 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1491 state = (struct inflate_state FAR *)strm->state;
1492 return state->mode == STORED && state->bits == 0;
1493 }
1494
1495 int ZEXPORT inflateCopy(dest, source)
1496 z_streamp dest;
1497 z_streamp source;
1498 {
1499 struct inflate_state FAR *state;
1500 struct inflate_state FAR *copy;
1501 unsigned char FAR *window;
1502 unsigned wsize;
1503
@@ -1537,14 +1478,11 @@
1537 copy->window = window;
1538 dest->state = (struct internal_state FAR *)copy;
1539 return Z_OK;
1540 }
1541
1542 int ZEXPORT inflateUndermine(strm, subvert)
1543 z_streamp strm;
1544 int subvert;
1545 {
1546 struct inflate_state FAR *state;
1547
1548 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1549 state = (struct inflate_state FAR *)strm->state;
1550 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
@@ -1555,14 +1493,11 @@
1555 state->sane = 1;
1556 return Z_DATA_ERROR;
1557 #endif
1558 }
1559
1560 int ZEXPORT inflateValidate(strm, check)
1561 z_streamp strm;
1562 int check;
1563 {
1564 struct inflate_state FAR *state;
1565
1566 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1567 state = (struct inflate_state FAR *)strm->state;
1568 if (check && state->wrap)
@@ -1570,13 +1505,11 @@
1570 else
1571 state->wrap &= ~4;
1572 return Z_OK;
1573 }
1574
1575 long ZEXPORT inflateMark(strm)
1576 z_streamp strm;
1577 {
1578 struct inflate_state FAR *state;
1579
1580 if (inflateStateCheck(strm))
1581 return -(1L << 16);
1582 state = (struct inflate_state FAR *)strm->state;
@@ -1583,13 +1516,11 @@
1583 return (long)(((unsigned long)((long)state->back)) << 16) +
1584 (state->mode == COPY ? state->length :
1585 (state->mode == MATCH ? state->was - state->length : 0));
1586 }
1587
1588 unsigned long ZEXPORT inflateCodesUsed(strm)
1589 z_streamp strm;
1590 {
1591 struct inflate_state FAR *state;
1592 if (inflateStateCheck(strm)) return (unsigned long)-1;
1593 state = (struct inflate_state FAR *)strm->state;
1594 return (unsigned long)(state->next - state->codes);
1595 }
1596
--- compat/zlib/inflate.c
+++ compat/zlib/inflate.c
@@ -89,24 +89,11 @@
89 # ifndef BUILDFIXED
90 # define BUILDFIXED
91 # endif
92 #endif
93
94 local int inflateStateCheck(z_streamp strm) {
 
 
 
 
 
 
 
 
 
 
 
 
 
95 struct inflate_state FAR *state;
96 if (strm == Z_NULL ||
97 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
98 return 1;
99 state = (struct inflate_state FAR *)strm->state;
@@ -114,13 +101,11 @@
101 state->mode < HEAD || state->mode > SYNC)
102 return 1;
103 return 0;
104 }
105
106 int ZEXPORT inflateResetKeep(z_streamp strm) {
 
 
107 struct inflate_state FAR *state;
108
109 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
110 state = (struct inflate_state FAR *)strm->state;
111 strm->total_in = strm->total_out = state->total = 0;
@@ -140,13 +125,11 @@
125 state->back = -1;
126 Tracev((stderr, "inflate: reset\n"));
127 return Z_OK;
128 }
129
130 int ZEXPORT inflateReset(z_streamp strm) {
 
 
131 struct inflate_state FAR *state;
132
133 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
134 state = (struct inflate_state FAR *)strm->state;
135 state->wsize = 0;
@@ -153,14 +136,11 @@
136 state->whave = 0;
137 state->wnext = 0;
138 return inflateResetKeep(strm);
139 }
140
141 int ZEXPORT inflateReset2(z_streamp strm, int windowBits) {
 
 
 
142 int wrap;
143 struct inflate_state FAR *state;
144
145 /* get the state */
146 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
@@ -193,16 +173,12 @@
173 state->wrap = wrap;
174 state->wbits = (unsigned)windowBits;
175 return inflateReset(strm);
176 }
177
178 int ZEXPORT inflateInit2_(z_streamp strm, int windowBits,
179 const char *version, int stream_size) {
 
 
 
 
180 int ret;
181 struct inflate_state FAR *state;
182
183 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
184 stream_size != (int)(sizeof(z_stream)))
@@ -237,26 +213,21 @@
213 strm->state = Z_NULL;
214 }
215 return ret;
216 }
217
218 int ZEXPORT inflateInit_(z_streamp strm, const char *version,
219 int stream_size) {
 
 
 
220 return inflateInit2_(strm, DEF_WBITS, version, stream_size);
221 }
222
223 int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) {
 
 
 
 
224 struct inflate_state FAR *state;
225
226 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
227 if (bits == 0)
228 return Z_OK;
229 state = (struct inflate_state FAR *)strm->state;
230 if (bits < 0) {
231 state->hold = 0;
232 state->bits = 0;
233 return Z_OK;
@@ -276,13 +247,11 @@
247 thereafter. This reduces the size of the code by about 2K bytes, in
248 exchange for a little execution time. However, BUILDFIXED should not be
249 used for threaded applications, since the rewriting of the tables and virgin
250 may not be thread-safe.
251 */
252 local void fixedtables(struct inflate_state FAR *state) {
 
 
253 #ifdef BUILDFIXED
254 static int virgin = 1;
255 static code *lenfix, *distfix;
256 static code fixed[544];
257
@@ -340,11 +309,11 @@
309
310 Then that can be linked with zlib built with MAKEFIXED defined and run:
311
312 a.out > inffixed.h
313 */
314 void makefixed(void)
315 {
316 unsigned low, size;
317 struct inflate_state state;
318
319 fixedtables(&state);
@@ -394,15 +363,11 @@
363 advantage, since only the last 32K of output is copied to the sliding window
364 upon return from inflate(), and since all distances after the first 32K of
365 output will fall in the output data, making match copies simpler and faster.
366 The advantage may be dependent on the size of the processor's data caches.
367 */
368 local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) {
 
 
 
 
369 struct inflate_state FAR *state;
370 unsigned dist;
371
372 state = (struct inflate_state FAR *)strm->state;
373
@@ -620,14 +585,11 @@
585 stream available. So the only thing the flush parameter actually does is:
586 when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
587 will return Z_BUF_ERROR if it has not reached the end of the stream.
588 */
589
590 int ZEXPORT inflate(z_streamp strm, int flush) {
 
 
 
591 struct inflate_state FAR *state;
592 z_const unsigned char FAR *next; /* next input */
593 unsigned char FAR *put; /* next output */
594 unsigned have, left; /* available input and output */
595 unsigned long hold; /* bit buffer */
@@ -1299,13 +1261,11 @@
1261 if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
1262 ret = Z_BUF_ERROR;
1263 return ret;
1264 }
1265
1266 int ZEXPORT inflateEnd(z_streamp strm) {
 
 
1267 struct inflate_state FAR *state;
1268 if (inflateStateCheck(strm))
1269 return Z_STREAM_ERROR;
1270 state = (struct inflate_state FAR *)strm->state;
1271 if (state->window != Z_NULL) ZFREE(strm, state->window);
@@ -1313,15 +1273,12 @@
1273 strm->state = Z_NULL;
1274 Tracev((stderr, "inflate: end\n"));
1275 return Z_OK;
1276 }
1277
1278 int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary,
1279 uInt *dictLength) {
 
 
 
1280 struct inflate_state FAR *state;
1281
1282 /* check state */
1283 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1284 state = (struct inflate_state FAR *)strm->state;
@@ -1336,15 +1293,12 @@
1293 if (dictLength != Z_NULL)
1294 *dictLength = state->whave;
1295 return Z_OK;
1296 }
1297
1298 int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
1299 uInt dictLength) {
 
 
 
1300 struct inflate_state FAR *state;
1301 unsigned long dictid;
1302 int ret;
1303
1304 /* check state */
@@ -1371,14 +1325,11 @@
1325 state->havedict = 1;
1326 Tracev((stderr, "inflate: dictionary set\n"));
1327 return Z_OK;
1328 }
1329
1330 int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) {
 
 
 
1331 struct inflate_state FAR *state;
1332
1333 /* check state */
1334 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1335 state = (struct inflate_state FAR *)strm->state;
@@ -1399,15 +1350,12 @@
1350 pattern. If *have is less than four, then the pattern has not been found
1351 yet and the return value is len. In the latter case, syncsearch() can be
1352 called again with more data and the *have state. *have is initialized to
1353 zero for the first call.
1354 */
1355 local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf,
1356 unsigned len) {
 
 
 
1357 unsigned got;
1358 unsigned next;
1359
1360 got = *have;
1361 next = 0;
@@ -1422,13 +1370,11 @@
1370 }
1371 *have = got;
1372 return next;
1373 }
1374
1375 int ZEXPORT inflateSync(z_streamp strm) {
 
 
1376 unsigned len; /* number of bytes to look at or looked at */
1377 int flags; /* temporary to save header status */
1378 unsigned long in, out; /* temporary to save total_in and total_out */
1379 unsigned char buf[4]; /* to restore bit buffer to byte string */
1380 struct inflate_state FAR *state;
@@ -1480,24 +1426,19 @@
1426 implementation to provide an additional safety check. PPP uses
1427 Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored
1428 block. When decompressing, PPP checks that at the end of input packet,
1429 inflate is waiting for these length bytes.
1430 */
1431 int ZEXPORT inflateSyncPoint(z_streamp strm) {
 
 
1432 struct inflate_state FAR *state;
1433
1434 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1435 state = (struct inflate_state FAR *)strm->state;
1436 return state->mode == STORED && state->bits == 0;
1437 }
1438
1439 int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
 
 
 
1440 struct inflate_state FAR *state;
1441 struct inflate_state FAR *copy;
1442 unsigned char FAR *window;
1443 unsigned wsize;
1444
@@ -1537,14 +1478,11 @@
1478 copy->window = window;
1479 dest->state = (struct internal_state FAR *)copy;
1480 return Z_OK;
1481 }
1482
1483 int ZEXPORT inflateUndermine(z_streamp strm, int subvert) {
 
 
 
1484 struct inflate_state FAR *state;
1485
1486 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1487 state = (struct inflate_state FAR *)strm->state;
1488 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
@@ -1555,14 +1493,11 @@
1493 state->sane = 1;
1494 return Z_DATA_ERROR;
1495 #endif
1496 }
1497
1498 int ZEXPORT inflateValidate(z_streamp strm, int check) {
 
 
 
1499 struct inflate_state FAR *state;
1500
1501 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1502 state = (struct inflate_state FAR *)strm->state;
1503 if (check && state->wrap)
@@ -1570,13 +1505,11 @@
1505 else
1506 state->wrap &= ~4;
1507 return Z_OK;
1508 }
1509
1510 long ZEXPORT inflateMark(z_streamp strm) {
 
 
1511 struct inflate_state FAR *state;
1512
1513 if (inflateStateCheck(strm))
1514 return -(1L << 16);
1515 state = (struct inflate_state FAR *)strm->state;
@@ -1583,13 +1516,11 @@
1516 return (long)(((unsigned long)((long)state->back)) << 16) +
1517 (state->mode == COPY ? state->length :
1518 (state->mode == MATCH ? state->was - state->length : 0));
1519 }
1520
1521 unsigned long ZEXPORT inflateCodesUsed(z_streamp strm) {
 
 
1522 struct inflate_state FAR *state;
1523 if (inflateStateCheck(strm)) return (unsigned long)-1;
1524 state = (struct inflate_state FAR *)strm->state;
1525 return (unsigned long)(state->next - state->codes);
1526 }
1527
--- compat/zlib/inftrees.c
+++ compat/zlib/inftrees.c
@@ -1,17 +1,17 @@
11
/* inftrees.c -- generate Huffman trees for efficient decoding
2
- * Copyright (C) 1995-2022 Mark Adler
2
+ * Copyright (C) 1995-2023 Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55
66
#include "zutil.h"
77
#include "inftrees.h"
88
99
#define MAXBITS 15
1010
1111
const char inflate_copyright[] =
12
- " inflate 1.2.13 Copyright 1995-2022 Mark Adler ";
12
+ " inflate 1.3 Copyright 1995-2023 Mark Adler ";
1313
/*
1414
If you use the zlib library in a product, an acknowledgment is welcome
1515
in the documentation of your product. If for some reason you cannot
1616
include such an acknowledgment, I would appreciate that you keep this
1717
copyright string in the executable of your product.
@@ -27,18 +27,13 @@
2727
on return points to the next available entry's address. bits is the
2828
requested root table index bits, and on return it is the actual root
2929
table index bits. It will differ if the request is greater than the
3030
longest code or if it is less than the shortest code.
3131
*/
32
-int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work)
33
-codetype type;
34
-unsigned short FAR *lens;
35
-unsigned codes;
36
-code FAR * FAR *table;
37
-unsigned FAR *bits;
38
-unsigned short FAR *work;
39
-{
32
+int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
33
+ unsigned codes, code FAR * FAR *table,
34
+ unsigned FAR *bits, unsigned short FAR *work) {
4035
unsigned len; /* a code's length in bits */
4136
unsigned sym; /* index of code symbols */
4237
unsigned min, max; /* minimum and maximum code lengths */
4338
unsigned root; /* number of index bits for root table */
4439
unsigned curr; /* number of index bits for current table */
@@ -60,11 +55,11 @@
6055
static const unsigned short lbase[31] = { /* Length codes 257..285 base */
6156
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
6257
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
6358
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
6459
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
65
- 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 194, 65};
60
+ 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 198, 203};
6661
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
6762
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
6863
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
6964
8193, 12289, 16385, 24577, 0, 0};
7065
static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
7166
--- compat/zlib/inftrees.c
+++ compat/zlib/inftrees.c
@@ -1,17 +1,17 @@
1 /* inftrees.c -- generate Huffman trees for efficient decoding
2 * Copyright (C) 1995-2022 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 #include "zutil.h"
7 #include "inftrees.h"
8
9 #define MAXBITS 15
10
11 const char inflate_copyright[] =
12 " inflate 1.2.13 Copyright 1995-2022 Mark Adler ";
13 /*
14 If you use the zlib library in a product, an acknowledgment is welcome
15 in the documentation of your product. If for some reason you cannot
16 include such an acknowledgment, I would appreciate that you keep this
17 copyright string in the executable of your product.
@@ -27,18 +27,13 @@
27 on return points to the next available entry's address. bits is the
28 requested root table index bits, and on return it is the actual root
29 table index bits. It will differ if the request is greater than the
30 longest code or if it is less than the shortest code.
31 */
32 int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work)
33 codetype type;
34 unsigned short FAR *lens;
35 unsigned codes;
36 code FAR * FAR *table;
37 unsigned FAR *bits;
38 unsigned short FAR *work;
39 {
40 unsigned len; /* a code's length in bits */
41 unsigned sym; /* index of code symbols */
42 unsigned min, max; /* minimum and maximum code lengths */
43 unsigned root; /* number of index bits for root table */
44 unsigned curr; /* number of index bits for current table */
@@ -60,11 +55,11 @@
60 static const unsigned short lbase[31] = { /* Length codes 257..285 base */
61 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
62 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
63 static const unsigned short lext[31] = { /* Length codes 257..285 extra */
64 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
65 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 194, 65};
66 static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
67 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
68 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
69 8193, 12289, 16385, 24577, 0, 0};
70 static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
71
--- compat/zlib/inftrees.c
+++ compat/zlib/inftrees.c
@@ -1,17 +1,17 @@
1 /* inftrees.c -- generate Huffman trees for efficient decoding
2 * Copyright (C) 1995-2023 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 #include "zutil.h"
7 #include "inftrees.h"
8
9 #define MAXBITS 15
10
11 const char inflate_copyright[] =
12 " inflate 1.3 Copyright 1995-2023 Mark Adler ";
13 /*
14 If you use the zlib library in a product, an acknowledgment is welcome
15 in the documentation of your product. If for some reason you cannot
16 include such an acknowledgment, I would appreciate that you keep this
17 copyright string in the executable of your product.
@@ -27,18 +27,13 @@
27 on return points to the next available entry's address. bits is the
28 requested root table index bits, and on return it is the actual root
29 table index bits. It will differ if the request is greater than the
30 longest code or if it is less than the shortest code.
31 */
32 int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
33 unsigned codes, code FAR * FAR *table,
34 unsigned FAR *bits, unsigned short FAR *work) {
 
 
 
 
 
35 unsigned len; /* a code's length in bits */
36 unsigned sym; /* index of code symbols */
37 unsigned min, max; /* minimum and maximum code lengths */
38 unsigned root; /* number of index bits for root table */
39 unsigned curr; /* number of index bits for current table */
@@ -60,11 +55,11 @@
55 static const unsigned short lbase[31] = { /* Length codes 257..285 base */
56 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
57 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
58 static const unsigned short lext[31] = { /* Length codes 257..285 extra */
59 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
60 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 198, 203};
61 static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
62 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
63 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
64 8193, 12289, 16385, 24577, 0, 0};
65 static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
66
--- compat/zlib/inftrees.h
+++ compat/zlib/inftrees.h
@@ -55,8 +55,8 @@
5555
CODES,
5656
LENS,
5757
DISTS
5858
} codetype;
5959
60
-int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
61
- unsigned codes, code FAR * FAR *table,
62
- unsigned FAR *bits, unsigned short FAR *work));
60
+int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
61
+ unsigned codes, code FAR * FAR *table,
62
+ unsigned FAR *bits, unsigned short FAR *work);
6363
--- compat/zlib/inftrees.h
+++ compat/zlib/inftrees.h
@@ -55,8 +55,8 @@
55 CODES,
56 LENS,
57 DISTS
58 } codetype;
59
60 int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
61 unsigned codes, code FAR * FAR *table,
62 unsigned FAR *bits, unsigned short FAR *work));
63
--- compat/zlib/inftrees.h
+++ compat/zlib/inftrees.h
@@ -55,8 +55,8 @@
55 CODES,
56 LENS,
57 DISTS
58 } codetype;
59
60 int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
61 unsigned codes, code FAR * FAR *table,
62 unsigned FAR *bits, unsigned short FAR *work);
63
--- compat/zlib/os400/README400
+++ compat/zlib/os400/README400
@@ -1,6 +1,6 @@
1
- ZLIB version 1.2.13 for OS/400 installation instructions
1
+ ZLIB version 1.3.0 for OS/400 installation instructions
22
33
1) Download and unpack the zlib tarball to some IFS directory.
44
(i.e.: /path/to/the/zlib/ifs/source/directory)
55
66
If the installed IFS command supports gzip format, this is straightforward,
77
--- compat/zlib/os400/README400
+++ compat/zlib/os400/README400
@@ -1,6 +1,6 @@
1 ZLIB version 1.2.13 for OS/400 installation instructions
2
3 1) Download and unpack the zlib tarball to some IFS directory.
4 (i.e.: /path/to/the/zlib/ifs/source/directory)
5
6 If the installed IFS command supports gzip format, this is straightforward,
7
--- compat/zlib/os400/README400
+++ compat/zlib/os400/README400
@@ -1,6 +1,6 @@
1 ZLIB version 1.3.0 for OS/400 installation instructions
2
3 1) Download and unpack the zlib tarball to some IFS directory.
4 (i.e.: /path/to/the/zlib/ifs/source/directory)
5
6 If the installed IFS command supports gzip format, this is straightforward,
7
--- compat/zlib/os400/zlib.inc
+++ compat/zlib/os400/zlib.inc
@@ -1,9 +1,9 @@
11
* ZLIB.INC - Interface to the general purpose compression library
22
*
33
* ILE RPG400 version by Patrick Monnerat, DATASPHERE.
4
- * Version 1.2.13
4
+ * Version 1.3.0
55
*
66
*
77
* WARNING:
88
* Procedures inflateInit(), inflateInit2(), deflateInit(),
99
* deflateInit2() and inflateBackInit() need to be called with
@@ -20,16 +20,16 @@
2020
* Constants
2121
**************************************************************************
2222
*
2323
* Versioning information.
2424
*
25
- D ZLIB_VERSION C '1.2.13'
25
+ D ZLIB_VERSION C '1.3.0'
2626
D ZLIB_VERNUM C X'12a0'
2727
D ZLIB_VER_MAJOR C 1
28
- D ZLIB_VER_MINOR C 2
28
+ D ZLIB_VER_MINOR C 3
2929
D ZLIB_VER_REVISION...
30
- D C 13
30
+ D C 0
3131
D ZLIB_VER_SUBREVISION...
3232
D C 0
3333
*
3434
* Other equates.
3535
*
3636
--- compat/zlib/os400/zlib.inc
+++ compat/zlib/os400/zlib.inc
@@ -1,9 +1,9 @@
1 * ZLIB.INC - Interface to the general purpose compression library
2 *
3 * ILE RPG400 version by Patrick Monnerat, DATASPHERE.
4 * Version 1.2.13
5 *
6 *
7 * WARNING:
8 * Procedures inflateInit(), inflateInit2(), deflateInit(),
9 * deflateInit2() and inflateBackInit() need to be called with
@@ -20,16 +20,16 @@
20 * Constants
21 **************************************************************************
22 *
23 * Versioning information.
24 *
25 D ZLIB_VERSION C '1.2.13'
26 D ZLIB_VERNUM C X'12a0'
27 D ZLIB_VER_MAJOR C 1
28 D ZLIB_VER_MINOR C 2
29 D ZLIB_VER_REVISION...
30 D C 13
31 D ZLIB_VER_SUBREVISION...
32 D C 0
33 *
34 * Other equates.
35 *
36
--- compat/zlib/os400/zlib.inc
+++ compat/zlib/os400/zlib.inc
@@ -1,9 +1,9 @@
1 * ZLIB.INC - Interface to the general purpose compression library
2 *
3 * ILE RPG400 version by Patrick Monnerat, DATASPHERE.
4 * Version 1.3.0
5 *
6 *
7 * WARNING:
8 * Procedures inflateInit(), inflateInit2(), deflateInit(),
9 * deflateInit2() and inflateBackInit() need to be called with
@@ -20,16 +20,16 @@
20 * Constants
21 **************************************************************************
22 *
23 * Versioning information.
24 *
25 D ZLIB_VERSION C '1.3.0'
26 D ZLIB_VERNUM C X'12a0'
27 D ZLIB_VER_MAJOR C 1
28 D ZLIB_VER_MINOR C 3
29 D ZLIB_VER_REVISION...
30 D C 0
31 D ZLIB_VER_SUBREVISION...
32 D C 0
33 *
34 * Other equates.
35 *
36
--- compat/zlib/qnx/package.qpg
+++ compat/zlib/qnx/package.qpg
@@ -23,14 +23,14 @@
2323
2424
<QPG:Values>
2525
<QPG:Files>
2626
<QPG:Add file="../zconf.h" install="/opt/include/" user="root:sys" permission="644"/>
2727
<QPG:Add file="../zlib.h" install="/opt/include/" user="root:sys" permission="644"/>
28
- <QPG:Add file="../libz.so.1.2.13" install="/opt/lib/" user="root:bin" permission="644"/>
29
- <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.2.13"/>
30
- <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.13"/>
31
- <QPG:Add file="../libz.so.1.2.13" install="/opt/lib/" component="slib"/>
28
+ <QPG:Add file="../libz.so.1.3.0" install="/opt/lib/" user="root:bin" permission="644"/>
29
+ <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.3.0"/>
30
+ <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.3.0"/>
31
+ <QPG:Add file="../libz.so.1.3.0" install="/opt/lib/" component="slib"/>
3232
</QPG:Files>
3333
3434
<QPG:PackageFilter>
3535
<QPM:PackageManifest>
3636
<QPM:PackageDescription>
@@ -61,11 +61,11 @@
6161
<QPM:ProductDescriptionURL>http://www.gzip.org/zlib</QPM:ProductDescriptionURL>
6262
<QPM:ProductDescriptionEmbedURL></QPM:ProductDescriptionEmbedURL>
6363
</QPM:ProductDescription>
6464
6565
<QPM:ReleaseDescription>
66
- <QPM:ReleaseVersion>1.2.13</QPM:ReleaseVersion>
66
+ <QPM:ReleaseVersion>1.3.0</QPM:ReleaseVersion>
6767
<QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency>
6868
<QPM:ReleaseStability>Stable</QPM:ReleaseStability>
6969
<QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor>
7070
<QPM:ReleaseNoteMajor></QPM:ReleaseNoteMajor>
7171
<QPM:ExcludeCountries>
7272
--- compat/zlib/qnx/package.qpg
+++ compat/zlib/qnx/package.qpg
@@ -23,14 +23,14 @@
23
24 <QPG:Values>
25 <QPG:Files>
26 <QPG:Add file="../zconf.h" install="/opt/include/" user="root:sys" permission="644"/>
27 <QPG:Add file="../zlib.h" install="/opt/include/" user="root:sys" permission="644"/>
28 <QPG:Add file="../libz.so.1.2.13" install="/opt/lib/" user="root:bin" permission="644"/>
29 <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.2.13"/>
30 <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.2.13"/>
31 <QPG:Add file="../libz.so.1.2.13" install="/opt/lib/" component="slib"/>
32 </QPG:Files>
33
34 <QPG:PackageFilter>
35 <QPM:PackageManifest>
36 <QPM:PackageDescription>
@@ -61,11 +61,11 @@
61 <QPM:ProductDescriptionURL>http://www.gzip.org/zlib</QPM:ProductDescriptionURL>
62 <QPM:ProductDescriptionEmbedURL></QPM:ProductDescriptionEmbedURL>
63 </QPM:ProductDescription>
64
65 <QPM:ReleaseDescription>
66 <QPM:ReleaseVersion>1.2.13</QPM:ReleaseVersion>
67 <QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency>
68 <QPM:ReleaseStability>Stable</QPM:ReleaseStability>
69 <QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor>
70 <QPM:ReleaseNoteMajor></QPM:ReleaseNoteMajor>
71 <QPM:ExcludeCountries>
72
--- compat/zlib/qnx/package.qpg
+++ compat/zlib/qnx/package.qpg
@@ -23,14 +23,14 @@
23
24 <QPG:Values>
25 <QPG:Files>
26 <QPG:Add file="../zconf.h" install="/opt/include/" user="root:sys" permission="644"/>
27 <QPG:Add file="../zlib.h" install="/opt/include/" user="root:sys" permission="644"/>
28 <QPG:Add file="../libz.so.1.3.0" install="/opt/lib/" user="root:bin" permission="644"/>
29 <QPG:Add file="libz.so" install="/opt/lib/" component="dev" filetype="symlink" linkto="libz.so.1.3.0"/>
30 <QPG:Add file="libz.so.1" install="/opt/lib/" filetype="symlink" linkto="libz.so.1.3.0"/>
31 <QPG:Add file="../libz.so.1.3.0" install="/opt/lib/" component="slib"/>
32 </QPG:Files>
33
34 <QPG:PackageFilter>
35 <QPM:PackageManifest>
36 <QPM:PackageDescription>
@@ -61,11 +61,11 @@
61 <QPM:ProductDescriptionURL>http://www.gzip.org/zlib</QPM:ProductDescriptionURL>
62 <QPM:ProductDescriptionEmbedURL></QPM:ProductDescriptionEmbedURL>
63 </QPM:ProductDescription>
64
65 <QPM:ReleaseDescription>
66 <QPM:ReleaseVersion>1.3.0</QPM:ReleaseVersion>
67 <QPM:ReleaseUrgency>Medium</QPM:ReleaseUrgency>
68 <QPM:ReleaseStability>Stable</QPM:ReleaseStability>
69 <QPM:ReleaseNoteMinor></QPM:ReleaseNoteMinor>
70 <QPM:ReleaseNoteMajor></QPM:ReleaseNoteMajor>
71 <QPM:ExcludeCountries>
72
--- compat/zlib/test/example.c
+++ compat/zlib/test/example.c
@@ -31,42 +31,19 @@
3131
* stresses the compression code better, sorry...
3232
*/
3333
3434
static const char dictionary[] = "hello";
3535
static uLong dictId; /* Adler32 value of the dictionary */
36
-
37
-void test_deflate OF((Byte *compr, uLong comprLen));
38
-void test_inflate OF((Byte *compr, uLong comprLen,
39
- Byte *uncompr, uLong uncomprLen));
40
-void test_large_deflate OF((Byte *compr, uLong comprLen,
41
- Byte *uncompr, uLong uncomprLen));
42
-void test_large_inflate OF((Byte *compr, uLong comprLen,
43
- Byte *uncompr, uLong uncomprLen));
44
-void test_flush OF((Byte *compr, uLong *comprLen));
45
-void test_sync OF((Byte *compr, uLong comprLen,
46
- Byte *uncompr, uLong uncomprLen));
47
-void test_dict_deflate OF((Byte *compr, uLong comprLen));
48
-void test_dict_inflate OF((Byte *compr, uLong comprLen,
49
- Byte *uncompr, uLong uncomprLen));
50
-int main OF((int argc, char *argv[]));
51
-
5236
5337
#ifdef Z_SOLO
5438
55
-void *myalloc OF((void *, unsigned, unsigned));
56
-void myfree OF((void *, void *));
57
-
58
-void *myalloc(q, n, m)
59
- void *q;
60
- unsigned n, m;
61
-{
39
+void *myalloc(void *q, unsigned n, unsigned m) {
6240
(void)q;
6341
return calloc(n, m);
6442
}
6543
66
-void myfree(void *q, void *p)
67
-{
44
+void myfree(void *q, void *p) {
6845
(void)q;
6946
free(p);
7047
}
7148
7249
static alloc_func zalloc = myalloc;
@@ -75,22 +52,15 @@
7552
#else /* !Z_SOLO */
7653
7754
static alloc_func zalloc = (alloc_func)0;
7855
static free_func zfree = (free_func)0;
7956
80
-void test_compress OF((Byte *compr, uLong comprLen,
81
- Byte *uncompr, uLong uncomprLen));
82
-void test_gzio OF((const char *fname,
83
- Byte *uncompr, uLong uncomprLen));
84
-
8557
/* ===========================================================================
8658
* Test compress() and uncompress()
8759
*/
88
-void test_compress(compr, comprLen, uncompr, uncomprLen)
89
- Byte *compr, *uncompr;
90
- uLong comprLen, uncomprLen;
91
-{
60
+void test_compress(Byte *compr, uLong comprLen, Byte *uncompr,
61
+ uLong uncomprLen) {
9262
int err;
9363
uLong len = (uLong)strlen(hello)+1;
9464
9565
err = compress(compr, &comprLen, (const Bytef*)hello, len);
9666
CHECK_ERR(err, "compress");
@@ -109,15 +79,11 @@
10979
}
11080
11181
/* ===========================================================================
11282
* Test read/write of .gz files
11383
*/
114
-void test_gzio(fname, uncompr, uncomprLen)
115
- const char *fname; /* compressed file name */
116
- Byte *uncompr;
117
- uLong uncomprLen;
118
-{
84
+void test_gzio(const char *fname, Byte *uncompr, uLong uncomprLen) {
11985
#ifdef NO_GZCOMPRESS
12086
fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
12187
#else
12288
int err;
12389
int len = (int)strlen(hello)+1;
@@ -195,14 +161,11 @@
195161
#endif /* Z_SOLO */
196162
197163
/* ===========================================================================
198164
* Test deflate() with small buffers
199165
*/
200
-void test_deflate(compr, comprLen)
201
- Byte *compr;
202
- uLong comprLen;
203
-{
166
+void test_deflate(Byte *compr, uLong comprLen) {
204167
z_stream c_stream; /* compression stream */
205168
int err;
206169
uLong len = (uLong)strlen(hello)+1;
207170
208171
c_stream.zalloc = zalloc;
@@ -233,14 +196,12 @@
233196
}
234197
235198
/* ===========================================================================
236199
* Test inflate() with small buffers
237200
*/
238
-void test_inflate(compr, comprLen, uncompr, uncomprLen)
239
- Byte *compr, *uncompr;
240
- uLong comprLen, uncomprLen;
241
-{
201
+void test_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
202
+ uLong uncomprLen) {
242203
int err;
243204
z_stream d_stream; /* decompression stream */
244205
245206
strcpy((char*)uncompr, "garbage");
246207
@@ -274,14 +235,12 @@
274235
}
275236
276237
/* ===========================================================================
277238
* Test deflate() with large buffers and dynamic change of compression level
278239
*/
279
-void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
280
- Byte *compr, *uncompr;
281
- uLong comprLen, uncomprLen;
282
-{
240
+void test_large_deflate(Byte *compr, uLong comprLen, Byte *uncompr,
241
+ uLong uncomprLen) {
283242
z_stream c_stream; /* compression stream */
284243
int err;
285244
286245
c_stream.zalloc = zalloc;
287246
c_stream.zfree = zfree;
@@ -306,11 +265,11 @@
306265
}
307266
308267
/* Feed in already compressed data and switch to no compression: */
309268
deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
310269
c_stream.next_in = compr;
311
- c_stream.avail_in = (uInt)comprLen/2;
270
+ c_stream.avail_in = (uInt)uncomprLen/2;
312271
err = deflate(&c_stream, Z_NO_FLUSH);
313272
CHECK_ERR(err, "deflate");
314273
315274
/* Switch back to compressing mode: */
316275
deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
@@ -329,14 +288,12 @@
329288
}
330289
331290
/* ===========================================================================
332291
* Test inflate() with large buffers
333292
*/
334
-void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
335
- Byte *compr, *uncompr;
336
- uLong comprLen, uncomprLen;
337
-{
293
+void test_large_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
294
+ uLong uncomprLen) {
338295
int err;
339296
z_stream d_stream; /* decompression stream */
340297
341298
strcpy((char*)uncompr, "garbage");
342299
@@ -359,11 +316,11 @@
359316
}
360317
361318
err = inflateEnd(&d_stream);
362319
CHECK_ERR(err, "inflateEnd");
363320
364
- if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
321
+ if (d_stream.total_out != 2*uncomprLen + uncomprLen/2) {
365322
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
366323
exit(1);
367324
} else {
368325
printf("large_inflate(): OK\n");
369326
}
@@ -370,14 +327,11 @@
370327
}
371328
372329
/* ===========================================================================
373330
* Test deflate() with full flush
374331
*/
375
-void test_flush(compr, comprLen)
376
- Byte *compr;
377
- uLong *comprLen;
378
-{
332
+void test_flush(Byte *compr, uLong *comprLen) {
379333
z_stream c_stream; /* compression stream */
380334
int err;
381335
uInt len = (uInt)strlen(hello)+1;
382336
383337
c_stream.zalloc = zalloc;
@@ -408,14 +362,11 @@
408362
}
409363
410364
/* ===========================================================================
411365
* Test inflateSync()
412366
*/
413
-void test_sync(compr, comprLen, uncompr, uncomprLen)
414
- Byte *compr, *uncompr;
415
- uLong comprLen, uncomprLen;
416
-{
367
+void test_sync(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen) {
417368
int err;
418369
z_stream d_stream; /* decompression stream */
419370
420371
strcpy((char*)uncompr, "garbage");
421372
@@ -451,14 +402,11 @@
451402
}
452403
453404
/* ===========================================================================
454405
* Test deflate() with preset dictionary
455406
*/
456
-void test_dict_deflate(compr, comprLen)
457
- Byte *compr;
458
- uLong comprLen;
459
-{
407
+void test_dict_deflate(Byte *compr, uLong comprLen) {
460408
z_stream c_stream; /* compression stream */
461409
int err;
462410
463411
c_stream.zalloc = zalloc;
464412
c_stream.zfree = zfree;
@@ -488,14 +436,12 @@
488436
}
489437
490438
/* ===========================================================================
491439
* Test inflate() with a preset dictionary
492440
*/
493
-void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
494
- Byte *compr, *uncompr;
495
- uLong comprLen, uncomprLen;
496
-{
441
+void test_dict_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
442
+ uLong uncomprLen) {
497443
int err;
498444
z_stream d_stream; /* decompression stream */
499445
500446
strcpy((char*)uncompr, "garbage");
501447
@@ -539,17 +485,14 @@
539485
540486
/* ===========================================================================
541487
* Usage: example [output.gz [input.gz]]
542488
*/
543489
544
-int main(argc, argv)
545
- int argc;
546
- char *argv[];
547
-{
490
+int main(int argc, char *argv[]) {
548491
Byte *compr, *uncompr;
549
- uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
550
- uLong uncomprLen = comprLen;
492
+ uLong uncomprLen = 20000;
493
+ uLong comprLen = 3 * uncomprLen;
551494
static const char* myVersion = ZLIB_VERSION;
552495
553496
if (zlibVersion()[0] != myVersion[0]) {
554497
fprintf(stderr, "incompatible zlib version\n");
555498
exit(1);
@@ -588,15 +531,15 @@
588531
test_large_deflate(compr, comprLen, uncompr, uncomprLen);
589532
test_large_inflate(compr, comprLen, uncompr, uncomprLen);
590533
591534
test_flush(compr, &comprLen);
592535
test_sync(compr, comprLen, uncompr, uncomprLen);
593
- comprLen = uncomprLen;
536
+ comprLen = 3 * uncomprLen;
594537
595538
test_dict_deflate(compr, comprLen);
596539
test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
597540
598541
free(compr);
599542
free(uncompr);
600543
601544
return 0;
602545
}
603546
--- compat/zlib/test/example.c
+++ compat/zlib/test/example.c
@@ -31,42 +31,19 @@
31 * stresses the compression code better, sorry...
32 */
33
34 static const char dictionary[] = "hello";
35 static uLong dictId; /* Adler32 value of the dictionary */
36
37 void test_deflate OF((Byte *compr, uLong comprLen));
38 void test_inflate OF((Byte *compr, uLong comprLen,
39 Byte *uncompr, uLong uncomprLen));
40 void test_large_deflate OF((Byte *compr, uLong comprLen,
41 Byte *uncompr, uLong uncomprLen));
42 void test_large_inflate OF((Byte *compr, uLong comprLen,
43 Byte *uncompr, uLong uncomprLen));
44 void test_flush OF((Byte *compr, uLong *comprLen));
45 void test_sync OF((Byte *compr, uLong comprLen,
46 Byte *uncompr, uLong uncomprLen));
47 void test_dict_deflate OF((Byte *compr, uLong comprLen));
48 void test_dict_inflate OF((Byte *compr, uLong comprLen,
49 Byte *uncompr, uLong uncomprLen));
50 int main OF((int argc, char *argv[]));
51
52
53 #ifdef Z_SOLO
54
55 void *myalloc OF((void *, unsigned, unsigned));
56 void myfree OF((void *, void *));
57
58 void *myalloc(q, n, m)
59 void *q;
60 unsigned n, m;
61 {
62 (void)q;
63 return calloc(n, m);
64 }
65
66 void myfree(void *q, void *p)
67 {
68 (void)q;
69 free(p);
70 }
71
72 static alloc_func zalloc = myalloc;
@@ -75,22 +52,15 @@
75 #else /* !Z_SOLO */
76
77 static alloc_func zalloc = (alloc_func)0;
78 static free_func zfree = (free_func)0;
79
80 void test_compress OF((Byte *compr, uLong comprLen,
81 Byte *uncompr, uLong uncomprLen));
82 void test_gzio OF((const char *fname,
83 Byte *uncompr, uLong uncomprLen));
84
85 /* ===========================================================================
86 * Test compress() and uncompress()
87 */
88 void test_compress(compr, comprLen, uncompr, uncomprLen)
89 Byte *compr, *uncompr;
90 uLong comprLen, uncomprLen;
91 {
92 int err;
93 uLong len = (uLong)strlen(hello)+1;
94
95 err = compress(compr, &comprLen, (const Bytef*)hello, len);
96 CHECK_ERR(err, "compress");
@@ -109,15 +79,11 @@
109 }
110
111 /* ===========================================================================
112 * Test read/write of .gz files
113 */
114 void test_gzio(fname, uncompr, uncomprLen)
115 const char *fname; /* compressed file name */
116 Byte *uncompr;
117 uLong uncomprLen;
118 {
119 #ifdef NO_GZCOMPRESS
120 fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
121 #else
122 int err;
123 int len = (int)strlen(hello)+1;
@@ -195,14 +161,11 @@
195 #endif /* Z_SOLO */
196
197 /* ===========================================================================
198 * Test deflate() with small buffers
199 */
200 void test_deflate(compr, comprLen)
201 Byte *compr;
202 uLong comprLen;
203 {
204 z_stream c_stream; /* compression stream */
205 int err;
206 uLong len = (uLong)strlen(hello)+1;
207
208 c_stream.zalloc = zalloc;
@@ -233,14 +196,12 @@
233 }
234
235 /* ===========================================================================
236 * Test inflate() with small buffers
237 */
238 void test_inflate(compr, comprLen, uncompr, uncomprLen)
239 Byte *compr, *uncompr;
240 uLong comprLen, uncomprLen;
241 {
242 int err;
243 z_stream d_stream; /* decompression stream */
244
245 strcpy((char*)uncompr, "garbage");
246
@@ -274,14 +235,12 @@
274 }
275
276 /* ===========================================================================
277 * Test deflate() with large buffers and dynamic change of compression level
278 */
279 void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
280 Byte *compr, *uncompr;
281 uLong comprLen, uncomprLen;
282 {
283 z_stream c_stream; /* compression stream */
284 int err;
285
286 c_stream.zalloc = zalloc;
287 c_stream.zfree = zfree;
@@ -306,11 +265,11 @@
306 }
307
308 /* Feed in already compressed data and switch to no compression: */
309 deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
310 c_stream.next_in = compr;
311 c_stream.avail_in = (uInt)comprLen/2;
312 err = deflate(&c_stream, Z_NO_FLUSH);
313 CHECK_ERR(err, "deflate");
314
315 /* Switch back to compressing mode: */
316 deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
@@ -329,14 +288,12 @@
329 }
330
331 /* ===========================================================================
332 * Test inflate() with large buffers
333 */
334 void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
335 Byte *compr, *uncompr;
336 uLong comprLen, uncomprLen;
337 {
338 int err;
339 z_stream d_stream; /* decompression stream */
340
341 strcpy((char*)uncompr, "garbage");
342
@@ -359,11 +316,11 @@
359 }
360
361 err = inflateEnd(&d_stream);
362 CHECK_ERR(err, "inflateEnd");
363
364 if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
365 fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
366 exit(1);
367 } else {
368 printf("large_inflate(): OK\n");
369 }
@@ -370,14 +327,11 @@
370 }
371
372 /* ===========================================================================
373 * Test deflate() with full flush
374 */
375 void test_flush(compr, comprLen)
376 Byte *compr;
377 uLong *comprLen;
378 {
379 z_stream c_stream; /* compression stream */
380 int err;
381 uInt len = (uInt)strlen(hello)+1;
382
383 c_stream.zalloc = zalloc;
@@ -408,14 +362,11 @@
408 }
409
410 /* ===========================================================================
411 * Test inflateSync()
412 */
413 void test_sync(compr, comprLen, uncompr, uncomprLen)
414 Byte *compr, *uncompr;
415 uLong comprLen, uncomprLen;
416 {
417 int err;
418 z_stream d_stream; /* decompression stream */
419
420 strcpy((char*)uncompr, "garbage");
421
@@ -451,14 +402,11 @@
451 }
452
453 /* ===========================================================================
454 * Test deflate() with preset dictionary
455 */
456 void test_dict_deflate(compr, comprLen)
457 Byte *compr;
458 uLong comprLen;
459 {
460 z_stream c_stream; /* compression stream */
461 int err;
462
463 c_stream.zalloc = zalloc;
464 c_stream.zfree = zfree;
@@ -488,14 +436,12 @@
488 }
489
490 /* ===========================================================================
491 * Test inflate() with a preset dictionary
492 */
493 void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
494 Byte *compr, *uncompr;
495 uLong comprLen, uncomprLen;
496 {
497 int err;
498 z_stream d_stream; /* decompression stream */
499
500 strcpy((char*)uncompr, "garbage");
501
@@ -539,17 +485,14 @@
539
540 /* ===========================================================================
541 * Usage: example [output.gz [input.gz]]
542 */
543
544 int main(argc, argv)
545 int argc;
546 char *argv[];
547 {
548 Byte *compr, *uncompr;
549 uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
550 uLong uncomprLen = comprLen;
551 static const char* myVersion = ZLIB_VERSION;
552
553 if (zlibVersion()[0] != myVersion[0]) {
554 fprintf(stderr, "incompatible zlib version\n");
555 exit(1);
@@ -588,15 +531,15 @@
588 test_large_deflate(compr, comprLen, uncompr, uncomprLen);
589 test_large_inflate(compr, comprLen, uncompr, uncomprLen);
590
591 test_flush(compr, &comprLen);
592 test_sync(compr, comprLen, uncompr, uncomprLen);
593 comprLen = uncomprLen;
594
595 test_dict_deflate(compr, comprLen);
596 test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
597
598 free(compr);
599 free(uncompr);
600
601 return 0;
602 }
603
--- compat/zlib/test/example.c
+++ compat/zlib/test/example.c
@@ -31,42 +31,19 @@
31 * stresses the compression code better, sorry...
32 */
33
34 static const char dictionary[] = "hello";
35 static uLong dictId; /* Adler32 value of the dictionary */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37 #ifdef Z_SOLO
38
39 void *myalloc(void *q, unsigned n, unsigned m) {
 
 
 
 
 
 
40 (void)q;
41 return calloc(n, m);
42 }
43
44 void myfree(void *q, void *p) {
 
45 (void)q;
46 free(p);
47 }
48
49 static alloc_func zalloc = myalloc;
@@ -75,22 +52,15 @@
52 #else /* !Z_SOLO */
53
54 static alloc_func zalloc = (alloc_func)0;
55 static free_func zfree = (free_func)0;
56
 
 
 
 
 
57 /* ===========================================================================
58 * Test compress() and uncompress()
59 */
60 void test_compress(Byte *compr, uLong comprLen, Byte *uncompr,
61 uLong uncomprLen) {
 
 
62 int err;
63 uLong len = (uLong)strlen(hello)+1;
64
65 err = compress(compr, &comprLen, (const Bytef*)hello, len);
66 CHECK_ERR(err, "compress");
@@ -109,15 +79,11 @@
79 }
80
81 /* ===========================================================================
82 * Test read/write of .gz files
83 */
84 void test_gzio(const char *fname, Byte *uncompr, uLong uncomprLen) {
 
 
 
 
85 #ifdef NO_GZCOMPRESS
86 fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
87 #else
88 int err;
89 int len = (int)strlen(hello)+1;
@@ -195,14 +161,11 @@
161 #endif /* Z_SOLO */
162
163 /* ===========================================================================
164 * Test deflate() with small buffers
165 */
166 void test_deflate(Byte *compr, uLong comprLen) {
 
 
 
167 z_stream c_stream; /* compression stream */
168 int err;
169 uLong len = (uLong)strlen(hello)+1;
170
171 c_stream.zalloc = zalloc;
@@ -233,14 +196,12 @@
196 }
197
198 /* ===========================================================================
199 * Test inflate() with small buffers
200 */
201 void test_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
202 uLong uncomprLen) {
 
 
203 int err;
204 z_stream d_stream; /* decompression stream */
205
206 strcpy((char*)uncompr, "garbage");
207
@@ -274,14 +235,12 @@
235 }
236
237 /* ===========================================================================
238 * Test deflate() with large buffers and dynamic change of compression level
239 */
240 void test_large_deflate(Byte *compr, uLong comprLen, Byte *uncompr,
241 uLong uncomprLen) {
 
 
242 z_stream c_stream; /* compression stream */
243 int err;
244
245 c_stream.zalloc = zalloc;
246 c_stream.zfree = zfree;
@@ -306,11 +265,11 @@
265 }
266
267 /* Feed in already compressed data and switch to no compression: */
268 deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
269 c_stream.next_in = compr;
270 c_stream.avail_in = (uInt)uncomprLen/2;
271 err = deflate(&c_stream, Z_NO_FLUSH);
272 CHECK_ERR(err, "deflate");
273
274 /* Switch back to compressing mode: */
275 deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
@@ -329,14 +288,12 @@
288 }
289
290 /* ===========================================================================
291 * Test inflate() with large buffers
292 */
293 void test_large_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
294 uLong uncomprLen) {
 
 
295 int err;
296 z_stream d_stream; /* decompression stream */
297
298 strcpy((char*)uncompr, "garbage");
299
@@ -359,11 +316,11 @@
316 }
317
318 err = inflateEnd(&d_stream);
319 CHECK_ERR(err, "inflateEnd");
320
321 if (d_stream.total_out != 2*uncomprLen + uncomprLen/2) {
322 fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
323 exit(1);
324 } else {
325 printf("large_inflate(): OK\n");
326 }
@@ -370,14 +327,11 @@
327 }
328
329 /* ===========================================================================
330 * Test deflate() with full flush
331 */
332 void test_flush(Byte *compr, uLong *comprLen) {
 
 
 
333 z_stream c_stream; /* compression stream */
334 int err;
335 uInt len = (uInt)strlen(hello)+1;
336
337 c_stream.zalloc = zalloc;
@@ -408,14 +362,11 @@
362 }
363
364 /* ===========================================================================
365 * Test inflateSync()
366 */
367 void test_sync(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen) {
 
 
 
368 int err;
369 z_stream d_stream; /* decompression stream */
370
371 strcpy((char*)uncompr, "garbage");
372
@@ -451,14 +402,11 @@
402 }
403
404 /* ===========================================================================
405 * Test deflate() with preset dictionary
406 */
407 void test_dict_deflate(Byte *compr, uLong comprLen) {
 
 
 
408 z_stream c_stream; /* compression stream */
409 int err;
410
411 c_stream.zalloc = zalloc;
412 c_stream.zfree = zfree;
@@ -488,14 +436,12 @@
436 }
437
438 /* ===========================================================================
439 * Test inflate() with a preset dictionary
440 */
441 void test_dict_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
442 uLong uncomprLen) {
 
 
443 int err;
444 z_stream d_stream; /* decompression stream */
445
446 strcpy((char*)uncompr, "garbage");
447
@@ -539,17 +485,14 @@
485
486 /* ===========================================================================
487 * Usage: example [output.gz [input.gz]]
488 */
489
490 int main(int argc, char *argv[]) {
 
 
 
491 Byte *compr, *uncompr;
492 uLong uncomprLen = 20000;
493 uLong comprLen = 3 * uncomprLen;
494 static const char* myVersion = ZLIB_VERSION;
495
496 if (zlibVersion()[0] != myVersion[0]) {
497 fprintf(stderr, "incompatible zlib version\n");
498 exit(1);
@@ -588,15 +531,15 @@
531 test_large_deflate(compr, comprLen, uncompr, uncomprLen);
532 test_large_inflate(compr, comprLen, uncompr, uncomprLen);
533
534 test_flush(compr, &comprLen);
535 test_sync(compr, comprLen, uncompr, uncomprLen);
536 comprLen = 3 * uncomprLen;
537
538 test_dict_deflate(compr, comprLen);
539 test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
540
541 free(compr);
542 free(uncompr);
543
544 return 0;
545 }
546
--- compat/zlib/test/infcover.c
+++ compat/zlib/test/infcover.c
@@ -371,11 +371,11 @@
371371
inf("", "bad window size", 0, 1, 0, Z_STREAM_ERROR);
372372
373373
mem_setup(&strm);
374374
strm.avail_in = 0;
375375
strm.next_in = Z_NULL;
376
- ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream));
376
+ ret = inflateInit_(&strm, "!", (int)sizeof(z_stream));
377377
assert(ret == Z_VERSION_ERROR);
378378
mem_done(&strm, "wrong version");
379379
380380
strm.avail_in = 0;
381381
strm.next_in = Z_NULL;
@@ -460,11 +460,12 @@
460460
return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0;
461461
}
462462
463463
local int push(void *desc, unsigned char *buf, unsigned len)
464464
{
465
- buf += len;
465
+ (void)buf;
466
+ (void)len;
466467
return desc != Z_NULL; /* force error if desc not null */
467468
}
468469
469470
/* cover inflateBack() up to common deflate data cases and after those */
470471
local void cover_back(void)
471472
--- compat/zlib/test/infcover.c
+++ compat/zlib/test/infcover.c
@@ -371,11 +371,11 @@
371 inf("", "bad window size", 0, 1, 0, Z_STREAM_ERROR);
372
373 mem_setup(&strm);
374 strm.avail_in = 0;
375 strm.next_in = Z_NULL;
376 ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream));
377 assert(ret == Z_VERSION_ERROR);
378 mem_done(&strm, "wrong version");
379
380 strm.avail_in = 0;
381 strm.next_in = Z_NULL;
@@ -460,11 +460,12 @@
460 return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0;
461 }
462
463 local int push(void *desc, unsigned char *buf, unsigned len)
464 {
465 buf += len;
 
466 return desc != Z_NULL; /* force error if desc not null */
467 }
468
469 /* cover inflateBack() up to common deflate data cases and after those */
470 local void cover_back(void)
471
--- compat/zlib/test/infcover.c
+++ compat/zlib/test/infcover.c
@@ -371,11 +371,11 @@
371 inf("", "bad window size", 0, 1, 0, Z_STREAM_ERROR);
372
373 mem_setup(&strm);
374 strm.avail_in = 0;
375 strm.next_in = Z_NULL;
376 ret = inflateInit_(&strm, "!", (int)sizeof(z_stream));
377 assert(ret == Z_VERSION_ERROR);
378 mem_done(&strm, "wrong version");
379
380 strm.avail_in = 0;
381 strm.next_in = Z_NULL;
@@ -460,11 +460,12 @@
460 return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0;
461 }
462
463 local int push(void *desc, unsigned char *buf, unsigned len)
464 {
465 (void)buf;
466 (void)len;
467 return desc != Z_NULL; /* force error if desc not null */
468 }
469
470 /* cover inflateBack() up to common deflate data cases and after those */
471 local void cover_back(void)
472
--- compat/zlib/test/minigzip.c
+++ compat/zlib/test/minigzip.c
@@ -57,11 +57,11 @@
5757
# include <unix.h> /* for fileno */
5858
#endif
5959
6060
#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
6161
#ifndef WIN32 /* unlink already in stdio.h for WIN32 */
62
- extern int unlink OF((const char *));
62
+ extern int unlink(const char *);
6363
#endif
6464
#endif
6565
6666
#if defined(UNDER_CE)
6767
# include <windows.h>
@@ -147,24 +147,16 @@
147147
148148
#if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)
149149
# include <unistd.h> /* for unlink() */
150150
#endif
151151
152
-void *myalloc OF((void *, unsigned, unsigned));
153
-void myfree OF((void *, void *));
154
-
155
-void *myalloc(q, n, m)
156
- void *q;
157
- unsigned n, m;
158
-{
152
+void *myalloc(void *q, unsigned n, unsigned m) {
159153
(void)q;
160154
return calloc(n, m);
161155
}
162156
163
-void myfree(q, p)
164
- void *q, *p;
165
-{
157
+void myfree(void *q, void *p) {
166158
(void)q;
167159
free(p);
168160
}
169161
170162
typedef struct gzFile_s {
@@ -173,33 +165,11 @@
173165
int err;
174166
char *msg;
175167
z_stream strm;
176168
} *gzFile;
177169
178
-gzFile gzopen OF((const char *, const char *));
179
-gzFile gzdopen OF((int, const char *));
180
-gzFile gz_open OF((const char *, int, const char *));
181
-
182
-gzFile gzopen(path, mode)
183
-const char *path;
184
-const char *mode;
185
-{
186
- return gz_open(path, -1, mode);
187
-}
188
-
189
-gzFile gzdopen(fd, mode)
190
-int fd;
191
-const char *mode;
192
-{
193
- return gz_open(NULL, fd, mode);
194
-}
195
-
196
-gzFile gz_open(path, fd, mode)
197
- const char *path;
198
- int fd;
199
- const char *mode;
200
-{
170
+gzFile gz_open(const char *path, int fd, const char *mode) {
201171
gzFile gz;
202172
int ret;
203173
204174
gz = malloc(sizeof(struct gzFile_s));
205175
if (gz == NULL)
@@ -229,17 +199,19 @@
229199
gz->err = 0;
230200
gz->msg = "";
231201
return gz;
232202
}
233203
234
-int gzwrite OF((gzFile, const void *, unsigned));
204
+gzFile gzopen(const char *path, const char *mode) {
205
+ return gz_open(path, -1, mode);
206
+}
207
+
208
+gzFile gzdopen(int fd, const char *mode) {
209
+ return gz_open(NULL, fd, mode);
210
+}
235211
236
-int gzwrite(gz, buf, len)
237
- gzFile gz;
238
- const void *buf;
239
- unsigned len;
240
-{
212
+int gzwrite(gzFile gz, const void *buf, unsigned len) {
241213
z_stream *strm;
242214
unsigned char out[BUFLEN];
243215
244216
if (gz == NULL || !gz->write)
245217
return 0;
@@ -253,17 +225,11 @@
253225
fwrite(out, 1, BUFLEN - strm->avail_out, gz->file);
254226
} while (strm->avail_out == 0);
255227
return len;
256228
}
257229
258
-int gzread OF((gzFile, void *, unsigned));
259
-
260
-int gzread(gz, buf, len)
261
- gzFile gz;
262
- void *buf;
263
- unsigned len;
264
-{
230
+int gzread(gzFile gz, void *buf, unsigned len) {
265231
int ret;
266232
unsigned got;
267233
unsigned char in[1];
268234
z_stream *strm;
269235
@@ -290,15 +256,11 @@
290256
inflateReset(strm);
291257
} while (strm->avail_out);
292258
return len - strm->avail_out;
293259
}
294260
295
-int gzclose OF((gzFile));
296
-
297
-int gzclose(gz)
298
- gzFile gz;
299
-{
261
+int gzclose(gzFile gz) {
300262
z_stream *strm;
301263
unsigned char out[BUFLEN];
302264
303265
if (gz == NULL)
304266
return Z_STREAM_ERROR;
@@ -319,85 +281,33 @@
319281
fclose(gz->file);
320282
free(gz);
321283
return Z_OK;
322284
}
323285
324
-const char *gzerror OF((gzFile, int *));
325
-
326
-const char *gzerror(gz, err)
327
- gzFile gz;
328
- int *err;
329
-{
286
+const char *gzerror(gzFile gz, int *err) {
330287
*err = gz->err;
331288
return gz->msg;
332289
}
333290
334291
#endif
335292
336293
static char *prog;
337294
338
-void error OF((const char *msg));
339
-void gz_compress OF((FILE *in, gzFile out));
340
-#ifdef USE_MMAP
341
-int gz_compress_mmap OF((FILE *in, gzFile out));
342
-#endif
343
-void gz_uncompress OF((gzFile in, FILE *out));
344
-void file_compress OF((char *file, char *mode));
345
-void file_uncompress OF((char *file));
346
-int main OF((int argc, char *argv[]));
347
-
348295
/* ===========================================================================
349296
* Display error message and exit
350297
*/
351
-void error(msg)
352
- const char *msg;
353
-{
298
+void error(const char *msg) {
354299
fprintf(stderr, "%s: %s\n", prog, msg);
355300
exit(1);
356301
}
357302
358
-/* ===========================================================================
359
- * Compress input to output then close both files.
360
- */
361
-
362
-void gz_compress(in, out)
363
- FILE *in;
364
- gzFile out;
365
-{
366
- local char buf[BUFLEN];
367
- int len;
368
- int err;
369
-
370
-#ifdef USE_MMAP
371
- /* Try first compressing with mmap. If mmap fails (minigzip used in a
372
- * pipe), use the normal fread loop.
373
- */
374
- if (gz_compress_mmap(in, out) == Z_OK) return;
375
-#endif
376
- for (;;) {
377
- len = (int)fread(buf, 1, sizeof(buf), in);
378
- if (ferror(in)) {
379
- perror("fread");
380
- exit(1);
381
- }
382
- if (len == 0) break;
383
-
384
- if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
385
- }
386
- fclose(in);
387
- if (gzclose(out) != Z_OK) error("failed gzclose");
388
-}
389
-
390303
#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <[email protected]> */
391304
392305
/* Try compressing the input file at once using mmap. Return Z_OK if
393306
* if success, Z_ERRNO otherwise.
394307
*/
395
-int gz_compress_mmap(in, out)
396
- FILE *in;
397
- gzFile out;
398
-{
308
+int gz_compress_mmap(FILE *in, gzFile out) {
399309
int len;
400310
int err;
401311
int ifd = fileno(in);
402312
caddr_t buf; /* mmap'ed buffer for the entire input file */
403313
off_t buf_len; /* length of the input file */
@@ -421,18 +331,44 @@
421331
fclose(in);
422332
if (gzclose(out) != Z_OK) error("failed gzclose");
423333
return Z_OK;
424334
}
425335
#endif /* USE_MMAP */
336
+
337
+/* ===========================================================================
338
+ * Compress input to output then close both files.
339
+ */
340
+
341
+void gz_compress(FILE *in, gzFile out) {
342
+ local char buf[BUFLEN];
343
+ int len;
344
+ int err;
345
+
346
+#ifdef USE_MMAP
347
+ /* Try first compressing with mmap. If mmap fails (minigzip used in a
348
+ * pipe), use the normal fread loop.
349
+ */
350
+ if (gz_compress_mmap(in, out) == Z_OK) return;
351
+#endif
352
+ for (;;) {
353
+ len = (int)fread(buf, 1, sizeof(buf), in);
354
+ if (ferror(in)) {
355
+ perror("fread");
356
+ exit(1);
357
+ }
358
+ if (len == 0) break;
359
+
360
+ if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
361
+ }
362
+ fclose(in);
363
+ if (gzclose(out) != Z_OK) error("failed gzclose");
364
+}
426365
427366
/* ===========================================================================
428367
* Uncompress input to output then close both files.
429368
*/
430
-void gz_uncompress(in, out)
431
- gzFile in;
432
- FILE *out;
433
-{
369
+void gz_uncompress(gzFile in, FILE *out) {
434370
local char buf[BUFLEN];
435371
int len;
436372
int err;
437373
438374
for (;;) {
@@ -452,14 +388,11 @@
452388
453389
/* ===========================================================================
454390
* Compress the given file: create a corresponding .gz file and remove the
455391
* original.
456392
*/
457
-void file_compress(file, mode)
458
- char *file;
459
- char *mode;
460
-{
393
+void file_compress(char *file, char *mode) {
461394
local char outfile[MAX_NAME_LEN];
462395
FILE *in;
463396
gzFile out;
464397
465398
if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) {
@@ -491,13 +424,11 @@
491424
492425
493426
/* ===========================================================================
494427
* Uncompress the given file and remove the original.
495428
*/
496
-void file_uncompress(file)
497
- char *file;
498
-{
429
+void file_uncompress(char *file) {
499430
local char buf[MAX_NAME_LEN];
500431
char *infile, *outfile;
501432
FILE *out;
502433
gzFile in;
503434
z_size_t len = strlen(file);
@@ -551,14 +482,11 @@
551482
* -h : compress with Z_HUFFMAN_ONLY
552483
* -r : compress with Z_RLE
553484
* -1 to -9 : compression level
554485
*/
555486
556
-int main(argc, argv)
557
- int argc;
558
- char *argv[];
559
-{
487
+int main(int argc, char *argv[]) {
560488
int copyout = 0;
561489
int uncompr = 0;
562490
gzFile file;
563491
char *bname, outmode[20];
564492
565493
--- compat/zlib/test/minigzip.c
+++ compat/zlib/test/minigzip.c
@@ -57,11 +57,11 @@
57 # include <unix.h> /* for fileno */
58 #endif
59
60 #if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
61 #ifndef WIN32 /* unlink already in stdio.h for WIN32 */
62 extern int unlink OF((const char *));
63 #endif
64 #endif
65
66 #if defined(UNDER_CE)
67 # include <windows.h>
@@ -147,24 +147,16 @@
147
148 #if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)
149 # include <unistd.h> /* for unlink() */
150 #endif
151
152 void *myalloc OF((void *, unsigned, unsigned));
153 void myfree OF((void *, void *));
154
155 void *myalloc(q, n, m)
156 void *q;
157 unsigned n, m;
158 {
159 (void)q;
160 return calloc(n, m);
161 }
162
163 void myfree(q, p)
164 void *q, *p;
165 {
166 (void)q;
167 free(p);
168 }
169
170 typedef struct gzFile_s {
@@ -173,33 +165,11 @@
173 int err;
174 char *msg;
175 z_stream strm;
176 } *gzFile;
177
178 gzFile gzopen OF((const char *, const char *));
179 gzFile gzdopen OF((int, const char *));
180 gzFile gz_open OF((const char *, int, const char *));
181
182 gzFile gzopen(path, mode)
183 const char *path;
184 const char *mode;
185 {
186 return gz_open(path, -1, mode);
187 }
188
189 gzFile gzdopen(fd, mode)
190 int fd;
191 const char *mode;
192 {
193 return gz_open(NULL, fd, mode);
194 }
195
196 gzFile gz_open(path, fd, mode)
197 const char *path;
198 int fd;
199 const char *mode;
200 {
201 gzFile gz;
202 int ret;
203
204 gz = malloc(sizeof(struct gzFile_s));
205 if (gz == NULL)
@@ -229,17 +199,19 @@
229 gz->err = 0;
230 gz->msg = "";
231 return gz;
232 }
233
234 int gzwrite OF((gzFile, const void *, unsigned));
 
 
 
 
 
 
235
236 int gzwrite(gz, buf, len)
237 gzFile gz;
238 const void *buf;
239 unsigned len;
240 {
241 z_stream *strm;
242 unsigned char out[BUFLEN];
243
244 if (gz == NULL || !gz->write)
245 return 0;
@@ -253,17 +225,11 @@
253 fwrite(out, 1, BUFLEN - strm->avail_out, gz->file);
254 } while (strm->avail_out == 0);
255 return len;
256 }
257
258 int gzread OF((gzFile, void *, unsigned));
259
260 int gzread(gz, buf, len)
261 gzFile gz;
262 void *buf;
263 unsigned len;
264 {
265 int ret;
266 unsigned got;
267 unsigned char in[1];
268 z_stream *strm;
269
@@ -290,15 +256,11 @@
290 inflateReset(strm);
291 } while (strm->avail_out);
292 return len - strm->avail_out;
293 }
294
295 int gzclose OF((gzFile));
296
297 int gzclose(gz)
298 gzFile gz;
299 {
300 z_stream *strm;
301 unsigned char out[BUFLEN];
302
303 if (gz == NULL)
304 return Z_STREAM_ERROR;
@@ -319,85 +281,33 @@
319 fclose(gz->file);
320 free(gz);
321 return Z_OK;
322 }
323
324 const char *gzerror OF((gzFile, int *));
325
326 const char *gzerror(gz, err)
327 gzFile gz;
328 int *err;
329 {
330 *err = gz->err;
331 return gz->msg;
332 }
333
334 #endif
335
336 static char *prog;
337
338 void error OF((const char *msg));
339 void gz_compress OF((FILE *in, gzFile out));
340 #ifdef USE_MMAP
341 int gz_compress_mmap OF((FILE *in, gzFile out));
342 #endif
343 void gz_uncompress OF((gzFile in, FILE *out));
344 void file_compress OF((char *file, char *mode));
345 void file_uncompress OF((char *file));
346 int main OF((int argc, char *argv[]));
347
348 /* ===========================================================================
349 * Display error message and exit
350 */
351 void error(msg)
352 const char *msg;
353 {
354 fprintf(stderr, "%s: %s\n", prog, msg);
355 exit(1);
356 }
357
358 /* ===========================================================================
359 * Compress input to output then close both files.
360 */
361
362 void gz_compress(in, out)
363 FILE *in;
364 gzFile out;
365 {
366 local char buf[BUFLEN];
367 int len;
368 int err;
369
370 #ifdef USE_MMAP
371 /* Try first compressing with mmap. If mmap fails (minigzip used in a
372 * pipe), use the normal fread loop.
373 */
374 if (gz_compress_mmap(in, out) == Z_OK) return;
375 #endif
376 for (;;) {
377 len = (int)fread(buf, 1, sizeof(buf), in);
378 if (ferror(in)) {
379 perror("fread");
380 exit(1);
381 }
382 if (len == 0) break;
383
384 if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
385 }
386 fclose(in);
387 if (gzclose(out) != Z_OK) error("failed gzclose");
388 }
389
390 #ifdef USE_MMAP /* MMAP version, Miguel Albrecht <[email protected]> */
391
392 /* Try compressing the input file at once using mmap. Return Z_OK if
393 * if success, Z_ERRNO otherwise.
394 */
395 int gz_compress_mmap(in, out)
396 FILE *in;
397 gzFile out;
398 {
399 int len;
400 int err;
401 int ifd = fileno(in);
402 caddr_t buf; /* mmap'ed buffer for the entire input file */
403 off_t buf_len; /* length of the input file */
@@ -421,18 +331,44 @@
421 fclose(in);
422 if (gzclose(out) != Z_OK) error("failed gzclose");
423 return Z_OK;
424 }
425 #endif /* USE_MMAP */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
427 /* ===========================================================================
428 * Uncompress input to output then close both files.
429 */
430 void gz_uncompress(in, out)
431 gzFile in;
432 FILE *out;
433 {
434 local char buf[BUFLEN];
435 int len;
436 int err;
437
438 for (;;) {
@@ -452,14 +388,11 @@
452
453 /* ===========================================================================
454 * Compress the given file: create a corresponding .gz file and remove the
455 * original.
456 */
457 void file_compress(file, mode)
458 char *file;
459 char *mode;
460 {
461 local char outfile[MAX_NAME_LEN];
462 FILE *in;
463 gzFile out;
464
465 if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) {
@@ -491,13 +424,11 @@
491
492
493 /* ===========================================================================
494 * Uncompress the given file and remove the original.
495 */
496 void file_uncompress(file)
497 char *file;
498 {
499 local char buf[MAX_NAME_LEN];
500 char *infile, *outfile;
501 FILE *out;
502 gzFile in;
503 z_size_t len = strlen(file);
@@ -551,14 +482,11 @@
551 * -h : compress with Z_HUFFMAN_ONLY
552 * -r : compress with Z_RLE
553 * -1 to -9 : compression level
554 */
555
556 int main(argc, argv)
557 int argc;
558 char *argv[];
559 {
560 int copyout = 0;
561 int uncompr = 0;
562 gzFile file;
563 char *bname, outmode[20];
564
565
--- compat/zlib/test/minigzip.c
+++ compat/zlib/test/minigzip.c
@@ -57,11 +57,11 @@
57 # include <unix.h> /* for fileno */
58 #endif
59
60 #if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
61 #ifndef WIN32 /* unlink already in stdio.h for WIN32 */
62 extern int unlink(const char *);
63 #endif
64 #endif
65
66 #if defined(UNDER_CE)
67 # include <windows.h>
@@ -147,24 +147,16 @@
147
148 #if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)
149 # include <unistd.h> /* for unlink() */
150 #endif
151
152 void *myalloc(void *q, unsigned n, unsigned m) {
 
 
 
 
 
 
153 (void)q;
154 return calloc(n, m);
155 }
156
157 void myfree(void *q, void *p) {
 
 
158 (void)q;
159 free(p);
160 }
161
162 typedef struct gzFile_s {
@@ -173,33 +165,11 @@
165 int err;
166 char *msg;
167 z_stream strm;
168 } *gzFile;
169
170 gzFile gz_open(const char *path, int fd, const char *mode) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171 gzFile gz;
172 int ret;
173
174 gz = malloc(sizeof(struct gzFile_s));
175 if (gz == NULL)
@@ -229,17 +199,19 @@
199 gz->err = 0;
200 gz->msg = "";
201 return gz;
202 }
203
204 gzFile gzopen(const char *path, const char *mode) {
205 return gz_open(path, -1, mode);
206 }
207
208 gzFile gzdopen(int fd, const char *mode) {
209 return gz_open(NULL, fd, mode);
210 }
211
212 int gzwrite(gzFile gz, const void *buf, unsigned len) {
 
 
 
 
213 z_stream *strm;
214 unsigned char out[BUFLEN];
215
216 if (gz == NULL || !gz->write)
217 return 0;
@@ -253,17 +225,11 @@
225 fwrite(out, 1, BUFLEN - strm->avail_out, gz->file);
226 } while (strm->avail_out == 0);
227 return len;
228 }
229
230 int gzread(gzFile gz, void *buf, unsigned len) {
 
 
 
 
 
 
231 int ret;
232 unsigned got;
233 unsigned char in[1];
234 z_stream *strm;
235
@@ -290,15 +256,11 @@
256 inflateReset(strm);
257 } while (strm->avail_out);
258 return len - strm->avail_out;
259 }
260
261 int gzclose(gzFile gz) {
 
 
 
 
262 z_stream *strm;
263 unsigned char out[BUFLEN];
264
265 if (gz == NULL)
266 return Z_STREAM_ERROR;
@@ -319,85 +281,33 @@
281 fclose(gz->file);
282 free(gz);
283 return Z_OK;
284 }
285
286 const char *gzerror(gzFile gz, int *err) {
 
 
 
 
 
287 *err = gz->err;
288 return gz->msg;
289 }
290
291 #endif
292
293 static char *prog;
294
 
 
 
 
 
 
 
 
 
 
295 /* ===========================================================================
296 * Display error message and exit
297 */
298 void error(const char *msg) {
 
 
299 fprintf(stderr, "%s: %s\n", prog, msg);
300 exit(1);
301 }
302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303 #ifdef USE_MMAP /* MMAP version, Miguel Albrecht <[email protected]> */
304
305 /* Try compressing the input file at once using mmap. Return Z_OK if
306 * if success, Z_ERRNO otherwise.
307 */
308 int gz_compress_mmap(FILE *in, gzFile out) {
 
 
 
309 int len;
310 int err;
311 int ifd = fileno(in);
312 caddr_t buf; /* mmap'ed buffer for the entire input file */
313 off_t buf_len; /* length of the input file */
@@ -421,18 +331,44 @@
331 fclose(in);
332 if (gzclose(out) != Z_OK) error("failed gzclose");
333 return Z_OK;
334 }
335 #endif /* USE_MMAP */
336
337 /* ===========================================================================
338 * Compress input to output then close both files.
339 */
340
341 void gz_compress(FILE *in, gzFile out) {
342 local char buf[BUFLEN];
343 int len;
344 int err;
345
346 #ifdef USE_MMAP
347 /* Try first compressing with mmap. If mmap fails (minigzip used in a
348 * pipe), use the normal fread loop.
349 */
350 if (gz_compress_mmap(in, out) == Z_OK) return;
351 #endif
352 for (;;) {
353 len = (int)fread(buf, 1, sizeof(buf), in);
354 if (ferror(in)) {
355 perror("fread");
356 exit(1);
357 }
358 if (len == 0) break;
359
360 if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
361 }
362 fclose(in);
363 if (gzclose(out) != Z_OK) error("failed gzclose");
364 }
365
366 /* ===========================================================================
367 * Uncompress input to output then close both files.
368 */
369 void gz_uncompress(gzFile in, FILE *out) {
 
 
 
370 local char buf[BUFLEN];
371 int len;
372 int err;
373
374 for (;;) {
@@ -452,14 +388,11 @@
388
389 /* ===========================================================================
390 * Compress the given file: create a corresponding .gz file and remove the
391 * original.
392 */
393 void file_compress(char *file, char *mode) {
 
 
 
394 local char outfile[MAX_NAME_LEN];
395 FILE *in;
396 gzFile out;
397
398 if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) {
@@ -491,13 +424,11 @@
424
425
426 /* ===========================================================================
427 * Uncompress the given file and remove the original.
428 */
429 void file_uncompress(char *file) {
 
 
430 local char buf[MAX_NAME_LEN];
431 char *infile, *outfile;
432 FILE *out;
433 gzFile in;
434 z_size_t len = strlen(file);
@@ -551,14 +482,11 @@
482 * -h : compress with Z_HUFFMAN_ONLY
483 * -r : compress with Z_RLE
484 * -1 to -9 : compression level
485 */
486
487 int main(int argc, char *argv[]) {
 
 
 
488 int copyout = 0;
489 int uncompr = 0;
490 gzFile file;
491 char *bname, outmode[20];
492
493
--- compat/zlib/treebuild.xml
+++ compat/zlib/treebuild.xml
@@ -1,8 +1,8 @@
11
<?xml version="1.0" ?>
2
-<package name="zlib" version="1.2.13">
3
- <library name="zlib" dlversion="1.2.13" dlname="z">
2
+<package name="zlib" version="1.3">
3
+ <library name="zlib" dlversion="1.3" dlname="z">
44
<property name="description"> zip compression library </property>
55
<property name="include-target-dir" value="$(@PACKAGE/install-includedir)" />
66
77
<!-- fixme: not implemented yet -->
88
<property name="compiler/c/inline" value="yes" />
99
--- compat/zlib/treebuild.xml
+++ compat/zlib/treebuild.xml
@@ -1,8 +1,8 @@
1 <?xml version="1.0" ?>
2 <package name="zlib" version="1.2.13">
3 <library name="zlib" dlversion="1.2.13" dlname="z">
4 <property name="description"> zip compression library </property>
5 <property name="include-target-dir" value="$(@PACKAGE/install-includedir)" />
6
7 <!-- fixme: not implemented yet -->
8 <property name="compiler/c/inline" value="yes" />
9
--- compat/zlib/treebuild.xml
+++ compat/zlib/treebuild.xml
@@ -1,8 +1,8 @@
1 <?xml version="1.0" ?>
2 <package name="zlib" version="1.3">
3 <library name="zlib" dlversion="1.3" dlname="z">
4 <property name="description"> zip compression library </property>
5 <property name="include-target-dir" value="$(@PACKAGE/install-includedir)" />
6
7 <!-- fixme: not implemented yet -->
8 <property name="compiler/c/inline" value="yes" />
9
+225 -303
--- compat/zlib/trees.c
+++ compat/zlib/trees.c
@@ -120,43 +120,120 @@
120120
int extra_base; /* base index for extra_bits */
121121
int elems; /* max number of elements in the tree */
122122
int max_length; /* max bit length for the codes */
123123
};
124124
125
-local const static_tree_desc static_l_desc =
125
+#ifdef NO_INIT_GLOBAL_POINTERS
126
+# define TCONST
127
+#else
128
+# define TCONST const
129
+#endif
130
+
131
+local TCONST static_tree_desc static_l_desc =
126132
{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
127133
128
-local const static_tree_desc static_d_desc =
134
+local TCONST static_tree_desc static_d_desc =
129135
{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
130136
131
-local const static_tree_desc static_bl_desc =
137
+local TCONST static_tree_desc static_bl_desc =
132138
{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
133139
134140
/* ===========================================================================
135
- * Local (static) routines in this file.
141
+ * Output a short LSB first on the stream.
142
+ * IN assertion: there is enough room in pendingBuf.
143
+ */
144
+#define put_short(s, w) { \
145
+ put_byte(s, (uch)((w) & 0xff)); \
146
+ put_byte(s, (uch)((ush)(w) >> 8)); \
147
+}
148
+
149
+/* ===========================================================================
150
+ * Reverse the first len bits of a code, using straightforward code (a faster
151
+ * method would use a table)
152
+ * IN assertion: 1 <= len <= 15
153
+ */
154
+local unsigned bi_reverse(unsigned code, int len) {
155
+ register unsigned res = 0;
156
+ do {
157
+ res |= code & 1;
158
+ code >>= 1, res <<= 1;
159
+ } while (--len > 0);
160
+ return res >> 1;
161
+}
162
+
163
+/* ===========================================================================
164
+ * Flush the bit buffer, keeping at most 7 bits in it.
165
+ */
166
+local void bi_flush(deflate_state *s) {
167
+ if (s->bi_valid == 16) {
168
+ put_short(s, s->bi_buf);
169
+ s->bi_buf = 0;
170
+ s->bi_valid = 0;
171
+ } else if (s->bi_valid >= 8) {
172
+ put_byte(s, (Byte)s->bi_buf);
173
+ s->bi_buf >>= 8;
174
+ s->bi_valid -= 8;
175
+ }
176
+}
177
+
178
+/* ===========================================================================
179
+ * Flush the bit buffer and align the output on a byte boundary
180
+ */
181
+local void bi_windup(deflate_state *s) {
182
+ if (s->bi_valid > 8) {
183
+ put_short(s, s->bi_buf);
184
+ } else if (s->bi_valid > 0) {
185
+ put_byte(s, (Byte)s->bi_buf);
186
+ }
187
+ s->bi_buf = 0;
188
+ s->bi_valid = 0;
189
+#ifdef ZLIB_DEBUG
190
+ s->bits_sent = (s->bits_sent + 7) & ~7;
191
+#endif
192
+}
193
+
194
+/* ===========================================================================
195
+ * Generate the codes for a given tree and bit counts (which need not be
196
+ * optimal).
197
+ * IN assertion: the array bl_count contains the bit length statistics for
198
+ * the given tree and the field len is set for all tree elements.
199
+ * OUT assertion: the field code is set for all tree elements of non
200
+ * zero code length.
136201
*/
137
-
138
-local void tr_static_init OF((void));
139
-local void init_block OF((deflate_state *s));
140
-local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
141
-local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
142
-local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
143
-local void build_tree OF((deflate_state *s, tree_desc *desc));
144
-local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
145
-local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
146
-local int build_bl_tree OF((deflate_state *s));
147
-local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
148
- int blcodes));
149
-local void compress_block OF((deflate_state *s, const ct_data *ltree,
150
- const ct_data *dtree));
151
-local int detect_data_type OF((deflate_state *s));
152
-local unsigned bi_reverse OF((unsigned code, int len));
153
-local void bi_windup OF((deflate_state *s));
154
-local void bi_flush OF((deflate_state *s));
202
+local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) {
203
+ ush next_code[MAX_BITS+1]; /* next code value for each bit length */
204
+ unsigned code = 0; /* running code value */
205
+ int bits; /* bit index */
206
+ int n; /* code index */
207
+
208
+ /* The distribution counts are first used to generate the code values
209
+ * without bit reversal.
210
+ */
211
+ for (bits = 1; bits <= MAX_BITS; bits++) {
212
+ code = (code + bl_count[bits - 1]) << 1;
213
+ next_code[bits] = (ush)code;
214
+ }
215
+ /* Check that the bit counts in bl_count are consistent. The last code
216
+ * must be all ones.
217
+ */
218
+ Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1,
219
+ "inconsistent bit counts");
220
+ Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
221
+
222
+ for (n = 0; n <= max_code; n++) {
223
+ int len = tree[n].Len;
224
+ if (len == 0) continue;
225
+ /* Now reverse the bits */
226
+ tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
227
+
228
+ Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
229
+ n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1));
230
+ }
231
+}
155232
156233
#ifdef GEN_TREES_H
157
-local void gen_trees_header OF((void));
234
+local void gen_trees_header(void);
158235
#endif
159236
160237
#ifndef ZLIB_DEBUG
161238
# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
162239
/* Send a code of the given tree. c and tree must not have side effects */
@@ -165,31 +242,16 @@
165242
# define send_code(s, c, tree) \
166243
{ if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
167244
send_bits(s, tree[c].Code, tree[c].Len); }
168245
#endif
169246
170
-/* ===========================================================================
171
- * Output a short LSB first on the stream.
172
- * IN assertion: there is enough room in pendingBuf.
173
- */
174
-#define put_short(s, w) { \
175
- put_byte(s, (uch)((w) & 0xff)); \
176
- put_byte(s, (uch)((ush)(w) >> 8)); \
177
-}
178
-
179247
/* ===========================================================================
180248
* Send a value on a given number of bits.
181249
* IN assertion: length <= 16 and value fits in length bits.
182250
*/
183251
#ifdef ZLIB_DEBUG
184
-local void send_bits OF((deflate_state *s, int value, int length));
185
-
186
-local void send_bits(s, value, length)
187
- deflate_state *s;
188
- int value; /* value to send */
189
- int length; /* number of bits */
190
-{
252
+local void send_bits(deflate_state *s, int value, int length) {
191253
Tracevv((stderr," l %2d v %4x ", length, value));
192254
Assert(length > 0 && length <= 15, "invalid length");
193255
s->bits_sent += (ulg)length;
194256
195257
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
@@ -227,12 +289,11 @@
227289
/* the arguments must not have side effects */
228290
229291
/* ===========================================================================
230292
* Initialize the various 'constant' tables.
231293
*/
232
-local void tr_static_init()
233
-{
294
+local void tr_static_init(void) {
234295
#if defined(GEN_TREES_H) || !defined(STDC)
235296
static int static_init_done = 0;
236297
int n; /* iterates over tree elements */
237298
int bits; /* bit counter */
238299
int length; /* length value */
@@ -321,12 +382,11 @@
321382
322383
# define SEPARATOR(i, last, width) \
323384
((i) == (last)? "\n};\n\n" : \
324385
((i) % (width) == (width) - 1 ? ",\n" : ", "))
325386
326
-void gen_trees_header()
327
-{
387
+void gen_trees_header(void) {
328388
FILE *header = fopen("trees.h", "w");
329389
int i;
330390
331391
Assert (header != NULL, "Can't open trees.h");
332392
fprintf(header,
@@ -370,17 +430,31 @@
370430
}
371431
372432
fclose(header);
373433
}
374434
#endif /* GEN_TREES_H */
435
+
436
+/* ===========================================================================
437
+ * Initialize a new block.
438
+ */
439
+local void init_block(deflate_state *s) {
440
+ int n; /* iterates over tree elements */
441
+
442
+ /* Initialize the trees. */
443
+ for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
444
+ for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
445
+ for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
446
+
447
+ s->dyn_ltree[END_BLOCK].Freq = 1;
448
+ s->opt_len = s->static_len = 0L;
449
+ s->sym_next = s->matches = 0;
450
+}
375451
376452
/* ===========================================================================
377453
* Initialize the tree data structures for a new zlib stream.
378454
*/
379
-void ZLIB_INTERNAL _tr_init(s)
380
- deflate_state *s;
381
-{
455
+void ZLIB_INTERNAL _tr_init(deflate_state *s) {
382456
tr_static_init();
383457
384458
s->l_desc.dyn_tree = s->dyn_ltree;
385459
s->l_desc.stat_desc = &static_l_desc;
386460
@@ -399,28 +473,10 @@
399473
400474
/* Initialize the first block of the first file: */
401475
init_block(s);
402476
}
403477
404
-/* ===========================================================================
405
- * Initialize a new block.
406
- */
407
-local void init_block(s)
408
- deflate_state *s;
409
-{
410
- int n; /* iterates over tree elements */
411
-
412
- /* Initialize the trees. */
413
- for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
414
- for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
415
- for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
416
-
417
- s->dyn_ltree[END_BLOCK].Freq = 1;
418
- s->opt_len = s->static_len = 0L;
419
- s->sym_next = s->matches = 0;
420
-}
421
-
422478
#define SMALLEST 1
423479
/* Index within the heap array of least frequent node in the Huffman tree */
424480
425481
426482
/* ===========================================================================
@@ -446,15 +502,11 @@
446502
* Restore the heap property by moving down the tree starting at node k,
447503
* exchanging a node with the smallest of its two sons if necessary, stopping
448504
* when the heap property is re-established (each father smaller than its
449505
* two sons).
450506
*/
451
-local void pqdownheap(s, tree, k)
452
- deflate_state *s;
453
- ct_data *tree; /* the tree to restore */
454
- int k; /* node to move down */
455
-{
507
+local void pqdownheap(deflate_state *s, ct_data *tree, int k) {
456508
int v = s->heap[k];
457509
int j = k << 1; /* left son of k */
458510
while (j <= s->heap_len) {
459511
/* Set j to the smallest of the two sons: */
460512
if (j < s->heap_len &&
@@ -481,14 +533,11 @@
481533
* OUT assertions: the field len is set to the optimal bit length, the
482534
* array bl_count contains the frequencies for each bit length.
483535
* The length opt_len is updated; static_len is also updated if stree is
484536
* not null.
485537
*/
486
-local void gen_bitlen(s, desc)
487
- deflate_state *s;
488
- tree_desc *desc; /* the tree descriptor */
489
-{
538
+local void gen_bitlen(deflate_state *s, tree_desc *desc) {
490539
ct_data *tree = desc->dyn_tree;
491540
int max_code = desc->max_code;
492541
const ct_data *stree = desc->stat_desc->static_tree;
493542
const intf *extra = desc->stat_desc->extra_bits;
494543
int base = desc->stat_desc->extra_base;
@@ -559,65 +608,23 @@
559608
n--;
560609
}
561610
}
562611
}
563612
564
-/* ===========================================================================
565
- * Generate the codes for a given tree and bit counts (which need not be
566
- * optimal).
567
- * IN assertion: the array bl_count contains the bit length statistics for
568
- * the given tree and the field len is set for all tree elements.
569
- * OUT assertion: the field code is set for all tree elements of non
570
- * zero code length.
571
- */
572
-local void gen_codes(tree, max_code, bl_count)
573
- ct_data *tree; /* the tree to decorate */
574
- int max_code; /* largest code with non zero frequency */
575
- ushf *bl_count; /* number of codes at each bit length */
576
-{
577
- ush next_code[MAX_BITS+1]; /* next code value for each bit length */
578
- unsigned code = 0; /* running code value */
579
- int bits; /* bit index */
580
- int n; /* code index */
581
-
582
- /* The distribution counts are first used to generate the code values
583
- * without bit reversal.
584
- */
585
- for (bits = 1; bits <= MAX_BITS; bits++) {
586
- code = (code + bl_count[bits - 1]) << 1;
587
- next_code[bits] = (ush)code;
588
- }
589
- /* Check that the bit counts in bl_count are consistent. The last code
590
- * must be all ones.
591
- */
592
- Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1,
593
- "inconsistent bit counts");
594
- Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
595
-
596
- for (n = 0; n <= max_code; n++) {
597
- int len = tree[n].Len;
598
- if (len == 0) continue;
599
- /* Now reverse the bits */
600
- tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
601
-
602
- Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
603
- n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1));
604
- }
605
-}
613
+#ifdef DUMP_BL_TREE
614
+# include <stdio.h>
615
+#endif
606616
607617
/* ===========================================================================
608618
* Construct one Huffman tree and assigns the code bit strings and lengths.
609619
* Update the total bit length for the current block.
610620
* IN assertion: the field freq is set for all tree elements.
611621
* OUT assertions: the fields len and code are set to the optimal bit length
612622
* and corresponding code. The length opt_len is updated; static_len is
613623
* also updated if stree is not null. The field max_code is set.
614624
*/
615
-local void build_tree(s, desc)
616
- deflate_state *s;
617
- tree_desc *desc; /* the tree descriptor */
618
-{
625
+local void build_tree(deflate_state *s, tree_desc *desc) {
619626
ct_data *tree = desc->dyn_tree;
620627
const ct_data *stree = desc->stat_desc->static_tree;
621628
int elems = desc->stat_desc->elems;
622629
int n, m; /* iterate over heap elements */
623630
int max_code = -1; /* largest code with non zero frequency */
@@ -698,15 +705,11 @@
698705
699706
/* ===========================================================================
700707
* Scan a literal or distance tree to determine the frequencies of the codes
701708
* in the bit length tree.
702709
*/
703
-local void scan_tree(s, tree, max_code)
704
- deflate_state *s;
705
- ct_data *tree; /* the tree to be scanned */
706
- int max_code; /* and its largest code of non zero frequency */
707
-{
710
+local void scan_tree(deflate_state *s, ct_data *tree, int max_code) {
708711
int n; /* iterates over all tree elements */
709712
int prevlen = -1; /* last emitted length */
710713
int curlen; /* length of current code */
711714
int nextlen = tree[0].Len; /* length of next code */
712715
int count = 0; /* repeat count of the current code */
@@ -743,15 +746,11 @@
743746
744747
/* ===========================================================================
745748
* Send a literal or distance tree in compressed form, using the codes in
746749
* bl_tree.
747750
*/
748
-local void send_tree(s, tree, max_code)
749
- deflate_state *s;
750
- ct_data *tree; /* the tree to be scanned */
751
- int max_code; /* and its largest code of non zero frequency */
752
-{
751
+local void send_tree(deflate_state *s, ct_data *tree, int max_code) {
753752
int n; /* iterates over all tree elements */
754753
int prevlen = -1; /* last emitted length */
755754
int curlen; /* length of current code */
756755
int nextlen = tree[0].Len; /* length of next code */
757756
int count = 0; /* repeat count of the current code */
@@ -794,13 +793,11 @@
794793
795794
/* ===========================================================================
796795
* Construct the Huffman tree for the bit lengths and return the index in
797796
* bl_order of the last bit length code to send.
798797
*/
799
-local int build_bl_tree(s)
800
- deflate_state *s;
801
-{
798
+local int build_bl_tree(deflate_state *s) {
802799
int max_blindex; /* index of last bit length code of non zero freq */
803800
804801
/* Determine the bit length frequencies for literal and distance trees */
805802
scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
806803
scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
@@ -829,14 +826,12 @@
829826
/* ===========================================================================
830827
* Send the header for a block using dynamic Huffman trees: the counts, the
831828
* lengths of the bit length codes, the literal tree and the distance tree.
832829
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
833830
*/
834
-local void send_all_trees(s, lcodes, dcodes, blcodes)
835
- deflate_state *s;
836
- int lcodes, dcodes, blcodes; /* number of codes for each tree */
837
-{
831
+local void send_all_trees(deflate_state *s, int lcodes, int dcodes,
832
+ int blcodes) {
838833
int rank; /* index in bl_order */
839834
840835
Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
841836
Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
842837
"too many codes");
@@ -858,16 +853,12 @@
858853
}
859854
860855
/* ===========================================================================
861856
* Send a stored block
862857
*/
863
-void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
864
- deflate_state *s;
865
- charf *buf; /* input block */
866
- ulg stored_len; /* length of input block */
867
- int last; /* one if this is the last block for a file */
868
-{
858
+void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
859
+ ulg stored_len, int last) {
869860
send_bits(s, (STORED_BLOCK<<1) + last, 3); /* send block type */
870861
bi_windup(s); /* align on byte boundary */
871862
put_short(s, (ush)stored_len);
872863
put_short(s, (ush)~stored_len);
873864
if (stored_len)
@@ -882,41 +873,120 @@
882873
}
883874
884875
/* ===========================================================================
885876
* Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
886877
*/
887
-void ZLIB_INTERNAL _tr_flush_bits(s)
888
- deflate_state *s;
889
-{
878
+void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) {
890879
bi_flush(s);
891880
}
892881
893882
/* ===========================================================================
894883
* Send one empty static block to give enough lookahead for inflate.
895884
* This takes 10 bits, of which 7 may remain in the bit buffer.
896885
*/
897
-void ZLIB_INTERNAL _tr_align(s)
898
- deflate_state *s;
899
-{
886
+void ZLIB_INTERNAL _tr_align(deflate_state *s) {
900887
send_bits(s, STATIC_TREES<<1, 3);
901888
send_code(s, END_BLOCK, static_ltree);
902889
#ifdef ZLIB_DEBUG
903890
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
904891
#endif
905892
bi_flush(s);
906893
}
894
+
895
+/* ===========================================================================
896
+ * Send the block data compressed using the given Huffman trees
897
+ */
898
+local void compress_block(deflate_state *s, const ct_data *ltree,
899
+ const ct_data *dtree) {
900
+ unsigned dist; /* distance of matched string */
901
+ int lc; /* match length or unmatched char (if dist == 0) */
902
+ unsigned sx = 0; /* running index in sym_buf */
903
+ unsigned code; /* the code to send */
904
+ int extra; /* number of extra bits to send */
905
+
906
+ if (s->sym_next != 0) do {
907
+ dist = s->sym_buf[sx++] & 0xff;
908
+ dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
909
+ lc = s->sym_buf[sx++];
910
+ if (dist == 0) {
911
+ send_code(s, lc, ltree); /* send a literal byte */
912
+ Tracecv(isgraph(lc), (stderr," '%c' ", lc));
913
+ } else {
914
+ /* Here, lc is the match length - MIN_MATCH */
915
+ code = _length_code[lc];
916
+ send_code(s, code + LITERALS + 1, ltree); /* send length code */
917
+ extra = extra_lbits[code];
918
+ if (extra != 0) {
919
+ lc -= base_length[code];
920
+ send_bits(s, lc, extra); /* send the extra length bits */
921
+ }
922
+ dist--; /* dist is now the match distance - 1 */
923
+ code = d_code(dist);
924
+ Assert (code < D_CODES, "bad d_code");
925
+
926
+ send_code(s, code, dtree); /* send the distance code */
927
+ extra = extra_dbits[code];
928
+ if (extra != 0) {
929
+ dist -= (unsigned)base_dist[code];
930
+ send_bits(s, dist, extra); /* send the extra distance bits */
931
+ }
932
+ } /* literal or match pair ? */
933
+
934
+ /* Check that the overlay between pending_buf and sym_buf is ok: */
935
+ Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
936
+
937
+ } while (sx < s->sym_next);
938
+
939
+ send_code(s, END_BLOCK, ltree);
940
+}
941
+
942
+/* ===========================================================================
943
+ * Check if the data type is TEXT or BINARY, using the following algorithm:
944
+ * - TEXT if the two conditions below are satisfied:
945
+ * a) There are no non-portable control characters belonging to the
946
+ * "block list" (0..6, 14..25, 28..31).
947
+ * b) There is at least one printable character belonging to the
948
+ * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
949
+ * - BINARY otherwise.
950
+ * - The following partially-portable control characters form a
951
+ * "gray list" that is ignored in this detection algorithm:
952
+ * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
953
+ * IN assertion: the fields Freq of dyn_ltree are set.
954
+ */
955
+local int detect_data_type(deflate_state *s) {
956
+ /* block_mask is the bit mask of block-listed bytes
957
+ * set bits 0..6, 14..25, and 28..31
958
+ * 0xf3ffc07f = binary 11110011111111111100000001111111
959
+ */
960
+ unsigned long block_mask = 0xf3ffc07fUL;
961
+ int n;
962
+
963
+ /* Check for non-textual ("block-listed") bytes. */
964
+ for (n = 0; n <= 31; n++, block_mask >>= 1)
965
+ if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0))
966
+ return Z_BINARY;
967
+
968
+ /* Check for textual ("allow-listed") bytes. */
969
+ if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
970
+ || s->dyn_ltree[13].Freq != 0)
971
+ return Z_TEXT;
972
+ for (n = 32; n < LITERALS; n++)
973
+ if (s->dyn_ltree[n].Freq != 0)
974
+ return Z_TEXT;
975
+
976
+ /* There are no "block-listed" or "allow-listed" bytes:
977
+ * this stream either is empty or has tolerated ("gray-listed") bytes only.
978
+ */
979
+ return Z_BINARY;
980
+}
907981
908982
/* ===========================================================================
909983
* Determine the best encoding for the current block: dynamic trees, static
910984
* trees or store, and write out the encoded block.
911985
*/
912
-void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
913
- deflate_state *s;
914
- charf *buf; /* input block, or NULL if too old */
915
- ulg stored_len; /* length of input block */
916
- int last; /* one if this is the last block for a file */
917
-{
986
+void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
987
+ ulg stored_len, int last) {
918988
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
919989
int max_blindex = 0; /* index of last bit length code of non zero freq */
920990
921991
/* Build the Huffman trees unless a stored block is forced */
922992
if (s->level > 0) {
@@ -1009,15 +1079,11 @@
10091079
10101080
/* ===========================================================================
10111081
* Save the match info and tally the frequency counts. Return true if
10121082
* the current block must be flushed.
10131083
*/
1014
-int ZLIB_INTERNAL _tr_tally(s, dist, lc)
1015
- deflate_state *s;
1016
- unsigned dist; /* distance of matched string */
1017
- unsigned lc; /* match length - MIN_MATCH or unmatched char (dist==0) */
1018
-{
1084
+int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) {
10191085
s->sym_buf[s->sym_next++] = (uch)dist;
10201086
s->sym_buf[s->sym_next++] = (uch)(dist >> 8);
10211087
s->sym_buf[s->sym_next++] = (uch)lc;
10221088
if (dist == 0) {
10231089
/* lc is the unmatched char */
@@ -1033,149 +1099,5 @@
10331099
s->dyn_ltree[_length_code[lc] + LITERALS + 1].Freq++;
10341100
s->dyn_dtree[d_code(dist)].Freq++;
10351101
}
10361102
return (s->sym_next == s->sym_end);
10371103
}
1038
-
1039
-/* ===========================================================================
1040
- * Send the block data compressed using the given Huffman trees
1041
- */
1042
-local void compress_block(s, ltree, dtree)
1043
- deflate_state *s;
1044
- const ct_data *ltree; /* literal tree */
1045
- const ct_data *dtree; /* distance tree */
1046
-{
1047
- unsigned dist; /* distance of matched string */
1048
- int lc; /* match length or unmatched char (if dist == 0) */
1049
- unsigned sx = 0; /* running index in sym_buf */
1050
- unsigned code; /* the code to send */
1051
- int extra; /* number of extra bits to send */
1052
-
1053
- if (s->sym_next != 0) do {
1054
- dist = s->sym_buf[sx++] & 0xff;
1055
- dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
1056
- lc = s->sym_buf[sx++];
1057
- if (dist == 0) {
1058
- send_code(s, lc, ltree); /* send a literal byte */
1059
- Tracecv(isgraph(lc), (stderr," '%c' ", lc));
1060
- } else {
1061
- /* Here, lc is the match length - MIN_MATCH */
1062
- code = _length_code[lc];
1063
- send_code(s, code + LITERALS + 1, ltree); /* send length code */
1064
- extra = extra_lbits[code];
1065
- if (extra != 0) {
1066
- lc -= base_length[code];
1067
- send_bits(s, lc, extra); /* send the extra length bits */
1068
- }
1069
- dist--; /* dist is now the match distance - 1 */
1070
- code = d_code(dist);
1071
- Assert (code < D_CODES, "bad d_code");
1072
-
1073
- send_code(s, code, dtree); /* send the distance code */
1074
- extra = extra_dbits[code];
1075
- if (extra != 0) {
1076
- dist -= (unsigned)base_dist[code];
1077
- send_bits(s, dist, extra); /* send the extra distance bits */
1078
- }
1079
- } /* literal or match pair ? */
1080
-
1081
- /* Check that the overlay between pending_buf and sym_buf is ok: */
1082
- Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
1083
-
1084
- } while (sx < s->sym_next);
1085
-
1086
- send_code(s, END_BLOCK, ltree);
1087
-}
1088
-
1089
-/* ===========================================================================
1090
- * Check if the data type is TEXT or BINARY, using the following algorithm:
1091
- * - TEXT if the two conditions below are satisfied:
1092
- * a) There are no non-portable control characters belonging to the
1093
- * "block list" (0..6, 14..25, 28..31).
1094
- * b) There is at least one printable character belonging to the
1095
- * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
1096
- * - BINARY otherwise.
1097
- * - The following partially-portable control characters form a
1098
- * "gray list" that is ignored in this detection algorithm:
1099
- * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
1100
- * IN assertion: the fields Freq of dyn_ltree are set.
1101
- */
1102
-local int detect_data_type(s)
1103
- deflate_state *s;
1104
-{
1105
- /* block_mask is the bit mask of block-listed bytes
1106
- * set bits 0..6, 14..25, and 28..31
1107
- * 0xf3ffc07f = binary 11110011111111111100000001111111
1108
- */
1109
- unsigned long block_mask = 0xf3ffc07fUL;
1110
- int n;
1111
-
1112
- /* Check for non-textual ("block-listed") bytes. */
1113
- for (n = 0; n <= 31; n++, block_mask >>= 1)
1114
- if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0))
1115
- return Z_BINARY;
1116
-
1117
- /* Check for textual ("allow-listed") bytes. */
1118
- if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
1119
- || s->dyn_ltree[13].Freq != 0)
1120
- return Z_TEXT;
1121
- for (n = 32; n < LITERALS; n++)
1122
- if (s->dyn_ltree[n].Freq != 0)
1123
- return Z_TEXT;
1124
-
1125
- /* There are no "block-listed" or "allow-listed" bytes:
1126
- * this stream either is empty or has tolerated ("gray-listed") bytes only.
1127
- */
1128
- return Z_BINARY;
1129
-}
1130
-
1131
-/* ===========================================================================
1132
- * Reverse the first len bits of a code, using straightforward code (a faster
1133
- * method would use a table)
1134
- * IN assertion: 1 <= len <= 15
1135
- */
1136
-local unsigned bi_reverse(code, len)
1137
- unsigned code; /* the value to invert */
1138
- int len; /* its bit length */
1139
-{
1140
- register unsigned res = 0;
1141
- do {
1142
- res |= code & 1;
1143
- code >>= 1, res <<= 1;
1144
- } while (--len > 0);
1145
- return res >> 1;
1146
-}
1147
-
1148
-/* ===========================================================================
1149
- * Flush the bit buffer, keeping at most 7 bits in it.
1150
- */
1151
-local void bi_flush(s)
1152
- deflate_state *s;
1153
-{
1154
- if (s->bi_valid == 16) {
1155
- put_short(s, s->bi_buf);
1156
- s->bi_buf = 0;
1157
- s->bi_valid = 0;
1158
- } else if (s->bi_valid >= 8) {
1159
- put_byte(s, (Byte)s->bi_buf);
1160
- s->bi_buf >>= 8;
1161
- s->bi_valid -= 8;
1162
- }
1163
-}
1164
-
1165
-/* ===========================================================================
1166
- * Flush the bit buffer and align the output on a byte boundary
1167
- */
1168
-local void bi_windup(s)
1169
- deflate_state *s;
1170
-{
1171
- if (s->bi_valid > 8) {
1172
- put_short(s, s->bi_buf);
1173
- } else if (s->bi_valid > 0) {
1174
- put_byte(s, (Byte)s->bi_buf);
1175
- }
1176
- s->bi_buf = 0;
1177
- s->bi_valid = 0;
1178
-#ifdef ZLIB_DEBUG
1179
- s->bits_sent = (s->bits_sent + 7) & ~7;
1180
-#endif
1181
-}
11821104
--- compat/zlib/trees.c
+++ compat/zlib/trees.c
@@ -120,43 +120,120 @@
120 int extra_base; /* base index for extra_bits */
121 int elems; /* max number of elements in the tree */
122 int max_length; /* max bit length for the codes */
123 };
124
125 local const static_tree_desc static_l_desc =
 
 
 
 
 
 
126 {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
127
128 local const static_tree_desc static_d_desc =
129 {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
130
131 local const static_tree_desc static_bl_desc =
132 {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
133
134 /* ===========================================================================
135 * Local (static) routines in this file.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136 */
137
138 local void tr_static_init OF((void));
139 local void init_block OF((deflate_state *s));
140 local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
141 local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
142 local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
143 local void build_tree OF((deflate_state *s, tree_desc *desc));
144 local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
145 local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
146 local int build_bl_tree OF((deflate_state *s));
147 local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
148 int blcodes));
149 local void compress_block OF((deflate_state *s, const ct_data *ltree,
150 const ct_data *dtree));
151 local int detect_data_type OF((deflate_state *s));
152 local unsigned bi_reverse OF((unsigned code, int len));
153 local void bi_windup OF((deflate_state *s));
154 local void bi_flush OF((deflate_state *s));
 
 
 
 
 
 
 
 
 
 
 
 
155
156 #ifdef GEN_TREES_H
157 local void gen_trees_header OF((void));
158 #endif
159
160 #ifndef ZLIB_DEBUG
161 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
162 /* Send a code of the given tree. c and tree must not have side effects */
@@ -165,31 +242,16 @@
165 # define send_code(s, c, tree) \
166 { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
167 send_bits(s, tree[c].Code, tree[c].Len); }
168 #endif
169
170 /* ===========================================================================
171 * Output a short LSB first on the stream.
172 * IN assertion: there is enough room in pendingBuf.
173 */
174 #define put_short(s, w) { \
175 put_byte(s, (uch)((w) & 0xff)); \
176 put_byte(s, (uch)((ush)(w) >> 8)); \
177 }
178
179 /* ===========================================================================
180 * Send a value on a given number of bits.
181 * IN assertion: length <= 16 and value fits in length bits.
182 */
183 #ifdef ZLIB_DEBUG
184 local void send_bits OF((deflate_state *s, int value, int length));
185
186 local void send_bits(s, value, length)
187 deflate_state *s;
188 int value; /* value to send */
189 int length; /* number of bits */
190 {
191 Tracevv((stderr," l %2d v %4x ", length, value));
192 Assert(length > 0 && length <= 15, "invalid length");
193 s->bits_sent += (ulg)length;
194
195 /* If not enough room in bi_buf, use (valid) bits from bi_buf and
@@ -227,12 +289,11 @@
227 /* the arguments must not have side effects */
228
229 /* ===========================================================================
230 * Initialize the various 'constant' tables.
231 */
232 local void tr_static_init()
233 {
234 #if defined(GEN_TREES_H) || !defined(STDC)
235 static int static_init_done = 0;
236 int n; /* iterates over tree elements */
237 int bits; /* bit counter */
238 int length; /* length value */
@@ -321,12 +382,11 @@
321
322 # define SEPARATOR(i, last, width) \
323 ((i) == (last)? "\n};\n\n" : \
324 ((i) % (width) == (width) - 1 ? ",\n" : ", "))
325
326 void gen_trees_header()
327 {
328 FILE *header = fopen("trees.h", "w");
329 int i;
330
331 Assert (header != NULL, "Can't open trees.h");
332 fprintf(header,
@@ -370,17 +430,31 @@
370 }
371
372 fclose(header);
373 }
374 #endif /* GEN_TREES_H */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
376 /* ===========================================================================
377 * Initialize the tree data structures for a new zlib stream.
378 */
379 void ZLIB_INTERNAL _tr_init(s)
380 deflate_state *s;
381 {
382 tr_static_init();
383
384 s->l_desc.dyn_tree = s->dyn_ltree;
385 s->l_desc.stat_desc = &static_l_desc;
386
@@ -399,28 +473,10 @@
399
400 /* Initialize the first block of the first file: */
401 init_block(s);
402 }
403
404 /* ===========================================================================
405 * Initialize a new block.
406 */
407 local void init_block(s)
408 deflate_state *s;
409 {
410 int n; /* iterates over tree elements */
411
412 /* Initialize the trees. */
413 for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
414 for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
415 for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
416
417 s->dyn_ltree[END_BLOCK].Freq = 1;
418 s->opt_len = s->static_len = 0L;
419 s->sym_next = s->matches = 0;
420 }
421
422 #define SMALLEST 1
423 /* Index within the heap array of least frequent node in the Huffman tree */
424
425
426 /* ===========================================================================
@@ -446,15 +502,11 @@
446 * Restore the heap property by moving down the tree starting at node k,
447 * exchanging a node with the smallest of its two sons if necessary, stopping
448 * when the heap property is re-established (each father smaller than its
449 * two sons).
450 */
451 local void pqdownheap(s, tree, k)
452 deflate_state *s;
453 ct_data *tree; /* the tree to restore */
454 int k; /* node to move down */
455 {
456 int v = s->heap[k];
457 int j = k << 1; /* left son of k */
458 while (j <= s->heap_len) {
459 /* Set j to the smallest of the two sons: */
460 if (j < s->heap_len &&
@@ -481,14 +533,11 @@
481 * OUT assertions: the field len is set to the optimal bit length, the
482 * array bl_count contains the frequencies for each bit length.
483 * The length opt_len is updated; static_len is also updated if stree is
484 * not null.
485 */
486 local void gen_bitlen(s, desc)
487 deflate_state *s;
488 tree_desc *desc; /* the tree descriptor */
489 {
490 ct_data *tree = desc->dyn_tree;
491 int max_code = desc->max_code;
492 const ct_data *stree = desc->stat_desc->static_tree;
493 const intf *extra = desc->stat_desc->extra_bits;
494 int base = desc->stat_desc->extra_base;
@@ -559,65 +608,23 @@
559 n--;
560 }
561 }
562 }
563
564 /* ===========================================================================
565 * Generate the codes for a given tree and bit counts (which need not be
566 * optimal).
567 * IN assertion: the array bl_count contains the bit length statistics for
568 * the given tree and the field len is set for all tree elements.
569 * OUT assertion: the field code is set for all tree elements of non
570 * zero code length.
571 */
572 local void gen_codes(tree, max_code, bl_count)
573 ct_data *tree; /* the tree to decorate */
574 int max_code; /* largest code with non zero frequency */
575 ushf *bl_count; /* number of codes at each bit length */
576 {
577 ush next_code[MAX_BITS+1]; /* next code value for each bit length */
578 unsigned code = 0; /* running code value */
579 int bits; /* bit index */
580 int n; /* code index */
581
582 /* The distribution counts are first used to generate the code values
583 * without bit reversal.
584 */
585 for (bits = 1; bits <= MAX_BITS; bits++) {
586 code = (code + bl_count[bits - 1]) << 1;
587 next_code[bits] = (ush)code;
588 }
589 /* Check that the bit counts in bl_count are consistent. The last code
590 * must be all ones.
591 */
592 Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1,
593 "inconsistent bit counts");
594 Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
595
596 for (n = 0; n <= max_code; n++) {
597 int len = tree[n].Len;
598 if (len == 0) continue;
599 /* Now reverse the bits */
600 tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
601
602 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
603 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1));
604 }
605 }
606
607 /* ===========================================================================
608 * Construct one Huffman tree and assigns the code bit strings and lengths.
609 * Update the total bit length for the current block.
610 * IN assertion: the field freq is set for all tree elements.
611 * OUT assertions: the fields len and code are set to the optimal bit length
612 * and corresponding code. The length opt_len is updated; static_len is
613 * also updated if stree is not null. The field max_code is set.
614 */
615 local void build_tree(s, desc)
616 deflate_state *s;
617 tree_desc *desc; /* the tree descriptor */
618 {
619 ct_data *tree = desc->dyn_tree;
620 const ct_data *stree = desc->stat_desc->static_tree;
621 int elems = desc->stat_desc->elems;
622 int n, m; /* iterate over heap elements */
623 int max_code = -1; /* largest code with non zero frequency */
@@ -698,15 +705,11 @@
698
699 /* ===========================================================================
700 * Scan a literal or distance tree to determine the frequencies of the codes
701 * in the bit length tree.
702 */
703 local void scan_tree(s, tree, max_code)
704 deflate_state *s;
705 ct_data *tree; /* the tree to be scanned */
706 int max_code; /* and its largest code of non zero frequency */
707 {
708 int n; /* iterates over all tree elements */
709 int prevlen = -1; /* last emitted length */
710 int curlen; /* length of current code */
711 int nextlen = tree[0].Len; /* length of next code */
712 int count = 0; /* repeat count of the current code */
@@ -743,15 +746,11 @@
743
744 /* ===========================================================================
745 * Send a literal or distance tree in compressed form, using the codes in
746 * bl_tree.
747 */
748 local void send_tree(s, tree, max_code)
749 deflate_state *s;
750 ct_data *tree; /* the tree to be scanned */
751 int max_code; /* and its largest code of non zero frequency */
752 {
753 int n; /* iterates over all tree elements */
754 int prevlen = -1; /* last emitted length */
755 int curlen; /* length of current code */
756 int nextlen = tree[0].Len; /* length of next code */
757 int count = 0; /* repeat count of the current code */
@@ -794,13 +793,11 @@
794
795 /* ===========================================================================
796 * Construct the Huffman tree for the bit lengths and return the index in
797 * bl_order of the last bit length code to send.
798 */
799 local int build_bl_tree(s)
800 deflate_state *s;
801 {
802 int max_blindex; /* index of last bit length code of non zero freq */
803
804 /* Determine the bit length frequencies for literal and distance trees */
805 scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
806 scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
@@ -829,14 +826,12 @@
829 /* ===========================================================================
830 * Send the header for a block using dynamic Huffman trees: the counts, the
831 * lengths of the bit length codes, the literal tree and the distance tree.
832 * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
833 */
834 local void send_all_trees(s, lcodes, dcodes, blcodes)
835 deflate_state *s;
836 int lcodes, dcodes, blcodes; /* number of codes for each tree */
837 {
838 int rank; /* index in bl_order */
839
840 Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
841 Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
842 "too many codes");
@@ -858,16 +853,12 @@
858 }
859
860 /* ===========================================================================
861 * Send a stored block
862 */
863 void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
864 deflate_state *s;
865 charf *buf; /* input block */
866 ulg stored_len; /* length of input block */
867 int last; /* one if this is the last block for a file */
868 {
869 send_bits(s, (STORED_BLOCK<<1) + last, 3); /* send block type */
870 bi_windup(s); /* align on byte boundary */
871 put_short(s, (ush)stored_len);
872 put_short(s, (ush)~stored_len);
873 if (stored_len)
@@ -882,41 +873,120 @@
882 }
883
884 /* ===========================================================================
885 * Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
886 */
887 void ZLIB_INTERNAL _tr_flush_bits(s)
888 deflate_state *s;
889 {
890 bi_flush(s);
891 }
892
893 /* ===========================================================================
894 * Send one empty static block to give enough lookahead for inflate.
895 * This takes 10 bits, of which 7 may remain in the bit buffer.
896 */
897 void ZLIB_INTERNAL _tr_align(s)
898 deflate_state *s;
899 {
900 send_bits(s, STATIC_TREES<<1, 3);
901 send_code(s, END_BLOCK, static_ltree);
902 #ifdef ZLIB_DEBUG
903 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
904 #endif
905 bi_flush(s);
906 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
907
908 /* ===========================================================================
909 * Determine the best encoding for the current block: dynamic trees, static
910 * trees or store, and write out the encoded block.
911 */
912 void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
913 deflate_state *s;
914 charf *buf; /* input block, or NULL if too old */
915 ulg stored_len; /* length of input block */
916 int last; /* one if this is the last block for a file */
917 {
918 ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
919 int max_blindex = 0; /* index of last bit length code of non zero freq */
920
921 /* Build the Huffman trees unless a stored block is forced */
922 if (s->level > 0) {
@@ -1009,15 +1079,11 @@
1009
1010 /* ===========================================================================
1011 * Save the match info and tally the frequency counts. Return true if
1012 * the current block must be flushed.
1013 */
1014 int ZLIB_INTERNAL _tr_tally(s, dist, lc)
1015 deflate_state *s;
1016 unsigned dist; /* distance of matched string */
1017 unsigned lc; /* match length - MIN_MATCH or unmatched char (dist==0) */
1018 {
1019 s->sym_buf[s->sym_next++] = (uch)dist;
1020 s->sym_buf[s->sym_next++] = (uch)(dist >> 8);
1021 s->sym_buf[s->sym_next++] = (uch)lc;
1022 if (dist == 0) {
1023 /* lc is the unmatched char */
@@ -1033,149 +1099,5 @@
1033 s->dyn_ltree[_length_code[lc] + LITERALS + 1].Freq++;
1034 s->dyn_dtree[d_code(dist)].Freq++;
1035 }
1036 return (s->sym_next == s->sym_end);
1037 }
1038
1039 /* ===========================================================================
1040 * Send the block data compressed using the given Huffman trees
1041 */
1042 local void compress_block(s, ltree, dtree)
1043 deflate_state *s;
1044 const ct_data *ltree; /* literal tree */
1045 const ct_data *dtree; /* distance tree */
1046 {
1047 unsigned dist; /* distance of matched string */
1048 int lc; /* match length or unmatched char (if dist == 0) */
1049 unsigned sx = 0; /* running index in sym_buf */
1050 unsigned code; /* the code to send */
1051 int extra; /* number of extra bits to send */
1052
1053 if (s->sym_next != 0) do {
1054 dist = s->sym_buf[sx++] & 0xff;
1055 dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
1056 lc = s->sym_buf[sx++];
1057 if (dist == 0) {
1058 send_code(s, lc, ltree); /* send a literal byte */
1059 Tracecv(isgraph(lc), (stderr," '%c' ", lc));
1060 } else {
1061 /* Here, lc is the match length - MIN_MATCH */
1062 code = _length_code[lc];
1063 send_code(s, code + LITERALS + 1, ltree); /* send length code */
1064 extra = extra_lbits[code];
1065 if (extra != 0) {
1066 lc -= base_length[code];
1067 send_bits(s, lc, extra); /* send the extra length bits */
1068 }
1069 dist--; /* dist is now the match distance - 1 */
1070 code = d_code(dist);
1071 Assert (code < D_CODES, "bad d_code");
1072
1073 send_code(s, code, dtree); /* send the distance code */
1074 extra = extra_dbits[code];
1075 if (extra != 0) {
1076 dist -= (unsigned)base_dist[code];
1077 send_bits(s, dist, extra); /* send the extra distance bits */
1078 }
1079 } /* literal or match pair ? */
1080
1081 /* Check that the overlay between pending_buf and sym_buf is ok: */
1082 Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
1083
1084 } while (sx < s->sym_next);
1085
1086 send_code(s, END_BLOCK, ltree);
1087 }
1088
1089 /* ===========================================================================
1090 * Check if the data type is TEXT or BINARY, using the following algorithm:
1091 * - TEXT if the two conditions below are satisfied:
1092 * a) There are no non-portable control characters belonging to the
1093 * "block list" (0..6, 14..25, 28..31).
1094 * b) There is at least one printable character belonging to the
1095 * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
1096 * - BINARY otherwise.
1097 * - The following partially-portable control characters form a
1098 * "gray list" that is ignored in this detection algorithm:
1099 * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
1100 * IN assertion: the fields Freq of dyn_ltree are set.
1101 */
1102 local int detect_data_type(s)
1103 deflate_state *s;
1104 {
1105 /* block_mask is the bit mask of block-listed bytes
1106 * set bits 0..6, 14..25, and 28..31
1107 * 0xf3ffc07f = binary 11110011111111111100000001111111
1108 */
1109 unsigned long block_mask = 0xf3ffc07fUL;
1110 int n;
1111
1112 /* Check for non-textual ("block-listed") bytes. */
1113 for (n = 0; n <= 31; n++, block_mask >>= 1)
1114 if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0))
1115 return Z_BINARY;
1116
1117 /* Check for textual ("allow-listed") bytes. */
1118 if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
1119 || s->dyn_ltree[13].Freq != 0)
1120 return Z_TEXT;
1121 for (n = 32; n < LITERALS; n++)
1122 if (s->dyn_ltree[n].Freq != 0)
1123 return Z_TEXT;
1124
1125 /* There are no "block-listed" or "allow-listed" bytes:
1126 * this stream either is empty or has tolerated ("gray-listed") bytes only.
1127 */
1128 return Z_BINARY;
1129 }
1130
1131 /* ===========================================================================
1132 * Reverse the first len bits of a code, using straightforward code (a faster
1133 * method would use a table)
1134 * IN assertion: 1 <= len <= 15
1135 */
1136 local unsigned bi_reverse(code, len)
1137 unsigned code; /* the value to invert */
1138 int len; /* its bit length */
1139 {
1140 register unsigned res = 0;
1141 do {
1142 res |= code & 1;
1143 code >>= 1, res <<= 1;
1144 } while (--len > 0);
1145 return res >> 1;
1146 }
1147
1148 /* ===========================================================================
1149 * Flush the bit buffer, keeping at most 7 bits in it.
1150 */
1151 local void bi_flush(s)
1152 deflate_state *s;
1153 {
1154 if (s->bi_valid == 16) {
1155 put_short(s, s->bi_buf);
1156 s->bi_buf = 0;
1157 s->bi_valid = 0;
1158 } else if (s->bi_valid >= 8) {
1159 put_byte(s, (Byte)s->bi_buf);
1160 s->bi_buf >>= 8;
1161 s->bi_valid -= 8;
1162 }
1163 }
1164
1165 /* ===========================================================================
1166 * Flush the bit buffer and align the output on a byte boundary
1167 */
1168 local void bi_windup(s)
1169 deflate_state *s;
1170 {
1171 if (s->bi_valid > 8) {
1172 put_short(s, s->bi_buf);
1173 } else if (s->bi_valid > 0) {
1174 put_byte(s, (Byte)s->bi_buf);
1175 }
1176 s->bi_buf = 0;
1177 s->bi_valid = 0;
1178 #ifdef ZLIB_DEBUG
1179 s->bits_sent = (s->bits_sent + 7) & ~7;
1180 #endif
1181 }
1182
--- compat/zlib/trees.c
+++ compat/zlib/trees.c
@@ -120,43 +120,120 @@
120 int extra_base; /* base index for extra_bits */
121 int elems; /* max number of elements in the tree */
122 int max_length; /* max bit length for the codes */
123 };
124
125 #ifdef NO_INIT_GLOBAL_POINTERS
126 # define TCONST
127 #else
128 # define TCONST const
129 #endif
130
131 local TCONST static_tree_desc static_l_desc =
132 {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
133
134 local TCONST static_tree_desc static_d_desc =
135 {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
136
137 local TCONST static_tree_desc static_bl_desc =
138 {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
139
140 /* ===========================================================================
141 * Output a short LSB first on the stream.
142 * IN assertion: there is enough room in pendingBuf.
143 */
144 #define put_short(s, w) { \
145 put_byte(s, (uch)((w) & 0xff)); \
146 put_byte(s, (uch)((ush)(w) >> 8)); \
147 }
148
149 /* ===========================================================================
150 * Reverse the first len bits of a code, using straightforward code (a faster
151 * method would use a table)
152 * IN assertion: 1 <= len <= 15
153 */
154 local unsigned bi_reverse(unsigned code, int len) {
155 register unsigned res = 0;
156 do {
157 res |= code & 1;
158 code >>= 1, res <<= 1;
159 } while (--len > 0);
160 return res >> 1;
161 }
162
163 /* ===========================================================================
164 * Flush the bit buffer, keeping at most 7 bits in it.
165 */
166 local void bi_flush(deflate_state *s) {
167 if (s->bi_valid == 16) {
168 put_short(s, s->bi_buf);
169 s->bi_buf = 0;
170 s->bi_valid = 0;
171 } else if (s->bi_valid >= 8) {
172 put_byte(s, (Byte)s->bi_buf);
173 s->bi_buf >>= 8;
174 s->bi_valid -= 8;
175 }
176 }
177
178 /* ===========================================================================
179 * Flush the bit buffer and align the output on a byte boundary
180 */
181 local void bi_windup(deflate_state *s) {
182 if (s->bi_valid > 8) {
183 put_short(s, s->bi_buf);
184 } else if (s->bi_valid > 0) {
185 put_byte(s, (Byte)s->bi_buf);
186 }
187 s->bi_buf = 0;
188 s->bi_valid = 0;
189 #ifdef ZLIB_DEBUG
190 s->bits_sent = (s->bits_sent + 7) & ~7;
191 #endif
192 }
193
194 /* ===========================================================================
195 * Generate the codes for a given tree and bit counts (which need not be
196 * optimal).
197 * IN assertion: the array bl_count contains the bit length statistics for
198 * the given tree and the field len is set for all tree elements.
199 * OUT assertion: the field code is set for all tree elements of non
200 * zero code length.
201 */
202 local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) {
203 ush next_code[MAX_BITS+1]; /* next code value for each bit length */
204 unsigned code = 0; /* running code value */
205 int bits; /* bit index */
206 int n; /* code index */
207
208 /* The distribution counts are first used to generate the code values
209 * without bit reversal.
210 */
211 for (bits = 1; bits <= MAX_BITS; bits++) {
212 code = (code + bl_count[bits - 1]) << 1;
213 next_code[bits] = (ush)code;
214 }
215 /* Check that the bit counts in bl_count are consistent. The last code
216 * must be all ones.
217 */
218 Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1,
219 "inconsistent bit counts");
220 Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
221
222 for (n = 0; n <= max_code; n++) {
223 int len = tree[n].Len;
224 if (len == 0) continue;
225 /* Now reverse the bits */
226 tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
227
228 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
229 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1));
230 }
231 }
232
233 #ifdef GEN_TREES_H
234 local void gen_trees_header(void);
235 #endif
236
237 #ifndef ZLIB_DEBUG
238 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
239 /* Send a code of the given tree. c and tree must not have side effects */
@@ -165,31 +242,16 @@
242 # define send_code(s, c, tree) \
243 { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
244 send_bits(s, tree[c].Code, tree[c].Len); }
245 #endif
246
 
 
 
 
 
 
 
 
 
247 /* ===========================================================================
248 * Send a value on a given number of bits.
249 * IN assertion: length <= 16 and value fits in length bits.
250 */
251 #ifdef ZLIB_DEBUG
252 local void send_bits(deflate_state *s, int value, int length) {
 
 
 
 
 
 
253 Tracevv((stderr," l %2d v %4x ", length, value));
254 Assert(length > 0 && length <= 15, "invalid length");
255 s->bits_sent += (ulg)length;
256
257 /* If not enough room in bi_buf, use (valid) bits from bi_buf and
@@ -227,12 +289,11 @@
289 /* the arguments must not have side effects */
290
291 /* ===========================================================================
292 * Initialize the various 'constant' tables.
293 */
294 local void tr_static_init(void) {
 
295 #if defined(GEN_TREES_H) || !defined(STDC)
296 static int static_init_done = 0;
297 int n; /* iterates over tree elements */
298 int bits; /* bit counter */
299 int length; /* length value */
@@ -321,12 +382,11 @@
382
383 # define SEPARATOR(i, last, width) \
384 ((i) == (last)? "\n};\n\n" : \
385 ((i) % (width) == (width) - 1 ? ",\n" : ", "))
386
387 void gen_trees_header(void) {
 
388 FILE *header = fopen("trees.h", "w");
389 int i;
390
391 Assert (header != NULL, "Can't open trees.h");
392 fprintf(header,
@@ -370,17 +430,31 @@
430 }
431
432 fclose(header);
433 }
434 #endif /* GEN_TREES_H */
435
436 /* ===========================================================================
437 * Initialize a new block.
438 */
439 local void init_block(deflate_state *s) {
440 int n; /* iterates over tree elements */
441
442 /* Initialize the trees. */
443 for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
444 for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
445 for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
446
447 s->dyn_ltree[END_BLOCK].Freq = 1;
448 s->opt_len = s->static_len = 0L;
449 s->sym_next = s->matches = 0;
450 }
451
452 /* ===========================================================================
453 * Initialize the tree data structures for a new zlib stream.
454 */
455 void ZLIB_INTERNAL _tr_init(deflate_state *s) {
 
 
456 tr_static_init();
457
458 s->l_desc.dyn_tree = s->dyn_ltree;
459 s->l_desc.stat_desc = &static_l_desc;
460
@@ -399,28 +473,10 @@
473
474 /* Initialize the first block of the first file: */
475 init_block(s);
476 }
477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478 #define SMALLEST 1
479 /* Index within the heap array of least frequent node in the Huffman tree */
480
481
482 /* ===========================================================================
@@ -446,15 +502,11 @@
502 * Restore the heap property by moving down the tree starting at node k,
503 * exchanging a node with the smallest of its two sons if necessary, stopping
504 * when the heap property is re-established (each father smaller than its
505 * two sons).
506 */
507 local void pqdownheap(deflate_state *s, ct_data *tree, int k) {
 
 
 
 
508 int v = s->heap[k];
509 int j = k << 1; /* left son of k */
510 while (j <= s->heap_len) {
511 /* Set j to the smallest of the two sons: */
512 if (j < s->heap_len &&
@@ -481,14 +533,11 @@
533 * OUT assertions: the field len is set to the optimal bit length, the
534 * array bl_count contains the frequencies for each bit length.
535 * The length opt_len is updated; static_len is also updated if stree is
536 * not null.
537 */
538 local void gen_bitlen(deflate_state *s, tree_desc *desc) {
 
 
 
539 ct_data *tree = desc->dyn_tree;
540 int max_code = desc->max_code;
541 const ct_data *stree = desc->stat_desc->static_tree;
542 const intf *extra = desc->stat_desc->extra_bits;
543 int base = desc->stat_desc->extra_base;
@@ -559,65 +608,23 @@
608 n--;
609 }
610 }
611 }
612
613 #ifdef DUMP_BL_TREE
614 # include <stdio.h>
615 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
617 /* ===========================================================================
618 * Construct one Huffman tree and assigns the code bit strings and lengths.
619 * Update the total bit length for the current block.
620 * IN assertion: the field freq is set for all tree elements.
621 * OUT assertions: the fields len and code are set to the optimal bit length
622 * and corresponding code. The length opt_len is updated; static_len is
623 * also updated if stree is not null. The field max_code is set.
624 */
625 local void build_tree(deflate_state *s, tree_desc *desc) {
 
 
 
626 ct_data *tree = desc->dyn_tree;
627 const ct_data *stree = desc->stat_desc->static_tree;
628 int elems = desc->stat_desc->elems;
629 int n, m; /* iterate over heap elements */
630 int max_code = -1; /* largest code with non zero frequency */
@@ -698,15 +705,11 @@
705
706 /* ===========================================================================
707 * Scan a literal or distance tree to determine the frequencies of the codes
708 * in the bit length tree.
709 */
710 local void scan_tree(deflate_state *s, ct_data *tree, int max_code) {
 
 
 
 
711 int n; /* iterates over all tree elements */
712 int prevlen = -1; /* last emitted length */
713 int curlen; /* length of current code */
714 int nextlen = tree[0].Len; /* length of next code */
715 int count = 0; /* repeat count of the current code */
@@ -743,15 +746,11 @@
746
747 /* ===========================================================================
748 * Send a literal or distance tree in compressed form, using the codes in
749 * bl_tree.
750 */
751 local void send_tree(deflate_state *s, ct_data *tree, int max_code) {
 
 
 
 
752 int n; /* iterates over all tree elements */
753 int prevlen = -1; /* last emitted length */
754 int curlen; /* length of current code */
755 int nextlen = tree[0].Len; /* length of next code */
756 int count = 0; /* repeat count of the current code */
@@ -794,13 +793,11 @@
793
794 /* ===========================================================================
795 * Construct the Huffman tree for the bit lengths and return the index in
796 * bl_order of the last bit length code to send.
797 */
798 local int build_bl_tree(deflate_state *s) {
 
 
799 int max_blindex; /* index of last bit length code of non zero freq */
800
801 /* Determine the bit length frequencies for literal and distance trees */
802 scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
803 scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
@@ -829,14 +826,12 @@
826 /* ===========================================================================
827 * Send the header for a block using dynamic Huffman trees: the counts, the
828 * lengths of the bit length codes, the literal tree and the distance tree.
829 * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
830 */
831 local void send_all_trees(deflate_state *s, int lcodes, int dcodes,
832 int blcodes) {
 
 
833 int rank; /* index in bl_order */
834
835 Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
836 Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
837 "too many codes");
@@ -858,16 +853,12 @@
853 }
854
855 /* ===========================================================================
856 * Send a stored block
857 */
858 void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
859 ulg stored_len, int last) {
 
 
 
 
860 send_bits(s, (STORED_BLOCK<<1) + last, 3); /* send block type */
861 bi_windup(s); /* align on byte boundary */
862 put_short(s, (ush)stored_len);
863 put_short(s, (ush)~stored_len);
864 if (stored_len)
@@ -882,41 +873,120 @@
873 }
874
875 /* ===========================================================================
876 * Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
877 */
878 void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) {
 
 
879 bi_flush(s);
880 }
881
882 /* ===========================================================================
883 * Send one empty static block to give enough lookahead for inflate.
884 * This takes 10 bits, of which 7 may remain in the bit buffer.
885 */
886 void ZLIB_INTERNAL _tr_align(deflate_state *s) {
 
 
887 send_bits(s, STATIC_TREES<<1, 3);
888 send_code(s, END_BLOCK, static_ltree);
889 #ifdef ZLIB_DEBUG
890 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
891 #endif
892 bi_flush(s);
893 }
894
895 /* ===========================================================================
896 * Send the block data compressed using the given Huffman trees
897 */
898 local void compress_block(deflate_state *s, const ct_data *ltree,
899 const ct_data *dtree) {
900 unsigned dist; /* distance of matched string */
901 int lc; /* match length or unmatched char (if dist == 0) */
902 unsigned sx = 0; /* running index in sym_buf */
903 unsigned code; /* the code to send */
904 int extra; /* number of extra bits to send */
905
906 if (s->sym_next != 0) do {
907 dist = s->sym_buf[sx++] & 0xff;
908 dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
909 lc = s->sym_buf[sx++];
910 if (dist == 0) {
911 send_code(s, lc, ltree); /* send a literal byte */
912 Tracecv(isgraph(lc), (stderr," '%c' ", lc));
913 } else {
914 /* Here, lc is the match length - MIN_MATCH */
915 code = _length_code[lc];
916 send_code(s, code + LITERALS + 1, ltree); /* send length code */
917 extra = extra_lbits[code];
918 if (extra != 0) {
919 lc -= base_length[code];
920 send_bits(s, lc, extra); /* send the extra length bits */
921 }
922 dist--; /* dist is now the match distance - 1 */
923 code = d_code(dist);
924 Assert (code < D_CODES, "bad d_code");
925
926 send_code(s, code, dtree); /* send the distance code */
927 extra = extra_dbits[code];
928 if (extra != 0) {
929 dist -= (unsigned)base_dist[code];
930 send_bits(s, dist, extra); /* send the extra distance bits */
931 }
932 } /* literal or match pair ? */
933
934 /* Check that the overlay between pending_buf and sym_buf is ok: */
935 Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
936
937 } while (sx < s->sym_next);
938
939 send_code(s, END_BLOCK, ltree);
940 }
941
942 /* ===========================================================================
943 * Check if the data type is TEXT or BINARY, using the following algorithm:
944 * - TEXT if the two conditions below are satisfied:
945 * a) There are no non-portable control characters belonging to the
946 * "block list" (0..6, 14..25, 28..31).
947 * b) There is at least one printable character belonging to the
948 * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
949 * - BINARY otherwise.
950 * - The following partially-portable control characters form a
951 * "gray list" that is ignored in this detection algorithm:
952 * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
953 * IN assertion: the fields Freq of dyn_ltree are set.
954 */
955 local int detect_data_type(deflate_state *s) {
956 /* block_mask is the bit mask of block-listed bytes
957 * set bits 0..6, 14..25, and 28..31
958 * 0xf3ffc07f = binary 11110011111111111100000001111111
959 */
960 unsigned long block_mask = 0xf3ffc07fUL;
961 int n;
962
963 /* Check for non-textual ("block-listed") bytes. */
964 for (n = 0; n <= 31; n++, block_mask >>= 1)
965 if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0))
966 return Z_BINARY;
967
968 /* Check for textual ("allow-listed") bytes. */
969 if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
970 || s->dyn_ltree[13].Freq != 0)
971 return Z_TEXT;
972 for (n = 32; n < LITERALS; n++)
973 if (s->dyn_ltree[n].Freq != 0)
974 return Z_TEXT;
975
976 /* There are no "block-listed" or "allow-listed" bytes:
977 * this stream either is empty or has tolerated ("gray-listed") bytes only.
978 */
979 return Z_BINARY;
980 }
981
982 /* ===========================================================================
983 * Determine the best encoding for the current block: dynamic trees, static
984 * trees or store, and write out the encoded block.
985 */
986 void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
987 ulg stored_len, int last) {
 
 
 
 
988 ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
989 int max_blindex = 0; /* index of last bit length code of non zero freq */
990
991 /* Build the Huffman trees unless a stored block is forced */
992 if (s->level > 0) {
@@ -1009,15 +1079,11 @@
1079
1080 /* ===========================================================================
1081 * Save the match info and tally the frequency counts. Return true if
1082 * the current block must be flushed.
1083 */
1084 int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) {
 
 
 
 
1085 s->sym_buf[s->sym_next++] = (uch)dist;
1086 s->sym_buf[s->sym_next++] = (uch)(dist >> 8);
1087 s->sym_buf[s->sym_next++] = (uch)lc;
1088 if (dist == 0) {
1089 /* lc is the unmatched char */
@@ -1033,149 +1099,5 @@
1099 s->dyn_ltree[_length_code[lc] + LITERALS + 1].Freq++;
1100 s->dyn_dtree[d_code(dist)].Freq++;
1101 }
1102 return (s->sym_next == s->sym_end);
1103 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1104
--- compat/zlib/uncompr.c
+++ compat/zlib/uncompr.c
@@ -22,16 +22,12 @@
2222
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
2323
memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
2424
Z_DATA_ERROR if the input data was corrupted, including if the input data is
2525
an incomplete zlib stream.
2626
*/
27
-int ZEXPORT uncompress2(dest, destLen, source, sourceLen)
28
- Bytef *dest;
29
- uLongf *destLen;
30
- const Bytef *source;
31
- uLong *sourceLen;
32
-{
27
+int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
28
+ uLong *sourceLen) {
3329
z_stream stream;
3430
int err;
3531
const uInt max = (uInt)-1;
3632
uLong len, left;
3733
Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
@@ -81,13 +77,9 @@
8177
err == Z_NEED_DICT ? Z_DATA_ERROR :
8278
err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
8379
err;
8480
}
8581
86
-int ZEXPORT uncompress(dest, destLen, source, sourceLen)
87
- Bytef *dest;
88
- uLongf *destLen;
89
- const Bytef *source;
90
- uLong sourceLen;
91
-{
82
+int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
83
+ uLong sourceLen) {
9284
return uncompress2(dest, destLen, source, &sourceLen);
9385
}
9486
--- compat/zlib/uncompr.c
+++ compat/zlib/uncompr.c
@@ -22,16 +22,12 @@
22 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
23 memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
24 Z_DATA_ERROR if the input data was corrupted, including if the input data is
25 an incomplete zlib stream.
26 */
27 int ZEXPORT uncompress2(dest, destLen, source, sourceLen)
28 Bytef *dest;
29 uLongf *destLen;
30 const Bytef *source;
31 uLong *sourceLen;
32 {
33 z_stream stream;
34 int err;
35 const uInt max = (uInt)-1;
36 uLong len, left;
37 Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
@@ -81,13 +77,9 @@
81 err == Z_NEED_DICT ? Z_DATA_ERROR :
82 err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
83 err;
84 }
85
86 int ZEXPORT uncompress(dest, destLen, source, sourceLen)
87 Bytef *dest;
88 uLongf *destLen;
89 const Bytef *source;
90 uLong sourceLen;
91 {
92 return uncompress2(dest, destLen, source, &sourceLen);
93 }
94
--- compat/zlib/uncompr.c
+++ compat/zlib/uncompr.c
@@ -22,16 +22,12 @@
22 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
23 memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
24 Z_DATA_ERROR if the input data was corrupted, including if the input data is
25 an incomplete zlib stream.
26 */
27 int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
28 uLong *sourceLen) {
 
 
 
 
29 z_stream stream;
30 int err;
31 const uInt max = (uInt)-1;
32 uLong len, left;
33 Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
@@ -81,13 +77,9 @@
77 err == Z_NEED_DICT ? Z_DATA_ERROR :
78 err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
79 err;
80 }
81
82 int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
83 uLong sourceLen) {
 
 
 
 
84 return uncompress2(dest, destLen, source, &sourceLen);
85 }
86
--- compat/zlib/win32/README-WIN32.txt
+++ compat/zlib/win32/README-WIN32.txt
@@ -1,8 +1,8 @@
11
ZLIB DATA COMPRESSION LIBRARY
22
3
-zlib 1.2.13 is a general purpose data compression library. All the code is
3
+zlib 1.3.0 is a general purpose data compression library. All the code is
44
thread safe. The data format used by the zlib library is described by RFCs
55
(Request for Comments) 1950 to 1952 in the files
66
http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
77
and rfc1952.txt (gzip format).
88
@@ -20,11 +20,11 @@
2020
before asking for help.
2121
2222
2323
Manifest:
2424
25
-The package zlib-1.2.13-win32-x86.zip will contain the following files:
25
+The package zlib-1.3.0-win32-x86.zip will contain the following files:
2626
2727
README-WIN32.txt This document
2828
ChangeLog Changes since previous zlib packages
2929
DLL_FAQ.txt Frequently asked questions about zlib1.dll
3030
zlib.3.pdf Documentation of this library in Adobe Acrobat format
3131
--- compat/zlib/win32/README-WIN32.txt
+++ compat/zlib/win32/README-WIN32.txt
@@ -1,8 +1,8 @@
1 ZLIB DATA COMPRESSION LIBRARY
2
3 zlib 1.2.13 is a general purpose data compression library. All the code is
4 thread safe. The data format used by the zlib library is described by RFCs
5 (Request for Comments) 1950 to 1952 in the files
6 http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
7 and rfc1952.txt (gzip format).
8
@@ -20,11 +20,11 @@
20 before asking for help.
21
22
23 Manifest:
24
25 The package zlib-1.2.13-win32-x86.zip will contain the following files:
26
27 README-WIN32.txt This document
28 ChangeLog Changes since previous zlib packages
29 DLL_FAQ.txt Frequently asked questions about zlib1.dll
30 zlib.3.pdf Documentation of this library in Adobe Acrobat format
31
--- compat/zlib/win32/README-WIN32.txt
+++ compat/zlib/win32/README-WIN32.txt
@@ -1,8 +1,8 @@
1 ZLIB DATA COMPRESSION LIBRARY
2
3 zlib 1.3.0 is a general purpose data compression library. All the code is
4 thread safe. The data format used by the zlib library is described by RFCs
5 (Request for Comments) 1950 to 1952 in the files
6 http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
7 and rfc1952.txt (gzip format).
8
@@ -20,11 +20,11 @@
20 before asking for help.
21
22
23 Manifest:
24
25 The package zlib-1.3.0-win32-x86.zip will contain the following files:
26
27 README-WIN32.txt This document
28 ChangeLog Changes since previous zlib packages
29 DLL_FAQ.txt Frequently asked questions about zlib1.dll
30 zlib.3.pdf Documentation of this library in Adobe Acrobat format
31
--- compat/zlib/zconf.h
+++ compat/zlib/zconf.h
@@ -239,11 +239,15 @@
239239
#else
240240
# define z_const
241241
#endif
242242
243243
#ifdef Z_SOLO
244
- typedef unsigned long z_size_t;
244
+# ifdef _WIN64
245
+ typedef unsigned long long z_size_t;
246
+# else
247
+ typedef unsigned long z_size_t;
248
+# endif
245249
#else
246250
# define z_longlong long long
247251
# if defined(NO_SIZE_T)
248252
typedef unsigned NO_SIZE_T z_size_t;
249253
# elif defined(STDC)
@@ -518,11 +522,11 @@
518522
#endif
519523
520524
#if !defined(_WIN32) && defined(Z_LARGE64)
521525
# define z_off64_t off64_t
522526
#else
523
-# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
527
+# if defined(_WIN32) && !defined(__GNUC__)
524528
# define z_off64_t __int64
525529
# else
526530
# define z_off64_t z_off_t
527531
# endif
528532
#endif
529533
--- compat/zlib/zconf.h
+++ compat/zlib/zconf.h
@@ -239,11 +239,15 @@
239 #else
240 # define z_const
241 #endif
242
243 #ifdef Z_SOLO
244 typedef unsigned long z_size_t;
 
 
 
 
245 #else
246 # define z_longlong long long
247 # if defined(NO_SIZE_T)
248 typedef unsigned NO_SIZE_T z_size_t;
249 # elif defined(STDC)
@@ -518,11 +522,11 @@
518 #endif
519
520 #if !defined(_WIN32) && defined(Z_LARGE64)
521 # define z_off64_t off64_t
522 #else
523 # if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
524 # define z_off64_t __int64
525 # else
526 # define z_off64_t z_off_t
527 # endif
528 #endif
529
--- compat/zlib/zconf.h
+++ compat/zlib/zconf.h
@@ -239,11 +239,15 @@
239 #else
240 # define z_const
241 #endif
242
243 #ifdef Z_SOLO
244 # ifdef _WIN64
245 typedef unsigned long long z_size_t;
246 # else
247 typedef unsigned long z_size_t;
248 # endif
249 #else
250 # define z_longlong long long
251 # if defined(NO_SIZE_T)
252 typedef unsigned NO_SIZE_T z_size_t;
253 # elif defined(STDC)
@@ -518,11 +522,11 @@
522 #endif
523
524 #if !defined(_WIN32) && defined(Z_LARGE64)
525 # define z_off64_t off64_t
526 #else
527 # if defined(_WIN32) && !defined(__GNUC__)
528 # define z_off64_t __int64
529 # else
530 # define z_off64_t z_off_t
531 # endif
532 #endif
533
--- compat/zlib/zconf.h.cmakein
+++ compat/zlib/zconf.h.cmakein
@@ -241,11 +241,15 @@
241241
#else
242242
# define z_const
243243
#endif
244244
245245
#ifdef Z_SOLO
246
- typedef unsigned long z_size_t;
246
+# ifdef _WIN64
247
+ typedef unsigned long long z_size_t;
248
+# else
249
+ typedef unsigned long z_size_t;
250
+# endif
247251
#else
248252
# define z_longlong long long
249253
# if defined(NO_SIZE_T)
250254
typedef unsigned NO_SIZE_T z_size_t;
251255
# elif defined(STDC)
@@ -520,11 +524,11 @@
520524
#endif
521525
522526
#if !defined(_WIN32) && defined(Z_LARGE64)
523527
# define z_off64_t off64_t
524528
#else
525
-# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
529
+# if defined(_WIN32) && !defined(__GNUC__)
526530
# define z_off64_t __int64
527531
# else
528532
# define z_off64_t z_off_t
529533
# endif
530534
#endif
531535
--- compat/zlib/zconf.h.cmakein
+++ compat/zlib/zconf.h.cmakein
@@ -241,11 +241,15 @@
241 #else
242 # define z_const
243 #endif
244
245 #ifdef Z_SOLO
246 typedef unsigned long z_size_t;
 
 
 
 
247 #else
248 # define z_longlong long long
249 # if defined(NO_SIZE_T)
250 typedef unsigned NO_SIZE_T z_size_t;
251 # elif defined(STDC)
@@ -520,11 +524,11 @@
520 #endif
521
522 #if !defined(_WIN32) && defined(Z_LARGE64)
523 # define z_off64_t off64_t
524 #else
525 # if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
526 # define z_off64_t __int64
527 # else
528 # define z_off64_t z_off_t
529 # endif
530 #endif
531
--- compat/zlib/zconf.h.cmakein
+++ compat/zlib/zconf.h.cmakein
@@ -241,11 +241,15 @@
241 #else
242 # define z_const
243 #endif
244
245 #ifdef Z_SOLO
246 # ifdef _WIN64
247 typedef unsigned long long z_size_t;
248 # else
249 typedef unsigned long z_size_t;
250 # endif
251 #else
252 # define z_longlong long long
253 # if defined(NO_SIZE_T)
254 typedef unsigned NO_SIZE_T z_size_t;
255 # elif defined(STDC)
@@ -520,11 +524,11 @@
524 #endif
525
526 #if !defined(_WIN32) && defined(Z_LARGE64)
527 # define z_off64_t off64_t
528 #else
529 # if defined(_WIN32) && !defined(__GNUC__)
530 # define z_off64_t __int64
531 # else
532 # define z_off64_t z_off_t
533 # endif
534 #endif
535
--- compat/zlib/zconf.h.in
+++ compat/zlib/zconf.h.in
@@ -239,11 +239,15 @@
239239
#else
240240
# define z_const
241241
#endif
242242
243243
#ifdef Z_SOLO
244
- typedef unsigned long z_size_t;
244
+# ifdef _WIN64
245
+ typedef unsigned long long z_size_t;
246
+# else
247
+ typedef unsigned long z_size_t;
248
+# endif
245249
#else
246250
# define z_longlong long long
247251
# if defined(NO_SIZE_T)
248252
typedef unsigned NO_SIZE_T z_size_t;
249253
# elif defined(STDC)
@@ -518,11 +522,11 @@
518522
#endif
519523
520524
#if !defined(_WIN32) && defined(Z_LARGE64)
521525
# define z_off64_t off64_t
522526
#else
523
-# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
527
+# if defined(_WIN32) && !defined(__GNUC__)
524528
# define z_off64_t __int64
525529
# else
526530
# define z_off64_t z_off_t
527531
# endif
528532
#endif
529533
--- compat/zlib/zconf.h.in
+++ compat/zlib/zconf.h.in
@@ -239,11 +239,15 @@
239 #else
240 # define z_const
241 #endif
242
243 #ifdef Z_SOLO
244 typedef unsigned long z_size_t;
 
 
 
 
245 #else
246 # define z_longlong long long
247 # if defined(NO_SIZE_T)
248 typedef unsigned NO_SIZE_T z_size_t;
249 # elif defined(STDC)
@@ -518,11 +522,11 @@
518 #endif
519
520 #if !defined(_WIN32) && defined(Z_LARGE64)
521 # define z_off64_t off64_t
522 #else
523 # if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
524 # define z_off64_t __int64
525 # else
526 # define z_off64_t z_off_t
527 # endif
528 #endif
529
--- compat/zlib/zconf.h.in
+++ compat/zlib/zconf.h.in
@@ -239,11 +239,15 @@
239 #else
240 # define z_const
241 #endif
242
243 #ifdef Z_SOLO
244 # ifdef _WIN64
245 typedef unsigned long long z_size_t;
246 # else
247 typedef unsigned long z_size_t;
248 # endif
249 #else
250 # define z_longlong long long
251 # if defined(NO_SIZE_T)
252 typedef unsigned NO_SIZE_T z_size_t;
253 # elif defined(STDC)
@@ -518,11 +522,11 @@
522 #endif
523
524 #if !defined(_WIN32) && defined(Z_LARGE64)
525 # define z_off64_t off64_t
526 #else
527 # if defined(_WIN32) && !defined(__GNUC__)
528 # define z_off64_t __int64
529 # else
530 # define z_off64_t z_off_t
531 # endif
532 #endif
533
--- compat/zlib/zlib.3
+++ compat/zlib/zlib.3
@@ -1,6 +1,6 @@
1
-.TH ZLIB 3 "13 Oct 2022"
1
+.TH ZLIB 3 "18 Aug 2023"
22
.SH NAME
33
zlib \- compression/decompression library
44
.SH SYNOPSIS
55
[see
66
.I zlib.h
@@ -103,13 +103,13 @@
103103
.LP
104104
before asking for help.
105105
Send questions and/or comments to [email protected],
106106
or (for the Windows DLL version) to Gilles Vollant ([email protected]).
107107
.SH AUTHORS AND LICENSE
108
-Version 1.2.13
108
+Version 1.3
109109
.LP
110
-Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
110
+Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
111111
.LP
112112
This software is provided 'as-is', without any express or implied
113113
warranty. In no event will the authors be held liable for any damages
114114
arising from the use of this software.
115115
.LP
116116
--- compat/zlib/zlib.3
+++ compat/zlib/zlib.3
@@ -1,6 +1,6 @@
1 .TH ZLIB 3 "13 Oct 2022"
2 .SH NAME
3 zlib \- compression/decompression library
4 .SH SYNOPSIS
5 [see
6 .I zlib.h
@@ -103,13 +103,13 @@
103 .LP
104 before asking for help.
105 Send questions and/or comments to [email protected],
106 or (for the Windows DLL version) to Gilles Vollant ([email protected]).
107 .SH AUTHORS AND LICENSE
108 Version 1.2.13
109 .LP
110 Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
111 .LP
112 This software is provided 'as-is', without any express or implied
113 warranty. In no event will the authors be held liable for any damages
114 arising from the use of this software.
115 .LP
116
--- compat/zlib/zlib.3
+++ compat/zlib/zlib.3
@@ -1,6 +1,6 @@
1 .TH ZLIB 3 "18 Aug 2023"
2 .SH NAME
3 zlib \- compression/decompression library
4 .SH SYNOPSIS
5 [see
6 .I zlib.h
@@ -103,13 +103,13 @@
103 .LP
104 before asking for help.
105 Send questions and/or comments to [email protected],
106 or (for the Windows DLL version) to Gilles Vollant ([email protected]).
107 .SH AUTHORS AND LICENSE
108 Version 1.3
109 .LP
110 Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
111 .LP
112 This software is provided 'as-is', without any express or implied
113 warranty. In no event will the authors be held liable for any damages
114 arising from the use of this software.
115 .LP
116
--- compat/zlib/zlib.3.pdf
+++ compat/zlib/zlib.3.pdf
cannot compute difference between binary files
11
--- compat/zlib/zlib.3.pdf
+++ compat/zlib/zlib.3.pdf
0 annot compute difference between binary files
1
--- compat/zlib/zlib.3.pdf
+++ compat/zlib/zlib.3.pdf
0 annot compute difference between binary files
1
+191 -188
--- compat/zlib/zlib.h
+++ compat/zlib/zlib.h
@@ -1,9 +1,9 @@
11
/* zlib.h -- interface of the 'zlib' general purpose compression library
2
- version 1.2.13, October 13th, 2022
2
+ version 1.3, August 18th, 2023
33
4
- Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
4
+ Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
55
66
This software is provided 'as-is', without any express or implied
77
warranty. In no event will the authors be held liable for any damages
88
arising from the use of this software.
99
@@ -35,15 +35,15 @@
3535
3636
#ifdef __cplusplus
3737
extern "C" {
3838
#endif
3939
40
-#define ZLIB_VERSION "1.2.13"
41
-#define ZLIB_VERNUM 0x12d0
40
+#define ZLIB_VERSION "1.3"
41
+#define ZLIB_VERNUM 0x1300
4242
#define ZLIB_VER_MAJOR 1
43
-#define ZLIB_VER_MINOR 2
44
-#define ZLIB_VER_REVISION 13
43
+#define ZLIB_VER_MINOR 3
44
+#define ZLIB_VER_REVISION 0
4545
#define ZLIB_VER_SUBREVISION 0
4646
4747
/*
4848
The 'zlib' compression library provides in-memory compression and
4949
decompression functions, including integrity checks of the uncompressed data.
@@ -76,12 +76,12 @@
7676
The library does not install any signal handler. The decoder checks
7777
the consistency of the compressed data, so the library should never crash
7878
even in the case of corrupted input.
7979
*/
8080
81
-typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
82
-typedef void (*free_func) OF((voidpf opaque, voidpf address));
81
+typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size);
82
+typedef void (*free_func)(voidpf opaque, voidpf address);
8383
8484
struct internal_state;
8585
8686
typedef struct z_stream_s {
8787
z_const Bytef *next_in; /* next input byte */
@@ -215,24 +215,24 @@
215215
/* for compatibility with versions < 1.0.2 */
216216
217217
218218
/* basic functions */
219219
220
-ZEXTERN const char * ZEXPORT zlibVersion OF((void));
220
+ZEXTERN const char * ZEXPORT zlibVersion(void);
221221
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
222222
If the first character differs, the library code actually used is not
223223
compatible with the zlib.h header file used by the application. This check
224224
is automatically made by deflateInit and inflateInit.
225225
*/
226226
227227
/*
228
-ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
228
+ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level);
229229
230230
Initializes the internal stream state for compression. The fields
231231
zalloc, zfree and opaque must be initialized before by the caller. If
232232
zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
233
- allocation functions.
233
+ allocation functions. total_in, total_out, adler, and msg are initialized.
234234
235235
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
236236
1 gives best speed, 9 gives best compression, 0 gives no compression at all
237237
(the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION
238238
requests a default compromise between speed and compression (currently
@@ -245,11 +245,11 @@
245245
if there is no error message. deflateInit does not perform any compression:
246246
this will be done by deflate().
247247
*/
248248
249249
250
-ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
250
+ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush);
251251
/*
252252
deflate compresses as much data as possible, and stops when the input
253253
buffer becomes empty or the output buffer becomes full. It may introduce
254254
some output latency (reading input without producing any output) except when
255255
forced to flush.
@@ -318,12 +318,12 @@
318318
319319
If deflate returns with avail_out == 0, this function must be called again
320320
with the same value of the flush parameter and more output space (updated
321321
avail_out), until the flush is complete (deflate returns with non-zero
322322
avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
323
- avail_out is greater than six to avoid repeated flush markers due to
324
- avail_out == 0 on return.
323
+ avail_out is greater than six when the flush marker begins, in order to avoid
324
+ repeated flush markers upon calling deflate() again when avail_out == 0.
325325
326326
If the parameter flush is set to Z_FINISH, pending input is processed,
327327
pending output is flushed and deflate returns with Z_STREAM_END if there was
328328
enough output space. If deflate returns with Z_OK or Z_BUF_ERROR, this
329329
function must be called again with Z_FINISH and more output space (updated
@@ -358,11 +358,11 @@
358358
deflate() can be called again with more input and more output space to
359359
continue compressing.
360360
*/
361361
362362
363
-ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
363
+ZEXTERN int ZEXPORT deflateEnd(z_streamp strm);
364364
/*
365365
All dynamically allocated data structures for this stream are freed.
366366
This function discards any unprocessed input and does not flush any pending
367367
output.
368368
@@ -373,19 +373,20 @@
373373
deallocated).
374374
*/
375375
376376
377377
/*
378
-ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
378
+ZEXTERN int ZEXPORT inflateInit(z_streamp strm);
379379
380380
Initializes the internal stream state for decompression. The fields
381381
next_in, avail_in, zalloc, zfree and opaque must be initialized before by
382382
the caller. In the current version of inflate, the provided input is not
383383
read or consumed. The allocation of a sliding window will be deferred to
384384
the first call of inflate (if the decompression does not complete on the
385385
first call). If zalloc and zfree are set to Z_NULL, inflateInit updates
386
- them to use default allocation functions.
386
+ them to use default allocation functions. total_in, total_out, adler, and
387
+ msg are initialized.
387388
388389
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
389390
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
390391
version assumed by the caller, or Z_STREAM_ERROR if the parameters are
391392
invalid, such as a null pointer to the structure. msg is set to null if
@@ -395,11 +396,11 @@
395396
implementation of inflateInit() does not process any header information --
396397
that is deferred until inflate() is called.
397398
*/
398399
399400
400
-ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
401
+ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush);
401402
/*
402403
inflate decompresses as much data as possible, and stops when the input
403404
buffer becomes empty or the output buffer becomes full. It may introduce
404405
some output latency (reading input without producing any output) except when
405406
forced to flush.
@@ -515,11 +516,11 @@
515516
then call inflateSync() to look for a good compression block if a partial
516517
recovery of the data is to be attempted.
517518
*/
518519
519520
520
-ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
521
+ZEXTERN int ZEXPORT inflateEnd(z_streamp strm);
521522
/*
522523
All dynamically allocated data structures for this stream are freed.
523524
This function discards any unprocessed input and does not flush any pending
524525
output.
525526
@@ -533,16 +534,16 @@
533534
/*
534535
The following functions are needed only in some special applications.
535536
*/
536537
537538
/*
538
-ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
539
- int level,
540
- int method,
541
- int windowBits,
542
- int memLevel,
543
- int strategy));
539
+ZEXTERN int ZEXPORT deflateInit2(z_streamp strm,
540
+ int level,
541
+ int method,
542
+ int windowBits,
543
+ int memLevel,
544
+ int strategy);
544545
545546
This is another version of deflateInit with more compression options. The
546547
fields zalloc, zfree and opaque must be initialized before by the caller.
547548
548549
The method parameter is the compression method. It must be Z_DEFLATED in
@@ -605,13 +606,13 @@
605606
incompatible with the version assumed by the caller (ZLIB_VERSION). msg is
606607
set to null if there is no error message. deflateInit2 does not perform any
607608
compression: this will be done by deflate().
608609
*/
609610
610
-ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
611
- const Bytef *dictionary,
612
- uInt dictLength));
611
+ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm,
612
+ const Bytef *dictionary,
613
+ uInt dictLength);
613614
/*
614615
Initializes the compression dictionary from the given byte sequence
615616
without producing any compressed output. When using the zlib format, this
616617
function must be called immediately after deflateInit, deflateInit2 or
617618
deflateReset, and before any call of deflate. When doing raw deflate, this
@@ -649,13 +650,13 @@
649650
inconsistent (for example if deflate has already been called for this stream
650651
or if not at a block boundary for raw deflate). deflateSetDictionary does
651652
not perform any compression: this will be done by deflate().
652653
*/
653654
654
-ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm,
655
- Bytef *dictionary,
656
- uInt *dictLength));
655
+ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm,
656
+ Bytef *dictionary,
657
+ uInt *dictLength);
657658
/*
658659
Returns the sliding dictionary being maintained by deflate. dictLength is
659660
set to the number of bytes in the dictionary, and that many bytes are copied
660661
to dictionary. dictionary must have enough space, where 32768 bytes is
661662
always enough. If deflateGetDictionary() is called with dictionary equal to
@@ -671,12 +672,12 @@
671672
672673
deflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
673674
stream state is inconsistent.
674675
*/
675676
676
-ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
677
- z_streamp source));
677
+ZEXTERN int ZEXPORT deflateCopy(z_streamp dest,
678
+ z_streamp source);
678679
/*
679680
Sets the destination stream as a complete copy of the source stream.
680681
681682
This function can be useful when several compression strategies will be
682683
tried, for example when there are several ways of pre-processing the input
@@ -689,24 +690,24 @@
689690
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
690691
(such as zalloc being Z_NULL). msg is left unchanged in both source and
691692
destination.
692693
*/
693694
694
-ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
695
+ZEXTERN int ZEXPORT deflateReset(z_streamp strm);
695696
/*
696697
This function is equivalent to deflateEnd followed by deflateInit, but
697698
does not free and reallocate the internal compression state. The stream
698699
will leave the compression level and any other attributes that may have been
699
- set unchanged.
700
+ set unchanged. total_in, total_out, adler, and msg are initialized.
700701
701702
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
702703
stream state was inconsistent (such as zalloc or state being Z_NULL).
703704
*/
704705
705
-ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
706
- int level,
707
- int strategy));
706
+ZEXTERN int ZEXPORT deflateParams(z_streamp strm,
707
+ int level,
708
+ int strategy);
708709
/*
709710
Dynamically update the compression level and compression strategy. The
710711
interpretation of level and strategy is as in deflateInit2(). This can be
711712
used to switch between compression and straight copy of the input data, or
712713
to switch to a different kind of input data requiring a different strategy.
@@ -727,11 +728,11 @@
727728
deflate stream should be flushed using deflate() with Z_BLOCK or other flush
728729
request until strm.avail_out is not zero, before calling deflateParams().
729730
Then no more input data should be provided before the deflateParams() call.
730731
If this is done, the old level and strategy will be applied to the data
731732
compressed before deflateParams(), and the new level and strategy will be
732
- applied to the the data compressed after deflateParams().
733
+ applied to the data compressed after deflateParams().
733734
734735
deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
735736
state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
736737
there was not enough output space to complete the compression of the
737738
available input data before a change in the strategy or approach. Note that
@@ -738,15 +739,15 @@
738739
in the case of a Z_BUF_ERROR, the parameters are not changed. A return
739740
value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be
740741
retried with more output space.
741742
*/
742743
743
-ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
744
- int good_length,
745
- int max_lazy,
746
- int nice_length,
747
- int max_chain));
744
+ZEXTERN int ZEXPORT deflateTune(z_streamp strm,
745
+ int good_length,
746
+ int max_lazy,
747
+ int nice_length,
748
+ int max_chain);
748749
/*
749750
Fine tune deflate's internal compression parameters. This should only be
750751
used by someone who understands the algorithm used by zlib's deflate for
751752
searching for the best matching string, and even then only by the most
752753
fanatic optimizer trying to squeeze out the last compressed bit for their
@@ -755,12 +756,12 @@
755756
756757
deflateTune() can be called after deflateInit() or deflateInit2(), and
757758
returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
758759
*/
759760
760
-ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
761
- uLong sourceLen));
761
+ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm,
762
+ uLong sourceLen);
762763
/*
763764
deflateBound() returns an upper bound on the compressed size after
764765
deflation of sourceLen bytes. It must be called after deflateInit() or
765766
deflateInit2(), and after deflateSetHeader(), if used. This would be used
766767
to allocate an output buffer for deflation in a single pass, and so would be
@@ -770,13 +771,13 @@
770771
to return Z_STREAM_END. Note that it is possible for the compressed size to
771772
be larger than the value returned by deflateBound() if flush options other
772773
than Z_FINISH or Z_NO_FLUSH are used.
773774
*/
774775
775
-ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
776
- unsigned *pending,
777
- int *bits));
776
+ZEXTERN int ZEXPORT deflatePending(z_streamp strm,
777
+ unsigned *pending,
778
+ int *bits);
778779
/*
779780
deflatePending() returns the number of bytes and bits of output that have
780781
been generated, but not yet provided in the available output. The bytes not
781782
provided would be due to the available output space having being consumed.
782783
The number of bits of output not provided are between 0 and 7, where they
@@ -785,13 +786,13 @@
785786
786787
deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
787788
stream state was inconsistent.
788789
*/
789790
790
-ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
791
- int bits,
792
- int value));
791
+ZEXTERN int ZEXPORT deflatePrime(z_streamp strm,
792
+ int bits,
793
+ int value);
793794
/*
794795
deflatePrime() inserts bits in the deflate output stream. The intent
795796
is that this function is used to start off the deflate output with the bits
796797
leftover from a previous deflate stream when appending to it. As such, this
797798
function can only be used for raw deflate, and must be used before the first
@@ -802,12 +803,12 @@
802803
deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
803804
room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
804805
source stream state was inconsistent.
805806
*/
806807
807
-ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
808
- gz_headerp head));
808
+ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm,
809
+ gz_headerp head);
809810
/*
810811
deflateSetHeader() provides gzip header information for when a gzip
811812
stream is requested by deflateInit2(). deflateSetHeader() may be called
812813
after deflateInit2() or deflateReset() and before the first call of
813814
deflate(). The text, time, os, extra field, name, and comment information
@@ -819,20 +820,21 @@
819820
the current versions of the command-line version of gzip (up through version
820821
1.3.x) do not support header crc's, and will report that it is a "multi-part
821822
gzip file" and give up.
822823
823824
If deflateSetHeader is not used, the default gzip header has text false,
824
- the time set to zero, and os set to 255, with no extra, name, or comment
825
- fields. The gzip header is returned to the default state by deflateReset().
825
+ the time set to zero, and os set to the current operating system, with no
826
+ extra, name, or comment fields. The gzip header is returned to the default
827
+ state by deflateReset().
826828
827829
deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
828830
stream state was inconsistent.
829831
*/
830832
831833
/*
832
-ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
833
- int windowBits));
834
+ZEXTERN int ZEXPORT inflateInit2(z_streamp strm,
835
+ int windowBits);
834836
835837
This is another version of inflateInit with an extra parameter. The
836838
fields next_in, avail_in, zalloc, zfree and opaque must be initialized
837839
before by the caller.
838840
@@ -881,13 +883,13 @@
881883
next_out and avail_out are unused and unchanged.) The current implementation
882884
of inflateInit2() does not process any header information -- that is
883885
deferred until inflate() is called.
884886
*/
885887
886
-ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
887
- const Bytef *dictionary,
888
- uInt dictLength));
888
+ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm,
889
+ const Bytef *dictionary,
890
+ uInt dictLength);
889891
/*
890892
Initializes the decompression dictionary from the given uncompressed byte
891893
sequence. This function must be called immediately after a call of inflate,
892894
if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
893895
can be determined from the Adler-32 value returned by that call of inflate.
@@ -904,13 +906,13 @@
904906
expected one (incorrect Adler-32 value). inflateSetDictionary does not
905907
perform any decompression: this will be done by subsequent calls of
906908
inflate().
907909
*/
908910
909
-ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm,
910
- Bytef *dictionary,
911
- uInt *dictLength));
911
+ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm,
912
+ Bytef *dictionary,
913
+ uInt *dictLength);
912914
/*
913915
Returns the sliding dictionary being maintained by inflate. dictLength is
914916
set to the number of bytes in the dictionary, and that many bytes are copied
915917
to dictionary. dictionary must have enough space, where 32768 bytes is
916918
always enough. If inflateGetDictionary() is called with dictionary equal to
@@ -919,11 +921,11 @@
919921
920922
inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
921923
stream state is inconsistent.
922924
*/
923925
924
-ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
926
+ZEXTERN int ZEXPORT inflateSync(z_streamp strm);
925927
/*
926928
Skips invalid compressed data until a possible full flush point (see above
927929
for the description of deflate with Z_FULL_FLUSH) can be found, or until all
928930
available input is skipped. No output is provided.
929931
@@ -938,12 +940,12 @@
938940
total_in which indicates where valid compressed data was found. In the
939941
error case, the application may repeatedly call inflateSync, providing more
940942
input each time, until success or end of the input data.
941943
*/
942944
943
-ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
944
- z_streamp source));
945
+ZEXTERN int ZEXPORT inflateCopy(z_streamp dest,
946
+ z_streamp source);
945947
/*
946948
Sets the destination stream as a complete copy of the source stream.
947949
948950
This function can be useful when randomly accessing a large stream. The
949951
first pass through the stream can periodically record the inflate state,
@@ -954,22 +956,23 @@
954956
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
955957
(such as zalloc being Z_NULL). msg is left unchanged in both source and
956958
destination.
957959
*/
958960
959
-ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
961
+ZEXTERN int ZEXPORT inflateReset(z_streamp strm);
960962
/*
961963
This function is equivalent to inflateEnd followed by inflateInit,
962964
but does not free and reallocate the internal decompression state. The
963965
stream will keep attributes that may have been set by inflateInit2.
966
+ total_in, total_out, adler, and msg are initialized.
964967
965968
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
966969
stream state was inconsistent (such as zalloc or state being Z_NULL).
967970
*/
968971
969
-ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
970
- int windowBits));
972
+ZEXTERN int ZEXPORT inflateReset2(z_streamp strm,
973
+ int windowBits);
971974
/*
972975
This function is the same as inflateReset, but it also permits changing
973976
the wrap and window size requests. The windowBits parameter is interpreted
974977
the same as it is for inflateInit2. If the window size is changed, then the
975978
memory allocated for the window is freed, and the window will be reallocated
@@ -978,13 +981,13 @@
978981
inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
979982
stream state was inconsistent (such as zalloc or state being Z_NULL), or if
980983
the windowBits parameter is invalid.
981984
*/
982985
983
-ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
984
- int bits,
985
- int value));
986
+ZEXTERN int ZEXPORT inflatePrime(z_streamp strm,
987
+ int bits,
988
+ int value);
986989
/*
987990
This function inserts bits in the inflate input stream. The intent is
988991
that this function is used to start inflating at a bit position in the
989992
middle of a byte. The provided bits will be used before any bytes are used
990993
from next_in. This function should only be used with raw inflate, and
@@ -999,11 +1002,11 @@
9991002
10001003
inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
10011004
stream state was inconsistent.
10021005
*/
10031006
1004
-ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
1007
+ZEXTERN long ZEXPORT inflateMark(z_streamp strm);
10051008
/*
10061009
This function returns two values, one in the lower 16 bits of the return
10071010
value, and the other in the remaining upper bits, obtained by shifting the
10081011
return value down 16 bits. If the upper value is -1 and the lower value is
10091012
zero, then inflate() is currently decoding information outside of a block.
@@ -1027,12 +1030,12 @@
10271030
10281031
inflateMark returns the value noted above, or -65536 if the provided
10291032
source stream state was inconsistent.
10301033
*/
10311034
1032
-ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
1033
- gz_headerp head));
1035
+ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm,
1036
+ gz_headerp head);
10341037
/*
10351038
inflateGetHeader() requests that gzip header information be stored in the
10361039
provided gz_header structure. inflateGetHeader() may be called after
10371040
inflateInit2() or inflateReset(), and before the first call of inflate().
10381041
As inflate() processes the gzip stream, head->done is zero until the header
@@ -1068,12 +1071,12 @@
10681071
inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
10691072
stream state was inconsistent.
10701073
*/
10711074
10721075
/*
1073
-ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
1074
- unsigned char FAR *window));
1076
+ZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits,
1077
+ unsigned char FAR *window);
10751078
10761079
Initialize the internal stream state for decompression using inflateBack()
10771080
calls. The fields zalloc, zfree and opaque in strm must be initialized
10781081
before the call. If zalloc and zfree are Z_NULL, then the default library-
10791082
derived memory allocation routines are used. windowBits is the base two
@@ -1089,17 +1092,17 @@
10891092
the parameters are invalid, Z_MEM_ERROR if the internal state could not be
10901093
allocated, or Z_VERSION_ERROR if the version of the library does not match
10911094
the version of the header file.
10921095
*/
10931096
1094
-typedef unsigned (*in_func) OF((void FAR *,
1095
- z_const unsigned char FAR * FAR *));
1096
-typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
1097
+typedef unsigned (*in_func)(void FAR *,
1098
+ z_const unsigned char FAR * FAR *);
1099
+typedef int (*out_func)(void FAR *, unsigned char FAR *, unsigned);
10971100
1098
-ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
1099
- in_func in, void FAR *in_desc,
1100
- out_func out, void FAR *out_desc));
1101
+ZEXTERN int ZEXPORT inflateBack(z_streamp strm,
1102
+ in_func in, void FAR *in_desc,
1103
+ out_func out, void FAR *out_desc);
11011104
/*
11021105
inflateBack() does a raw inflate with a single call using a call-back
11031106
interface for input and output. This is potentially more efficient than
11041107
inflate() for file i/o applications, in that it avoids copying between the
11051108
output and the sliding window by simply making the window itself the output
@@ -1163,19 +1166,19 @@
11631166
non-zero. (in() will always be called before out(), so strm->next_in is
11641167
assured to be defined if out() returns non-zero.) Note that inflateBack()
11651168
cannot return Z_OK.
11661169
*/
11671170
1168
-ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
1171
+ZEXTERN int ZEXPORT inflateBackEnd(z_streamp strm);
11691172
/*
11701173
All memory allocated by inflateBackInit() is freed.
11711174
11721175
inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
11731176
state was inconsistent.
11741177
*/
11751178
1176
-ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
1179
+ZEXTERN uLong ZEXPORT zlibCompileFlags(void);
11771180
/* Return flags indicating compile-time options.
11781181
11791182
Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
11801183
1.0: size of uInt
11811184
3.2: size of uLong
@@ -1224,12 +1227,12 @@
12241227
are assumed (compression level and memory usage, standard memory allocation
12251228
functions). The source code of these utility functions can be modified if
12261229
you need special options.
12271230
*/
12281231
1229
-ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
1230
- const Bytef *source, uLong sourceLen));
1232
+ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen,
1233
+ const Bytef *source, uLong sourceLen);
12311234
/*
12321235
Compresses the source buffer into the destination buffer. sourceLen is
12331236
the byte length of the source buffer. Upon entry, destLen is the total size
12341237
of the destination buffer, which must be at least the value returned by
12351238
compressBound(sourceLen). Upon exit, destLen is the actual size of the
@@ -1239,13 +1242,13 @@
12391242
compress returns Z_OK if success, Z_MEM_ERROR if there was not
12401243
enough memory, Z_BUF_ERROR if there was not enough room in the output
12411244
buffer.
12421245
*/
12431246
1244
-ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
1245
- const Bytef *source, uLong sourceLen,
1246
- int level));
1247
+ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen,
1248
+ const Bytef *source, uLong sourceLen,
1249
+ int level);
12471250
/*
12481251
Compresses the source buffer into the destination buffer. The level
12491252
parameter has the same meaning as in deflateInit. sourceLen is the byte
12501253
length of the source buffer. Upon entry, destLen is the total size of the
12511254
destination buffer, which must be at least the value returned by
@@ -1255,19 +1258,19 @@
12551258
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
12561259
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
12571260
Z_STREAM_ERROR if the level parameter is invalid.
12581261
*/
12591262
1260
-ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
1263
+ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen);
12611264
/*
12621265
compressBound() returns an upper bound on the compressed size after
12631266
compress() or compress2() on sourceLen bytes. It would be used before a
12641267
compress() or compress2() call to allocate the destination buffer.
12651268
*/
12661269
1267
-ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
1268
- const Bytef *source, uLong sourceLen));
1270
+ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen,
1271
+ const Bytef *source, uLong sourceLen);
12691272
/*
12701273
Decompresses the source buffer into the destination buffer. sourceLen is
12711274
the byte length of the source buffer. Upon entry, destLen is the total size
12721275
of the destination buffer, which must be large enough to hold the entire
12731276
uncompressed data. (The size of the uncompressed data must have been saved
@@ -1280,12 +1283,12 @@
12801283
buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
12811284
the case where there is not enough room, uncompress() will fill the output
12821285
buffer with the uncompressed data up to that point.
12831286
*/
12841287
1285
-ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen,
1286
- const Bytef *source, uLong *sourceLen));
1288
+ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen,
1289
+ const Bytef *source, uLong *sourceLen);
12871290
/*
12881291
Same as uncompress, except that sourceLen is a pointer, where the
12891292
length of the source is *sourceLen. On return, *sourceLen is the number of
12901293
source bytes consumed.
12911294
*/
@@ -1300,11 +1303,11 @@
13001303
*/
13011304
13021305
typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
13031306
13041307
/*
1305
-ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
1308
+ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode);
13061309
13071310
Open the gzip (.gz) file at path for reading and decompressing, or
13081311
compressing and writing. The mode parameter is as in fopen ("rb" or "wb")
13091312
but can also include a compression level ("wb9") or a strategy: 'f' for
13101313
filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h",
@@ -1337,11 +1340,11 @@
13371340
specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).
13381341
errno can be checked to determine if the reason gzopen failed was that the
13391342
file could not be opened.
13401343
*/
13411344
1342
-ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
1345
+ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode);
13431346
/*
13441347
Associate a gzFile with the file descriptor fd. File descriptors are
13451348
obtained from calls like open, dup, creat, pipe or fileno (if the file has
13461349
been previously opened with fopen). The mode parameter is as in gzopen.
13471350
@@ -1360,11 +1363,11 @@
13601363
provided, or '+' was provided), or if fd is -1. The file descriptor is not
13611364
used until the next gz* read, write, seek, or close operation, so gzdopen
13621365
will not detect if fd is invalid (unless fd is -1).
13631366
*/
13641367
1365
-ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
1368
+ZEXTERN int ZEXPORT gzbuffer(gzFile file, unsigned size);
13661369
/*
13671370
Set the internal buffer size used by this library's functions for file to
13681371
size. The default buffer size is 8192 bytes. This function must be called
13691372
after gzopen() or gzdopen(), and before any other calls that read or write
13701373
the file. The buffer memory allocation is always deferred to the first read
@@ -1376,11 +1379,11 @@
13761379
13771380
gzbuffer() returns 0 on success, or -1 on failure, such as being called
13781381
too late.
13791382
*/
13801383
1381
-ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
1384
+ZEXTERN int ZEXPORT gzsetparams(gzFile file, int level, int strategy);
13821385
/*
13831386
Dynamically update the compression level and strategy for file. See the
13841387
description of deflateInit2 for the meaning of these parameters. Previously
13851388
provided data is flushed before applying the parameter changes.
13861389
@@ -1387,11 +1390,11 @@
13871390
gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not
13881391
opened for writing, Z_ERRNO if there is an error writing the flushed data,
13891392
or Z_MEM_ERROR if there is a memory allocation error.
13901393
*/
13911394
1392
-ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
1395
+ZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len);
13931396
/*
13941397
Read and decompress up to len uncompressed bytes from file into buf. If
13951398
the input file is not in gzip format, gzread copies the given number of
13961399
bytes into the buffer directly from the file.
13971400
@@ -1417,12 +1420,12 @@
14171420
len for end of file, or -1 for error. If len is too large to fit in an int,
14181421
then nothing is read, -1 is returned, and the error state is set to
14191422
Z_STREAM_ERROR.
14201423
*/
14211424
1422
-ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems,
1423
- gzFile file));
1425
+ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems,
1426
+ gzFile file);
14241427
/*
14251428
Read and decompress up to nitems items of size size from file into buf,
14261429
otherwise operating as gzread() does. This duplicates the interface of
14271430
stdio's fread(), with size_t request and return types. If the library
14281431
defines size_t, then z_size_t is identical to size_t. If not, then z_size_t
@@ -1443,18 +1446,18 @@
14431446
is the same as the behavior of fread() implementations in common libraries,
14441447
but it prevents the direct use of gzfread() to read a concurrently written
14451448
file, resetting and retrying on end-of-file, when size is not 1.
14461449
*/
14471450
1448
-ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len));
1451
+ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len);
14491452
/*
14501453
Compress and write the len uncompressed bytes at buf to file. gzwrite
14511454
returns the number of uncompressed bytes written or 0 in case of error.
14521455
*/
14531456
1454
-ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size,
1455
- z_size_t nitems, gzFile file));
1457
+ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size,
1458
+ z_size_t nitems, gzFile file);
14561459
/*
14571460
Compress and write nitems items of size size from buf to file, duplicating
14581461
the interface of stdio's fwrite(), with size_t request and return types. If
14591462
the library defines size_t, then z_size_t is identical to size_t. If not,
14601463
then z_size_t is an unsigned integer type that can contain a pointer.
@@ -1463,11 +1466,11 @@
14631466
if there was an error. If the multiplication of size and nitems overflows,
14641467
i.e. the product does not fit in a z_size_t, then nothing is written, zero
14651468
is returned, and the error state is set to Z_STREAM_ERROR.
14661469
*/
14671470
1468
-ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
1471
+ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...);
14691472
/*
14701473
Convert, format, compress, and write the arguments (...) to file under
14711474
control of the string format, as in fprintf. gzprintf returns the number of
14721475
uncompressed bytes actually written, or a negative zlib error code in case
14731476
of error. The number of uncompressed bytes written is limited to 8191, or
@@ -1478,19 +1481,19 @@
14781481
zlib was compiled with the insecure functions sprintf() or vsprintf(),
14791482
because the secure snprintf() or vsnprintf() functions were not available.
14801483
This can be determined using zlibCompileFlags().
14811484
*/
14821485
1483
-ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
1486
+ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s);
14841487
/*
14851488
Compress and write the given null-terminated string s to file, excluding
14861489
the terminating null character.
14871490
14881491
gzputs returns the number of characters written, or -1 in case of error.
14891492
*/
14901493
1491
-ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
1494
+ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len);
14921495
/*
14931496
Read and decompress bytes from file into buf, until len-1 characters are
14941497
read, or until a newline character is read and transferred to buf, or an
14951498
end-of-file condition is encountered. If any characters are read or if len
14961499
is one, the string is terminated with a null character. If no characters
@@ -1500,26 +1503,26 @@
15001503
gzgets returns buf which is a null-terminated string, or it returns NULL
15011504
for end-of-file or in case of error. If there was an error, the contents at
15021505
buf are indeterminate.
15031506
*/
15041507
1505
-ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
1508
+ZEXTERN int ZEXPORT gzputc(gzFile file, int c);
15061509
/*
15071510
Compress and write c, converted to an unsigned char, into file. gzputc
15081511
returns the value that was written, or -1 in case of error.
15091512
*/
15101513
1511
-ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
1514
+ZEXTERN int ZEXPORT gzgetc(gzFile file);
15121515
/*
15131516
Read and decompress one byte from file. gzgetc returns this byte or -1
15141517
in case of end of file or error. This is implemented as a macro for speed.
15151518
As such, it does not do all of the checking the other functions do. I.e.
15161519
it does not check to see if file is NULL, nor whether the structure file
15171520
points to has been clobbered or not.
15181521
*/
15191522
1520
-ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
1523
+ZEXTERN int ZEXPORT gzungetc(int c, gzFile file);
15211524
/*
15221525
Push c back onto the stream for file to be read as the first character on
15231526
the next read. At least one character of push-back is always allowed.
15241527
gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
15251528
fail if c is -1, and may fail if a character has been pushed but not read
@@ -1527,11 +1530,11 @@
15271530
output buffer size of pushed characters is allowed. (See gzbuffer above.)
15281531
The pushed character will be discarded if the stream is repositioned with
15291532
gzseek() or gzrewind().
15301533
*/
15311534
1532
-ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
1535
+ZEXTERN int ZEXPORT gzflush(gzFile file, int flush);
15331536
/*
15341537
Flush all pending output to file. The parameter flush is as in the
15351538
deflate() function. The return value is the zlib error number (see function
15361539
gzerror below). gzflush is only permitted when writing.
15371540
@@ -1543,12 +1546,12 @@
15431546
gzflush should be called only when strictly necessary because it will
15441547
degrade compression if called too often.
15451548
*/
15461549
15471550
/*
1548
-ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
1549
- z_off_t offset, int whence));
1551
+ZEXTERN z_off_t ZEXPORT gzseek(gzFile file,
1552
+ z_off_t offset, int whence);
15501553
15511554
Set the starting position to offset relative to whence for the next gzread
15521555
or gzwrite on file. The offset represents a number of bytes in the
15531556
uncompressed data stream. The whence parameter is defined as in lseek(2);
15541557
the value SEEK_END is not supported.
@@ -1562,19 +1565,19 @@
15621565
the beginning of the uncompressed stream, or -1 in case of error, in
15631566
particular if the file is opened for writing and the new starting position
15641567
would be before the current position.
15651568
*/
15661569
1567
-ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
1570
+ZEXTERN int ZEXPORT gzrewind(gzFile file);
15681571
/*
15691572
Rewind file. This function is supported only for reading.
15701573
15711574
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET).
15721575
*/
15731576
15741577
/*
1575
-ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
1578
+ZEXTERN z_off_t ZEXPORT gztell(gzFile file);
15761579
15771580
Return the starting position for the next gzread or gzwrite on file.
15781581
This position represents a number of bytes in the uncompressed data stream,
15791582
and is zero when starting, even if appending or reading a gzip stream from
15801583
the middle of a file using gzdopen().
@@ -1581,20 +1584,20 @@
15811584
15821585
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
15831586
*/
15841587
15851588
/*
1586
-ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
1589
+ZEXTERN z_off_t ZEXPORT gzoffset(gzFile file);
15871590
15881591
Return the current compressed (actual) read or write offset of file. This
15891592
offset includes the count of bytes that precede the gzip stream, for example
15901593
when appending or when using gzdopen() for reading. When reading, the
15911594
offset does not include as yet unused buffered input. This information can
15921595
be used for a progress indicator. On error, gzoffset() returns -1.
15931596
*/
15941597
1595
-ZEXTERN int ZEXPORT gzeof OF((gzFile file));
1598
+ZEXTERN int ZEXPORT gzeof(gzFile file);
15961599
/*
15971600
Return true (1) if the end-of-file indicator for file has been set while
15981601
reading, false (0) otherwise. Note that the end-of-file indicator is set
15991602
only if the read tried to go past the end of the input, but came up short.
16001603
Therefore, just like feof(), gzeof() may return false even if there is no
@@ -1605,11 +1608,11 @@
16051608
If gzeof() returns true, then the read functions will return no more data,
16061609
unless the end-of-file indicator is reset by gzclearerr() and the input file
16071610
has grown since the previous end of file was detected.
16081611
*/
16091612
1610
-ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
1613
+ZEXTERN int ZEXPORT gzdirect(gzFile file);
16111614
/*
16121615
Return true (1) if file is being copied directly while reading, or false
16131616
(0) if file is a gzip stream being decompressed.
16141617
16151618
If the input file is empty, gzdirect() will return true, since the input
@@ -1626,11 +1629,11 @@
16261629
explicitly requested, so the application already knows the answer. When
16271630
linking statically, using gzdirect() will include all of the zlib code for
16281631
gzip file reading and decompression, which may not be desired.)
16291632
*/
16301633
1631
-ZEXTERN int ZEXPORT gzclose OF((gzFile file));
1634
+ZEXTERN int ZEXPORT gzclose(gzFile file);
16321635
/*
16331636
Flush all pending output for file, if necessary, close file and
16341637
deallocate the (de)compression state. Note that once file is closed, you
16351638
cannot call gzerror with file, since its structures have been deallocated.
16361639
gzclose must not be called more than once on the same file, just as free
@@ -1639,12 +1642,12 @@
16391642
gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
16401643
file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
16411644
last read ended in the middle of a gzip stream, or Z_OK on success.
16421645
*/
16431646
1644
-ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
1645
-ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
1647
+ZEXTERN int ZEXPORT gzclose_r(gzFile file);
1648
+ZEXTERN int ZEXPORT gzclose_w(gzFile file);
16461649
/*
16471650
Same as gzclose(), but gzclose_r() is only for use when reading, and
16481651
gzclose_w() is only for use when writing or appending. The advantage to
16491652
using these instead of gzclose() is that they avoid linking in zlib
16501653
compression or decompression code that is not used when only reading or only
@@ -1651,11 +1654,11 @@
16511654
writing respectively. If gzclose() is used, then both compression and
16521655
decompression code will be included the application when linking to a static
16531656
zlib library.
16541657
*/
16551658
1656
-ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1659
+ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum);
16571660
/*
16581661
Return the error message for the last error which occurred on file.
16591662
errnum is set to zlib error number. If an error occurred in the file system
16601663
and not in the compression library, errnum is set to Z_ERRNO and the
16611664
application may consult errno to get the exact error code.
@@ -1667,11 +1670,11 @@
16671670
16681671
gzerror() should be used to distinguish errors from end-of-file for those
16691672
functions above that do not distinguish those cases in their return values.
16701673
*/
16711674
1672
-ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1675
+ZEXTERN void ZEXPORT gzclearerr(gzFile file);
16731676
/*
16741677
Clear the error and end-of-file flags for file. This is analogous to the
16751678
clearerr() function in stdio. This is useful for continuing to read a gzip
16761679
file that is being written concurrently.
16771680
*/
@@ -1684,11 +1687,11 @@
16841687
These functions are not related to compression but are exported
16851688
anyway because they might be useful in applications using the compression
16861689
library.
16871690
*/
16881691
1689
-ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
1692
+ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len);
16901693
/*
16911694
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
16921695
return the updated checksum. An Adler-32 value is in the range of a 32-bit
16931696
unsigned integer. If buf is Z_NULL, this function returns the required
16941697
initial value for the checksum.
@@ -1704,29 +1707,29 @@
17041707
adler = adler32(adler, buffer, length);
17051708
}
17061709
if (adler != original_adler) error();
17071710
*/
17081711
1709
-ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf,
1710
- z_size_t len));
1712
+ZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf,
1713
+ z_size_t len);
17111714
/*
17121715
Same as adler32(), but with a size_t length.
17131716
*/
17141717
17151718
/*
1716
-ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
1717
- z_off_t len2));
1719
+ZEXTERN uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2,
1720
+ z_off_t len2);
17181721
17191722
Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
17201723
and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
17211724
each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
17221725
seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
17231726
that the z_off_t type (like off_t) is a signed integer. If len2 is
17241727
negative, the result has no meaning or utility.
17251728
*/
17261729
1727
-ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
1730
+ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len);
17281731
/*
17291732
Update a running CRC-32 with the bytes buf[0..len-1] and return the
17301733
updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer.
17311734
If buf is Z_NULL, this function returns the required initial value for the
17321735
crc. Pre- and post-conditioning (one's complement) is performed within this
@@ -1740,34 +1743,34 @@
17401743
crc = crc32(crc, buffer, length);
17411744
}
17421745
if (crc != original_crc) error();
17431746
*/
17441747
1745
-ZEXTERN uLong ZEXPORT crc32_z OF((uLong crc, const Bytef *buf,
1746
- z_size_t len));
1748
+ZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf,
1749
+ z_size_t len);
17471750
/*
17481751
Same as crc32(), but with a size_t length.
17491752
*/
17501753
17511754
/*
1752
-ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
1755
+ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2);
17531756
17541757
Combine two CRC-32 check values into one. For two sequences of bytes,
17551758
seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
17561759
calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
17571760
check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
17581761
len2.
17591762
*/
17601763
17611764
/*
1762
-ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2));
1765
+ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2);
17631766
17641767
Return the operator corresponding to length len2, to be used with
17651768
crc32_combine_op().
17661769
*/
17671770
1768
-ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op));
1771
+ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op);
17691772
/*
17701773
Give the same result as crc32_combine(), using op in place of len2. op is
17711774
is generated from len2 by crc32_combine_gen(). This will be faster than
17721775
crc32_combine() if the generated op is used more than once.
17731776
*/
@@ -1776,24 +1779,24 @@
17761779
/* various hacks, don't look :) */
17771780
17781781
/* deflateInit and inflateInit are macros to allow checking the zlib version
17791782
* and the compiler's view of z_stream:
17801783
*/
1781
-ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
1782
- const char *version, int stream_size));
1783
-ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
1784
- const char *version, int stream_size));
1785
-ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
1786
- int windowBits, int memLevel,
1787
- int strategy, const char *version,
1788
- int stream_size));
1789
-ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
1790
- const char *version, int stream_size));
1791
-ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
1792
- unsigned char FAR *window,
1793
- const char *version,
1794
- int stream_size));
1784
+ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level,
1785
+ const char *version, int stream_size);
1786
+ZEXTERN int ZEXPORT inflateInit_(z_streamp strm,
1787
+ const char *version, int stream_size);
1788
+ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
1789
+ int windowBits, int memLevel,
1790
+ int strategy, const char *version,
1791
+ int stream_size);
1792
+ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits,
1793
+ const char *version, int stream_size);
1794
+ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
1795
+ unsigned char FAR *window,
1796
+ const char *version,
1797
+ int stream_size);
17951798
#ifdef Z_PREFIX_SET
17961799
# define z_deflateInit(strm, level) \
17971800
deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
17981801
# define z_inflateInit(strm) \
17991802
inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
@@ -1834,11 +1837,11 @@
18341837
struct gzFile_s {
18351838
unsigned have;
18361839
unsigned char *next;
18371840
z_off64_t pos;
18381841
};
1839
-ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
1842
+ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */
18401843
#ifdef Z_PREFIX_SET
18411844
# undef z_gzgetc
18421845
# define z_gzgetc(g) \
18431846
((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
18441847
#else
@@ -1851,17 +1854,17 @@
18511854
* both are true, the application gets the *64 functions, and the regular
18521855
* functions are changed to 64 bits) -- in case these are set on systems
18531856
* without large file support, _LFS64_LARGEFILE must also be true
18541857
*/
18551858
#ifdef Z_LARGE64
1856
- ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
1857
- ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
1858
- ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
1859
- ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
1860
- ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t));
1861
- ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
1862
- ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t));
1859
+ ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
1860
+ ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
1861
+ ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
1862
+ ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
1863
+ ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t);
1864
+ ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t);
1865
+ ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t);
18631866
#endif
18641867
18651868
#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
18661869
# ifdef Z_PREFIX_SET
18671870
# define z_gzopen z_gzopen64
@@ -1879,57 +1882,57 @@
18791882
# define adler32_combine adler32_combine64
18801883
# define crc32_combine crc32_combine64
18811884
# define crc32_combine_gen crc32_combine_gen64
18821885
# endif
18831886
# ifndef Z_LARGE64
1884
- ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
1885
- ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
1886
- ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
1887
- ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
1888
- ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
1889
- ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
1890
- ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t));
1887
+ ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
1888
+ ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int);
1889
+ ZEXTERN z_off_t ZEXPORT gztell64(gzFile);
1890
+ ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile);
1891
+ ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
1892
+ ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
1893
+ ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
18911894
# endif
18921895
#else
1893
- ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
1894
- ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
1895
- ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
1896
- ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
1897
- ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
1898
- ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
1899
- ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t));
1896
+ ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *);
1897
+ ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int);
1898
+ ZEXTERN z_off_t ZEXPORT gztell(gzFile);
1899
+ ZEXTERN z_off_t ZEXPORT gzoffset(gzFile);
1900
+ ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t);
1901
+ ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t);
1902
+ ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t);
19001903
#endif
19011904
19021905
#else /* Z_SOLO */
19031906
1904
- ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
1905
- ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
1906
- ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t));
1907
+ ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t);
1908
+ ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t);
1909
+ ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t);
19071910
19081911
#endif /* !Z_SOLO */
19091912
19101913
/* undocumented functions */
1911
-ZEXTERN const char * ZEXPORT zError OF((int));
1912
-ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
1913
-ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
1914
-ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
1915
-ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int));
1916
-ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF((z_streamp));
1917
-ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
1918
-ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
1914
+ZEXTERN const char * ZEXPORT zError(int);
1915
+ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp);
1916
+ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void);
1917
+ZEXTERN int ZEXPORT inflateUndermine(z_streamp, int);
1918
+ZEXTERN int ZEXPORT inflateValidate(z_streamp, int);
1919
+ZEXTERN unsigned long ZEXPORT inflateCodesUsed(z_streamp);
1920
+ZEXTERN int ZEXPORT inflateResetKeep(z_streamp);
1921
+ZEXTERN int ZEXPORT deflateResetKeep(z_streamp);
19191922
#if defined(_WIN32) && !defined(Z_SOLO)
1920
-ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
1921
- const char *mode));
1923
+ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path,
1924
+ const char *mode);
19221925
#endif
19231926
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
19241927
# ifndef Z_SOLO
1925
-ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file,
1926
- const char *format,
1927
- va_list va));
1928
+ZEXTERN int ZEXPORTVA gzvprintf(gzFile file,
1929
+ const char *format,
1930
+ va_list va);
19281931
# endif
19291932
#endif
19301933
19311934
#ifdef __cplusplus
19321935
}
19331936
#endif
19341937
19351938
#endif /* ZLIB_H */
19361939
19371940
DELETED compat/zlib/zlib2ansi
--- compat/zlib/zlib.h
+++ compat/zlib/zlib.h
@@ -1,9 +1,9 @@
1 /* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 1.2.13, October 13th, 2022
3
4 Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
5
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
9
@@ -35,15 +35,15 @@
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 #define ZLIB_VERSION "1.2.13"
41 #define ZLIB_VERNUM 0x12d0
42 #define ZLIB_VER_MAJOR 1
43 #define ZLIB_VER_MINOR 2
44 #define ZLIB_VER_REVISION 13
45 #define ZLIB_VER_SUBREVISION 0
46
47 /*
48 The 'zlib' compression library provides in-memory compression and
49 decompression functions, including integrity checks of the uncompressed data.
@@ -76,12 +76,12 @@
76 The library does not install any signal handler. The decoder checks
77 the consistency of the compressed data, so the library should never crash
78 even in the case of corrupted input.
79 */
80
81 typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
82 typedef void (*free_func) OF((voidpf opaque, voidpf address));
83
84 struct internal_state;
85
86 typedef struct z_stream_s {
87 z_const Bytef *next_in; /* next input byte */
@@ -215,24 +215,24 @@
215 /* for compatibility with versions < 1.0.2 */
216
217
218 /* basic functions */
219
220 ZEXTERN const char * ZEXPORT zlibVersion OF((void));
221 /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
222 If the first character differs, the library code actually used is not
223 compatible with the zlib.h header file used by the application. This check
224 is automatically made by deflateInit and inflateInit.
225 */
226
227 /*
228 ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
229
230 Initializes the internal stream state for compression. The fields
231 zalloc, zfree and opaque must be initialized before by the caller. If
232 zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
233 allocation functions.
234
235 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
236 1 gives best speed, 9 gives best compression, 0 gives no compression at all
237 (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION
238 requests a default compromise between speed and compression (currently
@@ -245,11 +245,11 @@
245 if there is no error message. deflateInit does not perform any compression:
246 this will be done by deflate().
247 */
248
249
250 ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
251 /*
252 deflate compresses as much data as possible, and stops when the input
253 buffer becomes empty or the output buffer becomes full. It may introduce
254 some output latency (reading input without producing any output) except when
255 forced to flush.
@@ -318,12 +318,12 @@
318
319 If deflate returns with avail_out == 0, this function must be called again
320 with the same value of the flush parameter and more output space (updated
321 avail_out), until the flush is complete (deflate returns with non-zero
322 avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
323 avail_out is greater than six to avoid repeated flush markers due to
324 avail_out == 0 on return.
325
326 If the parameter flush is set to Z_FINISH, pending input is processed,
327 pending output is flushed and deflate returns with Z_STREAM_END if there was
328 enough output space. If deflate returns with Z_OK or Z_BUF_ERROR, this
329 function must be called again with Z_FINISH and more output space (updated
@@ -358,11 +358,11 @@
358 deflate() can be called again with more input and more output space to
359 continue compressing.
360 */
361
362
363 ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
364 /*
365 All dynamically allocated data structures for this stream are freed.
366 This function discards any unprocessed input and does not flush any pending
367 output.
368
@@ -373,19 +373,20 @@
373 deallocated).
374 */
375
376
377 /*
378 ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
379
380 Initializes the internal stream state for decompression. The fields
381 next_in, avail_in, zalloc, zfree and opaque must be initialized before by
382 the caller. In the current version of inflate, the provided input is not
383 read or consumed. The allocation of a sliding window will be deferred to
384 the first call of inflate (if the decompression does not complete on the
385 first call). If zalloc and zfree are set to Z_NULL, inflateInit updates
386 them to use default allocation functions.
 
387
388 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
389 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
390 version assumed by the caller, or Z_STREAM_ERROR if the parameters are
391 invalid, such as a null pointer to the structure. msg is set to null if
@@ -395,11 +396,11 @@
395 implementation of inflateInit() does not process any header information --
396 that is deferred until inflate() is called.
397 */
398
399
400 ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
401 /*
402 inflate decompresses as much data as possible, and stops when the input
403 buffer becomes empty or the output buffer becomes full. It may introduce
404 some output latency (reading input without producing any output) except when
405 forced to flush.
@@ -515,11 +516,11 @@
515 then call inflateSync() to look for a good compression block if a partial
516 recovery of the data is to be attempted.
517 */
518
519
520 ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
521 /*
522 All dynamically allocated data structures for this stream are freed.
523 This function discards any unprocessed input and does not flush any pending
524 output.
525
@@ -533,16 +534,16 @@
533 /*
534 The following functions are needed only in some special applications.
535 */
536
537 /*
538 ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
539 int level,
540 int method,
541 int windowBits,
542 int memLevel,
543 int strategy));
544
545 This is another version of deflateInit with more compression options. The
546 fields zalloc, zfree and opaque must be initialized before by the caller.
547
548 The method parameter is the compression method. It must be Z_DEFLATED in
@@ -605,13 +606,13 @@
605 incompatible with the version assumed by the caller (ZLIB_VERSION). msg is
606 set to null if there is no error message. deflateInit2 does not perform any
607 compression: this will be done by deflate().
608 */
609
610 ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
611 const Bytef *dictionary,
612 uInt dictLength));
613 /*
614 Initializes the compression dictionary from the given byte sequence
615 without producing any compressed output. When using the zlib format, this
616 function must be called immediately after deflateInit, deflateInit2 or
617 deflateReset, and before any call of deflate. When doing raw deflate, this
@@ -649,13 +650,13 @@
649 inconsistent (for example if deflate has already been called for this stream
650 or if not at a block boundary for raw deflate). deflateSetDictionary does
651 not perform any compression: this will be done by deflate().
652 */
653
654 ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm,
655 Bytef *dictionary,
656 uInt *dictLength));
657 /*
658 Returns the sliding dictionary being maintained by deflate. dictLength is
659 set to the number of bytes in the dictionary, and that many bytes are copied
660 to dictionary. dictionary must have enough space, where 32768 bytes is
661 always enough. If deflateGetDictionary() is called with dictionary equal to
@@ -671,12 +672,12 @@
671
672 deflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
673 stream state is inconsistent.
674 */
675
676 ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
677 z_streamp source));
678 /*
679 Sets the destination stream as a complete copy of the source stream.
680
681 This function can be useful when several compression strategies will be
682 tried, for example when there are several ways of pre-processing the input
@@ -689,24 +690,24 @@
689 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
690 (such as zalloc being Z_NULL). msg is left unchanged in both source and
691 destination.
692 */
693
694 ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
695 /*
696 This function is equivalent to deflateEnd followed by deflateInit, but
697 does not free and reallocate the internal compression state. The stream
698 will leave the compression level and any other attributes that may have been
699 set unchanged.
700
701 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
702 stream state was inconsistent (such as zalloc or state being Z_NULL).
703 */
704
705 ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
706 int level,
707 int strategy));
708 /*
709 Dynamically update the compression level and compression strategy. The
710 interpretation of level and strategy is as in deflateInit2(). This can be
711 used to switch between compression and straight copy of the input data, or
712 to switch to a different kind of input data requiring a different strategy.
@@ -727,11 +728,11 @@
727 deflate stream should be flushed using deflate() with Z_BLOCK or other flush
728 request until strm.avail_out is not zero, before calling deflateParams().
729 Then no more input data should be provided before the deflateParams() call.
730 If this is done, the old level and strategy will be applied to the data
731 compressed before deflateParams(), and the new level and strategy will be
732 applied to the the data compressed after deflateParams().
733
734 deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
735 state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
736 there was not enough output space to complete the compression of the
737 available input data before a change in the strategy or approach. Note that
@@ -738,15 +739,15 @@
738 in the case of a Z_BUF_ERROR, the parameters are not changed. A return
739 value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be
740 retried with more output space.
741 */
742
743 ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
744 int good_length,
745 int max_lazy,
746 int nice_length,
747 int max_chain));
748 /*
749 Fine tune deflate's internal compression parameters. This should only be
750 used by someone who understands the algorithm used by zlib's deflate for
751 searching for the best matching string, and even then only by the most
752 fanatic optimizer trying to squeeze out the last compressed bit for their
@@ -755,12 +756,12 @@
755
756 deflateTune() can be called after deflateInit() or deflateInit2(), and
757 returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
758 */
759
760 ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
761 uLong sourceLen));
762 /*
763 deflateBound() returns an upper bound on the compressed size after
764 deflation of sourceLen bytes. It must be called after deflateInit() or
765 deflateInit2(), and after deflateSetHeader(), if used. This would be used
766 to allocate an output buffer for deflation in a single pass, and so would be
@@ -770,13 +771,13 @@
770 to return Z_STREAM_END. Note that it is possible for the compressed size to
771 be larger than the value returned by deflateBound() if flush options other
772 than Z_FINISH or Z_NO_FLUSH are used.
773 */
774
775 ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
776 unsigned *pending,
777 int *bits));
778 /*
779 deflatePending() returns the number of bytes and bits of output that have
780 been generated, but not yet provided in the available output. The bytes not
781 provided would be due to the available output space having being consumed.
782 The number of bits of output not provided are between 0 and 7, where they
@@ -785,13 +786,13 @@
785
786 deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
787 stream state was inconsistent.
788 */
789
790 ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
791 int bits,
792 int value));
793 /*
794 deflatePrime() inserts bits in the deflate output stream. The intent
795 is that this function is used to start off the deflate output with the bits
796 leftover from a previous deflate stream when appending to it. As such, this
797 function can only be used for raw deflate, and must be used before the first
@@ -802,12 +803,12 @@
802 deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
803 room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
804 source stream state was inconsistent.
805 */
806
807 ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
808 gz_headerp head));
809 /*
810 deflateSetHeader() provides gzip header information for when a gzip
811 stream is requested by deflateInit2(). deflateSetHeader() may be called
812 after deflateInit2() or deflateReset() and before the first call of
813 deflate(). The text, time, os, extra field, name, and comment information
@@ -819,20 +820,21 @@
819 the current versions of the command-line version of gzip (up through version
820 1.3.x) do not support header crc's, and will report that it is a "multi-part
821 gzip file" and give up.
822
823 If deflateSetHeader is not used, the default gzip header has text false,
824 the time set to zero, and os set to 255, with no extra, name, or comment
825 fields. The gzip header is returned to the default state by deflateReset().
 
826
827 deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
828 stream state was inconsistent.
829 */
830
831 /*
832 ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
833 int windowBits));
834
835 This is another version of inflateInit with an extra parameter. The
836 fields next_in, avail_in, zalloc, zfree and opaque must be initialized
837 before by the caller.
838
@@ -881,13 +883,13 @@
881 next_out and avail_out are unused and unchanged.) The current implementation
882 of inflateInit2() does not process any header information -- that is
883 deferred until inflate() is called.
884 */
885
886 ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
887 const Bytef *dictionary,
888 uInt dictLength));
889 /*
890 Initializes the decompression dictionary from the given uncompressed byte
891 sequence. This function must be called immediately after a call of inflate,
892 if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
893 can be determined from the Adler-32 value returned by that call of inflate.
@@ -904,13 +906,13 @@
904 expected one (incorrect Adler-32 value). inflateSetDictionary does not
905 perform any decompression: this will be done by subsequent calls of
906 inflate().
907 */
908
909 ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm,
910 Bytef *dictionary,
911 uInt *dictLength));
912 /*
913 Returns the sliding dictionary being maintained by inflate. dictLength is
914 set to the number of bytes in the dictionary, and that many bytes are copied
915 to dictionary. dictionary must have enough space, where 32768 bytes is
916 always enough. If inflateGetDictionary() is called with dictionary equal to
@@ -919,11 +921,11 @@
919
920 inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
921 stream state is inconsistent.
922 */
923
924 ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
925 /*
926 Skips invalid compressed data until a possible full flush point (see above
927 for the description of deflate with Z_FULL_FLUSH) can be found, or until all
928 available input is skipped. No output is provided.
929
@@ -938,12 +940,12 @@
938 total_in which indicates where valid compressed data was found. In the
939 error case, the application may repeatedly call inflateSync, providing more
940 input each time, until success or end of the input data.
941 */
942
943 ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
944 z_streamp source));
945 /*
946 Sets the destination stream as a complete copy of the source stream.
947
948 This function can be useful when randomly accessing a large stream. The
949 first pass through the stream can periodically record the inflate state,
@@ -954,22 +956,23 @@
954 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
955 (such as zalloc being Z_NULL). msg is left unchanged in both source and
956 destination.
957 */
958
959 ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
960 /*
961 This function is equivalent to inflateEnd followed by inflateInit,
962 but does not free and reallocate the internal decompression state. The
963 stream will keep attributes that may have been set by inflateInit2.
 
964
965 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
966 stream state was inconsistent (such as zalloc or state being Z_NULL).
967 */
968
969 ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
970 int windowBits));
971 /*
972 This function is the same as inflateReset, but it also permits changing
973 the wrap and window size requests. The windowBits parameter is interpreted
974 the same as it is for inflateInit2. If the window size is changed, then the
975 memory allocated for the window is freed, and the window will be reallocated
@@ -978,13 +981,13 @@
978 inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
979 stream state was inconsistent (such as zalloc or state being Z_NULL), or if
980 the windowBits parameter is invalid.
981 */
982
983 ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
984 int bits,
985 int value));
986 /*
987 This function inserts bits in the inflate input stream. The intent is
988 that this function is used to start inflating at a bit position in the
989 middle of a byte. The provided bits will be used before any bytes are used
990 from next_in. This function should only be used with raw inflate, and
@@ -999,11 +1002,11 @@
999
1000 inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
1001 stream state was inconsistent.
1002 */
1003
1004 ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
1005 /*
1006 This function returns two values, one in the lower 16 bits of the return
1007 value, and the other in the remaining upper bits, obtained by shifting the
1008 return value down 16 bits. If the upper value is -1 and the lower value is
1009 zero, then inflate() is currently decoding information outside of a block.
@@ -1027,12 +1030,12 @@
1027
1028 inflateMark returns the value noted above, or -65536 if the provided
1029 source stream state was inconsistent.
1030 */
1031
1032 ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
1033 gz_headerp head));
1034 /*
1035 inflateGetHeader() requests that gzip header information be stored in the
1036 provided gz_header structure. inflateGetHeader() may be called after
1037 inflateInit2() or inflateReset(), and before the first call of inflate().
1038 As inflate() processes the gzip stream, head->done is zero until the header
@@ -1068,12 +1071,12 @@
1068 inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
1069 stream state was inconsistent.
1070 */
1071
1072 /*
1073 ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
1074 unsigned char FAR *window));
1075
1076 Initialize the internal stream state for decompression using inflateBack()
1077 calls. The fields zalloc, zfree and opaque in strm must be initialized
1078 before the call. If zalloc and zfree are Z_NULL, then the default library-
1079 derived memory allocation routines are used. windowBits is the base two
@@ -1089,17 +1092,17 @@
1089 the parameters are invalid, Z_MEM_ERROR if the internal state could not be
1090 allocated, or Z_VERSION_ERROR if the version of the library does not match
1091 the version of the header file.
1092 */
1093
1094 typedef unsigned (*in_func) OF((void FAR *,
1095 z_const unsigned char FAR * FAR *));
1096 typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
1097
1098 ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
1099 in_func in, void FAR *in_desc,
1100 out_func out, void FAR *out_desc));
1101 /*
1102 inflateBack() does a raw inflate with a single call using a call-back
1103 interface for input and output. This is potentially more efficient than
1104 inflate() for file i/o applications, in that it avoids copying between the
1105 output and the sliding window by simply making the window itself the output
@@ -1163,19 +1166,19 @@
1163 non-zero. (in() will always be called before out(), so strm->next_in is
1164 assured to be defined if out() returns non-zero.) Note that inflateBack()
1165 cannot return Z_OK.
1166 */
1167
1168 ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
1169 /*
1170 All memory allocated by inflateBackInit() is freed.
1171
1172 inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
1173 state was inconsistent.
1174 */
1175
1176 ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
1177 /* Return flags indicating compile-time options.
1178
1179 Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
1180 1.0: size of uInt
1181 3.2: size of uLong
@@ -1224,12 +1227,12 @@
1224 are assumed (compression level and memory usage, standard memory allocation
1225 functions). The source code of these utility functions can be modified if
1226 you need special options.
1227 */
1228
1229 ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
1230 const Bytef *source, uLong sourceLen));
1231 /*
1232 Compresses the source buffer into the destination buffer. sourceLen is
1233 the byte length of the source buffer. Upon entry, destLen is the total size
1234 of the destination buffer, which must be at least the value returned by
1235 compressBound(sourceLen). Upon exit, destLen is the actual size of the
@@ -1239,13 +1242,13 @@
1239 compress returns Z_OK if success, Z_MEM_ERROR if there was not
1240 enough memory, Z_BUF_ERROR if there was not enough room in the output
1241 buffer.
1242 */
1243
1244 ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
1245 const Bytef *source, uLong sourceLen,
1246 int level));
1247 /*
1248 Compresses the source buffer into the destination buffer. The level
1249 parameter has the same meaning as in deflateInit. sourceLen is the byte
1250 length of the source buffer. Upon entry, destLen is the total size of the
1251 destination buffer, which must be at least the value returned by
@@ -1255,19 +1258,19 @@
1255 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1256 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
1257 Z_STREAM_ERROR if the level parameter is invalid.
1258 */
1259
1260 ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
1261 /*
1262 compressBound() returns an upper bound on the compressed size after
1263 compress() or compress2() on sourceLen bytes. It would be used before a
1264 compress() or compress2() call to allocate the destination buffer.
1265 */
1266
1267 ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
1268 const Bytef *source, uLong sourceLen));
1269 /*
1270 Decompresses the source buffer into the destination buffer. sourceLen is
1271 the byte length of the source buffer. Upon entry, destLen is the total size
1272 of the destination buffer, which must be large enough to hold the entire
1273 uncompressed data. (The size of the uncompressed data must have been saved
@@ -1280,12 +1283,12 @@
1280 buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
1281 the case where there is not enough room, uncompress() will fill the output
1282 buffer with the uncompressed data up to that point.
1283 */
1284
1285 ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen,
1286 const Bytef *source, uLong *sourceLen));
1287 /*
1288 Same as uncompress, except that sourceLen is a pointer, where the
1289 length of the source is *sourceLen. On return, *sourceLen is the number of
1290 source bytes consumed.
1291 */
@@ -1300,11 +1303,11 @@
1300 */
1301
1302 typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
1303
1304 /*
1305 ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
1306
1307 Open the gzip (.gz) file at path for reading and decompressing, or
1308 compressing and writing. The mode parameter is as in fopen ("rb" or "wb")
1309 but can also include a compression level ("wb9") or a strategy: 'f' for
1310 filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h",
@@ -1337,11 +1340,11 @@
1337 specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).
1338 errno can be checked to determine if the reason gzopen failed was that the
1339 file could not be opened.
1340 */
1341
1342 ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
1343 /*
1344 Associate a gzFile with the file descriptor fd. File descriptors are
1345 obtained from calls like open, dup, creat, pipe or fileno (if the file has
1346 been previously opened with fopen). The mode parameter is as in gzopen.
1347
@@ -1360,11 +1363,11 @@
1360 provided, or '+' was provided), or if fd is -1. The file descriptor is not
1361 used until the next gz* read, write, seek, or close operation, so gzdopen
1362 will not detect if fd is invalid (unless fd is -1).
1363 */
1364
1365 ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
1366 /*
1367 Set the internal buffer size used by this library's functions for file to
1368 size. The default buffer size is 8192 bytes. This function must be called
1369 after gzopen() or gzdopen(), and before any other calls that read or write
1370 the file. The buffer memory allocation is always deferred to the first read
@@ -1376,11 +1379,11 @@
1376
1377 gzbuffer() returns 0 on success, or -1 on failure, such as being called
1378 too late.
1379 */
1380
1381 ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
1382 /*
1383 Dynamically update the compression level and strategy for file. See the
1384 description of deflateInit2 for the meaning of these parameters. Previously
1385 provided data is flushed before applying the parameter changes.
1386
@@ -1387,11 +1390,11 @@
1387 gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not
1388 opened for writing, Z_ERRNO if there is an error writing the flushed data,
1389 or Z_MEM_ERROR if there is a memory allocation error.
1390 */
1391
1392 ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
1393 /*
1394 Read and decompress up to len uncompressed bytes from file into buf. If
1395 the input file is not in gzip format, gzread copies the given number of
1396 bytes into the buffer directly from the file.
1397
@@ -1417,12 +1420,12 @@
1417 len for end of file, or -1 for error. If len is too large to fit in an int,
1418 then nothing is read, -1 is returned, and the error state is set to
1419 Z_STREAM_ERROR.
1420 */
1421
1422 ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems,
1423 gzFile file));
1424 /*
1425 Read and decompress up to nitems items of size size from file into buf,
1426 otherwise operating as gzread() does. This duplicates the interface of
1427 stdio's fread(), with size_t request and return types. If the library
1428 defines size_t, then z_size_t is identical to size_t. If not, then z_size_t
@@ -1443,18 +1446,18 @@
1443 is the same as the behavior of fread() implementations in common libraries,
1444 but it prevents the direct use of gzfread() to read a concurrently written
1445 file, resetting and retrying on end-of-file, when size is not 1.
1446 */
1447
1448 ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len));
1449 /*
1450 Compress and write the len uncompressed bytes at buf to file. gzwrite
1451 returns the number of uncompressed bytes written or 0 in case of error.
1452 */
1453
1454 ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size,
1455 z_size_t nitems, gzFile file));
1456 /*
1457 Compress and write nitems items of size size from buf to file, duplicating
1458 the interface of stdio's fwrite(), with size_t request and return types. If
1459 the library defines size_t, then z_size_t is identical to size_t. If not,
1460 then z_size_t is an unsigned integer type that can contain a pointer.
@@ -1463,11 +1466,11 @@
1463 if there was an error. If the multiplication of size and nitems overflows,
1464 i.e. the product does not fit in a z_size_t, then nothing is written, zero
1465 is returned, and the error state is set to Z_STREAM_ERROR.
1466 */
1467
1468 ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
1469 /*
1470 Convert, format, compress, and write the arguments (...) to file under
1471 control of the string format, as in fprintf. gzprintf returns the number of
1472 uncompressed bytes actually written, or a negative zlib error code in case
1473 of error. The number of uncompressed bytes written is limited to 8191, or
@@ -1478,19 +1481,19 @@
1478 zlib was compiled with the insecure functions sprintf() or vsprintf(),
1479 because the secure snprintf() or vsnprintf() functions were not available.
1480 This can be determined using zlibCompileFlags().
1481 */
1482
1483 ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
1484 /*
1485 Compress and write the given null-terminated string s to file, excluding
1486 the terminating null character.
1487
1488 gzputs returns the number of characters written, or -1 in case of error.
1489 */
1490
1491 ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
1492 /*
1493 Read and decompress bytes from file into buf, until len-1 characters are
1494 read, or until a newline character is read and transferred to buf, or an
1495 end-of-file condition is encountered. If any characters are read or if len
1496 is one, the string is terminated with a null character. If no characters
@@ -1500,26 +1503,26 @@
1500 gzgets returns buf which is a null-terminated string, or it returns NULL
1501 for end-of-file or in case of error. If there was an error, the contents at
1502 buf are indeterminate.
1503 */
1504
1505 ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
1506 /*
1507 Compress and write c, converted to an unsigned char, into file. gzputc
1508 returns the value that was written, or -1 in case of error.
1509 */
1510
1511 ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
1512 /*
1513 Read and decompress one byte from file. gzgetc returns this byte or -1
1514 in case of end of file or error. This is implemented as a macro for speed.
1515 As such, it does not do all of the checking the other functions do. I.e.
1516 it does not check to see if file is NULL, nor whether the structure file
1517 points to has been clobbered or not.
1518 */
1519
1520 ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
1521 /*
1522 Push c back onto the stream for file to be read as the first character on
1523 the next read. At least one character of push-back is always allowed.
1524 gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
1525 fail if c is -1, and may fail if a character has been pushed but not read
@@ -1527,11 +1530,11 @@
1527 output buffer size of pushed characters is allowed. (See gzbuffer above.)
1528 The pushed character will be discarded if the stream is repositioned with
1529 gzseek() or gzrewind().
1530 */
1531
1532 ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
1533 /*
1534 Flush all pending output to file. The parameter flush is as in the
1535 deflate() function. The return value is the zlib error number (see function
1536 gzerror below). gzflush is only permitted when writing.
1537
@@ -1543,12 +1546,12 @@
1543 gzflush should be called only when strictly necessary because it will
1544 degrade compression if called too often.
1545 */
1546
1547 /*
1548 ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
1549 z_off_t offset, int whence));
1550
1551 Set the starting position to offset relative to whence for the next gzread
1552 or gzwrite on file. The offset represents a number of bytes in the
1553 uncompressed data stream. The whence parameter is defined as in lseek(2);
1554 the value SEEK_END is not supported.
@@ -1562,19 +1565,19 @@
1562 the beginning of the uncompressed stream, or -1 in case of error, in
1563 particular if the file is opened for writing and the new starting position
1564 would be before the current position.
1565 */
1566
1567 ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
1568 /*
1569 Rewind file. This function is supported only for reading.
1570
1571 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET).
1572 */
1573
1574 /*
1575 ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
1576
1577 Return the starting position for the next gzread or gzwrite on file.
1578 This position represents a number of bytes in the uncompressed data stream,
1579 and is zero when starting, even if appending or reading a gzip stream from
1580 the middle of a file using gzdopen().
@@ -1581,20 +1584,20 @@
1581
1582 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
1583 */
1584
1585 /*
1586 ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
1587
1588 Return the current compressed (actual) read or write offset of file. This
1589 offset includes the count of bytes that precede the gzip stream, for example
1590 when appending or when using gzdopen() for reading. When reading, the
1591 offset does not include as yet unused buffered input. This information can
1592 be used for a progress indicator. On error, gzoffset() returns -1.
1593 */
1594
1595 ZEXTERN int ZEXPORT gzeof OF((gzFile file));
1596 /*
1597 Return true (1) if the end-of-file indicator for file has been set while
1598 reading, false (0) otherwise. Note that the end-of-file indicator is set
1599 only if the read tried to go past the end of the input, but came up short.
1600 Therefore, just like feof(), gzeof() may return false even if there is no
@@ -1605,11 +1608,11 @@
1605 If gzeof() returns true, then the read functions will return no more data,
1606 unless the end-of-file indicator is reset by gzclearerr() and the input file
1607 has grown since the previous end of file was detected.
1608 */
1609
1610 ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
1611 /*
1612 Return true (1) if file is being copied directly while reading, or false
1613 (0) if file is a gzip stream being decompressed.
1614
1615 If the input file is empty, gzdirect() will return true, since the input
@@ -1626,11 +1629,11 @@
1626 explicitly requested, so the application already knows the answer. When
1627 linking statically, using gzdirect() will include all of the zlib code for
1628 gzip file reading and decompression, which may not be desired.)
1629 */
1630
1631 ZEXTERN int ZEXPORT gzclose OF((gzFile file));
1632 /*
1633 Flush all pending output for file, if necessary, close file and
1634 deallocate the (de)compression state. Note that once file is closed, you
1635 cannot call gzerror with file, since its structures have been deallocated.
1636 gzclose must not be called more than once on the same file, just as free
@@ -1639,12 +1642,12 @@
1639 gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
1640 file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
1641 last read ended in the middle of a gzip stream, or Z_OK on success.
1642 */
1643
1644 ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
1645 ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
1646 /*
1647 Same as gzclose(), but gzclose_r() is only for use when reading, and
1648 gzclose_w() is only for use when writing or appending. The advantage to
1649 using these instead of gzclose() is that they avoid linking in zlib
1650 compression or decompression code that is not used when only reading or only
@@ -1651,11 +1654,11 @@
1651 writing respectively. If gzclose() is used, then both compression and
1652 decompression code will be included the application when linking to a static
1653 zlib library.
1654 */
1655
1656 ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1657 /*
1658 Return the error message for the last error which occurred on file.
1659 errnum is set to zlib error number. If an error occurred in the file system
1660 and not in the compression library, errnum is set to Z_ERRNO and the
1661 application may consult errno to get the exact error code.
@@ -1667,11 +1670,11 @@
1667
1668 gzerror() should be used to distinguish errors from end-of-file for those
1669 functions above that do not distinguish those cases in their return values.
1670 */
1671
1672 ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1673 /*
1674 Clear the error and end-of-file flags for file. This is analogous to the
1675 clearerr() function in stdio. This is useful for continuing to read a gzip
1676 file that is being written concurrently.
1677 */
@@ -1684,11 +1687,11 @@
1684 These functions are not related to compression but are exported
1685 anyway because they might be useful in applications using the compression
1686 library.
1687 */
1688
1689 ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
1690 /*
1691 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1692 return the updated checksum. An Adler-32 value is in the range of a 32-bit
1693 unsigned integer. If buf is Z_NULL, this function returns the required
1694 initial value for the checksum.
@@ -1704,29 +1707,29 @@
1704 adler = adler32(adler, buffer, length);
1705 }
1706 if (adler != original_adler) error();
1707 */
1708
1709 ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf,
1710 z_size_t len));
1711 /*
1712 Same as adler32(), but with a size_t length.
1713 */
1714
1715 /*
1716 ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
1717 z_off_t len2));
1718
1719 Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
1720 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
1721 each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
1722 seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
1723 that the z_off_t type (like off_t) is a signed integer. If len2 is
1724 negative, the result has no meaning or utility.
1725 */
1726
1727 ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
1728 /*
1729 Update a running CRC-32 with the bytes buf[0..len-1] and return the
1730 updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer.
1731 If buf is Z_NULL, this function returns the required initial value for the
1732 crc. Pre- and post-conditioning (one's complement) is performed within this
@@ -1740,34 +1743,34 @@
1740 crc = crc32(crc, buffer, length);
1741 }
1742 if (crc != original_crc) error();
1743 */
1744
1745 ZEXTERN uLong ZEXPORT crc32_z OF((uLong crc, const Bytef *buf,
1746 z_size_t len));
1747 /*
1748 Same as crc32(), but with a size_t length.
1749 */
1750
1751 /*
1752 ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
1753
1754 Combine two CRC-32 check values into one. For two sequences of bytes,
1755 seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
1756 calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
1757 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
1758 len2.
1759 */
1760
1761 /*
1762 ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2));
1763
1764 Return the operator corresponding to length len2, to be used with
1765 crc32_combine_op().
1766 */
1767
1768 ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op));
1769 /*
1770 Give the same result as crc32_combine(), using op in place of len2. op is
1771 is generated from len2 by crc32_combine_gen(). This will be faster than
1772 crc32_combine() if the generated op is used more than once.
1773 */
@@ -1776,24 +1779,24 @@
1776 /* various hacks, don't look :) */
1777
1778 /* deflateInit and inflateInit are macros to allow checking the zlib version
1779 * and the compiler's view of z_stream:
1780 */
1781 ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
1782 const char *version, int stream_size));
1783 ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
1784 const char *version, int stream_size));
1785 ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
1786 int windowBits, int memLevel,
1787 int strategy, const char *version,
1788 int stream_size));
1789 ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
1790 const char *version, int stream_size));
1791 ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
1792 unsigned char FAR *window,
1793 const char *version,
1794 int stream_size));
1795 #ifdef Z_PREFIX_SET
1796 # define z_deflateInit(strm, level) \
1797 deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
1798 # define z_inflateInit(strm) \
1799 inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
@@ -1834,11 +1837,11 @@
1834 struct gzFile_s {
1835 unsigned have;
1836 unsigned char *next;
1837 z_off64_t pos;
1838 };
1839 ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
1840 #ifdef Z_PREFIX_SET
1841 # undef z_gzgetc
1842 # define z_gzgetc(g) \
1843 ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
1844 #else
@@ -1851,17 +1854,17 @@
1851 * both are true, the application gets the *64 functions, and the regular
1852 * functions are changed to 64 bits) -- in case these are set on systems
1853 * without large file support, _LFS64_LARGEFILE must also be true
1854 */
1855 #ifdef Z_LARGE64
1856 ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
1857 ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
1858 ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
1859 ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
1860 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t));
1861 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
1862 ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t));
1863 #endif
1864
1865 #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
1866 # ifdef Z_PREFIX_SET
1867 # define z_gzopen z_gzopen64
@@ -1879,57 +1882,57 @@
1879 # define adler32_combine adler32_combine64
1880 # define crc32_combine crc32_combine64
1881 # define crc32_combine_gen crc32_combine_gen64
1882 # endif
1883 # ifndef Z_LARGE64
1884 ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
1885 ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
1886 ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
1887 ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
1888 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
1889 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
1890 ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t));
1891 # endif
1892 #else
1893 ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
1894 ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
1895 ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
1896 ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
1897 ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
1898 ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
1899 ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t));
1900 #endif
1901
1902 #else /* Z_SOLO */
1903
1904 ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
1905 ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
1906 ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t));
1907
1908 #endif /* !Z_SOLO */
1909
1910 /* undocumented functions */
1911 ZEXTERN const char * ZEXPORT zError OF((int));
1912 ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
1913 ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
1914 ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
1915 ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int));
1916 ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF((z_streamp));
1917 ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
1918 ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
1919 #if defined(_WIN32) && !defined(Z_SOLO)
1920 ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
1921 const char *mode));
1922 #endif
1923 #if defined(STDC) || defined(Z_HAVE_STDARG_H)
1924 # ifndef Z_SOLO
1925 ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file,
1926 const char *format,
1927 va_list va));
1928 # endif
1929 #endif
1930
1931 #ifdef __cplusplus
1932 }
1933 #endif
1934
1935 #endif /* ZLIB_H */
1936
1937 ELETED compat/zlib/zlib2ansi
--- compat/zlib/zlib.h
+++ compat/zlib/zlib.h
@@ -1,9 +1,9 @@
1 /* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 1.3, August 18th, 2023
3
4 Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler
5
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
9
@@ -35,15 +35,15 @@
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 #define ZLIB_VERSION "1.3"
41 #define ZLIB_VERNUM 0x1300
42 #define ZLIB_VER_MAJOR 1
43 #define ZLIB_VER_MINOR 3
44 #define ZLIB_VER_REVISION 0
45 #define ZLIB_VER_SUBREVISION 0
46
47 /*
48 The 'zlib' compression library provides in-memory compression and
49 decompression functions, including integrity checks of the uncompressed data.
@@ -76,12 +76,12 @@
76 The library does not install any signal handler. The decoder checks
77 the consistency of the compressed data, so the library should never crash
78 even in the case of corrupted input.
79 */
80
81 typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size);
82 typedef void (*free_func)(voidpf opaque, voidpf address);
83
84 struct internal_state;
85
86 typedef struct z_stream_s {
87 z_const Bytef *next_in; /* next input byte */
@@ -215,24 +215,24 @@
215 /* for compatibility with versions < 1.0.2 */
216
217
218 /* basic functions */
219
220 ZEXTERN const char * ZEXPORT zlibVersion(void);
221 /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
222 If the first character differs, the library code actually used is not
223 compatible with the zlib.h header file used by the application. This check
224 is automatically made by deflateInit and inflateInit.
225 */
226
227 /*
228 ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level);
229
230 Initializes the internal stream state for compression. The fields
231 zalloc, zfree and opaque must be initialized before by the caller. If
232 zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
233 allocation functions. total_in, total_out, adler, and msg are initialized.
234
235 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
236 1 gives best speed, 9 gives best compression, 0 gives no compression at all
237 (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION
238 requests a default compromise between speed and compression (currently
@@ -245,11 +245,11 @@
245 if there is no error message. deflateInit does not perform any compression:
246 this will be done by deflate().
247 */
248
249
250 ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush);
251 /*
252 deflate compresses as much data as possible, and stops when the input
253 buffer becomes empty or the output buffer becomes full. It may introduce
254 some output latency (reading input without producing any output) except when
255 forced to flush.
@@ -318,12 +318,12 @@
318
319 If deflate returns with avail_out == 0, this function must be called again
320 with the same value of the flush parameter and more output space (updated
321 avail_out), until the flush is complete (deflate returns with non-zero
322 avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
323 avail_out is greater than six when the flush marker begins, in order to avoid
324 repeated flush markers upon calling deflate() again when avail_out == 0.
325
326 If the parameter flush is set to Z_FINISH, pending input is processed,
327 pending output is flushed and deflate returns with Z_STREAM_END if there was
328 enough output space. If deflate returns with Z_OK or Z_BUF_ERROR, this
329 function must be called again with Z_FINISH and more output space (updated
@@ -358,11 +358,11 @@
358 deflate() can be called again with more input and more output space to
359 continue compressing.
360 */
361
362
363 ZEXTERN int ZEXPORT deflateEnd(z_streamp strm);
364 /*
365 All dynamically allocated data structures for this stream are freed.
366 This function discards any unprocessed input and does not flush any pending
367 output.
368
@@ -373,19 +373,20 @@
373 deallocated).
374 */
375
376
377 /*
378 ZEXTERN int ZEXPORT inflateInit(z_streamp strm);
379
380 Initializes the internal stream state for decompression. The fields
381 next_in, avail_in, zalloc, zfree and opaque must be initialized before by
382 the caller. In the current version of inflate, the provided input is not
383 read or consumed. The allocation of a sliding window will be deferred to
384 the first call of inflate (if the decompression does not complete on the
385 first call). If zalloc and zfree are set to Z_NULL, inflateInit updates
386 them to use default allocation functions. total_in, total_out, adler, and
387 msg are initialized.
388
389 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
390 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
391 version assumed by the caller, or Z_STREAM_ERROR if the parameters are
392 invalid, such as a null pointer to the structure. msg is set to null if
@@ -395,11 +396,11 @@
396 implementation of inflateInit() does not process any header information --
397 that is deferred until inflate() is called.
398 */
399
400
401 ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush);
402 /*
403 inflate decompresses as much data as possible, and stops when the input
404 buffer becomes empty or the output buffer becomes full. It may introduce
405 some output latency (reading input without producing any output) except when
406 forced to flush.
@@ -515,11 +516,11 @@
516 then call inflateSync() to look for a good compression block if a partial
517 recovery of the data is to be attempted.
518 */
519
520
521 ZEXTERN int ZEXPORT inflateEnd(z_streamp strm);
522 /*
523 All dynamically allocated data structures for this stream are freed.
524 This function discards any unprocessed input and does not flush any pending
525 output.
526
@@ -533,16 +534,16 @@
534 /*
535 The following functions are needed only in some special applications.
536 */
537
538 /*
539 ZEXTERN int ZEXPORT deflateInit2(z_streamp strm,
540 int level,
541 int method,
542 int windowBits,
543 int memLevel,
544 int strategy);
545
546 This is another version of deflateInit with more compression options. The
547 fields zalloc, zfree and opaque must be initialized before by the caller.
548
549 The method parameter is the compression method. It must be Z_DEFLATED in
@@ -605,13 +606,13 @@
606 incompatible with the version assumed by the caller (ZLIB_VERSION). msg is
607 set to null if there is no error message. deflateInit2 does not perform any
608 compression: this will be done by deflate().
609 */
610
611 ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm,
612 const Bytef *dictionary,
613 uInt dictLength);
614 /*
615 Initializes the compression dictionary from the given byte sequence
616 without producing any compressed output. When using the zlib format, this
617 function must be called immediately after deflateInit, deflateInit2 or
618 deflateReset, and before any call of deflate. When doing raw deflate, this
@@ -649,13 +650,13 @@
650 inconsistent (for example if deflate has already been called for this stream
651 or if not at a block boundary for raw deflate). deflateSetDictionary does
652 not perform any compression: this will be done by deflate().
653 */
654
655 ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm,
656 Bytef *dictionary,
657 uInt *dictLength);
658 /*
659 Returns the sliding dictionary being maintained by deflate. dictLength is
660 set to the number of bytes in the dictionary, and that many bytes are copied
661 to dictionary. dictionary must have enough space, where 32768 bytes is
662 always enough. If deflateGetDictionary() is called with dictionary equal to
@@ -671,12 +672,12 @@
672
673 deflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
674 stream state is inconsistent.
675 */
676
677 ZEXTERN int ZEXPORT deflateCopy(z_streamp dest,
678 z_streamp source);
679 /*
680 Sets the destination stream as a complete copy of the source stream.
681
682 This function can be useful when several compression strategies will be
683 tried, for example when there are several ways of pre-processing the input
@@ -689,24 +690,24 @@
690 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
691 (such as zalloc being Z_NULL). msg is left unchanged in both source and
692 destination.
693 */
694
695 ZEXTERN int ZEXPORT deflateReset(z_streamp strm);
696 /*
697 This function is equivalent to deflateEnd followed by deflateInit, but
698 does not free and reallocate the internal compression state. The stream
699 will leave the compression level and any other attributes that may have been
700 set unchanged. total_in, total_out, adler, and msg are initialized.
701
702 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
703 stream state was inconsistent (such as zalloc or state being Z_NULL).
704 */
705
706 ZEXTERN int ZEXPORT deflateParams(z_streamp strm,
707 int level,
708 int strategy);
709 /*
710 Dynamically update the compression level and compression strategy. The
711 interpretation of level and strategy is as in deflateInit2(). This can be
712 used to switch between compression and straight copy of the input data, or
713 to switch to a different kind of input data requiring a different strategy.
@@ -727,11 +728,11 @@
728 deflate stream should be flushed using deflate() with Z_BLOCK or other flush
729 request until strm.avail_out is not zero, before calling deflateParams().
730 Then no more input data should be provided before the deflateParams() call.
731 If this is done, the old level and strategy will be applied to the data
732 compressed before deflateParams(), and the new level and strategy will be
733 applied to the data compressed after deflateParams().
734
735 deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
736 state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
737 there was not enough output space to complete the compression of the
738 available input data before a change in the strategy or approach. Note that
@@ -738,15 +739,15 @@
739 in the case of a Z_BUF_ERROR, the parameters are not changed. A return
740 value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be
741 retried with more output space.
742 */
743
744 ZEXTERN int ZEXPORT deflateTune(z_streamp strm,
745 int good_length,
746 int max_lazy,
747 int nice_length,
748 int max_chain);
749 /*
750 Fine tune deflate's internal compression parameters. This should only be
751 used by someone who understands the algorithm used by zlib's deflate for
752 searching for the best matching string, and even then only by the most
753 fanatic optimizer trying to squeeze out the last compressed bit for their
@@ -755,12 +756,12 @@
756
757 deflateTune() can be called after deflateInit() or deflateInit2(), and
758 returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
759 */
760
761 ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm,
762 uLong sourceLen);
763 /*
764 deflateBound() returns an upper bound on the compressed size after
765 deflation of sourceLen bytes. It must be called after deflateInit() or
766 deflateInit2(), and after deflateSetHeader(), if used. This would be used
767 to allocate an output buffer for deflation in a single pass, and so would be
@@ -770,13 +771,13 @@
771 to return Z_STREAM_END. Note that it is possible for the compressed size to
772 be larger than the value returned by deflateBound() if flush options other
773 than Z_FINISH or Z_NO_FLUSH are used.
774 */
775
776 ZEXTERN int ZEXPORT deflatePending(z_streamp strm,
777 unsigned *pending,
778 int *bits);
779 /*
780 deflatePending() returns the number of bytes and bits of output that have
781 been generated, but not yet provided in the available output. The bytes not
782 provided would be due to the available output space having being consumed.
783 The number of bits of output not provided are between 0 and 7, where they
@@ -785,13 +786,13 @@
786
787 deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
788 stream state was inconsistent.
789 */
790
791 ZEXTERN int ZEXPORT deflatePrime(z_streamp strm,
792 int bits,
793 int value);
794 /*
795 deflatePrime() inserts bits in the deflate output stream. The intent
796 is that this function is used to start off the deflate output with the bits
797 leftover from a previous deflate stream when appending to it. As such, this
798 function can only be used for raw deflate, and must be used before the first
@@ -802,12 +803,12 @@
803 deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
804 room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
805 source stream state was inconsistent.
806 */
807
808 ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm,
809 gz_headerp head);
810 /*
811 deflateSetHeader() provides gzip header information for when a gzip
812 stream is requested by deflateInit2(). deflateSetHeader() may be called
813 after deflateInit2() or deflateReset() and before the first call of
814 deflate(). The text, time, os, extra field, name, and comment information
@@ -819,20 +820,21 @@
820 the current versions of the command-line version of gzip (up through version
821 1.3.x) do not support header crc's, and will report that it is a "multi-part
822 gzip file" and give up.
823
824 If deflateSetHeader is not used, the default gzip header has text false,
825 the time set to zero, and os set to the current operating system, with no
826 extra, name, or comment fields. The gzip header is returned to the default
827 state by deflateReset().
828
829 deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
830 stream state was inconsistent.
831 */
832
833 /*
834 ZEXTERN int ZEXPORT inflateInit2(z_streamp strm,
835 int windowBits);
836
837 This is another version of inflateInit with an extra parameter. The
838 fields next_in, avail_in, zalloc, zfree and opaque must be initialized
839 before by the caller.
840
@@ -881,13 +883,13 @@
883 next_out and avail_out are unused and unchanged.) The current implementation
884 of inflateInit2() does not process any header information -- that is
885 deferred until inflate() is called.
886 */
887
888 ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm,
889 const Bytef *dictionary,
890 uInt dictLength);
891 /*
892 Initializes the decompression dictionary from the given uncompressed byte
893 sequence. This function must be called immediately after a call of inflate,
894 if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
895 can be determined from the Adler-32 value returned by that call of inflate.
@@ -904,13 +906,13 @@
906 expected one (incorrect Adler-32 value). inflateSetDictionary does not
907 perform any decompression: this will be done by subsequent calls of
908 inflate().
909 */
910
911 ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm,
912 Bytef *dictionary,
913 uInt *dictLength);
914 /*
915 Returns the sliding dictionary being maintained by inflate. dictLength is
916 set to the number of bytes in the dictionary, and that many bytes are copied
917 to dictionary. dictionary must have enough space, where 32768 bytes is
918 always enough. If inflateGetDictionary() is called with dictionary equal to
@@ -919,11 +921,11 @@
921
922 inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
923 stream state is inconsistent.
924 */
925
926 ZEXTERN int ZEXPORT inflateSync(z_streamp strm);
927 /*
928 Skips invalid compressed data until a possible full flush point (see above
929 for the description of deflate with Z_FULL_FLUSH) can be found, or until all
930 available input is skipped. No output is provided.
931
@@ -938,12 +940,12 @@
940 total_in which indicates where valid compressed data was found. In the
941 error case, the application may repeatedly call inflateSync, providing more
942 input each time, until success or end of the input data.
943 */
944
945 ZEXTERN int ZEXPORT inflateCopy(z_streamp dest,
946 z_streamp source);
947 /*
948 Sets the destination stream as a complete copy of the source stream.
949
950 This function can be useful when randomly accessing a large stream. The
951 first pass through the stream can periodically record the inflate state,
@@ -954,22 +956,23 @@
956 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
957 (such as zalloc being Z_NULL). msg is left unchanged in both source and
958 destination.
959 */
960
961 ZEXTERN int ZEXPORT inflateReset(z_streamp strm);
962 /*
963 This function is equivalent to inflateEnd followed by inflateInit,
964 but does not free and reallocate the internal decompression state. The
965 stream will keep attributes that may have been set by inflateInit2.
966 total_in, total_out, adler, and msg are initialized.
967
968 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
969 stream state was inconsistent (such as zalloc or state being Z_NULL).
970 */
971
972 ZEXTERN int ZEXPORT inflateReset2(z_streamp strm,
973 int windowBits);
974 /*
975 This function is the same as inflateReset, but it also permits changing
976 the wrap and window size requests. The windowBits parameter is interpreted
977 the same as it is for inflateInit2. If the window size is changed, then the
978 memory allocated for the window is freed, and the window will be reallocated
@@ -978,13 +981,13 @@
981 inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
982 stream state was inconsistent (such as zalloc or state being Z_NULL), or if
983 the windowBits parameter is invalid.
984 */
985
986 ZEXTERN int ZEXPORT inflatePrime(z_streamp strm,
987 int bits,
988 int value);
989 /*
990 This function inserts bits in the inflate input stream. The intent is
991 that this function is used to start inflating at a bit position in the
992 middle of a byte. The provided bits will be used before any bytes are used
993 from next_in. This function should only be used with raw inflate, and
@@ -999,11 +1002,11 @@
1002
1003 inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
1004 stream state was inconsistent.
1005 */
1006
1007 ZEXTERN long ZEXPORT inflateMark(z_streamp strm);
1008 /*
1009 This function returns two values, one in the lower 16 bits of the return
1010 value, and the other in the remaining upper bits, obtained by shifting the
1011 return value down 16 bits. If the upper value is -1 and the lower value is
1012 zero, then inflate() is currently decoding information outside of a block.
@@ -1027,12 +1030,12 @@
1030
1031 inflateMark returns the value noted above, or -65536 if the provided
1032 source stream state was inconsistent.
1033 */
1034
1035 ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm,
1036 gz_headerp head);
1037 /*
1038 inflateGetHeader() requests that gzip header information be stored in the
1039 provided gz_header structure. inflateGetHeader() may be called after
1040 inflateInit2() or inflateReset(), and before the first call of inflate().
1041 As inflate() processes the gzip stream, head->done is zero until the header
@@ -1068,12 +1071,12 @@
1071 inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
1072 stream state was inconsistent.
1073 */
1074
1075 /*
1076 ZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits,
1077 unsigned char FAR *window);
1078
1079 Initialize the internal stream state for decompression using inflateBack()
1080 calls. The fields zalloc, zfree and opaque in strm must be initialized
1081 before the call. If zalloc and zfree are Z_NULL, then the default library-
1082 derived memory allocation routines are used. windowBits is the base two
@@ -1089,17 +1092,17 @@
1092 the parameters are invalid, Z_MEM_ERROR if the internal state could not be
1093 allocated, or Z_VERSION_ERROR if the version of the library does not match
1094 the version of the header file.
1095 */
1096
1097 typedef unsigned (*in_func)(void FAR *,
1098 z_const unsigned char FAR * FAR *);
1099 typedef int (*out_func)(void FAR *, unsigned char FAR *, unsigned);
1100
1101 ZEXTERN int ZEXPORT inflateBack(z_streamp strm,
1102 in_func in, void FAR *in_desc,
1103 out_func out, void FAR *out_desc);
1104 /*
1105 inflateBack() does a raw inflate with a single call using a call-back
1106 interface for input and output. This is potentially more efficient than
1107 inflate() for file i/o applications, in that it avoids copying between the
1108 output and the sliding window by simply making the window itself the output
@@ -1163,19 +1166,19 @@
1166 non-zero. (in() will always be called before out(), so strm->next_in is
1167 assured to be defined if out() returns non-zero.) Note that inflateBack()
1168 cannot return Z_OK.
1169 */
1170
1171 ZEXTERN int ZEXPORT inflateBackEnd(z_streamp strm);
1172 /*
1173 All memory allocated by inflateBackInit() is freed.
1174
1175 inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
1176 state was inconsistent.
1177 */
1178
1179 ZEXTERN uLong ZEXPORT zlibCompileFlags(void);
1180 /* Return flags indicating compile-time options.
1181
1182 Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
1183 1.0: size of uInt
1184 3.2: size of uLong
@@ -1224,12 +1227,12 @@
1227 are assumed (compression level and memory usage, standard memory allocation
1228 functions). The source code of these utility functions can be modified if
1229 you need special options.
1230 */
1231
1232 ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen,
1233 const Bytef *source, uLong sourceLen);
1234 /*
1235 Compresses the source buffer into the destination buffer. sourceLen is
1236 the byte length of the source buffer. Upon entry, destLen is the total size
1237 of the destination buffer, which must be at least the value returned by
1238 compressBound(sourceLen). Upon exit, destLen is the actual size of the
@@ -1239,13 +1242,13 @@
1242 compress returns Z_OK if success, Z_MEM_ERROR if there was not
1243 enough memory, Z_BUF_ERROR if there was not enough room in the output
1244 buffer.
1245 */
1246
1247 ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen,
1248 const Bytef *source, uLong sourceLen,
1249 int level);
1250 /*
1251 Compresses the source buffer into the destination buffer. The level
1252 parameter has the same meaning as in deflateInit. sourceLen is the byte
1253 length of the source buffer. Upon entry, destLen is the total size of the
1254 destination buffer, which must be at least the value returned by
@@ -1255,19 +1258,19 @@
1258 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1259 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
1260 Z_STREAM_ERROR if the level parameter is invalid.
1261 */
1262
1263 ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen);
1264 /*
1265 compressBound() returns an upper bound on the compressed size after
1266 compress() or compress2() on sourceLen bytes. It would be used before a
1267 compress() or compress2() call to allocate the destination buffer.
1268 */
1269
1270 ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen,
1271 const Bytef *source, uLong sourceLen);
1272 /*
1273 Decompresses the source buffer into the destination buffer. sourceLen is
1274 the byte length of the source buffer. Upon entry, destLen is the total size
1275 of the destination buffer, which must be large enough to hold the entire
1276 uncompressed data. (The size of the uncompressed data must have been saved
@@ -1280,12 +1283,12 @@
1283 buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
1284 the case where there is not enough room, uncompress() will fill the output
1285 buffer with the uncompressed data up to that point.
1286 */
1287
1288 ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen,
1289 const Bytef *source, uLong *sourceLen);
1290 /*
1291 Same as uncompress, except that sourceLen is a pointer, where the
1292 length of the source is *sourceLen. On return, *sourceLen is the number of
1293 source bytes consumed.
1294 */
@@ -1300,11 +1303,11 @@
1303 */
1304
1305 typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
1306
1307 /*
1308 ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode);
1309
1310 Open the gzip (.gz) file at path for reading and decompressing, or
1311 compressing and writing. The mode parameter is as in fopen ("rb" or "wb")
1312 but can also include a compression level ("wb9") or a strategy: 'f' for
1313 filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h",
@@ -1337,11 +1340,11 @@
1340 specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).
1341 errno can be checked to determine if the reason gzopen failed was that the
1342 file could not be opened.
1343 */
1344
1345 ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode);
1346 /*
1347 Associate a gzFile with the file descriptor fd. File descriptors are
1348 obtained from calls like open, dup, creat, pipe or fileno (if the file has
1349 been previously opened with fopen). The mode parameter is as in gzopen.
1350
@@ -1360,11 +1363,11 @@
1363 provided, or '+' was provided), or if fd is -1. The file descriptor is not
1364 used until the next gz* read, write, seek, or close operation, so gzdopen
1365 will not detect if fd is invalid (unless fd is -1).
1366 */
1367
1368 ZEXTERN int ZEXPORT gzbuffer(gzFile file, unsigned size);
1369 /*
1370 Set the internal buffer size used by this library's functions for file to
1371 size. The default buffer size is 8192 bytes. This function must be called
1372 after gzopen() or gzdopen(), and before any other calls that read or write
1373 the file. The buffer memory allocation is always deferred to the first read
@@ -1376,11 +1379,11 @@
1379
1380 gzbuffer() returns 0 on success, or -1 on failure, such as being called
1381 too late.
1382 */
1383
1384 ZEXTERN int ZEXPORT gzsetparams(gzFile file, int level, int strategy);
1385 /*
1386 Dynamically update the compression level and strategy for file. See the
1387 description of deflateInit2 for the meaning of these parameters. Previously
1388 provided data is flushed before applying the parameter changes.
1389
@@ -1387,11 +1390,11 @@
1390 gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not
1391 opened for writing, Z_ERRNO if there is an error writing the flushed data,
1392 or Z_MEM_ERROR if there is a memory allocation error.
1393 */
1394
1395 ZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len);
1396 /*
1397 Read and decompress up to len uncompressed bytes from file into buf. If
1398 the input file is not in gzip format, gzread copies the given number of
1399 bytes into the buffer directly from the file.
1400
@@ -1417,12 +1420,12 @@
1420 len for end of file, or -1 for error. If len is too large to fit in an int,
1421 then nothing is read, -1 is returned, and the error state is set to
1422 Z_STREAM_ERROR.
1423 */
1424
1425 ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems,
1426 gzFile file);
1427 /*
1428 Read and decompress up to nitems items of size size from file into buf,
1429 otherwise operating as gzread() does. This duplicates the interface of
1430 stdio's fread(), with size_t request and return types. If the library
1431 defines size_t, then z_size_t is identical to size_t. If not, then z_size_t
@@ -1443,18 +1446,18 @@
1446 is the same as the behavior of fread() implementations in common libraries,
1447 but it prevents the direct use of gzfread() to read a concurrently written
1448 file, resetting and retrying on end-of-file, when size is not 1.
1449 */
1450
1451 ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len);
1452 /*
1453 Compress and write the len uncompressed bytes at buf to file. gzwrite
1454 returns the number of uncompressed bytes written or 0 in case of error.
1455 */
1456
1457 ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size,
1458 z_size_t nitems, gzFile file);
1459 /*
1460 Compress and write nitems items of size size from buf to file, duplicating
1461 the interface of stdio's fwrite(), with size_t request and return types. If
1462 the library defines size_t, then z_size_t is identical to size_t. If not,
1463 then z_size_t is an unsigned integer type that can contain a pointer.
@@ -1463,11 +1466,11 @@
1466 if there was an error. If the multiplication of size and nitems overflows,
1467 i.e. the product does not fit in a z_size_t, then nothing is written, zero
1468 is returned, and the error state is set to Z_STREAM_ERROR.
1469 */
1470
1471 ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...);
1472 /*
1473 Convert, format, compress, and write the arguments (...) to file under
1474 control of the string format, as in fprintf. gzprintf returns the number of
1475 uncompressed bytes actually written, or a negative zlib error code in case
1476 of error. The number of uncompressed bytes written is limited to 8191, or
@@ -1478,19 +1481,19 @@
1481 zlib was compiled with the insecure functions sprintf() or vsprintf(),
1482 because the secure snprintf() or vsnprintf() functions were not available.
1483 This can be determined using zlibCompileFlags().
1484 */
1485
1486 ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s);
1487 /*
1488 Compress and write the given null-terminated string s to file, excluding
1489 the terminating null character.
1490
1491 gzputs returns the number of characters written, or -1 in case of error.
1492 */
1493
1494 ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len);
1495 /*
1496 Read and decompress bytes from file into buf, until len-1 characters are
1497 read, or until a newline character is read and transferred to buf, or an
1498 end-of-file condition is encountered. If any characters are read or if len
1499 is one, the string is terminated with a null character. If no characters
@@ -1500,26 +1503,26 @@
1503 gzgets returns buf which is a null-terminated string, or it returns NULL
1504 for end-of-file or in case of error. If there was an error, the contents at
1505 buf are indeterminate.
1506 */
1507
1508 ZEXTERN int ZEXPORT gzputc(gzFile file, int c);
1509 /*
1510 Compress and write c, converted to an unsigned char, into file. gzputc
1511 returns the value that was written, or -1 in case of error.
1512 */
1513
1514 ZEXTERN int ZEXPORT gzgetc(gzFile file);
1515 /*
1516 Read and decompress one byte from file. gzgetc returns this byte or -1
1517 in case of end of file or error. This is implemented as a macro for speed.
1518 As such, it does not do all of the checking the other functions do. I.e.
1519 it does not check to see if file is NULL, nor whether the structure file
1520 points to has been clobbered or not.
1521 */
1522
1523 ZEXTERN int ZEXPORT gzungetc(int c, gzFile file);
1524 /*
1525 Push c back onto the stream for file to be read as the first character on
1526 the next read. At least one character of push-back is always allowed.
1527 gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
1528 fail if c is -1, and may fail if a character has been pushed but not read
@@ -1527,11 +1530,11 @@
1530 output buffer size of pushed characters is allowed. (See gzbuffer above.)
1531 The pushed character will be discarded if the stream is repositioned with
1532 gzseek() or gzrewind().
1533 */
1534
1535 ZEXTERN int ZEXPORT gzflush(gzFile file, int flush);
1536 /*
1537 Flush all pending output to file. The parameter flush is as in the
1538 deflate() function. The return value is the zlib error number (see function
1539 gzerror below). gzflush is only permitted when writing.
1540
@@ -1543,12 +1546,12 @@
1546 gzflush should be called only when strictly necessary because it will
1547 degrade compression if called too often.
1548 */
1549
1550 /*
1551 ZEXTERN z_off_t ZEXPORT gzseek(gzFile file,
1552 z_off_t offset, int whence);
1553
1554 Set the starting position to offset relative to whence for the next gzread
1555 or gzwrite on file. The offset represents a number of bytes in the
1556 uncompressed data stream. The whence parameter is defined as in lseek(2);
1557 the value SEEK_END is not supported.
@@ -1562,19 +1565,19 @@
1565 the beginning of the uncompressed stream, or -1 in case of error, in
1566 particular if the file is opened for writing and the new starting position
1567 would be before the current position.
1568 */
1569
1570 ZEXTERN int ZEXPORT gzrewind(gzFile file);
1571 /*
1572 Rewind file. This function is supported only for reading.
1573
1574 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET).
1575 */
1576
1577 /*
1578 ZEXTERN z_off_t ZEXPORT gztell(gzFile file);
1579
1580 Return the starting position for the next gzread or gzwrite on file.
1581 This position represents a number of bytes in the uncompressed data stream,
1582 and is zero when starting, even if appending or reading a gzip stream from
1583 the middle of a file using gzdopen().
@@ -1581,20 +1584,20 @@
1584
1585 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
1586 */
1587
1588 /*
1589 ZEXTERN z_off_t ZEXPORT gzoffset(gzFile file);
1590
1591 Return the current compressed (actual) read or write offset of file. This
1592 offset includes the count of bytes that precede the gzip stream, for example
1593 when appending or when using gzdopen() for reading. When reading, the
1594 offset does not include as yet unused buffered input. This information can
1595 be used for a progress indicator. On error, gzoffset() returns -1.
1596 */
1597
1598 ZEXTERN int ZEXPORT gzeof(gzFile file);
1599 /*
1600 Return true (1) if the end-of-file indicator for file has been set while
1601 reading, false (0) otherwise. Note that the end-of-file indicator is set
1602 only if the read tried to go past the end of the input, but came up short.
1603 Therefore, just like feof(), gzeof() may return false even if there is no
@@ -1605,11 +1608,11 @@
1608 If gzeof() returns true, then the read functions will return no more data,
1609 unless the end-of-file indicator is reset by gzclearerr() and the input file
1610 has grown since the previous end of file was detected.
1611 */
1612
1613 ZEXTERN int ZEXPORT gzdirect(gzFile file);
1614 /*
1615 Return true (1) if file is being copied directly while reading, or false
1616 (0) if file is a gzip stream being decompressed.
1617
1618 If the input file is empty, gzdirect() will return true, since the input
@@ -1626,11 +1629,11 @@
1629 explicitly requested, so the application already knows the answer. When
1630 linking statically, using gzdirect() will include all of the zlib code for
1631 gzip file reading and decompression, which may not be desired.)
1632 */
1633
1634 ZEXTERN int ZEXPORT gzclose(gzFile file);
1635 /*
1636 Flush all pending output for file, if necessary, close file and
1637 deallocate the (de)compression state. Note that once file is closed, you
1638 cannot call gzerror with file, since its structures have been deallocated.
1639 gzclose must not be called more than once on the same file, just as free
@@ -1639,12 +1642,12 @@
1642 gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
1643 file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
1644 last read ended in the middle of a gzip stream, or Z_OK on success.
1645 */
1646
1647 ZEXTERN int ZEXPORT gzclose_r(gzFile file);
1648 ZEXTERN int ZEXPORT gzclose_w(gzFile file);
1649 /*
1650 Same as gzclose(), but gzclose_r() is only for use when reading, and
1651 gzclose_w() is only for use when writing or appending. The advantage to
1652 using these instead of gzclose() is that they avoid linking in zlib
1653 compression or decompression code that is not used when only reading or only
@@ -1651,11 +1654,11 @@
1654 writing respectively. If gzclose() is used, then both compression and
1655 decompression code will be included the application when linking to a static
1656 zlib library.
1657 */
1658
1659 ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum);
1660 /*
1661 Return the error message for the last error which occurred on file.
1662 errnum is set to zlib error number. If an error occurred in the file system
1663 and not in the compression library, errnum is set to Z_ERRNO and the
1664 application may consult errno to get the exact error code.
@@ -1667,11 +1670,11 @@
1670
1671 gzerror() should be used to distinguish errors from end-of-file for those
1672 functions above that do not distinguish those cases in their return values.
1673 */
1674
1675 ZEXTERN void ZEXPORT gzclearerr(gzFile file);
1676 /*
1677 Clear the error and end-of-file flags for file. This is analogous to the
1678 clearerr() function in stdio. This is useful for continuing to read a gzip
1679 file that is being written concurrently.
1680 */
@@ -1684,11 +1687,11 @@
1687 These functions are not related to compression but are exported
1688 anyway because they might be useful in applications using the compression
1689 library.
1690 */
1691
1692 ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len);
1693 /*
1694 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1695 return the updated checksum. An Adler-32 value is in the range of a 32-bit
1696 unsigned integer. If buf is Z_NULL, this function returns the required
1697 initial value for the checksum.
@@ -1704,29 +1707,29 @@
1707 adler = adler32(adler, buffer, length);
1708 }
1709 if (adler != original_adler) error();
1710 */
1711
1712 ZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf,
1713 z_size_t len);
1714 /*
1715 Same as adler32(), but with a size_t length.
1716 */
1717
1718 /*
1719 ZEXTERN uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2,
1720 z_off_t len2);
1721
1722 Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
1723 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
1724 each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
1725 seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
1726 that the z_off_t type (like off_t) is a signed integer. If len2 is
1727 negative, the result has no meaning or utility.
1728 */
1729
1730 ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len);
1731 /*
1732 Update a running CRC-32 with the bytes buf[0..len-1] and return the
1733 updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer.
1734 If buf is Z_NULL, this function returns the required initial value for the
1735 crc. Pre- and post-conditioning (one's complement) is performed within this
@@ -1740,34 +1743,34 @@
1743 crc = crc32(crc, buffer, length);
1744 }
1745 if (crc != original_crc) error();
1746 */
1747
1748 ZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf,
1749 z_size_t len);
1750 /*
1751 Same as crc32(), but with a size_t length.
1752 */
1753
1754 /*
1755 ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2);
1756
1757 Combine two CRC-32 check values into one. For two sequences of bytes,
1758 seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
1759 calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
1760 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
1761 len2.
1762 */
1763
1764 /*
1765 ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2);
1766
1767 Return the operator corresponding to length len2, to be used with
1768 crc32_combine_op().
1769 */
1770
1771 ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op);
1772 /*
1773 Give the same result as crc32_combine(), using op in place of len2. op is
1774 is generated from len2 by crc32_combine_gen(). This will be faster than
1775 crc32_combine() if the generated op is used more than once.
1776 */
@@ -1776,24 +1779,24 @@
1779 /* various hacks, don't look :) */
1780
1781 /* deflateInit and inflateInit are macros to allow checking the zlib version
1782 * and the compiler's view of z_stream:
1783 */
1784 ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level,
1785 const char *version, int stream_size);
1786 ZEXTERN int ZEXPORT inflateInit_(z_streamp strm,
1787 const char *version, int stream_size);
1788 ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
1789 int windowBits, int memLevel,
1790 int strategy, const char *version,
1791 int stream_size);
1792 ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits,
1793 const char *version, int stream_size);
1794 ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
1795 unsigned char FAR *window,
1796 const char *version,
1797 int stream_size);
1798 #ifdef Z_PREFIX_SET
1799 # define z_deflateInit(strm, level) \
1800 deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
1801 # define z_inflateInit(strm) \
1802 inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
@@ -1834,11 +1837,11 @@
1837 struct gzFile_s {
1838 unsigned have;
1839 unsigned char *next;
1840 z_off64_t pos;
1841 };
1842 ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */
1843 #ifdef Z_PREFIX_SET
1844 # undef z_gzgetc
1845 # define z_gzgetc(g) \
1846 ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
1847 #else
@@ -1851,17 +1854,17 @@
1854 * both are true, the application gets the *64 functions, and the regular
1855 * functions are changed to 64 bits) -- in case these are set on systems
1856 * without large file support, _LFS64_LARGEFILE must also be true
1857 */
1858 #ifdef Z_LARGE64
1859 ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
1860 ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
1861 ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
1862 ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
1863 ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t);
1864 ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t);
1865 ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t);
1866 #endif
1867
1868 #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
1869 # ifdef Z_PREFIX_SET
1870 # define z_gzopen z_gzopen64
@@ -1879,57 +1882,57 @@
1882 # define adler32_combine adler32_combine64
1883 # define crc32_combine crc32_combine64
1884 # define crc32_combine_gen crc32_combine_gen64
1885 # endif
1886 # ifndef Z_LARGE64
1887 ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
1888 ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int);
1889 ZEXTERN z_off_t ZEXPORT gztell64(gzFile);
1890 ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile);
1891 ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
1892 ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
1893 ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
1894 # endif
1895 #else
1896 ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *);
1897 ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int);
1898 ZEXTERN z_off_t ZEXPORT gztell(gzFile);
1899 ZEXTERN z_off_t ZEXPORT gzoffset(gzFile);
1900 ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t);
1901 ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t);
1902 ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t);
1903 #endif
1904
1905 #else /* Z_SOLO */
1906
1907 ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t);
1908 ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t);
1909 ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t);
1910
1911 #endif /* !Z_SOLO */
1912
1913 /* undocumented functions */
1914 ZEXTERN const char * ZEXPORT zError(int);
1915 ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp);
1916 ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void);
1917 ZEXTERN int ZEXPORT inflateUndermine(z_streamp, int);
1918 ZEXTERN int ZEXPORT inflateValidate(z_streamp, int);
1919 ZEXTERN unsigned long ZEXPORT inflateCodesUsed(z_streamp);
1920 ZEXTERN int ZEXPORT inflateResetKeep(z_streamp);
1921 ZEXTERN int ZEXPORT deflateResetKeep(z_streamp);
1922 #if defined(_WIN32) && !defined(Z_SOLO)
1923 ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path,
1924 const char *mode);
1925 #endif
1926 #if defined(STDC) || defined(Z_HAVE_STDARG_H)
1927 # ifndef Z_SOLO
1928 ZEXTERN int ZEXPORTVA gzvprintf(gzFile file,
1929 const char *format,
1930 va_list va);
1931 # endif
1932 #endif
1933
1934 #ifdef __cplusplus
1935 }
1936 #endif
1937
1938 #endif /* ZLIB_H */
1939
1940 ELETED compat/zlib/zlib2ansi
D compat/zlib/zlib2ansi
-152
--- a/compat/zlib/zlib2ansi
+++ b/compat/zlib/zlib2ansi
@@ -1,152 +0,0 @@
1
-#!/usr/bin/perl
2
-
3
-# Transform K&R C function definitions into ANSI equivalent.
4
-#
5
-# Author: Paul Marquess
6
-# Version: 1.0
7
-# Date: 3 October 2006
8
-
9
-# TODO
10
-#
11
-# Assumes no function pointer parameters. unless they are typedefed.
12
-# Assumes no literal strings that look like function definitions
13
-# Assumes functions start at the beginning of a line
14
-
15
-use strict;
16
-use warnings;
17
-
18
-local $/;
19
-$_ = <>;
20
-
21
-my $sp = qr{ \s* (?: /\* .*? \*/ )? \s* }x; # assume no nested comments
22
-
23
-my $d1 = qr{ $sp (?: [\w\*\s]+ $sp)* $sp \w+ $sp [\[\]\s]* $sp }x ;
24
-my $decl = qr{ $sp (?: \w+ $sp )+ $d1 }xo ;
25
-my $dList = qr{ $sp $decl (?: $sp , $d1 )* $sp ; $sp }xo ;
26
-
27
-
28
-while (s/^
29
- ( # Start $1
30
- ( # Start $2
31
- .*? # Minimal eat content
32
- ( ^ \w [\w\s\*]+ ) # $3 -- function name
33
- \s* # optional whitespace
34
- ) # $2 - Matched up to before parameter list
35
-
36
- \( \s* # Literal "(" + optional whitespace
37
- ( [^\)]+ ) # $4 - one or more anythings except ")"
38
- \s* \) # optional whitespace surrounding a Literal ")"
39
-
40
- ( (?: $dList )+ ) # $5
41
-
42
- $sp ^ { # literal "{" at start of line
43
- ) # Remember to $1
44
- //xsom
45
- )
46
-{
47
- my $all = $1 ;
48
- my $prefix = $2;
49
- my $param_list = $4 ;
50
- my $params = $5;
51
-
52
- StripComments($params);
53
- StripComments($param_list);
54
- $param_list =~ s/^\s+//;
55
- $param_list =~ s/\s+$//;
56
-
57
- my $i = 0 ;
58
- my %pList = map { $_ => $i++ }
59
- split /\s*,\s*/, $param_list;
60
- my $pMatch = '(\b' . join('|', keys %pList) . '\b)\W*$' ;
61
-
62
- my @params = split /\s*;\s*/, $params;
63
- my @outParams = ();
64
- foreach my $p (@params)
65
- {
66
- if ($p =~ /,/)
67
- {
68
- my @bits = split /\s*,\s*/, $p;
69
- my $first = shift @bits;
70
- $first =~ s/^\s*//;
71
- push @outParams, $first;
72
- $first =~ /^(\w+\s*)/;
73
- my $type = $1 ;
74
- push @outParams, map { $type . $_ } @bits;
75
- }
76
- else
77
- {
78
- $p =~ s/^\s+//;
79
- push @outParams, $p;
80
- }
81
- }
82
-
83
-
84
- my %tmp = map { /$pMatch/; $_ => $pList{$1} }
85
- @outParams ;
86
-
87
- @outParams = map { " $_" }
88
- sort { $tmp{$a} <=> $tmp{$b} }
89
- @outParams ;
90
-
91
- print $prefix ;
92
- print "(\n" . join(",\n", @outParams) . ")\n";
93
- print "{" ;
94
-
95
-}
96
-
97
-# Output any trailing code.
98
-print ;
99
-exit 0;
100
-
101
-
102
-sub StripComments
103
-{
104
-
105
- no warnings;
106
-
107
- # Strip C & C++ comments
108
- # From the perlfaq
109
- $_[0] =~
110
-
111
- s{
112
- /\* ## Start of /* ... */ comment
113
- [^*]*\*+ ## Non-* followed by 1-or-more *'s
114
- (
115
- [^/*][^*]*\*+
116
- )* ## 0-or-more things which don't start with /
117
- ## but do end with '*'
118
- / ## End of /* ... */ comment
119
-
120
- | ## OR C++ Comment
121
- // ## Start of C++ comment //
122
- [^\n]* ## followed by 0-or-more non end of line characters
123
-
124
- | ## OR various things which aren't comments:
125
-
126
- (
127
- " ## Start of " ... " string
128
- (
129
- \\. ## Escaped char
130
- | ## OR
131
- [^"\\] ## Non "\
132
- )*
133
- " ## End of " ... " string
134
-
135
- | ## OR
136
-
137
- ' ## Start of ' ... ' string
138
- (
139
- \\. ## Escaped char
140
- | ## OR
141
- [^'\\] ## Non '\
142
- )*
143
- ' ## End of ' ... ' string
144
-
145
- | ## OR
146
-
147
- . ## Anything other char
148
- [^/"'\\]* ## Chars which doesn't start a comment, string or escape
149
- )
150
- }{$2}gxs;
151
-
152
-}
--- a/compat/zlib/zlib2ansi
+++ b/compat/zlib/zlib2ansi
@@ -1,152 +0,0 @@
1 #!/usr/bin/perl
2
3 # Transform K&R C function definitions into ANSI equivalent.
4 #
5 # Author: Paul Marquess
6 # Version: 1.0
7 # Date: 3 October 2006
8
9 # TODO
10 #
11 # Assumes no function pointer parameters. unless they are typedefed.
12 # Assumes no literal strings that look like function definitions
13 # Assumes functions start at the beginning of a line
14
15 use strict;
16 use warnings;
17
18 local $/;
19 $_ = <>;
20
21 my $sp = qr{ \s* (?: /\* .*? \*/ )? \s* }x; # assume no nested comments
22
23 my $d1 = qr{ $sp (?: [\w\*\s]+ $sp)* $sp \w+ $sp [\[\]\s]* $sp }x ;
24 my $decl = qr{ $sp (?: \w+ $sp )+ $d1 }xo ;
25 my $dList = qr{ $sp $decl (?: $sp , $d1 )* $sp ; $sp }xo ;
26
27
28 while (s/^
29 ( # Start $1
30 ( # Start $2
31 .*? # Minimal eat content
32 ( ^ \w [\w\s\*]+ ) # $3 -- function name
33 \s* # optional whitespace
34 ) # $2 - Matched up to before parameter list
35
36 \( \s* # Literal "(" + optional whitespace
37 ( [^\)]+ ) # $4 - one or more anythings except ")"
38 \s* \) # optional whitespace surrounding a Literal ")"
39
40 ( (?: $dList )+ ) # $5
41
42 $sp ^ { # literal "{" at start of line
43 ) # Remember to $1
44 //xsom
45 )
46 {
47 my $all = $1 ;
48 my $prefix = $2;
49 my $param_list = $4 ;
50 my $params = $5;
51
52 StripComments($params);
53 StripComments($param_list);
54 $param_list =~ s/^\s+//;
55 $param_list =~ s/\s+$//;
56
57 my $i = 0 ;
58 my %pList = map { $_ => $i++ }
59 split /\s*,\s*/, $param_list;
60 my $pMatch = '(\b' . join('|', keys %pList) . '\b)\W*$' ;
61
62 my @params = split /\s*;\s*/, $params;
63 my @outParams = ();
64 foreach my $p (@params)
65 {
66 if ($p =~ /,/)
67 {
68 my @bits = split /\s*,\s*/, $p;
69 my $first = shift @bits;
70 $first =~ s/^\s*//;
71 push @outParams, $first;
72 $first =~ /^(\w+\s*)/;
73 my $type = $1 ;
74 push @outParams, map { $type . $_ } @bits;
75 }
76 else
77 {
78 $p =~ s/^\s+//;
79 push @outParams, $p;
80 }
81 }
82
83
84 my %tmp = map { /$pMatch/; $_ => $pList{$1} }
85 @outParams ;
86
87 @outParams = map { " $_" }
88 sort { $tmp{$a} <=> $tmp{$b} }
89 @outParams ;
90
91 print $prefix ;
92 print "(\n" . join(",\n", @outParams) . ")\n";
93 print "{" ;
94
95 }
96
97 # Output any trailing code.
98 print ;
99 exit 0;
100
101
102 sub StripComments
103 {
104
105 no warnings;
106
107 # Strip C & C++ comments
108 # From the perlfaq
109 $_[0] =~
110
111 s{
112 /\* ## Start of /* ... */ comment
113 [^*]*\*+ ## Non-* followed by 1-or-more *'s
114 (
115 [^/*][^*]*\*+
116 )* ## 0-or-more things which don't start with /
117 ## but do end with '*'
118 / ## End of /* ... */ comment
119
120 | ## OR C++ Comment
121 // ## Start of C++ comment //
122 [^\n]* ## followed by 0-or-more non end of line characters
123
124 | ## OR various things which aren't comments:
125
126 (
127 " ## Start of " ... " string
128 (
129 \\. ## Escaped char
130 | ## OR
131 [^"\\] ## Non "\
132 )*
133 " ## End of " ... " string
134
135 | ## OR
136
137 ' ## Start of ' ... ' string
138 (
139 \\. ## Escaped char
140 | ## OR
141 [^'\\] ## Non '\
142 )*
143 ' ## End of ' ... ' string
144
145 | ## OR
146
147 . ## Anything other char
148 [^/"'\\]* ## Chars which doesn't start a comment, string or escape
149 )
150 }{$2}gxs;
151
152 }
--- a/compat/zlib/zlib2ansi
+++ b/compat/zlib/zlib2ansi
@@ -1,152 +0,0 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- compat/zlib/zutil.c
+++ compat/zlib/zutil.c
@@ -22,17 +22,15 @@
2222
(z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
2323
(z_const char *)""
2424
};
2525
2626
27
-const char * ZEXPORT zlibVersion()
28
-{
27
+const char * ZEXPORT zlibVersion(void) {
2928
return ZLIB_VERSION;
3029
}
3130
32
-uLong ZEXPORT zlibCompileFlags()
33
-{
31
+uLong ZEXPORT zlibCompileFlags(void) {
3432
uLong flags;
3533
3634
flags = 0;
3735
switch ((int)(sizeof(uInt))) {
3836
case 2: break;
@@ -119,24 +117,20 @@
119117
# ifndef verbose
120118
# define verbose 0
121119
# endif
122120
int ZLIB_INTERNAL z_verbose = verbose;
123121
124
-void ZLIB_INTERNAL z_error(m)
125
- char *m;
126
-{
122
+void ZLIB_INTERNAL z_error(char *m) {
127123
fprintf(stderr, "%s\n", m);
128124
exit(1);
129125
}
130126
#endif
131127
132128
/* exported to allow conversion of error code to string for compress() and
133129
* uncompress()
134130
*/
135
-const char * ZEXPORT zError(err)
136
- int err;
137
-{
131
+const char * ZEXPORT zError(int err) {
138132
return ERR_MSG(err);
139133
}
140134
141135
#if defined(_WIN32_WCE) && _WIN32_WCE < 0x800
142136
/* The older Microsoft C Run-Time Library for Windows CE doesn't have
@@ -146,38 +140,27 @@
146140
int errno = 0;
147141
#endif
148142
149143
#ifndef HAVE_MEMCPY
150144
151
-void ZLIB_INTERNAL zmemcpy(dest, source, len)
152
- Bytef* dest;
153
- const Bytef* source;
154
- uInt len;
155
-{
145
+void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) {
156146
if (len == 0) return;
157147
do {
158148
*dest++ = *source++; /* ??? to be unrolled */
159149
} while (--len != 0);
160150
}
161151
162
-int ZLIB_INTERNAL zmemcmp(s1, s2, len)
163
- const Bytef* s1;
164
- const Bytef* s2;
165
- uInt len;
166
-{
152
+int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) {
167153
uInt j;
168154
169155
for (j = 0; j < len; j++) {
170156
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
171157
}
172158
return 0;
173159
}
174160
175
-void ZLIB_INTERNAL zmemzero(dest, len)
176
- Bytef* dest;
177
- uInt len;
178
-{
161
+void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) {
179162
if (len == 0) return;
180163
do {
181164
*dest++ = 0; /* ??? to be unrolled */
182165
} while (--len != 0);
183166
}
@@ -214,12 +197,11 @@
214197
* Since MSDOS is not a preemptive multitasking OS, this table is not
215198
* protected from concurrent access. This hack doesn't work anyway on
216199
* a protected system like OS/2. Use Microsoft C instead.
217200
*/
218201
219
-voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
220
-{
202
+voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
221203
voidpf buf;
222204
ulg bsize = (ulg)items*size;
223205
224206
(void)opaque;
225207
@@ -240,12 +222,11 @@
240222
*(ush*)&buf = 0;
241223
table[next_ptr++].new_ptr = buf;
242224
return buf;
243225
}
244226
245
-void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
246
-{
227
+void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
247228
int n;
248229
249230
(void)opaque;
250231
251232
if (*(ush*)&ptr != 0) { /* object < 64K */
@@ -277,18 +258,16 @@
277258
#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
278259
# define _halloc halloc
279260
# define _hfree hfree
280261
#endif
281262
282
-voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size)
283
-{
263
+voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) {
284264
(void)opaque;
285265
return _halloc((long)items, size);
286266
}
287267
288
-void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
289
-{
268
+void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
290269
(void)opaque;
291270
_hfree(ptr);
292271
}
293272
294273
#endif /* M_I86 */
@@ -297,31 +276,24 @@
297276
298277
299278
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
300279
301280
#ifndef STDC
302
-extern voidp malloc OF((uInt size));
303
-extern voidp calloc OF((uInt items, uInt size));
304
-extern void free OF((voidpf ptr));
281
+extern voidp malloc(uInt size);
282
+extern voidp calloc(uInt items, uInt size);
283
+extern void free(voidpf ptr);
305284
#endif
306285
307
-voidpf ZLIB_INTERNAL zcalloc(opaque, items, size)
308
- voidpf opaque;
309
- unsigned items;
310
- unsigned size;
311
-{
286
+voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
312287
(void)opaque;
313288
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
314289
(voidpf)calloc(items, size);
315290
}
316291
317
-void ZLIB_INTERNAL zcfree(opaque, ptr)
318
- voidpf opaque;
319
- voidpf ptr;
320
-{
292
+void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
321293
(void)opaque;
322294
free(ptr);
323295
}
324296
325297
#endif /* MY_ZCALLOC */
326298
327299
#endif /* !Z_SOLO */
328300
--- compat/zlib/zutil.c
+++ compat/zlib/zutil.c
@@ -22,17 +22,15 @@
22 (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
23 (z_const char *)""
24 };
25
26
27 const char * ZEXPORT zlibVersion()
28 {
29 return ZLIB_VERSION;
30 }
31
32 uLong ZEXPORT zlibCompileFlags()
33 {
34 uLong flags;
35
36 flags = 0;
37 switch ((int)(sizeof(uInt))) {
38 case 2: break;
@@ -119,24 +117,20 @@
119 # ifndef verbose
120 # define verbose 0
121 # endif
122 int ZLIB_INTERNAL z_verbose = verbose;
123
124 void ZLIB_INTERNAL z_error(m)
125 char *m;
126 {
127 fprintf(stderr, "%s\n", m);
128 exit(1);
129 }
130 #endif
131
132 /* exported to allow conversion of error code to string for compress() and
133 * uncompress()
134 */
135 const char * ZEXPORT zError(err)
136 int err;
137 {
138 return ERR_MSG(err);
139 }
140
141 #if defined(_WIN32_WCE) && _WIN32_WCE < 0x800
142 /* The older Microsoft C Run-Time Library for Windows CE doesn't have
@@ -146,38 +140,27 @@
146 int errno = 0;
147 #endif
148
149 #ifndef HAVE_MEMCPY
150
151 void ZLIB_INTERNAL zmemcpy(dest, source, len)
152 Bytef* dest;
153 const Bytef* source;
154 uInt len;
155 {
156 if (len == 0) return;
157 do {
158 *dest++ = *source++; /* ??? to be unrolled */
159 } while (--len != 0);
160 }
161
162 int ZLIB_INTERNAL zmemcmp(s1, s2, len)
163 const Bytef* s1;
164 const Bytef* s2;
165 uInt len;
166 {
167 uInt j;
168
169 for (j = 0; j < len; j++) {
170 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
171 }
172 return 0;
173 }
174
175 void ZLIB_INTERNAL zmemzero(dest, len)
176 Bytef* dest;
177 uInt len;
178 {
179 if (len == 0) return;
180 do {
181 *dest++ = 0; /* ??? to be unrolled */
182 } while (--len != 0);
183 }
@@ -214,12 +197,11 @@
214 * Since MSDOS is not a preemptive multitasking OS, this table is not
215 * protected from concurrent access. This hack doesn't work anyway on
216 * a protected system like OS/2. Use Microsoft C instead.
217 */
218
219 voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
220 {
221 voidpf buf;
222 ulg bsize = (ulg)items*size;
223
224 (void)opaque;
225
@@ -240,12 +222,11 @@
240 *(ush*)&buf = 0;
241 table[next_ptr++].new_ptr = buf;
242 return buf;
243 }
244
245 void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
246 {
247 int n;
248
249 (void)opaque;
250
251 if (*(ush*)&ptr != 0) { /* object < 64K */
@@ -277,18 +258,16 @@
277 #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
278 # define _halloc halloc
279 # define _hfree hfree
280 #endif
281
282 voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size)
283 {
284 (void)opaque;
285 return _halloc((long)items, size);
286 }
287
288 void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
289 {
290 (void)opaque;
291 _hfree(ptr);
292 }
293
294 #endif /* M_I86 */
@@ -297,31 +276,24 @@
297
298
299 #ifndef MY_ZCALLOC /* Any system without a special alloc function */
300
301 #ifndef STDC
302 extern voidp malloc OF((uInt size));
303 extern voidp calloc OF((uInt items, uInt size));
304 extern void free OF((voidpf ptr));
305 #endif
306
307 voidpf ZLIB_INTERNAL zcalloc(opaque, items, size)
308 voidpf opaque;
309 unsigned items;
310 unsigned size;
311 {
312 (void)opaque;
313 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
314 (voidpf)calloc(items, size);
315 }
316
317 void ZLIB_INTERNAL zcfree(opaque, ptr)
318 voidpf opaque;
319 voidpf ptr;
320 {
321 (void)opaque;
322 free(ptr);
323 }
324
325 #endif /* MY_ZCALLOC */
326
327 #endif /* !Z_SOLO */
328
--- compat/zlib/zutil.c
+++ compat/zlib/zutil.c
@@ -22,17 +22,15 @@
22 (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
23 (z_const char *)""
24 };
25
26
27 const char * ZEXPORT zlibVersion(void) {
 
28 return ZLIB_VERSION;
29 }
30
31 uLong ZEXPORT zlibCompileFlags(void) {
 
32 uLong flags;
33
34 flags = 0;
35 switch ((int)(sizeof(uInt))) {
36 case 2: break;
@@ -119,24 +117,20 @@
117 # ifndef verbose
118 # define verbose 0
119 # endif
120 int ZLIB_INTERNAL z_verbose = verbose;
121
122 void ZLIB_INTERNAL z_error(char *m) {
 
 
123 fprintf(stderr, "%s\n", m);
124 exit(1);
125 }
126 #endif
127
128 /* exported to allow conversion of error code to string for compress() and
129 * uncompress()
130 */
131 const char * ZEXPORT zError(int err) {
 
 
132 return ERR_MSG(err);
133 }
134
135 #if defined(_WIN32_WCE) && _WIN32_WCE < 0x800
136 /* The older Microsoft C Run-Time Library for Windows CE doesn't have
@@ -146,38 +140,27 @@
140 int errno = 0;
141 #endif
142
143 #ifndef HAVE_MEMCPY
144
145 void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) {
 
 
 
 
146 if (len == 0) return;
147 do {
148 *dest++ = *source++; /* ??? to be unrolled */
149 } while (--len != 0);
150 }
151
152 int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) {
 
 
 
 
153 uInt j;
154
155 for (j = 0; j < len; j++) {
156 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
157 }
158 return 0;
159 }
160
161 void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) {
 
 
 
162 if (len == 0) return;
163 do {
164 *dest++ = 0; /* ??? to be unrolled */
165 } while (--len != 0);
166 }
@@ -214,12 +197,11 @@
197 * Since MSDOS is not a preemptive multitasking OS, this table is not
198 * protected from concurrent access. This hack doesn't work anyway on
199 * a protected system like OS/2. Use Microsoft C instead.
200 */
201
202 voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
 
203 voidpf buf;
204 ulg bsize = (ulg)items*size;
205
206 (void)opaque;
207
@@ -240,12 +222,11 @@
222 *(ush*)&buf = 0;
223 table[next_ptr++].new_ptr = buf;
224 return buf;
225 }
226
227 void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
 
228 int n;
229
230 (void)opaque;
231
232 if (*(ush*)&ptr != 0) { /* object < 64K */
@@ -277,18 +258,16 @@
258 #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
259 # define _halloc halloc
260 # define _hfree hfree
261 #endif
262
263 voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) {
 
264 (void)opaque;
265 return _halloc((long)items, size);
266 }
267
268 void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
 
269 (void)opaque;
270 _hfree(ptr);
271 }
272
273 #endif /* M_I86 */
@@ -297,31 +276,24 @@
276
277
278 #ifndef MY_ZCALLOC /* Any system without a special alloc function */
279
280 #ifndef STDC
281 extern voidp malloc(uInt size);
282 extern voidp calloc(uInt items, uInt size);
283 extern void free(voidpf ptr);
284 #endif
285
286 voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
 
 
 
 
287 (void)opaque;
288 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
289 (voidpf)calloc(items, size);
290 }
291
292 void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
 
 
 
293 (void)opaque;
294 free(ptr);
295 }
296
297 #endif /* MY_ZCALLOC */
298
299 #endif /* !Z_SOLO */
300
--- compat/zlib/zutil.h
+++ compat/zlib/zutil.h
@@ -189,13 +189,13 @@
189189
#endif
190190
191191
/* provide prototypes for these when building zlib without LFS */
192192
#if !defined(_WIN32) && \
193193
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
194
- ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
195
- ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
196
- ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t));
194
+ ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
195
+ ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
196
+ ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
197197
#endif
198198
199199
/* common defaults */
200200
201201
#ifndef OS_CODE
@@ -230,20 +230,20 @@
230230
# define zmemcpy memcpy
231231
# define zmemcmp memcmp
232232
# define zmemzero(dest, len) memset(dest, 0, len)
233233
# endif
234234
#else
235
- void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
236
- int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
237
- void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
235
+ void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
236
+ int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
237
+ void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
238238
#endif
239239
240240
/* Diagnostic functions */
241241
#ifdef ZLIB_DEBUG
242242
# include <stdio.h>
243243
extern int ZLIB_INTERNAL z_verbose;
244
- extern void ZLIB_INTERNAL z_error OF((char *m));
244
+ extern void ZLIB_INTERNAL z_error(char *m);
245245
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
246246
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
247247
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
248248
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
249249
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
@@ -256,13 +256,13 @@
256256
# define Tracec(c,x)
257257
# define Tracecv(c,x)
258258
#endif
259259
260260
#ifndef Z_SOLO
261
- voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
262
- unsigned size));
263
- void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
261
+ voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
262
+ unsigned size);
263
+ void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
264264
#endif
265265
266266
#define ZALLOC(strm, items, size) \
267267
(*((strm)->zalloc))((strm)->opaque, (items), (size))
268268
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
269269
--- compat/zlib/zutil.h
+++ compat/zlib/zutil.h
@@ -189,13 +189,13 @@
189 #endif
190
191 /* provide prototypes for these when building zlib without LFS */
192 #if !defined(_WIN32) && \
193 (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
194 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
195 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
196 ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t));
197 #endif
198
199 /* common defaults */
200
201 #ifndef OS_CODE
@@ -230,20 +230,20 @@
230 # define zmemcpy memcpy
231 # define zmemcmp memcmp
232 # define zmemzero(dest, len) memset(dest, 0, len)
233 # endif
234 #else
235 void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
236 int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
237 void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
238 #endif
239
240 /* Diagnostic functions */
241 #ifdef ZLIB_DEBUG
242 # include <stdio.h>
243 extern int ZLIB_INTERNAL z_verbose;
244 extern void ZLIB_INTERNAL z_error OF((char *m));
245 # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
246 # define Trace(x) {if (z_verbose>=0) fprintf x ;}
247 # define Tracev(x) {if (z_verbose>0) fprintf x ;}
248 # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
249 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
@@ -256,13 +256,13 @@
256 # define Tracec(c,x)
257 # define Tracecv(c,x)
258 #endif
259
260 #ifndef Z_SOLO
261 voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
262 unsigned size));
263 void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
264 #endif
265
266 #define ZALLOC(strm, items, size) \
267 (*((strm)->zalloc))((strm)->opaque, (items), (size))
268 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
269
--- compat/zlib/zutil.h
+++ compat/zlib/zutil.h
@@ -189,13 +189,13 @@
189 #endif
190
191 /* provide prototypes for these when building zlib without LFS */
192 #if !defined(_WIN32) && \
193 (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
194 ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
195 ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
196 ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
197 #endif
198
199 /* common defaults */
200
201 #ifndef OS_CODE
@@ -230,20 +230,20 @@
230 # define zmemcpy memcpy
231 # define zmemcmp memcmp
232 # define zmemzero(dest, len) memset(dest, 0, len)
233 # endif
234 #else
235 void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
236 int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
237 void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
238 #endif
239
240 /* Diagnostic functions */
241 #ifdef ZLIB_DEBUG
242 # include <stdio.h>
243 extern int ZLIB_INTERNAL z_verbose;
244 extern void ZLIB_INTERNAL z_error(char *m);
245 # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
246 # define Trace(x) {if (z_verbose>=0) fprintf x ;}
247 # define Tracev(x) {if (z_verbose>0) fprintf x ;}
248 # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
249 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
@@ -256,13 +256,13 @@
256 # define Tracec(c,x)
257 # define Tracecv(c,x)
258 #endif
259
260 #ifndef Z_SOLO
261 voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
262 unsigned size);
263 void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
264 #endif
265
266 #define ZALLOC(strm, items, size) \
267 (*((strm)->zalloc))((strm)->opaque, (items), (size))
268 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
269

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button