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