merged tag ooo/DEV300_m102
[LibreOffice.git] / zlib / zlib-1.1.4.patch
blob19d1cd5904eac3f047bd7c79178a655e90fd96c7
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,73 @@
4 -dummy
5 +#*************************************************************************
6 +#
7 +# Copyright according the GNU Public License.
8 +#
9 +#*************************************************************************
11 +PRJ=..$/..$/..$/..
13 +PRJNAME=zlib
14 +TARGET=zlib
15 +LIBTARGET=NO
16 +EXTERNAL_WARNINGS_NOT_ERRORS=TRUE
18 +# --- Settings -----------------------------------------------------
20 +.INCLUDE : settings.mk
22 +# --- Files --------------------------------------------------------
24 +INCEXT=contrib$/minizip
26 +SLOFILES= $(SLO)$/adler32.obj \
27 + $(SLO)$/compress.obj \
28 + $(SLO)$/deflate.obj \
29 + $(SLO)$/crc32.obj \
30 + $(SLO)$/infblock.obj \
31 + $(SLO)$/infcodes.obj \
32 + $(SLO)$/inffast.obj \
33 + $(SLO)$/inflate.obj \
34 + $(SLO)$/inftrees.obj \
35 + $(SLO)$/infutil.obj \
36 + $(SLO)$/trees.obj \
37 + $(SLO)$/zutil.obj \
38 + $(SLO)$/unzip.obj \
39 + $(SLO)$/ioapi.obj
42 +LIB1TARGET=$(SLB)$/$(TARGET).lib
43 +LIB1ARCHIV=$(LB)$/lib$(TARGET).a
44 +LIB1OBJFILES=$(SLOFILES)
46 +.IF "$(BUILD_X64)"!=""
47 +SLOFILES_X64= $(SLO_X64)$/adler32.obj \
48 + $(SLO_X64)$/compress.obj \
49 + $(SLO_X64)$/deflate.obj \
50 + $(SLO_X64)$/crc32.obj \
51 + $(SLO_X64)$/infblock.obj \
52 + $(SLO_X64)$/infcodes.obj \
53 + $(SLO_X64)$/inffast.obj \
54 + $(SLO_X64)$/inflate.obj \
55 + $(SLO_X64)$/inftrees.obj \
56 + $(SLO_X64)$/infutil.obj \
57 + $(SLO_X64)$/trees.obj \
58 + $(SLO_X64)$/zutil.obj \
59 + $(SLO_X64)$/unzip.obj \
60 + $(SLO_X64)$/ioapi.obj
62 +LIB1TARGET_X64=$(SLB_X64)$/$(TARGET).lib
63 +LIB1OBJFILES_X64=$(SLOFILES_X64)
64 +.ENDIF # "$(BUILD_X64)"!=""
67 +# --- Targets ------------------------------------------------------
69 +$(MISC)$/%.c : contrib$/minizip$/%.c
70 + @echo ------------------------------
71 + @echo Making: $@
72 + @$(COPY) $< $@
74 +.INCLUDE : set_wntx64.mk
75 +.INCLUDE : target.mk
76 +.INCLUDE : tg_wntx64.mk
78 --- misc/zlib-1.1.4/zconf.h Mon Mar 11 14:16:01 2002
79 +++ misc/build/zlib-1.1.4/zconf.h Fri Mar 14 10:15:45 2008
80 @@ -12,6 +12,12 @@
81 * If you *really* need a unique prefix for all types and library functions,
82 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
84 +/*
85 + * we need the prefix to get the same names as in 1.1.3
86 +*/
88 +#define Z_PREFIX
90 #ifdef Z_PREFIX
91 # define deflateInit_ z_deflateInit_
92 # define deflate z_deflate
93 @@ -36,10 +42,26 @@
94 # define crc32 z_crc32
95 # define get_crc_table z_get_crc_table
97 +# define inflate_blocks z_inflate_blocks
98 +# define inflate_blocks_new z_inflate_blocks_new
99 +# define inflate_blocks_free z_inflate_blocks_free
100 +# define inflate_blocks_reset z_inflate_blocks_reset
101 +# define inflate_codes_free z_inflate_codes_free
102 +# define inflate_codes z_inflate_codes
103 +# define inflate_fast z_inflate_fast
104 +# define inflate_flush z_inflate_flush
105 +# define inflate_mask z_inflate_mask
106 +# define inflate_set_dictionary z_inflate_set_dictionary
107 +# define inflate_copyright z_inflate_copyright
108 +# define inflate_trees_bits z_inflate_trees_bits
109 +# define inflate_trees_dynamic z_inflate_trees_dynamic
110 +# define inflate_trees_fixed z_inflate_trees_fixed
111 +# define inflate_trees_free z_inflate_trees_free
113 # define Byte z_Byte
114 # define uInt z_uInt
115 # define uLong z_uLong
116 -# define Bytef z_Bytef
117 +# define Bytef z_Bytef
118 # define charf z_charf
119 # define intf z_intf
120 # define uIntf z_uIntf
121 --- misc/zlib-1.1.4/zlib.h Mon Mar 11 14:56:38 2002
122 +++ misc/build/zlib-1.1.4/zlib.h Fri Mar 14 10:15:45 2008
123 @@ -27,7 +27,6 @@
124 Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
125 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
128 #ifndef _ZLIB_H
129 #define _ZLIB_H
131 @@ -168,7 +167,9 @@
133 /* basic functions */
135 +#if !defined(ZUTIL_PROTOS_OFF)
136 ZEXTERN const char * ZEXPORT zlibVersion OF((void));
137 +#endif
138 /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
139 If the first character differs, the library code actually used is
140 not compatible with the zlib.h header file used by the application.
141 @@ -882,7 +883,9 @@
142 struct internal_state {int dummy;}; /* hack for buggy compilers */
143 #endif
145 +#if !defined(ZUTIL_PROTOS_OFF)
146 ZEXTERN const char * ZEXPORT zError OF((int err));
147 +#endif
148 ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
149 ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
151 --- misc/zlib-1.1.4/zutil.c Mon Mar 11 14:16:01 2002
152 +++ misc/build/zlib-1.1.4/zutil.c Fri Mar 14 10:15:45 2008
153 @@ -5,6 +5,9 @@
155 /* @(#) $Id$ */
157 +#ifdef MACOSX
158 +#define ZUTIL_PROTOS_OFF
159 +#endif
160 #include "zutil.h"
162 struct internal_state {int dummy;}; /* for buggy compilers */
163 --- misc/zlib-1.1.4/contrib/minizip/unzip.c 1998-06-15 17:34:20.000000000 +0200
164 +++ misc/build/zlib-1.1.4/contrib/minizip/unzip.c 2009-07-17 10:15:05.156250000 +0200
165 @@ -1,9 +1,39 @@
166 -/* unzip.c -- IO on .zip files using zlib
167 - Version 0.15 beta, Mar 19th, 1998,
168 +/* unzip.c -- IO for uncompress .zip files using zlib
169 + Version 1.01e, February 12th, 2005
171 + Copyright (C) 1998-2005 Gilles Vollant
173 Read unzip.h for more info
176 +/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
177 +compatibility with older software. The following is from the original crypt.c. Code
178 +woven in by Terry Thorsen 1/2003.
181 + Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
183 + See the accompanying file LICENSE, version 2000-Apr-09 or later
184 + (the contents of which are also included in zip.h) for terms of use.
185 + If, for some reason, all these files are missing, the Info-ZIP license
186 + also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
189 + crypt.c (full version) by Info-ZIP. Last revised: [see info_zip_crypt.h]
191 + The encryption/decryption parts of this source code (as opposed to the
192 + non-echoing password parts) were originally written in Europe. The
193 + whole source package can be freely distributed, including from the USA.
194 + (Prior to January 2000, re-export from the US was a violation of US law.)
195 + */
198 + This encryption code is a direct transcription of the algorithm from
199 + Roger Schlafly, described by Phil Katz in the file appnote.txt. This
200 + file (appnote.txt) is distributed with the PKZIP program (even in the
201 + version without encryption capabilities).
202 + */
205 #include <stdio.h>
206 #include <stdlib.h>
207 @@ -29,10 +59,10 @@
208 /* compile with -Dlocal if your debugger can't find static symbols */
212 -#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \
213 - !defined(CASESENSITIVITYDEFAULT_NO)
214 -#define CASESENSITIVITYDEFAULT_NO
215 +#ifndef CASESENSITIVITYDEFAULT_NO
216 +# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
217 +# define CASESENSITIVITYDEFAULT_NO
218 +# endif
219 #endif
222 @@ -55,22 +85,10 @@
223 #define SIZEZIPLOCALHEADER (0x1e)
226 -/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
228 -#ifndef SEEK_CUR
229 -#define SEEK_CUR 1
230 -#endif
232 -#ifndef SEEK_END
233 -#define SEEK_END 2
234 -#endif
236 -#ifndef SEEK_SET
237 -#define SEEK_SET 0
238 -#endif
240 const char unz_copyright[] =
241 - " unzip 0.15 Copyright 1998 Gilles Vollant ";
242 + " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
244 /* unz_file_info_interntal contain internal info about a file in zipfile*/
245 typedef struct unz_file_info_internal_s
246 @@ -83,23 +101,25 @@
247 when reading and decompress it */
248 typedef struct
250 - char *read_buffer; /* internal buffer for compressed data */
251 - z_stream stream; /* zLib stream structure for inflate */
252 + char *read_buffer; /* internal buffer for compressed data */
253 + z_stream stream; /* zLib stream structure for inflate */
255 - uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
256 - uLong stream_initialised; /* flag set if stream structure is initialised*/
257 + uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
258 + uLong stream_initialised; /* flag set if stream structure is initialised*/
260 - uLong offset_local_extrafield;/* offset of the local extra field */
261 - uInt size_local_extrafield;/* size of the local extra field */
262 - uLong pos_local_extrafield; /* position in the local extra field in read*/
264 - uLong crc32; /* crc32 of all data uncompressed */
265 - uLong crc32_wait; /* crc32 we must obtain after decompress all */
266 - uLong rest_read_compressed; /* number of byte to be decompressed */
267 - uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
268 - FILE* file; /* io structore of the zipfile */
269 - uLong compression_method; /* compression method (0==store) */
270 - uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
271 + uLong offset_local_extrafield;/* offset of the local extra field */
272 + uInt size_local_extrafield;/* size of the local extra field */
273 + uLong pos_local_extrafield; /* position in the local extra field in read*/
275 + uLong crc32; /* crc32 of all data uncompressed */
276 + uLong crc32_wait; /* crc32 we must obtain after decompress all */
277 + uLong rest_read_compressed; /* number of byte to be decompressed */
278 + uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
279 + zlib_filefunc_def z_filefunc;
280 + voidpf filestream; /* io structore of the zipfile */
281 + uLong compression_method; /* compression method (0==store) */
282 + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
283 + int raw;
284 } file_in_zip_read_info_s;
287 @@ -107,25 +127,35 @@
289 typedef struct
291 - FILE* file; /* io structore of the zipfile */
292 - unz_global_info gi; /* public global information */
293 - uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
294 - uLong num_file; /* number of the current file in the zipfile*/
295 - uLong pos_in_central_dir; /* pos of the current file in the central dir*/
296 - uLong current_file_ok; /* flag about the usability of the current file*/
297 - uLong central_pos; /* position of the beginning of the central dir*/
299 - uLong size_central_dir; /* size of the central directory */
300 - uLong offset_central_dir; /* offset of start of central directory with
301 - respect to the starting disk number */
302 + zlib_filefunc_def z_filefunc;
303 + voidpf filestream; /* io structore of the zipfile */
304 + unz_global_info gi; /* public global information */
305 + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
306 + uLong num_file; /* number of the current file in the zipfile*/
307 + uLong pos_in_central_dir; /* pos of the current file in the central dir*/
308 + uLong current_file_ok; /* flag about the usability of the current file*/
309 + uLong central_pos; /* position of the beginning of the central dir*/
311 + uLong size_central_dir; /* size of the central directory */
312 + uLong offset_central_dir; /* offset of start of central directory with
313 + respect to the starting disk number */
315 - unz_file_info cur_file_info; /* public info about the current file in zip*/
316 - unz_file_info_internal cur_file_info_internal; /* private info about it*/
317 + unz_file_info cur_file_info; /* public info about the current file in zip*/
318 + unz_file_info_internal cur_file_info_internal; /* private info about it*/
319 file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
320 - file if we are decompressing it */
321 + file if we are decompressing it */
322 + int encrypted;
323 +# ifndef NOUNCRYPT
324 + unsigned long keys[3]; /* keys defining the pseudo-random sequence */
325 + const unsigned long* pcrc_32_tab;
326 +# endif
327 } unz_s;
330 +#ifndef NOUNCRYPT
331 +#include "info_zip_crypt.h"
332 +#endif
334 /* ===========================================================================
335 Read a byte from a gz_stream; update next_in and avail_in. Return EOF
336 for end of file.
337 @@ -133,12 +163,18 @@
341 -local int unzlocal_getByte(fin,pi)
342 - FILE *fin;
343 - int *pi;
344 +local int unzlocal_getByte OF((
345 + const zlib_filefunc_def* pzlib_filefunc_def,
346 + voidpf filestream,
347 + int *pi));
349 +local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
350 + const zlib_filefunc_def* pzlib_filefunc_def;
351 + voidpf filestream;
352 + int *pi;
354 unsigned char c;
355 - int err = fread(&c, 1, 1, fin);
356 + int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
357 if (err==1)
359 *pi = (int)c;
360 @@ -146,7 +182,7 @@
362 else
364 - if (ferror(fin))
365 + if (ZERROR(*pzlib_filefunc_def,filestream))
366 return UNZ_ERRNO;
367 else
368 return UNZ_EOF;
369 @@ -155,23 +191,29 @@
372 /* ===========================================================================
373 - Reads a long in LSB order from the given gz_stream. Sets
374 + Reads a long in LSB order from the given gz_stream. Sets
376 -local int unzlocal_getShort (fin,pX)
377 - FILE* fin;
378 +local int unzlocal_getShort OF((
379 + const zlib_filefunc_def* pzlib_filefunc_def,
380 + voidpf filestream,
381 + uLong *pX));
383 +local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
384 + const zlib_filefunc_def* pzlib_filefunc_def;
385 + voidpf filestream;
386 uLong *pX;
388 uLong x ;
389 int i;
390 int err;
392 - err = unzlocal_getByte(fin,&i);
393 + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
394 x = (uLong)i;
397 if (err==UNZ_OK)
398 - err = unzlocal_getByte(fin,&i);
399 + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
400 x += ((uLong)i)<<8;
403 if (err==UNZ_OK)
404 *pX = x;
405 else
406 @@ -179,29 +221,35 @@
407 return err;
410 -local int unzlocal_getLong (fin,pX)
411 - FILE* fin;
412 +local int unzlocal_getLong OF((
413 + const zlib_filefunc_def* pzlib_filefunc_def,
414 + voidpf filestream,
415 + uLong *pX));
417 +local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
418 + const zlib_filefunc_def* pzlib_filefunc_def;
419 + voidpf filestream;
420 uLong *pX;
422 uLong x ;
423 int i;
424 int err;
426 - err = unzlocal_getByte(fin,&i);
427 + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
428 x = (uLong)i;
431 if (err==UNZ_OK)
432 - err = unzlocal_getByte(fin,&i);
433 + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
434 x += ((uLong)i)<<8;
436 if (err==UNZ_OK)
437 - err = unzlocal_getByte(fin,&i);
438 + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
439 x += ((uLong)i)<<16;
441 if (err==UNZ_OK)
442 - err = unzlocal_getByte(fin,&i);
443 + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
444 x += ((uLong)i)<<24;
447 if (err==UNZ_OK)
448 *pX = x;
449 else
450 @@ -212,26 +260,26 @@
452 /* My own strcmpi / strcasecmp */
453 local int strcmpcasenosensitive_internal (fileName1,fileName2)
454 - const char* fileName1;
455 - const char* fileName2;
456 + const char* fileName1;
457 + const char* fileName2;
459 - for (;;)
461 - char c1=*(fileName1++);
462 - char c2=*(fileName2++);
463 - if ((c1>='a') && (c1<='z'))
464 - c1 -= 0x20;
465 - if ((c2>='a') && (c2<='z'))
466 - c2 -= 0x20;
467 - if (c1=='\0')
468 - return ((c2=='\0') ? 0 : -1);
469 - if (c2=='\0')
470 - return 1;
471 - if (c1<c2)
472 - return -1;
473 - if (c1>c2)
474 - return 1;
476 + for (;;)
478 + char c1=*(fileName1++);
479 + char c2=*(fileName2++);
480 + if ((c1>='a') && (c1<='z'))
481 + c1 -= 0x20;
482 + if ((c2>='a') && (c2<='z'))
483 + c2 -= 0x20;
484 + if (c1=='\0')
485 + return ((c2=='\0') ? 0 : -1);
486 + if (c2=='\0')
487 + return 1;
488 + if (c1<c2)
489 + return -1;
490 + if (c1>c2)
491 + return 1;
496 @@ -245,7 +293,7 @@
497 #define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
498 #endif
500 -/*
502 Compare two filename (fileName1,fileName2).
503 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
504 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
505 @@ -255,203 +303,225 @@
508 extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
509 - const char* fileName1;
510 - const char* fileName2;
511 - int iCaseSensitivity;
512 + const char* fileName1;
513 + const char* fileName2;
514 + int iCaseSensitivity;
516 - if (iCaseSensitivity==0)
517 - iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
518 + if (iCaseSensitivity==0)
519 + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
521 - if (iCaseSensitivity==1)
522 - return strcmp(fileName1,fileName2);
523 + if (iCaseSensitivity==1)
524 + return strcmp(fileName1,fileName2);
526 - return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
528 + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
531 +#ifndef BUFREADCOMMENT
532 #define BUFREADCOMMENT (0x400)
533 +#endif
536 Locate the Central directory of a zipfile (at the end, just before
537 the global comment)
539 -local uLong unzlocal_SearchCentralDir(fin)
540 - FILE *fin;
541 +local uLong unzlocal_SearchCentralDir OF((
542 + const zlib_filefunc_def* pzlib_filefunc_def,
543 + voidpf filestream));
545 +local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
546 + const zlib_filefunc_def* pzlib_filefunc_def;
547 + voidpf filestream;
549 - unsigned char* buf;
550 - uLong uSizeFile;
551 - uLong uBackRead;
552 - uLong uMaxBack=0xffff; /* maximum size of global comment */
553 - uLong uPosFound=0;
555 - if (fseek(fin,0,SEEK_END) != 0)
556 - return 0;
559 - uSizeFile = ftell( fin );
561 - if (uMaxBack>uSizeFile)
562 - uMaxBack = uSizeFile;
564 - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
565 - if (buf==NULL)
566 - return 0;
568 - uBackRead = 4;
569 - while (uBackRead<uMaxBack)
571 - uLong uReadSize,uReadPos ;
572 - int i;
573 - if (uBackRead+BUFREADCOMMENT>uMaxBack)
574 - uBackRead = uMaxBack;
575 - else
576 - uBackRead+=BUFREADCOMMENT;
577 - uReadPos = uSizeFile-uBackRead ;
579 - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
580 + unsigned char* buf;
581 + uLong uSizeFile;
582 + uLong uBackRead;
583 + uLong uMaxBack=0xffff; /* maximum size of global comment */
584 + uLong uPosFound=0;
586 + if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
587 + return 0;
590 + uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
592 + if (uMaxBack>uSizeFile)
593 + uMaxBack = uSizeFile;
595 + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
596 + if (buf==NULL)
597 + return 0;
599 + uBackRead = 4;
600 + while (uBackRead<uMaxBack)
602 + uLong uReadSize,uReadPos ;
603 + int i;
604 + if (uBackRead+BUFREADCOMMENT>uMaxBack)
605 + uBackRead = uMaxBack;
606 + else
607 + uBackRead+=BUFREADCOMMENT;
608 + uReadPos = uSizeFile-uBackRead ;
610 + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
611 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
612 - if (fseek(fin,uReadPos,SEEK_SET)!=0)
613 - break;
614 + if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
615 + break;
617 - if (fread(buf,(uInt)uReadSize,1,fin)!=1)
618 - break;
619 + if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
620 + break;
622 - for (i=(int)uReadSize-3; (i--)>0;)
623 - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
624 - ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
626 - uPosFound = uReadPos+i;
627 - break;
630 - if (uPosFound!=0)
631 - break;
633 - TRYFREE(buf);
634 - return uPosFound;
635 + for (i=(int)uReadSize-3; (i--)>0;)
636 + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
637 + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
639 + uPosFound = uReadPos+i;
640 + break;
643 + if (uPosFound!=0)
644 + break;
646 + TRYFREE(buf);
647 + return uPosFound;
651 Open a Zip file. path contain the full pathname (by example,
652 - on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer
653 - "zlib/zlib109.zip".
654 - If the zipfile cannot be opened (file don't exist or in not valid), the
655 - return value is NULL.
656 + on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
657 + "zlib/zlib114.zip".
658 + If the zipfile cannot be opened (file doesn't exist or in not valid), the
659 + return value is NULL.
660 Else, the return value is a unzFile Handle, usable with other function
661 - of this unzip package.
662 + of this unzip package.
664 -extern unzFile ZEXPORT unzOpen (path)
665 - const char *path;
667 - unz_s us;
668 - unz_s *s;
669 - uLong central_pos,uL;
670 - FILE * fin ;
672 - uLong number_disk; /* number of the current dist, used for
673 - spaning ZIP, unsupported, always 0*/
674 - uLong number_disk_with_CD; /* number the the disk with central dir, used
675 - for spaning ZIP, unsupported, always 0*/
676 - uLong number_entry_CD; /* total number of entries in
677 - the central dir
678 - (same than number_entry on nospan) */
679 +extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
680 + const char *path;
681 + zlib_filefunc_def* pzlib_filefunc_def;
683 + unz_s us;
684 + unz_s *s;
685 + uLong central_pos,uL;
687 + uLong number_disk; /* number of the current dist, used for
688 + spaning ZIP, unsupported, always 0*/
689 + uLong number_disk_with_CD; /* number the the disk with central dir, used
690 + for spaning ZIP, unsupported, always 0*/
691 + uLong number_entry_CD; /* total number of entries in
692 + the central dir
693 + (same than number_entry on nospan) */
695 - int err=UNZ_OK;
696 + int err=UNZ_OK;
698 if (unz_copyright[0]!=' ')
699 return NULL;
701 - fin=fopen(path,"rb");
702 - if (fin==NULL)
703 - return NULL;
705 - central_pos = unzlocal_SearchCentralDir(fin);
706 - if (central_pos==0)
707 - err=UNZ_ERRNO;
709 - if (fseek(fin,central_pos,SEEK_SET)!=0)
710 - err=UNZ_ERRNO;
712 - /* the signature, already checked */
713 - if (unzlocal_getLong(fin,&uL)!=UNZ_OK)
714 - err=UNZ_ERRNO;
716 - /* number of this disk */
717 - if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK)
718 - err=UNZ_ERRNO;
720 - /* number of the disk with the start of the central directory */
721 - if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK)
722 - err=UNZ_ERRNO;
724 - /* total number of entries in the central dir on this disk */
725 - if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK)
726 - err=UNZ_ERRNO;
728 - /* total number of entries in the central dir */
729 - if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK)
730 - err=UNZ_ERRNO;
732 - if ((number_entry_CD!=us.gi.number_entry) ||
733 - (number_disk_with_CD!=0) ||
734 - (number_disk!=0))
735 - err=UNZ_BADZIPFILE;
737 - /* size of the central directory */
738 - if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK)
739 - err=UNZ_ERRNO;
741 - /* offset of start of central directory with respect to the
742 - starting disk number */
743 - if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK)
744 - err=UNZ_ERRNO;
746 - /* zipfile comment length */
747 - if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK)
748 - err=UNZ_ERRNO;
750 - if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
751 - (err==UNZ_OK))
752 - err=UNZ_BADZIPFILE;
754 - if (err!=UNZ_OK)
756 - fclose(fin);
757 - return NULL;
760 - us.file=fin;
761 - us.byte_before_the_zipfile = central_pos -
762 - (us.offset_central_dir+us.size_central_dir);
763 - us.central_pos = central_pos;
764 + if (pzlib_filefunc_def==NULL)
765 + fill_fopen_filefunc(&us.z_filefunc);
766 + else
767 + us.z_filefunc = *pzlib_filefunc_def;
769 + us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
770 + path,
771 + ZLIB_FILEFUNC_MODE_READ |
772 + ZLIB_FILEFUNC_MODE_EXISTING);
773 + if (us.filestream==NULL)
774 + return NULL;
776 + central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);
777 + if (central_pos==0)
778 + err=UNZ_ERRNO;
780 + if (ZSEEK(us.z_filefunc, us.filestream,
781 + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
782 + err=UNZ_ERRNO;
784 + /* the signature, already checked */
785 + if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
786 + err=UNZ_ERRNO;
788 + /* number of this disk */
789 + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
790 + err=UNZ_ERRNO;
792 + /* number of the disk with the start of the central directory */
793 + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
794 + err=UNZ_ERRNO;
796 + /* total number of entries in the central dir on this disk */
797 + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
798 + err=UNZ_ERRNO;
800 + /* total number of entries in the central dir */
801 + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
802 + err=UNZ_ERRNO;
804 + if ((number_entry_CD!=us.gi.number_entry) ||
805 + (number_disk_with_CD!=0) ||
806 + (number_disk!=0))
807 + err=UNZ_BADZIPFILE;
809 + /* size of the central directory */
810 + if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
811 + err=UNZ_ERRNO;
813 + /* offset of start of central directory with respect to the
814 + starting disk number */
815 + if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
816 + err=UNZ_ERRNO;
818 + /* zipfile comment length */
819 + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
820 + err=UNZ_ERRNO;
822 + if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
823 + (err==UNZ_OK))
824 + err=UNZ_BADZIPFILE;
826 + if (err!=UNZ_OK)
828 + ZCLOSE(us.z_filefunc, us.filestream);
829 + return NULL;
832 + us.byte_before_the_zipfile = central_pos -
833 + (us.offset_central_dir+us.size_central_dir);
834 + us.central_pos = central_pos;
835 us.pfile_in_zip_read = NULL;
837 + us.encrypted = 0;
839 - s=(unz_s*)ALLOC(sizeof(unz_s));
840 - *s=us;
841 - unzGoToFirstFile((unzFile)s);
842 - return (unzFile)s;
844 + s=(unz_s*)ALLOC(sizeof(unz_s));
845 + *s=us;
846 + unzGoToFirstFile((unzFile)s);
847 + return (unzFile)s;
851 +extern unzFile ZEXPORT unzOpen (path)
852 + const char *path;
854 + return unzOpen2(path, NULL);
858 Close a ZipFile opened with unzipOpen.
859 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
860 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
861 return UNZ_OK if there is no problem. */
862 extern int ZEXPORT unzClose (file)
863 - unzFile file;
864 + unzFile file;
866 - unz_s* s;
867 - if (file==NULL)
868 - return UNZ_PARAMERROR;
869 - s=(unz_s*)file;
870 + unz_s* s;
871 + if (file==NULL)
872 + return UNZ_PARAMERROR;
873 + s=(unz_s*)file;
875 if (s->pfile_in_zip_read!=NULL)
876 unzCloseCurrentFile(file);
878 - fclose(s->file);
879 - TRYFREE(s);
880 - return UNZ_OK;
881 + ZCLOSE(s->z_filefunc, s->filestream);
882 + TRYFREE(s);
883 + return UNZ_OK;
887 @@ -460,15 +530,15 @@
888 No preparation of the structure is needed
889 return UNZ_OK if there is no problem. */
890 extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)
891 - unzFile file;
892 - unz_global_info *pglobal_info;
893 + unzFile file;
894 + unz_global_info *pglobal_info;
896 - unz_s* s;
897 - if (file==NULL)
898 - return UNZ_PARAMERROR;
899 - s=(unz_s*)file;
900 - *pglobal_info=s->gi;
901 - return UNZ_OK;
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;
911 @@ -495,14 +565,14 @@
913 local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
914 unz_file_info *pfile_info,
915 - unz_file_info_internal
916 + unz_file_info_internal
917 *pfile_info_internal,
918 char *szFileName,
919 - uLong fileNameBufferSize,
920 + uLong fileNameBufferSize,
921 void *extraField,
922 - uLong extraFieldBufferSize,
923 + uLong extraFieldBufferSize,
924 char *szComment,
925 - uLong commentBufferSize));
926 + uLong commentBufferSize));
928 local int unzlocal_GetCurrentFileInfoInternal (file,
929 pfile_info,
930 @@ -510,156 +580,158 @@
931 szFileName, fileNameBufferSize,
932 extraField, extraFieldBufferSize,
933 szComment, commentBufferSize)
934 - unzFile file;
935 - unz_file_info *pfile_info;
936 - unz_file_info_internal *pfile_info_internal;
937 - char *szFileName;
938 - uLong fileNameBufferSize;
939 - void *extraField;
940 - uLong extraFieldBufferSize;
941 - char *szComment;
942 - uLong commentBufferSize;
944 - unz_s* s;
945 - unz_file_info file_info;
946 - unz_file_info_internal file_info_internal;
947 - int err=UNZ_OK;
948 - uLong uMagic;
949 - long lSeek=0;
951 - if (file==NULL)
952 - return UNZ_PARAMERROR;
953 - s=(unz_s*)file;
954 - if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0)
955 - err=UNZ_ERRNO;
958 - /* we check the magic */
959 - if (err==UNZ_OK)
960 - if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
961 - err=UNZ_ERRNO;
962 - else if (uMagic!=0x02014b50)
963 - err=UNZ_BADZIPFILE;
965 - if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK)
966 - err=UNZ_ERRNO;
968 - if (unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK)
969 - err=UNZ_ERRNO;
970 + unzFile file;
971 + unz_file_info *pfile_info;
972 + unz_file_info_internal *pfile_info_internal;
973 + char *szFileName;
974 + uLong fileNameBufferSize;
975 + void *extraField;
976 + uLong extraFieldBufferSize;
977 + char *szComment;
978 + uLong commentBufferSize;
980 + unz_s* s;
981 + unz_file_info file_info;
982 + unz_file_info_internal file_info_internal;
983 + int err=UNZ_OK;
984 + uLong uMagic;
985 + long lSeek=0;
987 + if (file==NULL)
988 + return UNZ_PARAMERROR;
989 + s=(unz_s*)file;
990 + if (ZSEEK(s->z_filefunc, s->filestream,
991 + s->pos_in_central_dir+s->byte_before_the_zipfile,
992 + ZLIB_FILEFUNC_SEEK_SET)!=0)
993 + err=UNZ_ERRNO;
996 + /* we check the magic */
997 + if (err==UNZ_OK)
998 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
999 + err=UNZ_ERRNO;
1000 + else if (uMagic!=0x02014b50)
1001 + err=UNZ_BADZIPFILE;
1003 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
1004 + err=UNZ_ERRNO;
1006 - if (unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK)
1007 - err=UNZ_ERRNO;
1008 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
1009 + err=UNZ_ERRNO;
1011 - if (unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK)
1012 - err=UNZ_ERRNO;
1013 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
1014 + err=UNZ_ERRNO;
1016 - if (unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK)
1017 - err=UNZ_ERRNO;
1018 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
1019 + err=UNZ_ERRNO;
1021 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
1022 + err=UNZ_ERRNO;
1024 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
1026 - if (unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK)
1027 - err=UNZ_ERRNO;
1028 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
1029 + err=UNZ_ERRNO;
1031 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
1032 + err=UNZ_ERRNO;
1034 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
1035 + err=UNZ_ERRNO;
1037 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
1038 + err=UNZ_ERRNO;
1040 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
1041 + err=UNZ_ERRNO;
1043 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
1044 + err=UNZ_ERRNO;
1046 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
1047 + err=UNZ_ERRNO;
1049 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
1050 + err=UNZ_ERRNO;
1052 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
1053 + err=UNZ_ERRNO;
1055 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
1056 + err=UNZ_ERRNO;
1058 + lSeek+=file_info.size_filename;
1059 + if ((err==UNZ_OK) && (szFileName!=NULL))
1061 + uLong uSizeRead ;
1062 + if (file_info.size_filename<fileNameBufferSize)
1064 + *(szFileName+file_info.size_filename)='\0';
1065 + uSizeRead = file_info.size_filename;
1067 + else
1068 + uSizeRead = fileNameBufferSize;
1070 + if ((file_info.size_filename>0) && (fileNameBufferSize>0))
1071 + if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
1072 + err=UNZ_ERRNO;
1073 + lSeek -= uSizeRead;
1077 + if ((err==UNZ_OK) && (extraField!=NULL))
1079 + uLong uSizeRead ;
1080 + if (file_info.size_file_extra<extraFieldBufferSize)
1081 + uSizeRead = file_info.size_file_extra;
1082 + else
1083 + uSizeRead = extraFieldBufferSize;
1085 + if (lSeek!=0)
1086 + if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1087 + lSeek=0;
1088 + else
1089 + err=UNZ_ERRNO;
1090 + if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
1091 + if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
1092 + err=UNZ_ERRNO;
1093 + lSeek += file_info.size_file_extra - uSizeRead;
1095 + else
1096 + lSeek+=file_info.size_file_extra;
1098 - if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK)
1099 - err=UNZ_ERRNO;
1101 - if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK)
1102 - err=UNZ_ERRNO;
1103 + if ((err==UNZ_OK) && (szComment!=NULL))
1105 + uLong uSizeRead ;
1106 + if (file_info.size_file_comment<commentBufferSize)
1108 + *(szComment+file_info.size_file_comment)='\0';
1109 + uSizeRead = file_info.size_file_comment;
1111 + else
1112 + uSizeRead = commentBufferSize;
1114 - if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK)
1115 - err=UNZ_ERRNO;
1117 - if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK)
1118 - err=UNZ_ERRNO;
1120 - if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK)
1121 - err=UNZ_ERRNO;
1123 - if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK)
1124 - err=UNZ_ERRNO;
1126 - if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK)
1127 - err=UNZ_ERRNO;
1129 - if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK)
1130 - err=UNZ_ERRNO;
1132 - if (unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK)
1133 - err=UNZ_ERRNO;
1135 - lSeek+=file_info.size_filename;
1136 - if ((err==UNZ_OK) && (szFileName!=NULL))
1138 - uLong uSizeRead ;
1139 - if (file_info.size_filename<fileNameBufferSize)
1141 - *(szFileName+file_info.size_filename)='\0';
1142 - uSizeRead = file_info.size_filename;
1144 - else
1145 - uSizeRead = fileNameBufferSize;
1147 - if ((file_info.size_filename>0) && (fileNameBufferSize>0))
1148 - if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1)
1149 - err=UNZ_ERRNO;
1150 - lSeek -= uSizeRead;
1154 - if ((err==UNZ_OK) && (extraField!=NULL))
1156 - uLong uSizeRead ;
1157 - if (file_info.size_file_extra<extraFieldBufferSize)
1158 - uSizeRead = file_info.size_file_extra;
1159 - else
1160 - uSizeRead = extraFieldBufferSize;
1162 - if (lSeek!=0)
1163 - if (fseek(s->file,lSeek,SEEK_CUR)==0)
1164 - lSeek=0;
1165 - else
1166 - err=UNZ_ERRNO;
1167 - if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
1168 - if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1)
1169 - err=UNZ_ERRNO;
1170 - lSeek += file_info.size_file_extra - uSizeRead;
1172 - else
1173 - lSeek+=file_info.size_file_extra;
1176 - if ((err==UNZ_OK) && (szComment!=NULL))
1178 - uLong uSizeRead ;
1179 - if (file_info.size_file_comment<commentBufferSize)
1181 - *(szComment+file_info.size_file_comment)='\0';
1182 - uSizeRead = file_info.size_file_comment;
1184 - else
1185 - uSizeRead = commentBufferSize;
1187 - if (lSeek!=0)
1188 - if (fseek(s->file,lSeek,SEEK_CUR)==0)
1189 - lSeek=0;
1190 - else
1191 - err=UNZ_ERRNO;
1192 - if ((file_info.size_file_comment>0) && (commentBufferSize>0))
1193 - if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1)
1194 - err=UNZ_ERRNO;
1195 - lSeek+=file_info.size_file_comment - uSizeRead;
1197 - else
1198 - lSeek+=file_info.size_file_comment;
1199 + if (lSeek!=0)
1200 + if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1201 + lSeek=0;
1202 + else
1203 + err=UNZ_ERRNO;
1204 + if ((file_info.size_file_comment>0) && (commentBufferSize>0))
1205 + if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
1206 + err=UNZ_ERRNO;
1207 + lSeek+=file_info.size_file_comment - uSizeRead;
1209 + else
1210 + lSeek+=file_info.size_file_comment;
1212 - if ((err==UNZ_OK) && (pfile_info!=NULL))
1213 - *pfile_info=file_info;
1214 + if ((err==UNZ_OK) && (pfile_info!=NULL))
1215 + *pfile_info=file_info;
1217 - if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
1218 - *pfile_info_internal=file_info_internal;
1219 + if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
1220 + *pfile_info_internal=file_info_internal;
1222 - return err;
1223 + return err;
1227 @@ -670,23 +742,23 @@
1228 return UNZ_OK if there is no problem.
1230 extern int ZEXPORT unzGetCurrentFileInfo (file,
1231 - pfile_info,
1232 - szFileName, fileNameBufferSize,
1233 - extraField, extraFieldBufferSize,
1234 - szComment, commentBufferSize)
1235 - unzFile file;
1236 - unz_file_info *pfile_info;
1237 - char *szFileName;
1238 - uLong fileNameBufferSize;
1239 - void *extraField;
1240 - uLong extraFieldBufferSize;
1241 - char *szComment;
1242 - uLong commentBufferSize;
1244 - return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
1245 - szFileName,fileNameBufferSize,
1246 - extraField,extraFieldBufferSize,
1247 - szComment,commentBufferSize);
1248 + pfile_info,
1249 + szFileName, fileNameBufferSize,
1250 + extraField, extraFieldBufferSize,
1251 + szComment, commentBufferSize)
1252 + unzFile file;
1253 + unz_file_info *pfile_info;
1254 + char *szFileName;
1255 + uLong fileNameBufferSize;
1256 + void *extraField;
1257 + uLong extraFieldBufferSize;
1258 + char *szComment;
1259 + uLong commentBufferSize;
1261 + return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
1262 + szFileName,fileNameBufferSize,
1263 + extraField,extraFieldBufferSize,
1264 + szComment,commentBufferSize);
1268 @@ -694,50 +766,50 @@
1269 return UNZ_OK if there is no problem
1271 extern int ZEXPORT unzGoToFirstFile (file)
1272 - unzFile file;
1273 + unzFile file;
1275 - int err=UNZ_OK;
1276 - unz_s* s;
1277 - if (file==NULL)
1278 - return UNZ_PARAMERROR;
1279 - s=(unz_s*)file;
1280 - s->pos_in_central_dir=s->offset_central_dir;
1281 - s->num_file=0;
1282 - err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1283 - &s->cur_file_info_internal,
1284 - NULL,0,NULL,0,NULL,0);
1285 - s->current_file_ok = (err == UNZ_OK);
1286 - return err;
1287 + int err=UNZ_OK;
1288 + unz_s* s;
1289 + if (file==NULL)
1290 + return UNZ_PARAMERROR;
1291 + s=(unz_s*)file;
1292 + s->pos_in_central_dir=s->offset_central_dir;
1293 + s->num_file=0;
1294 + err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1295 + &s->cur_file_info_internal,
1296 + NULL,0,NULL,0,NULL,0);
1297 + s->current_file_ok = (err == UNZ_OK);
1298 + return err;
1303 Set the current file of the zipfile to the next file.
1304 return UNZ_OK if there is no problem
1305 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
1307 extern int ZEXPORT unzGoToNextFile (file)
1308 - unzFile file;
1309 + unzFile file;
1311 - unz_s* s;
1312 - int err;
1313 + unz_s* s;
1314 + int err;
1316 - if (file==NULL)
1317 - return UNZ_PARAMERROR;
1318 - s=(unz_s*)file;
1319 - if (!s->current_file_ok)
1320 - return UNZ_END_OF_LIST_OF_FILE;
1321 - if (s->num_file+1==s->gi.number_entry)
1322 - return UNZ_END_OF_LIST_OF_FILE;
1324 - s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
1325 - s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
1326 - s->num_file++;
1327 - err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1328 - &s->cur_file_info_internal,
1329 - NULL,0,NULL,0,NULL,0);
1330 - s->current_file_ok = (err == UNZ_OK);
1331 - return err;
1332 + if (file==NULL)
1333 + return UNZ_PARAMERROR;
1334 + s=(unz_s*)file;
1335 + if (!s->current_file_ok)
1336 + return UNZ_END_OF_LIST_OF_FILE;
1337 + if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
1338 + if (s->num_file+1==s->gi.number_entry)
1339 + return UNZ_END_OF_LIST_OF_FILE;
1341 + s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
1342 + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
1343 + s->num_file++;
1344 + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1345 + &s->cur_file_info_internal,
1346 + NULL,0,NULL,0,NULL,0);
1347 + s->current_file_ok = (err == UNZ_OK);
1348 + return err;
1352 @@ -750,50 +822,130 @@
1353 UNZ_END_OF_LIST_OF_FILE if the file is not found
1355 extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
1356 - unzFile file;
1357 - const char *szFileName;
1358 - int iCaseSensitivity;
1359 + unzFile file;
1360 + const char *szFileName;
1361 + int iCaseSensitivity;
1363 - unz_s* s;
1364 - int err;
1365 + unz_s* s;
1366 + int err;
1369 - uLong num_fileSaved;
1370 - uLong pos_in_central_dirSaved;
1371 + /* We remember the 'current' position in the file so that we can jump
1372 + * back there if we fail.
1373 + */
1374 + unz_file_info cur_file_infoSaved;
1375 + unz_file_info_internal cur_file_info_internalSaved;
1376 + uLong num_fileSaved;
1377 + uLong pos_in_central_dirSaved;
1380 - if (file==NULL)
1381 - return UNZ_PARAMERROR;
1382 + if (file==NULL)
1383 + return UNZ_PARAMERROR;
1385 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
1386 return UNZ_PARAMERROR;
1388 - s=(unz_s*)file;
1389 - if (!s->current_file_ok)
1390 - return UNZ_END_OF_LIST_OF_FILE;
1392 - num_fileSaved = s->num_file;
1393 - pos_in_central_dirSaved = s->pos_in_central_dir;
1395 - err = unzGoToFirstFile(file);
1397 - while (err == UNZ_OK)
1399 - char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
1400 - unzGetCurrentFileInfo(file,NULL,
1401 - szCurrentFileName,sizeof(szCurrentFileName)-1,
1402 - NULL,0,NULL,0);
1403 - if (unzStringFileNameCompare(szCurrentFileName,
1404 - szFileName,iCaseSensitivity)==0)
1405 - return UNZ_OK;
1406 - err = unzGoToNextFile(file);
1409 - s->num_file = num_fileSaved ;
1410 - s->pos_in_central_dir = pos_in_central_dirSaved ;
1411 - return err;
1412 + s=(unz_s*)file;
1413 + if (!s->current_file_ok)
1414 + return UNZ_END_OF_LIST_OF_FILE;
1416 + /* Save the current state */
1417 + num_fileSaved = s->num_file;
1418 + pos_in_central_dirSaved = s->pos_in_central_dir;
1419 + cur_file_infoSaved = s->cur_file_info;
1420 + cur_file_info_internalSaved = s->cur_file_info_internal;
1422 + err = unzGoToFirstFile(file);
1424 + while (err == UNZ_OK)
1426 + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
1427 + err = unzGetCurrentFileInfo(file,NULL,
1428 + szCurrentFileName,sizeof(szCurrentFileName)-1,
1429 + NULL,0,NULL,0);
1430 + if (err == UNZ_OK)
1432 + if (unzStringFileNameCompare(szCurrentFileName,
1433 + szFileName,iCaseSensitivity)==0)
1434 + return UNZ_OK;
1435 + err = unzGoToNextFile(file);
1439 + /* We failed, so restore the state of the 'current file' to where we
1440 + * were.
1441 + */
1442 + s->num_file = num_fileSaved ;
1443 + s->pos_in_central_dir = pos_in_central_dirSaved ;
1444 + s->cur_file_info = cur_file_infoSaved;
1445 + s->cur_file_info_internal = cur_file_info_internalSaved;
1446 + return err;
1451 +///////////////////////////////////////////
1452 +// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
1453 +// I need random access
1455 +// Further optimization could be realized by adding an ability
1456 +// to cache the directory in memory. The goal being a single
1457 +// comprehensive file read to put the file I need in a memory.
1461 +typedef struct unz_file_pos_s
1463 + uLong pos_in_zip_directory; // offset in file
1464 + uLong num_of_file; // # of file
1465 +} unz_file_pos;
1468 +extern int ZEXPORT unzGetFilePos(file, file_pos)
1469 + unzFile file;
1470 + unz_file_pos* file_pos;
1472 + unz_s* s;
1474 + if (file==NULL || file_pos==NULL)
1475 + return UNZ_PARAMERROR;
1476 + s=(unz_s*)file;
1477 + if (!s->current_file_ok)
1478 + return UNZ_END_OF_LIST_OF_FILE;
1480 + file_pos->pos_in_zip_directory = s->pos_in_central_dir;
1481 + file_pos->num_of_file = s->num_file;
1483 + return UNZ_OK;
1486 +extern int ZEXPORT unzGoToFilePos(file, file_pos)
1487 + unzFile file;
1488 + unz_file_pos* file_pos;
1490 + unz_s* s;
1491 + int err;
1493 + if (file==NULL || file_pos==NULL)
1494 + return UNZ_PARAMERROR;
1495 + s=(unz_s*)file;
1497 + /* jump to the right spot */
1498 + s->pos_in_central_dir = file_pos->pos_in_zip_directory;
1499 + s->num_file = file_pos->num_of_file;
1501 + /* set the current file */
1502 + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1503 + &s->cur_file_info_internal,
1504 + NULL,0,NULL,0,NULL,0);
1505 + /* return results */
1506 + s->current_file_ok = (err == UNZ_OK);
1507 + return err;
1511 +// Unzip Helper Functions - should be here?
1512 +///////////////////////////////////////////
1516 Read the local header of the current zipfile
1517 @@ -803,185 +955,261 @@
1518 (filename and size of extra field data)
1520 local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
1521 - poffset_local_extrafield,
1522 - psize_local_extrafield)
1523 - unz_s* s;
1524 - uInt* piSizeVar;
1525 - uLong *poffset_local_extrafield;
1526 - uInt *psize_local_extrafield;
1528 - uLong uMagic,uData,uFlags;
1529 - uLong size_filename;
1530 - uLong size_extra_field;
1531 - int err=UNZ_OK;
1533 - *piSizeVar = 0;
1534 - *poffset_local_extrafield = 0;
1535 - *psize_local_extrafield = 0;
1537 - if (fseek(s->file,s->cur_file_info_internal.offset_curfile +
1538 - s->byte_before_the_zipfile,SEEK_SET)!=0)
1539 - return UNZ_ERRNO;
1542 - if (err==UNZ_OK)
1543 - if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
1544 - err=UNZ_ERRNO;
1545 - else if (uMagic!=0x04034b50)
1546 - err=UNZ_BADZIPFILE;
1548 - if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
1549 - err=UNZ_ERRNO;
1551 - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
1552 - err=UNZ_BADZIPFILE;
1554 - if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK)
1555 - err=UNZ_ERRNO;
1557 - if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
1558 - err=UNZ_ERRNO;
1559 - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
1560 - err=UNZ_BADZIPFILE;
1561 + poffset_local_extrafield,
1562 + psize_local_extrafield)
1563 + unz_s* s;
1564 + uInt* piSizeVar;
1565 + uLong *poffset_local_extrafield;
1566 + uInt *psize_local_extrafield;
1568 + uLong uMagic,uData,uFlags;
1569 + uLong size_filename;
1570 + uLong size_extra_field;
1571 + int err=UNZ_OK;
1573 + *piSizeVar = 0;
1574 + *poffset_local_extrafield = 0;
1575 + *psize_local_extrafield = 0;
1577 + if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
1578 + s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
1579 + return UNZ_ERRNO;
1582 + if (err==UNZ_OK)
1583 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
1584 + err=UNZ_ERRNO;
1585 + else if (uMagic!=0x04034b50)
1586 + err=UNZ_BADZIPFILE;
1588 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1589 + err=UNZ_ERRNO;
1591 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
1592 + err=UNZ_BADZIPFILE;
1594 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
1595 + err=UNZ_ERRNO;
1597 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1598 + err=UNZ_ERRNO;
1599 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
1600 + err=UNZ_BADZIPFILE;
1602 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
1603 (s->cur_file_info.compression_method!=Z_DEFLATED))
1604 err=UNZ_BADZIPFILE;
1606 - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */
1607 - err=UNZ_ERRNO;
1608 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
1609 + err=UNZ_ERRNO;
1611 - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */
1612 - err=UNZ_ERRNO;
1613 - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
1614 - ((uFlags & 8)==0))
1615 - err=UNZ_BADZIPFILE;
1617 - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */
1618 - err=UNZ_ERRNO;
1619 - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
1620 - ((uFlags & 8)==0))
1621 - err=UNZ_BADZIPFILE;
1623 - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */
1624 - err=UNZ_ERRNO;
1625 - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
1626 - ((uFlags & 8)==0))
1627 - err=UNZ_BADZIPFILE;
1630 - if (unzlocal_getShort(s->file,&size_filename) != UNZ_OK)
1631 - err=UNZ_ERRNO;
1632 - else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1633 - err=UNZ_BADZIPFILE;
1635 - *piSizeVar += (uInt)size_filename;
1637 - if (unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK)
1638 - err=UNZ_ERRNO;
1639 - *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1640 - SIZEZIPLOCALHEADER + size_filename;
1641 - *psize_local_extrafield = (uInt)size_extra_field;
1642 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
1643 + err=UNZ_ERRNO;
1644 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
1645 + ((uFlags & 8)==0))
1646 + err=UNZ_BADZIPFILE;
1648 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
1649 + err=UNZ_ERRNO;
1650 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
1651 + ((uFlags & 8)==0))
1652 + err=UNZ_BADZIPFILE;
1654 - *piSizeVar += (uInt)size_extra_field;
1655 + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
1656 + err=UNZ_ERRNO;
1657 + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
1658 + ((uFlags & 8)==0))
1659 + err=UNZ_BADZIPFILE;
1662 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1663 + err=UNZ_ERRNO;
1664 + else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1665 + err=UNZ_BADZIPFILE;
1667 - return err;
1668 + *piSizeVar += (uInt)size_filename;
1670 + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
1671 + err=UNZ_ERRNO;
1672 + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1673 + SIZEZIPLOCALHEADER + size_filename;
1674 + *psize_local_extrafield = (uInt)size_extra_field;
1676 + *piSizeVar += (uInt)size_extra_field;
1678 + return err;
1683 Open for reading data the current file in the zipfile.
1684 If there is no error and the file is opened, the return value is UNZ_OK.
1686 -extern int ZEXPORT unzOpenCurrentFile (file)
1687 - unzFile file;
1689 - int err=UNZ_OK;
1690 - int Store;
1691 - uInt iSizeVar;
1692 - unz_s* s;
1693 - file_in_zip_read_info_s* pfile_in_zip_read_info;
1694 - uLong offset_local_extrafield; /* offset of the local extra field */
1695 - uInt size_local_extrafield; /* size of the local extra field */
1697 - if (file==NULL)
1698 - return UNZ_PARAMERROR;
1699 - s=(unz_s*)file;
1700 - if (!s->current_file_ok)
1701 - return UNZ_PARAMERROR;
1702 +extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1703 + unzFile file;
1704 + int* method;
1705 + int* level;
1706 + int raw;
1707 + const char* password;
1709 + int err=UNZ_OK;
1710 + uInt iSizeVar;
1711 + unz_s* s;
1712 + file_in_zip_read_info_s* pfile_in_zip_read_info;
1713 + uLong offset_local_extrafield; /* offset of the local extra field */
1714 + uInt size_local_extrafield; /* size of the local extra field */
1715 +# ifndef NOUNCRYPT
1716 + char source[12];
1717 +# else
1718 + if (password != NULL)
1719 + return UNZ_PARAMERROR;
1720 +# endif
1722 + if (file==NULL)
1723 + return UNZ_PARAMERROR;
1724 + s=(unz_s*)file;
1725 + if (!s->current_file_ok)
1726 + return UNZ_PARAMERROR;
1728 if (s->pfile_in_zip_read != NULL)
1729 unzCloseCurrentFile(file);
1731 - if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
1732 - &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1733 - return UNZ_BADZIPFILE;
1735 - pfile_in_zip_read_info = (file_in_zip_read_info_s*)
1736 - ALLOC(sizeof(file_in_zip_read_info_s));
1737 - if (pfile_in_zip_read_info==NULL)
1738 - return UNZ_INTERNALERROR;
1740 - pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
1741 - pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1742 - pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1743 - pfile_in_zip_read_info->pos_local_extrafield=0;
1745 - if (pfile_in_zip_read_info->read_buffer==NULL)
1747 - TRYFREE(pfile_in_zip_read_info);
1748 - return UNZ_INTERNALERROR;
1751 - pfile_in_zip_read_info->stream_initialised=0;
1753 - if ((s->cur_file_info.compression_method!=0) &&
1754 + if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
1755 + &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1756 + return UNZ_BADZIPFILE;
1758 + pfile_in_zip_read_info = (file_in_zip_read_info_s*)
1759 + ALLOC(sizeof(file_in_zip_read_info_s));
1760 + if (pfile_in_zip_read_info==NULL)
1761 + return UNZ_INTERNALERROR;
1763 + pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
1764 + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1765 + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1766 + pfile_in_zip_read_info->pos_local_extrafield=0;
1767 + pfile_in_zip_read_info->raw=raw;
1769 + if (pfile_in_zip_read_info->read_buffer==NULL)
1771 + TRYFREE(pfile_in_zip_read_info);
1772 + return UNZ_INTERNALERROR;
1775 + pfile_in_zip_read_info->stream_initialised=0;
1777 + if (method!=NULL)
1778 + *method = (int)s->cur_file_info.compression_method;
1780 + if (level!=NULL)
1782 + *level = 6;
1783 + switch (s->cur_file_info.flag & 0x06)
1785 + case 6 : *level = 1; break;
1786 + case 4 : *level = 2; break;
1787 + case 2 : *level = 9; break;
1791 + if ((s->cur_file_info.compression_method!=0) &&
1792 (s->cur_file_info.compression_method!=Z_DEFLATED))
1793 - err=UNZ_BADZIPFILE;
1794 - Store = s->cur_file_info.compression_method==0;
1795 + err=UNZ_BADZIPFILE;
1797 - pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1798 - pfile_in_zip_read_info->crc32=0;
1799 - pfile_in_zip_read_info->compression_method =
1800 + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1801 + pfile_in_zip_read_info->crc32=0;
1802 + pfile_in_zip_read_info->compression_method =
1803 s->cur_file_info.compression_method;
1804 - pfile_in_zip_read_info->file=s->file;
1805 - pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1806 + pfile_in_zip_read_info->filestream=s->filestream;
1807 + pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
1808 + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1810 pfile_in_zip_read_info->stream.total_out = 0;
1812 - if (!Store)
1814 - pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1815 - pfile_in_zip_read_info->stream.zfree = (free_func)0;
1816 - pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1818 - err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1819 - if (err == Z_OK)
1820 - pfile_in_zip_read_info->stream_initialised=1;
1821 + if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
1822 + (!raw))
1824 + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1825 + pfile_in_zip_read_info->stream.zfree = (free_func)0;
1826 + pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1827 + pfile_in_zip_read_info->stream.next_in = (voidpf)0;
1828 + pfile_in_zip_read_info->stream.avail_in = 0;
1830 + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1831 + if (err == Z_OK)
1832 + pfile_in_zip_read_info->stream_initialised=1;
1833 + else
1835 + TRYFREE(pfile_in_zip_read_info);
1836 + return err;
1838 /* windowBits is passed < 0 to tell that there is no zlib header.
1839 * Note that in this case inflate *requires* an extra "dummy" byte
1840 * after the compressed stream in order to complete decompression and
1841 - * return Z_STREAM_END.
1842 - * In unzip, i don't wait absolutely Z_STREAM_END because I known the
1843 + * return Z_STREAM_END.
1844 + * In unzip, i don't wait absolutely Z_STREAM_END because I known the
1845 * size of both compressed and uncompressed data
1848 - pfile_in_zip_read_info->rest_read_compressed =
1850 + pfile_in_zip_read_info->rest_read_compressed =
1851 s->cur_file_info.compressed_size ;
1852 - pfile_in_zip_read_info->rest_read_uncompressed =
1853 + pfile_in_zip_read_info->rest_read_uncompressed =
1854 s->cur_file_info.uncompressed_size ;
1857 - pfile_in_zip_read_info->pos_in_zipfile =
1858 - s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
1859 - iSizeVar;
1861 - pfile_in_zip_read_info->stream.avail_in = (uInt)0;
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 + s->pfile_in_zip_read = pfile_in_zip_read_info;
1871 +# ifndef NOUNCRYPT
1872 + if (password != NULL)
1874 + int i;
1875 + s->pcrc_32_tab = get_crc_table();
1876 + init_keys(password,s->keys,s->pcrc_32_tab);
1877 + if (ZSEEK(s->z_filefunc, s->filestream,
1878 + s->pfile_in_zip_read->pos_in_zipfile +
1879 + s->pfile_in_zip_read->byte_before_the_zipfile,
1880 + SEEK_SET)!=0)
1881 + return UNZ_INTERNALERROR;
1882 + if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)
1883 + return UNZ_INTERNALERROR;
1885 + for (i = 0; i<12; i++)
1886 + zdecode(s->keys,s->pcrc_32_tab,source[i]);
1888 + s->pfile_in_zip_read->pos_in_zipfile+=12;
1889 + s->encrypted=1;
1891 +# endif
1894 - s->pfile_in_zip_read = pfile_in_zip_read_info;
1895 return UNZ_OK;
1898 +extern int ZEXPORT unzOpenCurrentFile (file)
1899 + unzFile file;
1901 + return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1904 +extern int ZEXPORT unzOpenCurrentFilePassword (file, password)
1905 + unzFile file;
1906 + const char* password;
1908 + return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1911 +extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
1912 + unzFile file;
1913 + int* method;
1914 + int* level;
1915 + int raw;
1917 + return unzOpenCurrentFile3(file, method, level, raw, NULL);
1921 Read bytes from the current file.
1922 @@ -994,126 +1222,160 @@
1923 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
1925 extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1926 - unzFile file;
1927 - voidp buf;
1928 - unsigned len;
1930 - int err=UNZ_OK;
1931 - uInt iRead = 0;
1932 - unz_s* s;
1933 - file_in_zip_read_info_s* pfile_in_zip_read_info;
1934 - if (file==NULL)
1935 - return UNZ_PARAMERROR;
1936 - s=(unz_s*)file;
1937 + unzFile file;
1938 + voidp buf;
1939 + unsigned len;
1941 + int err=UNZ_OK;
1942 + uInt iRead = 0;
1943 + unz_s* s;
1944 + file_in_zip_read_info_s* pfile_in_zip_read_info;
1945 + if (file==NULL)
1946 + return UNZ_PARAMERROR;
1947 + s=(unz_s*)file;
1948 pfile_in_zip_read_info=s->pfile_in_zip_read;
1950 - if (pfile_in_zip_read_info==NULL)
1951 - return UNZ_PARAMERROR;
1952 + if (pfile_in_zip_read_info==NULL)
1953 + return UNZ_PARAMERROR;
1956 - if ((pfile_in_zip_read_info->read_buffer == NULL))
1957 - return UNZ_END_OF_LIST_OF_FILE;
1958 - if (len==0)
1959 - return 0;
1961 - pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
1963 - pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1965 - if (len>pfile_in_zip_read_info->rest_read_uncompressed)
1966 - pfile_in_zip_read_info->stream.avail_out =
1967 - (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1969 - while (pfile_in_zip_read_info->stream.avail_out>0)
1971 - if ((pfile_in_zip_read_info->stream.avail_in==0) &&
1972 + if ((pfile_in_zip_read_info->read_buffer == NULL))
1973 + return UNZ_END_OF_LIST_OF_FILE;
1974 + if (len==0)
1975 + return 0;
1977 + pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
1979 + pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1981 + if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
1982 + (!(pfile_in_zip_read_info->raw)))
1983 + pfile_in_zip_read_info->stream.avail_out =
1984 + (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1986 + if ((len>pfile_in_zip_read_info->rest_read_compressed+
1987 + pfile_in_zip_read_info->stream.avail_in) &&
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_compressed+
1991 + pfile_in_zip_read_info->stream.avail_in;
1993 + while (pfile_in_zip_read_info->stream.avail_out>0)
1995 + if ((pfile_in_zip_read_info->stream.avail_in==0) &&
1996 (pfile_in_zip_read_info->rest_read_compressed>0))
1998 - uInt uReadThis = UNZ_BUFSIZE;
1999 - if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
2000 - uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
2001 - if (uReadThis == 0)
2002 - return UNZ_EOF;
2003 - if (fseek(pfile_in_zip_read_info->file,
2004 - pfile_in_zip_read_info->pos_in_zipfile +
2005 - pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0)
2006 - return UNZ_ERRNO;
2007 - if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1,
2008 - pfile_in_zip_read_info->file)!=1)
2009 - return UNZ_ERRNO;
2010 - pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
2012 - pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
2014 - pfile_in_zip_read_info->stream.next_in =
2016 + uInt uReadThis = UNZ_BUFSIZE;
2017 + if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
2018 + uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
2019 + if (uReadThis == 0)
2020 + return UNZ_EOF;
2021 + if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
2022 + pfile_in_zip_read_info->filestream,
2023 + pfile_in_zip_read_info->pos_in_zipfile +
2024 + pfile_in_zip_read_info->byte_before_the_zipfile,
2025 + ZLIB_FILEFUNC_SEEK_SET)!=0)
2026 + return UNZ_ERRNO;
2027 + if (ZREAD(pfile_in_zip_read_info->z_filefunc,
2028 + pfile_in_zip_read_info->filestream,
2029 + pfile_in_zip_read_info->read_buffer,
2030 + uReadThis)!=uReadThis)
2031 + return UNZ_ERRNO;
2034 +# ifndef NOUNCRYPT
2035 + if(s->encrypted)
2037 + uInt i;
2038 + for(i=0;i<uReadThis;i++)
2039 + pfile_in_zip_read_info->read_buffer[i] =
2040 + zdecode(s->keys,s->pcrc_32_tab,
2041 + pfile_in_zip_read_info->read_buffer[i]);
2043 +# endif
2046 + pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
2048 + pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
2050 + pfile_in_zip_read_info->stream.next_in =
2051 (Bytef*)pfile_in_zip_read_info->read_buffer;
2052 - pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
2054 + pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
2057 + if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
2059 + uInt uDoCopy,i ;
2061 + if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
2062 + (pfile_in_zip_read_info->rest_read_compressed == 0))
2063 + return (iRead==0) ? UNZ_EOF : iRead;
2065 - if (pfile_in_zip_read_info->compression_method==0)
2067 - uInt uDoCopy,i ;
2068 - if (pfile_in_zip_read_info->stream.avail_out <
2069 + if (pfile_in_zip_read_info->stream.avail_out <
2070 pfile_in_zip_read_info->stream.avail_in)
2071 - uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
2072 - else
2073 - uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
2075 - for (i=0;i<uDoCopy;i++)
2076 - *(pfile_in_zip_read_info->stream.next_out+i) =
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 *(pfile_in_zip_read_info->stream.next_in+i);
2085 - pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
2086 - pfile_in_zip_read_info->stream.next_out,
2087 - uDoCopy);
2088 - pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
2089 - pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
2090 - pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
2091 - pfile_in_zip_read_info->stream.next_out += uDoCopy;
2092 - pfile_in_zip_read_info->stream.next_in += uDoCopy;
2094 + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
2095 + pfile_in_zip_read_info->stream.next_out,
2096 + uDoCopy);
2097 + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
2098 + pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
2099 + pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
2100 + pfile_in_zip_read_info->stream.next_out += uDoCopy;
2101 + pfile_in_zip_read_info->stream.next_in += uDoCopy;
2102 pfile_in_zip_read_info->stream.total_out += uDoCopy;
2103 - iRead += uDoCopy;
2105 - else
2107 - uLong uTotalOutBefore,uTotalOutAfter;
2108 - const Bytef *bufBefore;
2109 - uLong uOutThis;
2110 - int flush=Z_SYNC_FLUSH;
2112 - uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
2113 - bufBefore = pfile_in_zip_read_info->stream.next_out;
2115 - /*
2116 - if ((pfile_in_zip_read_info->rest_read_uncompressed ==
2117 - pfile_in_zip_read_info->stream.avail_out) &&
2118 - (pfile_in_zip_read_info->rest_read_compressed == 0))
2119 - flush = Z_FINISH;
2120 - */
2121 - err=inflate(&pfile_in_zip_read_info->stream,flush);
2123 - uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
2124 - uOutThis = uTotalOutAfter-uTotalOutBefore;
2126 - pfile_in_zip_read_info->crc32 =
2127 + iRead += uDoCopy;
2129 + else
2131 + uLong uTotalOutBefore,uTotalOutAfter;
2132 + const Bytef *bufBefore;
2133 + uLong uOutThis;
2134 + int flush=Z_SYNC_FLUSH;
2136 + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
2137 + bufBefore = pfile_in_zip_read_info->stream.next_out;
2139 + /*
2140 + if ((pfile_in_zip_read_info->rest_read_uncompressed ==
2141 + pfile_in_zip_read_info->stream.avail_out) &&
2142 + (pfile_in_zip_read_info->rest_read_compressed == 0))
2143 + flush = Z_FINISH;
2144 + */
2145 + err=inflate(&pfile_in_zip_read_info->stream,flush);
2147 + if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
2148 + err = Z_DATA_ERROR;
2150 + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
2151 + uOutThis = uTotalOutAfter-uTotalOutBefore;
2153 + pfile_in_zip_read_info->crc32 =
2154 crc32(pfile_in_zip_read_info->crc32,bufBefore,
2155 (uInt)(uOutThis));
2157 - pfile_in_zip_read_info->rest_read_uncompressed -=
2158 + pfile_in_zip_read_info->rest_read_uncompressed -=
2159 uOutThis;
2161 - iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
2163 - if (err==Z_STREAM_END)
2164 - return (iRead==0) ? UNZ_EOF : iRead;
2165 - if (err!=Z_OK)
2166 - break;
2170 - if (err==Z_OK)
2171 - return iRead;
2172 - return err;
2173 + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
2175 + if (err==Z_STREAM_END)
2176 + return (iRead==0) ? UNZ_EOF : iRead;
2177 + if (err!=Z_OK)
2178 + break;
2182 + if (err==Z_OK)
2183 + return iRead;
2184 + return err;
2188 @@ -1121,42 +1383,42 @@
2189 Give the current position in uncompressed data
2191 extern z_off_t ZEXPORT unztell (file)
2192 - unzFile file;
2193 + unzFile file;
2195 - unz_s* s;
2196 - file_in_zip_read_info_s* pfile_in_zip_read_info;
2197 - if (file==NULL)
2198 - return UNZ_PARAMERROR;
2199 - s=(unz_s*)file;
2200 + unz_s* s;
2201 + file_in_zip_read_info_s* pfile_in_zip_read_info;
2202 + if (file==NULL)
2203 + return UNZ_PARAMERROR;
2204 + s=(unz_s*)file;
2205 pfile_in_zip_read_info=s->pfile_in_zip_read;
2207 - if (pfile_in_zip_read_info==NULL)
2208 - return UNZ_PARAMERROR;
2209 + if (pfile_in_zip_read_info==NULL)
2210 + return UNZ_PARAMERROR;
2212 - return (z_off_t)pfile_in_zip_read_info->stream.total_out;
2213 + return (z_off_t)pfile_in_zip_read_info->stream.total_out;
2218 - return 1 if the end of file was reached, 0 elsewhere
2219 + return 1 if the end of file was reached, 0 elsewhere
2221 extern int ZEXPORT unzeof (file)
2222 - unzFile file;
2223 + unzFile file;
2225 - unz_s* s;
2226 - file_in_zip_read_info_s* pfile_in_zip_read_info;
2227 - if (file==NULL)
2228 - return UNZ_PARAMERROR;
2229 - s=(unz_s*)file;
2230 + unz_s* s;
2231 + file_in_zip_read_info_s* pfile_in_zip_read_info;
2232 + if (file==NULL)
2233 + return UNZ_PARAMERROR;
2234 + s=(unz_s*)file;
2235 pfile_in_zip_read_info=s->pfile_in_zip_read;
2237 - if (pfile_in_zip_read_info==NULL)
2238 - return UNZ_PARAMERROR;
2240 - if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
2241 - return 1;
2242 - else
2243 - return 0;
2244 + if (pfile_in_zip_read_info==NULL)
2245 + return UNZ_PARAMERROR;
2247 + if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
2248 + return 1;
2249 + else
2250 + return 0;
2254 @@ -1169,51 +1431,55 @@
2255 if buf==NULL, it return the size of the local extra field that can be read
2257 if buf!=NULL, len is the size of the buffer, the extra header is copied in
2258 - buf.
2259 - the return value is the number of bytes copied in buf, or (if <0)
2260 - the error code
2261 + buf.
2262 + the return value is the number of bytes copied in buf, or (if <0)
2263 + the error code
2265 extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
2266 - unzFile file;
2267 - voidp buf;
2268 - unsigned len;
2270 - unz_s* s;
2271 - file_in_zip_read_info_s* pfile_in_zip_read_info;
2272 - uInt read_now;
2273 - uLong size_to_read;
2275 - if (file==NULL)
2276 - return UNZ_PARAMERROR;
2277 - s=(unz_s*)file;
2278 + unzFile file;
2279 + voidp buf;
2280 + unsigned len;
2282 + unz_s* s;
2283 + file_in_zip_read_info_s* pfile_in_zip_read_info;
2284 + uInt read_now;
2285 + uLong size_to_read;
2287 + if (file==NULL)
2288 + return UNZ_PARAMERROR;
2289 + s=(unz_s*)file;
2290 pfile_in_zip_read_info=s->pfile_in_zip_read;
2292 - if (pfile_in_zip_read_info==NULL)
2293 - return UNZ_PARAMERROR;
2294 + if (pfile_in_zip_read_info==NULL)
2295 + return UNZ_PARAMERROR;
2297 - size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
2298 - pfile_in_zip_read_info->pos_local_extrafield);
2299 + size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
2300 + pfile_in_zip_read_info->pos_local_extrafield);
2302 - if (buf==NULL)
2303 - return (int)size_to_read;
2305 - if (len>size_to_read)
2306 - read_now = (uInt)size_to_read;
2307 - else
2308 - read_now = (uInt)len ;
2310 - if (read_now==0)
2311 - return 0;
2313 - if (fseek(pfile_in_zip_read_info->file,
2314 - pfile_in_zip_read_info->offset_local_extrafield +
2315 - pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0)
2316 - return UNZ_ERRNO;
2317 + if (buf==NULL)
2318 + return (int)size_to_read;
2320 - if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1)
2321 - return UNZ_ERRNO;
2322 + if (len>size_to_read)
2323 + read_now = (uInt)size_to_read;
2324 + else
2325 + read_now = (uInt)len ;
2327 + if (read_now==0)
2328 + return 0;
2330 - return (int)read_now;
2331 + if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
2332 + pfile_in_zip_read_info->filestream,
2333 + pfile_in_zip_read_info->offset_local_extrafield +
2334 + pfile_in_zip_read_info->pos_local_extrafield,
2335 + ZLIB_FILEFUNC_SEEK_SET)!=0)
2336 + return UNZ_ERRNO;
2338 + if (ZREAD(pfile_in_zip_read_info->z_filefunc,
2339 + pfile_in_zip_read_info->filestream,
2340 + buf,read_now)!=read_now)
2341 + return UNZ_ERRNO;
2343 + return (int)read_now;
2347 @@ -1221,39 +1487,40 @@
2348 Return UNZ_CRCERROR if all the file was read but the CRC is not good
2350 extern int ZEXPORT unzCloseCurrentFile (file)
2351 - unzFile file;
2352 + unzFile file;
2354 - int err=UNZ_OK;
2355 + int err=UNZ_OK;
2357 - unz_s* s;
2358 - file_in_zip_read_info_s* pfile_in_zip_read_info;
2359 - if (file==NULL)
2360 - return UNZ_PARAMERROR;
2361 - s=(unz_s*)file;
2362 + unz_s* s;
2363 + file_in_zip_read_info_s* pfile_in_zip_read_info;
2364 + if (file==NULL)
2365 + return UNZ_PARAMERROR;
2366 + s=(unz_s*)file;
2367 pfile_in_zip_read_info=s->pfile_in_zip_read;
2369 - if (pfile_in_zip_read_info==NULL)
2370 - return UNZ_PARAMERROR;
2371 + if (pfile_in_zip_read_info==NULL)
2372 + return UNZ_PARAMERROR;
2375 - if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
2377 - if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
2378 - err=UNZ_CRCERROR;
2380 + if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
2381 + (!pfile_in_zip_read_info->raw))
2383 + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
2384 + err=UNZ_CRCERROR;
2388 - TRYFREE(pfile_in_zip_read_info->read_buffer);
2389 - pfile_in_zip_read_info->read_buffer = NULL;
2390 - if (pfile_in_zip_read_info->stream_initialised)
2391 - inflateEnd(&pfile_in_zip_read_info->stream);
2392 + TRYFREE(pfile_in_zip_read_info->read_buffer);
2393 + pfile_in_zip_read_info->read_buffer = NULL;
2394 + if (pfile_in_zip_read_info->stream_initialised)
2395 + inflateEnd(&pfile_in_zip_read_info->stream);
2397 - pfile_in_zip_read_info->stream_initialised = 0;
2398 - TRYFREE(pfile_in_zip_read_info);
2399 + pfile_in_zip_read_info->stream_initialised = 0;
2400 + TRYFREE(pfile_in_zip_read_info);
2402 s->pfile_in_zip_read=NULL;
2404 - return err;
2405 + return err;
2409 @@ -1263,32 +1530,69 @@
2410 return the number of byte copied or an error code <0
2412 extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
2413 - unzFile file;
2414 - char *szComment;
2415 - uLong uSizeBuf;
2417 - int err=UNZ_OK;
2418 - unz_s* s;
2419 - uLong uReadThis ;
2420 - if (file==NULL)
2421 - return UNZ_PARAMERROR;
2422 - s=(unz_s*)file;
2424 - uReadThis = uSizeBuf;
2425 - if (uReadThis>s->gi.size_comment)
2426 - uReadThis = s->gi.size_comment;
2427 + unzFile file;
2428 + char *szComment;
2429 + uLong uSizeBuf;
2431 + int err=UNZ_OK;
2432 + unz_s* s;
2433 + uLong uReadThis ;
2434 + if (file==NULL)
2435 + return UNZ_PARAMERROR;
2436 + s=(unz_s*)file;
2438 - if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0)
2439 - return UNZ_ERRNO;
2440 + uReadThis = uSizeBuf;
2441 + if (uReadThis>s->gi.size_comment)
2442 + uReadThis = s->gi.size_comment;
2444 - if (uReadThis>0)
2445 + if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
2446 + return UNZ_ERRNO;
2448 + if (uReadThis>0)
2450 *szComment='\0';
2451 - if (fread(szComment,(uInt)uReadThis,1,s->file)!=1)
2452 - return UNZ_ERRNO;
2453 + if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
2454 + return UNZ_ERRNO;
2457 - if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
2458 - *(szComment+s->gi.size_comment)='\0';
2459 - return (int)uReadThis;
2460 + if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
2461 + *(szComment+s->gi.size_comment)='\0';
2462 + return (int)uReadThis;
2465 +/* Additions by RX '2004 */
2466 +extern uLong ZEXPORT unzGetOffset (file)
2467 + unzFile file;
2469 + unz_s* s;
2471 + if (file==NULL)
2472 + return UNZ_PARAMERROR;
2473 + s=(unz_s*)file;
2474 + if (!s->current_file_ok)
2475 + return 0;
2476 + if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
2477 + if (s->num_file==s->gi.number_entry)
2478 + return 0;
2479 + return s->pos_in_central_dir;
2482 +extern int ZEXPORT unzSetOffset (file, pos)
2483 + unzFile file;
2484 + uLong pos;
2486 + unz_s* s;
2487 + int err;
2489 + if (file==NULL)
2490 + return UNZ_PARAMERROR;
2491 + s=(unz_s*)file;
2493 + s->pos_in_central_dir = pos;
2494 + s->num_file = s->gi.number_entry; /* hack */
2495 + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
2496 + &s->cur_file_info_internal,
2497 + NULL,0,NULL,0,NULL,0);
2498 + s->current_file_ok = (err == UNZ_OK);
2499 + return err;
2501 --- misc/zlib-1.1.4/contrib/minizip/unzip.h 1998-03-19 00:15:00.000000000 +0100
2502 +++ misc/build/zlib-1.1.4/contrib/minizip/unzip.h 2009-07-17 10:15:15.609375000 +0200
2503 @@ -1,15 +1,16 @@
2504 -/* unzip.h -- IO for uncompress .zip files using zlib
2505 - Version 0.15 beta, Mar 19th, 1998,
2506 +/* unzip.h -- IO for uncompress .zip files using zlib
2507 + Version 1.01e, February 12th, 2005
2509 - Copyright (C) 1998 Gilles Vollant
2510 + Copyright (C) 1998-2005 Gilles Vollant
2512 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
2513 WinZip, InfoZip tools and compatible.
2514 - Encryption and multi volume ZipFile (span) are not supported.
2516 + Multi volume ZipFile (span) are not supported.
2517 + Encryption compatible with pkzip 2.04g only supported
2518 Old compressions used by old PKZip 1.x are not supported
2520 - THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
2521 - CAN CHANGE IN FUTURE VERSION !!
2523 I WAIT FEEDBACK at mail info@winimage.com
2524 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
2526 @@ -33,10 +34,13 @@
2530 -/* for more info about .ZIP format, see
2531 - ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
2533 +/* for more info about .ZIP format, see
2534 + http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
2535 + http://www.info-zip.org/pub/infozip/doc/
2536 PkWare has also a specification at :
2537 - ftp://ftp.pkware.com/probdesc.zip */
2538 + ftp://ftp.pkware.com/probdesc.zip
2541 #ifndef _unz_H
2542 #define _unz_H
2543 @@ -46,46 +50,50 @@
2544 #endif
2546 #ifndef _ZLIB_H
2547 -#include "zlib.h"
2548 +#include "zlib/zlib.h"
2549 +#endif
2551 +#ifndef _ZLIBIOAPI_H
2552 +#include "ioapi.h"
2553 #endif
2555 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
2556 /* like the STRICT of WIN32, we define a pointer that cannot be converted
2557 from (void*) without cast */
2558 -typedef struct TagunzFile__ { int unused; } unzFile__;
2559 +typedef struct TagunzFile__ { int unused; } unzFile__;
2560 typedef unzFile__ *unzFile;
2561 #else
2562 typedef voidp unzFile;
2563 #endif
2566 -#define UNZ_OK (0)
2567 -#define UNZ_END_OF_LIST_OF_FILE (-100)
2568 -#define UNZ_ERRNO (Z_ERRNO)
2569 -#define UNZ_EOF (0)
2570 +#define UNZ_OK (0)
2571 +#define UNZ_END_OF_LIST_OF_FILE (-100)
2572 +#define UNZ_ERRNO (Z_ERRNO)
2573 +#define UNZ_EOF (0)
2574 #define UNZ_PARAMERROR (-102)
2575 #define UNZ_BADZIPFILE (-103)
2576 #define UNZ_INTERNALERROR (-104)
2577 #define UNZ_CRCERROR (-105)
2579 /* tm_unz contain date/time info */
2580 -typedef struct tm_unz_s
2581 +typedef struct tm_unz_s
2583 - uInt tm_sec; /* seconds after the minute - [0,59] */
2584 - uInt tm_min; /* minutes after the hour - [0,59] */
2585 - uInt tm_hour; /* hours since midnight - [0,23] */
2586 - uInt tm_mday; /* day of the month - [1,31] */
2587 - uInt tm_mon; /* months since January - [0,11] */
2588 - uInt tm_year; /* years - [1980..2044] */
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 } tm_unz;
2597 /* unz_global_info structure contain global data about the ZIPfile
2598 These data comes from the end of central dir */
2599 typedef struct unz_global_info_s
2601 - uLong number_entry; /* total number of entries in
2602 - the central dir on this disk */
2603 - uLong size_comment; /* size of the global comment of the zipfile */
2604 + uLong number_entry; /* total number of entries in
2605 + the central dir on this disk */
2606 + uLong size_comment; /* size of the global comment of the zipfile */
2607 } unz_global_info;
2610 @@ -98,8 +106,8 @@
2611 uLong compression_method; /* compression method 2 bytes */
2612 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
2613 uLong crc; /* crc-32 4 bytes */
2614 - uLong compressed_size; /* compressed size 4 bytes */
2615 - uLong uncompressed_size; /* uncompressed size 4 bytes */
2616 + uLong compressed_size; /* compressed size 4 bytes */
2617 + uLong uncompressed_size; /* uncompressed size 4 bytes */
2618 uLong size_filename; /* filename length 2 bytes */
2619 uLong size_file_extra; /* extra field length 2 bytes */
2620 uLong size_file_comment; /* file comment length 2 bytes */
2621 @@ -112,27 +120,34 @@
2622 } unz_file_info;
2624 extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
2625 - const char* fileName2,
2626 - int iCaseSensitivity));
2627 + const char* fileName2,
2628 + int iCaseSensitivity));
2630 Compare two filename (fileName1,fileName2).
2631 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
2632 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
2633 - or strcasecmp)
2634 + or strcasecmp)
2635 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
2636 - (like 1 on Unix, 2 on Windows)
2637 + (like 1 on Unix, 2 on Windows)
2641 extern unzFile ZEXPORT unzOpen OF((const char *path));
2643 Open a Zip file. path contain the full pathname (by example,
2644 - on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
2645 - "zlib/zlib111.zip".
2646 - If the zipfile cannot be opened (file don't exist or in not valid), the
2647 - return value is NULL.
2648 + on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
2649 + "zlib/zlib113.zip".
2650 + If the zipfile cannot be opened (file don't exist or in not valid), the
2651 + return value is NULL.
2652 Else, the return value is a unzFile Handle, usable with other function
2653 - of this unzip package.
2654 + of this unzip package.
2657 +extern unzFile ZEXPORT unzOpen2 OF((const char *path,
2658 + zlib_filefunc_def* pzlib_filefunc_def));
2660 + Open a Zip file, like unzOpen, but provide a set of file low level API
2661 + for read/write the zip file (see ioapi.h)
2664 extern int ZEXPORT unzClose OF((unzFile file));
2665 @@ -143,7 +158,7 @@
2666 return UNZ_OK if there is no problem. */
2668 extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
2669 - unz_global_info *pglobal_info));
2670 + unz_global_info *pglobal_info));
2672 Write info about the ZipFile in the *pglobal_info structure.
2673 No preparation of the structure is needed
2674 @@ -151,8 +166,8 @@
2677 extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
2678 - char *szComment,
2679 - uLong uSizeBuf));
2680 + char *szComment,
2681 + uLong uSizeBuf));
2683 Get the global comment string of the ZipFile, in the szComment buffer.
2684 uSizeBuf is the size of the szComment buffer.
2685 @@ -176,9 +191,9 @@
2686 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
2689 -extern int ZEXPORT unzLocateFile OF((unzFile file,
2690 - const char *szFileName,
2691 - int iCaseSensitivity));
2692 +extern int ZEXPORT unzLocateFile OF((unzFile file,
2693 + const char *szFileName,
2694 + int iCaseSensitivity));
2696 Try locate the file szFileName in the zipfile.
2697 For the iCaseSensitivity signification, see unzStringFileNameCompare
2698 @@ -189,25 +204,44 @@
2702 +/* ****************************************** */
2703 +/* Ryan supplied functions */
2704 +/* unz_file_info contain information about a file in the zipfile */
2705 +typedef struct unz_file_pos_s
2707 + uLong pos_in_zip_directory; /* offset in zip file directory */
2708 + uLong num_of_file; /* # of file */
2709 +} unz_file_pos;
2711 +extern int ZEXPORT unzGetFilePos(
2712 + unzFile file,
2713 + unz_file_pos* file_pos);
2715 +extern int ZEXPORT unzGoToFilePos(
2716 + unzFile file,
2717 + unz_file_pos* file_pos);
2719 +/* ****************************************** */
2721 extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
2722 - unz_file_info *pfile_info,
2723 - char *szFileName,
2724 - uLong fileNameBufferSize,
2725 - void *extraField,
2726 - uLong extraFieldBufferSize,
2727 - char *szComment,
2728 - uLong commentBufferSize));
2729 + unz_file_info *pfile_info,
2730 + char *szFileName,
2731 + uLong fileNameBufferSize,
2732 + void *extraField,
2733 + uLong extraFieldBufferSize,
2734 + char *szComment,
2735 + uLong commentBufferSize));
2737 Get Info about the current file
2738 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
2739 - the current file
2740 + the current file
2741 if szFileName!=NULL, the filemane string will be copied in szFileName
2742 - (fileNameBufferSize is the size of the buffer)
2743 + (fileNameBufferSize is the size of the buffer)
2744 if extraField!=NULL, the extra field information will be copied in extraField
2745 - (extraFieldBufferSize is the size of the buffer).
2746 - This is the Central-header version of the extra field
2747 + (extraFieldBufferSize is the size of the buffer).
2748 + This is the Central-header version of the extra field
2749 if szComment!=NULL, the comment string of the file will be copied in szComment
2750 - (commentBufferSize is the size of the buffer)
2751 + (commentBufferSize is the size of the buffer)
2754 /***************************************************************************/
2755 @@ -221,16 +255,51 @@
2756 If there is no error, the return value is UNZ_OK.
2759 +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
2760 + const char* password));
2762 + Open for reading data the current file in the zipfile.
2763 + password is a crypting password
2764 + If there is no error, the return value is UNZ_OK.
2767 +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
2768 + int* method,
2769 + int* level,
2770 + int raw));
2772 + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
2773 + if raw==1
2774 + *method will receive method of compression, *level will receive level of
2775 + compression
2776 + note : you can set level parameter as NULL (if you did not want known level,
2777 + but you CANNOT set method parameter as NULL
2780 +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
2781 + int* method,
2782 + int* level,
2783 + int raw,
2784 + const char* password));
2786 + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
2787 + if raw==1
2788 + *method will receive method of compression, *level will receive level of
2789 + compression
2790 + note : you can set level parameter as NULL (if you did not want known level,
2791 + but you CANNOT set method parameter as NULL
2795 extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
2797 Close the file in zip opened with unzOpenCurrentFile
2798 Return UNZ_CRCERROR if all the file was read but the CRC is not good
2802 -extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
2803 - voidp buf,
2804 - unsigned len));
2805 +extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
2806 + voidp buf,
2807 + unsigned len));
2809 Read bytes from the current file (opened by unzOpenCurrentFile)
2810 buf contain buffer where data must be copied
2811 @@ -249,12 +318,12 @@
2813 extern int ZEXPORT unzeof OF((unzFile file));
2815 - return 1 if the end of file was reached, 0 elsewhere
2816 + return 1 if the end of file was reached, 0 elsewhere
2819 extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
2820 - voidp buf,
2821 - unsigned len));
2822 + voidp buf,
2823 + unsigned len));
2825 Read extra field from the current file (opened by unzOpenCurrentFile)
2826 This is the local-header version of the extra field (sometimes, there is
2827 @@ -263,11 +332,21 @@
2828 if buf==NULL, it return the size of the local extra field
2830 if buf!=NULL, len is the size of the buffer, the extra header is copied in
2831 - buf.
2832 - the return value is the number of bytes copied in buf, or (if <0)
2833 - the error code
2834 + buf.
2835 + the return value is the number of bytes copied in buf, or (if <0)
2836 + the error code
2839 +/***************************************************************************/
2841 +/* Get the current file offset */
2842 +extern uLong ZEXPORT unzGetOffset (unzFile file);
2844 +/* Set the current file offset */
2845 +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
2849 #ifdef __cplusplus
2851 #endif
2852 --- misc/zlib-1.1.4/contrib/minizip/info_zip_crypt.h 2009-07-17 11:13:37.281250000 +0200
2853 +++ misc/build/zlib-1.1.4/contrib/minizip/info_zip_crypt.h 2009-07-17 10:58:41.843750000 +0200
2854 @@ -0,0 +1,132 @@
2855 +/* info_zip_crypt.h -- base code for crypt/uncrypt ZIPfile
2858 + Version 1.01e, February 12th, 2005
2860 + Copyright (C) 1998-2005 Gilles Vollant
2862 + This code is a modified version of crypting code in Infozip distribution
2864 + The encryption/decryption parts of this source code (as opposed to the
2865 + non-echoing password parts) were originally written in Europe. The
2866 + whole source package can be freely distributed, including from the USA.
2867 + (Prior to January 2000, re-export from the US was a violation of US law.)
2869 + This encryption code is a direct transcription of the algorithm from
2870 + Roger Schlafly, described by Phil Katz in the file appnote.txt. This
2871 + file (appnote.txt) is distributed with the PKZIP program (even in the
2872 + version without encryption capabilities).
2874 + If you don't need crypting in your application, just define symbols
2875 + NOCRYPT and NOUNCRYPT.
2877 + This code support the "Traditional PKWARE Encryption".
2879 + The new AES encryption added on Zip format by Winzip (see the page
2880 + http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
2881 + Encryption is not supported.
2884 +#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
2886 +/***********************************************************************
2887 + * Return the next byte in the pseudo-random sequence
2888 + */
2889 +static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
2891 + unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
2892 + * unpredictable manner on 16-bit systems; not a problem
2893 + * with any known compiler so far, though */
2895 + temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
2896 + return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
2899 +/***********************************************************************
2900 + * Update the encryption keys with the next byte of plain text
2901 + */
2902 +static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
2904 + (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
2905 + (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
2906 + (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
2908 + register int keyshift = (int)((*(pkeys+1)) >> 24);
2909 + (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
2911 + return c;
2915 +/***********************************************************************
2916 + * Initialize the encryption keys and the random header according to
2917 + * the given password.
2918 + */
2919 +static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
2921 + *(pkeys+0) = 305419896L;
2922 + *(pkeys+1) = 591751049L;
2923 + *(pkeys+2) = 878082192L;
2924 + while (*passwd != '\0') {
2925 + update_keys(pkeys,pcrc_32_tab,(int)*passwd);
2926 + passwd++;
2930 +#define zdecode(pkeys,pcrc_32_tab,c) \
2931 + (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
2933 +#define zencode(pkeys,pcrc_32_tab,c,t) \
2934 + (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
2936 +#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
2938 +#define RAND_HEAD_LEN 12
2939 + /* "last resort" source for second part of crypt seed pattern */
2940 +# ifndef ZCR_SEED2
2941 +# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
2942 +# endif
2944 +static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
2945 + const char *passwd; /* password string */
2946 + unsigned char *buf; /* where to write header */
2947 + int bufSize;
2948 + unsigned long* pkeys;
2949 + const unsigned long* pcrc_32_tab;
2950 + unsigned long crcForCrypting;
2952 + int n; /* index in random header */
2953 + int t; /* temporary */
2954 + int c; /* random byte */
2955 + unsigned char header[RAND_HEAD_LEN-2]; /* random header */
2956 + static unsigned calls = 0; /* ensure different random header each time */
2958 + if (bufSize<RAND_HEAD_LEN)
2959 + return 0;
2961 + /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
2962 + * output of rand() to get less predictability, since rand() is
2963 + * often poorly implemented.
2964 + */
2965 + if (++calls == 1)
2967 + srand((unsigned)(time(NULL) ^ ZCR_SEED2));
2969 + init_keys(passwd, pkeys, pcrc_32_tab);
2970 + for (n = 0; n < RAND_HEAD_LEN-2; n++)
2972 + c = (rand() >> 7) & 0xff;
2973 + header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
2975 + /* Encrypt random header (last two bytes is high word of crc) */
2976 + init_keys(passwd, pkeys, pcrc_32_tab);
2977 + for (n = 0; n < RAND_HEAD_LEN-2; n++)
2979 + buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
2981 + buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
2982 + buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
2983 + return n;
2986 +#endif
2987 --- misc/zlib-1.1.4/contrib/minizip/ioapi.c 2009-07-17 11:13:18.593750000 +0200
2988 +++ misc/build/zlib-1.1.4/contrib/minizip/ioapi.c 2009-07-17 10:58:56.718750000 +0200
2989 @@ -0,0 +1,177 @@
2990 +/* ioapi.c -- IO base function header for compress/uncompress .zip
2991 + files using zlib + zip or unzip API
2993 + Version 1.01e, February 12th, 2005
2995 + Copyright (C) 1998-2005 Gilles Vollant
2998 +#include <stdio.h>
2999 +#include <stdlib.h>
3000 +#include <string.h>
3002 +#include "zlib.h"
3003 +#include "ioapi.h"
3007 +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
3009 +#ifndef SEEK_CUR
3010 +#define SEEK_CUR 1
3011 +#endif
3013 +#ifndef SEEK_END
3014 +#define SEEK_END 2
3015 +#endif
3017 +#ifndef SEEK_SET
3018 +#define SEEK_SET 0
3019 +#endif
3021 +voidpf ZCALLBACK fopen_file_func OF((
3022 + voidpf opaque,
3023 + const char* filename,
3024 + int mode));
3026 +uLong ZCALLBACK fread_file_func OF((
3027 + voidpf opaque,
3028 + voidpf stream,
3029 + void* buf,
3030 + uLong size));
3032 +uLong ZCALLBACK fwrite_file_func OF((
3033 + voidpf opaque,
3034 + voidpf stream,
3035 + const void* buf,
3036 + uLong size));
3038 +long ZCALLBACK ftell_file_func OF((
3039 + voidpf opaque,
3040 + voidpf stream));
3042 +long ZCALLBACK fseek_file_func OF((
3043 + voidpf opaque,
3044 + voidpf stream,
3045 + uLong offset,
3046 + int origin));
3048 +int ZCALLBACK fclose_file_func OF((
3049 + voidpf opaque,
3050 + voidpf stream));
3052 +int ZCALLBACK ferror_file_func OF((
3053 + voidpf opaque,
3054 + voidpf stream));
3057 +voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
3058 + voidpf opaque;
3059 + const char* filename;
3060 + int mode;
3062 + FILE* file = NULL;
3063 + const char* mode_fopen = NULL;
3064 + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
3065 + mode_fopen = "rb";
3066 + else
3067 + if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
3068 + mode_fopen = "r+b";
3069 + else
3070 + if (mode & ZLIB_FILEFUNC_MODE_CREATE)
3071 + mode_fopen = "wb";
3073 + if ((filename!=NULL) && (mode_fopen != NULL))
3074 + file = fopen(filename, mode_fopen);
3075 + return file;
3079 +uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
3080 + voidpf opaque;
3081 + voidpf stream;
3082 + void* buf;
3083 + uLong size;
3085 + uLong ret;
3086 + ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
3087 + return ret;
3091 +uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
3092 + voidpf opaque;
3093 + voidpf stream;
3094 + const void* buf;
3095 + uLong size;
3097 + uLong ret;
3098 + ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
3099 + return ret;
3102 +long ZCALLBACK ftell_file_func (opaque, stream)
3103 + voidpf opaque;
3104 + voidpf stream;
3106 + long ret;
3107 + ret = ftell((FILE *)stream);
3108 + return ret;
3111 +long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
3112 + voidpf opaque;
3113 + voidpf stream;
3114 + uLong offset;
3115 + int origin;
3117 + int fseek_origin=0;
3118 + long ret;
3119 + switch (origin)
3121 + case ZLIB_FILEFUNC_SEEK_CUR :
3122 + fseek_origin = SEEK_CUR;
3123 + break;
3124 + case ZLIB_FILEFUNC_SEEK_END :
3125 + fseek_origin = SEEK_END;
3126 + break;
3127 + case ZLIB_FILEFUNC_SEEK_SET :
3128 + fseek_origin = SEEK_SET;
3129 + break;
3130 + default: return -1;
3132 + ret = 0;
3133 + fseek((FILE *)stream, offset, fseek_origin);
3134 + return ret;
3137 +int ZCALLBACK fclose_file_func (opaque, stream)
3138 + voidpf opaque;
3139 + voidpf stream;
3141 + int ret;
3142 + ret = fclose((FILE *)stream);
3143 + return ret;
3146 +int ZCALLBACK ferror_file_func (opaque, stream)
3147 + voidpf opaque;
3148 + voidpf stream;
3150 + int ret;
3151 + ret = ferror((FILE *)stream);
3152 + return ret;
3155 +void fill_fopen_filefunc (pzlib_filefunc_def)
3156 + zlib_filefunc_def* pzlib_filefunc_def;
3158 + pzlib_filefunc_def->zopen_file = fopen_file_func;
3159 + pzlib_filefunc_def->zread_file = fread_file_func;
3160 + pzlib_filefunc_def->zwrite_file = fwrite_file_func;
3161 + pzlib_filefunc_def->ztell_file = ftell_file_func;
3162 + pzlib_filefunc_def->zseek_file = fseek_file_func;
3163 + pzlib_filefunc_def->zclose_file = fclose_file_func;
3164 + pzlib_filefunc_def->zerror_file = ferror_file_func;
3165 + pzlib_filefunc_def->opaque = NULL;
3167 --- misc/zlib-1.1.4/contrib/minizip/ioapi.h 2009-07-17 11:13:30.109375000 +0200
3168 +++ misc/build/zlib-1.1.4/contrib/minizip/ioapi.h 2009-07-17 10:59:06.375000000 +0200
3169 @@ -0,0 +1,75 @@
3170 +/* ioapi.h -- IO base function header for compress/uncompress .zip
3171 + files using zlib + zip or unzip API
3173 + Version 1.01e, February 12th, 2005
3175 + Copyright (C) 1998-2005 Gilles Vollant
3178 +#ifndef _ZLIBIOAPI_H
3179 +#define _ZLIBIOAPI_H
3182 +#define ZLIB_FILEFUNC_SEEK_CUR (1)
3183 +#define ZLIB_FILEFUNC_SEEK_END (2)
3184 +#define ZLIB_FILEFUNC_SEEK_SET (0)
3186 +#define ZLIB_FILEFUNC_MODE_READ (1)
3187 +#define ZLIB_FILEFUNC_MODE_WRITE (2)
3188 +#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
3190 +#define ZLIB_FILEFUNC_MODE_EXISTING (4)
3191 +#define ZLIB_FILEFUNC_MODE_CREATE (8)
3194 +#ifndef ZCALLBACK
3196 +#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
3197 +#define ZCALLBACK CALLBACK
3198 +#else
3199 +#define ZCALLBACK
3200 +#endif
3201 +#endif
3203 +#ifdef __cplusplus
3204 +extern "C" {
3205 +#endif
3207 +typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
3208 +typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
3209 +typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
3210 +typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
3211 +typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
3212 +typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
3213 +typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
3215 +typedef struct zlib_filefunc_def_s
3217 + open_file_func zopen_file;
3218 + read_file_func zread_file;
3219 + write_file_func zwrite_file;
3220 + tell_file_func ztell_file;
3221 + seek_file_func zseek_file;
3222 + close_file_func zclose_file;
3223 + testerror_file_func zerror_file;
3224 + voidpf opaque;
3225 +} zlib_filefunc_def;
3229 +void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
3231 +#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
3232 +#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
3233 +#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
3234 +#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
3235 +#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
3236 +#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
3239 +#ifdef __cplusplus
3241 +#endif
3243 +#endif