packvfs

changeset 3:ef6c1472607f tip

jesus fucking christ that was easy... written a test prog "zipcat" to try out zlib's contrib library "minizip", to list and read files out of zip archives directly...
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 04 Nov 2013 06:46:17 +0200
parents dc23ab0545a6
children
files .hgignore test/zipcat/Makefile test/zipcat/src/main.c test/zipcat/src/minizip/crypt.h test/zipcat/src/minizip/ioapi.c test/zipcat/src/minizip/ioapi.h test/zipcat/src/minizip/iowin32.c test/zipcat/src/minizip/iowin32.h test/zipcat/src/minizip/mztools.c test/zipcat/src/minizip/mztools.h test/zipcat/src/minizip/unzip.c test/zipcat/src/minizip/unzip.h test/zipcat/src/minizip/zip.c test/zipcat/src/minizip/zip.h
diffstat 14 files changed, 6448 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/.hgignore	Mon Nov 04 03:50:55 2013 +0200
     1.2 +++ b/.hgignore	Mon Nov 04 06:46:17 2013 +0200
     1.3 @@ -3,3 +3,5 @@
     1.4  \.swp$
     1.5  ^libpackvfs\.
     1.6  /pvfsh$
     1.7 +/zipcat$
     1.8 +\.zip$
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/zipcat/Makefile	Mon Nov 04 06:46:17 2013 +0200
     2.3 @@ -0,0 +1,13 @@
     2.4 +src = $(wildcard src/*.c) $(wildcard src/minizip/*.c)
     2.5 +obj = $(src:.c=.o)
     2.6 +bin = zipcat
     2.7 +
     2.8 +CFLAGS = -std=c99 -pedantic -Wall -g
     2.9 +LDFLAGS = -lz
    2.10 +
    2.11 +$(bin): $(obj)
    2.12 +	$(CC) -o $@ $(obj) $(LDFLAGS)
    2.13 +
    2.14 +.PHONY: clean
    2.15 +clean:
    2.16 +	rm -f $(obj) $(bin)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/zipcat/src/main.c	Mon Nov 04 06:46:17 2013 +0200
     3.3 @@ -0,0 +1,93 @@
     3.4 +#include <stdio.h>
     3.5 +#include "minizip/unzip.h"
     3.6 +
     3.7 +int procfile(const char *zip_fname, const char *fname);
     3.8 +
     3.9 +int main(int argc, char **argv)
    3.10 +{
    3.11 +	int i, listonly = 0;
    3.12 +
    3.13 +	for(i=1; i<argc; i++) {
    3.14 +		if(argv[i][0] == '-') {
    3.15 +			switch(argv[i][1]) {
    3.16 +			case 'l':
    3.17 +				listonly = 1;
    3.18 +				break;
    3.19 +
    3.20 +			default:
    3.21 +				fprintf(stderr, "unexpected option: %s\n", argv[i]);
    3.22 +				return 1;
    3.23 +			}
    3.24 +		} else {
    3.25 +			if(!listonly) {
    3.26 +				procfile(argv[i], argv[i + 1]);
    3.27 +				i++;
    3.28 +			} else {
    3.29 +				procfile(argv[i], 0);
    3.30 +				listonly = 0;
    3.31 +			}
    3.32 +		}
    3.33 +	}
    3.34 +
    3.35 +	return 0;
    3.36 +}
    3.37 +
    3.38 +
    3.39 +int procfile(const char *zip_fname, const char *fname)
    3.40 +{
    3.41 +	char buf[512];
    3.42 +	unzFile zip;
    3.43 +	unz_global_info ginf;
    3.44 +	int res = -1;
    3.45 +
    3.46 +	if(!(zip = unzOpen(zip_fname))) {
    3.47 +		fprintf(stderr, "failed to open zip file: %s\n", zip_fname);
    3.48 +		return -1;
    3.49 +	}
    3.50 +
    3.51 +	unzGetGlobalInfo(zip, &ginf);
    3.52 +
    3.53 +	if(fname) {
    3.54 +		int sz;
    3.55 +
    3.56 +		if(unzLocateFile(zip, fname, 1) != UNZ_OK) {
    3.57 +			fprintf(stderr, "failed to locate \"%s\" in zip file: %s\n", fname, zip_fname);
    3.58 +			goto err;
    3.59 +		}
    3.60 +
    3.61 +		if(unzOpenCurrentFile(zip) != UNZ_OK) {
    3.62 +			fprintf(stderr, "failed to open \"%s\" in zip file: %s\n", fname, zip_fname);
    3.63 +			goto err;
    3.64 +		}
    3.65 +
    3.66 +		while((sz = unzReadCurrentFile(zip, buf, sizeof buf)) > 0) {
    3.67 +			fwrite(buf, 1, sz, stdout);
    3.68 +		}
    3.69 +		fflush(stdout);
    3.70 +
    3.71 +		unzCloseCurrentFile(zip);
    3.72 +
    3.73 +	} else {
    3.74 +		/* just list the contents */
    3.75 +		if(unzGoToFirstFile(zip) != UNZ_OK) {
    3.76 +			fprintf(stderr, "failed to start content listing\n");
    3.77 +			goto err;
    3.78 +		}
    3.79 +
    3.80 +		do {
    3.81 +			unz_file_info file_info;
    3.82 +			if(unzGetCurrentFileInfo(zip, &file_info, buf, sizeof buf, 0, 0, 0, 0) != UNZ_OK) {
    3.83 +				fprintf(stderr, "failed to retrieve file information\n");
    3.84 +				goto err;
    3.85 +			}
    3.86 +
    3.87 +			printf("%s - %lu bytes (%lu compressed)\n", buf, file_info.uncompressed_size,
    3.88 +					file_info.compressed_size);
    3.89 +		} while(unzGoToNextFile(zip) == UNZ_OK);
    3.90 +	}
    3.91 +
    3.92 +	res = 0;	/* success */
    3.93 +err:
    3.94 +	unzClose(zip);
    3.95 +	return res;
    3.96 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/zipcat/src/minizip/crypt.h	Mon Nov 04 06:46:17 2013 +0200
     4.3 @@ -0,0 +1,131 @@
     4.4 +/* crypt.h -- base code for crypt/uncrypt ZIPfile
     4.5 +
     4.6 +
     4.7 +   Version 1.01e, February 12th, 2005
     4.8 +
     4.9 +   Copyright (C) 1998-2005 Gilles Vollant
    4.10 +
    4.11 +   This code is a modified version of crypting code in Infozip distribution
    4.12 +
    4.13 +   The encryption/decryption parts of this source code (as opposed to the
    4.14 +   non-echoing password parts) were originally written in Europe.  The
    4.15 +   whole source package can be freely distributed, including from the USA.
    4.16 +   (Prior to January 2000, re-export from the US was a violation of US law.)
    4.17 +
    4.18 +   This encryption code is a direct transcription of the algorithm from
    4.19 +   Roger Schlafly, described by Phil Katz in the file appnote.txt.  This
    4.20 +   file (appnote.txt) is distributed with the PKZIP program (even in the
    4.21 +   version without encryption capabilities).
    4.22 +
    4.23 +   If you don't need crypting in your application, just define symbols
    4.24 +   NOCRYPT and NOUNCRYPT.
    4.25 +
    4.26 +   This code support the "Traditional PKWARE Encryption".
    4.27 +
    4.28 +   The new AES encryption added on Zip format by Winzip (see the page
    4.29 +   http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
    4.30 +   Encryption is not supported.
    4.31 +*/
    4.32 +
    4.33 +#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
    4.34 +
    4.35 +/***********************************************************************
    4.36 + * Return the next byte in the pseudo-random sequence
    4.37 + */
    4.38 +static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab)
    4.39 +{
    4.40 +    unsigned temp;  /* POTENTIAL BUG:  temp*(temp^1) may overflow in an
    4.41 +                     * unpredictable manner on 16-bit systems; not a problem
    4.42 +                     * with any known compiler so far, though */
    4.43 +
    4.44 +    temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
    4.45 +    return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
    4.46 +}
    4.47 +
    4.48 +/***********************************************************************
    4.49 + * Update the encryption keys with the next byte of plain text
    4.50 + */
    4.51 +static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c)
    4.52 +{
    4.53 +    (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
    4.54 +    (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
    4.55 +    (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
    4.56 +    {
    4.57 +      register int keyshift = (int)((*(pkeys+1)) >> 24);
    4.58 +      (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
    4.59 +    }
    4.60 +    return c;
    4.61 +}
    4.62 +
    4.63 +
    4.64 +/***********************************************************************
    4.65 + * Initialize the encryption keys and the random header according to
    4.66 + * the given password.
    4.67 + */
    4.68 +static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab)
    4.69 +{
    4.70 +    *(pkeys+0) = 305419896L;
    4.71 +    *(pkeys+1) = 591751049L;
    4.72 +    *(pkeys+2) = 878082192L;
    4.73 +    while (*passwd != '\0') {
    4.74 +        update_keys(pkeys,pcrc_32_tab,(int)*passwd);
    4.75 +        passwd++;
    4.76 +    }
    4.77 +}
    4.78 +
    4.79 +#define zdecode(pkeys,pcrc_32_tab,c) \
    4.80 +    (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
    4.81 +
    4.82 +#define zencode(pkeys,pcrc_32_tab,c,t) \
    4.83 +    (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
    4.84 +
    4.85 +#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
    4.86 +
    4.87 +#define RAND_HEAD_LEN  12
    4.88 +   /* "last resort" source for second part of crypt seed pattern */
    4.89 +#  ifndef ZCR_SEED2
    4.90 +#    define ZCR_SEED2 3141592654UL     /* use PI as default pattern */
    4.91 +#  endif
    4.92 +
    4.93 +static int crypthead(const char* passwd,      /* password string */
    4.94 +                     unsigned char* buf,      /* where to write header */
    4.95 +                     int bufSize,
    4.96 +                     unsigned long* pkeys,
    4.97 +                     const z_crc_t* pcrc_32_tab,
    4.98 +                     unsigned long crcForCrypting)
    4.99 +{
   4.100 +    int n;                       /* index in random header */
   4.101 +    int t;                       /* temporary */
   4.102 +    int c;                       /* random byte */
   4.103 +    unsigned char header[RAND_HEAD_LEN-2]; /* random header */
   4.104 +    static unsigned calls = 0;   /* ensure different random header each time */
   4.105 +
   4.106 +    if (bufSize<RAND_HEAD_LEN)
   4.107 +      return 0;
   4.108 +
   4.109 +    /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
   4.110 +     * output of rand() to get less predictability, since rand() is
   4.111 +     * often poorly implemented.
   4.112 +     */
   4.113 +    if (++calls == 1)
   4.114 +    {
   4.115 +        srand((unsigned)(time(NULL) ^ ZCR_SEED2));
   4.116 +    }
   4.117 +    init_keys(passwd, pkeys, pcrc_32_tab);
   4.118 +    for (n = 0; n < RAND_HEAD_LEN-2; n++)
   4.119 +    {
   4.120 +        c = (rand() >> 7) & 0xff;
   4.121 +        header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
   4.122 +    }
   4.123 +    /* Encrypt random header (last two bytes is high word of crc) */
   4.124 +    init_keys(passwd, pkeys, pcrc_32_tab);
   4.125 +    for (n = 0; n < RAND_HEAD_LEN-2; n++)
   4.126 +    {
   4.127 +        buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
   4.128 +    }
   4.129 +    buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
   4.130 +    buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
   4.131 +    return n;
   4.132 +}
   4.133 +
   4.134 +#endif
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/zipcat/src/minizip/ioapi.c	Mon Nov 04 06:46:17 2013 +0200
     5.3 @@ -0,0 +1,247 @@
     5.4 +/* ioapi.h -- IO base function header for compress/uncompress .zip
     5.5 +   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
     5.6 +
     5.7 +         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
     5.8 +
     5.9 +         Modifications for Zip64 support
    5.10 +         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
    5.11 +
    5.12 +         For more info read MiniZip_info.txt
    5.13 +
    5.14 +*/
    5.15 +
    5.16 +#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
    5.17 +        #define _CRT_SECURE_NO_WARNINGS
    5.18 +#endif
    5.19 +
    5.20 +#if defined(__APPLE__) || defined(IOAPI_NO_64)
    5.21 +// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
    5.22 +#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
    5.23 +#define FTELLO_FUNC(stream) ftello(stream)
    5.24 +#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
    5.25 +#else
    5.26 +#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
    5.27 +#define FTELLO_FUNC(stream) ftello64(stream)
    5.28 +#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
    5.29 +#endif
    5.30 +
    5.31 +
    5.32 +#include "ioapi.h"
    5.33 +
    5.34 +voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
    5.35 +{
    5.36 +    if (pfilefunc->zfile_func64.zopen64_file != NULL)
    5.37 +        return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
    5.38 +    else
    5.39 +    {
    5.40 +        return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
    5.41 +    }
    5.42 +}
    5.43 +
    5.44 +long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
    5.45 +{
    5.46 +    if (pfilefunc->zfile_func64.zseek64_file != NULL)
    5.47 +        return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
    5.48 +    else
    5.49 +    {
    5.50 +        uLong offsetTruncated = (uLong)offset;
    5.51 +        if (offsetTruncated != offset)
    5.52 +            return -1;
    5.53 +        else
    5.54 +            return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
    5.55 +    }
    5.56 +}
    5.57 +
    5.58 +ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
    5.59 +{
    5.60 +    if (pfilefunc->zfile_func64.zseek64_file != NULL)
    5.61 +        return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
    5.62 +    else
    5.63 +    {
    5.64 +        uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
    5.65 +        if ((tell_uLong) == MAXU32)
    5.66 +            return (ZPOS64_T)-1;
    5.67 +        else
    5.68 +            return tell_uLong;
    5.69 +    }
    5.70 +}
    5.71 +
    5.72 +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
    5.73 +{
    5.74 +    p_filefunc64_32->zfile_func64.zopen64_file = NULL;
    5.75 +    p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
    5.76 +    p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
    5.77 +    p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
    5.78 +    p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
    5.79 +    p_filefunc64_32->zfile_func64.ztell64_file = NULL;
    5.80 +    p_filefunc64_32->zfile_func64.zseek64_file = NULL;
    5.81 +    p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
    5.82 +    p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
    5.83 +    p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
    5.84 +    p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
    5.85 +    p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
    5.86 +}
    5.87 +
    5.88 +
    5.89 +
    5.90 +static voidpf  ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
    5.91 +static uLong   ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
    5.92 +static uLong   ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
    5.93 +static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
    5.94 +static long    ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
    5.95 +static int     ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
    5.96 +static int     ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
    5.97 +
    5.98 +static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
    5.99 +{
   5.100 +    FILE* file = NULL;
   5.101 +    const char* mode_fopen = NULL;
   5.102 +    if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
   5.103 +        mode_fopen = "rb";
   5.104 +    else
   5.105 +    if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
   5.106 +        mode_fopen = "r+b";
   5.107 +    else
   5.108 +    if (mode & ZLIB_FILEFUNC_MODE_CREATE)
   5.109 +        mode_fopen = "wb";
   5.110 +
   5.111 +    if ((filename!=NULL) && (mode_fopen != NULL))
   5.112 +        file = fopen(filename, mode_fopen);
   5.113 +    return file;
   5.114 +}
   5.115 +
   5.116 +static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
   5.117 +{
   5.118 +    FILE* file = NULL;
   5.119 +    const char* mode_fopen = NULL;
   5.120 +    if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
   5.121 +        mode_fopen = "rb";
   5.122 +    else
   5.123 +    if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
   5.124 +        mode_fopen = "r+b";
   5.125 +    else
   5.126 +    if (mode & ZLIB_FILEFUNC_MODE_CREATE)
   5.127 +        mode_fopen = "wb";
   5.128 +
   5.129 +    if ((filename!=NULL) && (mode_fopen != NULL))
   5.130 +        file = FOPEN_FUNC((const char*)filename, mode_fopen);
   5.131 +    return file;
   5.132 +}
   5.133 +
   5.134 +
   5.135 +static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
   5.136 +{
   5.137 +    uLong ret;
   5.138 +    ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
   5.139 +    return ret;
   5.140 +}
   5.141 +
   5.142 +static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
   5.143 +{
   5.144 +    uLong ret;
   5.145 +    ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
   5.146 +    return ret;
   5.147 +}
   5.148 +
   5.149 +static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
   5.150 +{
   5.151 +    long ret;
   5.152 +    ret = ftell((FILE *)stream);
   5.153 +    return ret;
   5.154 +}
   5.155 +
   5.156 +
   5.157 +static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
   5.158 +{
   5.159 +    ZPOS64_T ret;
   5.160 +    ret = FTELLO_FUNC((FILE *)stream);
   5.161 +    return ret;
   5.162 +}
   5.163 +
   5.164 +static long ZCALLBACK fseek_file_func (voidpf  opaque, voidpf stream, uLong offset, int origin)
   5.165 +{
   5.166 +    int fseek_origin=0;
   5.167 +    long ret;
   5.168 +    switch (origin)
   5.169 +    {
   5.170 +    case ZLIB_FILEFUNC_SEEK_CUR :
   5.171 +        fseek_origin = SEEK_CUR;
   5.172 +        break;
   5.173 +    case ZLIB_FILEFUNC_SEEK_END :
   5.174 +        fseek_origin = SEEK_END;
   5.175 +        break;
   5.176 +    case ZLIB_FILEFUNC_SEEK_SET :
   5.177 +        fseek_origin = SEEK_SET;
   5.178 +        break;
   5.179 +    default: return -1;
   5.180 +    }
   5.181 +    ret = 0;
   5.182 +    if (fseek((FILE *)stream, offset, fseek_origin) != 0)
   5.183 +        ret = -1;
   5.184 +    return ret;
   5.185 +}
   5.186 +
   5.187 +static long ZCALLBACK fseek64_file_func (voidpf  opaque, voidpf stream, ZPOS64_T offset, int origin)
   5.188 +{
   5.189 +    int fseek_origin=0;
   5.190 +    long ret;
   5.191 +    switch (origin)
   5.192 +    {
   5.193 +    case ZLIB_FILEFUNC_SEEK_CUR :
   5.194 +        fseek_origin = SEEK_CUR;
   5.195 +        break;
   5.196 +    case ZLIB_FILEFUNC_SEEK_END :
   5.197 +        fseek_origin = SEEK_END;
   5.198 +        break;
   5.199 +    case ZLIB_FILEFUNC_SEEK_SET :
   5.200 +        fseek_origin = SEEK_SET;
   5.201 +        break;
   5.202 +    default: return -1;
   5.203 +    }
   5.204 +    ret = 0;
   5.205 +
   5.206 +    if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0)
   5.207 +                        ret = -1;
   5.208 +
   5.209 +    return ret;
   5.210 +}
   5.211 +
   5.212 +
   5.213 +static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
   5.214 +{
   5.215 +    int ret;
   5.216 +    ret = fclose((FILE *)stream);
   5.217 +    return ret;
   5.218 +}
   5.219 +
   5.220 +static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
   5.221 +{
   5.222 +    int ret;
   5.223 +    ret = ferror((FILE *)stream);
   5.224 +    return ret;
   5.225 +}
   5.226 +
   5.227 +void fill_fopen_filefunc (pzlib_filefunc_def)
   5.228 +  zlib_filefunc_def* pzlib_filefunc_def;
   5.229 +{
   5.230 +    pzlib_filefunc_def->zopen_file = fopen_file_func;
   5.231 +    pzlib_filefunc_def->zread_file = fread_file_func;
   5.232 +    pzlib_filefunc_def->zwrite_file = fwrite_file_func;
   5.233 +    pzlib_filefunc_def->ztell_file = ftell_file_func;
   5.234 +    pzlib_filefunc_def->zseek_file = fseek_file_func;
   5.235 +    pzlib_filefunc_def->zclose_file = fclose_file_func;
   5.236 +    pzlib_filefunc_def->zerror_file = ferror_file_func;
   5.237 +    pzlib_filefunc_def->opaque = NULL;
   5.238 +}
   5.239 +
   5.240 +void fill_fopen64_filefunc (zlib_filefunc64_def*  pzlib_filefunc_def)
   5.241 +{
   5.242 +    pzlib_filefunc_def->zopen64_file = fopen64_file_func;
   5.243 +    pzlib_filefunc_def->zread_file = fread_file_func;
   5.244 +    pzlib_filefunc_def->zwrite_file = fwrite_file_func;
   5.245 +    pzlib_filefunc_def->ztell64_file = ftell64_file_func;
   5.246 +    pzlib_filefunc_def->zseek64_file = fseek64_file_func;
   5.247 +    pzlib_filefunc_def->zclose_file = fclose_file_func;
   5.248 +    pzlib_filefunc_def->zerror_file = ferror_file_func;
   5.249 +    pzlib_filefunc_def->opaque = NULL;
   5.250 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/zipcat/src/minizip/ioapi.h	Mon Nov 04 06:46:17 2013 +0200
     6.3 @@ -0,0 +1,208 @@
     6.4 +/* ioapi.h -- IO base function header for compress/uncompress .zip
     6.5 +   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
     6.6 +
     6.7 +         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
     6.8 +
     6.9 +         Modifications for Zip64 support
    6.10 +         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
    6.11 +
    6.12 +         For more info read MiniZip_info.txt
    6.13 +
    6.14 +         Changes
    6.15 +
    6.16 +    Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this)
    6.17 +    Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
    6.18 +               More if/def section may be needed to support other platforms
    6.19 +    Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
    6.20 +                          (but you should use iowin32.c for windows instead)
    6.21 +
    6.22 +*/
    6.23 +
    6.24 +#ifndef _ZLIBIOAPI64_H
    6.25 +#define _ZLIBIOAPI64_H
    6.26 +
    6.27 +#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
    6.28 +
    6.29 +  // Linux needs this to support file operation on files larger then 4+GB
    6.30 +  // But might need better if/def to select just the platforms that needs them.
    6.31 +
    6.32 +        #ifndef __USE_FILE_OFFSET64
    6.33 +                #define __USE_FILE_OFFSET64
    6.34 +        #endif
    6.35 +        #ifndef __USE_LARGEFILE64
    6.36 +                #define __USE_LARGEFILE64
    6.37 +        #endif
    6.38 +        #ifndef _LARGEFILE64_SOURCE
    6.39 +                #define _LARGEFILE64_SOURCE
    6.40 +        #endif
    6.41 +        #ifndef _FILE_OFFSET_BIT
    6.42 +                #define _FILE_OFFSET_BIT 64
    6.43 +        #endif
    6.44 +
    6.45 +#endif
    6.46 +
    6.47 +#include <stdio.h>
    6.48 +#include <stdlib.h>
    6.49 +#include "zlib.h"
    6.50 +
    6.51 +#if defined(USE_FILE32API)
    6.52 +#define fopen64 fopen
    6.53 +#define ftello64 ftell
    6.54 +#define fseeko64 fseek
    6.55 +#else
    6.56 +#ifdef __FreeBSD__
    6.57 +#define fopen64 fopen
    6.58 +#define ftello64 ftello
    6.59 +#define fseeko64 fseeko
    6.60 +#endif
    6.61 +#ifdef _MSC_VER
    6.62 + #define fopen64 fopen
    6.63 + #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
    6.64 +  #define ftello64 _ftelli64
    6.65 +  #define fseeko64 _fseeki64
    6.66 + #else // old MSC
    6.67 +  #define ftello64 ftell
    6.68 +  #define fseeko64 fseek
    6.69 + #endif
    6.70 +#endif
    6.71 +#endif
    6.72 +
    6.73 +/*
    6.74 +#ifndef ZPOS64_T
    6.75 +  #ifdef _WIN32
    6.76 +                #define ZPOS64_T fpos_t
    6.77 +  #else
    6.78 +    #include <stdint.h>
    6.79 +    #define ZPOS64_T uint64_t
    6.80 +  #endif
    6.81 +#endif
    6.82 +*/
    6.83 +
    6.84 +#ifdef HAVE_MINIZIP64_CONF_H
    6.85 +#include "mz64conf.h"
    6.86 +#endif
    6.87 +
    6.88 +/* a type choosen by DEFINE */
    6.89 +#ifdef HAVE_64BIT_INT_CUSTOM
    6.90 +typedef  64BIT_INT_CUSTOM_TYPE ZPOS64_T;
    6.91 +#else
    6.92 +#ifdef HAS_STDINT_H
    6.93 +#include "stdint.h"
    6.94 +typedef uint64_t ZPOS64_T;
    6.95 +#else
    6.96 +
    6.97 +/* Maximum unsigned 32-bit value used as placeholder for zip64 */
    6.98 +#define MAXU32 0xffffffff
    6.99 +
   6.100 +#if defined(_MSC_VER) || defined(__BORLANDC__)
   6.101 +typedef unsigned __int64 ZPOS64_T;
   6.102 +#else
   6.103 +typedef unsigned long long int ZPOS64_T;
   6.104 +#endif
   6.105 +#endif
   6.106 +#endif
   6.107 +
   6.108 +
   6.109 +
   6.110 +#ifdef __cplusplus
   6.111 +extern "C" {
   6.112 +#endif
   6.113 +
   6.114 +
   6.115 +#define ZLIB_FILEFUNC_SEEK_CUR (1)
   6.116 +#define ZLIB_FILEFUNC_SEEK_END (2)
   6.117 +#define ZLIB_FILEFUNC_SEEK_SET (0)
   6.118 +
   6.119 +#define ZLIB_FILEFUNC_MODE_READ      (1)
   6.120 +#define ZLIB_FILEFUNC_MODE_WRITE     (2)
   6.121 +#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
   6.122 +
   6.123 +#define ZLIB_FILEFUNC_MODE_EXISTING (4)
   6.124 +#define ZLIB_FILEFUNC_MODE_CREATE   (8)
   6.125 +
   6.126 +
   6.127 +#ifndef ZCALLBACK
   6.128 + #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
   6.129 +   #define ZCALLBACK CALLBACK
   6.130 + #else
   6.131 +   #define ZCALLBACK
   6.132 + #endif
   6.133 +#endif
   6.134 +
   6.135 +
   6.136 +
   6.137 +
   6.138 +typedef voidpf   (ZCALLBACK *open_file_func)      OF((voidpf opaque, const char* filename, int mode));
   6.139 +typedef uLong    (ZCALLBACK *read_file_func)      OF((voidpf opaque, voidpf stream, void* buf, uLong size));
   6.140 +typedef uLong    (ZCALLBACK *write_file_func)     OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
   6.141 +typedef int      (ZCALLBACK *close_file_func)     OF((voidpf opaque, voidpf stream));
   6.142 +typedef int      (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
   6.143 +
   6.144 +typedef long     (ZCALLBACK *tell_file_func)      OF((voidpf opaque, voidpf stream));
   6.145 +typedef long     (ZCALLBACK *seek_file_func)      OF((voidpf opaque, voidpf stream, uLong offset, int origin));
   6.146 +
   6.147 +
   6.148 +/* here is the "old" 32 bits structure structure */
   6.149 +typedef struct zlib_filefunc_def_s
   6.150 +{
   6.151 +    open_file_func      zopen_file;
   6.152 +    read_file_func      zread_file;
   6.153 +    write_file_func     zwrite_file;
   6.154 +    tell_file_func      ztell_file;
   6.155 +    seek_file_func      zseek_file;
   6.156 +    close_file_func     zclose_file;
   6.157 +    testerror_file_func zerror_file;
   6.158 +    voidpf              opaque;
   6.159 +} zlib_filefunc_def;
   6.160 +
   6.161 +typedef ZPOS64_T (ZCALLBACK *tell64_file_func)    OF((voidpf opaque, voidpf stream));
   6.162 +typedef long     (ZCALLBACK *seek64_file_func)    OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
   6.163 +typedef voidpf   (ZCALLBACK *open64_file_func)    OF((voidpf opaque, const void* filename, int mode));
   6.164 +
   6.165 +typedef struct zlib_filefunc64_def_s
   6.166 +{
   6.167 +    open64_file_func    zopen64_file;
   6.168 +    read_file_func      zread_file;
   6.169 +    write_file_func     zwrite_file;
   6.170 +    tell64_file_func    ztell64_file;
   6.171 +    seek64_file_func    zseek64_file;
   6.172 +    close_file_func     zclose_file;
   6.173 +    testerror_file_func zerror_file;
   6.174 +    voidpf              opaque;
   6.175 +} zlib_filefunc64_def;
   6.176 +
   6.177 +void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
   6.178 +void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
   6.179 +
   6.180 +/* now internal definition, only for zip.c and unzip.h */
   6.181 +typedef struct zlib_filefunc64_32_def_s
   6.182 +{
   6.183 +    zlib_filefunc64_def zfile_func64;
   6.184 +    open_file_func      zopen32_file;
   6.185 +    tell_file_func      ztell32_file;
   6.186 +    seek_file_func      zseek32_file;
   6.187 +} zlib_filefunc64_32_def;
   6.188 +
   6.189 +
   6.190 +#define ZREAD64(filefunc,filestream,buf,size)     ((*((filefunc).zfile_func64.zread_file))   ((filefunc).zfile_func64.opaque,filestream,buf,size))
   6.191 +#define ZWRITE64(filefunc,filestream,buf,size)    ((*((filefunc).zfile_func64.zwrite_file))  ((filefunc).zfile_func64.opaque,filestream,buf,size))
   6.192 +//#define ZTELL64(filefunc,filestream)            ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
   6.193 +//#define ZSEEK64(filefunc,filestream,pos,mode)   ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
   6.194 +#define ZCLOSE64(filefunc,filestream)             ((*((filefunc).zfile_func64.zclose_file))  ((filefunc).zfile_func64.opaque,filestream))
   6.195 +#define ZERROR64(filefunc,filestream)             ((*((filefunc).zfile_func64.zerror_file))  ((filefunc).zfile_func64.opaque,filestream))
   6.196 +
   6.197 +voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
   6.198 +long    call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
   6.199 +ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
   6.200 +
   6.201 +void    fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
   6.202 +
   6.203 +#define ZOPEN64(filefunc,filename,mode)         (call_zopen64((&(filefunc)),(filename),(mode)))
   6.204 +#define ZTELL64(filefunc,filestream)            (call_ztell64((&(filefunc)),(filestream)))
   6.205 +#define ZSEEK64(filefunc,filestream,pos,mode)   (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
   6.206 +
   6.207 +#ifdef __cplusplus
   6.208 +}
   6.209 +#endif
   6.210 +
   6.211 +#endif
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/zipcat/src/minizip/iowin32.c	Mon Nov 04 06:46:17 2013 +0200
     7.3 @@ -0,0 +1,467 @@
     7.4 +/* iowin32.c -- IO base function header for compress/uncompress .zip
     7.5 +     Version 1.1, February 14h, 2010
     7.6 +     part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
     7.7 +
     7.8 +         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
     7.9 +
    7.10 +         Modifications for Zip64 support
    7.11 +         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
    7.12 +
    7.13 +     For more info read MiniZip_info.txt
    7.14 +
    7.15 +*/
    7.16 +
    7.17 +#ifdef WIN32
    7.18 +
    7.19 +#include <stdlib.h>
    7.20 +
    7.21 +#include "zlib.h"
    7.22 +#include "ioapi.h"
    7.23 +#include "iowin32.h"
    7.24 +
    7.25 +#ifndef INVALID_HANDLE_VALUE
    7.26 +#define INVALID_HANDLE_VALUE (0xFFFFFFFF)
    7.27 +#endif
    7.28 +
    7.29 +#ifndef INVALID_SET_FILE_POINTER
    7.30 +#define INVALID_SET_FILE_POINTER ((DWORD)-1)
    7.31 +#endif
    7.32 +
    7.33 +
    7.34 +#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API)))
    7.35 +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
    7.36 +#define IOWIN32_USING_WINRT_API 1
    7.37 +#endif
    7.38 +#endif
    7.39 +
    7.40 +voidpf  ZCALLBACK win32_open_file_func  OF((voidpf opaque, const char* filename, int mode));
    7.41 +uLong   ZCALLBACK win32_read_file_func  OF((voidpf opaque, voidpf stream, void* buf, uLong size));
    7.42 +uLong   ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
    7.43 +ZPOS64_T ZCALLBACK win32_tell64_file_func  OF((voidpf opaque, voidpf stream));
    7.44 +long    ZCALLBACK win32_seek64_file_func  OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
    7.45 +int     ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream));
    7.46 +int     ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream));
    7.47 +
    7.48 +typedef struct
    7.49 +{
    7.50 +    HANDLE hf;
    7.51 +    int error;
    7.52 +} WIN32FILE_IOWIN;
    7.53 +
    7.54 +
    7.55 +static void win32_translate_open_mode(int mode,
    7.56 +                                      DWORD* lpdwDesiredAccess,
    7.57 +                                      DWORD* lpdwCreationDisposition,
    7.58 +                                      DWORD* lpdwShareMode,
    7.59 +                                      DWORD* lpdwFlagsAndAttributes)
    7.60 +{
    7.61 +    *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
    7.62 +
    7.63 +    if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
    7.64 +    {
    7.65 +        *lpdwDesiredAccess = GENERIC_READ;
    7.66 +        *lpdwCreationDisposition = OPEN_EXISTING;
    7.67 +        *lpdwShareMode = FILE_SHARE_READ;
    7.68 +    }
    7.69 +    else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
    7.70 +    {
    7.71 +        *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
    7.72 +        *lpdwCreationDisposition = OPEN_EXISTING;
    7.73 +    }
    7.74 +    else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
    7.75 +    {
    7.76 +        *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
    7.77 +        *lpdwCreationDisposition = CREATE_ALWAYS;
    7.78 +    }
    7.79 +}
    7.80 +
    7.81 +static voidpf win32_build_iowin(HANDLE hFile)
    7.82 +{
    7.83 +    voidpf ret=NULL;
    7.84 +
    7.85 +    if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
    7.86 +    {
    7.87 +        WIN32FILE_IOWIN w32fiow;
    7.88 +        w32fiow.hf = hFile;
    7.89 +        w32fiow.error = 0;
    7.90 +        ret = malloc(sizeof(WIN32FILE_IOWIN));
    7.91 +
    7.92 +        if (ret==NULL)
    7.93 +            CloseHandle(hFile);
    7.94 +        else
    7.95 +            *((WIN32FILE_IOWIN*)ret) = w32fiow;
    7.96 +    }
    7.97 +    return ret;
    7.98 +}
    7.99 +
   7.100 +voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode)
   7.101 +{
   7.102 +    const char* mode_fopen = NULL;
   7.103 +    DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
   7.104 +    HANDLE hFile = NULL;
   7.105 +
   7.106 +    win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
   7.107 +
   7.108 +#ifdef IOWIN32_USING_WINRT_API
   7.109 +#ifdef UNICODE
   7.110 +    if ((filename!=NULL) && (dwDesiredAccess != 0))
   7.111 +        hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
   7.112 +#else
   7.113 +    if ((filename!=NULL) && (dwDesiredAccess != 0))
   7.114 +    {
   7.115 +        WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
   7.116 +        MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200);
   7.117 +        hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
   7.118 +    }
   7.119 +#endif
   7.120 +#else
   7.121 +    if ((filename!=NULL) && (dwDesiredAccess != 0))
   7.122 +        hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
   7.123 +#endif
   7.124 +
   7.125 +    return win32_build_iowin(hFile);
   7.126 +}
   7.127 +
   7.128 +
   7.129 +voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode)
   7.130 +{
   7.131 +    const char* mode_fopen = NULL;
   7.132 +    DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
   7.133 +    HANDLE hFile = NULL;
   7.134 +
   7.135 +    win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
   7.136 +
   7.137 +#ifdef IOWIN32_USING_WINRT_API
   7.138 +    if ((filename!=NULL) && (dwDesiredAccess != 0))
   7.139 +    {
   7.140 +        WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
   7.141 +        MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200);
   7.142 +        hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
   7.143 +    }
   7.144 +#else
   7.145 +    if ((filename!=NULL) && (dwDesiredAccess != 0))
   7.146 +        hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
   7.147 +#endif
   7.148 +
   7.149 +    return win32_build_iowin(hFile);
   7.150 +}
   7.151 +
   7.152 +
   7.153 +voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
   7.154 +{
   7.155 +    const char* mode_fopen = NULL;
   7.156 +    DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
   7.157 +    HANDLE hFile = NULL;
   7.158 +
   7.159 +    win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
   7.160 +
   7.161 +#ifdef IOWIN32_USING_WINRT_API
   7.162 +    if ((filename!=NULL) && (dwDesiredAccess != 0))
   7.163 +        hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition,NULL);
   7.164 +#else
   7.165 +    if ((filename!=NULL) && (dwDesiredAccess != 0))
   7.166 +        hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
   7.167 +#endif
   7.168 +
   7.169 +    return win32_build_iowin(hFile);
   7.170 +}
   7.171 +
   7.172 +
   7.173 +voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode)
   7.174 +{
   7.175 +    const char* mode_fopen = NULL;
   7.176 +    DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
   7.177 +    HANDLE hFile = NULL;
   7.178 +
   7.179 +    win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
   7.180 +
   7.181 +#ifdef IOWIN32_USING_WINRT_API
   7.182 +#ifdef UNICODE
   7.183 +    if ((filename!=NULL) && (dwDesiredAccess != 0))
   7.184 +        hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
   7.185 +#else
   7.186 +    if ((filename!=NULL) && (dwDesiredAccess != 0))
   7.187 +    {
   7.188 +        WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
   7.189 +        MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200);
   7.190 +        hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
   7.191 +    }
   7.192 +#endif
   7.193 +#else
   7.194 +    if ((filename!=NULL) && (dwDesiredAccess != 0))
   7.195 +        hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
   7.196 +#endif
   7.197 +
   7.198 +    return win32_build_iowin(hFile);
   7.199 +}
   7.200 +
   7.201 +
   7.202 +uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
   7.203 +{
   7.204 +    uLong ret=0;
   7.205 +    HANDLE hFile = NULL;
   7.206 +    if (stream!=NULL)
   7.207 +        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
   7.208 +
   7.209 +    if (hFile != NULL)
   7.210 +    {
   7.211 +        if (!ReadFile(hFile, buf, size, &ret, NULL))
   7.212 +        {
   7.213 +            DWORD dwErr = GetLastError();
   7.214 +            if (dwErr == ERROR_HANDLE_EOF)
   7.215 +                dwErr = 0;
   7.216 +            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
   7.217 +        }
   7.218 +    }
   7.219 +
   7.220 +    return ret;
   7.221 +}
   7.222 +
   7.223 +
   7.224 +uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
   7.225 +{
   7.226 +    uLong ret=0;
   7.227 +    HANDLE hFile = NULL;
   7.228 +    if (stream!=NULL)
   7.229 +        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
   7.230 +
   7.231 +    if (hFile != NULL)
   7.232 +    {
   7.233 +        if (!WriteFile(hFile, buf, size, &ret, NULL))
   7.234 +        {
   7.235 +            DWORD dwErr = GetLastError();
   7.236 +            if (dwErr == ERROR_HANDLE_EOF)
   7.237 +                dwErr = 0;
   7.238 +            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
   7.239 +        }
   7.240 +    }
   7.241 +
   7.242 +    return ret;
   7.243 +}
   7.244 +
   7.245 +static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos,  DWORD dwMoveMethod)
   7.246 +{
   7.247 +#ifdef IOWIN32_USING_WINRT_API
   7.248 +    return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod);
   7.249 +#else
   7.250 +    LONG lHigh = pos.HighPart;
   7.251 +    DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, FILE_CURRENT);
   7.252 +    BOOL fOk = TRUE;
   7.253 +    if (dwNewPos == 0xFFFFFFFF)
   7.254 +        if (GetLastError() != NO_ERROR)
   7.255 +            fOk = FALSE;
   7.256 +    if ((newPos != NULL) && (fOk))
   7.257 +    {
   7.258 +        newPos->LowPart = dwNewPos;
   7.259 +        newPos->HighPart = lHigh;
   7.260 +    }
   7.261 +    return fOk;
   7.262 +#endif
   7.263 +}
   7.264 +
   7.265 +long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
   7.266 +{
   7.267 +    long ret=-1;
   7.268 +    HANDLE hFile = NULL;
   7.269 +    if (stream!=NULL)
   7.270 +        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
   7.271 +    if (hFile != NULL)
   7.272 +    {
   7.273 +        LARGE_INTEGER pos;
   7.274 +        pos.QuadPart = 0;
   7.275 +
   7.276 +        if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
   7.277 +        {
   7.278 +            DWORD dwErr = GetLastError();
   7.279 +            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
   7.280 +            ret = -1;
   7.281 +        }
   7.282 +        else
   7.283 +            ret=(long)pos.LowPart;
   7.284 +    }
   7.285 +    return ret;
   7.286 +}
   7.287 +
   7.288 +ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
   7.289 +{
   7.290 +    ZPOS64_T ret= (ZPOS64_T)-1;
   7.291 +    HANDLE hFile = NULL;
   7.292 +    if (stream!=NULL)
   7.293 +        hFile = ((WIN32FILE_IOWIN*)stream)->hf;
   7.294 +
   7.295 +    if (hFile)
   7.296 +    {
   7.297 +        LARGE_INTEGER pos;
   7.298 +        pos.QuadPart = 0;
   7.299 +
   7.300 +        if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
   7.301 +        {
   7.302 +            DWORD dwErr = GetLastError();
   7.303 +            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
   7.304 +            ret = (ZPOS64_T)-1;
   7.305 +        }
   7.306 +        else
   7.307 +            ret=pos.QuadPart;
   7.308 +    }
   7.309 +    return ret;
   7.310 +}
   7.311 +
   7.312 +
   7.313 +long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
   7.314 +{
   7.315 +    DWORD dwMoveMethod=0xFFFFFFFF;
   7.316 +    HANDLE hFile = NULL;
   7.317 +
   7.318 +    long ret=-1;
   7.319 +    if (stream!=NULL)
   7.320 +        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
   7.321 +    switch (origin)
   7.322 +    {
   7.323 +    case ZLIB_FILEFUNC_SEEK_CUR :
   7.324 +        dwMoveMethod = FILE_CURRENT;
   7.325 +        break;
   7.326 +    case ZLIB_FILEFUNC_SEEK_END :
   7.327 +        dwMoveMethod = FILE_END;
   7.328 +        break;
   7.329 +    case ZLIB_FILEFUNC_SEEK_SET :
   7.330 +        dwMoveMethod = FILE_BEGIN;
   7.331 +        break;
   7.332 +    default: return -1;
   7.333 +    }
   7.334 +
   7.335 +    if (hFile != NULL)
   7.336 +    {
   7.337 +        LARGE_INTEGER pos;
   7.338 +        pos.QuadPart = offset;
   7.339 +        if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod))
   7.340 +        {
   7.341 +            DWORD dwErr = GetLastError();
   7.342 +            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
   7.343 +            ret = -1;
   7.344 +        }
   7.345 +        else
   7.346 +            ret=0;
   7.347 +    }
   7.348 +    return ret;
   7.349 +}
   7.350 +
   7.351 +long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin)
   7.352 +{
   7.353 +    DWORD dwMoveMethod=0xFFFFFFFF;
   7.354 +    HANDLE hFile = NULL;
   7.355 +    long ret=-1;
   7.356 +
   7.357 +    if (stream!=NULL)
   7.358 +        hFile = ((WIN32FILE_IOWIN*)stream)->hf;
   7.359 +
   7.360 +    switch (origin)
   7.361 +    {
   7.362 +        case ZLIB_FILEFUNC_SEEK_CUR :
   7.363 +            dwMoveMethod = FILE_CURRENT;
   7.364 +            break;
   7.365 +        case ZLIB_FILEFUNC_SEEK_END :
   7.366 +            dwMoveMethod = FILE_END;
   7.367 +            break;
   7.368 +        case ZLIB_FILEFUNC_SEEK_SET :
   7.369 +            dwMoveMethod = FILE_BEGIN;
   7.370 +            break;
   7.371 +        default: return -1;
   7.372 +    }
   7.373 +
   7.374 +    if (hFile)
   7.375 +    {
   7.376 +        LARGE_INTEGER pos;
   7.377 +        pos.QuadPart = offset;
   7.378 +        if (!MySetFilePointerEx(hFile, pos, NULL, FILE_CURRENT))
   7.379 +        {
   7.380 +            DWORD dwErr = GetLastError();
   7.381 +            ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
   7.382 +            ret = -1;
   7.383 +        }
   7.384 +        else
   7.385 +            ret=0;
   7.386 +    }
   7.387 +    return ret;
   7.388 +}
   7.389 +
   7.390 +int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream)
   7.391 +{
   7.392 +    int ret=-1;
   7.393 +
   7.394 +    if (stream!=NULL)
   7.395 +    {
   7.396 +        HANDLE hFile;
   7.397 +        hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
   7.398 +        if (hFile != NULL)
   7.399 +        {
   7.400 +            CloseHandle(hFile);
   7.401 +            ret=0;
   7.402 +        }
   7.403 +        free(stream);
   7.404 +    }
   7.405 +    return ret;
   7.406 +}
   7.407 +
   7.408 +int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream)
   7.409 +{
   7.410 +    int ret=-1;
   7.411 +    if (stream!=NULL)
   7.412 +    {
   7.413 +        ret = ((WIN32FILE_IOWIN*)stream) -> error;
   7.414 +    }
   7.415 +    return ret;
   7.416 +}
   7.417 +
   7.418 +void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
   7.419 +{
   7.420 +    pzlib_filefunc_def->zopen_file = win32_open_file_func;
   7.421 +    pzlib_filefunc_def->zread_file = win32_read_file_func;
   7.422 +    pzlib_filefunc_def->zwrite_file = win32_write_file_func;
   7.423 +    pzlib_filefunc_def->ztell_file = win32_tell_file_func;
   7.424 +    pzlib_filefunc_def->zseek_file = win32_seek_file_func;
   7.425 +    pzlib_filefunc_def->zclose_file = win32_close_file_func;
   7.426 +    pzlib_filefunc_def->zerror_file = win32_error_file_func;
   7.427 +    pzlib_filefunc_def->opaque = NULL;
   7.428 +}
   7.429 +
   7.430 +void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def)
   7.431 +{
   7.432 +    pzlib_filefunc_def->zopen64_file = win32_open64_file_func;
   7.433 +    pzlib_filefunc_def->zread_file = win32_read_file_func;
   7.434 +    pzlib_filefunc_def->zwrite_file = win32_write_file_func;
   7.435 +    pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
   7.436 +    pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
   7.437 +    pzlib_filefunc_def->zclose_file = win32_close_file_func;
   7.438 +    pzlib_filefunc_def->zerror_file = win32_error_file_func;
   7.439 +    pzlib_filefunc_def->opaque = NULL;
   7.440 +}
   7.441 +
   7.442 +
   7.443 +void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def)
   7.444 +{
   7.445 +    pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA;
   7.446 +    pzlib_filefunc_def->zread_file = win32_read_file_func;
   7.447 +    pzlib_filefunc_def->zwrite_file = win32_write_file_func;
   7.448 +    pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
   7.449 +    pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
   7.450 +    pzlib_filefunc_def->zclose_file = win32_close_file_func;
   7.451 +    pzlib_filefunc_def->zerror_file = win32_error_file_func;
   7.452 +    pzlib_filefunc_def->opaque = NULL;
   7.453 +}
   7.454 +
   7.455 +
   7.456 +void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def)
   7.457 +{
   7.458 +    pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
   7.459 +    pzlib_filefunc_def->zread_file = win32_read_file_func;
   7.460 +    pzlib_filefunc_def->zwrite_file = win32_write_file_func;
   7.461 +    pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
   7.462 +    pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
   7.463 +    pzlib_filefunc_def->zclose_file = win32_close_file_func;
   7.464 +    pzlib_filefunc_def->zerror_file = win32_error_file_func;
   7.465 +    pzlib_filefunc_def->opaque = NULL;
   7.466 +}
   7.467 +
   7.468 +#else
   7.469 +int __minizip_iowin32_c_avoid_empty_unit_warning;
   7.470 +#endif	/* WIN32 */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/zipcat/src/minizip/iowin32.h	Mon Nov 04 06:46:17 2013 +0200
     8.3 @@ -0,0 +1,28 @@
     8.4 +/* iowin32.h -- IO base function header for compress/uncompress .zip
     8.5 +     Version 1.1, February 14h, 2010
     8.6 +     part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
     8.7 +
     8.8 +         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
     8.9 +
    8.10 +         Modifications for Zip64 support
    8.11 +         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
    8.12 +
    8.13 +         For more info read MiniZip_info.txt
    8.14 +
    8.15 +*/
    8.16 +
    8.17 +#include <windows.h>
    8.18 +
    8.19 +
    8.20 +#ifdef __cplusplus
    8.21 +extern "C" {
    8.22 +#endif
    8.23 +
    8.24 +void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
    8.25 +void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def));
    8.26 +void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def));
    8.27 +void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def));
    8.28 +
    8.29 +#ifdef __cplusplus
    8.30 +}
    8.31 +#endif
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/zipcat/src/minizip/mztools.c	Mon Nov 04 06:46:17 2013 +0200
     9.3 @@ -0,0 +1,291 @@
     9.4 +/*
     9.5 +  Additional tools for Minizip
     9.6 +  Code: Xavier Roche '2004
     9.7 +  License: Same as ZLIB (www.gzip.org)
     9.8 +*/
     9.9 +
    9.10 +/* Code */
    9.11 +#include <stdio.h>
    9.12 +#include <stdlib.h>
    9.13 +#include <string.h>
    9.14 +#include "zlib.h"
    9.15 +#include "unzip.h"
    9.16 +
    9.17 +#define READ_8(adr)  ((unsigned char)*(adr))
    9.18 +#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
    9.19 +#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
    9.20 +
    9.21 +#define WRITE_8(buff, n) do { \
    9.22 +  *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
    9.23 +} while(0)
    9.24 +#define WRITE_16(buff, n) do { \
    9.25 +  WRITE_8((unsigned char*)(buff), n); \
    9.26 +  WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
    9.27 +} while(0)
    9.28 +#define WRITE_32(buff, n) do { \
    9.29 +  WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
    9.30 +  WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
    9.31 +} while(0)
    9.32 +
    9.33 +extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
    9.34 +const char* file;
    9.35 +const char* fileOut;
    9.36 +const char* fileOutTmp;
    9.37 +uLong* nRecovered;
    9.38 +uLong* bytesRecovered;
    9.39 +{
    9.40 +  int err = Z_OK;
    9.41 +  FILE* fpZip = fopen(file, "rb");
    9.42 +  FILE* fpOut = fopen(fileOut, "wb");
    9.43 +  FILE* fpOutCD = fopen(fileOutTmp, "wb");
    9.44 +  if (fpZip != NULL &&  fpOut != NULL) {
    9.45 +    int entries = 0;
    9.46 +    uLong totalBytes = 0;
    9.47 +    char header[30];
    9.48 +    char filename[1024];
    9.49 +    char extra[1024];
    9.50 +    int offset = 0;
    9.51 +    int offsetCD = 0;
    9.52 +    while ( fread(header, 1, 30, fpZip) == 30 ) {
    9.53 +      int currentOffset = offset;
    9.54 +
    9.55 +      /* File entry */
    9.56 +      if (READ_32(header) == 0x04034b50) {
    9.57 +        unsigned int version = READ_16(header + 4);
    9.58 +        unsigned int gpflag = READ_16(header + 6);
    9.59 +        unsigned int method = READ_16(header + 8);
    9.60 +        unsigned int filetime = READ_16(header + 10);
    9.61 +        unsigned int filedate = READ_16(header + 12);
    9.62 +        unsigned int crc = READ_32(header + 14); /* crc */
    9.63 +        unsigned int cpsize = READ_32(header + 18); /* compressed size */
    9.64 +        unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
    9.65 +        unsigned int fnsize = READ_16(header + 26); /* file name length */
    9.66 +        unsigned int extsize = READ_16(header + 28); /* extra field length */
    9.67 +        filename[0] = extra[0] = '\0';
    9.68 +
    9.69 +        /* Header */
    9.70 +        if (fwrite(header, 1, 30, fpOut) == 30) {
    9.71 +          offset += 30;
    9.72 +        } else {
    9.73 +          err = Z_ERRNO;
    9.74 +          break;
    9.75 +        }
    9.76 +
    9.77 +        /* Filename */
    9.78 +        if (fnsize > 0) {
    9.79 +          if (fnsize < sizeof(filename)) {
    9.80 +            if (fread(filename, 1, fnsize, fpZip) == fnsize) {
    9.81 +                if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
    9.82 +                offset += fnsize;
    9.83 +              } else {
    9.84 +                err = Z_ERRNO;
    9.85 +                break;
    9.86 +              }
    9.87 +            } else {
    9.88 +              err = Z_ERRNO;
    9.89 +              break;
    9.90 +            }
    9.91 +          } else {
    9.92 +            err = Z_ERRNO;
    9.93 +            break;
    9.94 +          }
    9.95 +        } else {
    9.96 +          err = Z_STREAM_ERROR;
    9.97 +          break;
    9.98 +        }
    9.99 +
   9.100 +        /* Extra field */
   9.101 +        if (extsize > 0) {
   9.102 +          if (extsize < sizeof(extra)) {
   9.103 +            if (fread(extra, 1, extsize, fpZip) == extsize) {
   9.104 +              if (fwrite(extra, 1, extsize, fpOut) == extsize) {
   9.105 +                offset += extsize;
   9.106 +                } else {
   9.107 +                err = Z_ERRNO;
   9.108 +                break;
   9.109 +              }
   9.110 +            } else {
   9.111 +              err = Z_ERRNO;
   9.112 +              break;
   9.113 +            }
   9.114 +          } else {
   9.115 +            err = Z_ERRNO;
   9.116 +            break;
   9.117 +          }
   9.118 +        }
   9.119 +
   9.120 +        /* Data */
   9.121 +        {
   9.122 +          int dataSize = cpsize;
   9.123 +          if (dataSize == 0) {
   9.124 +            dataSize = uncpsize;
   9.125 +          }
   9.126 +          if (dataSize > 0) {
   9.127 +            char* data = malloc(dataSize);
   9.128 +            if (data != NULL) {
   9.129 +              if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
   9.130 +                if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
   9.131 +                  offset += dataSize;
   9.132 +                  totalBytes += dataSize;
   9.133 +                } else {
   9.134 +                  err = Z_ERRNO;
   9.135 +                }
   9.136 +              } else {
   9.137 +                err = Z_ERRNO;
   9.138 +              }
   9.139 +              free(data);
   9.140 +              if (err != Z_OK) {
   9.141 +                break;
   9.142 +              }
   9.143 +            } else {
   9.144 +              err = Z_MEM_ERROR;
   9.145 +              break;
   9.146 +            }
   9.147 +          }
   9.148 +        }
   9.149 +
   9.150 +        /* Central directory entry */
   9.151 +        {
   9.152 +          char header[46];
   9.153 +          char* comment = "";
   9.154 +          int comsize = (int) strlen(comment);
   9.155 +          WRITE_32(header, 0x02014b50);
   9.156 +          WRITE_16(header + 4, version);
   9.157 +          WRITE_16(header + 6, version);
   9.158 +          WRITE_16(header + 8, gpflag);
   9.159 +          WRITE_16(header + 10, method);
   9.160 +          WRITE_16(header + 12, filetime);
   9.161 +          WRITE_16(header + 14, filedate);
   9.162 +          WRITE_32(header + 16, crc);
   9.163 +          WRITE_32(header + 20, cpsize);
   9.164 +          WRITE_32(header + 24, uncpsize);
   9.165 +          WRITE_16(header + 28, fnsize);
   9.166 +          WRITE_16(header + 30, extsize);
   9.167 +          WRITE_16(header + 32, comsize);
   9.168 +          WRITE_16(header + 34, 0);     /* disk # */
   9.169 +          WRITE_16(header + 36, 0);     /* int attrb */
   9.170 +          WRITE_32(header + 38, 0);     /* ext attrb */
   9.171 +          WRITE_32(header + 42, currentOffset);
   9.172 +          /* Header */
   9.173 +          if (fwrite(header, 1, 46, fpOutCD) == 46) {
   9.174 +            offsetCD += 46;
   9.175 +
   9.176 +            /* Filename */
   9.177 +            if (fnsize > 0) {
   9.178 +              if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
   9.179 +                offsetCD += fnsize;
   9.180 +              } else {
   9.181 +                err = Z_ERRNO;
   9.182 +                break;
   9.183 +              }
   9.184 +            } else {
   9.185 +              err = Z_STREAM_ERROR;
   9.186 +              break;
   9.187 +            }
   9.188 +
   9.189 +            /* Extra field */
   9.190 +            if (extsize > 0) {
   9.191 +              if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
   9.192 +                offsetCD += extsize;
   9.193 +              } else {
   9.194 +                err = Z_ERRNO;
   9.195 +                break;
   9.196 +              }
   9.197 +            }
   9.198 +
   9.199 +            /* Comment field */
   9.200 +            if (comsize > 0) {
   9.201 +              if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
   9.202 +                offsetCD += comsize;
   9.203 +              } else {
   9.204 +                err = Z_ERRNO;
   9.205 +                break;
   9.206 +              }
   9.207 +            }
   9.208 +
   9.209 +
   9.210 +          } else {
   9.211 +            err = Z_ERRNO;
   9.212 +            break;
   9.213 +          }
   9.214 +        }
   9.215 +
   9.216 +        /* Success */
   9.217 +        entries++;
   9.218 +
   9.219 +      } else {
   9.220 +        break;
   9.221 +      }
   9.222 +    }
   9.223 +
   9.224 +    /* Final central directory  */
   9.225 +    {
   9.226 +      int entriesZip = entries;
   9.227 +      char header[22];
   9.228 +      char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
   9.229 +      int comsize = (int) strlen(comment);
   9.230 +      if (entriesZip > 0xffff) {
   9.231 +        entriesZip = 0xffff;
   9.232 +      }
   9.233 +      WRITE_32(header, 0x06054b50);
   9.234 +      WRITE_16(header + 4, 0);    /* disk # */
   9.235 +      WRITE_16(header + 6, 0);    /* disk # */
   9.236 +      WRITE_16(header + 8, entriesZip);   /* hack */
   9.237 +      WRITE_16(header + 10, entriesZip);  /* hack */
   9.238 +      WRITE_32(header + 12, offsetCD);    /* size of CD */
   9.239 +      WRITE_32(header + 16, offset);      /* offset to CD */
   9.240 +      WRITE_16(header + 20, comsize);     /* comment */
   9.241 +
   9.242 +      /* Header */
   9.243 +      if (fwrite(header, 1, 22, fpOutCD) == 22) {
   9.244 +
   9.245 +        /* Comment field */
   9.246 +        if (comsize > 0) {
   9.247 +          if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
   9.248 +            err = Z_ERRNO;
   9.249 +          }
   9.250 +        }
   9.251 +
   9.252 +      } else {
   9.253 +        err = Z_ERRNO;
   9.254 +      }
   9.255 +    }
   9.256 +
   9.257 +    /* Final merge (file + central directory) */
   9.258 +    fclose(fpOutCD);
   9.259 +    if (err == Z_OK) {
   9.260 +      fpOutCD = fopen(fileOutTmp, "rb");
   9.261 +      if (fpOutCD != NULL) {
   9.262 +        int nRead;
   9.263 +        char buffer[8192];
   9.264 +        while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
   9.265 +          if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
   9.266 +            err = Z_ERRNO;
   9.267 +            break;
   9.268 +          }
   9.269 +        }
   9.270 +        fclose(fpOutCD);
   9.271 +      }
   9.272 +    }
   9.273 +
   9.274 +    /* Close */
   9.275 +    fclose(fpZip);
   9.276 +    fclose(fpOut);
   9.277 +
   9.278 +    /* Wipe temporary file */
   9.279 +    (void)remove(fileOutTmp);
   9.280 +
   9.281 +    /* Number of recovered entries */
   9.282 +    if (err == Z_OK) {
   9.283 +      if (nRecovered != NULL) {
   9.284 +        *nRecovered = entries;
   9.285 +      }
   9.286 +      if (bytesRecovered != NULL) {
   9.287 +        *bytesRecovered = totalBytes;
   9.288 +      }
   9.289 +    }
   9.290 +  } else {
   9.291 +    err = Z_STREAM_ERROR;
   9.292 +  }
   9.293 +  return err;
   9.294 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/zipcat/src/minizip/mztools.h	Mon Nov 04 06:46:17 2013 +0200
    10.3 @@ -0,0 +1,37 @@
    10.4 +/*
    10.5 +  Additional tools for Minizip
    10.6 +  Code: Xavier Roche '2004
    10.7 +  License: Same as ZLIB (www.gzip.org)
    10.8 +*/
    10.9 +
   10.10 +#ifndef _zip_tools_H
   10.11 +#define _zip_tools_H
   10.12 +
   10.13 +#ifdef __cplusplus
   10.14 +extern "C" {
   10.15 +#endif
   10.16 +
   10.17 +#ifndef _ZLIB_H
   10.18 +#include "zlib.h"
   10.19 +#endif
   10.20 +
   10.21 +#include "unzip.h"
   10.22 +
   10.23 +/* Repair a ZIP file (missing central directory)
   10.24 +   file: file to recover
   10.25 +   fileOut: output file after recovery
   10.26 +   fileOutTmp: temporary file name used for recovery
   10.27 +*/
   10.28 +extern int ZEXPORT unzRepair(const char* file,
   10.29 +                             const char* fileOut,
   10.30 +                             const char* fileOutTmp,
   10.31 +                             uLong* nRecovered,
   10.32 +                             uLong* bytesRecovered);
   10.33 +
   10.34 +
   10.35 +#ifdef __cplusplus
   10.36 +}
   10.37 +#endif
   10.38 +
   10.39 +
   10.40 +#endif
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/zipcat/src/minizip/unzip.c	Mon Nov 04 06:46:17 2013 +0200
    11.3 @@ -0,0 +1,2125 @@
    11.4 +/* unzip.c -- IO for uncompress .zip files using zlib
    11.5 +   Version 1.1, February 14h, 2010
    11.6 +   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
    11.7 +
    11.8 +         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
    11.9 +
   11.10 +         Modifications of Unzip for Zip64
   11.11 +         Copyright (C) 2007-2008 Even Rouault
   11.12 +
   11.13 +         Modifications for Zip64 support on both zip and unzip
   11.14 +         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
   11.15 +
   11.16 +         For more info read MiniZip_info.txt
   11.17 +
   11.18 +
   11.19 +  ------------------------------------------------------------------------------------
   11.20 +  Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
   11.21 +  compatibility with older software. The following is from the original crypt.c.
   11.22 +  Code woven in by Terry Thorsen 1/2003.
   11.23 +
   11.24 +  Copyright (c) 1990-2000 Info-ZIP.  All rights reserved.
   11.25 +
   11.26 +  See the accompanying file LICENSE, version 2000-Apr-09 or later
   11.27 +  (the contents of which are also included in zip.h) for terms of use.
   11.28 +  If, for some reason, all these files are missing, the Info-ZIP license
   11.29 +  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
   11.30 +
   11.31 +        crypt.c (full version) by Info-ZIP.      Last revised:  [see crypt.h]
   11.32 +
   11.33 +  The encryption/decryption parts of this source code (as opposed to the
   11.34 +  non-echoing password parts) were originally written in Europe.  The
   11.35 +  whole source package can be freely distributed, including from the USA.
   11.36 +  (Prior to January 2000, re-export from the US was a violation of US law.)
   11.37 +
   11.38 +        This encryption code is a direct transcription of the algorithm from
   11.39 +  Roger Schlafly, described by Phil Katz in the file appnote.txt.  This
   11.40 +  file (appnote.txt) is distributed with the PKZIP program (even in the
   11.41 +  version without encryption capabilities).
   11.42 +
   11.43 +        ------------------------------------------------------------------------------------
   11.44 +
   11.45 +        Changes in unzip.c
   11.46 +
   11.47 +        2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos
   11.48 +  2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz*
   11.49 +  2007-2008 - Even Rouault - Remove old C style function prototypes
   11.50 +  2007-2008 - Even Rouault - Add unzip support for ZIP64
   11.51 +
   11.52 +        Copyright (C) 2007-2008 Even Rouault
   11.53 +
   11.54 +
   11.55 +        Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again).
   11.56 +  Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
   11.57 +                                should only read the compressed/uncompressed size from the Zip64 format if
   11.58 +                                the size from normal header was 0xFFFFFFFF
   11.59 +  Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
   11.60 +        Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
   11.61 +                                Patch created by Daniel Borca
   11.62 +
   11.63 +  Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
   11.64 +
   11.65 +  Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
   11.66 +
   11.67 +*/
   11.68 +
   11.69 +
   11.70 +#include <stdio.h>
   11.71 +#include <stdlib.h>
   11.72 +#include <string.h>
   11.73 +
   11.74 +#ifndef NOUNCRYPT
   11.75 +        #define NOUNCRYPT
   11.76 +#endif
   11.77 +
   11.78 +#include "zlib.h"
   11.79 +#include "unzip.h"
   11.80 +
   11.81 +#ifdef STDC
   11.82 +#  include <stddef.h>
   11.83 +#  include <string.h>
   11.84 +#  include <stdlib.h>
   11.85 +#endif
   11.86 +#ifdef NO_ERRNO_H
   11.87 +    extern int errno;
   11.88 +#else
   11.89 +#   include <errno.h>
   11.90 +#endif
   11.91 +
   11.92 +
   11.93 +#ifndef local
   11.94 +#  define local static
   11.95 +#endif
   11.96 +/* compile with -Dlocal if your debugger can't find static symbols */
   11.97 +
   11.98 +
   11.99 +#ifndef CASESENSITIVITYDEFAULT_NO
  11.100 +#  if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
  11.101 +#    define CASESENSITIVITYDEFAULT_NO
  11.102 +#  endif
  11.103 +#endif
  11.104 +
  11.105 +
  11.106 +#ifndef UNZ_BUFSIZE
  11.107 +#define UNZ_BUFSIZE (16384)
  11.108 +#endif
  11.109 +
  11.110 +#ifndef UNZ_MAXFILENAMEINZIP
  11.111 +#define UNZ_MAXFILENAMEINZIP (256)
  11.112 +#endif
  11.113 +
  11.114 +#ifndef ALLOC
  11.115 +# define ALLOC(size) (malloc(size))
  11.116 +#endif
  11.117 +#ifndef TRYFREE
  11.118 +# define TRYFREE(p) {if (p) free(p);}
  11.119 +#endif
  11.120 +
  11.121 +#define SIZECENTRALDIRITEM (0x2e)
  11.122 +#define SIZEZIPLOCALHEADER (0x1e)
  11.123 +
  11.124 +
  11.125 +const char unz_copyright[] =
  11.126 +   " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
  11.127 +
  11.128 +/* unz_file_info_interntal contain internal info about a file in zipfile*/
  11.129 +typedef struct unz_file_info64_internal_s
  11.130 +{
  11.131 +    ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */
  11.132 +} unz_file_info64_internal;
  11.133 +
  11.134 +
  11.135 +/* file_in_zip_read_info_s contain internal information about a file in zipfile,
  11.136 +    when reading and decompress it */
  11.137 +typedef struct
  11.138 +{
  11.139 +    char  *read_buffer;         /* internal buffer for compressed data */
  11.140 +    z_stream stream;            /* zLib stream structure for inflate */
  11.141 +
  11.142 +#ifdef HAVE_BZIP2
  11.143 +    bz_stream bstream;          /* bzLib stream structure for bziped */
  11.144 +#endif
  11.145 +
  11.146 +    ZPOS64_T pos_in_zipfile;       /* position in byte on the zipfile, for fseek*/
  11.147 +    uLong stream_initialised;   /* flag set if stream structure is initialised*/
  11.148 +
  11.149 +    ZPOS64_T offset_local_extrafield;/* offset of the local extra field */
  11.150 +    uInt  size_local_extrafield;/* size of the local extra field */
  11.151 +    ZPOS64_T pos_local_extrafield;   /* position in the local extra field in read*/
  11.152 +    ZPOS64_T total_out_64;
  11.153 +
  11.154 +    uLong crc32;                /* crc32 of all data uncompressed */
  11.155 +    uLong crc32_wait;           /* crc32 we must obtain after decompress all */
  11.156 +    ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
  11.157 +    ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
  11.158 +    zlib_filefunc64_32_def z_filefunc;
  11.159 +    voidpf filestream;        /* io structore of the zipfile */
  11.160 +    uLong compression_method;   /* compression method (0==store) */
  11.161 +    ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
  11.162 +    int   raw;
  11.163 +} file_in_zip64_read_info_s;
  11.164 +
  11.165 +
  11.166 +/* unz64_s contain internal information about the zipfile
  11.167 +*/
  11.168 +typedef struct
  11.169 +{
  11.170 +    zlib_filefunc64_32_def z_filefunc;
  11.171 +    int is64bitOpenFunction;
  11.172 +    voidpf filestream;        /* io structore of the zipfile */
  11.173 +    unz_global_info64 gi;       /* public global information */
  11.174 +    ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
  11.175 +    ZPOS64_T num_file;             /* number of the current file in the zipfile*/
  11.176 +    ZPOS64_T pos_in_central_dir;   /* pos of the current file in the central dir*/
  11.177 +    ZPOS64_T current_file_ok;      /* flag about the usability of the current file*/
  11.178 +    ZPOS64_T central_pos;          /* position of the beginning of the central dir*/
  11.179 +
  11.180 +    ZPOS64_T size_central_dir;     /* size of the central directory  */
  11.181 +    ZPOS64_T offset_central_dir;   /* offset of start of central directory with
  11.182 +                                   respect to the starting disk number */
  11.183 +
  11.184 +    unz_file_info64 cur_file_info; /* public info about the current file in zip*/
  11.185 +    unz_file_info64_internal cur_file_info_internal; /* private info about it*/
  11.186 +    file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current
  11.187 +                                        file if we are decompressing it */
  11.188 +    int encrypted;
  11.189 +
  11.190 +    int isZip64;
  11.191 +
  11.192 +#    ifndef NOUNCRYPT
  11.193 +    unsigned long keys[3];     /* keys defining the pseudo-random sequence */
  11.194 +    const z_crc_t* pcrc_32_tab;
  11.195 +#    endif
  11.196 +} unz64_s;
  11.197 +
  11.198 +
  11.199 +#ifndef NOUNCRYPT
  11.200 +#include "crypt.h"
  11.201 +#endif
  11.202 +
  11.203 +/* ===========================================================================
  11.204 +     Read a byte from a gz_stream; update next_in and avail_in. Return EOF
  11.205 +   for end of file.
  11.206 +   IN assertion: the stream s has been sucessfully opened for reading.
  11.207 +*/
  11.208 +
  11.209 +
  11.210 +local int unz64local_getByte OF((
  11.211 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
  11.212 +    voidpf filestream,
  11.213 +    int *pi));
  11.214 +
  11.215 +local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)
  11.216 +{
  11.217 +    unsigned char c;
  11.218 +    int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
  11.219 +    if (err==1)
  11.220 +    {
  11.221 +        *pi = (int)c;
  11.222 +        return UNZ_OK;
  11.223 +    }
  11.224 +    else
  11.225 +    {
  11.226 +        if (ZERROR64(*pzlib_filefunc_def,filestream))
  11.227 +            return UNZ_ERRNO;
  11.228 +        else
  11.229 +            return UNZ_EOF;
  11.230 +    }
  11.231 +}
  11.232 +
  11.233 +
  11.234 +/* ===========================================================================
  11.235 +   Reads a long in LSB order from the given gz_stream. Sets
  11.236 +*/
  11.237 +local int unz64local_getShort OF((
  11.238 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
  11.239 +    voidpf filestream,
  11.240 +    uLong *pX));
  11.241 +
  11.242 +local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
  11.243 +                             voidpf filestream,
  11.244 +                             uLong *pX)
  11.245 +{
  11.246 +    uLong x ;
  11.247 +    int i = 0;
  11.248 +    int err;
  11.249 +
  11.250 +    err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.251 +    x = (uLong)i;
  11.252 +
  11.253 +    if (err==UNZ_OK)
  11.254 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.255 +    x |= ((uLong)i)<<8;
  11.256 +
  11.257 +    if (err==UNZ_OK)
  11.258 +        *pX = x;
  11.259 +    else
  11.260 +        *pX = 0;
  11.261 +    return err;
  11.262 +}
  11.263 +
  11.264 +local int unz64local_getLong OF((
  11.265 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
  11.266 +    voidpf filestream,
  11.267 +    uLong *pX));
  11.268 +
  11.269 +local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
  11.270 +                            voidpf filestream,
  11.271 +                            uLong *pX)
  11.272 +{
  11.273 +    uLong x ;
  11.274 +    int i = 0;
  11.275 +    int err;
  11.276 +
  11.277 +    err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.278 +    x = (uLong)i;
  11.279 +
  11.280 +    if (err==UNZ_OK)
  11.281 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.282 +    x |= ((uLong)i)<<8;
  11.283 +
  11.284 +    if (err==UNZ_OK)
  11.285 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.286 +    x |= ((uLong)i)<<16;
  11.287 +
  11.288 +    if (err==UNZ_OK)
  11.289 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.290 +    x += ((uLong)i)<<24;
  11.291 +
  11.292 +    if (err==UNZ_OK)
  11.293 +        *pX = x;
  11.294 +    else
  11.295 +        *pX = 0;
  11.296 +    return err;
  11.297 +}
  11.298 +
  11.299 +local int unz64local_getLong64 OF((
  11.300 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
  11.301 +    voidpf filestream,
  11.302 +    ZPOS64_T *pX));
  11.303 +
  11.304 +
  11.305 +local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
  11.306 +                            voidpf filestream,
  11.307 +                            ZPOS64_T *pX)
  11.308 +{
  11.309 +    ZPOS64_T x ;
  11.310 +    int i = 0;
  11.311 +    int err;
  11.312 +
  11.313 +    err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.314 +    x = (ZPOS64_T)i;
  11.315 +
  11.316 +    if (err==UNZ_OK)
  11.317 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.318 +    x |= ((ZPOS64_T)i)<<8;
  11.319 +
  11.320 +    if (err==UNZ_OK)
  11.321 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.322 +    x |= ((ZPOS64_T)i)<<16;
  11.323 +
  11.324 +    if (err==UNZ_OK)
  11.325 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.326 +    x |= ((ZPOS64_T)i)<<24;
  11.327 +
  11.328 +    if (err==UNZ_OK)
  11.329 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.330 +    x |= ((ZPOS64_T)i)<<32;
  11.331 +
  11.332 +    if (err==UNZ_OK)
  11.333 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.334 +    x |= ((ZPOS64_T)i)<<40;
  11.335 +
  11.336 +    if (err==UNZ_OK)
  11.337 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.338 +    x |= ((ZPOS64_T)i)<<48;
  11.339 +
  11.340 +    if (err==UNZ_OK)
  11.341 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  11.342 +    x |= ((ZPOS64_T)i)<<56;
  11.343 +
  11.344 +    if (err==UNZ_OK)
  11.345 +        *pX = x;
  11.346 +    else
  11.347 +        *pX = 0;
  11.348 +    return err;
  11.349 +}
  11.350 +
  11.351 +/* My own strcmpi / strcasecmp */
  11.352 +local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
  11.353 +{
  11.354 +    for (;;)
  11.355 +    {
  11.356 +        char c1=*(fileName1++);
  11.357 +        char c2=*(fileName2++);
  11.358 +        if ((c1>='a') && (c1<='z'))
  11.359 +            c1 -= 0x20;
  11.360 +        if ((c2>='a') && (c2<='z'))
  11.361 +            c2 -= 0x20;
  11.362 +        if (c1=='\0')
  11.363 +            return ((c2=='\0') ? 0 : -1);
  11.364 +        if (c2=='\0')
  11.365 +            return 1;
  11.366 +        if (c1<c2)
  11.367 +            return -1;
  11.368 +        if (c1>c2)
  11.369 +            return 1;
  11.370 +    }
  11.371 +}
  11.372 +
  11.373 +
  11.374 +#ifdef  CASESENSITIVITYDEFAULT_NO
  11.375 +#define CASESENSITIVITYDEFAULTVALUE 2
  11.376 +#else
  11.377 +#define CASESENSITIVITYDEFAULTVALUE 1
  11.378 +#endif
  11.379 +
  11.380 +#ifndef STRCMPCASENOSENTIVEFUNCTION
  11.381 +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
  11.382 +#endif
  11.383 +
  11.384 +/*
  11.385 +   Compare two filename (fileName1,fileName2).
  11.386 +   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
  11.387 +   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
  11.388 +                                                                or strcasecmp)
  11.389 +   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
  11.390 +        (like 1 on Unix, 2 on Windows)
  11.391 +
  11.392 +*/
  11.393 +extern int ZEXPORT unzStringFileNameCompare (const char*  fileName1,
  11.394 +                                                 const char*  fileName2,
  11.395 +                                                 int iCaseSensitivity)
  11.396 +
  11.397 +{
  11.398 +    if (iCaseSensitivity==0)
  11.399 +        iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
  11.400 +
  11.401 +    if (iCaseSensitivity==1)
  11.402 +        return strcmp(fileName1,fileName2);
  11.403 +
  11.404 +    return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
  11.405 +}
  11.406 +
  11.407 +#ifndef BUFREADCOMMENT
  11.408 +#define BUFREADCOMMENT (0x400)
  11.409 +#endif
  11.410 +
  11.411 +/*
  11.412 +  Locate the Central directory of a zipfile (at the end, just before
  11.413 +    the global comment)
  11.414 +*/
  11.415 +local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
  11.416 +local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
  11.417 +{
  11.418 +    unsigned char* buf;
  11.419 +    ZPOS64_T uSizeFile;
  11.420 +    ZPOS64_T uBackRead;
  11.421 +    ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
  11.422 +    ZPOS64_T uPosFound=0;
  11.423 +
  11.424 +    if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
  11.425 +        return 0;
  11.426 +
  11.427 +
  11.428 +    uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
  11.429 +
  11.430 +    if (uMaxBack>uSizeFile)
  11.431 +        uMaxBack = uSizeFile;
  11.432 +
  11.433 +    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
  11.434 +    if (buf==NULL)
  11.435 +        return 0;
  11.436 +
  11.437 +    uBackRead = 4;
  11.438 +    while (uBackRead<uMaxBack)
  11.439 +    {
  11.440 +        uLong uReadSize;
  11.441 +        ZPOS64_T uReadPos ;
  11.442 +        int i;
  11.443 +        if (uBackRead+BUFREADCOMMENT>uMaxBack)
  11.444 +            uBackRead = uMaxBack;
  11.445 +        else
  11.446 +            uBackRead+=BUFREADCOMMENT;
  11.447 +        uReadPos = uSizeFile-uBackRead ;
  11.448 +
  11.449 +        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
  11.450 +                     (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
  11.451 +        if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
  11.452 +            break;
  11.453 +
  11.454 +        if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
  11.455 +            break;
  11.456 +
  11.457 +        for (i=(int)uReadSize-3; (i--)>0;)
  11.458 +            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
  11.459 +                ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
  11.460 +            {
  11.461 +                uPosFound = uReadPos+i;
  11.462 +                break;
  11.463 +            }
  11.464 +
  11.465 +        if (uPosFound!=0)
  11.466 +            break;
  11.467 +    }
  11.468 +    TRYFREE(buf);
  11.469 +    return uPosFound;
  11.470 +}
  11.471 +
  11.472 +
  11.473 +/*
  11.474 +  Locate the Central directory 64 of a zipfile (at the end, just before
  11.475 +    the global comment)
  11.476 +*/
  11.477 +local ZPOS64_T unz64local_SearchCentralDir64 OF((
  11.478 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
  11.479 +    voidpf filestream));
  11.480 +
  11.481 +local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
  11.482 +                                      voidpf filestream)
  11.483 +{
  11.484 +    unsigned char* buf;
  11.485 +    ZPOS64_T uSizeFile;
  11.486 +    ZPOS64_T uBackRead;
  11.487 +    ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
  11.488 +    ZPOS64_T uPosFound=0;
  11.489 +    uLong uL;
  11.490 +                ZPOS64_T relativeOffset;
  11.491 +
  11.492 +    if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
  11.493 +        return 0;
  11.494 +
  11.495 +
  11.496 +    uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
  11.497 +
  11.498 +    if (uMaxBack>uSizeFile)
  11.499 +        uMaxBack = uSizeFile;
  11.500 +
  11.501 +    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
  11.502 +    if (buf==NULL)
  11.503 +        return 0;
  11.504 +
  11.505 +    uBackRead = 4;
  11.506 +    while (uBackRead<uMaxBack)
  11.507 +    {
  11.508 +        uLong uReadSize;
  11.509 +        ZPOS64_T uReadPos;
  11.510 +        int i;
  11.511 +        if (uBackRead+BUFREADCOMMENT>uMaxBack)
  11.512 +            uBackRead = uMaxBack;
  11.513 +        else
  11.514 +            uBackRead+=BUFREADCOMMENT;
  11.515 +        uReadPos = uSizeFile-uBackRead ;
  11.516 +
  11.517 +        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
  11.518 +                     (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
  11.519 +        if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
  11.520 +            break;
  11.521 +
  11.522 +        if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
  11.523 +            break;
  11.524 +
  11.525 +        for (i=(int)uReadSize-3; (i--)>0;)
  11.526 +            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
  11.527 +                ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
  11.528 +            {
  11.529 +                uPosFound = uReadPos+i;
  11.530 +                break;
  11.531 +            }
  11.532 +
  11.533 +        if (uPosFound!=0)
  11.534 +            break;
  11.535 +    }
  11.536 +    TRYFREE(buf);
  11.537 +    if (uPosFound == 0)
  11.538 +        return 0;
  11.539 +
  11.540 +    /* Zip64 end of central directory locator */
  11.541 +    if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
  11.542 +        return 0;
  11.543 +
  11.544 +    /* the signature, already checked */
  11.545 +    if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
  11.546 +        return 0;
  11.547 +
  11.548 +    /* number of the disk with the start of the zip64 end of  central directory */
  11.549 +    if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
  11.550 +        return 0;
  11.551 +    if (uL != 0)
  11.552 +        return 0;
  11.553 +
  11.554 +    /* relative offset of the zip64 end of central directory record */
  11.555 +    if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
  11.556 +        return 0;
  11.557 +
  11.558 +    /* total number of disks */
  11.559 +    if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
  11.560 +        return 0;
  11.561 +    if (uL != 1)
  11.562 +        return 0;
  11.563 +
  11.564 +    /* Goto end of central directory record */
  11.565 +    if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
  11.566 +        return 0;
  11.567 +
  11.568 +     /* the signature */
  11.569 +    if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
  11.570 +        return 0;
  11.571 +
  11.572 +    if (uL != 0x06064b50)
  11.573 +        return 0;
  11.574 +
  11.575 +    return relativeOffset;
  11.576 +}
  11.577 +
  11.578 +/*
  11.579 +  Open a Zip file. path contain the full pathname (by example,
  11.580 +     on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
  11.581 +     "zlib/zlib114.zip".
  11.582 +     If the zipfile cannot be opened (file doesn't exist or in not valid), the
  11.583 +       return value is NULL.
  11.584 +     Else, the return value is a unzFile Handle, usable with other function
  11.585 +       of this unzip package.
  11.586 +*/
  11.587 +local unzFile unzOpenInternal (const void *path,
  11.588 +                               zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
  11.589 +                               int is64bitOpenFunction)
  11.590 +{
  11.591 +    unz64_s us;
  11.592 +    unz64_s *s;
  11.593 +    ZPOS64_T central_pos;
  11.594 +    uLong   uL;
  11.595 +
  11.596 +    uLong number_disk;          /* number of the current dist, used for
  11.597 +                                   spaning ZIP, unsupported, always 0*/
  11.598 +    uLong number_disk_with_CD;  /* number the the disk with central dir, used
  11.599 +                                   for spaning ZIP, unsupported, always 0*/
  11.600 +    ZPOS64_T number_entry_CD;      /* total number of entries in
  11.601 +                                   the central dir
  11.602 +                                   (same than number_entry on nospan) */
  11.603 +
  11.604 +    int err=UNZ_OK;
  11.605 +
  11.606 +    if (unz_copyright[0]!=' ')
  11.607 +        return NULL;
  11.608 +
  11.609 +    us.z_filefunc.zseek32_file = NULL;
  11.610 +    us.z_filefunc.ztell32_file = NULL;
  11.611 +    if (pzlib_filefunc64_32_def==NULL)
  11.612 +        fill_fopen64_filefunc(&us.z_filefunc.zfile_func64);
  11.613 +    else
  11.614 +        us.z_filefunc = *pzlib_filefunc64_32_def;
  11.615 +    us.is64bitOpenFunction = is64bitOpenFunction;
  11.616 +
  11.617 +
  11.618 +
  11.619 +    us.filestream = ZOPEN64(us.z_filefunc,
  11.620 +                                                 path,
  11.621 +                                                 ZLIB_FILEFUNC_MODE_READ |
  11.622 +                                                 ZLIB_FILEFUNC_MODE_EXISTING);
  11.623 +    if (us.filestream==NULL)
  11.624 +        return NULL;
  11.625 +
  11.626 +    central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
  11.627 +    if (central_pos)
  11.628 +    {
  11.629 +        uLong uS;
  11.630 +        ZPOS64_T uL64;
  11.631 +
  11.632 +        us.isZip64 = 1;
  11.633 +
  11.634 +        if (ZSEEK64(us.z_filefunc, us.filestream,
  11.635 +                                      central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
  11.636 +        err=UNZ_ERRNO;
  11.637 +
  11.638 +        /* the signature, already checked */
  11.639 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
  11.640 +            err=UNZ_ERRNO;
  11.641 +
  11.642 +        /* size of zip64 end of central directory record */
  11.643 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
  11.644 +            err=UNZ_ERRNO;
  11.645 +
  11.646 +        /* version made by */
  11.647 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
  11.648 +            err=UNZ_ERRNO;
  11.649 +
  11.650 +        /* version needed to extract */
  11.651 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
  11.652 +            err=UNZ_ERRNO;
  11.653 +
  11.654 +        /* number of this disk */
  11.655 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
  11.656 +            err=UNZ_ERRNO;
  11.657 +
  11.658 +        /* number of the disk with the start of the central directory */
  11.659 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
  11.660 +            err=UNZ_ERRNO;
  11.661 +
  11.662 +        /* total number of entries in the central directory on this disk */
  11.663 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
  11.664 +            err=UNZ_ERRNO;
  11.665 +
  11.666 +        /* total number of entries in the central directory */
  11.667 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
  11.668 +            err=UNZ_ERRNO;
  11.669 +
  11.670 +        if ((number_entry_CD!=us.gi.number_entry) ||
  11.671 +            (number_disk_with_CD!=0) ||
  11.672 +            (number_disk!=0))
  11.673 +            err=UNZ_BADZIPFILE;
  11.674 +
  11.675 +        /* size of the central directory */
  11.676 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
  11.677 +            err=UNZ_ERRNO;
  11.678 +
  11.679 +        /* offset of start of central directory with respect to the
  11.680 +          starting disk number */
  11.681 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
  11.682 +            err=UNZ_ERRNO;
  11.683 +
  11.684 +        us.gi.size_comment = 0;
  11.685 +    }
  11.686 +    else
  11.687 +    {
  11.688 +        central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
  11.689 +        if (central_pos==0)
  11.690 +            err=UNZ_ERRNO;
  11.691 +
  11.692 +        us.isZip64 = 0;
  11.693 +
  11.694 +        if (ZSEEK64(us.z_filefunc, us.filestream,
  11.695 +                                        central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
  11.696 +            err=UNZ_ERRNO;
  11.697 +
  11.698 +        /* the signature, already checked */
  11.699 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
  11.700 +            err=UNZ_ERRNO;
  11.701 +
  11.702 +        /* number of this disk */
  11.703 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
  11.704 +            err=UNZ_ERRNO;
  11.705 +
  11.706 +        /* number of the disk with the start of the central directory */
  11.707 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
  11.708 +            err=UNZ_ERRNO;
  11.709 +
  11.710 +        /* total number of entries in the central dir on this disk */
  11.711 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
  11.712 +            err=UNZ_ERRNO;
  11.713 +        us.gi.number_entry = uL;
  11.714 +
  11.715 +        /* total number of entries in the central dir */
  11.716 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
  11.717 +            err=UNZ_ERRNO;
  11.718 +        number_entry_CD = uL;
  11.719 +
  11.720 +        if ((number_entry_CD!=us.gi.number_entry) ||
  11.721 +            (number_disk_with_CD!=0) ||
  11.722 +            (number_disk!=0))
  11.723 +            err=UNZ_BADZIPFILE;
  11.724 +
  11.725 +        /* size of the central directory */
  11.726 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
  11.727 +            err=UNZ_ERRNO;
  11.728 +        us.size_central_dir = uL;
  11.729 +
  11.730 +        /* offset of start of central directory with respect to the
  11.731 +            starting disk number */
  11.732 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
  11.733 +            err=UNZ_ERRNO;
  11.734 +        us.offset_central_dir = uL;
  11.735 +
  11.736 +        /* zipfile comment length */
  11.737 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
  11.738 +            err=UNZ_ERRNO;
  11.739 +    }
  11.740 +
  11.741 +    if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
  11.742 +        (err==UNZ_OK))
  11.743 +        err=UNZ_BADZIPFILE;
  11.744 +
  11.745 +    if (err!=UNZ_OK)
  11.746 +    {
  11.747 +        ZCLOSE64(us.z_filefunc, us.filestream);
  11.748 +        return NULL;
  11.749 +    }
  11.750 +
  11.751 +    us.byte_before_the_zipfile = central_pos -
  11.752 +                            (us.offset_central_dir+us.size_central_dir);
  11.753 +    us.central_pos = central_pos;
  11.754 +    us.pfile_in_zip_read = NULL;
  11.755 +    us.encrypted = 0;
  11.756 +
  11.757 +
  11.758 +    s=(unz64_s*)ALLOC(sizeof(unz64_s));
  11.759 +    if( s != NULL)
  11.760 +    {
  11.761 +        *s=us;
  11.762 +        unzGoToFirstFile((unzFile)s);
  11.763 +    }
  11.764 +    return (unzFile)s;
  11.765 +}
  11.766 +
  11.767 +
  11.768 +extern unzFile ZEXPORT unzOpen2 (const char *path,
  11.769 +                                        zlib_filefunc_def* pzlib_filefunc32_def)
  11.770 +{
  11.771 +    if (pzlib_filefunc32_def != NULL)
  11.772 +    {
  11.773 +        zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
  11.774 +        fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
  11.775 +        return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
  11.776 +    }
  11.777 +    else
  11.778 +        return unzOpenInternal(path, NULL, 0);
  11.779 +}
  11.780 +
  11.781 +extern unzFile ZEXPORT unzOpen2_64 (const void *path,
  11.782 +                                     zlib_filefunc64_def* pzlib_filefunc_def)
  11.783 +{
  11.784 +    if (pzlib_filefunc_def != NULL)
  11.785 +    {
  11.786 +        zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
  11.787 +        zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
  11.788 +        zlib_filefunc64_32_def_fill.ztell32_file = NULL;
  11.789 +        zlib_filefunc64_32_def_fill.zseek32_file = NULL;
  11.790 +        return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1);
  11.791 +    }
  11.792 +    else
  11.793 +        return unzOpenInternal(path, NULL, 1);
  11.794 +}
  11.795 +
  11.796 +extern unzFile ZEXPORT unzOpen (const char *path)
  11.797 +{
  11.798 +    return unzOpenInternal(path, NULL, 0);
  11.799 +}
  11.800 +
  11.801 +extern unzFile ZEXPORT unzOpen64 (const void *path)
  11.802 +{
  11.803 +    return unzOpenInternal(path, NULL, 1);
  11.804 +}
  11.805 +
  11.806 +/*
  11.807 +  Close a ZipFile opened with unzOpen.
  11.808 +  If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
  11.809 +    these files MUST be closed with unzCloseCurrentFile before call unzClose.
  11.810 +  return UNZ_OK if there is no problem. */
  11.811 +extern int ZEXPORT unzClose (unzFile file)
  11.812 +{
  11.813 +    unz64_s* s;
  11.814 +    if (file==NULL)
  11.815 +        return UNZ_PARAMERROR;
  11.816 +    s=(unz64_s*)file;
  11.817 +
  11.818 +    if (s->pfile_in_zip_read!=NULL)
  11.819 +        unzCloseCurrentFile(file);
  11.820 +
  11.821 +    ZCLOSE64(s->z_filefunc, s->filestream);
  11.822 +    TRYFREE(s);
  11.823 +    return UNZ_OK;
  11.824 +}
  11.825 +
  11.826 +
  11.827 +/*
  11.828 +  Write info about the ZipFile in the *pglobal_info structure.
  11.829 +  No preparation of the structure is needed
  11.830 +  return UNZ_OK if there is no problem. */
  11.831 +extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
  11.832 +{
  11.833 +    unz64_s* s;
  11.834 +    if (file==NULL)
  11.835 +        return UNZ_PARAMERROR;
  11.836 +    s=(unz64_s*)file;
  11.837 +    *pglobal_info=s->gi;
  11.838 +    return UNZ_OK;
  11.839 +}
  11.840 +
  11.841 +extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
  11.842 +{
  11.843 +    unz64_s* s;
  11.844 +    if (file==NULL)
  11.845 +        return UNZ_PARAMERROR;
  11.846 +    s=(unz64_s*)file;
  11.847 +    /* to do : check if number_entry is not truncated */
  11.848 +    pglobal_info32->number_entry = (uLong)s->gi.number_entry;
  11.849 +    pglobal_info32->size_comment = s->gi.size_comment;
  11.850 +    return UNZ_OK;
  11.851 +}
  11.852 +/*
  11.853 +   Translate date/time from Dos format to tm_unz (readable more easilty)
  11.854 +*/
  11.855 +local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
  11.856 +{
  11.857 +    ZPOS64_T uDate;
  11.858 +    uDate = (ZPOS64_T)(ulDosDate>>16);
  11.859 +    ptm->tm_mday = (uInt)(uDate&0x1f) ;
  11.860 +    ptm->tm_mon =  (uInt)((((uDate)&0x1E0)/0x20)-1) ;
  11.861 +    ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
  11.862 +
  11.863 +    ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
  11.864 +    ptm->tm_min =  (uInt) ((ulDosDate&0x7E0)/0x20) ;
  11.865 +    ptm->tm_sec =  (uInt) (2*(ulDosDate&0x1f)) ;
  11.866 +}
  11.867 +
  11.868 +/*
  11.869 +  Get Info about the current file in the zipfile, with internal only info
  11.870 +*/
  11.871 +local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
  11.872 +                                                  unz_file_info64 *pfile_info,
  11.873 +                                                  unz_file_info64_internal
  11.874 +                                                  *pfile_info_internal,
  11.875 +                                                  char *szFileName,
  11.876 +                                                  uLong fileNameBufferSize,
  11.877 +                                                  void *extraField,
  11.878 +                                                  uLong extraFieldBufferSize,
  11.879 +                                                  char *szComment,
  11.880 +                                                  uLong commentBufferSize));
  11.881 +
  11.882 +local int unz64local_GetCurrentFileInfoInternal (unzFile file,
  11.883 +                                                  unz_file_info64 *pfile_info,
  11.884 +                                                  unz_file_info64_internal
  11.885 +                                                  *pfile_info_internal,
  11.886 +                                                  char *szFileName,
  11.887 +                                                  uLong fileNameBufferSize,
  11.888 +                                                  void *extraField,
  11.889 +                                                  uLong extraFieldBufferSize,
  11.890 +                                                  char *szComment,
  11.891 +                                                  uLong commentBufferSize)
  11.892 +{
  11.893 +    unz64_s* s;
  11.894 +    unz_file_info64 file_info;
  11.895 +    unz_file_info64_internal file_info_internal;
  11.896 +    int err=UNZ_OK;
  11.897 +    uLong uMagic;
  11.898 +    long lSeek=0;
  11.899 +    uLong uL;
  11.900 +
  11.901 +    if (file==NULL)
  11.902 +        return UNZ_PARAMERROR;
  11.903 +    s=(unz64_s*)file;
  11.904 +    if (ZSEEK64(s->z_filefunc, s->filestream,
  11.905 +              s->pos_in_central_dir+s->byte_before_the_zipfile,
  11.906 +              ZLIB_FILEFUNC_SEEK_SET)!=0)
  11.907 +        err=UNZ_ERRNO;
  11.908 +
  11.909 +
  11.910 +    /* we check the magic */
  11.911 +    if (err==UNZ_OK)
  11.912 +    {
  11.913 +        if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
  11.914 +            err=UNZ_ERRNO;
  11.915 +        else if (uMagic!=0x02014b50)
  11.916 +            err=UNZ_BADZIPFILE;
  11.917 +    }
  11.918 +
  11.919 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
  11.920 +        err=UNZ_ERRNO;
  11.921 +
  11.922 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
  11.923 +        err=UNZ_ERRNO;
  11.924 +
  11.925 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
  11.926 +        err=UNZ_ERRNO;
  11.927 +
  11.928 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
  11.929 +        err=UNZ_ERRNO;
  11.930 +
  11.931 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
  11.932 +        err=UNZ_ERRNO;
  11.933 +
  11.934 +    unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
  11.935 +
  11.936 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
  11.937 +        err=UNZ_ERRNO;
  11.938 +
  11.939 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
  11.940 +        err=UNZ_ERRNO;
  11.941 +    file_info.compressed_size = uL;
  11.942 +
  11.943 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
  11.944 +        err=UNZ_ERRNO;
  11.945 +    file_info.uncompressed_size = uL;
  11.946 +
  11.947 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
  11.948 +        err=UNZ_ERRNO;
  11.949 +
  11.950 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
  11.951 +        err=UNZ_ERRNO;
  11.952 +
  11.953 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
  11.954 +        err=UNZ_ERRNO;
  11.955 +
  11.956 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
  11.957 +        err=UNZ_ERRNO;
  11.958 +
  11.959 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
  11.960 +        err=UNZ_ERRNO;
  11.961 +
  11.962 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
  11.963 +        err=UNZ_ERRNO;
  11.964 +
  11.965 +                // relative offset of local header
  11.966 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
  11.967 +        err=UNZ_ERRNO;
  11.968 +    file_info_internal.offset_curfile = uL;
  11.969 +
  11.970 +    lSeek+=file_info.size_filename;
  11.971 +    if ((err==UNZ_OK) && (szFileName!=NULL))
  11.972 +    {
  11.973 +        uLong uSizeRead ;
  11.974 +        if (file_info.size_filename<fileNameBufferSize)
  11.975 +        {
  11.976 +            *(szFileName+file_info.size_filename)='\0';
  11.977 +            uSizeRead = file_info.size_filename;
  11.978 +        }
  11.979 +        else
  11.980 +            uSizeRead = fileNameBufferSize;
  11.981 +
  11.982 +        if ((file_info.size_filename>0) && (fileNameBufferSize>0))
  11.983 +            if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
  11.984 +                err=UNZ_ERRNO;
  11.985 +        lSeek -= uSizeRead;
  11.986 +    }
  11.987 +
  11.988 +    // Read extrafield
  11.989 +    if ((err==UNZ_OK) && (extraField!=NULL))
  11.990 +    {
  11.991 +        ZPOS64_T uSizeRead ;
  11.992 +        if (file_info.size_file_extra<extraFieldBufferSize)
  11.993 +            uSizeRead = file_info.size_file_extra;
  11.994 +        else
  11.995 +            uSizeRead = extraFieldBufferSize;
  11.996 +
  11.997 +        if (lSeek!=0)
  11.998 +        {
  11.999 +            if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
 11.1000 +                lSeek=0;
 11.1001 +            else
 11.1002 +                err=UNZ_ERRNO;
 11.1003 +        }
 11.1004 +
 11.1005 +        if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
 11.1006 +            if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
 11.1007 +                err=UNZ_ERRNO;
 11.1008 +
 11.1009 +        lSeek += file_info.size_file_extra - (uLong)uSizeRead;
 11.1010 +    }
 11.1011 +    else
 11.1012 +        lSeek += file_info.size_file_extra;
 11.1013 +
 11.1014 +
 11.1015 +    if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
 11.1016 +    {
 11.1017 +                                uLong acc = 0;
 11.1018 +
 11.1019 +        // since lSeek now points to after the extra field we need to move back
 11.1020 +        lSeek -= file_info.size_file_extra;
 11.1021 +
 11.1022 +        if (lSeek!=0)
 11.1023 +        {
 11.1024 +            if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
 11.1025 +                lSeek=0;
 11.1026 +            else
 11.1027 +                err=UNZ_ERRNO;
 11.1028 +        }
 11.1029 +
 11.1030 +        while(acc < file_info.size_file_extra)
 11.1031 +        {
 11.1032 +            uLong headerId;
 11.1033 +                                                uLong dataSize;
 11.1034 +
 11.1035 +            if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
 11.1036 +                err=UNZ_ERRNO;
 11.1037 +
 11.1038 +            if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
 11.1039 +                err=UNZ_ERRNO;
 11.1040 +
 11.1041 +            /* ZIP64 extra fields */
 11.1042 +            if (headerId == 0x0001)
 11.1043 +            {
 11.1044 +                                                        uLong uL;
 11.1045 +
 11.1046 +                                                                if(file_info.uncompressed_size == MAXU32)
 11.1047 +                                                                {
 11.1048 +                                                                        if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
 11.1049 +                                                                                        err=UNZ_ERRNO;
 11.1050 +                                                                }
 11.1051 +
 11.1052 +                                                                if(file_info.compressed_size == MAXU32)
 11.1053 +                                                                {
 11.1054 +                                                                        if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
 11.1055 +                                                                                  err=UNZ_ERRNO;
 11.1056 +                                                                }
 11.1057 +
 11.1058 +                                                                if(file_info_internal.offset_curfile == MAXU32)
 11.1059 +                                                                {
 11.1060 +                                                                        /* Relative Header offset */
 11.1061 +                                                                        if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
 11.1062 +                                                                                err=UNZ_ERRNO;
 11.1063 +                                                                }
 11.1064 +
 11.1065 +                                                                if(file_info.disk_num_start == MAXU32)
 11.1066 +                                                                {
 11.1067 +                                                                        /* Disk Start Number */
 11.1068 +                                                                        if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
 11.1069 +                                                                                err=UNZ_ERRNO;
 11.1070 +                                                                }
 11.1071 +
 11.1072 +            }
 11.1073 +            else
 11.1074 +            {
 11.1075 +                if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
 11.1076 +                    err=UNZ_ERRNO;
 11.1077 +            }
 11.1078 +
 11.1079 +            acc += 2 + 2 + dataSize;
 11.1080 +        }
 11.1081 +    }
 11.1082 +
 11.1083 +    if ((err==UNZ_OK) && (szComment!=NULL))
 11.1084 +    {
 11.1085 +        uLong uSizeRead ;
 11.1086 +        if (file_info.size_file_comment<commentBufferSize)
 11.1087 +        {
 11.1088 +            *(szComment+file_info.size_file_comment)='\0';
 11.1089 +            uSizeRead = file_info.size_file_comment;
 11.1090 +        }
 11.1091 +        else
 11.1092 +            uSizeRead = commentBufferSize;
 11.1093 +
 11.1094 +        if (lSeek!=0)
 11.1095 +        {
 11.1096 +            if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
 11.1097 +                lSeek=0;
 11.1098 +            else
 11.1099 +                err=UNZ_ERRNO;
 11.1100 +        }
 11.1101 +
 11.1102 +        if ((file_info.size_file_comment>0) && (commentBufferSize>0))
 11.1103 +            if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
 11.1104 +                err=UNZ_ERRNO;
 11.1105 +        lSeek+=file_info.size_file_comment - uSizeRead;
 11.1106 +    }
 11.1107 +    else
 11.1108 +        lSeek+=file_info.size_file_comment;
 11.1109 +
 11.1110 +
 11.1111 +    if ((err==UNZ_OK) && (pfile_info!=NULL))
 11.1112 +        *pfile_info=file_info;
 11.1113 +
 11.1114 +    if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
 11.1115 +        *pfile_info_internal=file_info_internal;
 11.1116 +
 11.1117 +    return err;
 11.1118 +}
 11.1119 +
 11.1120 +
 11.1121 +
 11.1122 +/*
 11.1123 +  Write info about the ZipFile in the *pglobal_info structure.
 11.1124 +  No preparation of the structure is needed
 11.1125 +  return UNZ_OK if there is no problem.
 11.1126 +*/
 11.1127 +extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
 11.1128 +                                          unz_file_info64 * pfile_info,
 11.1129 +                                          char * szFileName, uLong fileNameBufferSize,
 11.1130 +                                          void *extraField, uLong extraFieldBufferSize,
 11.1131 +                                          char* szComment,  uLong commentBufferSize)
 11.1132 +{
 11.1133 +    return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
 11.1134 +                                                szFileName,fileNameBufferSize,
 11.1135 +                                                extraField,extraFieldBufferSize,
 11.1136 +                                                szComment,commentBufferSize);
 11.1137 +}
 11.1138 +
 11.1139 +extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
 11.1140 +                                          unz_file_info * pfile_info,
 11.1141 +                                          char * szFileName, uLong fileNameBufferSize,
 11.1142 +                                          void *extraField, uLong extraFieldBufferSize,
 11.1143 +                                          char* szComment,  uLong commentBufferSize)
 11.1144 +{
 11.1145 +    int err;
 11.1146 +    unz_file_info64 file_info64;
 11.1147 +    err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
 11.1148 +                                                szFileName,fileNameBufferSize,
 11.1149 +                                                extraField,extraFieldBufferSize,
 11.1150 +                                                szComment,commentBufferSize);
 11.1151 +    if ((err==UNZ_OK) && (pfile_info != NULL))
 11.1152 +    {
 11.1153 +        pfile_info->version = file_info64.version;
 11.1154 +        pfile_info->version_needed = file_info64.version_needed;
 11.1155 +        pfile_info->flag = file_info64.flag;
 11.1156 +        pfile_info->compression_method = file_info64.compression_method;
 11.1157 +        pfile_info->dosDate = file_info64.dosDate;
 11.1158 +        pfile_info->crc = file_info64.crc;
 11.1159 +
 11.1160 +        pfile_info->size_filename = file_info64.size_filename;
 11.1161 +        pfile_info->size_file_extra = file_info64.size_file_extra;
 11.1162 +        pfile_info->size_file_comment = file_info64.size_file_comment;
 11.1163 +
 11.1164 +        pfile_info->disk_num_start = file_info64.disk_num_start;
 11.1165 +        pfile_info->internal_fa = file_info64.internal_fa;
 11.1166 +        pfile_info->external_fa = file_info64.external_fa;
 11.1167 +
 11.1168 +        pfile_info->tmu_date = file_info64.tmu_date,
 11.1169 +
 11.1170 +
 11.1171 +        pfile_info->compressed_size = (uLong)file_info64.compressed_size;
 11.1172 +        pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
 11.1173 +
 11.1174 +    }
 11.1175 +    return err;
 11.1176 +}
 11.1177 +/*
 11.1178 +  Set the current file of the zipfile to the first file.
 11.1179 +  return UNZ_OK if there is no problem
 11.1180 +*/
 11.1181 +extern int ZEXPORT unzGoToFirstFile (unzFile file)
 11.1182 +{
 11.1183 +    int err=UNZ_OK;
 11.1184 +    unz64_s* s;
 11.1185 +    if (file==NULL)
 11.1186 +        return UNZ_PARAMERROR;
 11.1187 +    s=(unz64_s*)file;
 11.1188 +    s->pos_in_central_dir=s->offset_central_dir;
 11.1189 +    s->num_file=0;
 11.1190 +    err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
 11.1191 +                                             &s->cur_file_info_internal,
 11.1192 +                                             NULL,0,NULL,0,NULL,0);
 11.1193 +    s->current_file_ok = (err == UNZ_OK);
 11.1194 +    return err;
 11.1195 +}
 11.1196 +
 11.1197 +/*
 11.1198 +  Set the current file of the zipfile to the next file.
 11.1199 +  return UNZ_OK if there is no problem
 11.1200 +  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
 11.1201 +*/
 11.1202 +extern int ZEXPORT unzGoToNextFile (unzFile  file)
 11.1203 +{
 11.1204 +    unz64_s* s;
 11.1205 +    int err;
 11.1206 +
 11.1207 +    if (file==NULL)
 11.1208 +        return UNZ_PARAMERROR;
 11.1209 +    s=(unz64_s*)file;
 11.1210 +    if (!s->current_file_ok)
 11.1211 +        return UNZ_END_OF_LIST_OF_FILE;
 11.1212 +    if (s->gi.number_entry != 0xffff)    /* 2^16 files overflow hack */
 11.1213 +      if (s->num_file+1==s->gi.number_entry)
 11.1214 +        return UNZ_END_OF_LIST_OF_FILE;
 11.1215 +
 11.1216 +    s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
 11.1217 +            s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
 11.1218 +    s->num_file++;
 11.1219 +    err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
 11.1220 +                                               &s->cur_file_info_internal,
 11.1221 +                                               NULL,0,NULL,0,NULL,0);
 11.1222 +    s->current_file_ok = (err == UNZ_OK);
 11.1223 +    return err;
 11.1224 +}
 11.1225 +
 11.1226 +
 11.1227 +/*
 11.1228 +  Try locate the file szFileName in the zipfile.
 11.1229 +  For the iCaseSensitivity signification, see unzStringFileNameCompare
 11.1230 +
 11.1231 +  return value :
 11.1232 +  UNZ_OK if the file is found. It becomes the current file.
 11.1233 +  UNZ_END_OF_LIST_OF_FILE if the file is not found
 11.1234 +*/
 11.1235 +extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
 11.1236 +{
 11.1237 +    unz64_s* s;
 11.1238 +    int err;
 11.1239 +
 11.1240 +    /* We remember the 'current' position in the file so that we can jump
 11.1241 +     * back there if we fail.
 11.1242 +     */
 11.1243 +    unz_file_info64 cur_file_infoSaved;
 11.1244 +    unz_file_info64_internal cur_file_info_internalSaved;
 11.1245 +    ZPOS64_T num_fileSaved;
 11.1246 +    ZPOS64_T pos_in_central_dirSaved;
 11.1247 +
 11.1248 +
 11.1249 +    if (file==NULL)
 11.1250 +        return UNZ_PARAMERROR;
 11.1251 +
 11.1252 +    if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
 11.1253 +        return UNZ_PARAMERROR;
 11.1254 +
 11.1255 +    s=(unz64_s*)file;
 11.1256 +    if (!s->current_file_ok)
 11.1257 +        return UNZ_END_OF_LIST_OF_FILE;
 11.1258 +
 11.1259 +    /* Save the current state */
 11.1260 +    num_fileSaved = s->num_file;
 11.1261 +    pos_in_central_dirSaved = s->pos_in_central_dir;
 11.1262 +    cur_file_infoSaved = s->cur_file_info;
 11.1263 +    cur_file_info_internalSaved = s->cur_file_info_internal;
 11.1264 +
 11.1265 +    err = unzGoToFirstFile(file);
 11.1266 +
 11.1267 +    while (err == UNZ_OK)
 11.1268 +    {
 11.1269 +        char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
 11.1270 +        err = unzGetCurrentFileInfo64(file,NULL,
 11.1271 +                                    szCurrentFileName,sizeof(szCurrentFileName)-1,
 11.1272 +                                    NULL,0,NULL,0);
 11.1273 +        if (err == UNZ_OK)
 11.1274 +        {
 11.1275 +            if (unzStringFileNameCompare(szCurrentFileName,
 11.1276 +                                            szFileName,iCaseSensitivity)==0)
 11.1277 +                return UNZ_OK;
 11.1278 +            err = unzGoToNextFile(file);
 11.1279 +        }
 11.1280 +    }
 11.1281 +
 11.1282 +    /* We failed, so restore the state of the 'current file' to where we
 11.1283 +     * were.
 11.1284 +     */
 11.1285 +    s->num_file = num_fileSaved ;
 11.1286 +    s->pos_in_central_dir = pos_in_central_dirSaved ;
 11.1287 +    s->cur_file_info = cur_file_infoSaved;
 11.1288 +    s->cur_file_info_internal = cur_file_info_internalSaved;
 11.1289 +    return err;
 11.1290 +}
 11.1291 +
 11.1292 +
 11.1293 +/*
 11.1294 +///////////////////////////////////////////
 11.1295 +// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
 11.1296 +// I need random access
 11.1297 +//
 11.1298 +// Further optimization could be realized by adding an ability
 11.1299 +// to cache the directory in memory. The goal being a single
 11.1300 +// comprehensive file read to put the file I need in a memory.
 11.1301 +*/
 11.1302 +
 11.1303 +/*
 11.1304 +typedef struct unz_file_pos_s
 11.1305 +{
 11.1306 +    ZPOS64_T pos_in_zip_directory;   // offset in file
 11.1307 +    ZPOS64_T num_of_file;            // # of file
 11.1308 +} unz_file_pos;
 11.1309 +*/
 11.1310 +
 11.1311 +extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos*  file_pos)
 11.1312 +{
 11.1313 +    unz64_s* s;
 11.1314 +
 11.1315 +    if (file==NULL || file_pos==NULL)
 11.1316 +        return UNZ_PARAMERROR;
 11.1317 +    s=(unz64_s*)file;
 11.1318 +    if (!s->current_file_ok)
 11.1319 +        return UNZ_END_OF_LIST_OF_FILE;
 11.1320 +
 11.1321 +    file_pos->pos_in_zip_directory  = s->pos_in_central_dir;
 11.1322 +    file_pos->num_of_file           = s->num_file;
 11.1323 +
 11.1324 +    return UNZ_OK;
 11.1325 +}
 11.1326 +
 11.1327 +extern int ZEXPORT unzGetFilePos(
 11.1328 +    unzFile file,
 11.1329 +    unz_file_pos* file_pos)
 11.1330 +{
 11.1331 +    unz64_file_pos file_pos64;
 11.1332 +    int err = unzGetFilePos64(file,&file_pos64);
 11.1333 +    if (err==UNZ_OK)
 11.1334 +    {
 11.1335 +        file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
 11.1336 +        file_pos->num_of_file = (uLong)file_pos64.num_of_file;
 11.1337 +    }
 11.1338 +    return err;
 11.1339 +}
 11.1340 +
 11.1341 +extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
 11.1342 +{
 11.1343 +    unz64_s* s;
 11.1344 +    int err;
 11.1345 +
 11.1346 +    if (file==NULL || file_pos==NULL)
 11.1347 +        return UNZ_PARAMERROR;
 11.1348 +    s=(unz64_s*)file;
 11.1349 +
 11.1350 +    /* jump to the right spot */
 11.1351 +    s->pos_in_central_dir = file_pos->pos_in_zip_directory;
 11.1352 +    s->num_file           = file_pos->num_of_file;
 11.1353 +
 11.1354 +    /* set the current file */
 11.1355 +    err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
 11.1356 +                                               &s->cur_file_info_internal,
 11.1357 +                                               NULL,0,NULL,0,NULL,0);
 11.1358 +    /* return results */
 11.1359 +    s->current_file_ok = (err == UNZ_OK);
 11.1360 +    return err;
 11.1361 +}
 11.1362 +
 11.1363 +extern int ZEXPORT unzGoToFilePos(
 11.1364 +    unzFile file,
 11.1365 +    unz_file_pos* file_pos)
 11.1366 +{
 11.1367 +    unz64_file_pos file_pos64;
 11.1368 +    if (file_pos == NULL)
 11.1369 +        return UNZ_PARAMERROR;
 11.1370 +
 11.1371 +    file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
 11.1372 +    file_pos64.num_of_file = file_pos->num_of_file;
 11.1373 +    return unzGoToFilePos64(file,&file_pos64);
 11.1374 +}
 11.1375 +
 11.1376 +/*
 11.1377 +// Unzip Helper Functions - should be here?
 11.1378 +///////////////////////////////////////////
 11.1379 +*/
 11.1380 +
 11.1381 +/*
 11.1382 +  Read the local header of the current zipfile
 11.1383 +  Check the coherency of the local header and info in the end of central
 11.1384 +        directory about this file
 11.1385 +  store in *piSizeVar the size of extra info in local header
 11.1386 +        (filename and size of extra field data)
 11.1387 +*/
 11.1388 +local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
 11.1389 +                                                    ZPOS64_T * poffset_local_extrafield,
 11.1390 +                                                    uInt  * psize_local_extrafield)
 11.1391 +{
 11.1392 +    uLong uMagic,uData,uFlags;
 11.1393 +    uLong size_filename;
 11.1394 +    uLong size_extra_field;
 11.1395 +    int err=UNZ_OK;
 11.1396 +
 11.1397 +    *piSizeVar = 0;
 11.1398 +    *poffset_local_extrafield = 0;
 11.1399 +    *psize_local_extrafield = 0;
 11.1400 +
 11.1401 +    if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
 11.1402 +                                s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
 11.1403 +        return UNZ_ERRNO;
 11.1404 +
 11.1405 +
 11.1406 +    if (err==UNZ_OK)
 11.1407 +    {
 11.1408 +        if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
 11.1409 +            err=UNZ_ERRNO;
 11.1410 +        else if (uMagic!=0x04034b50)
 11.1411 +            err=UNZ_BADZIPFILE;
 11.1412 +    }
 11.1413 +
 11.1414 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
 11.1415 +        err=UNZ_ERRNO;
 11.1416 +/*
 11.1417 +    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
 11.1418 +        err=UNZ_BADZIPFILE;
 11.1419 +*/
 11.1420 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
 11.1421 +        err=UNZ_ERRNO;
 11.1422 +
 11.1423 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
 11.1424 +        err=UNZ_ERRNO;
 11.1425 +    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
 11.1426 +        err=UNZ_BADZIPFILE;
 11.1427 +
 11.1428 +    if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
 11.1429 +/* #ifdef HAVE_BZIP2 */
 11.1430 +                         (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
 11.1431 +/* #endif */
 11.1432 +                         (s->cur_file_info.compression_method!=Z_DEFLATED))
 11.1433 +        err=UNZ_BADZIPFILE;
 11.1434 +
 11.1435 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
 11.1436 +        err=UNZ_ERRNO;
 11.1437 +
 11.1438 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
 11.1439 +        err=UNZ_ERRNO;
 11.1440 +    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
 11.1441 +        err=UNZ_BADZIPFILE;
 11.1442 +
 11.1443 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
 11.1444 +        err=UNZ_ERRNO;
 11.1445 +    else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
 11.1446 +        err=UNZ_BADZIPFILE;
 11.1447 +
 11.1448 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
 11.1449 +        err=UNZ_ERRNO;
 11.1450 +    else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
 11.1451 +        err=UNZ_BADZIPFILE;
 11.1452 +
 11.1453 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
 11.1454 +        err=UNZ_ERRNO;
 11.1455 +    else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
 11.1456 +        err=UNZ_BADZIPFILE;
 11.1457 +
 11.1458 +    *piSizeVar += (uInt)size_filename;
 11.1459 +
 11.1460 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
 11.1461 +        err=UNZ_ERRNO;
 11.1462 +    *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
 11.1463 +                                    SIZEZIPLOCALHEADER + size_filename;
 11.1464 +    *psize_local_extrafield = (uInt)size_extra_field;
 11.1465 +
 11.1466 +    *piSizeVar += (uInt)size_extra_field;
 11.1467 +
 11.1468 +    return err;
 11.1469 +}
 11.1470 +
 11.1471 +/*
 11.1472 +  Open for reading data the current file in the zipfile.
 11.1473 +  If there is no error and the file is opened, the return value is UNZ_OK.
 11.1474 +*/
 11.1475 +extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
 11.1476 +                                            int* level, int raw, const char* password)
 11.1477 +{
 11.1478 +    int err=UNZ_OK;
 11.1479 +    uInt iSizeVar;
 11.1480 +    unz64_s* s;
 11.1481 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
 11.1482 +    ZPOS64_T offset_local_extrafield;  /* offset of the local extra field */
 11.1483 +    uInt  size_local_extrafield;    /* size of the local extra field */
 11.1484 +#    ifndef NOUNCRYPT
 11.1485 +    char source[12];
 11.1486 +#    else
 11.1487 +    if (password != NULL)
 11.1488 +        return UNZ_PARAMERROR;
 11.1489 +#    endif
 11.1490 +
 11.1491 +    if (file==NULL)
 11.1492 +        return UNZ_PARAMERROR;
 11.1493 +    s=(unz64_s*)file;
 11.1494 +    if (!s->current_file_ok)
 11.1495 +        return UNZ_PARAMERROR;
 11.1496 +
 11.1497 +    if (s->pfile_in_zip_read != NULL)
 11.1498 +        unzCloseCurrentFile(file);
 11.1499 +
 11.1500 +    if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
 11.1501 +        return UNZ_BADZIPFILE;
 11.1502 +
 11.1503 +    pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
 11.1504 +    if (pfile_in_zip_read_info==NULL)
 11.1505 +        return UNZ_INTERNALERROR;
 11.1506 +
 11.1507 +    pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
 11.1508 +    pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
 11.1509 +    pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
 11.1510 +    pfile_in_zip_read_info->pos_local_extrafield=0;
 11.1511 +    pfile_in_zip_read_info->raw=raw;
 11.1512 +
 11.1513 +    if (pfile_in_zip_read_info->read_buffer==NULL)
 11.1514 +    {
 11.1515 +        TRYFREE(pfile_in_zip_read_info);
 11.1516 +        return UNZ_INTERNALERROR;
 11.1517 +    }
 11.1518 +
 11.1519 +    pfile_in_zip_read_info->stream_initialised=0;
 11.1520 +
 11.1521 +    if (method!=NULL)
 11.1522 +        *method = (int)s->cur_file_info.compression_method;
 11.1523 +
 11.1524 +    if (level!=NULL)
 11.1525 +    {
 11.1526 +        *level = 6;
 11.1527 +        switch (s->cur_file_info.flag & 0x06)
 11.1528 +        {
 11.1529 +          case 6 : *level = 1; break;
 11.1530 +          case 4 : *level = 2; break;
 11.1531 +          case 2 : *level = 9; break;
 11.1532 +        }
 11.1533 +    }
 11.1534 +
 11.1535 +    if ((s->cur_file_info.compression_method!=0) &&
 11.1536 +/* #ifdef HAVE_BZIP2 */
 11.1537 +        (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
 11.1538 +/* #endif */
 11.1539 +        (s->cur_file_info.compression_method!=Z_DEFLATED))
 11.1540 +
 11.1541 +        err=UNZ_BADZIPFILE;
 11.1542 +
 11.1543 +    pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
 11.1544 +    pfile_in_zip_read_info->crc32=0;
 11.1545 +    pfile_in_zip_read_info->total_out_64=0;
 11.1546 +    pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
 11.1547 +    pfile_in_zip_read_info->filestream=s->filestream;
 11.1548 +    pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
 11.1549 +    pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
 11.1550 +
 11.1551 +    pfile_in_zip_read_info->stream.total_out = 0;
 11.1552 +
 11.1553 +    if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
 11.1554 +    {
 11.1555 +#ifdef HAVE_BZIP2
 11.1556 +      pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
 11.1557 +      pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
 11.1558 +      pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
 11.1559 +      pfile_in_zip_read_info->bstream.state = (voidpf)0;
 11.1560 +
 11.1561 +      pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
 11.1562 +      pfile_in_zip_read_info->stream.zfree = (free_func)0;
 11.1563 +      pfile_in_zip_read_info->stream.opaque = (voidpf)0;
 11.1564 +      pfile_in_zip_read_info->stream.next_in = (voidpf)0;
 11.1565 +      pfile_in_zip_read_info->stream.avail_in = 0;
 11.1566 +
 11.1567 +      err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
 11.1568 +      if (err == Z_OK)
 11.1569 +        pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
 11.1570 +      else
 11.1571 +      {
 11.1572 +        TRYFREE(pfile_in_zip_read_info);
 11.1573 +        return err;
 11.1574 +      }
 11.1575 +#else
 11.1576 +      pfile_in_zip_read_info->raw=1;
 11.1577 +#endif
 11.1578 +    }
 11.1579 +    else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
 11.1580 +    {
 11.1581 +      pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
 11.1582 +      pfile_in_zip_read_info->stream.zfree = (free_func)0;
 11.1583 +      pfile_in_zip_read_info->stream.opaque = (voidpf)0;
 11.1584 +      pfile_in_zip_read_info->stream.next_in = 0;
 11.1585 +      pfile_in_zip_read_info->stream.avail_in = 0;
 11.1586 +
 11.1587 +      err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
 11.1588 +      if (err == Z_OK)
 11.1589 +        pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
 11.1590 +      else
 11.1591 +      {
 11.1592 +        TRYFREE(pfile_in_zip_read_info);
 11.1593 +        return err;
 11.1594 +      }
 11.1595 +        /* windowBits is passed < 0 to tell that there is no zlib header.
 11.1596 +         * Note that in this case inflate *requires* an extra "dummy" byte
 11.1597 +         * after the compressed stream in order to complete decompression and
 11.1598 +         * return Z_STREAM_END.
 11.1599 +         * In unzip, i don't wait absolutely Z_STREAM_END because I known the
 11.1600 +         * size of both compressed and uncompressed data
 11.1601 +         */
 11.1602 +    }
 11.1603 +    pfile_in_zip_read_info->rest_read_compressed =
 11.1604 +            s->cur_file_info.compressed_size ;
 11.1605 +    pfile_in_zip_read_info->rest_read_uncompressed =
 11.1606 +            s->cur_file_info.uncompressed_size ;
 11.1607 +
 11.1608 +
 11.1609 +    pfile_in_zip_read_info->pos_in_zipfile =
 11.1610 +            s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
 11.1611 +              iSizeVar;
 11.1612 +
 11.1613 +    pfile_in_zip_read_info->stream.avail_in = (uInt)0;
 11.1614 +
 11.1615 +    s->pfile_in_zip_read = pfile_in_zip_read_info;
 11.1616 +                s->encrypted = 0;
 11.1617 +
 11.1618 +#    ifndef NOUNCRYPT
 11.1619 +    if (password != NULL)
 11.1620 +    {
 11.1621 +        int i;
 11.1622 +        s->pcrc_32_tab = get_crc_table();
 11.1623 +        init_keys(password,s->keys,s->pcrc_32_tab);
 11.1624 +        if (ZSEEK64(s->z_filefunc, s->filestream,
 11.1625 +                  s->pfile_in_zip_read->pos_in_zipfile +
 11.1626 +                     s->pfile_in_zip_read->byte_before_the_zipfile,
 11.1627 +                  SEEK_SET)!=0)
 11.1628 +            return UNZ_INTERNALERROR;
 11.1629 +        if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
 11.1630 +            return UNZ_INTERNALERROR;
 11.1631 +
 11.1632 +        for (i = 0; i<12; i++)
 11.1633 +            zdecode(s->keys,s->pcrc_32_tab,source[i]);
 11.1634 +
 11.1635 +        s->pfile_in_zip_read->pos_in_zipfile+=12;
 11.1636 +        s->encrypted=1;
 11.1637 +    }
 11.1638 +#    endif
 11.1639 +
 11.1640 +
 11.1641 +    return UNZ_OK;
 11.1642 +}
 11.1643 +
 11.1644 +extern int ZEXPORT unzOpenCurrentFile (unzFile file)
 11.1645 +{
 11.1646 +    return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
 11.1647 +}
 11.1648 +
 11.1649 +extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char*  password)
 11.1650 +{
 11.1651 +    return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
 11.1652 +}
 11.1653 +
 11.1654 +extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
 11.1655 +{
 11.1656 +    return unzOpenCurrentFile3(file, method, level, raw, NULL);
 11.1657 +}
 11.1658 +
 11.1659 +/** Addition for GDAL : START */
 11.1660 +
 11.1661 +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
 11.1662 +{
 11.1663 +    unz64_s* s;
 11.1664 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
 11.1665 +    s=(unz64_s*)file;
 11.1666 +    if (file==NULL)
 11.1667 +        return 0; //UNZ_PARAMERROR;
 11.1668 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
 11.1669 +    if (pfile_in_zip_read_info==NULL)
 11.1670 +        return 0; //UNZ_PARAMERROR;
 11.1671 +    return pfile_in_zip_read_info->pos_in_zipfile +
 11.1672 +                         pfile_in_zip_read_info->byte_before_the_zipfile;
 11.1673 +}
 11.1674 +
 11.1675 +/** Addition for GDAL : END */
 11.1676 +
 11.1677 +/*
 11.1678 +  Read bytes from the current file.
 11.1679 +  buf contain buffer where data must be copied
 11.1680 +  len the size of buf.
 11.1681 +
 11.1682 +  return the number of byte copied if somes bytes are copied
 11.1683 +  return 0 if the end of file was reached
 11.1684 +  return <0 with error code if there is an error
 11.1685 +    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
 11.1686 +*/
 11.1687 +extern int ZEXPORT unzReadCurrentFile  (unzFile file, voidp buf, unsigned len)
 11.1688 +{
 11.1689 +    int err=UNZ_OK;
 11.1690 +    uInt iRead = 0;
 11.1691 +    unz64_s* s;
 11.1692 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
 11.1693 +    if (file==NULL)
 11.1694 +        return UNZ_PARAMERROR;
 11.1695 +    s=(unz64_s*)file;
 11.1696 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
 11.1697 +
 11.1698 +    if (pfile_in_zip_read_info==NULL)
 11.1699 +        return UNZ_PARAMERROR;
 11.1700 +
 11.1701 +
 11.1702 +    if (pfile_in_zip_read_info->read_buffer == NULL)
 11.1703 +        return UNZ_END_OF_LIST_OF_FILE;
 11.1704 +    if (len==0)
 11.1705 +        return 0;
 11.1706 +
 11.1707 +    pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
 11.1708 +
 11.1709 +    pfile_in_zip_read_info->stream.avail_out = (uInt)len;
 11.1710 +
 11.1711 +    if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
 11.1712 +        (!(pfile_in_zip_read_info->raw)))
 11.1713 +        pfile_in_zip_read_info->stream.avail_out =
 11.1714 +            (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
 11.1715 +
 11.1716 +    if ((len>pfile_in_zip_read_info->rest_read_compressed+
 11.1717 +           pfile_in_zip_read_info->stream.avail_in) &&
 11.1718 +         (pfile_in_zip_read_info->raw))
 11.1719 +        pfile_in_zip_read_info->stream.avail_out =
 11.1720 +            (uInt)pfile_in_zip_read_info->rest_read_compressed+
 11.1721 +            pfile_in_zip_read_info->stream.avail_in;
 11.1722 +
 11.1723 +    while (pfile_in_zip_read_info->stream.avail_out>0)
 11.1724 +    {
 11.1725 +        if ((pfile_in_zip_read_info->stream.avail_in==0) &&
 11.1726 +            (pfile_in_zip_read_info->rest_read_compressed>0))
 11.1727 +        {
 11.1728 +            uInt uReadThis = UNZ_BUFSIZE;
 11.1729 +            if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
 11.1730 +                uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
 11.1731 +            if (uReadThis == 0)
 11.1732 +                return UNZ_EOF;
 11.1733 +            if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
 11.1734 +                      pfile_in_zip_read_info->filestream,
 11.1735 +                      pfile_in_zip_read_info->pos_in_zipfile +
 11.1736 +                         pfile_in_zip_read_info->byte_before_the_zipfile,
 11.1737 +                         ZLIB_FILEFUNC_SEEK_SET)!=0)
 11.1738 +                return UNZ_ERRNO;
 11.1739 +            if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
 11.1740 +                      pfile_in_zip_read_info->filestream,
 11.1741 +                      pfile_in_zip_read_info->read_buffer,
 11.1742 +                      uReadThis)!=uReadThis)
 11.1743 +                return UNZ_ERRNO;
 11.1744 +
 11.1745 +
 11.1746 +#            ifndef NOUNCRYPT
 11.1747 +            if(s->encrypted)
 11.1748 +            {
 11.1749 +                uInt i;
 11.1750 +                for(i=0;i<uReadThis;i++)
 11.1751 +                  pfile_in_zip_read_info->read_buffer[i] =
 11.1752 +                      zdecode(s->keys,s->pcrc_32_tab,
 11.1753 +                              pfile_in_zip_read_info->read_buffer[i]);
 11.1754 +            }
 11.1755 +#            endif
 11.1756 +
 11.1757 +
 11.1758 +            pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
 11.1759 +
 11.1760 +            pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
 11.1761 +
 11.1762 +            pfile_in_zip_read_info->stream.next_in =
 11.1763 +                (Bytef*)pfile_in_zip_read_info->read_buffer;
 11.1764 +            pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
 11.1765 +        }
 11.1766 +
 11.1767 +        if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
 11.1768 +        {
 11.1769 +            uInt uDoCopy,i ;
 11.1770 +
 11.1771 +            if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
 11.1772 +                (pfile_in_zip_read_info->rest_read_compressed == 0))
 11.1773 +                return (iRead==0) ? UNZ_EOF : iRead;
 11.1774 +
 11.1775 +            if (pfile_in_zip_read_info->stream.avail_out <
 11.1776 +                            pfile_in_zip_read_info->stream.avail_in)
 11.1777 +                uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
 11.1778 +            else
 11.1779 +                uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
 11.1780 +
 11.1781 +            for (i=0;i<uDoCopy;i++)
 11.1782 +                *(pfile_in_zip_read_info->stream.next_out+i) =
 11.1783 +                        *(pfile_in_zip_read_info->stream.next_in+i);
 11.1784 +
 11.1785 +            pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
 11.1786 +
 11.1787 +            pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
 11.1788 +                                pfile_in_zip_read_info->stream.next_out,
 11.1789 +                                uDoCopy);
 11.1790 +            pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
 11.1791 +            pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
 11.1792 +            pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
 11.1793 +            pfile_in_zip_read_info->stream.next_out += uDoCopy;
 11.1794 +            pfile_in_zip_read_info->stream.next_in += uDoCopy;
 11.1795 +            pfile_in_zip_read_info->stream.total_out += uDoCopy;
 11.1796 +            iRead += uDoCopy;
 11.1797 +        }
 11.1798 +        else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
 11.1799 +        {
 11.1800 +#ifdef HAVE_BZIP2
 11.1801 +            uLong uTotalOutBefore,uTotalOutAfter;
 11.1802 +            const Bytef *bufBefore;
 11.1803 +            uLong uOutThis;
 11.1804 +
 11.1805 +            pfile_in_zip_read_info->bstream.next_in        = (char*)pfile_in_zip_read_info->stream.next_in;
 11.1806 +            pfile_in_zip_read_info->bstream.avail_in       = pfile_in_zip_read_info->stream.avail_in;
 11.1807 +            pfile_in_zip_read_info->bstream.total_in_lo32  = pfile_in_zip_read_info->stream.total_in;
 11.1808 +            pfile_in_zip_read_info->bstream.total_in_hi32  = 0;
 11.1809 +            pfile_in_zip_read_info->bstream.next_out       = (char*)pfile_in_zip_read_info->stream.next_out;
 11.1810 +            pfile_in_zip_read_info->bstream.avail_out      = pfile_in_zip_read_info->stream.avail_out;
 11.1811 +            pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
 11.1812 +            pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
 11.1813 +
 11.1814 +            uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
 11.1815 +            bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
 11.1816 +
 11.1817 +            err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
 11.1818 +
 11.1819 +            uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
 11.1820 +            uOutThis = uTotalOutAfter-uTotalOutBefore;
 11.1821 +
 11.1822 +            pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
 11.1823 +
 11.1824 +            pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
 11.1825 +            pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
 11.1826 +            iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
 11.1827 +
 11.1828 +            pfile_in_zip_read_info->stream.next_in   = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
 11.1829 +            pfile_in_zip_read_info->stream.avail_in  = pfile_in_zip_read_info->bstream.avail_in;
 11.1830 +            pfile_in_zip_read_info->stream.total_in  = pfile_in_zip_read_info->bstream.total_in_lo32;
 11.1831 +            pfile_in_zip_read_info->stream.next_out  = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
 11.1832 +            pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
 11.1833 +            pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
 11.1834 +
 11.1835 +            if (err==BZ_STREAM_END)
 11.1836 +              return (iRead==0) ? UNZ_EOF : iRead;
 11.1837 +            if (err!=BZ_OK)
 11.1838 +              break;
 11.1839 +#endif
 11.1840 +        } // end Z_BZIP2ED
 11.1841 +        else
 11.1842 +        {
 11.1843 +            ZPOS64_T uTotalOutBefore,uTotalOutAfter;
 11.1844 +            const Bytef *bufBefore;
 11.1845 +            ZPOS64_T uOutThis;
 11.1846 +            int flush=Z_SYNC_FLUSH;
 11.1847 +
 11.1848 +            uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
 11.1849 +            bufBefore = pfile_in_zip_read_info->stream.next_out;
 11.1850 +
 11.1851 +            /*
 11.1852 +            if ((pfile_in_zip_read_info->rest_read_uncompressed ==
 11.1853 +                     pfile_in_zip_read_info->stream.avail_out) &&
 11.1854 +                (pfile_in_zip_read_info->rest_read_compressed == 0))
 11.1855 +                flush = Z_FINISH;
 11.1856 +            */
 11.1857 +            err=inflate(&pfile_in_zip_read_info->stream,flush);
 11.1858 +
 11.1859 +            if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
 11.1860 +              err = Z_DATA_ERROR;
 11.1861 +
 11.1862 +            uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
 11.1863 +            uOutThis = uTotalOutAfter-uTotalOutBefore;
 11.1864 +
 11.1865 +            pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
 11.1866 +
 11.1867 +            pfile_in_zip_read_info->crc32 =
 11.1868 +                crc32(pfile_in_zip_read_info->crc32,bufBefore,
 11.1869 +                        (uInt)(uOutThis));
 11.1870 +
 11.1871 +            pfile_in_zip_read_info->rest_read_uncompressed -=
 11.1872 +                uOutThis;
 11.1873 +
 11.1874 +            iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
 11.1875 +
 11.1876 +            if (err==Z_STREAM_END)
 11.1877 +                return (iRead==0) ? UNZ_EOF : iRead;
 11.1878 +            if (err!=Z_OK)
 11.1879 +                break;
 11.1880 +        }
 11.1881 +    }
 11.1882 +
 11.1883 +    if (err==Z_OK)
 11.1884 +        return iRead;
 11.1885 +    return err;
 11.1886 +}
 11.1887 +
 11.1888 +
 11.1889 +/*
 11.1890 +  Give the current position in uncompressed data
 11.1891 +*/
 11.1892 +extern z_off_t ZEXPORT unztell (unzFile file)
 11.1893 +{
 11.1894 +    unz64_s* s;
 11.1895 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
 11.1896 +    if (file==NULL)
 11.1897 +        return UNZ_PARAMERROR;
 11.1898 +    s=(unz64_s*)file;
 11.1899 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
 11.1900 +
 11.1901 +    if (pfile_in_zip_read_info==NULL)
 11.1902 +        return UNZ_PARAMERROR;
 11.1903 +
 11.1904 +    return (z_off_t)pfile_in_zip_read_info->stream.total_out;
 11.1905 +}
 11.1906 +
 11.1907 +extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
 11.1908 +{
 11.1909 +
 11.1910 +    unz64_s* s;
 11.1911 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
 11.1912 +    if (file==NULL)
 11.1913 +        return (ZPOS64_T)-1;
 11.1914 +    s=(unz64_s*)file;
 11.1915 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
 11.1916 +
 11.1917 +    if (pfile_in_zip_read_info==NULL)
 11.1918 +        return (ZPOS64_T)-1;
 11.1919 +
 11.1920 +    return pfile_in_zip_read_info->total_out_64;
 11.1921 +}
 11.1922 +
 11.1923 +
 11.1924 +/*
 11.1925 +  return 1 if the end of file was reached, 0 elsewhere
 11.1926 +*/
 11.1927 +extern int ZEXPORT unzeof (unzFile file)
 11.1928 +{
 11.1929 +    unz64_s* s;
 11.1930 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
 11.1931 +    if (file==NULL)
 11.1932 +        return UNZ_PARAMERROR;
 11.1933 +    s=(unz64_s*)file;
 11.1934 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
 11.1935 +
 11.1936 +    if (pfile_in_zip_read_info==NULL)
 11.1937 +        return UNZ_PARAMERROR;
 11.1938 +
 11.1939 +    if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
 11.1940 +        return 1;
 11.1941 +    else
 11.1942 +        return 0;
 11.1943 +}
 11.1944 +
 11.1945 +
 11.1946 +
 11.1947 +/*
 11.1948 +Read extra field from the current file (opened by unzOpenCurrentFile)
 11.1949 +This is the local-header version of the extra field (sometimes, there is
 11.1950 +more info in the local-header version than in the central-header)
 11.1951 +
 11.1952 +  if buf==NULL, it return the size of the local extra field that can be read
 11.1953 +
 11.1954 +  if buf!=NULL, len is the size of the buffer, the extra header is copied in
 11.1955 +    buf.
 11.1956 +  the return value is the number of bytes copied in buf, or (if <0)
 11.1957 +    the error code
 11.1958 +*/
 11.1959 +extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
 11.1960 +{
 11.1961 +    unz64_s* s;
 11.1962 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
 11.1963 +    uInt read_now;
 11.1964 +    ZPOS64_T size_to_read;
 11.1965 +
 11.1966 +    if (file==NULL)
 11.1967 +        return UNZ_PARAMERROR;
 11.1968 +    s=(unz64_s*)file;
 11.1969 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
 11.1970 +
 11.1971 +    if (pfile_in_zip_read_info==NULL)
 11.1972 +        return UNZ_PARAMERROR;
 11.1973 +
 11.1974 +    size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
 11.1975 +                pfile_in_zip_read_info->pos_local_extrafield);
 11.1976 +
 11.1977 +    if (buf==NULL)
 11.1978 +        return (int)size_to_read;
 11.1979 +
 11.1980 +    if (len>size_to_read)
 11.1981 +        read_now = (uInt)size_to_read;
 11.1982 +    else
 11.1983 +        read_now = (uInt)len ;
 11.1984 +
 11.1985 +    if (read_now==0)
 11.1986 +        return 0;
 11.1987 +
 11.1988 +    if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
 11.1989 +              pfile_in_zip_read_info->filestream,
 11.1990 +              pfile_in_zip_read_info->offset_local_extrafield +
 11.1991 +              pfile_in_zip_read_info->pos_local_extrafield,
 11.1992 +              ZLIB_FILEFUNC_SEEK_SET)!=0)
 11.1993 +        return UNZ_ERRNO;
 11.1994 +
 11.1995 +    if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
 11.1996 +              pfile_in_zip_read_info->filestream,
 11.1997 +              buf,read_now)!=read_now)
 11.1998 +        return UNZ_ERRNO;
 11.1999 +
 11.2000 +    return (int)read_now;
 11.2001 +}
 11.2002 +
 11.2003 +/*
 11.2004 +  Close the file in zip opened with unzOpenCurrentFile
 11.2005 +  Return UNZ_CRCERROR if all the file was read but the CRC is not good
 11.2006 +*/
 11.2007 +extern int ZEXPORT unzCloseCurrentFile (unzFile file)
 11.2008 +{
 11.2009 +    int err=UNZ_OK;
 11.2010 +
 11.2011 +    unz64_s* s;
 11.2012 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
 11.2013 +    if (file==NULL)
 11.2014 +        return UNZ_PARAMERROR;
 11.2015 +    s=(unz64_s*)file;
 11.2016 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
 11.2017 +
 11.2018 +    if (pfile_in_zip_read_info==NULL)
 11.2019 +        return UNZ_PARAMERROR;
 11.2020 +
 11.2021 +
 11.2022 +    if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
 11.2023 +        (!pfile_in_zip_read_info->raw))
 11.2024 +    {
 11.2025 +        if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
 11.2026 +            err=UNZ_CRCERROR;
 11.2027 +    }
 11.2028 +
 11.2029 +
 11.2030 +    TRYFREE(pfile_in_zip_read_info->read_buffer);
 11.2031 +    pfile_in_zip_read_info->read_buffer = NULL;
 11.2032 +    if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
 11.2033 +        inflateEnd(&pfile_in_zip_read_info->stream);
 11.2034 +#ifdef HAVE_BZIP2
 11.2035 +    else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
 11.2036 +        BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
 11.2037 +#endif
 11.2038 +
 11.2039 +
 11.2040 +    pfile_in_zip_read_info->stream_initialised = 0;
 11.2041 +    TRYFREE(pfile_in_zip_read_info);
 11.2042 +
 11.2043 +    s->pfile_in_zip_read=NULL;
 11.2044 +
 11.2045 +    return err;
 11.2046 +}
 11.2047 +
 11.2048 +
 11.2049 +/*
 11.2050 +  Get the global comment string of the ZipFile, in the szComment buffer.
 11.2051 +  uSizeBuf is the size of the szComment buffer.
 11.2052 +  return the number of byte copied or an error code <0
 11.2053 +*/
 11.2054 +extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
 11.2055 +{
 11.2056 +    unz64_s* s;
 11.2057 +    uLong uReadThis ;
 11.2058 +    if (file==NULL)
 11.2059 +        return (int)UNZ_PARAMERROR;
 11.2060 +    s=(unz64_s*)file;
 11.2061 +
 11.2062 +    uReadThis = uSizeBuf;
 11.2063 +    if (uReadThis>s->gi.size_comment)
 11.2064 +        uReadThis = s->gi.size_comment;
 11.2065 +
 11.2066 +    if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
 11.2067 +        return UNZ_ERRNO;
 11.2068 +
 11.2069 +    if (uReadThis>0)
 11.2070 +    {
 11.2071 +      *szComment='\0';
 11.2072 +      if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
 11.2073 +        return UNZ_ERRNO;
 11.2074 +    }
 11.2075 +
 11.2076 +    if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
 11.2077 +        *(szComment+s->gi.size_comment)='\0';
 11.2078 +    return (int)uReadThis;
 11.2079 +}
 11.2080 +
 11.2081 +/* Additions by RX '2004 */
 11.2082 +extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
 11.2083 +{
 11.2084 +    unz64_s* s;
 11.2085 +
 11.2086 +    if (file==NULL)
 11.2087 +          return 0; //UNZ_PARAMERROR;
 11.2088 +    s=(unz64_s*)file;
 11.2089 +    if (!s->current_file_ok)
 11.2090 +      return 0;
 11.2091 +    if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
 11.2092 +      if (s->num_file==s->gi.number_entry)
 11.2093 +         return 0;
 11.2094 +    return s->pos_in_central_dir;
 11.2095 +}
 11.2096 +
 11.2097 +extern uLong ZEXPORT unzGetOffset (unzFile file)
 11.2098 +{
 11.2099 +    ZPOS64_T offset64;
 11.2100 +
 11.2101 +    if (file==NULL)
 11.2102 +          return 0; //UNZ_PARAMERROR;
 11.2103 +    offset64 = unzGetOffset64(file);
 11.2104 +    return (uLong)offset64;
 11.2105 +}
 11.2106 +
 11.2107 +extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
 11.2108 +{
 11.2109 +    unz64_s* s;
 11.2110 +    int err;
 11.2111 +
 11.2112 +    if (file==NULL)
 11.2113 +        return UNZ_PARAMERROR;
 11.2114 +    s=(unz64_s*)file;
 11.2115 +
 11.2116 +    s->pos_in_central_dir = pos;
 11.2117 +    s->num_file = s->gi.number_entry;      /* hack */
 11.2118 +    err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
 11.2119 +                                              &s->cur_file_info_internal,
 11.2120 +                                              NULL,0,NULL,0,NULL,0);
 11.2121 +    s->current_file_ok = (err == UNZ_OK);
 11.2122 +    return err;
 11.2123 +}
 11.2124 +
 11.2125 +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
 11.2126 +{
 11.2127 +    return unzSetOffset64(file,pos);
 11.2128 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/test/zipcat/src/minizip/unzip.h	Mon Nov 04 06:46:17 2013 +0200
    12.3 @@ -0,0 +1,437 @@
    12.4 +/* unzip.h -- IO for uncompress .zip files using zlib
    12.5 +   Version 1.1, February 14h, 2010
    12.6 +   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
    12.7 +
    12.8 +         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
    12.9 +
   12.10 +         Modifications of Unzip for Zip64
   12.11 +         Copyright (C) 2007-2008 Even Rouault
   12.12 +
   12.13 +         Modifications for Zip64 support on both zip and unzip
   12.14 +         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
   12.15 +
   12.16 +         For more info read MiniZip_info.txt
   12.17 +
   12.18 +         ---------------------------------------------------------------------------------
   12.19 +
   12.20 +        Condition of use and distribution are the same than zlib :
   12.21 +
   12.22 +  This software is provided 'as-is', without any express or implied
   12.23 +  warranty.  In no event will the authors be held liable for any damages
   12.24 +  arising from the use of this software.
   12.25 +
   12.26 +  Permission is granted to anyone to use this software for any purpose,
   12.27 +  including commercial applications, and to alter it and redistribute it
   12.28 +  freely, subject to the following restrictions:
   12.29 +
   12.30 +  1. The origin of this software must not be misrepresented; you must not
   12.31 +     claim that you wrote the original software. If you use this software
   12.32 +     in a product, an acknowledgment in the product documentation would be
   12.33 +     appreciated but is not required.
   12.34 +  2. Altered source versions must be plainly marked as such, and must not be
   12.35 +     misrepresented as being the original software.
   12.36 +  3. This notice may not be removed or altered from any source distribution.
   12.37 +
   12.38 +  ---------------------------------------------------------------------------------
   12.39 +
   12.40 +        Changes
   12.41 +
   12.42 +        See header of unzip64.c
   12.43 +
   12.44 +*/
   12.45 +
   12.46 +#ifndef _unz64_H
   12.47 +#define _unz64_H
   12.48 +
   12.49 +#ifdef __cplusplus
   12.50 +extern "C" {
   12.51 +#endif
   12.52 +
   12.53 +#ifndef _ZLIB_H
   12.54 +#include "zlib.h"
   12.55 +#endif
   12.56 +
   12.57 +#ifndef  _ZLIBIOAPI_H
   12.58 +#include "ioapi.h"
   12.59 +#endif
   12.60 +
   12.61 +#ifdef HAVE_BZIP2
   12.62 +#include "bzlib.h"
   12.63 +#endif
   12.64 +
   12.65 +#define Z_BZIP2ED 12
   12.66 +
   12.67 +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
   12.68 +/* like the STRICT of WIN32, we define a pointer that cannot be converted
   12.69 +    from (void*) without cast */
   12.70 +typedef struct TagunzFile__ { int unused; } unzFile__;
   12.71 +typedef unzFile__ *unzFile;
   12.72 +#else
   12.73 +typedef voidp unzFile;
   12.74 +#endif
   12.75 +
   12.76 +
   12.77 +#define UNZ_OK                          (0)
   12.78 +#define UNZ_END_OF_LIST_OF_FILE         (-100)
   12.79 +#define UNZ_ERRNO                       (Z_ERRNO)
   12.80 +#define UNZ_EOF                         (0)
   12.81 +#define UNZ_PARAMERROR                  (-102)
   12.82 +#define UNZ_BADZIPFILE                  (-103)
   12.83 +#define UNZ_INTERNALERROR               (-104)
   12.84 +#define UNZ_CRCERROR                    (-105)
   12.85 +
   12.86 +/* tm_unz contain date/time info */
   12.87 +typedef struct tm_unz_s
   12.88 +{
   12.89 +    uInt tm_sec;            /* seconds after the minute - [0,59] */
   12.90 +    uInt tm_min;            /* minutes after the hour - [0,59] */
   12.91 +    uInt tm_hour;           /* hours since midnight - [0,23] */
   12.92 +    uInt tm_mday;           /* day of the month - [1,31] */
   12.93 +    uInt tm_mon;            /* months since January - [0,11] */
   12.94 +    uInt tm_year;           /* years - [1980..2044] */
   12.95 +} tm_unz;
   12.96 +
   12.97 +/* unz_global_info structure contain global data about the ZIPfile
   12.98 +   These data comes from the end of central dir */
   12.99 +typedef struct unz_global_info64_s
  12.100 +{
  12.101 +    ZPOS64_T number_entry;         /* total number of entries in
  12.102 +                                     the central dir on this disk */
  12.103 +    uLong size_comment;         /* size of the global comment of the zipfile */
  12.104 +} unz_global_info64;
  12.105 +
  12.106 +typedef struct unz_global_info_s
  12.107 +{
  12.108 +    uLong number_entry;         /* total number of entries in
  12.109 +                                     the central dir on this disk */
  12.110 +    uLong size_comment;         /* size of the global comment of the zipfile */
  12.111 +} unz_global_info;
  12.112 +
  12.113 +/* unz_file_info contain information about a file in the zipfile */
  12.114 +typedef struct unz_file_info64_s
  12.115 +{
  12.116 +    uLong version;              /* version made by                 2 bytes */
  12.117 +    uLong version_needed;       /* version needed to extract       2 bytes */
  12.118 +    uLong flag;                 /* general purpose bit flag        2 bytes */
  12.119 +    uLong compression_method;   /* compression method              2 bytes */
  12.120 +    uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
  12.121 +    uLong crc;                  /* crc-32                          4 bytes */
  12.122 +    ZPOS64_T compressed_size;   /* compressed size                 8 bytes */
  12.123 +    ZPOS64_T uncompressed_size; /* uncompressed size               8 bytes */
  12.124 +    uLong size_filename;        /* filename length                 2 bytes */
  12.125 +    uLong size_file_extra;      /* extra field length              2 bytes */
  12.126 +    uLong size_file_comment;    /* file comment length             2 bytes */
  12.127 +
  12.128 +    uLong disk_num_start;       /* disk number start               2 bytes */
  12.129 +    uLong internal_fa;          /* internal file attributes        2 bytes */
  12.130 +    uLong external_fa;          /* external file attributes        4 bytes */
  12.131 +
  12.132 +    tm_unz tmu_date;
  12.133 +} unz_file_info64;
  12.134 +
  12.135 +typedef struct unz_file_info_s
  12.136 +{
  12.137 +    uLong version;              /* version made by                 2 bytes */
  12.138 +    uLong version_needed;       /* version needed to extract       2 bytes */
  12.139 +    uLong flag;                 /* general purpose bit flag        2 bytes */
  12.140 +    uLong compression_method;   /* compression method              2 bytes */
  12.141 +    uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
  12.142 +    uLong crc;                  /* crc-32                          4 bytes */
  12.143 +    uLong compressed_size;      /* compressed size                 4 bytes */
  12.144 +    uLong uncompressed_size;    /* uncompressed size               4 bytes */
  12.145 +    uLong size_filename;        /* filename length                 2 bytes */
  12.146 +    uLong size_file_extra;      /* extra field length              2 bytes */
  12.147 +    uLong size_file_comment;    /* file comment length             2 bytes */
  12.148 +
  12.149 +    uLong disk_num_start;       /* disk number start               2 bytes */
  12.150 +    uLong internal_fa;          /* internal file attributes        2 bytes */
  12.151 +    uLong external_fa;          /* external file attributes        4 bytes */
  12.152 +
  12.153 +    tm_unz tmu_date;
  12.154 +} unz_file_info;
  12.155 +
  12.156 +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
  12.157 +                                                 const char* fileName2,
  12.158 +                                                 int iCaseSensitivity));
  12.159 +/*
  12.160 +   Compare two filename (fileName1,fileName2).
  12.161 +   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
  12.162 +   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
  12.163 +                                or strcasecmp)
  12.164 +   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
  12.165 +    (like 1 on Unix, 2 on Windows)
  12.166 +*/
  12.167 +
  12.168 +
  12.169 +extern unzFile ZEXPORT unzOpen OF((const char *path));
  12.170 +extern unzFile ZEXPORT unzOpen64 OF((const void *path));
  12.171 +/*
  12.172 +  Open a Zip file. path contain the full pathname (by example,
  12.173 +     on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
  12.174 +     "zlib/zlib113.zip".
  12.175 +     If the zipfile cannot be opened (file don't exist or in not valid), the
  12.176 +       return value is NULL.
  12.177 +     Else, the return value is a unzFile Handle, usable with other function
  12.178 +       of this unzip package.
  12.179 +     the "64" function take a const void* pointer, because the path is just the
  12.180 +       value passed to the open64_file_func callback.
  12.181 +     Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
  12.182 +       is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
  12.183 +       does not describe the reality
  12.184 +*/
  12.185 +
  12.186 +
  12.187 +extern unzFile ZEXPORT unzOpen2 OF((const char *path,
  12.188 +                                    zlib_filefunc_def* pzlib_filefunc_def));
  12.189 +/*
  12.190 +   Open a Zip file, like unzOpen, but provide a set of file low level API
  12.191 +      for read/write the zip file (see ioapi.h)
  12.192 +*/
  12.193 +
  12.194 +extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
  12.195 +                                    zlib_filefunc64_def* pzlib_filefunc_def));
  12.196 +/*
  12.197 +   Open a Zip file, like unz64Open, but provide a set of file low level API
  12.198 +      for read/write the zip file (see ioapi.h)
  12.199 +*/
  12.200 +
  12.201 +extern int ZEXPORT unzClose OF((unzFile file));
  12.202 +/*
  12.203 +  Close a ZipFile opened with unzOpen.
  12.204 +  If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
  12.205 +    these files MUST be closed with unzCloseCurrentFile before call unzClose.
  12.206 +  return UNZ_OK if there is no problem. */
  12.207 +
  12.208 +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
  12.209 +                                        unz_global_info *pglobal_info));
  12.210 +
  12.211 +extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
  12.212 +                                        unz_global_info64 *pglobal_info));
  12.213 +/*
  12.214 +  Write info about the ZipFile in the *pglobal_info structure.
  12.215 +  No preparation of the structure is needed
  12.216 +  return UNZ_OK if there is no problem. */
  12.217 +
  12.218 +
  12.219 +extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
  12.220 +                                           char *szComment,
  12.221 +                                           uLong uSizeBuf));
  12.222 +/*
  12.223 +  Get the global comment string of the ZipFile, in the szComment buffer.
  12.224 +  uSizeBuf is the size of the szComment buffer.
  12.225 +  return the number of byte copied or an error code <0
  12.226 +*/
  12.227 +
  12.228 +
  12.229 +/***************************************************************************/
  12.230 +/* Unzip package allow you browse the directory of the zipfile */
  12.231 +
  12.232 +extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
  12.233 +/*
  12.234 +  Set the current file of the zipfile to the first file.
  12.235 +  return UNZ_OK if there is no problem
  12.236 +*/
  12.237 +
  12.238 +extern int ZEXPORT unzGoToNextFile OF((unzFile file));
  12.239 +/*
  12.240 +  Set the current file of the zipfile to the next file.
  12.241 +  return UNZ_OK if there is no problem
  12.242 +  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
  12.243 +*/
  12.244 +
  12.245 +extern int ZEXPORT unzLocateFile OF((unzFile file,
  12.246 +                     const char *szFileName,
  12.247 +                     int iCaseSensitivity));
  12.248 +/*
  12.249 +  Try locate the file szFileName in the zipfile.
  12.250 +  For the iCaseSensitivity signification, see unzStringFileNameCompare
  12.251 +
  12.252 +  return value :
  12.253 +  UNZ_OK if the file is found. It becomes the current file.
  12.254 +  UNZ_END_OF_LIST_OF_FILE if the file is not found
  12.255 +*/
  12.256 +
  12.257 +
  12.258 +/* ****************************************** */
  12.259 +/* Ryan supplied functions */
  12.260 +/* unz_file_info contain information about a file in the zipfile */
  12.261 +typedef struct unz_file_pos_s
  12.262 +{
  12.263 +    uLong pos_in_zip_directory;   /* offset in zip file directory */
  12.264 +    uLong num_of_file;            /* # of file */
  12.265 +} unz_file_pos;
  12.266 +
  12.267 +extern int ZEXPORT unzGetFilePos(
  12.268 +    unzFile file,
  12.269 +    unz_file_pos* file_pos);
  12.270 +
  12.271 +extern int ZEXPORT unzGoToFilePos(
  12.272 +    unzFile file,
  12.273 +    unz_file_pos* file_pos);
  12.274 +
  12.275 +typedef struct unz64_file_pos_s
  12.276 +{
  12.277 +    ZPOS64_T pos_in_zip_directory;   /* offset in zip file directory */
  12.278 +    ZPOS64_T num_of_file;            /* # of file */
  12.279 +} unz64_file_pos;
  12.280 +
  12.281 +extern int ZEXPORT unzGetFilePos64(
  12.282 +    unzFile file,
  12.283 +    unz64_file_pos* file_pos);
  12.284 +
  12.285 +extern int ZEXPORT unzGoToFilePos64(
  12.286 +    unzFile file,
  12.287 +    const unz64_file_pos* file_pos);
  12.288 +
  12.289 +/* ****************************************** */
  12.290 +
  12.291 +extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
  12.292 +                         unz_file_info64 *pfile_info,
  12.293 +                         char *szFileName,
  12.294 +                         uLong fileNameBufferSize,
  12.295 +                         void *extraField,
  12.296 +                         uLong extraFieldBufferSize,
  12.297 +                         char *szComment,
  12.298 +                         uLong commentBufferSize));
  12.299 +
  12.300 +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
  12.301 +                         unz_file_info *pfile_info,
  12.302 +                         char *szFileName,
  12.303 +                         uLong fileNameBufferSize,
  12.304 +                         void *extraField,
  12.305 +                         uLong extraFieldBufferSize,
  12.306 +                         char *szComment,
  12.307 +                         uLong commentBufferSize));
  12.308 +/*
  12.309 +  Get Info about the current file
  12.310 +  if pfile_info!=NULL, the *pfile_info structure will contain somes info about
  12.311 +        the current file
  12.312 +  if szFileName!=NULL, the filemane string will be copied in szFileName
  12.313 +            (fileNameBufferSize is the size of the buffer)
  12.314 +  if extraField!=NULL, the extra field information will be copied in extraField
  12.315 +            (extraFieldBufferSize is the size of the buffer).
  12.316 +            This is the Central-header version of the extra field
  12.317 +  if szComment!=NULL, the comment string of the file will be copied in szComment
  12.318 +            (commentBufferSize is the size of the buffer)
  12.319 +*/
  12.320 +
  12.321 +
  12.322 +/** Addition for GDAL : START */
  12.323 +
  12.324 +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
  12.325 +
  12.326 +/** Addition for GDAL : END */
  12.327 +
  12.328 +
  12.329 +/***************************************************************************/
  12.330 +/* for reading the content of the current zipfile, you can open it, read data
  12.331 +   from it, and close it (you can close it before reading all the file)
  12.332 +   */
  12.333 +
  12.334 +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
  12.335 +/*
  12.336 +  Open for reading data the current file in the zipfile.
  12.337 +  If there is no error, the return value is UNZ_OK.
  12.338 +*/
  12.339 +
  12.340 +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
  12.341 +                                                  const char* password));
  12.342 +/*
  12.343 +  Open for reading data the current file in the zipfile.
  12.344 +  password is a crypting password
  12.345 +  If there is no error, the return value is UNZ_OK.
  12.346 +*/
  12.347 +
  12.348 +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
  12.349 +                                           int* method,
  12.350 +                                           int* level,
  12.351 +                                           int raw));
  12.352 +/*
  12.353 +  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
  12.354 +    if raw==1
  12.355 +  *method will receive method of compression, *level will receive level of
  12.356 +     compression
  12.357 +  note : you can set level parameter as NULL (if you did not want known level,
  12.358 +         but you CANNOT set method parameter as NULL
  12.359 +*/
  12.360 +
  12.361 +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
  12.362 +                                           int* method,
  12.363 +                                           int* level,
  12.364 +                                           int raw,
  12.365 +                                           const char* password));
  12.366 +/*
  12.367 +  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
  12.368 +    if raw==1
  12.369 +  *method will receive method of compression, *level will receive level of
  12.370 +     compression
  12.371 +  note : you can set level parameter as NULL (if you did not want known level,
  12.372 +         but you CANNOT set method parameter as NULL
  12.373 +*/
  12.374 +
  12.375 +
  12.376 +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
  12.377 +/*
  12.378 +  Close the file in zip opened with unzOpenCurrentFile
  12.379 +  Return UNZ_CRCERROR if all the file was read but the CRC is not good
  12.380 +*/
  12.381 +
  12.382 +extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
  12.383 +                      voidp buf,
  12.384 +                      unsigned len));
  12.385 +/*
  12.386 +  Read bytes from the current file (opened by unzOpenCurrentFile)
  12.387 +  buf contain buffer where data must be copied
  12.388 +  len the size of buf.
  12.389 +
  12.390 +  return the number of byte copied if somes bytes are copied
  12.391 +  return 0 if the end of file was reached
  12.392 +  return <0 with error code if there is an error
  12.393 +    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
  12.394 +*/
  12.395 +
  12.396 +extern z_off_t ZEXPORT unztell OF((unzFile file));
  12.397 +
  12.398 +extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
  12.399 +/*
  12.400 +  Give the current position in uncompressed data
  12.401 +*/
  12.402 +
  12.403 +extern int ZEXPORT unzeof OF((unzFile file));
  12.404 +/*
  12.405 +  return 1 if the end of file was reached, 0 elsewhere
  12.406 +*/
  12.407 +
  12.408 +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
  12.409 +                                             voidp buf,
  12.410 +                                             unsigned len));
  12.411 +/*
  12.412 +  Read extra field from the current file (opened by unzOpenCurrentFile)
  12.413 +  This is the local-header version of the extra field (sometimes, there is
  12.414 +    more info in the local-header version than in the central-header)
  12.415 +
  12.416 +  if buf==NULL, it return the size of the local extra field
  12.417 +
  12.418 +  if buf!=NULL, len is the size of the buffer, the extra header is copied in
  12.419 +    buf.
  12.420 +  the return value is the number of bytes copied in buf, or (if <0)
  12.421 +    the error code
  12.422 +*/
  12.423 +
  12.424 +/***************************************************************************/
  12.425 +
  12.426 +/* Get the current file offset */
  12.427 +extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
  12.428 +extern uLong ZEXPORT unzGetOffset (unzFile file);
  12.429 +
  12.430 +/* Set the current file offset */
  12.431 +extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
  12.432 +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
  12.433 +
  12.434 +
  12.435 +
  12.436 +#ifdef __cplusplus
  12.437 +}
  12.438 +#endif
  12.439 +
  12.440 +#endif /* _unz64_H */
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/test/zipcat/src/minizip/zip.c	Mon Nov 04 06:46:17 2013 +0200
    13.3 @@ -0,0 +1,2007 @@
    13.4 +/* zip.c -- IO on .zip files using zlib
    13.5 +   Version 1.1, February 14h, 2010
    13.6 +   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
    13.7 +
    13.8 +         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
    13.9 +
   13.10 +         Modifications for Zip64 support
   13.11 +         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
   13.12 +
   13.13 +         For more info read MiniZip_info.txt
   13.14 +
   13.15 +         Changes
   13.16 +   Oct-2009 - Mathias Svensson - Remove old C style function prototypes
   13.17 +   Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives
   13.18 +   Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions.
   13.19 +   Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data
   13.20 +                                 It is used when recreting zip archive with RAW when deleting items from a zip.
   13.21 +                                 ZIP64 data is automaticly added to items that needs it, and existing ZIP64 data need to be removed.
   13.22 +   Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required)
   13.23 +   Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
   13.24 +
   13.25 +*/
   13.26 +
   13.27 +
   13.28 +#include <stdio.h>
   13.29 +#include <stdlib.h>
   13.30 +#include <string.h>
   13.31 +#include <time.h>
   13.32 +#include "zlib.h"
   13.33 +#include "zip.h"
   13.34 +
   13.35 +#ifdef STDC
   13.36 +#  include <stddef.h>
   13.37 +#  include <string.h>
   13.38 +#  include <stdlib.h>
   13.39 +#endif
   13.40 +#ifdef NO_ERRNO_H
   13.41 +    extern int errno;
   13.42 +#else
   13.43 +#   include <errno.h>
   13.44 +#endif
   13.45 +
   13.46 +
   13.47 +#ifndef local
   13.48 +#  define local static
   13.49 +#endif
   13.50 +/* compile with -Dlocal if your debugger can't find static symbols */
   13.51 +
   13.52 +#ifndef VERSIONMADEBY
   13.53 +# define VERSIONMADEBY   (0x0) /* platform depedent */
   13.54 +#endif
   13.55 +
   13.56 +#ifndef Z_BUFSIZE
   13.57 +#define Z_BUFSIZE (64*1024) //(16384)
   13.58 +#endif
   13.59 +
   13.60 +#ifndef Z_MAXFILENAMEINZIP
   13.61 +#define Z_MAXFILENAMEINZIP (256)
   13.62 +#endif
   13.63 +
   13.64 +#ifndef ALLOC
   13.65 +# define ALLOC(size) (malloc(size))
   13.66 +#endif
   13.67 +#ifndef TRYFREE
   13.68 +# define TRYFREE(p) {if (p) free(p);}
   13.69 +#endif
   13.70 +
   13.71 +/*
   13.72 +#define SIZECENTRALDIRITEM (0x2e)
   13.73 +#define SIZEZIPLOCALHEADER (0x1e)
   13.74 +*/
   13.75 +
   13.76 +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
   13.77 +
   13.78 +
   13.79 +// NOT sure that this work on ALL platform
   13.80 +#define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32))
   13.81 +
   13.82 +#ifndef SEEK_CUR
   13.83 +#define SEEK_CUR    1
   13.84 +#endif
   13.85 +
   13.86 +#ifndef SEEK_END
   13.87 +#define SEEK_END    2
   13.88 +#endif
   13.89 +
   13.90 +#ifndef SEEK_SET
   13.91 +#define SEEK_SET    0
   13.92 +#endif
   13.93 +
   13.94 +#ifndef DEF_MEM_LEVEL
   13.95 +#if MAX_MEM_LEVEL >= 8
   13.96 +#  define DEF_MEM_LEVEL 8
   13.97 +#else
   13.98 +#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
   13.99 +#endif
  13.100 +#endif
  13.101 +const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
  13.102 +
  13.103 +
  13.104 +#define SIZEDATA_INDATABLOCK (4096-(4*4))
  13.105 +
  13.106 +#define LOCALHEADERMAGIC    (0x04034b50)
  13.107 +#define CENTRALHEADERMAGIC  (0x02014b50)
  13.108 +#define ENDHEADERMAGIC      (0x06054b50)
  13.109 +#define ZIP64ENDHEADERMAGIC      (0x6064b50)
  13.110 +#define ZIP64ENDLOCHEADERMAGIC   (0x7064b50)
  13.111 +
  13.112 +#define FLAG_LOCALHEADER_OFFSET (0x06)
  13.113 +#define CRC_LOCALHEADER_OFFSET  (0x0e)
  13.114 +
  13.115 +#define SIZECENTRALHEADER (0x2e) /* 46 */
  13.116 +
  13.117 +typedef struct linkedlist_datablock_internal_s
  13.118 +{
  13.119 +  struct linkedlist_datablock_internal_s* next_datablock;
  13.120 +  uLong  avail_in_this_block;
  13.121 +  uLong  filled_in_this_block;
  13.122 +  uLong  unused; /* for future use and alignement */
  13.123 +  unsigned char data[SIZEDATA_INDATABLOCK];
  13.124 +} linkedlist_datablock_internal;
  13.125 +
  13.126 +typedef struct linkedlist_data_s
  13.127 +{
  13.128 +    linkedlist_datablock_internal* first_block;
  13.129 +    linkedlist_datablock_internal* last_block;
  13.130 +} linkedlist_data;
  13.131 +
  13.132 +
  13.133 +typedef struct
  13.134 +{
  13.135 +    z_stream stream;            /* zLib stream structure for inflate */
  13.136 +#ifdef HAVE_BZIP2
  13.137 +    bz_stream bstream;          /* bzLib stream structure for bziped */
  13.138 +#endif
  13.139 +
  13.140 +    int  stream_initialised;    /* 1 is stream is initialised */
  13.141 +    uInt pos_in_buffered_data;  /* last written byte in buffered_data */
  13.142 +
  13.143 +    ZPOS64_T pos_local_header;     /* offset of the local header of the file
  13.144 +                                     currenty writing */
  13.145 +    char* central_header;       /* central header data for the current file */
  13.146 +    uLong size_centralExtra;
  13.147 +    uLong size_centralheader;   /* size of the central header for cur file */
  13.148 +    uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */
  13.149 +    uLong flag;                 /* flag of the file currently writing */
  13.150 +
  13.151 +    int  method;                /* compression method of file currenty wr.*/
  13.152 +    int  raw;                   /* 1 for directly writing raw data */
  13.153 +    Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
  13.154 +    uLong dosDate;
  13.155 +    uLong crc32;
  13.156 +    int  encrypt;
  13.157 +    int  zip64;               /* Add ZIP64 extened information in the extra field */
  13.158 +    ZPOS64_T pos_zip64extrainfo;
  13.159 +    ZPOS64_T totalCompressedData;
  13.160 +    ZPOS64_T totalUncompressedData;
  13.161 +#ifndef NOCRYPT
  13.162 +    unsigned long keys[3];     /* keys defining the pseudo-random sequence */
  13.163 +    const z_crc_t* pcrc_32_tab;
  13.164 +    int crypt_header_size;
  13.165 +#endif
  13.166 +} curfile64_info;
  13.167 +
  13.168 +typedef struct
  13.169 +{
  13.170 +    zlib_filefunc64_32_def z_filefunc;
  13.171 +    voidpf filestream;        /* io structore of the zipfile */
  13.172 +    linkedlist_data central_dir;/* datablock with central dir in construction*/
  13.173 +    int  in_opened_file_inzip;  /* 1 if a file in the zip is currently writ.*/
  13.174 +    curfile64_info ci;            /* info on the file curretly writing */
  13.175 +
  13.176 +    ZPOS64_T begin_pos;            /* position of the beginning of the zipfile */
  13.177 +    ZPOS64_T add_position_when_writting_offset;
  13.178 +    ZPOS64_T number_entry;
  13.179 +
  13.180 +#ifndef NO_ADDFILEINEXISTINGZIP
  13.181 +    char *globalcomment;
  13.182 +#endif
  13.183 +
  13.184 +} zip64_internal;
  13.185 +
  13.186 +
  13.187 +#ifndef NOCRYPT
  13.188 +#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
  13.189 +#include "crypt.h"
  13.190 +#endif
  13.191 +
  13.192 +local linkedlist_datablock_internal* allocate_new_datablock()
  13.193 +{
  13.194 +    linkedlist_datablock_internal* ldi;
  13.195 +    ldi = (linkedlist_datablock_internal*)
  13.196 +                 ALLOC(sizeof(linkedlist_datablock_internal));
  13.197 +    if (ldi!=NULL)
  13.198 +    {
  13.199 +        ldi->next_datablock = NULL ;
  13.200 +        ldi->filled_in_this_block = 0 ;
  13.201 +        ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
  13.202 +    }
  13.203 +    return ldi;
  13.204 +}
  13.205 +
  13.206 +local void free_datablock(linkedlist_datablock_internal* ldi)
  13.207 +{
  13.208 +    while (ldi!=NULL)
  13.209 +    {
  13.210 +        linkedlist_datablock_internal* ldinext = ldi->next_datablock;
  13.211 +        TRYFREE(ldi);
  13.212 +        ldi = ldinext;
  13.213 +    }
  13.214 +}
  13.215 +
  13.216 +local void init_linkedlist(linkedlist_data* ll)
  13.217 +{
  13.218 +    ll->first_block = ll->last_block = NULL;
  13.219 +}
  13.220 +
  13.221 +local void free_linkedlist(linkedlist_data* ll)
  13.222 +{
  13.223 +    free_datablock(ll->first_block);
  13.224 +    ll->first_block = ll->last_block = NULL;
  13.225 +}
  13.226 +
  13.227 +
  13.228 +local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
  13.229 +{
  13.230 +    linkedlist_datablock_internal* ldi;
  13.231 +    const unsigned char* from_copy;
  13.232 +
  13.233 +    if (ll==NULL)
  13.234 +        return ZIP_INTERNALERROR;
  13.235 +
  13.236 +    if (ll->last_block == NULL)
  13.237 +    {
  13.238 +        ll->first_block = ll->last_block = allocate_new_datablock();
  13.239 +        if (ll->first_block == NULL)
  13.240 +            return ZIP_INTERNALERROR;
  13.241 +    }
  13.242 +
  13.243 +    ldi = ll->last_block;
  13.244 +    from_copy = (unsigned char*)buf;
  13.245 +
  13.246 +    while (len>0)
  13.247 +    {
  13.248 +        uInt copy_this;
  13.249 +        uInt i;
  13.250 +        unsigned char* to_copy;
  13.251 +
  13.252 +        if (ldi->avail_in_this_block==0)
  13.253 +        {
  13.254 +            ldi->next_datablock = allocate_new_datablock();
  13.255 +            if (ldi->next_datablock == NULL)
  13.256 +                return ZIP_INTERNALERROR;
  13.257 +            ldi = ldi->next_datablock ;
  13.258 +            ll->last_block = ldi;
  13.259 +        }
  13.260 +
  13.261 +        if (ldi->avail_in_this_block < len)
  13.262 +            copy_this = (uInt)ldi->avail_in_this_block;
  13.263 +        else
  13.264 +            copy_this = (uInt)len;
  13.265 +
  13.266 +        to_copy = &(ldi->data[ldi->filled_in_this_block]);
  13.267 +
  13.268 +        for (i=0;i<copy_this;i++)
  13.269 +            *(to_copy+i)=*(from_copy+i);
  13.270 +
  13.271 +        ldi->filled_in_this_block += copy_this;
  13.272 +        ldi->avail_in_this_block -= copy_this;
  13.273 +        from_copy += copy_this ;
  13.274 +        len -= copy_this;
  13.275 +    }
  13.276 +    return ZIP_OK;
  13.277 +}
  13.278 +
  13.279 +
  13.280 +
  13.281 +/****************************************************************************/
  13.282 +
  13.283 +#ifndef NO_ADDFILEINEXISTINGZIP
  13.284 +/* ===========================================================================
  13.285 +   Inputs a long in LSB order to the given file
  13.286 +   nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T)
  13.287 +*/
  13.288 +
  13.289 +local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte));
  13.290 +local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
  13.291 +{
  13.292 +    unsigned char buf[8];
  13.293 +    int n;
  13.294 +    for (n = 0; n < nbByte; n++)
  13.295 +    {
  13.296 +        buf[n] = (unsigned char)(x & 0xff);
  13.297 +        x >>= 8;
  13.298 +    }
  13.299 +    if (x != 0)
  13.300 +      {     /* data overflow - hack for ZIP64 (X Roche) */
  13.301 +      for (n = 0; n < nbByte; n++)
  13.302 +        {
  13.303 +          buf[n] = 0xff;
  13.304 +        }
  13.305 +      }
  13.306 +
  13.307 +    if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
  13.308 +        return ZIP_ERRNO;
  13.309 +    else
  13.310 +        return ZIP_OK;
  13.311 +}
  13.312 +
  13.313 +local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte));
  13.314 +local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte)
  13.315 +{
  13.316 +    unsigned char* buf=(unsigned char*)dest;
  13.317 +    int n;
  13.318 +    for (n = 0; n < nbByte; n++) {
  13.319 +        buf[n] = (unsigned char)(x & 0xff);
  13.320 +        x >>= 8;
  13.321 +    }
  13.322 +
  13.323 +    if (x != 0)
  13.324 +    {     /* data overflow - hack for ZIP64 */
  13.325 +       for (n = 0; n < nbByte; n++)
  13.326 +       {
  13.327 +          buf[n] = 0xff;
  13.328 +       }
  13.329 +    }
  13.330 +}
  13.331 +
  13.332 +/****************************************************************************/
  13.333 +
  13.334 +
  13.335 +local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm)
  13.336 +{
  13.337 +    uLong year = (uLong)ptm->tm_year;
  13.338 +    if (year>=1980)
  13.339 +        year-=1980;
  13.340 +    else if (year>=80)
  13.341 +        year-=80;
  13.342 +    return
  13.343 +      (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
  13.344 +        ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
  13.345 +}
  13.346 +
  13.347 +
  13.348 +/****************************************************************************/
  13.349 +
  13.350 +local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi));
  13.351 +
  13.352 +local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi)
  13.353 +{
  13.354 +    unsigned char c;
  13.355 +    int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
  13.356 +    if (err==1)
  13.357 +    {
  13.358 +        *pi = (int)c;
  13.359 +        return ZIP_OK;
  13.360 +    }
  13.361 +    else
  13.362 +    {
  13.363 +        if (ZERROR64(*pzlib_filefunc_def,filestream))
  13.364 +            return ZIP_ERRNO;
  13.365 +        else
  13.366 +            return ZIP_EOF;
  13.367 +    }
  13.368 +}
  13.369 +
  13.370 +
  13.371 +/* ===========================================================================
  13.372 +   Reads a long in LSB order from the given gz_stream. Sets
  13.373 +*/
  13.374 +local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
  13.375 +
  13.376 +local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
  13.377 +{
  13.378 +    uLong x ;
  13.379 +    int i = 0;
  13.380 +    int err;
  13.381 +
  13.382 +    err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.383 +    x = (uLong)i;
  13.384 +
  13.385 +    if (err==ZIP_OK)
  13.386 +        err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.387 +    x += ((uLong)i)<<8;
  13.388 +
  13.389 +    if (err==ZIP_OK)
  13.390 +        *pX = x;
  13.391 +    else
  13.392 +        *pX = 0;
  13.393 +    return err;
  13.394 +}
  13.395 +
  13.396 +local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
  13.397 +
  13.398 +local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
  13.399 +{
  13.400 +    uLong x ;
  13.401 +    int i = 0;
  13.402 +    int err;
  13.403 +
  13.404 +    err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.405 +    x = (uLong)i;
  13.406 +
  13.407 +    if (err==ZIP_OK)
  13.408 +        err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.409 +    x += ((uLong)i)<<8;
  13.410 +
  13.411 +    if (err==ZIP_OK)
  13.412 +        err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.413 +    x += ((uLong)i)<<16;
  13.414 +
  13.415 +    if (err==ZIP_OK)
  13.416 +        err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.417 +    x += ((uLong)i)<<24;
  13.418 +
  13.419 +    if (err==ZIP_OK)
  13.420 +        *pX = x;
  13.421 +    else
  13.422 +        *pX = 0;
  13.423 +    return err;
  13.424 +}
  13.425 +
  13.426 +local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX));
  13.427 +
  13.428 +
  13.429 +local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
  13.430 +{
  13.431 +  ZPOS64_T x;
  13.432 +  int i = 0;
  13.433 +  int err;
  13.434 +
  13.435 +  err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.436 +  x = (ZPOS64_T)i;
  13.437 +
  13.438 +  if (err==ZIP_OK)
  13.439 +    err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.440 +  x += ((ZPOS64_T)i)<<8;
  13.441 +
  13.442 +  if (err==ZIP_OK)
  13.443 +    err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.444 +  x += ((ZPOS64_T)i)<<16;
  13.445 +
  13.446 +  if (err==ZIP_OK)
  13.447 +    err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.448 +  x += ((ZPOS64_T)i)<<24;
  13.449 +
  13.450 +  if (err==ZIP_OK)
  13.451 +    err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.452 +  x += ((ZPOS64_T)i)<<32;
  13.453 +
  13.454 +  if (err==ZIP_OK)
  13.455 +    err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.456 +  x += ((ZPOS64_T)i)<<40;
  13.457 +
  13.458 +  if (err==ZIP_OK)
  13.459 +    err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.460 +  x += ((ZPOS64_T)i)<<48;
  13.461 +
  13.462 +  if (err==ZIP_OK)
  13.463 +    err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
  13.464 +  x += ((ZPOS64_T)i)<<56;
  13.465 +
  13.466 +  if (err==ZIP_OK)
  13.467 +    *pX = x;
  13.468 +  else
  13.469 +    *pX = 0;
  13.470 +
  13.471 +  return err;
  13.472 +}
  13.473 +
  13.474 +#ifndef BUFREADCOMMENT
  13.475 +#define BUFREADCOMMENT (0x400)
  13.476 +#endif
  13.477 +/*
  13.478 +  Locate the Central directory of a zipfile (at the end, just before
  13.479 +    the global comment)
  13.480 +*/
  13.481 +local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
  13.482 +
  13.483 +local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
  13.484 +{
  13.485 +  unsigned char* buf;
  13.486 +  ZPOS64_T uSizeFile;
  13.487 +  ZPOS64_T uBackRead;
  13.488 +  ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
  13.489 +  ZPOS64_T uPosFound=0;
  13.490 +
  13.491 +  if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
  13.492 +    return 0;
  13.493 +
  13.494 +
  13.495 +  uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
  13.496 +
  13.497 +  if (uMaxBack>uSizeFile)
  13.498 +    uMaxBack = uSizeFile;
  13.499 +
  13.500 +  buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
  13.501 +  if (buf==NULL)
  13.502 +    return 0;
  13.503 +
  13.504 +  uBackRead = 4;
  13.505 +  while (uBackRead<uMaxBack)
  13.506 +  {
  13.507 +    uLong uReadSize;
  13.508 +    ZPOS64_T uReadPos ;
  13.509 +    int i;
  13.510 +    if (uBackRead+BUFREADCOMMENT>uMaxBack)
  13.511 +      uBackRead = uMaxBack;
  13.512 +    else
  13.513 +      uBackRead+=BUFREADCOMMENT;
  13.514 +    uReadPos = uSizeFile-uBackRead ;
  13.515 +
  13.516 +    uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
  13.517 +      (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
  13.518 +    if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
  13.519 +      break;
  13.520 +
  13.521 +    if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
  13.522 +      break;
  13.523 +
  13.524 +    for (i=(int)uReadSize-3; (i--)>0;)
  13.525 +      if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
  13.526 +        ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
  13.527 +      {
  13.528 +        uPosFound = uReadPos+i;
  13.529 +        break;
  13.530 +      }
  13.531 +
  13.532 +      if (uPosFound!=0)
  13.533 +        break;
  13.534 +  }
  13.535 +  TRYFREE(buf);
  13.536 +  return uPosFound;
  13.537 +}
  13.538 +
  13.539 +/*
  13.540 +Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before
  13.541 +the global comment)
  13.542 +*/
  13.543 +local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
  13.544 +
  13.545 +local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
  13.546 +{
  13.547 +  unsigned char* buf;
  13.548 +  ZPOS64_T uSizeFile;
  13.549 +  ZPOS64_T uBackRead;
  13.550 +  ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
  13.551 +  ZPOS64_T uPosFound=0;
  13.552 +  uLong uL;
  13.553 +  ZPOS64_T relativeOffset;
  13.554 +
  13.555 +  if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
  13.556 +    return 0;
  13.557 +
  13.558 +  uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
  13.559 +
  13.560 +  if (uMaxBack>uSizeFile)
  13.561 +    uMaxBack = uSizeFile;
  13.562 +
  13.563 +  buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
  13.564 +  if (buf==NULL)
  13.565 +    return 0;
  13.566 +
  13.567 +  uBackRead = 4;
  13.568 +  while (uBackRead<uMaxBack)
  13.569 +  {
  13.570 +    uLong uReadSize;
  13.571 +    ZPOS64_T uReadPos;
  13.572 +    int i;
  13.573 +    if (uBackRead+BUFREADCOMMENT>uMaxBack)
  13.574 +      uBackRead = uMaxBack;
  13.575 +    else
  13.576 +      uBackRead+=BUFREADCOMMENT;
  13.577 +    uReadPos = uSizeFile-uBackRead ;
  13.578 +
  13.579 +    uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
  13.580 +      (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
  13.581 +    if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
  13.582 +      break;
  13.583 +
  13.584 +    if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
  13.585 +      break;
  13.586 +
  13.587 +    for (i=(int)uReadSize-3; (i--)>0;)
  13.588 +    {
  13.589 +      // Signature "0x07064b50" Zip64 end of central directory locater
  13.590 +      if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
  13.591 +      {
  13.592 +        uPosFound = uReadPos+i;
  13.593 +        break;
  13.594 +      }
  13.595 +    }
  13.596 +
  13.597 +      if (uPosFound!=0)
  13.598 +        break;
  13.599 +  }
  13.600 +
  13.601 +  TRYFREE(buf);
  13.602 +  if (uPosFound == 0)
  13.603 +    return 0;
  13.604 +
  13.605 +  /* Zip64 end of central directory locator */
  13.606 +  if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
  13.607 +    return 0;
  13.608 +
  13.609 +  /* the signature, already checked */
  13.610 +  if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
  13.611 +    return 0;
  13.612 +
  13.613 +  /* number of the disk with the start of the zip64 end of  central directory */
  13.614 +  if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
  13.615 +    return 0;
  13.616 +  if (uL != 0)
  13.617 +    return 0;
  13.618 +
  13.619 +  /* relative offset of the zip64 end of central directory record */
  13.620 +  if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK)
  13.621 +    return 0;
  13.622 +
  13.623 +  /* total number of disks */
  13.624 +  if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
  13.625 +    return 0;
  13.626 +  if (uL != 1)
  13.627 +    return 0;
  13.628 +
  13.629 +  /* Goto Zip64 end of central directory record */
  13.630 +  if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
  13.631 +    return 0;
  13.632 +
  13.633 +  /* the signature */
  13.634 +  if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
  13.635 +    return 0;
  13.636 +
  13.637 +  if (uL != 0x06064b50) // signature of 'Zip64 end of central directory'
  13.638 +    return 0;
  13.639 +
  13.640 +  return relativeOffset;
  13.641 +}
  13.642 +
  13.643 +int LoadCentralDirectoryRecord(zip64_internal* pziinit)
  13.644 +{
  13.645 +  int err=ZIP_OK;
  13.646 +  ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
  13.647 +
  13.648 +  ZPOS64_T size_central_dir;     /* size of the central directory  */
  13.649 +  ZPOS64_T offset_central_dir;   /* offset of start of central directory */
  13.650 +  ZPOS64_T central_pos;
  13.651 +  uLong uL;
  13.652 +
  13.653 +  uLong number_disk;          /* number of the current dist, used for
  13.654 +                              spaning ZIP, unsupported, always 0*/
  13.655 +  uLong number_disk_with_CD;  /* number the the disk with central dir, used
  13.656 +                              for spaning ZIP, unsupported, always 0*/
  13.657 +  ZPOS64_T number_entry;
  13.658 +  ZPOS64_T number_entry_CD;      /* total number of entries in
  13.659 +                                the central dir
  13.660 +                                (same than number_entry on nospan) */
  13.661 +  uLong VersionMadeBy;
  13.662 +  uLong VersionNeeded;
  13.663 +  uLong size_comment;
  13.664 +
  13.665 +  int hasZIP64Record = 0;
  13.666 +
  13.667 +  // check first if we find a ZIP64 record
  13.668 +  central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream);
  13.669 +  if(central_pos > 0)
  13.670 +  {
  13.671 +    hasZIP64Record = 1;
  13.672 +  }
  13.673 +  else if(central_pos == 0)
  13.674 +  {
  13.675 +    central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream);
  13.676 +  }
  13.677 +
  13.678 +/* disable to allow appending to empty ZIP archive
  13.679 +        if (central_pos==0)
  13.680 +            err=ZIP_ERRNO;
  13.681 +*/
  13.682 +
  13.683 +  if(hasZIP64Record)
  13.684 +  {
  13.685 +    ZPOS64_T sizeEndOfCentralDirectory;
  13.686 +    if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
  13.687 +      err=ZIP_ERRNO;
  13.688 +
  13.689 +    /* the signature, already checked */
  13.690 +    if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
  13.691 +      err=ZIP_ERRNO;
  13.692 +
  13.693 +    /* size of zip64 end of central directory record */
  13.694 +    if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK)
  13.695 +      err=ZIP_ERRNO;
  13.696 +
  13.697 +    /* version made by */
  13.698 +    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK)
  13.699 +      err=ZIP_ERRNO;
  13.700 +
  13.701 +    /* version needed to extract */
  13.702 +    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK)
  13.703 +      err=ZIP_ERRNO;
  13.704 +
  13.705 +    /* number of this disk */
  13.706 +    if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
  13.707 +      err=ZIP_ERRNO;
  13.708 +
  13.709 +    /* number of the disk with the start of the central directory */
  13.710 +    if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
  13.711 +      err=ZIP_ERRNO;
  13.712 +
  13.713 +    /* total number of entries in the central directory on this disk */
  13.714 +    if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK)
  13.715 +      err=ZIP_ERRNO;
  13.716 +
  13.717 +    /* total number of entries in the central directory */
  13.718 +    if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK)
  13.719 +      err=ZIP_ERRNO;
  13.720 +
  13.721 +    if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
  13.722 +      err=ZIP_BADZIPFILE;
  13.723 +
  13.724 +    /* size of the central directory */
  13.725 +    if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK)
  13.726 +      err=ZIP_ERRNO;
  13.727 +
  13.728 +    /* offset of start of central directory with respect to the
  13.729 +    starting disk number */
  13.730 +    if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK)
  13.731 +      err=ZIP_ERRNO;
  13.732 +
  13.733 +    // TODO..
  13.734 +    // read the comment from the standard central header.
  13.735 +    size_comment = 0;
  13.736 +  }
  13.737 +  else
  13.738 +  {
  13.739 +    // Read End of central Directory info
  13.740 +    if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
  13.741 +      err=ZIP_ERRNO;
  13.742 +
  13.743 +    /* the signature, already checked */
  13.744 +    if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
  13.745 +      err=ZIP_ERRNO;
  13.746 +
  13.747 +    /* number of this disk */
  13.748 +    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
  13.749 +      err=ZIP_ERRNO;
  13.750 +
  13.751 +    /* number of the disk with the start of the central directory */
  13.752 +    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
  13.753 +      err=ZIP_ERRNO;
  13.754 +
  13.755 +    /* total number of entries in the central dir on this disk */
  13.756 +    number_entry = 0;
  13.757 +    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
  13.758 +      err=ZIP_ERRNO;
  13.759 +    else
  13.760 +      number_entry = uL;
  13.761 +
  13.762 +    /* total number of entries in the central dir */
  13.763 +    number_entry_CD = 0;
  13.764 +    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
  13.765 +      err=ZIP_ERRNO;
  13.766 +    else
  13.767 +      number_entry_CD = uL;
  13.768 +
  13.769 +    if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
  13.770 +      err=ZIP_BADZIPFILE;
  13.771 +
  13.772 +    /* size of the central directory */
  13.773 +    size_central_dir = 0;
  13.774 +    if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
  13.775 +      err=ZIP_ERRNO;
  13.776 +    else
  13.777 +      size_central_dir = uL;
  13.778 +
  13.779 +    /* offset of start of central directory with respect to the starting disk number */
  13.780 +    offset_central_dir = 0;
  13.781 +    if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
  13.782 +      err=ZIP_ERRNO;
  13.783 +    else
  13.784 +      offset_central_dir = uL;
  13.785 +
  13.786 +
  13.787 +    /* zipfile global comment length */
  13.788 +    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK)
  13.789 +      err=ZIP_ERRNO;
  13.790 +  }
  13.791 +
  13.792 +  if ((central_pos<offset_central_dir+size_central_dir) &&
  13.793 +    (err==ZIP_OK))
  13.794 +    err=ZIP_BADZIPFILE;
  13.795 +
  13.796 +  if (err!=ZIP_OK)
  13.797 +  {
  13.798 +    ZCLOSE64(pziinit->z_filefunc, pziinit->filestream);
  13.799 +    return ZIP_ERRNO;
  13.800 +  }
  13.801 +
  13.802 +  if (size_comment>0)
  13.803 +  {
  13.804 +    pziinit->globalcomment = (char*)ALLOC(size_comment+1);
  13.805 +    if (pziinit->globalcomment)
  13.806 +    {
  13.807 +      size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment);
  13.808 +      pziinit->globalcomment[size_comment]=0;
  13.809 +    }
  13.810 +  }
  13.811 +
  13.812 +  byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir);
  13.813 +  pziinit->add_position_when_writting_offset = byte_before_the_zipfile;
  13.814 +
  13.815 +  {
  13.816 +    ZPOS64_T size_central_dir_to_read = size_central_dir;
  13.817 +    size_t buf_size = SIZEDATA_INDATABLOCK;
  13.818 +    void* buf_read = (void*)ALLOC(buf_size);
  13.819 +    if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
  13.820 +      err=ZIP_ERRNO;
  13.821 +
  13.822 +    while ((size_central_dir_to_read>0) && (err==ZIP_OK))
  13.823 +    {
  13.824 +      ZPOS64_T read_this = SIZEDATA_INDATABLOCK;
  13.825 +      if (read_this > size_central_dir_to_read)
  13.826 +        read_this = size_central_dir_to_read;
  13.827 +
  13.828 +      if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this)
  13.829 +        err=ZIP_ERRNO;
  13.830 +
  13.831 +      if (err==ZIP_OK)
  13.832 +        err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);
  13.833 +
  13.834 +      size_central_dir_to_read-=read_this;
  13.835 +    }
  13.836 +    TRYFREE(buf_read);
  13.837 +  }
  13.838 +  pziinit->begin_pos = byte_before_the_zipfile;
  13.839 +  pziinit->number_entry = number_entry_CD;
  13.840 +
  13.841 +  if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
  13.842 +    err=ZIP_ERRNO;
  13.843 +
  13.844 +  return err;
  13.845 +}
  13.846 +
  13.847 +
  13.848 +#endif /* !NO_ADDFILEINEXISTINGZIP*/
  13.849 +
  13.850 +
  13.851 +/************************************************************/
  13.852 +extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def)
  13.853 +{
  13.854 +    zip64_internal ziinit;
  13.855 +    zip64_internal* zi;
  13.856 +    int err=ZIP_OK;
  13.857 +
  13.858 +    ziinit.z_filefunc.zseek32_file = NULL;
  13.859 +    ziinit.z_filefunc.ztell32_file = NULL;
  13.860 +    if (pzlib_filefunc64_32_def==NULL)
  13.861 +        fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
  13.862 +    else
  13.863 +        ziinit.z_filefunc = *pzlib_filefunc64_32_def;
  13.864 +
  13.865 +    ziinit.filestream = ZOPEN64(ziinit.z_filefunc,
  13.866 +                  pathname,
  13.867 +                  (append == APPEND_STATUS_CREATE) ?
  13.868 +                  (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
  13.869 +                    (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
  13.870 +
  13.871 +    if (ziinit.filestream == NULL)
  13.872 +        return NULL;
  13.873 +
  13.874 +    if (append == APPEND_STATUS_CREATEAFTER)
  13.875 +        ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
  13.876 +
  13.877 +    ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream);
  13.878 +    ziinit.in_opened_file_inzip = 0;
  13.879 +    ziinit.ci.stream_initialised = 0;
  13.880 +    ziinit.number_entry = 0;
  13.881 +    ziinit.add_position_when_writting_offset = 0;
  13.882 +    init_linkedlist(&(ziinit.central_dir));
  13.883 +
  13.884 +
  13.885 +
  13.886 +    zi = (zip64_internal*)ALLOC(sizeof(zip64_internal));
  13.887 +    if (zi==NULL)
  13.888 +    {
  13.889 +        ZCLOSE64(ziinit.z_filefunc,ziinit.filestream);
  13.890 +        return NULL;
  13.891 +    }
  13.892 +
  13.893 +    /* now we add file in a zipfile */
  13.894 +#    ifndef NO_ADDFILEINEXISTINGZIP
  13.895 +    ziinit.globalcomment = NULL;
  13.896 +    if (append == APPEND_STATUS_ADDINZIP)
  13.897 +    {
  13.898 +      // Read and Cache Central Directory Records
  13.899 +      err = LoadCentralDirectoryRecord(&ziinit);
  13.900 +    }
  13.901 +
  13.902 +    if (globalcomment)
  13.903 +    {
  13.904 +      *globalcomment = ziinit.globalcomment;
  13.905 +    }
  13.906 +#    endif /* !NO_ADDFILEINEXISTINGZIP*/
  13.907 +
  13.908 +    if (err != ZIP_OK)
  13.909 +    {
  13.910 +#    ifndef NO_ADDFILEINEXISTINGZIP
  13.911 +        TRYFREE(ziinit.globalcomment);
  13.912 +#    endif /* !NO_ADDFILEINEXISTINGZIP*/
  13.913 +        TRYFREE(zi);
  13.914 +        return NULL;
  13.915 +    }
  13.916 +    else
  13.917 +    {
  13.918 +        *zi = ziinit;
  13.919 +        return (zipFile)zi;
  13.920 +    }
  13.921 +}
  13.922 +
  13.923 +extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def)
  13.924 +{
  13.925 +    if (pzlib_filefunc32_def != NULL)
  13.926 +    {
  13.927 +        zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
  13.928 +        fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
  13.929 +        return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
  13.930 +    }
  13.931 +    else
  13.932 +        return zipOpen3(pathname, append, globalcomment, NULL);
  13.933 +}
  13.934 +
  13.935 +extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def)
  13.936 +{
  13.937 +    if (pzlib_filefunc_def != NULL)
  13.938 +    {
  13.939 +        zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
  13.940 +        zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
  13.941 +        zlib_filefunc64_32_def_fill.ztell32_file = NULL;
  13.942 +        zlib_filefunc64_32_def_fill.zseek32_file = NULL;
  13.943 +        return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
  13.944 +    }
  13.945 +    else
  13.946 +        return zipOpen3(pathname, append, globalcomment, NULL);
  13.947 +}
  13.948 +
  13.949 +
  13.950 +
  13.951 +extern zipFile ZEXPORT zipOpen (const char* pathname, int append)
  13.952 +{
  13.953 +    return zipOpen3((const void*)pathname,append,NULL,NULL);
  13.954 +}
  13.955 +
  13.956 +extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append)
  13.957 +{
  13.958 +    return zipOpen3(pathname,append,NULL,NULL);
  13.959 +}
  13.960 +
  13.961 +int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local)
  13.962 +{
  13.963 +  /* write the local header */
  13.964 +  int err;
  13.965 +  uInt size_filename = (uInt)strlen(filename);
  13.966 +  uInt size_extrafield = size_extrafield_local;
  13.967 +
  13.968 +  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4);
  13.969 +
  13.970 +  if (err==ZIP_OK)
  13.971 +  {
  13.972 +    if(zi->ci.zip64)
  13.973 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */
  13.974 +    else
  13.975 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */
  13.976 +  }
  13.977 +
  13.978 +  if (err==ZIP_OK)
  13.979 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
  13.980 +
  13.981 +  if (err==ZIP_OK)
  13.982 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
  13.983 +
  13.984 +  if (err==ZIP_OK)
  13.985 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
  13.986 +
  13.987 +  // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later
  13.988 +  if (err==ZIP_OK)
  13.989 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
  13.990 +  if (err==ZIP_OK)
  13.991 +  {
  13.992 +    if(zi->ci.zip64)
  13.993 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */
  13.994 +    else
  13.995 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
  13.996 +  }
  13.997 +  if (err==ZIP_OK)
  13.998 +  {
  13.999 +    if(zi->ci.zip64)
 13.1000 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */
 13.1001 +    else
 13.1002 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
 13.1003 +  }
 13.1004 +
 13.1005 +  if (err==ZIP_OK)
 13.1006 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
 13.1007 +
 13.1008 +  if(zi->ci.zip64)
 13.1009 +  {
 13.1010 +    size_extrafield += 20;
 13.1011 +  }
 13.1012 +
 13.1013 +  if (err==ZIP_OK)
 13.1014 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2);
 13.1015 +
 13.1016 +  if ((err==ZIP_OK) && (size_filename > 0))
 13.1017 +  {
 13.1018 +    if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
 13.1019 +      err = ZIP_ERRNO;
 13.1020 +  }
 13.1021 +
 13.1022 +  if ((err==ZIP_OK) && (size_extrafield_local > 0))
 13.1023 +  {
 13.1024 +    if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local)
 13.1025 +      err = ZIP_ERRNO;
 13.1026 +  }
 13.1027 +
 13.1028 +
 13.1029 +  if ((err==ZIP_OK) && (zi->ci.zip64))
 13.1030 +  {
 13.1031 +      // write the Zip64 extended info
 13.1032 +      short HeaderID = 1;
 13.1033 +      short DataSize = 16;
 13.1034 +      ZPOS64_T CompressedSize = 0;
 13.1035 +      ZPOS64_T UncompressedSize = 0;
 13.1036 +
 13.1037 +      // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file)
 13.1038 +      zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream);
 13.1039 +
 13.1040 +      err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2);
 13.1041 +      err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2);
 13.1042 +
 13.1043 +      err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8);
 13.1044 +      err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8);
 13.1045 +  }
 13.1046 +
 13.1047 +  return err;
 13.1048 +}
 13.1049 +
 13.1050 +/*
 13.1051 + NOTE.
 13.1052 + When writing RAW the ZIP64 extended information in extrafield_local and extrafield_global needs to be stripped
 13.1053 + before calling this function it can be done with zipRemoveExtraInfoBlock
 13.1054 +
 13.1055 + It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize
 13.1056 + unnecessary allocations.
 13.1057 + */
 13.1058 +extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
 13.1059 +                                         const void* extrafield_local, uInt size_extrafield_local,
 13.1060 +                                         const void* extrafield_global, uInt size_extrafield_global,
 13.1061 +                                         const char* comment, int method, int level, int raw,
 13.1062 +                                         int windowBits,int memLevel, int strategy,
 13.1063 +                                         const char* password, uLong crcForCrypting,
 13.1064 +                                         uLong versionMadeBy, uLong flagBase, int zip64)
 13.1065 +{
 13.1066 +    zip64_internal* zi;
 13.1067 +    uInt size_filename;
 13.1068 +    uInt size_comment;
 13.1069 +    uInt i;
 13.1070 +    int err = ZIP_OK;
 13.1071 +
 13.1072 +#    ifdef NOCRYPT
 13.1073 +    (crcForCrypting);
 13.1074 +    if (password != NULL)
 13.1075 +        return ZIP_PARAMERROR;
 13.1076 +#    endif
 13.1077 +
 13.1078 +    if (file == NULL)
 13.1079 +        return ZIP_PARAMERROR;
 13.1080 +
 13.1081 +#ifdef HAVE_BZIP2
 13.1082 +    if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED))
 13.1083 +      return ZIP_PARAMERROR;
 13.1084 +#else
 13.1085 +    if ((method!=0) && (method!=Z_DEFLATED))
 13.1086 +      return ZIP_PARAMERROR;
 13.1087 +#endif
 13.1088 +
 13.1089 +    zi = (zip64_internal*)file;
 13.1090 +
 13.1091 +    if (zi->in_opened_file_inzip == 1)
 13.1092 +    {
 13.1093 +        err = zipCloseFileInZip (file);
 13.1094 +        if (err != ZIP_OK)
 13.1095 +            return err;
 13.1096 +    }
 13.1097 +
 13.1098 +    if (filename==NULL)
 13.1099 +        filename="-";
 13.1100 +
 13.1101 +    if (comment==NULL)
 13.1102 +        size_comment = 0;
 13.1103 +    else
 13.1104 +        size_comment = (uInt)strlen(comment);
 13.1105 +
 13.1106 +    size_filename = (uInt)strlen(filename);
 13.1107 +
 13.1108 +    if (zipfi == NULL)
 13.1109 +        zi->ci.dosDate = 0;
 13.1110 +    else
 13.1111 +    {
 13.1112 +        if (zipfi->dosDate != 0)
 13.1113 +            zi->ci.dosDate = zipfi->dosDate;
 13.1114 +        else
 13.1115 +          zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date);
 13.1116 +    }
 13.1117 +
 13.1118 +    zi->ci.flag = flagBase;
 13.1119 +    if ((level==8) || (level==9))
 13.1120 +      zi->ci.flag |= 2;
 13.1121 +    if (level==2)
 13.1122 +      zi->ci.flag |= 4;
 13.1123 +    if (level==1)
 13.1124 +      zi->ci.flag |= 6;
 13.1125 +    if (password != NULL)
 13.1126 +      zi->ci.flag |= 1;
 13.1127 +
 13.1128 +    zi->ci.crc32 = 0;
 13.1129 +    zi->ci.method = method;
 13.1130 +    zi->ci.encrypt = 0;
 13.1131 +    zi->ci.stream_initialised = 0;
 13.1132 +    zi->ci.pos_in_buffered_data = 0;
 13.1133 +    zi->ci.raw = raw;
 13.1134 +    zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream);
 13.1135 +
 13.1136 +    zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment;
 13.1137 +    zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data
 13.1138 +
 13.1139 +    zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree);
 13.1140 +
 13.1141 +    zi->ci.size_centralExtra = size_extrafield_global;
 13.1142 +    zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
 13.1143 +    /* version info */
 13.1144 +    zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2);
 13.1145 +    zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
 13.1146 +    zip64local_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
 13.1147 +    zip64local_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
 13.1148 +    zip64local_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
 13.1149 +    zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
 13.1150 +    zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
 13.1151 +    zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
 13.1152 +    zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
 13.1153 +    zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
 13.1154 +    zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
 13.1155 +    zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
 13.1156 +
 13.1157 +    if (zipfi==NULL)
 13.1158 +        zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
 13.1159 +    else
 13.1160 +        zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
 13.1161 +
 13.1162 +    if (zipfi==NULL)
 13.1163 +        zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
 13.1164 +    else
 13.1165 +        zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
 13.1166 +
 13.1167 +    if(zi->ci.pos_local_header >= 0xffffffff)
 13.1168 +      zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4);
 13.1169 +    else
 13.1170 +      zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset,4);
 13.1171 +
 13.1172 +    for (i=0;i<size_filename;i++)
 13.1173 +        *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
 13.1174 +
 13.1175 +    for (i=0;i<size_extrafield_global;i++)
 13.1176 +        *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
 13.1177 +              *(((const char*)extrafield_global)+i);
 13.1178 +
 13.1179 +    for (i=0;i<size_comment;i++)
 13.1180 +        *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
 13.1181 +              size_extrafield_global+i) = *(comment+i);
 13.1182 +    if (zi->ci.central_header == NULL)
 13.1183 +        return ZIP_INTERNALERROR;
 13.1184 +
 13.1185 +    zi->ci.zip64 = zip64;
 13.1186 +    zi->ci.totalCompressedData = 0;
 13.1187 +    zi->ci.totalUncompressedData = 0;
 13.1188 +    zi->ci.pos_zip64extrainfo = 0;
 13.1189 +
 13.1190 +    err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local);
 13.1191 +
 13.1192 +#ifdef HAVE_BZIP2
 13.1193 +    zi->ci.bstream.avail_in = (uInt)0;
 13.1194 +    zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
 13.1195 +    zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
 13.1196 +    zi->ci.bstream.total_in_hi32 = 0;
 13.1197 +    zi->ci.bstream.total_in_lo32 = 0;
 13.1198 +    zi->ci.bstream.total_out_hi32 = 0;
 13.1199 +    zi->ci.bstream.total_out_lo32 = 0;
 13.1200 +#endif
 13.1201 +
 13.1202 +    zi->ci.stream.avail_in = (uInt)0;
 13.1203 +    zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
 13.1204 +    zi->ci.stream.next_out = zi->ci.buffered_data;
 13.1205 +    zi->ci.stream.total_in = 0;
 13.1206 +    zi->ci.stream.total_out = 0;
 13.1207 +    zi->ci.stream.data_type = Z_BINARY;
 13.1208 +
 13.1209 +#ifdef HAVE_BZIP2
 13.1210 +    if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
 13.1211 +#else
 13.1212 +    if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
 13.1213 +#endif
 13.1214 +    {
 13.1215 +        if(zi->ci.method == Z_DEFLATED)
 13.1216 +        {
 13.1217 +          zi->ci.stream.zalloc = (alloc_func)0;
 13.1218 +          zi->ci.stream.zfree = (free_func)0;
 13.1219 +          zi->ci.stream.opaque = (voidpf)0;
 13.1220 +
 13.1221 +          if (windowBits>0)
 13.1222 +              windowBits = -windowBits;
 13.1223 +
 13.1224 +          err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
 13.1225 +
 13.1226 +          if (err==Z_OK)
 13.1227 +              zi->ci.stream_initialised = Z_DEFLATED;
 13.1228 +        }
 13.1229 +        else if(zi->ci.method == Z_BZIP2ED)
 13.1230 +        {
 13.1231 +#ifdef HAVE_BZIP2
 13.1232 +            // Init BZip stuff here
 13.1233 +          zi->ci.bstream.bzalloc = 0;
 13.1234 +          zi->ci.bstream.bzfree = 0;
 13.1235 +          zi->ci.bstream.opaque = (voidpf)0;
 13.1236 +
 13.1237 +          err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35);
 13.1238 +          if(err == BZ_OK)
 13.1239 +            zi->ci.stream_initialised = Z_BZIP2ED;
 13.1240 +#endif
 13.1241 +        }
 13.1242 +
 13.1243 +    }
 13.1244 +
 13.1245 +#    ifndef NOCRYPT
 13.1246 +    zi->ci.crypt_header_size = 0;
 13.1247 +    if ((err==Z_OK) && (password != NULL))
 13.1248 +    {
 13.1249 +        unsigned char bufHead[RAND_HEAD_LEN];
 13.1250 +        unsigned int sizeHead;
 13.1251 +        zi->ci.encrypt = 1;
 13.1252 +        zi->ci.pcrc_32_tab = get_crc_table();
 13.1253 +        /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
 13.1254 +
 13.1255 +        sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
 13.1256 +        zi->ci.crypt_header_size = sizeHead;
 13.1257 +
 13.1258 +        if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
 13.1259 +                err = ZIP_ERRNO;
 13.1260 +    }
 13.1261 +#    endif
 13.1262 +
 13.1263 +    if (err==Z_OK)
 13.1264 +        zi->in_opened_file_inzip = 1;
 13.1265 +    return err;
 13.1266 +}
 13.1267 +
 13.1268 +extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
 13.1269 +                                         const void* extrafield_local, uInt size_extrafield_local,
 13.1270 +                                         const void* extrafield_global, uInt size_extrafield_global,
 13.1271 +                                         const char* comment, int method, int level, int raw,
 13.1272 +                                         int windowBits,int memLevel, int strategy,
 13.1273 +                                         const char* password, uLong crcForCrypting,
 13.1274 +                                         uLong versionMadeBy, uLong flagBase)
 13.1275 +{
 13.1276 +    return zipOpenNewFileInZip4_64 (file, filename, zipfi,
 13.1277 +                                 extrafield_local, size_extrafield_local,
 13.1278 +                                 extrafield_global, size_extrafield_global,
 13.1279 +                                 comment, method, level, raw,
 13.1280 +                                 windowBits, memLevel, strategy,
 13.1281 +                                 password, crcForCrypting, versionMadeBy, flagBase, 0);
 13.1282 +}
 13.1283 +
 13.1284 +extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
 13.1285 +                                         const void* extrafield_local, uInt size_extrafield_local,
 13.1286 +                                         const void* extrafield_global, uInt size_extrafield_global,
 13.1287 +                                         const char* comment, int method, int level, int raw,
 13.1288 +                                         int windowBits,int memLevel, int strategy,
 13.1289 +                                         const char* password, uLong crcForCrypting)
 13.1290 +{
 13.1291 +    return zipOpenNewFileInZip4_64 (file, filename, zipfi,
 13.1292 +                                 extrafield_local, size_extrafield_local,
 13.1293 +                                 extrafield_global, size_extrafield_global,
 13.1294 +                                 comment, method, level, raw,
 13.1295 +                                 windowBits, memLevel, strategy,
 13.1296 +                                 password, crcForCrypting, VERSIONMADEBY, 0, 0);
 13.1297 +}
 13.1298 +
 13.1299 +extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
 13.1300 +                                         const void* extrafield_local, uInt size_extrafield_local,
 13.1301 +                                         const void* extrafield_global, uInt size_extrafield_global,
 13.1302 +                                         const char* comment, int method, int level, int raw,
 13.1303 +                                         int windowBits,int memLevel, int strategy,
 13.1304 +                                         const char* password, uLong crcForCrypting, int zip64)
 13.1305 +{
 13.1306 +    return zipOpenNewFileInZip4_64 (file, filename, zipfi,
 13.1307 +                                 extrafield_local, size_extrafield_local,
 13.1308 +                                 extrafield_global, size_extrafield_global,
 13.1309 +                                 comment, method, level, raw,
 13.1310 +                                 windowBits, memLevel, strategy,
 13.1311 +                                 password, crcForCrypting, VERSIONMADEBY, 0, zip64);
 13.1312 +}
 13.1313 +
 13.1314 +extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi,
 13.1315 +                                        const void* extrafield_local, uInt size_extrafield_local,
 13.1316 +                                        const void* extrafield_global, uInt size_extrafield_global,
 13.1317 +                                        const char* comment, int method, int level, int raw)
 13.1318 +{
 13.1319 +    return zipOpenNewFileInZip4_64 (file, filename, zipfi,
 13.1320 +                                 extrafield_local, size_extrafield_local,
 13.1321 +                                 extrafield_global, size_extrafield_global,
 13.1322 +                                 comment, method, level, raw,
 13.1323 +                                 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
 13.1324 +                                 NULL, 0, VERSIONMADEBY, 0, 0);
 13.1325 +}
 13.1326 +
 13.1327 +extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
 13.1328 +                                        const void* extrafield_local, uInt size_extrafield_local,
 13.1329 +                                        const void* extrafield_global, uInt size_extrafield_global,
 13.1330 +                                        const char* comment, int method, int level, int raw, int zip64)
 13.1331 +{
 13.1332 +    return zipOpenNewFileInZip4_64 (file, filename, zipfi,
 13.1333 +                                 extrafield_local, size_extrafield_local,
 13.1334 +                                 extrafield_global, size_extrafield_global,
 13.1335 +                                 comment, method, level, raw,
 13.1336 +                                 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
 13.1337 +                                 NULL, 0, VERSIONMADEBY, 0, zip64);
 13.1338 +}
 13.1339 +
 13.1340 +extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
 13.1341 +                                        const void* extrafield_local, uInt size_extrafield_local,
 13.1342 +                                        const void*extrafield_global, uInt size_extrafield_global,
 13.1343 +                                        const char* comment, int method, int level, int zip64)
 13.1344 +{
 13.1345 +    return zipOpenNewFileInZip4_64 (file, filename, zipfi,
 13.1346 +                                 extrafield_local, size_extrafield_local,
 13.1347 +                                 extrafield_global, size_extrafield_global,
 13.1348 +                                 comment, method, level, 0,
 13.1349 +                                 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
 13.1350 +                                 NULL, 0, VERSIONMADEBY, 0, zip64);
 13.1351 +}
 13.1352 +
 13.1353 +extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi,
 13.1354 +                                        const void* extrafield_local, uInt size_extrafield_local,
 13.1355 +                                        const void*extrafield_global, uInt size_extrafield_global,
 13.1356 +                                        const char* comment, int method, int level)
 13.1357 +{
 13.1358 +    return zipOpenNewFileInZip4_64 (file, filename, zipfi,
 13.1359 +                                 extrafield_local, size_extrafield_local,
 13.1360 +                                 extrafield_global, size_extrafield_global,
 13.1361 +                                 comment, method, level, 0,
 13.1362 +                                 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
 13.1363 +                                 NULL, 0, VERSIONMADEBY, 0, 0);
 13.1364 +}
 13.1365 +
 13.1366 +local int zip64FlushWriteBuffer(zip64_internal* zi)
 13.1367 +{
 13.1368 +    int err=ZIP_OK;
 13.1369 +
 13.1370 +    if (zi->ci.encrypt != 0)
 13.1371 +    {
 13.1372 +#ifndef NOCRYPT
 13.1373 +        uInt i;
 13.1374 +        int t;
 13.1375 +        for (i=0;i<zi->ci.pos_in_buffered_data;i++)
 13.1376 +            zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t);
 13.1377 +#endif
 13.1378 +    }
 13.1379 +
 13.1380 +    if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data)
 13.1381 +      err = ZIP_ERRNO;
 13.1382 +
 13.1383 +    zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data;
 13.1384 +
 13.1385 +#ifdef HAVE_BZIP2
 13.1386 +    if(zi->ci.method == Z_BZIP2ED)
 13.1387 +    {
 13.1388 +      zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32;
 13.1389 +      zi->ci.bstream.total_in_lo32 = 0;
 13.1390 +      zi->ci.bstream.total_in_hi32 = 0;
 13.1391 +    }
 13.1392 +    else
 13.1393 +#endif
 13.1394 +    {
 13.1395 +      zi->ci.totalUncompressedData += zi->ci.stream.total_in;
 13.1396 +      zi->ci.stream.total_in = 0;
 13.1397 +    }
 13.1398 +
 13.1399 +
 13.1400 +    zi->ci.pos_in_buffered_data = 0;
 13.1401 +
 13.1402 +    return err;
 13.1403 +}
 13.1404 +
 13.1405 +extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len)
 13.1406 +{
 13.1407 +    zip64_internal* zi;
 13.1408 +    int err=ZIP_OK;
 13.1409 +
 13.1410 +    if (file == NULL)
 13.1411 +        return ZIP_PARAMERROR;
 13.1412 +    zi = (zip64_internal*)file;
 13.1413 +
 13.1414 +    if (zi->in_opened_file_inzip == 0)
 13.1415 +        return ZIP_PARAMERROR;
 13.1416 +
 13.1417 +    zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len);
 13.1418 +
 13.1419 +#ifdef HAVE_BZIP2
 13.1420 +    if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw))
 13.1421 +    {
 13.1422 +      zi->ci.bstream.next_in = (void*)buf;
 13.1423 +      zi->ci.bstream.avail_in = len;
 13.1424 +      err = BZ_RUN_OK;
 13.1425 +
 13.1426 +      while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0))
 13.1427 +      {
 13.1428 +        if (zi->ci.bstream.avail_out == 0)
 13.1429 +        {
 13.1430 +          if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
 13.1431 +            err = ZIP_ERRNO;
 13.1432 +          zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
 13.1433 +          zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
 13.1434 +        }
 13.1435 +
 13.1436 +
 13.1437 +        if(err != BZ_RUN_OK)
 13.1438 +          break;
 13.1439 +
 13.1440 +        if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
 13.1441 +        {
 13.1442 +          uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
 13.1443 +//          uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32;
 13.1444 +          err=BZ2_bzCompress(&zi->ci.bstream,  BZ_RUN);
 13.1445 +
 13.1446 +          zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ;
 13.1447 +        }
 13.1448 +      }
 13.1449 +
 13.1450 +      if(err == BZ_RUN_OK)
 13.1451 +        err = ZIP_OK;
 13.1452 +    }
 13.1453 +    else
 13.1454 +#endif
 13.1455 +    {
 13.1456 +      zi->ci.stream.next_in = (Bytef*)buf;
 13.1457 +      zi->ci.stream.avail_in = len;
 13.1458 +
 13.1459 +      while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
 13.1460 +      {
 13.1461 +          if (zi->ci.stream.avail_out == 0)
 13.1462 +          {
 13.1463 +              if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
 13.1464 +                  err = ZIP_ERRNO;
 13.1465 +              zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
 13.1466 +              zi->ci.stream.next_out = zi->ci.buffered_data;
 13.1467 +          }
 13.1468 +
 13.1469 +
 13.1470 +          if(err != ZIP_OK)
 13.1471 +              break;
 13.1472 +
 13.1473 +          if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
 13.1474 +          {
 13.1475 +              uLong uTotalOutBefore = zi->ci.stream.total_out;
 13.1476 +              err=deflate(&zi->ci.stream,  Z_NO_FLUSH);
 13.1477 +              if(uTotalOutBefore > zi->ci.stream.total_out)
 13.1478 +              {
 13.1479 +                int bBreak = 0;
 13.1480 +                bBreak++;
 13.1481 +              }
 13.1482 +
 13.1483 +              zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
 13.1484 +          }
 13.1485 +          else
 13.1486 +          {
 13.1487 +              uInt copy_this,i;
 13.1488 +              if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
 13.1489 +                  copy_this = zi->ci.stream.avail_in;
 13.1490 +              else
 13.1491 +                  copy_this = zi->ci.stream.avail_out;
 13.1492 +
 13.1493 +              for (i = 0; i < copy_this; i++)
 13.1494 +                  *(((char*)zi->ci.stream.next_out)+i) =
 13.1495 +                      *(((const char*)zi->ci.stream.next_in)+i);
 13.1496 +              {
 13.1497 +                  zi->ci.stream.avail_in -= copy_this;
 13.1498 +                  zi->ci.stream.avail_out-= copy_this;
 13.1499 +                  zi->ci.stream.next_in+= copy_this;
 13.1500 +                  zi->ci.stream.next_out+= copy_this;
 13.1501 +                  zi->ci.stream.total_in+= copy_this;
 13.1502 +                  zi->ci.stream.total_out+= copy_this;
 13.1503 +                  zi->ci.pos_in_buffered_data += copy_this;
 13.1504 +              }
 13.1505 +          }
 13.1506 +      }// while(...)
 13.1507 +    }
 13.1508 +
 13.1509 +    return err;
 13.1510 +}
 13.1511 +
 13.1512 +extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32)
 13.1513 +{
 13.1514 +    return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
 13.1515 +}
 13.1516 +
 13.1517 +extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
 13.1518 +{
 13.1519 +    zip64_internal* zi;
 13.1520 +    ZPOS64_T compressed_size;
 13.1521 +    uLong invalidValue = 0xffffffff;
 13.1522 +    short datasize = 0;
 13.1523 +    int err=ZIP_OK;
 13.1524 +
 13.1525 +    if (file == NULL)
 13.1526 +        return ZIP_PARAMERROR;
 13.1527 +    zi = (zip64_internal*)file;
 13.1528 +
 13.1529 +    if (zi->in_opened_file_inzip == 0)
 13.1530 +        return ZIP_PARAMERROR;
 13.1531 +    zi->ci.stream.avail_in = 0;
 13.1532 +
 13.1533 +    if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
 13.1534 +                {
 13.1535 +                        while (err==ZIP_OK)
 13.1536 +                        {
 13.1537 +                                uLong uTotalOutBefore;
 13.1538 +                                if (zi->ci.stream.avail_out == 0)
 13.1539 +                                {
 13.1540 +                                        if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
 13.1541 +                                                err = ZIP_ERRNO;
 13.1542 +                                        zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
 13.1543 +                                        zi->ci.stream.next_out = zi->ci.buffered_data;
 13.1544 +                                }
 13.1545 +                                uTotalOutBefore = zi->ci.stream.total_out;
 13.1546 +                                err=deflate(&zi->ci.stream,  Z_FINISH);
 13.1547 +                                zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
 13.1548 +                        }
 13.1549 +                }
 13.1550 +    else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
 13.1551 +    {
 13.1552 +#ifdef HAVE_BZIP2
 13.1553 +      err = BZ_FINISH_OK;
 13.1554 +      while (err==BZ_FINISH_OK)
 13.1555 +      {
 13.1556 +        uLong uTotalOutBefore;
 13.1557 +        if (zi->ci.bstream.avail_out == 0)
 13.1558 +        {
 13.1559 +          if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
 13.1560 +            err = ZIP_ERRNO;
 13.1561 +          zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
 13.1562 +          zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
 13.1563 +        }
 13.1564 +        uTotalOutBefore = zi->ci.bstream.total_out_lo32;
 13.1565 +        err=BZ2_bzCompress(&zi->ci.bstream,  BZ_FINISH);
 13.1566 +        if(err == BZ_STREAM_END)
 13.1567 +          err = Z_STREAM_END;
 13.1568 +
 13.1569 +        zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore);
 13.1570 +      }
 13.1571 +
 13.1572 +      if(err == BZ_FINISH_OK)
 13.1573 +        err = ZIP_OK;
 13.1574 +#endif
 13.1575 +    }
 13.1576 +
 13.1577 +    if (err==Z_STREAM_END)
 13.1578 +        err=ZIP_OK; /* this is normal */
 13.1579 +
 13.1580 +    if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
 13.1581 +                {
 13.1582 +        if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO)
 13.1583 +            err = ZIP_ERRNO;
 13.1584 +                }
 13.1585 +
 13.1586 +    if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
 13.1587 +    {
 13.1588 +        int tmp_err = deflateEnd(&zi->ci.stream);
 13.1589 +        if (err == ZIP_OK)
 13.1590 +            err = tmp_err;
 13.1591 +        zi->ci.stream_initialised = 0;
 13.1592 +    }
 13.1593 +#ifdef HAVE_BZIP2
 13.1594 +    else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
 13.1595 +    {
 13.1596 +      int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream);
 13.1597 +                        if (err==ZIP_OK)
 13.1598 +                                err = tmperr;
 13.1599 +                        zi->ci.stream_initialised = 0;
 13.1600 +    }
 13.1601 +#endif
 13.1602 +
 13.1603 +    if (!zi->ci.raw)
 13.1604 +    {
 13.1605 +        crc32 = (uLong)zi->ci.crc32;
 13.1606 +        uncompressed_size = zi->ci.totalUncompressedData;
 13.1607 +    }
 13.1608 +    compressed_size = zi->ci.totalCompressedData;
 13.1609 +
 13.1610 +#    ifndef NOCRYPT
 13.1611 +    compressed_size += zi->ci.crypt_header_size;
 13.1612 +#    endif
 13.1613 +
 13.1614 +    // update Current Item crc and sizes,
 13.1615 +    if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
 13.1616 +    {
 13.1617 +      /*version Made by*/
 13.1618 +      zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2);
 13.1619 +      /*version needed*/
 13.1620 +      zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2);
 13.1621 +
 13.1622 +    }
 13.1623 +
 13.1624 +    zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
 13.1625 +
 13.1626 +
 13.1627 +    if(compressed_size >= 0xffffffff)
 13.1628 +      zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/
 13.1629 +    else
 13.1630 +      zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/
 13.1631 +
 13.1632 +    /// set internal file attributes field
 13.1633 +    if (zi->ci.stream.data_type == Z_ASCII)
 13.1634 +        zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
 13.1635 +
 13.1636 +    if(uncompressed_size >= 0xffffffff)
 13.1637 +      zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/
 13.1638 +    else
 13.1639 +      zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/
 13.1640 +
 13.1641 +    // Add ZIP64 extra info field for uncompressed size
 13.1642 +    if(uncompressed_size >= 0xffffffff)
 13.1643 +      datasize += 8;
 13.1644 +
 13.1645 +    // Add ZIP64 extra info field for compressed size
 13.1646 +    if(compressed_size >= 0xffffffff)
 13.1647 +      datasize += 8;
 13.1648 +
 13.1649 +    // Add ZIP64 extra info field for relative offset to local file header of current file
 13.1650 +    if(zi->ci.pos_local_header >= 0xffffffff)
 13.1651 +      datasize += 8;
 13.1652 +
 13.1653 +    if(datasize > 0)
 13.1654 +    {
 13.1655 +      char* p = NULL;
 13.1656 +
 13.1657 +      if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree)
 13.1658 +      {
 13.1659 +        // we can not write more data to the buffer that we have room for.
 13.1660 +        return ZIP_BADZIPFILE;
 13.1661 +      }
 13.1662 +
 13.1663 +      p = zi->ci.central_header + zi->ci.size_centralheader;
 13.1664 +
 13.1665 +      // Add Extra Information Header for 'ZIP64 information'
 13.1666 +      zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID
 13.1667 +      p += 2;
 13.1668 +      zip64local_putValue_inmemory(p, datasize, 2); // DataSize
 13.1669 +      p += 2;
 13.1670 +
 13.1671 +      if(uncompressed_size >= 0xffffffff)
 13.1672 +      {
 13.1673 +        zip64local_putValue_inmemory(p, uncompressed_size, 8);
 13.1674 +        p += 8;
 13.1675 +      }
 13.1676 +
 13.1677 +      if(compressed_size >= 0xffffffff)
 13.1678 +      {
 13.1679 +        zip64local_putValue_inmemory(p, compressed_size, 8);
 13.1680 +        p += 8;
 13.1681 +      }
 13.1682 +
 13.1683 +      if(zi->ci.pos_local_header >= 0xffffffff)
 13.1684 +      {
 13.1685 +        zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8);
 13.1686 +        p += 8;
 13.1687 +      }
 13.1688 +
 13.1689 +      // Update how much extra free space we got in the memory buffer
 13.1690 +      // and increase the centralheader size so the new ZIP64 fields are included
 13.1691 +      // ( 4 below is the size of HeaderID and DataSize field )
 13.1692 +      zi->ci.size_centralExtraFree -= datasize + 4;
 13.1693 +      zi->ci.size_centralheader += datasize + 4;
 13.1694 +
 13.1695 +      // Update the extra info size field
 13.1696 +      zi->ci.size_centralExtra += datasize + 4;
 13.1697 +      zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2);
 13.1698 +    }
 13.1699 +
 13.1700 +    if (err==ZIP_OK)
 13.1701 +        err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
 13.1702 +
 13.1703 +    free(zi->ci.central_header);
 13.1704 +
 13.1705 +    if (err==ZIP_OK)
 13.1706 +    {
 13.1707 +        // Update the LocalFileHeader with the new values.
 13.1708 +
 13.1709 +        ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
 13.1710 +
 13.1711 +        if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
 13.1712 +            err = ZIP_ERRNO;
 13.1713 +
 13.1714 +        if (err==ZIP_OK)
 13.1715 +            err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
 13.1716 +
 13.1717 +        if(uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff )
 13.1718 +        {
 13.1719 +          if(zi->ci.pos_zip64extrainfo > 0)
 13.1720 +          {
 13.1721 +            // Update the size in the ZIP64 extended field.
 13.1722 +            if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0)
 13.1723 +              err = ZIP_ERRNO;
 13.1724 +
 13.1725 +            if (err==ZIP_OK) /* compressed size, unknown */
 13.1726 +              err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8);
 13.1727 +
 13.1728 +            if (err==ZIP_OK) /* uncompressed size, unknown */
 13.1729 +              err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
 13.1730 +          }
 13.1731 +          else
 13.1732 +              err = ZIP_BADZIPFILE; // Caller passed zip64 = 0, so no room for zip64 info -> fatal
 13.1733 +        }
 13.1734 +        else
 13.1735 +        {
 13.1736 +          if (err==ZIP_OK) /* compressed size, unknown */
 13.1737 +              err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
 13.1738 +
 13.1739 +          if (err==ZIP_OK) /* uncompressed size, unknown */
 13.1740 +              err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
 13.1741 +        }
 13.1742 +
 13.1743 +        if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
 13.1744 +            err = ZIP_ERRNO;
 13.1745 +    }
 13.1746 +
 13.1747 +    zi->number_entry ++;
 13.1748 +    zi->in_opened_file_inzip = 0;
 13.1749 +
 13.1750 +    return err;
 13.1751 +}
 13.1752 +
 13.1753 +extern int ZEXPORT zipCloseFileInZip (zipFile file)
 13.1754 +{
 13.1755 +    return zipCloseFileInZipRaw (file,0,0);
 13.1756 +}
 13.1757 +
 13.1758 +int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip)
 13.1759 +{
 13.1760 +  int err = ZIP_OK;
 13.1761 +  ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset;
 13.1762 +
 13.1763 +  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4);
 13.1764 +
 13.1765 +  /*num disks*/
 13.1766 +    if (err==ZIP_OK) /* number of the disk with the start of the central directory */
 13.1767 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
 13.1768 +
 13.1769 +  /*relative offset*/
 13.1770 +    if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */
 13.1771 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8);
 13.1772 +
 13.1773 +  /*total disks*/ /* Do not support spawning of disk so always say 1 here*/
 13.1774 +    if (err==ZIP_OK) /* number of the disk with the start of the central directory */
 13.1775 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4);
 13.1776 +
 13.1777 +    return err;
 13.1778 +}
 13.1779 +
 13.1780 +int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
 13.1781 +{
 13.1782 +  int err = ZIP_OK;
 13.1783 +
 13.1784 +  uLong Zip64DataSize = 44;
 13.1785 +
 13.1786 +  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4);
 13.1787 +
 13.1788 +  if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */
 13.1789 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ?
 13.1790 +
 13.1791 +  if (err==ZIP_OK) /* version made by */
 13.1792 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
 13.1793 +
 13.1794 +  if (err==ZIP_OK) /* version needed */
 13.1795 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
 13.1796 +
 13.1797 +  if (err==ZIP_OK) /* number of this disk */
 13.1798 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
 13.1799 +
 13.1800 +  if (err==ZIP_OK) /* number of the disk with the start of the central directory */
 13.1801 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
 13.1802 +
 13.1803 +  if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
 13.1804 +    err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
 13.1805 +
 13.1806 +  if (err==ZIP_OK) /* total number of entries in the central dir */
 13.1807 +    err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
 13.1808 +
 13.1809 +  if (err==ZIP_OK) /* size of the central directory */
 13.1810 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8);
 13.1811 +
 13.1812 +  if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
 13.1813 +  {
 13.1814 +    ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
 13.1815 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8);
 13.1816 +  }
 13.1817 +  return err;
 13.1818 +}
 13.1819 +int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
 13.1820 +{
 13.1821 +  int err = ZIP_OK;
 13.1822 +
 13.1823 +  /*signature*/
 13.1824 +  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
 13.1825 +
 13.1826 +  if (err==ZIP_OK) /* number of this disk */
 13.1827 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
 13.1828 +
 13.1829 +  if (err==ZIP_OK) /* number of the disk with the start of the central directory */
 13.1830 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
 13.1831 +
 13.1832 +  if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
 13.1833 +  {
 13.1834 +    {
 13.1835 +      if(zi->number_entry >= 0xFFFF)
 13.1836 +        err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
 13.1837 +      else
 13.1838 +        err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
 13.1839 +    }
 13.1840 +  }
 13.1841 +
 13.1842 +  if (err==ZIP_OK) /* total number of entries in the central dir */
 13.1843 +  {
 13.1844 +    if(zi->number_entry >= 0xFFFF)
 13.1845 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
 13.1846 +    else
 13.1847 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
 13.1848 +  }
 13.1849 +
 13.1850 +  if (err==ZIP_OK) /* size of the central directory */
 13.1851 +    err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
 13.1852 +
 13.1853 +  if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
 13.1854 +  {
 13.1855 +    ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
 13.1856 +    if(pos >= 0xffffffff)
 13.1857 +    {
 13.1858 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4);
 13.1859 +    }
 13.1860 +    else
 13.1861 +      err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
 13.1862 +  }
 13.1863 +
 13.1864 +   return err;
 13.1865 +}
 13.1866 +
 13.1867 +int Write_GlobalComment(zip64_internal* zi, const char* global_comment)
 13.1868 +{
 13.1869 +  int err = ZIP_OK;
 13.1870 +  uInt size_global_comment = 0;
 13.1871 +
 13.1872 +  if(global_comment != NULL)
 13.1873 +    size_global_comment = (uInt)strlen(global_comment);
 13.1874 +
 13.1875 +  err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
 13.1876 +
 13.1877 +  if (err == ZIP_OK && size_global_comment > 0)
 13.1878 +  {
 13.1879 +    if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment)
 13.1880 +      err = ZIP_ERRNO;
 13.1881 +  }
 13.1882 +  return err;
 13.1883 +}
 13.1884 +
 13.1885 +extern int ZEXPORT zipClose (zipFile file, const char* global_comment)
 13.1886 +{
 13.1887 +    zip64_internal* zi;
 13.1888 +    int err = 0;
 13.1889 +    uLong size_centraldir = 0;
 13.1890 +    ZPOS64_T centraldir_pos_inzip;
 13.1891 +    ZPOS64_T pos;
 13.1892 +
 13.1893 +    if (file == NULL)
 13.1894 +        return ZIP_PARAMERROR;
 13.1895 +
 13.1896 +    zi = (zip64_internal*)file;
 13.1897 +
 13.1898 +    if (zi->in_opened_file_inzip == 1)
 13.1899 +    {
 13.1900 +        err = zipCloseFileInZip (file);
 13.1901 +    }
 13.1902 +
 13.1903 +#ifndef NO_ADDFILEINEXISTINGZIP
 13.1904 +    if (global_comment==NULL)
 13.1905 +        global_comment = zi->globalcomment;
 13.1906 +#endif
 13.1907 +
 13.1908 +    centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
 13.1909 +
 13.1910 +    if (err==ZIP_OK)
 13.1911 +    {
 13.1912 +        linkedlist_datablock_internal* ldi = zi->central_dir.first_block;
 13.1913 +        while (ldi!=NULL)
 13.1914 +        {
 13.1915 +            if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
 13.1916 +            {
 13.1917 +                if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block)
 13.1918 +                    err = ZIP_ERRNO;
 13.1919 +            }
 13.1920 +
 13.1921 +            size_centraldir += ldi->filled_in_this_block;
 13.1922 +            ldi = ldi->next_datablock;
 13.1923 +        }
 13.1924 +    }
 13.1925 +    free_linkedlist(&(zi->central_dir));
 13.1926 +
 13.1927 +    pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
 13.1928 +    if(pos >= 0xffffffff || zi->number_entry > 0xFFFF)
 13.1929 +    {
 13.1930 +      ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream);
 13.1931 +      Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
 13.1932 +
 13.1933 +      Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos);
 13.1934 +    }
 13.1935 +
 13.1936 +    if (err==ZIP_OK)
 13.1937 +      err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
 13.1938 +
 13.1939 +    if(err == ZIP_OK)
 13.1940 +      err = Write_GlobalComment(zi, global_comment);
 13.1941 +
 13.1942 +    if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0)
 13.1943 +        if (err == ZIP_OK)
 13.1944 +            err = ZIP_ERRNO;
 13.1945 +
 13.1946 +#ifndef NO_ADDFILEINEXISTINGZIP
 13.1947 +    TRYFREE(zi->globalcomment);
 13.1948 +#endif
 13.1949 +    TRYFREE(zi);
 13.1950 +
 13.1951 +    return err;
 13.1952 +}
 13.1953 +
 13.1954 +extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader)
 13.1955 +{
 13.1956 +  char* p = pData;
 13.1957 +  int size = 0;
 13.1958 +  char* pNewHeader;
 13.1959 +  char* pTmp;
 13.1960 +  short header;
 13.1961 +  short dataSize;
 13.1962 +
 13.1963 +  int retVal = ZIP_OK;
 13.1964 +
 13.1965 +  if(pData == NULL || *dataLen < 4)
 13.1966 +    return ZIP_PARAMERROR;
 13.1967 +
 13.1968 +  pNewHeader = (char*)ALLOC(*dataLen);
 13.1969 +  pTmp = pNewHeader;
 13.1970 +
 13.1971 +  while(p < (pData + *dataLen))
 13.1972 +  {
 13.1973 +    header = *(short*)p;
 13.1974 +    dataSize = *(((short*)p)+1);
 13.1975 +
 13.1976 +    if( header == sHeader ) // Header found.
 13.1977 +    {
 13.1978 +      p += dataSize + 4; // skip it. do not copy to temp buffer
 13.1979 +    }
 13.1980 +    else
 13.1981 +    {
 13.1982 +      // Extra Info block should not be removed, So copy it to the temp buffer.
 13.1983 +      memcpy(pTmp, p, dataSize + 4);
 13.1984 +      p += dataSize + 4;
 13.1985 +      size += dataSize + 4;
 13.1986 +    }
 13.1987 +
 13.1988 +  }
 13.1989 +
 13.1990 +  if(size < *dataLen)
 13.1991 +  {
 13.1992 +    // clean old extra info block.
 13.1993 +    memset(pData,0, *dataLen);
 13.1994 +
 13.1995 +    // copy the new extra info block over the old
 13.1996 +    if(size > 0)
 13.1997 +      memcpy(pData, pNewHeader, size);
 13.1998 +
 13.1999 +    // set the new extra info size
 13.2000 +    *dataLen = size;
 13.2001 +
 13.2002 +    retVal = ZIP_OK;
 13.2003 +  }
 13.2004 +  else
 13.2005 +    retVal = ZIP_ERRNO;
 13.2006 +
 13.2007 +  TRYFREE(pNewHeader);
 13.2008 +
 13.2009 +  return retVal;
 13.2010 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/test/zipcat/src/minizip/zip.h	Mon Nov 04 06:46:17 2013 +0200
    14.3 @@ -0,0 +1,362 @@
    14.4 +/* zip.h -- IO on .zip files using zlib
    14.5 +   Version 1.1, February 14h, 2010
    14.6 +   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
    14.7 +
    14.8 +         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
    14.9 +
   14.10 +         Modifications for Zip64 support
   14.11 +         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
   14.12 +
   14.13 +         For more info read MiniZip_info.txt
   14.14 +
   14.15 +         ---------------------------------------------------------------------------
   14.16 +
   14.17 +   Condition of use and distribution are the same than zlib :
   14.18 +
   14.19 +  This software is provided 'as-is', without any express or implied
   14.20 +  warranty.  In no event will the authors be held liable for any damages
   14.21 +  arising from the use of this software.
   14.22 +
   14.23 +  Permission is granted to anyone to use this software for any purpose,
   14.24 +  including commercial applications, and to alter it and redistribute it
   14.25 +  freely, subject to the following restrictions:
   14.26 +
   14.27 +  1. The origin of this software must not be misrepresented; you must not
   14.28 +     claim that you wrote the original software. If you use this software
   14.29 +     in a product, an acknowledgment in the product documentation would be
   14.30 +     appreciated but is not required.
   14.31 +  2. Altered source versions must be plainly marked as such, and must not be
   14.32 +     misrepresented as being the original software.
   14.33 +  3. This notice may not be removed or altered from any source distribution.
   14.34 +
   14.35 +        ---------------------------------------------------------------------------
   14.36 +
   14.37 +        Changes
   14.38 +
   14.39 +        See header of zip.h
   14.40 +
   14.41 +*/
   14.42 +
   14.43 +#ifndef _zip12_H
   14.44 +#define _zip12_H
   14.45 +
   14.46 +#ifdef __cplusplus
   14.47 +extern "C" {
   14.48 +#endif
   14.49 +
   14.50 +//#define HAVE_BZIP2
   14.51 +
   14.52 +#ifndef _ZLIB_H
   14.53 +#include "zlib.h"
   14.54 +#endif
   14.55 +
   14.56 +#ifndef _ZLIBIOAPI_H
   14.57 +#include "ioapi.h"
   14.58 +#endif
   14.59 +
   14.60 +#ifdef HAVE_BZIP2
   14.61 +#include "bzlib.h"
   14.62 +#endif
   14.63 +
   14.64 +#define Z_BZIP2ED 12
   14.65 +
   14.66 +#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
   14.67 +/* like the STRICT of WIN32, we define a pointer that cannot be converted
   14.68 +    from (void*) without cast */
   14.69 +typedef struct TagzipFile__ { int unused; } zipFile__;
   14.70 +typedef zipFile__ *zipFile;
   14.71 +#else
   14.72 +typedef voidp zipFile;
   14.73 +#endif
   14.74 +
   14.75 +#define ZIP_OK                          (0)
   14.76 +#define ZIP_EOF                         (0)
   14.77 +#define ZIP_ERRNO                       (Z_ERRNO)
   14.78 +#define ZIP_PARAMERROR                  (-102)
   14.79 +#define ZIP_BADZIPFILE                  (-103)
   14.80 +#define ZIP_INTERNALERROR               (-104)
   14.81 +
   14.82 +#ifndef DEF_MEM_LEVEL
   14.83 +#  if MAX_MEM_LEVEL >= 8
   14.84 +#    define DEF_MEM_LEVEL 8
   14.85 +#  else
   14.86 +#    define DEF_MEM_LEVEL  MAX_MEM_LEVEL
   14.87 +#  endif
   14.88 +#endif
   14.89 +/* default memLevel */
   14.90 +
   14.91 +/* tm_zip contain date/time info */
   14.92 +typedef struct tm_zip_s
   14.93 +{
   14.94 +    uInt tm_sec;            /* seconds after the minute - [0,59] */
   14.95 +    uInt tm_min;            /* minutes after the hour - [0,59] */
   14.96 +    uInt tm_hour;           /* hours since midnight - [0,23] */
   14.97 +    uInt tm_mday;           /* day of the month - [1,31] */
   14.98 +    uInt tm_mon;            /* months since January - [0,11] */
   14.99 +    uInt tm_year;           /* years - [1980..2044] */
  14.100 +} tm_zip;
  14.101 +
  14.102 +typedef struct
  14.103 +{
  14.104 +    tm_zip      tmz_date;       /* date in understandable format           */
  14.105 +    uLong       dosDate;       /* if dos_date == 0, tmu_date is used      */
  14.106 +/*    uLong       flag;        */   /* general purpose bit flag        2 bytes */
  14.107 +
  14.108 +    uLong       internal_fa;    /* internal file attributes        2 bytes */
  14.109 +    uLong       external_fa;    /* external file attributes        4 bytes */
  14.110 +} zip_fileinfo;
  14.111 +
  14.112 +typedef const char* zipcharpc;
  14.113 +
  14.114 +
  14.115 +#define APPEND_STATUS_CREATE        (0)
  14.116 +#define APPEND_STATUS_CREATEAFTER   (1)
  14.117 +#define APPEND_STATUS_ADDINZIP      (2)
  14.118 +
  14.119 +extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
  14.120 +extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
  14.121 +/*
  14.122 +  Create a zipfile.
  14.123 +     pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
  14.124 +       an Unix computer "zlib/zlib113.zip".
  14.125 +     if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
  14.126 +       will be created at the end of the file.
  14.127 +         (useful if the file contain a self extractor code)
  14.128 +     if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
  14.129 +       add files in existing zip (be sure you don't add file that doesn't exist)
  14.130 +     If the zipfile cannot be opened, the return value is NULL.
  14.131 +     Else, the return value is a zipFile Handle, usable with other function
  14.132 +       of this zip package.
  14.133 +*/
  14.134 +
  14.135 +/* Note : there is no delete function into a zipfile.
  14.136 +   If you want delete file into a zipfile, you must open a zipfile, and create another
  14.137 +   Of couse, you can use RAW reading and writing to copy the file you did not want delte
  14.138 +*/
  14.139 +
  14.140 +extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
  14.141 +                                   int append,
  14.142 +                                   zipcharpc* globalcomment,
  14.143 +                                   zlib_filefunc_def* pzlib_filefunc_def));
  14.144 +
  14.145 +extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
  14.146 +                                   int append,
  14.147 +                                   zipcharpc* globalcomment,
  14.148 +                                   zlib_filefunc64_def* pzlib_filefunc_def));
  14.149 +
  14.150 +extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
  14.151 +                       const char* filename,
  14.152 +                       const zip_fileinfo* zipfi,
  14.153 +                       const void* extrafield_local,
  14.154 +                       uInt size_extrafield_local,
  14.155 +                       const void* extrafield_global,
  14.156 +                       uInt size_extrafield_global,
  14.157 +                       const char* comment,
  14.158 +                       int method,
  14.159 +                       int level));
  14.160 +
  14.161 +extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
  14.162 +                       const char* filename,
  14.163 +                       const zip_fileinfo* zipfi,
  14.164 +                       const void* extrafield_local,
  14.165 +                       uInt size_extrafield_local,
  14.166 +                       const void* extrafield_global,
  14.167 +                       uInt size_extrafield_global,
  14.168 +                       const char* comment,
  14.169 +                       int method,
  14.170 +                       int level,
  14.171 +                       int zip64));
  14.172 +
  14.173 +/*
  14.174 +  Open a file in the ZIP for writing.
  14.175 +  filename : the filename in zip (if NULL, '-' without quote will be used
  14.176 +  *zipfi contain supplemental information
  14.177 +  if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
  14.178 +    contains the extrafield data the the local header
  14.179 +  if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
  14.180 +    contains the extrafield data the the local header
  14.181 +  if comment != NULL, comment contain the comment string
  14.182 +  method contain the compression method (0 for store, Z_DEFLATED for deflate)
  14.183 +  level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
  14.184 +  zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
  14.185 +                    this MUST be '1' if the uncompressed size is >= 0xffffffff.
  14.186 +
  14.187 +*/
  14.188 +
  14.189 +
  14.190 +extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
  14.191 +                                            const char* filename,
  14.192 +                                            const zip_fileinfo* zipfi,
  14.193 +                                            const void* extrafield_local,
  14.194 +                                            uInt size_extrafield_local,
  14.195 +                                            const void* extrafield_global,
  14.196 +                                            uInt size_extrafield_global,
  14.197 +                                            const char* comment,
  14.198 +                                            int method,
  14.199 +                                            int level,
  14.200 +                                            int raw));
  14.201 +
  14.202 +
  14.203 +extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
  14.204 +                                            const char* filename,
  14.205 +                                            const zip_fileinfo* zipfi,
  14.206 +                                            const void* extrafield_local,
  14.207 +                                            uInt size_extrafield_local,
  14.208 +                                            const void* extrafield_global,
  14.209 +                                            uInt size_extrafield_global,
  14.210 +                                            const char* comment,
  14.211 +                                            int method,
  14.212 +                                            int level,
  14.213 +                                            int raw,
  14.214 +                                            int zip64));
  14.215 +/*
  14.216 +  Same than zipOpenNewFileInZip, except if raw=1, we write raw file
  14.217 + */
  14.218 +
  14.219 +extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
  14.220 +                                            const char* filename,
  14.221 +                                            const zip_fileinfo* zipfi,
  14.222 +                                            const void* extrafield_local,
  14.223 +                                            uInt size_extrafield_local,
  14.224 +                                            const void* extrafield_global,
  14.225 +                                            uInt size_extrafield_global,
  14.226 +                                            const char* comment,
  14.227 +                                            int method,
  14.228 +                                            int level,
  14.229 +                                            int raw,
  14.230 +                                            int windowBits,
  14.231 +                                            int memLevel,
  14.232 +                                            int strategy,
  14.233 +                                            const char* password,
  14.234 +                                            uLong crcForCrypting));
  14.235 +
  14.236 +extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
  14.237 +                                            const char* filename,
  14.238 +                                            const zip_fileinfo* zipfi,
  14.239 +                                            const void* extrafield_local,
  14.240 +                                            uInt size_extrafield_local,
  14.241 +                                            const void* extrafield_global,
  14.242 +                                            uInt size_extrafield_global,
  14.243 +                                            const char* comment,
  14.244 +                                            int method,
  14.245 +                                            int level,
  14.246 +                                            int raw,
  14.247 +                                            int windowBits,
  14.248 +                                            int memLevel,
  14.249 +                                            int strategy,
  14.250 +                                            const char* password,
  14.251 +                                            uLong crcForCrypting,
  14.252 +                                            int zip64
  14.253 +                                            ));
  14.254 +
  14.255 +/*
  14.256 +  Same than zipOpenNewFileInZip2, except
  14.257 +    windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
  14.258 +    password : crypting password (NULL for no crypting)
  14.259 +    crcForCrypting : crc of file to compress (needed for crypting)
  14.260 + */
  14.261 +
  14.262 +extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
  14.263 +                                            const char* filename,
  14.264 +                                            const zip_fileinfo* zipfi,
  14.265 +                                            const void* extrafield_local,
  14.266 +                                            uInt size_extrafield_local,
  14.267 +                                            const void* extrafield_global,
  14.268 +                                            uInt size_extrafield_global,
  14.269 +                                            const char* comment,
  14.270 +                                            int method,
  14.271 +                                            int level,
  14.272 +                                            int raw,
  14.273 +                                            int windowBits,
  14.274 +                                            int memLevel,
  14.275 +                                            int strategy,
  14.276 +                                            const char* password,
  14.277 +                                            uLong crcForCrypting,
  14.278 +                                            uLong versionMadeBy,
  14.279 +                                            uLong flagBase
  14.280 +                                            ));
  14.281 +
  14.282 +
  14.283 +extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
  14.284 +                                            const char* filename,
  14.285 +                                            const zip_fileinfo* zipfi,
  14.286 +                                            const void* extrafield_local,
  14.287 +                                            uInt size_extrafield_local,
  14.288 +                                            const void* extrafield_global,
  14.289 +                                            uInt size_extrafield_global,
  14.290 +                                            const char* comment,
  14.291 +                                            int method,
  14.292 +                                            int level,
  14.293 +                                            int raw,
  14.294 +                                            int windowBits,
  14.295 +                                            int memLevel,
  14.296 +                                            int strategy,
  14.297 +                                            const char* password,
  14.298 +                                            uLong crcForCrypting,
  14.299 +                                            uLong versionMadeBy,
  14.300 +                                            uLong flagBase,
  14.301 +                                            int zip64
  14.302 +                                            ));
  14.303 +/*
  14.304 +  Same than zipOpenNewFileInZip4, except
  14.305 +    versionMadeBy : value for Version made by field
  14.306 +    flag : value for flag field (compression level info will be added)
  14.307 + */
  14.308 +
  14.309 +
  14.310 +extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
  14.311 +                       const void* buf,
  14.312 +                       unsigned len));
  14.313 +/*
  14.314 +  Write data in the zipfile
  14.315 +*/
  14.316 +
  14.317 +extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
  14.318 +/*
  14.319 +  Close the current file in the zipfile
  14.320 +*/
  14.321 +
  14.322 +extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
  14.323 +                                            uLong uncompressed_size,
  14.324 +                                            uLong crc32));
  14.325 +
  14.326 +extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
  14.327 +                                            ZPOS64_T uncompressed_size,
  14.328 +                                            uLong crc32));
  14.329 +
  14.330 +/*
  14.331 +  Close the current file in the zipfile, for file opened with
  14.332 +    parameter raw=1 in zipOpenNewFileInZip2
  14.333 +  uncompressed_size and crc32 are value for the uncompressed size
  14.334 +*/
  14.335 +
  14.336 +extern int ZEXPORT zipClose OF((zipFile file,
  14.337 +                const char* global_comment));
  14.338 +/*
  14.339 +  Close the zipfile
  14.340 +*/
  14.341 +
  14.342 +
  14.343 +extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
  14.344 +/*
  14.345 +  zipRemoveExtraInfoBlock -  Added by Mathias Svensson
  14.346 +
  14.347 +  Remove extra information block from a extra information data for the local file header or central directory header
  14.348 +
  14.349 +  It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
  14.350 +
  14.351 +  0x0001 is the signature header for the ZIP64 extra information blocks
  14.352 +
  14.353 +  usage.
  14.354 +                        Remove ZIP64 Extra information from a central director extra field data
  14.355 +              zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
  14.356 +
  14.357 +                        Remove ZIP64 Extra information from a Local File Header extra field data
  14.358 +        zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
  14.359 +*/
  14.360 +
  14.361 +#ifdef __cplusplus
  14.362 +}
  14.363 +#endif
  14.364 +
  14.365 +#endif /* _zip64_H */