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