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