summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:21:57 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:21:57 -0700
commit13a294f044ef0a89b2dcbfbb5d4d4c792673348e (patch)
treed9b377b4d8c00633c3da4e96659bfba9b08287f2
parent7c2a874e50b871d04fbd19501f7b42cff55e5abc (diff)
downloadzlib-1.2.0.1.tar.gz
zlib-1.2.0.1.tar.bz2
zlib-1.2.0.1.zip
zlib 1.2.0.1v1.2.0.1
-rw-r--r--ChangeLog34
-rw-r--r--FAQ105
-rw-r--r--INDEX34
-rw-r--r--Makefile5
-rw-r--r--Makefile.in5
-rw-r--r--README120
-rw-r--r--adler32.c4
-rw-r--r--contrib/README.contrib9
-rw-r--r--contrib/inflate86/inffas86.c783
-rw-r--r--contrib/inflate86/inffast.S2472
-rw-r--r--contrib/minizip/ChangeLogUnzip9
-rw-r--r--contrib/minizip/Makefile4
-rw-r--r--contrib/minizip/crypt.h104
-rw-r--r--contrib/minizip/ioapi.c177
-rw-r--r--contrib/minizip/ioapi.h75
-rw-r--r--contrib/minizip/iowin32.c271
-rw-r--r--contrib/minizip/iowin32.h19
-rw-r--r--contrib/minizip/miniunz.c609
-rw-r--r--contrib/minizip/minizip.c230
-rw-r--r--contrib/minizip/readme.txt37
-rw-r--r--contrib/minizip/unzip.c1845
-rw-r--r--contrib/minizip/unzip.def15
-rw-r--r--contrib/minizip/unzip.h191
-rw-r--r--contrib/minizip/zip.c662
-rw-r--r--contrib/minizip/zip.def5
-rw-r--r--contrib/minizip/zip.h161
-rw-r--r--contrib/minizip/zlibvc.dsp651
-rw-r--r--contrib/minizip/zlibvc.dsw41
-rw-r--r--contrib/testzlib/testzlib.c149
-rw-r--r--contrib/testzlib/testzlib.sln21
-rw-r--r--contrib/testzlib/testzlib.vcproj124
-rw-r--r--contrib/vstudio/readme.txt17
-rw-r--r--contrib/vstudio/vc15_16/zlib16.def94
-rw-r--r--contrib/vstudio/vc15_16/zlib16.mak256
-rw-r--r--contrib/vstudio/vc15_16/zlib16.rc33
-rw-r--r--contrib/vstudio/vc70_32/gvmat32.asm905
-rw-r--r--contrib/vstudio/vc70_32/gvmat32.objbin0 -> 10143 bytes
-rw-r--r--contrib/vstudio/vc70_32/gvmat32c.c209
-rw-r--r--contrib/vstudio/vc70_32/inffastAsm.asm1020
-rw-r--r--contrib/vstudio/vc70_32/inffastAsm.objbin0 -> 14895 bytes
-rw-r--r--contrib/vstudio/vc70_32/miniunz.vcproj124
-rw-r--r--contrib/vstudio/vc70_32/minizip.vcproj124
-rw-r--r--contrib/vstudio/vc70_32/mkgvmt32.bat2
-rw-r--r--contrib/vstudio/vc70_32/zlib.rc32
-rw-r--r--contrib/vstudio/vc70_32/zlibstat.vcproj253
-rw-r--r--contrib/vstudio/vc70_32/zlibvc.def88
-rw-r--r--contrib/vstudio/vc70_32/zlibvc.sln66
-rw-r--r--contrib/vstudio/vc70_32/zlibvc.vcproj434
-rw-r--r--deflate.c273
-rw-r--r--deflate.h2
-rw-r--r--example.c83
-rw-r--r--gzio.c298
-rw-r--r--infback.c3
-rw-r--r--inffast.c4
-rw-r--r--inflate.c4
-rw-r--r--inftrees.c4
-rw-r--r--minigzip.c29
-rw-r--r--msdos/Makefile.bor109
-rw-r--r--msdos/Makefile.tc94
-rw-r--r--old/msdos/Makefile.bor125
-rw-r--r--old/msdos/Makefile.tc108
-rw-r--r--trees.c76
-rw-r--r--win32/Makefile-dll.msc76
-rw-r--r--win32/Makefile.bor91
-rw-r--r--win32/Makefile.gcc105
-rw-r--r--win32/Makefile.msc69
-rw-r--r--win32/zlib.def (renamed from contrib/minizip/zlibvc.def)37
-rw-r--r--zconf.h31
-rw-r--r--zconf.in.h31
-rw-r--r--zlib.h37
-rw-r--r--zutil.h24
71 files changed, 10334 insertions, 4007 deletions
diff --git a/ChangeLog b/ChangeLog
index 6193e00..55c29c1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,29 @@
1 1
2 ChangeLog file for zlib 2 ChangeLog file for zlib
3Changes in 1.2.0.1 (17 March 2003)
4- Add Z_RLE strategy for run-length encoding [Truta]
5 - When Z_RLE requested, restrict matches to distance one
6 - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE
7- Correct FASTEST compilation to allow level == 0
8- Clean up what gets compiled for FASTEST
9- Incorporate changes to zconf.in.h [Vollant]
10 - Refine detection of Turbo C need for dummy returns
11 - Refine ZLIB_DLL compilation
12 - Include additional header file on VMS for off_t typedef
13- Try to use _vsnprintf where it supplants vsprintf [Vollant]
14- Add some casts in inffast.c
15- Enchance comments in zlib.h on what happens if the gzprintf() tries to
16 write more than 4095 bytes before compression
17- Remove unused state from inflateBackEnd()
18- Remove exit(0) from minigzip.c, example.c
19- Get rid of all those darn tabs
20- Add "check" target to Makefile.in that does the same thing as "test"
21- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in
22- Update contrib/inflate86 [Anderson]
23- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant]
24- Add msdos and win32 directories with makefiles [Truta]
25- More additions and improvements to the FAQ
26
3Changes in 1.2.0 (9 March 2003) 27Changes in 1.2.0 (9 March 2003)
4- New and improved inflate code 28- New and improved inflate code
5 - About 20% faster 29 - About 20% faster
@@ -236,13 +260,13 @@ Changes in 1.0.6 (19 Jan 1998)
236- added Makefile.nt (thanks to Stephen Williams) 260- added Makefile.nt (thanks to Stephen Williams)
237- added the unsupported "contrib" directory: 261- added the unsupported "contrib" directory:
238 contrib/asm386/ by Gilles Vollant <info@winimage.com> 262 contrib/asm386/ by Gilles Vollant <info@winimage.com>
239 386 asm code replacing longest_match(). 263 386 asm code replacing longest_match().
240 contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu> 264 contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
241 A C++ I/O streams interface to the zlib gz* functions 265 A C++ I/O streams interface to the zlib gz* functions
242 contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no> 266 contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
243 Another C++ I/O streams interface 267 Another C++ I/O streams interface
244 contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es> 268 contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
245 A very simple tar.gz file extractor using zlib 269 A very simple tar.gz file extractor using zlib
246 contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl> 270 contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
247 How to use compress(), uncompress() and the gz* functions from VB. 271 How to use compress(), uncompress() and the gz* functions from VB.
248- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression 272- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
@@ -269,7 +293,7 @@ Changes in 1.0.6 (19 Jan 1998)
269- add NEED_DUMMY_RETURN for Borland 293- add NEED_DUMMY_RETURN for Borland
270- use variable z_verbose for tracing in debug mode (L. Peter Deutsch). 294- use variable z_verbose for tracing in debug mode (L. Peter Deutsch).
271- allow compilation with CC 295- allow compilation with CC
272- defined STDC for OS/2 (David Charlap) 296- defined STDC for OS/2 (David Charlap)
273- limit external names to 8 chars for MVS (Thomas Lund) 297- limit external names to 8 chars for MVS (Thomas Lund)
274- in minigzip.c, use static buffers only for 16-bit systems 298- in minigzip.c, use static buffers only for 16-bit systems
275- fix suffix check for "minigzip -d foo.gz" 299- fix suffix check for "minigzip -d foo.gz"
diff --git a/FAQ b/FAQ
index abf680c..2a8247c 100644
--- a/FAQ
+++ b/FAQ
@@ -1,5 +1,5 @@
1 1
2 Frequently Asked Questions about zlib 2 Frequently Asked Questions about zlib
3 3
4 4
5If your question is not there, please check the zlib home page 5If your question is not there, please check the zlib home page
@@ -90,13 +90,14 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
90 ./configure -s 90 ./configure -s
91 make 91 make
92 92
9314. Why does "make test" fail on Mac OS X? 9314. How do I install a shared zlib library on Unix?
94 94
95 Mac OS X already includes zlib as a shared library, and so -lz links the 95 make install
96 shared library instead of the one that the "make" compiled. The two are 96
97 incompatible due to different compile-time options. Simply change the -lz 97 However, many flavors of Unix come with a shared zlib already installed.
98 in the Makefile to libz.a, and it will use the compiled library instead 98 Before going to the trouble of compiling a shared version of zlib and
99 of the shared one and the "make test" will succeed. 99 trying to install it, you may want to check if it's already there! If you
100 can #include <zlib.h>, it's there. The -lz option will probably link to it.
100 101
10115. I have a question about OttoPDF 10215. I have a question about OttoPDF
102 103
@@ -108,8 +109,8 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
108 The compress and deflate functions produce data in the zlib format, which 109 The compress and deflate functions produce data in the zlib format, which
109 is different and incompatible with the gzip format. The gz* functions in 110 is different and incompatible with the gzip format. The gz* functions in
110 zlib on the other hand use the gzip format. Both the zlib and gzip 111 zlib on the other hand use the gzip format. Both the zlib and gzip
111 formats use the same compressed data format, but have different headers 112 formats use the same compressed data format internally, but have different
112 and trailers. 113 headers and trailers around the compressed data.
113 114
11417. Ok, so why are there two different formats? 11517. Ok, so why are there two different formats?
115 116
@@ -127,12 +128,13 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
12719. Is zlib thread-safe? 12819. Is zlib thread-safe?
128 129
129 Yes. However any library routines that zlib uses and any application- 130 Yes. However any library routines that zlib uses and any application-
130 provided memory allocation routines must also be thread-safe. Of course, 131 provided memory allocation routines must also be thread-safe. zlib's gz*
131 you should only operate on any given zlib or gzip stream from a single 132 functions use stdio library routines, and most of zlib's functions use the
132 thread. zlib's gz* functions use stdio library routines, and most of 133 library memory allocation routines by default. zlib's Init functions allow
133 zlib's functions use the library memory allocation routines by default. 134 for the application to provide custom memory allocation routines.
134 zlib's Init functions allow for the application to provide custom memory 135
135 allocation routines. 136 Of course, you should only operate on any given zlib or gzip stream from a
137 single thread at a time.
136 138
13720. Can I use zlib in my commercial application? 13920. Can I use zlib in my commercial application?
138 140
@@ -142,24 +144,44 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
142 144
143 No. Please read the license in zlib.h. 145 No. Please read the license in zlib.h.
144 146
14522. Will zlib work on a big-endian or little-endian architecture, and can I 14722. The license says that altered source versions must be "plainly marked". So
148 what exactly do I need to do to meet that requirement?
149
150 You need to append something the ZLIB_VERSION string in zlib.h. For
151 example, if the version of the base zlib you are altering is "1.2.3", then
152 you could change the string to "1.2.3-fred-mods-v3". You should not change
153 it to "1.2.4" or "1.2.3.1" since the zlib authors would like to reserve
154 those forms of the version for their own use.
155
156 For altered source distributions, you should also note the origin and
157 nature of the changes in zlib.h, as well as in ChangeLog and README, along
158 with the dates of the alterations. The origin should include at least your
159 name (or your company's name), and an email address to contact for help or
160 issues with the library.
161
162 Note that distributing a compiled zlib library along with zlib.h and
163 zconf.h is also a source distribution, and so you should change
164 ZLIB_VERSION and note the origin and nature of the changes in zlib.h as you
165 would for a full source distribution.
166
16723. Will zlib work on a big-endian or little-endian architecture, and can I
146 exchange compressed data between them? 168 exchange compressed data between them?
147 169
148 Yes and yes. 170 Yes and yes.
149 171
15023. Will zlib work on a 64-bit machine? 17224. Will zlib work on a 64-bit machine?
151 173
152 It should. It has been tested on 64-bit machines, and has no dependence 174 It should. It has been tested on 64-bit machines, and has no dependence
153 on any data types being limited to 32-bits in length. If you have any 175 on any data types being limited to 32-bits in length. If you have any
154 difficulties, please provide a complete problem report to zlib@gzip.org 176 difficulties, please provide a complete problem report to zlib@gzip.org
155 177
15624. Will zlib decompress data from the PKWare Data Compression Library? 17825. Will zlib decompress data from the PKWare Data Compression Library?
157 179
158 No. The PKWare DCL uses a completely different compressed data format 180 No. The PKWare DCL uses a completely different compressed data format
159 than does PKZIP and zlib. However, you can look in zlib's contrib/blast 181 than does PKZIP and zlib. However, you can look in zlib's contrib/blast
160 directory for a possible solution to your problem. 182 directory for a possible solution to your problem.
161 183
16225. Can I access data randomly in a compressed stream? 18426. Can I access data randomly in a compressed stream?
163 185
164 No, not without some preparation. If when compressing you periodically 186 No, not without some preparation. If when compressing you periodically
165 use Z_FULL_FLUSH, carefully write all the pending data at those points, 187 use Z_FULL_FLUSH, carefully write all the pending data at those points,
@@ -167,76 +189,83 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
167 at those points. You have to be careful to not use Z_FULL_FLUSH too 189 at those points. You have to be careful to not use Z_FULL_FLUSH too
168 often, since it can significantly degrade compression. 190 often, since it can significantly degrade compression.
169 191
17026. Does zlib work on MVS, OS/390, CICS, etc.? 19227. Does zlib work on MVS, OS/390, CICS, etc.?
171 193
172 We don't know for sure. We have heard occasional reports of success on 194 We don't know for sure. We have heard occasional reports of success on
173 these systems. If you do use it on one of these, please provide us with 195 these systems. If you do use it on one of these, please provide us with
174 a report, instructions, and patches that we can reference when we get 196 a report, instructions, and patches that we can reference when we get
175 these questions. Thanks. 197 these questions. Thanks.
176 198
17727. Is there some simpler, easier to read version of inflate I can look at 19928. Is there some simpler, easier to read version of inflate I can look at
178 to understand the deflate format? 200 to understand the deflate format?
179 201
180 First off, you should read RFC 1951. Second, yes. Look in zlib's 202 First off, you should read RFC 1951. Second, yes. Look in zlib's
181 contrib/puff directory. 203 contrib/puff directory.
182 204
18328. Does zlib infringe on any patents? 20529. Does zlib infringe on any patents?
184 206
185 As far as we know, no. In fact, that was originally the whole point behind 207 As far as we know, no. In fact, that was originally the whole point behind
186 zlib. Look here for some more information: 208 zlib. Look here for some more information:
187 209
188 http://www.gzip.org/#faq11 210 http://www.gzip.org/#faq11
189 211
19029. Can zlib work with greater than 4 GB of data? 21230. Can zlib work with greater than 4 GB of data?
191 213
192 Yes. inflate() and deflate() will process any amount of data correctly. 214 Yes. inflate() and deflate() will process any amount of data correctly.
193 However the strm.total_in and strm_total_out counters may be limited to 215 However the strm.total_in and strm_total_out counters may be limited to
194 4 GB. The user can easily set up their own counters updated after each 216 4 GB. The application can easily set up its own counters updated after each
195 call of inflate() or deflate() to count beyond 4 GB. compress() and 217 call of inflate() or deflate() to count beyond 4 GB. compress() and
196 uncompress() may be limited to 4 GB, since they operate in a single 218 uncompress() may be limited to 4 GB, since they operate in a single call
197 call using unsigned long lengths. gzseek() may be limited to 4 GB 219 using unsigned long lengths. gzseek() and gztell() may be limited to 4 GB
198 depending on how zlib is compiled. 220 depending on how zlib is compiled.
199 221
20030. Does zlib have any security vulnerabilities? 22231. Does zlib have any security vulnerabilities?
201 223
202 The only one that we are aware of is potentially in gzprintf(). If zlib 224 The only one that we are aware of is potentially in gzprintf(). If zlib
203 is compiled to use sprintf() or vsprintf(), then there is no protection 225 is compiled to use sprintf() or vsprintf(), then there is no protection
204 against a buffer overflow of a 4K string space, other than the caller of 226 against a buffer overflow of a 4K string space, other than the caller of
205 gzprintf() assuring that the output will not exceed 4K. On the other 227 gzprintf() assuring that the output will not exceed 4K. On the other
206 hand, if zlib is compiled to use snprintf() or vsnprintf(), then there is 228 hand, if zlib is compiled to use snprintf() or vsnprintf(), which should
207 no vulnerability. 229 normally be the case, then there is no vulnerability. The ./configure
230 script will display warnings if an insecure variation of sprintf() will
231 be used by gzprintf().
232
233 If you don't have snprintf() or vsnprintf() and would like one, you can
234 find a portable implementation here:
235
236 http://www.ijs.si/software/snprintf/
208 237
209 Note that you should be using the most recent version of zlib. Versions 238 Note that you should be using the most recent version of zlib. Versions
210 1.1.3 and before were subject to a double-free vulnerability. 239 1.1.3 and before were subject to a double-free vulnerability.
211 240
21231. Is there a Java version of zlib? 24132. Is there a Java version of zlib?
213 242
214 Probably what you want is to use zlib in Java. zlib is already included 243 Probably what you want is to use zlib in Java. zlib is already included
215 as part of the Java SDK in the java.util.zip class. If you really want 244 as part of the Java SDK in the java.util.zip class. If you really want
216 a version of zlib written in the Java language, look on the zlib home 245 a version of zlib written in the Java language, look on the zlib home
217 page for links: http://www.zlib.org/ 246 page for links: http://www.zlib.org/
218 247
21932. I get this or that compiler or source-code scanner warning. Can't you guys 24833. I get this or that compiler or source-code scanner warning when I crank it
220 write proper code? 249 up to maximally-pendantic. Can't you guys write proper code?
221 250
222 Many years ago, we gave up attempting to avoid warnings on every compiler 251 Many years ago, we gave up attempting to avoid warnings on every compiler
223 in the universe. It just got to be a waste of time, and some compilers 252 in the universe. It just got to be a waste of time, and some compilers
224 were downright silly. So now, we simply make sure that the code always 253 were downright silly. So now, we simply make sure that the code always
225 works. 254 works.
226 255
22733. Will zlib read the (insert any ancient or arcane format here) compressed 25634. Will zlib read the (insert any ancient or arcane format here) compressed
228 data format? 257 data format?
229 258
230 Probably not. Look in the comp.compression FAQ for pointers to various 259 Probably not. Look in the comp.compression FAQ for pointers to various
231 formats and associated software. 260 formats and associated software.
232 261
23334. How can I encrypt/decrypt zip files with zlib? 26235. How can I encrypt/decrypt zip files with zlib?
234 263
235 zlib doesn't support encryption. PKZIP encryption is very weak and can be 264 zlib doesn't support encryption. PKZIP encryption is very weak and can be
236 broken with freely available programs. To get strong encryption, use gpg 265 broken with freely available programs. To get strong encryption, use gpg
237 which already includes zlib compression. 266 which already includes zlib compression.
238 267
23935. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings? 26836. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
240 269
241 "gzip" is the gzip format, and "deflate" is the zlib format. They should 270 "gzip" is the gzip format, and "deflate" is the zlib format. They should
242 probably have called the second one "zlib" instead to avoid confusion 271 probably have called the second one "zlib" instead to avoid confusion
@@ -250,14 +279,14 @@ The lastest zlib FAQ is at http://www.gzip.org/zlib/zlib_faq.html
250 for), using the "gzip" transfer encoding is probably more reliable due to 279 for), using the "gzip" transfer encoding is probably more reliable due to
251 an unfortunate choice of name on the part of the HTTP 1.1 authors. 280 an unfortunate choice of name on the part of the HTTP 1.1 authors.
252 281
25336. Does zlib support the new "Deflate64" format introduced by PKWare? 28237. Does zlib support the new "Deflate64" format introduced by PKWare?
254 283
255 No. PKWare has apparently decided to keep that format proprietary, since 284 No. PKWare has apparently decided to keep that format proprietary, since
256 they have not documented it as they have previous compression formats. 285 they have not documented it as they have previous compression formats.
257 In any case, the compression improvements are so modest compared to other 286 In any case, the compression improvements are so modest compared to other
258 more modern approaches, that it's not worth the effort to implement. 287 more modern approaches, that it's not worth the effort to implement.
259 288
26037. Can you please sign these lengthy legal documents and fax them back to us 28938. Can you please sign these lengthy legal documents and fax them back to us
261 so that we can use your software in our product? 290 so that we can use your software in our product?
262 291
263 No. 292 No. Go away.
diff --git a/INDEX b/INDEX
index 87df959..a1463ce 100644
--- a/INDEX
+++ b/INDEX
@@ -1,22 +1,24 @@
1ChangeLog history of changes 1ChangeLog history of changes
2FAQ Frequently Asked Questions about zlib 2FAQ Frequently Asked Questions about zlib
3INDEX this file 3INDEX this file
4Makefile makefile for Unix (generated by configure) 4Makefile makefile for Unix (generated by configure)
5Makefile.in makefile for Unix (template for configure) 5Makefile.in makefile for Unix (template for configure)
6README guess what 6README guess what
7algorithm.txt description of the (de)compression algorithm 7algorithm.txt description of the (de)compression algorithm
8configure configure script for Unix 8configure configure script for Unix
9zconf.in.h template for zconf.h (used by configure) 9zconf.in.h template for zconf.h (used by configure)
10 10
11aix/ instructions for building an AIX shared library 11aix/ instructions for building an AIX shared library
12old/ makefiles for various architectures and zlib documentation 12msdos/ makefiles for MSDOS
13 that has not yet been updated for zlib 1.2.x 13old/ makefiles for various architectures and zlib documentation
14 files that have not yet been updated for zlib 1.2.x
15win32/ makefiles for Windows
14 16
15 zlib public header files (must be kept): 17 zlib public header files (must be kept):
16zconf.h 18zconf.h
17zlib.h 19zlib.h
18 20
19 private source files used to build the zlib library: 21 private source files used to build the zlib library:
20adler32.c 22adler32.c
21compress.c 23compress.c
22crc32.c 24crc32.c
@@ -38,9 +40,9 @@ uncompr.c
38zutil.c 40zutil.c
39zutil.h 41zutil.h
40 42
41 source files for sample programs: 43 source files for sample programs:
42example.c 44example.c
43minigzip.c 45minigzip.c
44 46
45 unsupported contribution by third parties 47 unsupported contribution by third parties
46See contrib/README.contrib 48See contrib/README.contrib
diff --git a/Makefile b/Makefile
index 087e388..05540e9 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ LDFLAGS=libz.a
24LDSHARED=$(CC) 24LDSHARED=$(CC)
25CPP=$(CC) -E 25CPP=$(CC) -E
26 26
27VER=1.2.0 27VER=1.2.0.1
28LIBS=libz.a 28LIBS=libz.a
29SHAREDLIB=libz.so 29SHAREDLIB=libz.so
30 30
@@ -61,6 +61,7 @@ DISTFILES = README FAQ INDEX ChangeLog configure Make*[a-z0-9] *.[ch] *.mms \
61 61
62all: example minigzip 62all: example minigzip
63 63
64check: test
64test: all 65test: all
65 @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ 66 @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
66 echo hello world | ./minigzip | ./minigzip -d || \ 67 echo hello world | ./minigzip | ./minigzip -d || \
@@ -123,10 +124,12 @@ uninstall:
123 rm -f $(SHAREDLIB).$$v $(SHAREDLIB) $(SHAREDLIB).1; \ 124 rm -f $(SHAREDLIB).$$v $(SHAREDLIB) $(SHAREDLIB).1; \
124 fi 125 fi
125 126
127mostlyclean: clean
126clean: 128clean:
127 rm -f *.o *~ example minigzip libz.a libz.so* foo.gz so_locations \ 129 rm -f *.o *~ example minigzip libz.a libz.so* foo.gz so_locations \
128 _match.s maketree 130 _match.s maketree
129 131
132maintainer-clean: distclean
130distclean: clean 133distclean: clean
131 cp -p Makefile.in Makefile 134 cp -p Makefile.in Makefile
132 cp -p zconf.in.h zconf.h 135 cp -p zconf.in.h zconf.h
diff --git a/Makefile.in b/Makefile.in
index 087e388..05540e9 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -24,7 +24,7 @@ LDFLAGS=libz.a
24LDSHARED=$(CC) 24LDSHARED=$(CC)
25CPP=$(CC) -E 25CPP=$(CC) -E
26 26
27VER=1.2.0 27VER=1.2.0.1
28LIBS=libz.a 28LIBS=libz.a
29SHAREDLIB=libz.so 29SHAREDLIB=libz.so
30 30
@@ -61,6 +61,7 @@ DISTFILES = README FAQ INDEX ChangeLog configure Make*[a-z0-9] *.[ch] *.mms \
61 61
62all: example minigzip 62all: example minigzip
63 63
64check: test
64test: all 65test: all
65 @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ 66 @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
66 echo hello world | ./minigzip | ./minigzip -d || \ 67 echo hello world | ./minigzip | ./minigzip -d || \
@@ -123,10 +124,12 @@ uninstall:
123 rm -f $(SHAREDLIB).$$v $(SHAREDLIB) $(SHAREDLIB).1; \ 124 rm -f $(SHAREDLIB).$$v $(SHAREDLIB) $(SHAREDLIB).1; \
124 fi 125 fi
125 126
127mostlyclean: clean
126clean: 128clean:
127 rm -f *.o *~ example minigzip libz.a libz.so* foo.gz so_locations \ 129 rm -f *.o *~ example minigzip libz.a libz.so* foo.gz so_locations \
128 _match.s maketree 130 _match.s maketree
129 131
132maintainer-clean: distclean
130distclean: clean 133distclean: clean
131 cp -p Makefile.in Makefile 134 cp -p Makefile.in Makefile
132 cp -p zconf.in.h zconf.h 135 cp -p zconf.in.h zconf.h
diff --git a/README b/README
index 26ab2b6..8ac79a1 100644
--- a/README
+++ b/README
@@ -1,38 +1,40 @@
1zlib 1.2.0 is a general purpose data compression library. All the code 1ZLIB DATA COMPRESSION LIBRARY
2is thread safe. The data format used by the zlib library 2
3is described by RFCs (Request for Comments) 1950 to 1952 in the files 3zlib 1.2.0.1 is a general purpose data compression library. All the code is
4http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate 4thread safe. The data format used by the zlib library is described by RFCs
5format) and rfc1952.txt (gzip format). These documents are also available in 5(Request for Comments) 1950 to 1952 in the files
6other formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html 6http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
7and rfc1952.txt (gzip format). These documents are also available in other
8formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
7 9
8All functions of the compression library are documented in the file zlib.h 10All functions of the compression library are documented in the file zlib.h
9(volunteer to write man pages welcome, contact jloup@gzip.org). A usage 11(volunteer to write man pages welcome, contact jloup@gzip.org). A usage example
10example of the library is given in the file example.c which also tests that 12of the library is given in the file example.c which also tests that the library
11the library is working correctly. Another example is given in the file 13is working correctly. Another example is given in the file minigzip.c. The
12minigzip.c. The compression library itself is composed of all source files 14compression library itself is composed of all source files except example.c and
13except example.c and minigzip.c. 15minigzip.c.
14 16
15To compile all files and run the test program, follow the instructions 17To compile all files and run the test program, follow the instructions given at
16given at the top of Makefile. In short "make test; make install" 18the top of Makefile. In short "make test; make install" should work for most
17should work for most machines. For Unix: "./configure; make test; make install" 19machines. For Unix: "./configure; make test; make install" For MSDOS, use one
18For MSDOS, use one of the special makefiles such as Makefile.msc. 20of the special makefiles such as Makefile.msc. For VMS, use Make_vms.com or
19For VMS, use Make_vms.com or descrip.mms. 21descrip.mms.
20 22
21Questions about zlib should be sent to <zlib@gzip.org>, or to 23Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
22Gilles Vollant <info@winimage.com> for the Windows DLL version. 24<info@winimage.com> for the Windows DLL version. The zlib home page is
23The zlib home page is http://www.zlib.org or http://www.gzip.org/zlib/ 25http://www.zlib.org or http://www.gzip.org/zlib/ Before reporting a problem,
24Before reporting a problem, please check this site to verify that 26please check this site to verify that you have the latest version of zlib;
25you have the latest version of zlib; otherwise get the latest version and 27otherwise get the latest version and check whether the problem still exists or
26check whether the problem still exists or not. 28not.
27 29
28PLEASE read the zlib FAQ http://www.gzip.org/zlib/zlib_faq.html 30PLEASE read the zlib FAQ http://www.gzip.org/zlib/zlib_faq.html before asking
29before asking for help. 31for help.
30 32
31Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997 33Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
32issue of Dr. Dobb's Journal; a copy of the article is available in 34issue of Dr. Dobb's Journal; a copy of the article is available in
33http://dogma.net/markn/articles/zlibtool/zlibtool.htm 35http://dogma.net/markn/articles/zlibtool/zlibtool.htm
34 36
35The changes made in version 1.2.0 are documented in the file ChangeLog. 37The changes made in version 1.2.0.1 are documented in the file ChangeLog.
36 38
37Unsupported third party contributions are provided in directory "contrib". 39Unsupported third party contributions are provided in directory "contrib".
38 40
@@ -40,56 +42,56 @@ A Java implementation of zlib is available in the Java Development Kit
40http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html 42http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
41See the zlib home page http://www.zlib.org for details. 43See the zlib home page http://www.zlib.org for details.
42 44
43A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> 45A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is in the
44is in the CPAN (Comprehensive Perl Archive Network) sites 46CPAN (Comprehensive Perl Archive Network) sites
45http://www.cpan.org/modules/by-module/Compress/ 47http://www.cpan.org/modules/by-module/Compress/
46 48
47A Python interface to zlib written by A.M. Kuchling <amk@magnet.com> 49A Python interface to zlib written by A.M. Kuchling <amk@magnet.com> is
48is available in Python 1.5 and later versions, see 50available in Python 1.5 and later versions, see
49http://www.python.org/doc/lib/module-zlib.html 51http://www.python.org/doc/lib/module-zlib.html
50 52
51A zlib binding for TCL written by Andreas Kupries <a.kupries@westend.com> 53A zlib binding for TCL written by Andreas Kupries <a.kupries@westend.com> is
52is availlable at http://www.westend.com/~kupries/doc/trf/man/man.html 54availlable at http://www.westend.com/~kupries/doc/trf/man/man.html
53 55
54An experimental package to read and write files in .zip format, 56An experimental package to read and write files in .zip format, written on top
55written on top of zlib by Gilles Vollant <info@winimage.com>, is 57of zlib by Gilles Vollant <info@winimage.com>, is available at
56available at http://www.winimage.com/zLibDll/unzip.html 58http://www.winimage.com/zLibDll/unzip.html and also in the contrib/minizip
57and also in the contrib/minizip directory of zlib. 59directory of zlib.
58 60
59 61
60Notes for some targets: 62Notes for some targets:
61 63
62- To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc 64- To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc
63 and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL 65 and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL The
64 The zlib DLL support was initially done by Alessandro Iacopetti and is 66 zlib DLL support was initially done by Alessandro Iacopetti and is now
65 now maintained by Gilles Vollant <info@winimage.com>. Check the zlib DLL 67 maintained by Gilles Vollant <info@winimage.com>. Check the zlib DLL home
66 home page at http://www.winimage.com/zLibDll 68 page at http://www.winimage.com/zLibDll
67 69
68 From Visual Basic, you can call the DLL functions which do not take 70 From Visual Basic, you can call the DLL functions which do not take a
69 a structure as argument: compress, uncompress and all gz* functions. 71 structure as argument: compress, uncompress and all gz* functions. See
70 See contrib/visual-basic.txt for more information, or get 72 contrib/visual-basic.txt for more information, or get
71 http://www.tcfb.com/dowseware/cmp-z-it.zip 73 http://www.tcfb.com/dowseware/cmp-z-it.zip
72 74
73- For 64-bit Irix, deflate.c must be compiled without any optimization. 75- For 64-bit Irix, deflate.c must be compiled without any optimization. With
74 With -O, one libpng test fails. The test works in 32 bit mode (with 76 -O, one libpng test fails. The test works in 32 bit mode (with the -n32
75 the -n32 compiler flag). The compiler bug has been reported to SGI. 77 compiler flag). The compiler bug has been reported to SGI.
76 78
77- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 79- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
78 it works when compiled with cc. 80 when compiled with cc.
79 81
80- on Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 82- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
81 is necessary to get gzprintf working correctly. This is done by configure. 83 necessary to get gzprintf working correctly. This is done by configure.
82 84
83- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works 85- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
84 with other compilers. Use "make test" to check your compiler. 86 other compilers. Use "make test" to check your compiler.
85 87
86- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers. 88- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.
87 89
88- For Turbo C the small model is supported only with reduced performance to 90- For Turbo C the small model is supported only with reduced performance to
89 avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 91 avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
90 92
91- For PalmOs, see http://www.cs.uit.no/~perm/PASTA/pilot/software.html 93- For PalmOs, see http://www.cs.uit.no/~perm/PASTA/pilot/software.html Per
92 Per Harald Myrvang <perm@stud.cs.uit.no> 94 Harald Myrvang <perm@stud.cs.uit.no>
93 95
94 96
95Acknowledgments: 97Acknowledgments:
@@ -129,4 +131,6 @@ entirely written by Jean-loup Gailly and Mark Adler; it does not
129include third-party code. 131include third-party code.
130 132
131If you redistribute modified sources, we would appreciate that you include 133If you redistribute modified sources, we would appreciate that you include
132in the file ChangeLog history information documenting your changes. 134in the file ChangeLog history information documenting your changes. Please
135read the FAQ for more information on the distribution of modified source
136versions.
diff --git a/adler32.c b/adler32.c
index 319603c..28c65ba 100644
--- a/adler32.c
+++ b/adler32.c
@@ -34,12 +34,12 @@ uLong ZEXPORT adler32(adler, buf, len)
34 len -= k; 34 len -= k;
35 while (k >= 16) { 35 while (k >= 16) {
36 DO16(buf); 36 DO16(buf);
37 buf += 16; 37 buf += 16;
38 k -= 16; 38 k -= 16;
39 } 39 }
40 if (k != 0) do { 40 if (k != 0) do {
41 s1 += *buf++; 41 s1 += *buf++;
42 s2 += s1; 42 s2 += s1;
43 } while (--k); 43 } while (--k);
44 s1 %= BASE; 44 s1 %= BASE;
45 s2 %= BASE; 45 s2 %= BASE;
diff --git a/contrib/README.contrib b/contrib/README.contrib
index fcee020..3579d43 100644
--- a/contrib/README.contrib
+++ b/contrib/README.contrib
@@ -12,7 +12,7 @@ asm586/ and asm686/ by Brian Raiter <breadbox@muppetlabs.com>
12 See http://www.muppetlabs.com/~breadbox/software/assembly.html 12 See http://www.muppetlabs.com/~breadbox/software/assembly.html
13 13
14blast/ by Mark Adler <madler@alumni.caltech.edu> 14blast/ by Mark Adler <madler@alumni.caltech.edu>
15 Decompressor for output of PKWare Data Compression Library 15 Decompressor for output of PKWare Data Compression Library (DCL)
16 16
17delphi/ by Bob Dellaca <bobdl@xtra.co.nz> 17delphi/ by Bob Dellaca <bobdl@xtra.co.nz>
18 Support for Delphi 18 Support for Delphi
@@ -33,8 +33,15 @@ iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
33iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no> 33iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
34 Another C++ I/O streams interface 34 Another C++ I/O streams interface
35 35
36testzlib/ by Gilles Vollant <info@winimage.com>
37 Example of the use of zlib
38
36untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es> 39untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
37 A very simple tar.gz file extractor using zlib 40 A very simple tar.gz file extractor using zlib
38 41
39visual-basic.txt by Carlos Rios <c_rios@sonda.cl> 42visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
40 How to use compress(), uncompress() and the gz* functions from VB. 43 How to use compress(), uncompress() and the gz* functions from VB.
44
45vstudio/ by Gilles Vollant <info@winimage.com>
46 Building zlib DLL with Visual Studio .NET
47 Includes x86 inffast.asm for MASM
diff --git a/contrib/inflate86/inffas86.c b/contrib/inflate86/inffas86.c
new file mode 100644
index 0000000..4534693
--- /dev/null
+++ b/contrib/inflate86/inffas86.c
@@ -0,0 +1,783 @@
1/* inffas86.c is a hand tuned assembler version of
2 *
3 * inffast.c -- fast decoding
4 * Copyright (C) 1995-2003 Mark Adler
5 * For conditions of distribution and use, see copyright notice in zlib.h
6 *
7 * Copyright (C) 2003 Chris Anderson <christop@charm.net>
8 * Please use the copyright conditions above.
9 *
10 * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from
11 * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at
12 * the moment. I have successfully compiled and tested this code with gcc2.96,
13 * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S
14 * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX
15 * enabled. I will attempt to merge the MMX code into this version. Newer
16 * versions of this and inffast.S can be found at
17 * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/
18 */
19
20#include "zutil.h"
21#include "inftrees.h"
22#include "inflate.h"
23#include "inffast.h"
24
25/* Mark Adler's comments from inffast.c: */
26
27/*
28 Decode literal, length, and distance codes and write out the resulting
29 literal and match bytes until either not enough input or output is
30 available, an end-of-block is encountered, or a data error is encountered.
31 When large enough input and output buffers are supplied to inflate(), for
32 example, a 16K input buffer and a 64K output buffer, more than 95% of the
33 inflate execution time is spent in this routine.
34
35 Entry assumptions:
36
37 state->mode == LEN
38 strm->avail_in >= 6
39 strm->avail_out >= 258
40 start >= strm->avail_out
41 state->bits < 8
42
43 On return, state->mode is one of:
44
45 LEN -- ran out of enough output space or enough available input
46 TYPE -- reached end of block code, inflate() to interpret next block
47 BAD -- error in block data
48
49 Notes:
50
51 - The maximum input bits used by a length/distance pair is 15 bits for the
52 length code, 5 bits for the length extra, 15 bits for the distance code,
53 and 13 bits for the distance extra. This totals 48 bits, or six bytes.
54 Therefore if strm->avail_in >= 6, then there is enough input to avoid
55 checking for available input while decoding.
56
57 - The maximum bytes that a single length/distance pair can output is 258
58 bytes, which is the maximum length that can be coded. inflate_fast()
59 requires strm->avail_out >= 258 for each loop to avoid checking for
60 output space.
61 */
62void inflate_fast(strm, start)
63z_streamp strm;
64unsigned start; /* inflate()'s starting value for strm->avail_out */
65{
66 struct inflate_state FAR *state;
67 struct inffast_ar {
68 void *esp; /* esp save */
69 unsigned char FAR *in; /* local strm->next_in */
70 unsigned char FAR *last; /* while in < last, enough input available */
71 unsigned char FAR *out; /* local strm->next_out */
72 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
73 unsigned char FAR *end; /* while out < end, enough space available */
74 unsigned wsize; /* window size or zero if not using window */
75 unsigned write; /* window write index */
76 unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
77 unsigned long hold; /* local strm->hold */
78 unsigned bits; /* local strm->bits */
79 code const FAR *lcode; /* local strm->lencode */
80 code const FAR *dcode; /* local strm->distcode */
81 unsigned lmask; /* mask for first level of length codes */
82 unsigned dmask; /* mask for first level of distance codes */
83 unsigned len; /* match length, unused bytes */
84 unsigned dist; /* match distance */
85 unsigned status; /* this is set when state changes */
86 } ar;
87
88 /* copy state to local variables */
89 state = (struct inflate_state FAR *)strm->state;
90 ar.in = strm->next_in;
91 ar.last = ar.in + (strm->avail_in - 5);
92 ar.out = strm->next_out;
93 ar.beg = ar.out - (start - strm->avail_out);
94 ar.end = ar.out + (strm->avail_out - 257);
95 ar.wsize = state->wsize;
96 ar.write = state->write;
97 ar.window = state->window;
98 ar.hold = state->hold;
99 ar.bits = state->bits;
100 ar.lcode = state->lencode;
101 ar.dcode = state->distcode;
102 ar.lmask = (1U << state->lenbits) - 1;
103 ar.dmask = (1U << state->distbits) - 1;
104
105 /* decode literals and length/distances until end-of-block or not enough
106 input data or output space */
107
108 /* align in on 2 byte boundary */
109 if (((unsigned long)(void *)ar.in & 0x1) != 0) {
110 ar.hold += (unsigned long)*ar.in++ << ar.bits;
111 ar.bits += 8;
112 }
113
114#if defined( __GNUC__ ) || defined( __ICC )
115 __asm__ __volatile__ (
116" leal %0, %%eax\n"
117" pushf\n"
118" pushl %%ebp\n"
119" movl %%esp, (%%eax)\n"
120" movl %%eax, %%esp\n"
121" movl 4(%%esp), %%esi\n" /* esi = in */
122" movl 12(%%esp), %%edi\n" /* edi = out */
123" movl 36(%%esp), %%edx\n" /* edx = hold */
124" movl 40(%%esp), %%ebx\n" /* ebx = bits */
125" movl 44(%%esp), %%ebp\n" /* ebp = lcode */
126
127" cld\n"
128" jmp .L_do_loop\n"
129
130".L_while_test:\n"
131" cmpl %%edi, 20(%%esp)\n"
132" jbe .L_break_loop\n"
133" cmpl %%esi, 8(%%esp)\n"
134" jbe .L_break_loop\n"
135
136".L_do_loop:\n"
137" cmpb $15, %%bl\n"
138" ja .L_get_length_code\n" /* if (15 < bits) */
139
140" xorl %%eax, %%eax\n"
141" lodsw\n" /* al = *(ushort *)in++ */
142" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */
143" addb $16, %%bl\n" /* bits += 16 */
144" shll %%cl, %%eax\n"
145" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */
146
147".L_get_length_code:\n"
148" movl 52(%%esp), %%eax\n" /* eax = lmask */
149" andl %%edx, %%eax\n" /* eax &= hold */
150" movl (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[hold & lmask] */
151
152".L_dolen:\n"
153" movb %%ah, %%cl\n" /* cl = this.bits */
154" subb %%ah, %%bl\n" /* bits -= this.bits */
155" shrl %%cl, %%edx\n" /* hold >>= this.bits */
156
157" testb %%al, %%al\n"
158" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */
159
160" shrl $16, %%eax\n" /* output this.val char */
161" stosb\n"
162" jmp .L_while_test\n"
163
164".L_test_for_length_base:\n"
165" movl %%eax, %%ecx\n" /* len = this */
166" shrl $16, %%ecx\n" /* len = this.val */
167" movl %%ecx, 60(%%esp)\n" /* len = this */
168" movb %%al, %%cl\n"
169
170" testb $16, %%al\n"
171" jz .L_test_for_second_level_length\n" /* if ((op & 16) == 0) 8% */
172" andb $15, %%cl\n" /* op &= 15 */
173" jz .L_decode_distance\n" /* if (!op) */
174" cmpb %%cl, %%bl\n"
175" jae .L_add_bits_to_len\n" /* if (op <= bits) */
176
177" movb %%cl, %%ch\n" /* stash op in ch, freeing cl */
178" xorl %%eax, %%eax\n"
179" lodsw\n" /* al = *(ushort *)in++ */
180" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */
181" addb $16, %%bl\n" /* bits += 16 */
182" shll %%cl, %%eax\n"
183" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */
184" movb %%ch, %%cl\n" /* move op back to ecx */
185
186".L_add_bits_to_len:\n"
187" movl $1, %%eax\n"
188" shll %%cl, %%eax\n"
189" decl %%eax\n"
190" subb %%cl, %%bl\n"
191" andl %%edx, %%eax\n" /* eax &= hold */
192" shrl %%cl, %%edx\n"
193" addl %%eax, 60(%%esp)\n" /* len += hold & mask[op] */
194
195".L_decode_distance:\n"
196" cmpb $15, %%bl\n"
197" ja .L_get_distance_code\n" /* if (15 < bits) */
198
199" xorl %%eax, %%eax\n"
200" lodsw\n" /* al = *(ushort *)in++ */
201" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */
202" addb $16, %%bl\n" /* bits += 16 */
203" shll %%cl, %%eax\n"
204" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */
205
206".L_get_distance_code:\n"
207" movl 56(%%esp), %%eax\n" /* eax = dmask */
208" movl 48(%%esp), %%ecx\n" /* ecx = dcode */
209" andl %%edx, %%eax\n" /* eax &= hold */
210" movl (%%ecx,%%eax,4), %%eax\n"/* eax = dcode[hold & dmask] */
211
212".L_dodist:\n"
213" movl %%eax, %%ebp\n" /* dist = this */
214" shrl $16, %%ebp\n" /* dist = this.val */
215" movb %%ah, %%cl\n"
216" subb %%ah, %%bl\n" /* bits -= this.bits */
217" shrl %%cl, %%edx\n" /* hold >>= this.bits */
218" movb %%al, %%cl\n" /* cl = this.op */
219
220" testb $16, %%al\n" /* if ((op & 16) == 0) */
221" jz .L_test_for_second_level_dist\n"
222" andb $15, %%cl\n" /* op &= 15 */
223" jz .L_check_dist_one\n"
224" cmpb %%cl, %%bl\n"
225" jae .L_add_bits_to_dist\n" /* if (op <= bits) 97.6% */
226
227" movb %%cl, %%ch\n" /* stash op in ch, freeing cl */
228" xorl %%eax, %%eax\n"
229" lodsw\n" /* al = *(ushort *)in++ */
230" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */
231" addb $16, %%bl\n" /* bits += 16 */
232" shll %%cl, %%eax\n"
233" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */
234" movb %%ch, %%cl\n" /* move op back to ecx */
235
236".L_add_bits_to_dist:\n"
237" movl $1, %%eax\n"
238" shll %%cl, %%eax\n"
239" decl %%eax\n" /* (1 << op) - 1 */
240" subb %%cl, %%bl\n"
241" andl %%edx, %%eax\n" /* eax &= hold */
242" shrl %%cl, %%edx\n"
243" addl %%eax, %%ebp\n" /* dist += hold & ((1 << op) - 1) */
244
245".L_check_window:\n"
246" movl %%esi, 4(%%esp)\n" /* save in so from can use it's reg */
247" movl %%edi, %%eax\n"
248" subl 16(%%esp), %%eax\n" /* nbytes = out - beg */
249
250" cmpl %%ebp, %%eax\n"
251" jb .L_clip_window\n" /* if (dist > nbytes) 4.2% */
252
253" movl 60(%%esp), %%ecx\n"
254" movl %%edi, %%esi\n"
255" subl %%ebp, %%esi\n" /* from = out - dist */
256
257" subl $3, %%ecx\n" /* copy from to out */
258" movb (%%esi), %%al\n"
259" movb %%al, (%%edi)\n"
260" movb 1(%%esi), %%al\n"
261" movb 2(%%esi), %%ah\n"
262" addl $3, %%esi\n"
263" movb %%al, 1(%%edi)\n"
264" movb %%ah, 2(%%edi)\n"
265" addl $3, %%edi\n"
266" rep movsb\n"
267
268" movl 4(%%esp), %%esi\n" /* move in back to %esi, toss from */
269" movl 44(%%esp), %%ebp\n" /* ebp = lcode */
270" jmp .L_while_test\n"
271
272".L_check_dist_one:\n"
273" cmpl $1, %%ebp\n" /* if dist 1, is a memset */
274" jne .L_check_window\n"
275" cmpl %%edi, 16(%%esp)\n"
276" je .L_check_window\n"
277
278" decl %%edi\n"
279" movl 60(%%esp), %%ecx\n"
280" movb (%%edi), %%al\n"
281" subl $3, %%ecx\n"
282
283" movb %%al, 1(%%edi)\n" /* memset out with from[-1] */
284" movb %%al, 2(%%edi)\n"
285" movb %%al, 3(%%edi)\n"
286" addl $4, %%edi\n"
287" rep stosb\n"
288" movl 44(%%esp), %%ebp\n" /* ebp = lcode */
289" jmp .L_while_test\n"
290
291".L_test_for_second_level_length:\n"
292" testb $64, %%al\n"
293" jnz .L_test_for_end_of_block\n" /* if ((op & 64) != 0) */
294
295" movl $1, %%eax\n"
296" shll %%cl, %%eax\n"
297" decl %%eax\n"
298" andl %%edx, %%eax\n" /* eax &= hold */
299" addl 60(%%esp), %%eax\n" /* eax += this.val */
300" movl (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[val+(hold&mask[op])]*/
301" jmp .L_dolen\n"
302
303".L_test_for_second_level_dist:\n"
304" testb $64, %%al\n"
305" jnz .L_invalid_distance_code\n" /* if ((op & 64) != 0) */
306
307" movl $1, %%eax\n"
308" shll %%cl, %%eax\n"
309" decl %%eax\n"
310" andl %%edx, %%eax\n" /* eax &= hold */
311" addl %%ebp, %%eax\n" /* eax += this.val */
312" movl 48(%%esp), %%ecx\n" /* ecx = dcode */
313" movl (%%ecx,%%eax,4), %%eax\n" /* eax = dcode[val+(hold&mask[op])]*/
314" jmp .L_dodist\n"
315
316".L_clip_window:\n"
317" movl %%eax, %%ecx\n"
318" movl 24(%%esp), %%eax\n" /* prepare for dist compare */
319" negl %%ecx\n" /* nbytes = -nbytes */
320" movl 32(%%esp), %%esi\n" /* from = window */
321
322" cmpl %%ebp, %%eax\n"
323" jb .L_invalid_distance_too_far\n" /* if (dist > wsize) */
324
325" addl %%ebp, %%ecx\n" /* nbytes = dist - nbytes */
326" cmpl $0, 28(%%esp)\n"
327" jne .L_wrap_around_window\n" /* if (write != 0) */
328
329" subl %%ecx, %%eax\n"
330" addl %%eax, %%esi\n" /* from += wsize - nbytes */
331
332" movl 60(%%esp), %%eax\n"
333" cmpl %%ecx, %%eax\n"
334" jbe .L_do_copy1\n" /* if (nbytes >= len) */
335
336" subl %%ecx, %%eax\n" /* len -= nbytes */
337" rep movsb\n"
338" movl %%edi, %%esi\n"
339" subl %%ebp, %%esi\n" /* from = out - dist */
340" jmp .L_do_copy1\n"
341
342" cmpl %%ecx, %%eax\n"
343" jbe .L_do_copy1\n" /* if (nbytes >= len) */
344
345" subl %%ecx, %%eax\n" /* len -= nbytes */
346" rep movsb\n"
347" movl %%edi, %%esi\n"
348" subl %%ebp, %%esi\n" /* from = out - dist */
349" jmp .L_do_copy1\n"
350
351".L_wrap_around_window:\n"
352" movl 28(%%esp), %%eax\n"
353" cmpl %%eax, %%ecx\n"
354" jbe .L_contiguous_in_window\n" /* if (write >= nbytes) */
355
356" addl 24(%%esp), %%esi\n"
357" addl %%eax, %%esi\n"
358" subl %%ecx, %%esi\n" /* from += wsize + write - nbytes */
359" subl %%eax, %%ecx\n" /* nbytes -= write */
360
361" movl 60(%%esp), %%eax\n"
362" cmpl %%ecx, %%eax\n"
363" jbe .L_do_copy1\n" /* if (nbytes >= len) */
364
365" subl %%ecx, %%eax\n" /* len -= nbytes */
366" rep movsb\n"
367" movl 32(%%esp), %%esi\n" /* from = window */
368" movl 28(%%esp), %%ecx\n" /* nbytes = write */
369" cmpl %%ecx, %%eax\n"
370" jbe .L_do_copy1\n" /* if (nbytes >= len) */
371
372" subl %%ecx, %%eax\n" /* len -= nbytes */
373" rep movsb\n"
374" movl %%edi, %%esi\n"
375" subl %%ebp, %%esi\n" /* from = out - dist */
376" jmp .L_do_copy1\n"
377
378".L_contiguous_in_window:\n"
379" addl %%eax, %%esi\n"
380" subl %%ecx, %%esi\n" /* from += write - nbytes */
381
382" movl 60(%%esp), %%eax\n"
383" cmpl %%ecx, %%eax\n"
384" jbe .L_do_copy1\n" /* if (nbytes >= len) */
385
386" subl %%ecx, %%eax\n" /* len -= nbytes */
387" rep movsb\n"
388" movl %%edi, %%esi\n"
389" subl %%ebp, %%esi\n" /* from = out - dist */
390
391".L_do_copy1:\n"
392" movl %%eax, %%ecx\n"
393" rep movsb\n"
394
395" movl 4(%%esp), %%esi\n" /* move in back to %esi, toss from */
396" movl 44(%%esp), %%ebp\n" /* ebp = lcode */
397" jmp .L_while_test\n"
398
399".L_test_for_end_of_block:\n"
400" testb $32, %%al\n"
401" jz .L_invalid_literal_length_code\n"
402" movl $1, 68(%%esp)\n"
403" jmp .L_break_loop_with_status\n"
404
405".L_invalid_literal_length_code:\n"
406" movl $2, 68(%%esp)\n"
407" jmp .L_break_loop_with_status\n"
408
409".L_invalid_distance_code:\n"
410" movl $3, 68(%%esp)\n"
411" jmp .L_break_loop_with_status\n"
412
413".L_invalid_distance_too_far:\n"
414" movl 4(%%esp), %%esi\n"
415" movl $4, 68(%%esp)\n"
416" jmp .L_break_loop_with_status\n"
417
418".L_break_loop:\n"
419" movl $0, 68(%%esp)\n"
420
421".L_break_loop_with_status:\n"
422/* put in, out, bits, and hold back into ar and pop esp */
423" movl %%esi, 4(%%esp)\n"
424" movl %%edi, 12(%%esp)\n"
425" movl %%ebx, 40(%%esp)\n"
426" movl %%edx, 36(%%esp)\n"
427" movl (%%esp), %%esp\n"
428" popl %%ebp\n"
429" popf\n"
430 :
431 : "m" (ar)
432 : "memory", "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
433 );
434#elif defined( _MSC_VER )
435 __asm {
436 lea eax, ar
437 pushfd
438 push ebp
439 mov [eax], esp
440 mov esp, eax
441 mov esi, [esp+4] /* esi = in */
442 mov edi, [esp+12] /* edi = out */
443 mov edx, [esp+36] /* edx = hold */
444 mov ebx, [esp+40] /* ebx = bits */
445 mov ebp, [esp+44] /* ebp = lcode */
446
447 cld
448 jmp L_do_loop
449
450L_while_test:
451 cmp [esp+20], edi
452 jbe L_break_loop
453 cmp [esp+8], esi
454 jbe L_break_loop
455
456L_do_loop:
457 cmp bl, 15
458 ja L_get_length_code /* if (15 < bits) */
459
460 xor eax, eax
461 lodsw /* al = *(ushort *)in++ */
462 mov cl, bl /* cl = bits, needs it for shifting */
463 add bl, 16 /* bits += 16 */
464 shl eax, cl
465 or edx, eax /* hold |= *((ushort *)in)++ << bits */
466
467L_get_length_code:
468 mov eax, [esp+52] /* eax = lmask */
469 and eax, edx /* eax &= hold */
470 mov eax, [ebp+eax*4] /* eax = lcode[hold & lmask] */
471
472L_dolen:
473 mov cl, ah /* cl = this.bits */
474 sub bl, ah /* bits -= this.bits */
475 shr edx, cl /* hold >>= this.bits */
476
477 test al, al
478 jnz L_test_for_length_base /* if (op != 0) 45.7% */
479
480 shr eax, 16 /* output this.val char */
481 stosb
482 jmp L_while_test
483
484L_test_for_length_base:
485 mov ecx, eax /* len = this */
486 shr ecx, 16 /* len = this.val */
487 mov [esp+60], ecx /* len = this */
488 mov cl, al
489
490 test al, 16
491 jz L_test_for_second_level_length /* if ((op & 16) == 0) 8% */
492 and cl, 15 /* op &= 15 */
493 jz L_decode_distance /* if (!op) */
494 cmp bl, cl
495 jae L_add_bits_to_len /* if (op <= bits) */
496
497 mov ch, cl /* stash op in ch, freeing cl */
498 xor eax, eax
499 lodsw /* al = *(ushort *)in++ */
500 mov cl, bl /* cl = bits, needs it for shifting */
501 add bl, 16 /* bits += 16 */
502 shl eax, cl
503 or edx, eax /* hold |= *((ushort *)in)++ << bits */
504 mov cl, ch /* move op back to ecx */
505
506L_add_bits_to_len:
507 mov eax, 1
508 shl eax, cl
509 dec eax
510 sub bl, cl
511 and eax, edx /* eax &= hold */
512 shr edx, cl
513 add [esp+60], eax /* len += hold & mask[op] */
514
515L_decode_distance:
516 cmp bl, 15
517 ja L_get_distance_code /* if (15 < bits) */
518
519 xor eax, eax
520 lodsw /* al = *(ushort *)in++ */
521 mov cl, bl /* cl = bits, needs it for shifting */
522 add bl, 16 /* bits += 16 */
523 shl eax, cl
524 or edx, eax /* hold |= *((ushort *)in)++ << bits */
525
526L_get_distance_code:
527 mov eax, [esp+56] /* eax = dmask */
528 mov ecx, [esp+48] /* ecx = dcode */
529 and eax, edx /* eax &= hold */
530 mov eax, [ecx+eax*4]/* eax = dcode[hold & dmask] */
531
532L_dodist:
533 mov ebp, eax /* dist = this */
534 shr ebp, 16 /* dist = this.val */
535 mov cl, ah
536 sub bl, ah /* bits -= this.bits */
537 shr edx, cl /* hold >>= this.bits */
538 mov cl, al /* cl = this.op */
539
540 test al, 16 /* if ((op & 16) == 0) */
541 jz L_test_for_second_level_dist
542 and cl, 15 /* op &= 15 */
543 jz L_check_dist_one
544 cmp bl, cl
545 jae L_add_bits_to_dist /* if (op <= bits) 97.6% */
546
547 mov ch, cl /* stash op in ch, freeing cl */
548 xor eax, eax
549 lodsw /* al = *(ushort *)in++ */
550 mov cl, bl /* cl = bits, needs it for shifting */
551 add bl, 16 /* bits += 16 */
552 shl eax, cl
553 or edx, eax /* hold |= *((ushort *)in)++ << bits */
554 mov cl, ch /* move op back to ecx */
555
556L_add_bits_to_dist:
557 mov eax, 1
558 shl eax, cl
559 dec eax /* (1 << op) - 1 */
560 sub bl, cl
561 and eax, edx /* eax &= hold */
562 shr edx, cl
563 add ebp, eax /* dist += hold & ((1 << op) - 1) */
564
565L_check_window:
566 mov [esp+4], esi /* save in so from can use it's reg */
567 mov eax, edi
568 sub eax, [esp+16] /* nbytes = out - beg */
569
570 cmp eax, ebp
571 jb L_clip_window /* if (dist > nbytes) 4.2% */
572
573 mov ecx, [esp+60]
574 mov esi, edi
575 sub esi, ebp /* from = out - dist */
576
577 sub ecx, 3 /* copy from to out */
578 mov al, [esi]
579 mov [edi], al
580 mov al, [esi+1]
581 mov ah, [esi+2]
582 add esi, 3
583 mov [edi+1], al
584 mov [edi+2], ah
585 add edi, 3
586 rep movsb
587
588 mov esi, [esp+4] /* move in back to %esi, toss from */
589 mov ebp, [esp+44] /* ebp = lcode */
590 jmp L_while_test
591
592L_check_dist_one:
593 cmp ebp, 1 /* if dist 1, is a memset */
594 jne L_check_window
595 cmp [esp+16], edi
596 je L_check_window
597
598 dec edi
599 mov ecx, [esp+60]
600 mov al, [edi]
601 sub ecx, 3
602
603 mov [edi+1], al /* memset out with from[-1] */
604 mov [edi+2], al
605 mov [edi+3], al
606 add edi, 4
607 rep stosb
608 mov ebp, [esp+44] /* ebp = lcode */
609 jmp L_while_test
610
611L_test_for_second_level_length:
612 test al, 64
613 jnz L_test_for_end_of_block /* if ((op & 64) != 0) */
614
615 mov eax, 1
616 shl eax, cl
617 dec eax
618 and eax, edx /* eax &= hold */
619 add eax, [esp+60] /* eax += this.val */
620 mov eax, [ebp+eax*4] /* eax = lcode[val+(hold&mask[op])]*/
621 jmp L_dolen
622
623L_test_for_second_level_dist:
624 test al, 64
625 jnz L_invalid_distance_code /* if ((op & 64) != 0) */
626
627 mov eax, 1
628 shl eax, cl
629 dec eax
630 and eax, edx /* eax &= hold */
631 add eax, ebp /* eax += this.val */
632 mov ecx, [esp+48] /* ecx = dcode */
633 mov eax, [ecx+eax*4] /* eax = dcode[val+(hold&mask[op])]*/
634 jmp L_dodist
635
636L_clip_window:
637 mov ecx, eax
638 mov eax, [esp+24] /* prepare for dist compare */
639 neg ecx /* nbytes = -nbytes */
640 mov esi, [esp+32] /* from = window */
641
642 cmp eax, ebp
643 jb L_invalid_distance_too_far /* if (dist > wsize) */
644
645 add ecx, ebp /* nbytes = dist - nbytes */
646 cmp dword ptr [esp+28], 0
647 jne L_wrap_around_window /* if (write != 0) */
648
649 sub eax, ecx
650 add esi, eax /* from += wsize - nbytes */
651
652 mov eax, [esp+60]
653 cmp eax, ecx
654 jbe L_do_copy1 /* if (nbytes >= len) */
655
656 sub eax, ecx /* len -= nbytes */
657 rep movsb
658 mov esi, edi
659 sub esi, ebp /* from = out - dist */
660 jmp L_do_copy1
661
662 cmp eax, ecx
663 jbe L_do_copy1 /* if (nbytes >= len) */
664
665 sub eax, ecx /* len -= nbytes */
666 rep movsb
667 mov esi, edi
668 sub esi, ebp /* from = out - dist */
669 jmp L_do_copy1
670
671L_wrap_around_window:
672 mov eax, [esp+28]
673 cmp ecx, eax
674 jbe L_contiguous_in_window /* if (write >= nbytes) */
675
676 add esi, [esp+24]
677 add esi, eax
678 sub esi, ecx /* from += wsize + write - nbytes */
679 sub ecx, eax /* nbytes -= write */
680
681 mov eax, [esp+60]
682 cmp eax, ecx
683 jbe L_do_copy1 /* if (nbytes >= len) */
684
685 sub eax, ecx /* len -= nbytes */
686 rep movsb
687 mov esi, [esp+32] /* from = window */
688 mov ecx, [esp+28] /* nbytes = write */
689 cmp eax, ecx
690 jbe L_do_copy1 /* if (nbytes >= len) */
691
692 sub eax, ecx /* len -= nbytes */
693 rep movsb
694 mov esi, edi
695 sub esi, ebp /* from = out - dist */
696 jmp L_do_copy1
697
698L_contiguous_in_window:
699 add esi, eax
700 sub esi, ecx /* from += write - nbytes */
701
702 mov eax, [esp+60]
703 cmp eax, ecx
704 jbe L_do_copy1 /* if (nbytes >= len) */
705
706 sub eax, ecx /* len -= nbytes */
707 rep movsb
708 mov esi, edi
709 sub esi, ebp /* from = out - dist */
710
711L_do_copy1:
712 mov ecx, eax
713 rep movsb
714
715 mov esi, [esp+4] /* move in back to %esi, toss from */
716 mov ebp, [esp+44] /* ebp = lcode */
717 jmp L_while_test
718
719L_test_for_end_of_block:
720 test al, 32
721 jz L_invalid_literal_length_code
722 mov dword ptr [esp+68], 1
723 jmp L_break_loop_with_status
724
725L_invalid_literal_length_code:
726 mov dword ptr [esp+68], 2
727 jmp L_break_loop_with_status
728
729L_invalid_distance_code:
730 mov dword ptr [esp+68], 3
731 jmp L_break_loop_with_status
732
733L_invalid_distance_too_far:
734 mov esi, [esp+4]
735 mov dword ptr [esp+68], 4
736 jmp L_break_loop_with_status
737
738L_break_loop:
739 mov dword ptr [esp+68], 0
740
741L_break_loop_with_status:
742/* put in, out, bits, and hold back into ar and pop esp */
743 mov [esp+4], esi
744 mov [esp+12], edi
745 mov [esp+40], ebx
746 mov [esp+36], edx
747 mov esp, [esp]
748 pop ebp
749 popfd
750 }
751#endif
752
753 if (ar.status > 1) {
754 if (ar.status == 2)
755 strm->msg = "invalid literal/length code";
756 else if (ar.status == 3)
757 strm->msg = "invalid distance code";
758 else
759 strm->msg = "invalid distance too far back";
760 state->mode = BAD;
761 }
762 else if ( ar.status == 1 ) {
763 state->mode = TYPE;
764 }
765
766 /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
767 ar.len = ar.bits >> 3;
768 ar.in -= ar.len;
769 ar.bits -= ar.len << 3;
770 ar.hold &= (1U << ar.bits) - 1;
771
772 /* update state and return */
773 strm->next_in = ar.in;
774 strm->next_out = ar.out;
775 strm->avail_in = (unsigned)(ar.in < ar.last ? 5 + (ar.last - ar.in) :
776 5 - (ar.in - ar.last));
777 strm->avail_out = (unsigned)(ar.out < ar.end ? 257 + (ar.end - ar.out) :
778 257 - (ar.out - ar.end));
779 state->hold = ar.hold;
780 state->bits = ar.bits;
781 return;
782}
783
diff --git a/contrib/inflate86/inffast.S b/contrib/inflate86/inffast.S
index d1e80ef..3602907 100644
--- a/contrib/inflate86/inffast.S
+++ b/contrib/inflate86/inffast.S
@@ -1,1095 +1,1377 @@
1/* 1/*
2 * inffast.S is a hand tuned assembler version of: 2 * inffast.S is a hand tuned assembler version of:
3 * 3 *
4 * inffast.c -- fast decoding 4 * inffast.c -- fast decoding
5 * Copyright (C) 1995-2003 Mark Adler 5 * Copyright (C) 1995-2003 Mark Adler
6 * For conditions of distribution and use, see copyright notice in zlib.h 6 * For conditions of distribution and use, see copyright notice in zlib.h
7 * 7 *
8 * Copyright (C) 2003 Chris Anderson <christop@charm.net> 8 * Copyright (C) 2003 Chris Anderson <christop@charm.net>
9 * Please use the copyright conditions above. 9 * Please use the copyright conditions above.
10 * 10 *
11 * This version (Jan-23-2003) of inflate_fast was coded and tested under 11 * This version (Jan-23-2003) of inflate_fast was coded and tested under
12 * GNU/Linux on a pentium 3, using the gcc-3.2 compiler distribution. On that 12 * GNU/Linux on a pentium 3, using the gcc-3.2 compiler distribution. On that
13 * machine, I found that gzip style archives decompressed about 20% faster than 13 * machine, I found that gzip style archives decompressed about 20% faster than
14 * the gcc-3.2 -O3 -fomit-frame-pointer compiled version. Your results will 14 * the gcc-3.2 -O3 -fomit-frame-pointer compiled version. Your results will
15 * depend on how large of a buffer is used for z_stream.next_in & next_out 15 * depend on how large of a buffer is used for z_stream.next_in & next_out
16 * (8K-32K worked best for my 256K cpu cache) and how much overhead there is in 16 * (8K-32K worked best for my 256K cpu cache) and how much overhead there is in
17 * stream processing I/O and crc32/addler32. In my case, this routine used 17 * stream processing I/O and crc32/addler32. In my case, this routine used
18 * 70% of the cpu time and crc32 used 20%. 18 * 70% of the cpu time and crc32 used 20%.
19 * 19 *
20 * I am confident that this version will work in the general case, but I have 20 * I am confident that this version will work in the general case, but I have
21 * not tested a wide variety of datasets or a wide variety of platforms. 21 * not tested a wide variety of datasets or a wide variety of platforms.
22 * 22 *
23 * Jan-24-2003 -- Added -DUSE_MMX define for slightly faster inflating. 23 * Jan-24-2003 -- Added -DUSE_MMX define for slightly faster inflating.
24 * It should be a runtime flag instead of compile time flag... 24 * It should be a runtime flag instead of compile time flag...
25 */ 25 *
26 26 * Jan-26-2003 -- Added runtime check for MMX support with cpuid instruction.
27.file "inffast.S" 27 * With -DUSE_MMX, only MMX code is compiled. With -DNO_MMX, only non-MMX code
28 28 * is compiled. Without either option, runtime detection is enabled. Runtime
29.globl inflate_fast 29 * detection should work on all modern cpus and the recomended algorithm (flip
30 30 * ID bit on eflags and then use the cpuid instruction) is used in many
31.text 31 * multimedia applications. Tested under win2k with gcc-2.95 and gas-2.12
32.align 4,0 32 * distributed with cygwin3. Compiling with gcc-2.95 -c inffast.S -o
33.L_invalid_literal_length_code_msg: 33 * inffast.obj generates a COFF object which can then be linked with MSVC++
34.string "invalid literal/length code" 34 * compiled code. Tested under FreeBSD 4.7 with gcc-2.95.
35 35 *
36.align 4,0 36 * Jan-28-2003 -- Tested Athlon XP... MMX mode is slower than no MMX (and
37.L_invalid_distance_code_msg: 37 * slower than compiler generated code). Adjusted cpuid check to use the MMX
38.string "invalid distance code" 38 * code only for Pentiums < P4 until I have more data on the P4. Speed
39 39 * improvment is only about 15% on the Athlon when compared with code generated
40.align 4,0 40 * with MSVC++. Not sure yet, but I think the P4 will also be slower using the
41.L_invalid_distance_too_far_msg: 41 * MMX mode because many of it's x86 ALU instructions execute in .5 cycles and
42.string "invalid distance too far back" 42 * have less latency than MMX ops. Added code to buffer the last 11 bytes of
43 43 * the input stream since the MMX code grabs bits in chunks of 32, which
44#if defined( USE_MMX ) 44 * differs from the inffast.c algorithm. I don't think there would have been
45.align 4,0 45 * read overruns where a page boundary was crossed (a segfault), but there
46.L_mask: /* mask[N] = ( 1 << N ) - 1 */ 46 * could have been overruns when next_in ends on unaligned memory (unintialized
47.long 0 47 * memory read).
48.long 1 48 *
49.long 3 49 * Mar-13-2003 -- P4 MMX is slightly slower than P4 NO_MMX. I created a C
50.long 7 50 * version of the non-MMX code so that it doesn't depend on zstrm and zstate
51.long 15 51 * structure offsets which are hard coded in this file. This was last tested
52.long 31 52 * with zlib-1.2.0 which is currently in beta testing, newer versions of this
53.long 63 53 * and inffas86.c can be found at http://www.eetbeetee.com/zlib/ and
54.long 127 54 * http://www.charm.net/~christop/zlib/
55.long 255 55 */
56.long 511 56
57.long 1023 57
58.long 2047 58/*
59.long 4095 59 * if you have underscore linking problems (_inflate_fast undefined), try
60.long 8191 60 * using -DGAS_COFF
61.long 16383 61 */
62.long 32767 62#if ! defined( GAS_COFF ) && ! defined( GAS_ELF )
63.long 65535 63
64.long 131071 64#if defined( __CYGWIN__ )
65.long 262143 65#define GAS_COFF /* windows object format */
66.long 524287 66#else
67.long 1048575 67#define GAS_ELF
68.long 2097151 68#endif
69.long 4194303 69
70.long 8388607 70#endif /* ! GAS_COFF && ! GAS_ELF */
71.long 16777215 71
72.long 33554431 72
73.long 67108863 73#if defined( GAS_COFF )
74.long 134217727 74
75.long 268435455 75/* coff externals have underscores */
76.long 536870911 76#define inflate_fast _inflate_fast
77.long 1073741823 77#define inflate_fast_use_mmx _inflate_fast_use_mmx
78.long 2147483647 78
79.long 4294967295 79#endif /* GAS_COFF */
80#endif 80
81 81
82.text 82.file "inffast.S"
83 83
84/* 84.globl inflate_fast
85 * struct z_stream offsets, in zlib.h 85
86 */ 86.text
87#define next_in_strm 0 /* strm->next_in */ 87.align 4,0
88#define avail_in_strm 4 /* strm->avail_in */ 88.L_invalid_literal_length_code_msg:
89#define next_out_strm 12 /* strm->next_out */ 89.string "invalid literal/length code"
90#define avail_out_strm 16 /* strm->avail_out */ 90
91#define msg_strm 24 /* strm->msg */ 91.align 4,0
92#define state_strm 28 /* strm->state */ 92.L_invalid_distance_code_msg:
93 93.string "invalid distance code"
94/* 94
95 * struct inflate_state offsets, in inflate.h 95.align 4,0
96 */ 96.L_invalid_distance_too_far_msg:
97#define mode_state 0 /* state->mode */ 97.string "invalid distance too far back"
98#define wsize_state 32 /* state->wsize */ 98
99#define write_state 36 /* state->write */ 99#if ! defined( NO_MMX )
100#define window_state 40 /* state->window */ 100.align 4,0
101#define hold_state 44 /* state->hold */ 101.L_mask: /* mask[N] = ( 1 << N ) - 1 */
102#define bits_state 48 /* state->bits */ 102.long 0
103#define lencode_state 64 /* state->lencode */ 103.long 1
104#define distcode_state 68 /* state->distcode */ 104.long 3
105#define lenbits_state 72 /* state->lenbits */ 105.long 7
106#define distbits_state 76 /* state->distbits */ 106.long 15
107 107.long 31
108/* 108.long 63
109 * inflate_fast's activation record 109.long 127
110 */ 110.long 255
111#define local_var_size 56 /* how much local space for vars */ 111.long 511
112#define strm_sp 80 /* first arg: z_stream * (local_var_size + 24) */ 112.long 1023
113#define start_sp 84 /* second arg: unsigned int (local_var_size + 28) */ 113.long 2047
114 114.long 4095
115/* 115.long 8191
116 * offsets for local vars on stack 116.long 16383
117 */ 117.long 32767
118#define out 52 /* unsigned char* */ 118.long 65535
119#define window 48 /* unsigned char* */ 119.long 131071
120#define wsize 44 /* unsigned int */ 120.long 262143
121#define write 40 /* unsigned int */ 121.long 524287
122#define in 36 /* unsigned char* */ 122.long 1048575
123#define beg 32 /* unsigned char* */ 123.long 2097151
124#define dist 28 /* unsigned int */ 124.long 4194303
125#define len 24 /* unsigned int */ 125.long 8388607
126#define last 20 /* unsigned char* */ 126.long 16777215
127#define end 16 /* unsigned char* */ 127.long 33554431
128#define dcode 12 /* code* */ 128.long 67108863
129#define lcode 8 /* code* */ 129.long 134217727
130#define dmask 4 /* unsigned int */ 130.long 268435455
131#define lmask 0 /* unsigned int */ 131.long 536870911
132 132.long 1073741823
133/* 133.long 2147483647
134 * typedef enum inflate_mode consts, in inflate.h 134.long 4294967295
135 */ 135#endif /* NO_MMX */
136#ifndef NO_GUNZIP 136
137#define GUNZIP 137.text
138#endif 138
139 139/*
140#ifdef GUNZIP 140 * struct z_stream offsets, in zlib.h
141#define INFLATE_MODE_TYPE 11 /* state->mode flags enum-ed in inflate.h */ 141 */
142#define INFLATE_MODE_BAD 26 142#define next_in_strm 0 /* strm->next_in */
143#else 143#define avail_in_strm 4 /* strm->avail_in */
144#define INFLATE_MODE_TYPE 3 144#define next_out_strm 12 /* strm->next_out */
145#define INFLATE_MODE_BAD 17 145#define avail_out_strm 16 /* strm->avail_out */
146#endif 146#define msg_strm 24 /* strm->msg */
147 147#define state_strm 28 /* strm->state */
148 148
149.align 16,0x90 149/*
150inflate_fast: 150 * struct inflate_state offsets, in inflate.h
151 pushl %edi 151 */
152 pushl %esi 152#define mode_state 0 /* state->mode */
153 pushl %ebp 153#define wsize_state 32 /* state->wsize */
154 pushl %ebx 154#define write_state 36 /* state->write */
155 pushf /* save eflags (strm_sp, state_sp assumes this is 32 bits) */ 155#define window_state 40 /* state->window */
156 subl $local_var_size, %esp 156#define hold_state 44 /* state->hold */
157 cld 157#define bits_state 48 /* state->bits */
158#if defined( USE_MMX ) 158#define lencode_state 64 /* state->lencode */
159 emms 159#define distcode_state 68 /* state->distcode */
160#endif 160#define lenbits_state 72 /* state->lenbits */
161 161#define distbits_state 76 /* state->distbits */
162#define strm_r %esi 162
163#define state_r %edi 163/*
164 164 * inflate_fast's activation record
165 movl strm_sp(%esp), strm_r 165 */
166 movl state_strm(strm_r), state_r 166#define local_var_size 64 /* how much local space for vars */
167 167#define strm_sp 88 /* first arg: z_stream * (local_var_size + 24) */
168 /* in = strm->next_in; 168#define start_sp 92 /* second arg: unsigned int (local_var_size + 28) */
169 * out = strm->next_out; 169
170 * last = in + strm->avail_in - 5; 170/*
171 * beg = out - (start - strm->avail_out); 171 * offsets for local vars on stack
172 * end = out + (strm->avail_out - 257); 172 */
173 */ 173#define out 60 /* unsigned char* */
174 movl next_in_strm(strm_r), %eax 174#define window 56 /* unsigned char* */
175 movl next_out_strm(strm_r), %ebx 175#define wsize 52 /* unsigned int */
176 movl avail_in_strm(strm_r), %edx 176#define write 48 /* unsigned int */
177 movl avail_out_strm(strm_r), %ecx 177#define in 44 /* unsigned char* */
178 movl start_sp(%esp), %ebp 178#define beg 40 /* unsigned char* */
179 179#define buf 28 /* char[ 12 ] */
180 addl %eax, %edx /* avail_in += next_in */ 180#define len 24 /* unsigned int */
181 subl $5, %edx /* avail_in -= 5 */ 181#define last 20 /* unsigned char* */
182 182#define end 16 /* unsigned char* */
183 subl %ecx, %ebp /* start -= avail_out */ 183#define dcode 12 /* code* */
184 negl %ebp /* start = -start */ 184#define lcode 8 /* code* */
185 addl %ebx, %ebp /* start += next_out */ 185#define dmask 4 /* unsigned int */
186 186#define lmask 0 /* unsigned int */
187 subl $257, %ecx /* avail_out -= 257 */ 187
188 addl %ebx, %ecx /* avail_out += out */ 188/*
189 189 * typedef enum inflate_mode consts, in inflate.h
190 movl %eax, in(%esp) 190 */
191 movl %ebx, out(%esp) 191#ifndef NO_GUNZIP
192 movl %edx, last(%esp) 192#define GUNZIP
193 movl %ebp, beg(%esp) 193#endif
194 movl %ecx, end(%esp) 194
195 195#ifdef GUNZIP
196 /* wsize = state->wsize; 196#define INFLATE_MODE_TYPE 11 /* state->mode flags enum-ed in inflate.h */
197 * write = state->write; 197#define INFLATE_MODE_BAD 26
198 * window = state->window; 198#else
199 * hold = state->hold; 199#define INFLATE_MODE_TYPE 3
200 * bits = state->bits; 200#define INFLATE_MODE_BAD 17
201 * lcode = state->lencode; 201#endif
202 * dcode = state->distcode; 202
203 * lmask = ( 1 << state->lenbits ) - 1; 203
204 * dmask = ( 1 << state->distbits ) - 1; 204#if ! defined( USE_MMX ) && ! defined( NO_MMX )
205 */ 205
206 206#define RUN_TIME_MMX
207 movl lencode_state(state_r), %eax 207
208 movl distcode_state(state_r), %ecx 208#define CHECK_MMX 1
209 209#define DO_USE_MMX 2
210 movl %eax, lcode(%esp) 210#define DONT_USE_MMX 3
211 movl %ecx, dcode(%esp) 211
212 212.globl inflate_fast_use_mmx
213 movl $1, %eax 213
214 movl lenbits_state(state_r), %ecx 214.data
215 shll %cl, %eax 215
216 decl %eax 216.align 4,0
217 movl %eax, lmask(%esp) 217inflate_fast_use_mmx: /* integer flag for run time control 1=check,2=mmx,3=no */
218 218.long CHECK_MMX
219 movl $1, %eax 219
220 movl distbits_state(state_r), %ecx 220#if defined( GAS_ELF )
221 shll %cl, %eax 221/* elf info */
222 decl %eax 222.type inflate_fast_use_mmx,@object
223 movl %eax, dmask(%esp) 223.size inflate_fast_use_mmx,4
224 224#endif
225 movl wsize_state(state_r), %eax 225
226 movl write_state(state_r), %ecx 226#endif /* RUN_TIME_MMX */
227 movl window_state(state_r), %edx 227
228 228#if defined( GAS_COFF )
229 movl %eax, wsize(%esp) 229/* coff info: scl 2 = extern, type 32 = function */
230 movl %ecx, write(%esp) 230.def inflate_fast; .scl 2; .type 32; .endef
231 movl %edx, window(%esp) 231#endif
232 232
233#if ! defined( USE_MMX ) 233.text
234 234
235#define hold_r %ebp 235.align 32,0x90
236#define bits_r %bl 236inflate_fast:
237#define bitslong_r %ebx 237 pushl %edi
238 238 pushl %esi
239 movl hold_state(state_r), hold_r 239 pushl %ebp
240 movl bits_state(state_r), bitslong_r 240 pushl %ebx
241 241 pushf /* save eflags (strm_sp, state_sp assumes this is 32 bits) */
242#else /* USE_MMX */ 242 subl $local_var_size, %esp
243 243 cld
244#define hold_mm %mm0 244
245#define bits_r %ebp 245#define strm_r %esi
246#define bitslong_r %ebp 246#define state_r %edi
247 247
248 movl hold_state(state_r), %ebx 248 movl strm_sp(%esp), strm_r
249 movl bits_state(state_r), bitslong_r 249 movl state_strm(strm_r), state_r
250 250
251#endif 251 /* in = strm->next_in;
252 252 * out = strm->next_out;
253#undef strm_r 253 * last = in + strm->avail_in - 11;
254#undef state_r 254 * beg = out - (start - strm->avail_out);
255#define in_r %esi 255 * end = out + (strm->avail_out - 257);
256#define from_r %esi 256 */
257#define out_r %edi 257 movl avail_in_strm(strm_r), %edx
258 258 movl next_in_strm(strm_r), %eax
259 movl in(%esp), in_r 259
260 260 addl %eax, %edx /* avail_in += next_in */
261#if ! defined ( USE_MMX ) 261 subl $11, %edx /* avail_in -= 11 */
262 262
263 /* align in_r on word boundary */ 263 movl %eax, in(%esp)
264 testl $1, in_r 264 movl %edx, last(%esp)
265 jz .L_is_aligned 265
266 xorl %eax, %eax 266 movl start_sp(%esp), %ebp
267 movb (in_r), %al 267 movl avail_out_strm(strm_r), %ecx
268 incl in_r 268 movl next_out_strm(strm_r), %ebx
269 movb bits_r, %cl 269
270 addb $8, bits_r 270 subl %ecx, %ebp /* start -= avail_out */
271 shll %cl, %eax 271 negl %ebp /* start = -start */
272 orl %eax, hold_r 272 addl %ebx, %ebp /* start += next_out */
273 273
274#else 274 subl $257, %ecx /* avail_out -= 257 */
275 /* align in_r on long boundary */ 275 addl %ebx, %ecx /* avail_out += out */
276.L_align_long: 276
277 testl $3, in_r 277 movl %ebx, out(%esp)
278 jz .L_is_aligned 278 movl %ebp, beg(%esp)
279 xorl %eax, %eax 279 movl %ecx, end(%esp)
280 movb (in_r), %al 280
281 incl in_r 281 /* wsize = state->wsize;
282 movl bits_r, %ecx 282 * write = state->write;
283 addl $8, bits_r 283 * window = state->window;
284 shll %cl, %eax 284 * hold = state->hold;
285 orl %eax, %ebx 285 * bits = state->bits;
286 jmp .L_align_long 286 * lcode = state->lencode;
287 287 * dcode = state->distcode;
288#endif 288 * lmask = ( 1 << state->lenbits ) - 1;
289 289 * dmask = ( 1 << state->distbits ) - 1;
290.L_is_aligned: 290 */
291 movl out(%esp), out_r 291
292 292 movl lencode_state(state_r), %eax
293#if defined ( USE_MMX ) 293 movl distcode_state(state_r), %ecx
294 294
295#define used_mm %mm1 295 movl %eax, lcode(%esp)
296#define dmask2_mm %mm2 296 movl %ecx, dcode(%esp)
297#define lmask2_mm %mm3 297
298#define lmask_mm %mm4 298 movl $1, %eax
299#define dmask_mm %mm5 299 movl lenbits_state(state_r), %ecx
300#define tmp_mm %mm6 300 shll %cl, %eax
301 301 decl %eax
302 movl out(%esp), out_r 302 movl %eax, lmask(%esp)
303 movd lmask(%esp), lmask_mm 303
304 movq lmask_mm, lmask2_mm 304 movl $1, %eax
305 movd dmask(%esp), dmask_mm 305 movl distbits_state(state_r), %ecx
306 movq dmask_mm, dmask2_mm 306 shll %cl, %eax
307 movd %ebx, hold_mm 307 decl %eax
308 pxor used_mm, used_mm 308 movl %eax, dmask(%esp)
309 movl lcode(%esp), %ebx /* ebx = lcode */ 309
310#endif 310 movl wsize_state(state_r), %eax
311 311 movl write_state(state_r), %ecx
312 jmp .L_do_loop 312 movl window_state(state_r), %edx
313 313
314.align 16,0x90 314 movl %eax, wsize(%esp)
315 315 movl %ecx, write(%esp)
316#if ! defined ( USE_MMX ) 316 movl %edx, window(%esp)
317 317
318.L_do_loop: 318 movl hold_state(state_r), %ebp
319 /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out 319 movl bits_state(state_r), %ebx
320 * 320
321 * do { 321#undef strm_r
322 * if (bits < 15) { 322#undef state_r
323 * hold |= *((unsigned short *)in)++ << bits; 323
324 * bits += 16 324#define in_r %esi
325 * } 325#define from_r %esi
326 * this = lcode[hold & lmask] 326#define out_r %edi
327 */ 327
328 cmpb $15, bits_r 328 movl in(%esp), in_r
329 ja .L_get_length_code /* if (15 < bits) */ 329 movl last(%esp), %ecx
330 330 cmpl in_r, %ecx
331 xorl %eax, %eax 331 ja .L_align_long /* if in < last */
332 lodsw /* al = *(ushort *)in++ */ 332
333 movb bits_r, %cl /* cl = bits, needs it for shifting */ 333 addl $11, %ecx /* ecx = &in[ avail_in ] */
334 addb $16, bits_r /* bits += 16 */ 334 subl in_r, %ecx /* ecx = avail_in */
335 shll %cl, %eax 335 movl $12, %eax
336 orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ 336 subl %ecx, %eax /* eax = 12 - avail_in */
337 337 leal buf(%esp), %edi
338.L_get_length_code: 338 rep movsb /* memcpy( buf, in, avail_in ) */
339 movl lmask(%esp), %edx /* edx = lmask */ 339 movl %eax, %ecx
340 movl lcode(%esp), %ecx /* ecx = lcode */ 340 xorl %eax, %eax
341 andl hold_r, %edx /* edx &= hold */ 341 rep stosb /* memset( &buf[ avail_in ], 0, 12 - avail_in ) */
342 movl (%ecx,%edx,4), %eax /* eax = lcode[hold & lmask] */ 342 leal buf(%esp), in_r /* in = buf */
343 343 movl in_r, last(%esp) /* last = in, do just one iteration */
344#else /* USE_MMX */ 344 jmp .L_is_aligned
345 345
346.L_do_loop: 346 /* align in_r on long boundary */
347 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 347.L_align_long:
348 348 testl $3, in_r
349 cmpl $32, bits_r 349 jz .L_is_aligned
350 ja .L_get_length_code /* if (32 < bits) */ 350 xorl %eax, %eax
351 351 movb (in_r), %al
352 movd bits_r, tmp_mm 352 incl in_r
353 movd (in_r), %mm7 353 movl %ebx, %ecx
354 addl $4, in_r 354 addl $8, %ebx
355 psllq tmp_mm, %mm7 355 shll %cl, %eax
356 addl $32, bits_r 356 orl %eax, %ebp
357 por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */ 357 jmp .L_align_long
358 358
359.L_get_length_code: 359.L_is_aligned:
360 pand hold_mm, lmask_mm 360 movl out(%esp), out_r
361 movd lmask_mm, %eax 361
362 movq lmask2_mm, lmask_mm 362#if defined( NO_MMX )
363 movl (%ebx,%eax,4), %eax /* eax = lcode[hold & lmask] */ 363 jmp .L_do_loop
364 364#endif
365#endif 365
366 366#if defined( USE_MMX )
367#if ! defined( USE_MMX ) 367 jmp .L_init_mmx
368 368#endif
369.L_dolen: 369
370 /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out 370/*** Runtime MMX check ***/
371 * 371
372 * dolen: 372#if defined( RUN_TIME_MMX )
373 * bits -= this.bits; 373.L_check_mmx:
374 * hold >>= this.bits 374 cmpl $DO_USE_MMX, inflate_fast_use_mmx
375 */ 375 je .L_init_mmx
376 movb %ah, %cl /* cl = this.bits */ 376 ja .L_do_loop /* > 2 */
377 subb %ah, bits_r /* bits -= this.bits */ 377
378 shrl %cl, hold_r /* hold >>= this.bits */ 378 pushl %eax
379 379 pushl %ebx
380 /* check if op is a literal 380 pushl %ecx
381 * if (op == 0) { 381 pushl %edx
382 * PUP(out) = this.val; 382 pushf
383 * } 383 movl (%esp), %eax /* copy eflags to eax */
384 */ 384 xorl $0x200000, (%esp) /* try toggling ID bit of eflags (bit 21)
385 testb %al, %al 385 * to see if cpu supports cpuid...
386 jnz .L_test_for_length_base /* if (op != 0) 45.7% */ 386 * ID bit method not supported by NexGen but
387 387 * bios may load a cpuid instruction and
388 shrl $16, %eax /* output this.val char */ 388 * cpuid may be disabled on Cyrix 5-6x86 */
389 stosb 389 popf
390 390 pushf
391#else /* USE_MMX */ 391 popl %edx /* copy new eflags to edx */
392 392 xorl %eax, %edx /* test if ID bit is flipped */
393#define len_r %edx 393 jz .L_dont_use_mmx /* not flipped if zero */
394 394 xorl %eax, %eax
395.L_dolen: 395 cpuid
396 movzbl %ah, %ecx /* ecx = this.bits */ 396 cmpl $0x756e6547, %ebx /* check for GenuineIntel in ebx,ecx,edx */
397 movl %eax, len_r /* len = this */ 397 jne .L_dont_use_mmx
398 shrl $16, len_r /* len = this.val */ 398 cmpl $0x6c65746e, %ecx
399 movd %ecx, used_mm 399 jne .L_dont_use_mmx
400 subl %ecx, bits_r /* bits -= this.bits */ 400 cmpl $0x49656e69, %edx
401 401 jne .L_dont_use_mmx
402 testb %al, %al 402 movl $1, %eax
403 jnz .L_test_for_length_base /* if (op != 0) 45.7% */ 403 cpuid /* get cpu features */
404 404 shrl $8, %eax
405 movb %dl, (out_r) 405 andl $15, %eax
406 incl out_r 406 cmpl $6, %eax /* check for Pentium family, is 0xf for P4 */
407 407 jne .L_dont_use_mmx
408#endif 408 testl $0x800000, %edx /* test if MMX feature is set (bit 23) */
409 409 jnz .L_use_mmx
410.L_while_test: 410 jmp .L_dont_use_mmx
411 /* while (in < last && out < end) 411.L_use_mmx:
412 */ 412 movl $DO_USE_MMX, inflate_fast_use_mmx
413 cmpl out_r, end(%esp) 413 jmp .L_check_mmx_pop
414 jbe .L_break_loop /* if (out >= end) */ 414.L_dont_use_mmx:
415 415 movl $DONT_USE_MMX, inflate_fast_use_mmx
416 cmpl in_r, last(%esp) 416.L_check_mmx_pop:
417 ja .L_do_loop /* if (in < last) */ 417 popl %edx
418 jmp .L_break_loop 418 popl %ecx
419 419 popl %ebx
420#if ! defined( USE_MMX ) 420 popl %eax
421 421 jmp .L_check_mmx
422.L_test_for_length_base: 422#endif
423 /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = len 423
424 * 424
425 * else if (op & 16) { 425/*** Non-MMX code ***/
426 * len = this.val 426
427 * op &= 15 427#if defined ( NO_MMX ) || defined( RUN_TIME_MMX )
428 * if (op) { 428
429 * if (op > bits) { 429#define hold_r %ebp
430 * hold |= *((unsigned short *)in)++ << bits; 430#define bits_r %bl
431 * bits += 16 431#define bitslong_r %ebx
432 * } 432
433 * len += hold & mask[op]; 433.align 32,0x90
434 * bits -= op; 434.L_while_test:
435 * hold >>= op; 435 /* while (in < last && out < end)
436 * } 436 */
437 */ 437 cmpl out_r, end(%esp)
438#define len_r %edx 438 jbe .L_break_loop /* if (out >= end) */
439 movl %eax, len_r /* len = this */ 439
440 shrl $16, len_r /* len = this.val */ 440 cmpl in_r, last(%esp)
441 movb %al, %cl 441 jbe .L_break_loop
442 442
443 testb $16, %al 443.L_do_loop:
444 jz .L_test_for_second_level_length /* if ((op & 16) == 0) 8% */ 444 /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out
445 andb $15, %cl /* op &= 15 */ 445 *
446 jz .L_save_len /* if (!op) */ 446 * do {
447 cmpb %cl, bits_r 447 * if (bits < 15) {
448 jae .L_add_bits_to_len /* if (op <= bits) */ 448 * hold |= *((unsigned short *)in)++ << bits;
449 449 * bits += 16
450 movb %cl, %ch /* stash op in ch, freeing cl */ 450 * }
451 xorl %eax, %eax 451 * this = lcode[hold & lmask]
452 lodsw /* al = *(ushort *)in++ */ 452 */
453 movb bits_r, %cl /* cl = bits, needs it for shifting */ 453 cmpb $15, bits_r
454 addb $16, bits_r /* bits += 16 */ 454 ja .L_get_length_code /* if (15 < bits) */
455 shll %cl, %eax 455
456 orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ 456 xorl %eax, %eax
457 movb %ch, %cl /* move op back to ecx */ 457 lodsw /* al = *(ushort *)in++ */
458 458 movb bits_r, %cl /* cl = bits, needs it for shifting */
459.L_add_bits_to_len: 459 addb $16, bits_r /* bits += 16 */
460 movl $1, %eax 460 shll %cl, %eax
461 shll %cl, %eax 461 orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */
462 decl %eax 462
463 subb %cl, bits_r 463.L_get_length_code:
464 andl hold_r, %eax /* eax &= hold */ 464 movl lmask(%esp), %edx /* edx = lmask */
465 shrl %cl, hold_r 465 movl lcode(%esp), %ecx /* ecx = lcode */
466 addl %eax, len_r /* len += hold & mask[op] */ 466 andl hold_r, %edx /* edx &= hold */
467 467 movl (%ecx,%edx,4), %eax /* eax = lcode[hold & lmask] */
468.L_save_len: 468
469 movl len_r, len(%esp) /* save len */ 469.L_dolen:
470#undef len_r 470 /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out
471 471 *
472.L_decode_distance: 472 * dolen:
473 /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = dist 473 * bits -= this.bits;
474 * 474 * hold >>= this.bits
475 * if (bits < 15) { 475 */
476 * hold |= *((unsigned short *)in)++ << bits; 476 movb %ah, %cl /* cl = this.bits */
477 * bits += 16 477 subb %ah, bits_r /* bits -= this.bits */
478 * } 478 shrl %cl, hold_r /* hold >>= this.bits */
479 * this = dcode[hold & dmask]; 479
480 * dodist: 480 /* check if op is a literal
481 * bits -= this.bits; 481 * if (op == 0) {
482 * hold >>= this.bits; 482 * PUP(out) = this.val;
483 * op = this.op; 483 * }
484 */ 484 */
485 485 testb %al, %al
486 cmpb $15, bits_r 486 jnz .L_test_for_length_base /* if (op != 0) 45.7% */
487 ja .L_get_distance_code /* if (15 < bits) */ 487
488 488 shrl $16, %eax /* output this.val char */
489 xorl %eax, %eax 489 stosb
490 lodsw /* al = *(ushort *)in++ */ 490 jmp .L_while_test
491 movb bits_r, %cl /* cl = bits, needs it for shifting */ 491
492 addb $16, bits_r /* bits += 16 */ 492.L_test_for_length_base:
493 shll %cl, %eax 493 /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = len
494 orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ 494 *
495 495 * else if (op & 16) {
496.L_get_distance_code: 496 * len = this.val
497 movl dmask(%esp), %edx /* edx = dmask */ 497 * op &= 15
498 movl dcode(%esp), %ecx /* ecx = dcode */ 498 * if (op) {
499 andl hold_r, %edx /* edx &= hold */ 499 * if (op > bits) {
500 movl (%ecx,%edx,4), %eax /* eax = dcode[hold & dmask] */ 500 * hold |= *((unsigned short *)in)++ << bits;
501 501 * bits += 16
502#else /* USE_MMX */ 502 * }
503 503 * len += hold & mask[op];
504.L_test_for_length_base: 504 * bits -= op;
505 testb $16, %al 505 * hold >>= op;
506 jz .L_test_for_second_level_length /* if ((op & 16) == 0) 8% */ 506 * }
507 andl $15, %eax /* op &= 15 */ 507 */
508 jz .L_decode_distance /* if (!op) */ 508#define len_r %edx
509 509 movl %eax, len_r /* len = this */
510 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 510 shrl $16, len_r /* len = this.val */
511 movd %eax, used_mm 511 movb %al, %cl
512 movd hold_mm, %ecx 512
513 subl %eax, bits_r 513 testb $16, %al
514 andl .L_mask(,%eax,4), %ecx 514 jz .L_test_for_second_level_length /* if ((op & 16) == 0) 8% */
515 addl %ecx, len_r /* len += hold & mask[op] */ 515 andb $15, %cl /* op &= 15 */
516 516 jz .L_save_len /* if (!op) */
517.L_decode_distance: 517 cmpb %cl, bits_r
518 518 jae .L_add_bits_to_len /* if (op <= bits) */
519 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 519
520 520 movb %cl, %ch /* stash op in ch, freeing cl */
521 cmpl $32, bits_r 521 xorl %eax, %eax
522 ja .L_get_dist_code /* if (32 < bits) */ 522 lodsw /* al = *(ushort *)in++ */
523 523 movb bits_r, %cl /* cl = bits, needs it for shifting */
524 movd bits_r, tmp_mm 524 addb $16, bits_r /* bits += 16 */
525 movd (in_r), %mm7 525 shll %cl, %eax
526 addl $4, in_r 526 orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */
527 psllq tmp_mm, %mm7 527 movb %ch, %cl /* move op back to ecx */
528 addl $32, bits_r 528
529 por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */ 529.L_add_bits_to_len:
530 530 movl $1, %eax
531.L_get_dist_code: 531 shll %cl, %eax
532 movl dcode(%esp), %ebx /* ebx = dcode */ 532 decl %eax
533 pand hold_mm, dmask_mm 533 subb %cl, bits_r
534 movd dmask_mm, %eax 534 andl hold_r, %eax /* eax &= hold */
535 movq dmask2_mm, dmask_mm 535 shrl %cl, hold_r
536 movl (%ebx,%eax,4), %eax /* eax = dcode[hold & lmask] */ 536 addl %eax, len_r /* len += hold & mask[op] */
537 537
538#endif 538.L_save_len:
539 539 movl len_r, len(%esp) /* save len */
540#if ! defined( USE_MMX ) 540#undef len_r
541 541
542#define dist_r %edx 542.L_decode_distance:
543.L_dodist: 543 /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = dist
544 movl %eax, dist_r /* dist = this */ 544 *
545 shrl $16, dist_r /* dist = this.val */ 545 * if (bits < 15) {
546 movb %ah, %cl 546 * hold |= *((unsigned short *)in)++ << bits;
547 subb %ah, bits_r /* bits -= this.bits */ 547 * bits += 16
548 shrl %cl, hold_r /* hold >>= this.bits */ 548 * }
549 549 * this = dcode[hold & dmask];
550 /* if (op & 16) { 550 * dodist:
551 * dist = this.val 551 * bits -= this.bits;
552 * op &= 15 552 * hold >>= this.bits;
553 * if (op > bits) { 553 * op = this.op;
554 * hold |= *((unsigned short *)in)++ << bits; 554 */
555 * bits += 16 555
556 * } 556 cmpb $15, bits_r
557 * dist += hold & mask[op]; 557 ja .L_get_distance_code /* if (15 < bits) */
558 * bits -= op; 558
559 * hold >>= op; 559 xorl %eax, %eax
560 */ 560 lodsw /* al = *(ushort *)in++ */
561 movb %al, %cl /* cl = this.op */ 561 movb bits_r, %cl /* cl = bits, needs it for shifting */
562 562 addb $16, bits_r /* bits += 16 */
563 testb $16, %al /* if ((op & 16) == 0) */ 563 shll %cl, %eax
564 jz .L_test_for_second_level_dist 564 orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */
565 andb $15, %cl /* op &= 15 */ 565
566 jz .L_check_dist_one 566.L_get_distance_code:
567 cmpb %cl, bits_r 567 movl dmask(%esp), %edx /* edx = dmask */
568 jae .L_add_bits_to_dist /* if (op <= bits) 97.6% */ 568 movl dcode(%esp), %ecx /* ecx = dcode */
569 569 andl hold_r, %edx /* edx &= hold */
570 movb %cl, %ch /* stash op in ch, freeing cl */ 570 movl (%ecx,%edx,4), %eax /* eax = dcode[hold & dmask] */
571 xorl %eax, %eax 571
572 lodsw /* al = *(ushort *)in++ */ 572#define dist_r %edx
573 movb bits_r, %cl /* cl = bits, needs it for shifting */ 573.L_dodist:
574 addb $16, bits_r /* bits += 16 */ 574 movl %eax, dist_r /* dist = this */
575 shll %cl, %eax 575 shrl $16, dist_r /* dist = this.val */
576 orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ 576 movb %ah, %cl
577 movb %ch, %cl /* move op back to ecx */ 577 subb %ah, bits_r /* bits -= this.bits */
578 578 shrl %cl, hold_r /* hold >>= this.bits */
579.L_add_bits_to_dist: 579
580 movl $1, %eax 580 /* if (op & 16) {
581 shll %cl, %eax 581 * dist = this.val
582 decl %eax /* (1 << op) - 1 */ 582 * op &= 15
583 subb %cl, bits_r 583 * if (op > bits) {
584 andl hold_r, %eax /* eax &= hold */ 584 * hold |= *((unsigned short *)in)++ << bits;
585 shrl %cl, hold_r 585 * bits += 16
586 addl %eax, dist_r /* dist += hold & ((1 << op) - 1) */ 586 * }
587 jmp .L_check_window 587 * dist += hold & mask[op];
588 588 * bits -= op;
589#else /* USE_MMX */ 589 * hold >>= op;
590 590 */
591#define dist_r %ebx 591 movb %al, %cl /* cl = this.op */
592.L_dodist: 592
593 movzbl %ah, %ecx /* ecx = this.bits */ 593 testb $16, %al /* if ((op & 16) == 0) */
594 movl %eax, dist_r 594 jz .L_test_for_second_level_dist
595 shrl $16, dist_r /* dist = this.val */ 595 andb $15, %cl /* op &= 15 */
596 subl %ecx, bits_r /* bits -= this.bits */ 596 jz .L_check_dist_one
597 movd %ecx, used_mm 597 cmpb %cl, bits_r
598 598 jae .L_add_bits_to_dist /* if (op <= bits) 97.6% */
599 testb $16, %al /* if ((op & 16) == 0) */ 599
600 jz .L_test_for_second_level_dist 600 movb %cl, %ch /* stash op in ch, freeing cl */
601 andl $15, %eax /* op &= 15 */ 601 xorl %eax, %eax
602 jz .L_check_dist_one 602 lodsw /* al = *(ushort *)in++ */
603 603 movb bits_r, %cl /* cl = bits, needs it for shifting */
604.L_add_bits_to_dist: 604 addb $16, bits_r /* bits += 16 */
605 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 605 shll %cl, %eax
606 movd %eax, used_mm /* save bit length of current op */ 606 orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */
607 movd hold_mm, %ecx /* get the next bits on input stream */ 607 movb %ch, %cl /* move op back to ecx */
608 subl %eax, bits_r /* bits -= op bits */ 608
609 andl .L_mask(,%eax,4), %ecx /* ecx = hold & mask[op] */ 609.L_add_bits_to_dist:
610 addl %ecx, dist_r /* dist += hold & mask[op] */ 610 movl $1, %eax
611 jmp .L_check_window 611 shll %cl, %eax
612 612 decl %eax /* (1 << op) - 1 */
613#endif 613 subb %cl, bits_r
614 614 andl hold_r, %eax /* eax &= hold */
615.align 16,0x90 615 shrl %cl, hold_r
616 616 addl %eax, dist_r /* dist += hold & ((1 << op) - 1) */
617.L_check_dist_one: 617 jmp .L_check_window
618 cmpl $1, dist_r 618
619 jne .L_check_window 619.L_check_window:
620 cmpl out_r, beg(%esp) 620 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
621 je .L_check_window 621 * %ecx = nbytes
622 622 *
623 decl out_r 623 * nbytes = out - beg;
624#if ! defined( USE_MMX ) 624 * if (dist <= nbytes) {
625 movl len(%esp), %ecx 625 * from = out - dist;
626#else 626 * do {
627 movl len_r, %ecx 627 * PUP(out) = PUP(from);
628#endif 628 * } while (--len > 0) {
629 movb (out_r), %al 629 * }
630 subl $3, %ecx 630 */
631 631
632 movb %al, 1(out_r) 632 movl in_r, in(%esp) /* save in so from can use it's reg */
633 movb %al, 2(out_r) 633 movl out_r, %eax
634 movb %al, 3(out_r) 634 subl beg(%esp), %eax /* nbytes = out - beg */
635 addl $4, out_r 635
636 rep stosb 636 cmpl dist_r, %eax
637 637 jb .L_clip_window /* if (dist > nbytes) 4.2% */
638#if defined( USE_MMX ) 638
639 movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */ 639 movl len(%esp), %ecx
640#endif 640 movl out_r, from_r
641 jmp .L_while_test 641 subl dist_r, from_r /* from = out - dist */
642 642
643.align 16,0x90 643 subl $3, %ecx
644 644 movb (from_r), %al
645.L_check_window: 645 movb %al, (out_r)
646 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist 646 movb 1(from_r), %al
647 * %ecx = nbytes 647 movb 2(from_r), %dl
648 * 648 addl $3, from_r
649 * nbytes = out - beg; 649 movb %al, 1(out_r)
650 * if (dist <= nbytes) { 650 movb %dl, 2(out_r)
651 * from = out - dist; 651 addl $3, out_r
652 * do { 652 rep movsb
653 * PUP(out) = PUP(from); 653
654 * } while (--len > 0) { 654 movl in(%esp), in_r /* move in back to %esi, toss from */
655 * } 655 jmp .L_while_test
656 */ 656
657 657.align 16,0x90
658 movl in_r, in(%esp) /* save in so from can use it's reg */ 658.L_check_dist_one:
659 movl out_r, %eax 659 cmpl $1, dist_r
660 subl beg(%esp), %eax /* nbytes = out - beg */ 660 jne .L_check_window
661 661 cmpl out_r, beg(%esp)
662 cmpl dist_r, %eax 662 je .L_check_window
663 jb .L_clip_window /* if (dist > nbytes) 4.2% */ 663
664 664 decl out_r
665#if ! defined( USE_MMX ) 665 movl len(%esp), %ecx
666 movl len(%esp), %ecx 666 movb (out_r), %al
667#else 667 subl $3, %ecx
668 movl len_r, %ecx 668
669#endif 669 movb %al, 1(out_r)
670 movl out_r, from_r 670 movb %al, 2(out_r)
671 subl dist_r, from_r /* from = out - dist */ 671 movb %al, 3(out_r)
672 672 addl $4, out_r
673 subl $3, %ecx 673 rep stosb
674 movb (from_r), %al 674
675 movb %al, (out_r) 675 jmp .L_while_test
676 movb 1(from_r), %al 676
677 movb 2(from_r), %dl 677.align 16,0x90
678 addl $3, from_r 678.L_test_for_second_level_length:
679 movb %al, 1(out_r) 679 /* else if ((op & 64) == 0) {
680 movb %dl, 2(out_r) 680 * this = lcode[this.val + (hold & mask[op])];
681 addl $3, out_r 681 * }
682 rep movsb 682 */
683 683 testb $64, %al
684 movl in(%esp), in_r /* move in back to %esi, toss from */ 684 jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */
685#if defined( USE_MMX ) 685
686 movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */ 686 movl $1, %eax
687#endif 687 shll %cl, %eax
688 jmp .L_while_test 688 decl %eax
689 689 andl hold_r, %eax /* eax &= hold */
690.align 16,0x90 690 addl %edx, %eax /* eax += this.val */
691 691 movl lcode(%esp), %edx /* edx = lcode */
692#if ! defined( USE_MMX ) 692 movl (%edx,%eax,4), %eax /* eax = lcode[val + (hold&mask[op])] */
693 693 jmp .L_dolen
694.L_test_for_second_level_length: 694
695 /* else if ((op & 64) == 0) { 695.align 16,0x90
696 * this = lcode[this.val + (hold & mask[op])]; 696.L_test_for_second_level_dist:
697 * } 697 /* else if ((op & 64) == 0) {
698 */ 698 * this = dcode[this.val + (hold & mask[op])];
699 testb $64, %al 699 * }
700 jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */ 700 */
701 701 testb $64, %al
702 movl $1, %eax 702 jnz .L_invalid_distance_code /* if ((op & 64) != 0) */
703 shll %cl, %eax 703
704 decl %eax 704 movl $1, %eax
705 andl hold_r, %eax /* eax &= hold */ 705 shll %cl, %eax
706 addl %edx, %eax /* eax += this.val */ 706 decl %eax
707 movl lcode(%esp), %edx /* edx = lcode */ 707 andl hold_r, %eax /* eax &= hold */
708 movl (%edx,%eax,4), %eax /* eax = lcode[val + (hold&mask[op])] */ 708 addl %edx, %eax /* eax += this.val */
709 jmp .L_dolen 709 movl dcode(%esp), %edx /* edx = dcode */
710 710 movl (%edx,%eax,4), %eax /* eax = dcode[val + (hold&mask[op])] */
711#else /* USE_MMX */ 711 jmp .L_dodist
712 712
713.L_test_for_second_level_length: 713.align 16,0x90
714 testb $64, %al 714.L_clip_window:
715 jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */ 715 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
716 716 * %ecx = nbytes
717 andl $15, %eax 717 *
718 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 718 * else {
719 movd hold_mm, %ecx 719 * if (dist > wsize) {
720 andl .L_mask(,%eax,4), %ecx 720 * invalid distance
721 addl len_r, %ecx 721 * }
722 movl (%ebx,%ecx,4), %eax /* eax = lcode[hold & lmask] */ 722 * from = window;
723 jmp .L_dolen 723 * nbytes = dist - nbytes;
724 724 * if (write == 0) {
725#endif 725 * from += wsize - nbytes;
726 726 */
727.align 16,0x90 727#define nbytes_r %ecx
728 728 movl %eax, nbytes_r
729#if ! defined( USE_MMX ) 729 movl wsize(%esp), %eax /* prepare for dist compare */
730 730 negl nbytes_r /* nbytes = -nbytes */
731.L_test_for_second_level_dist: 731 movl window(%esp), from_r /* from = window */
732 /* else if ((op & 64) == 0) { 732
733 * this = dcode[this.val + (hold & mask[op])]; 733 cmpl dist_r, %eax
734 * } 734 jb .L_invalid_distance_too_far /* if (dist > wsize) */
735 */ 735
736 testb $64, %al 736 addl dist_r, nbytes_r /* nbytes = dist - nbytes */
737 jnz .L_invalid_distance_code /* if ((op & 64) != 0) */ 737 cmpl $0, write(%esp)
738 738 jne .L_wrap_around_window /* if (write != 0) */
739 movl $1, %eax 739
740 shll %cl, %eax 740 subl nbytes_r, %eax
741 decl %eax 741 addl %eax, from_r /* from += wsize - nbytes */
742 andl hold_r, %eax /* eax &= hold */ 742
743 addl %edx, %eax /* eax += this.val */ 743 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
744 movl dcode(%esp), %edx /* edx = dcode */ 744 * %ecx = nbytes, %eax = len
745 movl (%edx,%eax,4), %eax /* eax = dcode[val + (hold&mask[op])] */ 745 *
746 jmp .L_dodist 746 * if (nbytes < len) {
747 747 * len -= nbytes;
748#else /* USE_MMX */ 748 * do {
749 749 * PUP(out) = PUP(from);
750.L_test_for_second_level_dist: 750 * } while (--nbytes);
751 testb $64, %al 751 * from = out - dist;
752 jnz .L_invalid_distance_code /* if ((op & 64) != 0) */ 752 * }
753 753 * }
754 andl $15, %eax 754 */
755 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 755#define len_r %eax
756 movd hold_mm, %ecx 756 movl len(%esp), len_r
757 andl .L_mask(,%eax,4), %ecx 757 cmpl nbytes_r, len_r
758 movl dcode(%esp), %eax /* ecx = dcode */ 758 jbe .L_do_copy1 /* if (nbytes >= len) */
759 addl dist_r, %ecx 759
760 movl (%eax,%ecx,4), %eax /* eax = lcode[hold & lmask] */ 760 subl nbytes_r, len_r /* len -= nbytes */
761 jmp .L_dodist 761 rep movsb
762 762 movl out_r, from_r
763#endif 763 subl dist_r, from_r /* from = out - dist */
764 764 jmp .L_do_copy1
765.align 16,0x90 765
766.L_clip_window: 766 cmpl nbytes_r, len_r
767 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist 767 jbe .L_do_copy1 /* if (nbytes >= len) */
768 * %ecx = nbytes 768
769 * 769 subl nbytes_r, len_r /* len -= nbytes */
770 * else { 770 rep movsb
771 * if (dist > wsize) { 771 movl out_r, from_r
772 * invalid distance 772 subl dist_r, from_r /* from = out - dist */
773 * } 773 jmp .L_do_copy1
774 * from = window; 774
775 * nbytes = dist - nbytes; 775.L_wrap_around_window:
776 * if (write == 0) { 776 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
777 * from += wsize - nbytes; 777 * %ecx = nbytes, %eax = write, %eax = len
778 */ 778 *
779#define nbytes_r %ecx 779 * else if (write < nbytes) {
780 780 * from += wsize + write - nbytes;
781 movl %eax, nbytes_r 781 * nbytes -= write;
782 movl wsize(%esp), %eax /* prepare for dist compare */ 782 * if (nbytes < len) {
783 negl nbytes_r /* nbytes = -nbytes */ 783 * len -= nbytes;
784 movl window(%esp), from_r /* from = window */ 784 * do {
785 785 * PUP(out) = PUP(from);
786 cmpl dist_r, %eax 786 * } while (--nbytes);
787 jb .L_invalid_distance_too_far /* if (dist > wsize) */ 787 * from = window;
788 788 * nbytes = write;
789 addl dist_r, nbytes_r /* nbytes = dist - nbytes */ 789 * if (nbytes < len) {
790 cmpl $0, write(%esp) 790 * len -= nbytes;
791 jne .L_wrap_around_window /* if (write != 0) */ 791 * do {
792 792 * PUP(out) = PUP(from);
793 subl nbytes_r, %eax 793 * } while(--nbytes);
794 addl %eax, from_r /* from += wsize - nbytes */ 794 * from = out - dist;
795 795 * }
796 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist 796 * }
797 * %ecx = nbytes, %eax = len 797 * }
798 * 798 */
799 * if (nbytes < len) { 799#define write_r %eax
800 * len -= nbytes; 800 movl write(%esp), write_r
801 * do { 801 cmpl write_r, nbytes_r
802 * PUP(out) = PUP(from); 802 jbe .L_contiguous_in_window /* if (write >= nbytes) */
803 * } while (--nbytes); 803
804 * from = out - dist; 804 addl wsize(%esp), from_r
805 * } 805 addl write_r, from_r
806 * } 806 subl nbytes_r, from_r /* from += wsize + write - nbytes */
807 */ 807 subl write_r, nbytes_r /* nbytes -= write */
808 808#undef write_r
809#if ! defined( USE_MMX ) 809
810#define len_r %eax 810 movl len(%esp), len_r
811 movl len(%esp), len_r 811 cmpl nbytes_r, len_r
812#endif 812 jbe .L_do_copy1 /* if (nbytes >= len) */
813 cmpl nbytes_r, len_r 813
814 jbe .L_do_copy1 /* if (nbytes >= len) */ 814 subl nbytes_r, len_r /* len -= nbytes */
815 815 rep movsb
816 subl nbytes_r, len_r /* len -= nbytes */ 816 movl window(%esp), from_r /* from = window */
817 rep movsb 817 movl write(%esp), nbytes_r /* nbytes = write */
818 movl out_r, from_r 818 cmpl nbytes_r, len_r
819 subl dist_r, from_r /* from = out - dist */ 819 jbe .L_do_copy1 /* if (nbytes >= len) */
820 jmp .L_do_copy1 820
821 821 subl nbytes_r, len_r /* len -= nbytes */
822 cmpl nbytes_r, len_r 822 rep movsb
823 jbe .L_do_copy1 /* if (nbytes >= len) */ 823 movl out_r, from_r
824 824 subl dist_r, from_r /* from = out - dist */
825 subl nbytes_r, len_r /* len -= nbytes */ 825 jmp .L_do_copy1
826 rep movsb 826
827 movl out_r, from_r 827.L_contiguous_in_window:
828 subl dist_r, from_r /* from = out - dist */ 828 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist
829 jmp .L_do_copy1 829 * %ecx = nbytes, %eax = write, %eax = len
830 830 *
831.L_wrap_around_window: 831 * else {
832 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist 832 * from += write - nbytes;
833 * %ecx = nbytes, %eax = write, %eax = len 833 * if (nbytes < len) {
834 * 834 * len -= nbytes;
835 * else if (write < nbytes) { 835 * do {
836 * from += wsize + write - nbytes; 836 * PUP(out) = PUP(from);
837 * nbytes -= write; 837 * } while (--nbytes);
838 * if (nbytes < len) { 838 * from = out - dist;
839 * len -= nbytes; 839 * }
840 * do { 840 * }
841 * PUP(out) = PUP(from); 841 */
842 * } while (--nbytes); 842#define write_r %eax
843 * from = window; 843 addl write_r, from_r
844 * nbytes = write; 844 subl nbytes_r, from_r /* from += write - nbytes */
845 * if (nbytes < len) { 845#undef write_r
846 * len -= nbytes; 846
847 * do { 847 movl len(%esp), len_r
848 * PUP(out) = PUP(from); 848 cmpl nbytes_r, len_r
849 * } while(--nbytes); 849 jbe .L_do_copy1 /* if (nbytes >= len) */
850 * from = out - dist; 850
851 * } 851 subl nbytes_r, len_r /* len -= nbytes */
852 * } 852 rep movsb
853 * } 853 movl out_r, from_r
854 */ 854 subl dist_r, from_r /* from = out - dist */
855#define write_r %eax 855
856 856.L_do_copy1:
857 movl write(%esp), write_r 857 /* regs: %esi = from, %esi = in, %ebp = hold, %bl = bits, %edi = out
858 cmpl write_r, nbytes_r 858 * %eax = len
859 jbe .L_contiguous_in_window /* if (write >= nbytes) */ 859 *
860 860 * while (len > 0) {
861 addl wsize(%esp), from_r 861 * PUP(out) = PUP(from);
862 addl write_r, from_r 862 * len--;
863 subl nbytes_r, from_r /* from += wsize + write - nbytes */ 863 * }
864 subl write_r, nbytes_r /* nbytes -= write */ 864 * }
865#undef write_r 865 * } while (in < last && out < end);
866 866 */
867#if ! defined( USE_MMX ) 867#undef nbytes_r
868 movl len(%esp), len_r 868#define in_r %esi
869#endif 869 movl len_r, %ecx
870 cmpl nbytes_r, len_r 870 rep movsb
871 jbe .L_do_copy1 /* if (nbytes >= len) */ 871
872 872 movl in(%esp), in_r /* move in back to %esi, toss from */
873 subl nbytes_r, len_r /* len -= nbytes */ 873 jmp .L_while_test
874 rep movsb 874
875 movl window(%esp), from_r /* from = window */ 875#undef len_r
876 movl write(%esp), nbytes_r /* nbytes = write */ 876#undef dist_r
877 cmpl nbytes_r, len_r 877
878 jbe .L_do_copy1 /* if (nbytes >= len) */ 878#endif /* NO_MMX || RUN_TIME_MMX */
879 879
880 subl nbytes_r, len_r /* len -= nbytes */ 880
881 rep movsb 881/*** MMX code ***/
882 movl out_r, from_r 882
883 subl dist_r, from_r /* from = out - dist */ 883#if defined( USE_MMX ) || defined( RUN_TIME_MMX )
884 jmp .L_do_copy1 884
885 885.align 32,0x90
886.L_contiguous_in_window: 886.L_init_mmx:
887 /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist 887 emms
888 * %ecx = nbytes, %eax = write, %eax = len 888
889 * 889#undef bits_r
890 * else { 890#undef bitslong_r
891 * from += write - nbytes; 891#define bitslong_r %ebp
892 * if (nbytes < len) { 892#define hold_mm %mm0
893 * len -= nbytes; 893 movd %ebp, hold_mm
894 * do { 894 movl %ebx, bitslong_r
895 * PUP(out) = PUP(from); 895
896 * } while (--nbytes); 896#define used_mm %mm1
897 * from = out - dist; 897#define dmask2_mm %mm2
898 * } 898#define lmask2_mm %mm3
899 * } 899#define lmask_mm %mm4
900 */ 900#define dmask_mm %mm5
901#define write_r %eax 901#define tmp_mm %mm6
902 902
903 addl write_r, from_r 903 movd lmask(%esp), lmask_mm
904 subl nbytes_r, from_r /* from += write - nbytes */ 904 movq lmask_mm, lmask2_mm
905#undef write_r 905 movd dmask(%esp), dmask_mm
906 906 movq dmask_mm, dmask2_mm
907#if ! defined( USE_MMX ) 907 pxor used_mm, used_mm
908 movl len(%esp), len_r 908 movl lcode(%esp), %ebx /* ebx = lcode */
909#endif 909 jmp .L_do_loop_mmx
910 cmpl nbytes_r, len_r 910
911 jbe .L_do_copy1 /* if (nbytes >= len) */ 911.align 32,0x90
912 912.L_while_test_mmx:
913 subl nbytes_r, len_r /* len -= nbytes */ 913 /* while (in < last && out < end)
914 rep movsb 914 */
915 movl out_r, from_r 915 cmpl out_r, end(%esp)
916 subl dist_r, from_r /* from = out - dist */ 916 jbe .L_break_loop /* if (out >= end) */
917 917
918.L_do_copy1: 918 cmpl in_r, last(%esp)
919 /* regs: %esi = from, %esi = in, %ebp = hold, %bl = bits, %edi = out 919 jbe .L_break_loop
920 * %eax = len 920
921 * 921.L_do_loop_mmx:
922 * while (len > 0) { 922 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
923 * PUP(out) = PUP(from); 923
924 * len--; 924 cmpl $32, bitslong_r
925 * } 925 ja .L_get_length_code_mmx /* if (32 < bits) */
926 * } 926
927 * } while (in < last && out < end); 927 movd bitslong_r, tmp_mm
928 */ 928 movd (in_r), %mm7
929#undef nbytes_r 929 addl $4, in_r
930#define in_r %esi 930 psllq tmp_mm, %mm7
931 931 addl $32, bitslong_r
932 movl len_r, %ecx 932 por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */
933 rep movsb 933
934 934.L_get_length_code_mmx:
935 movl in(%esp), in_r /* move in back to %esi, toss from */ 935 pand hold_mm, lmask_mm
936#if defined( USE_MMX ) 936 movd lmask_mm, %eax
937 movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */ 937 movq lmask2_mm, lmask_mm
938#endif 938 movl (%ebx,%eax,4), %eax /* eax = lcode[hold & lmask] */
939 jmp .L_while_test 939
940 940.L_dolen_mmx:
941#undef len_r 941 movzbl %ah, %ecx /* ecx = this.bits */
942#undef from_r 942 movd %ecx, used_mm
943#undef dist_r 943 subl %ecx, bitslong_r /* bits -= this.bits */
944 944
945.L_invalid_distance_code: 945 testb %al, %al
946 /* else { 946 jnz .L_test_for_length_base_mmx /* if (op != 0) 45.7% */
947 * strm->msg = "invalid distance code"; 947
948 * state->mode = BAD; 948 shrl $16, %eax /* output this.val char */
949 * } 949 stosb
950 */ 950 jmp .L_while_test_mmx
951 movl $.L_invalid_distance_code_msg, %ecx 951
952 movl $INFLATE_MODE_BAD, %edx 952.L_test_for_length_base_mmx:
953 jmp .L_update_stream_state 953#define len_r %edx
954 954 movl %eax, len_r /* len = this */
955.L_test_for_end_of_block: 955 shrl $16, len_r /* len = this.val */
956 /* else if (op & 32) { 956
957 * state->mode = TYPE; 957 testb $16, %al
958 * break; 958 jz .L_test_for_second_level_length_mmx /* if ((op & 16) == 0) 8% */
959 * } 959 andl $15, %eax /* op &= 15 */
960 */ 960 jz .L_decode_distance_mmx /* if (!op) */
961 testb $32, %al 961
962 jz .L_invalid_literal_length_code /* if ((op & 32) == 0) */ 962 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
963 963 movd %eax, used_mm
964 movl $0, %ecx 964 movd hold_mm, %ecx
965 movl $INFLATE_MODE_TYPE, %edx 965 subl %eax, bitslong_r
966 jmp .L_update_stream_state 966 andl .L_mask(,%eax,4), %ecx
967 967 addl %ecx, len_r /* len += hold & mask[op] */
968.L_invalid_literal_length_code: 968
969 /* else { 969.L_decode_distance_mmx:
970 * strm->msg = "invalid literal/length code"; 970 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
971 * state->mode = BAD; 971
972 * } 972 cmpl $32, bitslong_r
973 */ 973 ja .L_get_dist_code_mmx /* if (32 < bits) */
974 movl $.L_invalid_literal_length_code_msg, %ecx 974
975 movl $INFLATE_MODE_BAD, %edx 975 movd bitslong_r, tmp_mm
976 jmp .L_update_stream_state 976 movd (in_r), %mm7
977 977 addl $4, in_r
978.L_invalid_distance_too_far: 978 psllq tmp_mm, %mm7
979 /* strm->msg = "invalid distance too far back"; 979 addl $32, bitslong_r
980 * state->mode = BAD; 980 por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */
981 */ 981
982 movl in(%esp), in_r /* from_r has in's reg, put in back */ 982.L_get_dist_code_mmx:
983 movl $.L_invalid_distance_too_far_msg, %ecx 983 movl dcode(%esp), %ebx /* ebx = dcode */
984 movl $INFLATE_MODE_BAD, %edx 984 pand hold_mm, dmask_mm
985 jmp .L_update_stream_state 985 movd dmask_mm, %eax
986 986 movq dmask2_mm, dmask_mm
987.L_update_stream_state: 987 movl (%ebx,%eax,4), %eax /* eax = dcode[hold & lmask] */
988 /* set strm->msg = %ecx, strm->state->mode = %edx */ 988
989 movl strm_sp(%esp), %eax 989.L_dodist_mmx:
990 testl %ecx, %ecx /* if (msg != NULL) */ 990#define dist_r %ebx
991 jz .L_skip_msg 991 movzbl %ah, %ecx /* ecx = this.bits */
992 movl %ecx, msg_strm(%eax) /* strm->msg = msg */ 992 movl %eax, dist_r
993.L_skip_msg: 993 shrl $16, dist_r /* dist = this.val */
994 movl state_strm(%eax), %eax /* state = strm->state */ 994 subl %ecx, bitslong_r /* bits -= this.bits */
995 movl %edx, mode_state(%eax) /* state->mode = edx (BAD | TYPE) */ 995 movd %ecx, used_mm
996 996
997.L_break_loop: 997 testb $16, %al /* if ((op & 16) == 0) */
998 998 jz .L_test_for_second_level_dist_mmx
999#define strm_r %eax 999 andl $15, %eax /* op &= 15 */
1000#define state_r %edx 1000 jz .L_check_dist_one_mmx
1001 1001
1002 /* len = bits >> 3; 1002.L_add_bits_to_dist_mmx:
1003 * in -= len; 1003 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
1004 * bits -= len << 3; 1004 movd %eax, used_mm /* save bit length of current op */
1005 * hold &= (1U << bits) - 1; 1005 movd hold_mm, %ecx /* get the next bits on input stream */
1006 * state->hold = hold; 1006 subl %eax, bitslong_r /* bits -= op bits */
1007 * state->bits = bits; 1007 andl .L_mask(,%eax,4), %ecx /* ecx = hold & mask[op] */
1008 * strm->next_in = in; 1008 addl %ecx, dist_r /* dist += hold & mask[op] */
1009 * strm->next_out = out; 1009
1010 */ 1010.L_check_window_mmx:
1011 movl strm_sp(%esp), strm_r 1011 movl in_r, in(%esp) /* save in so from can use it's reg */
1012 movl bitslong_r, %ecx 1012 movl out_r, %eax
1013 movl state_strm(strm_r), state_r 1013 subl beg(%esp), %eax /* nbytes = out - beg */
1014 shrl $3, %ecx 1014
1015 subl %ecx, in_r 1015 cmpl dist_r, %eax
1016 shll $3, %ecx 1016 jb .L_clip_window_mmx /* if (dist > nbytes) 4.2% */
1017 subl %ecx, bitslong_r 1017
1018 movl out_r, next_out_strm(strm_r) 1018 movl len_r, %ecx
1019 movl in_r, next_in_strm(strm_r) 1019 movl out_r, from_r
1020 movl bitslong_r, bits_state(state_r) 1020 subl dist_r, from_r /* from = out - dist */
1021 1021
1022 movl bitslong_r, %ecx 1022 subl $3, %ecx
1023 movl $1, %ebx /* overwrites bitslong_r, %bl */ 1023 movb (from_r), %al
1024 shll %cl, %ebx 1024 movb %al, (out_r)
1025 decl %ebx 1025 movb 1(from_r), %al
1026 1026 movb 2(from_r), %dl
1027#undef bits_r 1027 addl $3, from_r
1028#undef bitslong_r 1028 movb %al, 1(out_r)
1029 1029 movb %dl, 2(out_r)
1030#if ! defined( USE_MMX ) 1030 addl $3, out_r
1031 1031 rep movsb
1032 andl %ebx, hold_r 1032
1033 movl hold_r, hold_state(state_r) 1033 movl in(%esp), in_r /* move in back to %esi, toss from */
1034 1034 movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */
1035#else /* USE_MMX */ 1035 jmp .L_while_test_mmx
1036 1036
1037 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ 1037.align 16,0x90
1038 movd hold_mm, %ecx 1038.L_check_dist_one_mmx:
1039 andl %ebx, %ecx 1039 cmpl $1, dist_r
1040 movl %ecx, hold_state(state_r) 1040 jne .L_check_window_mmx
1041 1041 cmpl out_r, beg(%esp)
1042#endif 1042 je .L_check_window_mmx
1043 1043
1044#define last_r %ebx 1044 decl out_r
1045 1045 movl len_r, %ecx
1046 /* strm->avail_in = in < last ? 5 + (last - in) : 5 - (in - last) */ 1046 movb (out_r), %al
1047 movl last(%esp), last_r 1047 subl $3, %ecx
1048 cmpl in_r, last_r 1048
1049 jbe .L_last_is_smaller /* if (in >= last) */ 1049 movb %al, 1(out_r)
1050 1050 movb %al, 2(out_r)
1051 subl in_r, last_r /* last -= in */ 1051 movb %al, 3(out_r)
1052 addl $5, last_r /* last += 5 */ 1052 addl $4, out_r
1053 movl last_r, avail_in_strm(strm_r) 1053 rep stosb
1054 jmp .L_fixup_out 1054
1055.L_last_is_smaller: 1055 movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */
1056 subl last_r, in_r /* in -= last */ 1056 jmp .L_while_test_mmx
1057 negl in_r /* in = -in */ 1057
1058 addl $5, in_r /* in += 5 */ 1058.align 16,0x90
1059 movl in_r, avail_in_strm(strm_r) 1059.L_test_for_second_level_length_mmx:
1060 1060 testb $64, %al
1061#undef last_r 1061 jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */
1062#define end_r %ebx 1062
1063 1063 andl $15, %eax
1064.L_fixup_out: 1064 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
1065 /* strm->avail_out = out < end ? 257 + (end - out) : 257 - (out - end)*/ 1065 movd hold_mm, %ecx
1066 movl end(%esp), end_r 1066 andl .L_mask(,%eax,4), %ecx
1067 cmpl out_r, end_r 1067 addl len_r, %ecx
1068 jbe .L_end_is_smaller /* if (out >= end) */ 1068 movl (%ebx,%ecx,4), %eax /* eax = lcode[hold & lmask] */
1069 1069 jmp .L_dolen_mmx
1070 subl out_r, end_r /* end -= out */ 1070
1071 addl $257, end_r /* end += 257 */ 1071.align 16,0x90
1072 movl end_r, avail_out_strm(strm_r) 1072.L_test_for_second_level_dist_mmx:
1073 jmp .L_done 1073 testb $64, %al
1074.L_end_is_smaller: 1074 jnz .L_invalid_distance_code /* if ((op & 64) != 0) */
1075 subl end_r, out_r /* out -= end */ 1075
1076 negl out_r /* out = -out */ 1076 andl $15, %eax
1077 addl $257, out_r /* out += 257 */ 1077 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
1078 movl out_r, avail_out_strm(strm_r) 1078 movd hold_mm, %ecx
1079 1079 andl .L_mask(,%eax,4), %ecx
1080#undef end_r 1080 movl dcode(%esp), %eax /* ecx = dcode */
1081 1081 addl dist_r, %ecx
1082.L_done: 1082 movl (%eax,%ecx,4), %eax /* eax = lcode[hold & lmask] */
1083#if defined( USE_MMX ) 1083 jmp .L_dodist_mmx
1084 emms 1084
1085#endif 1085.align 16,0x90
1086 addl $local_var_size, %esp 1086.L_clip_window_mmx:
1087 popf 1087#define nbytes_r %ecx
1088 popl %ebx 1088 movl %eax, nbytes_r
1089 popl %ebp 1089 movl wsize(%esp), %eax /* prepare for dist compare */
1090 popl %esi 1090 negl nbytes_r /* nbytes = -nbytes */
1091 popl %edi 1091 movl window(%esp), from_r /* from = window */
1092 ret 1092
1093 1093 cmpl dist_r, %eax
1094.type inflate_fast,@function 1094 jb .L_invalid_distance_too_far /* if (dist > wsize) */
1095.size inflate_fast,.-inflate_fast 1095
1096 addl dist_r, nbytes_r /* nbytes = dist - nbytes */
1097 cmpl $0, write(%esp)
1098 jne .L_wrap_around_window_mmx /* if (write != 0) */
1099
1100 subl nbytes_r, %eax
1101 addl %eax, from_r /* from += wsize - nbytes */
1102
1103 cmpl nbytes_r, len_r
1104 jbe .L_do_copy1_mmx /* if (nbytes >= len) */
1105
1106 subl nbytes_r, len_r /* len -= nbytes */
1107 rep movsb
1108 movl out_r, from_r
1109 subl dist_r, from_r /* from = out - dist */
1110 jmp .L_do_copy1_mmx
1111
1112 cmpl nbytes_r, len_r
1113 jbe .L_do_copy1_mmx /* if (nbytes >= len) */
1114
1115 subl nbytes_r, len_r /* len -= nbytes */
1116 rep movsb
1117 movl out_r, from_r
1118 subl dist_r, from_r /* from = out - dist */
1119 jmp .L_do_copy1_mmx
1120
1121.L_wrap_around_window_mmx:
1122#define write_r %eax
1123 movl write(%esp), write_r
1124 cmpl write_r, nbytes_r
1125 jbe .L_contiguous_in_window_mmx /* if (write >= nbytes) */
1126
1127 addl wsize(%esp), from_r
1128 addl write_r, from_r
1129 subl nbytes_r, from_r /* from += wsize + write - nbytes */
1130 subl write_r, nbytes_r /* nbytes -= write */
1131#undef write_r
1132
1133 cmpl nbytes_r, len_r
1134 jbe .L_do_copy1_mmx /* if (nbytes >= len) */
1135
1136 subl nbytes_r, len_r /* len -= nbytes */
1137 rep movsb
1138 movl window(%esp), from_r /* from = window */
1139 movl write(%esp), nbytes_r /* nbytes = write */
1140 cmpl nbytes_r, len_r
1141 jbe .L_do_copy1_mmx /* if (nbytes >= len) */
1142
1143 subl nbytes_r, len_r /* len -= nbytes */
1144 rep movsb
1145 movl out_r, from_r
1146 subl dist_r, from_r /* from = out - dist */
1147 jmp .L_do_copy1_mmx
1148
1149.L_contiguous_in_window_mmx:
1150#define write_r %eax
1151 addl write_r, from_r
1152 subl nbytes_r, from_r /* from += write - nbytes */
1153#undef write_r
1154
1155 cmpl nbytes_r, len_r
1156 jbe .L_do_copy1_mmx /* if (nbytes >= len) */
1157
1158 subl nbytes_r, len_r /* len -= nbytes */
1159 rep movsb
1160 movl out_r, from_r
1161 subl dist_r, from_r /* from = out - dist */
1162
1163.L_do_copy1_mmx:
1164#undef nbytes_r
1165#define in_r %esi
1166 movl len_r, %ecx
1167 rep movsb
1168
1169 movl in(%esp), in_r /* move in back to %esi, toss from */
1170 movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */
1171 jmp .L_while_test_mmx
1172
1173#undef hold_r
1174#undef bitslong_r
1175
1176#endif /* USE_MMX || RUN_TIME_MMX */
1177
1178
1179/*** USE_MMX, NO_MMX, and RUNTIME_MMX from here on ***/
1180
1181.L_invalid_distance_code:
1182 /* else {
1183 * strm->msg = "invalid distance code";
1184 * state->mode = BAD;
1185 * }
1186 */
1187 movl $.L_invalid_distance_code_msg, %ecx
1188 movl $INFLATE_MODE_BAD, %edx
1189 jmp .L_update_stream_state
1190
1191.L_test_for_end_of_block:
1192 /* else if (op & 32) {
1193 * state->mode = TYPE;
1194 * break;
1195 * }
1196 */
1197 testb $32, %al
1198 jz .L_invalid_literal_length_code /* if ((op & 32) == 0) */
1199
1200 movl $0, %ecx
1201 movl $INFLATE_MODE_TYPE, %edx
1202 jmp .L_update_stream_state
1203
1204.L_invalid_literal_length_code:
1205 /* else {
1206 * strm->msg = "invalid literal/length code";
1207 * state->mode = BAD;
1208 * }
1209 */
1210 movl $.L_invalid_literal_length_code_msg, %ecx
1211 movl $INFLATE_MODE_BAD, %edx
1212 jmp .L_update_stream_state
1213
1214.L_invalid_distance_too_far:
1215 /* strm->msg = "invalid distance too far back";
1216 * state->mode = BAD;
1217 */
1218 movl in(%esp), in_r /* from_r has in's reg, put in back */
1219 movl $.L_invalid_distance_too_far_msg, %ecx
1220 movl $INFLATE_MODE_BAD, %edx
1221 jmp .L_update_stream_state
1222
1223.L_update_stream_state:
1224 /* set strm->msg = %ecx, strm->state->mode = %edx */
1225 movl strm_sp(%esp), %eax
1226 testl %ecx, %ecx /* if (msg != NULL) */
1227 jz .L_skip_msg
1228 movl %ecx, msg_strm(%eax) /* strm->msg = msg */
1229.L_skip_msg:
1230 movl state_strm(%eax), %eax /* state = strm->state */
1231 movl %edx, mode_state(%eax) /* state->mode = edx (BAD | TYPE) */
1232 jmp .L_break_loop
1233
1234.align 32,0x90
1235.L_break_loop:
1236
1237/*
1238 * Regs:
1239 *
1240 * bits = %ebp when mmx, and in %ebx when non-mmx
1241 * hold = %hold_mm when mmx, and in %ebp when non-mmx
1242 * in = %esi
1243 * out = %edi
1244 */
1245
1246#if defined( USE_MMX ) || defined( RUN_TIME_MMX )
1247
1248#if defined( RUN_TIME_MMX )
1249
1250 cmpl $DO_USE_MMX, inflate_fast_use_mmx
1251 jne .L_update_next_in
1252
1253#endif /* RUN_TIME_MMX */
1254
1255 movl %ebp, %ebx
1256
1257.L_update_next_in:
1258
1259#endif
1260
1261#define strm_r %eax
1262#define state_r %edx
1263
1264 /* len = bits >> 3;
1265 * in -= len;
1266 * bits -= len << 3;
1267 * hold &= (1U << bits) - 1;
1268 * state->hold = hold;
1269 * state->bits = bits;
1270 * strm->next_in = in;
1271 * strm->next_out = out;
1272 */
1273 movl strm_sp(%esp), strm_r
1274 movl %ebx, %ecx
1275 movl state_strm(strm_r), state_r
1276 shrl $3, %ecx
1277 subl %ecx, in_r
1278 shll $3, %ecx
1279 subl %ecx, %ebx
1280 movl out_r, next_out_strm(strm_r)
1281 movl %ebx, bits_state(state_r)
1282 movl %ebx, %ecx
1283
1284 leal buf(%esp), %ebx
1285 cmpl %ebx, last(%esp)
1286 jne .L_buf_not_used /* if buf != last */
1287
1288 subl %ebx, in_r /* in -= buf */
1289 movl next_in_strm(strm_r), %ebx
1290 movl %ebx, last(%esp) /* last = strm->next_in */
1291 addl %ebx, in_r /* in += strm->next_in */
1292 movl avail_in_strm(strm_r), %ebx
1293 subl $11, %ebx
1294 addl %ebx, last(%esp) /* last = &strm->next_in[ avail_in - 11 ] */
1295
1296.L_buf_not_used:
1297 movl in_r, next_in_strm(strm_r)
1298
1299 movl $1, %ebx
1300 shll %cl, %ebx
1301 decl %ebx
1302
1303#if defined( USE_MMX ) || defined( RUN_TIME_MMX )
1304
1305#if defined( RUN_TIME_MMX )
1306
1307 cmpl $DO_USE_MMX, inflate_fast_use_mmx
1308 jne .L_update_hold
1309
1310#endif /* RUN_TIME_MMX */
1311
1312 psrlq used_mm, hold_mm /* hold_mm >>= last bit length */
1313 movd hold_mm, %ebp
1314
1315 emms
1316
1317.L_update_hold:
1318
1319#endif /* USE_MMX || RUN_TIME_MMX */
1320
1321 andl %ebx, %ebp
1322 movl %ebp, hold_state(state_r)
1323
1324#define last_r %ebx
1325
1326 /* strm->avail_in = in < last ? 11 + (last - in) : 11 - (in - last) */
1327 movl last(%esp), last_r
1328 cmpl in_r, last_r
1329 jbe .L_last_is_smaller /* if (in >= last) */
1330
1331 subl in_r, last_r /* last -= in */
1332 addl $11, last_r /* last += 11 */
1333 movl last_r, avail_in_strm(strm_r)
1334 jmp .L_fixup_out
1335.L_last_is_smaller:
1336 subl last_r, in_r /* in -= last */
1337 negl in_r /* in = -in */
1338 addl $11, in_r /* in += 11 */
1339 movl in_r, avail_in_strm(strm_r)
1340
1341#undef last_r
1342#define end_r %ebx
1343
1344.L_fixup_out:
1345 /* strm->avail_out = out < end ? 257 + (end - out) : 257 - (out - end)*/
1346 movl end(%esp), end_r
1347 cmpl out_r, end_r
1348 jbe .L_end_is_smaller /* if (out >= end) */
1349
1350 subl out_r, end_r /* end -= out */
1351 addl $257, end_r /* end += 257 */
1352 movl end_r, avail_out_strm(strm_r)
1353 jmp .L_done
1354.L_end_is_smaller:
1355 subl end_r, out_r /* out -= end */
1356 negl out_r /* out = -out */
1357 addl $257, out_r /* out += 257 */
1358 movl out_r, avail_out_strm(strm_r)
1359
1360#undef end_r
1361#undef strm_r
1362#undef state_r
1363
1364.L_done:
1365 addl $local_var_size, %esp
1366 popf
1367 popl %ebx
1368 popl %ebp
1369 popl %esi
1370 popl %edi
1371 ret
1372
1373#if defined( GAS_ELF )
1374/* elf info */
1375.type inflate_fast,@function
1376.size inflate_fast,.-inflate_fast
1377#endif
diff --git a/contrib/minizip/ChangeLogUnzip b/contrib/minizip/ChangeLogUnzip
index 9987c54..18316fc 100644
--- a/contrib/minizip/ChangeLogUnzip
+++ b/contrib/minizip/ChangeLogUnzip
@@ -1,3 +1,12 @@
1Change in 0.21: (10 Mar 03)
2- bug fixes
3
4Change in 0.17: (27 Jan 02)
5- bug fixes
6
7Change in 0.16: (19 Jan 02)
8- Support of ioapi for virtualize zip file access
9
1Change in 0.15: (19 Mar 98) 10Change in 0.15: (19 Mar 98)
2- fix memory leak in minizip.c 11- fix memory leak in minizip.c
3 12
diff --git a/contrib/minizip/Makefile b/contrib/minizip/Makefile
index a1dfc16..84eaad2 100644
--- a/contrib/minizip/Makefile
+++ b/contrib/minizip/Makefile
@@ -1,8 +1,8 @@
1CC=cc 1CC=cc
2CFLAGS=-O -I../.. 2CFLAGS=-O -I../..
3 3
4UNZ_OBJS = miniunz.o unzip.o ../../libz.a 4UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
5ZIP_OBJS = minizip.o zip.o ../../libz.a 5ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
6 6
7.c.o: 7.c.o:
8 $(CC) -c $(CFLAGS) $*.c 8 $(CC) -c $(CFLAGS) $*.c
diff --git a/contrib/minizip/crypt.h b/contrib/minizip/crypt.h
new file mode 100644
index 0000000..e5bc627
--- /dev/null
+++ b/contrib/minizip/crypt.h
@@ -0,0 +1,104 @@
1
2#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
3
4/***********************************************************************
5 * Return the next byte in the pseudo-random sequence
6 */
7static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
8{
9 unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
10 * unpredictable manner on 16-bit systems; not a problem
11 * with any known compiler so far, though */
12
13 temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
14 return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
15}
16
17/***********************************************************************
18 * Update the encryption keys with the next byte of plain text
19 */
20static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
21{
22 (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
23 (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
24 (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
25 {
26 register int keyshift = (int)((*(pkeys+1)) >> 24);
27 (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
28 }
29 return c;
30}
31
32
33/***********************************************************************
34 * Initialize the encryption keys and the random header according to
35 * the given password.
36 */
37static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
38{
39 *(pkeys+0) = 305419896L;
40 *(pkeys+1) = 591751049L;
41 *(pkeys+2) = 878082192L;
42 while (*passwd != '\0') {
43 update_keys(pkeys,pcrc_32_tab,(int)*passwd);
44 passwd++;
45 }
46}
47
48#define zdecode(pkeys,pcrc_32_tab,c) \
49 (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
50
51#define zencode(pkeys,pcrc_32_tab,c,t) \
52 (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
53
54#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
55
56#define RAND_HEAD_LEN 12
57 /* "last resort" source for second part of crypt seed pattern */
58# ifndef ZCR_SEED2
59# define ZCR_SEED2 (unsigned long)3141592654L /* use PI as default pattern */
60# endif
61
62static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
63 const char *passwd; /* password string */
64 unsigned char *buf; /* where to write header */
65 int bufSize;
66 unsigned long* pkeys;
67 const unsigned long* pcrc_32_tab;
68 unsigned long crcForCrypting;
69{
70 int n; /* index in random header */
71 int t; /* temporary */
72 int c; /* random byte */
73 unsigned char header[RAND_HEAD_LEN-2]; /* random header */
74 static unsigned calls = 0; /* ensure different random header each time */
75
76 if (bufSize<RAND_HEAD_LEN)
77 return 0;
78
79 /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
80 * output of rand() to get less predictability, since rand() is
81 * often poorly implemented.
82 */
83 if (++calls == 1)
84 {
85 srand((unsigned)(time(NULL) ^ ZCR_SEED2));
86 }
87 init_keys(passwd, pkeys, pcrc_32_tab);
88 for (n = 0; n < RAND_HEAD_LEN-2; n++)
89 {
90 c = (rand() >> 7) & 0xff;
91 header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
92 }
93 /* Encrypt random header (last two bytes is high word of crc) */
94 init_keys(passwd, pkeys, pcrc_32_tab);
95 for (n = 0; n < RAND_HEAD_LEN-2; n++)
96 {
97 buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
98 }
99 buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
100 buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
101 return n;
102}
103
104#endif
diff --git a/contrib/minizip/ioapi.c b/contrib/minizip/ioapi.c
new file mode 100644
index 0000000..d35d5f5
--- /dev/null
+++ b/contrib/minizip/ioapi.c
@@ -0,0 +1,177 @@
1/* ioapi.c -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API
3
4 Version 0.21, March 10th, 2003
5
6 Copyright (C) 1998-2003 Gilles Vollant
7*/
8
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13#include "zlib.h"
14#include "ioapi.h"
15
16
17
18/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
19
20#ifndef SEEK_CUR
21#define SEEK_CUR 1
22#endif
23
24#ifndef SEEK_END
25#define SEEK_END 2
26#endif
27
28#ifndef SEEK_SET
29#define SEEK_SET 0
30#endif
31
32voidpf ZCALLBACK fopen_file_func OF((
33 voidpf opaque,
34 const char* filename,
35 int mode));
36
37uLong ZCALLBACK fread_file_func OF((
38 voidpf opaque,
39 voidpf stream,
40 void* buf,
41 uLong size));
42
43uLong ZCALLBACK fwrite_file_func OF((
44 voidpf opaque,
45 voidpf stream,
46 const void* buf,
47 uLong size));
48
49long ZCALLBACK ftell_file_func OF((
50 voidpf opaque,
51 voidpf stream));
52
53long ZCALLBACK fseek_file_func OF((
54 voidpf opaque,
55 voidpf stream,
56 uLong offset,
57 int origin));
58
59int ZCALLBACK fclose_file_func OF((
60 voidpf opaque,
61 voidpf stream));
62
63int ZCALLBACK ferror_file_func OF((
64 voidpf opaque,
65 voidpf stream));
66
67
68voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
69 voidpf opaque;
70 const char* filename;
71 int mode;
72{
73 FILE* file = NULL;
74 const char* mode_fopen = NULL;
75 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
76 mode_fopen = "rb";
77 else
78 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
79 mode_fopen = "r+b";
80 else
81 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
82 mode_fopen = "wb";
83
84 if ((filename!=NULL) && (mode_fopen != NULL))
85 file = fopen(filename, mode_fopen);
86 return file;
87}
88
89
90uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
91 voidpf opaque;
92 voidpf stream;
93 void* buf;
94 uLong size;
95{
96 uLong ret;
97 ret = fread(buf, 1, (size_t)size, (FILE *)stream);
98 return ret;
99}
100
101
102uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
103 voidpf opaque;
104 voidpf stream;
105 const void* buf;
106 uLong size;
107{
108 uLong ret;
109 ret = fwrite(buf, 1, (size_t)size, (FILE *)stream);
110 return ret;
111}
112
113long ZCALLBACK ftell_file_func (opaque, stream)
114 voidpf opaque;
115 voidpf stream;
116{
117 long ret;
118 ret = ftell((FILE *)stream);
119 return ret;
120}
121
122long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
123 voidpf opaque;
124 voidpf stream;
125 uLong offset;
126 int origin;
127{
128 int fseek_origin=0;
129 long ret;
130 switch (origin)
131 {
132 case ZLIB_FILEFUNC_SEEK_CUR :
133 fseek_origin = SEEK_CUR;
134 break;
135 case ZLIB_FILEFUNC_SEEK_END :
136 fseek_origin = SEEK_END;
137 break;
138 case ZLIB_FILEFUNC_SEEK_SET :
139 fseek_origin = SEEK_SET;
140 break;
141 default: return -1;
142 }
143 ret = 0;
144 fseek((FILE *)stream, offset, fseek_origin);
145 return ret;
146}
147
148int ZCALLBACK fclose_file_func (opaque, stream)
149 voidpf opaque;
150 voidpf stream;
151{
152 int ret;
153 ret = fclose((FILE *)stream);
154 return ret;
155}
156
157int ZCALLBACK ferror_file_func (opaque, stream)
158 voidpf opaque;
159 voidpf stream;
160{
161 int ret;
162 ret = ferror((FILE *)stream);
163 return ret;
164}
165
166void fill_fopen_filefunc (pzlib_filefunc_def)
167 zlib_filefunc_def* pzlib_filefunc_def;
168{
169 pzlib_filefunc_def->zopen_file = fopen_file_func;
170 pzlib_filefunc_def->zread_file = fread_file_func;
171 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
172 pzlib_filefunc_def->ztell_file = ftell_file_func;
173 pzlib_filefunc_def->zseek_file = fseek_file_func;
174 pzlib_filefunc_def->zclose_file = fclose_file_func;
175 pzlib_filefunc_def->zerror_file = ferror_file_func;
176 pzlib_filefunc_def->opaque = NULL;
177}
diff --git a/contrib/minizip/ioapi.h b/contrib/minizip/ioapi.h
new file mode 100644
index 0000000..f30fe7a
--- /dev/null
+++ b/contrib/minizip/ioapi.h
@@ -0,0 +1,75 @@
1/* ioapi.h -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API
3
4 Version 0.21, March 10th, 2003
5
6 Copyright (C) 1998-2003 Gilles Vollant
7*/
8
9#ifndef _ZLIBIOAPI_H
10#define _ZLIBIOAPI_H
11
12
13#define ZLIB_FILEFUNC_SEEK_CUR (1)
14#define ZLIB_FILEFUNC_SEEK_END (2)
15#define ZLIB_FILEFUNC_SEEK_SET (0)
16
17#define ZLIB_FILEFUNC_MODE_READ (1)
18#define ZLIB_FILEFUNC_MODE_WRITE (2)
19#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
20
21#define ZLIB_FILEFUNC_MODE_EXISTING (4)
22#define ZLIB_FILEFUNC_MODE_CREATE (8)
23
24
25#ifndef ZCALLBACK
26
27#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
28#define ZCALLBACK CALLBACK
29#else
30#define ZCALLBACK
31#endif
32#endif
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
39typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
40typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
41typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
42typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
43typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
44typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
45
46typedef struct zlib_filefunc_def_s
47{
48 open_file_func zopen_file;
49 read_file_func zread_file;
50 write_file_func zwrite_file;
51 tell_file_func ztell_file;
52 seek_file_func zseek_file;
53 close_file_func zclose_file;
54 testerror_file_func zerror_file;
55 voidpf opaque;
56} zlib_filefunc_def;
57
58
59
60void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
61
62#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
63#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
64#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
65#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
66#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
67#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
68
69
70#ifdef __cplusplus
71}
72#endif
73
74#endif
75
diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c
new file mode 100644
index 0000000..f1f5546
--- /dev/null
+++ b/contrib/minizip/iowin32.c
@@ -0,0 +1,271 @@
1/* iowin32.c -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API
3 This IO API version uses the Win32 API (for Microsoft Windows)
4
5 Version 0.21, March 10th, 2003
6
7 Copyright (C) 1998-2003 Gilles Vollant
8*/
9
10#include <windows.h>
11#include <stdlib.h>
12
13#include "zlib.h"
14#include "ioapi.h"
15#include "iowin32.h"
16
17#ifndef INVALID_HANDLE_VALUE
18#define INVALID_HANDLE_VALUE (0xFFFFFFFF)
19#endif
20
21#ifndef INVALID_SET_FILE_POINTER
22#define INVALID_SET_FILE_POINTER ((DWORD)-1)
23#endif
24
25voidpf ZCALLBACK win32_open_file_func OF((
26 voidpf opaque,
27 const char* filename,
28 int mode));
29
30uLong ZCALLBACK win32_read_file_func OF((
31 voidpf opaque,
32 voidpf stream,
33 void* buf,
34 uLong size));
35
36uLong ZCALLBACK win32_write_file_func OF((
37 voidpf opaque,
38 voidpf stream,
39 const void* buf,
40 uLong size));
41
42long ZCALLBACK win32_tell_file_func OF((
43 voidpf opaque,
44 voidpf stream));
45
46long ZCALLBACK win32_seek_file_func OF((
47 voidpf opaque,
48 voidpf stream,
49 uLong offset,
50 int origin));
51
52long ZCALLBACK win32_close_file_func OF((
53 voidpf opaque,
54 voidpf stream));
55
56int ZCALLBACK win32_error_file_func OF((
57 voidpf opaque,
58 voidpf stream));
59
60typedef struct
61{
62 HANDLE hf;
63 int error;
64} WIN32FILE_IOWIN;
65
66voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode)
67 voidpf opaque;
68 const char* filename;
69 int mode;
70{
71 const char* mode_fopen = NULL;
72 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
73 HANDLE hFile = 0;
74 voidpf ret=NULL;
75
76 dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0;
77
78 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
79 {
80 dwDesiredAccess = GENERIC_READ;
81 dwCreationDisposition = OPEN_EXISTING;
82 dwShareMode = FILE_SHARE_READ;
83 }
84 else
85 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
86 {
87 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
88 dwCreationDisposition = OPEN_EXISTING;
89 }
90 else
91 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
92 {
93 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
94 dwCreationDisposition = CREATE_ALWAYS;
95 }
96
97 if ((filename!=NULL) && (dwDesiredAccess != 0))
98 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL,
99 dwCreationDisposition, dwFlagsAndAttributes, NULL);
100
101 if (hFile == INVALID_HANDLE_VALUE)
102 hFile = NULL;
103
104 if (hFile != NULL)
105 {
106 WIN32FILE_IOWIN w32fiow;
107 w32fiow.hf = hFile;
108 w32fiow.error = 0;
109 ret = malloc(sizeof(WIN32FILE_IOWIN));
110 if (ret==NULL)
111 CloseHandle(hFile);
112 else *((WIN32FILE_IOWIN*)ret) = w32fiow;
113 }
114 return ret;
115}
116
117
118uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size)
119 voidpf opaque;
120 voidpf stream;
121 void* buf;
122 uLong size;
123{
124 uLong ret=0;
125 HANDLE hFile = NULL;
126 if (stream!=NULL)
127 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
128 if (hFile != NULL)
129 if (!ReadFile(hFile, buf, size, &ret, NULL))
130 {
131 DWORD dwErr = GetLastError();
132 if (dwErr == ERROR_HANDLE_EOF)
133 dwErr = 0;
134 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
135 }
136
137 return ret;
138}
139
140
141uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size)
142 voidpf opaque;
143 voidpf stream;
144 const void* buf;
145 uLong size;
146{
147 uLong ret=0;
148 HANDLE hFile = NULL;
149 if (stream!=NULL)
150 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
151
152 if (hFile !=NULL)
153 if (!WriteFile(hFile, buf, size, &ret, NULL))
154 {
155 DWORD dwErr = GetLastError();
156 if (dwErr == ERROR_HANDLE_EOF)
157 dwErr = 0;
158 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
159 }
160
161 return ret;
162}
163
164long ZCALLBACK win32_tell_file_func (opaque, stream)
165 voidpf opaque;
166 voidpf stream;
167{
168 long ret=-1;
169 HANDLE hFile = NULL;
170 if (stream!=NULL)
171 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
172 if (hFile != NULL)
173 {
174 DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);
175 if (dwSet == INVALID_SET_FILE_POINTER)
176 {
177 DWORD dwErr = GetLastError();
178 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
179 ret = -1;
180 }
181 else
182 ret=(long)dwSet;
183 }
184 return ret;
185}
186
187long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin)
188 voidpf opaque;
189 voidpf stream;
190 uLong offset;
191 int origin;
192{
193 DWORD dwMoveMethod=0xFFFFFFFF;
194 HANDLE hFile = NULL;
195
196 long ret=-1;
197 if (stream!=NULL)
198 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
199 switch (origin)
200 {
201 case ZLIB_FILEFUNC_SEEK_CUR :
202 dwMoveMethod = FILE_CURRENT;
203 break;
204 case ZLIB_FILEFUNC_SEEK_END :
205 dwMoveMethod = FILE_END;
206 break;
207 case ZLIB_FILEFUNC_SEEK_SET :
208 dwMoveMethod = FILE_BEGIN;
209 break;
210 default: return -1;
211 }
212
213 if (hFile != NULL)
214 {
215 DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod);
216 if (dwSet == INVALID_SET_FILE_POINTER)
217 {
218 DWORD dwErr = GetLastError();
219 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
220 ret = -1;
221 }
222 else
223 ret=0;
224 }
225 return ret;
226}
227
228long ZCALLBACK win32_close_file_func (opaque, stream)
229 voidpf opaque;
230 voidpf stream;
231{
232 long ret=-1;
233
234 if (stream!=NULL)
235 {
236 HANDLE hFile;
237 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
238 if (hFile != NULL)
239 {
240 CloseHandle(hFile);
241 ret=0;
242 }
243 free(stream);
244 }
245 return ret;
246}
247
248int ZCALLBACK win32_error_file_func (opaque, stream)
249 voidpf opaque;
250 voidpf stream;
251{
252 int ret=-1;
253 if (stream!=NULL)
254 {
255 ret = ((WIN32FILE_IOWIN*)stream) -> error;
256 }
257 return ret;
258}
259
260void fill_win32_filefunc (pzlib_filefunc_def)
261 zlib_filefunc_def* pzlib_filefunc_def;
262{
263 pzlib_filefunc_def->zopen_file = win32_open_file_func;
264 pzlib_filefunc_def->zread_file = win32_read_file_func;
265 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
266 pzlib_filefunc_def->ztell_file = win32_tell_file_func;
267 pzlib_filefunc_def->zseek_file = win32_seek_file_func;
268 pzlib_filefunc_def->zclose_file = win32_close_file_func;
269 pzlib_filefunc_def->zerror_file = win32_error_file_func;
270 pzlib_filefunc_def->opaque=NULL;
271}
diff --git a/contrib/minizip/iowin32.h b/contrib/minizip/iowin32.h
new file mode 100644
index 0000000..d2f5e37
--- /dev/null
+++ b/contrib/minizip/iowin32.h
@@ -0,0 +1,19 @@
1/* iowin32.h -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API
3 This IO API version uses the Win32 API (for Microsoft Windows)
4
5 Version 0.21, March 10th, 2003
6
7 Copyright (C) 1998-2003 Gilles Vollant
8*/
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
15
16
17#ifdef __cplusplus
18}
19#endif
diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c
index f3b7832..938d4ef 100644
--- a/contrib/minizip/miniunz.c
+++ b/contrib/minizip/miniunz.c
@@ -17,7 +17,12 @@
17 17
18#define CASESENSITIVITY (0) 18#define CASESENSITIVITY (0)
19#define WRITEBUFFERSIZE (8192) 19#define WRITEBUFFERSIZE (8192)
20#define MAXFILENAME (256)
20 21
22#ifdef WIN32
23#define USEWIN32IOAPI
24#include "iowin32.h"
25#endif
21/* 26/*
22 mini unzip, demo of unzip package 27 mini unzip, demo of unzip package
23 28
@@ -34,9 +39,9 @@
34 dosdate : the new date at the MSDos format (4 bytes) 39 dosdate : the new date at the MSDos format (4 bytes)
35 tmu_date : the SAME new date at the tm_unz format */ 40 tmu_date : the SAME new date at the tm_unz format */
36void change_file_date(filename,dosdate,tmu_date) 41void change_file_date(filename,dosdate,tmu_date)
37 const char *filename; 42 const char *filename;
38 uLong dosdate; 43 uLong dosdate;
39 tm_unz tmu_date; 44 tm_unz tmu_date;
40{ 45{
41#ifdef WIN32 46#ifdef WIN32
42 HANDLE hFile; 47 HANDLE hFile;
@@ -75,17 +80,17 @@ void change_file_date(filename,dosdate,tmu_date)
75 As I don't know well Unix, I wait feedback for the unix portion */ 80 As I don't know well Unix, I wait feedback for the unix portion */
76 81
77int mymkdir(dirname) 82int mymkdir(dirname)
78 const char* dirname; 83 const char* dirname;
79{ 84{
80 int ret=0; 85 int ret=0;
81#ifdef WIN32 86#ifdef WIN32
82 ret = mkdir(dirname); 87 ret = mkdir(dirname);
83#else 88#else
84#ifdef unix 89#ifdef unix
85 ret = mkdir (dirname,0775); 90 ret = mkdir (dirname,0775);
86#endif 91#endif
87#endif 92#endif
88 return ret; 93 return ret;
89} 94}
90 95
91int makedir (newdir) 96int makedir (newdir)
@@ -93,14 +98,14 @@ int makedir (newdir)
93{ 98{
94 char *buffer ; 99 char *buffer ;
95 char *p; 100 char *p;
96 int len = strlen(newdir); 101 int len = (int)strlen(newdir);
97 102
98 if (len <= 0) 103 if (len <= 0)
99 return 0; 104 return 0;
100 105
101 buffer = (char*)malloc(len+1); 106 buffer = (char*)malloc(len+1);
102 strcpy(buffer,newdir); 107 strcpy(buffer,newdir);
103 108
104 if (buffer[len-1] == '/') { 109 if (buffer[len-1] == '/') {
105 buffer[len-1] = '\0'; 110 buffer[len-1] = '\0';
106 } 111 }
@@ -135,104 +140,105 @@ int makedir (newdir)
135 140
136void do_banner() 141void do_banner()
137{ 142{
138 printf("MiniUnz 0.15, demo of zLib + Unz package written by Gilles Vollant\n"); 143 printf("MiniUnz 0.15, demo of zLib + Unz package written by Gilles Vollant\n");
139 printf("more info at http://wwww.winimage/zLibDll/unzip.htm\n\n"); 144 printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
140} 145}
141 146
142void do_help() 147void do_help()
143{ 148{
144 printf("Usage : miniunz [-exvlo] file.zip [file_to_extract]\n\n") ; 149 printf("Usage : miniunz [-exvlo] file.zip [file_to_extract]\n\n") ;
145} 150}
146 151
147 152
148int do_list(uf) 153int do_list(uf)
149 unzFile uf; 154 unzFile uf;
150{ 155{
151 uLong i; 156 uLong i;
152 unz_global_info gi; 157 unz_global_info gi;
153 int err; 158 int err;
154 159
155 err = unzGetGlobalInfo (uf,&gi); 160 err = unzGetGlobalInfo (uf,&gi);
156 if (err!=UNZ_OK) 161 if (err!=UNZ_OK)
157 printf("error %d with zipfile in unzGetGlobalInfo \n",err); 162 printf("error %d with zipfile in unzGetGlobalInfo \n",err);
158 printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); 163 printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
159 printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); 164 printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
160 for (i=0;i<gi.number_entry;i++) 165 for (i=0;i<gi.number_entry;i++)
161 { 166 {
162 char filename_inzip[256]; 167 char filename_inzip[256];
163 unz_file_info file_info; 168 unz_file_info file_info;
164 uLong ratio=0; 169 uLong ratio=0;
165 const char *string_method; 170 const char *string_method;
166 err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); 171 err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
167 if (err!=UNZ_OK) 172 if (err!=UNZ_OK)
168 { 173 {
169 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); 174 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
170 break; 175 break;
171 } 176 }
172 if (file_info.uncompressed_size>0) 177 if (file_info.uncompressed_size>0)
173 ratio = (file_info.compressed_size*100)/file_info.uncompressed_size; 178 ratio = (file_info.compressed_size*100)/file_info.uncompressed_size;
174 179
175 if (file_info.compression_method==0) 180 if (file_info.compression_method==0)
176 string_method="Stored"; 181 string_method="Stored";
177 else 182 else
178 if (file_info.compression_method==Z_DEFLATED) 183 if (file_info.compression_method==Z_DEFLATED)
179 { 184 {
180 uInt iLevel=(uInt)((file_info.flag & 0x6)/2); 185 uInt iLevel=(uInt)((file_info.flag & 0x6)/2);
181 if (iLevel==0) 186 if (iLevel==0)
182 string_method="Defl:N"; 187 string_method="Defl:N";
183 else if (iLevel==1) 188 else if (iLevel==1)
184 string_method="Defl:X"; 189 string_method="Defl:X";
185 else if ((iLevel==2) || (iLevel==3)) 190 else if ((iLevel==2) || (iLevel==3))
186 string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ 191 string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
187 } 192 }
188 else 193 else
189 string_method="Unkn. "; 194 string_method="Unkn. ";
190 195
191 printf("%7lu %6s %7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", 196 printf("%7lu %6s %7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
192 file_info.uncompressed_size,string_method,file_info.compressed_size, 197 file_info.uncompressed_size,string_method,file_info.compressed_size,
193 ratio, 198 ratio,
194 (uLong)file_info.tmu_date.tm_mon + 1, 199 (uLong)file_info.tmu_date.tm_mon + 1,
195 (uLong)file_info.tmu_date.tm_mday, 200 (uLong)file_info.tmu_date.tm_mday,
196 (uLong)file_info.tmu_date.tm_year % 100, 201 (uLong)file_info.tmu_date.tm_year % 100,
197 (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min, 202 (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min,
198 (uLong)file_info.crc,filename_inzip); 203 (uLong)file_info.crc,filename_inzip);
199 if ((i+1)<gi.number_entry) 204 if ((i+1)<gi.number_entry)
200 { 205 {
201 err = unzGoToNextFile(uf); 206 err = unzGoToNextFile(uf);
202 if (err!=UNZ_OK) 207 if (err!=UNZ_OK)
203 { 208 {
204 printf("error %d with zipfile in unzGoToNextFile\n",err); 209 printf("error %d with zipfile in unzGoToNextFile\n",err);
205 break; 210 break;
206 } 211 }
207 } 212 }
208 } 213 }
209 214
210 return 0; 215 return 0;
211} 216}
212 217
213 218
214int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite) 219int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
215 unzFile uf; 220 unzFile uf;
216 const int* popt_extract_without_path; 221 const int* popt_extract_without_path;
217 int* popt_overwrite; 222 int* popt_overwrite;
223 const char* password;
218{ 224{
219 char filename_inzip[256]; 225 char filename_inzip[256];
220 char* filename_withoutpath; 226 char* filename_withoutpath;
221 char* p; 227 char* p;
222 int err=UNZ_OK; 228 int err=UNZ_OK;
223 FILE *fout=NULL; 229 FILE *fout=NULL;
224 void* buf; 230 void* buf;
225 uInt size_buf; 231 uInt size_buf;
226
227 unz_file_info file_info;
228 uLong ratio=0;
229 err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
230 232
231 if (err!=UNZ_OK) 233 unz_file_info file_info;
232 { 234 uLong ratio=0;
233 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); 235 err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
234 return err; 236
235 } 237 if (err!=UNZ_OK)
238 {
239 printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
240 return err;
241 }
236 242
237 size_buf = WRITEBUFFERSIZE; 243 size_buf = WRITEBUFFERSIZE;
238 buf = (void*)malloc(size_buf); 244 buf = (void*)malloc(size_buf);
@@ -242,71 +248,71 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite)
242 return UNZ_INTERNALERROR; 248 return UNZ_INTERNALERROR;
243 } 249 }
244 250
245 p = filename_withoutpath = filename_inzip; 251 p = filename_withoutpath = filename_inzip;
246 while ((*p) != '\0') 252 while ((*p) != '\0')
247 { 253 {
248 if (((*p)=='/') || ((*p)=='\\')) 254 if (((*p)=='/') || ((*p)=='\\'))
249 filename_withoutpath = p+1; 255 filename_withoutpath = p+1;
250 p++; 256 p++;
251 } 257 }
252 258
253 if ((*filename_withoutpath)=='\0') 259 if ((*filename_withoutpath)=='\0')
254 { 260 {
255 if ((*popt_extract_without_path)==0) 261 if ((*popt_extract_without_path)==0)
256 { 262 {
257 printf("creating directory: %s\n",filename_inzip); 263 printf("creating directory: %s\n",filename_inzip);
258 mymkdir(filename_inzip); 264 mymkdir(filename_inzip);
259 } 265 }
260 } 266 }
261 else 267 else
262 { 268 {
263 const char* write_filename; 269 const char* write_filename;
264 int skip=0; 270 int skip=0;
265 271
266 if ((*popt_extract_without_path)==0) 272 if ((*popt_extract_without_path)==0)
267 write_filename = filename_inzip; 273 write_filename = filename_inzip;
268 else 274 else
269 write_filename = filename_withoutpath; 275 write_filename = filename_withoutpath;
270 276
271 err = unzOpenCurrentFile(uf); 277 err = unzOpenCurrentFilePassword(uf,password);
272 if (err!=UNZ_OK) 278 if (err!=UNZ_OK)
273 { 279 {
274 printf("error %d with zipfile in unzOpenCurrentFile\n",err); 280 printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err);
275 } 281 }
276 282
277 if (((*popt_overwrite)==0) && (err==UNZ_OK)) 283 if (((*popt_overwrite)==0) && (err==UNZ_OK))
278 { 284 {
279 char rep; 285 char rep=0;
280 FILE* ftestexist; 286 FILE* ftestexist;
281 ftestexist = fopen(write_filename,"rb"); 287 ftestexist = fopen(write_filename,"rb");
282 if (ftestexist!=NULL) 288 if (ftestexist!=NULL)
283 { 289 {
284 fclose(ftestexist); 290 fclose(ftestexist);
285 do 291 do
286 { 292 {
287 char answer[128]; 293 char answer[128];
288 printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename); 294 printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
289 scanf("%1s",answer); 295 scanf("%1s",answer);
290 rep = answer[0] ; 296 rep = answer[0] ;
291 if ((rep>='a') && (rep<='z')) 297 if ((rep>='a') && (rep<='z'))
292 rep -= 0x20; 298 rep -= 0x20;
293 } 299 }
294 while ((rep!='Y') && (rep!='N') && (rep!='A')); 300 while ((rep!='Y') && (rep!='N') && (rep!='A'));
295 } 301 }
296 302
297 if (rep == 'N') 303 if (rep == 'N')
298 skip = 1; 304 skip = 1;
299 305
300 if (rep == 'A') 306 if (rep == 'A')
301 *popt_overwrite=1; 307 *popt_overwrite=1;
302 } 308 }
303 309
304 if ((skip==0) && (err==UNZ_OK)) 310 if ((skip==0) && (err==UNZ_OK))
305 { 311 {
306 fout=fopen(write_filename,"wb"); 312 fout=fopen(write_filename,"wb");
307 313
308 /* some zipfile don't contain directory alone before file */ 314 /* some zipfile don't contain directory alone before file */
309 if ((fout==NULL) && ((*popt_extract_without_path)==0) && 315 if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
310 (filename_withoutpath!=(char*)filename_inzip)) 316 (filename_withoutpath!=(char*)filename_inzip))
311 { 317 {
312 char c=*(filename_withoutpath-1); 318 char c=*(filename_withoutpath-1);
@@ -316,95 +322,100 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite)
316 fout=fopen(write_filename,"wb"); 322 fout=fopen(write_filename,"wb");
317 } 323 }
318 324
319 if (fout==NULL) 325 if (fout==NULL)
320 { 326 {
321 printf("error opening %s\n",write_filename); 327 printf("error opening %s\n",write_filename);
322 } 328 }
323 } 329 }
324 330
325 if (fout!=NULL) 331 if (fout!=NULL)
326 { 332 {
327 printf(" extracting: %s\n",write_filename); 333 printf(" extracting: %s\n",write_filename);
328 334
329 do 335 do
330 { 336 {
331 err = unzReadCurrentFile(uf,buf,size_buf); 337 err = unzReadCurrentFile(uf,buf,size_buf);
332 if (err<0) 338 if (err<0)
333 { 339 {
334 printf("error %d with zipfile in unzReadCurrentFile\n",err); 340 printf("error %d with zipfile in unzReadCurrentFile\n",err);
335 break; 341 break;
336 } 342 }
337 if (err>0) 343 if (err>0)
338 if (fwrite(buf,err,1,fout)!=1) 344 if (fwrite(buf,err,1,fout)!=1)
339 { 345 {
340 printf("error in writing extracted file\n"); 346 printf("error in writing extracted file\n");
341 err=UNZ_ERRNO; 347 err=UNZ_ERRNO;
342 break; 348 break;
343 } 349 }
344 } 350 }
345 while (err>0); 351 while (err>0);
346 fclose(fout); 352 if (fout)
347 if (err==0) 353 fclose(fout);
348 change_file_date(write_filename,file_info.dosDate, 354
349 file_info.tmu_date); 355 if (err==0)
350 } 356 change_file_date(write_filename,file_info.dosDate,
357 file_info.tmu_date);
358 }
351 359
352 if (err==UNZ_OK) 360 if (err==UNZ_OK)
353 { 361 {
354 err = unzCloseCurrentFile (uf); 362 err = unzCloseCurrentFile (uf);
355 if (err!=UNZ_OK) 363 if (err!=UNZ_OK)
356 { 364 {
357 printf("error %d with zipfile in unzCloseCurrentFile\n",err); 365 printf("error %d with zipfile in unzCloseCurrentFile\n",err);
358 } 366 }
359 } 367 }
360 else 368 else
361 unzCloseCurrentFile(uf); /* don't lose the error */ 369 unzCloseCurrentFile(uf); /* don't lose the error */
362 } 370 }
363 371
364 free(buf); 372 free(buf);
365 return err; 373 return err;
366} 374}
367 375
368 376
369int do_extract(uf,opt_extract_without_path,opt_overwrite) 377int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
370 unzFile uf; 378 unzFile uf;
371 int opt_extract_without_path; 379 int opt_extract_without_path;
372 int opt_overwrite; 380 int opt_overwrite;
381 const char* password;
373{ 382{
374 uLong i; 383 uLong i;
375 unz_global_info gi; 384 unz_global_info gi;
376 int err; 385 int err;
377 FILE* fout=NULL; 386 FILE* fout=NULL;
378 387
379 err = unzGetGlobalInfo (uf,&gi); 388 err = unzGetGlobalInfo (uf,&gi);
380 if (err!=UNZ_OK) 389 if (err!=UNZ_OK)
381 printf("error %d with zipfile in unzGetGlobalInfo \n",err); 390 printf("error %d with zipfile in unzGetGlobalInfo \n",err);
382 391
383 for (i=0;i<gi.number_entry;i++) 392 for (i=0;i<gi.number_entry;i++)
384 { 393 {
385 if (do_extract_currentfile(uf,&opt_extract_without_path, 394 if (do_extract_currentfile(uf,&opt_extract_without_path,
386 &opt_overwrite) != UNZ_OK) 395 &opt_overwrite,
396 password) != UNZ_OK)
387 break; 397 break;
388 398
389 if ((i+1)<gi.number_entry) 399 if ((i+1)<gi.number_entry)
390 { 400 {
391 err = unzGoToNextFile(uf); 401 err = unzGoToNextFile(uf);
392 if (err!=UNZ_OK) 402 if (err!=UNZ_OK)
393 { 403 {
394 printf("error %d with zipfile in unzGoToNextFile\n",err); 404 printf("error %d with zipfile in unzGoToNextFile\n",err);
395 break; 405 break;
396 } 406 }
397 } 407 }
398 } 408 }
399 409
400 return 0; 410 return 0;
401} 411}
402 412
403int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite) 413int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password)
404 unzFile uf; 414 unzFile uf;
405 const char* filename; 415 const char* filename;
406 int opt_extract_without_path; 416 int opt_extract_without_path;
407 int opt_overwrite; 417 int opt_overwrite;
418 const char* password;
408{ 419{
409 int err = UNZ_OK; 420 int err = UNZ_OK;
410 if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK) 421 if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
@@ -414,7 +425,8 @@ int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite)
414 } 425 }
415 426
416 if (do_extract_currentfile(uf,&opt_extract_without_path, 427 if (do_extract_currentfile(uf,&opt_extract_without_path,
417 &opt_overwrite) == UNZ_OK) 428 &opt_overwrite,
429 password) == UNZ_OK)
418 return 0; 430 return 0;
419 else 431 else
420 return 1; 432 return 1;
@@ -422,87 +434,110 @@ int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite)
422 434
423 435
424int main(argc,argv) 436int main(argc,argv)
425 int argc; 437 int argc;
426 char *argv[]; 438 char *argv[];
427{ 439{
428 const char *zipfilename=NULL; 440 const char *zipfilename=NULL;
429 const char *filename_to_extract=NULL; 441 const char *filename_to_extract=NULL;
430 int i; 442 const char *password=NULL;
431 int opt_do_list=0; 443 char filename_try[MAXFILENAME+16] = "";
432 int opt_do_extract=1; 444 int i;
433 int opt_do_extract_withoutpath=0; 445 int opt_do_list=0;
434 int opt_overwrite=0; 446 int opt_do_extract=1;
435 char filename_try[512]; 447 int opt_do_extract_withoutpath=0;
436 unzFile uf=NULL; 448 int opt_overwrite=0;
437 449 unzFile uf=NULL;
438 do_banner(); 450
439 if (argc==1) 451 do_banner();
440 { 452 if (argc==1)
441 do_help(); 453 {
442 exit(0); 454 do_help();
443 } 455 return 0;
444 else 456 }
445 { 457 else
446 for (i=1;i<argc;i++) 458 {
447 { 459 for (i=1;i<argc;i++)
448 if ((*argv[i])=='-') 460 {
449 { 461 if ((*argv[i])=='-')
450 const char *p=argv[i]+1; 462 {
451 463 const char *p=argv[i]+1;
452 while ((*p)!='\0') 464
453 { 465 while ((*p)!='\0')
454 char c=*(p++);; 466 {
455 if ((c=='l') || (c=='L')) 467 char c=*(p++);;
456 opt_do_list = 1; 468 if ((c=='l') || (c=='L'))
457 if ((c=='v') || (c=='V')) 469 opt_do_list = 1;
458 opt_do_list = 1; 470 if ((c=='v') || (c=='V'))
459 if ((c=='x') || (c=='X')) 471 opt_do_list = 1;
460 opt_do_extract = 1; 472 if ((c=='x') || (c=='X'))
461 if ((c=='e') || (c=='E')) 473 opt_do_extract = 1;
462 opt_do_extract = opt_do_extract_withoutpath = 1; 474 if ((c=='e') || (c=='E'))
463 if ((c=='o') || (c=='O')) 475 opt_do_extract = opt_do_extract_withoutpath = 1;
464 opt_overwrite=1; 476 if ((c=='o') || (c=='O'))
465 } 477 opt_overwrite=1;
466 } 478 if (((c=='p') || (c=='P')) && (i+1<argc))
467 else 479 {
480 password=argv[i+1];
481 i++;
482 }
483 }
484 }
485 else
468 { 486 {
469 if (zipfilename == NULL) 487 if (zipfilename == NULL)
470 zipfilename = argv[i]; 488 zipfilename = argv[i];
471 else if (filename_to_extract==NULL) 489 else if (filename_to_extract==NULL)
472 filename_to_extract = argv[i] ; 490 filename_to_extract = argv[i] ;
473 } 491 }
474 } 492 }
475 } 493 }
476 494
477 if (zipfilename!=NULL) 495 if (zipfilename!=NULL)
478 { 496 {
479 strcpy(filename_try,zipfilename); 497
480 uf = unzOpen(zipfilename); 498 #ifdef USEWIN32IOAPI
481 if (uf==NULL) 499 zlib_filefunc_def ffunc;
482 { 500 #endif
483 strcat(filename_try,".zip"); 501
484 uf = unzOpen(filename_try); 502 strncpy(filename_try, zipfilename,MAXFILENAME-1);
485 } 503 /* strncpy doesnt append the trailing NULL, of the string is too long. */
486 } 504 filename_try[ MAXFILENAME ] = '\0';
487 505
488 if (uf==NULL) 506 #ifdef USEWIN32IOAPI
489 { 507 fill_win32_filefunc(&ffunc);
490 printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename); 508 uf = unzOpen2(zipfilename,&ffunc);
491 exit (1); 509 #else
492 } 510 uf = unzOpen(zipfilename);
511 #endif
512 if (uf==NULL)
513 {
514 strcat(filename_try,".zip");
515 #ifdef USEWIN32IOAPI
516 uf = unzOpen2(filename_try,&ffunc);
517 #else
518 uf = unzOpen(filename_try);
519 #endif
520 }
521 }
522
523 if (uf==NULL)
524 {
525 printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename);
526 return 1;
527 }
493 printf("%s opened\n",filename_try); 528 printf("%s opened\n",filename_try);
494 529
495 if (opt_do_list==1) 530 if (opt_do_list==1)
496 return do_list(uf); 531 return do_list(uf);
497 else if (opt_do_extract==1) 532 else if (opt_do_extract==1)
498 { 533 {
499 if (filename_to_extract == NULL) 534 if (filename_to_extract == NULL)
500 return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite); 535 return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password);
501 else 536 else
502 return do_extract_onefile(uf,filename_to_extract, 537 return do_extract_onefile(uf,filename_to_extract,
503 opt_do_extract_withoutpath,opt_overwrite); 538 opt_do_extract_withoutpath,opt_overwrite,password);
504 } 539 }
505 unzCloseCurrentFile(uf); 540 unzCloseCurrentFile(uf);
506 541
507 return 0; /* to avoid warning */ 542 return 0;
508} 543}
diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c
index 5e492d2..5792a1e 100644
--- a/contrib/minizip/minizip.c
+++ b/contrib/minizip/minizip.c
@@ -17,6 +17,12 @@
17 17
18#include "zip.h" 18#include "zip.h"
19 19
20#ifdef WIN32
21#define USEWIN32IOAPI
22#include "iowin32.h"
23#endif
24
25
20 26
21#define WRITEBUFFERSIZE (16384) 27#define WRITEBUFFERSIZE (16384)
22#define MAXFILENAME (256) 28#define MAXFILENAME (256)
@@ -55,12 +61,16 @@ uLong filetime(f, tmzip, dt)
55 struct stat s; /* results of stat() */ 61 struct stat s; /* results of stat() */
56 struct tm* filedate; 62 struct tm* filedate;
57 time_t tm_t=0; 63 time_t tm_t=0;
58 64
59 if (strcmp(f,"-")!=0) 65 if (strcmp(f,"-")!=0)
60 { 66 {
61 char name[MAXFILENAME]; 67 char name[MAXFILENAME+1];
62 int len = strlen(f); 68 int len = strlen(f);
63 strcpy(name, f); 69
70 strncpy(name, f,MAXFILENAME-1);
71 /* strncpy doesnt append the trailing NULL, of the string is too long. */
72 name[ MAXFILENAME ] = '\0';
73
64 if (name[len - 1] == '/') 74 if (name[len - 1] == '/')
65 name[len - 1] = '\0'; 75 name[len - 1] = '\0';
66 /* not all systems allow stat'ing a file with / appended */ 76 /* not all systems allow stat'ing a file with / appended */
@@ -98,10 +108,10 @@ uLong filetime(f, tmzip, dt)
98int check_exist_file(filename) 108int check_exist_file(filename)
99 const char* filename; 109 const char* filename;
100{ 110{
101 FILE* ftestexist; 111 FILE* ftestexist;
102 int ret = 1; 112 int ret = 1;
103 ftestexist = fopen(filename,"rb"); 113 ftestexist = fopen(filename,"rb");
104 if (ftestexist==NULL) 114 if (ftestexist==NULL)
105 ret = 0; 115 ret = 0;
106 else 116 else
107 fclose(ftestexist); 117 fclose(ftestexist);
@@ -110,59 +120,107 @@ int check_exist_file(filename)
110 120
111void do_banner() 121void do_banner()
112{ 122{
113 printf("MiniZip 0.15, demo of zLib + Zip package written by Gilles Vollant\n"); 123 printf("MiniZip 0.15, demo of zLib + Zip package written by Gilles Vollant\n");
114 printf("more info at http://wwww.winimage/zLibDll/unzip.htm\n\n"); 124 printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
115} 125}
116 126
117void do_help() 127void do_help()
118{ 128{
119 printf("Usage : minizip [-o] file.zip [files_to_add]\n\n") ; 129 printf("Usage : minizip [-o] file.zip [files_to_add]\n\n") ;
130}
131
132/* calculate the CRC32 of a file,
133 because to encrypt a file, we need known the CRC32 of the file before */
134int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)
135{
136 unsigned long calculate_crc=0;
137 int err=ZIP_OK;
138 FILE * fin = fopen(filenameinzip,"rb");
139 unsigned long size_read = 0;
140 unsigned long total_read = 0;
141 if (fin==NULL)
142 {
143 err = ZIP_ERRNO;
144 }
145
146 if (err == ZIP_OK)
147 do
148 {
149 err = ZIP_OK;
150 size_read = (int)fread(buf,1,size_buf,fin);
151 if (size_read < size_buf)
152 if (feof(fin)==0)
153 {
154 printf("error in reading %s\n",filenameinzip);
155 err = ZIP_ERRNO;
156 }
157
158 if (size_read>0)
159 calculate_crc = crc32(calculate_crc,buf,size_read);
160 total_read += size_read;
161
162 } while ((err == ZIP_OK) && (size_read>0));
163
164 if (fin)
165 fclose(fin);
166
167 *result_crc=calculate_crc;
168 printf("file %s crc %x\n",filenameinzip,calculate_crc);
169 return err;
120} 170}
121 171
122int main(argc,argv) 172int main(argc,argv)
123 int argc; 173 int argc;
124 char *argv[]; 174 char *argv[];
125{ 175{
126 int i; 176 int i;
127 int opt_overwrite=0; 177 int opt_overwrite=0;
128 int opt_compress_level=Z_DEFAULT_COMPRESSION; 178 int opt_compress_level=Z_DEFAULT_COMPRESSION;
129 int zipfilenamearg = 0; 179 int zipfilenamearg = 0;
130 char filename_try[MAXFILENAME]; 180 char filename_try[MAXFILENAME+16];
131 int zipok; 181 int zipok;
132 int err=0; 182 int err=0;
133 int size_buf=0; 183 int size_buf=0;
134 void* buf=NULL, 184 void* buf=NULL;
185 const char* password=NULL;
135 186
136 187
137 do_banner(); 188 do_banner();
138 if (argc==1) 189 if (argc==1)
139 { 190 {
140 do_help(); 191 do_help();
141 exit(0);
142 return 0; 192 return 0;
143 } 193 }
144 else 194 else
145 { 195 {
146 for (i=1;i<argc;i++) 196 for (i=1;i<argc;i++)
147 { 197 {
148 if ((*argv[i])=='-') 198 if ((*argv[i])=='-')
149 { 199 {
150 const char *p=argv[i]+1; 200 const char *p=argv[i]+1;
151 201
152 while ((*p)!='\0') 202 while ((*p)!='\0')
153 { 203 {
154 char c=*(p++);; 204 char c=*(p++);;
155 if ((c=='o') || (c=='O')) 205 if ((c=='o') || (c=='O'))
156 opt_overwrite = 1; 206 opt_overwrite = 1;
207 if ((c=='a') || (c=='A'))
208 opt_overwrite = 2;
157 if ((c>='0') && (c<='9')) 209 if ((c>='0') && (c<='9'))
158 opt_compress_level = c-'0'; 210 opt_compress_level = c-'0';
159 } 211
160 } 212 if (((c=='p') || (c=='P')) && (i+1<argc))
161 else 213 {
162 if (zipfilenamearg == 0) 214 password=argv[i+1];
215 i++;
216 }
217 }
218 }
219 else
220 if (zipfilenamearg == 0)
163 zipfilenamearg = i ; 221 zipfilenamearg = i ;
164 } 222 }
165 } 223 }
166 224
167 size_buf = WRITEBUFFERSIZE; 225 size_buf = WRITEBUFFERSIZE;
168 buf = (void*)malloc(size_buf); 226 buf = (void*)malloc(size_buf);
@@ -172,16 +230,19 @@ int main(argc,argv)
172 return ZIP_INTERNALERROR; 230 return ZIP_INTERNALERROR;
173 } 231 }
174 232
175 if (zipfilenamearg==0) 233 if (zipfilenamearg==0)
176 zipok=0; 234 zipok=0;
177 else 235 else
178 { 236 {
179 int i,len; 237 int i,len;
180 int dot_found=0; 238 int dot_found=0;
181 239
182 zipok = 1 ; 240 zipok = 1 ;
183 strcpy(filename_try,argv[zipfilenamearg]); 241 strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
184 len=strlen(filename_try); 242 /* strncpy doesnt append the trailing NULL, of the string is too long. */
243 filename_try[ MAXFILENAME ] = '\0';
244
245 len=(int)strlen(filename_try);
185 for (i=0;i<len;i++) 246 for (i=0;i<len;i++)
186 if (filename_try[i]=='.') 247 if (filename_try[i]=='.')
187 dot_found=1; 248 dot_found=1;
@@ -189,36 +250,52 @@ int main(argc,argv)
189 if (dot_found==0) 250 if (dot_found==0)
190 strcat(filename_try,".zip"); 251 strcat(filename_try,".zip");
191 252
253 if (opt_overwrite==2)
254 {
255 /* if the file don't exist, we not append file */
256 if (check_exist_file(filename_try)==0)
257 opt_overwrite=1;
258 }
259 else
192 if (opt_overwrite==0) 260 if (opt_overwrite==0)
193 if (check_exist_file(filename_try)!=0) 261 if (check_exist_file(filename_try)!=0)
194 { 262 {
195 char rep; 263 char rep=0;
196 do 264 do
197 { 265 {
198 char answer[128]; 266 char answer[128];
199 printf("The file %s exist. Overwrite ? [y]es, [n]o : ",filename_try); 267 printf("The file %s exist. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
200 scanf("%1s",answer); 268 scanf("%1s",answer);
201 rep = answer[0] ; 269 rep = answer[0] ;
202 if ((rep>='a') && (rep<='z')) 270 if ((rep>='a') && (rep<='z'))
203 rep -= 0x20; 271 rep -= 0x20;
204 } 272 }
205 while ((rep!='Y') && (rep!='N')); 273 while ((rep!='Y') && (rep!='N') && (rep!='A'));
206 if (rep=='N') 274 if (rep=='N')
207 zipok = 0; 275 zipok = 0;
208 } 276 if (rep=='A')
277 opt_overwrite = 2;
278 }
209 } 279 }
210 280
211 if (zipok==1) 281 if (zipok==1)
212 { 282 {
213 zipFile zf; 283 zipFile zf;
214 int errclose; 284 int errclose;
215 zf = zipOpen(filename_try,0); 285 #ifdef USEWIN32IOAPI
286 zlib_filefunc_def ffunc;
287 fill_win32_filefunc(&ffunc);
288 zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
289 #else
290 zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0);
291 #endif
292
216 if (zf == NULL) 293 if (zf == NULL)
217 { 294 {
218 printf("error opening %s\n",filename_try); 295 printf("error opening %s\n",filename_try);
219 err= ZIP_ERRNO; 296 err= ZIP_ERRNO;
220 } 297 }
221 else 298 else
222 printf("creating %s\n",filename_try); 299 printf("creating %s\n",filename_try);
223 300
224 for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++) 301 for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
@@ -229,19 +306,31 @@ int main(argc,argv)
229 int size_read; 306 int size_read;
230 const char* filenameinzip = argv[i]; 307 const char* filenameinzip = argv[i];
231 zip_fileinfo zi; 308 zip_fileinfo zi;
309 unsigned long crcFile=0;
232 310
233 zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = 311 zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
234 zi.tmz_date.tm_mday = zi.tmz_date.tm_min = zi.tmz_date.tm_year = 0; 312 zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
235 zi.dosDate = 0; 313 zi.dosDate = 0;
236 zi.internal_fa = 0; 314 zi.internal_fa = 0;
237 zi.external_fa = 0; 315 zi.external_fa = 0;
238 filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); 316 filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
239 317
240 318/*
241 err = zipOpenNewFileInZip(zf,filenameinzip,&zi, 319 err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
242 NULL,0,NULL,0,NULL /* comment*/, 320 NULL,0,NULL,0,NULL / * comment * /,
243 (opt_compress_level != 0) ? Z_DEFLATED : 0, 321 (opt_compress_level != 0) ? Z_DEFLATED : 0,
244 opt_compress_level); 322 opt_compress_level);
323*/
324 if ((password != NULL) && (err==ZIP_OK))
325 err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
326
327 err = zipOpenNewFileInZip3(zf,filenameinzip,&zi,
328 NULL,0,NULL,0,NULL /* comment*/,
329 (opt_compress_level != 0) ? Z_DEFLATED : 0,
330 opt_compress_level,0,
331 /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
332 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
333 password,crcFile);
245 334
246 if (err != ZIP_OK) 335 if (err != ZIP_OK)
247 printf("error in opening %s in zipfile\n",filenameinzip); 336 printf("error in opening %s in zipfile\n",filenameinzip);
@@ -259,7 +348,7 @@ int main(argc,argv)
259 do 348 do
260 { 349 {
261 err = ZIP_OK; 350 err = ZIP_OK;
262 size_read = fread(buf,1,size_buf,fin); 351 size_read = (int)fread(buf,1,size_buf,fin);
263 if (size_read < size_buf) 352 if (size_read < size_buf)
264 if (feof(fin)==0) 353 if (feof(fin)==0)
265 { 354 {
@@ -275,15 +364,17 @@ int main(argc,argv)
275 printf("error in writing %s in the zipfile\n", 364 printf("error in writing %s in the zipfile\n",
276 filenameinzip); 365 filenameinzip);
277 } 366 }
278 367
279 } 368 }
280 } while ((err == ZIP_OK) && (size_read>0)); 369 } while ((err == ZIP_OK) && (size_read>0));
281 370
282 fclose(fin); 371 if (fin)
372 fclose(fin);
373
283 if (err<0) 374 if (err<0)
284 err=ZIP_ERRNO; 375 err=ZIP_ERRNO;
285 else 376 else
286 { 377 {
287 err = zipCloseFileInZip(zf); 378 err = zipCloseFileInZip(zf);
288 if (err!=ZIP_OK) 379 if (err!=ZIP_OK)
289 printf("error in closing %s in the zipfile\n", 380 printf("error in closing %s in the zipfile\n",
@@ -297,6 +388,5 @@ int main(argc,argv)
297 } 388 }
298 389
299 free(buf); 390 free(buf);
300 exit(0); 391 return 0;
301 return 0; /* to avoid warning */
302} 392}
diff --git a/contrib/minizip/readme.txt b/contrib/minizip/readme.txt
deleted file mode 100644
index 1fc023c..0000000
--- a/contrib/minizip/readme.txt
+++ /dev/null
@@ -1,37 +0,0 @@
1
2UnZip 0.15 additionnal library
3
4
5 This unzip package allow extract file from .ZIP file, compatible with
6PKZip 2.04g, WinZip, InfoZip tools and compatible.
7
8 Multi volume ZipFile (span) are not supported, and old compression used by old
9PKZip 1.x are not supported.
10
11See probdesc.zip from PKWare for specification of .ZIP format.
12
13What is Unzip
14 The Zlib library support the deflate compression and the creation of gzip (.gz)
15file. Zlib is free and small.
16 The .Zip format, which can contain several compressed files (.gz can containt
17only one file) is a very popular format. This is why I've written a package for reading file compressed in Zipfile.
18
19Using Unzip package
20
21You need source of Zlib (get zlib111.zip and read zlib.h).
22Get unzlb015.zip and read unzip.h (whith documentation of unzip functions)
23
24The Unzip package is only two file : unzip.h and unzip.c. But it use the Zlib
25 files.
26unztst.c is a simple sample program, which list file in a zipfile and display
27 README.TXT or FILE_ID.DIZ (if these files are found).
28miniunz.c is a mini unzip program.
29
30I'm also currenlyt writing a zipping portion (zip.h, zip.c and test with minizip.c)
31
32Please email me for feedback.
33I hope my source is compatible with Unix system, but I need your help for be sure
34
35Latest revision : Mar 04th, 1998
36
37Check http://www.winimage.com/zLibDll/unzip.html for up to date info.
diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c
index ff71a47..7244523 100644
--- a/contrib/minizip/unzip.c
+++ b/contrib/minizip/unzip.c
@@ -1,9 +1,39 @@
1/* unzip.c -- IO on .zip files using zlib 1/* unzip.c -- IO for uncompress .zip files using zlib
2 Version 0.15 beta, Mar 19th, 1998, 2 Version 0.21 with encryption, March 10th, 2003
3
4 Copyright (C) 1998-2003 Gilles Vollant
3 5
4 Read unzip.h for more info 6 Read unzip.h for more info
5*/ 7*/
6 8
9/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
10compatibility with older software. The following is from the original crypt.c. Code
11woven in by Terry Thorsen 1/2003.
12*/
13/*
14 Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
15
16 See the accompanying file LICENSE, version 2000-Apr-09 or later
17 (the contents of which are also included in zip.h) for terms of use.
18 If, for some reason, all these files are missing, the Info-ZIP license
19 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
20*/
21/*
22 crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
23
24 The encryption/decryption parts of this source code (as opposed to the
25 non-echoing password parts) were originally written in Europe. The
26 whole source package can be freely distributed, including from the USA.
27 (Prior to January 2000, re-export from the US was a violation of US law.)
28 */
29
30/*
31 This encryption code is a direct transcription of the algorithm from
32 Roger Schlafly, described by Phil Katz in the file appnote.txt. This
33 file (appnote.txt) is distributed with the PKZIP program (even in the
34 version without encryption capabilities).
35 */
36
7 37
8#include <stdio.h> 38#include <stdio.h>
9#include <stdlib.h> 39#include <stdlib.h>
@@ -55,22 +85,10 @@
55#define SIZEZIPLOCALHEADER (0x1e) 85#define SIZEZIPLOCALHEADER (0x1e)
56 86
57 87
58/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
59
60#ifndef SEEK_CUR
61#define SEEK_CUR 1
62#endif
63
64#ifndef SEEK_END
65#define SEEK_END 2
66#endif
67 88
68#ifndef SEEK_SET
69#define SEEK_SET 0
70#endif
71 89
72const char unz_copyright[] = 90const char unz_copyright[] =
73 " unzip 0.15 Copyright 1998 Gilles Vollant "; 91 " unzip 0.21 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll";
74 92
75/* unz_file_info_interntal contain internal info about a file in zipfile*/ 93/* unz_file_info_interntal contain internal info about a file in zipfile*/
76typedef struct unz_file_info_internal_s 94typedef struct unz_file_info_internal_s
@@ -83,23 +101,25 @@ typedef struct unz_file_info_internal_s
83 when reading and decompress it */ 101 when reading and decompress it */
84typedef struct 102typedef struct
85{ 103{
86 char *read_buffer; /* internal buffer for compressed data */ 104 char *read_buffer; /* internal buffer for compressed data */
87 z_stream stream; /* zLib stream structure for inflate */ 105 z_stream stream; /* zLib stream structure for inflate */
88 106
89 uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ 107 uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
90 uLong stream_initialised; /* flag set if stream structure is initialised*/ 108 uLong stream_initialised; /* flag set if stream structure is initialised*/
91 109
92 uLong offset_local_extrafield;/* offset of the local extra field */ 110 uLong offset_local_extrafield;/* offset of the local extra field */
93 uInt size_local_extrafield;/* size of the local extra field */ 111 uInt size_local_extrafield;/* size of the local extra field */
94 uLong pos_local_extrafield; /* position in the local extra field in read*/ 112 uLong pos_local_extrafield; /* position in the local extra field in read*/
95 113
96 uLong crc32; /* crc32 of all data uncompressed */ 114 uLong crc32; /* crc32 of all data uncompressed */
97 uLong crc32_wait; /* crc32 we must obtain after decompress all */ 115 uLong crc32_wait; /* crc32 we must obtain after decompress all */
98 uLong rest_read_compressed; /* number of byte to be decompressed */ 116 uLong rest_read_compressed; /* number of byte to be decompressed */
99 uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ 117 uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
100 FILE* file; /* io structore of the zipfile */ 118 zlib_filefunc_def z_filefunc;
101 uLong compression_method; /* compression method (0==store) */ 119 voidpf filestream; /* io structore of the zipfile */
102 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 120 uLong compression_method; /* compression method (0==store) */
121 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
122 int raw;
103} file_in_zip_read_info_s; 123} file_in_zip_read_info_s;
104 124
105 125
@@ -107,25 +127,35 @@ typedef struct
107*/ 127*/
108typedef struct 128typedef struct
109{ 129{
110 FILE* file; /* io structore of the zipfile */ 130 zlib_filefunc_def z_filefunc;
111 unz_global_info gi; /* public global information */ 131 voidpf filestream; /* io structore of the zipfile */
112 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 132 unz_global_info gi; /* public global information */
113 uLong num_file; /* number of the current file in the zipfile*/ 133 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
114 uLong pos_in_central_dir; /* pos of the current file in the central dir*/ 134 uLong num_file; /* number of the current file in the zipfile*/
115 uLong current_file_ok; /* flag about the usability of the current file*/ 135 uLong pos_in_central_dir; /* pos of the current file in the central dir*/
116 uLong central_pos; /* position of the beginning of the central dir*/ 136 uLong current_file_ok; /* flag about the usability of the current file*/
117 137 uLong central_pos; /* position of the beginning of the central dir*/
118 uLong size_central_dir; /* size of the central directory */ 138
119 uLong offset_central_dir; /* offset of start of central directory with 139 uLong size_central_dir; /* size of the central directory */
120 respect to the starting disk number */ 140 uLong offset_central_dir; /* offset of start of central directory with
121 141 respect to the starting disk number */
122 unz_file_info cur_file_info; /* public info about the current file in zip*/ 142
123 unz_file_info_internal cur_file_info_internal; /* private info about it*/ 143 unz_file_info cur_file_info; /* public info about the current file in zip*/
144 unz_file_info_internal cur_file_info_internal; /* private info about it*/
124 file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current 145 file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
125 file if we are decompressing it */ 146 file if we are decompressing it */
147 int encrypted;
148 #ifndef NOUNCRPYT
149 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
150 const unsigned long* pcrc_32_tab;
151 #endif
126} unz_s; 152} unz_s;
127 153
128 154
155#ifndef NOUNCRPYT
156#include "crypt.h"
157#endif
158
129/* =========================================================================== 159/* ===========================================================================
130 Read a byte from a gz_stream; update next_in and avail_in. Return EOF 160 Read a byte from a gz_stream; update next_in and avail_in. Return EOF
131 for end of file. 161 for end of file.
@@ -133,12 +163,18 @@ typedef struct
133*/ 163*/
134 164
135 165
136local int unzlocal_getByte(fin,pi) 166local int unzlocal_getByte OF((
137 FILE *fin; 167 const zlib_filefunc_def* pzlib_filefunc_def,
138 int *pi; 168 voidpf filestream,
169 int *pi));
170
171local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
172 const zlib_filefunc_def* pzlib_filefunc_def;
173 voidpf filestream;
174 int *pi;
139{ 175{
140 unsigned char c; 176 unsigned char c;
141 int err = fread(&c, 1, 1, fin); 177 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
142 if (err==1) 178 if (err==1)
143 { 179 {
144 *pi = (int)c; 180 *pi = (int)c;
@@ -146,7 +182,7 @@ local int unzlocal_getByte(fin,pi)
146 } 182 }
147 else 183 else
148 { 184 {
149 if (ferror(fin)) 185 if (ZERROR(*pzlib_filefunc_def,filestream))
150 return UNZ_ERRNO; 186 return UNZ_ERRNO;
151 else 187 else
152 return UNZ_EOF; 188 return UNZ_EOF;
@@ -155,23 +191,29 @@ local int unzlocal_getByte(fin,pi)
155 191
156 192
157/* =========================================================================== 193/* ===========================================================================
158 Reads a long in LSB order from the given gz_stream. Sets 194 Reads a long in LSB order from the given gz_stream. Sets
159*/ 195*/
160local int unzlocal_getShort (fin,pX) 196local int unzlocal_getShort OF((
161 FILE* fin; 197 const zlib_filefunc_def* pzlib_filefunc_def,
198 voidpf filestream,
199 uLong *pX));
200
201local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
202 const zlib_filefunc_def* pzlib_filefunc_def;
203 voidpf filestream;
162 uLong *pX; 204 uLong *pX;
163{ 205{
164 uLong x ; 206 uLong x ;
165 int i; 207 int i;
166 int err; 208 int err;
167 209
168 err = unzlocal_getByte(fin,&i); 210 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
169 x = (uLong)i; 211 x = (uLong)i;
170 212
171 if (err==UNZ_OK) 213 if (err==UNZ_OK)
172 err = unzlocal_getByte(fin,&i); 214 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
173 x += ((uLong)i)<<8; 215 x += ((uLong)i)<<8;
174 216
175 if (err==UNZ_OK) 217 if (err==UNZ_OK)
176 *pX = x; 218 *pX = x;
177 else 219 else
@@ -179,29 +221,35 @@ local int unzlocal_getShort (fin,pX)
179 return err; 221 return err;
180} 222}
181 223
182local int unzlocal_getLong (fin,pX) 224local int unzlocal_getLong OF((
183 FILE* fin; 225 const zlib_filefunc_def* pzlib_filefunc_def,
226 voidpf filestream,
227 uLong *pX));
228
229local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
230 const zlib_filefunc_def* pzlib_filefunc_def;
231 voidpf filestream;
184 uLong *pX; 232 uLong *pX;
185{ 233{
186 uLong x ; 234 uLong x ;
187 int i; 235 int i;
188 int err; 236 int err;
189 237
190 err = unzlocal_getByte(fin,&i); 238 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
191 x = (uLong)i; 239 x = (uLong)i;
192 240
193 if (err==UNZ_OK) 241 if (err==UNZ_OK)
194 err = unzlocal_getByte(fin,&i); 242 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
195 x += ((uLong)i)<<8; 243 x += ((uLong)i)<<8;
196 244
197 if (err==UNZ_OK) 245 if (err==UNZ_OK)
198 err = unzlocal_getByte(fin,&i); 246 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
199 x += ((uLong)i)<<16; 247 x += ((uLong)i)<<16;
200 248
201 if (err==UNZ_OK) 249 if (err==UNZ_OK)
202 err = unzlocal_getByte(fin,&i); 250 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
203 x += ((uLong)i)<<24; 251 x += ((uLong)i)<<24;
204 252
205 if (err==UNZ_OK) 253 if (err==UNZ_OK)
206 *pX = x; 254 *pX = x;
207 else 255 else
@@ -212,26 +260,26 @@ local int unzlocal_getLong (fin,pX)
212 260
213/* My own strcmpi / strcasecmp */ 261/* My own strcmpi / strcasecmp */
214local int strcmpcasenosensitive_internal (fileName1,fileName2) 262local int strcmpcasenosensitive_internal (fileName1,fileName2)
215 const char* fileName1; 263 const char* fileName1;
216 const char* fileName2; 264 const char* fileName2;
217{ 265{
218 for (;;) 266 for (;;)
219 { 267 {
220 char c1=*(fileName1++); 268 char c1=*(fileName1++);
221 char c2=*(fileName2++); 269 char c2=*(fileName2++);
222 if ((c1>='a') && (c1<='z')) 270 if ((c1>='a') && (c1<='z'))
223 c1 -= 0x20; 271 c1 -= 0x20;
224 if ((c2>='a') && (c2<='z')) 272 if ((c2>='a') && (c2<='z'))
225 c2 -= 0x20; 273 c2 -= 0x20;
226 if (c1=='\0') 274 if (c1=='\0')
227 return ((c2=='\0') ? 0 : -1); 275 return ((c2=='\0') ? 0 : -1);
228 if (c2=='\0') 276 if (c2=='\0')
229 return 1; 277 return 1;
230 if (c1<c2) 278 if (c1<c2)
231 return -1; 279 return -1;
232 if (c1>c2) 280 if (c1>c2)
233 return 1; 281 return 1;
234 } 282 }
235} 283}
236 284
237 285
@@ -245,7 +293,7 @@ local int strcmpcasenosensitive_internal (fileName1,fileName2)
245#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal 293#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
246#endif 294#endif
247 295
248/* 296/*
249 Compare two filename (fileName1,fileName2). 297 Compare two filename (fileName1,fileName2).
250 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) 298 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
251 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi 299 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
@@ -255,203 +303,225 @@ local int strcmpcasenosensitive_internal (fileName1,fileName2)
255 303
256*/ 304*/
257extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) 305extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
258 const char* fileName1; 306 const char* fileName1;
259 const char* fileName2; 307 const char* fileName2;
260 int iCaseSensitivity; 308 int iCaseSensitivity;
261{ 309{
262 if (iCaseSensitivity==0) 310 if (iCaseSensitivity==0)
263 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; 311 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
264 312
265 if (iCaseSensitivity==1) 313 if (iCaseSensitivity==1)
266 return strcmp(fileName1,fileName2); 314 return strcmp(fileName1,fileName2);
267 315
268 return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); 316 return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
269} 317}
270 318
319#ifndef BUFREADCOMMENT
271#define BUFREADCOMMENT (0x400) 320#define BUFREADCOMMENT (0x400)
321#endif
272 322
273/* 323/*
274 Locate the Central directory of a zipfile (at the end, just before 324 Locate the Central directory of a zipfile (at the end, just before
275 the global comment) 325 the global comment)
276*/ 326*/
277local uLong unzlocal_SearchCentralDir(fin) 327local uLong unzlocal_SearchCentralDir OF((
278 FILE *fin; 328 const zlib_filefunc_def* pzlib_filefunc_def,
329 voidpf filestream));
330
331local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
332 const zlib_filefunc_def* pzlib_filefunc_def;
333 voidpf filestream;
279{ 334{
280 unsigned char* buf; 335 unsigned char* buf;
281 uLong uSizeFile; 336 uLong uSizeFile;
282 uLong uBackRead; 337 uLong uBackRead;
283 uLong uMaxBack=0xffff; /* maximum size of global comment */ 338 uLong uMaxBack=0xffff; /* maximum size of global comment */
284 uLong uPosFound=0; 339 uLong uPosFound=0;
285 340
286 if (fseek(fin,0,SEEK_END) != 0) 341 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
287 return 0; 342 return 0;
288 343
289 344
290 uSizeFile = ftell( fin ); 345 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
291 346
292 if (uMaxBack>uSizeFile) 347 if (uMaxBack>uSizeFile)
293 uMaxBack = uSizeFile; 348 uMaxBack = uSizeFile;
294 349
295 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); 350 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
296 if (buf==NULL) 351 if (buf==NULL)
297 return 0; 352 return 0;
298 353
299 uBackRead = 4; 354 uBackRead = 4;
300 while (uBackRead<uMaxBack) 355 while (uBackRead<uMaxBack)
301 { 356 {
302 uLong uReadSize,uReadPos ; 357 uLong uReadSize,uReadPos ;
303 int i; 358 int i;
304 if (uBackRead+BUFREADCOMMENT>uMaxBack) 359 if (uBackRead+BUFREADCOMMENT>uMaxBack)
305 uBackRead = uMaxBack; 360 uBackRead = uMaxBack;
306 else 361 else
307 uBackRead+=BUFREADCOMMENT; 362 uBackRead+=BUFREADCOMMENT;
308 uReadPos = uSizeFile-uBackRead ; 363 uReadPos = uSizeFile-uBackRead ;
309 364
310 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 365 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
311 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); 366 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
312 if (fseek(fin,uReadPos,SEEK_SET)!=0) 367 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
313 break; 368 break;
314 369
315 if (fread(buf,(uInt)uReadSize,1,fin)!=1) 370 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
316 break; 371 break;
317 372
318 for (i=(int)uReadSize-3; (i--)>0;) 373 for (i=(int)uReadSize-3; (i--)>0;)
319 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 374 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
320 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) 375 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
321 { 376 {
322 uPosFound = uReadPos+i; 377 uPosFound = uReadPos+i;
323 break; 378 break;
324 } 379 }
325 380
326 if (uPosFound!=0) 381 if (uPosFound!=0)
327 break; 382 break;
328 } 383 }
329 TRYFREE(buf); 384 TRYFREE(buf);
330 return uPosFound; 385 return uPosFound;
331} 386}
332 387
333/* 388/*
334 Open a Zip file. path contain the full pathname (by example, 389 Open a Zip file. path contain the full pathname (by example,
335 on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer 390 on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
336 "zlib/zlib109.zip". 391 "zlib/zlib114.zip".
337 If the zipfile cannot be opened (file don't exist or in not valid), the 392 If the zipfile cannot be opened (file doesn't exist or in not valid), the
338 return value is NULL. 393 return value is NULL.
339 Else, the return value is a unzFile Handle, usable with other function 394 Else, the return value is a unzFile Handle, usable with other function
340 of this unzip package. 395 of this unzip package.
341*/ 396*/
342extern unzFile ZEXPORT unzOpen (path) 397extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
343 const char *path; 398 const char *path;
399 zlib_filefunc_def* pzlib_filefunc_def;
344{ 400{
345 unz_s us; 401 unz_s us;
346 unz_s *s; 402 unz_s *s;
347 uLong central_pos,uL; 403 uLong central_pos,uL;
348 FILE * fin ;
349 404
350 uLong number_disk; /* number of the current dist, used for 405 uLong number_disk; /* number of the current dist, used for
351 spaning ZIP, unsupported, always 0*/ 406 spaning ZIP, unsupported, always 0*/
352 uLong number_disk_with_CD; /* number the the disk with central dir, used 407 uLong number_disk_with_CD; /* number the the disk with central dir, used
353 for spaning ZIP, unsupported, always 0*/ 408 for spaning ZIP, unsupported, always 0*/
354 uLong number_entry_CD; /* total number of entries in 409 uLong number_entry_CD; /* total number of entries in
355 the central dir 410 the central dir
356 (same than number_entry on nospan) */ 411 (same than number_entry on nospan) */
357 412
358 int err=UNZ_OK; 413 int err=UNZ_OK;
359 414
360 if (unz_copyright[0]!=' ') 415 if (unz_copyright[0]!=' ')
361 return NULL; 416 return NULL;
362 417
363 fin=fopen(path,"rb"); 418 if (pzlib_filefunc_def==NULL)
364 if (fin==NULL) 419 fill_fopen_filefunc(&us.z_filefunc);
365 return NULL; 420 else
366 421 us.z_filefunc = *pzlib_filefunc_def;
367 central_pos = unzlocal_SearchCentralDir(fin); 422
368 if (central_pos==0) 423 us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
369 err=UNZ_ERRNO; 424 path,
370 425 ZLIB_FILEFUNC_MODE_READ |
371 if (fseek(fin,central_pos,SEEK_SET)!=0) 426 ZLIB_FILEFUNC_MODE_EXISTING);
372 err=UNZ_ERRNO; 427 if (us.filestream==NULL)
373 428 return NULL;
374 /* the signature, already checked */ 429
375 if (unzlocal_getLong(fin,&uL)!=UNZ_OK) 430 central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);
376 err=UNZ_ERRNO; 431 if (central_pos==0)
377 432 err=UNZ_ERRNO;
378 /* number of this disk */ 433
379 if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK) 434 if (ZSEEK(us.z_filefunc, us.filestream,
380 err=UNZ_ERRNO; 435 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
381 436 err=UNZ_ERRNO;
382 /* number of the disk with the start of the central directory */ 437
383 if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK) 438 /* the signature, already checked */
384 err=UNZ_ERRNO; 439 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
385 440 err=UNZ_ERRNO;
386 /* total number of entries in the central dir on this disk */ 441
387 if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK) 442 /* number of this disk */
388 err=UNZ_ERRNO; 443 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
389 444 err=UNZ_ERRNO;
390 /* total number of entries in the central dir */ 445
391 if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK) 446 /* number of the disk with the start of the central directory */
392 err=UNZ_ERRNO; 447 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
393 448 err=UNZ_ERRNO;
394 if ((number_entry_CD!=us.gi.number_entry) || 449
395 (number_disk_with_CD!=0) || 450 /* total number of entries in the central dir on this disk */
396 (number_disk!=0)) 451 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
397 err=UNZ_BADZIPFILE; 452 err=UNZ_ERRNO;
398 453
399 /* size of the central directory */ 454 /* total number of entries in the central dir */
400 if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK) 455 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
401 err=UNZ_ERRNO; 456 err=UNZ_ERRNO;
402 457
403 /* offset of start of central directory with respect to the 458 if ((number_entry_CD!=us.gi.number_entry) ||
404 starting disk number */ 459 (number_disk_with_CD!=0) ||
405 if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK) 460 (number_disk!=0))
406 err=UNZ_ERRNO; 461 err=UNZ_BADZIPFILE;
407 462
408 /* zipfile comment length */ 463 /* size of the central directory */
409 if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK) 464 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
410 err=UNZ_ERRNO; 465 err=UNZ_ERRNO;
411 466
412 if ((central_pos<us.offset_central_dir+us.size_central_dir) && 467 /* offset of start of central directory with respect to the
413 (err==UNZ_OK)) 468 starting disk number */
414 err=UNZ_BADZIPFILE; 469 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
415 470 err=UNZ_ERRNO;
416 if (err!=UNZ_OK) 471
417 { 472 /* zipfile comment length */
418 fclose(fin); 473 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
419 return NULL; 474 err=UNZ_ERRNO;
420 } 475
421 476 if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
422 us.file=fin; 477 (err==UNZ_OK))
423 us.byte_before_the_zipfile = central_pos - 478 err=UNZ_BADZIPFILE;
424 (us.offset_central_dir+us.size_central_dir); 479
425 us.central_pos = central_pos; 480 if (err!=UNZ_OK)
481 {
482 ZCLOSE(us.z_filefunc, us.filestream);
483 return NULL;
484 }
485
486 us.byte_before_the_zipfile = central_pos -
487 (us.offset_central_dir+us.size_central_dir);
488 us.central_pos = central_pos;
426 us.pfile_in_zip_read = NULL; 489 us.pfile_in_zip_read = NULL;
427 490 us.encrypted = 0;
428 491
429 s=(unz_s*)ALLOC(sizeof(unz_s)); 492
430 *s=us; 493 s=(unz_s*)ALLOC(sizeof(unz_s));
431 unzGoToFirstFile((unzFile)s); 494 *s=us;
432 return (unzFile)s; 495 unzGoToFirstFile((unzFile)s);
496 return (unzFile)s;
433} 497}
434 498
435 499
500extern unzFile ZEXPORT unzOpen (path)
501 const char *path;
502{
503 return unzOpen2(path, NULL);
504}
505
436/* 506/*
437 Close a ZipFile opened with unzipOpen. 507 Close a ZipFile opened with unzipOpen.
438 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), 508 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
439 these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 509 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
440 return UNZ_OK if there is no problem. */ 510 return UNZ_OK if there is no problem. */
441extern int ZEXPORT unzClose (file) 511extern int ZEXPORT unzClose (file)
442 unzFile file; 512 unzFile file;
443{ 513{
444 unz_s* s; 514 unz_s* s;
445 if (file==NULL) 515 if (file==NULL)
446 return UNZ_PARAMERROR; 516 return UNZ_PARAMERROR;
447 s=(unz_s*)file; 517 s=(unz_s*)file;
448 518
449 if (s->pfile_in_zip_read!=NULL) 519 if (s->pfile_in_zip_read!=NULL)
450 unzCloseCurrentFile(file); 520 unzCloseCurrentFile(file);
451 521
452 fclose(s->file); 522 ZCLOSE(s->z_filefunc, s->filestream);
453 TRYFREE(s); 523 TRYFREE(s);
454 return UNZ_OK; 524 return UNZ_OK;
455} 525}
456 526
457 527
@@ -460,15 +530,15 @@ extern int ZEXPORT unzClose (file)
460 No preparation of the structure is needed 530 No preparation of the structure is needed
461 return UNZ_OK if there is no problem. */ 531 return UNZ_OK if there is no problem. */
462extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) 532extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)
463 unzFile file; 533 unzFile file;
464 unz_global_info *pglobal_info; 534 unz_global_info *pglobal_info;
465{ 535{
466 unz_s* s; 536 unz_s* s;
467 if (file==NULL) 537 if (file==NULL)
468 return UNZ_PARAMERROR; 538 return UNZ_PARAMERROR;
469 s=(unz_s*)file; 539 s=(unz_s*)file;
470 *pglobal_info=s->gi; 540 *pglobal_info=s->gi;
471 return UNZ_OK; 541 return UNZ_OK;
472} 542}
473 543
474 544
@@ -495,14 +565,14 @@ local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
495*/ 565*/
496local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, 566local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
497 unz_file_info *pfile_info, 567 unz_file_info *pfile_info,
498 unz_file_info_internal 568 unz_file_info_internal
499 *pfile_info_internal, 569 *pfile_info_internal,
500 char *szFileName, 570 char *szFileName,
501 uLong fileNameBufferSize, 571 uLong fileNameBufferSize,
502 void *extraField, 572 void *extraField,
503 uLong extraFieldBufferSize, 573 uLong extraFieldBufferSize,
504 char *szComment, 574 char *szComment,
505 uLong commentBufferSize)); 575 uLong commentBufferSize));
506 576
507local int unzlocal_GetCurrentFileInfoInternal (file, 577local int unzlocal_GetCurrentFileInfoInternal (file,
508 pfile_info, 578 pfile_info,
@@ -510,156 +580,158 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
510 szFileName, fileNameBufferSize, 580 szFileName, fileNameBufferSize,
511 extraField, extraFieldBufferSize, 581 extraField, extraFieldBufferSize,
512 szComment, commentBufferSize) 582 szComment, commentBufferSize)
513 unzFile file; 583 unzFile file;
514 unz_file_info *pfile_info; 584 unz_file_info *pfile_info;
515 unz_file_info_internal *pfile_info_internal; 585 unz_file_info_internal *pfile_info_internal;
516 char *szFileName; 586 char *szFileName;
517 uLong fileNameBufferSize; 587 uLong fileNameBufferSize;
518 void *extraField; 588 void *extraField;
519 uLong extraFieldBufferSize; 589 uLong extraFieldBufferSize;
520 char *szComment; 590 char *szComment;
521 uLong commentBufferSize; 591 uLong commentBufferSize;
522{ 592{
523 unz_s* s; 593 unz_s* s;
524 unz_file_info file_info; 594 unz_file_info file_info;
525 unz_file_info_internal file_info_internal; 595 unz_file_info_internal file_info_internal;
526 int err=UNZ_OK; 596 int err=UNZ_OK;
527 uLong uMagic; 597 uLong uMagic;
528 long lSeek=0; 598 long lSeek=0;
529 599
530 if (file==NULL) 600 if (file==NULL)
531 return UNZ_PARAMERROR; 601 return UNZ_PARAMERROR;
532 s=(unz_s*)file; 602 s=(unz_s*)file;
533 if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0) 603 if (ZSEEK(s->z_filefunc, s->filestream,
534 err=UNZ_ERRNO; 604 s->pos_in_central_dir+s->byte_before_the_zipfile,
605 ZLIB_FILEFUNC_SEEK_SET)!=0)
606 err=UNZ_ERRNO;
535 607
536 608
537 /* we check the magic */ 609 /* we check the magic */
538 if (err==UNZ_OK) 610 if (err==UNZ_OK)
539 if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) 611 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
540 err=UNZ_ERRNO; 612 err=UNZ_ERRNO;
541 else if (uMagic!=0x02014b50) 613 else if (uMagic!=0x02014b50)
542 err=UNZ_BADZIPFILE; 614 err=UNZ_BADZIPFILE;
543 615
544 if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK) 616 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
545 err=UNZ_ERRNO; 617 err=UNZ_ERRNO;
546 618
547 if (unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK) 619 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
548 err=UNZ_ERRNO; 620 err=UNZ_ERRNO;
549 621
550 if (unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK) 622 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
551 err=UNZ_ERRNO; 623 err=UNZ_ERRNO;
552 624
553 if (unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK) 625 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
554 err=UNZ_ERRNO; 626 err=UNZ_ERRNO;
555 627
556 if (unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK) 628 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
557 err=UNZ_ERRNO; 629 err=UNZ_ERRNO;
558 630
559 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); 631 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
560 632
561 if (unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK) 633 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
562 err=UNZ_ERRNO; 634 err=UNZ_ERRNO;
563 635
564 if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK) 636 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
565 err=UNZ_ERRNO; 637 err=UNZ_ERRNO;
566 638
567 if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK) 639 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
568 err=UNZ_ERRNO; 640 err=UNZ_ERRNO;
569 641
570 if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK) 642 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
571 err=UNZ_ERRNO; 643 err=UNZ_ERRNO;
572 644
573 if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK) 645 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
574 err=UNZ_ERRNO; 646 err=UNZ_ERRNO;
575 647
576 if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK) 648 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
577 err=UNZ_ERRNO; 649 err=UNZ_ERRNO;
578 650
579 if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK) 651 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
580 err=UNZ_ERRNO; 652 err=UNZ_ERRNO;
581 653
582 if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK) 654 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
583 err=UNZ_ERRNO; 655 err=UNZ_ERRNO;
584 656
585 if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK) 657 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
586 err=UNZ_ERRNO; 658 err=UNZ_ERRNO;
587 659
588 if (unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK) 660 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
589 err=UNZ_ERRNO; 661 err=UNZ_ERRNO;
590 662
591 lSeek+=file_info.size_filename; 663 lSeek+=file_info.size_filename;
592 if ((err==UNZ_OK) && (szFileName!=NULL)) 664 if ((err==UNZ_OK) && (szFileName!=NULL))
593 { 665 {
594 uLong uSizeRead ; 666 uLong uSizeRead ;
595 if (file_info.size_filename<fileNameBufferSize) 667 if (file_info.size_filename<fileNameBufferSize)
596 { 668 {
597 *(szFileName+file_info.size_filename)='\0'; 669 *(szFileName+file_info.size_filename)='\0';
598 uSizeRead = file_info.size_filename; 670 uSizeRead = file_info.size_filename;
599 } 671 }
600 else 672 else
601 uSizeRead = fileNameBufferSize; 673 uSizeRead = fileNameBufferSize;
602 674
603 if ((file_info.size_filename>0) && (fileNameBufferSize>0)) 675 if ((file_info.size_filename>0) && (fileNameBufferSize>0))
604 if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1) 676 if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
605 err=UNZ_ERRNO; 677 err=UNZ_ERRNO;
606 lSeek -= uSizeRead; 678 lSeek -= uSizeRead;
607 } 679 }
608 680
609 681
610 if ((err==UNZ_OK) && (extraField!=NULL)) 682 if ((err==UNZ_OK) && (extraField!=NULL))
611 { 683 {
612 uLong uSizeRead ; 684 uLong uSizeRead ;
613 if (file_info.size_file_extra<extraFieldBufferSize) 685 if (file_info.size_file_extra<extraFieldBufferSize)
614 uSizeRead = file_info.size_file_extra; 686 uSizeRead = file_info.size_file_extra;
615 else 687 else
616 uSizeRead = extraFieldBufferSize; 688 uSizeRead = extraFieldBufferSize;
617 689
618 if (lSeek!=0) 690 if (lSeek!=0)
619 if (fseek(s->file,lSeek,SEEK_CUR)==0) 691 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
620 lSeek=0; 692 lSeek=0;
621 else 693 else
622 err=UNZ_ERRNO; 694 err=UNZ_ERRNO;
623 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) 695 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
624 if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1) 696 if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
625 err=UNZ_ERRNO; 697 err=UNZ_ERRNO;
626 lSeek += file_info.size_file_extra - uSizeRead; 698 lSeek += file_info.size_file_extra - uSizeRead;
627 } 699 }
628 else 700 else
629 lSeek+=file_info.size_file_extra; 701 lSeek+=file_info.size_file_extra;
630 702
631 703
632 if ((err==UNZ_OK) && (szComment!=NULL)) 704 if ((err==UNZ_OK) && (szComment!=NULL))
633 { 705 {
634 uLong uSizeRead ; 706 uLong uSizeRead ;
635 if (file_info.size_file_comment<commentBufferSize) 707 if (file_info.size_file_comment<commentBufferSize)
636 { 708 {
637 *(szComment+file_info.size_file_comment)='\0'; 709 *(szComment+file_info.size_file_comment)='\0';
638 uSizeRead = file_info.size_file_comment; 710 uSizeRead = file_info.size_file_comment;
639 } 711 }
640 else 712 else
641 uSizeRead = commentBufferSize; 713 uSizeRead = commentBufferSize;
642 714
643 if (lSeek!=0) 715 if (lSeek!=0)
644 if (fseek(s->file,lSeek,SEEK_CUR)==0) 716 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
645 lSeek=0; 717 lSeek=0;
646 else 718 else
647 err=UNZ_ERRNO; 719 err=UNZ_ERRNO;
648 if ((file_info.size_file_comment>0) && (commentBufferSize>0)) 720 if ((file_info.size_file_comment>0) && (commentBufferSize>0))
649 if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1) 721 if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
650 err=UNZ_ERRNO; 722 err=UNZ_ERRNO;
651 lSeek+=file_info.size_file_comment - uSizeRead; 723 lSeek+=file_info.size_file_comment - uSizeRead;
652 } 724 }
653 else 725 else
654 lSeek+=file_info.size_file_comment; 726 lSeek+=file_info.size_file_comment;
655 727
656 if ((err==UNZ_OK) && (pfile_info!=NULL)) 728 if ((err==UNZ_OK) && (pfile_info!=NULL))
657 *pfile_info=file_info; 729 *pfile_info=file_info;
658 730
659 if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) 731 if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
660 *pfile_info_internal=file_info_internal; 732 *pfile_info_internal=file_info_internal;
661 733
662 return err; 734 return err;
663} 735}
664 736
665 737
@@ -670,23 +742,23 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
670 return UNZ_OK if there is no problem. 742 return UNZ_OK if there is no problem.
671*/ 743*/
672extern int ZEXPORT unzGetCurrentFileInfo (file, 744extern int ZEXPORT unzGetCurrentFileInfo (file,
673 pfile_info, 745 pfile_info,
674 szFileName, fileNameBufferSize, 746 szFileName, fileNameBufferSize,
675 extraField, extraFieldBufferSize, 747 extraField, extraFieldBufferSize,
676 szComment, commentBufferSize) 748 szComment, commentBufferSize)
677 unzFile file; 749 unzFile file;
678 unz_file_info *pfile_info; 750 unz_file_info *pfile_info;
679 char *szFileName; 751 char *szFileName;
680 uLong fileNameBufferSize; 752 uLong fileNameBufferSize;
681 void *extraField; 753 void *extraField;
682 uLong extraFieldBufferSize; 754 uLong extraFieldBufferSize;
683 char *szComment; 755 char *szComment;
684 uLong commentBufferSize; 756 uLong commentBufferSize;
685{ 757{
686 return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, 758 return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
687 szFileName,fileNameBufferSize, 759 szFileName,fileNameBufferSize,
688 extraField,extraFieldBufferSize, 760 extraField,extraFieldBufferSize,
689 szComment,commentBufferSize); 761 szComment,commentBufferSize);
690} 762}
691 763
692/* 764/*
@@ -694,50 +766,49 @@ extern int ZEXPORT unzGetCurrentFileInfo (file,
694 return UNZ_OK if there is no problem 766 return UNZ_OK if there is no problem
695*/ 767*/
696extern int ZEXPORT unzGoToFirstFile (file) 768extern int ZEXPORT unzGoToFirstFile (file)
697 unzFile file; 769 unzFile file;
698{ 770{
699 int err=UNZ_OK; 771 int err=UNZ_OK;
700 unz_s* s; 772 unz_s* s;
701 if (file==NULL) 773 if (file==NULL)
702 return UNZ_PARAMERROR; 774 return UNZ_PARAMERROR;
703 s=(unz_s*)file; 775 s=(unz_s*)file;
704 s->pos_in_central_dir=s->offset_central_dir; 776 s->pos_in_central_dir=s->offset_central_dir;
705 s->num_file=0; 777 s->num_file=0;
706 err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 778 err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
707 &s->cur_file_info_internal, 779 &s->cur_file_info_internal,
708 NULL,0,NULL,0,NULL,0); 780 NULL,0,NULL,0,NULL,0);
709 s->current_file_ok = (err == UNZ_OK); 781 s->current_file_ok = (err == UNZ_OK);
710 return err; 782 return err;
711} 783}
712 784
713
714/* 785/*
715 Set the current file of the zipfile to the next file. 786 Set the current file of the zipfile to the next file.
716 return UNZ_OK if there is no problem 787 return UNZ_OK if there is no problem
717 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 788 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
718*/ 789*/
719extern int ZEXPORT unzGoToNextFile (file) 790extern int ZEXPORT unzGoToNextFile (file)
720 unzFile file; 791 unzFile file;
721{ 792{
722 unz_s* s; 793 unz_s* s;
723 int err; 794 int err;
724 795
725 if (file==NULL) 796 if (file==NULL)
726 return UNZ_PARAMERROR; 797 return UNZ_PARAMERROR;
727 s=(unz_s*)file; 798 s=(unz_s*)file;
728 if (!s->current_file_ok) 799 if (!s->current_file_ok)
729 return UNZ_END_OF_LIST_OF_FILE; 800 return UNZ_END_OF_LIST_OF_FILE;
730 if (s->num_file+1==s->gi.number_entry) 801 if (s->num_file+1==s->gi.number_entry)
731 return UNZ_END_OF_LIST_OF_FILE; 802 return UNZ_END_OF_LIST_OF_FILE;
732 803
733 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + 804 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
734 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; 805 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
735 s->num_file++; 806 s->num_file++;
736 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 807 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
737 &s->cur_file_info_internal, 808 &s->cur_file_info_internal,
738 NULL,0,NULL,0,NULL,0); 809 NULL,0,NULL,0,NULL,0);
739 s->current_file_ok = (err == UNZ_OK); 810 s->current_file_ok = (err == UNZ_OK);
740 return err; 811 return err;
741} 812}
742 813
743 814
@@ -750,52 +821,117 @@ extern int ZEXPORT unzGoToNextFile (file)
750 UNZ_END_OF_LIST_OF_FILE if the file is not found 821 UNZ_END_OF_LIST_OF_FILE if the file is not found
751*/ 822*/
752extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) 823extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
753 unzFile file; 824 unzFile file;
754 const char *szFileName; 825 const char *szFileName;
755 int iCaseSensitivity; 826 int iCaseSensitivity;
756{ 827{
757 unz_s* s; 828 unz_s* s;
758 int err; 829 int err;
759 830
760
761 uLong num_fileSaved;
762 uLong pos_in_central_dirSaved;
763 831
832 uLong num_fileSaved;
833 uLong pos_in_central_dirSaved;
764 834
765 if (file==NULL) 835
766 return UNZ_PARAMERROR; 836 if (file==NULL)
837 return UNZ_PARAMERROR;
767 838
768 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) 839 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
769 return UNZ_PARAMERROR; 840 return UNZ_PARAMERROR;
770 841
771 s=(unz_s*)file; 842 s=(unz_s*)file;
772 if (!s->current_file_ok) 843 if (!s->current_file_ok)
773 return UNZ_END_OF_LIST_OF_FILE; 844 return UNZ_END_OF_LIST_OF_FILE;
774 845
775 num_fileSaved = s->num_file; 846 num_fileSaved = s->num_file;
776 pos_in_central_dirSaved = s->pos_in_central_dir; 847 pos_in_central_dirSaved = s->pos_in_central_dir;
777 848
778 err = unzGoToFirstFile(file); 849 err = unzGoToFirstFile(file);
779 850
780 while (err == UNZ_OK) 851 while (err == UNZ_OK)
781 { 852 {
782 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; 853 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
783 unzGetCurrentFileInfo(file,NULL, 854 unzGetCurrentFileInfo(file,NULL,
784 szCurrentFileName,sizeof(szCurrentFileName)-1, 855 szCurrentFileName,sizeof(szCurrentFileName)-1,
785 NULL,0,NULL,0); 856 NULL,0,NULL,0);
786 if (unzStringFileNameCompare(szCurrentFileName, 857 if (unzStringFileNameCompare(szCurrentFileName,
787 szFileName,iCaseSensitivity)==0) 858 szFileName,iCaseSensitivity)==0)
788 return UNZ_OK; 859 return UNZ_OK;
789 err = unzGoToNextFile(file); 860 err = unzGoToNextFile(file);
790 } 861 }
791 862
792 s->num_file = num_fileSaved ; 863 s->num_file = num_fileSaved ;
793 s->pos_in_central_dir = pos_in_central_dirSaved ; 864 s->pos_in_central_dir = pos_in_central_dirSaved ;
794 return err; 865 return err;
795} 866}
796 867
797 868
798/* 869/*
870///////////////////////////////////////////
871// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
872// I need random access
873//
874// Further optimization could be realized by adding an ability
875// to cache the directory in memory. The goal being a single
876// comprehensive file read to put the file I need in a memory.
877*/
878
879/*
880typedef struct unz_file_pos_s
881{
882 uLong pos_in_zip_directory; // offset in file
883 uLong num_of_file; // # of file
884} unz_file_pos;
885*/
886
887extern int ZEXPORT unzGetFilePos(file, file_pos)
888 unzFile file;
889 unz_file_pos* file_pos;
890{
891 unz_s* s;
892
893 if (file==NULL || file_pos==NULL)
894 return UNZ_PARAMERROR;
895 s=(unz_s*)file;
896 if (!s->current_file_ok)
897 return UNZ_END_OF_LIST_OF_FILE;
898
899 file_pos->pos_in_zip_directory = s->pos_in_central_dir;
900 file_pos->num_of_file = s->num_file;
901
902 return UNZ_OK;
903}
904
905extern int ZEXPORT unzGoToFilePos(file, file_pos)
906 unzFile file;
907 unz_file_pos* file_pos;
908{
909 unz_s* s;
910 int err;
911
912 if (file==NULL || file_pos==NULL)
913 return UNZ_PARAMERROR;
914 s=(unz_s*)file;
915
916 /* jump to the right spot */
917 s->pos_in_central_dir = file_pos->pos_in_zip_directory;
918 s->num_file = file_pos->num_of_file;
919
920 /* set the current file */
921 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
922 &s->cur_file_info_internal,
923 NULL,0,NULL,0,NULL,0);
924 /* return results */
925 s->current_file_ok = (err == UNZ_OK);
926 return err;
927}
928
929/*
930// Unzip Helper Functions - should be here?
931///////////////////////////////////////////
932*/
933
934/*
799 Read the local header of the current zipfile 935 Read the local header of the current zipfile
800 Check the coherency of the local header and info in the end of central 936 Check the coherency of the local header and info in the end of central
801 directory about this file 937 directory about this file
@@ -803,185 +939,256 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
803 (filename and size of extra field data) 939 (filename and size of extra field data)
804*/ 940*/
805local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, 941local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
806 poffset_local_extrafield, 942 poffset_local_extrafield,
807 psize_local_extrafield) 943 psize_local_extrafield)
808 unz_s* s; 944 unz_s* s;
809 uInt* piSizeVar; 945 uInt* piSizeVar;
810 uLong *poffset_local_extrafield; 946 uLong *poffset_local_extrafield;
811 uInt *psize_local_extrafield; 947 uInt *psize_local_extrafield;
812{ 948{
813 uLong uMagic,uData,uFlags; 949 uLong uMagic,uData,uFlags;
814 uLong size_filename; 950 uLong size_filename;
815 uLong size_extra_field; 951 uLong size_extra_field;
816 int err=UNZ_OK; 952 int err=UNZ_OK;
817 953
818 *piSizeVar = 0; 954 *piSizeVar = 0;
819 *poffset_local_extrafield = 0; 955 *poffset_local_extrafield = 0;
820 *psize_local_extrafield = 0; 956 *psize_local_extrafield = 0;
821 957
822 if (fseek(s->file,s->cur_file_info_internal.offset_curfile + 958 if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
823 s->byte_before_the_zipfile,SEEK_SET)!=0) 959 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
824 return UNZ_ERRNO; 960 return UNZ_ERRNO;
825 961
826 962
827 if (err==UNZ_OK) 963 if (err==UNZ_OK)
828 if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) 964 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
829 err=UNZ_ERRNO; 965 err=UNZ_ERRNO;
830 else if (uMagic!=0x04034b50) 966 else if (uMagic!=0x04034b50)
831 err=UNZ_BADZIPFILE; 967 err=UNZ_BADZIPFILE;
832 968
833 if (unzlocal_getShort(s->file,&uData) != UNZ_OK) 969 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
834 err=UNZ_ERRNO; 970 err=UNZ_ERRNO;
835/* 971/*
836 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) 972 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
837 err=UNZ_BADZIPFILE; 973 err=UNZ_BADZIPFILE;
838*/ 974*/
839 if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK) 975 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
840 err=UNZ_ERRNO; 976 err=UNZ_ERRNO;
841 977
842 if (unzlocal_getShort(s->file,&uData) != UNZ_OK) 978 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
843 err=UNZ_ERRNO; 979 err=UNZ_ERRNO;
844 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) 980 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
845 err=UNZ_BADZIPFILE; 981 err=UNZ_BADZIPFILE;
846 982
847 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && 983 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
848 (s->cur_file_info.compression_method!=Z_DEFLATED)) 984 (s->cur_file_info.compression_method!=Z_DEFLATED))
849 err=UNZ_BADZIPFILE; 985 err=UNZ_BADZIPFILE;
850 986
851 if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */ 987 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
852 err=UNZ_ERRNO; 988 err=UNZ_ERRNO;
853 989
854 if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */ 990 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
855 err=UNZ_ERRNO; 991 err=UNZ_ERRNO;
856 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && 992 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
857 ((uFlags & 8)==0)) 993 ((uFlags & 8)==0))
858 err=UNZ_BADZIPFILE; 994 err=UNZ_BADZIPFILE;
859 995
860 if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */ 996 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
861 err=UNZ_ERRNO; 997 err=UNZ_ERRNO;
862 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && 998 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
863 ((uFlags & 8)==0)) 999 ((uFlags & 8)==0))
864 err=UNZ_BADZIPFILE; 1000 err=UNZ_BADZIPFILE;
865 1001
866 if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */ 1002 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
867 err=UNZ_ERRNO; 1003 err=UNZ_ERRNO;
868 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && 1004 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
869 ((uFlags & 8)==0)) 1005 ((uFlags & 8)==0))
870 err=UNZ_BADZIPFILE; 1006 err=UNZ_BADZIPFILE;
871 1007
872 1008
873 if (unzlocal_getShort(s->file,&size_filename) != UNZ_OK) 1009 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
874 err=UNZ_ERRNO; 1010 err=UNZ_ERRNO;
875 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) 1011 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
876 err=UNZ_BADZIPFILE; 1012 err=UNZ_BADZIPFILE;
877 1013
878 *piSizeVar += (uInt)size_filename; 1014 *piSizeVar += (uInt)size_filename;
879 1015
880 if (unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK) 1016 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
881 err=UNZ_ERRNO; 1017 err=UNZ_ERRNO;
882 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + 1018 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
883 SIZEZIPLOCALHEADER + size_filename; 1019 SIZEZIPLOCALHEADER + size_filename;
884 *psize_local_extrafield = (uInt)size_extra_field; 1020 *psize_local_extrafield = (uInt)size_extra_field;
885 1021
886 *piSizeVar += (uInt)size_extra_field; 1022 *piSizeVar += (uInt)size_extra_field;
887 1023
888 return err; 1024 return err;
889} 1025}
890 1026
891/* 1027/*
892 Open for reading data the current file in the zipfile. 1028 Open for reading data the current file in the zipfile.
893 If there is no error and the file is opened, the return value is UNZ_OK. 1029 If there is no error and the file is opened, the return value is UNZ_OK.
894*/ 1030*/
895extern int ZEXPORT unzOpenCurrentFile (file) 1031extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
896 unzFile file; 1032 unzFile file;
1033 int* method;
1034 int* level;
1035 int raw;
1036 const char* password;
897{ 1037{
898 int err=UNZ_OK; 1038 int err=UNZ_OK;
899 int Store; 1039 uInt iSizeVar;
900 uInt iSizeVar; 1040 unz_s* s;
901 unz_s* s; 1041 file_in_zip_read_info_s* pfile_in_zip_read_info;
902 file_in_zip_read_info_s* pfile_in_zip_read_info; 1042 uLong offset_local_extrafield; /* offset of the local extra field */
903 uLong offset_local_extrafield; /* offset of the local extra field */ 1043 uInt size_local_extrafield; /* size of the local extra field */
904 uInt size_local_extrafield; /* size of the local extra field */ 1044 #ifndef NOUNCRPYT
905 1045 char source[12];
906 if (file==NULL) 1046 #else
907 return UNZ_PARAMERROR; 1047 if (password != NULL)
908 s=(unz_s*)file; 1048 return UNZ_PARAMERROR;
909 if (!s->current_file_ok) 1049 #endif
910 return UNZ_PARAMERROR; 1050
1051 if (file==NULL)
1052 return UNZ_PARAMERROR;
1053 s=(unz_s*)file;
1054 if (!s->current_file_ok)
1055 return UNZ_PARAMERROR;
911 1056
912 if (s->pfile_in_zip_read != NULL) 1057 if (s->pfile_in_zip_read != NULL)
913 unzCloseCurrentFile(file); 1058 unzCloseCurrentFile(file);
914 1059
915 if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, 1060 if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
916 &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) 1061 &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
917 return UNZ_BADZIPFILE; 1062 return UNZ_BADZIPFILE;
918 1063
919 pfile_in_zip_read_info = (file_in_zip_read_info_s*) 1064 pfile_in_zip_read_info = (file_in_zip_read_info_s*)
920 ALLOC(sizeof(file_in_zip_read_info_s)); 1065 ALLOC(sizeof(file_in_zip_read_info_s));
921 if (pfile_in_zip_read_info==NULL) 1066 if (pfile_in_zip_read_info==NULL)
922 return UNZ_INTERNALERROR; 1067 return UNZ_INTERNALERROR;
923 1068
924 pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); 1069 pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
925 pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; 1070 pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
926 pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; 1071 pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
927 pfile_in_zip_read_info->pos_local_extrafield=0; 1072 pfile_in_zip_read_info->pos_local_extrafield=0;
928 1073 pfile_in_zip_read_info->raw=raw;
929 if (pfile_in_zip_read_info->read_buffer==NULL) 1074
930 { 1075 if (pfile_in_zip_read_info->read_buffer==NULL)
931 TRYFREE(pfile_in_zip_read_info); 1076 {
932 return UNZ_INTERNALERROR; 1077 TRYFREE(pfile_in_zip_read_info);
933 } 1078 return UNZ_INTERNALERROR;
934 1079 }
935 pfile_in_zip_read_info->stream_initialised=0; 1080
936 1081 pfile_in_zip_read_info->stream_initialised=0;
937 if ((s->cur_file_info.compression_method!=0) && 1082
1083 if (method!=NULL)
1084 *method = (int)s->cur_file_info.compression_method;
1085
1086 if (level!=NULL)
1087 {
1088 *level = 6;
1089 switch (s->cur_file_info.flag & 0x06)
1090 {
1091 case 6 : *level = 1; break;
1092 case 4 : *level = 2; break;
1093 case 2 : *level = 9; break;
1094 }
1095 }
1096
1097 if ((s->cur_file_info.compression_method!=0) &&
938 (s->cur_file_info.compression_method!=Z_DEFLATED)) 1098 (s->cur_file_info.compression_method!=Z_DEFLATED))
939 err=UNZ_BADZIPFILE; 1099 err=UNZ_BADZIPFILE;
940 Store = s->cur_file_info.compression_method==0;
941 1100
942 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; 1101 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
943 pfile_in_zip_read_info->crc32=0; 1102 pfile_in_zip_read_info->crc32=0;
944 pfile_in_zip_read_info->compression_method = 1103 pfile_in_zip_read_info->compression_method =
945 s->cur_file_info.compression_method; 1104 s->cur_file_info.compression_method;
946 pfile_in_zip_read_info->file=s->file; 1105 pfile_in_zip_read_info->filestream=s->filestream;
947 pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; 1106 pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
1107 pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
948 1108
949 pfile_in_zip_read_info->stream.total_out = 0; 1109 pfile_in_zip_read_info->stream.total_out = 0;
950 1110
951 if (!Store) 1111 if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
952 { 1112 (!raw))
953 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; 1113 {
954 pfile_in_zip_read_info->stream.zfree = (free_func)0; 1114 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
955 pfile_in_zip_read_info->stream.opaque = (voidpf)0; 1115 pfile_in_zip_read_info->stream.zfree = (free_func)0;
956 1116 pfile_in_zip_read_info->stream.opaque = (voidpf)0;
957 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); 1117
958 if (err == Z_OK) 1118 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
959 pfile_in_zip_read_info->stream_initialised=1; 1119 if (err == Z_OK)
1120 pfile_in_zip_read_info->stream_initialised=1;
1121 else
1122 return err;
960 /* windowBits is passed < 0 to tell that there is no zlib header. 1123 /* windowBits is passed < 0 to tell that there is no zlib header.
961 * Note that in this case inflate *requires* an extra "dummy" byte 1124 * Note that in this case inflate *requires* an extra "dummy" byte
962 * after the compressed stream in order to complete decompression and 1125 * after the compressed stream in order to complete decompression and
963 * return Z_STREAM_END. 1126 * return Z_STREAM_END.
964 * In unzip, i don't wait absolutely Z_STREAM_END because I known the 1127 * In unzip, i don't wait absolutely Z_STREAM_END because I known the
965 * size of both compressed and uncompressed data 1128 * size of both compressed and uncompressed data
966 */ 1129 */
967 } 1130 }
968 pfile_in_zip_read_info->rest_read_compressed = 1131 pfile_in_zip_read_info->rest_read_compressed =
969 s->cur_file_info.compressed_size ; 1132 s->cur_file_info.compressed_size ;
970 pfile_in_zip_read_info->rest_read_uncompressed = 1133 pfile_in_zip_read_info->rest_read_uncompressed =
971 s->cur_file_info.uncompressed_size ; 1134 s->cur_file_info.uncompressed_size ;
972 1135
973 1136
974 pfile_in_zip_read_info->pos_in_zipfile = 1137 pfile_in_zip_read_info->pos_in_zipfile =
975 s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + 1138 s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
976 iSizeVar; 1139 iSizeVar;
977 1140
978 pfile_in_zip_read_info->stream.avail_in = (uInt)0; 1141 pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1142
1143 s->pfile_in_zip_read = pfile_in_zip_read_info;
1144
1145 #ifndef NOUNCRPYT
1146 if (password != NULL)
1147 {
1148 int i;
1149 s->pcrc_32_tab = get_crc_table();
1150 init_keys(password,s->keys,s->pcrc_32_tab);
1151 if (ZSEEK(s->z_filefunc, s->filestream,
1152 s->pfile_in_zip_read->pos_in_zipfile +
1153 s->pfile_in_zip_read->byte_before_the_zipfile,
1154 SEEK_SET)!=0)
1155 return UNZ_INTERNALERROR;
1156 if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)
1157 return UNZ_INTERNALERROR;
1158
1159 for (i = 0; i<12; i++)
1160 zdecode(s->keys,s->pcrc_32_tab,source[i]);
1161
1162 s->pfile_in_zip_read->pos_in_zipfile+=12;
1163 s->encrypted=1;
1164 }
1165 #endif
979 1166
980 1167
981 s->pfile_in_zip_read = pfile_in_zip_read_info;
982 return UNZ_OK; 1168 return UNZ_OK;
983} 1169}
984 1170
1171extern int ZEXPORT unzOpenCurrentFile (file)
1172 unzFile file;
1173{
1174 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1175}
1176
1177extern int ZEXPORT unzOpenCurrentFilePassword (file, password)
1178 unzFile file;
1179 const char* password;
1180{
1181 return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1182}
1183
1184extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
1185 unzFile file;
1186 int* method;
1187 int* level;
1188 int raw;
1189{
1190 return unzOpenCurrentFile3(file, method, level, raw, NULL);
1191}
985 1192
986/* 1193/*
987 Read bytes from the current file. 1194 Read bytes from the current file.
@@ -994,126 +1201,149 @@ extern int ZEXPORT unzOpenCurrentFile (file)
994 (UNZ_ERRNO for IO error, or zLib error for uncompress error) 1201 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
995*/ 1202*/
996extern int ZEXPORT unzReadCurrentFile (file, buf, len) 1203extern int ZEXPORT unzReadCurrentFile (file, buf, len)
997 unzFile file; 1204 unzFile file;
998 voidp buf; 1205 voidp buf;
999 unsigned len; 1206 unsigned len;
1000{ 1207{
1001 int err=UNZ_OK; 1208 int err=UNZ_OK;
1002 uInt iRead = 0; 1209 uInt iRead = 0;
1003 unz_s* s; 1210 unz_s* s;
1004 file_in_zip_read_info_s* pfile_in_zip_read_info; 1211 file_in_zip_read_info_s* pfile_in_zip_read_info;
1005 if (file==NULL) 1212 if (file==NULL)
1006 return UNZ_PARAMERROR; 1213 return UNZ_PARAMERROR;
1007 s=(unz_s*)file; 1214 s=(unz_s*)file;
1008 pfile_in_zip_read_info=s->pfile_in_zip_read; 1215 pfile_in_zip_read_info=s->pfile_in_zip_read;
1009 1216
1010 if (pfile_in_zip_read_info==NULL) 1217 if (pfile_in_zip_read_info==NULL)
1011 return UNZ_PARAMERROR; 1218 return UNZ_PARAMERROR;
1219
1012 1220
1221 if ((pfile_in_zip_read_info->read_buffer == NULL))
1222 return UNZ_END_OF_LIST_OF_FILE;
1223 if (len==0)
1224 return 0;
1013 1225
1014 if ((pfile_in_zip_read_info->read_buffer == NULL)) 1226 pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
1015 return UNZ_END_OF_LIST_OF_FILE;
1016 if (len==0)
1017 return 0;
1018 1227
1019 pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; 1228 pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1020 1229
1021 pfile_in_zip_read_info->stream.avail_out = (uInt)len; 1230 if (len>pfile_in_zip_read_info->rest_read_uncompressed)
1022 1231 pfile_in_zip_read_info->stream.avail_out =
1023 if (len>pfile_in_zip_read_info->rest_read_uncompressed) 1232 (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1024 pfile_in_zip_read_info->stream.avail_out =
1025 (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1026 1233
1027 while (pfile_in_zip_read_info->stream.avail_out>0) 1234 while (pfile_in_zip_read_info->stream.avail_out>0)
1028 { 1235 {
1029 if ((pfile_in_zip_read_info->stream.avail_in==0) && 1236 if ((pfile_in_zip_read_info->stream.avail_in==0) &&
1030 (pfile_in_zip_read_info->rest_read_compressed>0)) 1237 (pfile_in_zip_read_info->rest_read_compressed>0))
1031 { 1238 {
1032 uInt uReadThis = UNZ_BUFSIZE; 1239 uInt uReadThis = UNZ_BUFSIZE;
1033 if (pfile_in_zip_read_info->rest_read_compressed<uReadThis) 1240 if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
1034 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; 1241 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
1035 if (uReadThis == 0) 1242 if (uReadThis == 0)
1036 return UNZ_EOF; 1243 return UNZ_EOF;
1037 if (fseek(pfile_in_zip_read_info->file, 1244 if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
1038 pfile_in_zip_read_info->pos_in_zipfile + 1245 pfile_in_zip_read_info->filestream,
1039 pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0) 1246 pfile_in_zip_read_info->pos_in_zipfile +
1040 return UNZ_ERRNO; 1247 pfile_in_zip_read_info->byte_before_the_zipfile,
1041 if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1, 1248 ZLIB_FILEFUNC_SEEK_SET)!=0)
1042 pfile_in_zip_read_info->file)!=1) 1249 return UNZ_ERRNO;
1043 return UNZ_ERRNO; 1250 if (ZREAD(pfile_in_zip_read_info->z_filefunc,
1044 pfile_in_zip_read_info->pos_in_zipfile += uReadThis; 1251 pfile_in_zip_read_info->filestream,
1045 1252 pfile_in_zip_read_info->read_buffer,
1046 pfile_in_zip_read_info->rest_read_compressed-=uReadThis; 1253 uReadThis)!=uReadThis)
1047 1254 return UNZ_ERRNO;
1048 pfile_in_zip_read_info->stream.next_in = 1255
1256
1257 #ifndef NOUNCRPYT
1258 if(s->encrypted)
1259 {
1260 uInt i;
1261 for(i=0;i<uReadThis;i++)
1262 pfile_in_zip_read_info->read_buffer[i] =
1263 zdecode(s->keys,s->pcrc_32_tab,
1264 pfile_in_zip_read_info->read_buffer[i]);
1265 }
1266 #endif
1267
1268
1269 pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
1270
1271 pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
1272
1273 pfile_in_zip_read_info->stream.next_in =
1049 (Bytef*)pfile_in_zip_read_info->read_buffer; 1274 (Bytef*)pfile_in_zip_read_info->read_buffer;
1050 pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; 1275 pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
1051 } 1276 }
1052 1277
1053 if (pfile_in_zip_read_info->compression_method==0) 1278 if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
1054 { 1279 {
1055 uInt uDoCopy,i ; 1280 uInt uDoCopy,i ;
1056 if (pfile_in_zip_read_info->stream.avail_out < 1281
1282 if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
1283 (pfile_in_zip_read_info->rest_read_compressed == 0))
1284 return (iRead==0) ? UNZ_EOF : iRead;
1285
1286 if (pfile_in_zip_read_info->stream.avail_out <
1057 pfile_in_zip_read_info->stream.avail_in) 1287 pfile_in_zip_read_info->stream.avail_in)
1058 uDoCopy = pfile_in_zip_read_info->stream.avail_out ; 1288 uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
1059 else 1289 else
1060 uDoCopy = pfile_in_zip_read_info->stream.avail_in ; 1290 uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
1061 1291
1062 for (i=0;i<uDoCopy;i++) 1292 for (i=0;i<uDoCopy;i++)
1063 *(pfile_in_zip_read_info->stream.next_out+i) = 1293 *(pfile_in_zip_read_info->stream.next_out+i) =
1064 *(pfile_in_zip_read_info->stream.next_in+i); 1294 *(pfile_in_zip_read_info->stream.next_in+i);
1065 1295
1066 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, 1296 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
1067 pfile_in_zip_read_info->stream.next_out, 1297 pfile_in_zip_read_info->stream.next_out,
1068 uDoCopy); 1298 uDoCopy);
1069 pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; 1299 pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
1070 pfile_in_zip_read_info->stream.avail_in -= uDoCopy; 1300 pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
1071 pfile_in_zip_read_info->stream.avail_out -= uDoCopy; 1301 pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
1072 pfile_in_zip_read_info->stream.next_out += uDoCopy; 1302 pfile_in_zip_read_info->stream.next_out += uDoCopy;
1073 pfile_in_zip_read_info->stream.next_in += uDoCopy; 1303 pfile_in_zip_read_info->stream.next_in += uDoCopy;
1074 pfile_in_zip_read_info->stream.total_out += uDoCopy; 1304 pfile_in_zip_read_info->stream.total_out += uDoCopy;
1075 iRead += uDoCopy; 1305 iRead += uDoCopy;
1076 } 1306 }
1077 else 1307 else
1078 { 1308 {
1079 uLong uTotalOutBefore,uTotalOutAfter; 1309 uLong uTotalOutBefore,uTotalOutAfter;
1080 const Bytef *bufBefore; 1310 const Bytef *bufBefore;
1081 uLong uOutThis; 1311 uLong uOutThis;
1082 int flush=Z_SYNC_FLUSH; 1312 int flush=Z_SYNC_FLUSH;
1083 1313
1084 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; 1314 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
1085 bufBefore = pfile_in_zip_read_info->stream.next_out; 1315 bufBefore = pfile_in_zip_read_info->stream.next_out;
1086 1316
1087 /* 1317 /*
1088 if ((pfile_in_zip_read_info->rest_read_uncompressed == 1318 if ((pfile_in_zip_read_info->rest_read_uncompressed ==
1089 pfile_in_zip_read_info->stream.avail_out) && 1319 pfile_in_zip_read_info->stream.avail_out) &&
1090 (pfile_in_zip_read_info->rest_read_compressed == 0)) 1320 (pfile_in_zip_read_info->rest_read_compressed == 0))
1091 flush = Z_FINISH; 1321 flush = Z_FINISH;
1092 */ 1322 */
1093 err=inflate(&pfile_in_zip_read_info->stream,flush); 1323 err=inflate(&pfile_in_zip_read_info->stream,flush);
1094 1324
1095 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; 1325 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1096 uOutThis = uTotalOutAfter-uTotalOutBefore; 1326 uOutThis = uTotalOutAfter-uTotalOutBefore;
1097 1327
1098 pfile_in_zip_read_info->crc32 = 1328 pfile_in_zip_read_info->crc32 =
1099 crc32(pfile_in_zip_read_info->crc32,bufBefore, 1329 crc32(pfile_in_zip_read_info->crc32,bufBefore,
1100 (uInt)(uOutThis)); 1330 (uInt)(uOutThis));
1101 1331
1102 pfile_in_zip_read_info->rest_read_uncompressed -= 1332 pfile_in_zip_read_info->rest_read_uncompressed -=
1103 uOutThis; 1333 uOutThis;
1104 1334
1105 iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); 1335 iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1106 1336
1107 if (err==Z_STREAM_END) 1337 if (err==Z_STREAM_END)
1108 return (iRead==0) ? UNZ_EOF : iRead; 1338 return (iRead==0) ? UNZ_EOF : iRead;
1109 if (err!=Z_OK) 1339 if (err!=Z_OK)
1110 break; 1340 break;
1111 } 1341 }
1112 } 1342 }
1113 1343
1114 if (err==Z_OK) 1344 if (err==Z_OK)
1115 return iRead; 1345 return iRead;
1116 return err; 1346 return err;
1117} 1347}
1118 1348
1119 1349
@@ -1121,42 +1351,42 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1121 Give the current position in uncompressed data 1351 Give the current position in uncompressed data
1122*/ 1352*/
1123extern z_off_t ZEXPORT unztell (file) 1353extern z_off_t ZEXPORT unztell (file)
1124 unzFile file; 1354 unzFile file;
1125{ 1355{
1126 unz_s* s; 1356 unz_s* s;
1127 file_in_zip_read_info_s* pfile_in_zip_read_info; 1357 file_in_zip_read_info_s* pfile_in_zip_read_info;
1128 if (file==NULL) 1358 if (file==NULL)
1129 return UNZ_PARAMERROR; 1359 return UNZ_PARAMERROR;
1130 s=(unz_s*)file; 1360 s=(unz_s*)file;
1131 pfile_in_zip_read_info=s->pfile_in_zip_read; 1361 pfile_in_zip_read_info=s->pfile_in_zip_read;
1132 1362
1133 if (pfile_in_zip_read_info==NULL) 1363 if (pfile_in_zip_read_info==NULL)
1134 return UNZ_PARAMERROR; 1364 return UNZ_PARAMERROR;
1135 1365
1136 return (z_off_t)pfile_in_zip_read_info->stream.total_out; 1366 return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1137} 1367}
1138 1368
1139 1369
1140/* 1370/*
1141 return 1 if the end of file was reached, 0 elsewhere 1371 return 1 if the end of file was reached, 0 elsewhere
1142*/ 1372*/
1143extern int ZEXPORT unzeof (file) 1373extern int ZEXPORT unzeof (file)
1144 unzFile file; 1374 unzFile file;
1145{ 1375{
1146 unz_s* s; 1376 unz_s* s;
1147 file_in_zip_read_info_s* pfile_in_zip_read_info; 1377 file_in_zip_read_info_s* pfile_in_zip_read_info;
1148 if (file==NULL) 1378 if (file==NULL)
1149 return UNZ_PARAMERROR; 1379 return UNZ_PARAMERROR;
1150 s=(unz_s*)file; 1380 s=(unz_s*)file;
1151 pfile_in_zip_read_info=s->pfile_in_zip_read; 1381 pfile_in_zip_read_info=s->pfile_in_zip_read;
1152 1382
1153 if (pfile_in_zip_read_info==NULL) 1383 if (pfile_in_zip_read_info==NULL)
1154 return UNZ_PARAMERROR; 1384 return UNZ_PARAMERROR;
1155 1385
1156 if (pfile_in_zip_read_info->rest_read_uncompressed == 0) 1386 if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
1157 return 1; 1387 return 1;
1158 else 1388 else
1159 return 0; 1389 return 0;
1160} 1390}
1161 1391
1162 1392
@@ -1169,51 +1399,55 @@ extern int ZEXPORT unzeof (file)
1169 if buf==NULL, it return the size of the local extra field that can be read 1399 if buf==NULL, it return the size of the local extra field that can be read
1170 1400
1171 if buf!=NULL, len is the size of the buffer, the extra header is copied in 1401 if buf!=NULL, len is the size of the buffer, the extra header is copied in
1172 buf. 1402 buf.
1173 the return value is the number of bytes copied in buf, or (if <0) 1403 the return value is the number of bytes copied in buf, or (if <0)
1174 the error code 1404 the error code
1175*/ 1405*/
1176extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) 1406extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
1177 unzFile file; 1407 unzFile file;
1178 voidp buf; 1408 voidp buf;
1179 unsigned len; 1409 unsigned len;
1180{ 1410{
1181 unz_s* s; 1411 unz_s* s;
1182 file_in_zip_read_info_s* pfile_in_zip_read_info; 1412 file_in_zip_read_info_s* pfile_in_zip_read_info;
1183 uInt read_now; 1413 uInt read_now;
1184 uLong size_to_read; 1414 uLong size_to_read;
1185 1415
1186 if (file==NULL) 1416 if (file==NULL)
1187 return UNZ_PARAMERROR; 1417 return UNZ_PARAMERROR;
1188 s=(unz_s*)file; 1418 s=(unz_s*)file;
1189 pfile_in_zip_read_info=s->pfile_in_zip_read; 1419 pfile_in_zip_read_info=s->pfile_in_zip_read;
1190 1420
1191 if (pfile_in_zip_read_info==NULL) 1421 if (pfile_in_zip_read_info==NULL)
1192 return UNZ_PARAMERROR; 1422 return UNZ_PARAMERROR;
1193 1423
1194 size_to_read = (pfile_in_zip_read_info->size_local_extrafield - 1424 size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
1195 pfile_in_zip_read_info->pos_local_extrafield); 1425 pfile_in_zip_read_info->pos_local_extrafield);
1426
1427 if (buf==NULL)
1428 return (int)size_to_read;
1429
1430 if (len>size_to_read)
1431 read_now = (uInt)size_to_read;
1432 else
1433 read_now = (uInt)len ;
1196 1434
1197 if (buf==NULL) 1435 if (read_now==0)
1198 return (int)size_to_read; 1436 return 0;
1199
1200 if (len>size_to_read)
1201 read_now = (uInt)size_to_read;
1202 else
1203 read_now = (uInt)len ;
1204 1437
1205 if (read_now==0) 1438 if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
1206 return 0; 1439 pfile_in_zip_read_info->filestream,
1207 1440 pfile_in_zip_read_info->offset_local_extrafield +
1208 if (fseek(pfile_in_zip_read_info->file, 1441 pfile_in_zip_read_info->pos_local_extrafield,
1209 pfile_in_zip_read_info->offset_local_extrafield + 1442 ZLIB_FILEFUNC_SEEK_SET)!=0)
1210 pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0) 1443 return UNZ_ERRNO;
1211 return UNZ_ERRNO;
1212 1444
1213 if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1) 1445 if (ZREAD(pfile_in_zip_read_info->z_filefunc,
1214 return UNZ_ERRNO; 1446 pfile_in_zip_read_info->filestream,
1447 buf,size_to_read)!=size_to_read)
1448 return UNZ_ERRNO;
1215 1449
1216 return (int)read_now; 1450 return (int)read_now;
1217} 1451}
1218 1452
1219/* 1453/*
@@ -1221,39 +1455,40 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
1221 Return UNZ_CRCERROR if all the file was read but the CRC is not good 1455 Return UNZ_CRCERROR if all the file was read but the CRC is not good
1222*/ 1456*/
1223extern int ZEXPORT unzCloseCurrentFile (file) 1457extern int ZEXPORT unzCloseCurrentFile (file)
1224 unzFile file; 1458 unzFile file;
1225{ 1459{
1226 int err=UNZ_OK; 1460 int err=UNZ_OK;
1227 1461
1228 unz_s* s; 1462 unz_s* s;
1229 file_in_zip_read_info_s* pfile_in_zip_read_info; 1463 file_in_zip_read_info_s* pfile_in_zip_read_info;
1230 if (file==NULL) 1464 if (file==NULL)
1231 return UNZ_PARAMERROR; 1465 return UNZ_PARAMERROR;
1232 s=(unz_s*)file; 1466 s=(unz_s*)file;
1233 pfile_in_zip_read_info=s->pfile_in_zip_read; 1467 pfile_in_zip_read_info=s->pfile_in_zip_read;
1234 1468
1235 if (pfile_in_zip_read_info==NULL) 1469 if (pfile_in_zip_read_info==NULL)
1236 return UNZ_PARAMERROR; 1470 return UNZ_PARAMERROR;
1237 1471
1238 1472
1239 if (pfile_in_zip_read_info->rest_read_uncompressed == 0) 1473 if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
1240 { 1474 (!pfile_in_zip_read_info->raw))
1241 if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) 1475 {
1242 err=UNZ_CRCERROR; 1476 if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
1243 } 1477 err=UNZ_CRCERROR;
1478 }
1244 1479
1245 1480
1246 TRYFREE(pfile_in_zip_read_info->read_buffer); 1481 TRYFREE(pfile_in_zip_read_info->read_buffer);
1247 pfile_in_zip_read_info->read_buffer = NULL; 1482 pfile_in_zip_read_info->read_buffer = NULL;
1248 if (pfile_in_zip_read_info->stream_initialised) 1483 if (pfile_in_zip_read_info->stream_initialised)
1249 inflateEnd(&pfile_in_zip_read_info->stream); 1484 inflateEnd(&pfile_in_zip_read_info->stream);
1250 1485
1251 pfile_in_zip_read_info->stream_initialised = 0; 1486 pfile_in_zip_read_info->stream_initialised = 0;
1252 TRYFREE(pfile_in_zip_read_info); 1487 TRYFREE(pfile_in_zip_read_info);
1253 1488
1254 s->pfile_in_zip_read=NULL; 1489 s->pfile_in_zip_read=NULL;
1255 1490
1256 return err; 1491 return err;
1257} 1492}
1258 1493
1259 1494
@@ -1263,32 +1498,32 @@ extern int ZEXPORT unzCloseCurrentFile (file)
1263 return the number of byte copied or an error code <0 1498 return the number of byte copied or an error code <0
1264*/ 1499*/
1265extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) 1500extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
1266 unzFile file; 1501 unzFile file;
1267 char *szComment; 1502 char *szComment;
1268 uLong uSizeBuf; 1503 uLong uSizeBuf;
1269{ 1504{
1270 int err=UNZ_OK; 1505 int err=UNZ_OK;
1271 unz_s* s; 1506 unz_s* s;
1272 uLong uReadThis ; 1507 uLong uReadThis ;
1273 if (file==NULL) 1508 if (file==NULL)
1274 return UNZ_PARAMERROR; 1509 return UNZ_PARAMERROR;
1275 s=(unz_s*)file; 1510 s=(unz_s*)file;
1276 1511
1277 uReadThis = uSizeBuf; 1512 uReadThis = uSizeBuf;
1278 if (uReadThis>s->gi.size_comment) 1513 if (uReadThis>s->gi.size_comment)
1279 uReadThis = s->gi.size_comment; 1514 uReadThis = s->gi.size_comment;
1280 1515
1281 if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0) 1516 if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
1282 return UNZ_ERRNO; 1517 return UNZ_ERRNO;
1283 1518
1284 if (uReadThis>0) 1519 if (uReadThis>0)
1285 { 1520 {
1286 *szComment='\0'; 1521 *szComment='\0';
1287 if (fread(szComment,(uInt)uReadThis,1,s->file)!=1) 1522 if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
1288 return UNZ_ERRNO; 1523 return UNZ_ERRNO;
1289 } 1524 }
1290 1525
1291 if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) 1526 if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
1292 *(szComment+s->gi.size_comment)='\0'; 1527 *(szComment+s->gi.size_comment)='\0';
1293 return (int)uReadThis; 1528 return (int)uReadThis;
1294} 1529}
diff --git a/contrib/minizip/unzip.def b/contrib/minizip/unzip.def
deleted file mode 100644
index f6ede89..0000000
--- a/contrib/minizip/unzip.def
+++ /dev/null
@@ -1,15 +0,0 @@
1 unzOpen @61
2 unzClose @62
3 unzGetGlobalInfo @63
4 unzGetCurrentFileInfo @64
5 unzGoToFirstFile @65
6 unzGoToNextFile @66
7 unzOpenCurrentFile @67
8 unzReadCurrentFile @68
9 unztell @70
10 unzeof @71
11 unzCloseCurrentFile @72
12 unzGetGlobalComment @73
13 unzStringFileNameCompare @74
14 unzLocateFile @75
15 unzGetLocalExtrafield @76
diff --git a/contrib/minizip/unzip.h b/contrib/minizip/unzip.h
index 76692cb..67ca851 100644
--- a/contrib/minizip/unzip.h
+++ b/contrib/minizip/unzip.h
@@ -1,15 +1,14 @@
1/* unzip.h -- IO for uncompress .zip files using zlib 1/* unzip.h -- IO for uncompress .zip files using zlib
2 Version 0.15 beta, Mar 19th, 1998, 2 Version 0.21, March 10th, 2003
3 3
4 Copyright (C) 1998 Gilles Vollant 4 Copyright (C) 1998-2003 Gilles Vollant
5 5
6 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g 6 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
7 WinZip, InfoZip tools and compatible. 7 WinZip, InfoZip tools and compatible.
8 Encryption and multi volume ZipFile (span) are not supported. 8 Encryption and multi volume ZipFile (span) are not supported.
9 Old compressions used by old PKZip 1.x are not supported 9 Old compressions used by old PKZip 1.x are not supported
10 10
11 THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE 11
12 CAN CHANGE IN FUTURE VERSION !!
13 I WAIT FEEDBACK at mail info@winimage.com 12 I WAIT FEEDBACK at mail info@winimage.com
14 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution 13 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
15 14
@@ -33,10 +32,13 @@
33 32
34 33
35*/ 34*/
36/* for more info about .ZIP format, see 35
37 ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip 36/* for more info about .ZIP format, see
37 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
38 http://www.info-zip.org/pub/infozip/doc/
38 PkWare has also a specification at : 39 PkWare has also a specification at :
39 ftp://ftp.pkware.com/probdesc.zip */ 40 ftp://ftp.pkware.com/probdesc.zip
41*/
40 42
41#ifndef _unz_H 43#ifndef _unz_H
42#define _unz_H 44#define _unz_H
@@ -49,43 +51,47 @@ extern "C" {
49#include "zlib.h" 51#include "zlib.h"
50#endif 52#endif
51 53
54#ifndef _ZLIBIOAPI_H
55#include "ioapi.h"
56#endif
57
52#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 58#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
53/* like the STRICT of WIN32, we define a pointer that cannot be converted 59/* like the STRICT of WIN32, we define a pointer that cannot be converted
54 from (void*) without cast */ 60 from (void*) without cast */
55typedef struct TagunzFile__ { int unused; } unzFile__; 61typedef struct TagunzFile__ { int unused; } unzFile__;
56typedef unzFile__ *unzFile; 62typedef unzFile__ *unzFile;
57#else 63#else
58typedef voidp unzFile; 64typedef voidp unzFile;
59#endif 65#endif
60 66
61 67
62#define UNZ_OK (0) 68#define UNZ_OK (0)
63#define UNZ_END_OF_LIST_OF_FILE (-100) 69#define UNZ_END_OF_LIST_OF_FILE (-100)
64#define UNZ_ERRNO (Z_ERRNO) 70#define UNZ_ERRNO (Z_ERRNO)
65#define UNZ_EOF (0) 71#define UNZ_EOF (0)
66#define UNZ_PARAMERROR (-102) 72#define UNZ_PARAMERROR (-102)
67#define UNZ_BADZIPFILE (-103) 73#define UNZ_BADZIPFILE (-103)
68#define UNZ_INTERNALERROR (-104) 74#define UNZ_INTERNALERROR (-104)
69#define UNZ_CRCERROR (-105) 75#define UNZ_CRCERROR (-105)
70 76
71/* tm_unz contain date/time info */ 77/* tm_unz contain date/time info */
72typedef struct tm_unz_s 78typedef struct tm_unz_s
73{ 79{
74 uInt tm_sec; /* seconds after the minute - [0,59] */ 80 uInt tm_sec; /* seconds after the minute - [0,59] */
75 uInt tm_min; /* minutes after the hour - [0,59] */ 81 uInt tm_min; /* minutes after the hour - [0,59] */
76 uInt tm_hour; /* hours since midnight - [0,23] */ 82 uInt tm_hour; /* hours since midnight - [0,23] */
77 uInt tm_mday; /* day of the month - [1,31] */ 83 uInt tm_mday; /* day of the month - [1,31] */
78 uInt tm_mon; /* months since January - [0,11] */ 84 uInt tm_mon; /* months since January - [0,11] */
79 uInt tm_year; /* years - [1980..2044] */ 85 uInt tm_year; /* years - [1980..2044] */
80} tm_unz; 86} tm_unz;
81 87
82/* unz_global_info structure contain global data about the ZIPfile 88/* unz_global_info structure contain global data about the ZIPfile
83 These data comes from the end of central dir */ 89 These data comes from the end of central dir */
84typedef struct unz_global_info_s 90typedef struct unz_global_info_s
85{ 91{
86 uLong number_entry; /* total number of entries in 92 uLong number_entry; /* total number of entries in
87 the central dir on this disk */ 93 the central dir on this disk */
88 uLong size_comment; /* size of the global comment of the zipfile */ 94 uLong size_comment; /* size of the global comment of the zipfile */
89} unz_global_info; 95} unz_global_info;
90 96
91 97
@@ -98,8 +104,8 @@ typedef struct unz_file_info_s
98 uLong compression_method; /* compression method 2 bytes */ 104 uLong compression_method; /* compression method 2 bytes */
99 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 105 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
100 uLong crc; /* crc-32 4 bytes */ 106 uLong crc; /* crc-32 4 bytes */
101 uLong compressed_size; /* compressed size 4 bytes */ 107 uLong compressed_size; /* compressed size 4 bytes */
102 uLong uncompressed_size; /* uncompressed size 4 bytes */ 108 uLong uncompressed_size; /* uncompressed size 4 bytes */
103 uLong size_filename; /* filename length 2 bytes */ 109 uLong size_filename; /* filename length 2 bytes */
104 uLong size_file_extra; /* extra field length 2 bytes */ 110 uLong size_file_extra; /* extra field length 2 bytes */
105 uLong size_file_comment; /* file comment length 2 bytes */ 111 uLong size_file_comment; /* file comment length 2 bytes */
@@ -112,27 +118,34 @@ typedef struct unz_file_info_s
112} unz_file_info; 118} unz_file_info;
113 119
114extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, 120extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
115 const char* fileName2, 121 const char* fileName2,
116 int iCaseSensitivity)); 122 int iCaseSensitivity));
117/* 123/*
118 Compare two filename (fileName1,fileName2). 124 Compare two filename (fileName1,fileName2).
119 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) 125 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
120 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi 126 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
121 or strcasecmp) 127 or strcasecmp)
122 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system 128 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
123 (like 1 on Unix, 2 on Windows) 129 (like 1 on Unix, 2 on Windows)
124*/ 130*/
125 131
126 132
127extern unzFile ZEXPORT unzOpen OF((const char *path)); 133extern unzFile ZEXPORT unzOpen OF((const char *path));
128/* 134/*
129 Open a Zip file. path contain the full pathname (by example, 135 Open a Zip file. path contain the full pathname (by example,
130 on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer 136 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
131 "zlib/zlib111.zip". 137 "zlib/zlib113.zip".
132 If the zipfile cannot be opened (file don't exist or in not valid), the 138 If the zipfile cannot be opened (file don't exist or in not valid), the
133 return value is NULL. 139 return value is NULL.
134 Else, the return value is a unzFile Handle, usable with other function 140 Else, the return value is a unzFile Handle, usable with other function
135 of this unzip package. 141 of this unzip package.
142*/
143
144extern unzFile ZEXPORT unzOpen2 OF((const char *path,
145 zlib_filefunc_def* pzlib_filefunc_def));
146/*
147 Open a Zip file, like unzOpen, but provide a set of file low level API
148 for read/write the zip file (see ioapi.h)
136*/ 149*/
137 150
138extern int ZEXPORT unzClose OF((unzFile file)); 151extern int ZEXPORT unzClose OF((unzFile file));
@@ -143,7 +156,7 @@ extern int ZEXPORT unzClose OF((unzFile file));
143 return UNZ_OK if there is no problem. */ 156 return UNZ_OK if there is no problem. */
144 157
145extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, 158extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
146 unz_global_info *pglobal_info)); 159 unz_global_info *pglobal_info));
147/* 160/*
148 Write info about the ZipFile in the *pglobal_info structure. 161 Write info about the ZipFile in the *pglobal_info structure.
149 No preparation of the structure is needed 162 No preparation of the structure is needed
@@ -151,8 +164,8 @@ extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
151 164
152 165
153extern int ZEXPORT unzGetGlobalComment OF((unzFile file, 166extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
154 char *szComment, 167 char *szComment,
155 uLong uSizeBuf)); 168 uLong uSizeBuf));
156/* 169/*
157 Get the global comment string of the ZipFile, in the szComment buffer. 170 Get the global comment string of the ZipFile, in the szComment buffer.
158 uSizeBuf is the size of the szComment buffer. 171 uSizeBuf is the size of the szComment buffer.
@@ -176,9 +189,9 @@ extern int ZEXPORT unzGoToNextFile OF((unzFile file));
176 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 189 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
177*/ 190*/
178 191
179extern int ZEXPORT unzLocateFile OF((unzFile file, 192extern int ZEXPORT unzLocateFile OF((unzFile file,
180 const char *szFileName, 193 const char *szFileName,
181 int iCaseSensitivity)); 194 int iCaseSensitivity));
182/* 195/*
183 Try locate the file szFileName in the zipfile. 196 Try locate the file szFileName in the zipfile.
184 For the iCaseSensitivity signification, see unzStringFileNameCompare 197 For the iCaseSensitivity signification, see unzStringFileNameCompare
@@ -189,25 +202,44 @@ extern int ZEXPORT unzLocateFile OF((unzFile file,
189*/ 202*/
190 203
191 204
205/* ****************************************** */
206/* Ryan supplied functions */
207/* unz_file_info contain information about a file in the zipfile */
208typedef struct unz_file_pos_s
209{
210 uLong pos_in_zip_directory; /* offset in zip file directory */
211 uLong num_of_file; /* # of file */
212} unz_file_pos;
213
214extern int ZEXPORT unzGetFilePos(
215 unzFile file,
216 unz_file_pos* file_pos);
217
218extern int ZEXPORT unzGoToFilePos(
219 unzFile file,
220 unz_file_pos* file_pos);
221
222/* ****************************************** */
223
192extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, 224extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
193 unz_file_info *pfile_info, 225 unz_file_info *pfile_info,
194 char *szFileName, 226 char *szFileName,
195 uLong fileNameBufferSize, 227 uLong fileNameBufferSize,
196 void *extraField, 228 void *extraField,
197 uLong extraFieldBufferSize, 229 uLong extraFieldBufferSize,
198 char *szComment, 230 char *szComment,
199 uLong commentBufferSize)); 231 uLong commentBufferSize));
200/* 232/*
201 Get Info about the current file 233 Get Info about the current file
202 if pfile_info!=NULL, the *pfile_info structure will contain somes info about 234 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
203 the current file 235 the current file
204 if szFileName!=NULL, the filemane string will be copied in szFileName 236 if szFileName!=NULL, the filemane string will be copied in szFileName
205 (fileNameBufferSize is the size of the buffer) 237 (fileNameBufferSize is the size of the buffer)
206 if extraField!=NULL, the extra field information will be copied in extraField 238 if extraField!=NULL, the extra field information will be copied in extraField
207 (extraFieldBufferSize is the size of the buffer). 239 (extraFieldBufferSize is the size of the buffer).
208 This is the Central-header version of the extra field 240 This is the Central-header version of the extra field
209 if szComment!=NULL, the comment string of the file will be copied in szComment 241 if szComment!=NULL, the comment string of the file will be copied in szComment
210 (commentBufferSize is the size of the buffer) 242 (commentBufferSize is the size of the buffer)
211*/ 243*/
212 244
213/***************************************************************************/ 245/***************************************************************************/
@@ -221,16 +253,51 @@ extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
221 If there is no error, the return value is UNZ_OK. 253 If there is no error, the return value is UNZ_OK.
222*/ 254*/
223 255
256extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
257 const char* password));
258/*
259 Open for reading data the current file in the zipfile.
260 password is a crypting password
261 If there is no error, the return value is UNZ_OK.
262*/
263
264extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
265 int* method,
266 int* level,
267 int raw));
268/*
269 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
270 if raw==1
271 *method will receive method of compression, *level will receive level of
272 compression
273 note : you can set level parameter as NULL (if you did not want known level,
274 but you CANNOT set method parameter as NULL
275*/
276
277extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
278 int* method,
279 int* level,
280 int raw,
281 const char* password));
282/*
283 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
284 if raw==1
285 *method will receive method of compression, *level will receive level of
286 compression
287 note : you can set level parameter as NULL (if you did not want known level,
288 but you CANNOT set method parameter as NULL
289*/
290
291
224extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); 292extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
225/* 293/*
226 Close the file in zip opened with unzOpenCurrentFile 294 Close the file in zip opened with unzOpenCurrentFile
227 Return UNZ_CRCERROR if all the file was read but the CRC is not good 295 Return UNZ_CRCERROR if all the file was read but the CRC is not good
228*/ 296*/
229 297
230 298extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
231extern int ZEXPORT unzReadCurrentFile OF((unzFile file, 299 voidp buf,
232 voidp buf, 300 unsigned len));
233 unsigned len));
234/* 301/*
235 Read bytes from the current file (opened by unzOpenCurrentFile) 302 Read bytes from the current file (opened by unzOpenCurrentFile)
236 buf contain buffer where data must be copied 303 buf contain buffer where data must be copied
@@ -249,12 +316,12 @@ extern z_off_t ZEXPORT unztell OF((unzFile file));
249 316
250extern int ZEXPORT unzeof OF((unzFile file)); 317extern int ZEXPORT unzeof OF((unzFile file));
251/* 318/*
252 return 1 if the end of file was reached, 0 elsewhere 319 return 1 if the end of file was reached, 0 elsewhere
253*/ 320*/
254 321
255extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, 322extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
256 voidp buf, 323 voidp buf,
257 unsigned len)); 324 unsigned len));
258/* 325/*
259 Read extra field from the current file (opened by unzOpenCurrentFile) 326 Read extra field from the current file (opened by unzOpenCurrentFile)
260 This is the local-header version of the extra field (sometimes, there is 327 This is the local-header version of the extra field (sometimes, there is
@@ -263,9 +330,9 @@ extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
263 if buf==NULL, it return the size of the local extra field 330 if buf==NULL, it return the size of the local extra field
264 331
265 if buf!=NULL, len is the size of the buffer, the extra header is copied in 332 if buf!=NULL, len is the size of the buffer, the extra header is copied in
266 buf. 333 buf.
267 the return value is the number of bytes copied in buf, or (if <0) 334 the return value is the number of bytes copied in buf, or (if <0)
268 the error code 335 the error code
269*/ 336*/
270 337
271#ifdef __cplusplus 338#ifdef __cplusplus
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c
index 0cae64a..29c17d8 100644
--- a/contrib/minizip/zip.c
+++ b/contrib/minizip/zip.c
@@ -1,5 +1,5 @@
1/* zip.c -- IO on .zip files using zlib 1/* zip.c -- IO on .zip files using zlib
2 Version 0.15 beta, Mar 19th, 1998, 2 Version 0.21, March 10th, 2003
3 3
4 Read zip.h for more info 4 Read zip.h for more info
5*/ 5*/
@@ -8,6 +8,7 @@
8#include <stdio.h> 8#include <stdio.h>
9#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h> 10#include <string.h>
11#include <time.h>
11#include "zlib.h" 12#include "zlib.h"
12#include "zip.h" 13#include "zip.h"
13 14
@@ -66,8 +67,15 @@
66#define SEEK_SET 0 67#define SEEK_SET 0
67#endif 68#endif
68 69
70#ifndef DEF_MEM_LEVEL
71#if MAX_MEM_LEVEL >= 8
72# define DEF_MEM_LEVEL 8
73#else
74# define DEF_MEM_LEVEL MAX_MEM_LEVEL
75#endif
76#endif
69const char zip_copyright[] = 77const char zip_copyright[] =
70 " zip 0.15 Copyright 1998 Gilles Vollant "; 78 " zip 0.21 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll";
71 79
72 80
73#define SIZEDATA_INDATABLOCK (4096-(4*4)) 81#define SIZEDATA_INDATABLOCK (4096-(4*4))
@@ -99,33 +107,49 @@ typedef struct linkedlist_data_s
99 107
100typedef struct 108typedef struct
101{ 109{
102 z_stream stream; /* zLib stream structure for inflate */ 110 z_stream stream; /* zLib stream structure for inflate */
103 int stream_initialised; /* 1 is stream is initialised */ 111 int stream_initialised; /* 1 is stream is initialised */
104 uInt pos_in_buffered_data; /* last written byte in buffered_data */ 112 uInt pos_in_buffered_data; /* last written byte in buffered_data */
105 113
106 uLong pos_local_header; /* offset of the local header of the file 114 uLong pos_local_header; /* offset of the local header of the file
107 currenty writing */ 115 currenty writing */
108 char* central_header; /* central header data for the current file */ 116 char* central_header; /* central header data for the current file */
109 uLong size_centralheader; /* size of the central header for cur file */ 117 uLong size_centralheader; /* size of the central header for cur file */
110 uLong flag; /* flag of the file currently writing */ 118 uLong flag; /* flag of the file currently writing */
111 119
112 int method; /* compression method of file currenty wr.*/ 120 int method; /* compression method of file currenty wr.*/
121 int raw; /* 1 for directly writing raw data */
113 Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ 122 Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
114 uLong dosDate; 123 uLong dosDate;
115 uLong crc32; 124 uLong crc32;
125 int encrypt;
126#ifndef NOCRPYT
127 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
128 const unsigned long* pcrc_32_tab;
129 int crypt_header_size;
130#endif
116} curfile_info; 131} curfile_info;
117 132
118typedef struct 133typedef struct
119{ 134{
120 FILE * filezip; 135 zlib_filefunc_def z_filefunc;
136 voidpf filestream; /* io structore of the zipfile */
121 linkedlist_data central_dir;/* datablock with central dir in construction*/ 137 linkedlist_data central_dir;/* datablock with central dir in construction*/
122 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ 138 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
123 curfile_info ci; /* info on the file curretly writing */ 139 curfile_info ci; /* info on the file curretly writing */
124 140
125 uLong begin_pos; /* position of the beginning of the zipfile */ 141 uLong begin_pos; /* position of the beginning of the zipfile */
142 uLong add_position_when_writting_offset;
126 uLong number_entry; 143 uLong number_entry;
127} zip_internal; 144} zip_internal;
128 145
146
147
148#ifndef NOCRPYT
149#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
150#include "crypt.h"
151#endif
152
129local linkedlist_datablock_internal* allocate_new_datablock() 153local linkedlist_datablock_internal* allocate_new_datablock()
130{ 154{
131 linkedlist_datablock_internal* ldi; 155 linkedlist_datablock_internal* ldi;
@@ -166,7 +190,7 @@ local void free_linkedlist(ll)
166 190
167 191
168local int add_data_in_datablock(ll,buf,len) 192local int add_data_in_datablock(ll,buf,len)
169 linkedlist_data* ll; 193 linkedlist_data* ll;
170 const void* buf; 194 const void* buf;
171 uLong len; 195 uLong len;
172{ 196{
@@ -220,32 +244,20 @@ local int add_data_in_datablock(ll,buf,len)
220} 244}
221 245
222 246
223local int write_datablock(fout,ll)
224 FILE * fout;
225 linkedlist_data* ll;
226{
227 linkedlist_datablock_internal* ldi;
228 ldi = ll->first_block;
229 while (ldi!=NULL)
230 {
231 if (ldi->filled_in_this_block > 0)
232 if (fwrite(ldi->data,(uInt)ldi->filled_in_this_block,1,fout)!=1)
233 return ZIP_ERRNO;
234 ldi = ldi->next_datablock;
235 }
236 return ZIP_OK;
237}
238 247
239/****************************************************************************/ 248/****************************************************************************/
240 249
250#ifndef NO_ADDFILEINEXISTINGZIP
241/* =========================================================================== 251/* ===========================================================================
242 Outputs a long in LSB order to the given file 252 Inputs a long in LSB order to the given file
243 nbByte == 1, 2 or 4 (byte, short or long) 253 nbByte == 1, 2 or 4 (byte, short or long)
244*/ 254*/
245 255
246local int ziplocal_putValue OF((FILE *file, uLong x, int nbByte)); 256local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def,
247local int ziplocal_putValue (file, x, nbByte) 257 voidpf filestream, uLong x, int nbByte));
248 FILE *file; 258local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte)
259 const zlib_filefunc_def* pzlib_filefunc_def;
260 voidpf filestream;
249 uLong x; 261 uLong x;
250 int nbByte; 262 int nbByte;
251{ 263{
@@ -255,7 +267,7 @@ local int ziplocal_putValue (file, x, nbByte)
255 buf[n] = (unsigned char)(x & 0xff); 267 buf[n] = (unsigned char)(x & 0xff);
256 x >>= 8; 268 x >>= 8;
257 } 269 }
258 if (fwrite(buf,nbByte,1,file)!=1) 270 if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
259 return ZIP_ERRNO; 271 return ZIP_ERRNO;
260 else 272 else
261 return ZIP_OK; 273 return ZIP_OK;
@@ -278,7 +290,7 @@ local void ziplocal_putValue_inmemory (dest, x, nbByte)
278 290
279 291
280local uLong ziplocal_TmzDateToDosDate(ptm,dosDate) 292local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
281 tm_zip* ptm; 293 const tm_zip* ptm;
282 uLong dosDate; 294 uLong dosDate;
283{ 295{
284 uLong year = (uLong)ptm->tm_year; 296 uLong year = (uLong)ptm->tm_year;
@@ -294,38 +306,348 @@ local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
294 306
295/****************************************************************************/ 307/****************************************************************************/
296 308
297extern zipFile ZEXPORT zipOpen (pathname, append) 309local int ziplocal_getByte OF((
310 const zlib_filefunc_def* pzlib_filefunc_def,
311 voidpf filestream,
312 int *pi));
313
314local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi)
315 const zlib_filefunc_def* pzlib_filefunc_def;
316 voidpf filestream;
317 int *pi;
318{
319 unsigned char c;
320 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
321 if (err==1)
322 {
323 *pi = (int)c;
324 return ZIP_OK;
325 }
326 else
327 {
328 if (ZERROR(*pzlib_filefunc_def,filestream))
329 return ZIP_ERRNO;
330 else
331 return ZIP_EOF;
332 }
333}
334
335
336/* ===========================================================================
337 Reads a long in LSB order from the given gz_stream. Sets
338*/
339local int ziplocal_getShort OF((
340 const zlib_filefunc_def* pzlib_filefunc_def,
341 voidpf filestream,
342 uLong *pX));
343
344local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX)
345 const zlib_filefunc_def* pzlib_filefunc_def;
346 voidpf filestream;
347 uLong *pX;
348{
349 uLong x ;
350 int i;
351 int err;
352
353 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
354 x = (uLong)i;
355
356 if (err==ZIP_OK)
357 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
358 x += ((uLong)i)<<8;
359
360 if (err==ZIP_OK)
361 *pX = x;
362 else
363 *pX = 0;
364 return err;
365}
366
367local int ziplocal_getLong OF((
368 const zlib_filefunc_def* pzlib_filefunc_def,
369 voidpf filestream,
370 uLong *pX));
371
372local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX)
373 const zlib_filefunc_def* pzlib_filefunc_def;
374 voidpf filestream;
375 uLong *pX;
376{
377 uLong x ;
378 int i;
379 int err;
380
381 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
382 x = (uLong)i;
383
384 if (err==ZIP_OK)
385 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
386 x += ((uLong)i)<<8;
387
388 if (err==ZIP_OK)
389 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
390 x += ((uLong)i)<<16;
391
392 if (err==ZIP_OK)
393 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
394 x += ((uLong)i)<<24;
395
396 if (err==ZIP_OK)
397 *pX = x;
398 else
399 *pX = 0;
400 return err;
401}
402
403#ifndef BUFREADCOMMENT
404#define BUFREADCOMMENT (0x400)
405#endif
406/*
407 Locate the Central directory of a zipfile (at the end, just before
408 the global comment)
409*/
410local uLong ziplocal_SearchCentralDir OF((
411 const zlib_filefunc_def* pzlib_filefunc_def,
412 voidpf filestream));
413
414local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream)
415 const zlib_filefunc_def* pzlib_filefunc_def;
416 voidpf filestream;
417{
418 unsigned char* buf;
419 uLong uSizeFile;
420 uLong uBackRead;
421 uLong uMaxBack=0xffff; /* maximum size of global comment */
422 uLong uPosFound=0;
423
424 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
425 return 0;
426
427
428 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
429
430 if (uMaxBack>uSizeFile)
431 uMaxBack = uSizeFile;
432
433 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
434 if (buf==NULL)
435 return 0;
436
437 uBackRead = 4;
438 while (uBackRead<uMaxBack)
439 {
440 uLong uReadSize,uReadPos ;
441 int i;
442 if (uBackRead+BUFREADCOMMENT>uMaxBack)
443 uBackRead = uMaxBack;
444 else
445 uBackRead+=BUFREADCOMMENT;
446 uReadPos = uSizeFile-uBackRead ;
447
448 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
449 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
450 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
451 break;
452
453 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
454 break;
455
456 for (i=(int)uReadSize-3; (i--)>0;)
457 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
458 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
459 {
460 uPosFound = uReadPos+i;
461 break;
462 }
463
464 if (uPosFound!=0)
465 break;
466 }
467 TRYFREE(buf);
468 return uPosFound;
469}
470#endif /* !NO_ADDFILEINEXISTINGZIP*/
471
472/************************************************************/
473extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def)
298 const char *pathname; 474 const char *pathname;
299 int append; 475 int append;
476 zipcharpc* globalcomment;
477 zlib_filefunc_def* pzlib_filefunc_def;
300{ 478{
301 zip_internal ziinit; 479 zip_internal ziinit;
302 zip_internal* zi; 480 zip_internal* zi;
481 int err=ZIP_OK;
482
303 483
304 ziinit.filezip = fopen(pathname,(append == 0) ? "wb" : "ab"); 484 if (pzlib_filefunc_def==NULL)
305 if (ziinit.filezip == NULL) 485 fill_fopen_filefunc(&ziinit.z_filefunc);
486 else
487 ziinit.z_filefunc = *pzlib_filefunc_def;
488
489 ziinit.filestream = (*(ziinit.z_filefunc.zopen_file))
490 (ziinit.z_filefunc.opaque,
491 pathname,
492 (append == APPEND_STATUS_CREATE) ?
493 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
494 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
495
496 if (ziinit.filestream == NULL)
306 return NULL; 497 return NULL;
307 ziinit.begin_pos = ftell(ziinit.filezip); 498 ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream);
308 ziinit.in_opened_file_inzip = 0; 499 ziinit.in_opened_file_inzip = 0;
309 ziinit.ci.stream_initialised = 0; 500 ziinit.ci.stream_initialised = 0;
310 ziinit.number_entry = 0; 501 ziinit.number_entry = 0;
502 ziinit.add_position_when_writting_offset = 0;
311 init_linkedlist(&(ziinit.central_dir)); 503 init_linkedlist(&(ziinit.central_dir));
312 504
313 505
314 zi = (zip_internal*)ALLOC(sizeof(zip_internal)); 506 zi = (zip_internal*)ALLOC(sizeof(zip_internal));
315 if (zi==NULL) 507 if (zi==NULL)
316 { 508 {
317 fclose(ziinit.filezip); 509 ZCLOSE(ziinit.z_filefunc,ziinit.filestream);
318 return NULL; 510 return NULL;
319 } 511 }
320 512
321 *zi = ziinit; 513 /* now we add file in a zipfile */
322 return (zipFile)zi; 514 #ifndef NO_ADDFILEINEXISTINGZIP
515 if (append == APPEND_STATUS_ADDINZIP)
516 {
517 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
518
519 uLong size_central_dir; /* size of the central directory */
520 uLong offset_central_dir; /* offset of start of central directory */
521 uLong central_pos,uL;
522
523 uLong number_disk; /* number of the current dist, used for
524 spaning ZIP, unsupported, always 0*/
525 uLong number_disk_with_CD; /* number the the disk with central dir, used
526 for spaning ZIP, unsupported, always 0*/
527 uLong number_entry;
528 uLong number_entry_CD; /* total number of entries in
529 the central dir
530 (same than number_entry on nospan) */
531 uLong size_comment;
532
533 central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream);
534 if (central_pos==0)
535 err=ZIP_ERRNO;
536
537 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
538 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
539 err=ZIP_ERRNO;
540
541 /* the signature, already checked */
542 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK)
543 err=ZIP_ERRNO;
544
545 /* number of this disk */
546 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK)
547 err=ZIP_ERRNO;
548
549 /* number of the disk with the start of the central directory */
550 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK)
551 err=ZIP_ERRNO;
552
553 /* total number of entries in the central dir on this disk */
554 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK)
555 err=ZIP_ERRNO;
556
557 /* total number of entries in the central dir */
558 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK)
559 err=ZIP_ERRNO;
560
561 if ((number_entry_CD!=number_entry) ||
562 (number_disk_with_CD!=0) ||
563 (number_disk!=0))
564 err=ZIP_BADZIPFILE;
565
566 /* size of the central directory */
567 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&size_central_dir)!=ZIP_OK)
568 err=ZIP_ERRNO;
569
570 /* offset of start of central directory with respect to the
571 starting disk number */
572 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK)
573 err=ZIP_ERRNO;
574
575 /* zipfile comment length */
576 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK)
577 err=ZIP_ERRNO;
578
579 if ((central_pos<offset_central_dir+size_central_dir) &&
580 (err==ZIP_OK))
581 err=ZIP_BADZIPFILE;
582
583 if (err!=ZIP_OK)
584 {
585 ZCLOSE(ziinit.z_filefunc, ziinit.filestream);
586 return NULL;
587 }
588
589 byte_before_the_zipfile = central_pos -
590 (offset_central_dir+size_central_dir);
591 ziinit.add_position_when_writting_offset = byte_before_the_zipfile ;
592
593 {
594 uLong size_central_dir_to_read = size_central_dir;
595 size_t buf_size = SIZEDATA_INDATABLOCK;
596 void* buf_read = (void*)ALLOC(buf_size);
597 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
598 offset_central_dir + byte_before_the_zipfile,
599 ZLIB_FILEFUNC_SEEK_SET) != 0)
600 err=ZIP_ERRNO;
601
602 while ((size_central_dir_to_read>0) && (err==ZIP_OK))
603 {
604 uLong read_this = SIZEDATA_INDATABLOCK;
605 if (read_this > size_central_dir_to_read)
606 read_this = size_central_dir_to_read;
607 if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this)
608 err=ZIP_ERRNO;
609
610 if (err==ZIP_OK)
611 err = add_data_in_datablock(&ziinit.central_dir,buf_read,
612 (uLong)read_this);
613 size_central_dir_to_read-=read_this;
614 }
615 TRYFREE(buf_read);
616 }
617 ziinit.begin_pos = byte_before_the_zipfile;
618 ziinit.number_entry = number_entry_CD;
619
620 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
621 offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
622 err=ZIP_ERRNO;
623 }
624 #endif /* !NO_ADDFILEINEXISTINGZIP*/
625
626 if (err != ZIP_OK)
627 {
628 TRYFREE(zi);
629 return NULL;
630 }
631 else
632 {
633 *zi = ziinit;
634 return (zipFile)zi;
635 }
323} 636}
324 637
325extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi, 638extern zipFile ZEXPORT zipOpen (pathname, append)
326 extrafield_local, size_extrafield_local, 639 const char *pathname;
327 extrafield_global, size_extrafield_global, 640 int append;
328 comment, method, level) 641{
642 return zipOpen2(pathname,append,NULL,NULL);
643}
644
645extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
646 extrafield_local, size_extrafield_local,
647 extrafield_global, size_extrafield_global,
648 comment, method, level, raw,
649 windowBits, memLevel, strategy,
650 password, crcForCrypting)
329 zipFile file; 651 zipFile file;
330 const char* filename; 652 const char* filename;
331 const zip_fileinfo* zipfi; 653 const zip_fileinfo* zipfi;
@@ -336,6 +658,12 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
336 const char* comment; 658 const char* comment;
337 int method; 659 int method;
338 int level; 660 int level;
661 int raw;
662 int windowBits;
663 int memLevel;
664 int strategy;
665 const char* password;
666 uLong crcForCrypting;
339{ 667{
340 zip_internal* zi; 668 zip_internal* zi;
341 uInt size_filename; 669 uInt size_filename;
@@ -343,6 +671,11 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
343 uInt i; 671 uInt i;
344 int err = ZIP_OK; 672 int err = ZIP_OK;
345 673
674 #ifdef NOCRPYT
675 if (password != NULL)
676 return ZIP_PARAMERROR;
677 #endif
678
346 if (file == NULL) 679 if (file == NULL)
347 return ZIP_PARAMERROR; 680 return ZIP_PARAMERROR;
348 if ((method!=0) && (method!=Z_DEFLATED)) 681 if ((method!=0) && (method!=Z_DEFLATED))
@@ -384,13 +717,17 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
384 zi->ci.flag |= 4; 717 zi->ci.flag |= 4;
385 if ((level==1)) 718 if ((level==1))
386 zi->ci.flag |= 6; 719 zi->ci.flag |= 6;
720 if (password != NULL)
721 zi->ci.flag |= 1;
387 722
388 zi->ci.crc32 = 0; 723 zi->ci.crc32 = 0;
389 zi->ci.method = method; 724 zi->ci.method = method;
725 zi->ci.encrypt = 0;
390 zi->ci.stream_initialised = 0; 726 zi->ci.stream_initialised = 0;
391 zi->ci.pos_in_buffered_data = 0; 727 zi->ci.pos_in_buffered_data = 0;
392 zi->ci.pos_local_header = ftell(zi->filezip); 728 zi->ci.raw = raw;
393 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + 729 zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ;
730 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename +
394 size_extrafield_global + size_comment; 731 size_extrafield_global + size_comment;
395 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader); 732 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader);
396 733
@@ -410,16 +747,16 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
410 ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ 747 ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
411 748
412 if (zipfi==NULL) 749 if (zipfi==NULL)
413 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); 750 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
414 else 751 else
415 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); 752 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
416 753
417 if (zipfi==NULL) 754 if (zipfi==NULL)
418 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); 755 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
419 else 756 else
420 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); 757 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
421 758
422 ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header,4); 759 ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4);
423 760
424 for (i=0;i<size_filename;i++) 761 for (i=0;i<size_filename;i++)
425 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i); 762 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
@@ -430,44 +767,44 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
430 767
431 for (i=0;i<size_comment;i++) 768 for (i=0;i<size_comment;i++)
432 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+ 769 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
433 size_extrafield_global+i) = *(filename+i); 770 size_extrafield_global+i) = *(comment+i);
434 if (zi->ci.central_header == NULL) 771 if (zi->ci.central_header == NULL)
435 return ZIP_INTERNALERROR; 772 return ZIP_INTERNALERROR;
436 773
437 /* write the local header */ 774 /* write the local header */
438 err = ziplocal_putValue(zi->filezip,(uLong)LOCALHEADERMAGIC,4); 775 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4);
439 776
440 if (err==ZIP_OK) 777 if (err==ZIP_OK)
441 err = ziplocal_putValue(zi->filezip,(uLong)20,2);/* version needed to extract */ 778 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */
442 if (err==ZIP_OK) 779 if (err==ZIP_OK)
443 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.flag,2); 780 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
444 781
445 if (err==ZIP_OK) 782 if (err==ZIP_OK)
446 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.method,2); 783 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
447 784
448 if (err==ZIP_OK) 785 if (err==ZIP_OK)
449 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.dosDate,4); 786 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
450 787
451 if (err==ZIP_OK) 788 if (err==ZIP_OK)
452 err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* crc 32, unknown */ 789 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
453 if (err==ZIP_OK) 790 if (err==ZIP_OK)
454 err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* compressed size, unknown */ 791 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
455 if (err==ZIP_OK) 792 if (err==ZIP_OK)
456 err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* uncompressed size, unknown */ 793 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
457 794
458 if (err==ZIP_OK) 795 if (err==ZIP_OK)
459 err = ziplocal_putValue(zi->filezip,(uLong)size_filename,2); 796 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
460 797
461 if (err==ZIP_OK) 798 if (err==ZIP_OK)
462 err = ziplocal_putValue(zi->filezip,(uLong)size_extrafield_local,2); 799 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2);
463 800
464 if ((err==ZIP_OK) && (size_filename>0)) 801 if ((err==ZIP_OK) && (size_filename>0))
465 if (fwrite(filename,(uInt)size_filename,1,zi->filezip)!=1) 802 if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
466 err = ZIP_ERRNO; 803 err = ZIP_ERRNO;
467 804
468 if ((err==ZIP_OK) && (size_extrafield_local>0)) 805 if ((err==ZIP_OK) && (size_extrafield_local>0))
469 if (fwrite(extrafield_local,(uInt)size_extrafield_local,1,zi->filezip) 806 if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local)
470 !=1) 807 !=size_extrafield_local)
471 err = ZIP_ERRNO; 808 err = ZIP_ERRNO;
472 809
473 zi->ci.stream.avail_in = (uInt)0; 810 zi->ci.stream.avail_in = (uInt)0;
@@ -476,17 +813,38 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
476 zi->ci.stream.total_in = 0; 813 zi->ci.stream.total_in = 0;
477 zi->ci.stream.total_out = 0; 814 zi->ci.stream.total_out = 0;
478 815
479 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED)) 816 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
480 { 817 {
481 zi->ci.stream.zalloc = (alloc_func)0; 818 zi->ci.stream.zalloc = (alloc_func)0;
482 zi->ci.stream.zfree = (free_func)0; 819 zi->ci.stream.zfree = (free_func)0;
483 zi->ci.stream.opaque = (voidpf)0; 820 zi->ci.stream.opaque = (voidpf)0;
484 821
822 if (windowBits>0)
823 windowBits = -windowBits;
824
485 err = deflateInit2(&zi->ci.stream, level, 825 err = deflateInit2(&zi->ci.stream, level,
486 Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, 0); 826 Z_DEFLATED, windowBits, memLevel, strategy);
487 827
488 if (err==Z_OK) 828 if (err==Z_OK)
489 zi->ci.stream_initialised = 1; 829 zi->ci.stream_initialised = 1;
830
831 #ifndef NOCRPYT
832 zi->ci.crypt_header_size = 0;
833 if ((err==Z_OK) && (password != NULL))
834 {
835 unsigned char bufHead[RAND_HEAD_LEN];
836 unsigned int sizeHead;
837 zi->ci.encrypt = 1;
838 zi->ci.pcrc_32_tab = get_crc_table();
839 /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
840
841 sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
842 zi->ci.crypt_header_size = sizeHead;
843
844 if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
845 err = ZIP_ERRNO;
846 }
847 #endif
490 } 848 }
491 849
492 850
@@ -495,9 +853,74 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
495 return err; 853 return err;
496} 854}
497 855
856extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi,
857 extrafield_local, size_extrafield_local,
858 extrafield_global, size_extrafield_global,
859 comment, method, level, raw)
860 zipFile file;
861 const char* filename;
862 const zip_fileinfo* zipfi;
863 const void* extrafield_local;
864 uInt size_extrafield_local;
865 const void* extrafield_global;
866 uInt size_extrafield_global;
867 const char* comment;
868 int method;
869 int level;
870 int raw;
871{
872 return zipOpenNewFileInZip3 (file, filename, zipfi,
873 extrafield_local, size_extrafield_local,
874 extrafield_global, size_extrafield_global,
875 comment, method, level, raw,
876 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
877 NULL, 0);
878}
879
880extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
881 extrafield_local, size_extrafield_local,
882 extrafield_global, size_extrafield_global,
883 comment, method, level)
884 zipFile file;
885 const char* filename;
886 const zip_fileinfo* zipfi;
887 const void* extrafield_local;
888 uInt size_extrafield_local;
889 const void* extrafield_global;
890 uInt size_extrafield_global;
891 const char* comment;
892 int method;
893 int level;
894{
895 return zipOpenNewFileInZip2 (file, filename, zipfi,
896 extrafield_local, size_extrafield_local,
897 extrafield_global, size_extrafield_global,
898 comment, method, level, 0);
899}
900
901local int zipFlushWriteBuffer(zi)
902 zip_internal* zi;
903{
904 int err=ZIP_OK;
905
906 if (zi->ci.encrypt != 0)
907 {
908 uInt i;
909 int t;
910 for (i=0;i<zi->ci.pos_in_buffered_data;i++)
911 zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab,
912 zi->ci.buffered_data[i],t);
913 }
914 if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data)
915 !=zi->ci.pos_in_buffered_data)
916 err = ZIP_ERRNO;
917 zi->ci.pos_in_buffered_data = 0;
918 return err;
919}
920
498extern int ZEXPORT zipWriteInFileInZip (file, buf, len) 921extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
499 zipFile file; 922 zipFile file;
500 const voidp buf; 923 const void* buf;
501 unsigned len; 924 unsigned len;
502{ 925{
503 zip_internal* zi; 926 zip_internal* zi;
@@ -510,7 +933,7 @@ extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
510 if (zi->in_opened_file_inzip == 0) 933 if (zi->in_opened_file_inzip == 0)
511 return ZIP_PARAMERROR; 934 return ZIP_PARAMERROR;
512 935
513 zi->ci.stream.next_in = buf; 936 zi->ci.stream.next_in = (void*)buf;
514 zi->ci.stream.avail_in = len; 937 zi->ci.stream.avail_in = len;
515 zi->ci.crc32 = crc32(zi->ci.crc32,buf,len); 938 zi->ci.crc32 = crc32(zi->ci.crc32,buf,len);
516 939
@@ -518,15 +941,17 @@ extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
518 { 941 {
519 if (zi->ci.stream.avail_out == 0) 942 if (zi->ci.stream.avail_out == 0)
520 { 943 {
521 if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip) 944 if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)
522 !=1)
523 err = ZIP_ERRNO; 945 err = ZIP_ERRNO;
524 zi->ci.pos_in_buffered_data = 0;
525 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 946 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
526 zi->ci.stream.next_out = zi->ci.buffered_data; 947 zi->ci.stream.next_out = zi->ci.buffered_data;
527 } 948 }
528 949
529 if (zi->ci.method == Z_DEFLATED) 950
951 if(err != ZIP_OK)
952 break;
953
954 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
530 { 955 {
531 uLong uTotalOutBefore = zi->ci.stream.total_out; 956 uLong uTotalOutBefore = zi->ci.stream.total_out;
532 err=deflate(&zi->ci.stream, Z_NO_FLUSH); 957 err=deflate(&zi->ci.stream, Z_NO_FLUSH);
@@ -555,33 +980,34 @@ extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
555 } 980 }
556 } 981 }
557 982
558 return 0; 983 return err;
559} 984}
560 985
561extern int ZEXPORT zipCloseFileInZip (file) 986extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32)
562 zipFile file; 987 zipFile file;
988 uLong uncompressed_size;
989 uLong crc32;
563{ 990{
564 zip_internal* zi; 991 zip_internal* zi;
992 uLong compressed_size;
565 int err=ZIP_OK; 993 int err=ZIP_OK;
566 994
567 if (file == NULL) 995 if (file == NULL)
568 return ZIP_PARAMERROR; 996 return ZIP_PARAMERROR;
569 zi = (zip_internal*)file; 997 zi = (zip_internal*)file;
570 998
571 if (zi->in_opened_file_inzip == 0) 999 if (zi->in_opened_file_inzip == 0)
572 return ZIP_PARAMERROR; 1000 return ZIP_PARAMERROR;
573 zi->ci.stream.avail_in = 0; 1001 zi->ci.stream.avail_in = 0;
574 1002
575 if (zi->ci.method == Z_DEFLATED) 1003 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
576 while (err==ZIP_OK) 1004 while (err==ZIP_OK)
577 { 1005 {
578 uLong uTotalOutBefore; 1006 uLong uTotalOutBefore;
579 if (zi->ci.stream.avail_out == 0) 1007 if (zi->ci.stream.avail_out == 0)
580 { 1008 {
581 if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip) 1009 if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)
582 !=1)
583 err = ZIP_ERRNO; 1010 err = ZIP_ERRNO;
584 zi->ci.pos_in_buffered_data = 0;
585 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 1011 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
586 zi->ci.stream.next_out = zi->ci.buffered_data; 1012 zi->ci.stream.next_out = zi->ci.buffered_data;
587 } 1013 }
@@ -594,21 +1020,32 @@ extern int ZEXPORT zipCloseFileInZip (file)
594 err=ZIP_OK; /* this is normal */ 1020 err=ZIP_OK; /* this is normal */
595 1021
596 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) 1022 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
597 if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip) 1023 if (zipFlushWriteBuffer(zi)==ZIP_ERRNO)
598 !=1)
599 err = ZIP_ERRNO; 1024 err = ZIP_ERRNO;
600 1025
601 if ((zi->ci.method == Z_DEFLATED) && (err==ZIP_OK)) 1026 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
602 { 1027 {
603 err=deflateEnd(&zi->ci.stream); 1028 err=deflateEnd(&zi->ci.stream);
604 zi->ci.stream_initialised = 0; 1029 zi->ci.stream_initialised = 0;
605 } 1030 }
606 1031
607 ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)zi->ci.crc32,4); /*crc*/ 1032 if (!zi->ci.raw)
1033 {
1034 crc32 = (uLong)zi->ci.crc32;
1035 uncompressed_size = (uLong)zi->ci.stream.total_in;
1036 }
1037 compressed_size = (uLong)zi->ci.stream.total_out;
1038 #ifndef NOCRPYT
1039 compressed_size += zi->ci.crypt_header_size;
1040 #endif
1041
1042 ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
608 ziplocal_putValue_inmemory(zi->ci.central_header+20, 1043 ziplocal_putValue_inmemory(zi->ci.central_header+20,
609 (uLong)zi->ci.stream.total_out,4); /*compr size*/ 1044 compressed_size,4); /*compr size*/
1045 if (zi->ci.stream.data_type == Z_ASCII)
1046 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
610 ziplocal_putValue_inmemory(zi->ci.central_header+24, 1047 ziplocal_putValue_inmemory(zi->ci.central_header+24,
611 (uLong)zi->ci.stream.total_in,4); /*uncompr size*/ 1048 uncompressed_size,4); /*uncompr size*/
612 1049
613 if (err==ZIP_OK) 1050 if (err==ZIP_OK)
614 err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header, 1051 err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header,
@@ -617,23 +1054,23 @@ extern int ZEXPORT zipCloseFileInZip (file)
617 1054
618 if (err==ZIP_OK) 1055 if (err==ZIP_OK)
619 { 1056 {
620 long cur_pos_inzip = ftell(zi->filezip); 1057 long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);
621 if (fseek(zi->filezip, 1058 if (ZSEEK(zi->z_filefunc,zi->filestream,
622 zi->ci.pos_local_header + 14,SEEK_SET)!=0) 1059 zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
623 err = ZIP_ERRNO; 1060 err = ZIP_ERRNO;
624 1061
625 if (err==ZIP_OK) 1062 if (err==ZIP_OK)
626 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.crc32,4); /* crc 32, unknown */ 1063 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
627 1064
628 if (err==ZIP_OK) /* compressed size, unknown */ 1065 if (err==ZIP_OK) /* compressed size, unknown */
629 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_out,4); 1066 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
630 1067
631 if (err==ZIP_OK) /* uncompressed size, unknown */ 1068 if (err==ZIP_OK) /* uncompressed size, unknown */
632 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_in,4); 1069 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
633 1070
634 if (fseek(zi->filezip, 1071 if (ZSEEK(zi->z_filefunc,zi->filestream,
635 cur_pos_inzip,SEEK_SET)!=0) 1072 cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
636 err = ZIP_ERRNO; 1073 err = ZIP_ERRNO;
637 } 1074 }
638 1075
639 zi->number_entry ++; 1076 zi->number_entry ++;
@@ -642,6 +1079,12 @@ extern int ZEXPORT zipCloseFileInZip (file)
642 return err; 1079 return err;
643} 1080}
644 1081
1082extern int ZEXPORT zipCloseFileInZip (file)
1083 zipFile file;
1084{
1085 return zipCloseFileInZipRaw (file,0,0);
1086}
1087
645extern int ZEXPORT zipClose (file, global_comment) 1088extern int ZEXPORT zipClose (file, global_comment)
646 zipFile file; 1089 zipFile file;
647 const char* global_comment; 1090 const char* global_comment;
@@ -666,15 +1109,16 @@ extern int ZEXPORT zipClose (file, global_comment)
666 size_global_comment = strlen(global_comment); 1109 size_global_comment = strlen(global_comment);
667 1110
668 1111
669 centraldir_pos_inzip = ftell(zi->filezip); 1112 centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);
670 if (err==ZIP_OK) 1113 if (err==ZIP_OK)
671 { 1114 {
672 linkedlist_datablock_internal* ldi = zi->central_dir.first_block ; 1115 linkedlist_datablock_internal* ldi = zi->central_dir.first_block ;
673 while (ldi!=NULL) 1116 while (ldi!=NULL)
674 { 1117 {
675 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) 1118 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
676 if (fwrite(ldi->data,(uInt)ldi->filled_in_this_block, 1119 if (ZWRITE(zi->z_filefunc,zi->filestream,
677 1,zi->filezip) !=1 ) 1120 ldi->data,ldi->filled_in_this_block)
1121 !=ldi->filled_in_this_block )
678 err = ZIP_ERRNO; 1122 err = ZIP_ERRNO;
679 1123
680 size_centraldir += ldi->filled_in_this_block; 1124 size_centraldir += ldi->filled_in_this_block;
@@ -684,34 +1128,40 @@ extern int ZEXPORT zipClose (file, global_comment)
684 free_datablock(zi->central_dir.first_block); 1128 free_datablock(zi->central_dir.first_block);
685 1129
686 if (err==ZIP_OK) /* Magic End */ 1130 if (err==ZIP_OK) /* Magic End */
687 err = ziplocal_putValue(zi->filezip,(uLong)ENDHEADERMAGIC,4); 1131 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
688 1132
689 if (err==ZIP_OK) /* number of this disk */ 1133 if (err==ZIP_OK) /* number of this disk */
690 err = ziplocal_putValue(zi->filezip,(uLong)0,2); 1134 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
691 1135
692 if (err==ZIP_OK) /* number of the disk with the start of the central directory */ 1136 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
693 err = ziplocal_putValue(zi->filezip,(uLong)0,2); 1137 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
694 1138
695 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ 1139 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
696 err = ziplocal_putValue(zi->filezip,(uLong)zi->number_entry,2); 1140 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
697 1141
698 if (err==ZIP_OK) /* total number of entries in the central dir */ 1142 if (err==ZIP_OK) /* total number of entries in the central dir */
699 err = ziplocal_putValue(zi->filezip,(uLong)zi->number_entry,2); 1143 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
700 1144
701 if (err==ZIP_OK) /* size of the central directory */ 1145 if (err==ZIP_OK) /* size of the central directory */
702 err = ziplocal_putValue(zi->filezip,(uLong)size_centraldir,4); 1146 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
703 1147
704 if (err==ZIP_OK) /* offset of start of central directory with respect to the 1148 if (err==ZIP_OK) /* offset of start of central directory with respect to the
705 starting disk number */ 1149 starting disk number */
706 err = ziplocal_putValue(zi->filezip,(uLong)centraldir_pos_inzip ,4); 1150 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,
1151 (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
707 1152
708 if (err==ZIP_OK) /* zipfile comment length */ 1153 if (err==ZIP_OK) /* zipfile comment length */
709 err = ziplocal_putValue(zi->filezip,(uLong)size_global_comment,2); 1154 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
710 1155
711 if ((err==ZIP_OK) && (size_global_comment>0)) 1156 if ((err==ZIP_OK) && (size_global_comment>0))
712 if (fwrite(global_comment,(uInt)size_global_comment,1,zi->filezip) !=1 ) 1157 if (ZWRITE(zi->z_filefunc,zi->filestream,
1158 global_comment,size_global_comment) != size_global_comment)
713 err = ZIP_ERRNO; 1159 err = ZIP_ERRNO;
714 fclose(zi->filezip); 1160
1161 if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0)
1162 if (err == ZIP_OK)
1163 err = ZIP_ERRNO;
1164
715 TRYFREE(zi); 1165 TRYFREE(zi);
716 1166
717 return err; 1167 return err;
diff --git a/contrib/minizip/zip.def b/contrib/minizip/zip.def
deleted file mode 100644
index 5d5079f..0000000
--- a/contrib/minizip/zip.def
+++ /dev/null
@@ -1,5 +0,0 @@
1 zipOpen @80
2 zipOpenNewFileInZip @81
3 zipWriteInFileInZip @82
4 zipCloseFileInZip @83
5 zipClose @84
diff --git a/contrib/minizip/zip.h b/contrib/minizip/zip.h
index 678260b..4bc6aa4 100644
--- a/contrib/minizip/zip.h
+++ b/contrib/minizip/zip.h
@@ -1,7 +1,7 @@
1/* zip.h -- IO for compress .zip files using zlib 1/* zip.h -- IO for compress .zip files using zlib
2 Version 0.15 alpha, Mar 19th, 1998, 2 Version 0.21, March 10th, 2003
3 3
4 Copyright (C) 1998 Gilles Vollant 4 Copyright (C) 1998-2003 Gilles Vollant
5 5
6 This unzip package allow creates .ZIP file, compatible with PKZip 2.04g 6 This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
7 WinZip, InfoZip tools and compatible. 7 WinZip, InfoZip tools and compatible.
@@ -10,10 +10,9 @@
10 10
11 For uncompress .zip file, look at unzip.h 11 For uncompress .zip file, look at unzip.h
12 12
13 THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE 13
14 CAN CHANGE IN FUTURE VERSION !!
15 I WAIT FEEDBACK at mail info@winimage.com 14 I WAIT FEEDBACK at mail info@winimage.com
16 Visit also http://www.winimage.com/zLibDll/zip.htm for evolution 15 Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
17 16
18 Condition of use and distribution are the same than zlib : 17 Condition of use and distribution are the same than zlib :
19 18
@@ -36,8 +35,9 @@
36 35
37*/ 36*/
38 37
39/* for more info about .ZIP format, see 38/* for more info about .ZIP format, see
40 ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip 39 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
40 http://www.info-zip.org/pub/infozip/doc/
41 PkWare has also a specification at : 41 PkWare has also a specification at :
42 ftp://ftp.pkware.com/probdesc.zip 42 ftp://ftp.pkware.com/probdesc.zip
43*/ 43*/
@@ -53,34 +53,49 @@ extern "C" {
53#include "zlib.h" 53#include "zlib.h"
54#endif 54#endif
55 55
56#ifndef _ZLIBIOAPI_H
57#include "ioapi.h"
58#endif
59
56#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) 60#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
57/* like the STRICT of WIN32, we define a pointer that cannot be converted 61/* like the STRICT of WIN32, we define a pointer that cannot be converted
58 from (void*) without cast */ 62 from (void*) without cast */
59typedef struct TagzipFile__ { int unused; } zipFile__; 63typedef struct TagzipFile__ { int unused; } zipFile__;
60typedef zipFile__ *zipFile; 64typedef zipFile__ *zipFile;
61#else 65#else
62typedef voidp zipFile; 66typedef voidp zipFile;
63#endif 67#endif
64 68
65#define ZIP_OK (0) 69#define ZIP_OK (0)
66#define ZIP_ERRNO (Z_ERRNO) 70#define ZIP_EOF (0)
71#define ZIP_ERRNO (Z_ERRNO)
67#define ZIP_PARAMERROR (-102) 72#define ZIP_PARAMERROR (-102)
73#define ZIP_BADZIPFILE (-103)
68#define ZIP_INTERNALERROR (-104) 74#define ZIP_INTERNALERROR (-104)
69 75
76#ifndef DEF_MEM_LEVEL
77# if MAX_MEM_LEVEL >= 8
78# define DEF_MEM_LEVEL 8
79# else
80# define DEF_MEM_LEVEL MAX_MEM_LEVEL
81# endif
82#endif
83/* default memLevel */
84
70/* tm_zip contain date/time info */ 85/* tm_zip contain date/time info */
71typedef struct tm_zip_s 86typedef struct tm_zip_s
72{ 87{
73 uInt tm_sec; /* seconds after the minute - [0,59] */ 88 uInt tm_sec; /* seconds after the minute - [0,59] */
74 uInt tm_min; /* minutes after the hour - [0,59] */ 89 uInt tm_min; /* minutes after the hour - [0,59] */
75 uInt tm_hour; /* hours since midnight - [0,23] */ 90 uInt tm_hour; /* hours since midnight - [0,23] */
76 uInt tm_mday; /* day of the month - [1,31] */ 91 uInt tm_mday; /* day of the month - [1,31] */
77 uInt tm_mon; /* months since January - [0,11] */ 92 uInt tm_mon; /* months since January - [0,11] */
78 uInt tm_year; /* years - [1980..2044] */ 93 uInt tm_year; /* years - [1980..2044] */
79} tm_zip; 94} tm_zip;
80 95
81typedef struct 96typedef struct
82{ 97{
83 tm_zip tmz_date; /* date in understandable format */ 98 tm_zip tmz_date; /* date in understandable format */
84 uLong dosDate; /* if dos_date == 0, tmu_date is used */ 99 uLong dosDate; /* if dos_date == 0, tmu_date is used */
85/* uLong flag; */ /* general purpose bit flag 2 bytes */ 100/* uLong flag; */ /* general purpose bit flag 2 bytes */
86 101
@@ -88,30 +103,48 @@ typedef struct
88 uLong external_fa; /* external file attributes 4 bytes */ 103 uLong external_fa; /* external file attributes 4 bytes */
89} zip_fileinfo; 104} zip_fileinfo;
90 105
106typedef const char* zipcharpc;
107
108
109#define APPEND_STATUS_CREATE (0)
110#define APPEND_STATUS_CREATEAFTER (1)
111#define APPEND_STATUS_ADDINZIP (2)
112
91extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); 113extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
92/* 114/*
93 Create a zipfile. 115 Create a zipfile.
94 pathname contain on Windows NT a filename like "c:\\zlib\\zlib111.zip" or on 116 pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
95 an Unix computer "zlib/zlib111.zip". 117 an Unix computer "zlib/zlib113.zip".
96 if the file pathname exist and append=1, the zip will be created at the end 118 if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
97 of the file. (useful if the file contain a self extractor code) 119 will be created at the end of the file.
98 If the zipfile cannot be opened, the return value is NULL. 120 (useful if the file contain a self extractor code)
121 if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
122 add files in existing zip (be sure you don't add file that doesn't exist)
123 If the zipfile cannot be opened, the return value is NULL.
99 Else, the return value is a zipFile Handle, usable with other function 124 Else, the return value is a zipFile Handle, usable with other function
100 of this zip package. 125 of this zip package.
101 126*/
102 127
128/* Note : there is no delete function into a zipfile.
129 If you want delete file into a zipfile, you must open a zipfile, and create another
130 Of couse, you can use RAW reading and writing to copy the file you did not want delte
103*/ 131*/
104 132
133extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
134 int append,
135 zipcharpc* globalcomment,
136 zlib_filefunc_def* pzlib_filefunc_def));
137
105extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, 138extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
106 const char* filename, 139 const char* filename,
107 const zip_fileinfo* zipfi, 140 const zip_fileinfo* zipfi,
108 const void* extrafield_local, 141 const void* extrafield_local,
109 uInt size_extrafield_local, 142 uInt size_extrafield_local,
110 const void* extrafield_global, 143 const void* extrafield_global,
111 uInt size_extrafield_global, 144 uInt size_extrafield_global,
112 const char* comment, 145 const char* comment,
113 int method, 146 int method,
114 int level)); 147 int level));
115/* 148/*
116 Open a file in the ZIP for writing. 149 Open a file in the ZIP for writing.
117 filename : the filename in zip (if NULL, '-' without quote will be used 150 filename : the filename in zip (if NULL, '-' without quote will be used
@@ -125,9 +158,51 @@ extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
125 level contain the level of compression (can be Z_DEFAULT_COMPRESSION) 158 level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
126*/ 159*/
127 160
161
162extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
163 const char* filename,
164 const zip_fileinfo* zipfi,
165 const void* extrafield_local,
166 uInt size_extrafield_local,
167 const void* extrafield_global,
168 uInt size_extrafield_global,
169 const char* comment,
170 int method,
171 int level,
172 int raw));
173
174/*
175 Same than zipOpenNewFileInZip, except if raw=1, we write raw file
176 */
177
178extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
179 const char* filename,
180 const zip_fileinfo* zipfi,
181 const void* extrafield_local,
182 uInt size_extrafield_local,
183 const void* extrafield_global,
184 uInt size_extrafield_global,
185 const char* comment,
186 int method,
187 int level,
188 int raw,
189 int windowBits,
190 int memLevel,
191 int strategy,
192 const char* password,
193 uLong crcForCtypting));
194
195/*
196 Same than zipOpenNewFileInZip2, except
197 windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
198 password : crypting password (NULL for no crypting)
199 crcForCtypting : crc of file to compress (needed for crypting)
200 */
201
202
128extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, 203extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
129 const voidp buf, 204 const void* buf,
130 unsigned len)); 205 unsigned len));
131/* 206/*
132 Write data in the zipfile 207 Write data in the zipfile
133*/ 208*/
@@ -137,8 +212,18 @@ extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
137 Close the current file in the zipfile 212 Close the current file in the zipfile
138*/ 213*/
139 214
215
216extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
217 uLong uncompressed_size,
218 uLong crc32));
219/*
220 Close the current file in the zipfile, for fiel opened with
221 parameter raw=1 in zipOpenNewFileInZip2
222 uncompressed_size and crc32 are value for the uncompressed size
223*/
224
140extern int ZEXPORT zipClose OF((zipFile file, 225extern int ZEXPORT zipClose OF((zipFile file,
141 const char* global_comment)); 226 const char* global_comment));
142/* 227/*
143 Close the zipfile 228 Close the zipfile
144*/ 229*/
diff --git a/contrib/minizip/zlibvc.dsp b/contrib/minizip/zlibvc.dsp
deleted file mode 100644
index a70d4d4..0000000
--- a/contrib/minizip/zlibvc.dsp
+++ /dev/null
@@ -1,651 +0,0 @@
1# Microsoft Developer Studio Project File - Name="zlibvc" - Package Owner=<4>
2# Microsoft Developer Studio Generated Build File, Format Version 5.00
3# ** DO NOT EDIT **
4
5# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
6# TARGTYPE "Win32 (ALPHA) Dynamic-Link Library" 0x0602
7
8CFG=zlibvc - Win32 Release
9!MESSAGE This is not a valid makefile. To build this project using NMAKE,
10!MESSAGE use the Export Makefile command and run
11!MESSAGE
12!MESSAGE NMAKE /f "zlibvc.mak".
13!MESSAGE
14!MESSAGE You can specify a configuration when running NMAKE
15!MESSAGE by defining the macro CFG on the command line. For example:
16!MESSAGE
17!MESSAGE NMAKE /f "zlibvc.mak" CFG="zlibvc - Win32 Release"
18!MESSAGE
19!MESSAGE Possible choices for configuration are:
20!MESSAGE
21!MESSAGE "zlibvc - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
22!MESSAGE "zlibvc - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
23!MESSAGE "zlibvc - Win32 ReleaseAxp" (based on\
24 "Win32 (ALPHA) Dynamic-Link Library")
25!MESSAGE "zlibvc - Win32 ReleaseWithoutAsm" (based on\
26 "Win32 (x86) Dynamic-Link Library")
27!MESSAGE "zlibvc - Win32 ReleaseWithoutCrtdll" (based on\
28 "Win32 (x86) Dynamic-Link Library")
29!MESSAGE
30
31# Begin Project
32# PROP Scc_ProjName ""
33# PROP Scc_LocalPath ""
34
35!IF "$(CFG)" == "zlibvc - Win32 Release"
36
37# PROP BASE Use_MFC 0
38# PROP BASE Use_Debug_Libraries 0
39# PROP BASE Output_Dir ".\Release"
40# PROP BASE Intermediate_Dir ".\Release"
41# PROP BASE Target_Dir ""
42# PROP Use_MFC 0
43# PROP Use_Debug_Libraries 0
44# PROP Output_Dir ".\Release"
45# PROP Intermediate_Dir ".\Release"
46# PROP Ignore_Export_Lib 0
47# PROP Target_Dir ""
48CPP=cl.exe
49# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
50# ADD CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /D "ASMV" /FAcs /FR /FD /c
51# SUBTRACT CPP /YX
52MTL=midl.exe
53# ADD BASE MTL /nologo /D "NDEBUG" /win32
54# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
55RSC=rc.exe
56# ADD BASE RSC /l 0x40c /d "NDEBUG"
57# ADD RSC /l 0x40c /d "NDEBUG"
58BSC32=bscmake.exe
59# ADD BASE BSC32 /nologo
60# ADD BSC32 /nologo
61LINK32=link.exe
62# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
63# ADD LINK32 gvmat32.obj kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib crtdll.lib /nologo /subsystem:windows /dll /map /machine:I386 /nodefaultlib /out:".\Release\zlib.dll"
64# SUBTRACT LINK32 /pdb:none
65
66!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
67
68# PROP BASE Use_MFC 0
69# PROP BASE Use_Debug_Libraries 1
70# PROP BASE Output_Dir ".\Debug"
71# PROP BASE Intermediate_Dir ".\Debug"
72# PROP BASE Target_Dir ""
73# PROP Use_MFC 0
74# PROP Use_Debug_Libraries 1
75# PROP Output_Dir ".\Debug"
76# PROP Intermediate_Dir ".\Debug"
77# PROP Target_Dir ""
78CPP=cl.exe
79# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
80# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /FD /c
81# SUBTRACT CPP /YX
82MTL=midl.exe
83# ADD BASE MTL /nologo /D "_DEBUG" /win32
84# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
85RSC=rc.exe
86# ADD BASE RSC /l 0x40c /d "_DEBUG"
87# ADD RSC /l 0x40c /d "_DEBUG"
88BSC32=bscmake.exe
89# ADD BASE BSC32 /nologo
90# ADD BSC32 /nologo
91LINK32=link.exe
92# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386
93# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:".\Debug\zlib.dll"
94
95!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
96
97# PROP BASE Use_MFC 0
98# PROP BASE Use_Debug_Libraries 0
99# PROP BASE Output_Dir "zlibvc__"
100# PROP BASE Intermediate_Dir "zlibvc__"
101# PROP BASE Ignore_Export_Lib 0
102# PROP BASE Target_Dir ""
103# PROP Use_MFC 0
104# PROP Use_Debug_Libraries 0
105# PROP Output_Dir "zlibvc__"
106# PROP Intermediate_Dir "zlibvc__"
107# PROP Ignore_Export_Lib 0
108# PROP Target_Dir ""
109MTL=midl.exe
110# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
111# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
112CPP=cl.exe
113# ADD BASE CPP /nologo /MT /Gt0 /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /FAcs /FR /YX /FD /c
114# ADD CPP /nologo /MT /Gt0 /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /FAcs /FR /FD /c
115# SUBTRACT CPP /YX
116RSC=rc.exe
117# ADD BASE RSC /l 0x40c /d "NDEBUG"
118# ADD RSC /l 0x40c /d "NDEBUG"
119BSC32=bscmake.exe
120# ADD BASE BSC32 /nologo
121# ADD BSC32 /nologo
122LINK32=link.exe
123# ADD BASE LINK32 crtdll.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /map /machine:ALPHA /nodefaultlib /out:".\Release\zlib.dll"
124# SUBTRACT BASE LINK32 /pdb:none
125# ADD LINK32 crtdll.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /map /machine:ALPHA /nodefaultlib /out:"zlibvc__\zlib.dll"
126# SUBTRACT LINK32 /pdb:none
127
128!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
129
130# PROP BASE Use_MFC 0
131# PROP BASE Use_Debug_Libraries 0
132# PROP BASE Output_Dir "zlibvc_0"
133# PROP BASE Intermediate_Dir "zlibvc_0"
134# PROP BASE Ignore_Export_Lib 0
135# PROP BASE Target_Dir ""
136# PROP Use_MFC 0
137# PROP Use_Debug_Libraries 0
138# PROP Output_Dir "zlibvc_0"
139# PROP Intermediate_Dir "zlibvc_0"
140# PROP Ignore_Export_Lib 0
141# PROP Target_Dir ""
142CPP=cl.exe
143# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /FAcs /FR /YX /FD /c
144# ADD CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /FAcs /FR /FD /c
145# SUBTRACT CPP /YX
146MTL=midl.exe
147# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
148# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
149RSC=rc.exe
150# ADD BASE RSC /l 0x40c /d "NDEBUG"
151# ADD RSC /l 0x40c /d "NDEBUG"
152BSC32=bscmake.exe
153# ADD BASE BSC32 /nologo
154# ADD BSC32 /nologo
155LINK32=link.exe
156# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib crtdll.lib /nologo /subsystem:windows /dll /map /machine:I386 /nodefaultlib /out:".\Release\zlib.dll"
157# SUBTRACT BASE LINK32 /pdb:none
158# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib crtdll.lib /nologo /subsystem:windows /dll /map /machine:I386 /nodefaultlib /out:".\zlibvc_0\zlib.dll"
159# SUBTRACT LINK32 /pdb:none
160
161!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
162
163# PROP BASE Use_MFC 0
164# PROP BASE Use_Debug_Libraries 0
165# PROP BASE Output_Dir "zlibvc_1"
166# PROP BASE Intermediate_Dir "zlibvc_1"
167# PROP BASE Ignore_Export_Lib 0
168# PROP BASE Target_Dir ""
169# PROP Use_MFC 0
170# PROP Use_Debug_Libraries 0
171# PROP Output_Dir "zlibvc_1"
172# PROP Intermediate_Dir "zlibvc_1"
173# PROP Ignore_Export_Lib 0
174# PROP Target_Dir ""
175CPP=cl.exe
176# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /D "ASMV" /FAcs /FR /YX /FD /c
177# ADD CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_WIN32" /D "BUILD_ZLIBDLL" /D "ZLIB_DLL" /D "DYNAMIC_CRC_TABLE" /D "ASMV" /FAcs /FR /FD /c
178# SUBTRACT CPP /YX
179MTL=midl.exe
180# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
181# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
182RSC=rc.exe
183# ADD BASE RSC /l 0x40c /d "NDEBUG"
184# ADD RSC /l 0x40c /d "NDEBUG"
185BSC32=bscmake.exe
186# ADD BASE BSC32 /nologo
187# ADD BSC32 /nologo
188LINK32=link.exe
189# ADD BASE LINK32 gvmat32.obj kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib crtdll.lib /nologo /subsystem:windows /dll /map /machine:I386 /nodefaultlib /out:".\Release\zlib.dll"
190# SUBTRACT BASE LINK32 /pdb:none
191# ADD LINK32 gvmat32.obj kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib crtdll.lib /nologo /subsystem:windows /dll /map /machine:I386 /nodefaultlib /out:".\zlibvc_1\zlib.dll"
192# SUBTRACT LINK32 /pdb:none
193
194!ENDIF
195
196# Begin Target
197
198# Name "zlibvc - Win32 Release"
199# Name "zlibvc - Win32 Debug"
200# Name "zlibvc - Win32 ReleaseAxp"
201# Name "zlibvc - Win32 ReleaseWithoutAsm"
202# Name "zlibvc - Win32 ReleaseWithoutCrtdll"
203# Begin Group "Source Files"
204
205# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90"
206# Begin Source File
207
208SOURCE=.\adler32.c
209
210!IF "$(CFG)" == "zlibvc - Win32 Release"
211
212!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
213
214!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
215
216DEP_CPP_ADLER=\
217 ".\zconf.h"\
218 ".\zlib.h"\
219
220
221!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
222
223!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
224
225!ENDIF
226
227# End Source File
228# Begin Source File
229
230SOURCE=.\compress.c
231
232!IF "$(CFG)" == "zlibvc - Win32 Release"
233
234!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
235
236!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
237
238DEP_CPP_COMPR=\
239 ".\zconf.h"\
240 ".\zlib.h"\
241
242
243!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
244
245!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
246
247!ENDIF
248
249# End Source File
250# Begin Source File
251
252SOURCE=.\crc32.c
253
254!IF "$(CFG)" == "zlibvc - Win32 Release"
255
256!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
257
258!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
259
260DEP_CPP_CRC32=\
261 ".\zconf.h"\
262 ".\zlib.h"\
263
264
265!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
266
267!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
268
269!ENDIF
270
271# End Source File
272# Begin Source File
273
274SOURCE=.\deflate.c
275
276!IF "$(CFG)" == "zlibvc - Win32 Release"
277
278!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
279
280!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
281
282DEP_CPP_DEFLA=\
283 ".\deflate.h"\
284 ".\zconf.h"\
285 ".\zlib.h"\
286 ".\zutil.h"\
287
288
289!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
290
291!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
292
293!ENDIF
294
295# End Source File
296# Begin Source File
297
298SOURCE=.\gvmat32c.c
299
300!IF "$(CFG)" == "zlibvc - Win32 Release"
301
302!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
303
304!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
305
306!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
307
308!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
309
310!ENDIF
311
312# End Source File
313# Begin Source File
314
315SOURCE=.\gzio.c
316
317!IF "$(CFG)" == "zlibvc - Win32 Release"
318
319!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
320
321!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
322
323DEP_CPP_GZIO_=\
324 ".\zconf.h"\
325 ".\zlib.h"\
326 ".\zutil.h"\
327
328
329!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
330
331!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
332
333!ENDIF
334
335# End Source File
336# Begin Source File
337
338SOURCE=.\infblock.c
339
340!IF "$(CFG)" == "zlibvc - Win32 Release"
341
342!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
343
344!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
345
346DEP_CPP_INFBL=\
347 ".\infblock.h"\
348 ".\infcodes.h"\
349 ".\inftrees.h"\
350 ".\infutil.h"\
351 ".\zconf.h"\
352 ".\zlib.h"\
353 ".\zutil.h"\
354
355
356!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
357
358!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
359
360!ENDIF
361
362# End Source File
363# Begin Source File
364
365SOURCE=.\infcodes.c
366
367!IF "$(CFG)" == "zlibvc - Win32 Release"
368
369!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
370
371!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
372
373DEP_CPP_INFCO=\
374 ".\infblock.h"\
375 ".\infcodes.h"\
376 ".\inffast.h"\
377 ".\inftrees.h"\
378 ".\infutil.h"\
379 ".\zconf.h"\
380 ".\zlib.h"\
381 ".\zutil.h"\
382
383
384!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
385
386!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
387
388!ENDIF
389
390# End Source File
391# Begin Source File
392
393SOURCE=.\inffast.c
394
395!IF "$(CFG)" == "zlibvc - Win32 Release"
396
397!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
398
399!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
400
401DEP_CPP_INFFA=\
402 ".\infblock.h"\
403 ".\infcodes.h"\
404 ".\inffast.h"\
405 ".\inftrees.h"\
406 ".\infutil.h"\
407 ".\zconf.h"\
408 ".\zlib.h"\
409 ".\zutil.h"\
410
411
412!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
413
414!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
415
416!ENDIF
417
418# End Source File
419# Begin Source File
420
421SOURCE=.\inflate.c
422
423!IF "$(CFG)" == "zlibvc - Win32 Release"
424
425!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
426
427!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
428
429DEP_CPP_INFLA=\
430 ".\infblock.h"\
431 ".\zconf.h"\
432 ".\zlib.h"\
433 ".\zutil.h"\
434
435
436!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
437
438!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
439
440!ENDIF
441
442# End Source File
443# Begin Source File
444
445SOURCE=.\inftrees.c
446
447!IF "$(CFG)" == "zlibvc - Win32 Release"
448
449!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
450
451!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
452
453DEP_CPP_INFTR=\
454 ".\inftrees.h"\
455 ".\zconf.h"\
456 ".\zlib.h"\
457 ".\zutil.h"\
458
459
460!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
461
462!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
463
464!ENDIF
465
466# End Source File
467# Begin Source File
468
469SOURCE=.\infutil.c
470
471!IF "$(CFG)" == "zlibvc - Win32 Release"
472
473!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
474
475!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
476
477DEP_CPP_INFUT=\
478 ".\infblock.h"\
479 ".\infcodes.h"\
480 ".\inftrees.h"\
481 ".\infutil.h"\
482 ".\zconf.h"\
483 ".\zlib.h"\
484 ".\zutil.h"\
485
486
487!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
488
489!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
490
491!ENDIF
492
493# End Source File
494# Begin Source File
495
496SOURCE=.\trees.c
497
498!IF "$(CFG)" == "zlibvc - Win32 Release"
499
500!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
501
502!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
503
504DEP_CPP_TREES=\
505 ".\deflate.h"\
506 ".\zconf.h"\
507 ".\zlib.h"\
508 ".\zutil.h"\
509
510
511!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
512
513!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
514
515!ENDIF
516
517# End Source File
518# Begin Source File
519
520SOURCE=.\uncompr.c
521
522!IF "$(CFG)" == "zlibvc - Win32 Release"
523
524!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
525
526!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
527
528DEP_CPP_UNCOM=\
529 ".\zconf.h"\
530 ".\zlib.h"\
531
532
533!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
534
535!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
536
537!ENDIF
538
539# End Source File
540# Begin Source File
541
542SOURCE=.\unzip.c
543
544!IF "$(CFG)" == "zlibvc - Win32 Release"
545
546!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
547
548!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
549
550!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
551
552!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
553
554!ENDIF
555
556# End Source File
557# Begin Source File
558
559SOURCE=.\zip.c
560
561!IF "$(CFG)" == "zlibvc - Win32 Release"
562
563!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
564
565!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
566
567!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
568
569!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
570
571!ENDIF
572
573# End Source File
574# Begin Source File
575
576SOURCE=.\zlib.rc
577# End Source File
578# Begin Source File
579
580SOURCE=.\zlibvc.def
581# End Source File
582# Begin Source File
583
584SOURCE=.\zutil.c
585
586!IF "$(CFG)" == "zlibvc - Win32 Release"
587
588!ELSEIF "$(CFG)" == "zlibvc - Win32 Debug"
589
590!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseAxp"
591
592DEP_CPP_ZUTIL=\
593 ".\zconf.h"\
594 ".\zlib.h"\
595 ".\zutil.h"\
596
597
598!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutAsm"
599
600!ELSEIF "$(CFG)" == "zlibvc - Win32 ReleaseWithoutCrtdll"
601
602!ENDIF
603
604# End Source File
605# End Group
606# Begin Group "Header Files"
607
608# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
609# Begin Source File
610
611SOURCE=.\deflate.h
612# End Source File
613# Begin Source File
614
615SOURCE=.\infblock.h
616# End Source File
617# Begin Source File
618
619SOURCE=.\infcodes.h
620# End Source File
621# Begin Source File
622
623SOURCE=.\inffast.h
624# End Source File
625# Begin Source File
626
627SOURCE=.\inftrees.h
628# End Source File
629# Begin Source File
630
631SOURCE=.\infutil.h
632# End Source File
633# Begin Source File
634
635SOURCE=.\zconf.h
636# End Source File
637# Begin Source File
638
639SOURCE=.\zlib.h
640# End Source File
641# Begin Source File
642
643SOURCE=.\zutil.h
644# End Source File
645# End Group
646# Begin Group "Resource Files"
647
648# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
649# End Group
650# End Target
651# End Project
diff --git a/contrib/minizip/zlibvc.dsw b/contrib/minizip/zlibvc.dsw
deleted file mode 100644
index 493cd87..0000000
--- a/contrib/minizip/zlibvc.dsw
+++ /dev/null
@@ -1,41 +0,0 @@
1Microsoft Developer Studio Workspace File, Format Version 5.00
2# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
3
4###############################################################################
5
6Project: "zlibstat"=.\zlibstat.dsp - Package Owner=<4>
7
8Package=<5>
9{{{
10}}}
11
12Package=<4>
13{{{
14}}}
15
16###############################################################################
17
18Project: "zlibvc"=.\zlibvc.dsp - Package Owner=<4>
19
20Package=<5>
21{{{
22}}}
23
24Package=<4>
25{{{
26}}}
27
28###############################################################################
29
30Global:
31
32Package=<5>
33{{{
34}}}
35
36Package=<3>
37{{{
38}}}
39
40###############################################################################
41
diff --git a/contrib/testzlib/testzlib.c b/contrib/testzlib/testzlib.c
new file mode 100644
index 0000000..caae4ef
--- /dev/null
+++ b/contrib/testzlib/testzlib.c
@@ -0,0 +1,149 @@
1
2#include <stdio.h>
3#include <stdlib.h>
4#include <windows.h>
5#include "zlib.h"
6
7int ReadFileMemory(const char* filename,long* plFileSize,void** pFilePtr)
8{
9 FILE* stream;
10 void* ptr;
11 int retVal=1;
12 stream=fopen(filename, "rb");
13 if (stream==NULL)
14 return 0;
15
16 fseek(stream,0,SEEK_END);
17
18 *plFileSize=ftell(stream);
19 fseek(stream,0,SEEK_SET);
20 ptr=malloc((*plFileSize)+1);
21 if (ptr==NULL)
22 retVal=0;
23 else
24 {
25 if (fread(ptr, 1, *plFileSize,stream) != (*plFileSize))
26 retVal=0;
27 }
28 fclose(stream);
29 *pFilePtr=ptr;
30 return retVal;
31}
32
33int main(int argc, char *argv[])
34{
35 int BlockSizeCompress=0x8000;
36 int BlockSizeUncompress=0x8000;
37 int cprLevel=Z_DEFAULT_COMPRESSION ;
38 long lFileSize;
39 unsigned char* FilePtr;
40 long lBufferSizeCpr;
41 long lBufferSizeUncpr;
42 long lCompressedSize=0;
43 unsigned char* CprPtr;
44 unsigned char* UncprPtr;
45 long lSizeCpr,lSizeUncpr;
46 DWORD dwGetTick;
47
48 if (argc<=1)
49 {
50 printf("run TestZlib <File> [BlockSizeCompress] [BlockSizeUncompress] [compres. level]\n");
51 return 0;
52 }
53
54 if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0)
55 {
56 printf("error reading %s\n",argv[1]);
57 return 1;
58 }
59 else printf("file %s read, %u bytes\n",argv[1],lFileSize);
60
61 if (argc>=3)
62 BlockSizeCompress=atol(argv[2]);
63
64 if (argc>=4)
65 BlockSizeUncompress=atol(argv[3]);
66
67 if (argc>=5)
68 cprLevel=(int)atol(argv[4]);
69
70 lBufferSizeCpr = lFileSize + (lFileSize/0x10) + 0x200;
71 lBufferSizeUncpr = lBufferSizeCpr;
72
73 CprPtr=(unsigned char*)malloc(lBufferSizeCpr + BlockSizeCompress);
74 UncprPtr=(unsigned char*)malloc(lBufferSizeUncpr + BlockSizeUncompress);
75
76 dwGetTick=GetTickCount();
77 {
78 z_stream zcpr;
79 int ret=Z_OK;
80 long lOrigToDo = lFileSize;
81 long lOrigDone = 0;
82 int step=0;
83 memset(&zcpr,0,sizeof(z_stream));
84 deflateInit(&zcpr,cprLevel);
85
86 zcpr.next_in = FilePtr;
87 zcpr.next_out = CprPtr;
88
89
90 do
91 {
92 long all_read_before = zcpr.total_in;
93 zcpr.avail_in = min(lOrigToDo,BlockSizeCompress);
94 zcpr.avail_out = BlockSizeCompress;
95 ret=deflate(&zcpr,(zcpr.avail_in==lOrigToDo) ? Z_FINISH : Z_SYNC_FLUSH);
96 lOrigDone += (zcpr.total_in-all_read_before);
97 lOrigToDo -= (zcpr.total_in-all_read_before);
98 step++;
99 } while (ret==Z_OK);
100
101 lSizeCpr=zcpr.total_out;
102 deflateEnd(&zcpr);
103 dwGetTick=GetTickCount()-dwGetTick;
104 printf("total compress size = %u, in %u step\n",lSizeCpr,step);
105 printf("time = %u msec = %f sec\n\n",dwGetTick,dwGetTick/(double)1000.);
106 }
107
108 dwGetTick=GetTickCount();
109 {
110 z_stream zcpr;
111 int ret=Z_OK;
112 long lOrigToDo = lSizeCpr;
113 long lOrigDone = 0;
114 int step=0;
115 memset(&zcpr,0,sizeof(z_stream));
116 inflateInit(&zcpr);
117
118 zcpr.next_in = CprPtr;
119 zcpr.next_out = UncprPtr;
120
121
122 do
123 {
124 long all_read_before = zcpr.total_in;
125 zcpr.avail_in = min(lOrigToDo,BlockSizeUncompress);
126 zcpr.avail_out = BlockSizeUncompress;
127 ret=inflate(&zcpr,Z_SYNC_FLUSH);
128 lOrigDone += (zcpr.total_in-all_read_before);
129 lOrigToDo -= (zcpr.total_in-all_read_before);
130 step++;
131 } while (ret==Z_OK);
132
133 lSizeUncpr=zcpr.total_out;
134 inflateEnd(&zcpr);
135 dwGetTick=GetTickCount()-dwGetTick;
136 printf("total uncompress size = %u, in %u step\n",lSizeUncpr,step);
137 printf("time = %u msec = %f sec\n\n",dwGetTick,dwGetTick/(double)1000.);
138 }
139
140 if (lSizeUncpr==lFileSize)
141 {
142 if (memcmp(FilePtr,UncprPtr,lFileSize)==0)
143 printf("compare ok\n");
144
145 }
146
147 return 0;
148
149}
diff --git a/contrib/testzlib/testzlib.sln b/contrib/testzlib/testzlib.sln
new file mode 100644
index 0000000..86da716
--- /dev/null
+++ b/contrib/testzlib/testzlib.sln
@@ -0,0 +1,21 @@
1Microsoft Visual Studio Solution File, Format Version 7.00
2Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}"
3EndProject
4Global
5 GlobalSection(SolutionConfiguration) = preSolution
6 ConfigName.0 = Debug
7 ConfigName.1 = Release
8 EndGlobalSection
9 GlobalSection(ProjectDependencies) = postSolution
10 EndGlobalSection
11 GlobalSection(ProjectConfiguration) = postSolution
12 {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug.ActiveCfg = Debug|Win32
13 {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug.Build.0 = Debug|Win32
14 {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release.ActiveCfg = Release|Win32
15 {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release.Build.0 = Release|Win32
16 EndGlobalSection
17 GlobalSection(ExtensibilityGlobals) = postSolution
18 EndGlobalSection
19 GlobalSection(ExtensibilityAddIns) = postSolution
20 EndGlobalSection
21EndGlobal
diff --git a/contrib/testzlib/testzlib.vcproj b/contrib/testzlib/testzlib.vcproj
new file mode 100644
index 0000000..8e4233a
--- /dev/null
+++ b/contrib/testzlib/testzlib.vcproj
@@ -0,0 +1,124 @@
1<?xml version="1.0" encoding = "Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="7.00"
5 Name="testzlib"
6 ProjectGUID="{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}"
7 Keyword="Win32Proj">
8 <Platforms>
9 <Platform
10 Name="Win32"/>
11 </Platforms>
12 <Configurations>
13 <Configuration
14 Name="Debug|Win32"
15 OutputDirectory="Debug"
16 IntermediateDirectory="Debug"
17 ConfigurationType="1"
18 CharacterSet="2">
19 <Tool
20 Name="VCCLCompilerTool"
21 Optimization="0"
22 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
23 MinimalRebuild="TRUE"
24 BasicRuntimeChecks="3"
25 RuntimeLibrary="5"
26 UsePrecompiledHeader="0"
27 WarningLevel="3"
28 Detect64BitPortabilityProblems="TRUE"
29 DebugInformationFormat="4"/>
30 <Tool
31 Name="VCCustomBuildTool"/>
32 <Tool
33 Name="VCLinkerTool"
34 OutputFile="$(OutDir)/testzlib.exe"
35 LinkIncremental="2"
36 GenerateDebugInformation="TRUE"
37 ProgramDatabaseFile="$(OutDir)/testzlib.pdb"
38 SubSystem="1"
39 TargetMachine="1"/>
40 <Tool
41 Name="VCMIDLTool"/>
42 <Tool
43 Name="VCPostBuildEventTool"/>
44 <Tool
45 Name="VCPreBuildEventTool"/>
46 <Tool
47 Name="VCPreLinkEventTool"/>
48 <Tool
49 Name="VCResourceCompilerTool"/>
50 <Tool
51 Name="VCWebServiceProxyGeneratorTool"/>
52 <Tool
53 Name="VCWebDeploymentTool"/>
54 </Configuration>
55 <Configuration
56 Name="Release|Win32"
57 OutputDirectory="Release"
58 IntermediateDirectory="Release"
59 ConfigurationType="1"
60 CharacterSet="2">
61 <Tool
62 Name="VCCLCompilerTool"
63 Optimization="2"
64 InlineFunctionExpansion="1"
65 OmitFramePointers="TRUE"
66 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
67 StringPooling="TRUE"
68 RuntimeLibrary="4"
69 EnableFunctionLevelLinking="TRUE"
70 UsePrecompiledHeader="0"
71 WarningLevel="3"
72 Detect64BitPortabilityProblems="TRUE"
73 DebugInformationFormat="3"/>
74 <Tool
75 Name="VCCustomBuildTool"/>
76 <Tool
77 Name="VCLinkerTool"
78 OutputFile="$(OutDir)/testzlib.exe"
79 LinkIncremental="1"
80 GenerateDebugInformation="TRUE"
81 SubSystem="1"
82 OptimizeReferences="2"
83 EnableCOMDATFolding="2"
84 OptimizeForWindows98="1"
85 TargetMachine="1"/>
86 <Tool
87 Name="VCMIDLTool"/>
88 <Tool
89 Name="VCPostBuildEventTool"/>
90 <Tool
91 Name="VCPreBuildEventTool"/>
92 <Tool
93 Name="VCPreLinkEventTool"/>
94 <Tool
95 Name="VCResourceCompilerTool"/>
96 <Tool
97 Name="VCWebServiceProxyGeneratorTool"/>
98 <Tool
99 Name="VCWebDeploymentTool"/>
100 </Configuration>
101 </Configurations>
102 <Files>
103 <Filter
104 Name="Source Files"
105 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
106 <File
107 RelativePath="testzlib.c">
108 </File>
109 </Filter>
110 <Filter
111 Name="Header Files"
112 Filter="h;hpp;hxx;hm;inl;inc">
113 </Filter>
114 <Filter
115 Name="Resource Files"
116 Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
117 </Filter>
118 <File
119 RelativePath="zlib.lib">
120 </File>
121 </Files>
122 <Globals>
123 </Globals>
124</VisualStudioProject>
diff --git a/contrib/vstudio/readme.txt b/contrib/vstudio/readme.txt
new file mode 100644
index 0000000..a619b96
--- /dev/null
+++ b/contrib/vstudio/readme.txt
@@ -0,0 +1,17 @@
1For create the 16 and 32 bits DLL of Zlib 1.20
2
3For the 16 bits :
4unzip zlib120.zip and copy file from contrib\vstudio\vc15_16 and from contrib\minizip in the same directory
5open zlib16.mak with Microsoft Visual C++ 1.52
6
7
8For the 32 bits :
9unzip zlib120.zip and copy file from contrib\vstudio\vc70_32 and from contrib\minizip in the same directory
10You can also need unzip http://www.winimage.com/zLibDll/crtdll.zip
11
12If you are using x86, use target Release
13open zlibvc.sln with Microsoft Visual C++ 7.0 (Visual Studio .net)
14
15
16Note : You don't need recompile yourself. There is compiled .LIB in
17 http://www.winimage.com/zLibDll
diff --git a/contrib/vstudio/vc15_16/zlib16.def b/contrib/vstudio/vc15_16/zlib16.def
new file mode 100644
index 0000000..89cb8d1
--- /dev/null
+++ b/contrib/vstudio/vc15_16/zlib16.def
@@ -0,0 +1,94 @@
1LIBRARY "zlib"
2
3DESCRIPTION '"""zlib data compression library"""'
4
5EXETYPE WINDOWS
6
7VERSION 1.20
8
9CODE PRELOAD MOVEABLE DISCARDABLE
10DATA PRELOAD MOVEABLE SINGLE
11
12
13HEAPSIZE 32768,8192
14
15EXPORTS
16 adler32 @1
17 compress @2
18 crc32 @3
19 deflate @4
20 deflateCopy @5
21 deflateEnd @6
22 deflateInit2_ @7
23 deflateInit_ @8
24 deflateParams @9
25 deflateReset @10
26 deflateSetDictionary @11
27 gzclose @12
28 gzdopen @13
29 gzerror @14
30 gzflush @15
31 gzopen @16
32 gzread @17
33 gzwrite @18
34 inflate @19
35 inflateEnd @20
36 inflateInit2_ @21
37 inflateInit_ @22
38 inflateReset @23
39 inflateSetDictionary @24
40 inflateSync @25
41 uncompress @26
42 zlibVersion @27
43 _gzprintf @28
44 gzputc @29
45 gzgetc @30
46 gzseek @31
47 gzrewind @32
48 gztell @33
49 gzeof @34
50 gzsetparams @35
51 zError @36
52 inflateSyncPoint @37
53 get_crc_table @38
54 compress2 @39
55 gzputs @40
56 gzgets @41
57 inflateCopy @42
58 inflateBackInit_ @43
59 inflateBack @44
60 inflateBackEnd @45
61 compressBound @46
62
63 unzOpen @61
64 unzClose @62
65 unzGetGlobalInfo @63
66 unzGetCurrentFileInfo @64
67 unzGoToFirstFile @65
68 unzGoToNextFile @66
69 unzOpenCurrentFile @67
70 unzReadCurrentFile @68
71 unzOpenCurrentFile3 @69
72 unztell @70
73 unzeof @71
74 unzCloseCurrentFile @72
75 unzGetGlobalComment @73
76 unzStringFileNameCompare @74
77 unzLocateFile @75
78 unzGetLocalExtrafield @76
79 unzOpen2 @77
80 unzOpenCurrentFile2 @78
81 unzOpenCurrentFilePassword @79
82
83 zipOpen @80
84 zipOpenNewFileInZip @81
85 zipWriteInFileInZip @82
86 zipCloseFileInZip @83
87 zipClose @84
88 zipOpenNewFileInZip2 @86
89 zipCloseFileInZipRaw @87
90 zipOpen2 @88
91 zipOpenNewFileInZip3 @89
92
93 unzGetFilePos @100
94 unzGoToFilePos @101
diff --git a/contrib/vstudio/vc15_16/zlib16.mak b/contrib/vstudio/vc15_16/zlib16.mak
new file mode 100644
index 0000000..75c8d80
--- /dev/null
+++ b/contrib/vstudio/vc15_16/zlib16.mak
@@ -0,0 +1,256 @@
1# Microsoft Visual C++ generated build script - Do not modify
2
3PROJ = ZLIB16
4DEBUG = 0
5PROGTYPE = 1
6CALLER =
7ARGS =
8DLLS =
9D_RCDEFINES = -d_DEBUG
10R_RCDEFINES = -dNDEBUG
11ORIGIN = MSVC
12ORIGIN_VER = 1.00
13PROJPATH = c:\zlib\
14USEMFC = 0
15CC = cl
16CPP = cl
17CXX = cl
18CCREATEPCHFLAG =
19CPPCREATEPCHFLAG =
20CUSEPCHFLAG =
21CPPUSEPCHFLAG =
22FIRSTC = ADLER32.C
23FIRSTCPP =
24RC = rc
25CFLAGS_D_WDLL = /nologo /G2 /W3 /Zi /ALw /Od /D "_DEBUG" /D "WINDOWS" /D "ZLIB_DLL" /FR /GD /Fd"ZLIB.PDB"
26CFLAGS_R_WDLL = /nologo /W3 /ALw /O1 /D "NDEBUG" /D "WINDOWS" /D "ZLIB_DLL" /FR /GD
27LFLAGS_D_WDLL = /NOLOGO /ONERROR:NOEXE /NOD /PACKC:61440 /CO /NOE /ALIGN:16 /MAP:FULL
28LFLAGS_R_WDLL = /NOLOGO /ONERROR:NOEXE /NOD /PACKC:61440 /NOE /ALIGN:16 /MAP:FULL
29LIBS_D_WDLL = oldnames libw commdlg shell olecli olesvr ldllcew
30LIBS_R_WDLL = oldnames libw commdlg shell olecli olesvr ldllcew
31RCFLAGS = /nologo
32RESFLAGS = /nologo
33RUNFLAGS =
34DEFFILE = ZLIB16.DEF
35OBJS_EXT =
36LIBS_EXT =
37!if "$(DEBUG)" == "1"
38CFLAGS = $(CFLAGS_D_WDLL)
39LFLAGS = $(LFLAGS_D_WDLL)
40LIBS = $(LIBS_D_WDLL)
41MAPFILE = nul
42RCDEFINES = $(D_RCDEFINES)
43!else
44CFLAGS = $(CFLAGS_R_WDLL)
45LFLAGS = $(LFLAGS_R_WDLL)
46LIBS = $(LIBS_R_WDLL)
47MAPFILE = nul
48RCDEFINES = $(R_RCDEFINES)
49!endif
50!if [if exist MSVC.BND del MSVC.BND]
51!endif
52SBRS = ADLER32.SBR \
53 COMPRESS.SBR \
54 CRC32.SBR \
55 DEFLATE.SBR \
56 GZIO.SBR \
57 INFFAST.SBR \
58 INFLATE.SBR \
59 TREES.SBR \
60 UNCOMPR.SBR \
61 ZUTIL.SBR \
62 ZIP.SBR \
63 UNZIP.SBR \
64 INFBACK.SBR \
65 IOAPI.SBR \
66 INFTREES.SBR
67
68
69ADLER32_DEP = c:\zlib\zlib.h \
70 c:\zlib\zconf.h
71
72
73COMPRESS_DEP = c:\zlib\zlib.h \
74 c:\zlib\zconf.h
75
76
77CRC32_DEP = c:\zlib\zlib.h \
78 c:\zlib\zconf.h \
79 c:\zlib\crc32.h
80
81
82DEFLATE_DEP = c:\zlib\deflate.h \
83 c:\zlib\zutil.h \
84 c:\zlib\zlib.h \
85 c:\zlib\zconf.h
86
87
88GZIO_DEP = c:\zlib\zutil.h \
89 c:\zlib\zlib.h \
90 c:\zlib\zconf.h
91
92
93INFFAST_DEP = c:\zlib\zutil.h \
94 c:\zlib\zlib.h \
95 c:\zlib\zconf.h \
96 c:\zlib\inftrees.h \
97 c:\zlib\inflate.h \
98 c:\zlib\inffast.h
99
100
101INFLATE_DEP = c:\zlib\zutil.h \
102 c:\zlib\zlib.h \
103 c:\zlib\zconf.h \
104 c:\zlib\inftrees.h \
105 c:\zlib\inflate.h \
106 c:\zlib\inffast.h \
107 c:\zlib\inffixed.h
108
109
110TREES_DEP = c:\zlib\deflate.h \
111 c:\zlib\zutil.h \
112 c:\zlib\zlib.h \
113 c:\zlib\zconf.h \
114 c:\zlib\trees.h
115
116
117UNCOMPR_DEP = c:\zlib\zlib.h \
118 c:\zlib\zconf.h
119
120
121ZUTIL_DEP = c:\zlib\zutil.h \
122 c:\zlib\zlib.h \
123 c:\zlib\zconf.h
124
125
126ZLIB16_RCDEP =
127
128ZIP_DEP = c:\zlib\zlib.h \
129 c:\zlib\zconf.h \
130 c:\zlib\zip.h \
131 c:\zlib\ioapi.h
132
133
134UNZIP_DEP = c:\zlib\zlib.h \
135 c:\zlib\zconf.h \
136 c:\zlib\unzip.h \
137 c:\zlib\ioapi.h
138
139
140INFBACK_DEP = c:\zlib\zutil.h \
141 c:\zlib\zlib.h \
142 c:\zlib\zconf.h \
143 c:\zlib\inftrees.h \
144 c:\zlib\inflate.h \
145 c:\zlib\inffast.h \
146 c:\zlib\inffixed.h
147
148
149IOAPI_DEP = c:\zlib\zlib.h \
150 c:\zlib\zconf.h \
151 c:\zlib\ioapi.h
152
153
154INFTREES_DEP = c:\zlib\zutil.h \
155 c:\zlib\zlib.h \
156 c:\zlib\zconf.h \
157 c:\zlib\inftrees.h
158
159
160all: $(PROJ).DLL $(PROJ).BSC
161
162ADLER32.OBJ: ADLER32.C $(ADLER32_DEP)
163 $(CC) $(CFLAGS) $(CCREATEPCHFLAG) /c ADLER32.C
164
165COMPRESS.OBJ: COMPRESS.C $(COMPRESS_DEP)
166 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c COMPRESS.C
167
168CRC32.OBJ: CRC32.C $(CRC32_DEP)
169 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c CRC32.C
170
171DEFLATE.OBJ: DEFLATE.C $(DEFLATE_DEP)
172 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c DEFLATE.C
173
174GZIO.OBJ: GZIO.C $(GZIO_DEP)
175 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c GZIO.C
176
177INFFAST.OBJ: INFFAST.C $(INFFAST_DEP)
178 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c INFFAST.C
179
180INFLATE.OBJ: INFLATE.C $(INFLATE_DEP)
181 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c INFLATE.C
182
183TREES.OBJ: TREES.C $(TREES_DEP)
184 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c TREES.C
185
186UNCOMPR.OBJ: UNCOMPR.C $(UNCOMPR_DEP)
187 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c UNCOMPR.C
188
189ZUTIL.OBJ: ZUTIL.C $(ZUTIL_DEP)
190 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c ZUTIL.C
191
192ZLIB16.RES: ZLIB16.RC $(ZLIB16_RCDEP)
193 $(RC) $(RCFLAGS) $(RCDEFINES) -r ZLIB16.RC
194
195ZIP.OBJ: ZIP.C $(ZIP_DEP)
196 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c ZIP.C
197
198UNZIP.OBJ: UNZIP.C $(UNZIP_DEP)
199 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c UNZIP.C
200
201INFBACK.OBJ: INFBACK.C $(INFBACK_DEP)
202 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c INFBACK.C
203
204IOAPI.OBJ: IOAPI.C $(IOAPI_DEP)
205 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c IOAPI.C
206
207INFTREES.OBJ: INFTREES.C $(INFTREES_DEP)
208 $(CC) $(CFLAGS) $(CUSEPCHFLAG) /c INFTREES.C
209
210
211$(PROJ).DLL:: ZLIB16.RES
212
213$(PROJ).DLL:: ADLER32.OBJ COMPRESS.OBJ CRC32.OBJ DEFLATE.OBJ GZIO.OBJ INFFAST.OBJ \
214 INFLATE.OBJ TREES.OBJ UNCOMPR.OBJ ZUTIL.OBJ ZIP.OBJ UNZIP.OBJ INFBACK.OBJ IOAPI.OBJ \
215 INFTREES.OBJ $(OBJS_EXT) $(DEFFILE)
216 echo >NUL @<<$(PROJ).CRF
217ADLER32.OBJ +
218COMPRESS.OBJ +
219CRC32.OBJ +
220DEFLATE.OBJ +
221GZIO.OBJ +
222INFFAST.OBJ +
223INFLATE.OBJ +
224TREES.OBJ +
225UNCOMPR.OBJ +
226ZUTIL.OBJ +
227ZIP.OBJ +
228UNZIP.OBJ +
229INFBACK.OBJ +
230IOAPI.OBJ +
231INFTREES.OBJ +
232$(OBJS_EXT)
233$(PROJ).DLL
234$(MAPFILE)
235C:\MSVC\LIB\+
236C:\MSVC\MFC\LIB\+
237E:\PROGRAMFILES\MICROSOFTVISUALSTUDIO.NET\FRAMEWORKSDK\LIB\+
238$(LIBS)
239$(DEFFILE);
240<<
241 link $(LFLAGS) @$(PROJ).CRF
242 $(RC) $(RESFLAGS) ZLIB16.RES $@
243 @copy $(PROJ).CRF MSVC.BND
244 implib /nowep $(PROJ).LIB $(PROJ).DLL
245
246$(PROJ).DLL:: ZLIB16.RES
247 if not exist MSVC.BND $(RC) $(RESFLAGS) ZLIB16.RES $@
248
249run: $(PROJ).DLL
250 $(PROJ) $(RUNFLAGS)
251
252
253$(PROJ).BSC: $(SBRS)
254 bscmake @<<
255/o$@ $(SBRS)
256<<
diff --git a/contrib/vstudio/vc15_16/zlib16.rc b/contrib/vstudio/vc15_16/zlib16.rc
new file mode 100644
index 0000000..13d0d66
--- /dev/null
+++ b/contrib/vstudio/vc15_16/zlib16.rc
@@ -0,0 +1,33 @@
1#include <windows.h>
2#include <ver.h>
3
4#define IDR_VERSION1 1
5IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
6 FILEVERSION 1,2,0,0
7 PRODUCTVERSION 1,2,0,0
8 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
9 FILEFLAGS 0
10 FILEOS VOS_DOS_WINDOWS16
11 FILETYPE VFT_DLL
12 FILESUBTYPE 0 // not used
13BEGIN
14 BLOCK "StringFileInfo"
15 BEGIN
16 BLOCK "040904E4"
17 //language ID = U.S. English, char set = Windows, Multilingual
18
19 BEGIN
20 VALUE "FileDescription", "zlib data compression library\0"
21 VALUE "FileVersion", "1.2.0\0"
22 VALUE "InternalName", "zlib16\0"
23 VALUE "OriginalFilename", "zlib16.dll\0"
24 VALUE "ProductName", "ZLib16.DLL\0"
25 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
26 VALUE "LegalCopyright", "(C) 1995-2003 Jean-loup Gailly & Mark Adler\0"
27 END
28 END
29 BLOCK "VarFileInfo"
30 BEGIN
31 VALUE "Translation", 0x0409, 1252
32 END
33END
diff --git a/contrib/vstudio/vc70_32/gvmat32.asm b/contrib/vstudio/vc70_32/gvmat32.asm
new file mode 100644
index 0000000..320348f
--- /dev/null
+++ b/contrib/vstudio/vc70_32/gvmat32.asm
@@ -0,0 +1,905 @@
1;
2; gvmat32.asm -- Asm portion of the optimized longest_match for 32 bits x86
3; Copyright (C) 1995-1996 Jean-loup Gailly and Gilles Vollant.
4; File written by Gilles Vollant, by modifiying the longest_match
5; from Jean-loup Gailly in deflate.c
6; It need wmask == 0x7fff
7; (assembly code is faster with a fixed wmask)
8;
9; For Visual C++ 4.2 and ML 6.11c (version in directory \MASM611C of Win95 DDK)
10; I compile with : "ml /coff /Zi /c gvmat32.asm"
11;
12
13;uInt longest_match_7fff(s, cur_match)
14; deflate_state *s;
15; IPos cur_match; /* current match */
16
17 NbStack equ 76
18 cur_match equ dword ptr[esp+NbStack-0]
19 str_s equ dword ptr[esp+NbStack-4]
20; 5 dword on top (ret,ebp,esi,edi,ebx)
21 adrret equ dword ptr[esp+NbStack-8]
22 pushebp equ dword ptr[esp+NbStack-12]
23 pushedi equ dword ptr[esp+NbStack-16]
24 pushesi equ dword ptr[esp+NbStack-20]
25 pushebx equ dword ptr[esp+NbStack-24]
26
27 chain_length equ dword ptr [esp+NbStack-28]
28 limit equ dword ptr [esp+NbStack-32]
29 best_len equ dword ptr [esp+NbStack-36]
30 window equ dword ptr [esp+NbStack-40]
31 prev equ dword ptr [esp+NbStack-44]
32 scan_start equ word ptr [esp+NbStack-48]
33 wmask equ dword ptr [esp+NbStack-52]
34 match_start_ptr equ dword ptr [esp+NbStack-56]
35 nice_match equ dword ptr [esp+NbStack-60]
36 scan equ dword ptr [esp+NbStack-64]
37
38 windowlen equ dword ptr [esp+NbStack-68]
39 match_start equ dword ptr [esp+NbStack-72]
40 strend equ dword ptr [esp+NbStack-76]
41 NbStackAdd equ (NbStack-24)
42
43 .386p
44
45 name gvmatch
46 .MODEL FLAT
47
48
49
50; all the +4 offsets are due to the addition of pending_buf_size (in zlib
51; in the deflate_state structure since the asm code was first written
52; (if you compile with zlib 1.0.4 or older, remove the +4).
53; Note : these value are good with a 8 bytes boundary pack structure
54 dep_chain_length equ 70h+4
55 dep_window equ 2ch+4
56 dep_strstart equ 60h+4
57 dep_prev_length equ 6ch+4
58 dep_nice_match equ 84h+4
59 dep_w_size equ 20h+4
60 dep_prev equ 34h+4
61 dep_w_mask equ 28h+4
62 dep_good_match equ 80h+4
63 dep_match_start equ 64h+4
64 dep_lookahead equ 68h+4
65
66
67_TEXT segment
68
69IFDEF NOUNDERLINE
70 public longest_match_7fff
71 public longest_match_686
72; public match_init
73ELSE
74 public _longest_match_7fff
75 public _longest_match_686
76; public _match_init
77ENDIF
78
79 MAX_MATCH equ 258
80 MIN_MATCH equ 3
81 MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1)
82
83
84
85IFDEF NOUNDERLINE
86;match_init proc near
87; ret
88;match_init endp
89ELSE
90;_match_init proc near
91; ret
92;_match_init endp
93ENDIF
94
95
96IFDEF NOUNDERLINE
97longest_match_7fff proc near
98ELSE
99_longest_match_7fff proc near
100ENDIF
101
102 mov edx,[esp+4]
103
104
105
106 push ebp
107 push edi
108 push esi
109 push ebx
110
111 sub esp,NbStackAdd
112
113; initialize or check the variables used in match.asm.
114 mov ebp,edx
115
116; chain_length = s->max_chain_length
117; if (prev_length>=good_match) chain_length >>= 2
118 mov edx,[ebp+dep_chain_length]
119 mov ebx,[ebp+dep_prev_length]
120 cmp [ebp+dep_good_match],ebx
121 ja noshr
122 shr edx,2
123noshr:
124; we increment chain_length because in the asm, the --chain_lenght is in the beginning of the loop
125 inc edx
126 mov edi,[ebp+dep_nice_match]
127 mov chain_length,edx
128 mov eax,[ebp+dep_lookahead]
129 cmp eax,edi
130; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
131 jae nolookaheadnicematch
132 mov edi,eax
133nolookaheadnicematch:
134; best_len = s->prev_length
135 mov best_len,ebx
136
137; window = s->window
138 mov esi,[ebp+dep_window]
139 mov ecx,[ebp+dep_strstart]
140 mov window,esi
141
142 mov nice_match,edi
143; scan = window + strstart
144 add esi,ecx
145 mov scan,esi
146; dx = *window
147 mov dx,word ptr [esi]
148; bx = *(window+best_len-1)
149 mov bx,word ptr [esi+ebx-1]
150 add esi,MAX_MATCH-1
151; scan_start = *scan
152 mov scan_start,dx
153; strend = scan + MAX_MATCH-1
154 mov strend,esi
155; bx = scan_end = *(window+best_len-1)
156
157; IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
158; s->strstart - (IPos)MAX_DIST(s) : NIL;
159
160 mov esi,[ebp+dep_w_size]
161 sub esi,MIN_LOOKAHEAD
162; here esi = MAX_DIST(s)
163 sub ecx,esi
164 ja nodist
165 xor ecx,ecx
166nodist:
167 mov limit,ecx
168
169; prev = s->prev
170 mov edx,[ebp+dep_prev]
171 mov prev,edx
172
173;
174 mov edx,dword ptr [ebp+dep_match_start]
175 mov bp,scan_start
176 mov eax,cur_match
177 mov match_start,edx
178
179 mov edx,window
180 mov edi,edx
181 add edi,best_len
182 mov esi,prev
183 dec edi
184; windowlen = window + best_len -1
185 mov windowlen,edi
186
187 jmp beginloop2
188 align 4
189
190; here, in the loop
191; eax = ax = cur_match
192; ecx = limit
193; bx = scan_end
194; bp = scan_start
195; edi = windowlen (window + best_len -1)
196; esi = prev
197
198
199;// here; chain_length <=16
200normalbeg0add16:
201 add chain_length,16
202 jz exitloop
203normalbeg0:
204 cmp word ptr[edi+eax],bx
205 je normalbeg2noroll
206rcontlabnoroll:
207; cur_match = prev[cur_match & wmask]
208 and eax,7fffh
209 mov ax,word ptr[esi+eax*2]
210; if cur_match > limit, go to exitloop
211 cmp ecx,eax
212 jnb exitloop
213; if --chain_length != 0, go to exitloop
214 dec chain_length
215 jnz normalbeg0
216 jmp exitloop
217
218normalbeg2noroll:
219; if (scan_start==*(cur_match+window)) goto normalbeg2
220 cmp bp,word ptr[edx+eax]
221 jne rcontlabnoroll
222 jmp normalbeg2
223
224contloop3:
225 mov edi,windowlen
226
227; cur_match = prev[cur_match & wmask]
228 and eax,7fffh
229 mov ax,word ptr[esi+eax*2]
230; if cur_match > limit, go to exitloop
231 cmp ecx,eax
232jnbexitloopshort1:
233 jnb exitloop
234; if --chain_length != 0, go to exitloop
235
236
237; begin the main loop
238beginloop2:
239 sub chain_length,16+1
240; if chain_length <=16, don't use the unrolled loop
241 jna normalbeg0add16
242
243do16:
244 cmp word ptr[edi+eax],bx
245 je normalbeg2dc0
246
247maccn MACRO lab
248 and eax,7fffh
249 mov ax,word ptr[esi+eax*2]
250 cmp ecx,eax
251 jnb exitloop
252 cmp word ptr[edi+eax],bx
253 je lab
254 ENDM
255
256rcontloop0:
257 maccn normalbeg2dc1
258
259rcontloop1:
260 maccn normalbeg2dc2
261
262rcontloop2:
263 maccn normalbeg2dc3
264
265rcontloop3:
266 maccn normalbeg2dc4
267
268rcontloop4:
269 maccn normalbeg2dc5
270
271rcontloop5:
272 maccn normalbeg2dc6
273
274rcontloop6:
275 maccn normalbeg2dc7
276
277rcontloop7:
278 maccn normalbeg2dc8
279
280rcontloop8:
281 maccn normalbeg2dc9
282
283rcontloop9:
284 maccn normalbeg2dc10
285
286rcontloop10:
287 maccn short normalbeg2dc11
288
289rcontloop11:
290 maccn short normalbeg2dc12
291
292rcontloop12:
293 maccn short normalbeg2dc13
294
295rcontloop13:
296 maccn short normalbeg2dc14
297
298rcontloop14:
299 maccn short normalbeg2dc15
300
301rcontloop15:
302 and eax,7fffh
303 mov ax,word ptr[esi+eax*2]
304 cmp ecx,eax
305 jnb exitloop
306
307 sub chain_length,16
308 ja do16
309 jmp normalbeg0add16
310
311;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
312
313normbeg MACRO rcontlab,valsub
314; if we are here, we know that *(match+best_len-1) == scan_end
315 cmp bp,word ptr[edx+eax]
316; if (match != scan_start) goto rcontlab
317 jne rcontlab
318; calculate the good chain_length, and we'll compare scan and match string
319 add chain_length,16-valsub
320 jmp iseq
321 ENDM
322
323
324normalbeg2dc11:
325 normbeg rcontloop11,11
326
327normalbeg2dc12:
328 normbeg short rcontloop12,12
329
330normalbeg2dc13:
331 normbeg short rcontloop13,13
332
333normalbeg2dc14:
334 normbeg short rcontloop14,14
335
336normalbeg2dc15:
337 normbeg short rcontloop15,15
338
339normalbeg2dc10:
340 normbeg rcontloop10,10
341
342normalbeg2dc9:
343 normbeg rcontloop9,9
344
345normalbeg2dc8:
346 normbeg rcontloop8,8
347
348normalbeg2dc7:
349 normbeg rcontloop7,7
350
351normalbeg2dc6:
352 normbeg rcontloop6,6
353
354normalbeg2dc5:
355 normbeg rcontloop5,5
356
357normalbeg2dc4:
358 normbeg rcontloop4,4
359
360normalbeg2dc3:
361 normbeg rcontloop3,3
362
363normalbeg2dc2:
364 normbeg rcontloop2,2
365
366normalbeg2dc1:
367 normbeg rcontloop1,1
368
369normalbeg2dc0:
370 normbeg rcontloop0,0
371
372
373; we go in normalbeg2 because *(ushf*)(match+best_len-1) == scan_end
374
375normalbeg2:
376 mov edi,window
377
378 cmp bp,word ptr[edi+eax]
379 jne contloop3 ; if *(ushf*)match != scan_start, continue
380
381iseq:
382; if we are here, we know that *(match+best_len-1) == scan_end
383; and (match == scan_start)
384
385 mov edi,edx
386 mov esi,scan ; esi = scan
387 add edi,eax ; edi = window + cur_match = match
388
389 mov edx,[esi+3] ; compare manually dword at match+3
390 xor edx,[edi+3] ; and scan +3
391
392 jz begincompare ; if equal, go to long compare
393
394; we will determine the unmatch byte and calculate len (in esi)
395 or dl,dl
396 je eq1rr
397 mov esi,3
398 jmp trfinval
399eq1rr:
400 or dx,dx
401 je eq1
402
403 mov esi,4
404 jmp trfinval
405eq1:
406 and edx,0ffffffh
407 jz eq11
408 mov esi,5
409 jmp trfinval
410eq11:
411 mov esi,6
412 jmp trfinval
413
414begincompare:
415 ; here we now scan and match begin same
416 add edi,6
417 add esi,6
418 mov ecx,(MAX_MATCH-(2+4))/4 ; scan for at most MAX_MATCH bytes
419 repe cmpsd ; loop until mismatch
420
421 je trfin ; go to trfin if not unmatch
422; we determine the unmatch byte
423 sub esi,4
424 mov edx,[edi-4]
425 xor edx,[esi]
426
427 or dl,dl
428 jnz trfin
429 inc esi
430
431 or dx,dx
432 jnz trfin
433 inc esi
434
435 and edx,0ffffffh
436 jnz trfin
437 inc esi
438
439trfin:
440 sub esi,scan ; esi = len
441trfinval:
442; here we have finised compare, and esi contain len of equal string
443 cmp esi,best_len ; if len > best_len, go newbestlen
444 ja short newbestlen
445; now we restore edx, ecx and esi, for the big loop
446 mov esi,prev
447 mov ecx,limit
448 mov edx,window
449 jmp contloop3
450
451newbestlen:
452 mov best_len,esi ; len become best_len
453
454 mov match_start,eax ; save new position as match_start
455 cmp esi,nice_match ; if best_len >= nice_match, exit
456 jae exitloop
457 mov ecx,scan
458 mov edx,window ; restore edx=window
459 add ecx,esi
460 add esi,edx
461
462 dec esi
463 mov windowlen,esi ; windowlen = window + best_len-1
464 mov bx,[ecx-1] ; bx = *(scan+best_len-1) = scan_end
465
466; now we restore ecx and esi, for the big loop :
467 mov esi,prev
468 mov ecx,limit
469 jmp contloop3
470
471exitloop:
472; exit : s->match_start=match_start
473 mov ebx,match_start
474 mov ebp,str_s
475 mov ecx,best_len
476 mov dword ptr [ebp+dep_match_start],ebx
477 mov eax,dword ptr [ebp+dep_lookahead]
478 cmp ecx,eax
479 ja minexlo
480 mov eax,ecx
481minexlo:
482; return min(best_len,s->lookahead)
483
484; restore stack and register ebx,esi,edi,ebp
485 add esp,NbStackAdd
486
487 pop ebx
488 pop esi
489 pop edi
490 pop ebp
491 ret
492InfoAuthor:
493; please don't remove this string !
494; Your are free use gvmat32 in any fre or commercial apps if you don't remove the string in the binary!
495 db 0dh,0ah,"GVMat32 optimised assembly code written 1996-98 by Gilles Vollant",0dh,0ah
496
497
498
499IFDEF NOUNDERLINE
500longest_match_7fff endp
501ELSE
502_longest_match_7fff endp
503ENDIF
504
505
506IFDEF NOUNDERLINE
507cpudetect32 proc near
508ELSE
509_cpudetect32 proc near
510ENDIF
511
512 push ebx
513
514 pushfd ; push original EFLAGS
515 pop eax ; get original EFLAGS
516 mov ecx, eax ; save original EFLAGS
517 xor eax, 40000h ; flip AC bit in EFLAGS
518 push eax ; save new EFLAGS value on stack
519 popfd ; replace current EFLAGS value
520 pushfd ; get new EFLAGS
521 pop eax ; store new EFLAGS in EAX
522 xor eax, ecx ; can’t toggle AC bit, processor=80386
523 jz end_cpu_is_386 ; jump if 80386 processor
524 push ecx
525 popfd ; restore AC bit in EFLAGS first
526
527 pushfd
528 pushfd
529 pop ecx
530
531 mov eax, ecx ; get original EFLAGS
532 xor eax, 200000h ; flip ID bit in EFLAGS
533 push eax ; save new EFLAGS value on stack
534 popfd ; replace current EFLAGS value
535 pushfd ; get new EFLAGS
536 pop eax ; store new EFLAGS in EAX
537 popfd ; restore original EFLAGS
538 xor eax, ecx ; can’t toggle ID bit,
539 je is_old_486 ; processor=old
540
541 mov eax,1
542 db 0fh,0a2h ;CPUID
543
544exitcpudetect:
545 pop ebx
546 ret
547
548end_cpu_is_386:
549 mov eax,0300h
550 jmp exitcpudetect
551
552is_old_486:
553 mov eax,0400h
554 jmp exitcpudetect
555
556IFDEF NOUNDERLINE
557cpudetect32 endp
558ELSE
559_cpudetect32 endp
560ENDIF
561
562
563
564
565MAX_MATCH equ 258
566MIN_MATCH equ 3
567MIN_LOOKAHEAD equ (MAX_MATCH + MIN_MATCH + 1)
568MAX_MATCH_8_ equ ((MAX_MATCH + 7) AND 0FFF0h)
569
570
571;;; stack frame offsets
572
573chainlenwmask equ esp + 0 ; high word: current chain len
574 ; low word: s->wmask
575window equ esp + 4 ; local copy of s->window
576windowbestlen equ esp + 8 ; s->window + bestlen
577scanstart equ esp + 16 ; first two bytes of string
578scanend equ esp + 12 ; last two bytes of string
579scanalign equ esp + 20 ; dword-misalignment of string
580nicematch equ esp + 24 ; a good enough match size
581bestlen equ esp + 28 ; size of best match so far
582scan equ esp + 32 ; ptr to string wanting match
583
584LocalVarsSize equ 36
585; saved ebx byte esp + 36
586; saved edi byte esp + 40
587; saved esi byte esp + 44
588; saved ebp byte esp + 48
589; return address byte esp + 52
590deflatestate equ esp + 56 ; the function arguments
591curmatch equ esp + 60
592
593;;; Offsets for fields in the deflate_state structure. These numbers
594;;; are calculated from the definition of deflate_state, with the
595;;; assumption that the compiler will dword-align the fields. (Thus,
596;;; changing the definition of deflate_state could easily cause this
597;;; program to crash horribly, without so much as a warning at
598;;; compile time. Sigh.)
599
600dsWSize equ 36
601dsWMask equ 44
602dsWindow equ 48
603dsPrev equ 56
604dsMatchLen equ 88
605dsPrevMatch equ 92
606dsStrStart equ 100
607dsMatchStart equ 104
608dsLookahead equ 108
609dsPrevLen equ 112
610dsMaxChainLen equ 116
611dsGoodMatch equ 132
612dsNiceMatch equ 136
613
614
615;;; match.asm -- Pentium-Pro-optimized version of longest_match()
616;;; Written for zlib 1.1.2
617;;; Copyright (C) 1998 Brian Raiter <breadbox@muppetlabs.com>
618;;; You can look at http://www.muppetlabs.com/~breadbox/software/assembly.html
619;;;
620;;; This is free software; you can redistribute it and/or modify it
621;;; under the terms of the GNU General Public License.
622
623;GLOBAL _longest_match, _match_init
624
625
626;SECTION .text
627
628;;; uInt longest_match(deflate_state *deflatestate, IPos curmatch)
629
630;_longest_match:
631IFDEF NOUNDERLINE
632longest_match_686 proc near
633ELSE
634_longest_match_686 proc near
635ENDIF
636
637
638;;; Save registers that the compiler may be using, and adjust esp to
639;;; make room for our stack frame.
640
641 push ebp
642 push edi
643 push esi
644 push ebx
645 sub esp, LocalVarsSize
646
647;;; Retrieve the function arguments. ecx will hold cur_match
648;;; throughout the entire function. edx will hold the pointer to the
649;;; deflate_state structure during the function's setup (before
650;;; entering the main loop.
651
652 mov edx, [deflatestate]
653 mov ecx, [curmatch]
654
655;;; uInt wmask = s->w_mask;
656;;; unsigned chain_length = s->max_chain_length;
657;;; if (s->prev_length >= s->good_match) {
658;;; chain_length >>= 2;
659;;; }
660
661 mov eax, [edx + dsPrevLen]
662 mov ebx, [edx + dsGoodMatch]
663 cmp eax, ebx
664 mov eax, [edx + dsWMask]
665 mov ebx, [edx + dsMaxChainLen]
666 jl LastMatchGood
667 shr ebx, 2
668LastMatchGood:
669
670;;; chainlen is decremented once beforehand so that the function can
671;;; use the sign flag instead of the zero flag for the exit test.
672;;; It is then shifted into the high word, to make room for the wmask
673;;; value, which it will always accompany.
674
675 dec ebx
676 shl ebx, 16
677 or ebx, eax
678 mov [chainlenwmask], ebx
679
680;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
681
682 mov eax, [edx + dsNiceMatch]
683 mov ebx, [edx + dsLookahead]
684 cmp ebx, eax
685 jl LookaheadLess
686 mov ebx, eax
687LookaheadLess: mov [nicematch], ebx
688
689;;; register Bytef *scan = s->window + s->strstart;
690
691 mov esi, [edx + dsWindow]
692 mov [window], esi
693 mov ebp, [edx + dsStrStart]
694 lea edi, [esi + ebp]
695 mov [scan], edi
696
697;;; Determine how many bytes the scan ptr is off from being
698;;; dword-aligned.
699
700 mov eax, edi
701 neg eax
702 and eax, 3
703 mov [scanalign], eax
704
705;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
706;;; s->strstart - (IPos)MAX_DIST(s) : NIL;
707
708 mov eax, [edx + dsWSize]
709 sub eax, MIN_LOOKAHEAD
710 sub ebp, eax
711 jg LimitPositive
712 xor ebp, ebp
713LimitPositive:
714
715;;; int best_len = s->prev_length;
716
717 mov eax, [edx + dsPrevLen]
718 mov [bestlen], eax
719
720;;; Store the sum of s->window + best_len in esi locally, and in esi.
721
722 add esi, eax
723 mov [windowbestlen], esi
724
725;;; register ush scan_start = *(ushf*)scan;
726;;; register ush scan_end = *(ushf*)(scan+best_len-1);
727;;; Posf *prev = s->prev;
728
729 movzx ebx, word ptr [edi]
730 mov [scanstart], ebx
731 movzx ebx, word ptr [edi + eax - 1]
732 mov [scanend], ebx
733 mov edi, [edx + dsPrev]
734
735;;; Jump into the main loop.
736
737 mov edx, [chainlenwmask]
738 jmp short LoopEntry
739
740align 4
741
742;;; do {
743;;; match = s->window + cur_match;
744;;; if (*(ushf*)(match+best_len-1) != scan_end ||
745;;; *(ushf*)match != scan_start) continue;
746;;; [...]
747;;; } while ((cur_match = prev[cur_match & wmask]) > limit
748;;; && --chain_length != 0);
749;;;
750;;; Here is the inner loop of the function. The function will spend the
751;;; majority of its time in this loop, and majority of that time will
752;;; be spent in the first ten instructions.
753;;;
754;;; Within this loop:
755;;; ebx = scanend
756;;; ecx = curmatch
757;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask)
758;;; esi = windowbestlen - i.e., (window + bestlen)
759;;; edi = prev
760;;; ebp = limit
761
762LookupLoop:
763 and ecx, edx
764 movzx ecx, word ptr [edi + ecx*2]
765 cmp ecx, ebp
766 jbe LeaveNow
767 sub edx, 00010000h
768 js LeaveNow
769LoopEntry: movzx eax, word ptr [esi + ecx - 1]
770 cmp eax, ebx
771 jnz LookupLoop
772 mov eax, [window]
773 movzx eax, word ptr [eax + ecx]
774 cmp eax, [scanstart]
775 jnz LookupLoop
776
777;;; Store the current value of chainlen.
778
779 mov [chainlenwmask], edx
780
781;;; Point edi to the string under scrutiny, and esi to the string we
782;;; are hoping to match it up with. In actuality, esi and edi are
783;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is
784;;; initialized to -(MAX_MATCH_8 - scanalign).
785
786 mov esi, [window]
787 mov edi, [scan]
788 add esi, ecx
789 mov eax, [scanalign]
790 mov edx, 0fffffef8h; -(MAX_MATCH_8)
791 lea edi, [edi + eax + 0108h] ;MAX_MATCH_8]
792 lea esi, [esi + eax + 0108h] ;MAX_MATCH_8]
793
794;;; Test the strings for equality, 8 bytes at a time. At the end,
795;;; adjust edx so that it is offset to the exact byte that mismatched.
796;;;
797;;; We already know at this point that the first three bytes of the
798;;; strings match each other, and they can be safely passed over before
799;;; starting the compare loop. So what this code does is skip over 0-3
800;;; bytes, as much as necessary in order to dword-align the edi
801;;; pointer. (esi will still be misaligned three times out of four.)
802;;;
803;;; It should be confessed that this loop usually does not represent
804;;; much of the total running time. Replacing it with a more
805;;; straightforward "rep cmpsb" would not drastically degrade
806;;; performance.
807
808LoopCmps:
809 mov eax, [esi + edx]
810 xor eax, [edi + edx]
811 jnz LeaveLoopCmps
812 mov eax, [esi + edx + 4]
813 xor eax, [edi + edx + 4]
814 jnz LeaveLoopCmps4
815 add edx, 8
816 jnz LoopCmps
817 jmp short LenMaximum
818LeaveLoopCmps4: add edx, 4
819LeaveLoopCmps: test eax, 0000FFFFh
820 jnz LenLower
821 add edx, 2
822 shr eax, 16
823LenLower: sub al, 1
824 adc edx, 0
825
826;;; Calculate the length of the match. If it is longer than MAX_MATCH,
827;;; then automatically accept it as the best possible match and leave.
828
829 lea eax, [edi + edx]
830 mov edi, [scan]
831 sub eax, edi
832 cmp eax, MAX_MATCH
833 jge LenMaximum
834
835;;; If the length of the match is not longer than the best match we
836;;; have so far, then forget it and return to the lookup loop.
837
838 mov edx, [deflatestate]
839 mov ebx, [bestlen]
840 cmp eax, ebx
841 jg LongerMatch
842 mov esi, [windowbestlen]
843 mov edi, [edx + dsPrev]
844 mov ebx, [scanend]
845 mov edx, [chainlenwmask]
846 jmp LookupLoop
847
848;;; s->match_start = cur_match;
849;;; best_len = len;
850;;; if (len >= nice_match) break;
851;;; scan_end = *(ushf*)(scan+best_len-1);
852
853LongerMatch: mov ebx, [nicematch]
854 mov [bestlen], eax
855 mov [edx + dsMatchStart], ecx
856 cmp eax, ebx
857 jge LeaveNow
858 mov esi, [window]
859 add esi, eax
860 mov [windowbestlen], esi
861 movzx ebx, word ptr [edi + eax - 1]
862 mov edi, [edx + dsPrev]
863 mov [scanend], ebx
864 mov edx, [chainlenwmask]
865 jmp LookupLoop
866
867;;; Accept the current string, with the maximum possible length.
868
869LenMaximum: mov edx, [deflatestate]
870 mov dword ptr [bestlen], MAX_MATCH
871 mov [edx + dsMatchStart], ecx
872
873;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
874;;; return s->lookahead;
875
876LeaveNow:
877 mov edx, [deflatestate]
878 mov ebx, [bestlen]
879 mov eax, [edx + dsLookahead]
880 cmp ebx, eax
881 jg LookaheadRet
882 mov eax, ebx
883LookaheadRet:
884
885;;; Restore the stack and return from whence we came.
886
887 add esp, LocalVarsSize
888 pop ebx
889 pop esi
890 pop edi
891 pop ebp
892
893 ret
894; please don't remove this string !
895; Your are free use gvmat32 in any fre or commercial apps if you don't remove the string in the binary!
896 db 0dh,0ah,"asm686 with masm, code optimised assembly code from Brian Raiter, written 1998",0dh,0ah
897
898IFDEF NOUNDERLINE
899longest_match_686 endp
900ELSE
901_longest_match_686 endp
902ENDIF
903
904_TEXT ends
905end
diff --git a/contrib/vstudio/vc70_32/gvmat32.obj b/contrib/vstudio/vc70_32/gvmat32.obj
new file mode 100644
index 0000000..5b2f856
--- /dev/null
+++ b/contrib/vstudio/vc70_32/gvmat32.obj
Binary files differ
diff --git a/contrib/vstudio/vc70_32/gvmat32c.c b/contrib/vstudio/vc70_32/gvmat32c.c
new file mode 100644
index 0000000..38be10b
--- /dev/null
+++ b/contrib/vstudio/vc70_32/gvmat32c.c
@@ -0,0 +1,209 @@
1/* gvmat32.c -- C portion of the optimized longest_match for 32 bits x86
2 * Copyright (C) 1995-1996 Jean-loup Gailly and Gilles Vollant.
3 * File written by Gilles Vollant, by modifiying the longest_match
4 * from Jean-loup Gailly in deflate.c
5 * it prepare all parameters and call the assembly longest_match_gvasm
6 * longest_match execute standard C code is wmask != 0x7fff
7 * (assembly code is faster with a fixed wmask)
8 *
9 */
10
11#include "deflate.h"
12
13#undef FAR
14//#include <windows.h>
15
16#ifdef ASMV
17#define NIL 0
18
19#define UNALIGNED_OK
20
21
22/* if your C compiler don't add underline before function name,
23 define ADD_UNDERLINE_ASMFUNC */
24#ifdef ADD_UNDERLINE_ASMFUNC
25#define longest_match_7fff _longest_match_7fff
26#define longest_match_686 _longest_match_686
27#define cpudetect32 _cpudetect32
28#endif
29
30
31
32void match_init()
33{
34}
35
36unsigned long cpudetect32();
37
38uInt longest_match_c(
39 deflate_state *s,
40 IPos cur_match); /* current match */
41
42
43uInt longest_match_7fff(
44 deflate_state *s,
45 IPos cur_match); /* current match */
46
47uInt longest_match_686(
48 deflate_state *s,
49 IPos cur_match); /* current match */
50
51uInt longest_match(
52 deflate_state *s,
53 IPos cur_match) /* current match */
54{
55 static uInt iIsPPro=2;
56
57 if ((s->w_mask == 0x7fff) && (iIsPPro==0))
58 return longest_match_7fff(s,cur_match);
59
60 if (iIsPPro==1)
61 return longest_match_686(s,cur_match);
62
63 if (iIsPPro==2)
64 iIsPPro = (((cpudetect32()/0x100)&0xf)>=6) ? 1 : 0;
65
66 return longest_match_c(s,cur_match);
67}
68
69
70
71uInt longest_match_c(s, cur_match)
72 deflate_state *s;
73 IPos cur_match; /* current match */
74{
75 unsigned chain_length = s->max_chain_length;/* max hash chain length */
76 register Bytef *scan = s->window + s->strstart; /* current string */
77 register Bytef *match; /* matched string */
78 register int len; /* length of current match */
79 int best_len = s->prev_length; /* best match length so far */
80 int nice_match = s->nice_match; /* stop if match long enough */
81 IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
82 s->strstart - (IPos)MAX_DIST(s) : NIL;
83 /* Stop when cur_match becomes <= limit. To simplify the code,
84 * we prevent matches with the string of window index 0.
85 */
86 Posf *prev = s->prev;
87 uInt wmask = s->w_mask;
88
89#ifdef UNALIGNED_OK
90 /* Compare two bytes at a time. Note: this is not always beneficial.
91 * Try with and without -DUNALIGNED_OK to check.
92 */
93 register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
94 register ush scan_start = *(ushf*)scan;
95 register ush scan_end = *(ushf*)(scan+best_len-1);
96#else
97 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
98 register Byte scan_end1 = scan[best_len-1];
99 register Byte scan_end = scan[best_len];
100#endif
101
102 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
103 * It is easy to get rid of this optimization if necessary.
104 */
105 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
106
107 /* Do not waste too much time if we already have a good match: */
108 if (s->prev_length >= s->good_match) {
109 chain_length >>= 2;
110 }
111 /* Do not look for matches beyond the end of the input. This is necessary
112 * to make deflate deterministic.
113 */
114 if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
115
116 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
117
118 do {
119 Assert(cur_match < s->strstart, "no future");
120 match = s->window + cur_match;
121
122 /* Skip to next match if the match length cannot increase
123 * or if the match length is less than 2:
124 */
125#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
126 /* This code assumes sizeof(unsigned short) == 2. Do not use
127 * UNALIGNED_OK if your compiler uses a different size.
128 */
129 if (*(ushf*)(match+best_len-1) != scan_end ||
130 *(ushf*)match != scan_start) continue;
131
132 /* It is not necessary to compare scan[2] and match[2] since they are
133 * always equal when the other bytes match, given that the hash keys
134 * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
135 * strstart+3, +5, ... up to strstart+257. We check for insufficient
136 * lookahead only every 4th comparison; the 128th check will be made
137 * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
138 * necessary to put more guard bytes at the end of the window, or
139 * to check more often for insufficient lookahead.
140 */
141 Assert(scan[2] == match[2], "scan[2]?");
142 scan++, match++;
143 do {
144 } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
145 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
146 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
147 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
148 scan < strend);
149 /* The funny "do {}" generates better code on most compilers */
150
151 /* Here, scan <= window+strstart+257 */
152 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
153 if (*scan == *match) scan++;
154
155 len = (MAX_MATCH - 1) - (int)(strend-scan);
156 scan = strend - (MAX_MATCH-1);
157
158#else /* UNALIGNED_OK */
159
160 if (match[best_len] != scan_end ||
161 match[best_len-1] != scan_end1 ||
162 *match != *scan ||
163 *++match != scan[1]) continue;
164
165 /* The check at best_len-1 can be removed because it will be made
166 * again later. (This heuristic is not always a win.)
167 * It is not necessary to compare scan[2] and match[2] since they
168 * are always equal when the other bytes match, given that
169 * the hash keys are equal and that HASH_BITS >= 8.
170 */
171 scan += 2, match++;
172 Assert(*scan == *match, "match[2]?");
173
174 /* We check for insufficient lookahead only every 8th comparison;
175 * the 256th check will be made at strstart+258.
176 */
177 do {
178 } while (*++scan == *++match && *++scan == *++match &&
179 *++scan == *++match && *++scan == *++match &&
180 *++scan == *++match && *++scan == *++match &&
181 *++scan == *++match && *++scan == *++match &&
182 scan < strend);
183
184 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
185
186 len = MAX_MATCH - (int)(strend - scan);
187 scan = strend - MAX_MATCH;
188
189#endif /* UNALIGNED_OK */
190
191 if (len > best_len) {
192 s->match_start = cur_match;
193 best_len = len;
194 if (len >= nice_match) break;
195#ifdef UNALIGNED_OK
196 scan_end = *(ushf*)(scan+best_len-1);
197#else
198 scan_end1 = scan[best_len-1];
199 scan_end = scan[best_len];
200#endif
201 }
202 } while ((cur_match = prev[cur_match & wmask]) > limit
203 && --chain_length != 0);
204
205 if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
206 return s->lookahead;
207}
208
209#endif /* ASMV */
diff --git a/contrib/vstudio/vc70_32/inffastAsm.asm b/contrib/vstudio/vc70_32/inffastAsm.asm
new file mode 100644
index 0000000..f4b6a56
--- /dev/null
+++ b/contrib/vstudio/vc70_32/inffastAsm.asm
@@ -0,0 +1,1020 @@
1; 75 "inffast.S"
2;FILE "inffast.S"
3
4;;;GLOBAL _inflate_fast
5
6;;;SECTION .text
7
8
9
10 .586p
11 .mmx
12
13 name inflate_fast_x86
14 .MODEL FLAT
15
16_DATA segment
17inflate_fast_use_mmx:
18dd 1
19
20
21_TEXT segment
22PUBLIC _inflate_fast
23
24ALIGN 4
25_inflate_fast:
26 jmp inflate_fast_entry
27
28
29
30ALIGN 4
31 db 'Fast decoding Code from Chris Anderson'
32 db 0
33
34ALIGN 4
35invalid_literal_length_code_msg:
36 db 'invalid literal/length code'
37 db 0
38
39ALIGN 4
40invalid_distance_code_msg:
41 db 'invalid distance code'
42 db 0
43
44ALIGN 4
45invalid_distance_too_far_msg:
46 db 'invalid distance too far back'
47 db 0
48
49
50ALIGN 4
51inflate_fast_mask:
52dd 0
53dd 1
54dd 3
55dd 7
56dd 15
57dd 31
58dd 63
59dd 127
60dd 255
61dd 511
62dd 1023
63dd 2047
64dd 4095
65dd 8191
66dd 16383
67dd 32767
68dd 65535
69dd 131071
70dd 262143
71dd 524287
72dd 1048575
73dd 2097151
74dd 4194303
75dd 8388607
76dd 16777215
77dd 33554431
78dd 67108863
79dd 134217727
80dd 268435455
81dd 536870911
82dd 1073741823
83dd 2147483647
84dd 4294967295
85
86
87;;SECTION .text
88; 205 "inffast.S"
89;GLOBAL inflate_fast_use_mmx
90
91;SECTION .data
92
93
94; GLOBAL inflate_fast_use_mmx:object
95;.size inflate_fast_use_mmx, 4
96; 226 "inffast.S"
97;SECTION .text
98
99ALIGN 4
100inflate_fast_entry:
101 push edi
102 push esi
103 push ebp
104 push ebx
105 pushfd
106 sub esp,64
107 cld
108
109
110
111
112 mov esi, [esp+88]
113 mov edi, [esi+28]
114
115
116
117
118
119
120
121 mov edx, [esi+4]
122 mov eax, [esi+0]
123
124 add edx,eax
125 sub edx,11
126
127 mov [esp+44],eax
128 mov [esp+20],edx
129
130 mov ebp, [esp+92]
131 mov ecx, [esi+16]
132 mov ebx, [esi+12]
133
134 sub ebp,ecx
135 neg ebp
136 add ebp,ebx
137
138 sub ecx,257
139 add ecx,ebx
140
141 mov [esp+60],ebx
142 mov [esp+40],ebp
143 mov [esp+16],ecx
144; 285 "inffast.S"
145 mov eax, [edi+64]
146 mov ecx, [edi+68]
147
148 mov [esp+8],eax
149 mov [esp+12],ecx
150
151 mov eax,1
152 mov ecx, [edi+72]
153 shl eax,cl
154 dec eax
155 mov [esp+0],eax
156
157 mov eax,1
158 mov ecx, [edi+76]
159 shl eax,cl
160 dec eax
161 mov [esp+4],eax
162
163 mov eax, [edi+32]
164 mov ecx, [edi+36]
165 mov edx, [edi+40]
166
167 mov [esp+52],eax
168 mov [esp+48],ecx
169 mov [esp+56],edx
170
171 mov ebp, [edi+44]
172 mov ebx, [edi+48]
173; 321 "inffast.S"
174 mov esi, [esp+44]
175 mov ecx, [esp+20]
176 cmp ecx,esi
177 ja L_align_long
178
179 add ecx,11
180 sub ecx,esi
181 mov eax,12
182 sub eax,ecx
183 lea edi, [esp+28]
184 rep movsb
185 mov ecx,eax
186 xor eax,eax
187 rep stosb
188 lea esi, [esp+28]
189 mov [esp+20],esi
190 jmp L_is_aligned
191
192
193L_align_long:
194 test esi,3
195 jz L_is_aligned
196 xor eax,eax
197 mov al, [esi]
198 inc esi
199 mov ecx,ebx
200 add ebx,8
201 shl eax,cl
202 or ebp,eax
203 jmp L_align_long
204
205L_is_aligned:
206 mov edi, [esp+60]
207; 366 "inffast.S"
208L_check_mmx:
209 cmp dword ptr [inflate_fast_use_mmx],2
210 je L_init_mmx
211 ja L_do_loop
212
213 push eax
214 push ebx
215 push ecx
216 push edx
217 pushfd
218 mov eax, [esp]
219 xor dword ptr [esp],0200000h
220
221
222
223
224 popfd
225 pushfd
226 pop edx
227 xor edx,eax
228 jz L_dont_use_mmx
229 xor eax,eax
230 cpuid
231 cmp ebx,0756e6547h
232 jne L_dont_use_mmx
233 cmp ecx,06c65746eh
234 jne L_dont_use_mmx
235 cmp edx,049656e69h
236 jne L_dont_use_mmx
237 mov eax,1
238 cpuid
239 shr eax,8
240 and eax,15
241 cmp eax,6
242 jne L_dont_use_mmx
243 test edx,0800000h
244 jnz L_use_mmx
245 jmp L_dont_use_mmx
246L_use_mmx:
247 mov dword ptr [inflate_fast_use_mmx],2
248 jmp L_check_mmx_pop
249L_dont_use_mmx:
250 mov dword ptr [inflate_fast_use_mmx],3
251L_check_mmx_pop:
252 pop edx
253 pop ecx
254 pop ebx
255 pop eax
256 jmp L_check_mmx
257; 426 "inffast.S"
258ALIGN 4
259L_do_loop:
260; 437 "inffast.S"
261 cmp bl,15
262 ja L_get_length_code
263
264 xor eax,eax
265 lodsw
266 mov cl,bl
267 add bl,16
268 shl eax,cl
269 or ebp,eax
270
271L_get_length_code:
272 mov edx, [esp+0]
273 mov ecx, [esp+8]
274 and edx,ebp
275 mov eax, [ecx+edx*4]
276
277L_dolen:
278
279
280
281
282
283
284 mov cl,ah
285 sub bl,ah
286 shr ebp,cl
287
288
289
290
291
292
293 test al,al
294 jnz L_test_for_length_base
295
296 shr eax,16
297 stosb
298
299L_while_test:
300
301
302 cmp [esp+16],edi
303 jbe L_break_loop
304
305 cmp [esp+20],esi
306 ja L_do_loop
307 jmp L_break_loop
308
309L_test_for_length_base:
310; 502 "inffast.S"
311 mov edx,eax
312 shr edx,16
313 mov cl,al
314
315 test al,16
316 jz L_test_for_second_level_length
317 and cl,15
318 jz L_save_len
319 cmp bl,cl
320 jae L_add_bits_to_len
321
322 mov ch,cl
323 xor eax,eax
324 lodsw
325 mov cl,bl
326 add bl,16
327 shl eax,cl
328 or ebp,eax
329 mov cl,ch
330
331L_add_bits_to_len:
332 mov eax,1
333 shl eax,cl
334 dec eax
335 sub bl,cl
336 and eax,ebp
337 shr ebp,cl
338 add edx,eax
339
340L_save_len:
341 mov [esp+24],edx
342
343
344L_decode_distance:
345; 549 "inffast.S"
346 cmp bl,15
347 ja L_get_distance_code
348
349 xor eax,eax
350 lodsw
351 mov cl,bl
352 add bl,16
353 shl eax,cl
354 or ebp,eax
355
356L_get_distance_code:
357 mov edx, [esp+4]
358 mov ecx, [esp+12]
359 and edx,ebp
360 mov eax, [ecx+edx*4]
361
362
363L_dodist:
364 mov edx,eax
365 shr edx,16
366 mov cl,ah
367 sub bl,ah
368 shr ebp,cl
369; 584 "inffast.S"
370 mov cl,al
371
372 test al,16
373 jz L_test_for_second_level_dist
374 and cl,15
375 jz L_check_dist_one
376 cmp bl,cl
377 jae L_add_bits_to_dist
378
379 mov ch,cl
380 xor eax,eax
381 lodsw
382 mov cl,bl
383 add bl,16
384 shl eax,cl
385 or ebp,eax
386 mov cl,ch
387
388L_add_bits_to_dist:
389 mov eax,1
390 shl eax,cl
391 dec eax
392 sub bl,cl
393 and eax,ebp
394 shr ebp,cl
395 add edx,eax
396 jmp L_check_window
397
398L_check_window:
399; 625 "inffast.S"
400 mov [esp+44],esi
401 mov eax,edi
402 sub eax, [esp+40]
403
404 cmp eax,edx
405 jb L_clip_window
406
407 mov ecx, [esp+24]
408 mov esi,edi
409 sub esi,edx
410
411 sub ecx,3
412 mov al, [esi]
413 mov [edi],al
414 mov al, [esi+1]
415 mov dl, [esi+2]
416 add esi,3
417 mov [edi+1],al
418 mov [edi+2],dl
419 add edi,3
420 rep movsb
421
422 mov esi, [esp+44]
423 jmp L_while_test
424
425ALIGN 4
426L_check_dist_one:
427 cmp edx,1
428 jne L_check_window
429 cmp [esp+40],edi
430 je L_check_window
431
432 dec edi
433 mov ecx, [esp+24]
434 mov al, [edi]
435 sub ecx,3
436
437 mov [edi+1],al
438 mov [edi+2],al
439 mov [edi+3],al
440 add edi,4
441 rep stosb
442
443 jmp L_while_test
444
445ALIGN 4
446L_test_for_second_level_length:
447
448
449
450
451 test al,64
452 jnz L_test_for_end_of_block
453
454 mov eax,1
455 shl eax,cl
456 dec eax
457 and eax,ebp
458 add eax,edx
459 mov edx, [esp+8]
460 mov eax, [edx+eax*4]
461 jmp L_dolen
462
463ALIGN 4
464L_test_for_second_level_dist:
465
466
467
468
469 test al,64
470 jnz L_invalid_distance_code
471
472 mov eax,1
473 shl eax,cl
474 dec eax
475 and eax,ebp
476 add eax,edx
477 mov edx, [esp+12]
478 mov eax, [edx+eax*4]
479 jmp L_dodist
480
481ALIGN 4
482L_clip_window:
483; 721 "inffast.S"
484 mov ecx,eax
485 mov eax, [esp+52]
486 neg ecx
487 mov esi, [esp+56]
488
489 cmp eax,edx
490 jb L_invalid_distance_too_far
491
492 add ecx,edx
493 cmp dword ptr [esp+48],0
494 jne L_wrap_around_window
495
496 sub eax,ecx
497 add esi,eax
498; 749 "inffast.S"
499 mov eax, [esp+24]
500 cmp eax,ecx
501 jbe L_do_copy1
502
503 sub eax,ecx
504 rep movsb
505 mov esi,edi
506 sub esi,edx
507 jmp L_do_copy1
508
509 cmp eax,ecx
510 jbe L_do_copy1
511
512 sub eax,ecx
513 rep movsb
514 mov esi,edi
515 sub esi,edx
516 jmp L_do_copy1
517
518L_wrap_around_window:
519; 793 "inffast.S"
520 mov eax, [esp+48]
521 cmp ecx,eax
522 jbe L_contiguous_in_window
523
524 add esi, [esp+52]
525 add esi,eax
526 sub esi,ecx
527 sub ecx,eax
528
529
530 mov eax, [esp+24]
531 cmp eax,ecx
532 jbe L_do_copy1
533
534 sub eax,ecx
535 rep movsb
536 mov esi, [esp+56]
537 mov ecx, [esp+48]
538 cmp eax,ecx
539 jbe L_do_copy1
540
541 sub eax,ecx
542 rep movsb
543 mov esi,edi
544 sub esi,edx
545 jmp L_do_copy1
546
547L_contiguous_in_window:
548; 836 "inffast.S"
549 add esi,eax
550 sub esi,ecx
551
552
553 mov eax, [esp+24]
554 cmp eax,ecx
555 jbe L_do_copy1
556
557 sub eax,ecx
558 rep movsb
559 mov esi,edi
560 sub esi,edx
561
562L_do_copy1:
563; 862 "inffast.S"
564 mov ecx,eax
565 rep movsb
566
567 mov esi, [esp+44]
568 jmp L_while_test
569; 878 "inffast.S"
570ALIGN 4
571L_init_mmx:
572 emms
573
574
575
576
577
578 movd mm0,ebp
579 mov ebp,ebx
580; 896 "inffast.S"
581 movd mm4,[esp+0]
582 movq mm3,mm4
583 movd mm5,[esp+4]
584 movq mm2,mm5
585 pxor mm1,mm1
586 mov ebx, [esp+8]
587 jmp L_do_loop_mmx
588
589ALIGN 4
590L_do_loop_mmx:
591 psrlq mm0,mm1
592
593 cmp ebp,32
594 ja L_get_length_code_mmx
595
596 movd mm6,ebp
597 movd mm7,[esi]
598 add esi,4
599 psllq mm7,mm6
600 add ebp,32
601 por mm0,mm7
602
603L_get_length_code_mmx:
604 pand mm4,mm0
605 movd eax,mm4
606 movq mm4,mm3
607 mov eax, [ebx+eax*4]
608
609L_dolen_mmx:
610 movzx ecx,ah
611 movd mm1,ecx
612 sub ebp,ecx
613
614 test al,al
615 jnz L_test_for_length_base_mmx
616
617 shr eax,16
618 stosb
619
620L_while_test_mmx:
621
622
623 cmp [esp+16],edi
624 jbe L_break_loop
625
626 cmp [esp+20],esi
627 ja L_do_loop_mmx
628 jmp L_break_loop
629
630L_test_for_length_base_mmx:
631
632 mov edx,eax
633 shr edx,16
634
635 test al,16
636 jz L_test_for_second_level_length_mmx
637 and eax,15
638 jz L_decode_distance_mmx
639
640 psrlq mm0,mm1
641 movd mm1,eax
642 movd ecx,mm0
643 sub ebp,eax
644 and ecx, [inflate_fast_mask+eax*4]
645 add edx,ecx
646
647L_decode_distance_mmx:
648 psrlq mm0,mm1
649
650 cmp ebp,32
651 ja L_get_dist_code_mmx
652
653 movd mm6,ebp
654 movd mm7,[esi]
655 add esi,4
656 psllq mm7,mm6
657 add ebp,32
658 por mm0,mm7
659
660L_get_dist_code_mmx:
661 mov ebx, [esp+12]
662 pand mm5,mm0
663 movd eax,mm5
664 movq mm5,mm2
665 mov eax, [ebx+eax*4]
666
667L_dodist_mmx:
668
669 movzx ecx,ah
670 mov ebx,eax
671 shr ebx,16
672 sub ebp,ecx
673 movd mm1,ecx
674
675 test al,16
676 jz L_test_for_second_level_dist_mmx
677 and eax,15
678 jz L_check_dist_one_mmx
679
680L_add_bits_to_dist_mmx:
681 psrlq mm0,mm1
682 movd mm1,eax
683 movd ecx,mm0
684 sub ebp,eax
685 and ecx, [inflate_fast_mask+eax*4]
686 add ebx,ecx
687
688L_check_window_mmx:
689 mov [esp+44],esi
690 mov eax,edi
691 sub eax, [esp+40]
692
693 cmp eax,ebx
694 jb L_clip_window_mmx
695
696 mov ecx,edx
697 mov esi,edi
698 sub esi,ebx
699
700 sub ecx,3
701 mov al, [esi]
702 mov [edi],al
703 mov al, [esi+1]
704 mov dl, [esi+2]
705 add esi,3
706 mov [edi+1],al
707 mov [edi+2],dl
708 add edi,3
709 rep movsb
710
711 mov esi, [esp+44]
712 mov ebx, [esp+8]
713 jmp L_while_test_mmx
714
715ALIGN 4
716L_check_dist_one_mmx:
717 cmp ebx,1
718 jne L_check_window_mmx
719 cmp [esp+40],edi
720 je L_check_window_mmx
721
722 dec edi
723 mov ecx,edx
724 mov al, [edi]
725 sub ecx,3
726
727 mov [edi+1],al
728 mov [edi+2],al
729 mov [edi+3],al
730 add edi,4
731 rep stosb
732
733 mov ebx, [esp+8]
734 jmp L_while_test_mmx
735
736ALIGN 4
737L_test_for_second_level_length_mmx:
738 test al,64
739 jnz L_test_for_end_of_block
740
741 and eax,15
742 psrlq mm0,mm1
743 movd ecx,mm0
744 and ecx, [inflate_fast_mask+eax*4]
745 add ecx,edx
746 mov eax, [ebx+ecx*4]
747 jmp L_dolen_mmx
748
749ALIGN 4
750L_test_for_second_level_dist_mmx:
751 test al,64
752 jnz L_invalid_distance_code
753
754 and eax,15
755 psrlq mm0,mm1
756 movd ecx,mm0
757 and ecx, [inflate_fast_mask+eax*4]
758 mov eax, [esp+12]
759 add ecx,ebx
760 mov eax, [eax+ecx*4]
761 jmp L_dodist_mmx
762
763ALIGN 4
764L_clip_window_mmx:
765
766 mov ecx,eax
767 mov eax, [esp+52]
768 neg ecx
769 mov esi, [esp+56]
770
771 cmp eax,ebx
772 jb L_invalid_distance_too_far
773
774 add ecx,ebx
775 cmp dword ptr [esp+48],0
776 jne L_wrap_around_window_mmx
777
778 sub eax,ecx
779 add esi,eax
780
781 cmp edx,ecx
782 jbe L_do_copy1_mmx
783
784 sub edx,ecx
785 rep movsb
786 mov esi,edi
787 sub esi,ebx
788 jmp L_do_copy1_mmx
789
790 cmp edx,ecx
791 jbe L_do_copy1_mmx
792
793 sub edx,ecx
794 rep movsb
795 mov esi,edi
796 sub esi,ebx
797 jmp L_do_copy1_mmx
798
799L_wrap_around_window_mmx:
800
801 mov eax, [esp+48]
802 cmp ecx,eax
803 jbe L_contiguous_in_window_mmx
804
805 add esi, [esp+52]
806 add esi,eax
807 sub esi,ecx
808 sub ecx,eax
809
810
811 cmp edx,ecx
812 jbe L_do_copy1_mmx
813
814 sub edx,ecx
815 rep movsb
816 mov esi, [esp+56]
817 mov ecx, [esp+48]
818 cmp edx,ecx
819 jbe L_do_copy1_mmx
820
821 sub edx,ecx
822 rep movsb
823 mov esi,edi
824 sub esi,ebx
825 jmp L_do_copy1_mmx
826
827L_contiguous_in_window_mmx:
828
829 add esi,eax
830 sub esi,ecx
831
832
833 cmp edx,ecx
834 jbe L_do_copy1_mmx
835
836 sub edx,ecx
837 rep movsb
838 mov esi,edi
839 sub esi,ebx
840
841L_do_copy1_mmx:
842
843
844 mov ecx,edx
845 rep movsb
846
847 mov esi, [esp+44]
848 mov ebx, [esp+8]
849 jmp L_while_test_mmx
850; 1174 "inffast.S"
851L_invalid_distance_code:
852
853
854
855
856
857 mov ecx, invalid_distance_code_msg
858 mov edx,26
859 jmp L_update_stream_state
860
861L_test_for_end_of_block:
862
863
864
865
866
867 test al,32
868 jz L_invalid_literal_length_code
869
870 mov ecx,0
871 mov edx,11
872 jmp L_update_stream_state
873
874L_invalid_literal_length_code:
875
876
877
878
879
880 mov ecx, invalid_literal_length_code_msg
881 mov edx,26
882 jmp L_update_stream_state
883
884L_invalid_distance_too_far:
885
886
887
888 mov esi, [esp+44]
889 mov ecx, invalid_distance_too_far_msg
890 mov edx,26
891 jmp L_update_stream_state
892
893L_update_stream_state:
894
895 mov eax, [esp+88]
896 test ecx,ecx
897 jz L_skip_msg
898 mov [eax+24],ecx
899L_skip_msg:
900 mov eax, [eax+28]
901 mov [eax+0],edx
902 jmp L_break_loop
903
904ALIGN 4
905L_break_loop:
906; 1243 "inffast.S"
907 cmp dword ptr [inflate_fast_use_mmx],2
908 jne L_update_next_in
909
910
911
912 mov ebx,ebp
913
914L_update_next_in:
915; 1266 "inffast.S"
916 mov eax, [esp+88]
917 mov ecx,ebx
918 mov edx, [eax+28]
919 shr ecx,3
920 sub esi,ecx
921 shl ecx,3
922 sub ebx,ecx
923 mov [eax+12],edi
924 mov [edx+48],ebx
925 mov ecx,ebx
926
927 lea ebx, [esp+28]
928 cmp [esp+20],ebx
929 jne L_buf_not_used
930
931 sub esi,ebx
932 mov ebx, [eax+0]
933 mov [esp+20],ebx
934 add esi,ebx
935 mov ebx, [eax+4]
936 sub ebx,11
937 add [esp+20],ebx
938
939L_buf_not_used:
940 mov [eax+0],esi
941
942 mov ebx,1
943 shl ebx,cl
944 dec ebx
945
946
947
948
949
950 cmp dword ptr [inflate_fast_use_mmx],2
951 jne L_update_hold
952
953
954
955 psrlq mm0,mm1
956 movd ebp,mm0
957
958 emms
959
960L_update_hold:
961
962
963
964 and ebp,ebx
965 mov [edx+44],ebp
966
967
968
969
970 mov ebx, [esp+20]
971 cmp ebx,esi
972 jbe L_last_is_smaller
973
974 sub ebx,esi
975 add ebx,11
976 mov [eax+4],ebx
977 jmp L_fixup_out
978L_last_is_smaller:
979 sub esi,ebx
980 neg esi
981 add esi,11
982 mov [eax+4],esi
983
984
985
986
987L_fixup_out:
988
989 mov ebx, [esp+16]
990 cmp ebx,edi
991 jbe L_end_is_smaller
992
993 sub ebx,edi
994 add ebx,257
995 mov [eax+16],ebx
996 jmp L_done
997L_end_is_smaller:
998 sub edi,ebx
999 neg edi
1000 add edi,257
1001 mov [eax+16],edi
1002
1003
1004
1005
1006
1007L_done:
1008 add esp,64
1009 popfd
1010 pop ebx
1011 pop ebp
1012 pop esi
1013 pop edi
1014 ret
1015
1016
1017
1018
1019_TEXT ends
1020end
diff --git a/contrib/vstudio/vc70_32/inffastAsm.obj b/contrib/vstudio/vc70_32/inffastAsm.obj
new file mode 100644
index 0000000..3855400
--- /dev/null
+++ b/contrib/vstudio/vc70_32/inffastAsm.obj
Binary files differ
diff --git a/contrib/vstudio/vc70_32/miniunz.vcproj b/contrib/vstudio/vc70_32/miniunz.vcproj
new file mode 100644
index 0000000..56f0da3
--- /dev/null
+++ b/contrib/vstudio/vc70_32/miniunz.vcproj
@@ -0,0 +1,124 @@
1<?xml version="1.0" encoding = "Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="7.00"
5 Name="miniunz"
6 ProjectGUID="{C52F9E7B-498A-42BE-8DB4-85A15694382A}"
7 Keyword="Win32Proj">
8 <Platforms>
9 <Platform
10 Name="Win32"/>
11 </Platforms>
12 <Configurations>
13 <Configuration
14 Name="Debug|Win32"
15 OutputDirectory="Debug"
16 IntermediateDirectory="Debug"
17 ConfigurationType="1"
18 CharacterSet="2">
19 <Tool
20 Name="VCCLCompilerTool"
21 Optimization="0"
22 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
23 MinimalRebuild="TRUE"
24 BasicRuntimeChecks="3"
25 RuntimeLibrary="5"
26 UsePrecompiledHeader="0"
27 WarningLevel="3"
28 Detect64BitPortabilityProblems="TRUE"
29 DebugInformationFormat="4"/>
30 <Tool
31 Name="VCCustomBuildTool"/>
32 <Tool
33 Name="VCLinkerTool"
34 OutputFile="$(OutDir)/miniunz.exe"
35 LinkIncremental="2"
36 GenerateDebugInformation="TRUE"
37 ProgramDatabaseFile="$(OutDir)/miniunz.pdb"
38 SubSystem="1"
39 TargetMachine="1"/>
40 <Tool
41 Name="VCMIDLTool"/>
42 <Tool
43 Name="VCPostBuildEventTool"/>
44 <Tool
45 Name="VCPreBuildEventTool"/>
46 <Tool
47 Name="VCPreLinkEventTool"/>
48 <Tool
49 Name="VCResourceCompilerTool"/>
50 <Tool
51 Name="VCWebServiceProxyGeneratorTool"/>
52 <Tool
53 Name="VCWebDeploymentTool"/>
54 </Configuration>
55 <Configuration
56 Name="Release|Win32"
57 OutputDirectory="Release"
58 IntermediateDirectory="Release"
59 ConfigurationType="1"
60 CharacterSet="2">
61 <Tool
62 Name="VCCLCompilerTool"
63 Optimization="2"
64 InlineFunctionExpansion="1"
65 OmitFramePointers="TRUE"
66 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
67 StringPooling="TRUE"
68 RuntimeLibrary="4"
69 EnableFunctionLevelLinking="TRUE"
70 UsePrecompiledHeader="0"
71 WarningLevel="3"
72 Detect64BitPortabilityProblems="TRUE"
73 DebugInformationFormat="3"/>
74 <Tool
75 Name="VCCustomBuildTool"/>
76 <Tool
77 Name="VCLinkerTool"
78 OutputFile="$(OutDir)/miniunz.exe"
79 LinkIncremental="1"
80 GenerateDebugInformation="TRUE"
81 SubSystem="1"
82 OptimizeReferences="2"
83 EnableCOMDATFolding="2"
84 OptimizeForWindows98="1"
85 TargetMachine="1"/>
86 <Tool
87 Name="VCMIDLTool"/>
88 <Tool
89 Name="VCPostBuildEventTool"/>
90 <Tool
91 Name="VCPreBuildEventTool"/>
92 <Tool
93 Name="VCPreLinkEventTool"/>
94 <Tool
95 Name="VCResourceCompilerTool"/>
96 <Tool
97 Name="VCWebServiceProxyGeneratorTool"/>
98 <Tool
99 Name="VCWebDeploymentTool"/>
100 </Configuration>
101 </Configurations>
102 <Files>
103 <Filter
104 Name="Source Files"
105 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
106 <File
107 RelativePath="miniunz.c">
108 </File>
109 </Filter>
110 <Filter
111 Name="Header Files"
112 Filter="h;hpp;hxx;hm;inl;inc">
113 </Filter>
114 <Filter
115 Name="Resource Files"
116 Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
117 </Filter>
118 <File
119 RelativePath="zlib.lib">
120 </File>
121 </Files>
122 <Globals>
123 </Globals>
124</VisualStudioProject>
diff --git a/contrib/vstudio/vc70_32/minizip.vcproj b/contrib/vstudio/vc70_32/minizip.vcproj
new file mode 100644
index 0000000..2cc5aca
--- /dev/null
+++ b/contrib/vstudio/vc70_32/minizip.vcproj
@@ -0,0 +1,124 @@
1<?xml version="1.0" encoding = "Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="7.00"
5 Name="minizip"
6 ProjectGUID="{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}"
7 Keyword="Win32Proj">
8 <Platforms>
9 <Platform
10 Name="Win32"/>
11 </Platforms>
12 <Configurations>
13 <Configuration
14 Name="Debug|Win32"
15 OutputDirectory="Debug"
16 IntermediateDirectory="Debug"
17 ConfigurationType="1"
18 CharacterSet="2">
19 <Tool
20 Name="VCCLCompilerTool"
21 Optimization="0"
22 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
23 MinimalRebuild="TRUE"
24 BasicRuntimeChecks="3"
25 RuntimeLibrary="5"
26 UsePrecompiledHeader="0"
27 WarningLevel="3"
28 Detect64BitPortabilityProblems="TRUE"
29 DebugInformationFormat="4"/>
30 <Tool
31 Name="VCCustomBuildTool"/>
32 <Tool
33 Name="VCLinkerTool"
34 OutputFile="$(OutDir)/minizip.exe"
35 LinkIncremental="2"
36 GenerateDebugInformation="TRUE"
37 ProgramDatabaseFile="$(OutDir)/minizip.pdb"
38 SubSystem="1"
39 TargetMachine="1"/>
40 <Tool
41 Name="VCMIDLTool"/>
42 <Tool
43 Name="VCPostBuildEventTool"/>
44 <Tool
45 Name="VCPreBuildEventTool"/>
46 <Tool
47 Name="VCPreLinkEventTool"/>
48 <Tool
49 Name="VCResourceCompilerTool"/>
50 <Tool
51 Name="VCWebServiceProxyGeneratorTool"/>
52 <Tool
53 Name="VCWebDeploymentTool"/>
54 </Configuration>
55 <Configuration
56 Name="Release|Win32"
57 OutputDirectory="Release"
58 IntermediateDirectory="Release"
59 ConfigurationType="1"
60 CharacterSet="2">
61 <Tool
62 Name="VCCLCompilerTool"
63 Optimization="2"
64 InlineFunctionExpansion="1"
65 OmitFramePointers="TRUE"
66 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
67 StringPooling="TRUE"
68 RuntimeLibrary="4"
69 EnableFunctionLevelLinking="TRUE"
70 UsePrecompiledHeader="0"
71 WarningLevel="3"
72 Detect64BitPortabilityProblems="TRUE"
73 DebugInformationFormat="3"/>
74 <Tool
75 Name="VCCustomBuildTool"/>
76 <Tool
77 Name="VCLinkerTool"
78 OutputFile="$(OutDir)/minizip.exe"
79 LinkIncremental="1"
80 GenerateDebugInformation="TRUE"
81 SubSystem="1"
82 OptimizeReferences="2"
83 EnableCOMDATFolding="2"
84 OptimizeForWindows98="1"
85 TargetMachine="1"/>
86 <Tool
87 Name="VCMIDLTool"/>
88 <Tool
89 Name="VCPostBuildEventTool"/>
90 <Tool
91 Name="VCPreBuildEventTool"/>
92 <Tool
93 Name="VCPreLinkEventTool"/>
94 <Tool
95 Name="VCResourceCompilerTool"/>
96 <Tool
97 Name="VCWebServiceProxyGeneratorTool"/>
98 <Tool
99 Name="VCWebDeploymentTool"/>
100 </Configuration>
101 </Configurations>
102 <Files>
103 <Filter
104 Name="Source Files"
105 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
106 <File
107 RelativePath="minizip.c">
108 </File>
109 </Filter>
110 <Filter
111 Name="Header Files"
112 Filter="h;hpp;hxx;hm;inl;inc">
113 </Filter>
114 <Filter
115 Name="Resource Files"
116 Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
117 </Filter>
118 <File
119 RelativePath="zlib.lib">
120 </File>
121 </Files>
122 <Globals>
123 </Globals>
124</VisualStudioProject>
diff --git a/contrib/vstudio/vc70_32/mkgvmt32.bat b/contrib/vstudio/vc70_32/mkgvmt32.bat
new file mode 100644
index 0000000..9c54db7
--- /dev/null
+++ b/contrib/vstudio/vc70_32/mkgvmt32.bat
@@ -0,0 +1,2 @@
1c:\masm611\bin\ml /coff /Zi /c /Flgvmat32.lst gvmat32.asm
2c:\masm611\bin\ml /coff /Zi /c /FlinffastAsm.lst inffastAsm.asm
diff --git a/contrib/vstudio/vc70_32/zlib.rc b/contrib/vstudio/vc70_32/zlib.rc
new file mode 100644
index 0000000..5d86e03
--- /dev/null
+++ b/contrib/vstudio/vc70_32/zlib.rc
@@ -0,0 +1,32 @@
1#include <windows.h>
2
3#define IDR_VERSION1 1
4IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
5 FILEVERSION 1,2,0,0
6 PRODUCTVERSION 1,2,0,0
7 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 FILEFLAGS 0
9 FILEOS VOS_DOS_WINDOWS32
10 FILETYPE VFT_DLL
11 FILESUBTYPE 0 // not used
12BEGIN
13 BLOCK "StringFileInfo"
14 BEGIN
15 BLOCK "040904E4"
16 //language ID = U.S. English, char set = Windows, Multilingual
17
18 BEGIN
19 VALUE "FileDescription", "zlib data compression library\0"
20 VALUE "FileVersion", "1.2.0.0\0"
21 VALUE "InternalName", "zlib\0"
22 VALUE "OriginalFilename", "zlib.dll\0"
23 VALUE "ProductName", "ZLib.DLL\0"
24 VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0"
25 VALUE "LegalCopyright", "(C) 1995-2003 Jean-loup Gailly & Mark Adler\0"
26 END
27 END
28 BLOCK "VarFileInfo"
29 BEGIN
30 VALUE "Translation", 0x0409, 1252
31 END
32END
diff --git a/contrib/vstudio/vc70_32/zlibstat.vcproj b/contrib/vstudio/vc70_32/zlibstat.vcproj
new file mode 100644
index 0000000..94d4a63
--- /dev/null
+++ b/contrib/vstudio/vc70_32/zlibstat.vcproj
@@ -0,0 +1,253 @@
1<?xml version="1.0" encoding = "Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="7.00"
5 Name="zlibstat"
6 SccProjectName=""
7 SccLocalPath="">
8 <Platforms>
9 <Platform
10 Name="Win32"/>
11 </Platforms>
12 <Configurations>
13 <Configuration
14 Name="Debug|Win32"
15 OutputDirectory=".\zlibstatDebug"
16 IntermediateDirectory=".\zlibstatDebug"
17 ConfigurationType="4"
18 UseOfMFC="0"
19 ATLMinimizesCRunTimeLibraryUsage="FALSE">
20 <Tool
21 Name="VCCLCompilerTool"
22 Optimization="0"
23 PreprocessorDefinitions="WIN32"
24 ExceptionHandling="FALSE"
25 RuntimeLibrary="5"
26 PrecompiledHeaderFile=".\zlibstatDebug/zlibstat.pch"
27 AssemblerListingLocation=".\zlibstatDebug/"
28 ObjectFile=".\zlibstatDebug/"
29 ProgramDataBaseFileName=".\zlibstatDebug/"
30 WarningLevel="3"
31 SuppressStartupBanner="TRUE"
32 DebugInformationFormat="1"/>
33 <Tool
34 Name="VCCustomBuildTool"/>
35 <Tool
36 Name="VCLibrarianTool"
37 AdditionalOptions="/NODEFAULTLIB "
38 OutputFile=".\zlibstatDebug\zlibstat.lib"
39 SuppressStartupBanner="TRUE"/>
40 <Tool
41 Name="VCMIDLTool"/>
42 <Tool
43 Name="VCPostBuildEventTool"/>
44 <Tool
45 Name="VCPreBuildEventTool"/>
46 <Tool
47 Name="VCPreLinkEventTool"/>
48 <Tool
49 Name="VCResourceCompilerTool"
50 Culture="1036"/>
51 <Tool
52 Name="VCWebServiceProxyGeneratorTool"/>
53 </Configuration>
54 <Configuration
55 Name="ReleaseAxp|Win32"
56 OutputDirectory=".\zlibsta0"
57 IntermediateDirectory=".\zlibsta0"
58 ConfigurationType="4"
59 UseOfMFC="0"
60 ATLMinimizesCRunTimeLibraryUsage="FALSE">
61 <Tool
62 Name="VCCLCompilerTool"
63 InlineFunctionExpansion="1"
64 PreprocessorDefinitions="WIN32"
65 StringPooling="TRUE"
66 ExceptionHandling="FALSE"
67 RuntimeLibrary="4"
68 EnableFunctionLevelLinking="TRUE"
69 PrecompiledHeaderFile=".\zlibsta0/zlibstat.pch"
70 AssemblerListingLocation=".\zlibsta0/"
71 ObjectFile=".\zlibsta0/"
72 ProgramDataBaseFileName=".\zlibsta0/"
73 WarningLevel="3"
74 SuppressStartupBanner="TRUE"/>
75 <Tool
76 Name="VCCustomBuildTool"/>
77 <Tool
78 Name="VCLibrarianTool"
79 AdditionalOptions="/NODEFAULTLIB "
80 OutputFile=".\zlibsta0\zlibstat.lib"
81 SuppressStartupBanner="TRUE"/>
82 <Tool
83 Name="VCMIDLTool"/>
84 <Tool
85 Name="VCPostBuildEventTool"/>
86 <Tool
87 Name="VCPreBuildEventTool"/>
88 <Tool
89 Name="VCPreLinkEventTool"/>
90 <Tool
91 Name="VCResourceCompilerTool"/>
92 <Tool
93 Name="VCWebServiceProxyGeneratorTool"/>
94 </Configuration>
95 <Configuration
96 Name="Release|Win32"
97 OutputDirectory=".\zlibstat"
98 IntermediateDirectory=".\zlibstat"
99 ConfigurationType="4"
100 UseOfMFC="0"
101 ATLMinimizesCRunTimeLibraryUsage="FALSE">
102 <Tool
103 Name="VCCLCompilerTool"
104 InlineFunctionExpansion="1"
105 PreprocessorDefinitions="WIN32,ASMV"
106 StringPooling="TRUE"
107 ExceptionHandling="FALSE"
108 RuntimeLibrary="4"
109 EnableFunctionLevelLinking="TRUE"
110 PrecompiledHeaderFile=".\zlibstat/zlibstat.pch"
111 AssemblerListingLocation=".\zlibstat/"
112 ObjectFile=".\zlibstat/"
113 ProgramDataBaseFileName=".\zlibstat/"
114 WarningLevel="3"
115 SuppressStartupBanner="TRUE"/>
116 <Tool
117 Name="VCCustomBuildTool"/>
118 <Tool
119 Name="VCLibrarianTool"
120 AdditionalOptions="gvmat32.obj inffastAsm.obj /NODEFAULTLIB "
121 OutputFile=".\zlibstat\zlibstat.lib"
122 SuppressStartupBanner="TRUE"/>
123 <Tool
124 Name="VCMIDLTool"/>
125 <Tool
126 Name="VCPostBuildEventTool"/>
127 <Tool
128 Name="VCPreBuildEventTool"/>
129 <Tool
130 Name="VCPreLinkEventTool"/>
131 <Tool
132 Name="VCResourceCompilerTool"
133 Culture="1036"/>
134 <Tool
135 Name="VCWebServiceProxyGeneratorTool"/>
136 </Configuration>
137 <Configuration
138 Name="ReleaseWithoutAsm|Win32"
139 OutputDirectory="zlibstatWithoutAsm"
140 IntermediateDirectory="zlibstatWithoutAsm"
141 ConfigurationType="4"
142 UseOfMFC="0"
143 ATLMinimizesCRunTimeLibraryUsage="FALSE">
144 <Tool
145 Name="VCCLCompilerTool"
146 InlineFunctionExpansion="1"
147 PreprocessorDefinitions="WIN32"
148 StringPooling="TRUE"
149 ExceptionHandling="FALSE"
150 RuntimeLibrary="4"
151 EnableFunctionLevelLinking="TRUE"
152 PrecompiledHeaderFile=".\zlibstat/zlibstat.pch"
153 AssemblerListingLocation=".\zlibstatWithoutAsm/"
154 ObjectFile=".\zlibstatWithoutAsm/"
155 ProgramDataBaseFileName=".\zlibstatWithoutAsm/"
156 WarningLevel="3"
157 SuppressStartupBanner="TRUE"/>
158 <Tool
159 Name="VCCustomBuildTool"/>
160 <Tool
161 Name="VCLibrarianTool"
162 AdditionalOptions=" /NODEFAULTLIB "
163 OutputFile=".\zlibstatWithoutAsm\zlibstat.lib"
164 SuppressStartupBanner="TRUE"/>
165 <Tool
166 Name="VCMIDLTool"/>
167 <Tool
168 Name="VCPostBuildEventTool"/>
169 <Tool
170 Name="VCPreBuildEventTool"/>
171 <Tool
172 Name="VCPreLinkEventTool"/>
173 <Tool
174 Name="VCResourceCompilerTool"
175 Culture="1036"/>
176 <Tool
177 Name="VCWebServiceProxyGeneratorTool"/>
178 </Configuration>
179 </Configurations>
180 <Files>
181 <Filter
182 Name="Source Files"
183 Filter="">
184 <File
185 RelativePath=".\adler32.c">
186 </File>
187 <File
188 RelativePath=".\compress.c">
189 </File>
190 <File
191 RelativePath=".\crc32.c">
192 </File>
193 <File
194 RelativePath=".\deflate.c">
195 </File>
196 <File
197 RelativePath=".\gvmat32c.c">
198 </File>
199 <File
200 RelativePath=".\gzio.c">
201 </File>
202 <File
203 RelativePath=".\infback.c">
204 </File>
205 <File
206 RelativePath=".\inffast.c">
207 <FileConfiguration
208 Name="Release|Win32"
209 ExcludedFromBuild="TRUE">
210 <Tool
211 Name="VCCLCompilerTool"/>
212 </FileConfiguration>
213 <FileConfiguration
214 Name="ReleaseWithoutAsm|Win32">
215 <Tool
216 Name="VCCLCompilerTool"/>
217 </FileConfiguration>
218 </File>
219 <File
220 RelativePath=".\inflate.c">
221 </File>
222 <File
223 RelativePath=".\inftrees.c">
224 </File>
225 <File
226 RelativePath=".\ioapi.c">
227 </File>
228 <File
229 RelativePath=".\trees.c">
230 </File>
231 <File
232 RelativePath=".\uncompr.c">
233 </File>
234 <File
235 RelativePath=".\unzip.c">
236 </File>
237 <File
238 RelativePath=".\zip.c">
239 </File>
240 <File
241 RelativePath=".\zlib.rc">
242 </File>
243 <File
244 RelativePath=".\zlibvc.def">
245 </File>
246 <File
247 RelativePath=".\zutil.c">
248 </File>
249 </Filter>
250 </Files>
251 <Globals>
252 </Globals>
253</VisualStudioProject>
diff --git a/contrib/vstudio/vc70_32/zlibvc.def b/contrib/vstudio/vc70_32/zlibvc.def
new file mode 100644
index 0000000..90109d6
--- /dev/null
+++ b/contrib/vstudio/vc70_32/zlibvc.def
@@ -0,0 +1,88 @@
1LIBRARY "zlib"
2
3VERSION 1.20
4
5HEAPSIZE 1048576,8192
6
7EXPORTS
8 adler32 @1
9 compress @2
10 crc32 @3
11 deflate @4
12 deflateCopy @5
13 deflateEnd @6
14 deflateInit2_ @7
15 deflateInit_ @8
16 deflateParams @9
17 deflateReset @10
18 deflateSetDictionary @11
19 gzclose @12
20 gzdopen @13
21 gzerror @14
22 gzflush @15
23 gzopen @16
24 gzread @17
25 gzwrite @18
26 inflate @19
27 inflateEnd @20
28 inflateInit2_ @21
29 inflateInit_ @22
30 inflateReset @23
31 inflateSetDictionary @24
32 inflateSync @25
33 uncompress @26
34 zlibVersion @27
35 gzprintf @28
36 gzputc @29
37 gzgetc @30
38 gzseek @31
39 gzrewind @32
40 gztell @33
41 gzeof @34
42 gzsetparams @35
43 zError @36
44 inflateSyncPoint @37
45 get_crc_table @38
46 compress2 @39
47 gzputs @40
48 gzgets @41
49 inflateCopy @42
50 inflateBackInit_ @43
51 inflateBack @44
52 inflateBackEnd @45
53 compressBound @46
54
55 unzOpen @61
56 unzClose @62
57 unzGetGlobalInfo @63
58 unzGetCurrentFileInfo @64
59 unzGoToFirstFile @65
60 unzGoToNextFile @66
61 unzOpenCurrentFile @67
62 unzReadCurrentFile @68
63 unzOpenCurrentFile3 @69
64 unztell @70
65 unzeof @71
66 unzCloseCurrentFile @72
67 unzGetGlobalComment @73
68 unzStringFileNameCompare @74
69 unzLocateFile @75
70 unzGetLocalExtrafield @76
71 unzOpen2 @77
72 unzOpenCurrentFile2 @78
73 unzOpenCurrentFilePassword @79
74
75 zipOpen @80
76 zipOpenNewFileInZip @81
77 zipWriteInFileInZip @82
78 zipCloseFileInZip @83
79 zipClose @84
80 zipOpenNewFileInZip2 @86
81 zipCloseFileInZipRaw @87
82 zipOpen2 @88
83 zipOpenNewFileInZip3 @89
84
85 unzGetFilePos @100
86 unzGoToFilePos @101
87
88 fill_win32_filefunc @110
diff --git a/contrib/vstudio/vc70_32/zlibvc.sln b/contrib/vstudio/vc70_32/zlibvc.sln
new file mode 100644
index 0000000..5a007ff
--- /dev/null
+++ b/contrib/vstudio/vc70_32/zlibvc.sln
@@ -0,0 +1,66 @@
1Microsoft Visual Studio Solution File, Format Version 7.00
2Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}"
3EndProject
4Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}"
5EndProject
6Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}"
7EndProject
8Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}"
9EndProject
10Global
11 GlobalSection(SolutionConfiguration) = preSolution
12 ConfigName.0 = Debug
13 ConfigName.1 = Release
14 ConfigName.2 = ReleaseAxp
15 ConfigName.3 = ReleaseWithoutAsm
16 ConfigName.4 = ReleaseWithoutCrtdll
17 EndGlobalSection
18 GlobalSection(ProjectDependencies) = postSolution
19 EndGlobalSection
20 GlobalSection(ProjectConfiguration) = postSolution
21 {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug.ActiveCfg = Debug|Win32
22 {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug.Build.0 = Debug|Win32
23 {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release.ActiveCfg = Release|Win32
24 {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release.Build.0 = Release|Win32
25 {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseAxp.ActiveCfg = ReleaseAxp|Win32
26 {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseAxp.Build.0 = ReleaseAxp|Win32
27 {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm.ActiveCfg = ReleaseWithoutAsm|Win32
28 {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm.Build.0 = ReleaseWithoutAsm|Win32
29 {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutCrtdll.ActiveCfg = ReleaseAxp|Win32
30 {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutCrtdll.Build.0 = ReleaseAxp|Win32
31 {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug.ActiveCfg = Debug|Win32
32 {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug.Build.0 = Debug|Win32
33 {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release.ActiveCfg = Release|Win32
34 {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release.Build.0 = Release|Win32
35 {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseAxp.ActiveCfg = ReleaseAxp|Win32
36 {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseAxp.Build.0 = ReleaseAxp|Win32
37 {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm.ActiveCfg = ReleaseWithoutAsm|Win32
38 {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm.Build.0 = ReleaseWithoutAsm|Win32
39 {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutCrtdll.ActiveCfg = ReleaseWithoutCrtdll|Win32
40 {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutCrtdll.Build.0 = ReleaseWithoutCrtdll|Win32
41 {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug.ActiveCfg = Debug|Win32
42 {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug.Build.0 = Debug|Win32
43 {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release.ActiveCfg = Release|Win32
44 {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release.Build.0 = Release|Win32
45 {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseAxp.ActiveCfg = Release|Win32
46 {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseAxp.Build.0 = Release|Win32
47 {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm.ActiveCfg = Release|Win32
48 {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm.Build.0 = Release|Win32
49 {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutCrtdll.ActiveCfg = Release|Win32
50 {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutCrtdll.Build.0 = Release|Win32
51 {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug.ActiveCfg = Debug|Win32
52 {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug.Build.0 = Debug|Win32
53 {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release.ActiveCfg = Release|Win32
54 {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release.Build.0 = Release|Win32
55 {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseAxp.ActiveCfg = Release|Win32
56 {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseAxp.Build.0 = Release|Win32
57 {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm.ActiveCfg = Release|Win32
58 {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm.Build.0 = Release|Win32
59 {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutCrtdll.ActiveCfg = Release|Win32
60 {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutCrtdll.Build.0 = Release|Win32
61 EndGlobalSection
62 GlobalSection(ExtensibilityGlobals) = postSolution
63 EndGlobalSection
64 GlobalSection(ExtensibilityAddIns) = postSolution
65 EndGlobalSection
66EndGlobal
diff --git a/contrib/vstudio/vc70_32/zlibvc.vcproj b/contrib/vstudio/vc70_32/zlibvc.vcproj
new file mode 100644
index 0000000..fcf9892
--- /dev/null
+++ b/contrib/vstudio/vc70_32/zlibvc.vcproj
@@ -0,0 +1,434 @@
1<?xml version="1.0" encoding = "Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="7.00"
5 Name="zlibvc"
6 SccProjectName=""
7 SccLocalPath="">
8 <Platforms>
9 <Platform
10 Name="Win32"/>
11 </Platforms>
12 <Configurations>
13 <Configuration
14 Name="Debug|Win32"
15 OutputDirectory=".\DebugDll"
16 IntermediateDirectory=".\DebugDll"
17 ConfigurationType="2"
18 UseOfMFC="0"
19 ATLMinimizesCRunTimeLibraryUsage="FALSE">
20 <Tool
21 Name="VCCLCompilerTool"
22 Optimization="0"
23 PreprocessorDefinitions="WIN32,ASMV"
24 ExceptionHandling="FALSE"
25 RuntimeLibrary="1"
26 PrecompiledHeaderFile=".\DebugDll/zlibvc.pch"
27 AssemblerListingLocation=".\DebugDll/"
28 ObjectFile=".\DebugDll/"
29 ProgramDataBaseFileName=".\DebugDll/"
30 WarningLevel="3"
31 SuppressStartupBanner="TRUE"
32 DebugInformationFormat="4"/>
33 <Tool
34 Name="VCCustomBuildTool"/>
35 <Tool
36 Name="VCLinkerTool"
37 AdditionalOptions="/MACHINE:I386"
38 AdditionalDependencies="gvmat32.obj "
39 OutputFile=".\DebugDll\zlib.dll"
40 LinkIncremental="2"
41 SuppressStartupBanner="TRUE"
42 ModuleDefinitionFile=".\zlibvc.def"
43 GenerateDebugInformation="TRUE"
44 ProgramDatabaseFile=".\DebugDll/zlib.pdb"
45 SubSystem="2"
46 ImportLibrary=".\DebugDll/zlib.lib"/>
47 <Tool
48 Name="VCMIDLTool"
49 PreprocessorDefinitions="_DEBUG"
50 MkTypLibCompatible="TRUE"
51 SuppressStartupBanner="TRUE"
52 TargetEnvironment="1"
53 TypeLibraryName=".\DebugDll/zlibvc.tlb"/>
54 <Tool
55 Name="VCPostBuildEventTool"/>
56 <Tool
57 Name="VCPreBuildEventTool"/>
58 <Tool
59 Name="VCPreLinkEventTool"/>
60 <Tool
61 Name="VCResourceCompilerTool"
62 PreprocessorDefinitions="_DEBUG"
63 Culture="1036"/>
64 <Tool
65 Name="VCWebServiceProxyGeneratorTool"/>
66 <Tool
67 Name="VCWebDeploymentTool"/>
68 </Configuration>
69 <Configuration
70 Name="ReleaseWithoutAsm|Win32"
71 OutputDirectory=".\zlibDllWithoutAsm"
72 IntermediateDirectory=".\zlibDllWithoutAsm"
73 ConfigurationType="2"
74 UseOfMFC="0"
75 ATLMinimizesCRunTimeLibraryUsage="FALSE">
76 <Tool
77 Name="VCCLCompilerTool"
78 InlineFunctionExpansion="1"
79 PreprocessorDefinitions="WIN32"
80 StringPooling="TRUE"
81 ExceptionHandling="FALSE"
82 RuntimeLibrary="0"
83 EnableFunctionLevelLinking="TRUE"
84 PrecompiledHeaderFile=".\zlibDllWithoutAsm/zlibvc.pch"
85 AssemblerOutput="2"
86 AssemblerListingLocation=".\zlibDllWithoutAsm/"
87 ObjectFile=".\zlibDllWithoutAsm/"
88 ProgramDataBaseFileName=".\zlibDllWithoutAsm/"
89 BrowseInformation="1"
90 WarningLevel="3"
91 SuppressStartupBanner="TRUE"/>
92 <Tool
93 Name="VCCustomBuildTool"/>
94 <Tool
95 Name="VCLinkerTool"
96 AdditionalOptions="/MACHINE:I386"
97 AdditionalDependencies="crtdll.lib"
98 OutputFile=".\zlibDllWithoutAsm\zlib.dll"
99 LinkIncremental="1"
100 SuppressStartupBanner="TRUE"
101 IgnoreAllDefaultLibraries="TRUE"
102 ModuleDefinitionFile=".\zlibvc.def"
103 ProgramDatabaseFile=".\zlibDllWithoutAsm/zlib.pdb"
104 GenerateMapFile="TRUE"
105 MapFileName=".\zlibDllWithoutAsm/zlib.map"
106 SubSystem="2"
107 OptimizeForWindows98="1"
108 ImportLibrary=".\zlibDllWithoutAsm/zlib.lib"/>
109 <Tool
110 Name="VCMIDLTool"
111 PreprocessorDefinitions="NDEBUG"
112 MkTypLibCompatible="TRUE"
113 SuppressStartupBanner="TRUE"
114 TargetEnvironment="1"
115 TypeLibraryName=".\zlibDllWithoutAsm/zlibvc.tlb"/>
116 <Tool
117 Name="VCPostBuildEventTool"/>
118 <Tool
119 Name="VCPreBuildEventTool"/>
120 <Tool
121 Name="VCPreLinkEventTool"/>
122 <Tool
123 Name="VCResourceCompilerTool"
124 PreprocessorDefinitions="NDEBUG"
125 Culture="1036"/>
126 <Tool
127 Name="VCWebServiceProxyGeneratorTool"/>
128 <Tool
129 Name="VCWebDeploymentTool"/>
130 </Configuration>
131 <Configuration
132 Name="ReleaseWithoutCrtdll|Win32"
133 OutputDirectory=".\zlibDllWithoutCrtDll"
134 IntermediateDirectory=".\zlibDllWithoutCrtDll"
135 ConfigurationType="2"
136 UseOfMFC="0"
137 ATLMinimizesCRunTimeLibraryUsage="FALSE">
138 <Tool
139 Name="VCCLCompilerTool"
140 InlineFunctionExpansion="1"
141 PreprocessorDefinitions="WIN32,ASMV"
142 StringPooling="TRUE"
143 ExceptionHandling="FALSE"
144 RuntimeLibrary="0"
145 EnableFunctionLevelLinking="TRUE"
146 PrecompiledHeaderFile=".\zlibDllWithoutCrtDll/zlibvc.pch"
147 AssemblerOutput="2"
148 AssemblerListingLocation=".\zlibDllWithoutCrtDll/"
149 ObjectFile=".\zlibDllWithoutCrtDll/"
150 ProgramDataBaseFileName=".\zlibDllWithoutCrtDll/"
151 BrowseInformation="1"
152 WarningLevel="3"
153 SuppressStartupBanner="TRUE"/>
154 <Tool
155 Name="VCCustomBuildTool"/>
156 <Tool
157 Name="VCLinkerTool"
158 AdditionalOptions="/MACHINE:I386"
159 AdditionalDependencies="gvmat32.obj inffastAsm.obj "
160 OutputFile=".\zlibDllWithoutCrtDll\zlib.dll"
161 LinkIncremental="1"
162 SuppressStartupBanner="TRUE"
163 IgnoreAllDefaultLibraries="FALSE"
164 ModuleDefinitionFile=".\zlibvc.def"
165 ProgramDatabaseFile=".\zlibDllWithoutCrtDll/zlib.pdb"
166 GenerateMapFile="TRUE"
167 MapFileName=".\zlibDllWithoutCrtDll/zlib.map"
168 SubSystem="2"
169 OptimizeForWindows98="1"
170 ImportLibrary=".\zlibDllWithoutCrtDll/zlib.lib"/>
171 <Tool
172 Name="VCMIDLTool"
173 PreprocessorDefinitions="NDEBUG"
174 MkTypLibCompatible="TRUE"
175 SuppressStartupBanner="TRUE"
176 TargetEnvironment="1"
177 TypeLibraryName=".\zlibDllWithoutCrtDll/zlibvc.tlb"/>
178 <Tool
179 Name="VCPostBuildEventTool"/>
180 <Tool
181 Name="VCPreBuildEventTool"/>
182 <Tool
183 Name="VCPreLinkEventTool"/>
184 <Tool
185 Name="VCResourceCompilerTool"
186 PreprocessorDefinitions="NDEBUG"
187 Culture="1036"/>
188 <Tool
189 Name="VCWebServiceProxyGeneratorTool"/>
190 <Tool
191 Name="VCWebDeploymentTool"/>
192 </Configuration>
193 <Configuration
194 Name="ReleaseAxp|Win32"
195 OutputDirectory=".\zlibvc__"
196 IntermediateDirectory=".\zlibvc__"
197 ConfigurationType="2"
198 UseOfMFC="0"
199 ATLMinimizesCRunTimeLibraryUsage="FALSE">
200 <Tool
201 Name="VCCLCompilerTool"
202 InlineFunctionExpansion="1"
203 PreprocessorDefinitions="WIN32"
204 StringPooling="TRUE"
205 ExceptionHandling="FALSE"
206 RuntimeLibrary="0"
207 EnableFunctionLevelLinking="TRUE"
208 PrecompiledHeaderFile=".\zlibvc__/zlibvc.pch"
209 AssemblerOutput="2"
210 AssemblerListingLocation=".\zlibvc__/"
211 ObjectFile=".\zlibvc__/"
212 ProgramDataBaseFileName=".\zlibvc__/"
213 BrowseInformation="1"
214 WarningLevel="3"
215 SuppressStartupBanner="TRUE"/>
216 <Tool
217 Name="VCCustomBuildTool"/>
218 <Tool
219 Name="VCLinkerTool"
220 AdditionalDependencies="crtdll.lib"
221 OutputFile="zlibvc__\zlib.dll"
222 LinkIncremental="1"
223 SuppressStartupBanner="TRUE"
224 IgnoreAllDefaultLibraries="TRUE"
225 ModuleDefinitionFile=".\zlibvc.def"
226 ProgramDatabaseFile=".\zlibvc__/zlib.pdb"
227 GenerateMapFile="TRUE"
228 MapFileName=".\zlibvc__/zlib.map"
229 SubSystem="2"
230 ImportLibrary=".\zlibvc__/zlib.lib"/>
231 <Tool
232 Name="VCMIDLTool"
233 PreprocessorDefinitions="NDEBUG"
234 MkTypLibCompatible="TRUE"
235 SuppressStartupBanner="TRUE"
236 TargetEnvironment="1"
237 TypeLibraryName=".\zlibvc__/zlibvc.tlb"/>
238 <Tool
239 Name="VCPostBuildEventTool"/>
240 <Tool
241 Name="VCPreBuildEventTool"/>
242 <Tool
243 Name="VCPreLinkEventTool"/>
244 <Tool
245 Name="VCResourceCompilerTool"
246 PreprocessorDefinitions="NDEBUG"
247 Culture="1036"/>
248 <Tool
249 Name="VCWebServiceProxyGeneratorTool"/>
250 <Tool
251 Name="VCWebDeploymentTool"/>
252 </Configuration>
253 <Configuration
254 Name="Release|Win32"
255 OutputDirectory=".\ReleaseDll"
256 IntermediateDirectory=".\ReleaseDll"
257 ConfigurationType="2"
258 UseOfMFC="0"
259 ATLMinimizesCRunTimeLibraryUsage="FALSE">
260 <Tool
261 Name="VCCLCompilerTool"
262 InlineFunctionExpansion="1"
263 PreprocessorDefinitions="WIN32,ASMV"
264 StringPooling="TRUE"
265 ExceptionHandling="FALSE"
266 RuntimeLibrary="0"
267 EnableFunctionLevelLinking="TRUE"
268 PrecompiledHeaderFile=".\ReleaseDll/zlibvc.pch"
269 AssemblerOutput="2"
270 AssemblerListingLocation=".\ReleaseDll/"
271 ObjectFile=".\ReleaseDll/"
272 ProgramDataBaseFileName=".\ReleaseDll/"
273 BrowseInformation="1"
274 WarningLevel="3"
275 SuppressStartupBanner="TRUE"/>
276 <Tool
277 Name="VCCustomBuildTool"/>
278 <Tool
279 Name="VCLinkerTool"
280 AdditionalOptions="/MACHINE:I386"
281 AdditionalDependencies="gvmat32.obj inffastAsm.obj crtdll.lib"
282 OutputFile=".\ReleaseDll\zlib.dll"
283 LinkIncremental="1"
284 SuppressStartupBanner="TRUE"
285 IgnoreAllDefaultLibraries="TRUE"
286 ModuleDefinitionFile=".\zlibvc.def"
287 ProgramDatabaseFile=".\ReleaseDll/zlib.pdb"
288 GenerateMapFile="TRUE"
289 MapFileName=".\ReleaseDll/zlib.map"
290 SubSystem="2"
291 OptimizeForWindows98="1"
292 ImportLibrary=".\ReleaseDll/zlib.lib"/>
293 <Tool
294 Name="VCMIDLTool"
295 PreprocessorDefinitions="NDEBUG"
296 MkTypLibCompatible="TRUE"
297 SuppressStartupBanner="TRUE"
298 TargetEnvironment="1"
299 TypeLibraryName=".\Release/zlibvc.tlb"/>
300 <Tool
301 Name="VCPostBuildEventTool"/>
302 <Tool
303 Name="VCPreBuildEventTool"/>
304 <Tool
305 Name="VCPreLinkEventTool"/>
306 <Tool
307 Name="VCResourceCompilerTool"
308 PreprocessorDefinitions="NDEBUG"
309 Culture="1036"/>
310 <Tool
311 Name="VCWebServiceProxyGeneratorTool"/>
312 <Tool
313 Name="VCWebDeploymentTool"/>
314 </Configuration>
315 </Configurations>
316 <Files>
317 <Filter
318 Name="Source Files"
319 Filter="cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90">
320 <File
321 RelativePath=".\adler32.c">
322 </File>
323 <File
324 RelativePath=".\compress.c">
325 </File>
326 <File
327 RelativePath=".\crc32.c">
328 </File>
329 <File
330 RelativePath=".\deflate.c">
331 </File>
332 <File
333 RelativePath=".\gvmat32c.c">
334 <FileConfiguration
335 Name="ReleaseWithoutAsm|Win32"
336 ExcludedFromBuild="TRUE">
337 <Tool
338 Name="VCCLCompilerTool"/>
339 </FileConfiguration>
340 </File>
341 <File
342 RelativePath=".\gzio.c">
343 </File>
344 <File
345 RelativePath=".\infback.c">
346 </File>
347 <File
348 RelativePath=".\inffast.c">
349 <FileConfiguration
350 Name="ReleaseWithoutCrtdll|Win32"
351 ExcludedFromBuild="TRUE">
352 <Tool
353 Name="VCCLCompilerTool"/>
354 </FileConfiguration>
355 <FileConfiguration
356 Name="Release|Win32"
357 ExcludedFromBuild="TRUE">
358 <Tool
359 Name="VCCLCompilerTool"/>
360 </FileConfiguration>
361 </File>
362 <File
363 RelativePath=".\inflate.c">
364 </File>
365 <File
366 RelativePath=".\inftrees.c">
367 </File>
368 <File
369 RelativePath=".\ioapi.c">
370 </File>
371 <File
372 RelativePath=".\iowin32.c">
373 </File>
374 <File
375 RelativePath=".\trees.c">
376 </File>
377 <File
378 RelativePath=".\uncompr.c">
379 </File>
380 <File
381 RelativePath=".\unzip.c">
382 </File>
383 <File
384 RelativePath=".\zip.c">
385 </File>
386 <File
387 RelativePath=".\zlib.rc">
388 </File>
389 <File
390 RelativePath=".\zlibvc.def">
391 </File>
392 <File
393 RelativePath=".\zutil.c">
394 </File>
395 </Filter>
396 <Filter
397 Name="Header Files"
398 Filter="h;hpp;hxx;hm;inl;fi;fd">
399 <File
400 RelativePath=".\deflate.h">
401 </File>
402 <File
403 RelativePath=".\infblock.h">
404 </File>
405 <File
406 RelativePath=".\infcodes.h">
407 </File>
408 <File
409 RelativePath=".\inffast.h">
410 </File>
411 <File
412 RelativePath=".\inftrees.h">
413 </File>
414 <File
415 RelativePath=".\infutil.h">
416 </File>
417 <File
418 RelativePath=".\zconf.h">
419 </File>
420 <File
421 RelativePath=".\zlib.h">
422 </File>
423 <File
424 RelativePath=".\zutil.h">
425 </File>
426 </Filter>
427 <Filter
428 Name="Resource Files"
429 Filter="ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
430 </Filter>
431 </Files>
432 <Globals>
433 </Globals>
434</VisualStudioProject>
diff --git a/deflate.c b/deflate.c
index d13627e..97a080c 100644
--- a/deflate.c
+++ b/deflate.c
@@ -1,6 +1,6 @@
1/* deflate.c -- compress data using the deflation algorithm 1/* deflate.c -- compress data using the deflation algorithm
2 * Copyright (C) 1995-2003 Jean-loup Gailly. 2 * Copyright (C) 1995-2003 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* 6/*
@@ -52,7 +52,7 @@
52#include "deflate.h" 52#include "deflate.h"
53 53
54const char deflate_copyright[] = 54const char deflate_copyright[] =
55 " deflate 1.2.0 Copyright 1995-2003 Jean-loup Gailly "; 55 " deflate 1.2.0.1 Copyright 1995-2003 Jean-loup Gailly ";
56/* 56/*
57 If you use the zlib library in a product, an acknowledgment is welcome 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 58 in the documentation of your product. If for some reason you cannot
@@ -76,17 +76,22 @@ typedef block_state (*compress_func) OF((deflate_state *s, int flush));
76local void fill_window OF((deflate_state *s)); 76local void fill_window OF((deflate_state *s));
77local block_state deflate_stored OF((deflate_state *s, int flush)); 77local block_state deflate_stored OF((deflate_state *s, int flush));
78local block_state deflate_fast OF((deflate_state *s, int flush)); 78local block_state deflate_fast OF((deflate_state *s, int flush));
79#ifndef FASTEST
79local block_state deflate_slow OF((deflate_state *s, int flush)); 80local block_state deflate_slow OF((deflate_state *s, int flush));
81#endif
80local void lm_init OF((deflate_state *s)); 82local void lm_init OF((deflate_state *s));
81local void putShortMSB OF((deflate_state *s, uInt b)); 83local void putShortMSB OF((deflate_state *s, uInt b));
82local void flush_pending OF((z_streamp strm)); 84local void flush_pending OF((z_streamp strm));
83local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); 85local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
86#ifndef FASTEST
84#ifdef ASMV 87#ifdef ASMV
85 void match_init OF((void)); /* asm code initialization */ 88 void match_init OF((void)); /* asm code initialization */
86 uInt longest_match OF((deflate_state *s, IPos cur_match)); 89 uInt longest_match OF((deflate_state *s, IPos cur_match));
87#else 90#else
88local uInt longest_match OF((deflate_state *s, IPos cur_match)); 91local uInt longest_match OF((deflate_state *s, IPos cur_match));
89#endif 92#endif
93#endif
94local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
90 95
91#ifdef DEBUG 96#ifdef DEBUG
92local void check_match OF((deflate_state *s, IPos start, IPos match, 97local void check_match OF((deflate_state *s, IPos start, IPos match,
@@ -123,6 +128,12 @@ typedef struct config_s {
123 compress_func func; 128 compress_func func;
124} config; 129} config;
125 130
131#ifdef FASTEST
132local const config configuration_table[2] = {
133/* good lazy nice chain */
134/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
135/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* maximum speed, no lazy matches */
136#else
126local const config configuration_table[10] = { 137local const config configuration_table[10] = {
127/* good lazy nice chain */ 138/* good lazy nice chain */
128/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ 139/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
@@ -136,6 +147,7 @@ local const config configuration_table[10] = {
136/* 7 */ {8, 32, 128, 256, deflate_slow}, 147/* 7 */ {8, 32, 128, 256, deflate_slow},
137/* 8 */ {32, 128, 258, 1024, deflate_slow}, 148/* 8 */ {32, 128, 258, 1024, deflate_slow},
138/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */ 149/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */
150#endif
139 151
140/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 152/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
141 * For deflate_fast() (levels <= 3) good is ignored and lazy has a different 153 * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
@@ -194,13 +206,13 @@ int ZEXPORT deflateInit_(strm, level, version, stream_size)
194 int stream_size; 206 int stream_size;
195{ 207{
196 return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, 208 return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
197 Z_DEFAULT_STRATEGY, version, stream_size); 209 Z_DEFAULT_STRATEGY, version, stream_size);
198 /* To do: ignore strm->next_in if we use it as window */ 210 /* To do: ignore strm->next_in if we use it as window */
199} 211}
200 212
201/* ========================================================================= */ 213/* ========================================================================= */
202int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, 214int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
203 version, stream_size) 215 version, stream_size)
204 z_streamp strm; 216 z_streamp strm;
205 int level; 217 int level;
206 int method; 218 int method;
@@ -221,20 +233,21 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
221 233
222 if (version == Z_NULL || version[0] != my_version[0] || 234 if (version == Z_NULL || version[0] != my_version[0] ||
223 stream_size != sizeof(z_stream)) { 235 stream_size != sizeof(z_stream)) {
224 return Z_VERSION_ERROR; 236 return Z_VERSION_ERROR;
225 } 237 }
226 if (strm == Z_NULL) return Z_STREAM_ERROR; 238 if (strm == Z_NULL) return Z_STREAM_ERROR;
227 239
228 strm->msg = Z_NULL; 240 strm->msg = Z_NULL;
229 if (strm->zalloc == Z_NULL) { 241 if (strm->zalloc == Z_NULL) {
230 strm->zalloc = zcalloc; 242 strm->zalloc = zcalloc;
231 strm->opaque = (voidpf)0; 243 strm->opaque = (voidpf)0;
232 } 244 }
233 if (strm->zfree == Z_NULL) strm->zfree = zcfree; 245 if (strm->zfree == Z_NULL) strm->zfree = zcfree;
234 246
235 if (level == Z_DEFAULT_COMPRESSION) level = 6;
236#ifdef FASTEST 247#ifdef FASTEST
237 level = 1; 248 if (level != 0) level = 1;
249#else
250 if (level == Z_DEFAULT_COMPRESSION) level = 6;
238#endif 251#endif
239 252
240 if (windowBits < 0) { /* undocumented feature: suppress zlib header */ 253 if (windowBits < 0) { /* undocumented feature: suppress zlib header */
@@ -243,7 +256,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
243 } 256 }
244 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || 257 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
245 windowBits < 9 || windowBits > 15 || level < 0 || level > 9 || 258 windowBits < 9 || windowBits > 15 || level < 0 || level > 9 ||
246 strategy < 0 || strategy > Z_HUFFMAN_ONLY) { 259 strategy < 0 || strategy > Z_RLE) {
247 return Z_STREAM_ERROR; 260 return Z_STREAM_ERROR;
248 } 261 }
249 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); 262 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
@@ -309,9 +322,9 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
309 322
310 if (length < MIN_MATCH) return Z_OK; 323 if (length < MIN_MATCH) return Z_OK;
311 if (length > MAX_DIST(s)) { 324 if (length > MAX_DIST(s)) {
312 length = MAX_DIST(s); 325 length = MAX_DIST(s);
313#ifndef USE_DICT_HEAD 326#ifndef USE_DICT_HEAD
314 dictionary += dictLength - length; /* use the tail of the dictionary */ 327 dictionary += dictLength - length; /* use the tail of the dictionary */
315#endif 328#endif
316 } 329 }
317 zmemcpy(s->window, dictionary, length); 330 zmemcpy(s->window, dictionary, length);
@@ -325,7 +338,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
325 s->ins_h = s->window[0]; 338 s->ins_h = s->window[0];
326 UPDATE_HASH(s, s->ins_h, s->window[1]); 339 UPDATE_HASH(s, s->ins_h, s->window[1]);
327 for (n = 0; n <= length - MIN_MATCH; n++) { 340 for (n = 0; n <= length - MIN_MATCH; n++) {
328 INSERT_STRING(s, n, hash_head); 341 INSERT_STRING(s, n, hash_head);
329 } 342 }
330 if (hash_head) hash_head = 0; /* to make compiler happy */ 343 if (hash_head) hash_head = 0; /* to make compiler happy */
331 return Z_OK; 344 return Z_OK;
@@ -336,7 +349,7 @@ int ZEXPORT deflateReset (strm)
336 z_streamp strm; 349 z_streamp strm;
337{ 350{
338 deflate_state *s; 351 deflate_state *s;
339 352
340 if (strm == Z_NULL || strm->state == Z_NULL || 353 if (strm == Z_NULL || strm->state == Z_NULL ||
341 strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR; 354 strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR;
342 355
@@ -374,24 +387,26 @@ int ZEXPORT deflateParams(strm, level, strategy)
374 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 387 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
375 s = strm->state; 388 s = strm->state;
376 389
377 if (level == Z_DEFAULT_COMPRESSION) { 390#ifdef FASTEST
378 level = 6; 391 if (level != 0) level = 1;
379 } 392#else
380 if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) { 393 if (level == Z_DEFAULT_COMPRESSION) level = 6;
381 return Z_STREAM_ERROR; 394#endif
395 if (level < 0 || level > 9 || strategy < 0 || strategy > Z_RLE) {
396 return Z_STREAM_ERROR;
382 } 397 }
383 func = configuration_table[s->level].func; 398 func = configuration_table[s->level].func;
384 399
385 if (func != configuration_table[level].func && strm->total_in != 0) { 400 if (func != configuration_table[level].func && strm->total_in != 0) {
386 /* Flush the last buffer: */ 401 /* Flush the last buffer: */
387 err = deflate(strm, Z_PARTIAL_FLUSH); 402 err = deflate(strm, Z_PARTIAL_FLUSH);
388 } 403 }
389 if (s->level != level) { 404 if (s->level != level) {
390 s->level = level; 405 s->level = level;
391 s->max_lazy_match = configuration_table[level].max_lazy; 406 s->max_lazy_match = configuration_table[level].max_lazy;
392 s->good_match = configuration_table[level].good_length; 407 s->good_match = configuration_table[level].good_length;
393 s->nice_match = configuration_table[level].nice_length; 408 s->nice_match = configuration_table[level].nice_length;
394 s->max_chain_length = configuration_table[level].max_chain; 409 s->max_chain_length = configuration_table[level].max_chain;
395 } 410 }
396 s->strategy = strategy; 411 s->strategy = strategy;
397 return err; 412 return err;
@@ -449,7 +464,7 @@ local void putShortMSB (s, b)
449{ 464{
450 put_byte(s, (Byte)(b >> 8)); 465 put_byte(s, (Byte)(b >> 8));
451 put_byte(s, (Byte)(b & 0xff)); 466 put_byte(s, (Byte)(b & 0xff));
452} 467}
453 468
454/* ========================================================================= 469/* =========================================================================
455 * Flush as much pending output as possible. All deflate() output goes 470 * Flush as much pending output as possible. All deflate() output goes
@@ -485,14 +500,14 @@ int ZEXPORT deflate (strm, flush)
485 deflate_state *s; 500 deflate_state *s;
486 501
487 if (strm == Z_NULL || strm->state == Z_NULL || 502 if (strm == Z_NULL || strm->state == Z_NULL ||
488 flush > Z_FINISH || flush < 0) { 503 flush > Z_FINISH || flush < 0) {
489 return Z_STREAM_ERROR; 504 return Z_STREAM_ERROR;
490 } 505 }
491 s = strm->state; 506 s = strm->state;
492 507
493 if (strm->next_out == Z_NULL || 508 if (strm->next_out == Z_NULL ||
494 (strm->next_in == Z_NULL && strm->avail_in != 0) || 509 (strm->next_in == Z_NULL && strm->avail_in != 0) ||
495 (s->status == FINISH_STATE && flush != Z_FINISH)) { 510 (s->status == FINISH_STATE && flush != Z_FINISH)) {
496 ERR_RETURN(strm, Z_STREAM_ERROR); 511 ERR_RETURN(strm, Z_STREAM_ERROR);
497 } 512 }
498 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); 513 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
@@ -509,40 +524,40 @@ int ZEXPORT deflate (strm, flush)
509 524
510 if (level_flags > 3) level_flags = 3; 525 if (level_flags > 3) level_flags = 3;
511 header |= (level_flags << 6); 526 header |= (level_flags << 6);
512 if (s->strstart != 0) header |= PRESET_DICT; 527 if (s->strstart != 0) header |= PRESET_DICT;
513 header += 31 - (header % 31); 528 header += 31 - (header % 31);
514 529
515 s->status = BUSY_STATE; 530 s->status = BUSY_STATE;
516 putShortMSB(s, header); 531 putShortMSB(s, header);
517 532
518 /* Save the adler32 of the preset dictionary: */ 533 /* Save the adler32 of the preset dictionary: */
519 if (s->strstart != 0) { 534 if (s->strstart != 0) {
520 putShortMSB(s, (uInt)(strm->adler >> 16)); 535 putShortMSB(s, (uInt)(strm->adler >> 16));
521 putShortMSB(s, (uInt)(strm->adler & 0xffff)); 536 putShortMSB(s, (uInt)(strm->adler & 0xffff));
522 } 537 }
523 strm->adler = 1L; 538 strm->adler = 1L;
524 } 539 }
525 540
526 /* Flush as much pending output as possible */ 541 /* Flush as much pending output as possible */
527 if (s->pending != 0) { 542 if (s->pending != 0) {
528 flush_pending(strm); 543 flush_pending(strm);
529 if (strm->avail_out == 0) { 544 if (strm->avail_out == 0) {
530 /* Since avail_out is 0, deflate will be called again with 545 /* Since avail_out is 0, deflate will be called again with
531 * more output space, but possibly with both pending and 546 * more output space, but possibly with both pending and
532 * avail_in equal to zero. There won't be anything to do, 547 * avail_in equal to zero. There won't be anything to do,
533 * but this is not an error situation so make sure we 548 * but this is not an error situation so make sure we
534 * return OK instead of BUF_ERROR at next call of deflate: 549 * return OK instead of BUF_ERROR at next call of deflate:
535 */ 550 */
536 s->last_flush = -1; 551 s->last_flush = -1;
537 return Z_OK; 552 return Z_OK;
538 } 553 }
539 554
540 /* Make sure there is something to do and avoid duplicate consecutive 555 /* Make sure there is something to do and avoid duplicate consecutive
541 * flushes. For repeated and useless calls with Z_FINISH, we keep 556 * flushes. For repeated and useless calls with Z_FINISH, we keep
542 * returning Z_STREAM_END instead of Z_BUFF_ERROR. 557 * returning Z_STREAM_END instead of Z_BUF_ERROR.
543 */ 558 */
544 } else if (strm->avail_in == 0 && flush <= old_flush && 559 } else if (strm->avail_in == 0 && flush <= old_flush &&
545 flush != Z_FINISH) { 560 flush != Z_FINISH) {
546 ERR_RETURN(strm, Z_BUF_ERROR); 561 ERR_RETURN(strm, Z_BUF_ERROR);
547 } 562 }
548 563
@@ -557,24 +572,24 @@ int ZEXPORT deflate (strm, flush)
557 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { 572 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
558 block_state bstate; 573 block_state bstate;
559 574
560 bstate = (*(configuration_table[s->level].func))(s, flush); 575 bstate = (*(configuration_table[s->level].func))(s, flush);
561 576
562 if (bstate == finish_started || bstate == finish_done) { 577 if (bstate == finish_started || bstate == finish_done) {
563 s->status = FINISH_STATE; 578 s->status = FINISH_STATE;
564 } 579 }
565 if (bstate == need_more || bstate == finish_started) { 580 if (bstate == need_more || bstate == finish_started) {
566 if (strm->avail_out == 0) { 581 if (strm->avail_out == 0) {
567 s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ 582 s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
568 } 583 }
569 return Z_OK; 584 return Z_OK;
570 /* If flush != Z_NO_FLUSH && avail_out == 0, the next call 585 /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
571 * of deflate should use the same flush parameter to make sure 586 * of deflate should use the same flush parameter to make sure
572 * that the flush is complete. So we don't have to output an 587 * that the flush is complete. So we don't have to output an
573 * empty block here, this will be done at next call. This also 588 * empty block here, this will be done at next call. This also
574 * ensures that for a very small output buffer, we emit at most 589 * ensures that for a very small output buffer, we emit at most
575 * one empty block. 590 * one empty block.
576 */ 591 */
577 } 592 }
578 if (bstate == block_done) { 593 if (bstate == block_done) {
579 if (flush == Z_PARTIAL_FLUSH) { 594 if (flush == Z_PARTIAL_FLUSH) {
580 _tr_align(s); 595 _tr_align(s);
@@ -588,10 +603,10 @@ int ZEXPORT deflate (strm, flush)
588 } 603 }
589 } 604 }
590 flush_pending(strm); 605 flush_pending(strm);
591 if (strm->avail_out == 0) { 606 if (strm->avail_out == 0) {
592 s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ 607 s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
593 return Z_OK; 608 return Z_OK;
594 } 609 }
595 } 610 }
596 } 611 }
597 Assert(strm->avail_out > 0, "bug2"); 612 Assert(strm->avail_out > 0, "bug2");
@@ -620,7 +635,7 @@ int ZEXPORT deflateEnd (strm)
620 635
621 status = strm->state->status; 636 status = strm->state->status;
622 if (status != INIT_STATE && status != BUSY_STATE && 637 if (status != INIT_STATE && status != BUSY_STATE &&
623 status != FINISH_STATE) { 638 status != FINISH_STATE) {
624 return Z_STREAM_ERROR; 639 return Z_STREAM_ERROR;
625 } 640 }
626 641
@@ -693,7 +708,7 @@ int ZEXPORT deflateCopy (dest, source)
693 ds->bl_desc.dyn_tree = ds->bl_tree; 708 ds->bl_desc.dyn_tree = ds->bl_tree;
694 709
695 return Z_OK; 710 return Z_OK;
696#endif 711#endif /* MAXSEG_64K */
697} 712}
698 713
699/* =========================================================================== 714/* ===========================================================================
@@ -753,6 +768,7 @@ local void lm_init (s)
753#endif 768#endif
754} 769}
755 770
771#ifndef FASTEST
756/* =========================================================================== 772/* ===========================================================================
757 * Set match_start to the longest match starting at the given string and 773 * Set match_start to the longest match starting at the given string and
758 * return its length. Matches shorter or equal to prev_length are discarded, 774 * return its length. Matches shorter or equal to prev_length are discarded,
@@ -766,7 +782,6 @@ local void lm_init (s)
766/* For 80x86 and 680x0, an optimized version will be provided in match.asm or 782/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
767 * match.S. The code will be functionally equivalent. 783 * match.S. The code will be functionally equivalent.
768 */ 784 */
769#ifndef FASTEST
770local uInt longest_match(s, cur_match) 785local uInt longest_match(s, cur_match)
771 deflate_state *s; 786 deflate_state *s;
772 IPos cur_match; /* current match */ 787 IPos cur_match; /* current match */
@@ -904,12 +919,13 @@ local uInt longest_match(s, cur_match)
904 if ((uInt)best_len <= s->lookahead) return (uInt)best_len; 919 if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
905 return s->lookahead; 920 return s->lookahead;
906} 921}
922#endif /* ASMV */
923#endif /* FASTEST */
907 924
908#else /* FASTEST */
909/* --------------------------------------------------------------------------- 925/* ---------------------------------------------------------------------------
910 * Optimized version for level == 1 only 926 * Optimized version for level == 1 or strategy == Z_RLE only
911 */ 927 */
912local uInt longest_match(s, cur_match) 928local uInt longest_match_fast(s, cur_match)
913 deflate_state *s; 929 deflate_state *s;
914 IPos cur_match; /* current match */ 930 IPos cur_match; /* current match */
915{ 931{
@@ -947,10 +963,10 @@ local uInt longest_match(s, cur_match)
947 */ 963 */
948 do { 964 do {
949 } while (*++scan == *++match && *++scan == *++match && 965 } while (*++scan == *++match && *++scan == *++match &&
950 *++scan == *++match && *++scan == *++match && 966 *++scan == *++match && *++scan == *++match &&
951 *++scan == *++match && *++scan == *++match && 967 *++scan == *++match && *++scan == *++match &&
952 *++scan == *++match && *++scan == *++match && 968 *++scan == *++match && *++scan == *++match &&
953 scan < strend); 969 scan < strend);
954 970
955 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); 971 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
956 972
@@ -961,8 +977,6 @@ local uInt longest_match(s, cur_match)
961 s->match_start = cur_match; 977 s->match_start = cur_match;
962 return len <= s->lookahead ? len : s->lookahead; 978 return len <= s->lookahead ? len : s->lookahead;
963} 979}
964#endif /* FASTEST */
965#endif /* ASMV */
966 980
967#ifdef DEBUG 981#ifdef DEBUG
968/* =========================================================================== 982/* ===========================================================================
@@ -977,10 +991,10 @@ local void check_match(s, start, match, length)
977 if (zmemcmp(s->window + match, 991 if (zmemcmp(s->window + match,
978 s->window + start, length) != EQUAL) { 992 s->window + start, length) != EQUAL) {
979 fprintf(stderr, " start %u, match %u, length %d\n", 993 fprintf(stderr, " start %u, match %u, length %d\n",
980 start, match, length); 994 start, match, length);
981 do { 995 do {
982 fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); 996 fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
983 } while (--length != 0); 997 } while (--length != 0);
984 z_error("invalid match"); 998 z_error("invalid match");
985 } 999 }
986 if (z_verbose > 1) { 1000 if (z_verbose > 1) {
@@ -990,7 +1004,7 @@ local void check_match(s, start, match, length)
990} 1004}
991#else 1005#else
992# define check_match(s, start, match, length) 1006# define check_match(s, start, match, length)
993#endif 1007#endif /* DEBUG */
994 1008
995/* =========================================================================== 1009/* ===========================================================================
996 * Fill the window when the lookahead becomes insufficient. 1010 * Fill the window when the lookahead becomes insufficient.
@@ -1039,23 +1053,23 @@ local void fill_window(s)
1039 later. (Using level 0 permanently is not an optimal usage of 1053 later. (Using level 0 permanently is not an optimal usage of
1040 zlib, so we don't care about this pathological case.) 1054 zlib, so we don't care about this pathological case.)
1041 */ 1055 */
1042 n = s->hash_size; 1056 n = s->hash_size;
1043 p = &s->head[n]; 1057 p = &s->head[n];
1044 do { 1058 do {
1045 m = *--p; 1059 m = *--p;
1046 *p = (Pos)(m >= wsize ? m-wsize : NIL); 1060 *p = (Pos)(m >= wsize ? m-wsize : NIL);
1047 } while (--n); 1061 } while (--n);
1048 1062
1049 n = wsize; 1063 n = wsize;
1050#ifndef FASTEST 1064#ifndef FASTEST
1051 p = &s->prev[n]; 1065 p = &s->prev[n];
1052 do { 1066 do {
1053 m = *--p; 1067 m = *--p;
1054 *p = (Pos)(m >= wsize ? m-wsize : NIL); 1068 *p = (Pos)(m >= wsize ? m-wsize : NIL);
1055 /* If n is not on any hash chain, prev[n] is garbage but 1069 /* If n is not on any hash chain, prev[n] is garbage but
1056 * its value will never be used. 1070 * its value will never be used.
1057 */ 1071 */
1058 } while (--n); 1072 } while (--n);
1059#endif 1073#endif
1060 more += wsize; 1074 more += wsize;
1061 } 1075 }
@@ -1100,8 +1114,8 @@ local void fill_window(s)
1100 _tr_flush_block(s, (s->block_start >= 0L ? \ 1114 _tr_flush_block(s, (s->block_start >= 0L ? \
1101 (charf *)&s->window[(unsigned)s->block_start] : \ 1115 (charf *)&s->window[(unsigned)s->block_start] : \
1102 (charf *)Z_NULL), \ 1116 (charf *)Z_NULL), \
1103 (ulg)((long)s->strstart - s->block_start), \ 1117 (ulg)((long)s->strstart - s->block_start), \
1104 (eof)); \ 1118 (eof)); \
1105 s->block_start = s->strstart; \ 1119 s->block_start = s->strstart; \
1106 flush_pending(s->strm); \ 1120 flush_pending(s->strm); \
1107 Tracev((stderr,"[FLUSH]")); \ 1121 Tracev((stderr,"[FLUSH]")); \
@@ -1142,32 +1156,32 @@ local block_state deflate_stored(s, flush)
1142 if (s->lookahead <= 1) { 1156 if (s->lookahead <= 1) {
1143 1157
1144 Assert(s->strstart < s->w_size+MAX_DIST(s) || 1158 Assert(s->strstart < s->w_size+MAX_DIST(s) ||
1145 s->block_start >= (long)s->w_size, "slide too late"); 1159 s->block_start >= (long)s->w_size, "slide too late");
1146 1160
1147 fill_window(s); 1161 fill_window(s);
1148 if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; 1162 if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
1149 1163
1150 if (s->lookahead == 0) break; /* flush the current block */ 1164 if (s->lookahead == 0) break; /* flush the current block */
1151 } 1165 }
1152 Assert(s->block_start >= 0L, "block gone"); 1166 Assert(s->block_start >= 0L, "block gone");
1153 1167
1154 s->strstart += s->lookahead; 1168 s->strstart += s->lookahead;
1155 s->lookahead = 0; 1169 s->lookahead = 0;
1156 1170
1157 /* Emit a stored block if pending_buf will be full: */ 1171 /* Emit a stored block if pending_buf will be full: */
1158 max_start = s->block_start + max_block_size; 1172 max_start = s->block_start + max_block_size;
1159 if (s->strstart == 0 || (ulg)s->strstart >= max_start) { 1173 if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
1160 /* strstart == 0 is possible when wraparound on 16-bit machine */ 1174 /* strstart == 0 is possible when wraparound on 16-bit machine */
1161 s->lookahead = (uInt)(s->strstart - max_start); 1175 s->lookahead = (uInt)(s->strstart - max_start);
1162 s->strstart = (uInt)max_start; 1176 s->strstart = (uInt)max_start;
1163 FLUSH_BLOCK(s, 0); 1177 FLUSH_BLOCK(s, 0);
1164 } 1178 }
1165 /* Flush if we may have to slide, otherwise block_start may become 1179 /* Flush if we may have to slide, otherwise block_start may become
1166 * negative and the data will be gone: 1180 * negative and the data will be gone:
1167 */ 1181 */
1168 if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { 1182 if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
1169 FLUSH_BLOCK(s, 0); 1183 FLUSH_BLOCK(s, 0);
1170 } 1184 }
1171 } 1185 }
1172 FLUSH_BLOCK(s, flush == Z_FINISH); 1186 FLUSH_BLOCK(s, flush == Z_FINISH);
1173 return flush == Z_FINISH ? finish_done : block_done; 1187 return flush == Z_FINISH ? finish_done : block_done;
@@ -1196,8 +1210,8 @@ local block_state deflate_fast(s, flush)
1196 if (s->lookahead < MIN_LOOKAHEAD) { 1210 if (s->lookahead < MIN_LOOKAHEAD) {
1197 fill_window(s); 1211 fill_window(s);
1198 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { 1212 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1199 return need_more; 1213 return need_more;
1200 } 1214 }
1201 if (s->lookahead == 0) break; /* flush the current block */ 1215 if (s->lookahead == 0) break; /* flush the current block */
1202 } 1216 }
1203 1217
@@ -1216,10 +1230,19 @@ local block_state deflate_fast(s, flush)
1216 * of window index 0 (in particular we have to avoid a match 1230 * of window index 0 (in particular we have to avoid a match
1217 * of the string with itself at the start of the input file). 1231 * of the string with itself at the start of the input file).
1218 */ 1232 */
1219 if (s->strategy != Z_HUFFMAN_ONLY) { 1233#ifdef FASTEST
1234 if ((s->strategy < Z_HUFFMAN_ONLY) ||
1235 (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
1236 s->match_length = longest_match_fast (s, hash_head);
1237 }
1238#else
1239 if (s->strategy < Z_HUFFMAN_ONLY) {
1220 s->match_length = longest_match (s, hash_head); 1240 s->match_length = longest_match (s, hash_head);
1241 } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
1242 s->match_length = longest_match_fast (s, hash_head);
1221 } 1243 }
1222 /* longest_match() sets match_start */ 1244#endif
1245 /* longest_match() or longest_match_fast() sets match_start */
1223 } 1246 }
1224 if (s->match_length >= MIN_MATCH) { 1247 if (s->match_length >= MIN_MATCH) {
1225 check_match(s, s->strstart, s->match_start, s->match_length); 1248 check_match(s, s->strstart, s->match_start, s->match_length);
@@ -1243,10 +1266,10 @@ local block_state deflate_fast(s, flush)
1243 * always MIN_MATCH bytes ahead. 1266 * always MIN_MATCH bytes ahead.
1244 */ 1267 */
1245 } while (--s->match_length != 0); 1268 } while (--s->match_length != 0);
1246 s->strstart++; 1269 s->strstart++;
1247 } else 1270 } else
1248#endif 1271#endif
1249 { 1272 {
1250 s->strstart += s->match_length; 1273 s->strstart += s->match_length;
1251 s->match_length = 0; 1274 s->match_length = 0;
1252 s->ins_h = s->window[s->strstart]; 1275 s->ins_h = s->window[s->strstart];
@@ -1263,7 +1286,7 @@ local block_state deflate_fast(s, flush)
1263 Tracevv((stderr,"%c", s->window[s->strstart])); 1286 Tracevv((stderr,"%c", s->window[s->strstart]));
1264 _tr_tally_lit (s, s->window[s->strstart], bflush); 1287 _tr_tally_lit (s, s->window[s->strstart], bflush);
1265 s->lookahead--; 1288 s->lookahead--;
1266 s->strstart++; 1289 s->strstart++;
1267 } 1290 }
1268 if (bflush) FLUSH_BLOCK(s, 0); 1291 if (bflush) FLUSH_BLOCK(s, 0);
1269 } 1292 }
@@ -1271,6 +1294,7 @@ local block_state deflate_fast(s, flush)
1271 return flush == Z_FINISH ? finish_done : block_done; 1294 return flush == Z_FINISH ? finish_done : block_done;
1272} 1295}
1273 1296
1297#ifndef FASTEST
1274/* =========================================================================== 1298/* ===========================================================================
1275 * Same as above, but achieves better compression. We use a lazy 1299 * Same as above, but achieves better compression. We use a lazy
1276 * evaluation for matches: a match is finally adopted only if there is 1300 * evaluation for matches: a match is finally adopted only if there is
@@ -1293,8 +1317,8 @@ local block_state deflate_slow(s, flush)
1293 if (s->lookahead < MIN_LOOKAHEAD) { 1317 if (s->lookahead < MIN_LOOKAHEAD) {
1294 fill_window(s); 1318 fill_window(s);
1295 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { 1319 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1296 return need_more; 1320 return need_more;
1297 } 1321 }
1298 if (s->lookahead == 0) break; /* flush the current block */ 1322 if (s->lookahead == 0) break; /* flush the current block */
1299 } 1323 }
1300 1324
@@ -1316,10 +1340,12 @@ local block_state deflate_slow(s, flush)
1316 * of window index 0 (in particular we have to avoid a match 1340 * of window index 0 (in particular we have to avoid a match
1317 * of the string with itself at the start of the input file). 1341 * of the string with itself at the start of the input file).
1318 */ 1342 */
1319 if (s->strategy != Z_HUFFMAN_ONLY) { 1343 if (s->strategy < Z_HUFFMAN_ONLY) {
1320 s->match_length = longest_match (s, hash_head); 1344 s->match_length = longest_match (s, hash_head);
1345 } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
1346 s->match_length = longest_match_fast (s, hash_head);
1321 } 1347 }
1322 /* longest_match() sets match_start */ 1348 /* longest_match() or longest_match_fast() sets match_start */
1323 1349
1324 if (s->match_length <= 5 && (s->strategy == Z_FILTERED || 1350 if (s->match_length <= 5 && (s->strategy == Z_FILTERED ||
1325 (s->match_length == MIN_MATCH && 1351 (s->match_length == MIN_MATCH &&
@@ -1341,7 +1367,7 @@ local block_state deflate_slow(s, flush)
1341 check_match(s, s->strstart-1, s->prev_match, s->prev_length); 1367 check_match(s, s->strstart-1, s->prev_match, s->prev_length);
1342 1368
1343 _tr_tally_dist(s, s->strstart -1 - s->prev_match, 1369 _tr_tally_dist(s, s->strstart -1 - s->prev_match,
1344 s->prev_length - MIN_MATCH, bflush); 1370 s->prev_length - MIN_MATCH, bflush);
1345 1371
1346 /* Insert in hash table all strings up to the end of the match. 1372 /* Insert in hash table all strings up to the end of the match.
1347 * strstart-1 and strstart are already inserted. If there is not 1373 * strstart-1 and strstart are already inserted. If there is not
@@ -1367,8 +1393,8 @@ local block_state deflate_slow(s, flush)
1367 * is longer, truncate the previous match to a single literal. 1393 * is longer, truncate the previous match to a single literal.
1368 */ 1394 */
1369 Tracevv((stderr,"%c", s->window[s->strstart-1])); 1395 Tracevv((stderr,"%c", s->window[s->strstart-1]));
1370 _tr_tally_lit(s, s->window[s->strstart-1], bflush); 1396 _tr_tally_lit(s, s->window[s->strstart-1], bflush);
1371 if (bflush) { 1397 if (bflush) {
1372 FLUSH_BLOCK_ONLY(s, 0); 1398 FLUSH_BLOCK_ONLY(s, 0);
1373 } 1399 }
1374 s->strstart++; 1400 s->strstart++;
@@ -1392,3 +1418,4 @@ local block_state deflate_slow(s, flush)
1392 FLUSH_BLOCK(s, flush == Z_FINISH); 1418 FLUSH_BLOCK(s, flush == Z_FINISH);
1393 return flush == Z_FINISH ? finish_done : block_done; 1419 return flush == Z_FINISH ? finish_done : block_done;
1394} 1420}
1421#endif /* FASTEST */
diff --git a/deflate.h b/deflate.h
index b99a48a..c3f8858 100644
--- a/deflate.h
+++ b/deflate.h
@@ -269,7 +269,7 @@ typedef struct internal_state {
269void _tr_init OF((deflate_state *s)); 269void _tr_init OF((deflate_state *s));
270int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); 270int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
271void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, 271void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
272 int eof)); 272 int eof));
273void _tr_align OF((deflate_state *s)); 273void _tr_align OF((deflate_state *s));
274void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, 274void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
275 int eof)); 275 int eof));
diff --git a/example.c b/example.c
index 8820e56..9fd13ce 100644
--- a/example.c
+++ b/example.c
@@ -1,6 +1,6 @@
1/* example.c -- usage example of the zlib compression library 1/* example.c -- usage example of the zlib compression library
2 * Copyright (C) 1995-2003 Jean-loup Gailly. 2 * Copyright (C) 1995-2003 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* @(#) $Id$ */ 6/* @(#) $Id$ */
@@ -37,22 +37,22 @@ const char dictionary[] = "hello";
37uLong dictId; /* Adler32 value of the dictionary */ 37uLong dictId; /* Adler32 value of the dictionary */
38 38
39void test_compress OF((Byte *compr, uLong comprLen, 39void test_compress OF((Byte *compr, uLong comprLen,
40 Byte *uncompr, uLong uncomprLen)); 40 Byte *uncompr, uLong uncomprLen));
41void test_gzio OF((const char *out, const char *in, 41void test_gzio OF((const char *out, const char *in,
42 Byte *uncompr, int uncomprLen)); 42 Byte *uncompr, int uncomprLen));
43void test_deflate OF((Byte *compr, uLong comprLen)); 43void test_deflate OF((Byte *compr, uLong comprLen));
44void test_inflate OF((Byte *compr, uLong comprLen, 44void test_inflate OF((Byte *compr, uLong comprLen,
45 Byte *uncompr, uLong uncomprLen)); 45 Byte *uncompr, uLong uncomprLen));
46void test_large_deflate OF((Byte *compr, uLong comprLen, 46void test_large_deflate OF((Byte *compr, uLong comprLen,
47 Byte *uncompr, uLong uncomprLen)); 47 Byte *uncompr, uLong uncomprLen));
48void test_large_inflate OF((Byte *compr, uLong comprLen, 48void test_large_inflate OF((Byte *compr, uLong comprLen,
49 Byte *uncompr, uLong uncomprLen)); 49 Byte *uncompr, uLong uncomprLen));
50void test_flush OF((Byte *compr, uLong *comprLen)); 50void test_flush OF((Byte *compr, uLong *comprLen));
51void test_sync OF((Byte *compr, uLong comprLen, 51void test_sync OF((Byte *compr, uLong comprLen,
52 Byte *uncompr, uLong uncomprLen)); 52 Byte *uncompr, uLong uncomprLen));
53void test_dict_deflate OF((Byte *compr, uLong comprLen)); 53void test_dict_deflate OF((Byte *compr, uLong comprLen));
54void test_dict_inflate OF((Byte *compr, uLong comprLen, 54void test_dict_inflate OF((Byte *compr, uLong comprLen,
55 Byte *uncompr, uLong uncomprLen)); 55 Byte *uncompr, uLong uncomprLen));
56int main OF((int argc, char *argv[])); 56int main OF((int argc, char *argv[]));
57 57
58/* =========================================================================== 58/* ===========================================================================
@@ -75,7 +75,7 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
75 75
76 if (strcmp((char*)uncompr, hello)) { 76 if (strcmp((char*)uncompr, hello)) {
77 fprintf(stderr, "bad uncompress\n"); 77 fprintf(stderr, "bad uncompress\n");
78 exit(1); 78 exit(1);
79 } else { 79 } else {
80 printf("uncompress(): %s\n", (char *)uncompr); 80 printf("uncompress(): %s\n", (char *)uncompr);
81 } 81 }
@@ -103,11 +103,11 @@ void test_gzio(out, in, uncompr, uncomprLen)
103 gzputc(file, 'h'); 103 gzputc(file, 'h');
104 if (gzputs(file, "ello") != 4) { 104 if (gzputs(file, "ello") != 4) {
105 fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err)); 105 fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
106 exit(1); 106 exit(1);
107 } 107 }
108 if (gzprintf(file, ", %s!", "hello") != 8) { 108 if (gzprintf(file, ", %s!", "hello") != 8) {
109 fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err)); 109 fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
110 exit(1); 110 exit(1);
111 } 111 }
112 gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ 112 gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
113 gzclose(file); 113 gzclose(file);
@@ -121,36 +121,36 @@ void test_gzio(out, in, uncompr, uncomprLen)
121 uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen); 121 uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen);
122 if (uncomprLen != len) { 122 if (uncomprLen != len) {
123 fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); 123 fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
124 exit(1); 124 exit(1);
125 } 125 }
126 if (strcmp((char*)uncompr, hello)) { 126 if (strcmp((char*)uncompr, hello)) {
127 fprintf(stderr, "bad gzread: %s\n", (char*)uncompr); 127 fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
128 exit(1); 128 exit(1);
129 } else { 129 } else {
130 printf("gzread(): %s\n", (char *)uncompr); 130 printf("gzread(): %s\n", (char *)uncompr);
131 } 131 }
132 132
133 pos = gzseek(file, -8L, SEEK_CUR); 133 pos = gzseek(file, -8L, SEEK_CUR);
134 if (pos != 6 || gztell(file) != pos) { 134 if (pos != 6 || gztell(file) != pos) {
135 fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n", 135 fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
136 (long)pos, (long)gztell(file)); 136 (long)pos, (long)gztell(file));
137 exit(1); 137 exit(1);
138 } 138 }
139 139
140 if (gzgetc(file) != ' ') { 140 if (gzgetc(file) != ' ') {
141 fprintf(stderr, "gzgetc error\n"); 141 fprintf(stderr, "gzgetc error\n");
142 exit(1); 142 exit(1);
143 } 143 }
144 144
145 gzgets(file, (char*)uncompr, uncomprLen); 145 gzgets(file, (char*)uncompr, uncomprLen);
146 uncomprLen = strlen((char*)uncompr); 146 uncomprLen = strlen((char*)uncompr);
147 if (uncomprLen != 6) { /* "hello!" */ 147 if (uncomprLen != 6) { /* "hello!" */
148 fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err)); 148 fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
149 exit(1); 149 exit(1);
150 } 150 }
151 if (strcmp((char*)uncompr, hello+7)) { 151 if (strcmp((char*)uncompr, hello+7)) {
152 fprintf(stderr, "bad gzgets after gzseek\n"); 152 fprintf(stderr, "bad gzgets after gzseek\n");
153 exit(1); 153 exit(1);
154 } else { 154 } else {
155 printf("gzgets() after gzseek: %s\n", (char *)uncompr); 155 printf("gzgets() after gzseek: %s\n", (char *)uncompr);
156 } 156 }
@@ -231,7 +231,7 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
231 231
232 if (strcmp((char*)uncompr, hello)) { 232 if (strcmp((char*)uncompr, hello)) {
233 fprintf(stderr, "bad inflate\n"); 233 fprintf(stderr, "bad inflate\n");
234 exit(1); 234 exit(1);
235 } else { 235 } else {
236 printf("inflate(): %s\n", (char *)uncompr); 236 printf("inflate(): %s\n", (char *)uncompr);
237 } 237 }
@@ -266,7 +266,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
266 CHECK_ERR(err, "deflate"); 266 CHECK_ERR(err, "deflate");
267 if (c_stream.avail_in != 0) { 267 if (c_stream.avail_in != 0) {
268 fprintf(stderr, "deflate not greedy\n"); 268 fprintf(stderr, "deflate not greedy\n");
269 exit(1); 269 exit(1);
270 } 270 }
271 271
272 /* Feed in already compressed data and switch to no compression: */ 272 /* Feed in already compressed data and switch to no compression: */
@@ -286,7 +286,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
286 err = deflate(&c_stream, Z_FINISH); 286 err = deflate(&c_stream, Z_FINISH);
287 if (err != Z_STREAM_END) { 287 if (err != Z_STREAM_END) {
288 fprintf(stderr, "deflate should report Z_STREAM_END\n"); 288 fprintf(stderr, "deflate should report Z_STREAM_END\n");
289 exit(1); 289 exit(1);
290 } 290 }
291 err = deflateEnd(&c_stream); 291 err = deflateEnd(&c_stream);
292 CHECK_ERR(err, "deflateEnd"); 292 CHECK_ERR(err, "deflateEnd");
@@ -316,7 +316,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
316 316
317 for (;;) { 317 for (;;) {
318 d_stream.next_out = uncompr; /* discard the output */ 318 d_stream.next_out = uncompr; /* discard the output */
319 d_stream.avail_out = (uInt)uncomprLen; 319 d_stream.avail_out = (uInt)uncomprLen;
320 err = inflate(&d_stream, Z_NO_FLUSH); 320 err = inflate(&d_stream, Z_NO_FLUSH);
321 if (err == Z_STREAM_END) break; 321 if (err == Z_STREAM_END) break;
322 CHECK_ERR(err, "large inflate"); 322 CHECK_ERR(err, "large inflate");
@@ -327,7 +327,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
327 327
328 if (d_stream.total_out != 2*uncomprLen + comprLen/2) { 328 if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
329 fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out); 329 fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
330 exit(1); 330 exit(1);
331 } else { 331 } else {
332 printf("large_inflate(): OK\n"); 332 printf("large_inflate(): OK\n");
333 } 333 }
@@ -407,7 +407,7 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
407 if (err != Z_DATA_ERROR) { 407 if (err != Z_DATA_ERROR) {
408 fprintf(stderr, "inflate should report DATA_ERROR\n"); 408 fprintf(stderr, "inflate should report DATA_ERROR\n");
409 /* Because of incorrect adler32 */ 409 /* Because of incorrect adler32 */
410 exit(1); 410 exit(1);
411 } 411 }
412 err = inflateEnd(&d_stream); 412 err = inflateEnd(&d_stream);
413 CHECK_ERR(err, "inflateEnd"); 413 CHECK_ERR(err, "inflateEnd");
@@ -433,7 +433,7 @@ void test_dict_deflate(compr, comprLen)
433 CHECK_ERR(err, "deflateInit"); 433 CHECK_ERR(err, "deflateInit");
434 434
435 err = deflateSetDictionary(&c_stream, 435 err = deflateSetDictionary(&c_stream,
436 (const Bytef*)dictionary, sizeof(dictionary)); 436 (const Bytef*)dictionary, sizeof(dictionary));
437 CHECK_ERR(err, "deflateSetDictionary"); 437 CHECK_ERR(err, "deflateSetDictionary");
438 438
439 dictId = c_stream.adler; 439 dictId = c_stream.adler;
@@ -446,7 +446,7 @@ void test_dict_deflate(compr, comprLen)
446 err = deflate(&c_stream, Z_FINISH); 446 err = deflate(&c_stream, Z_FINISH);
447 if (err != Z_STREAM_END) { 447 if (err != Z_STREAM_END) {
448 fprintf(stderr, "deflate should report Z_STREAM_END\n"); 448 fprintf(stderr, "deflate should report Z_STREAM_END\n");
449 exit(1); 449 exit(1);
450 } 450 }
451 err = deflateEnd(&c_stream); 451 err = deflateEnd(&c_stream);
452 CHECK_ERR(err, "deflateEnd"); 452 CHECK_ERR(err, "deflateEnd");
@@ -480,14 +480,14 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
480 for (;;) { 480 for (;;) {
481 err = inflate(&d_stream, Z_NO_FLUSH); 481 err = inflate(&d_stream, Z_NO_FLUSH);
482 if (err == Z_STREAM_END) break; 482 if (err == Z_STREAM_END) break;
483 if (err == Z_NEED_DICT) { 483 if (err == Z_NEED_DICT) {
484 if (d_stream.adler != dictId) { 484 if (d_stream.adler != dictId) {
485 fprintf(stderr, "unexpected dictionary"); 485 fprintf(stderr, "unexpected dictionary");
486 exit(1); 486 exit(1);
487 } 487 }
488 err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary, 488 err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
489 sizeof(dictionary)); 489 sizeof(dictionary));
490 } 490 }
491 CHECK_ERR(err, "inflate with dict"); 491 CHECK_ERR(err, "inflate with dict");
492 } 492 }
493 493
@@ -496,7 +496,7 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
496 496
497 if (strcmp((char*)uncompr, hello)) { 497 if (strcmp((char*)uncompr, hello)) {
498 fprintf(stderr, "bad inflate with dict\n"); 498 fprintf(stderr, "bad inflate with dict\n");
499 exit(1); 499 exit(1);
500 } else { 500 } else {
501 printf("inflate with dictionary: %s\n", (char *)uncompr); 501 printf("inflate with dictionary: %s\n", (char *)uncompr);
502 } 502 }
@@ -530,13 +530,13 @@ int main(argc, argv)
530 */ 530 */
531 if (compr == Z_NULL || uncompr == Z_NULL) { 531 if (compr == Z_NULL || uncompr == Z_NULL) {
532 printf("out of memory\n"); 532 printf("out of memory\n");
533 exit(1); 533 exit(1);
534 } 534 }
535 test_compress(compr, comprLen, uncompr, uncomprLen); 535 test_compress(compr, comprLen, uncompr, uncomprLen);
536 536
537 test_gzio((argc > 1 ? argv[1] : TESTFILE), 537 test_gzio((argc > 1 ? argv[1] : TESTFILE),
538 (argc > 2 ? argv[2] : TESTFILE), 538 (argc > 2 ? argv[2] : TESTFILE),
539 uncompr, (int)uncomprLen); 539 uncompr, (int)uncomprLen);
540 540
541 test_deflate(compr, comprLen); 541 test_deflate(compr, comprLen);
542 test_inflate(compr, comprLen, uncompr, uncomprLen); 542 test_inflate(compr, comprLen, uncompr, uncomprLen);
@@ -554,6 +554,5 @@ int main(argc, argv)
554 free(compr); 554 free(compr);
555 free(uncompr); 555 free(uncompr);
556 556
557 exit(0); 557 return 0;
558 return 0; /* to avoid warning */
559} 558}
diff --git a/gzio.c b/gzio.c
index 3337353..1f561ac 100644
--- a/gzio.c
+++ b/gzio.c
@@ -117,17 +117,19 @@ local gzFile gz_open (path, mode, fd)
117 if (*p == 'r') s->mode = 'r'; 117 if (*p == 'r') s->mode = 'r';
118 if (*p == 'w' || *p == 'a') s->mode = 'w'; 118 if (*p == 'w' || *p == 'a') s->mode = 'w';
119 if (*p >= '0' && *p <= '9') { 119 if (*p >= '0' && *p <= '9') {
120 level = *p - '0'; 120 level = *p - '0';
121 } else if (*p == 'f') { 121 } else if (*p == 'f') {
122 strategy = Z_FILTERED; 122 strategy = Z_FILTERED;
123 } else if (*p == 'h') { 123 } else if (*p == 'h') {
124 strategy = Z_HUFFMAN_ONLY; 124 strategy = Z_HUFFMAN_ONLY;
125 } else { 125 } else if (*p == 'R') {
126 *m++ = *p; /* copy the mode */ 126 strategy = Z_RLE;
127 } 127 } else {
128 *m++ = *p; /* copy the mode */
129 }
128 } while (*p++ && m != fmode + sizeof(fmode)); 130 } while (*p++ && m != fmode + sizeof(fmode));
129 if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL; 131 if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
130 132
131 if (s->mode == 'w') { 133 if (s->mode == 'w') {
132#ifdef NO_DEFLATE 134#ifdef NO_DEFLATE
133 err = Z_STREAM_ERROR; 135 err = Z_STREAM_ERROR;
@@ -168,17 +170,17 @@ local gzFile gz_open (path, mode, fd)
168 */ 170 */
169 fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], 171 fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
170 Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); 172 Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
171 s->startpos = 10L; 173 s->startpos = 10L;
172 /* We use 10L instead of ftell(s->file) to because ftell causes an 174 /* We use 10L instead of ftell(s->file) to because ftell causes an
173 * fflush on some systems. This version of the library doesn't use 175 * fflush on some systems. This version of the library doesn't use
174 * startpos anyway in write mode, so this initialization is not 176 * startpos anyway in write mode, so this initialization is not
175 * necessary. 177 * necessary.
176 */ 178 */
177 } else { 179 } else {
178 check_header(s); /* skip the .gz header */ 180 check_header(s); /* skip the .gz header */
179 s->startpos = (ftell(s->file) - s->stream.avail_in); 181 s->startpos = (ftell(s->file) - s->stream.avail_in);
180 } 182 }
181 183
182 return (gzFile)s; 184 return (gzFile)s;
183} 185}
184 186
@@ -223,11 +225,11 @@ int ZEXPORT gzsetparams (file, level, strategy)
223 /* Make room to allow flushing */ 225 /* Make room to allow flushing */
224 if (s->stream.avail_out == 0) { 226 if (s->stream.avail_out == 0) {
225 227
226 s->stream.next_out = s->outbuf; 228 s->stream.next_out = s->outbuf;
227 if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) { 229 if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
228 s->z_err = Z_ERRNO; 230 s->z_err = Z_ERRNO;
229 } 231 }
230 s->stream.avail_out = Z_BUFSIZE; 232 s->stream.avail_out = Z_BUFSIZE;
231 } 233 }
232 234
233 return deflateParams (&(s->stream), level, strategy); 235 return deflateParams (&(s->stream), level, strategy);
@@ -243,14 +245,14 @@ local int get_byte(s)
243{ 245{
244 if (s->z_eof) return EOF; 246 if (s->z_eof) return EOF;
245 if (s->stream.avail_in == 0) { 247 if (s->stream.avail_in == 0) {
246 errno = 0; 248 errno = 0;
247 s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file); 249 s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
248 if (s->stream.avail_in == 0) { 250 if (s->stream.avail_in == 0) {
249 s->z_eof = 1; 251 s->z_eof = 1;
250 if (ferror(s->file)) s->z_err = Z_ERRNO; 252 if (ferror(s->file)) s->z_err = Z_ERRNO;
251 return EOF; 253 return EOF;
252 } 254 }
253 s->stream.next_in = s->inbuf; 255 s->stream.next_in = s->inbuf;
254 } 256 }
255 s->stream.avail_in--; 257 s->stream.avail_in--;
256 return *(s->stream.next_in)++; 258 return *(s->stream.next_in)++;
@@ -292,7 +294,7 @@ local void check_header(s)
292 294
293 /* Peek ahead to check the gzip magic header */ 295 /* Peek ahead to check the gzip magic header */
294 if (s->stream.next_in[0] != gz_magic[0] || 296 if (s->stream.next_in[0] != gz_magic[0] ||
295 s->stream.next_in[1] != gz_magic[1]) { 297 s->stream.next_in[1] != gz_magic[1]) {
296 s->transparent = 1; 298 s->transparent = 1;
297 return; 299 return;
298 } 300 }
@@ -303,27 +305,27 @@ local void check_header(s)
303 method = get_byte(s); 305 method = get_byte(s);
304 flags = get_byte(s); 306 flags = get_byte(s);
305 if (method != Z_DEFLATED || (flags & RESERVED) != 0) { 307 if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
306 s->z_err = Z_DATA_ERROR; 308 s->z_err = Z_DATA_ERROR;
307 return; 309 return;
308 } 310 }
309 311
310 /* Discard time, xflags and OS code: */ 312 /* Discard time, xflags and OS code: */
311 for (len = 0; len < 6; len++) (void)get_byte(s); 313 for (len = 0; len < 6; len++) (void)get_byte(s);
312 314
313 if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */ 315 if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
314 len = (uInt)get_byte(s); 316 len = (uInt)get_byte(s);
315 len += ((uInt)get_byte(s))<<8; 317 len += ((uInt)get_byte(s))<<8;
316 /* len is garbage if EOF but the loop below will quit anyway */ 318 /* len is garbage if EOF but the loop below will quit anyway */
317 while (len-- != 0 && get_byte(s) != EOF) ; 319 while (len-- != 0 && get_byte(s) != EOF) ;
318 } 320 }
319 if ((flags & ORIG_NAME) != 0) { /* skip the original file name */ 321 if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
320 while ((c = get_byte(s)) != 0 && c != EOF) ; 322 while ((c = get_byte(s)) != 0 && c != EOF) ;
321 } 323 }
322 if ((flags & COMMENT) != 0) { /* skip the .gz file comment */ 324 if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
323 while ((c = get_byte(s)) != 0 && c != EOF) ; 325 while ((c = get_byte(s)) != 0 && c != EOF) ;
324 } 326 }
325 if ((flags & HEAD_CRC) != 0) { /* skip the header crc */ 327 if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
326 for (len = 0; len < 2; len++) (void)get_byte(s); 328 for (len = 0; len < 2; len++) (void)get_byte(s);
327 } 329 }
328 s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK; 330 s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
329} 331}
@@ -342,21 +344,21 @@ local int destroy (s)
342 TRYFREE(s->msg); 344 TRYFREE(s->msg);
343 345
344 if (s->stream.state != NULL) { 346 if (s->stream.state != NULL) {
345 if (s->mode == 'w') { 347 if (s->mode == 'w') {
346#ifdef NO_DEFLATE 348#ifdef NO_DEFLATE
347 err = Z_STREAM_ERROR; 349 err = Z_STREAM_ERROR;
348#else 350#else
349 err = deflateEnd(&(s->stream)); 351 err = deflateEnd(&(s->stream));
350#endif 352#endif
351 } else if (s->mode == 'r') { 353 } else if (s->mode == 'r') {
352 err = inflateEnd(&(s->stream)); 354 err = inflateEnd(&(s->stream));
353 } 355 }
354 } 356 }
355 if (s->file != NULL && fclose(s->file)) { 357 if (s->file != NULL && fclose(s->file)) {
356#ifdef ESPIPE 358#ifdef ESPIPE
357 if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */ 359 if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
358#endif 360#endif
359 err = Z_ERRNO; 361 err = Z_ERRNO;
360 } 362 }
361 if (s->z_err < 0) err = s->z_err; 363 if (s->z_err < 0) err = s->z_err;
362 364
@@ -391,69 +393,69 @@ int ZEXPORT gzread (file, buf, len)
391 393
392 while (s->stream.avail_out != 0) { 394 while (s->stream.avail_out != 0) {
393 395
394 if (s->transparent) { 396 if (s->transparent) {
395 /* Copy first the lookahead bytes: */ 397 /* Copy first the lookahead bytes: */
396 uInt n = s->stream.avail_in; 398 uInt n = s->stream.avail_in;
397 if (n > s->stream.avail_out) n = s->stream.avail_out; 399 if (n > s->stream.avail_out) n = s->stream.avail_out;
398 if (n > 0) { 400 if (n > 0) {
399 zmemcpy(s->stream.next_out, s->stream.next_in, n); 401 zmemcpy(s->stream.next_out, s->stream.next_in, n);
400 next_out += n; 402 next_out += n;
401 s->stream.next_out = next_out; 403 s->stream.next_out = next_out;
402 s->stream.next_in += n; 404 s->stream.next_in += n;
403 s->stream.avail_out -= n; 405 s->stream.avail_out -= n;
404 s->stream.avail_in -= n; 406 s->stream.avail_in -= n;
405 } 407 }
406 if (s->stream.avail_out > 0) { 408 if (s->stream.avail_out > 0) {
407 s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out, 409 s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out,
408 s->file); 410 s->file);
409 } 411 }
410 len -= s->stream.avail_out; 412 len -= s->stream.avail_out;
411 s->stream.total_in += (uLong)len; 413 s->stream.total_in += (uLong)len;
412 s->stream.total_out += (uLong)len; 414 s->stream.total_out += (uLong)len;
413 if (len == 0) s->z_eof = 1; 415 if (len == 0) s->z_eof = 1;
414 return (int)len; 416 return (int)len;
415 } 417 }
416 if (s->stream.avail_in == 0 && !s->z_eof) { 418 if (s->stream.avail_in == 0 && !s->z_eof) {
417 419
418 errno = 0; 420 errno = 0;
419 s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file); 421 s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
420 if (s->stream.avail_in == 0) { 422 if (s->stream.avail_in == 0) {
421 s->z_eof = 1; 423 s->z_eof = 1;
422 if (ferror(s->file)) { 424 if (ferror(s->file)) {
423 s->z_err = Z_ERRNO; 425 s->z_err = Z_ERRNO;
424 break; 426 break;
425 } 427 }
426 } 428 }
427 s->stream.next_in = s->inbuf; 429 s->stream.next_in = s->inbuf;
428 } 430 }
429 s->z_err = inflate(&(s->stream), Z_NO_FLUSH); 431 s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
430 432
431 if (s->z_err == Z_STREAM_END) { 433 if (s->z_err == Z_STREAM_END) {
432 /* Check CRC and original size */ 434 /* Check CRC and original size */
433 s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); 435 s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
434 start = s->stream.next_out; 436 start = s->stream.next_out;
435 437
436 if (getLong(s) != s->crc) { 438 if (getLong(s) != s->crc) {
437 s->z_err = Z_DATA_ERROR; 439 s->z_err = Z_DATA_ERROR;
438 } else { 440 } else {
439 (void)getLong(s); 441 (void)getLong(s);
440 /* The uncompressed length returned by above getlong() may 442 /* The uncompressed length returned by above getlong() may
441 * be different from s->stream.total_out) in case of 443 * be different from s->stream.total_out) in case of
442 * concatenated .gz files. Check for such files: 444 * concatenated .gz files. Check for such files:
443 */ 445 */
444 check_header(s); 446 check_header(s);
445 if (s->z_err == Z_OK) { 447 if (s->z_err == Z_OK) {
446 uLong total_in = s->stream.total_in; 448 uLong total_in = s->stream.total_in;
447 uLong total_out = s->stream.total_out; 449 uLong total_out = s->stream.total_out;
448 450
449 inflateReset(&(s->stream)); 451 inflateReset(&(s->stream));
450 s->stream.total_in = total_in; 452 s->stream.total_in = total_in;
451 s->stream.total_out = total_out; 453 s->stream.total_out = total_out;
452 s->crc = crc32(0L, Z_NULL, 0); 454 s->crc = crc32(0L, Z_NULL, 0);
453 } 455 }
454 } 456 }
455 } 457 }
456 if (s->z_err != Z_OK || s->z_eof) break; 458 if (s->z_err != Z_OK || s->z_eof) break;
457 } 459 }
458 s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); 460 s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
459 461
@@ -580,11 +582,11 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
580#else /* not ANSI C */ 582#else /* not ANSI C */
581 583
582int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, 584int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
583 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) 585 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
584 gzFile file; 586 gzFile file;
585 const char *format; 587 const char *format;
586 int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, 588 int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
587 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; 589 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
588{ 590{
589 char buf[Z_PRINTF_BUFSIZE]; 591 char buf[Z_PRINTF_BUFSIZE];
590 int len; 592 int len;
@@ -592,25 +594,25 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
592#ifdef NO_snprintf 594#ifdef NO_snprintf
593# ifdef HAS_sprintf_void 595# ifdef HAS_sprintf_void
594 sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, 596 sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
595 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 597 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
596 len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */ 598 len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */
597 if (len <= 0) return 0; 599 if (len <= 0) return 0;
598# else 600# else
599 len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, 601 len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
600 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 602 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
601 if (len <= 0 || len >= sizeof(buf)) 603 if (len <= 0 || len >= sizeof(buf))
602 return 0; 604 return 0;
603# endif 605# endif
604#else 606#else
605# ifdef HAS_snprintf_void 607# ifdef HAS_snprintf_void
606 snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, 608 snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
607 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 609 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
608 len = strlen(buf); 610 len = strlen(buf);
609 if (len <= 0) 611 if (len <= 0)
610 return 0; 612 return 0;
611# else 613# else
612 len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, 614 len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
613 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 615 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
614 if (len <= 0 || len >= sizeof(buf)) 616 if (len <= 0 || len >= sizeof(buf))
615 return 0; 617 return 0;
616# endif 618# endif
@@ -677,14 +679,14 @@ local int do_flush (file, flush)
677 if (done) break; 679 if (done) break;
678 s->z_err = deflate(&(s->stream), flush); 680 s->z_err = deflate(&(s->stream), flush);
679 681
680 /* Ignore the second of two consecutive flushes: */ 682 /* Ignore the second of two consecutive flushes: */
681 if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK; 683 if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
682 684
683 /* deflate has finished flushing only when it hasn't used up 685 /* deflate has finished flushing only when it hasn't used up
684 * all the available space in the output buffer: 686 * all the available space in the output buffer:
685 */ 687 */
686 done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END); 688 done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
687 689
688 if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break; 690 if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
689 } 691 }
690 return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; 692 return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
@@ -719,86 +721,86 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
719 gz_stream *s = (gz_stream*)file; 721 gz_stream *s = (gz_stream*)file;
720 722
721 if (s == NULL || whence == SEEK_END || 723 if (s == NULL || whence == SEEK_END ||
722 s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) { 724 s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
723 return -1L; 725 return -1L;
724 } 726 }
725 727
726 if (s->mode == 'w') { 728 if (s->mode == 'w') {
727#ifdef NO_DEFLATE 729#ifdef NO_DEFLATE
728 return -1L; 730 return -1L;
729#else 731#else
730 if (whence == SEEK_SET) { 732 if (whence == SEEK_SET) {
731 offset -= s->stream.total_in; 733 offset -= s->stream.total_in;
732 } 734 }
733 if (offset < 0) return -1L; 735 if (offset < 0) return -1L;
734 736
735 /* At this point, offset is the number of zero bytes to write. */ 737 /* At this point, offset is the number of zero bytes to write. */
736 if (s->inbuf == Z_NULL) { 738 if (s->inbuf == Z_NULL) {
737 s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */ 739 s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
738 if (s->inbuf == Z_NULL) return -1L; 740 if (s->inbuf == Z_NULL) return -1L;
739 zmemzero(s->inbuf, Z_BUFSIZE); 741 zmemzero(s->inbuf, Z_BUFSIZE);
740 } 742 }
741 while (offset > 0) { 743 while (offset > 0) {
742 uInt size = Z_BUFSIZE; 744 uInt size = Z_BUFSIZE;
743 if (offset < Z_BUFSIZE) size = (uInt)offset; 745 if (offset < Z_BUFSIZE) size = (uInt)offset;
744 746
745 size = gzwrite(file, s->inbuf, size); 747 size = gzwrite(file, s->inbuf, size);
746 if (size == 0) return -1L; 748 if (size == 0) return -1L;
747 749
748 offset -= size; 750 offset -= size;
749 } 751 }
750 return (z_off_t)s->stream.total_in; 752 return (z_off_t)s->stream.total_in;
751#endif 753#endif
752 } 754 }
753 /* Rest of function is for reading only */ 755 /* Rest of function is for reading only */
754 756
755 /* compute absolute position */ 757 /* compute absolute position */
756 if (whence == SEEK_CUR) { 758 if (whence == SEEK_CUR) {
757 offset += s->stream.total_out; 759 offset += s->stream.total_out;
758 } 760 }
759 if (offset < 0) return -1L; 761 if (offset < 0) return -1L;
760 762
761 if (s->transparent) { 763 if (s->transparent) {
762 /* map to fseek */ 764 /* map to fseek */
763 s->stream.avail_in = 0; 765 s->stream.avail_in = 0;
764 s->stream.next_in = s->inbuf; 766 s->stream.next_in = s->inbuf;
765 if (fseek(s->file, offset, SEEK_SET) < 0) return -1L; 767 if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
766 768
767 s->stream.total_in = s->stream.total_out = (uLong)offset; 769 s->stream.total_in = s->stream.total_out = (uLong)offset;
768 return offset; 770 return offset;
769 } 771 }
770 772
771 /* For a negative seek, rewind and use positive seek */ 773 /* For a negative seek, rewind and use positive seek */
772 if ((uLong)offset >= s->stream.total_out) { 774 if ((uLong)offset >= s->stream.total_out) {
773 offset -= s->stream.total_out; 775 offset -= s->stream.total_out;
774 } else if (gzrewind(file) < 0) { 776 } else if (gzrewind(file) < 0) {
775 return -1L; 777 return -1L;
776 } 778 }
777 /* offset is now the number of bytes to skip. */ 779 /* offset is now the number of bytes to skip. */
778 780
779 if (offset != 0 && s->outbuf == Z_NULL) { 781 if (offset != 0 && s->outbuf == Z_NULL) {
780 s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); 782 s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
781 if (s->outbuf == Z_NULL) return -1L; 783 if (s->outbuf == Z_NULL) return -1L;
782 } 784 }
783 while (offset > 0) { 785 while (offset > 0) {
784 int size = Z_BUFSIZE; 786 int size = Z_BUFSIZE;
785 if (offset < Z_BUFSIZE) size = (int)offset; 787 if (offset < Z_BUFSIZE) size = (int)offset;
786 788
787 size = gzread(file, s->outbuf, (uInt)size); 789 size = gzread(file, s->outbuf, (uInt)size);
788 if (size <= 0) return -1L; 790 if (size <= 0) return -1L;
789 offset -= size; 791 offset -= size;
790 } 792 }
791 return (z_off_t)s->stream.total_out; 793 return (z_off_t)s->stream.total_out;
792} 794}
793 795
794/* =========================================================================== 796/* ===========================================================================
795 Rewinds input file. 797 Rewinds input file.
796*/ 798*/
797int ZEXPORT gzrewind (file) 799int ZEXPORT gzrewind (file)
798 gzFile file; 800 gzFile file;
799{ 801{
800 gz_stream *s = (gz_stream*)file; 802 gz_stream *s = (gz_stream*)file;
801 803
802 if (s == NULL || s->mode != 'r') return -1; 804 if (s == NULL || s->mode != 'r') return -1;
803 805
804 s->z_err = Z_OK; 806 s->z_err = Z_OK;
@@ -806,10 +808,10 @@ int ZEXPORT gzrewind (file)
806 s->stream.avail_in = 0; 808 s->stream.avail_in = 0;
807 s->stream.next_in = s->inbuf; 809 s->stream.next_in = s->inbuf;
808 s->crc = crc32(0L, Z_NULL, 0); 810 s->crc = crc32(0L, Z_NULL, 0);
809 811
810 if (s->startpos == 0) { /* not a compressed file */ 812 if (s->startpos == 0) { /* not a compressed file */
811 rewind(s->file); 813 rewind(s->file);
812 return 0; 814 return 0;
813 } 815 }
814 816
815 (void) inflateReset(&s->stream); 817 (void) inflateReset(&s->stream);
@@ -835,7 +837,7 @@ int ZEXPORT gzeof (file)
835 gzFile file; 837 gzFile file;
836{ 838{
837 gz_stream *s = (gz_stream*)file; 839 gz_stream *s = (gz_stream*)file;
838 840
839 return (s == NULL || s->mode != 'r') ? 0 : s->z_eof; 841 return (s == NULL || s->mode != 'r') ? 0 : s->z_eof;
840} 842}
841 843
@@ -885,7 +887,7 @@ int ZEXPORT gzclose (file)
885 887
886 if (s->mode == 'w') { 888 if (s->mode == 'w') {
887#ifdef NO_DEFLATE 889#ifdef NO_DEFLATE
888 return Z_STREAM_ERROR; 890 return Z_STREAM_ERROR;
889#else 891#else
890 err = do_flush (file, Z_FINISH); 892 err = do_flush (file, Z_FINISH);
891 if (err != Z_OK) return destroy((gz_stream*)file); 893 if (err != Z_OK) return destroy((gz_stream*)file);
diff --git a/infback.c b/infback.c
index 46090ad..fdd7d89 100644
--- a/infback.c
+++ b/infback.c
@@ -603,11 +603,8 @@ void FAR *out_desc;
603int ZEXPORT inflateBackEnd(strm) 603int ZEXPORT inflateBackEnd(strm)
604z_stream FAR *strm; 604z_stream FAR *strm;
605{ 605{
606 struct inflate_state FAR *state;
607
608 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == Z_NULL) 606 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == Z_NULL)
609 return Z_STREAM_ERROR; 607 return Z_STREAM_ERROR;
610 state = (struct inflate_state FAR *)strm->state;
611 ZFREE(strm, strm->state); 608 ZFREE(strm, strm->state);
612 strm->state = Z_NULL; 609 strm->state = Z_NULL;
613 Tracev((stderr, "inflate: end\n")); 610 Tracev((stderr, "inflate: end\n"));
diff --git a/inffast.c b/inffast.c
index 8d145c2..59a8af8 100644
--- a/inffast.c
+++ b/inffast.c
@@ -133,7 +133,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
133 hold += (unsigned long)(PUP(in)) << bits; 133 hold += (unsigned long)(PUP(in)) << bits;
134 bits += 8; 134 bits += 8;
135 } 135 }
136 len += hold & ((1U << op) - 1); 136 len += (unsigned)hold & ((1U << op) - 1);
137 hold >>= op; 137 hold >>= op;
138 bits -= op; 138 bits -= op;
139 } 139 }
@@ -161,7 +161,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
161 bits += 8; 161 bits += 8;
162 } 162 }
163 } 163 }
164 dist += hold & ((1U << op) - 1); 164 dist += (unsigned)hold & ((1U << op) - 1);
165 hold >>= op; 165 hold >>= op;
166 bits -= op; 166 bits -= op;
167 Tracevv((stderr, "inflate: distance %u\n", dist)); 167 Tracevv((stderr, "inflate: distance %u\n", dist));
diff --git a/inflate.c b/inflate.c
index 36fbb75..1da2776 100644
--- a/inflate.c
+++ b/inflate.c
@@ -70,14 +70,14 @@
70 * - Changed many types to unsigned or unsigned short to avoid warnings 70 * - Changed many types to unsigned or unsigned short to avoid warnings
71 * - Added inflateCopy() function 71 * - Added inflateCopy() function
72 * 72 *
73 * 1.2.0 9 Mar 2003 73 * 1.2.0 9 Mar 2003
74 * - Changed inflateBack() interface to provide separate opaque descriptors 74 * - Changed inflateBack() interface to provide separate opaque descriptors
75 * for the in() and out() functions 75 * for the in() and out() functions
76 * - Changed inflateBack() argument and in_func typedef to swap the length 76 * - Changed inflateBack() argument and in_func typedef to swap the length
77 * and buffer address return values for the input function 77 * and buffer address return values for the input function
78 * - Check next_in and next_out for Z_NULL on entry to inflate() 78 * - Check next_in and next_out for Z_NULL on entry to inflate()
79 * 79 *
80 * Remainder of change history is in ChangeLog in zlib distribution. 80 * The history for versions past 1.2.0 are in ChangeLog in zlib distribution.
81 */ 81 */
82 82
83#include "zutil.h" 83#include "zutil.h"
diff --git a/inftrees.c b/inftrees.c
index 24ca089..a4e0745 100644
--- a/inftrees.c
+++ b/inftrees.c
@@ -9,7 +9,7 @@
9#define MAXBITS 15 9#define MAXBITS 15
10 10
11const char inflate_copyright[] = 11const char inflate_copyright[] =
12 " inflate 1.2.0 Copyright 1995-2003 Mark Adler "; 12 " inflate 1.2.0.1 Copyright 1995-2003 Mark Adler ";
13/* 13/*
14 If you use the zlib library in a product, an acknowledgment is welcome 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 15 in the documentation of your product. If for some reason you cannot
@@ -62,7 +62,7 @@ unsigned short FAR *work;
62 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 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 */ 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, 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, 73, 194}; 65 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 205, 64};
66 static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 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, 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, 68 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
diff --git a/minigzip.c b/minigzip.c
index 97b7c2d..3918cbc 100644
--- a/minigzip.c
+++ b/minigzip.c
@@ -1,6 +1,7 @@
1/* minigzip.c -- simulate gzip using the zlib compression library 1/* minigzip.c -- simulate gzip using the zlib compression library
2 * Copyright (C) 1995-2002 Jean-loup Gailly. 2 * Copyright (C) 1995-2002 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * Adapted for Z_RLE by Cosmin Truta, 2003.
4 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 5 */
5 6
6/* 7/*
@@ -147,7 +148,7 @@ int gz_compress_mmap(in, out)
147 if (buf_len <= 0) return Z_ERRNO; 148 if (buf_len <= 0) return Z_ERRNO;
148 149
149 /* Now do the actual mmap: */ 150 /* Now do the actual mmap: */
150 buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0); 151 buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
151 if (buf == (caddr_t)(-1)) return Z_ERRNO; 152 if (buf == (caddr_t)(-1)) return Z_ERRNO;
152 153
153 /* Compress the whole file at once: */ 154 /* Compress the whole file at once: */
@@ -179,8 +180,8 @@ void gz_uncompress(in, out)
179 if (len == 0) break; 180 if (len == 0) break;
180 181
181 if ((int)fwrite(buf, 1, (unsigned)len, out) != len) { 182 if ((int)fwrite(buf, 1, (unsigned)len, out) != len) {
182 error("failed fwrite"); 183 error("failed fwrite");
183 } 184 }
184 } 185 }
185 if (fclose(out)) error("failed fclose"); 186 if (fclose(out)) error("failed fclose");
186 187
@@ -260,10 +261,11 @@ void file_uncompress(file)
260 261
261 262
262/* =========================================================================== 263/* ===========================================================================
263 * Usage: minigzip [-d] [-f] [-h] [-1 to -9] [files...] 264 * Usage: minigzip [-d] [-f] [-h] [-r] [-1 to -9] [files...]
264 * -d : decompress 265 * -d : decompress
265 * -f : compress with Z_FILTERED 266 * -f : compress with Z_FILTERED
266 * -h : compress with Z_HUFFMAN_ONLY 267 * -h : compress with Z_HUFFMAN_ONLY
268 * -r : compress with Z_RLE
267 * -1 to -9 : compression level 269 * -1 to -9 : compression level
268 */ 270 */
269 271
@@ -282,16 +284,18 @@ int main(argc, argv)
282 284
283 while (argc > 0) { 285 while (argc > 0) {
284 if (strcmp(*argv, "-d") == 0) 286 if (strcmp(*argv, "-d") == 0)
285 uncompr = 1; 287 uncompr = 1;
286 else if (strcmp(*argv, "-f") == 0) 288 else if (strcmp(*argv, "-f") == 0)
287 outmode[3] = 'f'; 289 outmode[3] = 'f';
288 else if (strcmp(*argv, "-h") == 0) 290 else if (strcmp(*argv, "-h") == 0)
289 outmode[3] = 'h'; 291 outmode[3] = 'h';
292 else if (strcmp(*argv, "-r") == 0)
293 outmode[3] = 'R';
290 else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' && 294 else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
291 (*argv)[2] == 0) 295 (*argv)[2] == 0)
292 outmode[2] = (*argv)[1]; 296 outmode[2] = (*argv)[1];
293 else 297 else
294 break; 298 break;
295 argc--, argv++; 299 argc--, argv++;
296 } 300 }
297 if (argc == 0) { 301 if (argc == 0) {
@@ -315,6 +319,5 @@ int main(argc, argv)
315 } 319 }
316 } while (argv++, --argc); 320 } while (argv++, --argc);
317 } 321 }
318 exit(0); 322 return 0;
319 return 0; /* to avoid warning */
320} 323}
diff --git a/msdos/Makefile.bor b/msdos/Makefile.bor
new file mode 100644
index 0000000..4ad4061
--- /dev/null
+++ b/msdos/Makefile.bor
@@ -0,0 +1,109 @@
1# Makefile for zlib
2# Borland C++
3# Updated for zlib-1.2.x by Cosmin Truta, 15-Mar-2003.
4
5# To use, do "make -fmakefile.bor"
6# To compile in small model, set below: MODEL=s
7
8# WARNING: the small model is supported but only for small values of
9# MAX_WBITS and MAX_MEM_LEVEL. For example:
10# -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3
11# If you wish to reduce the memory requirements (default 256K for big
12# objects plus a few K), you can add to the LOC macro below:
13# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
14# See zconf.h for details about the memory requirements.
15
16# ------------ Turbo C++, Borland C++ ------------
17
18# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7)
19# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added
20# to the declaration of LOC here:
21LOC = $(LOCAL_ZLIB)
22
23# type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc.
24CPU_TYP = 0
25
26# memory model: one of s, m, c, l (small, medium, compact, large)
27MODEL=l
28
29# replace bcc with tcc for Turbo C++ 1.0, with bcc32 for the 32 bit version
30CC=bcc
31LD=bcc
32AR=tlib
33
34# compiler flags
35# replace "-O2" by "-O -G -a -d" for Turbo C++ 1.0
36CFLAGS=-O2 -Z -m$(MODEL) $(LOC)
37
38LDFLAGS=-m$(MODEL) -f-
39
40
41# variables
42ZLIB_LIB = zlib_$(MODEL).lib
43
44OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj
45OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
46OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj
47OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
48
49
50# targets
51all: $(ZLIB_LIB) example.exe minigzip.exe
52
53.c.obj:
54 $(CC) -c $(CFLAGS) $*.c
55
56adler32.obj: adler32.c zlib.h zconf.h
57
58compress.obj: compress.c zlib.h zconf.h
59
60crc32.obj: crc32.c zlib.h zconf.h crc32.h
61
62deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
63
64gzio.obj: gzio.c zutil.h zlib.h zconf.h
65
66infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
67 inffast.h inffixed.h
68
69inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
70 inffast.h
71
72inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
73 inffast.h inffixed.h
74
75inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
76
77trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
78
79uncompr.obj: uncompr.c zlib.h zconf.h
80
81zutil.obj: zutil.c zutil.h zlib.h zconf.h
82
83example.obj: example.c zlib.h zconf.h
84
85minigzip.obj: minigzip.c zlib.h zconf.h
86
87
88# the command line is cut to fit in the MS-DOS 128 byte limit:
89$(ZLIB_LIB): $(OBJ1) $(OBJ2)
90 -del $(ZLIB_LIB)
91 $(AR) $(ZLIB_LIB) $(OBJP1)
92 $(AR) $(ZLIB_LIB) $(OBJP2)
93
94example.exe: example.obj $(ZLIB_LIB)
95 $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB)
96
97minigzip.exe: minigzip.obj $(ZLIB_LIB)
98 $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB)
99
100test: example.exe minigzip.exe
101 example
102 echo hello world | minigzip | minigzip -d
103
104clean:
105 -del *.obj
106 -del *.exe
107 -del *.lib
108 -del zlib_$(MODEL).bak
109 -del foo.gz
diff --git a/msdos/Makefile.tc b/msdos/Makefile.tc
new file mode 100644
index 0000000..d0a7864
--- /dev/null
+++ b/msdos/Makefile.tc
@@ -0,0 +1,94 @@
1# Makefile for zlib
2# Turbo C 2.01, Turbo C++ 1.01
3# Updated for zlib-1.2.x by Cosmin Truta, 15-Mar-2003.
4
5# To use, do "make -fmakefile.tc"
6# To compile in small model, set below: MODEL=s
7
8# WARNING: the small model is supported but only for small values of
9# MAX_WBITS and MAX_MEM_LEVEL. For example:
10# -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
11# If you wish to reduce the memory requirements (default 256K for big
12# objects plus a few K), you can add to CFLAGS below:
13# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
14# See zconf.h for details about the memory requirements.
15
16# ------------ Turbo C 2.01, Turbo C++ 1.01 ------------
17MODEL=l
18CC=tcc
19LD=tcc
20AR=tlib
21# CFLAGS=-O2 -G -Z -m$(MODEL) -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
22CFLAGS=-O2 -G -Z -m$(MODEL)
23LDFLAGS=-m$(MODEL) -f-
24
25
26# variables
27ZLIB_LIB = zlib_$(MODEL).lib
28
29OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj
30OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
31OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj
32OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
33
34
35# targets
36all: $(ZLIB_LIB) example.exe minigzip.exe
37
38.c.obj:
39 $(CC) -c $(CFLAGS) $*.c
40
41adler32.obj: adler32.c zlib.h zconf.h
42
43compress.obj: compress.c zlib.h zconf.h
44
45crc32.obj: crc32.c zlib.h zconf.h crc32.h
46
47deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
48
49gzio.obj: gzio.c zutil.h zlib.h zconf.h
50
51infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
52 inffast.h inffixed.h
53
54inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
55 inffast.h
56
57inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
58 inffast.h inffixed.h
59
60inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
61
62trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
63
64uncompr.obj: uncompr.c zlib.h zconf.h
65
66zutil.obj: zutil.c zutil.h zlib.h zconf.h
67
68example.obj: example.c zlib.h zconf.h
69
70minigzip.obj: minigzip.c zlib.h zconf.h
71
72
73# the command line is cut to fit in the MS-DOS 128 byte limit:
74$(ZLIB_LIB): $(OBJ1) $(OBJ2)
75 -del $(ZLIB_LIB)
76 $(AR) $(ZLIB_LIB) $(OBJP1)
77 $(AR) $(ZLIB_LIB) $(OBJP2)
78
79example.exe: example.obj $(ZLIB_LIB)
80 $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB)
81
82minigzip.exe: minigzip.obj $(ZLIB_LIB)
83 $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB)
84
85test: example.exe minigzip.exe
86 example
87 echo hello world | minigzip | minigzip -d
88
89clean:
90 -del *.obj
91 -del *.exe
92 -del *.lib
93 -del zlib_$(MODEL).bak
94 -del foo.gz
diff --git a/old/msdos/Makefile.bor b/old/msdos/Makefile.bor
deleted file mode 100644
index f5651b4..0000000
--- a/old/msdos/Makefile.bor
+++ /dev/null
@@ -1,125 +0,0 @@
1# Makefile for zlib
2# Borland C++ ************ UNTESTED ***********
3
4# To use, do "make -fmakefile.bor"
5# To compile in small model, set below: MODEL=s
6
7# WARNING: the small model is supported but only for small values of
8# MAX_WBITS and MAX_MEM_LEVEL. For example:
9# -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3
10# If you wish to reduce the memory requirements (default 256K for big
11# objects plus a few K), you can add to the LOC macro below:
12# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
13# See zconf.h for details about the memory requirements.
14
15# ------------- Turbo C++, Borland C++ -------------
16
17# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7)
18# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added
19# to the declaration of LOC here:
20LOC = $(LOCAL_ZLIB)
21
22# Type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc.
23CPU_TYP = 0
24
25# Memory model: one of s, m, c, l (small, medium, compact, large)
26MODEL=l
27
28CC=bcc
29# replace bcc with tcc for Turbo C++ 1.0, with bcc32 for the 32 bit version
30LD=$(CC)
31AR=tlib
32
33# compiler flags
34CFLAGS=-O2 -Z -m$(MODEL) $(LOC)
35# replace "-O2" by "-O -G -a -d" for Turbo C++ 1.0
36
37LDFLAGS=-m$(MODEL)
38
39O=.obj
40
41# variables
42OBJ1 = adler32$(O) compress$(O) crc32$(O) gzio$(O) uncompr$(O) deflate$(O) \
43 trees$(O)
44OBJP1 = adler32$(O)+compress$(O)+crc32$(O)+gzio$(O)+uncompr$(O)+deflate$(O)+\
45 trees$(O)
46OBJ2 = zutil$(O) inflate$(O) infblock$(O) inftrees$(O) infcodes$(O) \
47 infutil$(O) inffast$(O)
48OBJP2 = zutil$(O)+inflate$(O)+infblock$(O)+inftrees$(O)+infcodes$(O)+\
49 infutil$(O)+inffast$(O)
50
51ZLIB_H = zlib.h zconf.h
52ZUTIL_H = zutil.h $(ZLIB_H)
53
54ZLIB_LIB = zlib_$(MODEL).lib
55
56all: test
57
58# individual dependencies and action rules:
59adler32.obj: adler32.c $(ZLIB_H)
60 $(CC) -c $(CFLAGS) $*.c
61
62compress.obj: compress.c $(ZLIB_H)
63 $(CC) -c $(CFLAGS) $*.c
64
65crc32.obj: crc32.c $(ZLIB_H)
66 $(CC) -c $(CFLAGS) $*.c
67
68deflate.obj: deflate.c deflate.h $(ZUTIL_H)
69 $(CC) -c $(CFLAGS) $*.c
70
71gzio.obj: gzio.c $(ZUTIL_H)
72 $(CC) -c $(CFLAGS) $*.c
73
74infblock.obj: infblock.c $(ZUTIL_H) infblock.h inftrees.h infcodes.h infutil.h
75 $(CC) -c $(CFLAGS) $*.c
76
77infcodes.obj: infcodes.c $(ZUTIL_H) inftrees.h infutil.h infcodes.h inffast.h
78 $(CC) -c $(CFLAGS) $*.c
79
80inflate.obj: inflate.c $(ZUTIL_H) infblock.h
81 $(CC) -c $(CFLAGS) $*.c
82
83inftrees.obj: inftrees.c $(ZUTIL_H) inftrees.h
84 $(CC) -c $(CFLAGS) $*.c
85
86infutil.obj: infutil.c $(ZUTIL_H) inftrees.h infutil.h
87 $(CC) -c $(CFLAGS) $*.c
88
89inffast.obj: inffast.c $(ZUTIL_H) inftrees.h infutil.h inffast.h
90 $(CC) -c $(CFLAGS) $*.c
91
92trees.obj: trees.c deflate.h $(ZUTIL_H)
93 $(CC) -c $(CFLAGS) $*.c
94
95uncompr.obj: uncompr.c $(ZLIB_H)
96 $(CC) -c $(CFLAGS) $*.c
97
98zutil.obj: zutil.c $(ZUTIL_H)
99 $(CC) -c $(CFLAGS) $*.c
100
101example.obj: example.c $(ZLIB_H)
102 $(CC) -c $(CFLAGS) $*.c
103
104minigzip.obj: minigzip.c $(ZLIB_H)
105 $(CC) -c $(CFLAGS) $*.c
106
107# we must cut the command line to fit in the MS/DOS 128 byte limit:
108$(ZLIB_LIB): $(OBJ1) $(OBJ2)
109 del $(ZLIB_LIB)
110 $(AR) $(ZLIB_LIB) +$(OBJP1)
111 $(AR) $(ZLIB_LIB) +$(OBJP2)
112
113example.exe: example.obj $(ZLIB_LIB)
114 $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB)
115
116minigzip.exe: minigzip.obj $(ZLIB_LIB)
117 $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB)
118
119test: example.exe minigzip.exe
120 example
121 echo hello world | minigzip | minigzip -d
122
123#clean:
124# del *.obj
125# del *.exe
diff --git a/old/msdos/Makefile.tc b/old/msdos/Makefile.tc
deleted file mode 100644
index 63e0550..0000000
--- a/old/msdos/Makefile.tc
+++ /dev/null
@@ -1,108 +0,0 @@
1# Makefile for zlib
2# TurboC 2.0
3
4# To use, do "make -fmakefile.tc"
5# To compile in small model, set below: MODEL=-ms
6
7# WARNING: the small model is supported but only for small values of
8# MAX_WBITS and MAX_MEM_LEVEL. For example:
9# -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
10# If you wish to reduce the memory requirements (default 256K for big
11# objects plus a few K), you can add to CFLAGS below:
12# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
13# See zconf.h for details about the memory requirements.
14
15# ------------- Turbo C 2.0 -------------
16MODEL=l
17# CFLAGS=-O2 -G -Z -m$(MODEL) -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
18CFLAGS=-O2 -G -Z -m$(MODEL)
19CC=tcc -I\tc\include
20LD=tcc -L\tc\lib
21AR=tlib
22LDFLAGS=-m$(MODEL) -f-
23O=.obj
24
25# variables
26OBJ1 = adler32$(O) compress$(O) crc32$(O) gzio$(O) uncompr$(O) deflate$(O) \
27 trees$(O)
28OBJP1 = adler32$(O)+compress$(O)+crc32$(O)+gzio$(O)+uncompr$(O)+deflate$(O)+\
29 trees$(O)
30OBJ2 = zutil$(O) inflate$(O) infblock$(O) inftrees$(O) infcodes$(O) \
31 infutil$(O) inffast$(O)
32OBJP2 = zutil$(O)+inflate$(O)+infblock$(O)+inftrees$(O)+infcodes$(O)+\
33 infutil$(O)+inffast$(O)
34
35ZLIB_H = zlib.h zconf.h
36ZUTIL_H = zutil.h $(ZLIB_H)
37
38ZLIB_LIB = zlib_$(MODEL).lib
39
40all: test
41
42adler32.obj: adler32.c $(ZLIB_H)
43 $(CC) -c $(CFLAGS) $*.c
44
45compress.obj: compress.c $(ZLIB_H)
46 $(CC) -c $(CFLAGS) $*.c
47
48crc32.obj: crc32.c $(ZLIB_H)
49 $(CC) -c $(CFLAGS) $*.c
50
51deflate.obj: deflate.c deflate.h $(ZUTIL_H)
52 $(CC) -c $(CFLAGS) $*.c
53
54gzio.obj: gzio.c $(ZUTIL_H)
55 $(CC) -c $(CFLAGS) $*.c
56
57infblock.obj: infblock.c $(ZUTIL_H) infblock.h inftrees.h infcodes.h infutil.h
58 $(CC) -c $(CFLAGS) $*.c
59
60infcodes.obj: infcodes.c $(ZUTIL_H) inftrees.h infutil.h infcodes.h inffast.h
61 $(CC) -c $(CFLAGS) $*.c
62
63inflate.obj: inflate.c $(ZUTIL_H) infblock.h
64 $(CC) -c $(CFLAGS) $*.c
65
66inftrees.obj: inftrees.c $(ZUTIL_H) inftrees.h
67 $(CC) -c $(CFLAGS) $*.c
68
69infutil.obj: infutil.c $(ZUTIL_H) inftrees.h infutil.h
70 $(CC) -c $(CFLAGS) $*.c
71
72inffast.obj: inffast.c $(ZUTIL_H) inftrees.h infutil.h inffast.h
73 $(CC) -c $(CFLAGS) $*.c
74
75trees.obj: trees.c deflate.h $(ZUTIL_H)
76 $(CC) -c $(CFLAGS) $*.c
77
78uncompr.obj: uncompr.c $(ZLIB_H)
79 $(CC) -c $(CFLAGS) $*.c
80
81zutil.obj: zutil.c $(ZUTIL_H)
82 $(CC) -c $(CFLAGS) $*.c
83
84example.obj: example.c $(ZLIB_H)
85 $(CC) -c $(CFLAGS) $*.c
86
87minigzip.obj: minigzip.c $(ZLIB_H)
88 $(CC) -c $(CFLAGS) $*.c
89
90# we must cut the command line to fit in the MS/DOS 128 byte limit:
91$(ZLIB_LIB): $(OBJ1) $(OBJ2)
92 del $(ZLIB_LIB)
93 $(AR) $(ZLIB_LIB) +$(OBJP1)
94 $(AR) $(ZLIB_LIB) +$(OBJP2)
95
96example.exe: example.obj $(ZLIB_LIB)
97 $(LD) $(LDFLAGS) -eexample.exe example.obj $(ZLIB_LIB)
98
99minigzip.exe: minigzip.obj $(ZLIB_LIB)
100 $(LD) $(LDFLAGS) -eminigzip.exe minigzip.obj $(ZLIB_LIB)
101
102test: example.exe minigzip.exe
103 example
104 echo hello world | minigzip | minigzip -d
105
106#clean:
107# del *.obj
108# del *.exe
diff --git a/trees.c b/trees.c
index f7f4a84..5f6d4af 100644
--- a/trees.c
+++ b/trees.c
@@ -1,6 +1,6 @@
1/* trees.c -- output deflated data using Huffman coding 1/* trees.c -- output deflated data using Huffman coding
2 * Copyright (C) 1995-2003 Jean-loup Gailly 2 * Copyright (C) 1995-2003 Jean-loup Gailly
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* 6/*
@@ -334,42 +334,42 @@ void gen_trees_header()
334 334
335 Assert (header != NULL, "Can't open trees.h"); 335 Assert (header != NULL, "Can't open trees.h");
336 fprintf(header, 336 fprintf(header,
337 "/* header created automatically with -DGEN_TREES_H */\n\n"); 337 "/* header created automatically with -DGEN_TREES_H */\n\n");
338 338
339 fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); 339 fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
340 for (i = 0; i < L_CODES+2; i++) { 340 for (i = 0; i < L_CODES+2; i++) {
341 fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, 341 fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
342 static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); 342 static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
343 } 343 }
344 344
345 fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); 345 fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
346 for (i = 0; i < D_CODES; i++) { 346 for (i = 0; i < D_CODES; i++) {
347 fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, 347 fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
348 static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); 348 static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
349 } 349 }
350 350
351 fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n"); 351 fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
352 for (i = 0; i < DIST_CODE_LEN; i++) { 352 for (i = 0; i < DIST_CODE_LEN; i++) {
353 fprintf(header, "%2u%s", _dist_code[i], 353 fprintf(header, "%2u%s", _dist_code[i],
354 SEPARATOR(i, DIST_CODE_LEN-1, 20)); 354 SEPARATOR(i, DIST_CODE_LEN-1, 20));
355 } 355 }
356 356
357 fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); 357 fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
358 for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { 358 for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
359 fprintf(header, "%2u%s", _length_code[i], 359 fprintf(header, "%2u%s", _length_code[i],
360 SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); 360 SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
361 } 361 }
362 362
363 fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); 363 fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
364 for (i = 0; i < LENGTH_CODES; i++) { 364 for (i = 0; i < LENGTH_CODES; i++) {
365 fprintf(header, "%1u%s", base_length[i], 365 fprintf(header, "%1u%s", base_length[i],
366 SEPARATOR(i, LENGTH_CODES-1, 20)); 366 SEPARATOR(i, LENGTH_CODES-1, 20));
367 } 367 }
368 368
369 fprintf(header, "local const int base_dist[D_CODES] = {\n"); 369 fprintf(header, "local const int base_dist[D_CODES] = {\n");
370 for (i = 0; i < D_CODES; i++) { 370 for (i = 0; i < D_CODES; i++) {
371 fprintf(header, "%5u%s", base_dist[i], 371 fprintf(header, "%5u%s", base_dist[i],
372 SEPARATOR(i, D_CODES-1, 10)); 372 SEPARATOR(i, D_CODES-1, 10));
373 } 373 }
374 374
375 fclose(header); 375 fclose(header);
@@ -930,39 +930,39 @@ void _tr_flush_block(s, buf, stored_len, eof)
930 /* Build the Huffman trees unless a stored block is forced */ 930 /* Build the Huffman trees unless a stored block is forced */
931 if (s->level > 0) { 931 if (s->level > 0) {
932 932
933 /* Check if the file is ascii or binary */ 933 /* Check if the file is ascii or binary */
934 if (s->data_type == Z_UNKNOWN) set_data_type(s); 934 if (s->data_type == Z_UNKNOWN) set_data_type(s);
935 935
936 /* Construct the literal and distance trees */ 936 /* Construct the literal and distance trees */
937 build_tree(s, (tree_desc *)(&(s->l_desc))); 937 build_tree(s, (tree_desc *)(&(s->l_desc)));
938 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, 938 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
939 s->static_len)); 939 s->static_len));
940 940
941 build_tree(s, (tree_desc *)(&(s->d_desc))); 941 build_tree(s, (tree_desc *)(&(s->d_desc)));
942 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, 942 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
943 s->static_len)); 943 s->static_len));
944 /* At this point, opt_len and static_len are the total bit lengths of 944 /* At this point, opt_len and static_len are the total bit lengths of
945 * the compressed block data, excluding the tree representations. 945 * the compressed block data, excluding the tree representations.
946 */ 946 */
947 947
948 /* Build the bit length tree for the above two trees, and get the index 948 /* Build the bit length tree for the above two trees, and get the index
949 * in bl_order of the last bit length code to send. 949 * in bl_order of the last bit length code to send.
950 */ 950 */
951 max_blindex = build_bl_tree(s); 951 max_blindex = build_bl_tree(s);
952 952
953 /* Determine the best encoding. Compute the block lengths in bytes. */ 953 /* Determine the best encoding. Compute the block lengths in bytes. */
954 opt_lenb = (s->opt_len+3+7)>>3; 954 opt_lenb = (s->opt_len+3+7)>>3;
955 static_lenb = (s->static_len+3+7)>>3; 955 static_lenb = (s->static_len+3+7)>>3;
956 956
957 Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", 957 Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
958 opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, 958 opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
959 s->last_lit)); 959 s->last_lit));
960 960
961 if (static_lenb <= opt_lenb) opt_lenb = static_lenb; 961 if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
962 962
963 } else { 963 } else {
964 Assert(buf != (char*)0, "lost buf"); 964 Assert(buf != (char*)0, "lost buf");
965 opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ 965 opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
966 } 966 }
967 967
968#ifdef FORCE_STORED 968#ifdef FORCE_STORED
@@ -1199,7 +1199,7 @@ local void copy_block(s, buf, len, header)
1199 s->last_eob_len = 8; /* enough lookahead for inflate */ 1199 s->last_eob_len = 8; /* enough lookahead for inflate */
1200 1200
1201 if (header) { 1201 if (header) {
1202 put_short(s, (ush)len); 1202 put_short(s, (ush)len);
1203 put_short(s, (ush)~len); 1203 put_short(s, (ush)~len);
1204#ifdef DEBUG 1204#ifdef DEBUG
1205 s->bits_sent += 2*16; 1205 s->bits_sent += 2*16;
diff --git a/win32/Makefile-dll.msc b/win32/Makefile-dll.msc
new file mode 100644
index 0000000..516f4cf
--- /dev/null
+++ b/win32/Makefile-dll.msc
@@ -0,0 +1,76 @@
1# Makefile for zlib.dll -- Microsoft (Visual) C.
2# Author: Cosmin Truta, 11-Mar-2003.
3#
4# Usage: nmake -f win32/Makefile-dll.msc
5
6CC = cl
7LD = cl
8CFLAGS = -nologo -MD -O2
9LDFLAGS = -nologo
10
11OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj \
12 inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
13
14# targets
15all: zlib.dll zlib.lib example.exe minigzip.exe
16
17zlib.lib: $(OBJS)
18 lib -out:$@ $(OBJS)
19
20zlib.dll: $(OBJS) win32/zlib.def
21 link -release -def:win32/zlib.def -dll -out:$@ $(OBJS)
22
23zlib.lib: zlib.dll
24
25example.exe: example.obj zlib.lib
26 $(LD) $(LDFLAGS) example.obj zlib.lib
27
28minigzip.exe: minigzip.obj zlib.lib
29 $(LD) $(LDFLAGS) minigzip.obj zlib.lib
30
31.c.obj:
32 $(CC) -c $(CFLAGS) $*.c
33
34adler32.obj: adler32.c zlib.h zconf.h
35
36compress.obj: compress.c zlib.h zconf.h
37
38crc32.obj: crc32.c zlib.h zconf.h crc32.h
39
40deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
41
42gzio.obj: gzio.c zutil.h zlib.h zconf.h
43
44infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
45 inffast.h inffixed.h
46
47inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
48 inffast.h
49
50inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
51 inffast.h inffixed.h
52
53inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
54
55trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
56
57uncompr.obj: uncompr.c zlib.h zconf.h
58
59zutil.obj: zutil.c zutil.h zlib.h zconf.h
60
61example.obj: example.c zlib.h zconf.h
62
63minigzip.obj: minigzip.c zlib.h zconf.h
64
65# testing
66test: example.exe minigzip.exe
67 example
68 echo hello world | minigzip | minigzip -d
69
70# cleanup
71clean:
72 del *.obj
73 del *.dll
74 del *.lib
75 del *.exp
76 del *.exe
diff --git a/win32/Makefile.bor b/win32/Makefile.bor
new file mode 100644
index 0000000..f1a1c46
--- /dev/null
+++ b/win32/Makefile.bor
@@ -0,0 +1,91 @@
1# Makefile for zlib
2# Borland C++ for Win32
3# Updated for zlib-1.2.x by Cosmin Truta, 11-Mar-2003.
4
5# Usage: "make -f win32/makefile.bor"
6
7# ------------ Borland C++ for Win32 ------------
8
9# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7)
10# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added
11# to the declaration of LOC here:
12LOC = $(LOCAL_ZLIB)
13
14CC = bcc32
15LD = bcc32
16AR = tlib
17CFLAGS = -O2 -d -k- $(LOC)
18LDFLAGS = $(LOC)
19
20
21# variables
22ZLIB_LIB = zlib.lib
23
24OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj
25OBJ2 = inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
26OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzio.obj+infback.obj
27OBJP2 = +inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj
28
29
30# targets
31all: $(ZLIB_LIB) example.exe minigzip.exe
32
33.c.obj:
34 $(CC) -c $(CFLAGS) $*.c
35
36adler32.obj: adler32.c zlib.h zconf.h
37
38compress.obj: compress.c zlib.h zconf.h
39
40crc32.obj: crc32.c zlib.h zconf.h crc32.h
41
42deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
43
44gzio.obj: gzio.c zutil.h zlib.h zconf.h
45
46infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
47 inffast.h inffixed.h
48
49inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
50 inffast.h
51
52inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
53 inffast.h inffixed.h
54
55inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
56
57trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
58
59uncompr.obj: uncompr.c zlib.h zconf.h
60
61zutil.obj: zutil.c zutil.h zlib.h zconf.h
62
63example.obj: example.c zlib.h zconf.h
64
65minigzip.obj: minigzip.c zlib.h zconf.h
66
67
68# For the sake of the old Borland make,
69# the command line is cut to fit in the MS-DOS 128 byte limit:
70$(ZLIB_LIB): $(OBJ1) $(OBJ2)
71 -del $(ZLIB_LIB)
72 $(AR) $(ZLIB_LIB) $(OBJP1)
73 $(AR) $(ZLIB_LIB) $(OBJP2)
74
75example.exe: example.obj $(ZLIB_LIB)
76 $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB)
77
78minigzip.exe: minigzip.obj $(ZLIB_LIB)
79 $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB)
80
81test: example.exe minigzip.exe
82 example
83 echo hello world | minigzip | minigzip -d
84
85clean:
86 -del *.obj
87 -del *.exe
88 -del *.lib
89 -del *.tds
90 -del zlib.bak
91 -del foo.gz
diff --git a/win32/Makefile.gcc b/win32/Makefile.gcc
new file mode 100644
index 0000000..7f9973b
--- /dev/null
+++ b/win32/Makefile.gcc
@@ -0,0 +1,105 @@
1# Makefile for zlib, derived from Makefile.dj2.
2# Modified for mingw32 by C. Spieler, 6/16/98.
3# Updated for zlib-1.2.x by Cosmin Truta, 11-Mar-2003.
4# Tested under Cygwin and MinGW.
5
6# Copyright (C) 1995-1998 Jean-loup Gailly.
7# For conditions of distribution and use, see copyright notice in zlib.h
8
9# To compile, or to compile and test, type:
10#
11# make -fmakefile.gcc; make test -fmakefile.gcc
12#
13# To install libz.a, zconf.h and zlib.h in the system directories, type:
14#
15# make install -fmakefile.gcc
16#
17
18LIB = libz.a
19SHAREDLIB = libz.so
20VER = 1.2.0
21
22CC = gcc
23#CFLAGS = -DDEBUG -MMD -g
24CFLAGS = $(LOC) -O3 -Wall
25
26AS = $(CC)
27ASFLAGS = $(LOC) -Wall
28
29LD = $(CC)
30LDFLAGS = $(LOC) -s
31
32AR = ar
33ARFLAGS = rcs
34
35CP = cp -fp
36# If GNU install is available, replace $(CP) with install.
37INSTALL = $(CP)
38RM = rm -f
39
40prefix = /usr/local
41exec_prefix = $(prefix)
42
43OBJS = adler32.o compress.o crc32.o deflate.o gzio.o infback.o \
44 inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
45
46# to use the asm code: make OBJA=match.o
47OBJA =
48
49TEST_OBJS = example.o minigzip.o
50
51all: $(LIB) example minigzip
52
53test: all
54 ./example
55 echo hello world | ./minigzip | ./minigzip -d
56
57.c.o:
58 $(CC) $(CFLAGS) -c -o $@ $<
59
60libz.a: $(OBJS)
61 $(AR) $(ARFLAGS) $@ $(OBJS)
62
63example: example.o $(LIB)
64 $(LD) -o $@ $< $(LIB)
65
66minigzip: minigzip.o $(LIB)
67 $(LD) -o $@ $< $(LIB)
68
69
70# INCLUDE_PATH and LIBRARY_PATH were set for [make] in djgpp.env .
71
72.PHONY : uninstall clean
73
74install: zlib.h zconf.h $(LIB)
75 -@if not exist $(INCLUDE_PATH)/nul mkdir $(INCLUDE_PATH)
76 -@if not exist $(LIBRARY_PATH)/nul mkdir $(LIBRARY_PATH)
77 $(INSTALL) zlib.h $(INCLUDE_PATH)
78 $(INSTALL) zconf.h $(INCLUDE_PATH)
79 $(INSTALL) $(LIB) $(LIBRARY_PATH)
80
81uninstall:
82 $(RM) $(INCLUDE_PATH)/zlib.h
83 $(RM) $(INCLUDE_PATH)/zconf.h
84 $(RM) $(LIBRARY_PATH)/libz.a
85
86clean:
87 $(RM) *.o
88 $(RM) *.exe
89 $(RM) libz.a
90 $(RM) foo.gz
91
92adler32.o: zlib.h zconf.h
93compress.o: zlib.h zconf.h
94crc32.o: crc32.h zlib.h zconf.h
95deflate.o: deflate.h zutil.h zlib.h zconf.h
96example.o: zlib.h zconf.h
97gzio.o: zutil.h zlib.h zconf.h
98inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
99inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
100infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
101inftrees.o: zutil.h zlib.h zconf.h inftrees.h
102minigzip.o: zlib.h zconf.h
103trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
104uncompr.o: zlib.h zconf.h
105zutil.o: zutil.h zlib.h zconf.h
diff --git a/win32/Makefile.msc b/win32/Makefile.msc
new file mode 100644
index 0000000..9760208
--- /dev/null
+++ b/win32/Makefile.msc
@@ -0,0 +1,69 @@
1# Makefile for (static) zlib -- Microsoft (Visual) C.
2# Author: Cosmin Truta, 11-Mar-2003.
3#
4# Usage: nmake -f win32/Makefile.msc
5
6CC = cl
7LD = cl
8CFLAGS = -nologo -MD -O2
9LDFLAGS = -nologo
10
11OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzio.obj infback.obj \
12 inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj
13
14# targets
15all: zlib.lib example.exe minigzip.exe
16
17zlib.lib: $(OBJS)
18 lib -out:$@ $(OBJS)
19
20example.exe: example.obj zlib.lib
21 $(LD) $(LDFLAGS) example.obj zlib.lib
22
23minigzip.exe: minigzip.obj zlib.lib
24 $(LD) $(LDFLAGS) minigzip.obj zlib.lib
25
26.c.obj:
27 $(CC) -c $(CFLAGS) $*.c
28
29adler32.obj: adler32.c zlib.h zconf.h
30
31compress.obj: compress.c zlib.h zconf.h
32
33crc32.obj: crc32.c zlib.h zconf.h crc32.h
34
35deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
36
37gzio.obj: gzio.c zutil.h zlib.h zconf.h
38
39infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
40 inffast.h inffixed.h
41
42inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
43 inffast.h
44
45inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \
46 inffast.h inffixed.h
47
48inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
49
50trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h
51
52uncompr.obj: uncompr.c zlib.h zconf.h
53
54zutil.obj: zutil.c zutil.h zlib.h zconf.h
55
56example.obj: example.c zlib.h zconf.h
57
58minigzip.obj: minigzip.c zlib.h zconf.h
59
60# testing
61test: example.exe minigzip.exe
62 example
63 echo hello world | minigzip | minigzip -d
64
65# cleanup
66clean:
67 del *.obj
68 del *.lib
69 del *.exe
diff --git a/contrib/minizip/zlibvc.def b/win32/zlib.def
index 7e9d60d..3b4b05a 100644
--- a/contrib/minizip/zlibvc.def
+++ b/win32/zlib.def
@@ -1,12 +1,5 @@
1LIBRARY "zlib" 1LIBRARY zlib.dll
2 2DESCRIPTION "zlib compression library for Windows"
3DESCRIPTION '"""zlib data compression library"""'
4
5
6VERSION 1.11
7
8
9HEAPSIZE 1048576,8192
10 3
11EXPORTS 4EXPORTS
12 adler32 @1 5 adler32 @1
@@ -50,25 +43,7 @@ EXPORTS
50 compress2 @39 43 compress2 @39
51 gzputs @40 44 gzputs @40
52 gzgets @41 45 gzgets @41
53 46; The following functions exist since zlib-1.2.0
54 unzOpen @61 47; deflateBound @42
55 unzClose @62 48; compressBound @43
56 unzGetGlobalInfo @63 49; etc.
57 unzGetCurrentFileInfo @64
58 unzGoToFirstFile @65
59 unzGoToNextFile @66
60 unzOpenCurrentFile @67
61 unzReadCurrentFile @68
62 unztell @70
63 unzeof @71
64 unzCloseCurrentFile @72
65 unzGetGlobalComment @73
66 unzStringFileNameCompare @74
67 unzLocateFile @75
68 unzGetLocalExtrafield @76
69
70 zipOpen @80
71 zipOpenNewFileInZip @81
72 zipWriteInFileInZip @82
73 zipCloseFileInZip @83
74 zipClose @84
diff --git a/zconf.h b/zconf.h
index 8ef845e..f3c4430 100644
--- a/zconf.h
+++ b/zconf.h
@@ -91,7 +91,7 @@
91 91
92#ifndef STDC 92#ifndef STDC
93# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 93# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
94# define const /* note: need a more gentle solution here */ 94# define const /* note: need a more gentle solution here */
95# endif 95# endif
96#endif 96#endif
97 97
@@ -101,7 +101,10 @@
101#endif 101#endif
102 102
103/* Old Borland C incorrectly complains about missing returns: */ 103/* Old Borland C incorrectly complains about missing returns: */
104#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) 104#if defined(__BORLANDC__) && (__BORLANDC__ < 0x460)
105# define NEED_DUMMY_RETURN
106#endif
107#if defined(__TURBOC__) && !defined(__BORLANDC__)
105# define NEED_DUMMY_RETURN 108# define NEED_DUMMY_RETURN
106#endif 109#endif
107 110
@@ -169,17 +172,24 @@
169# endif 172# endif
170#endif 173#endif
171 174
175#if defined(WIN32) && (!defined(ZLIB_WIN32_NODLL)) && (!defined(ZLIB_DLL))
176# define ZLIB_DLL
177#endif
178
172/* Compile with -DZLIB_DLL for Windows DLL support */ 179/* Compile with -DZLIB_DLL for Windows DLL support */
173#if defined(ZLIB_DLL) 180#if defined(ZLIB_DLL)
174# if defined(_WINDOWS) || defined(WINDOWS) 181# if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32)
175# ifdef FAR 182# ifndef WINAPIV
176# undef FAR 183# ifdef FAR
184# undef FAR
185# endif
186# include <windows.h>
177# endif 187# endif
178# include <windows.h>
179# define ZEXPORT WINAPI
180# ifdef WIN32 188# ifdef WIN32
189# define ZEXPORT WINAPI
181# define ZEXPORTVA WINAPIV 190# define ZEXPORTVA WINAPIV
182# else 191# else
192# define ZEXPORT WINAPI _export
183# define ZEXPORTVA FAR _cdecl _export 193# define ZEXPORTVA FAR _cdecl _export
184# endif 194# endif
185# endif 195# endif
@@ -187,7 +197,7 @@
187# if (__BORLANDC__ >= 0x0500) && defined (WIN32) 197# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
188# include <windows.h> 198# include <windows.h>
189# define ZEXPORT __declspec(dllexport) WINAPI 199# define ZEXPORT __declspec(dllexport) WINAPI
190# define ZEXPORTRVA __declspec(dllexport) WINAPIV 200# define ZEXPORTVA __declspec(dllexport) WINAPIV
191# else 201# else
192# if defined (_Windows) && defined (__DLL__) 202# if defined (_Windows) && defined (__DLL__)
193# define ZEXPORT _export 203# define ZEXPORT _export
@@ -246,9 +256,12 @@ typedef uLong FAR uLongf;
246 typedef Byte *voidp; 256 typedef Byte *voidp;
247#endif 257#endif
248 258
249#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ 259#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
250# include <sys/types.h> /* for off_t */ 260# include <sys/types.h> /* for off_t */
251# include <unistd.h> /* for SEEK_* and off_t */ 261# include <unistd.h> /* for SEEK_* and off_t */
262# ifdef VMS
263# include <unixio.h> /* for off_t */
264# endif
252# define z_off_t off_t 265# define z_off_t off_t
253#endif 266#endif
254#ifndef SEEK_SET 267#ifndef SEEK_SET
diff --git a/zconf.in.h b/zconf.in.h
index 8ef845e..f3c4430 100644
--- a/zconf.in.h
+++ b/zconf.in.h
@@ -91,7 +91,7 @@
91 91
92#ifndef STDC 92#ifndef STDC
93# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 93# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
94# define const /* note: need a more gentle solution here */ 94# define const /* note: need a more gentle solution here */
95# endif 95# endif
96#endif 96#endif
97 97
@@ -101,7 +101,10 @@
101#endif 101#endif
102 102
103/* Old Borland C incorrectly complains about missing returns: */ 103/* Old Borland C incorrectly complains about missing returns: */
104#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) 104#if defined(__BORLANDC__) && (__BORLANDC__ < 0x460)
105# define NEED_DUMMY_RETURN
106#endif
107#if defined(__TURBOC__) && !defined(__BORLANDC__)
105# define NEED_DUMMY_RETURN 108# define NEED_DUMMY_RETURN
106#endif 109#endif
107 110
@@ -169,17 +172,24 @@
169# endif 172# endif
170#endif 173#endif
171 174
175#if defined(WIN32) && (!defined(ZLIB_WIN32_NODLL)) && (!defined(ZLIB_DLL))
176# define ZLIB_DLL
177#endif
178
172/* Compile with -DZLIB_DLL for Windows DLL support */ 179/* Compile with -DZLIB_DLL for Windows DLL support */
173#if defined(ZLIB_DLL) 180#if defined(ZLIB_DLL)
174# if defined(_WINDOWS) || defined(WINDOWS) 181# if defined(_WINDOWS) || defined(WINDOWS) || defined(WIN32)
175# ifdef FAR 182# ifndef WINAPIV
176# undef FAR 183# ifdef FAR
184# undef FAR
185# endif
186# include <windows.h>
177# endif 187# endif
178# include <windows.h>
179# define ZEXPORT WINAPI
180# ifdef WIN32 188# ifdef WIN32
189# define ZEXPORT WINAPI
181# define ZEXPORTVA WINAPIV 190# define ZEXPORTVA WINAPIV
182# else 191# else
192# define ZEXPORT WINAPI _export
183# define ZEXPORTVA FAR _cdecl _export 193# define ZEXPORTVA FAR _cdecl _export
184# endif 194# endif
185# endif 195# endif
@@ -187,7 +197,7 @@
187# if (__BORLANDC__ >= 0x0500) && defined (WIN32) 197# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
188# include <windows.h> 198# include <windows.h>
189# define ZEXPORT __declspec(dllexport) WINAPI 199# define ZEXPORT __declspec(dllexport) WINAPI
190# define ZEXPORTRVA __declspec(dllexport) WINAPIV 200# define ZEXPORTVA __declspec(dllexport) WINAPIV
191# else 201# else
192# if defined (_Windows) && defined (__DLL__) 202# if defined (_Windows) && defined (__DLL__)
193# define ZEXPORT _export 203# define ZEXPORT _export
@@ -246,9 +256,12 @@ typedef uLong FAR uLongf;
246 typedef Byte *voidp; 256 typedef Byte *voidp;
247#endif 257#endif
248 258
249#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ 259#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
250# include <sys/types.h> /* for off_t */ 260# include <sys/types.h> /* for off_t */
251# include <unistd.h> /* for SEEK_* and off_t */ 261# include <unistd.h> /* for SEEK_* and off_t */
262# ifdef VMS
263# include <unixio.h> /* for off_t */
264# endif
252# define z_off_t off_t 265# define z_off_t off_t
253#endif 266#endif
254#ifndef SEEK_SET 267#ifndef SEEK_SET
diff --git a/zlib.h b/zlib.h
index c514256..2d239a2 100644
--- a/zlib.h
+++ b/zlib.h
@@ -1,5 +1,5 @@
1/* zlib.h -- interface of the 'zlib' general purpose compression library 1/* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 1.2.0, March 9th, 2003 2 version 1.2.0.1, March 17th, 2003
3 3
4 Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler 4 Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler
5 5
@@ -37,7 +37,7 @@
37extern "C" { 37extern "C" {
38#endif 38#endif
39 39
40#define ZLIB_VERSION "1.2.0" 40#define ZLIB_VERSION "1.2.0.1"
41 41
42/* 42/*
43 The 'zlib' compression library provides in-memory compression and 43 The 'zlib' compression library provides in-memory compression and
@@ -165,6 +165,7 @@ typedef z_stream FAR *z_streamp;
165 165
166#define Z_FILTERED 1 166#define Z_FILTERED 1
167#define Z_HUFFMAN_ONLY 2 167#define Z_HUFFMAN_ONLY 2
168#define Z_RLE 3
168#define Z_DEFAULT_STRATEGY 0 169#define Z_DEFAULT_STRATEGY 0
169/* compression strategy; see deflateInit2() below for details */ 170/* compression strategy; see deflateInit2() below for details */
170 171
@@ -461,14 +462,16 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
461 462
462 The strategy parameter is used to tune the compression algorithm. Use the 463 The strategy parameter is used to tune the compression algorithm. Use the
463 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 464 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
464 filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no 465 filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
465 string match). Filtered data consists mostly of small values with a 466 string match), or Z_RLE to limit match distances to one (run-length
466 somewhat random distribution. In this case, the compression algorithm is 467 encoding). Filtered data consists mostly of small values with a somewhat
467 tuned to compress them better. The effect of Z_FILTERED is to force more 468 random distribution. In this case, the compression algorithm is tuned to
468 Huffman coding and less string matching; it is somewhat intermediate 469 compress them better. The effect of Z_FILTERED is to force more Huffman
469 between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects 470 coding and less string matching; it is somewhat intermediate between
470 the compression ratio but not the correctness of the compressed output even 471 Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
471 if it is not set appropriately. 472 Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
473 parameter only affects the compression ratio but not the correctness of the
474 compressed output even if it is not set appropriately.
472 475
473 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 476 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
474 memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid 477 memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
@@ -843,8 +846,9 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
843 Opens a gzip (.gz) file for reading or writing. The mode parameter 846 Opens a gzip (.gz) file for reading or writing. The mode parameter
844 is as in fopen ("rb" or "wb") but can also include a compression level 847 is as in fopen ("rb" or "wb") but can also include a compression level
845 ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for 848 ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
846 Huffman only compression as in "wb1h". (See the description 849 Huffman only compression as in "wb1h", or 'R' for run-length encoding
847 of deflateInit2 for more information about the strategy parameter.) 850 as in "wb1R". (See the description of deflateInit2 for more information
851 about the strategy parameter.)
848 852
849 gzopen can be used to read a file which is not in gzip format; in this 853 gzopen can be used to read a file which is not in gzip format; in this
850 case gzread will directly read from the file without decompression. 854 case gzread will directly read from the file without decompression.
@@ -896,9 +900,12 @@ ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
896 Converts, formats, and writes the args to the compressed file under 900 Converts, formats, and writes the args to the compressed file under
897 control of the format string, as in fprintf. gzprintf returns the number of 901 control of the format string, as in fprintf. gzprintf returns the number of
898 uncompressed bytes actually written (0 in case of error). The number of 902 uncompressed bytes actually written (0 in case of error). The number of
899 uncompressed bytes written is limited to 4095. The caller should assure 903 uncompressed bytes written is limited to 4095. The caller should assure that
900 that this limit is not exceeded, since otherwise a buffer overflow may 904 this limit is not exceeded. If it is exceeded, then either gzprintf() will
901 result. 905 return an error (0) with nothing written, or there will be a buffer overflow
906 with unpredictable consequences. The latter is possible only if zlib was
907 compiled with insecure variants of printf, i.e. sprintf() or vsprintf()
908 because the secure snprintf() or vsnprintf() functions were not available.
902*/ 909*/
903 910
904ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); 911ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
diff --git a/zutil.h b/zutil.h
index d9c36ab..91083ed 100644
--- a/zutil.h
+++ b/zutil.h
@@ -150,6 +150,30 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
150 150
151 /* functions */ 151 /* functions */
152 152
153#ifdef __STDC_VERSION__
154# if __STDC_VERSION__ >= 199901L
155# ifndef STDC99
156# define STDC99
157# endif
158# endif
159#endif
160#if !defined(STDC99) && !(defined(__TURBOC__) && __TURBOC__ >= 0x550) && !defined(VSNPRINTF_DEFINED)
161# ifdef MSDOS
162 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
163 but for now we just assume it doesn't. */
164# define NO_vsnprintf
165# endif
166# ifdef WIN32
167 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
168# if !defined(vsnprintf) && !defined(__TURBOC__)
169# define vsnprintf _vsnprintf
170# endif
171# endif
172# ifdef __TURBOC__
173# define NO_vsnprintf
174# endif
175#endif
176
153#ifdef HAVE_STRERROR 177#ifdef HAVE_STRERROR
154 extern char *strerror OF((int)); 178 extern char *strerror OF((int));
155# define zstrerror(errnum) strerror(errnum) 179# define zstrerror(errnum) strerror(errnum)