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