archivers/unzip.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 02 Sep 2001 01:11:56 +0000
changeset 91 4a13fbf4a88a
parent 47 fbf5d37147eb
child 143 337505f94c10
permissions -rw-r--r--
Updated again.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/* unzip.c -- IO on .zip files using zlib 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
   Version 0.15 beta, Mar 19th, 1998,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
   Read unzip.h for more info
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
#include <stdio.h>
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#include <stdlib.h>
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#include <string.h>
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#include "zlib.h"
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include "unzip.h"
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#ifdef STDC
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#  include <stddef.h>
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#  include <string.h>
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#  include <stdlib.h>
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#ifdef NO_ERRNO_H
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
    extern int errno;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#   include <errno.h>
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
#ifndef local
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
#  define local static
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
/* compile with -Dlocal if your debugger can't find static symbols */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
                      !defined(CASESENSITIVITYDEFAULT_NO)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
#define CASESENSITIVITYDEFAULT_NO
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
#ifndef UNZ_BUFSIZE
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
#define UNZ_BUFSIZE (16384)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
#ifndef UNZ_MAXFILENAMEINZIP
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
#define UNZ_MAXFILENAMEINZIP (256)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
#ifndef ALLOC
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
# define ALLOC(size) (malloc(size))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
#ifndef TRYFREE
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
# define TRYFREE(p) {if (p) free(p);}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
#define SIZECENTRALDIRITEM (0x2e)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
#define SIZEZIPLOCALHEADER (0x1e)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
#ifndef SEEK_CUR
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
#define SEEK_CUR    1
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
#ifndef SEEK_END
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
#define SEEK_END    2
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
#ifndef SEEK_SET
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
#define SEEK_SET    0
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
const char unz_copyright[] =
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
   " unzip 0.15 Copyright 1998 Gilles Vollant ";
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
/* unz_file_info_interntal contain internal info about a file in zipfile*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
typedef struct unz_file_info_internal_s
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
    uLong offset_curfile;/* relative offset of local header 4 bytes */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
} unz_file_info_internal;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
/* file_in_zip_read_info_s contain internal information about a file in zipfile,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
    when reading and decompress it */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
typedef struct
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
	char  *read_buffer;         /* internal buffer for compressed data */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
	z_stream stream;            /* zLib stream structure for inflate */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
	uLong pos_in_zipfile;       /* position in byte on the zipfile, for fseek*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
	uLong stream_initialised;   /* flag set if stream structure is initialised*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
	uLong offset_local_extrafield;/* offset of the local extra field */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
	uInt  size_local_extrafield;/* size of the local extra field */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
	uLong pos_local_extrafield;   /* position in the local extra field in read*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
	uLong crc32;                /* crc32 of all data uncompressed */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
	uLong crc32_wait;           /* crc32 we must obtain after decompress all */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
	uLong rest_read_compressed; /* number of byte to be decompressed */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
	uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
	FILE* file;                 /* io structore of the zipfile */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
	uLong compression_method;   /* compression method (0==store) */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
	uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
} file_in_zip_read_info_s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
/* unz_s contain internal information about the zipfile
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
typedef struct
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
	FILE* file;                 /* io structore of the zipfile */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
	unz_global_info gi;       /* public global information */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
	uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
	uLong num_file;             /* number of the current file in the zipfile*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
	uLong pos_in_central_dir;   /* pos of the current file in the central dir*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
	uLong current_file_ok;      /* flag about the usability of the current file*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
	uLong central_pos;          /* position of the beginning of the central dir*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
	uLong size_central_dir;     /* size of the central directory  */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
	uLong offset_central_dir;   /* offset of start of central directory with
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
								   respect to the starting disk number */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
	unz_file_info cur_file_info; /* public info about the current file in zip*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
	unz_file_info_internal cur_file_info_internal; /* private info about it*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
    file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
	                                    file if we are decompressing it */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
} unz_s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
/* ===========================================================================
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
     Read a byte from a gz_stream; update next_in and avail_in. Return EOF
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
   for end of file.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
   IN assertion: the stream s has been sucessfully opened for reading.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
local int unzlocal_getByte(fin,pi)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
	FILE *fin;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
	int *pi;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    unsigned char c;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
	int err = fread(&c, 1, 1, fin);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
    if (err==1)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
    {
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
        *pi = (int)c;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
        return UNZ_OK;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
    }
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
    else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    {
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
        if (ferror(fin)) 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
            return UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
        else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
            return UNZ_EOF;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
    }
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
/* ===========================================================================
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
   Reads a long in LSB order from the given gz_stream. Sets 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
local int unzlocal_getShort (fin,pX)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
	FILE* fin;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
    uLong *pX;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
    uLong x ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
    int i;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
    int err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
    err = unzlocal_getByte(fin,&i);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
    x = (uLong)i;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
    
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
    if (err==UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
        err = unzlocal_getByte(fin,&i);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
    x += ((uLong)i)<<8;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
   
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
    if (err==UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
        *pX = x;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
        *pX = 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
    return err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
local int unzlocal_getLong (fin,pX)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
	FILE* fin;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
    uLong *pX;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
    uLong x ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
    int i;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
    int err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
    err = unzlocal_getByte(fin,&i);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
    x = (uLong)i;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
    
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
    if (err==UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
        err = unzlocal_getByte(fin,&i);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    x += ((uLong)i)<<8;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
    if (err==UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
        err = unzlocal_getByte(fin,&i);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
    x += ((uLong)i)<<16;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
    if (err==UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
        err = unzlocal_getByte(fin,&i);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
    x += ((uLong)i)<<24;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
   
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
    if (err==UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
        *pX = x;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
    else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
        *pX = 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
    return err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
/* My own strcmpi / strcasecmp */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
local int strcmpcasenosensitive_internal (fileName1,fileName2)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
	const char* fileName1;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
	const char* fileName2;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
	for (;;)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
		char c1=*(fileName1++);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
		char c2=*(fileName2++);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
		if ((c1>='a') && (c1<='z'))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
			c1 -= 0x20;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
		if ((c2>='a') && (c2<='z'))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
			c2 -= 0x20;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
		if (c1=='\0')
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
			return ((c2=='\0') ? 0 : -1);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
		if (c2=='\0')
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
			return 1;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
		if (c1<c2)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
			return -1;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
		if (c1>c2)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
			return 1;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
#ifdef  CASESENSITIVITYDEFAULT_NO
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
#define CASESENSITIVITYDEFAULTVALUE 2
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
#else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
#define CASESENSITIVITYDEFAULTVALUE 1
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
#ifndef STRCMPCASENOSENTIVEFUNCTION
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
#endif
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
/* 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
   Compare two filename (fileName1,fileName2).
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
                                                                or strcasecmp)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
        (like 1 on Unix, 2 on Windows)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
	const char* fileName1;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
	const char* fileName2;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
	int iCaseSensitivity;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
	if (iCaseSensitivity==0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
		iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
	if (iCaseSensitivity==1)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
		return strcmp(fileName1,fileName2);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
	return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
} 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
#define BUFREADCOMMENT (0x400)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
  Locate the Central directory of a zipfile (at the end, just before
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
    the global comment)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
local uLong unzlocal_SearchCentralDir(fin)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
	FILE *fin;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
	unsigned char* buf;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
	uLong uSizeFile;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
	uLong uBackRead;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
	uLong uMaxBack=0xffff; /* maximum size of global comment */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
	uLong uPosFound=0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
	if (fseek(fin,0,SEEK_END) != 0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
		return 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
	uSizeFile = ftell( fin );
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
	if (uMaxBack>uSizeFile)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
		uMaxBack = uSizeFile;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
	buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
	if (buf==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
		return 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
	uBackRead = 4;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
	while (uBackRead<uMaxBack)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
		uLong uReadSize,uReadPos ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
		int i;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
		if (uBackRead+BUFREADCOMMENT>uMaxBack) 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
			uBackRead = uMaxBack;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
		else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
			uBackRead+=BUFREADCOMMENT;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
		uReadPos = uSizeFile-uBackRead ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
		
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
		uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
                     (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
		if (fseek(fin,uReadPos,SEEK_SET)!=0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
			break;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
		if (fread(buf,(uInt)uReadSize,1,fin)!=1)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
			break;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
                for (i=(int)uReadSize-3; (i--)>0;)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
			if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
				((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
			{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
				uPosFound = uReadPos+i;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
				break;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
			}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
		if (uPosFound!=0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
			break;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
	TRYFREE(buf);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
	return uPosFound;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
  Open a Zip file. path contain the full pathname (by example,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
     on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
	 "zlib/zlib109.zip".
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
	 If the zipfile cannot be opened (file don't exist or in not valid), the
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
	   return value is NULL.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
     Else, the return value is a unzFile Handle, usable with other function
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
	   of this unzip package.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
extern unzFile ZEXPORT unzOpen (path)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
	const char *path;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
	unz_s us;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
	unz_s *s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
	uLong central_pos,uL;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
	FILE * fin ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
	uLong number_disk;          /* number of the current dist, used for 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
								   spaning ZIP, unsupported, always 0*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
	uLong number_disk_with_CD;  /* number the the disk with central dir, used
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
								   for spaning ZIP, unsupported, always 0*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
	uLong number_entry_CD;      /* total number of entries in
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
	                               the central dir 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
	                               (same than number_entry on nospan) */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
	int err=UNZ_OK;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
    if (unz_copyright[0]!=' ')
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
        return NULL;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
    fin=fopen(path,"rb");
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
	if (fin==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
		return NULL;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
	central_pos = unzlocal_SearchCentralDir(fin);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
	if (central_pos==0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
	if (fseek(fin,central_pos,SEEK_SET)!=0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
	/* the signature, already checked */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
	if (unzlocal_getLong(fin,&uL)!=UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
	/* number of this disk */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
	if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
	/* number of the disk with the start of the central directory */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
	if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
	/* total number of entries in the central dir on this disk */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
	if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
	/* total number of entries in the central dir */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
	if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
	if ((number_entry_CD!=us.gi.number_entry) ||
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
		(number_disk_with_CD!=0) ||
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
		(number_disk!=0))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
		err=UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
	/* size of the central directory */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
	if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
	/* offset of start of central directory with respect to the 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
	      starting disk number */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
	if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
	/* zipfile comment length */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
	if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
	if ((central_pos<us.offset_central_dir+us.size_central_dir) && 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
		(err==UNZ_OK))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
		err=UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
	if (err!=UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
		fclose(fin);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
		return NULL;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
	us.file=fin;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
	us.byte_before_the_zipfile = central_pos -
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
		                    (us.offset_central_dir+us.size_central_dir);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
	us.central_pos = central_pos;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
    us.pfile_in_zip_read = NULL;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
	s=(unz_s*)ALLOC(sizeof(unz_s));
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
	*s=us;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
	unzGoToFirstFile((unzFile)s);	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
	return (unzFile)s;	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
  Close a ZipFile opened with unzipOpen.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
  If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
  return UNZ_OK if there is no problem. */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
extern int ZEXPORT unzClose (file)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   442
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
	unz_s* s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
    if (s->pfile_in_zip_read!=NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
        unzCloseCurrentFile(file);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
	fclose(s->file);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
	TRYFREE(s);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
	return UNZ_OK;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
  Write info about the ZipFile in the *pglobal_info structure.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
  No preparation of the structure is needed
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   461
  return UNZ_OK if there is no problem. */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
	unz_global_info *pglobal_info;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
	unz_s* s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
	*pglobal_info=s->gi;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
	return UNZ_OK;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
   Translate date/time from Dos format to tm_unz (readable more easilty)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
    uLong ulDosDate;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
    tm_unz* ptm;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
    uLong uDate;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
    uDate = (uLong)(ulDosDate>>16);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
    ptm->tm_mday = (uInt)(uDate&0x1f) ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
    ptm->tm_mon =  (uInt)((((uDate)&0x1E0)/0x20)-1) ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   486
    ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   488
    ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   489
    ptm->tm_min =  (uInt) ((ulDosDate&0x7E0)/0x20) ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
    ptm->tm_sec =  (uInt) (2*(ulDosDate&0x1f)) ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   494
  Get Info about the current file in the zipfile, with internal only info
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
                                                  unz_file_info *pfile_info,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
                                                  unz_file_info_internal 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
                                                  *pfile_info_internal,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
                                                  char *szFileName,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
												  uLong fileNameBufferSize,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
                                                  void *extraField,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   503
												  uLong extraFieldBufferSize,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   504
                                                  char *szComment,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
												  uLong commentBufferSize));
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   506
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   507
local int unzlocal_GetCurrentFileInfoInternal (file,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
                                              pfile_info,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
                                              pfile_info_internal,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   510
                                              szFileName, fileNameBufferSize,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   511
                                              extraField, extraFieldBufferSize,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
                                              szComment,  commentBufferSize)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   514
	unz_file_info *pfile_info;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
	unz_file_info_internal *pfile_info_internal;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
	char *szFileName;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
	uLong fileNameBufferSize;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
	void *extraField;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
	uLong extraFieldBufferSize;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
	char *szComment;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   521
	uLong commentBufferSize;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   523
	unz_s* s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
	unz_file_info file_info;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
	unz_file_info_internal file_info_internal;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
	int err=UNZ_OK;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   527
	uLong uMagic;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
	long lSeek=0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   531
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
	if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   535
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   536
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   537
	/* we check the magic */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   538
	if (err==UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   539
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   540
		if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
			err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   542
		else if (uMagic!=0x02014b50)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
			err=UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
	if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   547
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
	if (unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
	if (unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   553
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
	if (unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   558
	if (unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   559
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   560
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
    unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   562
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
	if (unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   566
	if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   567
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
	if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   570
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   572
	if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   573
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   574
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   575
	if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   577
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   578
	if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   579
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   580
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   581
	if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   582
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   583
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   584
	if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   585
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   586
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   587
	if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   588
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   589
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   590
	if (unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   591
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   592
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
	lSeek+=file_info.size_filename;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
	if ((err==UNZ_OK) && (szFileName!=NULL))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   595
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   596
		uLong uSizeRead ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   597
		if (file_info.size_filename<fileNameBufferSize)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   598
		{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   599
			*(szFileName+file_info.size_filename)='\0';
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   600
			uSizeRead = file_info.size_filename;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   601
		}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   602
		else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   603
			uSizeRead = fileNameBufferSize;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   604
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   605
		if ((file_info.size_filename>0) && (fileNameBufferSize>0))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   606
			if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   607
				err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   608
		lSeek -= uSizeRead;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   609
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   610
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   611
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
	if ((err==UNZ_OK) && (extraField!=NULL))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   613
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   614
		uLong uSizeRead ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   615
		if (file_info.size_file_extra<extraFieldBufferSize)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
			uSizeRead = file_info.size_file_extra;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   617
		else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   618
			uSizeRead = extraFieldBufferSize;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   619
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
		if (lSeek!=0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   621
		{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   622
			if (fseek(s->file,lSeek,SEEK_CUR)==0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   623
				lSeek=0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   624
			else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
				err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
		}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   627
		if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   628
		{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   629
			if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   630
				err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   631
		}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632
		lSeek += file_info.size_file_extra - uSizeRead;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   633
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
	else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   635
		lSeek+=file_info.size_file_extra; 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   636
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   638
	if ((err==UNZ_OK) && (szComment!=NULL))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
		uLong uSizeRead ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   641
		if (file_info.size_file_comment<commentBufferSize)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
		{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   643
			*(szComment+file_info.size_file_comment)='\0';
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   644
			uSizeRead = file_info.size_file_comment;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   645
		}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   646
		else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   647
			uSizeRead = commentBufferSize;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   648
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
		if (lSeek!=0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
        {
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
			if (fseek(s->file,lSeek,SEEK_CUR)==0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   652
				lSeek=0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
			else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   654
				err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   655
        }
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   656
		if ((file_info.size_file_comment>0) && (commentBufferSize>0))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
		{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
			if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   659
				err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
		}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
		lSeek+=file_info.size_file_comment - uSizeRead;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   662
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   663
	else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   664
		lSeek+=file_info.size_file_comment;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   665
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   666
	if ((err==UNZ_OK) && (pfile_info!=NULL))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   667
		*pfile_info=file_info;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   668
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   669
	if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   670
		*pfile_info_internal=file_info_internal;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   671
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   672
	return err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   673
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   674
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   675
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   676
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   677
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   678
  Write info about the ZipFile in the *pglobal_info structure.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   679
  No preparation of the structure is needed
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   680
  return UNZ_OK if there is no problem.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   681
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   682
extern int ZEXPORT unzGetCurrentFileInfo (file,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   683
                                                  pfile_info,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   684
                                                  szFileName, fileNameBufferSize,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   685
                                                  extraField, extraFieldBufferSize,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   686
                                                  szComment,  commentBufferSize)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   687
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   688
	unz_file_info *pfile_info;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   689
	char *szFileName;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   690
	uLong fileNameBufferSize;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   691
	void *extraField;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   692
	uLong extraFieldBufferSize;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   693
	char *szComment;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   694
	uLong commentBufferSize;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   695
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   696
	return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   697
												szFileName,fileNameBufferSize,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   698
												extraField,extraFieldBufferSize,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   699
												szComment,commentBufferSize);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   700
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   701
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   702
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   703
  Set the current file of the zipfile to the first file.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   704
  return UNZ_OK if there is no problem
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   705
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   706
extern int ZEXPORT unzGoToFirstFile (file)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   707
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   708
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   709
	int err=UNZ_OK;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   710
	unz_s* s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   711
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   712
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   713
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   714
	s->pos_in_central_dir=s->offset_central_dir;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   715
	s->num_file=0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   716
	err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   717
											 &s->cur_file_info_internal,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   718
											 NULL,0,NULL,0,NULL,0);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   719
	s->current_file_ok = (err == UNZ_OK);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   720
	return err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   721
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   722
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   723
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   724
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   725
  Set the current file of the zipfile to the next file.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   726
  return UNZ_OK if there is no problem
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   727
  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   728
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   729
extern int ZEXPORT unzGoToNextFile (file)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   730
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   731
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   732
	unz_s* s;	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   733
	int err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   734
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   735
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   736
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   737
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   738
	if (!s->current_file_ok)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   739
		return UNZ_END_OF_LIST_OF_FILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   740
	if (s->num_file+1==s->gi.number_entry)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   741
		return UNZ_END_OF_LIST_OF_FILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   742
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   743
	s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   744
			s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   745
	s->num_file++;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   746
	err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   747
											   &s->cur_file_info_internal,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   748
											   NULL,0,NULL,0,NULL,0);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   749
	s->current_file_ok = (err == UNZ_OK);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   750
	return err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   751
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   752
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   753
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   754
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   755
  Try locate the file szFileName in the zipfile.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   756
  For the iCaseSensitivity signification, see unzipStringFileNameCompare
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   757
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   758
  return value :
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   759
  UNZ_OK if the file is found. It becomes the current file.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   760
  UNZ_END_OF_LIST_OF_FILE if the file is not found
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   761
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   762
extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   763
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   764
	const char *szFileName;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   765
	int iCaseSensitivity;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   766
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   767
	unz_s* s;	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   768
	int err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   769
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   770
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   771
	uLong num_fileSaved;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   772
	uLong pos_in_central_dirSaved;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   773
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   774
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   775
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   776
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   777
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   778
    if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   779
        return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   780
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   781
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   782
	if (!s->current_file_ok)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   783
		return UNZ_END_OF_LIST_OF_FILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   784
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   785
	num_fileSaved = s->num_file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   786
	pos_in_central_dirSaved = s->pos_in_central_dir;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   787
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   788
	err = unzGoToFirstFile(file);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   789
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   790
	while (err == UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   791
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   792
		char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   793
		unzGetCurrentFileInfo(file,NULL,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   794
								szCurrentFileName,sizeof(szCurrentFileName)-1,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   795
								NULL,0,NULL,0);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   796
		if (unzStringFileNameCompare(szCurrentFileName,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   797
										szFileName,iCaseSensitivity)==0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   798
			return UNZ_OK;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   799
		err = unzGoToNextFile(file);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   800
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   801
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   802
	s->num_file = num_fileSaved ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   803
	s->pos_in_central_dir = pos_in_central_dirSaved ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   804
	return err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   805
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   806
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   807
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   808
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   809
  Read the local header of the current zipfile
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   810
  Check the coherency of the local header and info in the end of central
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   811
        directory about this file
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   812
  store in *piSizeVar the size of extra info in local header
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   813
        (filename and size of extra field data)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   814
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   815
local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   816
													poffset_local_extrafield,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   817
													psize_local_extrafield)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   818
	unz_s* s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   819
	uInt* piSizeVar;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   820
	uLong *poffset_local_extrafield;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   821
	uInt  *psize_local_extrafield;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   822
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   823
	uLong uMagic,uData,uFlags;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   824
	uLong size_filename;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   825
	uLong size_extra_field;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   826
	int err=UNZ_OK;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   827
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   828
	*piSizeVar = 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   829
	*poffset_local_extrafield = 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   830
	*psize_local_extrafield = 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   831
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   832
	if (fseek(s->file,s->cur_file_info_internal.offset_curfile +
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   833
								s->byte_before_the_zipfile,SEEK_SET)!=0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   834
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   835
		return UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   836
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   837
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   838
	if (err==UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   839
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   840
		if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   841
			err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   842
		else if (uMagic!=0x04034b50)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   843
			err=UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   844
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   845
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   846
	if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   847
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   848
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   849
	else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   850
		err=UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   851
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   852
	if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   853
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   854
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   855
	if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   856
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   857
	else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   858
		err=UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   859
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   860
    if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   861
                         (s->cur_file_info.compression_method!=Z_DEFLATED))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   862
        err=UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   863
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   864
	if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   865
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   866
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   867
	if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   868
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   869
	else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   870
		                      ((uFlags & 8)==0))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   871
		err=UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   872
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   873
	if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   874
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   875
	else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   876
							  ((uFlags & 8)==0))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   877
		err=UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   878
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   879
	if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   880
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   881
	else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   882
							  ((uFlags & 8)==0))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   883
		err=UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   884
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   885
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   886
	if (unzlocal_getShort(s->file,&size_filename) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   887
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   888
	else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   889
		err=UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   890
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   891
	*piSizeVar += (uInt)size_filename;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   892
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   893
	if (unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   894
		err=UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   895
	*poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   896
									SIZEZIPLOCALHEADER + size_filename;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   897
	*psize_local_extrafield = (uInt)size_extra_field;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   898
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   899
	*piSizeVar += (uInt)size_extra_field;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   900
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   901
	return err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   902
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   903
												
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   904
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   905
  Open for reading data the current file in the zipfile.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   906
  If there is no error and the file is opened, the return value is UNZ_OK.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   907
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   908
extern int ZEXPORT unzOpenCurrentFile (file)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   909
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   910
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   911
	int err=UNZ_OK;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   912
	int Store;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   913
	uInt iSizeVar;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   914
	unz_s* s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   915
	file_in_zip_read_info_s* pfile_in_zip_read_info;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   916
	uLong offset_local_extrafield;  /* offset of the local extra field */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   917
	uInt  size_local_extrafield;    /* size of the local extra field */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   918
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   919
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   920
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   921
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   922
	if (!s->current_file_ok)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   923
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   924
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   925
    if (s->pfile_in_zip_read != NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   926
        unzCloseCurrentFile(file);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   927
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   928
	if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   929
				&offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   930
		return UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   931
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   932
	pfile_in_zip_read_info = (file_in_zip_read_info_s*)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   933
									    ALLOC(sizeof(file_in_zip_read_info_s));
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   934
	if (pfile_in_zip_read_info==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   935
		return UNZ_INTERNALERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   936
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   937
	pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   938
	pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   939
	pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   940
	pfile_in_zip_read_info->pos_local_extrafield=0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   941
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   942
	if (pfile_in_zip_read_info->read_buffer==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   943
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   944
		TRYFREE(pfile_in_zip_read_info);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   945
		return UNZ_INTERNALERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   946
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   947
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   948
	pfile_in_zip_read_info->stream_initialised=0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   949
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   950
	if ((s->cur_file_info.compression_method!=0) &&
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   951
        (s->cur_file_info.compression_method!=Z_DEFLATED))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   952
		err=UNZ_BADZIPFILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   953
	Store = s->cur_file_info.compression_method==0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   954
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   955
	pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   956
	pfile_in_zip_read_info->crc32=0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   957
	pfile_in_zip_read_info->compression_method =
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   958
            s->cur_file_info.compression_method;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   959
	pfile_in_zip_read_info->file=s->file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   960
	pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   961
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   962
    pfile_in_zip_read_info->stream.total_out = 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   963
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   964
	if (!Store)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   965
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   966
	  pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   967
	  pfile_in_zip_read_info->stream.zfree = (free_func)0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   968
	  pfile_in_zip_read_info->stream.opaque = (voidpf)0; 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   969
      
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   970
	  err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   971
	  if (err == Z_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   972
	    pfile_in_zip_read_info->stream_initialised=1;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   973
        /* windowBits is passed < 0 to tell that there is no zlib header.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   974
         * Note that in this case inflate *requires* an extra "dummy" byte
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   975
         * after the compressed stream in order to complete decompression and
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   976
         * return Z_STREAM_END. 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   977
         * In unzip, i don't wait absolutely Z_STREAM_END because I known the 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   978
         * size of both compressed and uncompressed data
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   979
         */
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   980
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   981
	pfile_in_zip_read_info->rest_read_compressed = 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   982
            s->cur_file_info.compressed_size ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   983
	pfile_in_zip_read_info->rest_read_uncompressed = 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   984
            s->cur_file_info.uncompressed_size ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   985
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   986
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   987
	pfile_in_zip_read_info->pos_in_zipfile = 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   988
            s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   989
			  iSizeVar;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   990
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   991
	pfile_in_zip_read_info->stream.avail_in = (uInt)0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   992
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   993
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   994
	s->pfile_in_zip_read = pfile_in_zip_read_info;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   995
    return UNZ_OK;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   996
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   997
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   998
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   999
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1000
  Read bytes from the current file.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1001
  buf contain buffer where data must be copied
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1002
  len the size of buf.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1003
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1004
  return the number of byte copied if somes bytes are copied
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1005
  return 0 if the end of file was reached
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1006
  return <0 with error code if there is an error
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1007
    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1008
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1009
extern int ZEXPORT unzReadCurrentFile  (file, buf, len)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1010
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1011
	voidp buf;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1012
	unsigned len;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1013
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1014
	int err=UNZ_OK;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1015
	uInt iRead = 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1016
	unz_s* s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1017
	file_in_zip_read_info_s* pfile_in_zip_read_info;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1018
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1019
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1020
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1021
    pfile_in_zip_read_info=s->pfile_in_zip_read;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1022
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1023
	if (pfile_in_zip_read_info==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1024
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1025
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1026
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1027
	if ((pfile_in_zip_read_info->read_buffer == NULL))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1028
		return UNZ_END_OF_LIST_OF_FILE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1029
	if (len==0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1030
		return 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1031
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1032
	pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1033
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1034
	pfile_in_zip_read_info->stream.avail_out = (uInt)len;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1035
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1036
	if (len>pfile_in_zip_read_info->rest_read_uncompressed)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1037
		pfile_in_zip_read_info->stream.avail_out = 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1038
		  (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1039
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1040
	while (pfile_in_zip_read_info->stream.avail_out>0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1041
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1042
		if ((pfile_in_zip_read_info->stream.avail_in==0) &&
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1043
            (pfile_in_zip_read_info->rest_read_compressed>0))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1044
		{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1045
			uInt uReadThis = UNZ_BUFSIZE;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1046
			if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1047
				uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1048
			if (uReadThis == 0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1049
				return UNZ_EOF;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1050
			if (fseek(pfile_in_zip_read_info->file,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1051
                      pfile_in_zip_read_info->pos_in_zipfile + 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1052
                         pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1053
				return UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1054
			if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1055
                         pfile_in_zip_read_info->file)!=1)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1056
				return UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1057
			pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1058
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1059
			pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1060
			
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1061
			pfile_in_zip_read_info->stream.next_in = 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1062
                (Bytef*)pfile_in_zip_read_info->read_buffer;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1063
			pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1064
		}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1065
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1066
		if (pfile_in_zip_read_info->compression_method==0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1067
		{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1068
			uInt uDoCopy,i ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1069
			if (pfile_in_zip_read_info->stream.avail_out < 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1070
                            pfile_in_zip_read_info->stream.avail_in)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1071
				uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1072
			else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1073
				uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1074
				
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1075
			for (i=0;i<uDoCopy;i++)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1076
				*(pfile_in_zip_read_info->stream.next_out+i) =
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1077
                        *(pfile_in_zip_read_info->stream.next_in+i);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1078
					
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1079
			pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1080
								pfile_in_zip_read_info->stream.next_out,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1081
								uDoCopy);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1082
			pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1083
			pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1084
			pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1085
			pfile_in_zip_read_info->stream.next_out += uDoCopy;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1086
			pfile_in_zip_read_info->stream.next_in += uDoCopy;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1087
            pfile_in_zip_read_info->stream.total_out += uDoCopy;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1088
			iRead += uDoCopy;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1089
		}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1090
		else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1091
		{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1092
			uLong uTotalOutBefore,uTotalOutAfter;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1093
			const Bytef *bufBefore;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1094
			uLong uOutThis;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1095
			int flush=Z_SYNC_FLUSH;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1096
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1097
			uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1098
			bufBefore = pfile_in_zip_read_info->stream.next_out;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1099
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1100
			/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1101
			if ((pfile_in_zip_read_info->rest_read_uncompressed ==
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1102
			         pfile_in_zip_read_info->stream.avail_out) &&
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1103
				(pfile_in_zip_read_info->rest_read_compressed == 0))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1104
				flush = Z_FINISH;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1105
			*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1106
			err=inflate(&pfile_in_zip_read_info->stream,flush);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1107
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1108
			uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1109
			uOutThis = uTotalOutAfter-uTotalOutBefore;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1110
			
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1111
			pfile_in_zip_read_info->crc32 = 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1112
                crc32(pfile_in_zip_read_info->crc32,bufBefore,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1113
                        (uInt)(uOutThis));
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1114
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1115
			pfile_in_zip_read_info->rest_read_uncompressed -=
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1116
                uOutThis;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1117
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1118
			iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1119
            
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1120
			if (err==Z_STREAM_END)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1121
				return (iRead==0) ? UNZ_EOF : iRead;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1122
			if (err!=Z_OK) 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1123
				break;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1124
		}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1125
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1126
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1127
	if (err==Z_OK)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1128
		return iRead;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1129
	return err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1130
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1131
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1132
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1133
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1134
  Give the current position in uncompressed data
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1135
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1136
extern z_off_t ZEXPORT unztell (file)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1137
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1138
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1139
	unz_s* s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1140
	file_in_zip_read_info_s* pfile_in_zip_read_info;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1141
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1142
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1143
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1144
    pfile_in_zip_read_info=s->pfile_in_zip_read;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1145
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1146
	if (pfile_in_zip_read_info==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1147
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1148
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1149
	return (z_off_t)pfile_in_zip_read_info->stream.total_out;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1150
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1151
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1152
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1153
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1154
  return 1 if the end of file was reached, 0 elsewhere 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1155
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1156
extern int ZEXPORT unzeof (file)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1157
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1158
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1159
	unz_s* s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1160
	file_in_zip_read_info_s* pfile_in_zip_read_info;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1161
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1162
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1163
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1164
    pfile_in_zip_read_info=s->pfile_in_zip_read;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1165
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1166
	if (pfile_in_zip_read_info==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1167
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1168
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1169
	if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1170
		return 1;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1171
	else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1172
		return 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1173
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1174
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1175
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1176
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1177
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1178
  Read extra field from the current file (opened by unzOpenCurrentFile)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1179
  This is the local-header version of the extra field (sometimes, there is
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1180
    more info in the local-header version than in the central-header)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1181
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1182
  if buf==NULL, it return the size of the local extra field that can be read
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1183
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1184
  if buf!=NULL, len is the size of the buffer, the extra header is copied in
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1185
	buf.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1186
  the return value is the number of bytes copied in buf, or (if <0) 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1187
	the error code
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1188
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1189
extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1190
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1191
	voidp buf;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1192
	unsigned len;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1193
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1194
	unz_s* s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1195
	file_in_zip_read_info_s* pfile_in_zip_read_info;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1196
	uInt read_now;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1197
	uLong size_to_read;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1198
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1199
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1200
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1201
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1202
    pfile_in_zip_read_info=s->pfile_in_zip_read;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1203
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1204
	if (pfile_in_zip_read_info==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1205
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1206
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1207
	size_to_read = (pfile_in_zip_read_info->size_local_extrafield - 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1208
				pfile_in_zip_read_info->pos_local_extrafield);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1209
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1210
	if (buf==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1211
		return (int)size_to_read;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1212
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1213
	if (len>size_to_read)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1214
		read_now = (uInt)size_to_read;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1215
	else
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1216
		read_now = (uInt)len ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1217
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1218
	if (read_now==0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1219
		return 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1220
	
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1221
	if (fseek(pfile_in_zip_read_info->file,
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1222
              pfile_in_zip_read_info->offset_local_extrafield + 
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1223
			  pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1224
		return UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1225
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1226
	if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1227
		return UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1228
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1229
	return (int)read_now;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1230
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1231
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1232
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1233
  Close the file in zip opened with unzipOpenCurrentFile
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1234
  Return UNZ_CRCERROR if all the file was read but the CRC is not good
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1235
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1236
extern int ZEXPORT unzCloseCurrentFile (file)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1237
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1238
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1239
	int err=UNZ_OK;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1240
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1241
	unz_s* s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1242
	file_in_zip_read_info_s* pfile_in_zip_read_info;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1243
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1244
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1245
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1246
    pfile_in_zip_read_info=s->pfile_in_zip_read;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1247
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1248
	if (pfile_in_zip_read_info==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1249
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1250
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1251
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1252
	if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1253
	{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1254
		if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1255
			err=UNZ_CRCERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1256
	}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1257
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1258
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1259
	TRYFREE(pfile_in_zip_read_info->read_buffer);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1260
	pfile_in_zip_read_info->read_buffer = NULL;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1261
	if (pfile_in_zip_read_info->stream_initialised)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1262
		inflateEnd(&pfile_in_zip_read_info->stream);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1263
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1264
	pfile_in_zip_read_info->stream_initialised = 0;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1265
	TRYFREE(pfile_in_zip_read_info);
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1266
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1267
    s->pfile_in_zip_read=NULL;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1268
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1269
	return err;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1270
}
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1271
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1272
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1273
/*
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1274
  Get the global comment string of the ZipFile, in the szComment buffer.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1275
  uSizeBuf is the size of the szComment buffer.
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1276
  return the number of byte copied or an error code <0
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1277
*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1278
extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1279
	unzFile file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1280
	char *szComment;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1281
	uLong uSizeBuf;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1282
{
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1283
	/*int err=UNZ_OK;*/
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1284
	unz_s* s;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1285
	uLong uReadThis ;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1286
	if (file==NULL)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1287
		return UNZ_PARAMERROR;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1288
	s=(unz_s*)file;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1289
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1290
	uReadThis = uSizeBuf;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1291
	if (uReadThis>s->gi.size_comment)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1292
		uReadThis = s->gi.size_comment;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1293
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1294
	if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1295
		return UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1296
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1297
	if (uReadThis>0)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1298
    {
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1299
      *szComment='\0';
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1300
	  if (fread(szComment,(uInt)uReadThis,1,s->file)!=1)
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1301
		return UNZ_ERRNO;
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1302
    }
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1303
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1304
	if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1305
		*(szComment+s->gi.size_comment)='\0';
fbf5d37147eb Initial add.
Ryan C. Gordon <icculus&