Home | History | Annotate | Line # | Download | only in minizip
unzip.c revision 1.1.1.1.2.2
      1  1.1.1.1.2.2  pgoyette /* unzip.c -- IO for uncompress .zip files using zlib
      2  1.1.1.1.2.2  pgoyette    Version 1.1, February 14h, 2010
      3  1.1.1.1.2.2  pgoyette    part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
      4  1.1.1.1.2.2  pgoyette 
      5  1.1.1.1.2.2  pgoyette          Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
      6  1.1.1.1.2.2  pgoyette 
      7  1.1.1.1.2.2  pgoyette          Modifications of Unzip for Zip64
      8  1.1.1.1.2.2  pgoyette          Copyright (C) 2007-2008 Even Rouault
      9  1.1.1.1.2.2  pgoyette 
     10  1.1.1.1.2.2  pgoyette          Modifications for Zip64 support on both zip and unzip
     11  1.1.1.1.2.2  pgoyette          Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
     12  1.1.1.1.2.2  pgoyette 
     13  1.1.1.1.2.2  pgoyette          For more info read MiniZip_info.txt
     14  1.1.1.1.2.2  pgoyette 
     15  1.1.1.1.2.2  pgoyette 
     16  1.1.1.1.2.2  pgoyette   ------------------------------------------------------------------------------------
     17  1.1.1.1.2.2  pgoyette   Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
     18  1.1.1.1.2.2  pgoyette   compatibility with older software. The following is from the original crypt.c.
     19  1.1.1.1.2.2  pgoyette   Code woven in by Terry Thorsen 1/2003.
     20  1.1.1.1.2.2  pgoyette 
     21  1.1.1.1.2.2  pgoyette   Copyright (c) 1990-2000 Info-ZIP.  All rights reserved.
     22  1.1.1.1.2.2  pgoyette 
     23  1.1.1.1.2.2  pgoyette   See the accompanying file LICENSE, version 2000-Apr-09 or later
     24  1.1.1.1.2.2  pgoyette   (the contents of which are also included in zip.h) for terms of use.
     25  1.1.1.1.2.2  pgoyette   If, for some reason, all these files are missing, the Info-ZIP license
     26  1.1.1.1.2.2  pgoyette   also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
     27  1.1.1.1.2.2  pgoyette 
     28  1.1.1.1.2.2  pgoyette         crypt.c (full version) by Info-ZIP.      Last revised:  [see crypt.h]
     29  1.1.1.1.2.2  pgoyette 
     30  1.1.1.1.2.2  pgoyette   The encryption/decryption parts of this source code (as opposed to the
     31  1.1.1.1.2.2  pgoyette   non-echoing password parts) were originally written in Europe.  The
     32  1.1.1.1.2.2  pgoyette   whole source package can be freely distributed, including from the USA.
     33  1.1.1.1.2.2  pgoyette   (Prior to January 2000, re-export from the US was a violation of US law.)
     34  1.1.1.1.2.2  pgoyette 
     35  1.1.1.1.2.2  pgoyette         This encryption code is a direct transcription of the algorithm from
     36  1.1.1.1.2.2  pgoyette   Roger Schlafly, described by Phil Katz in the file appnote.txt.  This
     37  1.1.1.1.2.2  pgoyette   file (appnote.txt) is distributed with the PKZIP program (even in the
     38  1.1.1.1.2.2  pgoyette   version without encryption capabilities).
     39  1.1.1.1.2.2  pgoyette 
     40  1.1.1.1.2.2  pgoyette         ------------------------------------------------------------------------------------
     41  1.1.1.1.2.2  pgoyette 
     42  1.1.1.1.2.2  pgoyette         Changes in unzip.c
     43  1.1.1.1.2.2  pgoyette 
     44  1.1.1.1.2.2  pgoyette         2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos
     45  1.1.1.1.2.2  pgoyette   2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz*
     46  1.1.1.1.2.2  pgoyette   2007-2008 - Even Rouault - Remove old C style function prototypes
     47  1.1.1.1.2.2  pgoyette   2007-2008 - Even Rouault - Add unzip support for ZIP64
     48  1.1.1.1.2.2  pgoyette 
     49  1.1.1.1.2.2  pgoyette         Copyright (C) 2007-2008 Even Rouault
     50  1.1.1.1.2.2  pgoyette 
     51  1.1.1.1.2.2  pgoyette 
     52  1.1.1.1.2.2  pgoyette         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).
     53  1.1.1.1.2.2  pgoyette   Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
     54  1.1.1.1.2.2  pgoyette                                 should only read the compressed/uncompressed size from the Zip64 format if
     55  1.1.1.1.2.2  pgoyette                                 the size from normal header was 0xFFFFFFFF
     56  1.1.1.1.2.2  pgoyette   Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
     57  1.1.1.1.2.2  pgoyette         Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
     58  1.1.1.1.2.2  pgoyette                                 Patch created by Daniel Borca
     59  1.1.1.1.2.2  pgoyette 
     60  1.1.1.1.2.2  pgoyette   Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
     61  1.1.1.1.2.2  pgoyette 
     62  1.1.1.1.2.2  pgoyette   Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
     63  1.1.1.1.2.2  pgoyette 
     64  1.1.1.1.2.2  pgoyette */
     65  1.1.1.1.2.2  pgoyette 
     66  1.1.1.1.2.2  pgoyette 
     67  1.1.1.1.2.2  pgoyette #include <stdio.h>
     68  1.1.1.1.2.2  pgoyette #include <stdlib.h>
     69  1.1.1.1.2.2  pgoyette #include <string.h>
     70  1.1.1.1.2.2  pgoyette 
     71  1.1.1.1.2.2  pgoyette #ifndef NOUNCRYPT
     72  1.1.1.1.2.2  pgoyette         #define NOUNCRYPT
     73  1.1.1.1.2.2  pgoyette #endif
     74  1.1.1.1.2.2  pgoyette 
     75  1.1.1.1.2.2  pgoyette #include "zlib.h"
     76  1.1.1.1.2.2  pgoyette #include "unzip.h"
     77  1.1.1.1.2.2  pgoyette 
     78  1.1.1.1.2.2  pgoyette #ifdef STDC
     79  1.1.1.1.2.2  pgoyette #  include <stddef.h>
     80  1.1.1.1.2.2  pgoyette #  include <string.h>
     81  1.1.1.1.2.2  pgoyette #  include <stdlib.h>
     82  1.1.1.1.2.2  pgoyette #endif
     83  1.1.1.1.2.2  pgoyette #ifdef NO_ERRNO_H
     84  1.1.1.1.2.2  pgoyette     extern int errno;
     85  1.1.1.1.2.2  pgoyette #else
     86  1.1.1.1.2.2  pgoyette #   include <errno.h>
     87  1.1.1.1.2.2  pgoyette #endif
     88  1.1.1.1.2.2  pgoyette 
     89  1.1.1.1.2.2  pgoyette 
     90  1.1.1.1.2.2  pgoyette #ifndef local
     91  1.1.1.1.2.2  pgoyette #  define local static
     92  1.1.1.1.2.2  pgoyette #endif
     93  1.1.1.1.2.2  pgoyette /* compile with -Dlocal if your debugger can't find static symbols */
     94  1.1.1.1.2.2  pgoyette 
     95  1.1.1.1.2.2  pgoyette 
     96  1.1.1.1.2.2  pgoyette #ifndef CASESENSITIVITYDEFAULT_NO
     97  1.1.1.1.2.2  pgoyette #  if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
     98  1.1.1.1.2.2  pgoyette #    define CASESENSITIVITYDEFAULT_NO
     99  1.1.1.1.2.2  pgoyette #  endif
    100  1.1.1.1.2.2  pgoyette #endif
    101  1.1.1.1.2.2  pgoyette 
    102  1.1.1.1.2.2  pgoyette 
    103  1.1.1.1.2.2  pgoyette #ifndef UNZ_BUFSIZE
    104  1.1.1.1.2.2  pgoyette #define UNZ_BUFSIZE (16384)
    105  1.1.1.1.2.2  pgoyette #endif
    106  1.1.1.1.2.2  pgoyette 
    107  1.1.1.1.2.2  pgoyette #ifndef UNZ_MAXFILENAMEINZIP
    108  1.1.1.1.2.2  pgoyette #define UNZ_MAXFILENAMEINZIP (256)
    109  1.1.1.1.2.2  pgoyette #endif
    110  1.1.1.1.2.2  pgoyette 
    111  1.1.1.1.2.2  pgoyette #ifndef ALLOC
    112  1.1.1.1.2.2  pgoyette # define ALLOC(size) (malloc(size))
    113  1.1.1.1.2.2  pgoyette #endif
    114  1.1.1.1.2.2  pgoyette #ifndef TRYFREE
    115  1.1.1.1.2.2  pgoyette # define TRYFREE(p) {if (p) free(p);}
    116  1.1.1.1.2.2  pgoyette #endif
    117  1.1.1.1.2.2  pgoyette 
    118  1.1.1.1.2.2  pgoyette #define SIZECENTRALDIRITEM (0x2e)
    119  1.1.1.1.2.2  pgoyette #define SIZEZIPLOCALHEADER (0x1e)
    120  1.1.1.1.2.2  pgoyette 
    121  1.1.1.1.2.2  pgoyette 
    122  1.1.1.1.2.2  pgoyette const char unz_copyright[] =
    123  1.1.1.1.2.2  pgoyette    " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
    124  1.1.1.1.2.2  pgoyette 
    125  1.1.1.1.2.2  pgoyette /* unz_file_info_interntal contain internal info about a file in zipfile*/
    126  1.1.1.1.2.2  pgoyette typedef struct unz_file_info64_internal_s
    127  1.1.1.1.2.2  pgoyette {
    128  1.1.1.1.2.2  pgoyette     ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */
    129  1.1.1.1.2.2  pgoyette } unz_file_info64_internal;
    130  1.1.1.1.2.2  pgoyette 
    131  1.1.1.1.2.2  pgoyette 
    132  1.1.1.1.2.2  pgoyette /* file_in_zip_read_info_s contain internal information about a file in zipfile,
    133  1.1.1.1.2.2  pgoyette     when reading and decompress it */
    134  1.1.1.1.2.2  pgoyette typedef struct
    135  1.1.1.1.2.2  pgoyette {
    136  1.1.1.1.2.2  pgoyette     char  *read_buffer;         /* internal buffer for compressed data */
    137  1.1.1.1.2.2  pgoyette     z_stream stream;            /* zLib stream structure for inflate */
    138  1.1.1.1.2.2  pgoyette 
    139  1.1.1.1.2.2  pgoyette #ifdef HAVE_BZIP2
    140  1.1.1.1.2.2  pgoyette     bz_stream bstream;          /* bzLib stream structure for bziped */
    141  1.1.1.1.2.2  pgoyette #endif
    142  1.1.1.1.2.2  pgoyette 
    143  1.1.1.1.2.2  pgoyette     ZPOS64_T pos_in_zipfile;       /* position in byte on the zipfile, for fseek*/
    144  1.1.1.1.2.2  pgoyette     uLong stream_initialised;   /* flag set if stream structure is initialised*/
    145  1.1.1.1.2.2  pgoyette 
    146  1.1.1.1.2.2  pgoyette     ZPOS64_T offset_local_extrafield;/* offset of the local extra field */
    147  1.1.1.1.2.2  pgoyette     uInt  size_local_extrafield;/* size of the local extra field */
    148  1.1.1.1.2.2  pgoyette     ZPOS64_T pos_local_extrafield;   /* position in the local extra field in read*/
    149  1.1.1.1.2.2  pgoyette     ZPOS64_T total_out_64;
    150  1.1.1.1.2.2  pgoyette 
    151  1.1.1.1.2.2  pgoyette     uLong crc32;                /* crc32 of all data uncompressed */
    152  1.1.1.1.2.2  pgoyette     uLong crc32_wait;           /* crc32 we must obtain after decompress all */
    153  1.1.1.1.2.2  pgoyette     ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
    154  1.1.1.1.2.2  pgoyette     ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
    155  1.1.1.1.2.2  pgoyette     zlib_filefunc64_32_def z_filefunc;
    156  1.1.1.1.2.2  pgoyette     voidpf filestream;        /* io structore of the zipfile */
    157  1.1.1.1.2.2  pgoyette     uLong compression_method;   /* compression method (0==store) */
    158  1.1.1.1.2.2  pgoyette     ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
    159  1.1.1.1.2.2  pgoyette     int   raw;
    160  1.1.1.1.2.2  pgoyette } file_in_zip64_read_info_s;
    161  1.1.1.1.2.2  pgoyette 
    162  1.1.1.1.2.2  pgoyette 
    163  1.1.1.1.2.2  pgoyette /* unz64_s contain internal information about the zipfile
    164  1.1.1.1.2.2  pgoyette */
    165  1.1.1.1.2.2  pgoyette typedef struct
    166  1.1.1.1.2.2  pgoyette {
    167  1.1.1.1.2.2  pgoyette     zlib_filefunc64_32_def z_filefunc;
    168  1.1.1.1.2.2  pgoyette     int is64bitOpenFunction;
    169  1.1.1.1.2.2  pgoyette     voidpf filestream;        /* io structore of the zipfile */
    170  1.1.1.1.2.2  pgoyette     unz_global_info64 gi;       /* public global information */
    171  1.1.1.1.2.2  pgoyette     ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
    172  1.1.1.1.2.2  pgoyette     ZPOS64_T num_file;             /* number of the current file in the zipfile*/
    173  1.1.1.1.2.2  pgoyette     ZPOS64_T pos_in_central_dir;   /* pos of the current file in the central dir*/
    174  1.1.1.1.2.2  pgoyette     ZPOS64_T current_file_ok;      /* flag about the usability of the current file*/
    175  1.1.1.1.2.2  pgoyette     ZPOS64_T central_pos;          /* position of the beginning of the central dir*/
    176  1.1.1.1.2.2  pgoyette 
    177  1.1.1.1.2.2  pgoyette     ZPOS64_T size_central_dir;     /* size of the central directory  */
    178  1.1.1.1.2.2  pgoyette     ZPOS64_T offset_central_dir;   /* offset of start of central directory with
    179  1.1.1.1.2.2  pgoyette                                    respect to the starting disk number */
    180  1.1.1.1.2.2  pgoyette 
    181  1.1.1.1.2.2  pgoyette     unz_file_info64 cur_file_info; /* public info about the current file in zip*/
    182  1.1.1.1.2.2  pgoyette     unz_file_info64_internal cur_file_info_internal; /* private info about it*/
    183  1.1.1.1.2.2  pgoyette     file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current
    184  1.1.1.1.2.2  pgoyette                                         file if we are decompressing it */
    185  1.1.1.1.2.2  pgoyette     int encrypted;
    186  1.1.1.1.2.2  pgoyette 
    187  1.1.1.1.2.2  pgoyette     int isZip64;
    188  1.1.1.1.2.2  pgoyette 
    189  1.1.1.1.2.2  pgoyette #    ifndef NOUNCRYPT
    190  1.1.1.1.2.2  pgoyette     unsigned long keys[3];     /* keys defining the pseudo-random sequence */
    191  1.1.1.1.2.2  pgoyette     const unsigned long* pcrc_32_tab;
    192  1.1.1.1.2.2  pgoyette #    endif
    193  1.1.1.1.2.2  pgoyette } unz64_s;
    194  1.1.1.1.2.2  pgoyette 
    195  1.1.1.1.2.2  pgoyette 
    196  1.1.1.1.2.2  pgoyette #ifndef NOUNCRYPT
    197  1.1.1.1.2.2  pgoyette #include "crypt.h"
    198  1.1.1.1.2.2  pgoyette #endif
    199  1.1.1.1.2.2  pgoyette 
    200  1.1.1.1.2.2  pgoyette /* ===========================================================================
    201  1.1.1.1.2.2  pgoyette      Read a byte from a gz_stream; update next_in and avail_in. Return EOF
    202  1.1.1.1.2.2  pgoyette    for end of file.
    203  1.1.1.1.2.2  pgoyette    IN assertion: the stream s has been sucessfully opened for reading.
    204  1.1.1.1.2.2  pgoyette */
    205  1.1.1.1.2.2  pgoyette 
    206  1.1.1.1.2.2  pgoyette 
    207  1.1.1.1.2.2  pgoyette local int unz64local_getByte OF((
    208  1.1.1.1.2.2  pgoyette     const zlib_filefunc64_32_def* pzlib_filefunc_def,
    209  1.1.1.1.2.2  pgoyette     voidpf filestream,
    210  1.1.1.1.2.2  pgoyette     int *pi));
    211  1.1.1.1.2.2  pgoyette 
    212  1.1.1.1.2.2  pgoyette local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)
    213  1.1.1.1.2.2  pgoyette {
    214  1.1.1.1.2.2  pgoyette     unsigned char c;
    215  1.1.1.1.2.2  pgoyette     int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
    216  1.1.1.1.2.2  pgoyette     if (err==1)
    217  1.1.1.1.2.2  pgoyette     {
    218  1.1.1.1.2.2  pgoyette         *pi = (int)c;
    219  1.1.1.1.2.2  pgoyette         return UNZ_OK;
    220  1.1.1.1.2.2  pgoyette     }
    221  1.1.1.1.2.2  pgoyette     else
    222  1.1.1.1.2.2  pgoyette     {
    223  1.1.1.1.2.2  pgoyette         if (ZERROR64(*pzlib_filefunc_def,filestream))
    224  1.1.1.1.2.2  pgoyette             return UNZ_ERRNO;
    225  1.1.1.1.2.2  pgoyette         else
    226  1.1.1.1.2.2  pgoyette             return UNZ_EOF;
    227  1.1.1.1.2.2  pgoyette     }
    228  1.1.1.1.2.2  pgoyette }
    229  1.1.1.1.2.2  pgoyette 
    230  1.1.1.1.2.2  pgoyette 
    231  1.1.1.1.2.2  pgoyette /* ===========================================================================
    232  1.1.1.1.2.2  pgoyette    Reads a long in LSB order from the given gz_stream. Sets
    233  1.1.1.1.2.2  pgoyette */
    234  1.1.1.1.2.2  pgoyette local int unz64local_getShort OF((
    235  1.1.1.1.2.2  pgoyette     const zlib_filefunc64_32_def* pzlib_filefunc_def,
    236  1.1.1.1.2.2  pgoyette     voidpf filestream,
    237  1.1.1.1.2.2  pgoyette     uLong *pX));
    238  1.1.1.1.2.2  pgoyette 
    239  1.1.1.1.2.2  pgoyette local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
    240  1.1.1.1.2.2  pgoyette                              voidpf filestream,
    241  1.1.1.1.2.2  pgoyette                              uLong *pX)
    242  1.1.1.1.2.2  pgoyette {
    243  1.1.1.1.2.2  pgoyette     uLong x ;
    244  1.1.1.1.2.2  pgoyette     int i = 0;
    245  1.1.1.1.2.2  pgoyette     int err;
    246  1.1.1.1.2.2  pgoyette 
    247  1.1.1.1.2.2  pgoyette     err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    248  1.1.1.1.2.2  pgoyette     x = (uLong)i;
    249  1.1.1.1.2.2  pgoyette 
    250  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    251  1.1.1.1.2.2  pgoyette         err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    252  1.1.1.1.2.2  pgoyette     x |= ((uLong)i)<<8;
    253  1.1.1.1.2.2  pgoyette 
    254  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    255  1.1.1.1.2.2  pgoyette         *pX = x;
    256  1.1.1.1.2.2  pgoyette     else
    257  1.1.1.1.2.2  pgoyette         *pX = 0;
    258  1.1.1.1.2.2  pgoyette     return err;
    259  1.1.1.1.2.2  pgoyette }
    260  1.1.1.1.2.2  pgoyette 
    261  1.1.1.1.2.2  pgoyette local int unz64local_getLong OF((
    262  1.1.1.1.2.2  pgoyette     const zlib_filefunc64_32_def* pzlib_filefunc_def,
    263  1.1.1.1.2.2  pgoyette     voidpf filestream,
    264  1.1.1.1.2.2  pgoyette     uLong *pX));
    265  1.1.1.1.2.2  pgoyette 
    266  1.1.1.1.2.2  pgoyette local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
    267  1.1.1.1.2.2  pgoyette                             voidpf filestream,
    268  1.1.1.1.2.2  pgoyette                             uLong *pX)
    269  1.1.1.1.2.2  pgoyette {
    270  1.1.1.1.2.2  pgoyette     uLong x ;
    271  1.1.1.1.2.2  pgoyette     int i = 0;
    272  1.1.1.1.2.2  pgoyette     int err;
    273  1.1.1.1.2.2  pgoyette 
    274  1.1.1.1.2.2  pgoyette     err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    275  1.1.1.1.2.2  pgoyette     x = (uLong)i;
    276  1.1.1.1.2.2  pgoyette 
    277  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    278  1.1.1.1.2.2  pgoyette         err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    279  1.1.1.1.2.2  pgoyette     x |= ((uLong)i)<<8;
    280  1.1.1.1.2.2  pgoyette 
    281  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    282  1.1.1.1.2.2  pgoyette         err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    283  1.1.1.1.2.2  pgoyette     x |= ((uLong)i)<<16;
    284  1.1.1.1.2.2  pgoyette 
    285  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    286  1.1.1.1.2.2  pgoyette         err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    287  1.1.1.1.2.2  pgoyette     x += ((uLong)i)<<24;
    288  1.1.1.1.2.2  pgoyette 
    289  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    290  1.1.1.1.2.2  pgoyette         *pX = x;
    291  1.1.1.1.2.2  pgoyette     else
    292  1.1.1.1.2.2  pgoyette         *pX = 0;
    293  1.1.1.1.2.2  pgoyette     return err;
    294  1.1.1.1.2.2  pgoyette }
    295  1.1.1.1.2.2  pgoyette 
    296  1.1.1.1.2.2  pgoyette local int unz64local_getLong64 OF((
    297  1.1.1.1.2.2  pgoyette     const zlib_filefunc64_32_def* pzlib_filefunc_def,
    298  1.1.1.1.2.2  pgoyette     voidpf filestream,
    299  1.1.1.1.2.2  pgoyette     ZPOS64_T *pX));
    300  1.1.1.1.2.2  pgoyette 
    301  1.1.1.1.2.2  pgoyette 
    302  1.1.1.1.2.2  pgoyette local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
    303  1.1.1.1.2.2  pgoyette                             voidpf filestream,
    304  1.1.1.1.2.2  pgoyette                             ZPOS64_T *pX)
    305  1.1.1.1.2.2  pgoyette {
    306  1.1.1.1.2.2  pgoyette     ZPOS64_T x ;
    307  1.1.1.1.2.2  pgoyette     int i = 0;
    308  1.1.1.1.2.2  pgoyette     int err;
    309  1.1.1.1.2.2  pgoyette 
    310  1.1.1.1.2.2  pgoyette     err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    311  1.1.1.1.2.2  pgoyette     x = (ZPOS64_T)i;
    312  1.1.1.1.2.2  pgoyette 
    313  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    314  1.1.1.1.2.2  pgoyette         err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    315  1.1.1.1.2.2  pgoyette     x |= ((ZPOS64_T)i)<<8;
    316  1.1.1.1.2.2  pgoyette 
    317  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    318  1.1.1.1.2.2  pgoyette         err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    319  1.1.1.1.2.2  pgoyette     x |= ((ZPOS64_T)i)<<16;
    320  1.1.1.1.2.2  pgoyette 
    321  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    322  1.1.1.1.2.2  pgoyette         err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    323  1.1.1.1.2.2  pgoyette     x |= ((ZPOS64_T)i)<<24;
    324  1.1.1.1.2.2  pgoyette 
    325  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    326  1.1.1.1.2.2  pgoyette         err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    327  1.1.1.1.2.2  pgoyette     x |= ((ZPOS64_T)i)<<32;
    328  1.1.1.1.2.2  pgoyette 
    329  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    330  1.1.1.1.2.2  pgoyette         err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    331  1.1.1.1.2.2  pgoyette     x |= ((ZPOS64_T)i)<<40;
    332  1.1.1.1.2.2  pgoyette 
    333  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    334  1.1.1.1.2.2  pgoyette         err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    335  1.1.1.1.2.2  pgoyette     x |= ((ZPOS64_T)i)<<48;
    336  1.1.1.1.2.2  pgoyette 
    337  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    338  1.1.1.1.2.2  pgoyette         err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
    339  1.1.1.1.2.2  pgoyette     x |= ((ZPOS64_T)i)<<56;
    340  1.1.1.1.2.2  pgoyette 
    341  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    342  1.1.1.1.2.2  pgoyette         *pX = x;
    343  1.1.1.1.2.2  pgoyette     else
    344  1.1.1.1.2.2  pgoyette         *pX = 0;
    345  1.1.1.1.2.2  pgoyette     return err;
    346  1.1.1.1.2.2  pgoyette }
    347  1.1.1.1.2.2  pgoyette 
    348  1.1.1.1.2.2  pgoyette /* My own strcmpi / strcasecmp */
    349  1.1.1.1.2.2  pgoyette local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
    350  1.1.1.1.2.2  pgoyette {
    351  1.1.1.1.2.2  pgoyette     for (;;)
    352  1.1.1.1.2.2  pgoyette     {
    353  1.1.1.1.2.2  pgoyette         char c1=*(fileName1++);
    354  1.1.1.1.2.2  pgoyette         char c2=*(fileName2++);
    355  1.1.1.1.2.2  pgoyette         if ((c1>='a') && (c1<='z'))
    356  1.1.1.1.2.2  pgoyette             c1 -= 0x20;
    357  1.1.1.1.2.2  pgoyette         if ((c2>='a') && (c2<='z'))
    358  1.1.1.1.2.2  pgoyette             c2 -= 0x20;
    359  1.1.1.1.2.2  pgoyette         if (c1=='\0')
    360  1.1.1.1.2.2  pgoyette             return ((c2=='\0') ? 0 : -1);
    361  1.1.1.1.2.2  pgoyette         if (c2=='\0')
    362  1.1.1.1.2.2  pgoyette             return 1;
    363  1.1.1.1.2.2  pgoyette         if (c1<c2)
    364  1.1.1.1.2.2  pgoyette             return -1;
    365  1.1.1.1.2.2  pgoyette         if (c1>c2)
    366  1.1.1.1.2.2  pgoyette             return 1;
    367  1.1.1.1.2.2  pgoyette     }
    368  1.1.1.1.2.2  pgoyette }
    369  1.1.1.1.2.2  pgoyette 
    370  1.1.1.1.2.2  pgoyette 
    371  1.1.1.1.2.2  pgoyette #ifdef  CASESENSITIVITYDEFAULT_NO
    372  1.1.1.1.2.2  pgoyette #define CASESENSITIVITYDEFAULTVALUE 2
    373  1.1.1.1.2.2  pgoyette #else
    374  1.1.1.1.2.2  pgoyette #define CASESENSITIVITYDEFAULTVALUE 1
    375  1.1.1.1.2.2  pgoyette #endif
    376  1.1.1.1.2.2  pgoyette 
    377  1.1.1.1.2.2  pgoyette #ifndef STRCMPCASENOSENTIVEFUNCTION
    378  1.1.1.1.2.2  pgoyette #define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
    379  1.1.1.1.2.2  pgoyette #endif
    380  1.1.1.1.2.2  pgoyette 
    381  1.1.1.1.2.2  pgoyette /*
    382  1.1.1.1.2.2  pgoyette    Compare two filename (fileName1,fileName2).
    383  1.1.1.1.2.2  pgoyette    If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
    384  1.1.1.1.2.2  pgoyette    If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
    385  1.1.1.1.2.2  pgoyette                                                                 or strcasecmp)
    386  1.1.1.1.2.2  pgoyette    If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
    387  1.1.1.1.2.2  pgoyette         (like 1 on Unix, 2 on Windows)
    388  1.1.1.1.2.2  pgoyette 
    389  1.1.1.1.2.2  pgoyette */
    390  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzStringFileNameCompare (const char*  fileName1,
    391  1.1.1.1.2.2  pgoyette                                                  const char*  fileName2,
    392  1.1.1.1.2.2  pgoyette                                                  int iCaseSensitivity)
    393  1.1.1.1.2.2  pgoyette 
    394  1.1.1.1.2.2  pgoyette {
    395  1.1.1.1.2.2  pgoyette     if (iCaseSensitivity==0)
    396  1.1.1.1.2.2  pgoyette         iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
    397  1.1.1.1.2.2  pgoyette 
    398  1.1.1.1.2.2  pgoyette     if (iCaseSensitivity==1)
    399  1.1.1.1.2.2  pgoyette         return strcmp(fileName1,fileName2);
    400  1.1.1.1.2.2  pgoyette 
    401  1.1.1.1.2.2  pgoyette     return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
    402  1.1.1.1.2.2  pgoyette }
    403  1.1.1.1.2.2  pgoyette 
    404  1.1.1.1.2.2  pgoyette #ifndef BUFREADCOMMENT
    405  1.1.1.1.2.2  pgoyette #define BUFREADCOMMENT (0x400)
    406  1.1.1.1.2.2  pgoyette #endif
    407  1.1.1.1.2.2  pgoyette 
    408  1.1.1.1.2.2  pgoyette /*
    409  1.1.1.1.2.2  pgoyette   Locate the Central directory of a zipfile (at the end, just before
    410  1.1.1.1.2.2  pgoyette     the global comment)
    411  1.1.1.1.2.2  pgoyette */
    412  1.1.1.1.2.2  pgoyette local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
    413  1.1.1.1.2.2  pgoyette local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
    414  1.1.1.1.2.2  pgoyette {
    415  1.1.1.1.2.2  pgoyette     unsigned char* buf;
    416  1.1.1.1.2.2  pgoyette     ZPOS64_T uSizeFile;
    417  1.1.1.1.2.2  pgoyette     ZPOS64_T uBackRead;
    418  1.1.1.1.2.2  pgoyette     ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
    419  1.1.1.1.2.2  pgoyette     ZPOS64_T uPosFound=0;
    420  1.1.1.1.2.2  pgoyette 
    421  1.1.1.1.2.2  pgoyette     if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
    422  1.1.1.1.2.2  pgoyette         return 0;
    423  1.1.1.1.2.2  pgoyette 
    424  1.1.1.1.2.2  pgoyette 
    425  1.1.1.1.2.2  pgoyette     uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
    426  1.1.1.1.2.2  pgoyette 
    427  1.1.1.1.2.2  pgoyette     if (uMaxBack>uSizeFile)
    428  1.1.1.1.2.2  pgoyette         uMaxBack = uSizeFile;
    429  1.1.1.1.2.2  pgoyette 
    430  1.1.1.1.2.2  pgoyette     buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
    431  1.1.1.1.2.2  pgoyette     if (buf==NULL)
    432  1.1.1.1.2.2  pgoyette         return 0;
    433  1.1.1.1.2.2  pgoyette 
    434  1.1.1.1.2.2  pgoyette     uBackRead = 4;
    435  1.1.1.1.2.2  pgoyette     while (uBackRead<uMaxBack)
    436  1.1.1.1.2.2  pgoyette     {
    437  1.1.1.1.2.2  pgoyette         uLong uReadSize;
    438  1.1.1.1.2.2  pgoyette         ZPOS64_T uReadPos ;
    439  1.1.1.1.2.2  pgoyette         int i;
    440  1.1.1.1.2.2  pgoyette         if (uBackRead+BUFREADCOMMENT>uMaxBack)
    441  1.1.1.1.2.2  pgoyette             uBackRead = uMaxBack;
    442  1.1.1.1.2.2  pgoyette         else
    443  1.1.1.1.2.2  pgoyette             uBackRead+=BUFREADCOMMENT;
    444  1.1.1.1.2.2  pgoyette         uReadPos = uSizeFile-uBackRead ;
    445  1.1.1.1.2.2  pgoyette 
    446  1.1.1.1.2.2  pgoyette         uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
    447  1.1.1.1.2.2  pgoyette                      (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
    448  1.1.1.1.2.2  pgoyette         if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
    449  1.1.1.1.2.2  pgoyette             break;
    450  1.1.1.1.2.2  pgoyette 
    451  1.1.1.1.2.2  pgoyette         if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
    452  1.1.1.1.2.2  pgoyette             break;
    453  1.1.1.1.2.2  pgoyette 
    454  1.1.1.1.2.2  pgoyette         for (i=(int)uReadSize-3; (i--)>0;)
    455  1.1.1.1.2.2  pgoyette             if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
    456  1.1.1.1.2.2  pgoyette                 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
    457  1.1.1.1.2.2  pgoyette             {
    458  1.1.1.1.2.2  pgoyette                 uPosFound = uReadPos+i;
    459  1.1.1.1.2.2  pgoyette                 break;
    460  1.1.1.1.2.2  pgoyette             }
    461  1.1.1.1.2.2  pgoyette 
    462  1.1.1.1.2.2  pgoyette         if (uPosFound!=0)
    463  1.1.1.1.2.2  pgoyette             break;
    464  1.1.1.1.2.2  pgoyette     }
    465  1.1.1.1.2.2  pgoyette     TRYFREE(buf);
    466  1.1.1.1.2.2  pgoyette     return uPosFound;
    467  1.1.1.1.2.2  pgoyette }
    468  1.1.1.1.2.2  pgoyette 
    469  1.1.1.1.2.2  pgoyette 
    470  1.1.1.1.2.2  pgoyette /*
    471  1.1.1.1.2.2  pgoyette   Locate the Central directory 64 of a zipfile (at the end, just before
    472  1.1.1.1.2.2  pgoyette     the global comment)
    473  1.1.1.1.2.2  pgoyette */
    474  1.1.1.1.2.2  pgoyette local ZPOS64_T unz64local_SearchCentralDir64 OF((
    475  1.1.1.1.2.2  pgoyette     const zlib_filefunc64_32_def* pzlib_filefunc_def,
    476  1.1.1.1.2.2  pgoyette     voidpf filestream));
    477  1.1.1.1.2.2  pgoyette 
    478  1.1.1.1.2.2  pgoyette local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
    479  1.1.1.1.2.2  pgoyette                                       voidpf filestream)
    480  1.1.1.1.2.2  pgoyette {
    481  1.1.1.1.2.2  pgoyette     unsigned char* buf;
    482  1.1.1.1.2.2  pgoyette     ZPOS64_T uSizeFile;
    483  1.1.1.1.2.2  pgoyette     ZPOS64_T uBackRead;
    484  1.1.1.1.2.2  pgoyette     ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
    485  1.1.1.1.2.2  pgoyette     ZPOS64_T uPosFound=0;
    486  1.1.1.1.2.2  pgoyette     uLong uL;
    487  1.1.1.1.2.2  pgoyette                 ZPOS64_T relativeOffset;
    488  1.1.1.1.2.2  pgoyette 
    489  1.1.1.1.2.2  pgoyette     if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
    490  1.1.1.1.2.2  pgoyette         return 0;
    491  1.1.1.1.2.2  pgoyette 
    492  1.1.1.1.2.2  pgoyette 
    493  1.1.1.1.2.2  pgoyette     uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
    494  1.1.1.1.2.2  pgoyette 
    495  1.1.1.1.2.2  pgoyette     if (uMaxBack>uSizeFile)
    496  1.1.1.1.2.2  pgoyette         uMaxBack = uSizeFile;
    497  1.1.1.1.2.2  pgoyette 
    498  1.1.1.1.2.2  pgoyette     buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
    499  1.1.1.1.2.2  pgoyette     if (buf==NULL)
    500  1.1.1.1.2.2  pgoyette         return 0;
    501  1.1.1.1.2.2  pgoyette 
    502  1.1.1.1.2.2  pgoyette     uBackRead = 4;
    503  1.1.1.1.2.2  pgoyette     while (uBackRead<uMaxBack)
    504  1.1.1.1.2.2  pgoyette     {
    505  1.1.1.1.2.2  pgoyette         uLong uReadSize;
    506  1.1.1.1.2.2  pgoyette         ZPOS64_T uReadPos;
    507  1.1.1.1.2.2  pgoyette         int i;
    508  1.1.1.1.2.2  pgoyette         if (uBackRead+BUFREADCOMMENT>uMaxBack)
    509  1.1.1.1.2.2  pgoyette             uBackRead = uMaxBack;
    510  1.1.1.1.2.2  pgoyette         else
    511  1.1.1.1.2.2  pgoyette             uBackRead+=BUFREADCOMMENT;
    512  1.1.1.1.2.2  pgoyette         uReadPos = uSizeFile-uBackRead ;
    513  1.1.1.1.2.2  pgoyette 
    514  1.1.1.1.2.2  pgoyette         uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
    515  1.1.1.1.2.2  pgoyette                      (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
    516  1.1.1.1.2.2  pgoyette         if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
    517  1.1.1.1.2.2  pgoyette             break;
    518  1.1.1.1.2.2  pgoyette 
    519  1.1.1.1.2.2  pgoyette         if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
    520  1.1.1.1.2.2  pgoyette             break;
    521  1.1.1.1.2.2  pgoyette 
    522  1.1.1.1.2.2  pgoyette         for (i=(int)uReadSize-3; (i--)>0;)
    523  1.1.1.1.2.2  pgoyette             if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
    524  1.1.1.1.2.2  pgoyette                 ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
    525  1.1.1.1.2.2  pgoyette             {
    526  1.1.1.1.2.2  pgoyette                 uPosFound = uReadPos+i;
    527  1.1.1.1.2.2  pgoyette                 break;
    528  1.1.1.1.2.2  pgoyette             }
    529  1.1.1.1.2.2  pgoyette 
    530  1.1.1.1.2.2  pgoyette         if (uPosFound!=0)
    531  1.1.1.1.2.2  pgoyette             break;
    532  1.1.1.1.2.2  pgoyette     }
    533  1.1.1.1.2.2  pgoyette     TRYFREE(buf);
    534  1.1.1.1.2.2  pgoyette     if (uPosFound == 0)
    535  1.1.1.1.2.2  pgoyette         return 0;
    536  1.1.1.1.2.2  pgoyette 
    537  1.1.1.1.2.2  pgoyette     /* Zip64 end of central directory locator */
    538  1.1.1.1.2.2  pgoyette     if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
    539  1.1.1.1.2.2  pgoyette         return 0;
    540  1.1.1.1.2.2  pgoyette 
    541  1.1.1.1.2.2  pgoyette     /* the signature, already checked */
    542  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
    543  1.1.1.1.2.2  pgoyette         return 0;
    544  1.1.1.1.2.2  pgoyette 
    545  1.1.1.1.2.2  pgoyette     /* number of the disk with the start of the zip64 end of  central directory */
    546  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
    547  1.1.1.1.2.2  pgoyette         return 0;
    548  1.1.1.1.2.2  pgoyette     if (uL != 0)
    549  1.1.1.1.2.2  pgoyette         return 0;
    550  1.1.1.1.2.2  pgoyette 
    551  1.1.1.1.2.2  pgoyette     /* relative offset of the zip64 end of central directory record */
    552  1.1.1.1.2.2  pgoyette     if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
    553  1.1.1.1.2.2  pgoyette         return 0;
    554  1.1.1.1.2.2  pgoyette 
    555  1.1.1.1.2.2  pgoyette     /* total number of disks */
    556  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
    557  1.1.1.1.2.2  pgoyette         return 0;
    558  1.1.1.1.2.2  pgoyette     if (uL != 1)
    559  1.1.1.1.2.2  pgoyette         return 0;
    560  1.1.1.1.2.2  pgoyette 
    561  1.1.1.1.2.2  pgoyette     /* Goto end of central directory record */
    562  1.1.1.1.2.2  pgoyette     if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
    563  1.1.1.1.2.2  pgoyette         return 0;
    564  1.1.1.1.2.2  pgoyette 
    565  1.1.1.1.2.2  pgoyette      /* the signature */
    566  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
    567  1.1.1.1.2.2  pgoyette         return 0;
    568  1.1.1.1.2.2  pgoyette 
    569  1.1.1.1.2.2  pgoyette     if (uL != 0x06064b50)
    570  1.1.1.1.2.2  pgoyette         return 0;
    571  1.1.1.1.2.2  pgoyette 
    572  1.1.1.1.2.2  pgoyette     return relativeOffset;
    573  1.1.1.1.2.2  pgoyette }
    574  1.1.1.1.2.2  pgoyette 
    575  1.1.1.1.2.2  pgoyette /*
    576  1.1.1.1.2.2  pgoyette   Open a Zip file. path contain the full pathname (by example,
    577  1.1.1.1.2.2  pgoyette      on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
    578  1.1.1.1.2.2  pgoyette      "zlib/zlib114.zip".
    579  1.1.1.1.2.2  pgoyette      If the zipfile cannot be opened (file doesn't exist or in not valid), the
    580  1.1.1.1.2.2  pgoyette        return value is NULL.
    581  1.1.1.1.2.2  pgoyette      Else, the return value is a unzFile Handle, usable with other function
    582  1.1.1.1.2.2  pgoyette        of this unzip package.
    583  1.1.1.1.2.2  pgoyette */
    584  1.1.1.1.2.2  pgoyette local unzFile unzOpenInternal (const void *path,
    585  1.1.1.1.2.2  pgoyette                                zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
    586  1.1.1.1.2.2  pgoyette                                int is64bitOpenFunction)
    587  1.1.1.1.2.2  pgoyette {
    588  1.1.1.1.2.2  pgoyette     unz64_s us;
    589  1.1.1.1.2.2  pgoyette     unz64_s *s;
    590  1.1.1.1.2.2  pgoyette     ZPOS64_T central_pos;
    591  1.1.1.1.2.2  pgoyette     uLong   uL;
    592  1.1.1.1.2.2  pgoyette 
    593  1.1.1.1.2.2  pgoyette     uLong number_disk;          /* number of the current dist, used for
    594  1.1.1.1.2.2  pgoyette                                    spaning ZIP, unsupported, always 0*/
    595  1.1.1.1.2.2  pgoyette     uLong number_disk_with_CD;  /* number the the disk with central dir, used
    596  1.1.1.1.2.2  pgoyette                                    for spaning ZIP, unsupported, always 0*/
    597  1.1.1.1.2.2  pgoyette     ZPOS64_T number_entry_CD;      /* total number of entries in
    598  1.1.1.1.2.2  pgoyette                                    the central dir
    599  1.1.1.1.2.2  pgoyette                                    (same than number_entry on nospan) */
    600  1.1.1.1.2.2  pgoyette 
    601  1.1.1.1.2.2  pgoyette     int err=UNZ_OK;
    602  1.1.1.1.2.2  pgoyette 
    603  1.1.1.1.2.2  pgoyette     if (unz_copyright[0]!=' ')
    604  1.1.1.1.2.2  pgoyette         return NULL;
    605  1.1.1.1.2.2  pgoyette 
    606  1.1.1.1.2.2  pgoyette     us.z_filefunc.zseek32_file = NULL;
    607  1.1.1.1.2.2  pgoyette     us.z_filefunc.ztell32_file = NULL;
    608  1.1.1.1.2.2  pgoyette     if (pzlib_filefunc64_32_def==NULL)
    609  1.1.1.1.2.2  pgoyette         fill_fopen64_filefunc(&us.z_filefunc.zfile_func64);
    610  1.1.1.1.2.2  pgoyette     else
    611  1.1.1.1.2.2  pgoyette         us.z_filefunc = *pzlib_filefunc64_32_def;
    612  1.1.1.1.2.2  pgoyette     us.is64bitOpenFunction = is64bitOpenFunction;
    613  1.1.1.1.2.2  pgoyette 
    614  1.1.1.1.2.2  pgoyette 
    615  1.1.1.1.2.2  pgoyette 
    616  1.1.1.1.2.2  pgoyette     us.filestream = ZOPEN64(us.z_filefunc,
    617  1.1.1.1.2.2  pgoyette                                                  path,
    618  1.1.1.1.2.2  pgoyette                                                  ZLIB_FILEFUNC_MODE_READ |
    619  1.1.1.1.2.2  pgoyette                                                  ZLIB_FILEFUNC_MODE_EXISTING);
    620  1.1.1.1.2.2  pgoyette     if (us.filestream==NULL)
    621  1.1.1.1.2.2  pgoyette         return NULL;
    622  1.1.1.1.2.2  pgoyette 
    623  1.1.1.1.2.2  pgoyette     central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
    624  1.1.1.1.2.2  pgoyette     if (central_pos)
    625  1.1.1.1.2.2  pgoyette     {
    626  1.1.1.1.2.2  pgoyette         uLong uS;
    627  1.1.1.1.2.2  pgoyette         ZPOS64_T uL64;
    628  1.1.1.1.2.2  pgoyette 
    629  1.1.1.1.2.2  pgoyette         us.isZip64 = 1;
    630  1.1.1.1.2.2  pgoyette 
    631  1.1.1.1.2.2  pgoyette         if (ZSEEK64(us.z_filefunc, us.filestream,
    632  1.1.1.1.2.2  pgoyette                                       central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
    633  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    634  1.1.1.1.2.2  pgoyette 
    635  1.1.1.1.2.2  pgoyette         /* the signature, already checked */
    636  1.1.1.1.2.2  pgoyette         if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
    637  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    638  1.1.1.1.2.2  pgoyette 
    639  1.1.1.1.2.2  pgoyette         /* size of zip64 end of central directory record */
    640  1.1.1.1.2.2  pgoyette         if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
    641  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    642  1.1.1.1.2.2  pgoyette 
    643  1.1.1.1.2.2  pgoyette         /* version made by */
    644  1.1.1.1.2.2  pgoyette         if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
    645  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    646  1.1.1.1.2.2  pgoyette 
    647  1.1.1.1.2.2  pgoyette         /* version needed to extract */
    648  1.1.1.1.2.2  pgoyette         if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
    649  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    650  1.1.1.1.2.2  pgoyette 
    651  1.1.1.1.2.2  pgoyette         /* number of this disk */
    652  1.1.1.1.2.2  pgoyette         if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
    653  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    654  1.1.1.1.2.2  pgoyette 
    655  1.1.1.1.2.2  pgoyette         /* number of the disk with the start of the central directory */
    656  1.1.1.1.2.2  pgoyette         if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
    657  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    658  1.1.1.1.2.2  pgoyette 
    659  1.1.1.1.2.2  pgoyette         /* total number of entries in the central directory on this disk */
    660  1.1.1.1.2.2  pgoyette         if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
    661  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    662  1.1.1.1.2.2  pgoyette 
    663  1.1.1.1.2.2  pgoyette         /* total number of entries in the central directory */
    664  1.1.1.1.2.2  pgoyette         if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
    665  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    666  1.1.1.1.2.2  pgoyette 
    667  1.1.1.1.2.2  pgoyette         if ((number_entry_CD!=us.gi.number_entry) ||
    668  1.1.1.1.2.2  pgoyette             (number_disk_with_CD!=0) ||
    669  1.1.1.1.2.2  pgoyette             (number_disk!=0))
    670  1.1.1.1.2.2  pgoyette             err=UNZ_BADZIPFILE;
    671  1.1.1.1.2.2  pgoyette 
    672  1.1.1.1.2.2  pgoyette         /* size of the central directory */
    673  1.1.1.1.2.2  pgoyette         if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
    674  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    675  1.1.1.1.2.2  pgoyette 
    676  1.1.1.1.2.2  pgoyette         /* offset of start of central directory with respect to the
    677  1.1.1.1.2.2  pgoyette           starting disk number */
    678  1.1.1.1.2.2  pgoyette         if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
    679  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    680  1.1.1.1.2.2  pgoyette 
    681  1.1.1.1.2.2  pgoyette         us.gi.size_comment = 0;
    682  1.1.1.1.2.2  pgoyette     }
    683  1.1.1.1.2.2  pgoyette     else
    684  1.1.1.1.2.2  pgoyette     {
    685  1.1.1.1.2.2  pgoyette         central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
    686  1.1.1.1.2.2  pgoyette         if (central_pos==0)
    687  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    688  1.1.1.1.2.2  pgoyette 
    689  1.1.1.1.2.2  pgoyette         us.isZip64 = 0;
    690  1.1.1.1.2.2  pgoyette 
    691  1.1.1.1.2.2  pgoyette         if (ZSEEK64(us.z_filefunc, us.filestream,
    692  1.1.1.1.2.2  pgoyette                                         central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
    693  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    694  1.1.1.1.2.2  pgoyette 
    695  1.1.1.1.2.2  pgoyette         /* the signature, already checked */
    696  1.1.1.1.2.2  pgoyette         if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
    697  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    698  1.1.1.1.2.2  pgoyette 
    699  1.1.1.1.2.2  pgoyette         /* number of this disk */
    700  1.1.1.1.2.2  pgoyette         if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
    701  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    702  1.1.1.1.2.2  pgoyette 
    703  1.1.1.1.2.2  pgoyette         /* number of the disk with the start of the central directory */
    704  1.1.1.1.2.2  pgoyette         if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
    705  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    706  1.1.1.1.2.2  pgoyette 
    707  1.1.1.1.2.2  pgoyette         /* total number of entries in the central dir on this disk */
    708  1.1.1.1.2.2  pgoyette         if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
    709  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    710  1.1.1.1.2.2  pgoyette         us.gi.number_entry = uL;
    711  1.1.1.1.2.2  pgoyette 
    712  1.1.1.1.2.2  pgoyette         /* total number of entries in the central dir */
    713  1.1.1.1.2.2  pgoyette         if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
    714  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    715  1.1.1.1.2.2  pgoyette         number_entry_CD = uL;
    716  1.1.1.1.2.2  pgoyette 
    717  1.1.1.1.2.2  pgoyette         if ((number_entry_CD!=us.gi.number_entry) ||
    718  1.1.1.1.2.2  pgoyette             (number_disk_with_CD!=0) ||
    719  1.1.1.1.2.2  pgoyette             (number_disk!=0))
    720  1.1.1.1.2.2  pgoyette             err=UNZ_BADZIPFILE;
    721  1.1.1.1.2.2  pgoyette 
    722  1.1.1.1.2.2  pgoyette         /* size of the central directory */
    723  1.1.1.1.2.2  pgoyette         if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
    724  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    725  1.1.1.1.2.2  pgoyette         us.size_central_dir = uL;
    726  1.1.1.1.2.2  pgoyette 
    727  1.1.1.1.2.2  pgoyette         /* offset of start of central directory with respect to the
    728  1.1.1.1.2.2  pgoyette             starting disk number */
    729  1.1.1.1.2.2  pgoyette         if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
    730  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    731  1.1.1.1.2.2  pgoyette         us.offset_central_dir = uL;
    732  1.1.1.1.2.2  pgoyette 
    733  1.1.1.1.2.2  pgoyette         /* zipfile comment length */
    734  1.1.1.1.2.2  pgoyette         if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
    735  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    736  1.1.1.1.2.2  pgoyette     }
    737  1.1.1.1.2.2  pgoyette 
    738  1.1.1.1.2.2  pgoyette     if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
    739  1.1.1.1.2.2  pgoyette         (err==UNZ_OK))
    740  1.1.1.1.2.2  pgoyette         err=UNZ_BADZIPFILE;
    741  1.1.1.1.2.2  pgoyette 
    742  1.1.1.1.2.2  pgoyette     if (err!=UNZ_OK)
    743  1.1.1.1.2.2  pgoyette     {
    744  1.1.1.1.2.2  pgoyette         ZCLOSE64(us.z_filefunc, us.filestream);
    745  1.1.1.1.2.2  pgoyette         return NULL;
    746  1.1.1.1.2.2  pgoyette     }
    747  1.1.1.1.2.2  pgoyette 
    748  1.1.1.1.2.2  pgoyette     us.byte_before_the_zipfile = central_pos -
    749  1.1.1.1.2.2  pgoyette                             (us.offset_central_dir+us.size_central_dir);
    750  1.1.1.1.2.2  pgoyette     us.central_pos = central_pos;
    751  1.1.1.1.2.2  pgoyette     us.pfile_in_zip_read = NULL;
    752  1.1.1.1.2.2  pgoyette     us.encrypted = 0;
    753  1.1.1.1.2.2  pgoyette 
    754  1.1.1.1.2.2  pgoyette 
    755  1.1.1.1.2.2  pgoyette     s=(unz64_s*)ALLOC(sizeof(unz64_s));
    756  1.1.1.1.2.2  pgoyette     if( s != NULL)
    757  1.1.1.1.2.2  pgoyette     {
    758  1.1.1.1.2.2  pgoyette         *s=us;
    759  1.1.1.1.2.2  pgoyette         unzGoToFirstFile((unzFile)s);
    760  1.1.1.1.2.2  pgoyette     }
    761  1.1.1.1.2.2  pgoyette     return (unzFile)s;
    762  1.1.1.1.2.2  pgoyette }
    763  1.1.1.1.2.2  pgoyette 
    764  1.1.1.1.2.2  pgoyette 
    765  1.1.1.1.2.2  pgoyette extern unzFile ZEXPORT unzOpen2 (const char *path,
    766  1.1.1.1.2.2  pgoyette                                         zlib_filefunc_def* pzlib_filefunc32_def)
    767  1.1.1.1.2.2  pgoyette {
    768  1.1.1.1.2.2  pgoyette     if (pzlib_filefunc32_def != NULL)
    769  1.1.1.1.2.2  pgoyette     {
    770  1.1.1.1.2.2  pgoyette         zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
    771  1.1.1.1.2.2  pgoyette         fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
    772  1.1.1.1.2.2  pgoyette         return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
    773  1.1.1.1.2.2  pgoyette     }
    774  1.1.1.1.2.2  pgoyette     else
    775  1.1.1.1.2.2  pgoyette         return unzOpenInternal(path, NULL, 0);
    776  1.1.1.1.2.2  pgoyette }
    777  1.1.1.1.2.2  pgoyette 
    778  1.1.1.1.2.2  pgoyette extern unzFile ZEXPORT unzOpen2_64 (const void *path,
    779  1.1.1.1.2.2  pgoyette                                      zlib_filefunc64_def* pzlib_filefunc_def)
    780  1.1.1.1.2.2  pgoyette {
    781  1.1.1.1.2.2  pgoyette     if (pzlib_filefunc_def != NULL)
    782  1.1.1.1.2.2  pgoyette     {
    783  1.1.1.1.2.2  pgoyette         zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
    784  1.1.1.1.2.2  pgoyette         zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
    785  1.1.1.1.2.2  pgoyette         zlib_filefunc64_32_def_fill.ztell32_file = NULL;
    786  1.1.1.1.2.2  pgoyette         zlib_filefunc64_32_def_fill.zseek32_file = NULL;
    787  1.1.1.1.2.2  pgoyette         return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1);
    788  1.1.1.1.2.2  pgoyette     }
    789  1.1.1.1.2.2  pgoyette     else
    790  1.1.1.1.2.2  pgoyette         return unzOpenInternal(path, NULL, 1);
    791  1.1.1.1.2.2  pgoyette }
    792  1.1.1.1.2.2  pgoyette 
    793  1.1.1.1.2.2  pgoyette extern unzFile ZEXPORT unzOpen (const char *path)
    794  1.1.1.1.2.2  pgoyette {
    795  1.1.1.1.2.2  pgoyette     return unzOpenInternal(path, NULL, 0);
    796  1.1.1.1.2.2  pgoyette }
    797  1.1.1.1.2.2  pgoyette 
    798  1.1.1.1.2.2  pgoyette extern unzFile ZEXPORT unzOpen64 (const void *path)
    799  1.1.1.1.2.2  pgoyette {
    800  1.1.1.1.2.2  pgoyette     return unzOpenInternal(path, NULL, 1);
    801  1.1.1.1.2.2  pgoyette }
    802  1.1.1.1.2.2  pgoyette 
    803  1.1.1.1.2.2  pgoyette /*
    804  1.1.1.1.2.2  pgoyette   Close a ZipFile opened with unzipOpen.
    805  1.1.1.1.2.2  pgoyette   If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
    806  1.1.1.1.2.2  pgoyette     these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
    807  1.1.1.1.2.2  pgoyette   return UNZ_OK if there is no problem. */
    808  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzClose (unzFile file)
    809  1.1.1.1.2.2  pgoyette {
    810  1.1.1.1.2.2  pgoyette     unz64_s* s;
    811  1.1.1.1.2.2  pgoyette     if (file==NULL)
    812  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
    813  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
    814  1.1.1.1.2.2  pgoyette 
    815  1.1.1.1.2.2  pgoyette     if (s->pfile_in_zip_read!=NULL)
    816  1.1.1.1.2.2  pgoyette         unzCloseCurrentFile(file);
    817  1.1.1.1.2.2  pgoyette 
    818  1.1.1.1.2.2  pgoyette     ZCLOSE64(s->z_filefunc, s->filestream);
    819  1.1.1.1.2.2  pgoyette     TRYFREE(s);
    820  1.1.1.1.2.2  pgoyette     return UNZ_OK;
    821  1.1.1.1.2.2  pgoyette }
    822  1.1.1.1.2.2  pgoyette 
    823  1.1.1.1.2.2  pgoyette 
    824  1.1.1.1.2.2  pgoyette /*
    825  1.1.1.1.2.2  pgoyette   Write info about the ZipFile in the *pglobal_info structure.
    826  1.1.1.1.2.2  pgoyette   No preparation of the structure is needed
    827  1.1.1.1.2.2  pgoyette   return UNZ_OK if there is no problem. */
    828  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
    829  1.1.1.1.2.2  pgoyette {
    830  1.1.1.1.2.2  pgoyette     unz64_s* s;
    831  1.1.1.1.2.2  pgoyette     if (file==NULL)
    832  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
    833  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
    834  1.1.1.1.2.2  pgoyette     *pglobal_info=s->gi;
    835  1.1.1.1.2.2  pgoyette     return UNZ_OK;
    836  1.1.1.1.2.2  pgoyette }
    837  1.1.1.1.2.2  pgoyette 
    838  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
    839  1.1.1.1.2.2  pgoyette {
    840  1.1.1.1.2.2  pgoyette     unz64_s* s;
    841  1.1.1.1.2.2  pgoyette     if (file==NULL)
    842  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
    843  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
    844  1.1.1.1.2.2  pgoyette     /* to do : check if number_entry is not truncated */
    845  1.1.1.1.2.2  pgoyette     pglobal_info32->number_entry = (uLong)s->gi.number_entry;
    846  1.1.1.1.2.2  pgoyette     pglobal_info32->size_comment = s->gi.size_comment;
    847  1.1.1.1.2.2  pgoyette     return UNZ_OK;
    848  1.1.1.1.2.2  pgoyette }
    849  1.1.1.1.2.2  pgoyette /*
    850  1.1.1.1.2.2  pgoyette    Translate date/time from Dos format to tm_unz (readable more easilty)
    851  1.1.1.1.2.2  pgoyette */
    852  1.1.1.1.2.2  pgoyette local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
    853  1.1.1.1.2.2  pgoyette {
    854  1.1.1.1.2.2  pgoyette     ZPOS64_T uDate;
    855  1.1.1.1.2.2  pgoyette     uDate = (ZPOS64_T)(ulDosDate>>16);
    856  1.1.1.1.2.2  pgoyette     ptm->tm_mday = (uInt)(uDate&0x1f) ;
    857  1.1.1.1.2.2  pgoyette     ptm->tm_mon =  (uInt)((((uDate)&0x1E0)/0x20)-1) ;
    858  1.1.1.1.2.2  pgoyette     ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
    859  1.1.1.1.2.2  pgoyette 
    860  1.1.1.1.2.2  pgoyette     ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
    861  1.1.1.1.2.2  pgoyette     ptm->tm_min =  (uInt) ((ulDosDate&0x7E0)/0x20) ;
    862  1.1.1.1.2.2  pgoyette     ptm->tm_sec =  (uInt) (2*(ulDosDate&0x1f)) ;
    863  1.1.1.1.2.2  pgoyette }
    864  1.1.1.1.2.2  pgoyette 
    865  1.1.1.1.2.2  pgoyette /*
    866  1.1.1.1.2.2  pgoyette   Get Info about the current file in the zipfile, with internal only info
    867  1.1.1.1.2.2  pgoyette */
    868  1.1.1.1.2.2  pgoyette local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
    869  1.1.1.1.2.2  pgoyette                                                   unz_file_info64 *pfile_info,
    870  1.1.1.1.2.2  pgoyette                                                   unz_file_info64_internal
    871  1.1.1.1.2.2  pgoyette                                                   *pfile_info_internal,
    872  1.1.1.1.2.2  pgoyette                                                   char *szFileName,
    873  1.1.1.1.2.2  pgoyette                                                   uLong fileNameBufferSize,
    874  1.1.1.1.2.2  pgoyette                                                   void *extraField,
    875  1.1.1.1.2.2  pgoyette                                                   uLong extraFieldBufferSize,
    876  1.1.1.1.2.2  pgoyette                                                   char *szComment,
    877  1.1.1.1.2.2  pgoyette                                                   uLong commentBufferSize));
    878  1.1.1.1.2.2  pgoyette 
    879  1.1.1.1.2.2  pgoyette local int unz64local_GetCurrentFileInfoInternal (unzFile file,
    880  1.1.1.1.2.2  pgoyette                                                   unz_file_info64 *pfile_info,
    881  1.1.1.1.2.2  pgoyette                                                   unz_file_info64_internal
    882  1.1.1.1.2.2  pgoyette                                                   *pfile_info_internal,
    883  1.1.1.1.2.2  pgoyette                                                   char *szFileName,
    884  1.1.1.1.2.2  pgoyette                                                   uLong fileNameBufferSize,
    885  1.1.1.1.2.2  pgoyette                                                   void *extraField,
    886  1.1.1.1.2.2  pgoyette                                                   uLong extraFieldBufferSize,
    887  1.1.1.1.2.2  pgoyette                                                   char *szComment,
    888  1.1.1.1.2.2  pgoyette                                                   uLong commentBufferSize)
    889  1.1.1.1.2.2  pgoyette {
    890  1.1.1.1.2.2  pgoyette     unz64_s* s;
    891  1.1.1.1.2.2  pgoyette     unz_file_info64 file_info;
    892  1.1.1.1.2.2  pgoyette     unz_file_info64_internal file_info_internal;
    893  1.1.1.1.2.2  pgoyette     int err=UNZ_OK;
    894  1.1.1.1.2.2  pgoyette     uLong uMagic;
    895  1.1.1.1.2.2  pgoyette     long lSeek=0;
    896  1.1.1.1.2.2  pgoyette     uLong uL;
    897  1.1.1.1.2.2  pgoyette 
    898  1.1.1.1.2.2  pgoyette     if (file==NULL)
    899  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
    900  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
    901  1.1.1.1.2.2  pgoyette     if (ZSEEK64(s->z_filefunc, s->filestream,
    902  1.1.1.1.2.2  pgoyette               s->pos_in_central_dir+s->byte_before_the_zipfile,
    903  1.1.1.1.2.2  pgoyette               ZLIB_FILEFUNC_SEEK_SET)!=0)
    904  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    905  1.1.1.1.2.2  pgoyette 
    906  1.1.1.1.2.2  pgoyette 
    907  1.1.1.1.2.2  pgoyette     /* we check the magic */
    908  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
    909  1.1.1.1.2.2  pgoyette     {
    910  1.1.1.1.2.2  pgoyette         if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
    911  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
    912  1.1.1.1.2.2  pgoyette         else if (uMagic!=0x02014b50)
    913  1.1.1.1.2.2  pgoyette             err=UNZ_BADZIPFILE;
    914  1.1.1.1.2.2  pgoyette     }
    915  1.1.1.1.2.2  pgoyette 
    916  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
    917  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    918  1.1.1.1.2.2  pgoyette 
    919  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
    920  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    921  1.1.1.1.2.2  pgoyette 
    922  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
    923  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    924  1.1.1.1.2.2  pgoyette 
    925  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
    926  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    927  1.1.1.1.2.2  pgoyette 
    928  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
    929  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    930  1.1.1.1.2.2  pgoyette 
    931  1.1.1.1.2.2  pgoyette     unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
    932  1.1.1.1.2.2  pgoyette 
    933  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
    934  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    935  1.1.1.1.2.2  pgoyette 
    936  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
    937  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    938  1.1.1.1.2.2  pgoyette     file_info.compressed_size = uL;
    939  1.1.1.1.2.2  pgoyette 
    940  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
    941  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    942  1.1.1.1.2.2  pgoyette     file_info.uncompressed_size = uL;
    943  1.1.1.1.2.2  pgoyette 
    944  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
    945  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    946  1.1.1.1.2.2  pgoyette 
    947  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
    948  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    949  1.1.1.1.2.2  pgoyette 
    950  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
    951  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    952  1.1.1.1.2.2  pgoyette 
    953  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
    954  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    955  1.1.1.1.2.2  pgoyette 
    956  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
    957  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    958  1.1.1.1.2.2  pgoyette 
    959  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
    960  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    961  1.1.1.1.2.2  pgoyette 
    962  1.1.1.1.2.2  pgoyette                 // relative offset of local header
    963  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
    964  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
    965  1.1.1.1.2.2  pgoyette     file_info_internal.offset_curfile = uL;
    966  1.1.1.1.2.2  pgoyette 
    967  1.1.1.1.2.2  pgoyette     lSeek+=file_info.size_filename;
    968  1.1.1.1.2.2  pgoyette     if ((err==UNZ_OK) && (szFileName!=NULL))
    969  1.1.1.1.2.2  pgoyette     {
    970  1.1.1.1.2.2  pgoyette         uLong uSizeRead ;
    971  1.1.1.1.2.2  pgoyette         if (file_info.size_filename<fileNameBufferSize)
    972  1.1.1.1.2.2  pgoyette         {
    973  1.1.1.1.2.2  pgoyette             *(szFileName+file_info.size_filename)='\0';
    974  1.1.1.1.2.2  pgoyette             uSizeRead = file_info.size_filename;
    975  1.1.1.1.2.2  pgoyette         }
    976  1.1.1.1.2.2  pgoyette         else
    977  1.1.1.1.2.2  pgoyette             uSizeRead = fileNameBufferSize;
    978  1.1.1.1.2.2  pgoyette 
    979  1.1.1.1.2.2  pgoyette         if ((file_info.size_filename>0) && (fileNameBufferSize>0))
    980  1.1.1.1.2.2  pgoyette             if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
    981  1.1.1.1.2.2  pgoyette                 err=UNZ_ERRNO;
    982  1.1.1.1.2.2  pgoyette         lSeek -= uSizeRead;
    983  1.1.1.1.2.2  pgoyette     }
    984  1.1.1.1.2.2  pgoyette 
    985  1.1.1.1.2.2  pgoyette     // Read extrafield
    986  1.1.1.1.2.2  pgoyette     if ((err==UNZ_OK) && (extraField!=NULL))
    987  1.1.1.1.2.2  pgoyette     {
    988  1.1.1.1.2.2  pgoyette         ZPOS64_T uSizeRead ;
    989  1.1.1.1.2.2  pgoyette         if (file_info.size_file_extra<extraFieldBufferSize)
    990  1.1.1.1.2.2  pgoyette             uSizeRead = file_info.size_file_extra;
    991  1.1.1.1.2.2  pgoyette         else
    992  1.1.1.1.2.2  pgoyette             uSizeRead = extraFieldBufferSize;
    993  1.1.1.1.2.2  pgoyette 
    994  1.1.1.1.2.2  pgoyette         if (lSeek!=0)
    995  1.1.1.1.2.2  pgoyette         {
    996  1.1.1.1.2.2  pgoyette             if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
    997  1.1.1.1.2.2  pgoyette                 lSeek=0;
    998  1.1.1.1.2.2  pgoyette             else
    999  1.1.1.1.2.2  pgoyette                 err=UNZ_ERRNO;
   1000  1.1.1.1.2.2  pgoyette         }
   1001  1.1.1.1.2.2  pgoyette 
   1002  1.1.1.1.2.2  pgoyette         if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
   1003  1.1.1.1.2.2  pgoyette             if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
   1004  1.1.1.1.2.2  pgoyette                 err=UNZ_ERRNO;
   1005  1.1.1.1.2.2  pgoyette 
   1006  1.1.1.1.2.2  pgoyette         lSeek += file_info.size_file_extra - (uLong)uSizeRead;
   1007  1.1.1.1.2.2  pgoyette     }
   1008  1.1.1.1.2.2  pgoyette     else
   1009  1.1.1.1.2.2  pgoyette         lSeek += file_info.size_file_extra;
   1010  1.1.1.1.2.2  pgoyette 
   1011  1.1.1.1.2.2  pgoyette 
   1012  1.1.1.1.2.2  pgoyette     if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
   1013  1.1.1.1.2.2  pgoyette     {
   1014  1.1.1.1.2.2  pgoyette                                 uLong acc = 0;
   1015  1.1.1.1.2.2  pgoyette 
   1016  1.1.1.1.2.2  pgoyette         // since lSeek now points to after the extra field we need to move back
   1017  1.1.1.1.2.2  pgoyette         lSeek -= file_info.size_file_extra;
   1018  1.1.1.1.2.2  pgoyette 
   1019  1.1.1.1.2.2  pgoyette         if (lSeek!=0)
   1020  1.1.1.1.2.2  pgoyette         {
   1021  1.1.1.1.2.2  pgoyette             if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
   1022  1.1.1.1.2.2  pgoyette                 lSeek=0;
   1023  1.1.1.1.2.2  pgoyette             else
   1024  1.1.1.1.2.2  pgoyette                 err=UNZ_ERRNO;
   1025  1.1.1.1.2.2  pgoyette         }
   1026  1.1.1.1.2.2  pgoyette 
   1027  1.1.1.1.2.2  pgoyette         while(acc < file_info.size_file_extra)
   1028  1.1.1.1.2.2  pgoyette         {
   1029  1.1.1.1.2.2  pgoyette             uLong headerId;
   1030  1.1.1.1.2.2  pgoyette                                                 uLong dataSize;
   1031  1.1.1.1.2.2  pgoyette 
   1032  1.1.1.1.2.2  pgoyette             if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
   1033  1.1.1.1.2.2  pgoyette                 err=UNZ_ERRNO;
   1034  1.1.1.1.2.2  pgoyette 
   1035  1.1.1.1.2.2  pgoyette             if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
   1036  1.1.1.1.2.2  pgoyette                 err=UNZ_ERRNO;
   1037  1.1.1.1.2.2  pgoyette 
   1038  1.1.1.1.2.2  pgoyette             /* ZIP64 extra fields */
   1039  1.1.1.1.2.2  pgoyette             if (headerId == 0x0001)
   1040  1.1.1.1.2.2  pgoyette             {
   1041  1.1.1.1.2.2  pgoyette                                                         uLong uL;
   1042  1.1.1.1.2.2  pgoyette 
   1043  1.1.1.1.2.2  pgoyette                                                                 if(file_info.uncompressed_size == MAXU32)
   1044  1.1.1.1.2.2  pgoyette                                                                 {
   1045  1.1.1.1.2.2  pgoyette                                                                         if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
   1046  1.1.1.1.2.2  pgoyette                                                                                         err=UNZ_ERRNO;
   1047  1.1.1.1.2.2  pgoyette                                                                 }
   1048  1.1.1.1.2.2  pgoyette 
   1049  1.1.1.1.2.2  pgoyette                                                                 if(file_info.compressed_size == MAXU32)
   1050  1.1.1.1.2.2  pgoyette                                                                 {
   1051  1.1.1.1.2.2  pgoyette                                                                         if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
   1052  1.1.1.1.2.2  pgoyette                                                                                   err=UNZ_ERRNO;
   1053  1.1.1.1.2.2  pgoyette                                                                 }
   1054  1.1.1.1.2.2  pgoyette 
   1055  1.1.1.1.2.2  pgoyette                                                                 if(file_info_internal.offset_curfile == MAXU32)
   1056  1.1.1.1.2.2  pgoyette                                                                 {
   1057  1.1.1.1.2.2  pgoyette                                                                         /* Relative Header offset */
   1058  1.1.1.1.2.2  pgoyette                                                                         if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
   1059  1.1.1.1.2.2  pgoyette                                                                                 err=UNZ_ERRNO;
   1060  1.1.1.1.2.2  pgoyette                                                                 }
   1061  1.1.1.1.2.2  pgoyette 
   1062  1.1.1.1.2.2  pgoyette                                                                 if(file_info.disk_num_start == MAXU32)
   1063  1.1.1.1.2.2  pgoyette                                                                 {
   1064  1.1.1.1.2.2  pgoyette                                                                         /* Disk Start Number */
   1065  1.1.1.1.2.2  pgoyette                                                                         if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
   1066  1.1.1.1.2.2  pgoyette                                                                                 err=UNZ_ERRNO;
   1067  1.1.1.1.2.2  pgoyette                                                                 }
   1068  1.1.1.1.2.2  pgoyette 
   1069  1.1.1.1.2.2  pgoyette             }
   1070  1.1.1.1.2.2  pgoyette             else
   1071  1.1.1.1.2.2  pgoyette             {
   1072  1.1.1.1.2.2  pgoyette                 if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
   1073  1.1.1.1.2.2  pgoyette                     err=UNZ_ERRNO;
   1074  1.1.1.1.2.2  pgoyette             }
   1075  1.1.1.1.2.2  pgoyette 
   1076  1.1.1.1.2.2  pgoyette             acc += 2 + 2 + dataSize;
   1077  1.1.1.1.2.2  pgoyette         }
   1078  1.1.1.1.2.2  pgoyette     }
   1079  1.1.1.1.2.2  pgoyette 
   1080  1.1.1.1.2.2  pgoyette     if ((err==UNZ_OK) && (szComment!=NULL))
   1081  1.1.1.1.2.2  pgoyette     {
   1082  1.1.1.1.2.2  pgoyette         uLong uSizeRead ;
   1083  1.1.1.1.2.2  pgoyette         if (file_info.size_file_comment<commentBufferSize)
   1084  1.1.1.1.2.2  pgoyette         {
   1085  1.1.1.1.2.2  pgoyette             *(szComment+file_info.size_file_comment)='\0';
   1086  1.1.1.1.2.2  pgoyette             uSizeRead = file_info.size_file_comment;
   1087  1.1.1.1.2.2  pgoyette         }
   1088  1.1.1.1.2.2  pgoyette         else
   1089  1.1.1.1.2.2  pgoyette             uSizeRead = commentBufferSize;
   1090  1.1.1.1.2.2  pgoyette 
   1091  1.1.1.1.2.2  pgoyette         if (lSeek!=0)
   1092  1.1.1.1.2.2  pgoyette         {
   1093  1.1.1.1.2.2  pgoyette             if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
   1094  1.1.1.1.2.2  pgoyette                 lSeek=0;
   1095  1.1.1.1.2.2  pgoyette             else
   1096  1.1.1.1.2.2  pgoyette                 err=UNZ_ERRNO;
   1097  1.1.1.1.2.2  pgoyette         }
   1098  1.1.1.1.2.2  pgoyette 
   1099  1.1.1.1.2.2  pgoyette         if ((file_info.size_file_comment>0) && (commentBufferSize>0))
   1100  1.1.1.1.2.2  pgoyette             if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
   1101  1.1.1.1.2.2  pgoyette                 err=UNZ_ERRNO;
   1102  1.1.1.1.2.2  pgoyette         lSeek+=file_info.size_file_comment - uSizeRead;
   1103  1.1.1.1.2.2  pgoyette     }
   1104  1.1.1.1.2.2  pgoyette     else
   1105  1.1.1.1.2.2  pgoyette         lSeek+=file_info.size_file_comment;
   1106  1.1.1.1.2.2  pgoyette 
   1107  1.1.1.1.2.2  pgoyette 
   1108  1.1.1.1.2.2  pgoyette     if ((err==UNZ_OK) && (pfile_info!=NULL))
   1109  1.1.1.1.2.2  pgoyette         *pfile_info=file_info;
   1110  1.1.1.1.2.2  pgoyette 
   1111  1.1.1.1.2.2  pgoyette     if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
   1112  1.1.1.1.2.2  pgoyette         *pfile_info_internal=file_info_internal;
   1113  1.1.1.1.2.2  pgoyette 
   1114  1.1.1.1.2.2  pgoyette     return err;
   1115  1.1.1.1.2.2  pgoyette }
   1116  1.1.1.1.2.2  pgoyette 
   1117  1.1.1.1.2.2  pgoyette 
   1118  1.1.1.1.2.2  pgoyette 
   1119  1.1.1.1.2.2  pgoyette /*
   1120  1.1.1.1.2.2  pgoyette   Write info about the ZipFile in the *pglobal_info structure.
   1121  1.1.1.1.2.2  pgoyette   No preparation of the structure is needed
   1122  1.1.1.1.2.2  pgoyette   return UNZ_OK if there is no problem.
   1123  1.1.1.1.2.2  pgoyette */
   1124  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
   1125  1.1.1.1.2.2  pgoyette                                           unz_file_info64 * pfile_info,
   1126  1.1.1.1.2.2  pgoyette                                           char * szFileName, uLong fileNameBufferSize,
   1127  1.1.1.1.2.2  pgoyette                                           void *extraField, uLong extraFieldBufferSize,
   1128  1.1.1.1.2.2  pgoyette                                           char* szComment,  uLong commentBufferSize)
   1129  1.1.1.1.2.2  pgoyette {
   1130  1.1.1.1.2.2  pgoyette     return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
   1131  1.1.1.1.2.2  pgoyette                                                 szFileName,fileNameBufferSize,
   1132  1.1.1.1.2.2  pgoyette                                                 extraField,extraFieldBufferSize,
   1133  1.1.1.1.2.2  pgoyette                                                 szComment,commentBufferSize);
   1134  1.1.1.1.2.2  pgoyette }
   1135  1.1.1.1.2.2  pgoyette 
   1136  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
   1137  1.1.1.1.2.2  pgoyette                                           unz_file_info * pfile_info,
   1138  1.1.1.1.2.2  pgoyette                                           char * szFileName, uLong fileNameBufferSize,
   1139  1.1.1.1.2.2  pgoyette                                           void *extraField, uLong extraFieldBufferSize,
   1140  1.1.1.1.2.2  pgoyette                                           char* szComment,  uLong commentBufferSize)
   1141  1.1.1.1.2.2  pgoyette {
   1142  1.1.1.1.2.2  pgoyette     int err;
   1143  1.1.1.1.2.2  pgoyette     unz_file_info64 file_info64;
   1144  1.1.1.1.2.2  pgoyette     err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
   1145  1.1.1.1.2.2  pgoyette                                                 szFileName,fileNameBufferSize,
   1146  1.1.1.1.2.2  pgoyette                                                 extraField,extraFieldBufferSize,
   1147  1.1.1.1.2.2  pgoyette                                                 szComment,commentBufferSize);
   1148  1.1.1.1.2.2  pgoyette     if ((err==UNZ_OK) && (pfile_info != NULL))
   1149  1.1.1.1.2.2  pgoyette     {
   1150  1.1.1.1.2.2  pgoyette         pfile_info->version = file_info64.version;
   1151  1.1.1.1.2.2  pgoyette         pfile_info->version_needed = file_info64.version_needed;
   1152  1.1.1.1.2.2  pgoyette         pfile_info->flag = file_info64.flag;
   1153  1.1.1.1.2.2  pgoyette         pfile_info->compression_method = file_info64.compression_method;
   1154  1.1.1.1.2.2  pgoyette         pfile_info->dosDate = file_info64.dosDate;
   1155  1.1.1.1.2.2  pgoyette         pfile_info->crc = file_info64.crc;
   1156  1.1.1.1.2.2  pgoyette 
   1157  1.1.1.1.2.2  pgoyette         pfile_info->size_filename = file_info64.size_filename;
   1158  1.1.1.1.2.2  pgoyette         pfile_info->size_file_extra = file_info64.size_file_extra;
   1159  1.1.1.1.2.2  pgoyette         pfile_info->size_file_comment = file_info64.size_file_comment;
   1160  1.1.1.1.2.2  pgoyette 
   1161  1.1.1.1.2.2  pgoyette         pfile_info->disk_num_start = file_info64.disk_num_start;
   1162  1.1.1.1.2.2  pgoyette         pfile_info->internal_fa = file_info64.internal_fa;
   1163  1.1.1.1.2.2  pgoyette         pfile_info->external_fa = file_info64.external_fa;
   1164  1.1.1.1.2.2  pgoyette 
   1165  1.1.1.1.2.2  pgoyette         pfile_info->tmu_date = file_info64.tmu_date,
   1166  1.1.1.1.2.2  pgoyette 
   1167  1.1.1.1.2.2  pgoyette 
   1168  1.1.1.1.2.2  pgoyette         pfile_info->compressed_size = (uLong)file_info64.compressed_size;
   1169  1.1.1.1.2.2  pgoyette         pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
   1170  1.1.1.1.2.2  pgoyette 
   1171  1.1.1.1.2.2  pgoyette     }
   1172  1.1.1.1.2.2  pgoyette     return err;
   1173  1.1.1.1.2.2  pgoyette }
   1174  1.1.1.1.2.2  pgoyette /*
   1175  1.1.1.1.2.2  pgoyette   Set the current file of the zipfile to the first file.
   1176  1.1.1.1.2.2  pgoyette   return UNZ_OK if there is no problem
   1177  1.1.1.1.2.2  pgoyette */
   1178  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzGoToFirstFile (unzFile file)
   1179  1.1.1.1.2.2  pgoyette {
   1180  1.1.1.1.2.2  pgoyette     int err=UNZ_OK;
   1181  1.1.1.1.2.2  pgoyette     unz64_s* s;
   1182  1.1.1.1.2.2  pgoyette     if (file==NULL)
   1183  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1184  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   1185  1.1.1.1.2.2  pgoyette     s->pos_in_central_dir=s->offset_central_dir;
   1186  1.1.1.1.2.2  pgoyette     s->num_file=0;
   1187  1.1.1.1.2.2  pgoyette     err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
   1188  1.1.1.1.2.2  pgoyette                                              &s->cur_file_info_internal,
   1189  1.1.1.1.2.2  pgoyette                                              NULL,0,NULL,0,NULL,0);
   1190  1.1.1.1.2.2  pgoyette     s->current_file_ok = (err == UNZ_OK);
   1191  1.1.1.1.2.2  pgoyette     return err;
   1192  1.1.1.1.2.2  pgoyette }
   1193  1.1.1.1.2.2  pgoyette 
   1194  1.1.1.1.2.2  pgoyette /*
   1195  1.1.1.1.2.2  pgoyette   Set the current file of the zipfile to the next file.
   1196  1.1.1.1.2.2  pgoyette   return UNZ_OK if there is no problem
   1197  1.1.1.1.2.2  pgoyette   return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
   1198  1.1.1.1.2.2  pgoyette */
   1199  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzGoToNextFile (unzFile  file)
   1200  1.1.1.1.2.2  pgoyette {
   1201  1.1.1.1.2.2  pgoyette     unz64_s* s;
   1202  1.1.1.1.2.2  pgoyette     int err;
   1203  1.1.1.1.2.2  pgoyette 
   1204  1.1.1.1.2.2  pgoyette     if (file==NULL)
   1205  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1206  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   1207  1.1.1.1.2.2  pgoyette     if (!s->current_file_ok)
   1208  1.1.1.1.2.2  pgoyette         return UNZ_END_OF_LIST_OF_FILE;
   1209  1.1.1.1.2.2  pgoyette     if (s->gi.number_entry != 0xffff)    /* 2^16 files overflow hack */
   1210  1.1.1.1.2.2  pgoyette       if (s->num_file+1==s->gi.number_entry)
   1211  1.1.1.1.2.2  pgoyette         return UNZ_END_OF_LIST_OF_FILE;
   1212  1.1.1.1.2.2  pgoyette 
   1213  1.1.1.1.2.2  pgoyette     s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
   1214  1.1.1.1.2.2  pgoyette             s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
   1215  1.1.1.1.2.2  pgoyette     s->num_file++;
   1216  1.1.1.1.2.2  pgoyette     err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
   1217  1.1.1.1.2.2  pgoyette                                                &s->cur_file_info_internal,
   1218  1.1.1.1.2.2  pgoyette                                                NULL,0,NULL,0,NULL,0);
   1219  1.1.1.1.2.2  pgoyette     s->current_file_ok = (err == UNZ_OK);
   1220  1.1.1.1.2.2  pgoyette     return err;
   1221  1.1.1.1.2.2  pgoyette }
   1222  1.1.1.1.2.2  pgoyette 
   1223  1.1.1.1.2.2  pgoyette 
   1224  1.1.1.1.2.2  pgoyette /*
   1225  1.1.1.1.2.2  pgoyette   Try locate the file szFileName in the zipfile.
   1226  1.1.1.1.2.2  pgoyette   For the iCaseSensitivity signification, see unzipStringFileNameCompare
   1227  1.1.1.1.2.2  pgoyette 
   1228  1.1.1.1.2.2  pgoyette   return value :
   1229  1.1.1.1.2.2  pgoyette   UNZ_OK if the file is found. It becomes the current file.
   1230  1.1.1.1.2.2  pgoyette   UNZ_END_OF_LIST_OF_FILE if the file is not found
   1231  1.1.1.1.2.2  pgoyette */
   1232  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
   1233  1.1.1.1.2.2  pgoyette {
   1234  1.1.1.1.2.2  pgoyette     unz64_s* s;
   1235  1.1.1.1.2.2  pgoyette     int err;
   1236  1.1.1.1.2.2  pgoyette 
   1237  1.1.1.1.2.2  pgoyette     /* We remember the 'current' position in the file so that we can jump
   1238  1.1.1.1.2.2  pgoyette      * back there if we fail.
   1239  1.1.1.1.2.2  pgoyette      */
   1240  1.1.1.1.2.2  pgoyette     unz_file_info64 cur_file_infoSaved;
   1241  1.1.1.1.2.2  pgoyette     unz_file_info64_internal cur_file_info_internalSaved;
   1242  1.1.1.1.2.2  pgoyette     ZPOS64_T num_fileSaved;
   1243  1.1.1.1.2.2  pgoyette     ZPOS64_T pos_in_central_dirSaved;
   1244  1.1.1.1.2.2  pgoyette 
   1245  1.1.1.1.2.2  pgoyette 
   1246  1.1.1.1.2.2  pgoyette     if (file==NULL)
   1247  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1248  1.1.1.1.2.2  pgoyette 
   1249  1.1.1.1.2.2  pgoyette     if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
   1250  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1251  1.1.1.1.2.2  pgoyette 
   1252  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   1253  1.1.1.1.2.2  pgoyette     if (!s->current_file_ok)
   1254  1.1.1.1.2.2  pgoyette         return UNZ_END_OF_LIST_OF_FILE;
   1255  1.1.1.1.2.2  pgoyette 
   1256  1.1.1.1.2.2  pgoyette     /* Save the current state */
   1257  1.1.1.1.2.2  pgoyette     num_fileSaved = s->num_file;
   1258  1.1.1.1.2.2  pgoyette     pos_in_central_dirSaved = s->pos_in_central_dir;
   1259  1.1.1.1.2.2  pgoyette     cur_file_infoSaved = s->cur_file_info;
   1260  1.1.1.1.2.2  pgoyette     cur_file_info_internalSaved = s->cur_file_info_internal;
   1261  1.1.1.1.2.2  pgoyette 
   1262  1.1.1.1.2.2  pgoyette     err = unzGoToFirstFile(file);
   1263  1.1.1.1.2.2  pgoyette 
   1264  1.1.1.1.2.2  pgoyette     while (err == UNZ_OK)
   1265  1.1.1.1.2.2  pgoyette     {
   1266  1.1.1.1.2.2  pgoyette         char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
   1267  1.1.1.1.2.2  pgoyette         err = unzGetCurrentFileInfo64(file,NULL,
   1268  1.1.1.1.2.2  pgoyette                                     szCurrentFileName,sizeof(szCurrentFileName)-1,
   1269  1.1.1.1.2.2  pgoyette                                     NULL,0,NULL,0);
   1270  1.1.1.1.2.2  pgoyette         if (err == UNZ_OK)
   1271  1.1.1.1.2.2  pgoyette         {
   1272  1.1.1.1.2.2  pgoyette             if (unzStringFileNameCompare(szCurrentFileName,
   1273  1.1.1.1.2.2  pgoyette                                             szFileName,iCaseSensitivity)==0)
   1274  1.1.1.1.2.2  pgoyette                 return UNZ_OK;
   1275  1.1.1.1.2.2  pgoyette             err = unzGoToNextFile(file);
   1276  1.1.1.1.2.2  pgoyette         }
   1277  1.1.1.1.2.2  pgoyette     }
   1278  1.1.1.1.2.2  pgoyette 
   1279  1.1.1.1.2.2  pgoyette     /* We failed, so restore the state of the 'current file' to where we
   1280  1.1.1.1.2.2  pgoyette      * were.
   1281  1.1.1.1.2.2  pgoyette      */
   1282  1.1.1.1.2.2  pgoyette     s->num_file = num_fileSaved ;
   1283  1.1.1.1.2.2  pgoyette     s->pos_in_central_dir = pos_in_central_dirSaved ;
   1284  1.1.1.1.2.2  pgoyette     s->cur_file_info = cur_file_infoSaved;
   1285  1.1.1.1.2.2  pgoyette     s->cur_file_info_internal = cur_file_info_internalSaved;
   1286  1.1.1.1.2.2  pgoyette     return err;
   1287  1.1.1.1.2.2  pgoyette }
   1288  1.1.1.1.2.2  pgoyette 
   1289  1.1.1.1.2.2  pgoyette 
   1290  1.1.1.1.2.2  pgoyette /*
   1291  1.1.1.1.2.2  pgoyette ///////////////////////////////////////////
   1292  1.1.1.1.2.2  pgoyette // Contributed by Ryan Haksi (mailto://cryogen (at) infoserve.net)
   1293  1.1.1.1.2.2  pgoyette // I need random access
   1294  1.1.1.1.2.2  pgoyette //
   1295  1.1.1.1.2.2  pgoyette // Further optimization could be realized by adding an ability
   1296  1.1.1.1.2.2  pgoyette // to cache the directory in memory. The goal being a single
   1297  1.1.1.1.2.2  pgoyette // comprehensive file read to put the file I need in a memory.
   1298  1.1.1.1.2.2  pgoyette */
   1299  1.1.1.1.2.2  pgoyette 
   1300  1.1.1.1.2.2  pgoyette /*
   1301  1.1.1.1.2.2  pgoyette typedef struct unz_file_pos_s
   1302  1.1.1.1.2.2  pgoyette {
   1303  1.1.1.1.2.2  pgoyette     ZPOS64_T pos_in_zip_directory;   // offset in file
   1304  1.1.1.1.2.2  pgoyette     ZPOS64_T num_of_file;            // # of file
   1305  1.1.1.1.2.2  pgoyette } unz_file_pos;
   1306  1.1.1.1.2.2  pgoyette */
   1307  1.1.1.1.2.2  pgoyette 
   1308  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos*  file_pos)
   1309  1.1.1.1.2.2  pgoyette {
   1310  1.1.1.1.2.2  pgoyette     unz64_s* s;
   1311  1.1.1.1.2.2  pgoyette 
   1312  1.1.1.1.2.2  pgoyette     if (file==NULL || file_pos==NULL)
   1313  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1314  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   1315  1.1.1.1.2.2  pgoyette     if (!s->current_file_ok)
   1316  1.1.1.1.2.2  pgoyette         return UNZ_END_OF_LIST_OF_FILE;
   1317  1.1.1.1.2.2  pgoyette 
   1318  1.1.1.1.2.2  pgoyette     file_pos->pos_in_zip_directory  = s->pos_in_central_dir;
   1319  1.1.1.1.2.2  pgoyette     file_pos->num_of_file           = s->num_file;
   1320  1.1.1.1.2.2  pgoyette 
   1321  1.1.1.1.2.2  pgoyette     return UNZ_OK;
   1322  1.1.1.1.2.2  pgoyette }
   1323  1.1.1.1.2.2  pgoyette 
   1324  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzGetFilePos(
   1325  1.1.1.1.2.2  pgoyette     unzFile file,
   1326  1.1.1.1.2.2  pgoyette     unz_file_pos* file_pos)
   1327  1.1.1.1.2.2  pgoyette {
   1328  1.1.1.1.2.2  pgoyette     unz64_file_pos file_pos64;
   1329  1.1.1.1.2.2  pgoyette     int err = unzGetFilePos64(file,&file_pos64);
   1330  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
   1331  1.1.1.1.2.2  pgoyette     {
   1332  1.1.1.1.2.2  pgoyette         file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
   1333  1.1.1.1.2.2  pgoyette         file_pos->num_of_file = (uLong)file_pos64.num_of_file;
   1334  1.1.1.1.2.2  pgoyette     }
   1335  1.1.1.1.2.2  pgoyette     return err;
   1336  1.1.1.1.2.2  pgoyette }
   1337  1.1.1.1.2.2  pgoyette 
   1338  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
   1339  1.1.1.1.2.2  pgoyette {
   1340  1.1.1.1.2.2  pgoyette     unz64_s* s;
   1341  1.1.1.1.2.2  pgoyette     int err;
   1342  1.1.1.1.2.2  pgoyette 
   1343  1.1.1.1.2.2  pgoyette     if (file==NULL || file_pos==NULL)
   1344  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1345  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   1346  1.1.1.1.2.2  pgoyette 
   1347  1.1.1.1.2.2  pgoyette     /* jump to the right spot */
   1348  1.1.1.1.2.2  pgoyette     s->pos_in_central_dir = file_pos->pos_in_zip_directory;
   1349  1.1.1.1.2.2  pgoyette     s->num_file           = file_pos->num_of_file;
   1350  1.1.1.1.2.2  pgoyette 
   1351  1.1.1.1.2.2  pgoyette     /* set the current file */
   1352  1.1.1.1.2.2  pgoyette     err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
   1353  1.1.1.1.2.2  pgoyette                                                &s->cur_file_info_internal,
   1354  1.1.1.1.2.2  pgoyette                                                NULL,0,NULL,0,NULL,0);
   1355  1.1.1.1.2.2  pgoyette     /* return results */
   1356  1.1.1.1.2.2  pgoyette     s->current_file_ok = (err == UNZ_OK);
   1357  1.1.1.1.2.2  pgoyette     return err;
   1358  1.1.1.1.2.2  pgoyette }
   1359  1.1.1.1.2.2  pgoyette 
   1360  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzGoToFilePos(
   1361  1.1.1.1.2.2  pgoyette     unzFile file,
   1362  1.1.1.1.2.2  pgoyette     unz_file_pos* file_pos)
   1363  1.1.1.1.2.2  pgoyette {
   1364  1.1.1.1.2.2  pgoyette     unz64_file_pos file_pos64;
   1365  1.1.1.1.2.2  pgoyette     if (file_pos == NULL)
   1366  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1367  1.1.1.1.2.2  pgoyette 
   1368  1.1.1.1.2.2  pgoyette     file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
   1369  1.1.1.1.2.2  pgoyette     file_pos64.num_of_file = file_pos->num_of_file;
   1370  1.1.1.1.2.2  pgoyette     return unzGoToFilePos64(file,&file_pos64);
   1371  1.1.1.1.2.2  pgoyette }
   1372  1.1.1.1.2.2  pgoyette 
   1373  1.1.1.1.2.2  pgoyette /*
   1374  1.1.1.1.2.2  pgoyette // Unzip Helper Functions - should be here?
   1375  1.1.1.1.2.2  pgoyette ///////////////////////////////////////////
   1376  1.1.1.1.2.2  pgoyette */
   1377  1.1.1.1.2.2  pgoyette 
   1378  1.1.1.1.2.2  pgoyette /*
   1379  1.1.1.1.2.2  pgoyette   Read the local header of the current zipfile
   1380  1.1.1.1.2.2  pgoyette   Check the coherency of the local header and info in the end of central
   1381  1.1.1.1.2.2  pgoyette         directory about this file
   1382  1.1.1.1.2.2  pgoyette   store in *piSizeVar the size of extra info in local header
   1383  1.1.1.1.2.2  pgoyette         (filename and size of extra field data)
   1384  1.1.1.1.2.2  pgoyette */
   1385  1.1.1.1.2.2  pgoyette local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
   1386  1.1.1.1.2.2  pgoyette                                                     ZPOS64_T * poffset_local_extrafield,
   1387  1.1.1.1.2.2  pgoyette                                                     uInt  * psize_local_extrafield)
   1388  1.1.1.1.2.2  pgoyette {
   1389  1.1.1.1.2.2  pgoyette     uLong uMagic,uData,uFlags;
   1390  1.1.1.1.2.2  pgoyette     uLong size_filename;
   1391  1.1.1.1.2.2  pgoyette     uLong size_extra_field;
   1392  1.1.1.1.2.2  pgoyette     int err=UNZ_OK;
   1393  1.1.1.1.2.2  pgoyette 
   1394  1.1.1.1.2.2  pgoyette     *piSizeVar = 0;
   1395  1.1.1.1.2.2  pgoyette     *poffset_local_extrafield = 0;
   1396  1.1.1.1.2.2  pgoyette     *psize_local_extrafield = 0;
   1397  1.1.1.1.2.2  pgoyette 
   1398  1.1.1.1.2.2  pgoyette     if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
   1399  1.1.1.1.2.2  pgoyette                                 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
   1400  1.1.1.1.2.2  pgoyette         return UNZ_ERRNO;
   1401  1.1.1.1.2.2  pgoyette 
   1402  1.1.1.1.2.2  pgoyette 
   1403  1.1.1.1.2.2  pgoyette     if (err==UNZ_OK)
   1404  1.1.1.1.2.2  pgoyette     {
   1405  1.1.1.1.2.2  pgoyette         if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
   1406  1.1.1.1.2.2  pgoyette             err=UNZ_ERRNO;
   1407  1.1.1.1.2.2  pgoyette         else if (uMagic!=0x04034b50)
   1408  1.1.1.1.2.2  pgoyette             err=UNZ_BADZIPFILE;
   1409  1.1.1.1.2.2  pgoyette     }
   1410  1.1.1.1.2.2  pgoyette 
   1411  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
   1412  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
   1413  1.1.1.1.2.2  pgoyette /*
   1414  1.1.1.1.2.2  pgoyette     else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
   1415  1.1.1.1.2.2  pgoyette         err=UNZ_BADZIPFILE;
   1416  1.1.1.1.2.2  pgoyette */
   1417  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
   1418  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
   1419  1.1.1.1.2.2  pgoyette 
   1420  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
   1421  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
   1422  1.1.1.1.2.2  pgoyette     else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
   1423  1.1.1.1.2.2  pgoyette         err=UNZ_BADZIPFILE;
   1424  1.1.1.1.2.2  pgoyette 
   1425  1.1.1.1.2.2  pgoyette     if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
   1426  1.1.1.1.2.2  pgoyette /* #ifdef HAVE_BZIP2 */
   1427  1.1.1.1.2.2  pgoyette                          (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
   1428  1.1.1.1.2.2  pgoyette /* #endif */
   1429  1.1.1.1.2.2  pgoyette                          (s->cur_file_info.compression_method!=Z_DEFLATED))
   1430  1.1.1.1.2.2  pgoyette         err=UNZ_BADZIPFILE;
   1431  1.1.1.1.2.2  pgoyette 
   1432  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
   1433  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
   1434  1.1.1.1.2.2  pgoyette 
   1435  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
   1436  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
   1437  1.1.1.1.2.2  pgoyette     else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
   1438  1.1.1.1.2.2  pgoyette         err=UNZ_BADZIPFILE;
   1439  1.1.1.1.2.2  pgoyette 
   1440  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
   1441  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
   1442  1.1.1.1.2.2  pgoyette     else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
   1443  1.1.1.1.2.2  pgoyette         err=UNZ_BADZIPFILE;
   1444  1.1.1.1.2.2  pgoyette 
   1445  1.1.1.1.2.2  pgoyette     if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
   1446  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
   1447  1.1.1.1.2.2  pgoyette     else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
   1448  1.1.1.1.2.2  pgoyette         err=UNZ_BADZIPFILE;
   1449  1.1.1.1.2.2  pgoyette 
   1450  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
   1451  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
   1452  1.1.1.1.2.2  pgoyette     else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
   1453  1.1.1.1.2.2  pgoyette         err=UNZ_BADZIPFILE;
   1454  1.1.1.1.2.2  pgoyette 
   1455  1.1.1.1.2.2  pgoyette     *piSizeVar += (uInt)size_filename;
   1456  1.1.1.1.2.2  pgoyette 
   1457  1.1.1.1.2.2  pgoyette     if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
   1458  1.1.1.1.2.2  pgoyette         err=UNZ_ERRNO;
   1459  1.1.1.1.2.2  pgoyette     *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
   1460  1.1.1.1.2.2  pgoyette                                     SIZEZIPLOCALHEADER + size_filename;
   1461  1.1.1.1.2.2  pgoyette     *psize_local_extrafield = (uInt)size_extra_field;
   1462  1.1.1.1.2.2  pgoyette 
   1463  1.1.1.1.2.2  pgoyette     *piSizeVar += (uInt)size_extra_field;
   1464  1.1.1.1.2.2  pgoyette 
   1465  1.1.1.1.2.2  pgoyette     return err;
   1466  1.1.1.1.2.2  pgoyette }
   1467  1.1.1.1.2.2  pgoyette 
   1468  1.1.1.1.2.2  pgoyette /*
   1469  1.1.1.1.2.2  pgoyette   Open for reading data the current file in the zipfile.
   1470  1.1.1.1.2.2  pgoyette   If there is no error and the file is opened, the return value is UNZ_OK.
   1471  1.1.1.1.2.2  pgoyette */
   1472  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
   1473  1.1.1.1.2.2  pgoyette                                             int* level, int raw, const char* password)
   1474  1.1.1.1.2.2  pgoyette {
   1475  1.1.1.1.2.2  pgoyette     int err=UNZ_OK;
   1476  1.1.1.1.2.2  pgoyette     uInt iSizeVar;
   1477  1.1.1.1.2.2  pgoyette     unz64_s* s;
   1478  1.1.1.1.2.2  pgoyette     file_in_zip64_read_info_s* pfile_in_zip_read_info;
   1479  1.1.1.1.2.2  pgoyette     ZPOS64_T offset_local_extrafield;  /* offset of the local extra field */
   1480  1.1.1.1.2.2  pgoyette     uInt  size_local_extrafield;    /* size of the local extra field */
   1481  1.1.1.1.2.2  pgoyette #    ifndef NOUNCRYPT
   1482  1.1.1.1.2.2  pgoyette     char source[12];
   1483  1.1.1.1.2.2  pgoyette #    else
   1484  1.1.1.1.2.2  pgoyette     if (password != NULL)
   1485  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1486  1.1.1.1.2.2  pgoyette #    endif
   1487  1.1.1.1.2.2  pgoyette 
   1488  1.1.1.1.2.2  pgoyette     if (file==NULL)
   1489  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1490  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   1491  1.1.1.1.2.2  pgoyette     if (!s->current_file_ok)
   1492  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1493  1.1.1.1.2.2  pgoyette 
   1494  1.1.1.1.2.2  pgoyette     if (s->pfile_in_zip_read != NULL)
   1495  1.1.1.1.2.2  pgoyette         unzCloseCurrentFile(file);
   1496  1.1.1.1.2.2  pgoyette 
   1497  1.1.1.1.2.2  pgoyette     if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
   1498  1.1.1.1.2.2  pgoyette         return UNZ_BADZIPFILE;
   1499  1.1.1.1.2.2  pgoyette 
   1500  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
   1501  1.1.1.1.2.2  pgoyette     if (pfile_in_zip_read_info==NULL)
   1502  1.1.1.1.2.2  pgoyette         return UNZ_INTERNALERROR;
   1503  1.1.1.1.2.2  pgoyette 
   1504  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
   1505  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
   1506  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
   1507  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->pos_local_extrafield=0;
   1508  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->raw=raw;
   1509  1.1.1.1.2.2  pgoyette 
   1510  1.1.1.1.2.2  pgoyette     if (pfile_in_zip_read_info->read_buffer==NULL)
   1511  1.1.1.1.2.2  pgoyette     {
   1512  1.1.1.1.2.2  pgoyette         TRYFREE(pfile_in_zip_read_info);
   1513  1.1.1.1.2.2  pgoyette         return UNZ_INTERNALERROR;
   1514  1.1.1.1.2.2  pgoyette     }
   1515  1.1.1.1.2.2  pgoyette 
   1516  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->stream_initialised=0;
   1517  1.1.1.1.2.2  pgoyette 
   1518  1.1.1.1.2.2  pgoyette     if (method!=NULL)
   1519  1.1.1.1.2.2  pgoyette         *method = (int)s->cur_file_info.compression_method;
   1520  1.1.1.1.2.2  pgoyette 
   1521  1.1.1.1.2.2  pgoyette     if (level!=NULL)
   1522  1.1.1.1.2.2  pgoyette     {
   1523  1.1.1.1.2.2  pgoyette         *level = 6;
   1524  1.1.1.1.2.2  pgoyette         switch (s->cur_file_info.flag & 0x06)
   1525  1.1.1.1.2.2  pgoyette         {
   1526  1.1.1.1.2.2  pgoyette           case 6 : *level = 1; break;
   1527  1.1.1.1.2.2  pgoyette           case 4 : *level = 2; break;
   1528  1.1.1.1.2.2  pgoyette           case 2 : *level = 9; break;
   1529  1.1.1.1.2.2  pgoyette         }
   1530  1.1.1.1.2.2  pgoyette     }
   1531  1.1.1.1.2.2  pgoyette 
   1532  1.1.1.1.2.2  pgoyette     if ((s->cur_file_info.compression_method!=0) &&
   1533  1.1.1.1.2.2  pgoyette /* #ifdef HAVE_BZIP2 */
   1534  1.1.1.1.2.2  pgoyette         (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
   1535  1.1.1.1.2.2  pgoyette /* #endif */
   1536  1.1.1.1.2.2  pgoyette         (s->cur_file_info.compression_method!=Z_DEFLATED))
   1537  1.1.1.1.2.2  pgoyette 
   1538  1.1.1.1.2.2  pgoyette         err=UNZ_BADZIPFILE;
   1539  1.1.1.1.2.2  pgoyette 
   1540  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
   1541  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->crc32=0;
   1542  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->total_out_64=0;
   1543  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
   1544  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->filestream=s->filestream;
   1545  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
   1546  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
   1547  1.1.1.1.2.2  pgoyette 
   1548  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->stream.total_out = 0;
   1549  1.1.1.1.2.2  pgoyette 
   1550  1.1.1.1.2.2  pgoyette     if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
   1551  1.1.1.1.2.2  pgoyette     {
   1552  1.1.1.1.2.2  pgoyette #ifdef HAVE_BZIP2
   1553  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
   1554  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
   1555  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
   1556  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->bstream.state = (voidpf)0;
   1557  1.1.1.1.2.2  pgoyette 
   1558  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
   1559  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->stream.zfree = (free_func)0;
   1560  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->stream.opaque = (voidpf)0;
   1561  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->stream.next_in = (voidpf)0;
   1562  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->stream.avail_in = 0;
   1563  1.1.1.1.2.2  pgoyette 
   1564  1.1.1.1.2.2  pgoyette       err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
   1565  1.1.1.1.2.2  pgoyette       if (err == Z_OK)
   1566  1.1.1.1.2.2  pgoyette         pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
   1567  1.1.1.1.2.2  pgoyette       else
   1568  1.1.1.1.2.2  pgoyette       {
   1569  1.1.1.1.2.2  pgoyette         TRYFREE(pfile_in_zip_read_info);
   1570  1.1.1.1.2.2  pgoyette         return err;
   1571  1.1.1.1.2.2  pgoyette       }
   1572  1.1.1.1.2.2  pgoyette #else
   1573  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->raw=1;
   1574  1.1.1.1.2.2  pgoyette #endif
   1575  1.1.1.1.2.2  pgoyette     }
   1576  1.1.1.1.2.2  pgoyette     else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
   1577  1.1.1.1.2.2  pgoyette     {
   1578  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
   1579  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->stream.zfree = (free_func)0;
   1580  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->stream.opaque = (voidpf)0;
   1581  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->stream.next_in = 0;
   1582  1.1.1.1.2.2  pgoyette       pfile_in_zip_read_info->stream.avail_in = 0;
   1583  1.1.1.1.2.2  pgoyette 
   1584  1.1.1.1.2.2  pgoyette       err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
   1585  1.1.1.1.2.2  pgoyette       if (err == Z_OK)
   1586  1.1.1.1.2.2  pgoyette         pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
   1587  1.1.1.1.2.2  pgoyette       else
   1588  1.1.1.1.2.2  pgoyette       {
   1589  1.1.1.1.2.2  pgoyette         TRYFREE(pfile_in_zip_read_info);
   1590  1.1.1.1.2.2  pgoyette         return err;
   1591  1.1.1.1.2.2  pgoyette       }
   1592  1.1.1.1.2.2  pgoyette         /* windowBits is passed < 0 to tell that there is no zlib header.
   1593  1.1.1.1.2.2  pgoyette          * Note that in this case inflate *requires* an extra "dummy" byte
   1594  1.1.1.1.2.2  pgoyette          * after the compressed stream in order to complete decompression and
   1595  1.1.1.1.2.2  pgoyette          * return Z_STREAM_END.
   1596  1.1.1.1.2.2  pgoyette          * In unzip, i don't wait absolutely Z_STREAM_END because I known the
   1597  1.1.1.1.2.2  pgoyette          * size of both compressed and uncompressed data
   1598  1.1.1.1.2.2  pgoyette          */
   1599  1.1.1.1.2.2  pgoyette     }
   1600  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->rest_read_compressed =
   1601  1.1.1.1.2.2  pgoyette             s->cur_file_info.compressed_size ;
   1602  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->rest_read_uncompressed =
   1603  1.1.1.1.2.2  pgoyette             s->cur_file_info.uncompressed_size ;
   1604  1.1.1.1.2.2  pgoyette 
   1605  1.1.1.1.2.2  pgoyette 
   1606  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->pos_in_zipfile =
   1607  1.1.1.1.2.2  pgoyette             s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
   1608  1.1.1.1.2.2  pgoyette               iSizeVar;
   1609  1.1.1.1.2.2  pgoyette 
   1610  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->stream.avail_in = (uInt)0;
   1611  1.1.1.1.2.2  pgoyette 
   1612  1.1.1.1.2.2  pgoyette     s->pfile_in_zip_read = pfile_in_zip_read_info;
   1613  1.1.1.1.2.2  pgoyette                 s->encrypted = 0;
   1614  1.1.1.1.2.2  pgoyette 
   1615  1.1.1.1.2.2  pgoyette #    ifndef NOUNCRYPT
   1616  1.1.1.1.2.2  pgoyette     if (password != NULL)
   1617  1.1.1.1.2.2  pgoyette     {
   1618  1.1.1.1.2.2  pgoyette         int i;
   1619  1.1.1.1.2.2  pgoyette         s->pcrc_32_tab = get_crc_table();
   1620  1.1.1.1.2.2  pgoyette         init_keys(password,s->keys,s->pcrc_32_tab);
   1621  1.1.1.1.2.2  pgoyette         if (ZSEEK64(s->z_filefunc, s->filestream,
   1622  1.1.1.1.2.2  pgoyette                   s->pfile_in_zip_read->pos_in_zipfile +
   1623  1.1.1.1.2.2  pgoyette                      s->pfile_in_zip_read->byte_before_the_zipfile,
   1624  1.1.1.1.2.2  pgoyette                   SEEK_SET)!=0)
   1625  1.1.1.1.2.2  pgoyette             return UNZ_INTERNALERROR;
   1626  1.1.1.1.2.2  pgoyette         if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
   1627  1.1.1.1.2.2  pgoyette             return UNZ_INTERNALERROR;
   1628  1.1.1.1.2.2  pgoyette 
   1629  1.1.1.1.2.2  pgoyette         for (i = 0; i<12; i++)
   1630  1.1.1.1.2.2  pgoyette             zdecode(s->keys,s->pcrc_32_tab,source[i]);
   1631  1.1.1.1.2.2  pgoyette 
   1632  1.1.1.1.2.2  pgoyette         s->pfile_in_zip_read->pos_in_zipfile+=12;
   1633  1.1.1.1.2.2  pgoyette         s->encrypted=1;
   1634  1.1.1.1.2.2  pgoyette     }
   1635  1.1.1.1.2.2  pgoyette #    endif
   1636  1.1.1.1.2.2  pgoyette 
   1637  1.1.1.1.2.2  pgoyette 
   1638  1.1.1.1.2.2  pgoyette     return UNZ_OK;
   1639  1.1.1.1.2.2  pgoyette }
   1640  1.1.1.1.2.2  pgoyette 
   1641  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzOpenCurrentFile (unzFile file)
   1642  1.1.1.1.2.2  pgoyette {
   1643  1.1.1.1.2.2  pgoyette     return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
   1644  1.1.1.1.2.2  pgoyette }
   1645  1.1.1.1.2.2  pgoyette 
   1646  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char*  password)
   1647  1.1.1.1.2.2  pgoyette {
   1648  1.1.1.1.2.2  pgoyette     return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
   1649  1.1.1.1.2.2  pgoyette }
   1650  1.1.1.1.2.2  pgoyette 
   1651  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
   1652  1.1.1.1.2.2  pgoyette {
   1653  1.1.1.1.2.2  pgoyette     return unzOpenCurrentFile3(file, method, level, raw, NULL);
   1654  1.1.1.1.2.2  pgoyette }
   1655  1.1.1.1.2.2  pgoyette 
   1656  1.1.1.1.2.2  pgoyette /** Addition for GDAL : START */
   1657  1.1.1.1.2.2  pgoyette 
   1658  1.1.1.1.2.2  pgoyette extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
   1659  1.1.1.1.2.2  pgoyette {
   1660  1.1.1.1.2.2  pgoyette     unz64_s* s;
   1661  1.1.1.1.2.2  pgoyette     file_in_zip64_read_info_s* pfile_in_zip_read_info;
   1662  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   1663  1.1.1.1.2.2  pgoyette     if (file==NULL)
   1664  1.1.1.1.2.2  pgoyette         return 0; //UNZ_PARAMERROR;
   1665  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info=s->pfile_in_zip_read;
   1666  1.1.1.1.2.2  pgoyette     if (pfile_in_zip_read_info==NULL)
   1667  1.1.1.1.2.2  pgoyette         return 0; //UNZ_PARAMERROR;
   1668  1.1.1.1.2.2  pgoyette     return pfile_in_zip_read_info->pos_in_zipfile +
   1669  1.1.1.1.2.2  pgoyette                          pfile_in_zip_read_info->byte_before_the_zipfile;
   1670  1.1.1.1.2.2  pgoyette }
   1671  1.1.1.1.2.2  pgoyette 
   1672  1.1.1.1.2.2  pgoyette /** Addition for GDAL : END */
   1673  1.1.1.1.2.2  pgoyette 
   1674  1.1.1.1.2.2  pgoyette /*
   1675  1.1.1.1.2.2  pgoyette   Read bytes from the current file.
   1676  1.1.1.1.2.2  pgoyette   buf contain buffer where data must be copied
   1677  1.1.1.1.2.2  pgoyette   len the size of buf.
   1678  1.1.1.1.2.2  pgoyette 
   1679  1.1.1.1.2.2  pgoyette   return the number of byte copied if somes bytes are copied
   1680  1.1.1.1.2.2  pgoyette   return 0 if the end of file was reached
   1681  1.1.1.1.2.2  pgoyette   return <0 with error code if there is an error
   1682  1.1.1.1.2.2  pgoyette     (UNZ_ERRNO for IO error, or zLib error for uncompress error)
   1683  1.1.1.1.2.2  pgoyette */
   1684  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzReadCurrentFile  (unzFile file, voidp buf, unsigned len)
   1685  1.1.1.1.2.2  pgoyette {
   1686  1.1.1.1.2.2  pgoyette     int err=UNZ_OK;
   1687  1.1.1.1.2.2  pgoyette     uInt iRead = 0;
   1688  1.1.1.1.2.2  pgoyette     unz64_s* s;
   1689  1.1.1.1.2.2  pgoyette     file_in_zip64_read_info_s* pfile_in_zip_read_info;
   1690  1.1.1.1.2.2  pgoyette     if (file==NULL)
   1691  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1692  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   1693  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info=s->pfile_in_zip_read;
   1694  1.1.1.1.2.2  pgoyette 
   1695  1.1.1.1.2.2  pgoyette     if (pfile_in_zip_read_info==NULL)
   1696  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1697  1.1.1.1.2.2  pgoyette 
   1698  1.1.1.1.2.2  pgoyette 
   1699  1.1.1.1.2.2  pgoyette     if (pfile_in_zip_read_info->read_buffer == NULL)
   1700  1.1.1.1.2.2  pgoyette         return UNZ_END_OF_LIST_OF_FILE;
   1701  1.1.1.1.2.2  pgoyette     if (len==0)
   1702  1.1.1.1.2.2  pgoyette         return 0;
   1703  1.1.1.1.2.2  pgoyette 
   1704  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
   1705  1.1.1.1.2.2  pgoyette 
   1706  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->stream.avail_out = (uInt)len;
   1707  1.1.1.1.2.2  pgoyette 
   1708  1.1.1.1.2.2  pgoyette     if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
   1709  1.1.1.1.2.2  pgoyette         (!(pfile_in_zip_read_info->raw)))
   1710  1.1.1.1.2.2  pgoyette         pfile_in_zip_read_info->stream.avail_out =
   1711  1.1.1.1.2.2  pgoyette             (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
   1712  1.1.1.1.2.2  pgoyette 
   1713  1.1.1.1.2.2  pgoyette     if ((len>pfile_in_zip_read_info->rest_read_compressed+
   1714  1.1.1.1.2.2  pgoyette            pfile_in_zip_read_info->stream.avail_in) &&
   1715  1.1.1.1.2.2  pgoyette          (pfile_in_zip_read_info->raw))
   1716  1.1.1.1.2.2  pgoyette         pfile_in_zip_read_info->stream.avail_out =
   1717  1.1.1.1.2.2  pgoyette             (uInt)pfile_in_zip_read_info->rest_read_compressed+
   1718  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.avail_in;
   1719  1.1.1.1.2.2  pgoyette 
   1720  1.1.1.1.2.2  pgoyette     while (pfile_in_zip_read_info->stream.avail_out>0)
   1721  1.1.1.1.2.2  pgoyette     {
   1722  1.1.1.1.2.2  pgoyette         if ((pfile_in_zip_read_info->stream.avail_in==0) &&
   1723  1.1.1.1.2.2  pgoyette             (pfile_in_zip_read_info->rest_read_compressed>0))
   1724  1.1.1.1.2.2  pgoyette         {
   1725  1.1.1.1.2.2  pgoyette             uInt uReadThis = UNZ_BUFSIZE;
   1726  1.1.1.1.2.2  pgoyette             if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
   1727  1.1.1.1.2.2  pgoyette                 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
   1728  1.1.1.1.2.2  pgoyette             if (uReadThis == 0)
   1729  1.1.1.1.2.2  pgoyette                 return UNZ_EOF;
   1730  1.1.1.1.2.2  pgoyette             if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
   1731  1.1.1.1.2.2  pgoyette                       pfile_in_zip_read_info->filestream,
   1732  1.1.1.1.2.2  pgoyette                       pfile_in_zip_read_info->pos_in_zipfile +
   1733  1.1.1.1.2.2  pgoyette                          pfile_in_zip_read_info->byte_before_the_zipfile,
   1734  1.1.1.1.2.2  pgoyette                          ZLIB_FILEFUNC_SEEK_SET)!=0)
   1735  1.1.1.1.2.2  pgoyette                 return UNZ_ERRNO;
   1736  1.1.1.1.2.2  pgoyette             if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
   1737  1.1.1.1.2.2  pgoyette                       pfile_in_zip_read_info->filestream,
   1738  1.1.1.1.2.2  pgoyette                       pfile_in_zip_read_info->read_buffer,
   1739  1.1.1.1.2.2  pgoyette                       uReadThis)!=uReadThis)
   1740  1.1.1.1.2.2  pgoyette                 return UNZ_ERRNO;
   1741  1.1.1.1.2.2  pgoyette 
   1742  1.1.1.1.2.2  pgoyette 
   1743  1.1.1.1.2.2  pgoyette #            ifndef NOUNCRYPT
   1744  1.1.1.1.2.2  pgoyette             if(s->encrypted)
   1745  1.1.1.1.2.2  pgoyette             {
   1746  1.1.1.1.2.2  pgoyette                 uInt i;
   1747  1.1.1.1.2.2  pgoyette                 for(i=0;i<uReadThis;i++)
   1748  1.1.1.1.2.2  pgoyette                   pfile_in_zip_read_info->read_buffer[i] =
   1749  1.1.1.1.2.2  pgoyette                       zdecode(s->keys,s->pcrc_32_tab,
   1750  1.1.1.1.2.2  pgoyette                               pfile_in_zip_read_info->read_buffer[i]);
   1751  1.1.1.1.2.2  pgoyette             }
   1752  1.1.1.1.2.2  pgoyette #            endif
   1753  1.1.1.1.2.2  pgoyette 
   1754  1.1.1.1.2.2  pgoyette 
   1755  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
   1756  1.1.1.1.2.2  pgoyette 
   1757  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
   1758  1.1.1.1.2.2  pgoyette 
   1759  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.next_in =
   1760  1.1.1.1.2.2  pgoyette                 (Bytef*)pfile_in_zip_read_info->read_buffer;
   1761  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
   1762  1.1.1.1.2.2  pgoyette         }
   1763  1.1.1.1.2.2  pgoyette 
   1764  1.1.1.1.2.2  pgoyette         if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
   1765  1.1.1.1.2.2  pgoyette         {
   1766  1.1.1.1.2.2  pgoyette             uInt uDoCopy,i ;
   1767  1.1.1.1.2.2  pgoyette 
   1768  1.1.1.1.2.2  pgoyette             if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
   1769  1.1.1.1.2.2  pgoyette                 (pfile_in_zip_read_info->rest_read_compressed == 0))
   1770  1.1.1.1.2.2  pgoyette                 return (iRead==0) ? UNZ_EOF : iRead;
   1771  1.1.1.1.2.2  pgoyette 
   1772  1.1.1.1.2.2  pgoyette             if (pfile_in_zip_read_info->stream.avail_out <
   1773  1.1.1.1.2.2  pgoyette                             pfile_in_zip_read_info->stream.avail_in)
   1774  1.1.1.1.2.2  pgoyette                 uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
   1775  1.1.1.1.2.2  pgoyette             else
   1776  1.1.1.1.2.2  pgoyette                 uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
   1777  1.1.1.1.2.2  pgoyette 
   1778  1.1.1.1.2.2  pgoyette             for (i=0;i<uDoCopy;i++)
   1779  1.1.1.1.2.2  pgoyette                 *(pfile_in_zip_read_info->stream.next_out+i) =
   1780  1.1.1.1.2.2  pgoyette                         *(pfile_in_zip_read_info->stream.next_in+i);
   1781  1.1.1.1.2.2  pgoyette 
   1782  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
   1783  1.1.1.1.2.2  pgoyette 
   1784  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
   1785  1.1.1.1.2.2  pgoyette                                 pfile_in_zip_read_info->stream.next_out,
   1786  1.1.1.1.2.2  pgoyette                                 uDoCopy);
   1787  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
   1788  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
   1789  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
   1790  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.next_out += uDoCopy;
   1791  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.next_in += uDoCopy;
   1792  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.total_out += uDoCopy;
   1793  1.1.1.1.2.2  pgoyette             iRead += uDoCopy;
   1794  1.1.1.1.2.2  pgoyette         }
   1795  1.1.1.1.2.2  pgoyette         else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
   1796  1.1.1.1.2.2  pgoyette         {
   1797  1.1.1.1.2.2  pgoyette #ifdef HAVE_BZIP2
   1798  1.1.1.1.2.2  pgoyette             uLong uTotalOutBefore,uTotalOutAfter;
   1799  1.1.1.1.2.2  pgoyette             const Bytef *bufBefore;
   1800  1.1.1.1.2.2  pgoyette             uLong uOutThis;
   1801  1.1.1.1.2.2  pgoyette 
   1802  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->bstream.next_in        = (char*)pfile_in_zip_read_info->stream.next_in;
   1803  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->bstream.avail_in       = pfile_in_zip_read_info->stream.avail_in;
   1804  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->bstream.total_in_lo32  = pfile_in_zip_read_info->stream.total_in;
   1805  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->bstream.total_in_hi32  = 0;
   1806  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->bstream.next_out       = (char*)pfile_in_zip_read_info->stream.next_out;
   1807  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->bstream.avail_out      = pfile_in_zip_read_info->stream.avail_out;
   1808  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
   1809  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
   1810  1.1.1.1.2.2  pgoyette 
   1811  1.1.1.1.2.2  pgoyette             uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
   1812  1.1.1.1.2.2  pgoyette             bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
   1813  1.1.1.1.2.2  pgoyette 
   1814  1.1.1.1.2.2  pgoyette             err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
   1815  1.1.1.1.2.2  pgoyette 
   1816  1.1.1.1.2.2  pgoyette             uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
   1817  1.1.1.1.2.2  pgoyette             uOutThis = uTotalOutAfter-uTotalOutBefore;
   1818  1.1.1.1.2.2  pgoyette 
   1819  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
   1820  1.1.1.1.2.2  pgoyette 
   1821  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
   1822  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
   1823  1.1.1.1.2.2  pgoyette             iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
   1824  1.1.1.1.2.2  pgoyette 
   1825  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.next_in   = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
   1826  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.avail_in  = pfile_in_zip_read_info->bstream.avail_in;
   1827  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.total_in  = pfile_in_zip_read_info->bstream.total_in_lo32;
   1828  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.next_out  = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
   1829  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
   1830  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
   1831  1.1.1.1.2.2  pgoyette 
   1832  1.1.1.1.2.2  pgoyette             if (err==BZ_STREAM_END)
   1833  1.1.1.1.2.2  pgoyette               return (iRead==0) ? UNZ_EOF : iRead;
   1834  1.1.1.1.2.2  pgoyette             if (err!=BZ_OK)
   1835  1.1.1.1.2.2  pgoyette               break;
   1836  1.1.1.1.2.2  pgoyette #endif
   1837  1.1.1.1.2.2  pgoyette         } // end Z_BZIP2ED
   1838  1.1.1.1.2.2  pgoyette         else
   1839  1.1.1.1.2.2  pgoyette         {
   1840  1.1.1.1.2.2  pgoyette             ZPOS64_T uTotalOutBefore,uTotalOutAfter;
   1841  1.1.1.1.2.2  pgoyette             const Bytef *bufBefore;
   1842  1.1.1.1.2.2  pgoyette             ZPOS64_T uOutThis;
   1843  1.1.1.1.2.2  pgoyette             int flush=Z_SYNC_FLUSH;
   1844  1.1.1.1.2.2  pgoyette 
   1845  1.1.1.1.2.2  pgoyette             uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
   1846  1.1.1.1.2.2  pgoyette             bufBefore = pfile_in_zip_read_info->stream.next_out;
   1847  1.1.1.1.2.2  pgoyette 
   1848  1.1.1.1.2.2  pgoyette             /*
   1849  1.1.1.1.2.2  pgoyette             if ((pfile_in_zip_read_info->rest_read_uncompressed ==
   1850  1.1.1.1.2.2  pgoyette                      pfile_in_zip_read_info->stream.avail_out) &&
   1851  1.1.1.1.2.2  pgoyette                 (pfile_in_zip_read_info->rest_read_compressed == 0))
   1852  1.1.1.1.2.2  pgoyette                 flush = Z_FINISH;
   1853  1.1.1.1.2.2  pgoyette             */
   1854  1.1.1.1.2.2  pgoyette             err=inflate(&pfile_in_zip_read_info->stream,flush);
   1855  1.1.1.1.2.2  pgoyette 
   1856  1.1.1.1.2.2  pgoyette             if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
   1857  1.1.1.1.2.2  pgoyette               err = Z_DATA_ERROR;
   1858  1.1.1.1.2.2  pgoyette 
   1859  1.1.1.1.2.2  pgoyette             uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
   1860  1.1.1.1.2.2  pgoyette             uOutThis = uTotalOutAfter-uTotalOutBefore;
   1861  1.1.1.1.2.2  pgoyette 
   1862  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
   1863  1.1.1.1.2.2  pgoyette 
   1864  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->crc32 =
   1865  1.1.1.1.2.2  pgoyette                 crc32(pfile_in_zip_read_info->crc32,bufBefore,
   1866  1.1.1.1.2.2  pgoyette                         (uInt)(uOutThis));
   1867  1.1.1.1.2.2  pgoyette 
   1868  1.1.1.1.2.2  pgoyette             pfile_in_zip_read_info->rest_read_uncompressed -=
   1869  1.1.1.1.2.2  pgoyette                 uOutThis;
   1870  1.1.1.1.2.2  pgoyette 
   1871  1.1.1.1.2.2  pgoyette             iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
   1872  1.1.1.1.2.2  pgoyette 
   1873  1.1.1.1.2.2  pgoyette             if (err==Z_STREAM_END)
   1874  1.1.1.1.2.2  pgoyette                 return (iRead==0) ? UNZ_EOF : iRead;
   1875  1.1.1.1.2.2  pgoyette             if (err!=Z_OK)
   1876  1.1.1.1.2.2  pgoyette                 break;
   1877  1.1.1.1.2.2  pgoyette         }
   1878  1.1.1.1.2.2  pgoyette     }
   1879  1.1.1.1.2.2  pgoyette 
   1880  1.1.1.1.2.2  pgoyette     if (err==Z_OK)
   1881  1.1.1.1.2.2  pgoyette         return iRead;
   1882  1.1.1.1.2.2  pgoyette     return err;
   1883  1.1.1.1.2.2  pgoyette }
   1884  1.1.1.1.2.2  pgoyette 
   1885  1.1.1.1.2.2  pgoyette 
   1886  1.1.1.1.2.2  pgoyette /*
   1887  1.1.1.1.2.2  pgoyette   Give the current position in uncompressed data
   1888  1.1.1.1.2.2  pgoyette */
   1889  1.1.1.1.2.2  pgoyette extern z_off_t ZEXPORT unztell (unzFile file)
   1890  1.1.1.1.2.2  pgoyette {
   1891  1.1.1.1.2.2  pgoyette     unz64_s* s;
   1892  1.1.1.1.2.2  pgoyette     file_in_zip64_read_info_s* pfile_in_zip_read_info;
   1893  1.1.1.1.2.2  pgoyette     if (file==NULL)
   1894  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1895  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   1896  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info=s->pfile_in_zip_read;
   1897  1.1.1.1.2.2  pgoyette 
   1898  1.1.1.1.2.2  pgoyette     if (pfile_in_zip_read_info==NULL)
   1899  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1900  1.1.1.1.2.2  pgoyette 
   1901  1.1.1.1.2.2  pgoyette     return (z_off_t)pfile_in_zip_read_info->stream.total_out;
   1902  1.1.1.1.2.2  pgoyette }
   1903  1.1.1.1.2.2  pgoyette 
   1904  1.1.1.1.2.2  pgoyette extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
   1905  1.1.1.1.2.2  pgoyette {
   1906  1.1.1.1.2.2  pgoyette 
   1907  1.1.1.1.2.2  pgoyette     unz64_s* s;
   1908  1.1.1.1.2.2  pgoyette     file_in_zip64_read_info_s* pfile_in_zip_read_info;
   1909  1.1.1.1.2.2  pgoyette     if (file==NULL)
   1910  1.1.1.1.2.2  pgoyette         return (ZPOS64_T)-1;
   1911  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   1912  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info=s->pfile_in_zip_read;
   1913  1.1.1.1.2.2  pgoyette 
   1914  1.1.1.1.2.2  pgoyette     if (pfile_in_zip_read_info==NULL)
   1915  1.1.1.1.2.2  pgoyette         return (ZPOS64_T)-1;
   1916  1.1.1.1.2.2  pgoyette 
   1917  1.1.1.1.2.2  pgoyette     return pfile_in_zip_read_info->total_out_64;
   1918  1.1.1.1.2.2  pgoyette }
   1919  1.1.1.1.2.2  pgoyette 
   1920  1.1.1.1.2.2  pgoyette 
   1921  1.1.1.1.2.2  pgoyette /*
   1922  1.1.1.1.2.2  pgoyette   return 1 if the end of file was reached, 0 elsewhere
   1923  1.1.1.1.2.2  pgoyette */
   1924  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzeof (unzFile file)
   1925  1.1.1.1.2.2  pgoyette {
   1926  1.1.1.1.2.2  pgoyette     unz64_s* s;
   1927  1.1.1.1.2.2  pgoyette     file_in_zip64_read_info_s* pfile_in_zip_read_info;
   1928  1.1.1.1.2.2  pgoyette     if (file==NULL)
   1929  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1930  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   1931  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info=s->pfile_in_zip_read;
   1932  1.1.1.1.2.2  pgoyette 
   1933  1.1.1.1.2.2  pgoyette     if (pfile_in_zip_read_info==NULL)
   1934  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1935  1.1.1.1.2.2  pgoyette 
   1936  1.1.1.1.2.2  pgoyette     if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
   1937  1.1.1.1.2.2  pgoyette         return 1;
   1938  1.1.1.1.2.2  pgoyette     else
   1939  1.1.1.1.2.2  pgoyette         return 0;
   1940  1.1.1.1.2.2  pgoyette }
   1941  1.1.1.1.2.2  pgoyette 
   1942  1.1.1.1.2.2  pgoyette 
   1943  1.1.1.1.2.2  pgoyette 
   1944  1.1.1.1.2.2  pgoyette /*
   1945  1.1.1.1.2.2  pgoyette Read extra field from the current file (opened by unzOpenCurrentFile)
   1946  1.1.1.1.2.2  pgoyette This is the local-header version of the extra field (sometimes, there is
   1947  1.1.1.1.2.2  pgoyette more info in the local-header version than in the central-header)
   1948  1.1.1.1.2.2  pgoyette 
   1949  1.1.1.1.2.2  pgoyette   if buf==NULL, it return the size of the local extra field that can be read
   1950  1.1.1.1.2.2  pgoyette 
   1951  1.1.1.1.2.2  pgoyette   if buf!=NULL, len is the size of the buffer, the extra header is copied in
   1952  1.1.1.1.2.2  pgoyette     buf.
   1953  1.1.1.1.2.2  pgoyette   the return value is the number of bytes copied in buf, or (if <0)
   1954  1.1.1.1.2.2  pgoyette     the error code
   1955  1.1.1.1.2.2  pgoyette */
   1956  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
   1957  1.1.1.1.2.2  pgoyette {
   1958  1.1.1.1.2.2  pgoyette     unz64_s* s;
   1959  1.1.1.1.2.2  pgoyette     file_in_zip64_read_info_s* pfile_in_zip_read_info;
   1960  1.1.1.1.2.2  pgoyette     uInt read_now;
   1961  1.1.1.1.2.2  pgoyette     ZPOS64_T size_to_read;
   1962  1.1.1.1.2.2  pgoyette 
   1963  1.1.1.1.2.2  pgoyette     if (file==NULL)
   1964  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1965  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   1966  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info=s->pfile_in_zip_read;
   1967  1.1.1.1.2.2  pgoyette 
   1968  1.1.1.1.2.2  pgoyette     if (pfile_in_zip_read_info==NULL)
   1969  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   1970  1.1.1.1.2.2  pgoyette 
   1971  1.1.1.1.2.2  pgoyette     size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
   1972  1.1.1.1.2.2  pgoyette                 pfile_in_zip_read_info->pos_local_extrafield);
   1973  1.1.1.1.2.2  pgoyette 
   1974  1.1.1.1.2.2  pgoyette     if (buf==NULL)
   1975  1.1.1.1.2.2  pgoyette         return (int)size_to_read;
   1976  1.1.1.1.2.2  pgoyette 
   1977  1.1.1.1.2.2  pgoyette     if (len>size_to_read)
   1978  1.1.1.1.2.2  pgoyette         read_now = (uInt)size_to_read;
   1979  1.1.1.1.2.2  pgoyette     else
   1980  1.1.1.1.2.2  pgoyette         read_now = (uInt)len ;
   1981  1.1.1.1.2.2  pgoyette 
   1982  1.1.1.1.2.2  pgoyette     if (read_now==0)
   1983  1.1.1.1.2.2  pgoyette         return 0;
   1984  1.1.1.1.2.2  pgoyette 
   1985  1.1.1.1.2.2  pgoyette     if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
   1986  1.1.1.1.2.2  pgoyette               pfile_in_zip_read_info->filestream,
   1987  1.1.1.1.2.2  pgoyette               pfile_in_zip_read_info->offset_local_extrafield +
   1988  1.1.1.1.2.2  pgoyette               pfile_in_zip_read_info->pos_local_extrafield,
   1989  1.1.1.1.2.2  pgoyette               ZLIB_FILEFUNC_SEEK_SET)!=0)
   1990  1.1.1.1.2.2  pgoyette         return UNZ_ERRNO;
   1991  1.1.1.1.2.2  pgoyette 
   1992  1.1.1.1.2.2  pgoyette     if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
   1993  1.1.1.1.2.2  pgoyette               pfile_in_zip_read_info->filestream,
   1994  1.1.1.1.2.2  pgoyette               buf,read_now)!=read_now)
   1995  1.1.1.1.2.2  pgoyette         return UNZ_ERRNO;
   1996  1.1.1.1.2.2  pgoyette 
   1997  1.1.1.1.2.2  pgoyette     return (int)read_now;
   1998  1.1.1.1.2.2  pgoyette }
   1999  1.1.1.1.2.2  pgoyette 
   2000  1.1.1.1.2.2  pgoyette /*
   2001  1.1.1.1.2.2  pgoyette   Close the file in zip opened with unzipOpenCurrentFile
   2002  1.1.1.1.2.2  pgoyette   Return UNZ_CRCERROR if all the file was read but the CRC is not good
   2003  1.1.1.1.2.2  pgoyette */
   2004  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzCloseCurrentFile (unzFile file)
   2005  1.1.1.1.2.2  pgoyette {
   2006  1.1.1.1.2.2  pgoyette     int err=UNZ_OK;
   2007  1.1.1.1.2.2  pgoyette 
   2008  1.1.1.1.2.2  pgoyette     unz64_s* s;
   2009  1.1.1.1.2.2  pgoyette     file_in_zip64_read_info_s* pfile_in_zip_read_info;
   2010  1.1.1.1.2.2  pgoyette     if (file==NULL)
   2011  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   2012  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   2013  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info=s->pfile_in_zip_read;
   2014  1.1.1.1.2.2  pgoyette 
   2015  1.1.1.1.2.2  pgoyette     if (pfile_in_zip_read_info==NULL)
   2016  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   2017  1.1.1.1.2.2  pgoyette 
   2018  1.1.1.1.2.2  pgoyette 
   2019  1.1.1.1.2.2  pgoyette     if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
   2020  1.1.1.1.2.2  pgoyette         (!pfile_in_zip_read_info->raw))
   2021  1.1.1.1.2.2  pgoyette     {
   2022  1.1.1.1.2.2  pgoyette         if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
   2023  1.1.1.1.2.2  pgoyette             err=UNZ_CRCERROR;
   2024  1.1.1.1.2.2  pgoyette     }
   2025  1.1.1.1.2.2  pgoyette 
   2026  1.1.1.1.2.2  pgoyette 
   2027  1.1.1.1.2.2  pgoyette     TRYFREE(pfile_in_zip_read_info->read_buffer);
   2028  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->read_buffer = NULL;
   2029  1.1.1.1.2.2  pgoyette     if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
   2030  1.1.1.1.2.2  pgoyette         inflateEnd(&pfile_in_zip_read_info->stream);
   2031  1.1.1.1.2.2  pgoyette #ifdef HAVE_BZIP2
   2032  1.1.1.1.2.2  pgoyette     else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
   2033  1.1.1.1.2.2  pgoyette         BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
   2034  1.1.1.1.2.2  pgoyette #endif
   2035  1.1.1.1.2.2  pgoyette 
   2036  1.1.1.1.2.2  pgoyette 
   2037  1.1.1.1.2.2  pgoyette     pfile_in_zip_read_info->stream_initialised = 0;
   2038  1.1.1.1.2.2  pgoyette     TRYFREE(pfile_in_zip_read_info);
   2039  1.1.1.1.2.2  pgoyette 
   2040  1.1.1.1.2.2  pgoyette     s->pfile_in_zip_read=NULL;
   2041  1.1.1.1.2.2  pgoyette 
   2042  1.1.1.1.2.2  pgoyette     return err;
   2043  1.1.1.1.2.2  pgoyette }
   2044  1.1.1.1.2.2  pgoyette 
   2045  1.1.1.1.2.2  pgoyette 
   2046  1.1.1.1.2.2  pgoyette /*
   2047  1.1.1.1.2.2  pgoyette   Get the global comment string of the ZipFile, in the szComment buffer.
   2048  1.1.1.1.2.2  pgoyette   uSizeBuf is the size of the szComment buffer.
   2049  1.1.1.1.2.2  pgoyette   return the number of byte copied or an error code <0
   2050  1.1.1.1.2.2  pgoyette */
   2051  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
   2052  1.1.1.1.2.2  pgoyette {
   2053  1.1.1.1.2.2  pgoyette     unz64_s* s;
   2054  1.1.1.1.2.2  pgoyette     uLong uReadThis ;
   2055  1.1.1.1.2.2  pgoyette     if (file==NULL)
   2056  1.1.1.1.2.2  pgoyette         return (int)UNZ_PARAMERROR;
   2057  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   2058  1.1.1.1.2.2  pgoyette 
   2059  1.1.1.1.2.2  pgoyette     uReadThis = uSizeBuf;
   2060  1.1.1.1.2.2  pgoyette     if (uReadThis>s->gi.size_comment)
   2061  1.1.1.1.2.2  pgoyette         uReadThis = s->gi.size_comment;
   2062  1.1.1.1.2.2  pgoyette 
   2063  1.1.1.1.2.2  pgoyette     if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
   2064  1.1.1.1.2.2  pgoyette         return UNZ_ERRNO;
   2065  1.1.1.1.2.2  pgoyette 
   2066  1.1.1.1.2.2  pgoyette     if (uReadThis>0)
   2067  1.1.1.1.2.2  pgoyette     {
   2068  1.1.1.1.2.2  pgoyette       *szComment='\0';
   2069  1.1.1.1.2.2  pgoyette       if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
   2070  1.1.1.1.2.2  pgoyette         return UNZ_ERRNO;
   2071  1.1.1.1.2.2  pgoyette     }
   2072  1.1.1.1.2.2  pgoyette 
   2073  1.1.1.1.2.2  pgoyette     if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
   2074  1.1.1.1.2.2  pgoyette         *(szComment+s->gi.size_comment)='\0';
   2075  1.1.1.1.2.2  pgoyette     return (int)uReadThis;
   2076  1.1.1.1.2.2  pgoyette }
   2077  1.1.1.1.2.2  pgoyette 
   2078  1.1.1.1.2.2  pgoyette /* Additions by RX '2004 */
   2079  1.1.1.1.2.2  pgoyette extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
   2080  1.1.1.1.2.2  pgoyette {
   2081  1.1.1.1.2.2  pgoyette     unz64_s* s;
   2082  1.1.1.1.2.2  pgoyette 
   2083  1.1.1.1.2.2  pgoyette     if (file==NULL)
   2084  1.1.1.1.2.2  pgoyette           return 0; //UNZ_PARAMERROR;
   2085  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   2086  1.1.1.1.2.2  pgoyette     if (!s->current_file_ok)
   2087  1.1.1.1.2.2  pgoyette       return 0;
   2088  1.1.1.1.2.2  pgoyette     if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
   2089  1.1.1.1.2.2  pgoyette       if (s->num_file==s->gi.number_entry)
   2090  1.1.1.1.2.2  pgoyette          return 0;
   2091  1.1.1.1.2.2  pgoyette     return s->pos_in_central_dir;
   2092  1.1.1.1.2.2  pgoyette }
   2093  1.1.1.1.2.2  pgoyette 
   2094  1.1.1.1.2.2  pgoyette extern uLong ZEXPORT unzGetOffset (unzFile file)
   2095  1.1.1.1.2.2  pgoyette {
   2096  1.1.1.1.2.2  pgoyette     ZPOS64_T offset64;
   2097  1.1.1.1.2.2  pgoyette 
   2098  1.1.1.1.2.2  pgoyette     if (file==NULL)
   2099  1.1.1.1.2.2  pgoyette           return 0; //UNZ_PARAMERROR;
   2100  1.1.1.1.2.2  pgoyette     offset64 = unzGetOffset64(file);
   2101  1.1.1.1.2.2  pgoyette     return (uLong)offset64;
   2102  1.1.1.1.2.2  pgoyette }
   2103  1.1.1.1.2.2  pgoyette 
   2104  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
   2105  1.1.1.1.2.2  pgoyette {
   2106  1.1.1.1.2.2  pgoyette     unz64_s* s;
   2107  1.1.1.1.2.2  pgoyette     int err;
   2108  1.1.1.1.2.2  pgoyette 
   2109  1.1.1.1.2.2  pgoyette     if (file==NULL)
   2110  1.1.1.1.2.2  pgoyette         return UNZ_PARAMERROR;
   2111  1.1.1.1.2.2  pgoyette     s=(unz64_s*)file;
   2112  1.1.1.1.2.2  pgoyette 
   2113  1.1.1.1.2.2  pgoyette     s->pos_in_central_dir = pos;
   2114  1.1.1.1.2.2  pgoyette     s->num_file = s->gi.number_entry;      /* hack */
   2115  1.1.1.1.2.2  pgoyette     err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
   2116  1.1.1.1.2.2  pgoyette                                               &s->cur_file_info_internal,
   2117  1.1.1.1.2.2  pgoyette                                               NULL,0,NULL,0,NULL,0);
   2118  1.1.1.1.2.2  pgoyette     s->current_file_ok = (err == UNZ_OK);
   2119  1.1.1.1.2.2  pgoyette     return err;
   2120  1.1.1.1.2.2  pgoyette }
   2121  1.1.1.1.2.2  pgoyette 
   2122  1.1.1.1.2.2  pgoyette extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
   2123  1.1.1.1.2.2  pgoyette {
   2124  1.1.1.1.2.2  pgoyette     return unzSetOffset64(file,pos);
   2125  1.1.1.1.2.2  pgoyette }
   2126