packvfs

diff test/zipcat/src/minizip/unzip.c @ 3:ef6c1472607f

jesus fucking christ that was easy... written a test prog "zipcat" to try out zlib's contrib library "minizip", to list and read files out of zip archives directly...
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 04 Nov 2013 06:46:17 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/zipcat/src/minizip/unzip.c	Mon Nov 04 06:46:17 2013 +0200
     1.3 @@ -0,0 +1,2125 @@
     1.4 +/* unzip.c -- IO for uncompress .zip files using zlib
     1.5 +   Version 1.1, February 14h, 2010
     1.6 +   part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
     1.7 +
     1.8 +         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
     1.9 +
    1.10 +         Modifications of Unzip for Zip64
    1.11 +         Copyright (C) 2007-2008 Even Rouault
    1.12 +
    1.13 +         Modifications for Zip64 support on both zip and unzip
    1.14 +         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
    1.15 +
    1.16 +         For more info read MiniZip_info.txt
    1.17 +
    1.18 +
    1.19 +  ------------------------------------------------------------------------------------
    1.20 +  Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
    1.21 +  compatibility with older software. The following is from the original crypt.c.
    1.22 +  Code woven in by Terry Thorsen 1/2003.
    1.23 +
    1.24 +  Copyright (c) 1990-2000 Info-ZIP.  All rights reserved.
    1.25 +
    1.26 +  See the accompanying file LICENSE, version 2000-Apr-09 or later
    1.27 +  (the contents of which are also included in zip.h) for terms of use.
    1.28 +  If, for some reason, all these files are missing, the Info-ZIP license
    1.29 +  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
    1.30 +
    1.31 +        crypt.c (full version) by Info-ZIP.      Last revised:  [see crypt.h]
    1.32 +
    1.33 +  The encryption/decryption parts of this source code (as opposed to the
    1.34 +  non-echoing password parts) were originally written in Europe.  The
    1.35 +  whole source package can be freely distributed, including from the USA.
    1.36 +  (Prior to January 2000, re-export from the US was a violation of US law.)
    1.37 +
    1.38 +        This encryption code is a direct transcription of the algorithm from
    1.39 +  Roger Schlafly, described by Phil Katz in the file appnote.txt.  This
    1.40 +  file (appnote.txt) is distributed with the PKZIP program (even in the
    1.41 +  version without encryption capabilities).
    1.42 +
    1.43 +        ------------------------------------------------------------------------------------
    1.44 +
    1.45 +        Changes in unzip.c
    1.46 +
    1.47 +        2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos
    1.48 +  2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz*
    1.49 +  2007-2008 - Even Rouault - Remove old C style function prototypes
    1.50 +  2007-2008 - Even Rouault - Add unzip support for ZIP64
    1.51 +
    1.52 +        Copyright (C) 2007-2008 Even Rouault
    1.53 +
    1.54 +
    1.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).
    1.56 +  Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
    1.57 +                                should only read the compressed/uncompressed size from the Zip64 format if
    1.58 +                                the size from normal header was 0xFFFFFFFF
    1.59 +  Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
    1.60 +        Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
    1.61 +                                Patch created by Daniel Borca
    1.62 +
    1.63 +  Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
    1.64 +
    1.65 +  Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
    1.66 +
    1.67 +*/
    1.68 +
    1.69 +
    1.70 +#include <stdio.h>
    1.71 +#include <stdlib.h>
    1.72 +#include <string.h>
    1.73 +
    1.74 +#ifndef NOUNCRYPT
    1.75 +        #define NOUNCRYPT
    1.76 +#endif
    1.77 +
    1.78 +#include "zlib.h"
    1.79 +#include "unzip.h"
    1.80 +
    1.81 +#ifdef STDC
    1.82 +#  include <stddef.h>
    1.83 +#  include <string.h>
    1.84 +#  include <stdlib.h>
    1.85 +#endif
    1.86 +#ifdef NO_ERRNO_H
    1.87 +    extern int errno;
    1.88 +#else
    1.89 +#   include <errno.h>
    1.90 +#endif
    1.91 +
    1.92 +
    1.93 +#ifndef local
    1.94 +#  define local static
    1.95 +#endif
    1.96 +/* compile with -Dlocal if your debugger can't find static symbols */
    1.97 +
    1.98 +
    1.99 +#ifndef CASESENSITIVITYDEFAULT_NO
   1.100 +#  if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
   1.101 +#    define CASESENSITIVITYDEFAULT_NO
   1.102 +#  endif
   1.103 +#endif
   1.104 +
   1.105 +
   1.106 +#ifndef UNZ_BUFSIZE
   1.107 +#define UNZ_BUFSIZE (16384)
   1.108 +#endif
   1.109 +
   1.110 +#ifndef UNZ_MAXFILENAMEINZIP
   1.111 +#define UNZ_MAXFILENAMEINZIP (256)
   1.112 +#endif
   1.113 +
   1.114 +#ifndef ALLOC
   1.115 +# define ALLOC(size) (malloc(size))
   1.116 +#endif
   1.117 +#ifndef TRYFREE
   1.118 +# define TRYFREE(p) {if (p) free(p);}
   1.119 +#endif
   1.120 +
   1.121 +#define SIZECENTRALDIRITEM (0x2e)
   1.122 +#define SIZEZIPLOCALHEADER (0x1e)
   1.123 +
   1.124 +
   1.125 +const char unz_copyright[] =
   1.126 +   " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
   1.127 +
   1.128 +/* unz_file_info_interntal contain internal info about a file in zipfile*/
   1.129 +typedef struct unz_file_info64_internal_s
   1.130 +{
   1.131 +    ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */
   1.132 +} unz_file_info64_internal;
   1.133 +
   1.134 +
   1.135 +/* file_in_zip_read_info_s contain internal information about a file in zipfile,
   1.136 +    when reading and decompress it */
   1.137 +typedef struct
   1.138 +{
   1.139 +    char  *read_buffer;         /* internal buffer for compressed data */
   1.140 +    z_stream stream;            /* zLib stream structure for inflate */
   1.141 +
   1.142 +#ifdef HAVE_BZIP2
   1.143 +    bz_stream bstream;          /* bzLib stream structure for bziped */
   1.144 +#endif
   1.145 +
   1.146 +    ZPOS64_T pos_in_zipfile;       /* position in byte on the zipfile, for fseek*/
   1.147 +    uLong stream_initialised;   /* flag set if stream structure is initialised*/
   1.148 +
   1.149 +    ZPOS64_T offset_local_extrafield;/* offset of the local extra field */
   1.150 +    uInt  size_local_extrafield;/* size of the local extra field */
   1.151 +    ZPOS64_T pos_local_extrafield;   /* position in the local extra field in read*/
   1.152 +    ZPOS64_T total_out_64;
   1.153 +
   1.154 +    uLong crc32;                /* crc32 of all data uncompressed */
   1.155 +    uLong crc32_wait;           /* crc32 we must obtain after decompress all */
   1.156 +    ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
   1.157 +    ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
   1.158 +    zlib_filefunc64_32_def z_filefunc;
   1.159 +    voidpf filestream;        /* io structore of the zipfile */
   1.160 +    uLong compression_method;   /* compression method (0==store) */
   1.161 +    ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
   1.162 +    int   raw;
   1.163 +} file_in_zip64_read_info_s;
   1.164 +
   1.165 +
   1.166 +/* unz64_s contain internal information about the zipfile
   1.167 +*/
   1.168 +typedef struct
   1.169 +{
   1.170 +    zlib_filefunc64_32_def z_filefunc;
   1.171 +    int is64bitOpenFunction;
   1.172 +    voidpf filestream;        /* io structore of the zipfile */
   1.173 +    unz_global_info64 gi;       /* public global information */
   1.174 +    ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
   1.175 +    ZPOS64_T num_file;             /* number of the current file in the zipfile*/
   1.176 +    ZPOS64_T pos_in_central_dir;   /* pos of the current file in the central dir*/
   1.177 +    ZPOS64_T current_file_ok;      /* flag about the usability of the current file*/
   1.178 +    ZPOS64_T central_pos;          /* position of the beginning of the central dir*/
   1.179 +
   1.180 +    ZPOS64_T size_central_dir;     /* size of the central directory  */
   1.181 +    ZPOS64_T offset_central_dir;   /* offset of start of central directory with
   1.182 +                                   respect to the starting disk number */
   1.183 +
   1.184 +    unz_file_info64 cur_file_info; /* public info about the current file in zip*/
   1.185 +    unz_file_info64_internal cur_file_info_internal; /* private info about it*/
   1.186 +    file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current
   1.187 +                                        file if we are decompressing it */
   1.188 +    int encrypted;
   1.189 +
   1.190 +    int isZip64;
   1.191 +
   1.192 +#    ifndef NOUNCRYPT
   1.193 +    unsigned long keys[3];     /* keys defining the pseudo-random sequence */
   1.194 +    const z_crc_t* pcrc_32_tab;
   1.195 +#    endif
   1.196 +} unz64_s;
   1.197 +
   1.198 +
   1.199 +#ifndef NOUNCRYPT
   1.200 +#include "crypt.h"
   1.201 +#endif
   1.202 +
   1.203 +/* ===========================================================================
   1.204 +     Read a byte from a gz_stream; update next_in and avail_in. Return EOF
   1.205 +   for end of file.
   1.206 +   IN assertion: the stream s has been sucessfully opened for reading.
   1.207 +*/
   1.208 +
   1.209 +
   1.210 +local int unz64local_getByte OF((
   1.211 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
   1.212 +    voidpf filestream,
   1.213 +    int *pi));
   1.214 +
   1.215 +local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)
   1.216 +{
   1.217 +    unsigned char c;
   1.218 +    int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
   1.219 +    if (err==1)
   1.220 +    {
   1.221 +        *pi = (int)c;
   1.222 +        return UNZ_OK;
   1.223 +    }
   1.224 +    else
   1.225 +    {
   1.226 +        if (ZERROR64(*pzlib_filefunc_def,filestream))
   1.227 +            return UNZ_ERRNO;
   1.228 +        else
   1.229 +            return UNZ_EOF;
   1.230 +    }
   1.231 +}
   1.232 +
   1.233 +
   1.234 +/* ===========================================================================
   1.235 +   Reads a long in LSB order from the given gz_stream. Sets
   1.236 +*/
   1.237 +local int unz64local_getShort OF((
   1.238 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
   1.239 +    voidpf filestream,
   1.240 +    uLong *pX));
   1.241 +
   1.242 +local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
   1.243 +                             voidpf filestream,
   1.244 +                             uLong *pX)
   1.245 +{
   1.246 +    uLong x ;
   1.247 +    int i = 0;
   1.248 +    int err;
   1.249 +
   1.250 +    err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.251 +    x = (uLong)i;
   1.252 +
   1.253 +    if (err==UNZ_OK)
   1.254 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.255 +    x |= ((uLong)i)<<8;
   1.256 +
   1.257 +    if (err==UNZ_OK)
   1.258 +        *pX = x;
   1.259 +    else
   1.260 +        *pX = 0;
   1.261 +    return err;
   1.262 +}
   1.263 +
   1.264 +local int unz64local_getLong OF((
   1.265 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
   1.266 +    voidpf filestream,
   1.267 +    uLong *pX));
   1.268 +
   1.269 +local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
   1.270 +                            voidpf filestream,
   1.271 +                            uLong *pX)
   1.272 +{
   1.273 +    uLong x ;
   1.274 +    int i = 0;
   1.275 +    int err;
   1.276 +
   1.277 +    err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.278 +    x = (uLong)i;
   1.279 +
   1.280 +    if (err==UNZ_OK)
   1.281 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.282 +    x |= ((uLong)i)<<8;
   1.283 +
   1.284 +    if (err==UNZ_OK)
   1.285 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.286 +    x |= ((uLong)i)<<16;
   1.287 +
   1.288 +    if (err==UNZ_OK)
   1.289 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.290 +    x += ((uLong)i)<<24;
   1.291 +
   1.292 +    if (err==UNZ_OK)
   1.293 +        *pX = x;
   1.294 +    else
   1.295 +        *pX = 0;
   1.296 +    return err;
   1.297 +}
   1.298 +
   1.299 +local int unz64local_getLong64 OF((
   1.300 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
   1.301 +    voidpf filestream,
   1.302 +    ZPOS64_T *pX));
   1.303 +
   1.304 +
   1.305 +local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
   1.306 +                            voidpf filestream,
   1.307 +                            ZPOS64_T *pX)
   1.308 +{
   1.309 +    ZPOS64_T x ;
   1.310 +    int i = 0;
   1.311 +    int err;
   1.312 +
   1.313 +    err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.314 +    x = (ZPOS64_T)i;
   1.315 +
   1.316 +    if (err==UNZ_OK)
   1.317 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.318 +    x |= ((ZPOS64_T)i)<<8;
   1.319 +
   1.320 +    if (err==UNZ_OK)
   1.321 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.322 +    x |= ((ZPOS64_T)i)<<16;
   1.323 +
   1.324 +    if (err==UNZ_OK)
   1.325 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.326 +    x |= ((ZPOS64_T)i)<<24;
   1.327 +
   1.328 +    if (err==UNZ_OK)
   1.329 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.330 +    x |= ((ZPOS64_T)i)<<32;
   1.331 +
   1.332 +    if (err==UNZ_OK)
   1.333 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.334 +    x |= ((ZPOS64_T)i)<<40;
   1.335 +
   1.336 +    if (err==UNZ_OK)
   1.337 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.338 +    x |= ((ZPOS64_T)i)<<48;
   1.339 +
   1.340 +    if (err==UNZ_OK)
   1.341 +        err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
   1.342 +    x |= ((ZPOS64_T)i)<<56;
   1.343 +
   1.344 +    if (err==UNZ_OK)
   1.345 +        *pX = x;
   1.346 +    else
   1.347 +        *pX = 0;
   1.348 +    return err;
   1.349 +}
   1.350 +
   1.351 +/* My own strcmpi / strcasecmp */
   1.352 +local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
   1.353 +{
   1.354 +    for (;;)
   1.355 +    {
   1.356 +        char c1=*(fileName1++);
   1.357 +        char c2=*(fileName2++);
   1.358 +        if ((c1>='a') && (c1<='z'))
   1.359 +            c1 -= 0x20;
   1.360 +        if ((c2>='a') && (c2<='z'))
   1.361 +            c2 -= 0x20;
   1.362 +        if (c1=='\0')
   1.363 +            return ((c2=='\0') ? 0 : -1);
   1.364 +        if (c2=='\0')
   1.365 +            return 1;
   1.366 +        if (c1<c2)
   1.367 +            return -1;
   1.368 +        if (c1>c2)
   1.369 +            return 1;
   1.370 +    }
   1.371 +}
   1.372 +
   1.373 +
   1.374 +#ifdef  CASESENSITIVITYDEFAULT_NO
   1.375 +#define CASESENSITIVITYDEFAULTVALUE 2
   1.376 +#else
   1.377 +#define CASESENSITIVITYDEFAULTVALUE 1
   1.378 +#endif
   1.379 +
   1.380 +#ifndef STRCMPCASENOSENTIVEFUNCTION
   1.381 +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
   1.382 +#endif
   1.383 +
   1.384 +/*
   1.385 +   Compare two filename (fileName1,fileName2).
   1.386 +   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
   1.387 +   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
   1.388 +                                                                or strcasecmp)
   1.389 +   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
   1.390 +        (like 1 on Unix, 2 on Windows)
   1.391 +
   1.392 +*/
   1.393 +extern int ZEXPORT unzStringFileNameCompare (const char*  fileName1,
   1.394 +                                                 const char*  fileName2,
   1.395 +                                                 int iCaseSensitivity)
   1.396 +
   1.397 +{
   1.398 +    if (iCaseSensitivity==0)
   1.399 +        iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
   1.400 +
   1.401 +    if (iCaseSensitivity==1)
   1.402 +        return strcmp(fileName1,fileName2);
   1.403 +
   1.404 +    return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
   1.405 +}
   1.406 +
   1.407 +#ifndef BUFREADCOMMENT
   1.408 +#define BUFREADCOMMENT (0x400)
   1.409 +#endif
   1.410 +
   1.411 +/*
   1.412 +  Locate the Central directory of a zipfile (at the end, just before
   1.413 +    the global comment)
   1.414 +*/
   1.415 +local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
   1.416 +local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
   1.417 +{
   1.418 +    unsigned char* buf;
   1.419 +    ZPOS64_T uSizeFile;
   1.420 +    ZPOS64_T uBackRead;
   1.421 +    ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
   1.422 +    ZPOS64_T uPosFound=0;
   1.423 +
   1.424 +    if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
   1.425 +        return 0;
   1.426 +
   1.427 +
   1.428 +    uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
   1.429 +
   1.430 +    if (uMaxBack>uSizeFile)
   1.431 +        uMaxBack = uSizeFile;
   1.432 +
   1.433 +    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
   1.434 +    if (buf==NULL)
   1.435 +        return 0;
   1.436 +
   1.437 +    uBackRead = 4;
   1.438 +    while (uBackRead<uMaxBack)
   1.439 +    {
   1.440 +        uLong uReadSize;
   1.441 +        ZPOS64_T uReadPos ;
   1.442 +        int i;
   1.443 +        if (uBackRead+BUFREADCOMMENT>uMaxBack)
   1.444 +            uBackRead = uMaxBack;
   1.445 +        else
   1.446 +            uBackRead+=BUFREADCOMMENT;
   1.447 +        uReadPos = uSizeFile-uBackRead ;
   1.448 +
   1.449 +        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
   1.450 +                     (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
   1.451 +        if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
   1.452 +            break;
   1.453 +
   1.454 +        if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
   1.455 +            break;
   1.456 +
   1.457 +        for (i=(int)uReadSize-3; (i--)>0;)
   1.458 +            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
   1.459 +                ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
   1.460 +            {
   1.461 +                uPosFound = uReadPos+i;
   1.462 +                break;
   1.463 +            }
   1.464 +
   1.465 +        if (uPosFound!=0)
   1.466 +            break;
   1.467 +    }
   1.468 +    TRYFREE(buf);
   1.469 +    return uPosFound;
   1.470 +}
   1.471 +
   1.472 +
   1.473 +/*
   1.474 +  Locate the Central directory 64 of a zipfile (at the end, just before
   1.475 +    the global comment)
   1.476 +*/
   1.477 +local ZPOS64_T unz64local_SearchCentralDir64 OF((
   1.478 +    const zlib_filefunc64_32_def* pzlib_filefunc_def,
   1.479 +    voidpf filestream));
   1.480 +
   1.481 +local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
   1.482 +                                      voidpf filestream)
   1.483 +{
   1.484 +    unsigned char* buf;
   1.485 +    ZPOS64_T uSizeFile;
   1.486 +    ZPOS64_T uBackRead;
   1.487 +    ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
   1.488 +    ZPOS64_T uPosFound=0;
   1.489 +    uLong uL;
   1.490 +                ZPOS64_T relativeOffset;
   1.491 +
   1.492 +    if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
   1.493 +        return 0;
   1.494 +
   1.495 +
   1.496 +    uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
   1.497 +
   1.498 +    if (uMaxBack>uSizeFile)
   1.499 +        uMaxBack = uSizeFile;
   1.500 +
   1.501 +    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
   1.502 +    if (buf==NULL)
   1.503 +        return 0;
   1.504 +
   1.505 +    uBackRead = 4;
   1.506 +    while (uBackRead<uMaxBack)
   1.507 +    {
   1.508 +        uLong uReadSize;
   1.509 +        ZPOS64_T uReadPos;
   1.510 +        int i;
   1.511 +        if (uBackRead+BUFREADCOMMENT>uMaxBack)
   1.512 +            uBackRead = uMaxBack;
   1.513 +        else
   1.514 +            uBackRead+=BUFREADCOMMENT;
   1.515 +        uReadPos = uSizeFile-uBackRead ;
   1.516 +
   1.517 +        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
   1.518 +                     (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
   1.519 +        if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
   1.520 +            break;
   1.521 +
   1.522 +        if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
   1.523 +            break;
   1.524 +
   1.525 +        for (i=(int)uReadSize-3; (i--)>0;)
   1.526 +            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
   1.527 +                ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
   1.528 +            {
   1.529 +                uPosFound = uReadPos+i;
   1.530 +                break;
   1.531 +            }
   1.532 +
   1.533 +        if (uPosFound!=0)
   1.534 +            break;
   1.535 +    }
   1.536 +    TRYFREE(buf);
   1.537 +    if (uPosFound == 0)
   1.538 +        return 0;
   1.539 +
   1.540 +    /* Zip64 end of central directory locator */
   1.541 +    if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
   1.542 +        return 0;
   1.543 +
   1.544 +    /* the signature, already checked */
   1.545 +    if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
   1.546 +        return 0;
   1.547 +
   1.548 +    /* number of the disk with the start of the zip64 end of  central directory */
   1.549 +    if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
   1.550 +        return 0;
   1.551 +    if (uL != 0)
   1.552 +        return 0;
   1.553 +
   1.554 +    /* relative offset of the zip64 end of central directory record */
   1.555 +    if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
   1.556 +        return 0;
   1.557 +
   1.558 +    /* total number of disks */
   1.559 +    if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
   1.560 +        return 0;
   1.561 +    if (uL != 1)
   1.562 +        return 0;
   1.563 +
   1.564 +    /* Goto end of central directory record */
   1.565 +    if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
   1.566 +        return 0;
   1.567 +
   1.568 +     /* the signature */
   1.569 +    if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
   1.570 +        return 0;
   1.571 +
   1.572 +    if (uL != 0x06064b50)
   1.573 +        return 0;
   1.574 +
   1.575 +    return relativeOffset;
   1.576 +}
   1.577 +
   1.578 +/*
   1.579 +  Open a Zip file. path contain the full pathname (by example,
   1.580 +     on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
   1.581 +     "zlib/zlib114.zip".
   1.582 +     If the zipfile cannot be opened (file doesn't exist or in not valid), the
   1.583 +       return value is NULL.
   1.584 +     Else, the return value is a unzFile Handle, usable with other function
   1.585 +       of this unzip package.
   1.586 +*/
   1.587 +local unzFile unzOpenInternal (const void *path,
   1.588 +                               zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
   1.589 +                               int is64bitOpenFunction)
   1.590 +{
   1.591 +    unz64_s us;
   1.592 +    unz64_s *s;
   1.593 +    ZPOS64_T central_pos;
   1.594 +    uLong   uL;
   1.595 +
   1.596 +    uLong number_disk;          /* number of the current dist, used for
   1.597 +                                   spaning ZIP, unsupported, always 0*/
   1.598 +    uLong number_disk_with_CD;  /* number the the disk with central dir, used
   1.599 +                                   for spaning ZIP, unsupported, always 0*/
   1.600 +    ZPOS64_T number_entry_CD;      /* total number of entries in
   1.601 +                                   the central dir
   1.602 +                                   (same than number_entry on nospan) */
   1.603 +
   1.604 +    int err=UNZ_OK;
   1.605 +
   1.606 +    if (unz_copyright[0]!=' ')
   1.607 +        return NULL;
   1.608 +
   1.609 +    us.z_filefunc.zseek32_file = NULL;
   1.610 +    us.z_filefunc.ztell32_file = NULL;
   1.611 +    if (pzlib_filefunc64_32_def==NULL)
   1.612 +        fill_fopen64_filefunc(&us.z_filefunc.zfile_func64);
   1.613 +    else
   1.614 +        us.z_filefunc = *pzlib_filefunc64_32_def;
   1.615 +    us.is64bitOpenFunction = is64bitOpenFunction;
   1.616 +
   1.617 +
   1.618 +
   1.619 +    us.filestream = ZOPEN64(us.z_filefunc,
   1.620 +                                                 path,
   1.621 +                                                 ZLIB_FILEFUNC_MODE_READ |
   1.622 +                                                 ZLIB_FILEFUNC_MODE_EXISTING);
   1.623 +    if (us.filestream==NULL)
   1.624 +        return NULL;
   1.625 +
   1.626 +    central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
   1.627 +    if (central_pos)
   1.628 +    {
   1.629 +        uLong uS;
   1.630 +        ZPOS64_T uL64;
   1.631 +
   1.632 +        us.isZip64 = 1;
   1.633 +
   1.634 +        if (ZSEEK64(us.z_filefunc, us.filestream,
   1.635 +                                      central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
   1.636 +        err=UNZ_ERRNO;
   1.637 +
   1.638 +        /* the signature, already checked */
   1.639 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
   1.640 +            err=UNZ_ERRNO;
   1.641 +
   1.642 +        /* size of zip64 end of central directory record */
   1.643 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
   1.644 +            err=UNZ_ERRNO;
   1.645 +
   1.646 +        /* version made by */
   1.647 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
   1.648 +            err=UNZ_ERRNO;
   1.649 +
   1.650 +        /* version needed to extract */
   1.651 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
   1.652 +            err=UNZ_ERRNO;
   1.653 +
   1.654 +        /* number of this disk */
   1.655 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
   1.656 +            err=UNZ_ERRNO;
   1.657 +
   1.658 +        /* number of the disk with the start of the central directory */
   1.659 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
   1.660 +            err=UNZ_ERRNO;
   1.661 +
   1.662 +        /* total number of entries in the central directory on this disk */
   1.663 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
   1.664 +            err=UNZ_ERRNO;
   1.665 +
   1.666 +        /* total number of entries in the central directory */
   1.667 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
   1.668 +            err=UNZ_ERRNO;
   1.669 +
   1.670 +        if ((number_entry_CD!=us.gi.number_entry) ||
   1.671 +            (number_disk_with_CD!=0) ||
   1.672 +            (number_disk!=0))
   1.673 +            err=UNZ_BADZIPFILE;
   1.674 +
   1.675 +        /* size of the central directory */
   1.676 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
   1.677 +            err=UNZ_ERRNO;
   1.678 +
   1.679 +        /* offset of start of central directory with respect to the
   1.680 +          starting disk number */
   1.681 +        if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
   1.682 +            err=UNZ_ERRNO;
   1.683 +
   1.684 +        us.gi.size_comment = 0;
   1.685 +    }
   1.686 +    else
   1.687 +    {
   1.688 +        central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
   1.689 +        if (central_pos==0)
   1.690 +            err=UNZ_ERRNO;
   1.691 +
   1.692 +        us.isZip64 = 0;
   1.693 +
   1.694 +        if (ZSEEK64(us.z_filefunc, us.filestream,
   1.695 +                                        central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
   1.696 +            err=UNZ_ERRNO;
   1.697 +
   1.698 +        /* the signature, already checked */
   1.699 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
   1.700 +            err=UNZ_ERRNO;
   1.701 +
   1.702 +        /* number of this disk */
   1.703 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
   1.704 +            err=UNZ_ERRNO;
   1.705 +
   1.706 +        /* number of the disk with the start of the central directory */
   1.707 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
   1.708 +            err=UNZ_ERRNO;
   1.709 +
   1.710 +        /* total number of entries in the central dir on this disk */
   1.711 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
   1.712 +            err=UNZ_ERRNO;
   1.713 +        us.gi.number_entry = uL;
   1.714 +
   1.715 +        /* total number of entries in the central dir */
   1.716 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
   1.717 +            err=UNZ_ERRNO;
   1.718 +        number_entry_CD = uL;
   1.719 +
   1.720 +        if ((number_entry_CD!=us.gi.number_entry) ||
   1.721 +            (number_disk_with_CD!=0) ||
   1.722 +            (number_disk!=0))
   1.723 +            err=UNZ_BADZIPFILE;
   1.724 +
   1.725 +        /* size of the central directory */
   1.726 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
   1.727 +            err=UNZ_ERRNO;
   1.728 +        us.size_central_dir = uL;
   1.729 +
   1.730 +        /* offset of start of central directory with respect to the
   1.731 +            starting disk number */
   1.732 +        if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
   1.733 +            err=UNZ_ERRNO;
   1.734 +        us.offset_central_dir = uL;
   1.735 +
   1.736 +        /* zipfile comment length */
   1.737 +        if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
   1.738 +            err=UNZ_ERRNO;
   1.739 +    }
   1.740 +
   1.741 +    if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
   1.742 +        (err==UNZ_OK))
   1.743 +        err=UNZ_BADZIPFILE;
   1.744 +
   1.745 +    if (err!=UNZ_OK)
   1.746 +    {
   1.747 +        ZCLOSE64(us.z_filefunc, us.filestream);
   1.748 +        return NULL;
   1.749 +    }
   1.750 +
   1.751 +    us.byte_before_the_zipfile = central_pos -
   1.752 +                            (us.offset_central_dir+us.size_central_dir);
   1.753 +    us.central_pos = central_pos;
   1.754 +    us.pfile_in_zip_read = NULL;
   1.755 +    us.encrypted = 0;
   1.756 +
   1.757 +
   1.758 +    s=(unz64_s*)ALLOC(sizeof(unz64_s));
   1.759 +    if( s != NULL)
   1.760 +    {
   1.761 +        *s=us;
   1.762 +        unzGoToFirstFile((unzFile)s);
   1.763 +    }
   1.764 +    return (unzFile)s;
   1.765 +}
   1.766 +
   1.767 +
   1.768 +extern unzFile ZEXPORT unzOpen2 (const char *path,
   1.769 +                                        zlib_filefunc_def* pzlib_filefunc32_def)
   1.770 +{
   1.771 +    if (pzlib_filefunc32_def != NULL)
   1.772 +    {
   1.773 +        zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
   1.774 +        fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
   1.775 +        return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
   1.776 +    }
   1.777 +    else
   1.778 +        return unzOpenInternal(path, NULL, 0);
   1.779 +}
   1.780 +
   1.781 +extern unzFile ZEXPORT unzOpen2_64 (const void *path,
   1.782 +                                     zlib_filefunc64_def* pzlib_filefunc_def)
   1.783 +{
   1.784 +    if (pzlib_filefunc_def != NULL)
   1.785 +    {
   1.786 +        zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
   1.787 +        zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
   1.788 +        zlib_filefunc64_32_def_fill.ztell32_file = NULL;
   1.789 +        zlib_filefunc64_32_def_fill.zseek32_file = NULL;
   1.790 +        return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1);
   1.791 +    }
   1.792 +    else
   1.793 +        return unzOpenInternal(path, NULL, 1);
   1.794 +}
   1.795 +
   1.796 +extern unzFile ZEXPORT unzOpen (const char *path)
   1.797 +{
   1.798 +    return unzOpenInternal(path, NULL, 0);
   1.799 +}
   1.800 +
   1.801 +extern unzFile ZEXPORT unzOpen64 (const void *path)
   1.802 +{
   1.803 +    return unzOpenInternal(path, NULL, 1);
   1.804 +}
   1.805 +
   1.806 +/*
   1.807 +  Close a ZipFile opened with unzOpen.
   1.808 +  If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
   1.809 +    these files MUST be closed with unzCloseCurrentFile before call unzClose.
   1.810 +  return UNZ_OK if there is no problem. */
   1.811 +extern int ZEXPORT unzClose (unzFile file)
   1.812 +{
   1.813 +    unz64_s* s;
   1.814 +    if (file==NULL)
   1.815 +        return UNZ_PARAMERROR;
   1.816 +    s=(unz64_s*)file;
   1.817 +
   1.818 +    if (s->pfile_in_zip_read!=NULL)
   1.819 +        unzCloseCurrentFile(file);
   1.820 +
   1.821 +    ZCLOSE64(s->z_filefunc, s->filestream);
   1.822 +    TRYFREE(s);
   1.823 +    return UNZ_OK;
   1.824 +}
   1.825 +
   1.826 +
   1.827 +/*
   1.828 +  Write info about the ZipFile in the *pglobal_info structure.
   1.829 +  No preparation of the structure is needed
   1.830 +  return UNZ_OK if there is no problem. */
   1.831 +extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
   1.832 +{
   1.833 +    unz64_s* s;
   1.834 +    if (file==NULL)
   1.835 +        return UNZ_PARAMERROR;
   1.836 +    s=(unz64_s*)file;
   1.837 +    *pglobal_info=s->gi;
   1.838 +    return UNZ_OK;
   1.839 +}
   1.840 +
   1.841 +extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
   1.842 +{
   1.843 +    unz64_s* s;
   1.844 +    if (file==NULL)
   1.845 +        return UNZ_PARAMERROR;
   1.846 +    s=(unz64_s*)file;
   1.847 +    /* to do : check if number_entry is not truncated */
   1.848 +    pglobal_info32->number_entry = (uLong)s->gi.number_entry;
   1.849 +    pglobal_info32->size_comment = s->gi.size_comment;
   1.850 +    return UNZ_OK;
   1.851 +}
   1.852 +/*
   1.853 +   Translate date/time from Dos format to tm_unz (readable more easilty)
   1.854 +*/
   1.855 +local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
   1.856 +{
   1.857 +    ZPOS64_T uDate;
   1.858 +    uDate = (ZPOS64_T)(ulDosDate>>16);
   1.859 +    ptm->tm_mday = (uInt)(uDate&0x1f) ;
   1.860 +    ptm->tm_mon =  (uInt)((((uDate)&0x1E0)/0x20)-1) ;
   1.861 +    ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
   1.862 +
   1.863 +    ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
   1.864 +    ptm->tm_min =  (uInt) ((ulDosDate&0x7E0)/0x20) ;
   1.865 +    ptm->tm_sec =  (uInt) (2*(ulDosDate&0x1f)) ;
   1.866 +}
   1.867 +
   1.868 +/*
   1.869 +  Get Info about the current file in the zipfile, with internal only info
   1.870 +*/
   1.871 +local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
   1.872 +                                                  unz_file_info64 *pfile_info,
   1.873 +                                                  unz_file_info64_internal
   1.874 +                                                  *pfile_info_internal,
   1.875 +                                                  char *szFileName,
   1.876 +                                                  uLong fileNameBufferSize,
   1.877 +                                                  void *extraField,
   1.878 +                                                  uLong extraFieldBufferSize,
   1.879 +                                                  char *szComment,
   1.880 +                                                  uLong commentBufferSize));
   1.881 +
   1.882 +local int unz64local_GetCurrentFileInfoInternal (unzFile file,
   1.883 +                                                  unz_file_info64 *pfile_info,
   1.884 +                                                  unz_file_info64_internal
   1.885 +                                                  *pfile_info_internal,
   1.886 +                                                  char *szFileName,
   1.887 +                                                  uLong fileNameBufferSize,
   1.888 +                                                  void *extraField,
   1.889 +                                                  uLong extraFieldBufferSize,
   1.890 +                                                  char *szComment,
   1.891 +                                                  uLong commentBufferSize)
   1.892 +{
   1.893 +    unz64_s* s;
   1.894 +    unz_file_info64 file_info;
   1.895 +    unz_file_info64_internal file_info_internal;
   1.896 +    int err=UNZ_OK;
   1.897 +    uLong uMagic;
   1.898 +    long lSeek=0;
   1.899 +    uLong uL;
   1.900 +
   1.901 +    if (file==NULL)
   1.902 +        return UNZ_PARAMERROR;
   1.903 +    s=(unz64_s*)file;
   1.904 +    if (ZSEEK64(s->z_filefunc, s->filestream,
   1.905 +              s->pos_in_central_dir+s->byte_before_the_zipfile,
   1.906 +              ZLIB_FILEFUNC_SEEK_SET)!=0)
   1.907 +        err=UNZ_ERRNO;
   1.908 +
   1.909 +
   1.910 +    /* we check the magic */
   1.911 +    if (err==UNZ_OK)
   1.912 +    {
   1.913 +        if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
   1.914 +            err=UNZ_ERRNO;
   1.915 +        else if (uMagic!=0x02014b50)
   1.916 +            err=UNZ_BADZIPFILE;
   1.917 +    }
   1.918 +
   1.919 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
   1.920 +        err=UNZ_ERRNO;
   1.921 +
   1.922 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
   1.923 +        err=UNZ_ERRNO;
   1.924 +
   1.925 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
   1.926 +        err=UNZ_ERRNO;
   1.927 +
   1.928 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
   1.929 +        err=UNZ_ERRNO;
   1.930 +
   1.931 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
   1.932 +        err=UNZ_ERRNO;
   1.933 +
   1.934 +    unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
   1.935 +
   1.936 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
   1.937 +        err=UNZ_ERRNO;
   1.938 +
   1.939 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
   1.940 +        err=UNZ_ERRNO;
   1.941 +    file_info.compressed_size = uL;
   1.942 +
   1.943 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
   1.944 +        err=UNZ_ERRNO;
   1.945 +    file_info.uncompressed_size = uL;
   1.946 +
   1.947 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
   1.948 +        err=UNZ_ERRNO;
   1.949 +
   1.950 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
   1.951 +        err=UNZ_ERRNO;
   1.952 +
   1.953 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
   1.954 +        err=UNZ_ERRNO;
   1.955 +
   1.956 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
   1.957 +        err=UNZ_ERRNO;
   1.958 +
   1.959 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
   1.960 +        err=UNZ_ERRNO;
   1.961 +
   1.962 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
   1.963 +        err=UNZ_ERRNO;
   1.964 +
   1.965 +                // relative offset of local header
   1.966 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
   1.967 +        err=UNZ_ERRNO;
   1.968 +    file_info_internal.offset_curfile = uL;
   1.969 +
   1.970 +    lSeek+=file_info.size_filename;
   1.971 +    if ((err==UNZ_OK) && (szFileName!=NULL))
   1.972 +    {
   1.973 +        uLong uSizeRead ;
   1.974 +        if (file_info.size_filename<fileNameBufferSize)
   1.975 +        {
   1.976 +            *(szFileName+file_info.size_filename)='\0';
   1.977 +            uSizeRead = file_info.size_filename;
   1.978 +        }
   1.979 +        else
   1.980 +            uSizeRead = fileNameBufferSize;
   1.981 +
   1.982 +        if ((file_info.size_filename>0) && (fileNameBufferSize>0))
   1.983 +            if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
   1.984 +                err=UNZ_ERRNO;
   1.985 +        lSeek -= uSizeRead;
   1.986 +    }
   1.987 +
   1.988 +    // Read extrafield
   1.989 +    if ((err==UNZ_OK) && (extraField!=NULL))
   1.990 +    {
   1.991 +        ZPOS64_T uSizeRead ;
   1.992 +        if (file_info.size_file_extra<extraFieldBufferSize)
   1.993 +            uSizeRead = file_info.size_file_extra;
   1.994 +        else
   1.995 +            uSizeRead = extraFieldBufferSize;
   1.996 +
   1.997 +        if (lSeek!=0)
   1.998 +        {
   1.999 +            if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
  1.1000 +                lSeek=0;
  1.1001 +            else
  1.1002 +                err=UNZ_ERRNO;
  1.1003 +        }
  1.1004 +
  1.1005 +        if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
  1.1006 +            if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
  1.1007 +                err=UNZ_ERRNO;
  1.1008 +
  1.1009 +        lSeek += file_info.size_file_extra - (uLong)uSizeRead;
  1.1010 +    }
  1.1011 +    else
  1.1012 +        lSeek += file_info.size_file_extra;
  1.1013 +
  1.1014 +
  1.1015 +    if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
  1.1016 +    {
  1.1017 +                                uLong acc = 0;
  1.1018 +
  1.1019 +        // since lSeek now points to after the extra field we need to move back
  1.1020 +        lSeek -= file_info.size_file_extra;
  1.1021 +
  1.1022 +        if (lSeek!=0)
  1.1023 +        {
  1.1024 +            if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
  1.1025 +                lSeek=0;
  1.1026 +            else
  1.1027 +                err=UNZ_ERRNO;
  1.1028 +        }
  1.1029 +
  1.1030 +        while(acc < file_info.size_file_extra)
  1.1031 +        {
  1.1032 +            uLong headerId;
  1.1033 +                                                uLong dataSize;
  1.1034 +
  1.1035 +            if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
  1.1036 +                err=UNZ_ERRNO;
  1.1037 +
  1.1038 +            if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
  1.1039 +                err=UNZ_ERRNO;
  1.1040 +
  1.1041 +            /* ZIP64 extra fields */
  1.1042 +            if (headerId == 0x0001)
  1.1043 +            {
  1.1044 +                                                        uLong uL;
  1.1045 +
  1.1046 +                                                                if(file_info.uncompressed_size == MAXU32)
  1.1047 +                                                                {
  1.1048 +                                                                        if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
  1.1049 +                                                                                        err=UNZ_ERRNO;
  1.1050 +                                                                }
  1.1051 +
  1.1052 +                                                                if(file_info.compressed_size == MAXU32)
  1.1053 +                                                                {
  1.1054 +                                                                        if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
  1.1055 +                                                                                  err=UNZ_ERRNO;
  1.1056 +                                                                }
  1.1057 +
  1.1058 +                                                                if(file_info_internal.offset_curfile == MAXU32)
  1.1059 +                                                                {
  1.1060 +                                                                        /* Relative Header offset */
  1.1061 +                                                                        if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
  1.1062 +                                                                                err=UNZ_ERRNO;
  1.1063 +                                                                }
  1.1064 +
  1.1065 +                                                                if(file_info.disk_num_start == MAXU32)
  1.1066 +                                                                {
  1.1067 +                                                                        /* Disk Start Number */
  1.1068 +                                                                        if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
  1.1069 +                                                                                err=UNZ_ERRNO;
  1.1070 +                                                                }
  1.1071 +
  1.1072 +            }
  1.1073 +            else
  1.1074 +            {
  1.1075 +                if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
  1.1076 +                    err=UNZ_ERRNO;
  1.1077 +            }
  1.1078 +
  1.1079 +            acc += 2 + 2 + dataSize;
  1.1080 +        }
  1.1081 +    }
  1.1082 +
  1.1083 +    if ((err==UNZ_OK) && (szComment!=NULL))
  1.1084 +    {
  1.1085 +        uLong uSizeRead ;
  1.1086 +        if (file_info.size_file_comment<commentBufferSize)
  1.1087 +        {
  1.1088 +            *(szComment+file_info.size_file_comment)='\0';
  1.1089 +            uSizeRead = file_info.size_file_comment;
  1.1090 +        }
  1.1091 +        else
  1.1092 +            uSizeRead = commentBufferSize;
  1.1093 +
  1.1094 +        if (lSeek!=0)
  1.1095 +        {
  1.1096 +            if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
  1.1097 +                lSeek=0;
  1.1098 +            else
  1.1099 +                err=UNZ_ERRNO;
  1.1100 +        }
  1.1101 +
  1.1102 +        if ((file_info.size_file_comment>0) && (commentBufferSize>0))
  1.1103 +            if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
  1.1104 +                err=UNZ_ERRNO;
  1.1105 +        lSeek+=file_info.size_file_comment - uSizeRead;
  1.1106 +    }
  1.1107 +    else
  1.1108 +        lSeek+=file_info.size_file_comment;
  1.1109 +
  1.1110 +
  1.1111 +    if ((err==UNZ_OK) && (pfile_info!=NULL))
  1.1112 +        *pfile_info=file_info;
  1.1113 +
  1.1114 +    if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
  1.1115 +        *pfile_info_internal=file_info_internal;
  1.1116 +
  1.1117 +    return err;
  1.1118 +}
  1.1119 +
  1.1120 +
  1.1121 +
  1.1122 +/*
  1.1123 +  Write info about the ZipFile in the *pglobal_info structure.
  1.1124 +  No preparation of the structure is needed
  1.1125 +  return UNZ_OK if there is no problem.
  1.1126 +*/
  1.1127 +extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
  1.1128 +                                          unz_file_info64 * pfile_info,
  1.1129 +                                          char * szFileName, uLong fileNameBufferSize,
  1.1130 +                                          void *extraField, uLong extraFieldBufferSize,
  1.1131 +                                          char* szComment,  uLong commentBufferSize)
  1.1132 +{
  1.1133 +    return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
  1.1134 +                                                szFileName,fileNameBufferSize,
  1.1135 +                                                extraField,extraFieldBufferSize,
  1.1136 +                                                szComment,commentBufferSize);
  1.1137 +}
  1.1138 +
  1.1139 +extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
  1.1140 +                                          unz_file_info * pfile_info,
  1.1141 +                                          char * szFileName, uLong fileNameBufferSize,
  1.1142 +                                          void *extraField, uLong extraFieldBufferSize,
  1.1143 +                                          char* szComment,  uLong commentBufferSize)
  1.1144 +{
  1.1145 +    int err;
  1.1146 +    unz_file_info64 file_info64;
  1.1147 +    err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
  1.1148 +                                                szFileName,fileNameBufferSize,
  1.1149 +                                                extraField,extraFieldBufferSize,
  1.1150 +                                                szComment,commentBufferSize);
  1.1151 +    if ((err==UNZ_OK) && (pfile_info != NULL))
  1.1152 +    {
  1.1153 +        pfile_info->version = file_info64.version;
  1.1154 +        pfile_info->version_needed = file_info64.version_needed;
  1.1155 +        pfile_info->flag = file_info64.flag;
  1.1156 +        pfile_info->compression_method = file_info64.compression_method;
  1.1157 +        pfile_info->dosDate = file_info64.dosDate;
  1.1158 +        pfile_info->crc = file_info64.crc;
  1.1159 +
  1.1160 +        pfile_info->size_filename = file_info64.size_filename;
  1.1161 +        pfile_info->size_file_extra = file_info64.size_file_extra;
  1.1162 +        pfile_info->size_file_comment = file_info64.size_file_comment;
  1.1163 +
  1.1164 +        pfile_info->disk_num_start = file_info64.disk_num_start;
  1.1165 +        pfile_info->internal_fa = file_info64.internal_fa;
  1.1166 +        pfile_info->external_fa = file_info64.external_fa;
  1.1167 +
  1.1168 +        pfile_info->tmu_date = file_info64.tmu_date,
  1.1169 +
  1.1170 +
  1.1171 +        pfile_info->compressed_size = (uLong)file_info64.compressed_size;
  1.1172 +        pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
  1.1173 +
  1.1174 +    }
  1.1175 +    return err;
  1.1176 +}
  1.1177 +/*
  1.1178 +  Set the current file of the zipfile to the first file.
  1.1179 +  return UNZ_OK if there is no problem
  1.1180 +*/
  1.1181 +extern int ZEXPORT unzGoToFirstFile (unzFile file)
  1.1182 +{
  1.1183 +    int err=UNZ_OK;
  1.1184 +    unz64_s* s;
  1.1185 +    if (file==NULL)
  1.1186 +        return UNZ_PARAMERROR;
  1.1187 +    s=(unz64_s*)file;
  1.1188 +    s->pos_in_central_dir=s->offset_central_dir;
  1.1189 +    s->num_file=0;
  1.1190 +    err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
  1.1191 +                                             &s->cur_file_info_internal,
  1.1192 +                                             NULL,0,NULL,0,NULL,0);
  1.1193 +    s->current_file_ok = (err == UNZ_OK);
  1.1194 +    return err;
  1.1195 +}
  1.1196 +
  1.1197 +/*
  1.1198 +  Set the current file of the zipfile to the next file.
  1.1199 +  return UNZ_OK if there is no problem
  1.1200 +  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
  1.1201 +*/
  1.1202 +extern int ZEXPORT unzGoToNextFile (unzFile  file)
  1.1203 +{
  1.1204 +    unz64_s* s;
  1.1205 +    int err;
  1.1206 +
  1.1207 +    if (file==NULL)
  1.1208 +        return UNZ_PARAMERROR;
  1.1209 +    s=(unz64_s*)file;
  1.1210 +    if (!s->current_file_ok)
  1.1211 +        return UNZ_END_OF_LIST_OF_FILE;
  1.1212 +    if (s->gi.number_entry != 0xffff)    /* 2^16 files overflow hack */
  1.1213 +      if (s->num_file+1==s->gi.number_entry)
  1.1214 +        return UNZ_END_OF_LIST_OF_FILE;
  1.1215 +
  1.1216 +    s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
  1.1217 +            s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
  1.1218 +    s->num_file++;
  1.1219 +    err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
  1.1220 +                                               &s->cur_file_info_internal,
  1.1221 +                                               NULL,0,NULL,0,NULL,0);
  1.1222 +    s->current_file_ok = (err == UNZ_OK);
  1.1223 +    return err;
  1.1224 +}
  1.1225 +
  1.1226 +
  1.1227 +/*
  1.1228 +  Try locate the file szFileName in the zipfile.
  1.1229 +  For the iCaseSensitivity signification, see unzStringFileNameCompare
  1.1230 +
  1.1231 +  return value :
  1.1232 +  UNZ_OK if the file is found. It becomes the current file.
  1.1233 +  UNZ_END_OF_LIST_OF_FILE if the file is not found
  1.1234 +*/
  1.1235 +extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
  1.1236 +{
  1.1237 +    unz64_s* s;
  1.1238 +    int err;
  1.1239 +
  1.1240 +    /* We remember the 'current' position in the file so that we can jump
  1.1241 +     * back there if we fail.
  1.1242 +     */
  1.1243 +    unz_file_info64 cur_file_infoSaved;
  1.1244 +    unz_file_info64_internal cur_file_info_internalSaved;
  1.1245 +    ZPOS64_T num_fileSaved;
  1.1246 +    ZPOS64_T pos_in_central_dirSaved;
  1.1247 +
  1.1248 +
  1.1249 +    if (file==NULL)
  1.1250 +        return UNZ_PARAMERROR;
  1.1251 +
  1.1252 +    if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
  1.1253 +        return UNZ_PARAMERROR;
  1.1254 +
  1.1255 +    s=(unz64_s*)file;
  1.1256 +    if (!s->current_file_ok)
  1.1257 +        return UNZ_END_OF_LIST_OF_FILE;
  1.1258 +
  1.1259 +    /* Save the current state */
  1.1260 +    num_fileSaved = s->num_file;
  1.1261 +    pos_in_central_dirSaved = s->pos_in_central_dir;
  1.1262 +    cur_file_infoSaved = s->cur_file_info;
  1.1263 +    cur_file_info_internalSaved = s->cur_file_info_internal;
  1.1264 +
  1.1265 +    err = unzGoToFirstFile(file);
  1.1266 +
  1.1267 +    while (err == UNZ_OK)
  1.1268 +    {
  1.1269 +        char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
  1.1270 +        err = unzGetCurrentFileInfo64(file,NULL,
  1.1271 +                                    szCurrentFileName,sizeof(szCurrentFileName)-1,
  1.1272 +                                    NULL,0,NULL,0);
  1.1273 +        if (err == UNZ_OK)
  1.1274 +        {
  1.1275 +            if (unzStringFileNameCompare(szCurrentFileName,
  1.1276 +                                            szFileName,iCaseSensitivity)==0)
  1.1277 +                return UNZ_OK;
  1.1278 +            err = unzGoToNextFile(file);
  1.1279 +        }
  1.1280 +    }
  1.1281 +
  1.1282 +    /* We failed, so restore the state of the 'current file' to where we
  1.1283 +     * were.
  1.1284 +     */
  1.1285 +    s->num_file = num_fileSaved ;
  1.1286 +    s->pos_in_central_dir = pos_in_central_dirSaved ;
  1.1287 +    s->cur_file_info = cur_file_infoSaved;
  1.1288 +    s->cur_file_info_internal = cur_file_info_internalSaved;
  1.1289 +    return err;
  1.1290 +}
  1.1291 +
  1.1292 +
  1.1293 +/*
  1.1294 +///////////////////////////////////////////
  1.1295 +// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
  1.1296 +// I need random access
  1.1297 +//
  1.1298 +// Further optimization could be realized by adding an ability
  1.1299 +// to cache the directory in memory. The goal being a single
  1.1300 +// comprehensive file read to put the file I need in a memory.
  1.1301 +*/
  1.1302 +
  1.1303 +/*
  1.1304 +typedef struct unz_file_pos_s
  1.1305 +{
  1.1306 +    ZPOS64_T pos_in_zip_directory;   // offset in file
  1.1307 +    ZPOS64_T num_of_file;            // # of file
  1.1308 +} unz_file_pos;
  1.1309 +*/
  1.1310 +
  1.1311 +extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos*  file_pos)
  1.1312 +{
  1.1313 +    unz64_s* s;
  1.1314 +
  1.1315 +    if (file==NULL || file_pos==NULL)
  1.1316 +        return UNZ_PARAMERROR;
  1.1317 +    s=(unz64_s*)file;
  1.1318 +    if (!s->current_file_ok)
  1.1319 +        return UNZ_END_OF_LIST_OF_FILE;
  1.1320 +
  1.1321 +    file_pos->pos_in_zip_directory  = s->pos_in_central_dir;
  1.1322 +    file_pos->num_of_file           = s->num_file;
  1.1323 +
  1.1324 +    return UNZ_OK;
  1.1325 +}
  1.1326 +
  1.1327 +extern int ZEXPORT unzGetFilePos(
  1.1328 +    unzFile file,
  1.1329 +    unz_file_pos* file_pos)
  1.1330 +{
  1.1331 +    unz64_file_pos file_pos64;
  1.1332 +    int err = unzGetFilePos64(file,&file_pos64);
  1.1333 +    if (err==UNZ_OK)
  1.1334 +    {
  1.1335 +        file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
  1.1336 +        file_pos->num_of_file = (uLong)file_pos64.num_of_file;
  1.1337 +    }
  1.1338 +    return err;
  1.1339 +}
  1.1340 +
  1.1341 +extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
  1.1342 +{
  1.1343 +    unz64_s* s;
  1.1344 +    int err;
  1.1345 +
  1.1346 +    if (file==NULL || file_pos==NULL)
  1.1347 +        return UNZ_PARAMERROR;
  1.1348 +    s=(unz64_s*)file;
  1.1349 +
  1.1350 +    /* jump to the right spot */
  1.1351 +    s->pos_in_central_dir = file_pos->pos_in_zip_directory;
  1.1352 +    s->num_file           = file_pos->num_of_file;
  1.1353 +
  1.1354 +    /* set the current file */
  1.1355 +    err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
  1.1356 +                                               &s->cur_file_info_internal,
  1.1357 +                                               NULL,0,NULL,0,NULL,0);
  1.1358 +    /* return results */
  1.1359 +    s->current_file_ok = (err == UNZ_OK);
  1.1360 +    return err;
  1.1361 +}
  1.1362 +
  1.1363 +extern int ZEXPORT unzGoToFilePos(
  1.1364 +    unzFile file,
  1.1365 +    unz_file_pos* file_pos)
  1.1366 +{
  1.1367 +    unz64_file_pos file_pos64;
  1.1368 +    if (file_pos == NULL)
  1.1369 +        return UNZ_PARAMERROR;
  1.1370 +
  1.1371 +    file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
  1.1372 +    file_pos64.num_of_file = file_pos->num_of_file;
  1.1373 +    return unzGoToFilePos64(file,&file_pos64);
  1.1374 +}
  1.1375 +
  1.1376 +/*
  1.1377 +// Unzip Helper Functions - should be here?
  1.1378 +///////////////////////////////////////////
  1.1379 +*/
  1.1380 +
  1.1381 +/*
  1.1382 +  Read the local header of the current zipfile
  1.1383 +  Check the coherency of the local header and info in the end of central
  1.1384 +        directory about this file
  1.1385 +  store in *piSizeVar the size of extra info in local header
  1.1386 +        (filename and size of extra field data)
  1.1387 +*/
  1.1388 +local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
  1.1389 +                                                    ZPOS64_T * poffset_local_extrafield,
  1.1390 +                                                    uInt  * psize_local_extrafield)
  1.1391 +{
  1.1392 +    uLong uMagic,uData,uFlags;
  1.1393 +    uLong size_filename;
  1.1394 +    uLong size_extra_field;
  1.1395 +    int err=UNZ_OK;
  1.1396 +
  1.1397 +    *piSizeVar = 0;
  1.1398 +    *poffset_local_extrafield = 0;
  1.1399 +    *psize_local_extrafield = 0;
  1.1400 +
  1.1401 +    if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
  1.1402 +                                s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
  1.1403 +        return UNZ_ERRNO;
  1.1404 +
  1.1405 +
  1.1406 +    if (err==UNZ_OK)
  1.1407 +    {
  1.1408 +        if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
  1.1409 +            err=UNZ_ERRNO;
  1.1410 +        else if (uMagic!=0x04034b50)
  1.1411 +            err=UNZ_BADZIPFILE;
  1.1412 +    }
  1.1413 +
  1.1414 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
  1.1415 +        err=UNZ_ERRNO;
  1.1416 +/*
  1.1417 +    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
  1.1418 +        err=UNZ_BADZIPFILE;
  1.1419 +*/
  1.1420 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
  1.1421 +        err=UNZ_ERRNO;
  1.1422 +
  1.1423 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
  1.1424 +        err=UNZ_ERRNO;
  1.1425 +    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
  1.1426 +        err=UNZ_BADZIPFILE;
  1.1427 +
  1.1428 +    if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
  1.1429 +/* #ifdef HAVE_BZIP2 */
  1.1430 +                         (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
  1.1431 +/* #endif */
  1.1432 +                         (s->cur_file_info.compression_method!=Z_DEFLATED))
  1.1433 +        err=UNZ_BADZIPFILE;
  1.1434 +
  1.1435 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
  1.1436 +        err=UNZ_ERRNO;
  1.1437 +
  1.1438 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
  1.1439 +        err=UNZ_ERRNO;
  1.1440 +    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
  1.1441 +        err=UNZ_BADZIPFILE;
  1.1442 +
  1.1443 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
  1.1444 +        err=UNZ_ERRNO;
  1.1445 +    else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
  1.1446 +        err=UNZ_BADZIPFILE;
  1.1447 +
  1.1448 +    if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
  1.1449 +        err=UNZ_ERRNO;
  1.1450 +    else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
  1.1451 +        err=UNZ_BADZIPFILE;
  1.1452 +
  1.1453 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
  1.1454 +        err=UNZ_ERRNO;
  1.1455 +    else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
  1.1456 +        err=UNZ_BADZIPFILE;
  1.1457 +
  1.1458 +    *piSizeVar += (uInt)size_filename;
  1.1459 +
  1.1460 +    if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
  1.1461 +        err=UNZ_ERRNO;
  1.1462 +    *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
  1.1463 +                                    SIZEZIPLOCALHEADER + size_filename;
  1.1464 +    *psize_local_extrafield = (uInt)size_extra_field;
  1.1465 +
  1.1466 +    *piSizeVar += (uInt)size_extra_field;
  1.1467 +
  1.1468 +    return err;
  1.1469 +}
  1.1470 +
  1.1471 +/*
  1.1472 +  Open for reading data the current file in the zipfile.
  1.1473 +  If there is no error and the file is opened, the return value is UNZ_OK.
  1.1474 +*/
  1.1475 +extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
  1.1476 +                                            int* level, int raw, const char* password)
  1.1477 +{
  1.1478 +    int err=UNZ_OK;
  1.1479 +    uInt iSizeVar;
  1.1480 +    unz64_s* s;
  1.1481 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1.1482 +    ZPOS64_T offset_local_extrafield;  /* offset of the local extra field */
  1.1483 +    uInt  size_local_extrafield;    /* size of the local extra field */
  1.1484 +#    ifndef NOUNCRYPT
  1.1485 +    char source[12];
  1.1486 +#    else
  1.1487 +    if (password != NULL)
  1.1488 +        return UNZ_PARAMERROR;
  1.1489 +#    endif
  1.1490 +
  1.1491 +    if (file==NULL)
  1.1492 +        return UNZ_PARAMERROR;
  1.1493 +    s=(unz64_s*)file;
  1.1494 +    if (!s->current_file_ok)
  1.1495 +        return UNZ_PARAMERROR;
  1.1496 +
  1.1497 +    if (s->pfile_in_zip_read != NULL)
  1.1498 +        unzCloseCurrentFile(file);
  1.1499 +
  1.1500 +    if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
  1.1501 +        return UNZ_BADZIPFILE;
  1.1502 +
  1.1503 +    pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
  1.1504 +    if (pfile_in_zip_read_info==NULL)
  1.1505 +        return UNZ_INTERNALERROR;
  1.1506 +
  1.1507 +    pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
  1.1508 +    pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
  1.1509 +    pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
  1.1510 +    pfile_in_zip_read_info->pos_local_extrafield=0;
  1.1511 +    pfile_in_zip_read_info->raw=raw;
  1.1512 +
  1.1513 +    if (pfile_in_zip_read_info->read_buffer==NULL)
  1.1514 +    {
  1.1515 +        TRYFREE(pfile_in_zip_read_info);
  1.1516 +        return UNZ_INTERNALERROR;
  1.1517 +    }
  1.1518 +
  1.1519 +    pfile_in_zip_read_info->stream_initialised=0;
  1.1520 +
  1.1521 +    if (method!=NULL)
  1.1522 +        *method = (int)s->cur_file_info.compression_method;
  1.1523 +
  1.1524 +    if (level!=NULL)
  1.1525 +    {
  1.1526 +        *level = 6;
  1.1527 +        switch (s->cur_file_info.flag & 0x06)
  1.1528 +        {
  1.1529 +          case 6 : *level = 1; break;
  1.1530 +          case 4 : *level = 2; break;
  1.1531 +          case 2 : *level = 9; break;
  1.1532 +        }
  1.1533 +    }
  1.1534 +
  1.1535 +    if ((s->cur_file_info.compression_method!=0) &&
  1.1536 +/* #ifdef HAVE_BZIP2 */
  1.1537 +        (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
  1.1538 +/* #endif */
  1.1539 +        (s->cur_file_info.compression_method!=Z_DEFLATED))
  1.1540 +
  1.1541 +        err=UNZ_BADZIPFILE;
  1.1542 +
  1.1543 +    pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
  1.1544 +    pfile_in_zip_read_info->crc32=0;
  1.1545 +    pfile_in_zip_read_info->total_out_64=0;
  1.1546 +    pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
  1.1547 +    pfile_in_zip_read_info->filestream=s->filestream;
  1.1548 +    pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
  1.1549 +    pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
  1.1550 +
  1.1551 +    pfile_in_zip_read_info->stream.total_out = 0;
  1.1552 +
  1.1553 +    if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
  1.1554 +    {
  1.1555 +#ifdef HAVE_BZIP2
  1.1556 +      pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
  1.1557 +      pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
  1.1558 +      pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
  1.1559 +      pfile_in_zip_read_info->bstream.state = (voidpf)0;
  1.1560 +
  1.1561 +      pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
  1.1562 +      pfile_in_zip_read_info->stream.zfree = (free_func)0;
  1.1563 +      pfile_in_zip_read_info->stream.opaque = (voidpf)0;
  1.1564 +      pfile_in_zip_read_info->stream.next_in = (voidpf)0;
  1.1565 +      pfile_in_zip_read_info->stream.avail_in = 0;
  1.1566 +
  1.1567 +      err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
  1.1568 +      if (err == Z_OK)
  1.1569 +        pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
  1.1570 +      else
  1.1571 +      {
  1.1572 +        TRYFREE(pfile_in_zip_read_info);
  1.1573 +        return err;
  1.1574 +      }
  1.1575 +#else
  1.1576 +      pfile_in_zip_read_info->raw=1;
  1.1577 +#endif
  1.1578 +    }
  1.1579 +    else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
  1.1580 +    {
  1.1581 +      pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
  1.1582 +      pfile_in_zip_read_info->stream.zfree = (free_func)0;
  1.1583 +      pfile_in_zip_read_info->stream.opaque = (voidpf)0;
  1.1584 +      pfile_in_zip_read_info->stream.next_in = 0;
  1.1585 +      pfile_in_zip_read_info->stream.avail_in = 0;
  1.1586 +
  1.1587 +      err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
  1.1588 +      if (err == Z_OK)
  1.1589 +        pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
  1.1590 +      else
  1.1591 +      {
  1.1592 +        TRYFREE(pfile_in_zip_read_info);
  1.1593 +        return err;
  1.1594 +      }
  1.1595 +        /* windowBits is passed < 0 to tell that there is no zlib header.
  1.1596 +         * Note that in this case inflate *requires* an extra "dummy" byte
  1.1597 +         * after the compressed stream in order to complete decompression and
  1.1598 +         * return Z_STREAM_END.
  1.1599 +         * In unzip, i don't wait absolutely Z_STREAM_END because I known the
  1.1600 +         * size of both compressed and uncompressed data
  1.1601 +         */
  1.1602 +    }
  1.1603 +    pfile_in_zip_read_info->rest_read_compressed =
  1.1604 +            s->cur_file_info.compressed_size ;
  1.1605 +    pfile_in_zip_read_info->rest_read_uncompressed =
  1.1606 +            s->cur_file_info.uncompressed_size ;
  1.1607 +
  1.1608 +
  1.1609 +    pfile_in_zip_read_info->pos_in_zipfile =
  1.1610 +            s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
  1.1611 +              iSizeVar;
  1.1612 +
  1.1613 +    pfile_in_zip_read_info->stream.avail_in = (uInt)0;
  1.1614 +
  1.1615 +    s->pfile_in_zip_read = pfile_in_zip_read_info;
  1.1616 +                s->encrypted = 0;
  1.1617 +
  1.1618 +#    ifndef NOUNCRYPT
  1.1619 +    if (password != NULL)
  1.1620 +    {
  1.1621 +        int i;
  1.1622 +        s->pcrc_32_tab = get_crc_table();
  1.1623 +        init_keys(password,s->keys,s->pcrc_32_tab);
  1.1624 +        if (ZSEEK64(s->z_filefunc, s->filestream,
  1.1625 +                  s->pfile_in_zip_read->pos_in_zipfile +
  1.1626 +                     s->pfile_in_zip_read->byte_before_the_zipfile,
  1.1627 +                  SEEK_SET)!=0)
  1.1628 +            return UNZ_INTERNALERROR;
  1.1629 +        if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
  1.1630 +            return UNZ_INTERNALERROR;
  1.1631 +
  1.1632 +        for (i = 0; i<12; i++)
  1.1633 +            zdecode(s->keys,s->pcrc_32_tab,source[i]);
  1.1634 +
  1.1635 +        s->pfile_in_zip_read->pos_in_zipfile+=12;
  1.1636 +        s->encrypted=1;
  1.1637 +    }
  1.1638 +#    endif
  1.1639 +
  1.1640 +
  1.1641 +    return UNZ_OK;
  1.1642 +}
  1.1643 +
  1.1644 +extern int ZEXPORT unzOpenCurrentFile (unzFile file)
  1.1645 +{
  1.1646 +    return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
  1.1647 +}
  1.1648 +
  1.1649 +extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char*  password)
  1.1650 +{
  1.1651 +    return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
  1.1652 +}
  1.1653 +
  1.1654 +extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
  1.1655 +{
  1.1656 +    return unzOpenCurrentFile3(file, method, level, raw, NULL);
  1.1657 +}
  1.1658 +
  1.1659 +/** Addition for GDAL : START */
  1.1660 +
  1.1661 +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
  1.1662 +{
  1.1663 +    unz64_s* s;
  1.1664 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1.1665 +    s=(unz64_s*)file;
  1.1666 +    if (file==NULL)
  1.1667 +        return 0; //UNZ_PARAMERROR;
  1.1668 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  1.1669 +    if (pfile_in_zip_read_info==NULL)
  1.1670 +        return 0; //UNZ_PARAMERROR;
  1.1671 +    return pfile_in_zip_read_info->pos_in_zipfile +
  1.1672 +                         pfile_in_zip_read_info->byte_before_the_zipfile;
  1.1673 +}
  1.1674 +
  1.1675 +/** Addition for GDAL : END */
  1.1676 +
  1.1677 +/*
  1.1678 +  Read bytes from the current file.
  1.1679 +  buf contain buffer where data must be copied
  1.1680 +  len the size of buf.
  1.1681 +
  1.1682 +  return the number of byte copied if somes bytes are copied
  1.1683 +  return 0 if the end of file was reached
  1.1684 +  return <0 with error code if there is an error
  1.1685 +    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
  1.1686 +*/
  1.1687 +extern int ZEXPORT unzReadCurrentFile  (unzFile file, voidp buf, unsigned len)
  1.1688 +{
  1.1689 +    int err=UNZ_OK;
  1.1690 +    uInt iRead = 0;
  1.1691 +    unz64_s* s;
  1.1692 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1.1693 +    if (file==NULL)
  1.1694 +        return UNZ_PARAMERROR;
  1.1695 +    s=(unz64_s*)file;
  1.1696 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  1.1697 +
  1.1698 +    if (pfile_in_zip_read_info==NULL)
  1.1699 +        return UNZ_PARAMERROR;
  1.1700 +
  1.1701 +
  1.1702 +    if (pfile_in_zip_read_info->read_buffer == NULL)
  1.1703 +        return UNZ_END_OF_LIST_OF_FILE;
  1.1704 +    if (len==0)
  1.1705 +        return 0;
  1.1706 +
  1.1707 +    pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
  1.1708 +
  1.1709 +    pfile_in_zip_read_info->stream.avail_out = (uInt)len;
  1.1710 +
  1.1711 +    if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
  1.1712 +        (!(pfile_in_zip_read_info->raw)))
  1.1713 +        pfile_in_zip_read_info->stream.avail_out =
  1.1714 +            (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
  1.1715 +
  1.1716 +    if ((len>pfile_in_zip_read_info->rest_read_compressed+
  1.1717 +           pfile_in_zip_read_info->stream.avail_in) &&
  1.1718 +         (pfile_in_zip_read_info->raw))
  1.1719 +        pfile_in_zip_read_info->stream.avail_out =
  1.1720 +            (uInt)pfile_in_zip_read_info->rest_read_compressed+
  1.1721 +            pfile_in_zip_read_info->stream.avail_in;
  1.1722 +
  1.1723 +    while (pfile_in_zip_read_info->stream.avail_out>0)
  1.1724 +    {
  1.1725 +        if ((pfile_in_zip_read_info->stream.avail_in==0) &&
  1.1726 +            (pfile_in_zip_read_info->rest_read_compressed>0))
  1.1727 +        {
  1.1728 +            uInt uReadThis = UNZ_BUFSIZE;
  1.1729 +            if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
  1.1730 +                uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
  1.1731 +            if (uReadThis == 0)
  1.1732 +                return UNZ_EOF;
  1.1733 +            if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
  1.1734 +                      pfile_in_zip_read_info->filestream,
  1.1735 +                      pfile_in_zip_read_info->pos_in_zipfile +
  1.1736 +                         pfile_in_zip_read_info->byte_before_the_zipfile,
  1.1737 +                         ZLIB_FILEFUNC_SEEK_SET)!=0)
  1.1738 +                return UNZ_ERRNO;
  1.1739 +            if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
  1.1740 +                      pfile_in_zip_read_info->filestream,
  1.1741 +                      pfile_in_zip_read_info->read_buffer,
  1.1742 +                      uReadThis)!=uReadThis)
  1.1743 +                return UNZ_ERRNO;
  1.1744 +
  1.1745 +
  1.1746 +#            ifndef NOUNCRYPT
  1.1747 +            if(s->encrypted)
  1.1748 +            {
  1.1749 +                uInt i;
  1.1750 +                for(i=0;i<uReadThis;i++)
  1.1751 +                  pfile_in_zip_read_info->read_buffer[i] =
  1.1752 +                      zdecode(s->keys,s->pcrc_32_tab,
  1.1753 +                              pfile_in_zip_read_info->read_buffer[i]);
  1.1754 +            }
  1.1755 +#            endif
  1.1756 +
  1.1757 +
  1.1758 +            pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
  1.1759 +
  1.1760 +            pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
  1.1761 +
  1.1762 +            pfile_in_zip_read_info->stream.next_in =
  1.1763 +                (Bytef*)pfile_in_zip_read_info->read_buffer;
  1.1764 +            pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
  1.1765 +        }
  1.1766 +
  1.1767 +        if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
  1.1768 +        {
  1.1769 +            uInt uDoCopy,i ;
  1.1770 +
  1.1771 +            if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
  1.1772 +                (pfile_in_zip_read_info->rest_read_compressed == 0))
  1.1773 +                return (iRead==0) ? UNZ_EOF : iRead;
  1.1774 +
  1.1775 +            if (pfile_in_zip_read_info->stream.avail_out <
  1.1776 +                            pfile_in_zip_read_info->stream.avail_in)
  1.1777 +                uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
  1.1778 +            else
  1.1779 +                uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
  1.1780 +
  1.1781 +            for (i=0;i<uDoCopy;i++)
  1.1782 +                *(pfile_in_zip_read_info->stream.next_out+i) =
  1.1783 +                        *(pfile_in_zip_read_info->stream.next_in+i);
  1.1784 +
  1.1785 +            pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
  1.1786 +
  1.1787 +            pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
  1.1788 +                                pfile_in_zip_read_info->stream.next_out,
  1.1789 +                                uDoCopy);
  1.1790 +            pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
  1.1791 +            pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
  1.1792 +            pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
  1.1793 +            pfile_in_zip_read_info->stream.next_out += uDoCopy;
  1.1794 +            pfile_in_zip_read_info->stream.next_in += uDoCopy;
  1.1795 +            pfile_in_zip_read_info->stream.total_out += uDoCopy;
  1.1796 +            iRead += uDoCopy;
  1.1797 +        }
  1.1798 +        else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
  1.1799 +        {
  1.1800 +#ifdef HAVE_BZIP2
  1.1801 +            uLong uTotalOutBefore,uTotalOutAfter;
  1.1802 +            const Bytef *bufBefore;
  1.1803 +            uLong uOutThis;
  1.1804 +
  1.1805 +            pfile_in_zip_read_info->bstream.next_in        = (char*)pfile_in_zip_read_info->stream.next_in;
  1.1806 +            pfile_in_zip_read_info->bstream.avail_in       = pfile_in_zip_read_info->stream.avail_in;
  1.1807 +            pfile_in_zip_read_info->bstream.total_in_lo32  = pfile_in_zip_read_info->stream.total_in;
  1.1808 +            pfile_in_zip_read_info->bstream.total_in_hi32  = 0;
  1.1809 +            pfile_in_zip_read_info->bstream.next_out       = (char*)pfile_in_zip_read_info->stream.next_out;
  1.1810 +            pfile_in_zip_read_info->bstream.avail_out      = pfile_in_zip_read_info->stream.avail_out;
  1.1811 +            pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
  1.1812 +            pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
  1.1813 +
  1.1814 +            uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
  1.1815 +            bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
  1.1816 +
  1.1817 +            err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
  1.1818 +
  1.1819 +            uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
  1.1820 +            uOutThis = uTotalOutAfter-uTotalOutBefore;
  1.1821 +
  1.1822 +            pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
  1.1823 +
  1.1824 +            pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
  1.1825 +            pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
  1.1826 +            iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
  1.1827 +
  1.1828 +            pfile_in_zip_read_info->stream.next_in   = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
  1.1829 +            pfile_in_zip_read_info->stream.avail_in  = pfile_in_zip_read_info->bstream.avail_in;
  1.1830 +            pfile_in_zip_read_info->stream.total_in  = pfile_in_zip_read_info->bstream.total_in_lo32;
  1.1831 +            pfile_in_zip_read_info->stream.next_out  = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
  1.1832 +            pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
  1.1833 +            pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
  1.1834 +
  1.1835 +            if (err==BZ_STREAM_END)
  1.1836 +              return (iRead==0) ? UNZ_EOF : iRead;
  1.1837 +            if (err!=BZ_OK)
  1.1838 +              break;
  1.1839 +#endif
  1.1840 +        } // end Z_BZIP2ED
  1.1841 +        else
  1.1842 +        {
  1.1843 +            ZPOS64_T uTotalOutBefore,uTotalOutAfter;
  1.1844 +            const Bytef *bufBefore;
  1.1845 +            ZPOS64_T uOutThis;
  1.1846 +            int flush=Z_SYNC_FLUSH;
  1.1847 +
  1.1848 +            uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
  1.1849 +            bufBefore = pfile_in_zip_read_info->stream.next_out;
  1.1850 +
  1.1851 +            /*
  1.1852 +            if ((pfile_in_zip_read_info->rest_read_uncompressed ==
  1.1853 +                     pfile_in_zip_read_info->stream.avail_out) &&
  1.1854 +                (pfile_in_zip_read_info->rest_read_compressed == 0))
  1.1855 +                flush = Z_FINISH;
  1.1856 +            */
  1.1857 +            err=inflate(&pfile_in_zip_read_info->stream,flush);
  1.1858 +
  1.1859 +            if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
  1.1860 +              err = Z_DATA_ERROR;
  1.1861 +
  1.1862 +            uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
  1.1863 +            uOutThis = uTotalOutAfter-uTotalOutBefore;
  1.1864 +
  1.1865 +            pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
  1.1866 +
  1.1867 +            pfile_in_zip_read_info->crc32 =
  1.1868 +                crc32(pfile_in_zip_read_info->crc32,bufBefore,
  1.1869 +                        (uInt)(uOutThis));
  1.1870 +
  1.1871 +            pfile_in_zip_read_info->rest_read_uncompressed -=
  1.1872 +                uOutThis;
  1.1873 +
  1.1874 +            iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
  1.1875 +
  1.1876 +            if (err==Z_STREAM_END)
  1.1877 +                return (iRead==0) ? UNZ_EOF : iRead;
  1.1878 +            if (err!=Z_OK)
  1.1879 +                break;
  1.1880 +        }
  1.1881 +    }
  1.1882 +
  1.1883 +    if (err==Z_OK)
  1.1884 +        return iRead;
  1.1885 +    return err;
  1.1886 +}
  1.1887 +
  1.1888 +
  1.1889 +/*
  1.1890 +  Give the current position in uncompressed data
  1.1891 +*/
  1.1892 +extern z_off_t ZEXPORT unztell (unzFile file)
  1.1893 +{
  1.1894 +    unz64_s* s;
  1.1895 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1.1896 +    if (file==NULL)
  1.1897 +        return UNZ_PARAMERROR;
  1.1898 +    s=(unz64_s*)file;
  1.1899 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  1.1900 +
  1.1901 +    if (pfile_in_zip_read_info==NULL)
  1.1902 +        return UNZ_PARAMERROR;
  1.1903 +
  1.1904 +    return (z_off_t)pfile_in_zip_read_info->stream.total_out;
  1.1905 +}
  1.1906 +
  1.1907 +extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
  1.1908 +{
  1.1909 +
  1.1910 +    unz64_s* s;
  1.1911 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1.1912 +    if (file==NULL)
  1.1913 +        return (ZPOS64_T)-1;
  1.1914 +    s=(unz64_s*)file;
  1.1915 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  1.1916 +
  1.1917 +    if (pfile_in_zip_read_info==NULL)
  1.1918 +        return (ZPOS64_T)-1;
  1.1919 +
  1.1920 +    return pfile_in_zip_read_info->total_out_64;
  1.1921 +}
  1.1922 +
  1.1923 +
  1.1924 +/*
  1.1925 +  return 1 if the end of file was reached, 0 elsewhere
  1.1926 +*/
  1.1927 +extern int ZEXPORT unzeof (unzFile file)
  1.1928 +{
  1.1929 +    unz64_s* s;
  1.1930 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1.1931 +    if (file==NULL)
  1.1932 +        return UNZ_PARAMERROR;
  1.1933 +    s=(unz64_s*)file;
  1.1934 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  1.1935 +
  1.1936 +    if (pfile_in_zip_read_info==NULL)
  1.1937 +        return UNZ_PARAMERROR;
  1.1938 +
  1.1939 +    if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
  1.1940 +        return 1;
  1.1941 +    else
  1.1942 +        return 0;
  1.1943 +}
  1.1944 +
  1.1945 +
  1.1946 +
  1.1947 +/*
  1.1948 +Read extra field from the current file (opened by unzOpenCurrentFile)
  1.1949 +This is the local-header version of the extra field (sometimes, there is
  1.1950 +more info in the local-header version than in the central-header)
  1.1951 +
  1.1952 +  if buf==NULL, it return the size of the local extra field that can be read
  1.1953 +
  1.1954 +  if buf!=NULL, len is the size of the buffer, the extra header is copied in
  1.1955 +    buf.
  1.1956 +  the return value is the number of bytes copied in buf, or (if <0)
  1.1957 +    the error code
  1.1958 +*/
  1.1959 +extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
  1.1960 +{
  1.1961 +    unz64_s* s;
  1.1962 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1.1963 +    uInt read_now;
  1.1964 +    ZPOS64_T size_to_read;
  1.1965 +
  1.1966 +    if (file==NULL)
  1.1967 +        return UNZ_PARAMERROR;
  1.1968 +    s=(unz64_s*)file;
  1.1969 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  1.1970 +
  1.1971 +    if (pfile_in_zip_read_info==NULL)
  1.1972 +        return UNZ_PARAMERROR;
  1.1973 +
  1.1974 +    size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
  1.1975 +                pfile_in_zip_read_info->pos_local_extrafield);
  1.1976 +
  1.1977 +    if (buf==NULL)
  1.1978 +        return (int)size_to_read;
  1.1979 +
  1.1980 +    if (len>size_to_read)
  1.1981 +        read_now = (uInt)size_to_read;
  1.1982 +    else
  1.1983 +        read_now = (uInt)len ;
  1.1984 +
  1.1985 +    if (read_now==0)
  1.1986 +        return 0;
  1.1987 +
  1.1988 +    if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
  1.1989 +              pfile_in_zip_read_info->filestream,
  1.1990 +              pfile_in_zip_read_info->offset_local_extrafield +
  1.1991 +              pfile_in_zip_read_info->pos_local_extrafield,
  1.1992 +              ZLIB_FILEFUNC_SEEK_SET)!=0)
  1.1993 +        return UNZ_ERRNO;
  1.1994 +
  1.1995 +    if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
  1.1996 +              pfile_in_zip_read_info->filestream,
  1.1997 +              buf,read_now)!=read_now)
  1.1998 +        return UNZ_ERRNO;
  1.1999 +
  1.2000 +    return (int)read_now;
  1.2001 +}
  1.2002 +
  1.2003 +/*
  1.2004 +  Close the file in zip opened with unzOpenCurrentFile
  1.2005 +  Return UNZ_CRCERROR if all the file was read but the CRC is not good
  1.2006 +*/
  1.2007 +extern int ZEXPORT unzCloseCurrentFile (unzFile file)
  1.2008 +{
  1.2009 +    int err=UNZ_OK;
  1.2010 +
  1.2011 +    unz64_s* s;
  1.2012 +    file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1.2013 +    if (file==NULL)
  1.2014 +        return UNZ_PARAMERROR;
  1.2015 +    s=(unz64_s*)file;
  1.2016 +    pfile_in_zip_read_info=s->pfile_in_zip_read;
  1.2017 +
  1.2018 +    if (pfile_in_zip_read_info==NULL)
  1.2019 +        return UNZ_PARAMERROR;
  1.2020 +
  1.2021 +
  1.2022 +    if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
  1.2023 +        (!pfile_in_zip_read_info->raw))
  1.2024 +    {
  1.2025 +        if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
  1.2026 +            err=UNZ_CRCERROR;
  1.2027 +    }
  1.2028 +
  1.2029 +
  1.2030 +    TRYFREE(pfile_in_zip_read_info->read_buffer);
  1.2031 +    pfile_in_zip_read_info->read_buffer = NULL;
  1.2032 +    if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
  1.2033 +        inflateEnd(&pfile_in_zip_read_info->stream);
  1.2034 +#ifdef HAVE_BZIP2
  1.2035 +    else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
  1.2036 +        BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
  1.2037 +#endif
  1.2038 +
  1.2039 +
  1.2040 +    pfile_in_zip_read_info->stream_initialised = 0;
  1.2041 +    TRYFREE(pfile_in_zip_read_info);
  1.2042 +
  1.2043 +    s->pfile_in_zip_read=NULL;
  1.2044 +
  1.2045 +    return err;
  1.2046 +}
  1.2047 +
  1.2048 +
  1.2049 +/*
  1.2050 +  Get the global comment string of the ZipFile, in the szComment buffer.
  1.2051 +  uSizeBuf is the size of the szComment buffer.
  1.2052 +  return the number of byte copied or an error code <0
  1.2053 +*/
  1.2054 +extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
  1.2055 +{
  1.2056 +    unz64_s* s;
  1.2057 +    uLong uReadThis ;
  1.2058 +    if (file==NULL)
  1.2059 +        return (int)UNZ_PARAMERROR;
  1.2060 +    s=(unz64_s*)file;
  1.2061 +
  1.2062 +    uReadThis = uSizeBuf;
  1.2063 +    if (uReadThis>s->gi.size_comment)
  1.2064 +        uReadThis = s->gi.size_comment;
  1.2065 +
  1.2066 +    if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
  1.2067 +        return UNZ_ERRNO;
  1.2068 +
  1.2069 +    if (uReadThis>0)
  1.2070 +    {
  1.2071 +      *szComment='\0';
  1.2072 +      if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
  1.2073 +        return UNZ_ERRNO;
  1.2074 +    }
  1.2075 +
  1.2076 +    if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
  1.2077 +        *(szComment+s->gi.size_comment)='\0';
  1.2078 +    return (int)uReadThis;
  1.2079 +}
  1.2080 +
  1.2081 +/* Additions by RX '2004 */
  1.2082 +extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
  1.2083 +{
  1.2084 +    unz64_s* s;
  1.2085 +
  1.2086 +    if (file==NULL)
  1.2087 +          return 0; //UNZ_PARAMERROR;
  1.2088 +    s=(unz64_s*)file;
  1.2089 +    if (!s->current_file_ok)
  1.2090 +      return 0;
  1.2091 +    if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
  1.2092 +      if (s->num_file==s->gi.number_entry)
  1.2093 +         return 0;
  1.2094 +    return s->pos_in_central_dir;
  1.2095 +}
  1.2096 +
  1.2097 +extern uLong ZEXPORT unzGetOffset (unzFile file)
  1.2098 +{
  1.2099 +    ZPOS64_T offset64;
  1.2100 +
  1.2101 +    if (file==NULL)
  1.2102 +          return 0; //UNZ_PARAMERROR;
  1.2103 +    offset64 = unzGetOffset64(file);
  1.2104 +    return (uLong)offset64;
  1.2105 +}
  1.2106 +
  1.2107 +extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
  1.2108 +{
  1.2109 +    unz64_s* s;
  1.2110 +    int err;
  1.2111 +
  1.2112 +    if (file==NULL)
  1.2113 +        return UNZ_PARAMERROR;
  1.2114 +    s=(unz64_s*)file;
  1.2115 +
  1.2116 +    s->pos_in_central_dir = pos;
  1.2117 +    s->num_file = s->gi.number_entry;      /* hack */
  1.2118 +    err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
  1.2119 +                                              &s->cur_file_info_internal,
  1.2120 +                                              NULL,0,NULL,0,NULL,0);
  1.2121 +    s->current_file_ok = (err == UNZ_OK);
  1.2122 +    return err;
  1.2123 +}
  1.2124 +
  1.2125 +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
  1.2126 +{
  1.2127 +    return unzSetOffset64(file,pos);
  1.2128 +}