packio-simple

changeset 0:d81c3ae262a0

initial commit
author John Tsiombikas <nuclear@mutantstargoat.com>
date Sun, 09 Sep 2012 06:05:11 +0300
parents
children eb07de55d0e6
files .hgignore Makefile include/packio.h src/minizip/ioapi.c src/minizip/ioapi.h src/minizip/unzip.c src/minizip/unzip.h src/packio_impl.h
diffstat 8 files changed, 3153 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Sun Sep 09 06:05:11 2012 +0300
     1.3 @@ -0,0 +1,6 @@
     1.4 +\.o$
     1.5 +\.swp$
     1.6 +\.d$
     1.7 +\.so
     1.8 +\.dylib$
     1.9 +\.a$
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile	Sun Sep 09 06:05:11 2012 +0300
     2.3 @@ -0,0 +1,57 @@
     2.4 +src = $(wildcard src/*.c)
     2.5 +hdr = packio.h
     2.6 +obj = $(src:.c=.o)
     2.7 +dep = $(obj:.o=.d)
     2.8 +name = packio
     2.9 +lib_a = lib$(name).a
    2.10 +
    2.11 +abimaj = 0
    2.12 +abimin = 1
    2.13 +
    2.14 +CFLAGS = -pedantic -Wall $(pic) $(dbg) $(opt)
    2.15 +LDFLAGS = $(libs)
    2.16 +
    2.17 +ifeq ($(shell uname -s), Darwin)
    2.18 +	lib_so = lib$(name).dylib
    2.19 +	shared = -dynamiclib
    2.20 +else
    2.21 +	devlink = lib$(name).so
    2.22 +	soname = $(devlink).$(abimaj)
    2.23 +	lib_so = $(soname).$(abimin)
    2.24 +	shared = -shared -Wl,-soname=$(soname)
    2.25 +	pic = -fPIC
    2.26 +endif
    2.27 +
    2.28 +
    2.29 +$(lib_so): $(obj)
    2.30 +	$(CC) -o $@ $(shared) $(obj) $(LDFLAGS)
    2.31 +
    2.32 +-include $(dep)
    2.33 +
    2.34 +%.d: %.c
    2.35 +	@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
    2.36 +
    2.37 +.PHONY: clean
    2.38 +clean:
    2.39 +	rm -f $(obj) $(bin) $(lib_so) $(lib_a) $(dep)
    2.40 +
    2.41 +.PHONY: install
    2.42 +install: $(lib_so)
    2.43 +	mkdir -p $(DESTDIR)$(PREFIX)/include $(DESTDIR)$(PREFIX)/lib
    2.44 +	cp include/$(hdr) $(DESTDIR)$(PREFIX)/include/$(hdr)
    2.45 +	cp $(lib_so) $(DESTDIR)$(PREFIX)/lib/$(lib_so)
    2.46 +	[ -n "$(soname)" ] \
    2.47 +		&& cd $(DESTDIR)$(PREFIX)/lib \
    2.48 +		&& rm -f $(soname) $(devlink) \
    2.49 +		&& ln -s $(lib_so) $(soname) \
    2.50 +		&& ln -s $(soname) $(devlink) \
    2.51 +		|| true
    2.52 +
    2.53 +.PHONY: uninstall
    2.54 +uninstall:
    2.55 +	rm -f $(DESTDIR)$(PREFIX)/include/$(hdr)
    2.56 +	rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_so)
    2.57 +	[ -n "$(soname)" ] \
    2.58 +		&& rm -f $(DESTDIR)$(PREFIX)/lib/$(soname) \
    2.59 +		&& rm -f $(DESTDIR)$(PREFIX)/lib/$(devlink) \
    2.60 +		|| true
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/include/packio.h	Sun Sep 09 06:05:11 2012 +0300
     3.3 @@ -0,0 +1,50 @@
     3.4 +#ifndef PACKIO_H_
     3.5 +#define PACKIO_H_
     3.6 +
     3.7 +struct pack_file;
     3.8 +struct pack_dir;
     3.9 +
    3.10 +#define PACK_NAME_MAX	256
    3.11 +
    3.12 +struct pack_dirent {
    3.13 +	char d_name[PACK_NAME_MAX];
    3.14 +};
    3.15 +
    3.16 +/* not sure I like this capitalization, but it matches the libc counterparts */
    3.17 +typedef struct pack_file PACKFILE;
    3.18 +typedef struct pack_dir PACKDIR;
    3.19 +
    3.20 +
    3.21 +int pack_init(void);
    3.22 +void pack_cleanup(void);
    3.23 +int pack_mount(const char *fname, const char *path);
    3.24 +
    3.25 +int pack_exists(const char *path);
    3.26 +int pack_isfile(const char *path);
    3.27 +int pack_isdir(const char *path);
    3.28 +
    3.29 +
    3.30 +/* file i/o */
    3.31 +PACKFILE *pack_fopen(const char *path, const char *mode);
    3.32 +int pack_fclose(PACKFILE *fp);
    3.33 +
    3.34 +int pack_feof(PACKFILE *fp);
    3.35 +long pack_filesize(PACKFILE *fp);
    3.36 +
    3.37 +int pack_fseek(PACKFILE *fp, long offs, int whence);
    3.38 +long pack_ftell(PACKFILE *fp);
    3.39 +void pack_rewind(PACKFILE *fp);
    3.40 +
    3.41 +size_t pack_fread(void *ptr, size_t size, size_t nmemb, PACKFILE *fp);
    3.42 +size_t pack_fwrite(void *ptr, size_t size, size_t nmemb, PACKFILE *fp);
    3.43 +
    3.44 +int pack_fgetc(PACKFILE *fp);
    3.45 +char *pack_fgets(char *buf, int size, PACKFILE *fp);
    3.46 +
    3.47 +/* directory handling */
    3.48 +PACKDIR *pack_opendir(const char *name);
    3.49 +int pack_closedir(PACKDIR *dir);
    3.50 +struct pack_dirent *pack_readdir(PACKDIR *dir);
    3.51 +
    3.52 +
    3.53 +#endif	/* PACKIO_H_ */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/minizip/ioapi.c	Sun Sep 09 06:05:11 2012 +0300
     4.3 @@ -0,0 +1,247 @@
     4.4 +/* ioapi.h -- IO base function header for compress/uncompress .zip
     4.5 +   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
     4.6 +
     4.7 +         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
     4.8 +
     4.9 +         Modifications for Zip64 support
    4.10 +         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
    4.11 +
    4.12 +         For more info read MiniZip_info.txt
    4.13 +
    4.14 +*/
    4.15 +
    4.16 +#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
    4.17 +        #define _CRT_SECURE_NO_WARNINGS
    4.18 +#endif
    4.19 +
    4.20 +#if defined(__APPLE__) || defined(IOAPI_NO_64)
    4.21 +// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
    4.22 +#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
    4.23 +#define FTELLO_FUNC(stream) ftello(stream)
    4.24 +#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
    4.25 +#else
    4.26 +#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
    4.27 +#define FTELLO_FUNC(stream) ftello64(stream)
    4.28 +#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
    4.29 +#endif
    4.30 +
    4.31 +
    4.32 +#include "ioapi.h"
    4.33 +
    4.34 +voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
    4.35 +{
    4.36 +    if (pfilefunc->zfile_func64.zopen64_file != NULL)
    4.37 +        return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
    4.38 +    else
    4.39 +    {
    4.40 +        return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
    4.41 +    }
    4.42 +}
    4.43 +
    4.44 +long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
    4.45 +{
    4.46 +    if (pfilefunc->zfile_func64.zseek64_file != NULL)
    4.47 +        return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
    4.48 +    else
    4.49 +    {
    4.50 +        uLong offsetTruncated = (uLong)offset;
    4.51 +        if (offsetTruncated != offset)
    4.52 +            return -1;
    4.53 +        else
    4.54 +            return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
    4.55 +    }
    4.56 +}
    4.57 +
    4.58 +ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
    4.59 +{
    4.60 +    if (pfilefunc->zfile_func64.zseek64_file != NULL)
    4.61 +        return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
    4.62 +    else
    4.63 +    {
    4.64 +        uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
    4.65 +        if ((tell_uLong) == MAXU32)
    4.66 +            return (ZPOS64_T)-1;
    4.67 +        else
    4.68 +            return tell_uLong;
    4.69 +    }
    4.70 +}
    4.71 +
    4.72 +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
    4.73 +{
    4.74 +    p_filefunc64_32->zfile_func64.zopen64_file = NULL;
    4.75 +    p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
    4.76 +    p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
    4.77 +    p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
    4.78 +    p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
    4.79 +    p_filefunc64_32->zfile_func64.ztell64_file = NULL;
    4.80 +    p_filefunc64_32->zfile_func64.zseek64_file = NULL;
    4.81 +    p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
    4.82 +    p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
    4.83 +    p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
    4.84 +    p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
    4.85 +    p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
    4.86 +}
    4.87 +
    4.88 +
    4.89 +
    4.90 +static voidpf  ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
    4.91 +static uLong   ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
    4.92 +static uLong   ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
    4.93 +static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
    4.94 +static long    ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
    4.95 +static int     ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
    4.96 +static int     ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
    4.97 +
    4.98 +static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
    4.99 +{
   4.100 +    FILE* file = NULL;
   4.101 +    const char* mode_fopen = NULL;
   4.102 +    if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
   4.103 +        mode_fopen = "rb";
   4.104 +    else
   4.105 +    if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
   4.106 +        mode_fopen = "r+b";
   4.107 +    else
   4.108 +    if (mode & ZLIB_FILEFUNC_MODE_CREATE)
   4.109 +        mode_fopen = "wb";
   4.110 +
   4.111 +    if ((filename!=NULL) && (mode_fopen != NULL))
   4.112 +        file = fopen(filename, mode_fopen);
   4.113 +    return file;
   4.114 +}
   4.115 +
   4.116 +static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
   4.117 +{
   4.118 +    FILE* file = NULL;
   4.119 +    const char* mode_fopen = NULL;
   4.120 +    if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
   4.121 +        mode_fopen = "rb";
   4.122 +    else
   4.123 +    if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
   4.124 +        mode_fopen = "r+b";
   4.125 +    else
   4.126 +    if (mode & ZLIB_FILEFUNC_MODE_CREATE)
   4.127 +        mode_fopen = "wb";
   4.128 +
   4.129 +    if ((filename!=NULL) && (mode_fopen != NULL))
   4.130 +        file = FOPEN_FUNC((const char*)filename, mode_fopen);
   4.131 +    return file;
   4.132 +}
   4.133 +
   4.134 +
   4.135 +static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
   4.136 +{
   4.137 +    uLong ret;
   4.138 +    ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
   4.139 +    return ret;
   4.140 +}
   4.141 +
   4.142 +static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
   4.143 +{
   4.144 +    uLong ret;
   4.145 +    ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
   4.146 +    return ret;
   4.147 +}
   4.148 +
   4.149 +static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
   4.150 +{
   4.151 +    long ret;
   4.152 +    ret = ftell((FILE *)stream);
   4.153 +    return ret;
   4.154 +}
   4.155 +
   4.156 +
   4.157 +static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
   4.158 +{
   4.159 +    ZPOS64_T ret;
   4.160 +    ret = FTELLO_FUNC((FILE *)stream);
   4.161 +    return ret;
   4.162 +}
   4.163 +
   4.164 +static long ZCALLBACK fseek_file_func (voidpf  opaque, voidpf stream, uLong offset, int origin)
   4.165 +{
   4.166 +    int fseek_origin=0;
   4.167 +    long ret;
   4.168 +    switch (origin)
   4.169 +    {
   4.170 +    case ZLIB_FILEFUNC_SEEK_CUR :
   4.171 +        fseek_origin = SEEK_CUR;
   4.172 +        break;
   4.173 +    case ZLIB_FILEFUNC_SEEK_END :
   4.174 +        fseek_origin = SEEK_END;
   4.175 +        break;
   4.176 +    case ZLIB_FILEFUNC_SEEK_SET :
   4.177 +        fseek_origin = SEEK_SET;
   4.178 +        break;
   4.179 +    default: return -1;
   4.180 +    }
   4.181 +    ret = 0;
   4.182 +    if (fseek((FILE *)stream, offset, fseek_origin) != 0)
   4.183 +        ret = -1;
   4.184 +    return ret;
   4.185 +}
   4.186 +
   4.187 +static long ZCALLBACK fseek64_file_func (voidpf  opaque, voidpf stream, ZPOS64_T offset, int origin)
   4.188 +{
   4.189 +    int fseek_origin=0;
   4.190 +    long ret;
   4.191 +    switch (origin)
   4.192 +    {
   4.193 +    case ZLIB_FILEFUNC_SEEK_CUR :
   4.194 +        fseek_origin = SEEK_CUR;
   4.195 +        break;
   4.196 +    case ZLIB_FILEFUNC_SEEK_END :
   4.197 +        fseek_origin = SEEK_END;
   4.198 +        break;
   4.199 +    case ZLIB_FILEFUNC_SEEK_SET :
   4.200 +        fseek_origin = SEEK_SET;
   4.201 +        break;
   4.202 +    default: return -1;
   4.203 +    }
   4.204 +    ret = 0;
   4.205 +
   4.206 +    if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0)
   4.207 +                        ret = -1;
   4.208 +
   4.209 +    return ret;
   4.210 +}
   4.211 +
   4.212 +
   4.213 +static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
   4.214 +{
   4.215 +    int ret;
   4.216 +    ret = fclose((FILE *)stream);
   4.217 +    return ret;
   4.218 +}
   4.219 +
   4.220 +static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
   4.221 +{
   4.222 +    int ret;
   4.223 +    ret = ferror((FILE *)stream);
   4.224 +    return ret;
   4.225 +}
   4.226 +
   4.227 +void fill_fopen_filefunc (pzlib_filefunc_def)
   4.228 +  zlib_filefunc_def* pzlib_filefunc_def;
   4.229 +{
   4.230 +    pzlib_filefunc_def->zopen_file = fopen_file_func;
   4.231 +    pzlib_filefunc_def->zread_file = fread_file_func;
   4.232 +    pzlib_filefunc_def->zwrite_file = fwrite_file_func;
   4.233 +    pzlib_filefunc_def->ztell_file = ftell_file_func;
   4.234 +    pzlib_filefunc_def->zseek_file = fseek_file_func;
   4.235 +    pzlib_filefunc_def->zclose_file = fclose_file_func;
   4.236 +    pzlib_filefunc_def->zerror_file = ferror_file_func;
   4.237 +    pzlib_filefunc_def->opaque = NULL;
   4.238 +}
   4.239 +
   4.240 +void fill_fopen64_filefunc (zlib_filefunc64_def*  pzlib_filefunc_def)
   4.241 +{
   4.242 +    pzlib_filefunc_def->zopen64_file = fopen64_file_func;
   4.243 +    pzlib_filefunc_def->zread_file = fread_file_func;
   4.244 +    pzlib_filefunc_def->zwrite_file = fwrite_file_func;
   4.245 +    pzlib_filefunc_def->ztell64_file = ftell64_file_func;
   4.246 +    pzlib_filefunc_def->zseek64_file = fseek64_file_func;
   4.247 +    pzlib_filefunc_def->zclose_file = fclose_file_func;
   4.248 +    pzlib_filefunc_def->zerror_file = ferror_file_func;
   4.249 +    pzlib_filefunc_def->opaque = NULL;
   4.250 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/minizip/ioapi.h	Sun Sep 09 06:05:11 2012 +0300
     5.3 @@ -0,0 +1,208 @@
     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 +         Changes
    5.15 +
    5.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)
    5.17 +    Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
    5.18 +               More if/def section may be needed to support other platforms
    5.19 +    Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
    5.20 +                          (but you should use iowin32.c for windows instead)
    5.21 +
    5.22 +*/
    5.23 +
    5.24 +#ifndef _ZLIBIOAPI64_H
    5.25 +#define _ZLIBIOAPI64_H
    5.26 +
    5.27 +#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
    5.28 +
    5.29 +  // Linux needs this to support file operation on files larger then 4+GB
    5.30 +  // But might need better if/def to select just the platforms that needs them.
    5.31 +
    5.32 +        #ifndef __USE_FILE_OFFSET64
    5.33 +                #define __USE_FILE_OFFSET64
    5.34 +        #endif
    5.35 +        #ifndef __USE_LARGEFILE64
    5.36 +                #define __USE_LARGEFILE64
    5.37 +        #endif
    5.38 +        #ifndef _LARGEFILE64_SOURCE
    5.39 +                #define _LARGEFILE64_SOURCE
    5.40 +        #endif
    5.41 +        #ifndef _FILE_OFFSET_BIT
    5.42 +                #define _FILE_OFFSET_BIT 64
    5.43 +        #endif
    5.44 +
    5.45 +#endif
    5.46 +
    5.47 +#include <stdio.h>
    5.48 +#include <stdlib.h>
    5.49 +#include "zlib.h"
    5.50 +
    5.51 +#if defined(USE_FILE32API)
    5.52 +#define fopen64 fopen
    5.53 +#define ftello64 ftell
    5.54 +#define fseeko64 fseek
    5.55 +#else
    5.56 +#ifdef __FreeBSD__
    5.57 +#define fopen64 fopen
    5.58 +#define ftello64 ftello
    5.59 +#define fseeko64 fseeko
    5.60 +#endif
    5.61 +#ifdef _MSC_VER
    5.62 + #define fopen64 fopen
    5.63 + #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
    5.64 +  #define ftello64 _ftelli64
    5.65 +  #define fseeko64 _fseeki64
    5.66 + #else // old MSC
    5.67 +  #define ftello64 ftell
    5.68 +  #define fseeko64 fseek
    5.69 + #endif
    5.70 +#endif
    5.71 +#endif
    5.72 +
    5.73 +/*
    5.74 +#ifndef ZPOS64_T
    5.75 +  #ifdef _WIN32
    5.76 +                #define ZPOS64_T fpos_t
    5.77 +  #else
    5.78 +    #include <stdint.h>
    5.79 +    #define ZPOS64_T uint64_t
    5.80 +  #endif
    5.81 +#endif
    5.82 +*/
    5.83 +
    5.84 +#ifdef HAVE_MINIZIP64_CONF_H
    5.85 +#include "mz64conf.h"
    5.86 +#endif
    5.87 +
    5.88 +/* a type choosen by DEFINE */
    5.89 +#ifdef HAVE_64BIT_INT_CUSTOM
    5.90 +typedef  64BIT_INT_CUSTOM_TYPE ZPOS64_T;
    5.91 +#else
    5.92 +#ifdef HAS_STDINT_H
    5.93 +#include "stdint.h"
    5.94 +typedef uint64_t ZPOS64_T;
    5.95 +#else
    5.96 +
    5.97 +/* Maximum unsigned 32-bit value used as placeholder for zip64 */
    5.98 +#define MAXU32 0xffffffff
    5.99 +
   5.100 +#if defined(_MSC_VER) || defined(__BORLANDC__)
   5.101 +typedef unsigned __int64 ZPOS64_T;
   5.102 +#else
   5.103 +typedef unsigned long long int ZPOS64_T;
   5.104 +#endif
   5.105 +#endif
   5.106 +#endif
   5.107 +
   5.108 +
   5.109 +
   5.110 +#ifdef __cplusplus
   5.111 +extern "C" {
   5.112 +#endif
   5.113 +
   5.114 +
   5.115 +#define ZLIB_FILEFUNC_SEEK_CUR (1)
   5.116 +#define ZLIB_FILEFUNC_SEEK_END (2)
   5.117 +#define ZLIB_FILEFUNC_SEEK_SET (0)
   5.118 +
   5.119 +#define ZLIB_FILEFUNC_MODE_READ      (1)
   5.120 +#define ZLIB_FILEFUNC_MODE_WRITE     (2)
   5.121 +#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
   5.122 +
   5.123 +#define ZLIB_FILEFUNC_MODE_EXISTING (4)
   5.124 +#define ZLIB_FILEFUNC_MODE_CREATE   (8)
   5.125 +
   5.126 +
   5.127 +#ifndef ZCALLBACK
   5.128 + #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
   5.129 +   #define ZCALLBACK CALLBACK
   5.130 + #else
   5.131 +   #define ZCALLBACK
   5.132 + #endif
   5.133 +#endif
   5.134 +
   5.135 +
   5.136 +
   5.137 +
   5.138 +typedef voidpf   (ZCALLBACK *open_file_func)      OF((voidpf opaque, const char* filename, int mode));
   5.139 +typedef uLong    (ZCALLBACK *read_file_func)      OF((voidpf opaque, voidpf stream, void* buf, uLong size));
   5.140 +typedef uLong    (ZCALLBACK *write_file_func)     OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
   5.141 +typedef int      (ZCALLBACK *close_file_func)     OF((voidpf opaque, voidpf stream));
   5.142 +typedef int      (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
   5.143 +
   5.144 +typedef long     (ZCALLBACK *tell_file_func)      OF((voidpf opaque, voidpf stream));
   5.145 +typedef long     (ZCALLBACK *seek_file_func)      OF((voidpf opaque, voidpf stream, uLong offset, int origin));
   5.146 +
   5.147 +
   5.148 +/* here is the "old" 32 bits structure structure */
   5.149 +typedef struct zlib_filefunc_def_s
   5.150 +{
   5.151 +    open_file_func      zopen_file;
   5.152 +    read_file_func      zread_file;
   5.153 +    write_file_func     zwrite_file;
   5.154 +    tell_file_func      ztell_file;
   5.155 +    seek_file_func      zseek_file;
   5.156 +    close_file_func     zclose_file;
   5.157 +    testerror_file_func zerror_file;
   5.158 +    voidpf              opaque;
   5.159 +} zlib_filefunc_def;
   5.160 +
   5.161 +typedef ZPOS64_T (ZCALLBACK *tell64_file_func)    OF((voidpf opaque, voidpf stream));
   5.162 +typedef long     (ZCALLBACK *seek64_file_func)    OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
   5.163 +typedef voidpf   (ZCALLBACK *open64_file_func)    OF((voidpf opaque, const void* filename, int mode));
   5.164 +
   5.165 +typedef struct zlib_filefunc64_def_s
   5.166 +{
   5.167 +    open64_file_func    zopen64_file;
   5.168 +    read_file_func      zread_file;
   5.169 +    write_file_func     zwrite_file;
   5.170 +    tell64_file_func    ztell64_file;
   5.171 +    seek64_file_func    zseek64_file;
   5.172 +    close_file_func     zclose_file;
   5.173 +    testerror_file_func zerror_file;
   5.174 +    voidpf              opaque;
   5.175 +} zlib_filefunc64_def;
   5.176 +
   5.177 +void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
   5.178 +void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
   5.179 +
   5.180 +/* now internal definition, only for zip.c and unzip.h */
   5.181 +typedef struct zlib_filefunc64_32_def_s
   5.182 +{
   5.183 +    zlib_filefunc64_def zfile_func64;
   5.184 +    open_file_func      zopen32_file;
   5.185 +    tell_file_func      ztell32_file;
   5.186 +    seek_file_func      zseek32_file;
   5.187 +} zlib_filefunc64_32_def;
   5.188 +
   5.189 +
   5.190 +#define ZREAD64(filefunc,filestream,buf,size)     ((*((filefunc).zfile_func64.zread_file))   ((filefunc).zfile_func64.opaque,filestream,buf,size))
   5.191 +#define ZWRITE64(filefunc,filestream,buf,size)    ((*((filefunc).zfile_func64.zwrite_file))  ((filefunc).zfile_func64.opaque,filestream,buf,size))
   5.192 +//#define ZTELL64(filefunc,filestream)            ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
   5.193 +//#define ZSEEK64(filefunc,filestream,pos,mode)   ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
   5.194 +#define ZCLOSE64(filefunc,filestream)             ((*((filefunc).zfile_func64.zclose_file))  ((filefunc).zfile_func64.opaque,filestream))
   5.195 +#define ZERROR64(filefunc,filestream)             ((*((filefunc).zfile_func64.zerror_file))  ((filefunc).zfile_func64.opaque,filestream))
   5.196 +
   5.197 +voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
   5.198 +long    call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
   5.199 +ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
   5.200 +
   5.201 +void    fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
   5.202 +
   5.203 +#define ZOPEN64(filefunc,filename,mode)         (call_zopen64((&(filefunc)),(filename),(mode)))
   5.204 +#define ZTELL64(filefunc,filestream)            (call_ztell64((&(filefunc)),(filestream)))
   5.205 +#define ZSEEK64(filefunc,filestream,pos,mode)   (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
   5.206 +
   5.207 +#ifdef __cplusplus
   5.208 +}
   5.209 +#endif
   5.210 +
   5.211 +#endif
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/minizip/unzip.c	Sun Sep 09 06:05:11 2012 +0300
     6.3 @@ -0,0 +1,2125 @@
     6.4 +/* unzip.c -- IO for uncompress .zip files using zlib
     6.5 +   Version 1.1, February 14h, 2010
     6.6 +   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
     6.7 +
     6.8 +         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
     6.9 +
    6.10 +         Modifications of Unzip for Zip64
    6.11 +         Copyright (C) 2007-2008 Even Rouault
    6.12 +
    6.13 +         Modifications for Zip64 support on both zip and unzip
    6.14 +         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
    6.15 +
    6.16 +         For more info read MiniZip_info.txt
    6.17 +
    6.18 +
    6.19 +  ------------------------------------------------------------------------------------
    6.20 +  Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
    6.21 +  compatibility with older software. The following is from the original crypt.c.
    6.22 +  Code woven in by Terry Thorsen 1/2003.
    6.23 +
    6.24 +  Copyright (c) 1990-2000 Info-ZIP.  All rights reserved.
    6.25 +
    6.26 +  See the accompanying file LICENSE, version 2000-Apr-09 or later
    6.27 +  (the contents of which are also included in zip.h) for terms of use.
    6.28 +  If, for some reason, all these files are missing, the Info-ZIP license
    6.29 +  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
    6.30 +
    6.31 +        crypt.c (full version) by Info-ZIP.      Last revised:  [see crypt.h]
    6.32 +
    6.33 +  The encryption/decryption parts of this source code (as opposed to the
    6.34 +  non-echoing password parts) were originally written in Europe.  The
    6.35 +  whole source package can be freely distributed, including from the USA.
    6.36 +  (Prior to January 2000, re-export from the US was a violation of US law.)
    6.37 +
    6.38 +        This encryption code is a direct transcription of the algorithm from
    6.39 +  Roger Schlafly, described by Phil Katz in the file appnote.txt.  This
    6.40 +  file (appnote.txt) is distributed with the PKZIP program (even in the
    6.41 +  version without encryption capabilities).
    6.42 +
    6.43 +        ------------------------------------------------------------------------------------
    6.44 +
    6.45 +        Changes in unzip.c
    6.46 +
    6.47 +        2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos
    6.48 +  2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz*
    6.49 +  2007-2008 - Even Rouault - Remove old C style function prototypes
    6.50 +  2007-2008 - Even Rouault - Add unzip support for ZIP64
    6.51 +
    6.52 +        Copyright (C) 2007-2008 Even Rouault
    6.53 +
    6.54 +
    6.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).
    6.56 +  Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
    6.57 +                                should only read the compressed/uncompressed size from the Zip64 format if
    6.58 +                                the size from normal header was 0xFFFFFFFF
    6.59 +  Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
    6.60 +        Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
    6.61 +                                Patch created by Daniel Borca
    6.62 +
    6.63 +  Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
    6.64 +
    6.65 +  Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
    6.66 +
    6.67 +*/
    6.68 +
    6.69 +
    6.70 +#include <stdio.h>
    6.71 +#include <stdlib.h>
    6.72 +#include <string.h>
    6.73 +
    6.74 +#ifndef NOUNCRYPT
    6.75 +        #define NOUNCRYPT
    6.76 +#endif
    6.77 +
    6.78 +#include "zlib.h"
    6.79 +#include "unzip.h"
    6.80 +
    6.81 +#ifdef STDC
    6.82 +#  include <stddef.h>
    6.83 +#  include <string.h>
    6.84 +#  include <stdlib.h>
    6.85 +#endif
    6.86 +#ifdef NO_ERRNO_H
    6.87 +    extern int errno;
    6.88 +#else
    6.89 +#   include <errno.h>
    6.90 +#endif
    6.91 +
    6.92 +
    6.93 +#ifndef local
    6.94 +#  define local static
    6.95 +#endif
    6.96 +/* compile with -Dlocal if your debugger can't find static symbols */
    6.97 +
    6.98 +
    6.99 +#ifndef CASESENSITIVITYDEFAULT_NO
   6.100 +#  if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
   6.101 +#    define CASESENSITIVITYDEFAULT_NO
   6.102 +#  endif
   6.103 +#endif
   6.104 +
   6.105 +
   6.106 +#ifndef UNZ_BUFSIZE
   6.107 +#define UNZ_BUFSIZE (16384)
   6.108 +#endif
   6.109 +
   6.110 +#ifndef UNZ_MAXFILENAMEINZIP
   6.111 +#define UNZ_MAXFILENAMEINZIP (256)
   6.112 +#endif
   6.113 +
   6.114 +#ifndef ALLOC
   6.115 +# define ALLOC(size) (malloc(size))
   6.116 +#endif
   6.117 +#ifndef TRYFREE
   6.118 +# define TRYFREE(p) {if (p) free(p);}
   6.119 +#endif
   6.120 +
   6.121 +#define SIZECENTRALDIRITEM (0x2e)
   6.122 +#define SIZEZIPLOCALHEADER (0x1e)
   6.123 +
   6.124 +
   6.125 +const char unz_copyright[] =
   6.126 +   " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
   6.127 +
   6.128 +/* unz_file_info_interntal contain internal info about a file in zipfile*/
   6.129 +typedef struct unz_file_info64_internal_s
   6.130 +{
   6.131 +    ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */
   6.132 +} unz_file_info64_internal;
   6.133 +
   6.134 +
   6.135 +/* file_in_zip_read_info_s contain internal information about a file in zipfile,
   6.136 +    when reading and decompress it */
   6.137 +typedef struct
   6.138 +{
   6.139 +    char  *read_buffer;         /* internal buffer for compressed data */
   6.140 +    z_stream stream;            /* zLib stream structure for inflate */
   6.141 +
   6.142 +#ifdef HAVE_BZIP2
   6.143 +    bz_stream bstream;          /* bzLib stream structure for bziped */
   6.144 +#endif
   6.145 +
   6.146 +    ZPOS64_T pos_in_zipfile;       /* position in byte on the zipfile, for fseek*/
   6.147 +    uLong stream_initialised;   /* flag set if stream structure is initialised*/
   6.148 +
   6.149 +    ZPOS64_T offset_local_extrafield;/* offset of the local extra field */
   6.150 +    uInt  size_local_extrafield;/* size of the local extra field */
   6.151 +    ZPOS64_T pos_local_extrafield;   /* position in the local extra field in read*/
   6.152 +    ZPOS64_T total_out_64;
   6.153 +
   6.154 +    uLong crc32;                /* crc32 of all data uncompressed */
   6.155 +    uLong crc32_wait;           /* crc32 we must obtain after decompress all */
   6.156 +    ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
   6.157 +    ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
   6.158 +    zlib_filefunc64_32_def z_filefunc;
   6.159 +    voidpf filestream;        /* io structore of the zipfile */
   6.160 +    uLong compression_method;   /* compression method (0==store) */
   6.161 +    ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
   6.162 +    int   raw;
   6.163 +} file_in_zip64_read_info_s;
   6.164 +
   6.165 +
   6.166 +/* unz64_s contain internal information about the zipfile
   6.167 +*/
   6.168 +typedef struct
   6.169 +{
   6.170 +    zlib_filefunc64_32_def z_filefunc;
   6.171 +    int is64bitOpenFunction;
   6.172 +    voidpf filestream;        /* io structore of the zipfile */
   6.173 +    unz_global_info64 gi;       /* public global information */
   6.174 +    ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
   6.175 +    ZPOS64_T num_file;             /* number of the current file in the zipfile*/
   6.176 +    ZPOS64_T pos_in_central_dir;   /* pos of the current file in the central dir*/
   6.177 +    ZPOS64_T current_file_ok;      /* flag about the usability of the current file*/
   6.178 +    ZPOS64_T central_pos;          /* position of the beginning of the central dir*/
   6.179 +
   6.180 +    ZPOS64_T size_central_dir;     /* size of the central directory  */
   6.181 +    ZPOS64_T offset_central_dir;   /* offset of start of central directory with
   6.182 +                                   respect to the starting disk number */
   6.183 +
   6.184 +    unz_file_info64 cur_file_info; /* public info about the current file in zip*/
   6.185 +    unz_file_info64_internal cur_file_info_internal; /* private info about it*/
   6.186 +    file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current
   6.187 +                                        file if we are decompressing it */
   6.188 +    int encrypted;
   6.189 +
   6.190 +    int isZip64;
   6.191 +
   6.192 +#    ifndef NOUNCRYPT
   6.193 +    unsigned long keys[3];     /* keys defining the pseudo-random sequence */
   6.194 +    const unsigned long* pcrc_32_tab;
   6.195 +#    endif
   6.196 +} unz64_s;
   6.197 +
   6.198 +
   6.199 +#ifndef NOUNCRYPT
   6.200 +#include "crypt.h"
   6.201 +#endif
   6.202 +
   6.203 +/* ===========================================================================
   6.204 +     Read a byte from a gz_stream; update next_in and avail_in. Return EOF
   6.205 +   for end of file.
   6.206 +   IN assertion: the stream s has been sucessfully opened for reading.
   6.207 +*/
   6.208 +
   6.209 +
   6.210 +local int unz64local_getByte OF((
   6.211 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
   6.212 +    voidpf filestream,
   6.213 +    int *pi));
   6.214 +
   6.215 +local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)
   6.216 +{
   6.217 +    unsigned char c;
   6.218 +    int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
   6.219 +    if (err==1)
   6.220 +    {
   6.221 +        *pi = (int)c;
   6.222 +        return UNZ_OK;
   6.223 +    }
   6.224 +    else
   6.225 +    {
   6.226 +        if (ZERROR64(*pzlib_filefunc_def,filestream))
   6.227 +            return UNZ_ERRNO;
   6.228 +        else
   6.229 +            return UNZ_EOF;
   6.230 +    }
   6.231 +}
   6.232 +
   6.233 +
   6.234 +/* ===========================================================================
   6.235 +   Reads a long in LSB order from the given gz_stream. Sets
   6.236 +*/
   6.237 +local int unz64local_getShort OF((
   6.238 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
   6.239 +    voidpf filestream,
   6.240 +    uLong *pX));
   6.241 +
   6.242 +local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
   6.243 +                             voidpf filestream,
   6.244 +                             uLong *pX)
   6.245 +{
   6.246 +    uLong x ;
   6.247 +    int i = 0;
   6.248 +    int err;
   6.249 +
   6.250 +    err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.251 +    x = (uLong)i;
   6.252 +
   6.253 +    if (err==UNZ_OK)
   6.254 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.255 +    x |= ((uLong)i)<<8;
   6.256 +
   6.257 +    if (err==UNZ_OK)
   6.258 +        *pX = x;
   6.259 +    else
   6.260 +        *pX = 0;
   6.261 +    return err;
   6.262 +}
   6.263 +
   6.264 +local int unz64local_getLong OF((
   6.265 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
   6.266 +    voidpf filestream,
   6.267 +    uLong *pX));
   6.268 +
   6.269 +local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
   6.270 +                            voidpf filestream,
   6.271 +                            uLong *pX)
   6.272 +{
   6.273 +    uLong x ;
   6.274 +    int i = 0;
   6.275 +    int err;
   6.276 +
   6.277 +    err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.278 +    x = (uLong)i;
   6.279 +
   6.280 +    if (err==UNZ_OK)
   6.281 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.282 +    x |= ((uLong)i)<<8;
   6.283 +
   6.284 +    if (err==UNZ_OK)
   6.285 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.286 +    x |= ((uLong)i)<<16;
   6.287 +
   6.288 +    if (err==UNZ_OK)
   6.289 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.290 +    x += ((uLong)i)<<24;
   6.291 +
   6.292 +    if (err==UNZ_OK)
   6.293 +        *pX = x;
   6.294 +    else
   6.295 +        *pX = 0;
   6.296 +    return err;
   6.297 +}
   6.298 +
   6.299 +local int unz64local_getLong64 OF((
   6.300 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
   6.301 +    voidpf filestream,
   6.302 +    ZPOS64_T *pX));
   6.303 +
   6.304 +
   6.305 +local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
   6.306 +                            voidpf filestream,
   6.307 +                            ZPOS64_T *pX)
   6.308 +{
   6.309 +    ZPOS64_T x ;
   6.310 +    int i = 0;
   6.311 +    int err;
   6.312 +
   6.313 +    err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.314 +    x = (ZPOS64_T)i;
   6.315 +
   6.316 +    if (err==UNZ_OK)
   6.317 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.318 +    x |= ((ZPOS64_T)i)<<8;
   6.319 +
   6.320 +    if (err==UNZ_OK)
   6.321 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.322 +    x |= ((ZPOS64_T)i)<<16;
   6.323 +
   6.324 +    if (err==UNZ_OK)
   6.325 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.326 +    x |= ((ZPOS64_T)i)<<24;
   6.327 +
   6.328 +    if (err==UNZ_OK)
   6.329 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.330 +    x |= ((ZPOS64_T)i)<<32;
   6.331 +
   6.332 +    if (err==UNZ_OK)
   6.333 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.334 +    x |= ((ZPOS64_T)i)<<40;
   6.335 +
   6.336 +    if (err==UNZ_OK)
   6.337 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.338 +    x |= ((ZPOS64_T)i)<<48;
   6.339 +
   6.340 +    if (err==UNZ_OK)
   6.341 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   6.342 +    x |= ((ZPOS64_T)i)<<56;
   6.343 +
   6.344 +    if (err==UNZ_OK)
   6.345 +        *pX = x;
   6.346 +    else
   6.347 +        *pX = 0;
   6.348 +    return err;
   6.349 +}
   6.350 +
   6.351 +/* My own strcmpi / strcasecmp */
   6.352 +local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
   6.353 +{
   6.354 +    for (;;)
   6.355 +    {
   6.356 +        char c1=*(fileName1++);
   6.357 +        char c2=*(fileName2++);
   6.358 +        if ((c1>='a') && (c1<='z'))
   6.359 +            c1 -= 0x20;
   6.360 +        if ((c2>='a') && (c2<='z'))
   6.361 +            c2 -= 0x20;
   6.362 +        if (c1=='\0')
   6.363 +            return ((c2=='\0') ? 0 : -1);
   6.364 +        if (c2=='\0')
   6.365 +            return 1;
   6.366 +        if (c1<c2)
   6.367 +            return -1;
   6.368 +        if (c1>c2)
   6.369 +            return 1;
   6.370 +    }
   6.371 +}
   6.372 +
   6.373 +
   6.374 +#ifdef  CASESENSITIVITYDEFAULT_NO
   6.375 +#define CASESENSITIVITYDEFAULTVALUE 2
   6.376 +#else
   6.377 +#define CASESENSITIVITYDEFAULTVALUE 1
   6.378 +#endif
   6.379 +
   6.380 +#ifndef STRCMPCASENOSENTIVEFUNCTION
   6.381 +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
   6.382 +#endif
   6.383 +
   6.384 +/*
   6.385 +   Compare two filename (fileName1,fileName2).
   6.386 +   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
   6.387 +   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
   6.388 +                                                                or strcasecmp)
   6.389 +   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
   6.390 +        (like 1 on Unix, 2 on Windows)
   6.391 +
   6.392 +*/
   6.393 +extern int ZEXPORT unzStringFileNameCompare (const char*  fileName1,
   6.394 +                                                 const char*  fileName2,
   6.395 +                                                 int iCaseSensitivity)
   6.396 +
   6.397 +{
   6.398 +    if (iCaseSensitivity==0)
   6.399 +        iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
   6.400 +
   6.401 +    if (iCaseSensitivity==1)
   6.402 +        return strcmp(fileName1,fileName2);
   6.403 +
   6.404 +    return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
   6.405 +}
   6.406 +
   6.407 +#ifndef BUFREADCOMMENT
   6.408 +#define BUFREADCOMMENT (0x400)
   6.409 +#endif
   6.410 +
   6.411 +/*
   6.412 +  Locate the Central directory of a zipfile (at the end, just before
   6.413 +    the global comment)
   6.414 +*/
   6.415 +local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
   6.416 +local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
   6.417 +{
   6.418 +    unsigned char* buf;
   6.419 +    ZPOS64_T uSizeFile;
   6.420 +    ZPOS64_T uBackRead;
   6.421 +    ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
   6.422 +    ZPOS64_T uPosFound=0;
   6.423 +
   6.424 +    if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
   6.425 +        return 0;
   6.426 +
   6.427 +
   6.428 +    uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
   6.429 +
   6.430 +    if (uMaxBack>uSizeFile)
   6.431 +        uMaxBack = uSizeFile;
   6.432 +
   6.433 +    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
   6.434 +    if (buf==NULL)
   6.435 +        return 0;
   6.436 +
   6.437 +    uBackRead = 4;
   6.438 +    while (uBackRead<uMaxBack)
   6.439 +    {
   6.440 +        uLong uReadSize;
   6.441 +        ZPOS64_T uReadPos ;
   6.442 +        int i;
   6.443 +        if (uBackRead+BUFREADCOMMENT>uMaxBack)
   6.444 +            uBackRead = uMaxBack;
   6.445 +        else
   6.446 +            uBackRead+=BUFREADCOMMENT;
   6.447 +        uReadPos = uSizeFile-uBackRead ;
   6.448 +
   6.449 +        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
   6.450 +                     (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
   6.451 +        if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
   6.452 +            break;
   6.453 +
   6.454 +        if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
   6.455 +            break;
   6.456 +
   6.457 +        for (i=(int)uReadSize-3; (i--)>0;)
   6.458 +            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
   6.459 +                ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
   6.460 +            {
   6.461 +                uPosFound = uReadPos+i;
   6.462 +                break;
   6.463 +            }
   6.464 +
   6.465 +        if (uPosFound!=0)
   6.466 +            break;
   6.467 +    }
   6.468 +    TRYFREE(buf);
   6.469 +    return uPosFound;
   6.470 +}
   6.471 +
   6.472 +
   6.473 +/*
   6.474 +  Locate the Central directory 64 of a zipfile (at the end, just before
   6.475 +    the global comment)
   6.476 +*/
   6.477 +local ZPOS64_T unz64local_SearchCentralDir64 OF((
   6.478 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
   6.479 +    voidpf filestream));
   6.480 +
   6.481 +local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
   6.482 +                                      voidpf filestream)
   6.483 +{
   6.484 +    unsigned char* buf;
   6.485 +    ZPOS64_T uSizeFile;
   6.486 +    ZPOS64_T uBackRead;
   6.487 +    ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
   6.488 +    ZPOS64_T uPosFound=0;
   6.489 +    uLong uL;
   6.490 +                ZPOS64_T relativeOffset;
   6.491 +
   6.492 +    if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
   6.493 +        return 0;
   6.494 +
   6.495 +
   6.496 +    uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
   6.497 +
   6.498 +    if (uMaxBack>uSizeFile)
   6.499 +        uMaxBack = uSizeFile;
   6.500 +
   6.501 +    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
   6.502 +    if (buf==NULL)
   6.503 +        return 0;
   6.504 +
   6.505 +    uBackRead = 4;
   6.506 +    while (uBackRead<uMaxBack)
   6.507 +    {
   6.508 +        uLong uReadSize;
   6.509 +        ZPOS64_T uReadPos;
   6.510 +        int i;
   6.511 +        if (uBackRead+BUFREADCOMMENT>uMaxBack)
   6.512 +            uBackRead = uMaxBack;
   6.513 +        else
   6.514 +            uBackRead+=BUFREADCOMMENT;
   6.515 +        uReadPos = uSizeFile-uBackRead ;
   6.516 +
   6.517 +        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
   6.518 +                     (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
   6.519 +        if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
   6.520 +            break;
   6.521 +
   6.522 +        if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
   6.523 +            break;
   6.524 +
   6.525 +        for (i=(int)uReadSize-3; (i--)>0;)
   6.526 +            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
   6.527 +                ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
   6.528 +            {
   6.529 +                uPosFound = uReadPos+i;
   6.530 +                break;
   6.531 +            }
   6.532 +
   6.533 +        if (uPosFound!=0)
   6.534 +            break;
   6.535 +    }
   6.536 +    TRYFREE(buf);
   6.537 +    if (uPosFound == 0)
   6.538 +        return 0;
   6.539 +
   6.540 +    /* Zip64 end of central directory locator */
   6.541 +    if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
   6.542 +        return 0;
   6.543 +
   6.544 +    /* the signature, already checked */
   6.545 +    if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
   6.546 +        return 0;
   6.547 +
   6.548 +    /* number of the disk with the start of the zip64 end of  central directory */
   6.549 +    if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
   6.550 +        return 0;
   6.551 +    if (uL != 0)
   6.552 +        return 0;
   6.553 +
   6.554 +    /* relative offset of the zip64 end of central directory record */
   6.555 +    if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
   6.556 +        return 0;
   6.557 +
   6.558 +    /* total number of disks */
   6.559 +    if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
   6.560 +        return 0;
   6.561 +    if (uL != 1)
   6.562 +        return 0;
   6.563 +
   6.564 +    /* Goto end of central directory record */
   6.565 +    if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
   6.566 +        return 0;
   6.567 +
   6.568 +     /* the signature */
   6.569 +    if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
   6.570 +        return 0;
   6.571 +
   6.572 +    if (uL != 0x06064b50)
   6.573 +        return 0;
   6.574 +
   6.575 +    return relativeOffset;
   6.576 +}
   6.577 +
   6.578 +/*
   6.579 +  Open a Zip file. path contain the full pathname (by example,
   6.580 +     on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
   6.581 +     "zlib/zlib114.zip".
   6.582 +     If the zipfile cannot be opened (file doesn't exist or in not valid), the
   6.583 +       return value is NULL.
   6.584 +     Else, the return value is a unzFile Handle, usable with other function
   6.585 +       of this unzip package.
   6.586 +*/
   6.587 +local unzFile unzOpenInternal (const void *path,
   6.588 +                               zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
   6.589 +                               int is64bitOpenFunction)
   6.590 +{
   6.591 +    unz64_s us;
   6.592 +    unz64_s *s;
   6.593 +    ZPOS64_T central_pos;
   6.594 +    uLong   uL;
   6.595 +
   6.596 +    uLong number_disk;          /* number of the current dist, used for
   6.597 +                                   spaning ZIP, unsupported, always 0*/
   6.598 +    uLong number_disk_with_CD;  /* number the the disk with central dir, used
   6.599 +                                   for spaning ZIP, unsupported, always 0*/
   6.600 +    ZPOS64_T number_entry_CD;      /* total number of entries in
   6.601 +                                   the central dir
   6.602 +                                   (same than number_entry on nospan) */
   6.603 +
   6.604 +    int err=UNZ_OK;
   6.605 +
   6.606 +    if (unz_copyright[0]!=' ')
   6.607 +        return NULL;
   6.608 +
   6.609 +    us.z_filefunc.zseek32_file = NULL;
   6.610 +    us.z_filefunc.ztell32_file = NULL;
   6.611 +    if (pzlib_filefunc64_32_def==NULL)
   6.612 +        fill_fopen64_filefunc(&us.z_filefunc.zfile_func64);
   6.613 +    else
   6.614 +        us.z_filefunc = *pzlib_filefunc64_32_def;
   6.615 +    us.is64bitOpenFunction = is64bitOpenFunction;
   6.616 +
   6.617 +
   6.618 +
   6.619 +    us.filestream = ZOPEN64(us.z_filefunc,
   6.620 +                                                 path,
   6.621 +                                                 ZLIB_FILEFUNC_MODE_READ |
   6.622 +                                                 ZLIB_FILEFUNC_MODE_EXISTING);
   6.623 +    if (us.filestream==NULL)
   6.624 +        return NULL;
   6.625 +
   6.626 +    central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
   6.627 +    if (central_pos)
   6.628 +    {
   6.629 +        uLong uS;
   6.630 +        ZPOS64_T uL64;
   6.631 +
   6.632 +        us.isZip64 = 1;
   6.633 +
   6.634 +        if (ZSEEK64(us.z_filefunc, us.filestream,
   6.635 +                                      central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
   6.636 +        err=UNZ_ERRNO;
   6.637 +
   6.638 +        /* the signature, already checked */
   6.639 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
   6.640 +            err=UNZ_ERRNO;
   6.641 +
   6.642 +        /* size of zip64 end of central directory record */
   6.643 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
   6.644 +            err=UNZ_ERRNO;
   6.645 +
   6.646 +        /* version made by */
   6.647 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
   6.648 +            err=UNZ_ERRNO;
   6.649 +
   6.650 +        /* version needed to extract */
   6.651 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
   6.652 +            err=UNZ_ERRNO;
   6.653 +
   6.654 +        /* number of this disk */
   6.655 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
   6.656 +            err=UNZ_ERRNO;
   6.657 +
   6.658 +        /* number of the disk with the start of the central directory */
   6.659 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
   6.660 +            err=UNZ_ERRNO;
   6.661 +
   6.662 +        /* total number of entries in the central directory on this disk */
   6.663 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
   6.664 +            err=UNZ_ERRNO;
   6.665 +
   6.666 +        /* total number of entries in the central directory */
   6.667 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
   6.668 +            err=UNZ_ERRNO;
   6.669 +
   6.670 +        if ((number_entry_CD!=us.gi.number_entry) ||
   6.671 +            (number_disk_with_CD!=0) ||
   6.672 +            (number_disk!=0))
   6.673 +            err=UNZ_BADZIPFILE;
   6.674 +
   6.675 +        /* size of the central directory */
   6.676 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
   6.677 +            err=UNZ_ERRNO;
   6.678 +
   6.679 +        /* offset of start of central directory with respect to the
   6.680 +          starting disk number */
   6.681 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
   6.682 +            err=UNZ_ERRNO;
   6.683 +
   6.684 +        us.gi.size_comment = 0;
   6.685 +    }
   6.686 +    else
   6.687 +    {
   6.688 +        central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
   6.689 +        if (central_pos==0)
   6.690 +            err=UNZ_ERRNO;
   6.691 +
   6.692 +        us.isZip64 = 0;
   6.693 +
   6.694 +        if (ZSEEK64(us.z_filefunc, us.filestream,
   6.695 +                                        central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
   6.696 +            err=UNZ_ERRNO;
   6.697 +
   6.698 +        /* the signature, already checked */
   6.699 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
   6.700 +            err=UNZ_ERRNO;
   6.701 +
   6.702 +        /* number of this disk */
   6.703 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
   6.704 +            err=UNZ_ERRNO;
   6.705 +
   6.706 +        /* number of the disk with the start of the central directory */
   6.707 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
   6.708 +            err=UNZ_ERRNO;
   6.709 +
   6.710 +        /* total number of entries in the central dir on this disk */
   6.711 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
   6.712 +            err=UNZ_ERRNO;
   6.713 +        us.gi.number_entry = uL;
   6.714 +
   6.715 +        /* total number of entries in the central dir */
   6.716 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
   6.717 +            err=UNZ_ERRNO;
   6.718 +        number_entry_CD = uL;
   6.719 +
   6.720 +        if ((number_entry_CD!=us.gi.number_entry) ||
   6.721 +            (number_disk_with_CD!=0) ||
   6.722 +            (number_disk!=0))
   6.723 +            err=UNZ_BADZIPFILE;
   6.724 +
   6.725 +        /* size of the central directory */
   6.726 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
   6.727 +            err=UNZ_ERRNO;
   6.728 +        us.size_central_dir = uL;
   6.729 +
   6.730 +        /* offset of start of central directory with respect to the
   6.731 +            starting disk number */
   6.732 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
   6.733 +            err=UNZ_ERRNO;
   6.734 +        us.offset_central_dir = uL;
   6.735 +
   6.736 +        /* zipfile comment length */
   6.737 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
   6.738 +            err=UNZ_ERRNO;
   6.739 +    }
   6.740 +
   6.741 +    if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
   6.742 +        (err==UNZ_OK))
   6.743 +        err=UNZ_BADZIPFILE;
   6.744 +
   6.745 +    if (err!=UNZ_OK)
   6.746 +    {
   6.747 +        ZCLOSE64(us.z_filefunc, us.filestream);
   6.748 +        return NULL;
   6.749 +    }
   6.750 +
   6.751 +    us.byte_before_the_zipfile = central_pos -
   6.752 +                            (us.offset_central_dir+us.size_central_dir);
   6.753 +    us.central_pos = central_pos;
   6.754 +    us.pfile_in_zip_read = NULL;
   6.755 +    us.encrypted = 0;
   6.756 +
   6.757 +
   6.758 +    s=(unz64_s*)ALLOC(sizeof(unz64_s));
   6.759 +    if( s != NULL)
   6.760 +    {
   6.761 +        *s=us;
   6.762 +        unzGoToFirstFile((unzFile)s);
   6.763 +    }
   6.764 +    return (unzFile)s;
   6.765 +}
   6.766 +
   6.767 +
   6.768 +extern unzFile ZEXPORT unzOpen2 (const char *path,
   6.769 +                                        zlib_filefunc_def* pzlib_filefunc32_def)
   6.770 +{
   6.771 +    if (pzlib_filefunc32_def != NULL)
   6.772 +    {
   6.773 +        zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
   6.774 +        fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
   6.775 +        return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
   6.776 +    }
   6.777 +    else
   6.778 +        return unzOpenInternal(path, NULL, 0);
   6.779 +}
   6.780 +
   6.781 +extern unzFile ZEXPORT unzOpen2_64 (const void *path,
   6.782 +                                     zlib_filefunc64_def* pzlib_filefunc_def)
   6.783 +{
   6.784 +    if (pzlib_filefunc_def != NULL)
   6.785 +    {
   6.786 +        zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
   6.787 +        zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
   6.788 +        zlib_filefunc64_32_def_fill.ztell32_file = NULL;
   6.789 +        zlib_filefunc64_32_def_fill.zseek32_file = NULL;
   6.790 +        return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1);
   6.791 +    }
   6.792 +    else
   6.793 +        return unzOpenInternal(path, NULL, 1);
   6.794 +}
   6.795 +
   6.796 +extern unzFile ZEXPORT unzOpen (const char *path)
   6.797 +{
   6.798 +    return unzOpenInternal(path, NULL, 0);
   6.799 +}
   6.800 +
   6.801 +extern unzFile ZEXPORT unzOpen64 (const void *path)
   6.802 +{
   6.803 +    return unzOpenInternal(path, NULL, 1);
   6.804 +}
   6.805 +
   6.806 +/*
   6.807 +  Close a ZipFile opened with unzipOpen.
   6.808 +  If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
   6.809 +    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
   6.810 +  return UNZ_OK if there is no problem. */
   6.811 +extern int ZEXPORT unzClose (unzFile file)
   6.812 +{
   6.813 +    unz64_s* s;
   6.814 +    if (file==NULL)
   6.815 +        return UNZ_PARAMERROR;
   6.816 +    s=(unz64_s*)file;
   6.817 +
   6.818 +    if (s->pfile_in_zip_read!=NULL)
   6.819 +        unzCloseCurrentFile(file);
   6.820 +
   6.821 +    ZCLOSE64(s->z_filefunc, s->filestream);
   6.822 +    TRYFREE(s);
   6.823 +    return UNZ_OK;
   6.824 +}
   6.825 +
   6.826 +
   6.827 +/*
   6.828 +  Write info about the ZipFile in the *pglobal_info structure.
   6.829 +  No preparation of the structure is needed
   6.830 +  return UNZ_OK if there is no problem. */
   6.831 +extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
   6.832 +{
   6.833 +    unz64_s* s;
   6.834 +    if (file==NULL)
   6.835 +        return UNZ_PARAMERROR;
   6.836 +    s=(unz64_s*)file;
   6.837 +    *pglobal_info=s->gi;
   6.838 +    return UNZ_OK;
   6.839 +}
   6.840 +
   6.841 +extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
   6.842 +{
   6.843 +    unz64_s* s;
   6.844 +    if (file==NULL)
   6.845 +        return UNZ_PARAMERROR;
   6.846 +    s=(unz64_s*)file;
   6.847 +    /* to do : check if number_entry is not truncated */
   6.848 +    pglobal_info32->number_entry = (uLong)s->gi.number_entry;
   6.849 +    pglobal_info32->size_comment = s->gi.size_comment;
   6.850 +    return UNZ_OK;
   6.851 +}
   6.852 +/*
   6.853 +   Translate date/time from Dos format to tm_unz (readable more easilty)
   6.854 +*/
   6.855 +local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
   6.856 +{
   6.857 +    ZPOS64_T uDate;
   6.858 +    uDate = (ZPOS64_T)(ulDosDate>>16);
   6.859 +    ptm->tm_mday = (uInt)(uDate&0x1f) ;
   6.860 +    ptm->tm_mon =  (uInt)((((uDate)&0x1E0)/0x20)-1) ;
   6.861 +    ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
   6.862 +
   6.863 +    ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
   6.864 +    ptm->tm_min =  (uInt) ((ulDosDate&0x7E0)/0x20) ;
   6.865 +    ptm->tm_sec =  (uInt) (2*(ulDosDate&0x1f)) ;
   6.866 +}
   6.867 +
   6.868 +/*
   6.869 +  Get Info about the current file in the zipfile, with internal only info
   6.870 +*/
   6.871 +local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
   6.872 +                                                  unz_file_info64 *pfile_info,
   6.873 +                                                  unz_file_info64_internal
   6.874 +                                                  *pfile_info_internal,
   6.875 +                                                  char *szFileName,
   6.876 +                                                  uLong fileNameBufferSize,
   6.877 +                                                  void *extraField,
   6.878 +                                                  uLong extraFieldBufferSize,
   6.879 +                                                  char *szComment,
   6.880 +                                                  uLong commentBufferSize));
   6.881 +
   6.882 +local int unz64local_GetCurrentFileInfoInternal (unzFile file,
   6.883 +                                                  unz_file_info64 *pfile_info,
   6.884 +                                                  unz_file_info64_internal
   6.885 +                                                  *pfile_info_internal,
   6.886 +                                                  char *szFileName,
   6.887 +                                                  uLong fileNameBufferSize,
   6.888 +                                                  void *extraField,
   6.889 +                                                  uLong extraFieldBufferSize,
   6.890 +                                                  char *szComment,
   6.891 +                                                  uLong commentBufferSize)
   6.892 +{
   6.893 +    unz64_s* s;
   6.894 +    unz_file_info64 file_info;
   6.895 +    unz_file_info64_internal file_info_internal;
   6.896 +    int err=UNZ_OK;
   6.897 +    uLong uMagic;
   6.898 +    long lSeek=0;
   6.899 +    uLong uL;
   6.900 +
   6.901 +    if (file==NULL)
   6.902 +        return UNZ_PARAMERROR;
   6.903 +    s=(unz64_s*)file;
   6.904 +    if (ZSEEK64(s->z_filefunc, s->filestream,
   6.905 +              s->pos_in_central_dir+s->byte_before_the_zipfile,
   6.906 +              ZLIB_FILEFUNC_SEEK_SET)!=0)
   6.907 +        err=UNZ_ERRNO;
   6.908 +
   6.909 +
   6.910 +    /* we check the magic */
   6.911 +    if (err==UNZ_OK)
   6.912 +    {
   6.913 +        if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
   6.914 +            err=UNZ_ERRNO;
   6.915 +        else if (uMagic!=0x02014b50)
   6.916 +            err=UNZ_BADZIPFILE;
   6.917 +    }
   6.918 +
   6.919 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
   6.920 +        err=UNZ_ERRNO;
   6.921 +
   6.922 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
   6.923 +        err=UNZ_ERRNO;
   6.924 +
   6.925 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
   6.926 +        err=UNZ_ERRNO;
   6.927 +
   6.928 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
   6.929 +        err=UNZ_ERRNO;
   6.930 +
   6.931 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
   6.932 +        err=UNZ_ERRNO;
   6.933 +
   6.934 +    unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
   6.935 +
   6.936 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
   6.937 +        err=UNZ_ERRNO;
   6.938 +
   6.939 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
   6.940 +        err=UNZ_ERRNO;
   6.941 +    file_info.compressed_size = uL;
   6.942 +
   6.943 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
   6.944 +        err=UNZ_ERRNO;
   6.945 +    file_info.uncompressed_size = uL;
   6.946 +
   6.947 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
   6.948 +        err=UNZ_ERRNO;
   6.949 +
   6.950 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
   6.951 +        err=UNZ_ERRNO;
   6.952 +
   6.953 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
   6.954 +        err=UNZ_ERRNO;
   6.955 +
   6.956 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
   6.957 +        err=UNZ_ERRNO;
   6.958 +
   6.959 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
   6.960 +        err=UNZ_ERRNO;
   6.961 +
   6.962 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
   6.963 +        err=UNZ_ERRNO;
   6.964 +
   6.965 +                // relative offset of local header
   6.966 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
   6.967 +        err=UNZ_ERRNO;
   6.968 +    file_info_internal.offset_curfile = uL;
   6.969 +
   6.970 +    lSeek+=file_info.size_filename;
   6.971 +    if ((err==UNZ_OK) && (szFileName!=NULL))
   6.972 +    {
   6.973 +        uLong uSizeRead ;
   6.974 +        if (file_info.size_filename<fileNameBufferSize)
   6.975 +        {
   6.976 +            *(szFileName+file_info.size_filename)='\0';
   6.977 +            uSizeRead = file_info.size_filename;
   6.978 +        }
   6.979 +        else
   6.980 +            uSizeRead = fileNameBufferSize;
   6.981 +
   6.982 +        if ((file_info.size_filename>0) && (fileNameBufferSize>0))
   6.983 +            if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
   6.984 +                err=UNZ_ERRNO;
   6.985 +        lSeek -= uSizeRead;
   6.986 +    }
   6.987 +
   6.988 +    // Read extrafield
   6.989 +    if ((err==UNZ_OK) && (extraField!=NULL))
   6.990 +    {
   6.991 +        ZPOS64_T uSizeRead ;
   6.992 +        if (file_info.size_file_extra<extraFieldBufferSize)
   6.993 +            uSizeRead = file_info.size_file_extra;
   6.994 +        else
   6.995 +            uSizeRead = extraFieldBufferSize;
   6.996 +
   6.997 +        if (lSeek!=0)
   6.998 +        {
   6.999 +            if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
  6.1000 +                lSeek=0;
  6.1001 +            else
  6.1002 +                err=UNZ_ERRNO;
  6.1003 +        }
  6.1004 +
  6.1005 +        if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
  6.1006 +            if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
  6.1007 +                err=UNZ_ERRNO;
  6.1008 +
  6.1009 +        lSeek += file_info.size_file_extra - (uLong)uSizeRead;
  6.1010 +    }
  6.1011 +    else
  6.1012 +        lSeek += file_info.size_file_extra;
  6.1013 +
  6.1014 +
  6.1015 +    if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
  6.1016 +    {
  6.1017 +                                uLong acc = 0;
  6.1018 +
  6.1019 +        // since lSeek now points to after the extra field we need to move back
  6.1020 +        lSeek -= file_info.size_file_extra;
  6.1021 +
  6.1022 +        if (lSeek!=0)
  6.1023 +        {
  6.1024 +            if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
  6.1025 +                lSeek=0;
  6.1026 +            else
  6.1027 +                err=UNZ_ERRNO;
  6.1028 +        }
  6.1029 +
  6.1030 +        while(acc < file_info.size_file_extra)
  6.1031 +        {
  6.1032 +            uLong headerId;
  6.1033 +                                                uLong dataSize;
  6.1034 +
  6.1035 +            if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
  6.1036 +                err=UNZ_ERRNO;
  6.1037 +
  6.1038 +            if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
  6.1039 +                err=UNZ_ERRNO;
  6.1040 +
  6.1041 +            /* ZIP64 extra fields */
  6.1042 +            if (headerId == 0x0001)
  6.1043 +            {
  6.1044 +                                                        uLong uL;
  6.1045 +
  6.1046 +                                                                if(file_info.uncompressed_size == MAXU32)
  6.1047 +                                                                {
  6.1048 +                                                                        if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
  6.1049 +                                                                                        err=UNZ_ERRNO;
  6.1050 +                                                                }
  6.1051 +
  6.1052 +                                                                if(file_info.compressed_size == MAXU32)
  6.1053 +                                                                {
  6.1054 +                                                                        if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
  6.1055 +                                                                                  err=UNZ_ERRNO;
  6.1056 +                                                                }
  6.1057 +
  6.1058 +                                                                if(file_info_internal.offset_curfile == MAXU32)
  6.1059 +                                                                {
  6.1060 +                                                                        /* Relative Header offset */
  6.1061 +                                                                        if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
  6.1062 +                                                                                err=UNZ_ERRNO;
  6.1063 +                                                                }
  6.1064 +
  6.1065 +                                                                if(file_info.disk_num_start == MAXU32)
  6.1066 +                                                                {
  6.1067 +                                                                        /* Disk Start Number */
  6.1068 +                                                                        if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
  6.1069 +                                                                                err=UNZ_ERRNO;
  6.1070 +                                                                }
  6.1071 +
  6.1072 +            }
  6.1073 +            else
  6.1074 +            {
  6.1075 +                if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
  6.1076 +                    err=UNZ_ERRNO;
  6.1077 +            }
  6.1078 +
  6.1079 +            acc += 2 + 2 + dataSize;
  6.1080 +        }
  6.1081 +    }
  6.1082 +
  6.1083 +    if ((err==UNZ_OK) && (szComment!=NULL))
  6.1084 +    {
  6.1085 +        uLong uSizeRead ;
  6.1086 +        if (file_info.size_file_comment<commentBufferSize)
  6.1087 +        {
  6.1088 +            *(szComment+file_info.size_file_comment)='\0';
  6.1089 +            uSizeRead = file_info.size_file_comment;
  6.1090 +        }
  6.1091 +        else
  6.1092 +            uSizeRead = commentBufferSize;
  6.1093 +
  6.1094 +        if (lSeek!=0)
  6.1095 +        {
  6.1096 +            if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
  6.1097 +                lSeek=0;
  6.1098 +            else
  6.1099 +                err=UNZ_ERRNO;
  6.1100 +        }
  6.1101 +
  6.1102 +        if ((file_info.size_file_comment>0) && (commentBufferSize>0))
  6.1103 +            if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
  6.1104 +                err=UNZ_ERRNO;
  6.1105 +        lSeek+=file_info.size_file_comment - uSizeRead;
  6.1106 +    }
  6.1107 +    else
  6.1108 +        lSeek+=file_info.size_file_comment;
  6.1109 +
  6.1110 +
  6.1111 +    if ((err==UNZ_OK) && (pfile_info!=NULL))
  6.1112 +        *pfile_info=file_info;
  6.1113 +
  6.1114 +    if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
  6.1115 +        *pfile_info_internal=file_info_internal;
  6.1116 +
  6.1117 +    return err;
  6.1118 +}
  6.1119 +
  6.1120 +
  6.1121 +
  6.1122 +/*
  6.1123 +  Write info about the ZipFile in the *pglobal_info structure.
  6.1124 +  No preparation of the structure is needed
  6.1125 +  return UNZ_OK if there is no problem.
  6.1126 +*/
  6.1127 +extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
  6.1128 +                                          unz_file_info64 * pfile_info,
  6.1129 +                                          char * szFileName, uLong fileNameBufferSize,
  6.1130 +                                          void *extraField, uLong extraFieldBufferSize,
  6.1131 +                                          char* szComment,  uLong commentBufferSize)
  6.1132 +{
  6.1133 +    return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
  6.1134 +                                                szFileName,fileNameBufferSize,
  6.1135 +                                                extraField,extraFieldBufferSize,
  6.1136 +                                                szComment,commentBufferSize);
  6.1137 +}
  6.1138 +
  6.1139 +extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
  6.1140 +                                          unz_file_info * pfile_info,
  6.1141 +                                          char * szFileName, uLong fileNameBufferSize,
  6.1142 +                                          void *extraField, uLong extraFieldBufferSize,
  6.1143 +                                          char* szComment,  uLong commentBufferSize)
  6.1144 +{
  6.1145 +    int err;
  6.1146 +    unz_file_info64 file_info64;
  6.1147 +    err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
  6.1148 +                                                szFileName,fileNameBufferSize,
  6.1149 +                                                extraField,extraFieldBufferSize,
  6.1150 +                                                szComment,commentBufferSize);
  6.1151 +    if ((err==UNZ_OK) && (pfile_info != NULL))
  6.1152 +    {
  6.1153 +        pfile_info->version = file_info64.version;
  6.1154 +        pfile_info->version_needed = file_info64.version_needed;
  6.1155 +        pfile_info->flag = file_info64.flag;
  6.1156 +        pfile_info->compression_method = file_info64.compression_method;
  6.1157 +        pfile_info->dosDate = file_info64.dosDate;
  6.1158 +        pfile_info->crc = file_info64.crc;
  6.1159 +
  6.1160 +        pfile_info->size_filename = file_info64.size_filename;
  6.1161 +        pfile_info->size_file_extra = file_info64.size_file_extra;
  6.1162 +        pfile_info->size_file_comment = file_info64.size_file_comment;
  6.1163 +
  6.1164 +        pfile_info->disk_num_start = file_info64.disk_num_start;
  6.1165 +        pfile_info->internal_fa = file_info64.internal_fa;
  6.1166 +        pfile_info->external_fa = file_info64.external_fa;
  6.1167 +
  6.1168 +        pfile_info->tmu_date = file_info64.tmu_date,
  6.1169 +
  6.1170 +
  6.1171 +        pfile_info->compressed_size = (uLong)file_info64.compressed_size;
  6.1172 +        pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
  6.1173 +
  6.1174 +    }
  6.1175 +    return err;
  6.1176 +}
  6.1177 +/*
  6.1178 +  Set the current file of the zipfile to the first file.
  6.1179 +  return UNZ_OK if there is no problem
  6.1180 +*/
  6.1181 +extern int ZEXPORT unzGoToFirstFile (unzFile file)
  6.1182 +{
  6.1183 +    int err=UNZ_OK;
  6.1184 +    unz64_s* s;
  6.1185 +    if (file==NULL)
  6.1186 +        return UNZ_PARAMERROR;
  6.1187 +    s=(unz64_s*)file;
  6.1188 +    s->pos_in_central_dir=s->offset_central_dir;
  6.1189 +    s->num_file=0;
  6.1190 +    err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
  6.1191 +                                             &s->cur_file_info_internal,
  6.1192 +                                             NULL,0,NULL,0,NULL,0);
  6.1193 +    s->current_file_ok = (err == UNZ_OK);
  6.1194 +    return err;
  6.1195 +}
  6.1196 +
  6.1197 +/*
  6.1198 +  Set the current file of the zipfile to the next file.
  6.1199 +  return UNZ_OK if there is no problem
  6.1200 +  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
  6.1201 +*/
  6.1202 +extern int ZEXPORT unzGoToNextFile (unzFile  file)
  6.1203 +{
  6.1204 +    unz64_s* s;
  6.1205 +    int err;
  6.1206 +
  6.1207 +    if (file==NULL)
  6.1208 +        return UNZ_PARAMERROR;
  6.1209 +    s=(unz64_s*)file;
  6.1210 +    if (!s->current_file_ok)
  6.1211 +        return UNZ_END_OF_LIST_OF_FILE;
  6.1212 +    if (s->gi.number_entry != 0xffff)    /* 2^16 files overflow hack */
  6.1213 +      if (s->num_file+1==s->gi.number_entry)
  6.1214 +        return UNZ_END_OF_LIST_OF_FILE;
  6.1215 +
  6.1216 +    s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
  6.1217 +            s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
  6.1218 +    s->num_file++;
  6.1219 +    err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
  6.1220 +                                               &s->cur_file_info_internal,
  6.1221 +                                               NULL,0,NULL,0,NULL,0);
  6.1222 +    s->current_file_ok = (err == UNZ_OK);
  6.1223 +    return err;
  6.1224 +}
  6.1225 +
  6.1226 +
  6.1227 +/*
  6.1228 +  Try locate the file szFileName in the zipfile.
  6.1229 +  For the iCaseSensitivity signification, see unzipStringFileNameCompare
  6.1230 +
  6.1231 +  return value :
  6.1232 +  UNZ_OK if the file is found. It becomes the current file.
  6.1233 +  UNZ_END_OF_LIST_OF_FILE if the file is not found
  6.1234 +*/
  6.1235 +extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
  6.1236 +{
  6.1237 +    unz64_s* s;
  6.1238 +    int err;
  6.1239 +
  6.1240 +    /* We remember the 'current' position in the file so that we can jump
  6.1241 +     * back there if we fail.
  6.1242 +     */
  6.1243 +    unz_file_info64 cur_file_infoSaved;
  6.1244 +    unz_file_info64_internal cur_file_info_internalSaved;
  6.1245 +    ZPOS64_T num_fileSaved;
  6.1246 +    ZPOS64_T pos_in_central_dirSaved;
  6.1247 +
  6.1248 +
  6.1249 +    if (file==NULL)
  6.1250 +        return UNZ_PARAMERROR;
  6.1251 +
  6.1252 +    if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
  6.1253 +        return UNZ_PARAMERROR;
  6.1254 +
  6.1255 +    s=(unz64_s*)file;
  6.1256 +    if (!s->current_file_ok)
  6.1257 +        return UNZ_END_OF_LIST_OF_FILE;
  6.1258 +
  6.1259 +    /* Save the current state */
  6.1260 +    num_fileSaved = s->num_file;
  6.1261 +    pos_in_central_dirSaved = s->pos_in_central_dir;
  6.1262 +    cur_file_infoSaved = s->cur_file_info;
  6.1263 +    cur_file_info_internalSaved = s->cur_file_info_internal;
  6.1264 +
  6.1265 +    err = unzGoToFirstFile(file);
  6.1266 +
  6.1267 +    while (err == UNZ_OK)
  6.1268 +    {
  6.1269 +        char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
  6.1270 +        err = unzGetCurrentFileInfo64(file,NULL,
  6.1271 +                                    szCurrentFileName,sizeof(szCurrentFileName)-1,
  6.1272 +                                    NULL,0,NULL,0);
  6.1273 +        if (err == UNZ_OK)
  6.1274 +        {
  6.1275 +            if (unzStringFileNameCompare(szCurrentFileName,
  6.1276 +                                            szFileName,iCaseSensitivity)==0)
  6.1277 +                return UNZ_OK;
  6.1278 +            err = unzGoToNextFile(file);
  6.1279 +        }
  6.1280 +    }
  6.1281 +
  6.1282 +    /* We failed, so restore the state of the 'current file' to where we
  6.1283 +     * were.
  6.1284 +     */
  6.1285 +    s->num_file = num_fileSaved ;
  6.1286 +    s->pos_in_central_dir = pos_in_central_dirSaved ;
  6.1287 +    s->cur_file_info = cur_file_infoSaved;
  6.1288 +    s->cur_file_info_internal = cur_file_info_internalSaved;
  6.1289 +    return err;
  6.1290 +}
  6.1291 +
  6.1292 +
  6.1293 +/*
  6.1294 +///////////////////////////////////////////
  6.1295 +// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
  6.1296 +// I need random access
  6.1297 +//
  6.1298 +// Further optimization could be realized by adding an ability
  6.1299 +// to cache the directory in memory. The goal being a single
  6.1300 +// comprehensive file read to put the file I need in a memory.
  6.1301 +*/
  6.1302 +
  6.1303 +/*
  6.1304 +typedef struct unz_file_pos_s
  6.1305 +{
  6.1306 +    ZPOS64_T pos_in_zip_directory;   // offset in file
  6.1307 +    ZPOS64_T num_of_file;            // # of file
  6.1308 +} unz_file_pos;
  6.1309 +*/
  6.1310 +
  6.1311 +extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos*  file_pos)
  6.1312 +{
  6.1313 +    unz64_s* s;
  6.1314 +
  6.1315 +    if (file==NULL || file_pos==NULL)
  6.1316 +        return UNZ_PARAMERROR;
  6.1317 +    s=(unz64_s*)file;
  6.1318 +    if (!s->current_file_ok)
  6.1319 +        return UNZ_END_OF_LIST_OF_FILE;
  6.1320 +
  6.1321 +    file_pos->pos_in_zip_directory  = s->pos_in_central_dir;
  6.1322 +    file_pos->num_of_file           = s->num_file;
  6.1323 +
  6.1324 +    return UNZ_OK;
  6.1325 +}
  6.1326 +
  6.1327 +extern int ZEXPORT unzGetFilePos(
  6.1328 +    unzFile file,
  6.1329 +    unz_file_pos* file_pos)
  6.1330 +{
  6.1331 +    unz64_file_pos file_pos64;
  6.1332 +    int err = unzGetFilePos64(file,&file_pos64);
  6.1333 +    if (err==UNZ_OK)
  6.1334 +    {
  6.1335 +        file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
  6.1336 +        file_pos->num_of_file = (uLong)file_pos64.num_of_file;
  6.1337 +    }
  6.1338 +    return err;
  6.1339 +}
  6.1340 +
  6.1341 +extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
  6.1342 +{
  6.1343 +    unz64_s* s;
  6.1344 +    int err;
  6.1345 +
  6.1346 +    if (file==NULL || file_pos==NULL)
  6.1347 +        return UNZ_PARAMERROR;
  6.1348 +    s=(unz64_s*)file;
  6.1349 +
  6.1350 +    /* jump to the right spot */
  6.1351 +    s->pos_in_central_dir = file_pos->pos_in_zip_directory;
  6.1352 +    s->num_file           = file_pos->num_of_file;
  6.1353 +
  6.1354 +    /* set the current file */
  6.1355 +    err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
  6.1356 +                                               &s->cur_file_info_internal,
  6.1357 +                                               NULL,0,NULL,0,NULL,0);
  6.1358 +    /* return results */
  6.1359 +    s->current_file_ok = (err == UNZ_OK);
  6.1360 +    return err;
  6.1361 +}
  6.1362 +
  6.1363 +extern int ZEXPORT unzGoToFilePos(
  6.1364 +    unzFile file,
  6.1365 +    unz_file_pos* file_pos)
  6.1366 +{
  6.1367 +    unz64_file_pos file_pos64;
  6.1368 +    if (file_pos == NULL)
  6.1369 +        return UNZ_PARAMERROR;
  6.1370 +
  6.1371 +    file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
  6.1372 +    file_pos64.num_of_file = file_pos->num_of_file;
  6.1373 +    return unzGoToFilePos64(file,&file_pos64);
  6.1374 +}
  6.1375 +
  6.1376 +/*
  6.1377 +// Unzip Helper Functions - should be here?
  6.1378 +///////////////////////////////////////////
  6.1379 +*/
  6.1380 +
  6.1381 +/*
  6.1382 +  Read the local header of the current zipfile
  6.1383 +  Check the coherency of the local header and info in the end of central
  6.1384 +        directory about this file
  6.1385 +  store in *piSizeVar the size of extra info in local header
  6.1386 +        (filename and size of extra field data)
  6.1387 +*/
  6.1388 +local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
  6.1389 +                                                    ZPOS64_T * poffset_local_extrafield,
  6.1390 +                                                    uInt  * psize_local_extrafield)
  6.1391 +{
  6.1392 +    uLong uMagic,uData,uFlags;
  6.1393 +    uLong size_filename;
  6.1394 +    uLong size_extra_field;
  6.1395 +    int err=UNZ_OK;
  6.1396 +
  6.1397 +    *piSizeVar = 0;
  6.1398 +    *poffset_local_extrafield = 0;
  6.1399 +    *psize_local_extrafield = 0;
  6.1400 +
  6.1401 +    if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
  6.1402 +                                s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
  6.1403 +        return UNZ_ERRNO;
  6.1404 +
  6.1405 +
  6.1406 +    if (err==UNZ_OK)
  6.1407 +    {
  6.1408 +        if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
  6.1409 +            err=UNZ_ERRNO;
  6.1410 +        else if (uMagic!=0x04034b50)
  6.1411 +            err=UNZ_BADZIPFILE;
  6.1412 +    }
  6.1413 +
  6.1414 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
  6.1415 +        err=UNZ_ERRNO;
  6.1416 +/*
  6.1417 +    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
  6.1418 +        err=UNZ_BADZIPFILE;
  6.1419 +*/
  6.1420 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
  6.1421 +        err=UNZ_ERRNO;
  6.1422 +
  6.1423 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
  6.1424 +        err=UNZ_ERRNO;
  6.1425 +    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
  6.1426 +        err=UNZ_BADZIPFILE;
  6.1427 +
  6.1428 +    if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
  6.1429 +/* #ifdef HAVE_BZIP2 */
  6.1430 +                         (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
  6.1431 +/* #endif */
  6.1432 +                         (s->cur_file_info.compression_method!=Z_DEFLATED))
  6.1433 +        err=UNZ_BADZIPFILE;
  6.1434 +
  6.1435 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
  6.1436 +        err=UNZ_ERRNO;
  6.1437 +
  6.1438 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
  6.1439 +        err=UNZ_ERRNO;
  6.1440 +    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
  6.1441 +        err=UNZ_BADZIPFILE;
  6.1442 +
  6.1443 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
  6.1444 +        err=UNZ_ERRNO;
  6.1445 +    else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
  6.1446 +        err=UNZ_BADZIPFILE;
  6.1447 +
  6.1448 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
  6.1449 +        err=UNZ_ERRNO;
  6.1450 +    else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
  6.1451 +        err=UNZ_BADZIPFILE;
  6.1452 +
  6.1453 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
  6.1454 +        err=UNZ_ERRNO;
  6.1455 +    else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
  6.1456 +        err=UNZ_BADZIPFILE;
  6.1457 +
  6.1458 +    *piSizeVar += (uInt)size_filename;
  6.1459 +
  6.1460 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
  6.1461 +        err=UNZ_ERRNO;
  6.1462 +    *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
  6.1463 +                                    SIZEZIPLOCALHEADER + size_filename;
  6.1464 +    *psize_local_extrafield = (uInt)size_extra_field;
  6.1465 +
  6.1466 +    *piSizeVar += (uInt)size_extra_field;
  6.1467 +
  6.1468 +    return err;
  6.1469 +}
  6.1470 +
  6.1471 +/*
  6.1472 +  Open for reading data the current file in the zipfile.
  6.1473 +  If there is no error and the file is opened, the return value is UNZ_OK.
  6.1474 +*/
  6.1475 +extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
  6.1476 +                                            int* level, int raw, const char* password)
  6.1477 +{
  6.1478 +    int err=UNZ_OK;
  6.1479 +    uInt iSizeVar;
  6.1480 +    unz64_s* s;
  6.1481 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  6.1482 +    ZPOS64_T offset_local_extrafield;  /* offset of the local extra field */
  6.1483 +    uInt  size_local_extrafield;    /* size of the local extra field */
  6.1484 +#    ifndef NOUNCRYPT
  6.1485 +    char source[12];
  6.1486 +#    else
  6.1487 +    if (password != NULL)
  6.1488 +        return UNZ_PARAMERROR;
  6.1489 +#    endif
  6.1490 +
  6.1491 +    if (file==NULL)
  6.1492 +        return UNZ_PARAMERROR;
  6.1493 +    s=(unz64_s*)file;
  6.1494 +    if (!s->current_file_ok)
  6.1495 +        return UNZ_PARAMERROR;
  6.1496 +
  6.1497 +    if (s->pfile_in_zip_read != NULL)
  6.1498 +        unzCloseCurrentFile(file);
  6.1499 +
  6.1500 +    if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
  6.1501 +        return UNZ_BADZIPFILE;
  6.1502 +
  6.1503 +    pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
  6.1504 +    if (pfile_in_zip_read_info==NULL)
  6.1505 +        return UNZ_INTERNALERROR;
  6.1506 +
  6.1507 +    pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
  6.1508 +    pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
  6.1509 +    pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
  6.1510 +    pfile_in_zip_read_info->pos_local_extrafield=0;
  6.1511 +    pfile_in_zip_read_info->raw=raw;
  6.1512 +
  6.1513 +    if (pfile_in_zip_read_info->read_buffer==NULL)
  6.1514 +    {
  6.1515 +        TRYFREE(pfile_in_zip_read_info);
  6.1516 +        return UNZ_INTERNALERROR;
  6.1517 +    }
  6.1518 +
  6.1519 +    pfile_in_zip_read_info->stream_initialised=0;
  6.1520 +
  6.1521 +    if (method!=NULL)
  6.1522 +        *method = (int)s->cur_file_info.compression_method;
  6.1523 +
  6.1524 +    if (level!=NULL)
  6.1525 +    {
  6.1526 +        *level = 6;
  6.1527 +        switch (s->cur_file_info.flag & 0x06)
  6.1528 +        {
  6.1529 +          case 6 : *level = 1; break;
  6.1530 +          case 4 : *level = 2; break;
  6.1531 +          case 2 : *level = 9; break;
  6.1532 +        }
  6.1533 +    }
  6.1534 +
  6.1535 +    if ((s->cur_file_info.compression_method!=0) &&
  6.1536 +/* #ifdef HAVE_BZIP2 */
  6.1537 +        (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
  6.1538 +/* #endif */
  6.1539 +        (s->cur_file_info.compression_method!=Z_DEFLATED))
  6.1540 +
  6.1541 +        err=UNZ_BADZIPFILE;
  6.1542 +
  6.1543 +    pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
  6.1544 +    pfile_in_zip_read_info->crc32=0;
  6.1545 +    pfile_in_zip_read_info->total_out_64=0;
  6.1546 +    pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
  6.1547 +    pfile_in_zip_read_info->filestream=s->filestream;
  6.1548 +    pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
  6.1549 +    pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
  6.1550 +
  6.1551 +    pfile_in_zip_read_info->stream.total_out = 0;
  6.1552 +
  6.1553 +    if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
  6.1554 +    {
  6.1555 +#ifdef HAVE_BZIP2
  6.1556 +      pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
  6.1557 +      pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
  6.1558 +      pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
  6.1559 +      pfile_in_zip_read_info->bstream.state = (voidpf)0;
  6.1560 +
  6.1561 +      pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
  6.1562 +      pfile_in_zip_read_info->stream.zfree = (free_func)0;
  6.1563 +      pfile_in_zip_read_info->stream.opaque = (voidpf)0;
  6.1564 +      pfile_in_zip_read_info->stream.next_in = (voidpf)0;
  6.1565 +      pfile_in_zip_read_info->stream.avail_in = 0;
  6.1566 +
  6.1567 +      err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
  6.1568 +      if (err == Z_OK)
  6.1569 +        pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
  6.1570 +      else
  6.1571 +      {
  6.1572 +        TRYFREE(pfile_in_zip_read_info);
  6.1573 +        return err;
  6.1574 +      }
  6.1575 +#else
  6.1576 +      pfile_in_zip_read_info->raw=1;
  6.1577 +#endif
  6.1578 +    }
  6.1579 +    else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
  6.1580 +    {
  6.1581 +      pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
  6.1582 +      pfile_in_zip_read_info->stream.zfree = (free_func)0;
  6.1583 +      pfile_in_zip_read_info->stream.opaque = (voidpf)0;
  6.1584 +      pfile_in_zip_read_info->stream.next_in = 0;
  6.1585 +      pfile_in_zip_read_info->stream.avail_in = 0;
  6.1586 +
  6.1587 +      err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
  6.1588 +      if (err == Z_OK)
  6.1589 +        pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
  6.1590 +      else
  6.1591 +      {
  6.1592 +        TRYFREE(pfile_in_zip_read_info);
  6.1593 +        return err;
  6.1594 +      }
  6.1595 +        /* windowBits is passed < 0 to tell that there is no zlib header.
  6.1596 +         * Note that in this case inflate *requires* an extra "dummy" byte
  6.1597 +         * after the compressed stream in order to complete decompression and
  6.1598 +         * return Z_STREAM_END.
  6.1599 +         * In unzip, i don't wait absolutely Z_STREAM_END because I known the
  6.1600 +         * size of both compressed and uncompressed data
  6.1601 +         */
  6.1602 +    }
  6.1603 +    pfile_in_zip_read_info->rest_read_compressed =
  6.1604 +            s->cur_file_info.compressed_size ;
  6.1605 +    pfile_in_zip_read_info->rest_read_uncompressed =
  6.1606 +            s->cur_file_info.uncompressed_size ;
  6.1607 +
  6.1608 +
  6.1609 +    pfile_in_zip_read_info->pos_in_zipfile =
  6.1610 +            s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
  6.1611 +              iSizeVar;
  6.1612 +
  6.1613 +    pfile_in_zip_read_info->stream.avail_in = (uInt)0;
  6.1614 +
  6.1615 +    s->pfile_in_zip_read = pfile_in_zip_read_info;
  6.1616 +                s->encrypted = 0;
  6.1617 +
  6.1618 +#    ifndef NOUNCRYPT
  6.1619 +    if (password != NULL)
  6.1620 +    {
  6.1621 +        int i;
  6.1622 +        s->pcrc_32_tab = get_crc_table();
  6.1623 +        init_keys(password,s->keys,s->pcrc_32_tab);
  6.1624 +        if (ZSEEK64(s->z_filefunc, s->filestream,
  6.1625 +                  s->pfile_in_zip_read->pos_in_zipfile +
  6.1626 +                     s->pfile_in_zip_read->byte_before_the_zipfile,
  6.1627 +                  SEEK_SET)!=0)
  6.1628 +            return UNZ_INTERNALERROR;
  6.1629 +        if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
  6.1630 +            return UNZ_INTERNALERROR;
  6.1631 +
  6.1632 +        for (i = 0; i<12; i++)
  6.1633 +            zdecode(s->keys,s->pcrc_32_tab,source[i]);
  6.1634 +
  6.1635 +        s->pfile_in_zip_read->pos_in_zipfile+=12;
  6.1636 +        s->encrypted=1;
  6.1637 +    }
  6.1638 +#    endif
  6.1639 +
  6.1640 +
  6.1641 +    return UNZ_OK;
  6.1642 +}
  6.1643 +
  6.1644 +extern int ZEXPORT unzOpenCurrentFile (unzFile file)
  6.1645 +{
  6.1646 +    return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
  6.1647 +}
  6.1648 +
  6.1649 +extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char*  password)
  6.1650 +{
  6.1651 +    return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
  6.1652 +}
  6.1653 +
  6.1654 +extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
  6.1655 +{
  6.1656 +    return unzOpenCurrentFile3(file, method, level, raw, NULL);
  6.1657 +}
  6.1658 +
  6.1659 +/** Addition for GDAL : START */
  6.1660 +
  6.1661 +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
  6.1662 +{
  6.1663 +    unz64_s* s;
  6.1664 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  6.1665 +    s=(unz64_s*)file;
  6.1666 +    if (file==NULL)
  6.1667 +        return 0; //UNZ_PARAMERROR;
  6.1668 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  6.1669 +    if (pfile_in_zip_read_info==NULL)
  6.1670 +        return 0; //UNZ_PARAMERROR;
  6.1671 +    return pfile_in_zip_read_info->pos_in_zipfile +
  6.1672 +                         pfile_in_zip_read_info->byte_before_the_zipfile;
  6.1673 +}
  6.1674 +
  6.1675 +/** Addition for GDAL : END */
  6.1676 +
  6.1677 +/*
  6.1678 +  Read bytes from the current file.
  6.1679 +  buf contain buffer where data must be copied
  6.1680 +  len the size of buf.
  6.1681 +
  6.1682 +  return the number of byte copied if somes bytes are copied
  6.1683 +  return 0 if the end of file was reached
  6.1684 +  return <0 with error code if there is an error
  6.1685 +    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
  6.1686 +*/
  6.1687 +extern int ZEXPORT unzReadCurrentFile  (unzFile file, voidp buf, unsigned len)
  6.1688 +{
  6.1689 +    int err=UNZ_OK;
  6.1690 +    uInt iRead = 0;
  6.1691 +    unz64_s* s;
  6.1692 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  6.1693 +    if (file==NULL)
  6.1694 +        return UNZ_PARAMERROR;
  6.1695 +    s=(unz64_s*)file;
  6.1696 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  6.1697 +
  6.1698 +    if (pfile_in_zip_read_info==NULL)
  6.1699 +        return UNZ_PARAMERROR;
  6.1700 +
  6.1701 +
  6.1702 +    if (pfile_in_zip_read_info->read_buffer == NULL)
  6.1703 +        return UNZ_END_OF_LIST_OF_FILE;
  6.1704 +    if (len==0)
  6.1705 +        return 0;
  6.1706 +
  6.1707 +    pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
  6.1708 +
  6.1709 +    pfile_in_zip_read_info->stream.avail_out = (uInt)len;
  6.1710 +
  6.1711 +    if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
  6.1712 +        (!(pfile_in_zip_read_info->raw)))
  6.1713 +        pfile_in_zip_read_info->stream.avail_out =
  6.1714 +            (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
  6.1715 +
  6.1716 +    if ((len>pfile_in_zip_read_info->rest_read_compressed+
  6.1717 +           pfile_in_zip_read_info->stream.avail_in) &&
  6.1718 +         (pfile_in_zip_read_info->raw))
  6.1719 +        pfile_in_zip_read_info->stream.avail_out =
  6.1720 +            (uInt)pfile_in_zip_read_info->rest_read_compressed+
  6.1721 +            pfile_in_zip_read_info->stream.avail_in;
  6.1722 +
  6.1723 +    while (pfile_in_zip_read_info->stream.avail_out>0)
  6.1724 +    {
  6.1725 +        if ((pfile_in_zip_read_info->stream.avail_in==0) &&
  6.1726 +            (pfile_in_zip_read_info->rest_read_compressed>0))
  6.1727 +        {
  6.1728 +            uInt uReadThis = UNZ_BUFSIZE;
  6.1729 +            if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
  6.1730 +                uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
  6.1731 +            if (uReadThis == 0)
  6.1732 +                return UNZ_EOF;
  6.1733 +            if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
  6.1734 +                      pfile_in_zip_read_info->filestream,
  6.1735 +                      pfile_in_zip_read_info->pos_in_zipfile +
  6.1736 +                         pfile_in_zip_read_info->byte_before_the_zipfile,
  6.1737 +                         ZLIB_FILEFUNC_SEEK_SET)!=0)
  6.1738 +                return UNZ_ERRNO;
  6.1739 +            if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
  6.1740 +                      pfile_in_zip_read_info->filestream,
  6.1741 +                      pfile_in_zip_read_info->read_buffer,
  6.1742 +                      uReadThis)!=uReadThis)
  6.1743 +                return UNZ_ERRNO;
  6.1744 +
  6.1745 +
  6.1746 +#            ifndef NOUNCRYPT
  6.1747 +            if(s->encrypted)
  6.1748 +            {
  6.1749 +                uInt i;
  6.1750 +                for(i=0;i<uReadThis;i++)
  6.1751 +                  pfile_in_zip_read_info->read_buffer[i] =
  6.1752 +                      zdecode(s->keys,s->pcrc_32_tab,
  6.1753 +                              pfile_in_zip_read_info->read_buffer[i]);
  6.1754 +            }
  6.1755 +#            endif
  6.1756 +
  6.1757 +
  6.1758 +            pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
  6.1759 +
  6.1760 +            pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
  6.1761 +
  6.1762 +            pfile_in_zip_read_info->stream.next_in =
  6.1763 +                (Bytef*)pfile_in_zip_read_info->read_buffer;
  6.1764 +            pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
  6.1765 +        }
  6.1766 +
  6.1767 +        if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
  6.1768 +        {
  6.1769 +            uInt uDoCopy,i ;
  6.1770 +
  6.1771 +            if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
  6.1772 +                (pfile_in_zip_read_info->rest_read_compressed == 0))
  6.1773 +                return (iRead==0) ? UNZ_EOF : iRead;
  6.1774 +
  6.1775 +            if (pfile_in_zip_read_info->stream.avail_out <
  6.1776 +                            pfile_in_zip_read_info->stream.avail_in)
  6.1777 +                uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
  6.1778 +            else
  6.1779 +                uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
  6.1780 +
  6.1781 +            for (i=0;i<uDoCopy;i++)
  6.1782 +                *(pfile_in_zip_read_info->stream.next_out+i) =
  6.1783 +                        *(pfile_in_zip_read_info->stream.next_in+i);
  6.1784 +
  6.1785 +            pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
  6.1786 +
  6.1787 +            pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
  6.1788 +                                pfile_in_zip_read_info->stream.next_out,
  6.1789 +                                uDoCopy);
  6.1790 +            pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
  6.1791 +            pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
  6.1792 +            pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
  6.1793 +            pfile_in_zip_read_info->stream.next_out += uDoCopy;
  6.1794 +            pfile_in_zip_read_info->stream.next_in += uDoCopy;
  6.1795 +            pfile_in_zip_read_info->stream.total_out += uDoCopy;
  6.1796 +            iRead += uDoCopy;
  6.1797 +        }
  6.1798 +        else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
  6.1799 +        {
  6.1800 +#ifdef HAVE_BZIP2
  6.1801 +            uLong uTotalOutBefore,uTotalOutAfter;
  6.1802 +            const Bytef *bufBefore;
  6.1803 +            uLong uOutThis;
  6.1804 +
  6.1805 +            pfile_in_zip_read_info->bstream.next_in        = (char*)pfile_in_zip_read_info->stream.next_in;
  6.1806 +            pfile_in_zip_read_info->bstream.avail_in       = pfile_in_zip_read_info->stream.avail_in;
  6.1807 +            pfile_in_zip_read_info->bstream.total_in_lo32  = pfile_in_zip_read_info->stream.total_in;
  6.1808 +            pfile_in_zip_read_info->bstream.total_in_hi32  = 0;
  6.1809 +            pfile_in_zip_read_info->bstream.next_out       = (char*)pfile_in_zip_read_info->stream.next_out;
  6.1810 +            pfile_in_zip_read_info->bstream.avail_out      = pfile_in_zip_read_info->stream.avail_out;
  6.1811 +            pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
  6.1812 +            pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
  6.1813 +
  6.1814 +            uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
  6.1815 +            bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
  6.1816 +
  6.1817 +            err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
  6.1818 +
  6.1819 +            uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
  6.1820 +            uOutThis = uTotalOutAfter-uTotalOutBefore;
  6.1821 +
  6.1822 +            pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
  6.1823 +
  6.1824 +            pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
  6.1825 +            pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
  6.1826 +            iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
  6.1827 +
  6.1828 +            pfile_in_zip_read_info->stream.next_in   = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
  6.1829 +            pfile_in_zip_read_info->stream.avail_in  = pfile_in_zip_read_info->bstream.avail_in;
  6.1830 +            pfile_in_zip_read_info->stream.total_in  = pfile_in_zip_read_info->bstream.total_in_lo32;
  6.1831 +            pfile_in_zip_read_info->stream.next_out  = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
  6.1832 +            pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
  6.1833 +            pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
  6.1834 +
  6.1835 +            if (err==BZ_STREAM_END)
  6.1836 +              return (iRead==0) ? UNZ_EOF : iRead;
  6.1837 +            if (err!=BZ_OK)
  6.1838 +              break;
  6.1839 +#endif
  6.1840 +        } // end Z_BZIP2ED
  6.1841 +        else
  6.1842 +        {
  6.1843 +            ZPOS64_T uTotalOutBefore,uTotalOutAfter;
  6.1844 +            const Bytef *bufBefore;
  6.1845 +            ZPOS64_T uOutThis;
  6.1846 +            int flush=Z_SYNC_FLUSH;
  6.1847 +
  6.1848 +            uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
  6.1849 +            bufBefore = pfile_in_zip_read_info->stream.next_out;
  6.1850 +
  6.1851 +            /*
  6.1852 +            if ((pfile_in_zip_read_info->rest_read_uncompressed ==
  6.1853 +                     pfile_in_zip_read_info->stream.avail_out) &&
  6.1854 +                (pfile_in_zip_read_info->rest_read_compressed == 0))
  6.1855 +                flush = Z_FINISH;
  6.1856 +            */
  6.1857 +            err=inflate(&pfile_in_zip_read_info->stream,flush);
  6.1858 +
  6.1859 +            if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
  6.1860 +              err = Z_DATA_ERROR;
  6.1861 +
  6.1862 +            uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
  6.1863 +            uOutThis = uTotalOutAfter-uTotalOutBefore;
  6.1864 +
  6.1865 +            pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
  6.1866 +
  6.1867 +            pfile_in_zip_read_info->crc32 =
  6.1868 +                crc32(pfile_in_zip_read_info->crc32,bufBefore,
  6.1869 +                        (uInt)(uOutThis));
  6.1870 +
  6.1871 +            pfile_in_zip_read_info->rest_read_uncompressed -=
  6.1872 +                uOutThis;
  6.1873 +
  6.1874 +            iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
  6.1875 +
  6.1876 +            if (err==Z_STREAM_END)
  6.1877 +                return (iRead==0) ? UNZ_EOF : iRead;
  6.1878 +            if (err!=Z_OK)
  6.1879 +                break;
  6.1880 +        }
  6.1881 +    }
  6.1882 +
  6.1883 +    if (err==Z_OK)
  6.1884 +        return iRead;
  6.1885 +    return err;
  6.1886 +}
  6.1887 +
  6.1888 +
  6.1889 +/*
  6.1890 +  Give the current position in uncompressed data
  6.1891 +*/
  6.1892 +extern z_off_t ZEXPORT unztell (unzFile file)
  6.1893 +{
  6.1894 +    unz64_s* s;
  6.1895 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  6.1896 +    if (file==NULL)
  6.1897 +        return UNZ_PARAMERROR;
  6.1898 +    s=(unz64_s*)file;
  6.1899 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  6.1900 +
  6.1901 +    if (pfile_in_zip_read_info==NULL)
  6.1902 +        return UNZ_PARAMERROR;
  6.1903 +
  6.1904 +    return (z_off_t)pfile_in_zip_read_info->stream.total_out;
  6.1905 +}
  6.1906 +
  6.1907 +extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
  6.1908 +{
  6.1909 +
  6.1910 +    unz64_s* s;
  6.1911 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  6.1912 +    if (file==NULL)
  6.1913 +        return (ZPOS64_T)-1;
  6.1914 +    s=(unz64_s*)file;
  6.1915 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  6.1916 +
  6.1917 +    if (pfile_in_zip_read_info==NULL)
  6.1918 +        return (ZPOS64_T)-1;
  6.1919 +
  6.1920 +    return pfile_in_zip_read_info->total_out_64;
  6.1921 +}
  6.1922 +
  6.1923 +
  6.1924 +/*
  6.1925 +  return 1 if the end of file was reached, 0 elsewhere
  6.1926 +*/
  6.1927 +extern int ZEXPORT unzeof (unzFile file)
  6.1928 +{
  6.1929 +    unz64_s* s;
  6.1930 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  6.1931 +    if (file==NULL)
  6.1932 +        return UNZ_PARAMERROR;
  6.1933 +    s=(unz64_s*)file;
  6.1934 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  6.1935 +
  6.1936 +    if (pfile_in_zip_read_info==NULL)
  6.1937 +        return UNZ_PARAMERROR;
  6.1938 +
  6.1939 +    if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
  6.1940 +        return 1;
  6.1941 +    else
  6.1942 +        return 0;
  6.1943 +}
  6.1944 +
  6.1945 +
  6.1946 +
  6.1947 +/*
  6.1948 +Read extra field from the current file (opened by unzOpenCurrentFile)
  6.1949 +This is the local-header version of the extra field (sometimes, there is
  6.1950 +more info in the local-header version than in the central-header)
  6.1951 +
  6.1952 +  if buf==NULL, it return the size of the local extra field that can be read
  6.1953 +
  6.1954 +  if buf!=NULL, len is the size of the buffer, the extra header is copied in
  6.1955 +    buf.
  6.1956 +  the return value is the number of bytes copied in buf, or (if <0)
  6.1957 +    the error code
  6.1958 +*/
  6.1959 +extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
  6.1960 +{
  6.1961 +    unz64_s* s;
  6.1962 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  6.1963 +    uInt read_now;
  6.1964 +    ZPOS64_T size_to_read;
  6.1965 +
  6.1966 +    if (file==NULL)
  6.1967 +        return UNZ_PARAMERROR;
  6.1968 +    s=(unz64_s*)file;
  6.1969 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  6.1970 +
  6.1971 +    if (pfile_in_zip_read_info==NULL)
  6.1972 +        return UNZ_PARAMERROR;
  6.1973 +
  6.1974 +    size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
  6.1975 +                pfile_in_zip_read_info->pos_local_extrafield);
  6.1976 +
  6.1977 +    if (buf==NULL)
  6.1978 +        return (int)size_to_read;
  6.1979 +
  6.1980 +    if (len>size_to_read)
  6.1981 +        read_now = (uInt)size_to_read;
  6.1982 +    else
  6.1983 +        read_now = (uInt)len ;
  6.1984 +
  6.1985 +    if (read_now==0)
  6.1986 +        return 0;
  6.1987 +
  6.1988 +    if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
  6.1989 +              pfile_in_zip_read_info->filestream,
  6.1990 +              pfile_in_zip_read_info->offset_local_extrafield +
  6.1991 +              pfile_in_zip_read_info->pos_local_extrafield,
  6.1992 +              ZLIB_FILEFUNC_SEEK_SET)!=0)
  6.1993 +        return UNZ_ERRNO;
  6.1994 +
  6.1995 +    if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
  6.1996 +              pfile_in_zip_read_info->filestream,
  6.1997 +              buf,read_now)!=read_now)
  6.1998 +        return UNZ_ERRNO;
  6.1999 +
  6.2000 +    return (int)read_now;
  6.2001 +}
  6.2002 +
  6.2003 +/*
  6.2004 +  Close the file in zip opened with unzipOpenCurrentFile
  6.2005 +  Return UNZ_CRCERROR if all the file was read but the CRC is not good
  6.2006 +*/
  6.2007 +extern int ZEXPORT unzCloseCurrentFile (unzFile file)
  6.2008 +{
  6.2009 +    int err=UNZ_OK;
  6.2010 +
  6.2011 +    unz64_s* s;
  6.2012 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  6.2013 +    if (file==NULL)
  6.2014 +        return UNZ_PARAMERROR;
  6.2015 +    s=(unz64_s*)file;
  6.2016 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  6.2017 +
  6.2018 +    if (pfile_in_zip_read_info==NULL)
  6.2019 +        return UNZ_PARAMERROR;
  6.2020 +
  6.2021 +
  6.2022 +    if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
  6.2023 +        (!pfile_in_zip_read_info->raw))
  6.2024 +    {
  6.2025 +        if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
  6.2026 +            err=UNZ_CRCERROR;
  6.2027 +    }
  6.2028 +
  6.2029 +
  6.2030 +    TRYFREE(pfile_in_zip_read_info->read_buffer);
  6.2031 +    pfile_in_zip_read_info->read_buffer = NULL;
  6.2032 +    if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
  6.2033 +        inflateEnd(&pfile_in_zip_read_info->stream);
  6.2034 +#ifdef HAVE_BZIP2
  6.2035 +    else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
  6.2036 +        BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
  6.2037 +#endif
  6.2038 +
  6.2039 +
  6.2040 +    pfile_in_zip_read_info->stream_initialised = 0;
  6.2041 +    TRYFREE(pfile_in_zip_read_info);
  6.2042 +
  6.2043 +    s->pfile_in_zip_read=NULL;
  6.2044 +
  6.2045 +    return err;
  6.2046 +}
  6.2047 +
  6.2048 +
  6.2049 +/*
  6.2050 +  Get the global comment string of the ZipFile, in the szComment buffer.
  6.2051 +  uSizeBuf is the size of the szComment buffer.
  6.2052 +  return the number of byte copied or an error code <0
  6.2053 +*/
  6.2054 +extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
  6.2055 +{
  6.2056 +    unz64_s* s;
  6.2057 +    uLong uReadThis ;
  6.2058 +    if (file==NULL)
  6.2059 +        return (int)UNZ_PARAMERROR;
  6.2060 +    s=(unz64_s*)file;
  6.2061 +
  6.2062 +    uReadThis = uSizeBuf;
  6.2063 +    if (uReadThis>s->gi.size_comment)
  6.2064 +        uReadThis = s->gi.size_comment;
  6.2065 +
  6.2066 +    if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
  6.2067 +        return UNZ_ERRNO;
  6.2068 +
  6.2069 +    if (uReadThis>0)
  6.2070 +    {
  6.2071 +      *szComment='\0';
  6.2072 +      if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
  6.2073 +        return UNZ_ERRNO;
  6.2074 +    }
  6.2075 +
  6.2076 +    if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
  6.2077 +        *(szComment+s->gi.size_comment)='\0';
  6.2078 +    return (int)uReadThis;
  6.2079 +}
  6.2080 +
  6.2081 +/* Additions by RX '2004 */
  6.2082 +extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
  6.2083 +{
  6.2084 +    unz64_s* s;
  6.2085 +
  6.2086 +    if (file==NULL)
  6.2087 +          return 0; //UNZ_PARAMERROR;
  6.2088 +    s=(unz64_s*)file;
  6.2089 +    if (!s->current_file_ok)
  6.2090 +      return 0;
  6.2091 +    if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
  6.2092 +      if (s->num_file==s->gi.number_entry)
  6.2093 +         return 0;
  6.2094 +    return s->pos_in_central_dir;
  6.2095 +}
  6.2096 +
  6.2097 +extern uLong ZEXPORT unzGetOffset (unzFile file)
  6.2098 +{
  6.2099 +    ZPOS64_T offset64;
  6.2100 +
  6.2101 +    if (file==NULL)
  6.2102 +          return 0; //UNZ_PARAMERROR;
  6.2103 +    offset64 = unzGetOffset64(file);
  6.2104 +    return (uLong)offset64;
  6.2105 +}
  6.2106 +
  6.2107 +extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
  6.2108 +{
  6.2109 +    unz64_s* s;
  6.2110 +    int err;
  6.2111 +
  6.2112 +    if (file==NULL)
  6.2113 +        return UNZ_PARAMERROR;
  6.2114 +    s=(unz64_s*)file;
  6.2115 +
  6.2116 +    s->pos_in_central_dir = pos;
  6.2117 +    s->num_file = s->gi.number_entry;      /* hack */
  6.2118 +    err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
  6.2119 +                                              &s->cur_file_info_internal,
  6.2120 +                                              NULL,0,NULL,0,NULL,0);
  6.2121 +    s->current_file_ok = (err == UNZ_OK);
  6.2122 +    return err;
  6.2123 +}
  6.2124 +
  6.2125 +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
  6.2126 +{
  6.2127 +    return unzSetOffset64(file,pos);
  6.2128 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/minizip/unzip.h	Sun Sep 09 06:05:11 2012 +0300
     7.3 @@ -0,0 +1,437 @@
     7.4 +/* unzip.h -- IO for uncompress .zip files using zlib
     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 of Unzip for Zip64
    7.11 +         Copyright (C) 2007-2008 Even Rouault
    7.12 +
    7.13 +         Modifications for Zip64 support on both zip and unzip
    7.14 +         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
    7.15 +
    7.16 +         For more info read MiniZip_info.txt
    7.17 +
    7.18 +         ---------------------------------------------------------------------------------
    7.19 +
    7.20 +        Condition of use and distribution are the same than zlib :
    7.21 +
    7.22 +  This software is provided 'as-is', without any express or implied
    7.23 +  warranty.  In no event will the authors be held liable for any damages
    7.24 +  arising from the use of this software.
    7.25 +
    7.26 +  Permission is granted to anyone to use this software for any purpose,
    7.27 +  including commercial applications, and to alter it and redistribute it
    7.28 +  freely, subject to the following restrictions:
    7.29 +
    7.30 +  1. The origin of this software must not be misrepresented; you must not
    7.31 +     claim that you wrote the original software. If you use this software
    7.32 +     in a product, an acknowledgment in the product documentation would be
    7.33 +     appreciated but is not required.
    7.34 +  2. Altered source versions must be plainly marked as such, and must not be
    7.35 +     misrepresented as being the original software.
    7.36 +  3. This notice may not be removed or altered from any source distribution.
    7.37 +
    7.38 +  ---------------------------------------------------------------------------------
    7.39 +
    7.40 +        Changes
    7.41 +
    7.42 +        See header of unzip64.c
    7.43 +
    7.44 +*/
    7.45 +
    7.46 +#ifndef _unz64_H
    7.47 +#define _unz64_H
    7.48 +
    7.49 +#ifdef __cplusplus
    7.50 +extern "C" {
    7.51 +#endif
    7.52 +
    7.53 +#ifndef _ZLIB_H
    7.54 +#include "zlib.h"
    7.55 +#endif
    7.56 +
    7.57 +#ifndef  _ZLIBIOAPI_H
    7.58 +#include "ioapi.h"
    7.59 +#endif
    7.60 +
    7.61 +#ifdef HAVE_BZIP2
    7.62 +#include "bzlib.h"
    7.63 +#endif
    7.64 +
    7.65 +#define Z_BZIP2ED 12
    7.66 +
    7.67 +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
    7.68 +/* like the STRICT of WIN32, we define a pointer that cannot be converted
    7.69 +    from (void*) without cast */
    7.70 +typedef struct TagunzFile__ { int unused; } unzFile__;
    7.71 +typedef unzFile__ *unzFile;
    7.72 +#else
    7.73 +typedef voidp unzFile;
    7.74 +#endif
    7.75 +
    7.76 +
    7.77 +#define UNZ_OK                          (0)
    7.78 +#define UNZ_END_OF_LIST_OF_FILE         (-100)
    7.79 +#define UNZ_ERRNO                       (Z_ERRNO)
    7.80 +#define UNZ_EOF                         (0)
    7.81 +#define UNZ_PARAMERROR                  (-102)
    7.82 +#define UNZ_BADZIPFILE                  (-103)
    7.83 +#define UNZ_INTERNALERROR               (-104)
    7.84 +#define UNZ_CRCERROR                    (-105)
    7.85 +
    7.86 +/* tm_unz contain date/time info */
    7.87 +typedef struct tm_unz_s
    7.88 +{
    7.89 +    uInt tm_sec;            /* seconds after the minute - [0,59] */
    7.90 +    uInt tm_min;            /* minutes after the hour - [0,59] */
    7.91 +    uInt tm_hour;           /* hours since midnight - [0,23] */
    7.92 +    uInt tm_mday;           /* day of the month - [1,31] */
    7.93 +    uInt tm_mon;            /* months since January - [0,11] */
    7.94 +    uInt tm_year;           /* years - [1980..2044] */
    7.95 +} tm_unz;
    7.96 +
    7.97 +/* unz_global_info structure contain global data about the ZIPfile
    7.98 +   These data comes from the end of central dir */
    7.99 +typedef struct unz_global_info64_s
   7.100 +{
   7.101 +    ZPOS64_T number_entry;         /* total number of entries in
   7.102 +                                     the central dir on this disk */
   7.103 +    uLong size_comment;         /* size of the global comment of the zipfile */
   7.104 +} unz_global_info64;
   7.105 +
   7.106 +typedef struct unz_global_info_s
   7.107 +{
   7.108 +    uLong number_entry;         /* total number of entries in
   7.109 +                                     the central dir on this disk */
   7.110 +    uLong size_comment;         /* size of the global comment of the zipfile */
   7.111 +} unz_global_info;
   7.112 +
   7.113 +/* unz_file_info contain information about a file in the zipfile */
   7.114 +typedef struct unz_file_info64_s
   7.115 +{
   7.116 +    uLong version;              /* version made by                 2 bytes */
   7.117 +    uLong version_needed;       /* version needed to extract       2 bytes */
   7.118 +    uLong flag;                 /* general purpose bit flag        2 bytes */
   7.119 +    uLong compression_method;   /* compression method              2 bytes */
   7.120 +    uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
   7.121 +    uLong crc;                  /* crc-32                          4 bytes */
   7.122 +    ZPOS64_T compressed_size;   /* compressed size                 8 bytes */
   7.123 +    ZPOS64_T uncompressed_size; /* uncompressed size               8 bytes */
   7.124 +    uLong size_filename;        /* filename length                 2 bytes */
   7.125 +    uLong size_file_extra;      /* extra field length              2 bytes */
   7.126 +    uLong size_file_comment;    /* file comment length             2 bytes */
   7.127 +
   7.128 +    uLong disk_num_start;       /* disk number start               2 bytes */
   7.129 +    uLong internal_fa;          /* internal file attributes        2 bytes */
   7.130 +    uLong external_fa;          /* external file attributes        4 bytes */
   7.131 +
   7.132 +    tm_unz tmu_date;
   7.133 +} unz_file_info64;
   7.134 +
   7.135 +typedef struct unz_file_info_s
   7.136 +{
   7.137 +    uLong version;              /* version made by                 2 bytes */
   7.138 +    uLong version_needed;       /* version needed to extract       2 bytes */
   7.139 +    uLong flag;                 /* general purpose bit flag        2 bytes */
   7.140 +    uLong compression_method;   /* compression method              2 bytes */
   7.141 +    uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
   7.142 +    uLong crc;                  /* crc-32                          4 bytes */
   7.143 +    uLong compressed_size;      /* compressed size                 4 bytes */
   7.144 +    uLong uncompressed_size;    /* uncompressed size               4 bytes */
   7.145 +    uLong size_filename;        /* filename length                 2 bytes */
   7.146 +    uLong size_file_extra;      /* extra field length              2 bytes */
   7.147 +    uLong size_file_comment;    /* file comment length             2 bytes */
   7.148 +
   7.149 +    uLong disk_num_start;       /* disk number start               2 bytes */
   7.150 +    uLong internal_fa;          /* internal file attributes        2 bytes */
   7.151 +    uLong external_fa;          /* external file attributes        4 bytes */
   7.152 +
   7.153 +    tm_unz tmu_date;
   7.154 +} unz_file_info;
   7.155 +
   7.156 +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
   7.157 +                                                 const char* fileName2,
   7.158 +                                                 int iCaseSensitivity));
   7.159 +/*
   7.160 +   Compare two filename (fileName1,fileName2).
   7.161 +   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
   7.162 +   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
   7.163 +                                or strcasecmp)
   7.164 +   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
   7.165 +    (like 1 on Unix, 2 on Windows)
   7.166 +*/
   7.167 +
   7.168 +
   7.169 +extern unzFile ZEXPORT unzOpen OF((const char *path));
   7.170 +extern unzFile ZEXPORT unzOpen64 OF((const void *path));
   7.171 +/*
   7.172 +  Open a Zip file. path contain the full pathname (by example,
   7.173 +     on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
   7.174 +     "zlib/zlib113.zip".
   7.175 +     If the zipfile cannot be opened (file don't exist or in not valid), the
   7.176 +       return value is NULL.
   7.177 +     Else, the return value is a unzFile Handle, usable with other function
   7.178 +       of this unzip package.
   7.179 +     the "64" function take a const void* pointer, because the path is just the
   7.180 +       value passed to the open64_file_func callback.
   7.181 +     Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
   7.182 +       is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
   7.183 +       does not describe the reality
   7.184 +*/
   7.185 +
   7.186 +
   7.187 +extern unzFile ZEXPORT unzOpen2 OF((const char *path,
   7.188 +                                    zlib_filefunc_def* pzlib_filefunc_def));
   7.189 +/*
   7.190 +   Open a Zip file, like unzOpen, but provide a set of file low level API
   7.191 +      for read/write the zip file (see ioapi.h)
   7.192 +*/
   7.193 +
   7.194 +extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
   7.195 +                                    zlib_filefunc64_def* pzlib_filefunc_def));
   7.196 +/*
   7.197 +   Open a Zip file, like unz64Open, but provide a set of file low level API
   7.198 +      for read/write the zip file (see ioapi.h)
   7.199 +*/
   7.200 +
   7.201 +extern int ZEXPORT unzClose OF((unzFile file));
   7.202 +/*
   7.203 +  Close a ZipFile opened with unzipOpen.
   7.204 +  If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
   7.205 +    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
   7.206 +  return UNZ_OK if there is no problem. */
   7.207 +
   7.208 +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
   7.209 +                                        unz_global_info *pglobal_info));
   7.210 +
   7.211 +extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
   7.212 +                                        unz_global_info64 *pglobal_info));
   7.213 +/*
   7.214 +  Write info about the ZipFile in the *pglobal_info structure.
   7.215 +  No preparation of the structure is needed
   7.216 +  return UNZ_OK if there is no problem. */
   7.217 +
   7.218 +
   7.219 +extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
   7.220 +                                           char *szComment,
   7.221 +                                           uLong uSizeBuf));
   7.222 +/*
   7.223 +  Get the global comment string of the ZipFile, in the szComment buffer.
   7.224 +  uSizeBuf is the size of the szComment buffer.
   7.225 +  return the number of byte copied or an error code <0
   7.226 +*/
   7.227 +
   7.228 +
   7.229 +/***************************************************************************/
   7.230 +/* Unzip package allow you browse the directory of the zipfile */
   7.231 +
   7.232 +extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
   7.233 +/*
   7.234 +  Set the current file of the zipfile to the first file.
   7.235 +  return UNZ_OK if there is no problem
   7.236 +*/
   7.237 +
   7.238 +extern int ZEXPORT unzGoToNextFile OF((unzFile file));
   7.239 +/*
   7.240 +  Set the current file of the zipfile to the next file.
   7.241 +  return UNZ_OK if there is no problem
   7.242 +  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
   7.243 +*/
   7.244 +
   7.245 +extern int ZEXPORT unzLocateFile OF((unzFile file,
   7.246 +                     const char *szFileName,
   7.247 +                     int iCaseSensitivity));
   7.248 +/*
   7.249 +  Try locate the file szFileName in the zipfile.
   7.250 +  For the iCaseSensitivity signification, see unzStringFileNameCompare
   7.251 +
   7.252 +  return value :
   7.253 +  UNZ_OK if the file is found. It becomes the current file.
   7.254 +  UNZ_END_OF_LIST_OF_FILE if the file is not found
   7.255 +*/
   7.256 +
   7.257 +
   7.258 +/* ****************************************** */
   7.259 +/* Ryan supplied functions */
   7.260 +/* unz_file_info contain information about a file in the zipfile */
   7.261 +typedef struct unz_file_pos_s
   7.262 +{
   7.263 +    uLong pos_in_zip_directory;   /* offset in zip file directory */
   7.264 +    uLong num_of_file;            /* # of file */
   7.265 +} unz_file_pos;
   7.266 +
   7.267 +extern int ZEXPORT unzGetFilePos(
   7.268 +    unzFile file,
   7.269 +    unz_file_pos* file_pos);
   7.270 +
   7.271 +extern int ZEXPORT unzGoToFilePos(
   7.272 +    unzFile file,
   7.273 +    unz_file_pos* file_pos);
   7.274 +
   7.275 +typedef struct unz64_file_pos_s
   7.276 +{
   7.277 +    ZPOS64_T pos_in_zip_directory;   /* offset in zip file directory */
   7.278 +    ZPOS64_T num_of_file;            /* # of file */
   7.279 +} unz64_file_pos;
   7.280 +
   7.281 +extern int ZEXPORT unzGetFilePos64(
   7.282 +    unzFile file,
   7.283 +    unz64_file_pos* file_pos);
   7.284 +
   7.285 +extern int ZEXPORT unzGoToFilePos64(
   7.286 +    unzFile file,
   7.287 +    const unz64_file_pos* file_pos);
   7.288 +
   7.289 +/* ****************************************** */
   7.290 +
   7.291 +extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
   7.292 +                         unz_file_info64 *pfile_info,
   7.293 +                         char *szFileName,
   7.294 +                         uLong fileNameBufferSize,
   7.295 +                         void *extraField,
   7.296 +                         uLong extraFieldBufferSize,
   7.297 +                         char *szComment,
   7.298 +                         uLong commentBufferSize));
   7.299 +
   7.300 +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
   7.301 +                         unz_file_info *pfile_info,
   7.302 +                         char *szFileName,
   7.303 +                         uLong fileNameBufferSize,
   7.304 +                         void *extraField,
   7.305 +                         uLong extraFieldBufferSize,
   7.306 +                         char *szComment,
   7.307 +                         uLong commentBufferSize));
   7.308 +/*
   7.309 +  Get Info about the current file
   7.310 +  if pfile_info!=NULL, the *pfile_info structure will contain somes info about
   7.311 +        the current file
   7.312 +  if szFileName!=NULL, the filemane string will be copied in szFileName
   7.313 +            (fileNameBufferSize is the size of the buffer)
   7.314 +  if extraField!=NULL, the extra field information will be copied in extraField
   7.315 +            (extraFieldBufferSize is the size of the buffer).
   7.316 +            This is the Central-header version of the extra field
   7.317 +  if szComment!=NULL, the comment string of the file will be copied in szComment
   7.318 +            (commentBufferSize is the size of the buffer)
   7.319 +*/
   7.320 +
   7.321 +
   7.322 +/** Addition for GDAL : START */
   7.323 +
   7.324 +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
   7.325 +
   7.326 +/** Addition for GDAL : END */
   7.327 +
   7.328 +
   7.329 +/***************************************************************************/
   7.330 +/* for reading the content of the current zipfile, you can open it, read data
   7.331 +   from it, and close it (you can close it before reading all the file)
   7.332 +   */
   7.333 +
   7.334 +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
   7.335 +/*
   7.336 +  Open for reading data the current file in the zipfile.
   7.337 +  If there is no error, the return value is UNZ_OK.
   7.338 +*/
   7.339 +
   7.340 +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
   7.341 +                                                  const char* password));
   7.342 +/*
   7.343 +  Open for reading data the current file in the zipfile.
   7.344 +  password is a crypting password
   7.345 +  If there is no error, the return value is UNZ_OK.
   7.346 +*/
   7.347 +
   7.348 +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
   7.349 +                                           int* method,
   7.350 +                                           int* level,
   7.351 +                                           int raw));
   7.352 +/*
   7.353 +  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
   7.354 +    if raw==1
   7.355 +  *method will receive method of compression, *level will receive level of
   7.356 +     compression
   7.357 +  note : you can set level parameter as NULL (if you did not want known level,
   7.358 +         but you CANNOT set method parameter as NULL
   7.359 +*/
   7.360 +
   7.361 +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
   7.362 +                                           int* method,
   7.363 +                                           int* level,
   7.364 +                                           int raw,
   7.365 +                                           const char* password));
   7.366 +/*
   7.367 +  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
   7.368 +    if raw==1
   7.369 +  *method will receive method of compression, *level will receive level of
   7.370 +     compression
   7.371 +  note : you can set level parameter as NULL (if you did not want known level,
   7.372 +         but you CANNOT set method parameter as NULL
   7.373 +*/
   7.374 +
   7.375 +
   7.376 +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
   7.377 +/*
   7.378 +  Close the file in zip opened with unzOpenCurrentFile
   7.379 +  Return UNZ_CRCERROR if all the file was read but the CRC is not good
   7.380 +*/
   7.381 +
   7.382 +extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
   7.383 +                      voidp buf,
   7.384 +                      unsigned len));
   7.385 +/*
   7.386 +  Read bytes from the current file (opened by unzOpenCurrentFile)
   7.387 +  buf contain buffer where data must be copied
   7.388 +  len the size of buf.
   7.389 +
   7.390 +  return the number of byte copied if somes bytes are copied
   7.391 +  return 0 if the end of file was reached
   7.392 +  return <0 with error code if there is an error
   7.393 +    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
   7.394 +*/
   7.395 +
   7.396 +extern z_off_t ZEXPORT unztell OF((unzFile file));
   7.397 +
   7.398 +extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
   7.399 +/*
   7.400 +  Give the current position in uncompressed data
   7.401 +*/
   7.402 +
   7.403 +extern int ZEXPORT unzeof OF((unzFile file));
   7.404 +/*
   7.405 +  return 1 if the end of file was reached, 0 elsewhere
   7.406 +*/
   7.407 +
   7.408 +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
   7.409 +                                             voidp buf,
   7.410 +                                             unsigned len));
   7.411 +/*
   7.412 +  Read extra field from the current file (opened by unzOpenCurrentFile)
   7.413 +  This is the local-header version of the extra field (sometimes, there is
   7.414 +    more info in the local-header version than in the central-header)
   7.415 +
   7.416 +  if buf==NULL, it return the size of the local extra field
   7.417 +
   7.418 +  if buf!=NULL, len is the size of the buffer, the extra header is copied in
   7.419 +    buf.
   7.420 +  the return value is the number of bytes copied in buf, or (if <0)
   7.421 +    the error code
   7.422 +*/
   7.423 +
   7.424 +/***************************************************************************/
   7.425 +
   7.426 +/* Get the current file offset */
   7.427 +extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
   7.428 +extern uLong ZEXPORT unzGetOffset (unzFile file);
   7.429 +
   7.430 +/* Set the current file offset */
   7.431 +extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
   7.432 +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
   7.433 +
   7.434 +
   7.435 +
   7.436 +#ifdef __cplusplus
   7.437 +}
   7.438 +#endif
   7.439 +
   7.440 +#endif /* _unz64_H */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/packio_impl.h	Sun Sep 09 06:05:11 2012 +0300
     8.3 @@ -0,0 +1,23 @@
     8.4 +#ifndef PACKIO_IMPL_H_
     8.5 +#define PACKIO_IMPL_H_
     8.6 +
     8.7 +enum { NODE_FILE, NODE_DIR };
     8.8 +enum { FILE_REAL, FILE_VIRT };
     8.9 +
    8.10 +struct fsnode {
    8.11 +	int type, ftype;
    8.12 +	long size;
    8.13 +
    8.14 +	struct fsnode *clist, *clist_tail;
    8.15 +};
    8.16 +
    8.17 +struct pack_file {
    8.18 +	struct fsnode *node;
    8.19 +	long pos;
    8.20 +};
    8.21 +
    8.22 +struct pack_dir {
    8.23 +	struct fsnode *node;
    8.24 +};
    8.25 +
    8.26 +#endif	/* PACKIO_IMPL_H_ */