misc/quazip/unzip.c
author sheepluva
Tue, 04 Sep 2012 13:18:26 +0200
changeset 7669 a85e1c167b69
parent 5752 ea95ee97c805
permissions -rw-r--r--
I didn't want to do this since it seems less clean, but... moving the stats-fix into CheckForWin, since that function is the one sending the damage stats (whyyyy?) therefore it's not sufficient to update stats after calling it, some of the stats won't be transfered to frontend then
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5752
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     1
/* unzip.c -- IO for uncompress .zip files using zlib
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     2
   Version 1.01e, February 12th, 2005
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     3
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     4
   Copyright (C) 1998-2005 Gilles Vollant
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     5
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     6
   Read unzip.h for more info
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     7
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     8
   Modified by Sergey A. Tachenov to integrate with Qt.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     9
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    10
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    11
/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    12
compatibility with older software. The following is from the original crypt.c. Code
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    13
woven in by Terry Thorsen 1/2003.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    14
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    15
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    16
  Copyright (c) 1990-2000 Info-ZIP.  All rights reserved.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    17
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    18
  See the accompanying file LICENSE, version 2000-Apr-09 or later
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    19
  (the contents of which are also included in zip.h) for terms of use.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    20
  If, for some reason, all these files are missing, the Info-ZIP license
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    21
  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    22
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    23
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    24
  crypt.c (full version) by Info-ZIP.      Last revised:  [see crypt.h]
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    25
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    26
  The encryption/decryption parts of this source code (as opposed to the
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    27
  non-echoing password parts) were originally written in Europe.  The
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    28
  whole source package can be freely distributed, including from the USA.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    29
  (Prior to January 2000, re-export from the US was a violation of US law.)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    30
 */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    31
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    32
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    33
  This encryption code is a direct transcription of the algorithm from
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    34
  Roger Schlafly, described by Phil Katz in the file appnote.txt.  This
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    35
  file (appnote.txt) is distributed with the PKZIP program (even in the
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    36
  version without encryption capabilities).
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    37
 */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    38
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    39
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    40
#include <stdio.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    41
#include <stdlib.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    42
#include <string.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    43
#include "zlib.h"
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    44
#include "unzip.h"
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    45
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    46
#ifdef STDC
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    47
#  include <stddef.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    48
#  include <string.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    49
#  include <stdlib.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    50
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    51
#ifdef NO_ERRNO_H
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    52
    extern int errno;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    53
#else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    54
#   include <errno.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    55
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    56
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    57
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    58
#ifndef local
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    59
#  define local static
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    60
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    61
/* compile with -Dlocal if your debugger can't find static symbols */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    62
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    63
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    64
#ifndef CASESENSITIVITYDEFAULT_NO
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    65
#  if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    66
#    define CASESENSITIVITYDEFAULT_NO
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    67
#  endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    68
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    69
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    70
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    71
#ifndef UNZ_BUFSIZE
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    72
#define UNZ_BUFSIZE (16384)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    73
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    74
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    75
#ifndef UNZ_MAXFILENAMEINZIP
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    76
#define UNZ_MAXFILENAMEINZIP (256)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    77
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    78
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    79
#ifndef ALLOC
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    80
# define ALLOC(size) (malloc(size))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    81
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    82
#ifndef TRYFREE
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    83
# define TRYFREE(p) {if (p) free(p);}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    84
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    85
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    86
#define SIZECENTRALDIRITEM (0x2e)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    87
#define SIZEZIPLOCALHEADER (0x1e)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    88
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    89
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    90
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    91
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    92
const char unz_copyright[] =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    93
   " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    94
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    95
/* unz_file_info_interntal contain internal info about a file in zipfile*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    96
typedef struct unz_file_info_internal_s
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    97
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    98
    uLong offset_curfile;/* relative offset of local header 4 bytes */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    99
} unz_file_info_internal;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   100
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   101
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   102
/* file_in_zip_read_info_s contain internal information about a file in zipfile,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   103
    when reading and decompress it */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   104
typedef struct
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   105
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   106
    char  *read_buffer;         /* internal buffer for compressed data */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   107
    z_stream stream;            /* zLib stream structure for inflate */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   108
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   109
    uLong pos_in_zipfile;       /* position in byte on the zipfile, for fseek*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   110
    uLong stream_initialised;   /* flag set if stream structure is initialised*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   111
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   112
    uLong offset_local_extrafield;/* offset of the local extra field */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   113
    uInt  size_local_extrafield;/* size of the local extra field */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   114
    uLong pos_local_extrafield;   /* position in the local extra field in read*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   115
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   116
    uLong crc32;                /* crc32 of all data uncompressed */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   117
    uLong crc32_wait;           /* crc32 we must obtain after decompress all */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   118
    uLong rest_read_compressed; /* number of byte to be decompressed */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   119
    uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   120
    zlib_filefunc_def z_filefunc;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   121
    voidpf filestream;        /* io structore of the zipfile */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   122
    uLong compression_method;   /* compression method (0==store) */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   123
    uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   124
    int   raw;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   125
} file_in_zip_read_info_s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   126
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   127
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   128
/* unz_s contain internal information about the zipfile
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   129
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   130
typedef struct
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   131
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   132
    zlib_filefunc_def z_filefunc;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   133
    voidpf filestream;        /* io structore of the zipfile */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   134
    unz_global_info gi;       /* public global information */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   135
    uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   136
    uLong num_file;             /* number of the current file in the zipfile*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   137
    uLong pos_in_central_dir;   /* pos of the current file in the central dir*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   138
    uLong current_file_ok;      /* flag about the usability of the current file*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   139
    uLong central_pos;          /* position of the beginning of the central dir*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   140
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   141
    uLong size_central_dir;     /* size of the central directory  */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   142
    uLong offset_central_dir;   /* offset of start of central directory with
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   143
                                   respect to the starting disk number */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   144
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   145
    unz_file_info cur_file_info; /* public info about the current file in zip*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   146
    unz_file_info_internal cur_file_info_internal; /* private info about it*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   147
    file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   148
                                        file if we are decompressing it */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   149
    int encrypted;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   150
#    ifndef NOUNCRYPT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   151
    unsigned long keys[3];     /* keys defining the pseudo-random sequence */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   152
    const unsigned long* pcrc_32_tab;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   153
#    endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   154
} unz_s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   155
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   156
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   157
#ifndef NOUNCRYPT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   158
#include "crypt.h"
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   159
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   160
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   161
/* ===========================================================================
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   162
     Read a byte from a gz_stream; update next_in and avail_in. Return EOF
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   163
   for end of file.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   164
   IN assertion: the stream s has been sucessfully opened for reading.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   165
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   166
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   167
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   168
local int unzlocal_getByte OF((
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   169
    const zlib_filefunc_def* pzlib_filefunc_def,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   170
    voidpf filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   171
    int *pi));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   172
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   173
local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   174
    const zlib_filefunc_def* pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   175
    voidpf filestream;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   176
    int *pi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   177
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   178
    unsigned char c;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   179
    int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   180
    if (err==1)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   181
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   182
        *pi = (int)c;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   183
        return UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   184
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   185
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   186
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   187
        if (ZERROR(*pzlib_filefunc_def,filestream))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   188
            return UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   189
        else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   190
            return UNZ_EOF;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   191
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   192
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   193
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   194
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   195
/* ===========================================================================
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   196
   Reads a long in LSB order from the given gz_stream. Sets
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   197
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   198
local int unzlocal_getShort OF((
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   199
    const zlib_filefunc_def* pzlib_filefunc_def,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   200
    voidpf filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   201
    uLong *pX));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   202
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   203
local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   204
    const zlib_filefunc_def* pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   205
    voidpf filestream;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   206
    uLong *pX;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   207
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   208
    uLong x ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   209
    int i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   210
    int err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   211
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   212
    err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   213
    x = (uLong)i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   214
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   215
    if (err==UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   216
        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   217
    x += ((uLong)i)<<8;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   218
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   219
    if (err==UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   220
        *pX = x;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   221
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   222
        *pX = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   223
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   224
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   225
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   226
local int unzlocal_getLong OF((
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   227
    const zlib_filefunc_def* pzlib_filefunc_def,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   228
    voidpf filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   229
    uLong *pX));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   230
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   231
local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   232
    const zlib_filefunc_def* pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   233
    voidpf filestream;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   234
    uLong *pX;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   235
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   236
    uLong x ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   237
    int i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   238
    int err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   239
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   240
    err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   241
    x = (uLong)i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   242
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   243
    if (err==UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   244
        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   245
    x += ((uLong)i)<<8;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   246
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   247
    if (err==UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   248
        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   249
    x += ((uLong)i)<<16;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   250
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   251
    if (err==UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   252
        err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   253
    x += ((uLong)i)<<24;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   254
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   255
    if (err==UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   256
        *pX = x;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   257
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   258
        *pX = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   259
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   260
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   261
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   262
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   263
/* My own strcmpi / strcasecmp */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   264
local int strcmpcasenosensitive_internal (fileName1,fileName2)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   265
    const char* fileName1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   266
    const char* fileName2;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   267
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   268
    for (;;)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   269
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   270
        char c1=*(fileName1++);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   271
        char c2=*(fileName2++);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   272
        if ((c1>='a') && (c1<='z'))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   273
            c1 -= 0x20;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   274
        if ((c2>='a') && (c2<='z'))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   275
            c2 -= 0x20;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   276
        if (c1=='\0')
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   277
            return ((c2=='\0') ? 0 : -1);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   278
        if (c2=='\0')
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   279
            return 1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   280
        if (c1<c2)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   281
            return -1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   282
        if (c1>c2)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   283
            return 1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   284
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   285
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   286
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   287
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   288
#ifdef  CASESENSITIVITYDEFAULT_NO
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   289
#define CASESENSITIVITYDEFAULTVALUE 2
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   290
#else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   291
#define CASESENSITIVITYDEFAULTVALUE 1
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   292
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   293
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   294
#ifndef STRCMPCASENOSENTIVEFUNCTION
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   295
#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   296
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   297
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   298
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   299
   Compare two filename (fileName1,fileName2).
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   300
   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   301
   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   302
                                                                or strcasecmp)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   303
   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   304
        (like 1 on Unix, 2 on Windows)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   305
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   306
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   307
extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   308
    const char* fileName1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   309
    const char* fileName2;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   310
    int iCaseSensitivity;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   311
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   312
    if (iCaseSensitivity==0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   313
        iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   314
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   315
    if (iCaseSensitivity==1)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   316
        return strcmp(fileName1,fileName2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   317
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   318
    return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   319
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   320
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   321
#ifndef BUFREADCOMMENT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   322
#define BUFREADCOMMENT (0x400)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   323
#endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   324
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   325
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   326
  Locate the Central directory of a zipfile (at the end, just before
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   327
    the global comment)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   328
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   329
local uLong unzlocal_SearchCentralDir OF((
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   330
    const zlib_filefunc_def* pzlib_filefunc_def,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   331
    voidpf filestream));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   332
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   333
local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   334
    const zlib_filefunc_def* pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   335
    voidpf filestream;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   336
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   337
    unsigned char* buf;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   338
    uLong uSizeFile;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   339
    uLong uBackRead;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   340
    uLong uMaxBack=0xffff; /* maximum size of global comment */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   341
    uLong uPosFound=0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   342
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   343
    if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   344
        return 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   345
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   346
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   347
    uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   348
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   349
    if (uMaxBack>uSizeFile)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   350
        uMaxBack = uSizeFile;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   351
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   352
    buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   353
    if (buf==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   354
        return 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   355
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   356
    uBackRead = 4;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   357
    while (uBackRead<uMaxBack)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   358
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   359
        uLong uReadSize,uReadPos ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   360
        int i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   361
        if (uBackRead+BUFREADCOMMENT>uMaxBack)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   362
            uBackRead = uMaxBack;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   363
        else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   364
            uBackRead+=BUFREADCOMMENT;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   365
        uReadPos = uSizeFile-uBackRead ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   366
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   367
        uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   368
                     (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   369
        if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   370
            break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   371
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   372
        if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   373
            break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   374
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   375
        for (i=(int)uReadSize-3; (i--)>0;)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   376
            if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   377
                ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   378
            {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   379
                uPosFound = uReadPos+i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   380
                break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   381
            }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   382
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   383
        if (uPosFound!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   384
            break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   385
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   386
    TRYFREE(buf);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   387
    return uPosFound;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   388
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   389
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   390
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   391
  Open a Zip file. path contain the full pathname (by example,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   392
     on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   393
     "zlib/zlib114.zip".
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   394
     If the zipfile cannot be opened (file doesn't exist or in not valid), the
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   395
       return value is NULL.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   396
     Else, the return value is a unzFile Handle, usable with other function
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   397
       of this unzip package.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   398
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   399
extern unzFile ZEXPORT unzOpen2 (file, pzlib_filefunc_def)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   400
    voidpf file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   401
    zlib_filefunc_def* pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   402
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   403
    unz_s us;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   404
    unz_s *s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   405
    uLong central_pos,uL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   406
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   407
    uLong number_disk;          /* number of the current dist, used for
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   408
                                   spaning ZIP, unsupported, always 0*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   409
    uLong number_disk_with_CD;  /* number the the disk with central dir, used
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   410
                                   for spaning ZIP, unsupported, always 0*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   411
    uLong number_entry_CD;      /* total number of entries in
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   412
                                   the central dir
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   413
                                   (same than number_entry on nospan) */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   414
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   415
    int err=UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   416
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   417
    if (unz_copyright[0]!=' ')
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   418
        return NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   419
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   420
    if (pzlib_filefunc_def==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   421
        fill_qiodevice_filefunc(&us.z_filefunc);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   422
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   423
        us.z_filefunc = *pzlib_filefunc_def;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   424
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   425
    us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   426
                                                 file,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   427
                                                 ZLIB_FILEFUNC_MODE_READ |
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   428
                                                 ZLIB_FILEFUNC_MODE_EXISTING);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   429
    if (us.filestream==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   430
        return NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   431
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   432
    central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   433
    if (central_pos==0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   434
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   435
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   436
    if (ZSEEK(us.z_filefunc, us.filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   437
                                      central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   438
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   439
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   440
    /* the signature, already checked */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   441
    if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   442
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   443
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   444
    /* number of this disk */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   445
    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   446
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   447
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   448
    /* number of the disk with the start of the central directory */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   449
    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   450
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   451
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   452
    /* total number of entries in the central dir on this disk */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   453
    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   454
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   455
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   456
    /* total number of entries in the central dir */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   457
    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   458
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   459
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   460
    if ((number_entry_CD!=us.gi.number_entry) ||
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   461
        (number_disk_with_CD!=0) ||
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   462
        (number_disk!=0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   463
        err=UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   464
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   465
    /* size of the central directory */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   466
    if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   467
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   468
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   469
    /* offset of start of central directory with respect to the
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   470
          starting disk number */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   471
    if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   472
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   473
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   474
    /* zipfile comment length */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   475
    if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   476
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   477
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   478
    if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   479
        (err==UNZ_OK))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   480
        err=UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   481
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   482
    if (err!=UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   483
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   484
        ZCLOSE(us.z_filefunc, us.filestream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   485
        return NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   486
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   487
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   488
    us.byte_before_the_zipfile = central_pos -
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   489
                            (us.offset_central_dir+us.size_central_dir);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   490
    us.central_pos = central_pos;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   491
    us.pfile_in_zip_read = NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   492
    us.encrypted = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   493
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   494
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   495
    s=(unz_s*)ALLOC(sizeof(unz_s));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   496
    *s=us;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   497
    unzGoToFirstFile((unzFile)s);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   498
    return (unzFile)s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   499
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   500
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   501
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   502
extern unzFile ZEXPORT unzOpen (file)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   503
    voidpf file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   504
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   505
    return unzOpen2(file, NULL);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   506
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   507
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   508
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   509
  Close a ZipFile opened with unzipOpen.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   510
  If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   511
    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   512
  return UNZ_OK if there is no problem. */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   513
extern int ZEXPORT unzClose (file)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   514
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   515
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   516
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   517
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   518
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   519
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   520
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   521
    if (s->pfile_in_zip_read!=NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   522
        unzCloseCurrentFile(file);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   523
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   524
    ZCLOSE(s->z_filefunc, s->filestream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   525
    TRYFREE(s);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   526
    return UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   527
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   528
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   529
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   530
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   531
  Write info about the ZipFile in the *pglobal_info structure.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   532
  No preparation of the structure is needed
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   533
  return UNZ_OK if there is no problem. */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   534
extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   535
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   536
    unz_global_info *pglobal_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   537
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   538
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   539
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   540
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   541
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   542
    *pglobal_info=s->gi;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   543
    return UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   544
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   545
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   546
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   547
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   548
   Translate date/time from Dos format to tm_unz (readable more easilty)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   549
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   550
local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   551
    uLong ulDosDate;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   552
    tm_unz* ptm;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   553
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   554
    uLong uDate;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   555
    uDate = (uLong)(ulDosDate>>16);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   556
    ptm->tm_mday = (uInt)(uDate&0x1f) ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   557
    ptm->tm_mon =  (uInt)((((uDate)&0x1E0)/0x20)-1) ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   558
    ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   559
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   560
    ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   561
    ptm->tm_min =  (uInt) ((ulDosDate&0x7E0)/0x20) ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   562
    ptm->tm_sec =  (uInt) (2*(ulDosDate&0x1f)) ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   563
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   564
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   565
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   566
  Get Info about the current file in the zipfile, with internal only info
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   567
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   568
local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   569
                                                  unz_file_info *pfile_info,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   570
                                                  unz_file_info_internal
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   571
                                                  *pfile_info_internal,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   572
                                                  char *szFileName,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   573
                                                  uLong fileNameBufferSize,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   574
                                                  void *extraField,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   575
                                                  uLong extraFieldBufferSize,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   576
                                                  char *szComment,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   577
                                                  uLong commentBufferSize));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   578
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   579
local int unzlocal_GetCurrentFileInfoInternal (file,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   580
                                              pfile_info,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   581
                                              pfile_info_internal,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   582
                                              szFileName, fileNameBufferSize,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   583
                                              extraField, extraFieldBufferSize,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   584
                                              szComment,  commentBufferSize)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   585
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   586
    unz_file_info *pfile_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   587
    unz_file_info_internal *pfile_info_internal;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   588
    char *szFileName;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   589
    uLong fileNameBufferSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   590
    void *extraField;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   591
    uLong extraFieldBufferSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   592
    char *szComment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   593
    uLong commentBufferSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   594
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   595
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   596
    unz_file_info file_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   597
    unz_file_info_internal file_info_internal;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   598
    int err=UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   599
    uLong uMagic;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   600
    uLong uSeek=0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   601
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   602
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   603
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   604
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   605
    if (ZSEEK(s->z_filefunc, s->filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   606
              s->pos_in_central_dir+s->byte_before_the_zipfile,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   607
              ZLIB_FILEFUNC_SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   608
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   609
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   610
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   611
    /* we check the magic */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   612
    if (err==UNZ_OK) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   613
        if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   614
            err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   615
        else if (uMagic!=0x02014b50)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   616
            err=UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   617
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   618
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   619
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   620
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   621
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   622
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   623
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   624
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   625
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   626
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   627
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   628
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   629
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   630
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   631
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   632
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   633
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   634
    unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   635
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   636
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   637
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   638
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   639
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   640
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   641
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   642
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   643
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   644
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   645
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   646
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   647
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   648
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   649
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   650
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   651
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   652
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   653
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   654
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   655
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   656
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   657
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   658
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   659
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   660
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   661
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   662
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   663
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   664
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   665
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   666
    uSeek+=file_info.size_filename;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   667
    if ((err==UNZ_OK) && (szFileName!=NULL))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   668
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   669
        uLong uSizeRead ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   670
        if (file_info.size_filename<fileNameBufferSize)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   671
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   672
            *(szFileName+file_info.size_filename)='\0';
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   673
            uSizeRead = file_info.size_filename;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   674
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   675
        else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   676
            uSizeRead = fileNameBufferSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   677
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   678
        if ((file_info.size_filename>0) && (fileNameBufferSize>0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   679
            if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   680
                err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   681
        uSeek -= uSizeRead;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   682
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   683
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   684
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   685
    if ((err==UNZ_OK) && (extraField!=NULL))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   686
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   687
        uLong uSizeRead ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   688
        if (file_info.size_file_extra<extraFieldBufferSize)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   689
            uSizeRead = file_info.size_file_extra;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   690
        else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   691
            uSizeRead = extraFieldBufferSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   692
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   693
        if (uSeek!=0) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   694
            if (ZSEEK(s->z_filefunc, s->filestream,uSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   695
                uSeek=0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   696
            else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   697
                err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   698
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   699
        if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   700
            if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   701
                err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   702
        uSeek += file_info.size_file_extra - uSizeRead;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   703
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   704
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   705
        uSeek+=file_info.size_file_extra;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   706
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   707
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   708
    if ((err==UNZ_OK) && (szComment!=NULL))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   709
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   710
        uLong uSizeRead ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   711
        if (file_info.size_file_comment<commentBufferSize)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   712
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   713
            *(szComment+file_info.size_file_comment)='\0';
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   714
            uSizeRead = file_info.size_file_comment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   715
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   716
        else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   717
            uSizeRead = commentBufferSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   718
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   719
        if (uSeek!=0) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   720
            if (ZSEEK(s->z_filefunc, s->filestream,uSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   721
                uSeek=0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   722
            else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   723
                err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   724
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   725
        if ((file_info.size_file_comment>0) && (commentBufferSize>0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   726
            if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   727
                err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   728
        uSeek+=file_info.size_file_comment - uSizeRead;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   729
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   730
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   731
        uSeek+=file_info.size_file_comment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   732
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   733
    if ((err==UNZ_OK) && (pfile_info!=NULL))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   734
        *pfile_info=file_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   735
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   736
    if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   737
        *pfile_info_internal=file_info_internal;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   738
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   739
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   740
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   741
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   742
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   743
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   744
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   745
  Write info about the ZipFile in the *pglobal_info structure.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   746
  No preparation of the structure is needed
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   747
  return UNZ_OK if there is no problem.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   748
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   749
extern int ZEXPORT unzGetCurrentFileInfo (file,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   750
                                          pfile_info,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   751
                                          szFileName, fileNameBufferSize,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   752
                                          extraField, extraFieldBufferSize,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   753
                                          szComment,  commentBufferSize)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   754
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   755
    unz_file_info *pfile_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   756
    char *szFileName;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   757
    uLong fileNameBufferSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   758
    void *extraField;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   759
    uLong extraFieldBufferSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   760
    char *szComment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   761
    uLong commentBufferSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   762
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   763
    return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   764
                                                szFileName,fileNameBufferSize,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   765
                                                extraField,extraFieldBufferSize,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   766
                                                szComment,commentBufferSize);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   767
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   768
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   769
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   770
  Set the current file of the zipfile to the first file.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   771
  return UNZ_OK if there is no problem
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   772
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   773
extern int ZEXPORT unzGoToFirstFile (file)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   774
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   775
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   776
    int err=UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   777
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   778
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   779
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   780
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   781
    s->pos_in_central_dir=s->offset_central_dir;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   782
    s->num_file=0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   783
    err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   784
                                             &s->cur_file_info_internal,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   785
                                             NULL,0,NULL,0,NULL,0);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   786
    s->current_file_ok = (err == UNZ_OK);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   787
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   788
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   789
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   790
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   791
  Set the current file of the zipfile to the next file.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   792
  return UNZ_OK if there is no problem
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   793
  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   794
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   795
extern int ZEXPORT unzGoToNextFile (file)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   796
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   797
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   798
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   799
    int err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   800
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   801
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   802
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   803
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   804
    if (!s->current_file_ok)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   805
        return UNZ_END_OF_LIST_OF_FILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   806
    if (s->gi.number_entry != 0xffff)    /* 2^16 files overflow hack */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   807
      if (s->num_file+1==s->gi.number_entry)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   808
        return UNZ_END_OF_LIST_OF_FILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   809
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   810
    s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   811
            s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   812
    s->num_file++;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   813
    err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   814
                                               &s->cur_file_info_internal,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   815
                                               NULL,0,NULL,0,NULL,0);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   816
    s->current_file_ok = (err == UNZ_OK);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   817
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   818
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   819
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   820
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   821
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   822
  Try locate the file szFileName in the zipfile.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   823
  For the iCaseSensitivity signification, see unzipStringFileNameCompare
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   824
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   825
  return value :
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   826
  UNZ_OK if the file is found. It becomes the current file.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   827
  UNZ_END_OF_LIST_OF_FILE if the file is not found
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   828
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   829
extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   830
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   831
    const char *szFileName;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   832
    int iCaseSensitivity;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   833
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   834
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   835
    int err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   836
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   837
    /* We remember the 'current' position in the file so that we can jump
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   838
     * back there if we fail.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   839
     */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   840
    unz_file_info cur_file_infoSaved;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   841
    unz_file_info_internal cur_file_info_internalSaved;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   842
    uLong num_fileSaved;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   843
    uLong pos_in_central_dirSaved;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   844
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   845
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   846
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   847
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   848
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   849
    if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   850
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   851
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   852
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   853
    if (!s->current_file_ok)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   854
        return UNZ_END_OF_LIST_OF_FILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   855
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   856
    /* Save the current state */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   857
    num_fileSaved = s->num_file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   858
    pos_in_central_dirSaved = s->pos_in_central_dir;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   859
    cur_file_infoSaved = s->cur_file_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   860
    cur_file_info_internalSaved = s->cur_file_info_internal;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   861
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   862
    err = unzGoToFirstFile(file);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   863
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   864
    while (err == UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   865
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   866
        char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   867
        err = unzGetCurrentFileInfo(file,NULL,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   868
                                    szCurrentFileName,sizeof(szCurrentFileName)-1,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   869
                                    NULL,0,NULL,0);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   870
        if (err == UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   871
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   872
            if (unzStringFileNameCompare(szCurrentFileName,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   873
                                            szFileName,iCaseSensitivity)==0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   874
                return UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   875
            err = unzGoToNextFile(file);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   876
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   877
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   878
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   879
    /* We failed, so restore the state of the 'current file' to where we
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   880
     * were.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   881
     */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   882
    s->num_file = num_fileSaved ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   883
    s->pos_in_central_dir = pos_in_central_dirSaved ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   884
    s->cur_file_info = cur_file_infoSaved;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   885
    s->cur_file_info_internal = cur_file_info_internalSaved;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   886
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   887
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   888
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   889
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   890
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   891
///////////////////////////////////////////
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   892
// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   893
// I need random access
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   894
//
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   895
// Further optimization could be realized by adding an ability
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   896
// to cache the directory in memory. The goal being a single
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   897
// comprehensive file read to put the file I need in a memory.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   898
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   899
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   900
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   901
typedef struct unz_file_pos_s
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   902
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   903
    uLong pos_in_zip_directory;   // offset in file
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   904
    uLong num_of_file;            // # of file
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   905
} unz_file_pos;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   906
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   907
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   908
extern int ZEXPORT unzGetFilePos(file, file_pos)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   909
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   910
    unz_file_pos* file_pos;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   911
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   912
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   913
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   914
    if (file==NULL || file_pos==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   915
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   916
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   917
    if (!s->current_file_ok)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   918
        return UNZ_END_OF_LIST_OF_FILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   919
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   920
    file_pos->pos_in_zip_directory  = s->pos_in_central_dir;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   921
    file_pos->num_of_file           = s->num_file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   922
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   923
    return UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   924
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   925
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   926
extern int ZEXPORT unzGoToFilePos(file, file_pos)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   927
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   928
    unz_file_pos* file_pos;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   929
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   930
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   931
    int err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   932
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   933
    if (file==NULL || file_pos==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   934
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   935
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   936
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   937
    /* jump to the right spot */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   938
    s->pos_in_central_dir = file_pos->pos_in_zip_directory;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   939
    s->num_file           = file_pos->num_of_file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   940
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   941
    /* set the current file */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   942
    err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   943
                                               &s->cur_file_info_internal,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   944
                                               NULL,0,NULL,0,NULL,0);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   945
    /* return results */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   946
    s->current_file_ok = (err == UNZ_OK);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   947
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   948
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   949
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   950
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   951
// Unzip Helper Functions - should be here?
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   952
///////////////////////////////////////////
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   953
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   954
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   955
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   956
  Read the local header of the current zipfile
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   957
  Check the coherency of the local header and info in the end of central
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   958
        directory about this file
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   959
  store in *piSizeVar the size of extra info in local header
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   960
        (filename and size of extra field data)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   961
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   962
local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   963
                                                    poffset_local_extrafield,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   964
                                                    psize_local_extrafield)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   965
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   966
    uInt* piSizeVar;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   967
    uLong *poffset_local_extrafield;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   968
    uInt  *psize_local_extrafield;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   969
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   970
    uLong uMagic,uData,uFlags;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   971
    uLong size_filename;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   972
    uLong size_extra_field;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   973
    int err=UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   974
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   975
    *piSizeVar = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   976
    *poffset_local_extrafield = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   977
    *psize_local_extrafield = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   978
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   979
    if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   980
                                s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   981
        return UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   982
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   983
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   984
    if (err==UNZ_OK) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   985
        if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   986
            err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   987
        else if (uMagic!=0x04034b50)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   988
            err=UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   989
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   990
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   991
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   992
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   993
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   994
    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   995
        err=UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   996
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   997
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   998
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   999
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1000
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1001
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1002
    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1003
        err=UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1004
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1005
    if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1006
                         (s->cur_file_info.compression_method!=Z_DEFLATED))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1007
        err=UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1008
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1009
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1010
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1011
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1012
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1013
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1014
    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1015
                              ((uFlags & 8)==0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1016
        err=UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1017
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1018
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1019
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1020
    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1021
                              ((uFlags & 8)==0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1022
        err=UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1023
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1024
    if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1025
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1026
    else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1027
                              ((uFlags & 8)==0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1028
        err=UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1029
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1030
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1031
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1032
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1033
    else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1034
        err=UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1035
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1036
    *piSizeVar += (uInt)size_filename;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1037
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1038
    if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1039
        err=UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1040
    *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1041
                                    SIZEZIPLOCALHEADER + size_filename;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1042
    *psize_local_extrafield = (uInt)size_extra_field;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1043
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1044
    *piSizeVar += (uInt)size_extra_field;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1045
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1046
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1047
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1048
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1049
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1050
  Open for reading data the current file in the zipfile.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1051
  If there is no error and the file is opened, the return value is UNZ_OK.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1052
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1053
extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1054
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1055
    int* method;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1056
    int* level;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1057
    int raw;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1058
    const char* password;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1059
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1060
    int err=UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1061
    uInt iSizeVar;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1062
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1063
    file_in_zip_read_info_s* pfile_in_zip_read_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1064
    uLong offset_local_extrafield;  /* offset of the local extra field */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1065
    uInt  size_local_extrafield;    /* size of the local extra field */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1066
#    ifndef NOUNCRYPT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1067
    char source[12];
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1068
#    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1069
    if (password != NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1070
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1071
#    endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1072
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1073
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1074
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1075
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1076
    if (!s->current_file_ok)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1077
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1078
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1079
    if (s->pfile_in_zip_read != NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1080
        unzCloseCurrentFile(file);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1081
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1082
    if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1083
                &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1084
        return UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1085
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1086
    pfile_in_zip_read_info = (file_in_zip_read_info_s*)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1087
                                        ALLOC(sizeof(file_in_zip_read_info_s));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1088
    if (pfile_in_zip_read_info==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1089
        return UNZ_INTERNALERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1090
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1091
    pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1092
    pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1093
    pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1094
    pfile_in_zip_read_info->pos_local_extrafield=0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1095
    pfile_in_zip_read_info->raw=raw;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1096
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1097
    if (pfile_in_zip_read_info->read_buffer==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1098
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1099
        TRYFREE(pfile_in_zip_read_info);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1100
        return UNZ_INTERNALERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1101
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1102
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1103
    pfile_in_zip_read_info->stream_initialised=0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1104
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1105
    if (method!=NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1106
        *method = (int)s->cur_file_info.compression_method;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1107
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1108
    if (level!=NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1109
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1110
        *level = 6;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1111
        switch (s->cur_file_info.flag & 0x06)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1112
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1113
          case 6 : *level = 1; break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1114
          case 4 : *level = 2; break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1115
          case 2 : *level = 9; break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1116
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1117
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1118
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1119
    if ((s->cur_file_info.compression_method!=0) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1120
        (s->cur_file_info.compression_method!=Z_DEFLATED))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1121
        err=UNZ_BADZIPFILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1122
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1123
    pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1124
    pfile_in_zip_read_info->crc32=0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1125
    pfile_in_zip_read_info->compression_method =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1126
            s->cur_file_info.compression_method;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1127
    pfile_in_zip_read_info->filestream=s->filestream;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1128
    pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1129
    pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1130
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1131
    pfile_in_zip_read_info->stream.total_out = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1132
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1133
    if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1134
        (!raw))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1135
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1136
      pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1137
      pfile_in_zip_read_info->stream.zfree = (free_func)0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1138
      pfile_in_zip_read_info->stream.opaque = (voidpf)0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1139
      pfile_in_zip_read_info->stream.next_in = (voidpf)0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1140
      pfile_in_zip_read_info->stream.avail_in = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1141
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1142
      err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1143
      if (err == Z_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1144
        pfile_in_zip_read_info->stream_initialised=1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1145
      else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1146
      {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1147
        TRYFREE(pfile_in_zip_read_info);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1148
        return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1149
      }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1150
        /* windowBits is passed < 0 to tell that there is no zlib header.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1151
         * Note that in this case inflate *requires* an extra "dummy" byte
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1152
         * after the compressed stream in order to complete decompression and
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1153
         * return Z_STREAM_END.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1154
         * In unzip, i don't wait absolutely Z_STREAM_END because I known the
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1155
         * size of both compressed and uncompressed data
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1156
         */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1157
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1158
    pfile_in_zip_read_info->rest_read_compressed =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1159
            s->cur_file_info.compressed_size ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1160
    pfile_in_zip_read_info->rest_read_uncompressed =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1161
            s->cur_file_info.uncompressed_size ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1162
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1163
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1164
    pfile_in_zip_read_info->pos_in_zipfile =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1165
            s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1166
              iSizeVar;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1167
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1168
    pfile_in_zip_read_info->stream.avail_in = (uInt)0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1169
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1170
    s->pfile_in_zip_read = pfile_in_zip_read_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1171
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1172
#    ifndef NOUNCRYPT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1173
    if (password != NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1174
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1175
        int i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1176
        s->pcrc_32_tab = get_crc_table();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1177
        init_keys(password,s->keys,s->pcrc_32_tab);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1178
        if (ZSEEK(s->z_filefunc, s->filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1179
                  s->pfile_in_zip_read->pos_in_zipfile +
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1180
                     s->pfile_in_zip_read->byte_before_the_zipfile,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1181
                  SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1182
            return UNZ_INTERNALERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1183
        if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1184
            return UNZ_INTERNALERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1185
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1186
        for (i = 0; i<12; i++)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1187
            zdecode(s->keys,s->pcrc_32_tab,source[i]);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1188
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1189
        s->pfile_in_zip_read->pos_in_zipfile+=12;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1190
        s->encrypted=1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1191
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1192
#    endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1193
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1194
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1195
    return UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1196
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1197
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1198
extern int ZEXPORT unzOpenCurrentFile (file)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1199
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1200
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1201
    return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1202
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1203
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1204
extern int ZEXPORT unzOpenCurrentFilePassword (file, password)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1205
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1206
    const char* password;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1207
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1208
    return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1209
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1210
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1211
extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1212
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1213
    int* method;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1214
    int* level;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1215
    int raw;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1216
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1217
    return unzOpenCurrentFile3(file, method, level, raw, NULL);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1218
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1219
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1220
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1221
  Read bytes from the current file.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1222
  buf contain buffer where data must be copied
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1223
  len the size of buf.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1224
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1225
  return the number of byte copied if somes bytes are copied
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1226
  return 0 if the end of file was reached
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1227
  return <0 with error code if there is an error
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1228
    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1229
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1230
extern int ZEXPORT unzReadCurrentFile  (file, buf, len)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1231
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1232
    voidp buf;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1233
    unsigned len;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1234
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1235
    int err=UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1236
    uInt iRead = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1237
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1238
    file_in_zip_read_info_s* pfile_in_zip_read_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1239
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1240
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1241
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1242
    pfile_in_zip_read_info=s->pfile_in_zip_read;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1243
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1244
    if (pfile_in_zip_read_info==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1245
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1246
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1247
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1248
    if ((pfile_in_zip_read_info->read_buffer == NULL))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1249
        return UNZ_END_OF_LIST_OF_FILE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1250
    if (len==0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1251
        return 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1252
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1253
    pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1254
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1255
    pfile_in_zip_read_info->stream.avail_out = (uInt)len;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1256
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1257
    if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1258
        (!(pfile_in_zip_read_info->raw)))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1259
        pfile_in_zip_read_info->stream.avail_out =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1260
            (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1261
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1262
    if ((len>pfile_in_zip_read_info->rest_read_compressed+
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1263
           pfile_in_zip_read_info->stream.avail_in) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1264
         (pfile_in_zip_read_info->raw))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1265
        pfile_in_zip_read_info->stream.avail_out =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1266
            (uInt)pfile_in_zip_read_info->rest_read_compressed+
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1267
            pfile_in_zip_read_info->stream.avail_in;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1268
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1269
    while (pfile_in_zip_read_info->stream.avail_out>0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1270
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1271
        if ((pfile_in_zip_read_info->stream.avail_in==0) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1272
            (pfile_in_zip_read_info->rest_read_compressed>0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1273
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1274
            uInt uReadThis = UNZ_BUFSIZE;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1275
            if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1276
                uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1277
            if (uReadThis == 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1278
                return UNZ_EOF;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1279
            if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1280
                      pfile_in_zip_read_info->filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1281
                      pfile_in_zip_read_info->pos_in_zipfile +
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1282
                         pfile_in_zip_read_info->byte_before_the_zipfile,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1283
                         ZLIB_FILEFUNC_SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1284
                return UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1285
            if (ZREAD(pfile_in_zip_read_info->z_filefunc,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1286
                      pfile_in_zip_read_info->filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1287
                      pfile_in_zip_read_info->read_buffer,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1288
                      uReadThis)!=uReadThis)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1289
                return UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1290
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1291
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1292
#            ifndef NOUNCRYPT
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1293
            if(s->encrypted)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1294
            {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1295
                uInt i;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1296
                for(i=0;i<uReadThis;i++)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1297
                  pfile_in_zip_read_info->read_buffer[i] =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1298
                      zdecode(s->keys,s->pcrc_32_tab,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1299
                              pfile_in_zip_read_info->read_buffer[i]);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1300
            }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1301
#            endif
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1302
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1303
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1304
            pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1305
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1306
            pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1307
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1308
            pfile_in_zip_read_info->stream.next_in =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1309
                (Bytef*)pfile_in_zip_read_info->read_buffer;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1310
            pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1311
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1312
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1313
        if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1314
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1315
            uInt uDoCopy,i ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1316
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1317
            if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1318
                (pfile_in_zip_read_info->rest_read_compressed == 0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1319
                return (iRead==0) ? UNZ_EOF : iRead;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1320
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1321
            if (pfile_in_zip_read_info->stream.avail_out <
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1322
                            pfile_in_zip_read_info->stream.avail_in)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1323
                uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1324
            else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1325
                uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1326
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1327
            for (i=0;i<uDoCopy;i++)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1328
                *(pfile_in_zip_read_info->stream.next_out+i) =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1329
                        *(pfile_in_zip_read_info->stream.next_in+i);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1330
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1331
            pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1332
                                pfile_in_zip_read_info->stream.next_out,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1333
                                uDoCopy);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1334
            pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1335
            pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1336
            pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1337
            pfile_in_zip_read_info->stream.next_out += uDoCopy;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1338
            pfile_in_zip_read_info->stream.next_in += uDoCopy;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1339
            pfile_in_zip_read_info->stream.total_out += uDoCopy;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1340
            iRead += uDoCopy;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1341
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1342
        else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1343
        {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1344
            uLong uTotalOutBefore,uTotalOutAfter;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1345
            const Bytef *bufBefore;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1346
            uLong uOutThis;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1347
            int flush=Z_SYNC_FLUSH;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1348
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1349
            uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1350
            bufBefore = pfile_in_zip_read_info->stream.next_out;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1351
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1352
            /*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1353
            if ((pfile_in_zip_read_info->rest_read_uncompressed ==
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1354
                     pfile_in_zip_read_info->stream.avail_out) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1355
                (pfile_in_zip_read_info->rest_read_compressed == 0))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1356
                flush = Z_FINISH;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1357
            */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1358
            err=inflate(&pfile_in_zip_read_info->stream,flush);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1359
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1360
            if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1361
              err = Z_DATA_ERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1362
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1363
            uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1364
            uOutThis = uTotalOutAfter-uTotalOutBefore;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1365
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1366
            pfile_in_zip_read_info->crc32 =
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1367
                crc32(pfile_in_zip_read_info->crc32,bufBefore,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1368
                        (uInt)(uOutThis));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1369
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1370
            pfile_in_zip_read_info->rest_read_uncompressed -=
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1371
                uOutThis;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1372
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1373
            iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1374
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1375
            if (err==Z_STREAM_END)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1376
                return (iRead==0) ? UNZ_EOF : iRead;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1377
            if (err!=Z_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1378
                break;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1379
        }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1380
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1381
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1382
    if (err==Z_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1383
        return iRead;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1384
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1385
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1386
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1387
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1388
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1389
  Give the current position in uncompressed data
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1390
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1391
extern z_off_t ZEXPORT unztell (file)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1392
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1393
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1394
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1395
    file_in_zip_read_info_s* pfile_in_zip_read_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1396
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1397
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1398
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1399
    pfile_in_zip_read_info=s->pfile_in_zip_read;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1400
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1401
    if (pfile_in_zip_read_info==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1402
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1403
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1404
    return (z_off_t)pfile_in_zip_read_info->stream.total_out;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1405
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1406
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1407
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1408
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1409
  return 1 if the end of file was reached, 0 elsewhere
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1410
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1411
extern int ZEXPORT unzeof (file)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1412
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1413
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1414
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1415
    file_in_zip_read_info_s* pfile_in_zip_read_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1416
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1417
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1418
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1419
    pfile_in_zip_read_info=s->pfile_in_zip_read;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1420
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1421
    if (pfile_in_zip_read_info==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1422
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1423
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1424
    if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1425
        return 1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1426
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1427
        return 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1428
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1429
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1430
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1431
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1432
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1433
  Read extra field from the current file (opened by unzOpenCurrentFile)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1434
  This is the local-header version of the extra field (sometimes, there is
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1435
    more info in the local-header version than in the central-header)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1436
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1437
  if buf==NULL, it return the size of the local extra field that can be read
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1438
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1439
  if buf!=NULL, len is the size of the buffer, the extra header is copied in
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1440
    buf.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1441
  the return value is the number of bytes copied in buf, or (if <0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1442
    the error code
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1443
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1444
extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1445
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1446
    voidp buf;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1447
    unsigned len;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1448
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1449
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1450
    file_in_zip_read_info_s* pfile_in_zip_read_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1451
    uInt read_now;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1452
    uLong size_to_read;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1453
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1454
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1455
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1456
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1457
    pfile_in_zip_read_info=s->pfile_in_zip_read;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1458
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1459
    if (pfile_in_zip_read_info==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1460
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1461
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1462
    size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1463
                pfile_in_zip_read_info->pos_local_extrafield);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1464
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1465
    if (buf==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1466
        return (int)size_to_read;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1467
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1468
    if (len>size_to_read)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1469
        read_now = (uInt)size_to_read;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1470
    else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1471
        read_now = (uInt)len ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1472
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1473
    if (read_now==0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1474
        return 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1475
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1476
    if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1477
              pfile_in_zip_read_info->filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1478
              pfile_in_zip_read_info->offset_local_extrafield +
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1479
              pfile_in_zip_read_info->pos_local_extrafield,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1480
              ZLIB_FILEFUNC_SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1481
        return UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1482
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1483
    if (ZREAD(pfile_in_zip_read_info->z_filefunc,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1484
              pfile_in_zip_read_info->filestream,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1485
              buf,read_now)!=read_now)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1486
        return UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1487
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1488
    return (int)read_now;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1489
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1490
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1491
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1492
  Close the file in zip opened with unzipOpenCurrentFile
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1493
  Return UNZ_CRCERROR if all the file was read but the CRC is not good
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1494
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1495
extern int ZEXPORT unzCloseCurrentFile (file)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1496
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1497
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1498
    int err=UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1499
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1500
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1501
    file_in_zip_read_info_s* pfile_in_zip_read_info;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1502
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1503
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1504
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1505
    pfile_in_zip_read_info=s->pfile_in_zip_read;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1506
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1507
    if (pfile_in_zip_read_info==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1508
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1509
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1510
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1511
    if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1512
        (!pfile_in_zip_read_info->raw))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1513
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1514
        if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1515
            err=UNZ_CRCERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1516
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1517
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1518
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1519
    TRYFREE(pfile_in_zip_read_info->read_buffer);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1520
    pfile_in_zip_read_info->read_buffer = NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1521
    if (pfile_in_zip_read_info->stream_initialised)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1522
        inflateEnd(&pfile_in_zip_read_info->stream);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1523
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1524
    pfile_in_zip_read_info->stream_initialised = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1525
    TRYFREE(pfile_in_zip_read_info);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1526
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1527
    s->pfile_in_zip_read=NULL;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1528
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1529
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1530
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1531
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1532
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1533
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1534
  Get the global comment string of the ZipFile, in the szComment buffer.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1535
  uSizeBuf is the size of the szComment buffer.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1536
  return the number of byte copied or an error code <0
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1537
*/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1538
extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1539
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1540
    char *szComment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1541
    uLong uSizeBuf;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1542
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1543
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1544
    uLong uReadThis ;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1545
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1546
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1547
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1548
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1549
    uReadThis = uSizeBuf;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1550
    if (uReadThis>s->gi.size_comment)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1551
        uReadThis = s->gi.size_comment;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1552
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1553
    if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1554
        return UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1555
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1556
    if (uReadThis>0)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1557
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1558
      *szComment='\0';
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1559
      if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1560
        return UNZ_ERRNO;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1561
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1562
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1563
    if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1564
        *(szComment+s->gi.size_comment)='\0';
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1565
    return (int)uReadThis;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1566
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1567
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1568
/* Additions by RX '2004 */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1569
extern uLong ZEXPORT unzGetOffset (file)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1570
    unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1571
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1572
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1573
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1574
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1575
          return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1576
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1577
    if (!s->current_file_ok)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1578
      return 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1579
    if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1580
      if (s->num_file==s->gi.number_entry)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1581
         return 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1582
    return s->pos_in_central_dir;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1583
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1584
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1585
extern int ZEXPORT unzSetOffset (file, pos)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1586
        unzFile file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1587
        uLong pos;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1588
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1589
    unz_s* s;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1590
    int err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1591
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1592
    if (file==NULL)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1593
        return UNZ_PARAMERROR;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1594
    s=(unz_s*)file;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1595
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1596
    s->pos_in_central_dir = pos;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1597
    s->num_file = s->gi.number_entry;      /* hack */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1598
    err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1599
                                              &s->cur_file_info_internal,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1600
                                              NULL,0,NULL,0,NULL,0);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1601
    s->current_file_ok = (err == UNZ_OK);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1602
    return err;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
  1603
}