update dev300-m58
[ooovba.git] / zlib / zlib-1.1.4.patch
blob34f2fdde44ee6a9570c7d6d66286c826b1edb245
1 --- misc/zlib-1.1.4/makefile.mk Fri Mar 14 10:17:06 2008
2 +++ misc/build/zlib-1.1.4/makefile.mk Fri Mar 14 10:16:56 2008
3 @@ -1 +1,79 @@
4 -dummy
5 +#*************************************************************************
6 +#
7 +# $RCSfile: makefile.mk,v $
8 +#
9 +# $Revision: 1.8 $
11 +# last change: $Author: mtg $ $Date: 2000/11/09 10:19:32 $
13 +# Copyright according the GNU Public License.
15 +#*************************************************************************
17 +PRJ=..$/..$/..$/..
19 +PRJNAME=zlib
20 +TARGET=zlib
21 +LIBTARGET=NO
22 +EXTERNAL_WARNINGS_NOT_ERRORS=TRUE
24 +# --- Settings -----------------------------------------------------
26 +.INCLUDE : settings.mk
28 +# --- Files --------------------------------------------------------
30 +INCEXT=contrib$/minizip
32 +SLOFILES= $(SLO)$/adler32.obj \
33 + $(SLO)$/compress.obj \
34 + $(SLO)$/deflate.obj \
35 + $(SLO)$/crc32.obj \
36 + $(SLO)$/infblock.obj \
37 + $(SLO)$/infcodes.obj \
38 + $(SLO)$/inffast.obj \
39 + $(SLO)$/inflate.obj \
40 + $(SLO)$/inftrees.obj \
41 + $(SLO)$/infutil.obj \
42 + $(SLO)$/trees.obj \
43 + $(SLO)$/zutil.obj \
44 + $(SLO)$/unzip.obj \
45 + $(SLO)$/ioapi.obj
48 +LIB1TARGET=$(SLB)$/$(TARGET).lib
49 +LIB1ARCHIV=$(LB)$/lib$(TARGET).a
50 +LIB1OBJFILES=$(SLOFILES)
52 +.IF "$(BUILD_X64)"!=""
53 +SLOFILES_X64= $(SLO_X64)$/adler32.obj \
54 + $(SLO_X64)$/compress.obj \
55 + $(SLO_X64)$/deflate.obj \
56 + $(SLO_X64)$/crc32.obj \
57 + $(SLO_X64)$/infblock.obj \
58 + $(SLO_X64)$/infcodes.obj \
59 + $(SLO_X64)$/inffast.obj \
60 + $(SLO_X64)$/inflate.obj \
61 + $(SLO_X64)$/inftrees.obj \
62 + $(SLO_X64)$/infutil.obj \
63 + $(SLO_X64)$/trees.obj \
64 + $(SLO_X64)$/zutil.obj \
65 + $(SLO_X64)$/unzip.obj \
66 + $(SLO)$/ioapi.obj
68 +LIB1TARGET_X64=$(SLB_X64)$/$(TARGET).lib
69 +LIB1OBJFILES_X64=$(SLOFILES_X64)
70 +.ENDIF # "$(BUILD_X64)"!=""
73 +# --- Targets ------------------------------------------------------
75 +$(MISC)$/%.c : contrib$/minizip$/%.c
76 + @echo ------------------------------
77 + @echo Making: $@
78 + @$(COPY) $< $@
80 +.INCLUDE : set_wntx64.mk
81 +.INCLUDE : target.mk
82 +.INCLUDE : tg_wntx64.mk
84 --- misc/zlib-1.1.4/zconf.h Mon Mar 11 14:16:01 2002
85 +++ misc/build/zlib-1.1.4/zconf.h Fri Mar 14 10:15:45 2008
86 @@ -12,6 +12,12 @@
87 * If you *really* need a unique prefix for all types and library functions,
88 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
90 +/*
91 + * we need the prefix to get the same names as in 1.1.3
92 +*/
94 +#define Z_PREFIX
96 #ifdef Z_PREFIX
97 # define deflateInit_ z_deflateInit_
98 # define deflate z_deflate
99 @@ -36,10 +42,26 @@
100 # define crc32 z_crc32
101 # define get_crc_table z_get_crc_table
103 +# define inflate_blocks z_inflate_blocks
104 +# define inflate_blocks_new z_inflate_blocks_new
105 +# define inflate_blocks_free z_inflate_blocks_free
106 +# define inflate_blocks_reset z_inflate_blocks_reset
107 +# define inflate_codes_free z_inflate_codes_free
108 +# define inflate_codes z_inflate_codes
109 +# define inflate_fast z_inflate_fast
110 +# define inflate_flush z_inflate_flush
111 +# define inflate_mask z_inflate_mask
112 +# define inflate_set_dictionary z_inflate_set_dictionary
113 +# define inflate_copyright z_inflate_copyright
114 +# define inflate_trees_bits z_inflate_trees_bits
115 +# define inflate_trees_dynamic z_inflate_trees_dynamic
116 +# define inflate_trees_fixed z_inflate_trees_fixed
117 +# define inflate_trees_free z_inflate_trees_free
119 # define Byte z_Byte
120 # define uInt z_uInt
121 # define uLong z_uLong
122 -# define Bytef z_Bytef
123 +# define Bytef z_Bytef
124 # define charf z_charf
125 # define intf z_intf
126 # define uIntf z_uIntf
127 --- misc/zlib-1.1.4/zlib.h Mon Mar 11 14:56:38 2002
128 +++ misc/build/zlib-1.1.4/zlib.h Fri Mar 14 10:15:45 2008
129 @@ -27,7 +27,6 @@
130 Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
131 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
134 #ifndef _ZLIB_H
135 #define _ZLIB_H
137 @@ -168,7 +167,9 @@
139 /* basic functions */
141 +#if !defined(ZUTIL_PROTOS_OFF)
142 ZEXTERN const char * ZEXPORT zlibVersion OF((void));
143 +#endif
144 /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
145 If the first character differs, the library code actually used is
146 not compatible with the zlib.h header file used by the application.
147 @@ -882,7 +883,9 @@
148 struct internal_state {int dummy;}; /* hack for buggy compilers */
149 #endif
151 +#if !defined(ZUTIL_PROTOS_OFF)
152 ZEXTERN const char * ZEXPORT zError OF((int err));
153 +#endif
154 ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
155 ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
157 --- misc/zlib-1.1.4/zutil.c Mon Mar 11 14:16:01 2002
158 +++ misc/build/zlib-1.1.4/zutil.c Fri Mar 14 10:15:45 2008
159 @@ -5,6 +5,9 @@
161 /* @(#) $Id$ */
163 +#ifdef MACOSX
164 +#define ZUTIL_PROTOS_OFF
165 +#endif
166 #include "zutil.h"
168 struct internal_state {int dummy;}; /* for buggy compilers */
169 --- misc/zlib-1.1.4/contrib/minizip/unzip.c 1998-06-15 17:34:20.000000000 +0200
170 +++ misc/build/zlib-1.1.4/contrib/minizip/unzip.c 2009-07-17 10:15:05.156250000 +0200
171 @@ -1,9 +1,39 @@
172 -/* unzip.c -- IO on .zip files using zlib
173 - Version 0.15 beta, Mar 19th, 1998,
174 +/* unzip.c -- IO for uncompress .zip files using zlib
175 + Version 1.01e, February 12th, 2005
177 + Copyright (C) 1998-2005 Gilles Vollant
179 Read unzip.h for more info
182 +/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
183 +compatibility with older software. The following is from the original crypt.c. Code
184 +woven in by Terry Thorsen 1/2003.
187 + Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
189 + See the accompanying file LICENSE, version 2000-Apr-09 or later
190 + (the contents of which are also included in zip.h) for terms of use.
191 + If, for some reason, all these files are missing, the Info-ZIP license
192 + also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
195 + crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
197 + The encryption/decryption parts of this source code (as opposed to the
198 + non-echoing password parts) were originally written in Europe. The
199 + whole source package can be freely distributed, including from the USA.
200 + (Prior to January 2000, re-export from the US was a violation of US law.)
201 + */
204 + This encryption code is a direct transcription of the algorithm from
205 + Roger Schlafly, described by Phil Katz in the file appnote.txt. This
206 + file (appnote.txt) is distributed with the PKZIP program (even in the
207 + version without encryption capabilities).
208 + */
211 #include <stdio.h>
212 #include <stdlib.h>
213 @@ -29,10 +59,10 @@
214 /* compile with -Dlocal if your debugger can't find static symbols */
218 -#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \
219 - !defined(CASESENSITIVITYDEFAULT_NO)
220 -#define CASESENSITIVITYDEFAULT_NO
221 +#ifndef CASESENSITIVITYDEFAULT_NO
222 +# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
223 +# define CASESENSITIVITYDEFAULT_NO
224 +# endif
225 #endif
228 @@ -55,22 +85,10 @@
229 #define SIZEZIPLOCALHEADER (0x1e)
232 -/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
234 -#ifndef SEEK_CUR
235 -#define SEEK_CUR 1
236 -#endif
238 -#ifndef SEEK_END
239 -#define SEEK_END 2
240 -#endif
242 -#ifndef SEEK_SET
243 -#define SEEK_SET 0
244 -#endif
246 const char unz_copyright[] =
247 - " unzip 0.15 Copyright 1998 Gilles Vollant ";
248 + " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
250 /* unz_file_info_interntal contain internal info about a file in zipfile*/
251 typedef struct unz_file_info_internal_s
252 @@ -83,23 +101,25 @@
253 when reading and decompress it */
254 typedef struct
256 - char *read_buffer; /* internal buffer for compressed data */
257 - z_stream stream; /* zLib stream structure for inflate */
258 + char *read_buffer; /* internal buffer for compressed data */
259 + z_stream stream; /* zLib stream structure for inflate */
261 - uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
262 - uLong stream_initialised; /* flag set if stream structure is initialised*/
263 + uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
264 + uLong stream_initialised; /* flag set if stream structure is initialised*/
266 - uLong offset_local_extrafield;/* offset of the local extra field */
267 - uInt size_local_extrafield;/* size of the local extra field */
268 - uLong pos_local_extrafield; /* position in the local extra field in read*/
270 - uLong crc32; /* crc32 of all data uncompressed */
271 - uLong crc32_wait; /* crc32 we must obtain after decompress all */
272 - uLong rest_read_compressed; /* number of byte to be decompressed */
273 - uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
274 - FILE* file; /* io structore of the zipfile */
275 - uLong compression_method; /* compression method (0==store) */
276 - uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
277 + uLong offset_local_extrafield;/* offset of the local extra field */
278 + uInt size_local_extrafield;/* size of the local extra field */
279 + uLong pos_local_extrafield; /* position in the local extra field in read*/
281 + uLong crc32; /* crc32 of all data uncompressed */
282 + uLong crc32_wait; /* crc32 we must obtain after decompress all */
283 + uLong rest_read_compressed; /* number of byte to be decompressed */
284 + uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
285 + zlib_filefunc_def z_filefunc;
286 + voidpf filestream; /* io structore of the zipfile */
287 + uLong compression_method; /* compression method (0==store) */
288 + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
289 + int raw;
290 } file_in_zip_read_info_s;
293 @@ -107,25 +127,35 @@
295 typedef struct
297 - FILE* file; /* io structore of the zipfile */
298 - unz_global_info gi; /* public global information */
299 - uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
300 - uLong num_file; /* number of the current file in the zipfile*/
301 - uLong pos_in_central_dir; /* pos of the current file in the central dir*/
302 - uLong current_file_ok; /* flag about the usability of the current file*/
303 - uLong central_pos; /* position of the beginning of the central dir*/
305 - uLong size_central_dir; /* size of the central directory */
306 - uLong offset_central_dir; /* offset of start of central directory with
307 - respect to the starting disk number */
308 + zlib_filefunc_def z_filefunc;
309 + voidpf filestream; /* io structore of the zipfile */
310 + unz_global_info gi; /* public global information */
311 + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
312 + uLong num_file; /* number of the current file in the zipfile*/
313 + uLong pos_in_central_dir; /* pos of the current file in the central dir*/
314 + uLong current_file_ok; /* flag about the usability of the current file*/
315 + uLong central_pos; /* position of the beginning of the central dir*/
317 + uLong size_central_dir; /* size of the central directory */
318 + uLong offset_central_dir; /* offset of start of central directory with
319 + respect to the starting disk number */
321 - unz_file_info cur_file_info; /* public info about the current file in zip*/
322 - unz_file_info_internal cur_file_info_internal; /* private info about it*/
323 + unz_file_info cur_file_info; /* public info about the current file in zip*/
324 + unz_file_info_internal cur_file_info_internal; /* private info about it*/
325 file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
326 - file if we are decompressing it */
327 + file if we are decompressing it */
328 + int encrypted;
329 +# ifndef NOUNCRYPT
330 + unsigned long keys[3]; /* keys defining the pseudo-random sequence */
331 + const unsigned long* pcrc_32_tab;
332 +# endif
333 } unz_s;
336 +#ifndef NOUNCRYPT
337 +#include "crypt.h"
338 +#endif
340 /* ===========================================================================
341 Read a byte from a gz_stream; update next_in and avail_in. Return EOF
342 for end of file.
343 @@ -133,12 +163,18 @@
347 -local int unzlocal_getByte(fin,pi)
348 - FILE *fin;
349 - int *pi;
350 +local int unzlocal_getByte OF((
351 + const zlib_filefunc_def* pzlib_filefunc_def,
352 + voidpf filestream,
353 + int *pi));
355 +local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
356 + const zlib_filefunc_def* pzlib_filefunc_def;
357 + voidpf filestream;
358 + int *pi;
360 unsigned char c;
361 - int err = fread(&c, 1, 1, fin);
362 + int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
363 if (err==1)
365 *pi = (int)c;
366 @@ -146,7 +182,7 @@
368 else
370 - if (ferror(fin))
371 + if (ZERROR(*pzlib_filefunc_def,filestream))
372 return UNZ_ERRNO;
373 else
374 return UNZ_EOF;
375 @@ -155,23 +191,29 @@
378 /* ===========================================================================
379 - Reads a long in LSB order from the given gz_stream. Sets
380 + Reads a long in LSB order from the given gz_stream. Sets
382 -local int unzlocal_getShort (fin,pX)
383 - FILE* fin;
384 +local int unzlocal_getShort OF((
385 + const zlib_filefunc_def* pzlib_filefunc_def,
386 + voidpf filestream,
387 + uLong *pX));
389 +local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
390 + const zlib_filefunc_def* pzlib_filefunc_def;
391 + voidpf filestream;
392 uLong *pX;
394 uLong x ;
395 int i;
396 int err;
398 - err = unzlocal_getByte(fin,&i);
399 + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
400 x = (uLong)i;
403 if (err==UNZ_OK)
404 - err = unzlocal_getByte(fin,&i);
405 + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
406 x += ((uLong)i)<<8;
409 if (err==UNZ_OK)
410 *pX = x;
411 else
412 @@ -179,29 +221,35 @@
413 return err;
416 -local int unzlocal_getLong (fin,pX)
417 - FILE* fin;
418 +local int unzlocal_getLong OF((
419 + const zlib_filefunc_def* pzlib_filefunc_def,
420 + voidpf filestream,
421 + uLong *pX));
423 +local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
424 + const zlib_filefunc_def* pzlib_filefunc_def;
425 + voidpf filestream;
426 uLong *pX;
428 uLong x ;
429 int i;
430 int err;
432 - err = unzlocal_getByte(fin,&i);
433 + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
434 x = (uLong)i;
437 if (err==UNZ_OK)
438 - err = unzlocal_getByte(fin,&i);
439 + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
440 x += ((uLong)i)<<8;
442 if (err==UNZ_OK)
443 - err = unzlocal_getByte(fin,&i);
444 + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
445 x += ((uLong)i)<<16;
447 if (err==UNZ_OK)
448 - err = unzlocal_getByte(fin,&i);
449 + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
450 x += ((uLong)i)<<24;
453 if (err==UNZ_OK)
454 *pX = x;
455 else
456 @@ -212,26 +260,26 @@
458 /* My own strcmpi / strcasecmp */
459 local int strcmpcasenosensitive_internal (fileName1,fileName2)
460 - const char* fileName1;
461 - const char* fileName2;
462 + const char* fileName1;
463 + const char* fileName2;
465 - for (;;)
467 - char c1=*(fileName1++);
468 - char c2=*(fileName2++);
469 - if ((c1>='a') && (c1<='z'))
470 - c1 -= 0x20;
471 - if ((c2>='a') && (c2<='z'))
472 - c2 -= 0x20;
473 - if (c1=='\0')
474 - return ((c2=='\0') ? 0 : -1);
475 - if (c2=='\0')
476 - return 1;
477 - if (c1<c2)
478 - return -1;
479 - if (c1>c2)
480 - return 1;
482 + for (;;)
484 + char c1=*(fileName1++);
485 + char c2=*(fileName2++);
486 + if ((c1>='a') && (c1<='z'))
487 + c1 -= 0x20;
488 + if ((c2>='a') && (c2<='z'))
489 + c2 -= 0x20;
490 + if (c1=='\0')
491 + return ((c2=='\0') ? 0 : -1);
492 + if (c2=='\0')
493 + return 1;
494 + if (c1<c2)
495 + return -1;
496 + if (c1>c2)
497 + return 1;
502 @@ -245,7 +293,7 @@
503 #define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
504 #endif
506 -/*
508 Compare two filename (fileName1,fileName2).
509 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
510 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
511 @@ -255,203 +303,225 @@
514 extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
515 - const char* fileName1;
516 - const char* fileName2;
517 - int iCaseSensitivity;
518 + const char* fileName1;
519 + const char* fileName2;
520 + int iCaseSensitivity;
522 - if (iCaseSensitivity==0)
523 - iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
524 + if (iCaseSensitivity==0)
525 + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
527 - if (iCaseSensitivity==1)
528 - return strcmp(fileName1,fileName2);
529 + if (iCaseSensitivity==1)
530 + return strcmp(fileName1,fileName2);
532 - return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
534 + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
537 +#ifndef BUFREADCOMMENT
538 #define BUFREADCOMMENT (0x400)
539 +#endif
542 Locate the Central directory of a zipfile (at the end, just before
543 the global comment)
545 -local uLong unzlocal_SearchCentralDir(fin)
546 - FILE *fin;
547 +local uLong unzlocal_SearchCentralDir OF((
548 + const zlib_filefunc_def* pzlib_filefunc_def,
549 + voidpf filestream));
551 +local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
552 + const zlib_filefunc_def* pzlib_filefunc_def;
553 + voidpf filestream;
555 - unsigned char* buf;
556 - uLong uSizeFile;
557 - uLong uBackRead;
558 - uLong uMaxBack=0xffff; /* maximum size of global comment */
559 - uLong uPosFound=0;
561 - if (fseek(fin,0,SEEK_END) != 0)
562 - return 0;
565 - uSizeFile = ftell( fin );
567 - if (uMaxBack>uSizeFile)
568 - uMaxBack = uSizeFile;
570 - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
571 - if (buf==NULL)
572 - return 0;
574 - uBackRead = 4;
575 - while (uBackRead<uMaxBack)
577 - uLong uReadSize,uReadPos ;
578 - int i;
579 - if (uBackRead+BUFREADCOMMENT>uMaxBack)
580 - uBackRead = uMaxBack;
581 - else
582 - uBackRead+=BUFREADCOMMENT;
583 - uReadPos = uSizeFile-uBackRead ;
585 - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
586 + unsigned char* buf;
587 + uLong uSizeFile;
588 + uLong uBackRead;
589 + uLong uMaxBack=0xffff; /* maximum size of global comment */
590 + uLong uPosFound=0;
592 + if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
593 + return 0;
596 + uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
598 + if (uMaxBack>uSizeFile)
599 + uMaxBack = uSizeFile;
601 + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
602 + if (buf==NULL)
603 + return 0;
605 + uBackRead = 4;
606 + while (uBackRead<uMaxBack)
608 + uLong uReadSize,uReadPos ;
609 + int i;
610 + if (uBackRead+BUFREADCOMMENT>uMaxBack)
611 + uBackRead = uMaxBack;
612 + else
613 + uBackRead+=BUFREADCOMMENT;
614 + uReadPos = uSizeFile-uBackRead ;
616 + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
617 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
618 - if (fseek(fin,uReadPos,SEEK_SET)!=0)
619 - break;
620 + if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
621 + break;
623 - if (fread(buf,(uInt)uReadSize,1,fin)!=1)
624 - break;
625 + if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
626 + break;
628 - for (i=(int)uReadSize-3; (i--)>0;)
629 - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
630 - ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
632 - uPosFound = uReadPos+i;
633 - break;
636 - if (uPosFound!=0)
637 - break;
639 - TRYFREE(buf);
640 - return uPosFound;
641 + for (i=(int)uReadSize-3; (i--)>0;)
642 + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
643 + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
645 + uPosFound = uReadPos+i;
646 + break;
649 + if (uPosFound!=0)
650 + break;
652 + TRYFREE(buf);
653 + return uPosFound;
657 Open a Zip file. path contain the full pathname (by example,
658 - on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer
659 - "zlib/zlib109.zip".
660 - If the zipfile cannot be opened (file don't exist or in not valid), the
661 - return value is NULL.
662 + on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
663 + "zlib/zlib114.zip".
664 + If the zipfile cannot be opened (file doesn't exist or in not valid), the
665 + return value is NULL.
666 Else, the return value is a unzFile Handle, usable with other function
667 - of this unzip package.
668 + of this unzip package.
670 -extern unzFile ZEXPORT unzOpen (path)
671 - const char *path;
673 - unz_s us;
674 - unz_s *s;
675 - uLong central_pos,uL;
676 - FILE * fin ;
678 - uLong number_disk; /* number of the current dist, used for
679 - spaning ZIP, unsupported, always 0*/
680 - uLong number_disk_with_CD; /* number the the disk with central dir, used
681 - for spaning ZIP, unsupported, always 0*/
682 - uLong number_entry_CD; /* total number of entries in
683 - the central dir
684 - (same than number_entry on nospan) */
685 +extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
686 + const char *path;
687 + zlib_filefunc_def* pzlib_filefunc_def;
689 + unz_s us;
690 + unz_s *s;
691 + uLong central_pos,uL;
693 + uLong number_disk; /* number of the current dist, used for
694 + spaning ZIP, unsupported, always 0*/
695 + uLong number_disk_with_CD; /* number the the disk with central dir, used
696 + for spaning ZIP, unsupported, always 0*/
697 + uLong number_entry_CD; /* total number of entries in
698 + the central dir
699 + (same than number_entry on nospan) */
701 - int err=UNZ_OK;
702 + int err=UNZ_OK;
704 if (unz_copyright[0]!=' ')
705 return NULL;
707 - fin=fopen(path,"rb");
708 - if (fin==NULL)
709 - return NULL;
711 - central_pos = unzlocal_SearchCentralDir(fin);
712 - if (central_pos==0)
713 - err=UNZ_ERRNO;
715 - if (fseek(fin,central_pos,SEEK_SET)!=0)
716 - err=UNZ_ERRNO;
718 - /* the signature, already checked */
719 - if (unzlocal_getLong(fin,&uL)!=UNZ_OK)
720 - err=UNZ_ERRNO;
722 - /* number of this disk */
723 - if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK)
724 - err=UNZ_ERRNO;
726 - /* number of the disk with the start of the central directory */
727 - if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK)
728 - err=UNZ_ERRNO;
730 - /* total number of entries in the central dir on this disk */
731 - if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK)
732 - err=UNZ_ERRNO;
734 - /* total number of entries in the central dir */
735 - if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK)
736 - err=UNZ_ERRNO;
738 - if ((number_entry_CD!=us.gi.number_entry) ||
739 - (number_disk_with_CD!=0) ||
740 - (number_disk!=0))
741 - err=UNZ_BADZIPFILE;
743 - /* size of the central directory */
744 - if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK)
745 - err=UNZ_ERRNO;
747 - /* offset of start of central directory with respect to the
748 - starting disk number */
749 - if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK)
750 - err=UNZ_ERRNO;
752 - /* zipfile comment length */
753 - if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK)
754 - err=UNZ_ERRNO;
756 - if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
757 - (err==UNZ_OK))
758 - err=UNZ_BADZIPFILE;
760 - if (err!=UNZ_OK)
762 - fclose(fin);
763 - return NULL;
766 - us.file=fin;
767 - us.byte_before_the_zipfile = central_pos -
768 - (us.offset_central_dir+us.size_central_dir);
769 - us.central_pos = central_pos;
770 + if (pzlib_filefunc_def==NULL)
771 + fill_fopen_filefunc(&us.z_filefunc);
772 + else
773 + us.z_filefunc = *pzlib_filefunc_def;
775 + us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
776 + path,
777 + ZLIB_FILEFUNC_MODE_READ |
778 + ZLIB_FILEFUNC_MODE_EXISTING);
779 + if (us.filestream==NULL)
780 + return NULL;
782 + central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);
783 + if (central_pos==0)
784 + err=UNZ_ERRNO;
786 + if (ZSEEK(us.z_filefunc, us.filestream,
787 + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
788 + err=UNZ_ERRNO;
790 + /* the signature, already checked */
791 + if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
792 + err=UNZ_ERRNO;
794 + /* number of this disk */
795 + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
796 + err=UNZ_ERRNO;
798 + /* number of the disk with the start of the central directory */
799 + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
800 + err=UNZ_ERRNO;
802 + /* total number of entries in the central dir on this disk */
803 + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
804 + err=UNZ_ERRNO;
806 + /* total number of entries in the central dir */
807 + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
808 + err=UNZ_ERRNO;
810 + if ((number_entry_CD!=us.gi.number_entry) ||
811 + (number_disk_with_CD!=0) ||
812 + (number_disk!=0))
813 + err=UNZ_BADZIPFILE;
815 + /* size of the central directory */
816 + if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
817 + err=UNZ_ERRNO;
819 + /* offset of start of central directory with respect to the
820 + starting disk number */
821 + if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
822 + err=UNZ_ERRNO;
824 + /* zipfile comment length */
825 + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
826 + err=UNZ_ERRNO;
828 + if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
829 + (err==UNZ_OK))
830 + err=UNZ_BADZIPFILE;
832 + if (err!=UNZ_OK)
834 + ZCLOSE(us.z_filefunc, us.filestream);
835 + return NULL;
838 + us.byte_before_the_zipfile = central_pos -
839 + (us.offset_central_dir+us.size_central_dir);
840 + us.central_pos = central_pos;
841 us.pfile_in_zip_read = NULL;
843 + us.encrypted = 0;
845 - s=(unz_s*)ALLOC(sizeof(unz_s));
846 - *s=us;
847 - unzGoToFirstFile((unzFile)s);
848 - return (unzFile)s;
850 + s=(unz_s*)ALLOC(sizeof(unz_s));
851 + *s=us;
852 + unzGoToFirstFile((unzFile)s);
853 + return (unzFile)s;
857 +extern unzFile ZEXPORT unzOpen (path)
858 + const char *path;
860 + return unzOpen2(path, NULL);
864 Close a ZipFile opened with unzipOpen.
865 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
866 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
867 return UNZ_OK if there is no problem. */
868 extern int ZEXPORT unzClose (file)
869 - unzFile file;
870 + unzFile file;
872 - unz_s* s;
873 - if (file==NULL)
874 - return UNZ_PARAMERROR;
875 - s=(unz_s*)file;
876 + unz_s* s;
877 + if (file==NULL)
878 + return UNZ_PARAMERROR;
879 + s=(unz_s*)file;
881 if (s->pfile_in_zip_read!=NULL)
882 unzCloseCurrentFile(file);
884 - fclose(s->file);
885 - TRYFREE(s);
886 - return UNZ_OK;
887 + ZCLOSE(s->z_filefunc, s->filestream);
888 + TRYFREE(s);
889 + return UNZ_OK;
893 @@ -460,15 +530,15 @@
894 No preparation of the structure is needed
895 return UNZ_OK if there is no problem. */
896 extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)
897 - unzFile file;
898 - unz_global_info *pglobal_info;
899 + unzFile file;
900 + unz_global_info *pglobal_info;
902 - unz_s* s;
903 - if (file==NULL)
904 - return UNZ_PARAMERROR;
905 - s=(unz_s*)file;
906 - *pglobal_info=s->gi;
907 - return UNZ_OK;
908 + unz_s* s;
909 + if (file==NULL)
910 + return UNZ_PARAMERROR;
911 + s=(unz_s*)file;
912 + *pglobal_info=s->gi;
913 + return UNZ_OK;
917 @@ -495,14 +565,14 @@
919 local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
920 unz_file_info *pfile_info,
921 - unz_file_info_internal
922 + unz_file_info_internal
923 *pfile_info_internal,
924 char *szFileName,
925 - uLong fileNameBufferSize,
926 + uLong fileNameBufferSize,
927 void *extraField,
928 - uLong extraFieldBufferSize,
929 + uLong extraFieldBufferSize,
930 char *szComment,
931 - uLong commentBufferSize));
932 + uLong commentBufferSize));
934 local int unzlocal_GetCurrentFileInfoInternal (file,
935 pfile_info,
936 @@ -510,156 +580,158 @@
937 szFileName, fileNameBufferSize,
938 extraField, extraFieldBufferSize,
939 szComment, commentBufferSize)
940 - unzFile file;
941 - unz_file_info *pfile_info;
942 - unz_file_info_internal *pfile_info_internal;
943 - char *szFileName;
944 - uLong fileNameBufferSize;
945 - void *extraField;
946 - uLong extraFieldBufferSize;
947 - char *szComment;
948 - uLong commentBufferSize;
950 - unz_s* s;
951 - unz_file_info file_info;
952 - unz_file_info_internal file_info_internal;
953 - int err=UNZ_OK;
954 - uLong uMagic;
955 - long lSeek=0;
957 - if (file==NULL)
958 - return UNZ_PARAMERROR;
959 - s=(unz_s*)file;
960 - if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0)
961 - err=UNZ_ERRNO;
964 - /* we check the magic */
965 - if (err==UNZ_OK)
966 - if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
967 - err=UNZ_ERRNO;
968 - else if (uMagic!=0x02014b50)
969 - err=UNZ_BADZIPFILE;
971 - if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK)
972 - err=UNZ_ERRNO;
974 - if (unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK)
975 - err=UNZ_ERRNO;
976 + unzFile file;
977 + unz_file_info *pfile_info;
978 + unz_file_info_internal *pfile_info_internal;
979 + char *szFileName;
980 + uLong fileNameBufferSize;
981 + void *extraField;
982 + uLong extraFieldBufferSize;
983 + char *szComment;
984 + uLong commentBufferSize;
986 + unz_s* s;
987 + unz_file_info file_info;
988 + unz_file_info_internal file_info_internal;
989 + int err=UNZ_OK;
990 + uLong uMagic;
991 + long lSeek=0;
993 + if (file==NULL)
994 + return UNZ_PARAMERROR;
995 + s=(unz_s*)file;
996 + if (ZSEEK(s->z_filefunc, s->filestream,
997 + s->pos_in_central_dir+s->byte_before_the_zipfile,
998 + ZLIB_FILEFUNC_SEEK_SET)!=0)
999 + err=UNZ_ERRNO;
1002 + /* we check the magic */
1003 + if (err==UNZ_OK)
1004 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
1005 + err=UNZ_ERRNO;
1006 + else if (uMagic!=0x02014b50)
1007 + err=UNZ_BADZIPFILE;
1009 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
1010 + err=UNZ_ERRNO;
1012 - if (unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK)
1013 - err=UNZ_ERRNO;
1014 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
1015 + err=UNZ_ERRNO;
1017 - if (unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK)
1018 - err=UNZ_ERRNO;
1019 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
1020 + err=UNZ_ERRNO;
1022 - if (unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK)
1023 - err=UNZ_ERRNO;
1024 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
1025 + err=UNZ_ERRNO;
1027 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
1028 + err=UNZ_ERRNO;
1030 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
1032 - if (unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK)
1033 - err=UNZ_ERRNO;
1034 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
1035 + err=UNZ_ERRNO;
1037 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
1038 + err=UNZ_ERRNO;
1040 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
1041 + err=UNZ_ERRNO;
1043 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
1044 + err=UNZ_ERRNO;
1046 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
1047 + err=UNZ_ERRNO;
1049 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
1050 + err=UNZ_ERRNO;
1052 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
1053 + err=UNZ_ERRNO;
1055 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
1056 + err=UNZ_ERRNO;
1058 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
1059 + err=UNZ_ERRNO;
1061 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
1062 + err=UNZ_ERRNO;
1064 + lSeek+=file_info.size_filename;
1065 + if ((err==UNZ_OK) && (szFileName!=NULL))
1067 + uLong uSizeRead ;
1068 + if (file_info.size_filename<fileNameBufferSize)
1070 + *(szFileName+file_info.size_filename)='\0';
1071 + uSizeRead = file_info.size_filename;
1073 + else
1074 + uSizeRead = fileNameBufferSize;
1076 + if ((file_info.size_filename>0) && (fileNameBufferSize>0))
1077 + if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
1078 + err=UNZ_ERRNO;
1079 + lSeek -= uSizeRead;
1083 + if ((err==UNZ_OK) && (extraField!=NULL))
1085 + uLong uSizeRead ;
1086 + if (file_info.size_file_extra<extraFieldBufferSize)
1087 + uSizeRead = file_info.size_file_extra;
1088 + else
1089 + uSizeRead = extraFieldBufferSize;
1091 + if (lSeek!=0)
1092 + if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1093 + lSeek=0;
1094 + else
1095 + err=UNZ_ERRNO;
1096 + if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
1097 + if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
1098 + err=UNZ_ERRNO;
1099 + lSeek += file_info.size_file_extra - uSizeRead;
1101 + else
1102 + lSeek+=file_info.size_file_extra;
1104 - if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK)
1105 - err=UNZ_ERRNO;
1107 - if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK)
1108 - err=UNZ_ERRNO;
1109 + if ((err==UNZ_OK) && (szComment!=NULL))
1111 + uLong uSizeRead ;
1112 + if (file_info.size_file_comment<commentBufferSize)
1114 + *(szComment+file_info.size_file_comment)='\0';
1115 + uSizeRead = file_info.size_file_comment;
1117 + else
1118 + uSizeRead = commentBufferSize;
1120 - if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK)
1121 - err=UNZ_ERRNO;
1123 - if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK)
1124 - err=UNZ_ERRNO;
1126 - if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK)
1127 - err=UNZ_ERRNO;
1129 - if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK)
1130 - err=UNZ_ERRNO;
1132 - if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK)
1133 - err=UNZ_ERRNO;
1135 - if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK)
1136 - err=UNZ_ERRNO;
1138 - if (unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK)
1139 - err=UNZ_ERRNO;
1141 - lSeek+=file_info.size_filename;
1142 - if ((err==UNZ_OK) && (szFileName!=NULL))
1144 - uLong uSizeRead ;
1145 - if (file_info.size_filename<fileNameBufferSize)
1147 - *(szFileName+file_info.size_filename)='\0';
1148 - uSizeRead = file_info.size_filename;
1150 - else
1151 - uSizeRead = fileNameBufferSize;
1153 - if ((file_info.size_filename>0) && (fileNameBufferSize>0))
1154 - if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1)
1155 - err=UNZ_ERRNO;
1156 - lSeek -= uSizeRead;
1160 - if ((err==UNZ_OK) && (extraField!=NULL))
1162 - uLong uSizeRead ;
1163 - if (file_info.size_file_extra<extraFieldBufferSize)
1164 - uSizeRead = file_info.size_file_extra;
1165 - else
1166 - uSizeRead = extraFieldBufferSize;
1168 - if (lSeek!=0)
1169 - if (fseek(s->file,lSeek,SEEK_CUR)==0)
1170 - lSeek=0;
1171 - else
1172 - err=UNZ_ERRNO;
1173 - if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
1174 - if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1)
1175 - err=UNZ_ERRNO;
1176 - lSeek += file_info.size_file_extra - uSizeRead;
1178 - else
1179 - lSeek+=file_info.size_file_extra;
1182 - if ((err==UNZ_OK) && (szComment!=NULL))
1184 - uLong uSizeRead ;
1185 - if (file_info.size_file_comment<commentBufferSize)
1187 - *(szComment+file_info.size_file_comment)='\0';
1188 - uSizeRead = file_info.size_file_comment;
1190 - else
1191 - uSizeRead = commentBufferSize;
1193 - if (lSeek!=0)
1194 - if (fseek(s->file,lSeek,SEEK_CUR)==0)
1195 - lSeek=0;
1196 - else
1197 - err=UNZ_ERRNO;
1198 - if ((file_info.size_file_comment>0) && (commentBufferSize>0))
1199 - if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1)
1200 - err=UNZ_ERRNO;
1201 - lSeek+=file_info.size_file_comment - uSizeRead;
1203 - else
1204 - lSeek+=file_info.size_file_comment;
1205 + if (lSeek!=0)
1206 + if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1207 + lSeek=0;
1208 + else
1209 + err=UNZ_ERRNO;
1210 + if ((file_info.size_file_comment>0) && (commentBufferSize>0))
1211 + if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
1212 + err=UNZ_ERRNO;
1213 + lSeek+=file_info.size_file_comment - uSizeRead;
1215 + else
1216 + lSeek+=file_info.size_file_comment;
1218 - if ((err==UNZ_OK) && (pfile_info!=NULL))
1219 - *pfile_info=file_info;
1220 + if ((err==UNZ_OK) && (pfile_info!=NULL))
1221 + *pfile_info=file_info;
1223 - if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
1224 - *pfile_info_internal=file_info_internal;
1225 + if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
1226 + *pfile_info_internal=file_info_internal;
1228 - return err;
1229 + return err;
1233 @@ -670,23 +742,23 @@
1234 return UNZ_OK if there is no problem.
1236 extern int ZEXPORT unzGetCurrentFileInfo (file,
1237 - pfile_info,
1238 - szFileName, fileNameBufferSize,
1239 - extraField, extraFieldBufferSize,
1240 - szComment, commentBufferSize)
1241 - unzFile file;
1242 - unz_file_info *pfile_info;
1243 - char *szFileName;
1244 - uLong fileNameBufferSize;
1245 - void *extraField;
1246 - uLong extraFieldBufferSize;
1247 - char *szComment;
1248 - uLong commentBufferSize;
1250 - return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
1251 - szFileName,fileNameBufferSize,
1252 - extraField,extraFieldBufferSize,
1253 - szComment,commentBufferSize);
1254 + pfile_info,
1255 + szFileName, fileNameBufferSize,
1256 + extraField, extraFieldBufferSize,
1257 + szComment, commentBufferSize)
1258 + unzFile file;
1259 + unz_file_info *pfile_info;
1260 + char *szFileName;
1261 + uLong fileNameBufferSize;
1262 + void *extraField;
1263 + uLong extraFieldBufferSize;
1264 + char *szComment;
1265 + uLong commentBufferSize;
1267 + return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
1268 + szFileName,fileNameBufferSize,
1269 + extraField,extraFieldBufferSize,
1270 + szComment,commentBufferSize);
1274 @@ -694,50 +766,50 @@
1275 return UNZ_OK if there is no problem
1277 extern int ZEXPORT unzGoToFirstFile (file)
1278 - unzFile file;
1279 + unzFile file;
1281 - int err=UNZ_OK;
1282 - unz_s* s;
1283 - if (file==NULL)
1284 - return UNZ_PARAMERROR;
1285 - s=(unz_s*)file;
1286 - s->pos_in_central_dir=s->offset_central_dir;
1287 - s->num_file=0;
1288 - err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1289 - &s->cur_file_info_internal,
1290 - NULL,0,NULL,0,NULL,0);
1291 - s->current_file_ok = (err == UNZ_OK);
1292 - return err;
1293 + int err=UNZ_OK;
1294 + unz_s* s;
1295 + if (file==NULL)
1296 + return UNZ_PARAMERROR;
1297 + s=(unz_s*)file;
1298 + s->pos_in_central_dir=s->offset_central_dir;
1299 + s->num_file=0;
1300 + err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1301 + &s->cur_file_info_internal,
1302 + NULL,0,NULL,0,NULL,0);
1303 + s->current_file_ok = (err == UNZ_OK);
1304 + return err;
1309 Set the current file of the zipfile to the next file.
1310 return UNZ_OK if there is no problem
1311 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
1313 extern int ZEXPORT unzGoToNextFile (file)
1314 - unzFile file;
1315 + unzFile file;
1317 - unz_s* s;
1318 - int err;
1319 + unz_s* s;
1320 + int err;
1322 - if (file==NULL)
1323 - return UNZ_PARAMERROR;
1324 - s=(unz_s*)file;
1325 - if (!s->current_file_ok)
1326 - return UNZ_END_OF_LIST_OF_FILE;
1327 - if (s->num_file+1==s->gi.number_entry)
1328 - return UNZ_END_OF_LIST_OF_FILE;
1330 - s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
1331 - s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
1332 - s->num_file++;
1333 - err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1334 - &s->cur_file_info_internal,
1335 - NULL,0,NULL,0,NULL,0);
1336 - s->current_file_ok = (err == UNZ_OK);
1337 - return err;
1338 + if (file==NULL)
1339 + return UNZ_PARAMERROR;
1340 + s=(unz_s*)file;
1341 + if (!s->current_file_ok)
1342 + return UNZ_END_OF_LIST_OF_FILE;
1343 + if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
1344 + if (s->num_file+1==s->gi.number_entry)
1345 + return UNZ_END_OF_LIST_OF_FILE;
1347 + s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
1348 + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
1349 + s->num_file++;
1350 + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1351 + &s->cur_file_info_internal,
1352 + NULL,0,NULL,0,NULL,0);
1353 + s->current_file_ok = (err == UNZ_OK);
1354 + return err;
1358 @@ -750,50 +822,130 @@
1359 UNZ_END_OF_LIST_OF_FILE if the file is not found
1361 extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
1362 - unzFile file;
1363 - const char *szFileName;
1364 - int iCaseSensitivity;
1365 + unzFile file;
1366 + const char *szFileName;
1367 + int iCaseSensitivity;
1369 - unz_s* s;
1370 - int err;
1371 + unz_s* s;
1372 + int err;
1375 - uLong num_fileSaved;
1376 - uLong pos_in_central_dirSaved;
1377 + /* We remember the 'current' position in the file so that we can jump
1378 + * back there if we fail.
1379 + */
1380 + unz_file_info cur_file_infoSaved;
1381 + unz_file_info_internal cur_file_info_internalSaved;
1382 + uLong num_fileSaved;
1383 + uLong pos_in_central_dirSaved;
1386 - if (file==NULL)
1387 - return UNZ_PARAMERROR;
1388 + if (file==NULL)
1389 + return UNZ_PARAMERROR;
1391 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
1392 return UNZ_PARAMERROR;
1394 - s=(unz_s*)file;
1395 - if (!s->current_file_ok)
1396 - return UNZ_END_OF_LIST_OF_FILE;
1398 - num_fileSaved = s->num_file;
1399 - pos_in_central_dirSaved = s->pos_in_central_dir;
1401 - err = unzGoToFirstFile(file);
1403 - while (err == UNZ_OK)
1405 - char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
1406 - unzGetCurrentFileInfo(file,NULL,
1407 - szCurrentFileName,sizeof(szCurrentFileName)-1,
1408 - NULL,0,NULL,0);
1409 - if (unzStringFileNameCompare(szCurrentFileName,
1410 - szFileName,iCaseSensitivity)==0)
1411 - return UNZ_OK;
1412 - err = unzGoToNextFile(file);
1415 - s->num_file = num_fileSaved ;
1416 - s->pos_in_central_dir = pos_in_central_dirSaved ;
1417 - return err;
1418 + s=(unz_s*)file;
1419 + if (!s->current_file_ok)
1420 + return UNZ_END_OF_LIST_OF_FILE;
1422 + /* Save the current state */
1423 + num_fileSaved = s->num_file;
1424 + pos_in_central_dirSaved = s->pos_in_central_dir;
1425 + cur_file_infoSaved = s->cur_file_info;
1426 + cur_file_info_internalSaved = s->cur_file_info_internal;
1428 + err = unzGoToFirstFile(file);
1430 + while (err == UNZ_OK)
1432 + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
1433 + err = unzGetCurrentFileInfo(file,NULL,
1434 + szCurrentFileName,sizeof(szCurrentFileName)-1,
1435 + NULL,0,NULL,0);
1436 + if (err == UNZ_OK)
1438 + if (unzStringFileNameCompare(szCurrentFileName,
1439 + szFileName,iCaseSensitivity)==0)
1440 + return UNZ_OK;
1441 + err = unzGoToNextFile(file);
1445 + /* We failed, so restore the state of the 'current file' to where we
1446 + * were.
1447 + */
1448 + s->num_file = num_fileSaved ;
1449 + s->pos_in_central_dir = pos_in_central_dirSaved ;
1450 + s->cur_file_info = cur_file_infoSaved;
1451 + s->cur_file_info_internal = cur_file_info_internalSaved;
1452 + return err;
1457 +///////////////////////////////////////////
1458 +// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
1459 +// I need random access
1461 +// Further optimization could be realized by adding an ability
1462 +// to cache the directory in memory. The goal being a single
1463 +// comprehensive file read to put the file I need in a memory.
1467 +typedef struct unz_file_pos_s
1469 + uLong pos_in_zip_directory; // offset in file
1470 + uLong num_of_file; // # of file
1471 +} unz_file_pos;
1474 +extern int ZEXPORT unzGetFilePos(file, file_pos)
1475 + unzFile file;
1476 + unz_file_pos* file_pos;
1478 + unz_s* s;
1480 + if (file==NULL || file_pos==NULL)
1481 + return UNZ_PARAMERROR;
1482 + s=(unz_s*)file;
1483 + if (!s->current_file_ok)
1484 + return UNZ_END_OF_LIST_OF_FILE;
1486 + file_pos->pos_in_zip_directory = s->pos_in_central_dir;
1487 + file_pos->num_of_file = s->num_file;
1489 + return UNZ_OK;
1492 +extern int ZEXPORT unzGoToFilePos(file, file_pos)
1493 + unzFile file;
1494 + unz_file_pos* file_pos;
1496 + unz_s* s;
1497 + int err;
1499 + if (file==NULL || file_pos==NULL)
1500 + return UNZ_PARAMERROR;
1501 + s=(unz_s*)file;
1503 + /* jump to the right spot */
1504 + s->pos_in_central_dir = file_pos->pos_in_zip_directory;
1505 + s->num_file = file_pos->num_of_file;
1507 + /* set the current file */
1508 + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1509 + &s->cur_file_info_internal,
1510 + NULL,0,NULL,0,NULL,0);
1511 + /* return results */
1512 + s->current_file_ok = (err == UNZ_OK);
1513 + return err;
1517 +// Unzip Helper Functions - should be here?
1518 +///////////////////////////////////////////
1522 Read the local header of the current zipfile
1523 @@ -803,185 +955,261 @@
1524 (filename and size of extra field data)
1526 local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
1527 - poffset_local_extrafield,
1528 - psize_local_extrafield)
1529 - unz_s* s;
1530 - uInt* piSizeVar;
1531 - uLong *poffset_local_extrafield;
1532 - uInt *psize_local_extrafield;
1534 - uLong uMagic,uData,uFlags;
1535 - uLong size_filename;
1536 - uLong size_extra_field;
1537 - int err=UNZ_OK;
1539 - *piSizeVar = 0;
1540 - *poffset_local_extrafield = 0;
1541 - *psize_local_extrafield = 0;
1543 - if (fseek(s->file,s->cur_file_info_internal.offset_curfile +
1544 - s->byte_before_the_zipfile,SEEK_SET)!=0)
1545 - return UNZ_ERRNO;
1548 - if (err==UNZ_OK)
1549 - if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
1550 - err=UNZ_ERRNO;
1551 - else if (uMagic!=0x04034b50)
1552 - err=UNZ_BADZIPFILE;
1554 - if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
1555 - err=UNZ_ERRNO;
1557 - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
1558 - err=UNZ_BADZIPFILE;
1560 - if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK)
1561 - err=UNZ_ERRNO;
1563 - if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
1564 - err=UNZ_ERRNO;
1565 - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
1566 - err=UNZ_BADZIPFILE;
1567 + poffset_local_extrafield,
1568 + psize_local_extrafield)
1569 + unz_s* s;
1570 + uInt* piSizeVar;
1571 + uLong *poffset_local_extrafield;
1572 + uInt *psize_local_extrafield;
1574 + uLong uMagic,uData,uFlags;
1575 + uLong size_filename;
1576 + uLong size_extra_field;
1577 + int err=UNZ_OK;
1579 + *piSizeVar = 0;
1580 + *poffset_local_extrafield = 0;
1581 + *psize_local_extrafield = 0;
1583 + if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
1584 + s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
1585 + return UNZ_ERRNO;
1588 + if (err==UNZ_OK)
1589 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
1590 + err=UNZ_ERRNO;
1591 + else if (uMagic!=0x04034b50)
1592 + err=UNZ_BADZIPFILE;
1594 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1595 + err=UNZ_ERRNO;
1597 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
1598 + err=UNZ_BADZIPFILE;
1600 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
1601 + err=UNZ_ERRNO;
1603 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1604 + err=UNZ_ERRNO;
1605 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
1606 + err=UNZ_BADZIPFILE;
1608 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
1609 (s->cur_file_info.compression_method!=Z_DEFLATED))
1610 err=UNZ_BADZIPFILE;
1612 - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */
1613 - err=UNZ_ERRNO;
1614 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
1615 + err=UNZ_ERRNO;
1617 - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */
1618 - err=UNZ_ERRNO;
1619 - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
1620 - ((uFlags & 8)==0))
1621 - err=UNZ_BADZIPFILE;
1623 - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */
1624 - err=UNZ_ERRNO;
1625 - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
1626 - ((uFlags & 8)==0))
1627 - err=UNZ_BADZIPFILE;
1629 - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */
1630 - err=UNZ_ERRNO;
1631 - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
1632 - ((uFlags & 8)==0))
1633 - err=UNZ_BADZIPFILE;
1636 - if (unzlocal_getShort(s->file,&size_filename) != UNZ_OK)
1637 - err=UNZ_ERRNO;
1638 - else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1639 - err=UNZ_BADZIPFILE;
1641 - *piSizeVar += (uInt)size_filename;
1643 - if (unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK)
1644 - err=UNZ_ERRNO;
1645 - *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1646 - SIZEZIPLOCALHEADER + size_filename;
1647 - *psize_local_extrafield = (uInt)size_extra_field;
1648 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
1649 + err=UNZ_ERRNO;
1650 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
1651 + ((uFlags & 8)==0))
1652 + err=UNZ_BADZIPFILE;
1654 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
1655 + err=UNZ_ERRNO;
1656 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
1657 + ((uFlags & 8)==0))
1658 + err=UNZ_BADZIPFILE;
1660 - *piSizeVar += (uInt)size_extra_field;
1661 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
1662 + err=UNZ_ERRNO;
1663 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
1664 + ((uFlags & 8)==0))
1665 + err=UNZ_BADZIPFILE;
1668 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1669 + err=UNZ_ERRNO;
1670 + else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1671 + err=UNZ_BADZIPFILE;
1673 - return err;
1674 + *piSizeVar += (uInt)size_filename;
1676 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
1677 + err=UNZ_ERRNO;
1678 + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1679 + SIZEZIPLOCALHEADER + size_filename;
1680 + *psize_local_extrafield = (uInt)size_extra_field;
1682 + *piSizeVar += (uInt)size_extra_field;
1684 + return err;
1689 Open for reading data the current file in the zipfile.
1690 If there is no error and the file is opened, the return value is UNZ_OK.
1692 -extern int ZEXPORT unzOpenCurrentFile (file)
1693 - unzFile file;
1695 - int err=UNZ_OK;
1696 - int Store;
1697 - uInt iSizeVar;
1698 - unz_s* s;
1699 - file_in_zip_read_info_s* pfile_in_zip_read_info;
1700 - uLong offset_local_extrafield; /* offset of the local extra field */
1701 - uInt size_local_extrafield; /* size of the local extra field */
1703 - if (file==NULL)
1704 - return UNZ_PARAMERROR;
1705 - s=(unz_s*)file;
1706 - if (!s->current_file_ok)
1707 - return UNZ_PARAMERROR;
1708 +extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1709 + unzFile file;
1710 + int* method;
1711 + int* level;
1712 + int raw;
1713 + const char* password;
1715 + int err=UNZ_OK;
1716 + uInt iSizeVar;
1717 + unz_s* s;
1718 + file_in_zip_read_info_s* pfile_in_zip_read_info;
1719 + uLong offset_local_extrafield; /* offset of the local extra field */
1720 + uInt size_local_extrafield; /* size of the local extra field */
1721 +# ifndef NOUNCRYPT
1722 + char source[12];
1723 +# else
1724 + if (password != NULL)
1725 + return UNZ_PARAMERROR;
1726 +# endif
1728 + if (file==NULL)
1729 + return UNZ_PARAMERROR;
1730 + s=(unz_s*)file;
1731 + if (!s->current_file_ok)
1732 + return UNZ_PARAMERROR;
1734 if (s->pfile_in_zip_read != NULL)
1735 unzCloseCurrentFile(file);
1737 - if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
1738 - &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1739 - return UNZ_BADZIPFILE;
1741 - pfile_in_zip_read_info = (file_in_zip_read_info_s*)
1742 - ALLOC(sizeof(file_in_zip_read_info_s));
1743 - if (pfile_in_zip_read_info==NULL)
1744 - return UNZ_INTERNALERROR;
1746 - pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
1747 - pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1748 - pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1749 - pfile_in_zip_read_info->pos_local_extrafield=0;
1751 - if (pfile_in_zip_read_info->read_buffer==NULL)
1753 - TRYFREE(pfile_in_zip_read_info);
1754 - return UNZ_INTERNALERROR;
1757 - pfile_in_zip_read_info->stream_initialised=0;
1759 - if ((s->cur_file_info.compression_method!=0) &&
1760 + if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
1761 + &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1762 + return UNZ_BADZIPFILE;
1764 + pfile_in_zip_read_info = (file_in_zip_read_info_s*)
1765 + ALLOC(sizeof(file_in_zip_read_info_s));
1766 + if (pfile_in_zip_read_info==NULL)
1767 + return UNZ_INTERNALERROR;
1769 + pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
1770 + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1771 + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1772 + pfile_in_zip_read_info->pos_local_extrafield=0;
1773 + pfile_in_zip_read_info->raw=raw;
1775 + if (pfile_in_zip_read_info->read_buffer==NULL)
1777 + TRYFREE(pfile_in_zip_read_info);
1778 + return UNZ_INTERNALERROR;
1781 + pfile_in_zip_read_info->stream_initialised=0;
1783 + if (method!=NULL)
1784 + *method = (int)s->cur_file_info.compression_method;
1786 + if (level!=NULL)
1788 + *level = 6;
1789 + switch (s->cur_file_info.flag & 0x06)
1791 + case 6 : *level = 1; break;
1792 + case 4 : *level = 2; break;
1793 + case 2 : *level = 9; break;
1797 + if ((s->cur_file_info.compression_method!=0) &&
1798 (s->cur_file_info.compression_method!=Z_DEFLATED))
1799 - err=UNZ_BADZIPFILE;
1800 - Store = s->cur_file_info.compression_method==0;
1801 + err=UNZ_BADZIPFILE;
1803 - pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1804 - pfile_in_zip_read_info->crc32=0;
1805 - pfile_in_zip_read_info->compression_method =
1806 + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1807 + pfile_in_zip_read_info->crc32=0;
1808 + pfile_in_zip_read_info->compression_method =
1809 s->cur_file_info.compression_method;
1810 - pfile_in_zip_read_info->file=s->file;
1811 - pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1812 + pfile_in_zip_read_info->filestream=s->filestream;
1813 + pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
1814 + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1816 pfile_in_zip_read_info->stream.total_out = 0;
1818 - if (!Store)
1820 - pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1821 - pfile_in_zip_read_info->stream.zfree = (free_func)0;
1822 - pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1824 - err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1825 - if (err == Z_OK)
1826 - pfile_in_zip_read_info->stream_initialised=1;
1827 + if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
1828 + (!raw))
1830 + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1831 + pfile_in_zip_read_info->stream.zfree = (free_func)0;
1832 + pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1833 + pfile_in_zip_read_info->stream.next_in = (voidpf)0;
1834 + pfile_in_zip_read_info->stream.avail_in = 0;
1836 + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1837 + if (err == Z_OK)
1838 + pfile_in_zip_read_info->stream_initialised=1;
1839 + else
1841 + TRYFREE(pfile_in_zip_read_info);
1842 + return err;
1844 /* windowBits is passed < 0 to tell that there is no zlib header.
1845 * Note that in this case inflate *requires* an extra "dummy" byte
1846 * after the compressed stream in order to complete decompression and
1847 - * return Z_STREAM_END.
1848 - * In unzip, i don't wait absolutely Z_STREAM_END because I known the
1849 + * return Z_STREAM_END.
1850 + * In unzip, i don't wait absolutely Z_STREAM_END because I known the
1851 * size of both compressed and uncompressed data
1854 - pfile_in_zip_read_info->rest_read_compressed =
1856 + pfile_in_zip_read_info->rest_read_compressed =
1857 s->cur_file_info.compressed_size ;
1858 - pfile_in_zip_read_info->rest_read_uncompressed =
1859 + pfile_in_zip_read_info->rest_read_uncompressed =
1860 s->cur_file_info.uncompressed_size ;
1863 - pfile_in_zip_read_info->pos_in_zipfile =
1864 - s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
1865 - iSizeVar;
1867 - pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1869 + pfile_in_zip_read_info->pos_in_zipfile =
1870 + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
1871 + iSizeVar;
1873 + pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1875 + s->pfile_in_zip_read = pfile_in_zip_read_info;
1877 +# ifndef NOUNCRYPT
1878 + if (password != NULL)
1880 + int i;
1881 + s->pcrc_32_tab = get_crc_table();
1882 + init_keys(password,s->keys,s->pcrc_32_tab);
1883 + if (ZSEEK(s->z_filefunc, s->filestream,
1884 + s->pfile_in_zip_read->pos_in_zipfile +
1885 + s->pfile_in_zip_read->byte_before_the_zipfile,
1886 + SEEK_SET)!=0)
1887 + return UNZ_INTERNALERROR;
1888 + if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)
1889 + return UNZ_INTERNALERROR;
1891 + for (i = 0; i<12; i++)
1892 + zdecode(s->keys,s->pcrc_32_tab,source[i]);
1894 + s->pfile_in_zip_read->pos_in_zipfile+=12;
1895 + s->encrypted=1;
1897 +# endif
1900 - s->pfile_in_zip_read = pfile_in_zip_read_info;
1901 return UNZ_OK;
1904 +extern int ZEXPORT unzOpenCurrentFile (file)
1905 + unzFile file;
1907 + return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1910 +extern int ZEXPORT unzOpenCurrentFilePassword (file, password)
1911 + unzFile file;
1912 + const char* password;
1914 + return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1917 +extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
1918 + unzFile file;
1919 + int* method;
1920 + int* level;
1921 + int raw;
1923 + return unzOpenCurrentFile3(file, method, level, raw, NULL);
1927 Read bytes from the current file.
1928 @@ -994,126 +1222,160 @@
1929 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
1931 extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1932 - unzFile file;
1933 - voidp buf;
1934 - unsigned len;
1936 - int err=UNZ_OK;
1937 - uInt iRead = 0;
1938 - unz_s* s;
1939 - file_in_zip_read_info_s* pfile_in_zip_read_info;
1940 - if (file==NULL)
1941 - return UNZ_PARAMERROR;
1942 - s=(unz_s*)file;
1943 + unzFile file;
1944 + voidp buf;
1945 + unsigned len;
1947 + int err=UNZ_OK;
1948 + uInt iRead = 0;
1949 + unz_s* s;
1950 + file_in_zip_read_info_s* pfile_in_zip_read_info;
1951 + if (file==NULL)
1952 + return UNZ_PARAMERROR;
1953 + s=(unz_s*)file;
1954 pfile_in_zip_read_info=s->pfile_in_zip_read;
1956 - if (pfile_in_zip_read_info==NULL)
1957 - return UNZ_PARAMERROR;
1958 + if (pfile_in_zip_read_info==NULL)
1959 + return UNZ_PARAMERROR;
1962 - if ((pfile_in_zip_read_info->read_buffer == NULL))
1963 - return UNZ_END_OF_LIST_OF_FILE;
1964 - if (len==0)
1965 - return 0;
1967 - pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
1969 - pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1971 - if (len>pfile_in_zip_read_info->rest_read_uncompressed)
1972 - pfile_in_zip_read_info->stream.avail_out =
1973 - (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1975 - while (pfile_in_zip_read_info->stream.avail_out>0)
1977 - if ((pfile_in_zip_read_info->stream.avail_in==0) &&
1978 + if ((pfile_in_zip_read_info->read_buffer == NULL))
1979 + return UNZ_END_OF_LIST_OF_FILE;
1980 + if (len==0)
1981 + return 0;
1983 + pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
1985 + pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1987 + if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
1988 + (!(pfile_in_zip_read_info->raw)))
1989 + pfile_in_zip_read_info->stream.avail_out =
1990 + (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1992 + if ((len>pfile_in_zip_read_info->rest_read_compressed+
1993 + pfile_in_zip_read_info->stream.avail_in) &&
1994 + (pfile_in_zip_read_info->raw))
1995 + pfile_in_zip_read_info->stream.avail_out =
1996 + (uInt)pfile_in_zip_read_info->rest_read_compressed+
1997 + pfile_in_zip_read_info->stream.avail_in;
1999 + while (pfile_in_zip_read_info->stream.avail_out>0)
2001 + if ((pfile_in_zip_read_info->stream.avail_in==0) &&
2002 (pfile_in_zip_read_info->rest_read_compressed>0))
2004 - uInt uReadThis = UNZ_BUFSIZE;
2005 - if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
2006 - uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
2007 - if (uReadThis == 0)
2008 - return UNZ_EOF;
2009 - if (fseek(pfile_in_zip_read_info->file,
2010 - pfile_in_zip_read_info->pos_in_zipfile +
2011 - pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0)
2012 - return UNZ_ERRNO;
2013 - if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1,
2014 - pfile_in_zip_read_info->file)!=1)
2015 - return UNZ_ERRNO;
2016 - pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
2018 - pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
2020 - pfile_in_zip_read_info->stream.next_in =
2022 + uInt uReadThis = UNZ_BUFSIZE;
2023 + if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
2024 + uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
2025 + if (uReadThis == 0)
2026 + return UNZ_EOF;
2027 + if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
2028 + pfile_in_zip_read_info->filestream,
2029 + pfile_in_zip_read_info->pos_in_zipfile +
2030 + pfile_in_zip_read_info->byte_before_the_zipfile,
2031 + ZLIB_FILEFUNC_SEEK_SET)!=0)
2032 + return UNZ_ERRNO;
2033 + if (ZREAD(pfile_in_zip_read_info->z_filefunc,
2034 + pfile_in_zip_read_info->filestream,
2035 + pfile_in_zip_read_info->read_buffer,
2036 + uReadThis)!=uReadThis)
2037 + return UNZ_ERRNO;
2040 +# ifndef NOUNCRYPT
2041 + if(s->encrypted)
2043 + uInt i;
2044 + for(i=0;i<uReadThis;i++)
2045 + pfile_in_zip_read_info->read_buffer[i] =
2046 + zdecode(s->keys,s->pcrc_32_tab,
2047 + pfile_in_zip_read_info->read_buffer[i]);
2049 +# endif
2052 + pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
2054 + pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
2056 + pfile_in_zip_read_info->stream.next_in =
2057 (Bytef*)pfile_in_zip_read_info->read_buffer;
2058 - pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
2060 + pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
2063 + if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
2065 + uInt uDoCopy,i ;
2067 + if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
2068 + (pfile_in_zip_read_info->rest_read_compressed == 0))
2069 + return (iRead==0) ? UNZ_EOF : iRead;
2071 - if (pfile_in_zip_read_info->compression_method==0)
2073 - uInt uDoCopy,i ;
2074 - if (pfile_in_zip_read_info->stream.avail_out <
2075 + if (pfile_in_zip_read_info->stream.avail_out <
2076 pfile_in_zip_read_info->stream.avail_in)
2077 - uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
2078 - else
2079 - uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
2081 - for (i=0;i<uDoCopy;i++)
2082 - *(pfile_in_zip_read_info->stream.next_out+i) =
2083 + uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
2084 + else
2085 + uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
2087 + for (i=0;i<uDoCopy;i++)
2088 + *(pfile_in_zip_read_info->stream.next_out+i) =
2089 *(pfile_in_zip_read_info->stream.next_in+i);
2091 - pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
2092 - pfile_in_zip_read_info->stream.next_out,
2093 - uDoCopy);
2094 - pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
2095 - pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
2096 - pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
2097 - pfile_in_zip_read_info->stream.next_out += uDoCopy;
2098 - pfile_in_zip_read_info->stream.next_in += uDoCopy;
2100 + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
2101 + pfile_in_zip_read_info->stream.next_out,
2102 + uDoCopy);
2103 + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
2104 + pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
2105 + pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
2106 + pfile_in_zip_read_info->stream.next_out += uDoCopy;
2107 + pfile_in_zip_read_info->stream.next_in += uDoCopy;
2108 pfile_in_zip_read_info->stream.total_out += uDoCopy;
2109 - iRead += uDoCopy;
2111 - else
2113 - uLong uTotalOutBefore,uTotalOutAfter;
2114 - const Bytef *bufBefore;
2115 - uLong uOutThis;
2116 - int flush=Z_SYNC_FLUSH;
2118 - uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
2119 - bufBefore = pfile_in_zip_read_info->stream.next_out;
2121 - /*
2122 - if ((pfile_in_zip_read_info->rest_read_uncompressed ==
2123 - pfile_in_zip_read_info->stream.avail_out) &&
2124 - (pfile_in_zip_read_info->rest_read_compressed == 0))
2125 - flush = Z_FINISH;
2126 - */
2127 - err=inflate(&pfile_in_zip_read_info->stream,flush);
2129 - uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
2130 - uOutThis = uTotalOutAfter-uTotalOutBefore;
2132 - pfile_in_zip_read_info->crc32 =
2133 + iRead += uDoCopy;
2135 + else
2137 + uLong uTotalOutBefore,uTotalOutAfter;
2138 + const Bytef *bufBefore;
2139 + uLong uOutThis;
2140 + int flush=Z_SYNC_FLUSH;
2142 + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
2143 + bufBefore = pfile_in_zip_read_info->stream.next_out;
2145 + /*
2146 + if ((pfile_in_zip_read_info->rest_read_uncompressed ==
2147 + pfile_in_zip_read_info->stream.avail_out) &&
2148 + (pfile_in_zip_read_info->rest_read_compressed == 0))
2149 + flush = Z_FINISH;
2150 + */
2151 + err=inflate(&pfile_in_zip_read_info->stream,flush);
2153 + if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
2154 + err = Z_DATA_ERROR;
2156 + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
2157 + uOutThis = uTotalOutAfter-uTotalOutBefore;
2159 + pfile_in_zip_read_info->crc32 =
2160 crc32(pfile_in_zip_read_info->crc32,bufBefore,
2161 (uInt)(uOutThis));
2163 - pfile_in_zip_read_info->rest_read_uncompressed -=
2164 + pfile_in_zip_read_info->rest_read_uncompressed -=
2165 uOutThis;
2167 - iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
2169 - if (err==Z_STREAM_END)
2170 - return (iRead==0) ? UNZ_EOF : iRead;
2171 - if (err!=Z_OK)
2172 - break;
2176 - if (err==Z_OK)
2177 - return iRead;
2178 - return err;
2179 + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
2181 + if (err==Z_STREAM_END)
2182 + return (iRead==0) ? UNZ_EOF : iRead;
2183 + if (err!=Z_OK)
2184 + break;
2188 + if (err==Z_OK)
2189 + return iRead;
2190 + return err;
2194 @@ -1121,42 +1383,42 @@
2195 Give the current position in uncompressed data
2197 extern z_off_t ZEXPORT unztell (file)
2198 - unzFile file;
2199 + unzFile file;
2201 - unz_s* s;
2202 - file_in_zip_read_info_s* pfile_in_zip_read_info;
2203 - if (file==NULL)
2204 - return UNZ_PARAMERROR;
2205 - s=(unz_s*)file;
2206 + unz_s* s;
2207 + file_in_zip_read_info_s* pfile_in_zip_read_info;
2208 + if (file==NULL)
2209 + return UNZ_PARAMERROR;
2210 + s=(unz_s*)file;
2211 pfile_in_zip_read_info=s->pfile_in_zip_read;
2213 - if (pfile_in_zip_read_info==NULL)
2214 - return UNZ_PARAMERROR;
2215 + if (pfile_in_zip_read_info==NULL)
2216 + return UNZ_PARAMERROR;
2218 - return (z_off_t)pfile_in_zip_read_info->stream.total_out;
2219 + return (z_off_t)pfile_in_zip_read_info->stream.total_out;
2224 - return 1 if the end of file was reached, 0 elsewhere
2225 + return 1 if the end of file was reached, 0 elsewhere
2227 extern int ZEXPORT unzeof (file)
2228 - unzFile file;
2229 + unzFile file;
2231 - unz_s* s;
2232 - file_in_zip_read_info_s* pfile_in_zip_read_info;
2233 - if (file==NULL)
2234 - return UNZ_PARAMERROR;
2235 - s=(unz_s*)file;
2236 + unz_s* s;
2237 + file_in_zip_read_info_s* pfile_in_zip_read_info;
2238 + if (file==NULL)
2239 + return UNZ_PARAMERROR;
2240 + s=(unz_s*)file;
2241 pfile_in_zip_read_info=s->pfile_in_zip_read;
2243 - if (pfile_in_zip_read_info==NULL)
2244 - return UNZ_PARAMERROR;
2246 - if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
2247 - return 1;
2248 - else
2249 - return 0;
2250 + if (pfile_in_zip_read_info==NULL)
2251 + return UNZ_PARAMERROR;
2253 + if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
2254 + return 1;
2255 + else
2256 + return 0;
2260 @@ -1169,51 +1431,55 @@
2261 if buf==NULL, it return the size of the local extra field that can be read
2263 if buf!=NULL, len is the size of the buffer, the extra header is copied in
2264 - buf.
2265 - the return value is the number of bytes copied in buf, or (if <0)
2266 - the error code
2267 + buf.
2268 + the return value is the number of bytes copied in buf, or (if <0)
2269 + the error code
2271 extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
2272 - unzFile file;
2273 - voidp buf;
2274 - unsigned len;
2276 - unz_s* s;
2277 - file_in_zip_read_info_s* pfile_in_zip_read_info;
2278 - uInt read_now;
2279 - uLong size_to_read;
2281 - if (file==NULL)
2282 - return UNZ_PARAMERROR;
2283 - s=(unz_s*)file;
2284 + unzFile file;
2285 + voidp buf;
2286 + unsigned len;
2288 + unz_s* s;
2289 + file_in_zip_read_info_s* pfile_in_zip_read_info;
2290 + uInt read_now;
2291 + uLong size_to_read;
2293 + if (file==NULL)
2294 + return UNZ_PARAMERROR;
2295 + s=(unz_s*)file;
2296 pfile_in_zip_read_info=s->pfile_in_zip_read;
2298 - if (pfile_in_zip_read_info==NULL)
2299 - return UNZ_PARAMERROR;
2300 + if (pfile_in_zip_read_info==NULL)
2301 + return UNZ_PARAMERROR;
2303 - size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
2304 - pfile_in_zip_read_info->pos_local_extrafield);
2305 + size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
2306 + pfile_in_zip_read_info->pos_local_extrafield);
2308 - if (buf==NULL)
2309 - return (int)size_to_read;
2311 - if (len>size_to_read)
2312 - read_now = (uInt)size_to_read;
2313 - else
2314 - read_now = (uInt)len ;
2316 - if (read_now==0)
2317 - return 0;
2319 - if (fseek(pfile_in_zip_read_info->file,
2320 - pfile_in_zip_read_info->offset_local_extrafield +
2321 - pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0)
2322 - return UNZ_ERRNO;
2323 + if (buf==NULL)
2324 + return (int)size_to_read;
2326 - if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1)
2327 - return UNZ_ERRNO;
2328 + if (len>size_to_read)
2329 + read_now = (uInt)size_to_read;
2330 + else
2331 + read_now = (uInt)len ;
2333 + if (read_now==0)
2334 + return 0;
2336 - return (int)read_now;
2337 + if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
2338 + pfile_in_zip_read_info->filestream,
2339 + pfile_in_zip_read_info->offset_local_extrafield +
2340 + pfile_in_zip_read_info->pos_local_extrafield,
2341 + ZLIB_FILEFUNC_SEEK_SET)!=0)
2342 + return UNZ_ERRNO;
2344 + if (ZREAD(pfile_in_zip_read_info->z_filefunc,
2345 + pfile_in_zip_read_info->filestream,
2346 + buf,read_now)!=read_now)
2347 + return UNZ_ERRNO;
2349 + return (int)read_now;
2353 @@ -1221,39 +1487,40 @@
2354 Return UNZ_CRCERROR if all the file was read but the CRC is not good
2356 extern int ZEXPORT unzCloseCurrentFile (file)
2357 - unzFile file;
2358 + unzFile file;
2360 - int err=UNZ_OK;
2361 + int err=UNZ_OK;
2363 - unz_s* s;
2364 - file_in_zip_read_info_s* pfile_in_zip_read_info;
2365 - if (file==NULL)
2366 - return UNZ_PARAMERROR;
2367 - s=(unz_s*)file;
2368 + unz_s* s;
2369 + file_in_zip_read_info_s* pfile_in_zip_read_info;
2370 + if (file==NULL)
2371 + return UNZ_PARAMERROR;
2372 + s=(unz_s*)file;
2373 pfile_in_zip_read_info=s->pfile_in_zip_read;
2375 - if (pfile_in_zip_read_info==NULL)
2376 - return UNZ_PARAMERROR;
2377 + if (pfile_in_zip_read_info==NULL)
2378 + return UNZ_PARAMERROR;
2381 - if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
2383 - if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
2384 - err=UNZ_CRCERROR;
2386 + if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
2387 + (!pfile_in_zip_read_info->raw))
2389 + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
2390 + err=UNZ_CRCERROR;
2394 - TRYFREE(pfile_in_zip_read_info->read_buffer);
2395 - pfile_in_zip_read_info->read_buffer = NULL;
2396 - if (pfile_in_zip_read_info->stream_initialised)
2397 - inflateEnd(&pfile_in_zip_read_info->stream);
2398 + TRYFREE(pfile_in_zip_read_info->read_buffer);
2399 + pfile_in_zip_read_info->read_buffer = NULL;
2400 + if (pfile_in_zip_read_info->stream_initialised)
2401 + inflateEnd(&pfile_in_zip_read_info->stream);
2403 - pfile_in_zip_read_info->stream_initialised = 0;
2404 - TRYFREE(pfile_in_zip_read_info);
2405 + pfile_in_zip_read_info->stream_initialised = 0;
2406 + TRYFREE(pfile_in_zip_read_info);
2408 s->pfile_in_zip_read=NULL;
2410 - return err;
2411 + return err;
2415 @@ -1263,32 +1530,69 @@
2416 return the number of byte copied or an error code <0
2418 extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
2419 - unzFile file;
2420 - char *szComment;
2421 - uLong uSizeBuf;
2423 - int err=UNZ_OK;
2424 - unz_s* s;
2425 - uLong uReadThis ;
2426 - if (file==NULL)
2427 - return UNZ_PARAMERROR;
2428 - s=(unz_s*)file;
2430 - uReadThis = uSizeBuf;
2431 - if (uReadThis>s->gi.size_comment)
2432 - uReadThis = s->gi.size_comment;
2433 + unzFile file;
2434 + char *szComment;
2435 + uLong uSizeBuf;
2437 + int err=UNZ_OK;
2438 + unz_s* s;
2439 + uLong uReadThis ;
2440 + if (file==NULL)
2441 + return UNZ_PARAMERROR;
2442 + s=(unz_s*)file;
2444 - if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0)
2445 - return UNZ_ERRNO;
2446 + uReadThis = uSizeBuf;
2447 + if (uReadThis>s->gi.size_comment)
2448 + uReadThis = s->gi.size_comment;
2450 - if (uReadThis>0)
2451 + if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
2452 + return UNZ_ERRNO;
2454 + if (uReadThis>0)
2456 *szComment='\0';
2457 - if (fread(szComment,(uInt)uReadThis,1,s->file)!=1)
2458 - return UNZ_ERRNO;
2459 + if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
2460 + return UNZ_ERRNO;
2463 - if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
2464 - *(szComment+s->gi.size_comment)='\0';
2465 - return (int)uReadThis;
2466 + if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
2467 + *(szComment+s->gi.size_comment)='\0';
2468 + return (int)uReadThis;
2471 +/* Additions by RX '2004 */
2472 +extern uLong ZEXPORT unzGetOffset (file)
2473 + unzFile file;
2475 + unz_s* s;
2477 + if (file==NULL)
2478 + return UNZ_PARAMERROR;
2479 + s=(unz_s*)file;
2480 + if (!s->current_file_ok)
2481 + return 0;
2482 + if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
2483 + if (s->num_file==s->gi.number_entry)
2484 + return 0;
2485 + return s->pos_in_central_dir;
2488 +extern int ZEXPORT unzSetOffset (file, pos)
2489 + unzFile file;
2490 + uLong pos;
2492 + unz_s* s;
2493 + int err;
2495 + if (file==NULL)
2496 + return UNZ_PARAMERROR;
2497 + s=(unz_s*)file;
2499 + s->pos_in_central_dir = pos;
2500 + s->num_file = s->gi.number_entry; /* hack */
2501 + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
2502 + &s->cur_file_info_internal,
2503 + NULL,0,NULL,0,NULL,0);
2504 + s->current_file_ok = (err == UNZ_OK);
2505 + return err;
2507 --- misc/zlib-1.1.4/contrib/minizip/unzip.h 1998-03-19 00:15:00.000000000 +0100
2508 +++ misc/build/zlib-1.1.4/contrib/minizip/unzip.h 2009-07-17 10:15:15.609375000 +0200
2509 @@ -1,15 +1,16 @@
2510 -/* unzip.h -- IO for uncompress .zip files using zlib
2511 - Version 0.15 beta, Mar 19th, 1998,
2512 +/* unzip.h -- IO for uncompress .zip files using zlib
2513 + Version 1.01e, February 12th, 2005
2515 - Copyright (C) 1998 Gilles Vollant
2516 + Copyright (C) 1998-2005 Gilles Vollant
2518 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
2519 WinZip, InfoZip tools and compatible.
2520 - Encryption and multi volume ZipFile (span) are not supported.
2522 + Multi volume ZipFile (span) are not supported.
2523 + Encryption compatible with pkzip 2.04g only supported
2524 Old compressions used by old PKZip 1.x are not supported
2526 - THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
2527 - CAN CHANGE IN FUTURE VERSION !!
2529 I WAIT FEEDBACK at mail info@winimage.com
2530 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
2532 @@ -33,10 +34,13 @@
2536 -/* for more info about .ZIP format, see
2537 - ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
2539 +/* for more info about .ZIP format, see
2540 + http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
2541 + http://www.info-zip.org/pub/infozip/doc/
2542 PkWare has also a specification at :
2543 - ftp://ftp.pkware.com/probdesc.zip */
2544 + ftp://ftp.pkware.com/probdesc.zip
2547 #ifndef _unz_H
2548 #define _unz_H
2549 @@ -46,46 +50,50 @@
2550 #endif
2552 #ifndef _ZLIB_H
2553 -#include "zlib.h"
2554 +#include "zlib/zlib.h"
2555 +#endif
2557 +#ifndef _ZLIBIOAPI_H
2558 +#include "ioapi.h"
2559 #endif
2561 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
2562 /* like the STRICT of WIN32, we define a pointer that cannot be converted
2563 from (void*) without cast */
2564 -typedef struct TagunzFile__ { int unused; } unzFile__;
2565 +typedef struct TagunzFile__ { int unused; } unzFile__;
2566 typedef unzFile__ *unzFile;
2567 #else
2568 typedef voidp unzFile;
2569 #endif
2572 -#define UNZ_OK (0)
2573 -#define UNZ_END_OF_LIST_OF_FILE (-100)
2574 -#define UNZ_ERRNO (Z_ERRNO)
2575 -#define UNZ_EOF (0)
2576 +#define UNZ_OK (0)
2577 +#define UNZ_END_OF_LIST_OF_FILE (-100)
2578 +#define UNZ_ERRNO (Z_ERRNO)
2579 +#define UNZ_EOF (0)
2580 #define UNZ_PARAMERROR (-102)
2581 #define UNZ_BADZIPFILE (-103)
2582 #define UNZ_INTERNALERROR (-104)
2583 #define UNZ_CRCERROR (-105)
2585 /* tm_unz contain date/time info */
2586 -typedef struct tm_unz_s
2587 +typedef struct tm_unz_s
2589 - uInt tm_sec; /* seconds after the minute - [0,59] */
2590 - uInt tm_min; /* minutes after the hour - [0,59] */
2591 - uInt tm_hour; /* hours since midnight - [0,23] */
2592 - uInt tm_mday; /* day of the month - [1,31] */
2593 - uInt tm_mon; /* months since January - [0,11] */
2594 - uInt tm_year; /* years - [1980..2044] */
2595 + uInt tm_sec; /* seconds after the minute - [0,59] */
2596 + uInt tm_min; /* minutes after the hour - [0,59] */
2597 + uInt tm_hour; /* hours since midnight - [0,23] */
2598 + uInt tm_mday; /* day of the month - [1,31] */
2599 + uInt tm_mon; /* months since January - [0,11] */
2600 + uInt tm_year; /* years - [1980..2044] */
2601 } tm_unz;
2603 /* unz_global_info structure contain global data about the ZIPfile
2604 These data comes from the end of central dir */
2605 typedef struct unz_global_info_s
2607 - uLong number_entry; /* total number of entries in
2608 - the central dir on this disk */
2609 - uLong size_comment; /* size of the global comment of the zipfile */
2610 + uLong number_entry; /* total number of entries in
2611 + the central dir on this disk */
2612 + uLong size_comment; /* size of the global comment of the zipfile */
2613 } unz_global_info;
2616 @@ -98,8 +106,8 @@
2617 uLong compression_method; /* compression method 2 bytes */
2618 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
2619 uLong crc; /* crc-32 4 bytes */
2620 - uLong compressed_size; /* compressed size 4 bytes */
2621 - uLong uncompressed_size; /* uncompressed size 4 bytes */
2622 + uLong compressed_size; /* compressed size 4 bytes */
2623 + uLong uncompressed_size; /* uncompressed size 4 bytes */
2624 uLong size_filename; /* filename length 2 bytes */
2625 uLong size_file_extra; /* extra field length 2 bytes */
2626 uLong size_file_comment; /* file comment length 2 bytes */
2627 @@ -112,27 +120,34 @@
2628 } unz_file_info;
2630 extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
2631 - const char* fileName2,
2632 - int iCaseSensitivity));
2633 + const char* fileName2,
2634 + int iCaseSensitivity));
2636 Compare two filename (fileName1,fileName2).
2637 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
2638 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
2639 - or strcasecmp)
2640 + or strcasecmp)
2641 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
2642 - (like 1 on Unix, 2 on Windows)
2643 + (like 1 on Unix, 2 on Windows)
2647 extern unzFile ZEXPORT unzOpen OF((const char *path));
2649 Open a Zip file. path contain the full pathname (by example,
2650 - on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
2651 - "zlib/zlib111.zip".
2652 - If the zipfile cannot be opened (file don't exist or in not valid), the
2653 - return value is NULL.
2654 + on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
2655 + "zlib/zlib113.zip".
2656 + If the zipfile cannot be opened (file don't exist or in not valid), the
2657 + return value is NULL.
2658 Else, the return value is a unzFile Handle, usable with other function
2659 - of this unzip package.
2660 + of this unzip package.
2663 +extern unzFile ZEXPORT unzOpen2 OF((const char *path,
2664 + zlib_filefunc_def* pzlib_filefunc_def));
2666 + Open a Zip file, like unzOpen, but provide a set of file low level API
2667 + for read/write the zip file (see ioapi.h)
2670 extern int ZEXPORT unzClose OF((unzFile file));
2671 @@ -143,7 +158,7 @@
2672 return UNZ_OK if there is no problem. */
2674 extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
2675 - unz_global_info *pglobal_info));
2676 + unz_global_info *pglobal_info));
2678 Write info about the ZipFile in the *pglobal_info structure.
2679 No preparation of the structure is needed
2680 @@ -151,8 +166,8 @@
2683 extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
2684 - char *szComment,
2685 - uLong uSizeBuf));
2686 + char *szComment,
2687 + uLong uSizeBuf));
2689 Get the global comment string of the ZipFile, in the szComment buffer.
2690 uSizeBuf is the size of the szComment buffer.
2691 @@ -176,9 +191,9 @@
2692 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
2695 -extern int ZEXPORT unzLocateFile OF((unzFile file,
2696 - const char *szFileName,
2697 - int iCaseSensitivity));
2698 +extern int ZEXPORT unzLocateFile OF((unzFile file,
2699 + const char *szFileName,
2700 + int iCaseSensitivity));
2702 Try locate the file szFileName in the zipfile.
2703 For the iCaseSensitivity signification, see unzStringFileNameCompare
2704 @@ -189,25 +204,44 @@
2708 +/* ****************************************** */
2709 +/* Ryan supplied functions */
2710 +/* unz_file_info contain information about a file in the zipfile */
2711 +typedef struct unz_file_pos_s
2713 + uLong pos_in_zip_directory; /* offset in zip file directory */
2714 + uLong num_of_file; /* # of file */
2715 +} unz_file_pos;
2717 +extern int ZEXPORT unzGetFilePos(
2718 + unzFile file,
2719 + unz_file_pos* file_pos);
2721 +extern int ZEXPORT unzGoToFilePos(
2722 + unzFile file,
2723 + unz_file_pos* file_pos);
2725 +/* ****************************************** */
2727 extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
2728 - unz_file_info *pfile_info,
2729 - char *szFileName,
2730 - uLong fileNameBufferSize,
2731 - void *extraField,
2732 - uLong extraFieldBufferSize,
2733 - char *szComment,
2734 - uLong commentBufferSize));
2735 + unz_file_info *pfile_info,
2736 + char *szFileName,
2737 + uLong fileNameBufferSize,
2738 + void *extraField,
2739 + uLong extraFieldBufferSize,
2740 + char *szComment,
2741 + uLong commentBufferSize));
2743 Get Info about the current file
2744 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
2745 - the current file
2746 + the current file
2747 if szFileName!=NULL, the filemane string will be copied in szFileName
2748 - (fileNameBufferSize is the size of the buffer)
2749 + (fileNameBufferSize is the size of the buffer)
2750 if extraField!=NULL, the extra field information will be copied in extraField
2751 - (extraFieldBufferSize is the size of the buffer).
2752 - This is the Central-header version of the extra field
2753 + (extraFieldBufferSize is the size of the buffer).
2754 + This is the Central-header version of the extra field
2755 if szComment!=NULL, the comment string of the file will be copied in szComment
2756 - (commentBufferSize is the size of the buffer)
2757 + (commentBufferSize is the size of the buffer)
2760 /***************************************************************************/
2761 @@ -221,16 +255,51 @@
2762 If there is no error, the return value is UNZ_OK.
2765 +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
2766 + const char* password));
2768 + Open for reading data the current file in the zipfile.
2769 + password is a crypting password
2770 + If there is no error, the return value is UNZ_OK.
2773 +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
2774 + int* method,
2775 + int* level,
2776 + int raw));
2778 + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
2779 + if raw==1
2780 + *method will receive method of compression, *level will receive level of
2781 + compression
2782 + note : you can set level parameter as NULL (if you did not want known level,
2783 + but you CANNOT set method parameter as NULL
2786 +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
2787 + int* method,
2788 + int* level,
2789 + int raw,
2790 + const char* password));
2792 + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
2793 + if raw==1
2794 + *method will receive method of compression, *level will receive level of
2795 + compression
2796 + note : you can set level parameter as NULL (if you did not want known level,
2797 + but you CANNOT set method parameter as NULL
2801 extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
2803 Close the file in zip opened with unzOpenCurrentFile
2804 Return UNZ_CRCERROR if all the file was read but the CRC is not good
2808 -extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
2809 - voidp buf,
2810 - unsigned len));
2811 +extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
2812 + voidp buf,
2813 + unsigned len));
2815 Read bytes from the current file (opened by unzOpenCurrentFile)
2816 buf contain buffer where data must be copied
2817 @@ -249,12 +318,12 @@
2819 extern int ZEXPORT unzeof OF((unzFile file));
2821 - return 1 if the end of file was reached, 0 elsewhere
2822 + return 1 if the end of file was reached, 0 elsewhere
2825 extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
2826 - voidp buf,
2827 - unsigned len));
2828 + voidp buf,
2829 + unsigned len));
2831 Read extra field from the current file (opened by unzOpenCurrentFile)
2832 This is the local-header version of the extra field (sometimes, there is
2833 @@ -263,11 +332,21 @@
2834 if buf==NULL, it return the size of the local extra field
2836 if buf!=NULL, len is the size of the buffer, the extra header is copied in
2837 - buf.
2838 - the return value is the number of bytes copied in buf, or (if <0)
2839 - the error code
2840 + buf.
2841 + the return value is the number of bytes copied in buf, or (if <0)
2842 + the error code
2845 +/***************************************************************************/
2847 +/* Get the current file offset */
2848 +extern uLong ZEXPORT unzGetOffset (unzFile file);
2850 +/* Set the current file offset */
2851 +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
2855 #ifdef __cplusplus
2857 #endif
2858 --- misc/zlib-1.1.4/contrib/minizip/crypt.h 2009-07-17 11:13:37.281250000 +0200
2859 +++ misc/build/zlib-1.1.4/contrib/minizip/crypt.h 2009-07-17 10:58:41.843750000 +0200
2860 @@ -0,0 +1,132 @@
2861 +/* crypt.h -- base code for crypt/uncrypt ZIPfile
2864 + Version 1.01e, February 12th, 2005
2866 + Copyright (C) 1998-2005 Gilles Vollant
2868 + This code is a modified version of crypting code in Infozip distribution
2870 + The encryption/decryption parts of this source code (as opposed to the
2871 + non-echoing password parts) were originally written in Europe. The
2872 + whole source package can be freely distributed, including from the USA.
2873 + (Prior to January 2000, re-export from the US was a violation of US law.)
2875 + This encryption code is a direct transcription of the algorithm from
2876 + Roger Schlafly, described by Phil Katz in the file appnote.txt. This
2877 + file (appnote.txt) is distributed with the PKZIP program (even in the
2878 + version without encryption capabilities).
2880 + If you don't need crypting in your application, just define symbols
2881 + NOCRYPT and NOUNCRYPT.
2883 + This code support the "Traditional PKWARE Encryption".
2885 + The new AES encryption added on Zip format by Winzip (see the page
2886 + http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
2887 + Encryption is not supported.
2890 +#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
2892 +/***********************************************************************
2893 + * Return the next byte in the pseudo-random sequence
2894 + */
2895 +static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
2897 + unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
2898 + * unpredictable manner on 16-bit systems; not a problem
2899 + * with any known compiler so far, though */
2901 + temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
2902 + return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
2905 +/***********************************************************************
2906 + * Update the encryption keys with the next byte of plain text
2907 + */
2908 +static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
2910 + (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
2911 + (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
2912 + (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
2914 + register int keyshift = (int)((*(pkeys+1)) >> 24);
2915 + (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
2917 + return c;
2921 +/***********************************************************************
2922 + * Initialize the encryption keys and the random header according to
2923 + * the given password.
2924 + */
2925 +static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
2927 + *(pkeys+0) = 305419896L;
2928 + *(pkeys+1) = 591751049L;
2929 + *(pkeys+2) = 878082192L;
2930 + while (*passwd != '\0') {
2931 + update_keys(pkeys,pcrc_32_tab,(int)*passwd);
2932 + passwd++;
2936 +#define zdecode(pkeys,pcrc_32_tab,c) \
2937 + (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
2939 +#define zencode(pkeys,pcrc_32_tab,c,t) \
2940 + (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
2942 +#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
2944 +#define RAND_HEAD_LEN 12
2945 + /* "last resort" source for second part of crypt seed pattern */
2946 +# ifndef ZCR_SEED2
2947 +# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
2948 +# endif
2950 +static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
2951 + const char *passwd; /* password string */
2952 + unsigned char *buf; /* where to write header */
2953 + int bufSize;
2954 + unsigned long* pkeys;
2955 + const unsigned long* pcrc_32_tab;
2956 + unsigned long crcForCrypting;
2958 + int n; /* index in random header */
2959 + int t; /* temporary */
2960 + int c; /* random byte */
2961 + unsigned char header[RAND_HEAD_LEN-2]; /* random header */
2962 + static unsigned calls = 0; /* ensure different random header each time */
2964 + if (bufSize<RAND_HEAD_LEN)
2965 + return 0;
2967 + /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
2968 + * output of rand() to get less predictability, since rand() is
2969 + * often poorly implemented.
2970 + */
2971 + if (++calls == 1)
2973 + srand((unsigned)(time(NULL) ^ ZCR_SEED2));
2975 + init_keys(passwd, pkeys, pcrc_32_tab);
2976 + for (n = 0; n < RAND_HEAD_LEN-2; n++)
2978 + c = (rand() >> 7) & 0xff;
2979 + header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
2981 + /* Encrypt random header (last two bytes is high word of crc) */
2982 + init_keys(passwd, pkeys, pcrc_32_tab);
2983 + for (n = 0; n < RAND_HEAD_LEN-2; n++)
2985 + buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
2987 + buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
2988 + buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
2989 + return n;
2992 +#endif
2993 --- misc/zlib-1.1.4/contrib/minizip/ioapi.c 2009-07-17 11:13:18.593750000 +0200
2994 +++ misc/build/zlib-1.1.4/contrib/minizip/ioapi.c 2009-07-17 10:58:56.718750000 +0200
2995 @@ -0,0 +1,177 @@
2996 +/* ioapi.c -- IO base function header for compress/uncompress .zip
2997 + files using zlib + zip or unzip API
2999 + Version 1.01e, February 12th, 2005
3001 + Copyright (C) 1998-2005 Gilles Vollant
3004 +#include <stdio.h>
3005 +#include <stdlib.h>
3006 +#include <string.h>
3008 +#include "zlib.h"
3009 +#include "ioapi.h"
3013 +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
3015 +#ifndef SEEK_CUR
3016 +#define SEEK_CUR 1
3017 +#endif
3019 +#ifndef SEEK_END
3020 +#define SEEK_END 2
3021 +#endif
3023 +#ifndef SEEK_SET
3024 +#define SEEK_SET 0
3025 +#endif
3027 +voidpf ZCALLBACK fopen_file_func OF((
3028 + voidpf opaque,
3029 + const char* filename,
3030 + int mode));
3032 +uLong ZCALLBACK fread_file_func OF((
3033 + voidpf opaque,
3034 + voidpf stream,
3035 + void* buf,
3036 + uLong size));
3038 +uLong ZCALLBACK fwrite_file_func OF((
3039 + voidpf opaque,
3040 + voidpf stream,
3041 + const void* buf,
3042 + uLong size));
3044 +long ZCALLBACK ftell_file_func OF((
3045 + voidpf opaque,
3046 + voidpf stream));
3048 +long ZCALLBACK fseek_file_func OF((
3049 + voidpf opaque,
3050 + voidpf stream,
3051 + uLong offset,
3052 + int origin));
3054 +int ZCALLBACK fclose_file_func OF((
3055 + voidpf opaque,
3056 + voidpf stream));
3058 +int ZCALLBACK ferror_file_func OF((
3059 + voidpf opaque,
3060 + voidpf stream));
3063 +voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
3064 + voidpf opaque;
3065 + const char* filename;
3066 + int mode;
3068 + FILE* file = NULL;
3069 + const char* mode_fopen = NULL;
3070 + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
3071 + mode_fopen = "rb";
3072 + else
3073 + if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
3074 + mode_fopen = "r+b";
3075 + else
3076 + if (mode & ZLIB_FILEFUNC_MODE_CREATE)
3077 + mode_fopen = "wb";
3079 + if ((filename!=NULL) && (mode_fopen != NULL))
3080 + file = fopen(filename, mode_fopen);
3081 + return file;
3085 +uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
3086 + voidpf opaque;
3087 + voidpf stream;
3088 + void* buf;
3089 + uLong size;
3091 + uLong ret;
3092 + ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
3093 + return ret;
3097 +uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
3098 + voidpf opaque;
3099 + voidpf stream;
3100 + const void* buf;
3101 + uLong size;
3103 + uLong ret;
3104 + ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
3105 + return ret;
3108 +long ZCALLBACK ftell_file_func (opaque, stream)
3109 + voidpf opaque;
3110 + voidpf stream;
3112 + long ret;
3113 + ret = ftell((FILE *)stream);
3114 + return ret;
3117 +long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
3118 + voidpf opaque;
3119 + voidpf stream;
3120 + uLong offset;
3121 + int origin;
3123 + int fseek_origin=0;
3124 + long ret;
3125 + switch (origin)
3127 + case ZLIB_FILEFUNC_SEEK_CUR :
3128 + fseek_origin = SEEK_CUR;
3129 + break;
3130 + case ZLIB_FILEFUNC_SEEK_END :
3131 + fseek_origin = SEEK_END;
3132 + break;
3133 + case ZLIB_FILEFUNC_SEEK_SET :
3134 + fseek_origin = SEEK_SET;
3135 + break;
3136 + default: return -1;
3138 + ret = 0;
3139 + fseek((FILE *)stream, offset, fseek_origin);
3140 + return ret;
3143 +int ZCALLBACK fclose_file_func (opaque, stream)
3144 + voidpf opaque;
3145 + voidpf stream;
3147 + int ret;
3148 + ret = fclose((FILE *)stream);
3149 + return ret;
3152 +int ZCALLBACK ferror_file_func (opaque, stream)
3153 + voidpf opaque;
3154 + voidpf stream;
3156 + int ret;
3157 + ret = ferror((FILE *)stream);
3158 + return ret;
3161 +void fill_fopen_filefunc (pzlib_filefunc_def)
3162 + zlib_filefunc_def* pzlib_filefunc_def;
3164 + pzlib_filefunc_def->zopen_file = fopen_file_func;
3165 + pzlib_filefunc_def->zread_file = fread_file_func;
3166 + pzlib_filefunc_def->zwrite_file = fwrite_file_func;
3167 + pzlib_filefunc_def->ztell_file = ftell_file_func;
3168 + pzlib_filefunc_def->zseek_file = fseek_file_func;
3169 + pzlib_filefunc_def->zclose_file = fclose_file_func;
3170 + pzlib_filefunc_def->zerror_file = ferror_file_func;
3171 + pzlib_filefunc_def->opaque = NULL;
3173 --- misc/zlib-1.1.4/contrib/minizip/ioapi.h 2009-07-17 11:13:30.109375000 +0200
3174 +++ misc/build/zlib-1.1.4/contrib/minizip/ioapi.h 2009-07-17 10:59:06.375000000 +0200
3175 @@ -0,0 +1,75 @@
3176 +/* ioapi.h -- IO base function header for compress/uncompress .zip
3177 + files using zlib + zip or unzip API
3179 + Version 1.01e, February 12th, 2005
3181 + Copyright (C) 1998-2005 Gilles Vollant
3184 +#ifndef _ZLIBIOAPI_H
3185 +#define _ZLIBIOAPI_H
3188 +#define ZLIB_FILEFUNC_SEEK_CUR (1)
3189 +#define ZLIB_FILEFUNC_SEEK_END (2)
3190 +#define ZLIB_FILEFUNC_SEEK_SET (0)
3192 +#define ZLIB_FILEFUNC_MODE_READ (1)
3193 +#define ZLIB_FILEFUNC_MODE_WRITE (2)
3194 +#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
3196 +#define ZLIB_FILEFUNC_MODE_EXISTING (4)
3197 +#define ZLIB_FILEFUNC_MODE_CREATE (8)
3200 +#ifndef ZCALLBACK
3202 +#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
3203 +#define ZCALLBACK CALLBACK
3204 +#else
3205 +#define ZCALLBACK
3206 +#endif
3207 +#endif
3209 +#ifdef __cplusplus
3210 +extern "C" {
3211 +#endif
3213 +typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
3214 +typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
3215 +typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
3216 +typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
3217 +typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
3218 +typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
3219 +typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
3221 +typedef struct zlib_filefunc_def_s
3223 + open_file_func zopen_file;
3224 + read_file_func zread_file;
3225 + write_file_func zwrite_file;
3226 + tell_file_func ztell_file;
3227 + seek_file_func zseek_file;
3228 + close_file_func zclose_file;
3229 + testerror_file_func zerror_file;
3230 + voidpf opaque;
3231 +} zlib_filefunc_def;
3235 +void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
3237 +#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
3238 +#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
3239 +#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
3240 +#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
3241 +#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
3242 +#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
3245 +#ifdef __cplusplus
3247 +#endif
3249 +#endif