author | Ryan C. Gordon <icculus@icculus.org> |
Thu, 16 Dec 2004 16:20:46 +0000 | |
changeset 669 | 66a1058b803d |
parent 658 | 1981818c6170 |
child 691 | 71d9affe0d8a |
permissions | -rw-r--r-- |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/* |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
* ZIP support routines for PhysicsFS. |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
* |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
* Please see the file LICENSE in the source's root directory. |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* |
337 | 6 |
* This file written by Ryan C. Gordon, with some peeking at "unzip.c" |
7 |
* by Gilles Vollant. |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
*/ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
|
214
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
10 |
#if HAVE_CONFIG_H |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
11 |
# include <config.h> |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
12 |
#endif |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
13 |
|
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
14 |
#if (defined PHYSFS_SUPPORTS_ZIP) |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
15 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
#include <stdio.h> |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
#include <stdlib.h> |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
18 |
#include <string.h> |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
551
diff
changeset
|
19 |
#ifndef _WIN32_WCE |
504
3420d82f9b01
Some cleanups for PocketPC port.
Ryan C. Gordon <icculus@icculus.org>
parents:
494
diff
changeset
|
20 |
#include <errno.h> |
254
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
21 |
#include <time.h> |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
551
diff
changeset
|
22 |
#endif |
22
49f6101707b4
More tweaks; GRP completely implemented. Everything builds clean.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
23 |
#include "physfs.h" |
337 | 24 |
#include "zlib.h" |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
#define __PHYSICSFS_INTERNAL__ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 |
#include "physfs_internal.h" |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
29 |
/* |
337 | 30 |
* A buffer of ZIP_READBUFSIZE is malloc() for each compressed file opened, |
31 |
* and is free()'d when you close the file; compressed data is read into |
|
32 |
* this buffer, and then is decompressed into the buffer passed to |
|
33 |
* PHYSFS_read(). |
|
34 |
* |
|
35 |
* Uncompressed entries in a zipfile do not allocate this buffer; they just |
|
36 |
* read data directly into the buffer passed to PHYSFS_read(). |
|
37 |
* |
|
38 |
* Depending on your speed and memory requirements, you should tweak this |
|
39 |
* value. |
|
40 |
*/ |
|
41 |
#define ZIP_READBUFSIZE (16 * 1024) |
|
42 |
||
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
43 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
44 |
/* |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
45 |
* Entries are "unresolved" until they are first opened. At that time, |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
46 |
* local file headers parsed/validated, data offsets will be updated to look |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
47 |
* at the actual file data instead of the header, and symlinks will be |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
48 |
* followed and optimized. This means that we don't seek and read around the |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
49 |
* archive until forced to do so, and after the first time, we had to do |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
50 |
* less reading and parsing, which is very CD-ROM friendly. |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
51 |
*/ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
52 |
typedef enum |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
53 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
54 |
ZIP_UNRESOLVED_FILE, |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
55 |
ZIP_UNRESOLVED_SYMLINK, |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
56 |
ZIP_RESOLVING, |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
57 |
ZIP_RESOLVED, |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
58 |
ZIP_BROKEN_FILE, |
538
8752e3c0dbf9
Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
59 |
ZIP_BROKEN_SYMLINK |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
60 |
} ZipResolveType; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
61 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
62 |
|
337 | 63 |
/* |
64 |
* One ZIPentry is kept for each file in an open ZIP archive. |
|
65 |
*/ |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
66 |
typedef struct _ZIPentry |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
67 |
{ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
68 |
char *name; /* Name of file in archive */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
69 |
struct _ZIPentry *symlink; /* NULL or file we symlink to */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
70 |
ZipResolveType resolved; /* Have we resolved file/symlink? */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
71 |
PHYSFS_uint32 offset; /* offset of data in archive */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
72 |
PHYSFS_uint16 version; /* version made by */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
73 |
PHYSFS_uint16 version_needed; /* version needed to extract */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
74 |
PHYSFS_uint16 compression_method; /* compression method */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
75 |
PHYSFS_uint32 crc; /* crc-32 */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
76 |
PHYSFS_uint32 compressed_size; /* compressed size */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
77 |
PHYSFS_uint32 uncompressed_size; /* uncompressed size */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
78 |
PHYSFS_sint64 last_mod_time; /* last file mod time */ |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
79 |
} ZIPentry; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
80 |
|
337 | 81 |
/* |
82 |
* One ZIPinfo is kept for each open ZIP archive. |
|
83 |
*/ |
|
84 |
typedef struct |
|
85 |
{ |
|
86 |
char *archiveName; /* path to ZIP in platform-dependent notation. */ |
|
87 |
PHYSFS_uint16 entryCount; /* Number of files in ZIP. */ |
|
88 |
ZIPentry *entries; /* info on all files in ZIP. */ |
|
89 |
} ZIPinfo; |
|
90 |
||
91 |
/* |
|
92 |
* One ZIPfileinfo is kept for each open file in a ZIP archive. |
|
93 |
*/ |
|
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
94 |
typedef struct |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
95 |
{ |
337 | 96 |
ZIPentry *entry; /* Info on file. */ |
97 |
void *handle; /* physical file handle. */ |
|
98 |
PHYSFS_uint32 compressed_position; /* offset in compressed data. */ |
|
99 |
PHYSFS_uint32 uncompressed_position; /* tell() position. */ |
|
100 |
PHYSFS_uint8 *buffer; /* decompression buffer. */ |
|
101 |
z_stream stream; /* zlib stream state. */ |
|
102 |
} ZIPfileinfo; |
|
103 |
||
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
104 |
|
337 | 105 |
/* Magic numbers... */ |
106 |
#define ZIP_LOCAL_FILE_SIG 0x04034b50 |
|
107 |
#define ZIP_CENTRAL_DIR_SIG 0x02014b50 |
|
108 |
#define ZIP_END_OF_CENTRAL_DIR_SIG 0x06054b50 |
|
109 |
||
110 |
/* compression methods... */ |
|
111 |
#define COMPMETH_NONE 0 |
|
112 |
/* ...and others... */ |
|
113 |
||
114 |
||
342
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
115 |
#define UNIX_FILETYPE_MASK 0170000 |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
116 |
#define UNIX_FILETYPE_SYMLINK 0120000 |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
117 |
|
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
118 |
|
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
119 |
/* |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
120 |
* Bridge physfs allocation functions to zlib's format... |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
121 |
*/ |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
122 |
static voidpf zlibPhysfsAlloc(voidpf opaque, uInt items, uInt size) |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
123 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
124 |
return(((PHYSFS_Allocator *) opaque)->malloc(items * size)); |
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
125 |
} /* zlibPhysfsAlloc */ |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
126 |
|
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
127 |
/* |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
128 |
* Bridge physfs allocation functions to zlib's format... |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
129 |
*/ |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
130 |
static void zlibPhysfsFree(voidpf opaque, voidpf address) |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
131 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
132 |
((PHYSFS_Allocator *) opaque)->free(address); |
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
133 |
} /* zlibPhysfsFree */ |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
134 |
|
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
135 |
|
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
136 |
/* |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
137 |
* Construct a new z_stream to a sane state. |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
138 |
*/ |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
139 |
static void initializeZStream(z_stream *pstr) |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
140 |
{ |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
141 |
memset(pstr, '\0', sizeof (z_stream)); |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
142 |
pstr->zalloc = zlibPhysfsAlloc; |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
143 |
pstr->zfree = zlibPhysfsFree; |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
144 |
pstr->opaque = __PHYSFS_getAllocator(); |
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
145 |
} /* initializeZStream */ |
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
146 |
|
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
147 |
|
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
148 |
static const char *zlib_error_string(int rc) |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
149 |
{ |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
150 |
switch (rc) |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
151 |
{ |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
152 |
case Z_OK: return(NULL); /* not an error. */ |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
153 |
case Z_STREAM_END: return(NULL); /* not an error. */ |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
551
diff
changeset
|
154 |
#ifndef _WIN32_WCE |
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
155 |
case Z_ERRNO: return(strerror(errno)); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
551
diff
changeset
|
156 |
#endif |
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
157 |
case Z_NEED_DICT: return(ERR_ZLIB_NEED_DICT); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
158 |
case Z_DATA_ERROR: return(ERR_ZLIB_DATA_ERROR); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
159 |
case Z_MEM_ERROR: return(ERR_ZLIB_MEMORY_ERROR); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
160 |
case Z_BUF_ERROR: return(ERR_ZLIB_BUFFER_ERROR); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
161 |
case Z_VERSION_ERROR: return(ERR_ZLIB_VERSION_ERROR); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
162 |
default: return(ERR_ZLIB_UNKNOWN_ERROR); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
163 |
} /* switch */ |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
164 |
|
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
165 |
return(NULL); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
166 |
} /* zlib_error_string */ |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
167 |
|
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
168 |
|
337 | 169 |
/* |
170 |
* Wrap all zlib calls in this, so the physfs error state is set appropriately. |
|
171 |
*/ |
|
172 |
static int zlib_err(int rc) |
|
173 |
{ |
|
427
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
174 |
const char *str = zlib_error_string(rc); |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
175 |
if (str != NULL) |
c38ace41039f
Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents:
413
diff
changeset
|
176 |
__PHYSFS_setError(str); |
337 | 177 |
return(rc); |
178 |
} /* zlib_err */ |
|
179 |
||
180 |
||
181 |
/* |
|
182 |
* Read an unsigned 32-bit int and swap to native byte order. |
|
183 |
*/ |
|
184 |
static int readui32(void *in, PHYSFS_uint32 *val) |
|
185 |
{ |
|
186 |
PHYSFS_uint32 v; |
|
187 |
BAIL_IF_MACRO(__PHYSFS_platformRead(in, &v, sizeof (v), 1) != 1, NULL, 0); |
|
188 |
*val = PHYSFS_swapULE32(v); |
|
189 |
return(1); |
|
190 |
} /* readui32 */ |
|
191 |
||
192 |
||
193 |
/* |
|
194 |
* Read an unsigned 16-bit int and swap to native byte order. |
|
195 |
*/ |
|
196 |
static int readui16(void *in, PHYSFS_uint16 *val) |
|
197 |
{ |
|
198 |
PHYSFS_uint16 v; |
|
199 |
BAIL_IF_MACRO(__PHYSFS_platformRead(in, &v, sizeof (v), 1) != 1, NULL, 0); |
|
200 |
*val = PHYSFS_swapULE16(v); |
|
201 |
return(1); |
|
202 |
} /* readui16 */ |
|
203 |
||
204 |
||
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
205 |
static PHYSFS_sint64 ZIP_read(fvoid *opaque, void *buf, |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
206 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
207 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
208 |
ZIPfileinfo *finfo = (ZIPfileinfo *) opaque; |
337 | 209 |
ZIPentry *entry = finfo->entry; |
210 |
PHYSFS_sint64 retval = 0; |
|
211 |
PHYSFS_sint64 maxread = ((PHYSFS_sint64) objSize) * objCount; |
|
212 |
PHYSFS_sint64 avail = entry->uncompressed_size - |
|
213 |
finfo->uncompressed_position; |
|
214 |
||
215 |
BAIL_IF_MACRO(maxread == 0, NULL, 0); /* quick rejection. */ |
|
216 |
||
217 |
if (avail < maxread) |
|
218 |
{ |
|
219 |
maxread = avail - (avail % objSize); |
|
540
a6b6f0a54cd2
Attempt at type correctness.
Ryan C. Gordon <icculus@icculus.org>
parents:
538
diff
changeset
|
220 |
objCount = (PHYSFS_uint32) (maxread / objSize); |
337 | 221 |
BAIL_IF_MACRO(objCount == 0, ERR_PAST_EOF, 0); /* quick rejection. */ |
222 |
__PHYSFS_setError(ERR_PAST_EOF); /* this is always true here. */ |
|
223 |
} /* if */ |
|
224 |
||
225 |
if (entry->compression_method == COMPMETH_NONE) |
|
226 |
{ |
|
227 |
retval = __PHYSFS_platformRead(finfo->handle, buf, objSize, objCount); |
|
228 |
} /* if */ |
|
229 |
||
230 |
else |
|
231 |
{ |
|
232 |
finfo->stream.next_out = buf; |
|
233 |
finfo->stream.avail_out = objSize * objCount; |
|
234 |
||
235 |
while (retval < maxread) |
|
236 |
{ |
|
237 |
PHYSFS_uint32 before = finfo->stream.total_out; |
|
238 |
int rc; |
|
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
239 |
|
337 | 240 |
if (finfo->stream.avail_in == 0) |
241 |
{ |
|
242 |
PHYSFS_sint64 br; |
|
243 |
||
244 |
br = entry->compressed_size - finfo->compressed_position; |
|
245 |
if (br > 0) |
|
246 |
{ |
|
247 |
if (br > ZIP_READBUFSIZE) |
|
248 |
br = ZIP_READBUFSIZE; |
|
249 |
||
250 |
br = __PHYSFS_platformRead(finfo->handle, |
|
251 |
finfo->buffer, |
|
540
a6b6f0a54cd2
Attempt at type correctness.
Ryan C. Gordon <icculus@icculus.org>
parents:
538
diff
changeset
|
252 |
1, (PHYSFS_uint32) br); |
337 | 253 |
if (br <= 0) |
254 |
break; |
|
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
255 |
|
540
a6b6f0a54cd2
Attempt at type correctness.
Ryan C. Gordon <icculus@icculus.org>
parents:
538
diff
changeset
|
256 |
finfo->compressed_position += (PHYSFS_uint32) br; |
337 | 257 |
finfo->stream.next_in = finfo->buffer; |
540
a6b6f0a54cd2
Attempt at type correctness.
Ryan C. Gordon <icculus@icculus.org>
parents:
538
diff
changeset
|
258 |
finfo->stream.avail_in = (PHYSFS_uint32) br; |
337 | 259 |
} /* if */ |
260 |
} /* if */ |
|
261 |
||
262 |
rc = zlib_err(inflate(&finfo->stream, Z_SYNC_FLUSH)); |
|
263 |
retval += (finfo->stream.total_out - before); |
|
264 |
||
265 |
if (rc != Z_OK) |
|
266 |
break; |
|
267 |
} /* while */ |
|
268 |
||
269 |
retval /= objSize; |
|
270 |
} /* else */ |
|
271 |
||
272 |
if (retval > 0) |
|
540
a6b6f0a54cd2
Attempt at type correctness.
Ryan C. Gordon <icculus@icculus.org>
parents:
538
diff
changeset
|
273 |
finfo->uncompressed_position += (PHYSFS_uint32) (retval * objSize); |
337 | 274 |
|
275 |
return(retval); |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
276 |
} /* ZIP_read */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
277 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
278 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
279 |
static PHYSFS_sint64 ZIP_write(fvoid *opaque, const void *buf, |
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
280 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
281 |
{ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
282 |
BAIL_MACRO(ERR_NOT_SUPPORTED, -1); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
283 |
} /* ZIP_write */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
284 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
285 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
286 |
static int ZIP_eof(fvoid *opaque) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
287 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
288 |
ZIPfileinfo *finfo = (ZIPfileinfo *) opaque; |
337 | 289 |
return(finfo->uncompressed_position >= finfo->entry->uncompressed_size); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
290 |
} /* ZIP_eof */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
291 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
292 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
293 |
static PHYSFS_sint64 ZIP_tell(fvoid *opaque) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
294 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
295 |
return(((ZIPfileinfo *) opaque)->uncompressed_position); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
296 |
} /* ZIP_tell */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
297 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
298 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
299 |
static int ZIP_seek(fvoid *opaque, PHYSFS_uint64 offset) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
300 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
301 |
ZIPfileinfo *finfo = (ZIPfileinfo *) opaque; |
337 | 302 |
ZIPentry *entry = finfo->entry; |
303 |
void *in = finfo->handle; |
|
304 |
||
305 |
BAIL_IF_MACRO(offset > entry->uncompressed_size, ERR_PAST_EOF, 0); |
|
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
306 |
|
337 | 307 |
if (entry->compression_method == COMPMETH_NONE) |
308 |
{ |
|
309 |
PHYSFS_sint64 newpos = offset + entry->offset; |
|
310 |
BAIL_IF_MACRO(!__PHYSFS_platformSeek(in, newpos), NULL, 0); |
|
551
f0fc464fd51b
Fixed seeking in uncompressed zip entries and handle Java-created JAR files.
Ryan C. Gordon <icculus@icculus.org>
parents:
541
diff
changeset
|
311 |
finfo->uncompressed_position = (PHYSFS_uint32) offset; |
337 | 312 |
} /* if */ |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
313 |
|
337 | 314 |
else |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
315 |
{ |
337 | 316 |
/* |
317 |
* If seeking backwards, we need to redecode the file |
|
318 |
* from the start and throw away the compressed bits until we hit |
|
319 |
* the offset we need. If seeking forward, we still need to |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
320 |
* decode, but we don't rewind first. |
337 | 321 |
*/ |
322 |
if (offset < finfo->uncompressed_position) |
|
323 |
{ |
|
324 |
/* we do a copy so state is sane if inflateInit2() fails. */ |
|
325 |
z_stream str; |
|
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
326 |
initializeZStream(&str); |
337 | 327 |
if (zlib_err(inflateInit2(&str, -MAX_WBITS)) != Z_OK) |
328 |
return(0); |
|
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
329 |
|
345
cbcb27547864
Seeking backwards in ZIP_seek() works now.
Ryan C. Gordon <icculus@icculus.org>
parents:
342
diff
changeset
|
330 |
if (!__PHYSFS_platformSeek(in, entry->offset)) |
cbcb27547864
Seeking backwards in ZIP_seek() works now.
Ryan C. Gordon <icculus@icculus.org>
parents:
342
diff
changeset
|
331 |
return(0); |
cbcb27547864
Seeking backwards in ZIP_seek() works now.
Ryan C. Gordon <icculus@icculus.org>
parents:
342
diff
changeset
|
332 |
|
337 | 333 |
inflateEnd(&finfo->stream); |
334 |
memcpy(&finfo->stream, &str, sizeof (z_stream)); |
|
335 |
finfo->uncompressed_position = finfo->compressed_position = 0; |
|
336 |
} /* if */ |
|
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
337 |
|
337 | 338 |
while (finfo->uncompressed_position != offset) |
339 |
{ |
|
340 |
PHYSFS_uint8 buf[512]; |
|
540
a6b6f0a54cd2
Attempt at type correctness.
Ryan C. Gordon <icculus@icculus.org>
parents:
538
diff
changeset
|
341 |
PHYSFS_uint32 maxread; |
a6b6f0a54cd2
Attempt at type correctness.
Ryan C. Gordon <icculus@icculus.org>
parents:
538
diff
changeset
|
342 |
|
a6b6f0a54cd2
Attempt at type correctness.
Ryan C. Gordon <icculus@icculus.org>
parents:
538
diff
changeset
|
343 |
maxread = (PHYSFS_uint32) (offset - finfo->uncompressed_position); |
337 | 344 |
if (maxread > sizeof (buf)) |
345 |
maxread = sizeof (buf); |
|
346 |
||
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
347 |
if (ZIP_read(finfo, buf, maxread, 1) != 1) |
337 | 348 |
return(0); |
349 |
} /* while */ |
|
350 |
} /* else */ |
|
351 |
||
352 |
return(1); |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
353 |
} /* ZIP_seek */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
354 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
355 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
356 |
static PHYSFS_sint64 ZIP_fileLength(fvoid *opaque) |
28
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
357 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
358 |
ZIPfileinfo *finfo = (ZIPfileinfo *) opaque; |
337 | 359 |
return(finfo->entry->uncompressed_size); |
28
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
360 |
} /* ZIP_fileLength */ |
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
361 |
|
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
362 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
363 |
static int ZIP_fileClose(fvoid *opaque) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
364 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
365 |
ZIPfileinfo *finfo = (ZIPfileinfo *) opaque; |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
366 |
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0); |
337 | 367 |
|
368 |
if (finfo->entry->compression_method != COMPMETH_NONE) |
|
369 |
inflateEnd(&finfo->stream); |
|
370 |
||
371 |
if (finfo->buffer != NULL) |
|
372 |
free(finfo->buffer); |
|
373 |
||
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
374 |
free(finfo); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
375 |
return(1); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
376 |
} /* ZIP_fileClose */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
377 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
378 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
379 |
static PHYSFS_sint64 zip_find_end_of_central_dir(void *in, PHYSFS_sint64 *len) |
337 | 380 |
{ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
381 |
PHYSFS_uint8 buf[256]; |
413
d669d303317d
Initialized some variables to stop compiler whining.
Ryan C. Gordon <icculus@icculus.org>
parents:
402
diff
changeset
|
382 |
PHYSFS_sint32 i = 0; |
337 | 383 |
PHYSFS_sint64 filelen; |
384 |
PHYSFS_sint64 filepos; |
|
385 |
PHYSFS_sint32 maxread; |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
386 |
PHYSFS_sint32 totalread = 0; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
387 |
int found = 0; |
413
d669d303317d
Initialized some variables to stop compiler whining.
Ryan C. Gordon <icculus@icculus.org>
parents:
402
diff
changeset
|
388 |
PHYSFS_uint32 extra = 0; |
337 | 389 |
|
390 |
filelen = __PHYSFS_platformFileLength(in); |
|
391 |
BAIL_IF_MACRO(filelen == -1, NULL, 0); |
|
541
2be2fff14b7a
Another attempt at type size correctness.
Ryan C. Gordon <icculus@icculus.org>
parents:
540
diff
changeset
|
392 |
BAIL_IF_MACRO(filelen > 0xFFFFFFFF, "ZIP bigger than 2 gigs?!", 0); |
337 | 393 |
|
394 |
/* |
|
395 |
* Jump to the end of the file and start reading backwards. |
|
396 |
* The last thing in the file is the zipfile comment, which is variable |
|
397 |
* length, and the field that specifies its size is before it in the |
|
398 |
* file (argh!)...this means that we need to scan backwards until we |
|
399 |
* hit the end-of-central-dir signature. We can then sanity check that |
|
400 |
* the comment was as big as it should be to make sure we're in the |
|
401 |
* right place. The comment length field is 16 bits, so we can stop |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
402 |
* searching for that signature after a little more than 64k at most, |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
403 |
* and call it a corrupted zipfile. |
337 | 404 |
*/ |
405 |
||
406 |
if (sizeof (buf) < filelen) |
|
407 |
{ |
|
408 |
filepos = filelen - sizeof (buf); |
|
409 |
maxread = sizeof (buf); |
|
410 |
} /* if */ |
|
411 |
else |
|
412 |
{ |
|
413 |
filepos = 0; |
|
541
2be2fff14b7a
Another attempt at type size correctness.
Ryan C. Gordon <icculus@icculus.org>
parents:
540
diff
changeset
|
414 |
maxread = (PHYSFS_uint32) filelen; |
337 | 415 |
} /* else */ |
416 |
||
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
417 |
while ((totalread < filelen) && (totalread < 65557)) |
337 | 418 |
{ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
419 |
BAIL_IF_MACRO(!__PHYSFS_platformSeek(in, filepos), NULL, -1); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
420 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
421 |
/* make sure we catch a signature between buffers. */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
422 |
if (totalread != 0) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
423 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
424 |
if (__PHYSFS_platformRead(in, buf, maxread - 4, 1) != 1) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
425 |
return(-1); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
426 |
*((PHYSFS_uint32 *) (&buf[maxread - 4])) = extra; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
427 |
totalread += maxread - 4; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
428 |
} /* if */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
429 |
else |
337 | 430 |
{ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
431 |
if (__PHYSFS_platformRead(in, buf, maxread, 1) != 1) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
432 |
return(-1); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
433 |
totalread += maxread; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
434 |
} /* else */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
435 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
436 |
extra = *((PHYSFS_uint32 *) (&buf[0])); |
337 | 437 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
438 |
for (i = maxread - 4; i > 0; i--) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
439 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
440 |
if ((buf[i + 0] == 0x50) && |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
441 |
(buf[i + 1] == 0x4B) && |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
442 |
(buf[i + 2] == 0x05) && |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
443 |
(buf[i + 3] == 0x06) ) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
444 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
445 |
found = 1; /* that's the signature! */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
446 |
break; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
447 |
} /* if */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
448 |
} /* for */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
449 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
450 |
if (found) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
451 |
break; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
452 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
453 |
filepos -= (maxread - 4); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
454 |
} /* while */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
455 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
456 |
BAIL_IF_MACRO(!found, ERR_NOT_AN_ARCHIVE, -1); |
337 | 457 |
|
458 |
if (len != NULL) |
|
459 |
*len = filelen; |
|
460 |
||
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
461 |
return(filepos + i); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
462 |
} /* zip_find_end_of_central_dir */ |
337 | 463 |
|
464 |
||
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
465 |
static int ZIP_isArchive(const char *filename, int forWriting) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
466 |
{ |
337 | 467 |
PHYSFS_uint32 sig; |
446
e1f7fe003b70
Fix for correct cleanup on read error.
Ryan C. Gordon <icculus@icculus.org>
parents:
429
diff
changeset
|
468 |
int retval = 0; |
337 | 469 |
void *in; |
470 |
||
471 |
in = __PHYSFS_platformOpenRead(filename); |
|
472 |
BAIL_IF_MACRO(in == NULL, NULL, 0); |
|
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
473 |
|
337 | 474 |
/* |
475 |
* The first thing in a zip file might be the signature of the |
|
476 |
* first local file record, so it makes for a quick determination. |
|
477 |
*/ |
|
446
e1f7fe003b70
Fix for correct cleanup on read error.
Ryan C. Gordon <icculus@icculus.org>
parents:
429
diff
changeset
|
478 |
if (readui32(in, &sig)) |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
479 |
{ |
446
e1f7fe003b70
Fix for correct cleanup on read error.
Ryan C. Gordon <icculus@icculus.org>
parents:
429
diff
changeset
|
480 |
retval = (sig == ZIP_LOCAL_FILE_SIG); |
e1f7fe003b70
Fix for correct cleanup on read error.
Ryan C. Gordon <icculus@icculus.org>
parents:
429
diff
changeset
|
481 |
if (!retval) |
e1f7fe003b70
Fix for correct cleanup on read error.
Ryan C. Gordon <icculus@icculus.org>
parents:
429
diff
changeset
|
482 |
{ |
e1f7fe003b70
Fix for correct cleanup on read error.
Ryan C. Gordon <icculus@icculus.org>
parents:
429
diff
changeset
|
483 |
/* |
e1f7fe003b70
Fix for correct cleanup on read error.
Ryan C. Gordon <icculus@icculus.org>
parents:
429
diff
changeset
|
484 |
* No sig...might be a ZIP with data at the start |
e1f7fe003b70
Fix for correct cleanup on read error.
Ryan C. Gordon <icculus@icculus.org>
parents:
429
diff
changeset
|
485 |
* (a self-extracting executable, etc), so we'll have to do |
e1f7fe003b70
Fix for correct cleanup on read error.
Ryan C. Gordon <icculus@icculus.org>
parents:
429
diff
changeset
|
486 |
* it the hard way... |
e1f7fe003b70
Fix for correct cleanup on read error.
Ryan C. Gordon <icculus@icculus.org>
parents:
429
diff
changeset
|
487 |
*/ |
e1f7fe003b70
Fix for correct cleanup on read error.
Ryan C. Gordon <icculus@icculus.org>
parents:
429
diff
changeset
|
488 |
retval = (zip_find_end_of_central_dir(in, NULL) != -1); |
e1f7fe003b70
Fix for correct cleanup on read error.
Ryan C. Gordon <icculus@icculus.org>
parents:
429
diff
changeset
|
489 |
} /* if */ |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
490 |
} /* if */ |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
491 |
|
337 | 492 |
__PHYSFS_platformClose(in); |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
493 |
return(retval); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
494 |
} /* ZIP_isArchive */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
495 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
496 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
497 |
static void zip_free_entries(ZIPentry *entries, PHYSFS_uint32 max) |
337 | 498 |
{ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
499 |
PHYSFS_uint32 i; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
500 |
for (i = 0; i < max; i++) |
337 | 501 |
{ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
502 |
ZIPentry *entry = &entries[i]; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
503 |
if (entry->name != NULL) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
504 |
free(entry->name); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
505 |
} /* for */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
506 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
507 |
free(entries); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
508 |
} /* zip_free_entries */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
509 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
510 |
|
483
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
511 |
/* |
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
512 |
* This will find the ZIPentry associated with a path in platform-independent |
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
513 |
* notation. Directories don't have ZIPentries associated with them, but |
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
514 |
* (*isDir) will be set to non-zero if a dir was hit. |
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
515 |
*/ |
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
516 |
static ZIPentry *zip_find_entry(ZIPinfo *info, const char *path, int *isDir) |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
517 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
518 |
ZIPentry *a = info->entries; |
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
519 |
PHYSFS_sint32 pathlen = strlen(path); |
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
520 |
PHYSFS_sint32 lo = 0; |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
521 |
PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
522 |
PHYSFS_sint32 middle; |
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
523 |
const char *thispath = NULL; |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
524 |
int rc; |
337 | 525 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
526 |
while (lo <= hi) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
527 |
{ |
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
528 |
middle = lo + ((hi - lo) / 2); |
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
529 |
thispath = a[middle].name; |
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
530 |
rc = strncmp(path, thispath, pathlen); |
483
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
531 |
|
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
532 |
if (rc > 0) |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
533 |
lo = middle + 1; |
483
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
534 |
|
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
535 |
else if (rc < 0) |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
536 |
hi = middle - 1; |
483
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
537 |
|
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
538 |
else /* substring match...might be dir or entry or nothing. */ |
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
539 |
{ |
483
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
540 |
if (isDir != NULL) |
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
541 |
{ |
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
542 |
*isDir = (thispath[pathlen] == '/'); |
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
543 |
if (*isDir) |
483
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
544 |
return(NULL); |
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
545 |
} /* if */ |
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
546 |
|
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
547 |
if (thispath[pathlen] == '\0') /* found entry? */ |
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
548 |
return(&a[middle]); |
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
549 |
else |
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
550 |
hi = middle - 1; /* adjust search params, try again. */ |
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
551 |
} /* if */ |
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
552 |
} /* while */ |
483
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
553 |
|
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
554 |
if (isDir != NULL) |
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
555 |
*isDir = 0; |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
556 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
557 |
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
558 |
} /* zip_find_entry */ |
337 | 559 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
560 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
561 |
/* Convert paths from old, buggy DOS zippers... */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
562 |
static void zip_convert_dos_path(ZIPentry *entry, char *path) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
563 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
564 |
PHYSFS_uint8 hosttype = (PHYSFS_uint8) ((entry->version >> 8) & 0xFF); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
565 |
if (hosttype == 0) /* FS_FAT_ */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
566 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
567 |
while (*path) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
568 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
569 |
if (*path == '\\') |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
570 |
*path = '/'; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
571 |
path++; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
572 |
} /* while */ |
337 | 573 |
} /* if */ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
574 |
} /* zip_convert_dos_path */ |
337 | 575 |
|
576 |
||
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
577 |
static void zip_expand_symlink_path(char *path) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
578 |
{ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
579 |
char *ptr = path; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
580 |
char *prevptr = path; |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
581 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
582 |
while (1) |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
583 |
{ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
584 |
ptr = strchr(ptr, '/'); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
585 |
if (ptr == NULL) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
586 |
break; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
587 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
588 |
if (*(ptr + 1) == '.') |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
589 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
590 |
if (*(ptr + 2) == '/') |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
591 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
592 |
/* current dir in middle of string: ditch it. */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
593 |
memmove(ptr, ptr + 2, strlen(ptr + 2) + 1); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
594 |
} /* else if */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
595 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
596 |
else if (*(ptr + 2) == '\0') |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
597 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
598 |
/* current dir at end of string: ditch it. */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
599 |
*ptr = '\0'; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
600 |
} /* else if */ |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
601 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
602 |
else if (*(ptr + 2) == '.') |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
603 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
604 |
if (*(ptr + 3) == '/') |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
605 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
606 |
/* parent dir in middle: move back one, if possible. */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
607 |
memmove(prevptr, ptr + 4, strlen(ptr + 4) + 1); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
608 |
ptr = prevptr; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
609 |
while (prevptr != path) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
610 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
611 |
prevptr--; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
612 |
if (*prevptr == '/') |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
613 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
614 |
prevptr++; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
615 |
break; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
616 |
} /* if */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
617 |
} /* while */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
618 |
} /* if */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
619 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
620 |
if (*(ptr + 3) == '\0') |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
621 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
622 |
/* parent dir at end: move back one, if possible. */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
623 |
*prevptr = '\0'; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
624 |
} /* if */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
625 |
} /* if */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
626 |
} /* if */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
627 |
else |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
628 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
629 |
prevptr = ptr; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
630 |
} /* else */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
631 |
} /* while */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
632 |
} /* zip_expand_symlink_path */ |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
633 |
|
658
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
634 |
/* (forward reference: zip_follow_symlink and zip_resolve call each other.) */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
635 |
static int zip_resolve(void *in, ZIPinfo *info, ZIPentry *entry); |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
636 |
|
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
637 |
/* |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
638 |
* Look for the entry named by (path). If it exists, resolve it, and return |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
639 |
* a pointer to that entry. If it's another symlink, keep resolving until you |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
640 |
* hit a real file and then return a pointer to the final non-symlink entry. |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
641 |
* If there's a problem, return NULL. (path) is always free()'d by this |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
642 |
* function. |
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
643 |
*/ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
644 |
static ZIPentry *zip_follow_symlink(void *in, ZIPinfo *info, char *path) |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
645 |
{ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
646 |
ZIPentry *entry; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
647 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
648 |
zip_expand_symlink_path(path); |
483
d788c84d8694
Fixed bug that prevented use when symlinks were disallowed.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
649 |
entry = zip_find_entry(info, path, NULL); |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
650 |
if (entry != NULL) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
651 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
652 |
if (!zip_resolve(in, info, entry)) /* recursive! */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
653 |
entry = NULL; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
654 |
else |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
655 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
656 |
if (entry->symlink != NULL) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
657 |
entry = entry->symlink; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
658 |
} /* else */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
659 |
} /* if */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
660 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
661 |
free(path); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
662 |
return(entry); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
663 |
} /* zip_follow_symlink */ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
664 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
665 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
666 |
static int zip_resolve_symlink(void *in, ZIPinfo *info, ZIPentry *entry) |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
667 |
{ |
337 | 668 |
char *path; |
669 |
PHYSFS_uint32 size = entry->uncompressed_size; |
|
670 |
int rc = 0; |
|
671 |
||
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
672 |
/* |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
673 |
* We've already parsed the local file header of the symlink at this |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
674 |
* point. Now we need to read the actual link from the file data and |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
675 |
* follow it. |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
676 |
*/ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
677 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
678 |
BAIL_IF_MACRO(!__PHYSFS_platformSeek(in, entry->offset), NULL, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
679 |
|
337 | 680 |
path = (char *) malloc(size + 1); |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
681 |
BAIL_IF_MACRO(path == NULL, ERR_OUT_OF_MEMORY, 0); |
337 | 682 |
|
683 |
if (entry->compression_method == COMPMETH_NONE) |
|
684 |
rc = (__PHYSFS_platformRead(in, path, size, 1) == 1); |
|
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
685 |
|
337 | 686 |
else /* symlink target path is compressed... */ |
687 |
{ |
|
688 |
z_stream stream; |
|
340
24a11f8566f8
Symlink fixes. Still broken, though.
Ryan C. Gordon <icculus@icculus.org>
parents:
337
diff
changeset
|
689 |
PHYSFS_uint32 compsize = entry->compressed_size; |
337 | 690 |
PHYSFS_uint8 *compressed = (PHYSFS_uint8 *) malloc(compsize); |
691 |
if (compressed != NULL) |
|
692 |
{ |
|
693 |
if (__PHYSFS_platformRead(in, compressed, compsize, 1) == 1) |
|
694 |
{ |
|
644
1cb5533d369c
Initial structure for replacable allocator work.
Ryan C. Gordon <icculus@icculus.org>
parents:
579
diff
changeset
|
695 |
initializeZStream(&stream); |
337 | 696 |
stream.next_in = compressed; |
697 |
stream.avail_in = compsize; |
|
538
8752e3c0dbf9
Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
698 |
stream.next_out = (unsigned char *) path; |
337 | 699 |
stream.avail_out = size; |
700 |
if (zlib_err(inflateInit2(&stream, -MAX_WBITS)) == Z_OK) |
|
701 |
{ |
|
340
24a11f8566f8
Symlink fixes. Still broken, though.
Ryan C. Gordon <icculus@icculus.org>
parents:
337
diff
changeset
|
702 |
rc = zlib_err(inflate(&stream, Z_FINISH)); |
337 | 703 |
inflateEnd(&stream); |
340
24a11f8566f8
Symlink fixes. Still broken, though.
Ryan C. Gordon <icculus@icculus.org>
parents:
337
diff
changeset
|
704 |
|
24a11f8566f8
Symlink fixes. Still broken, though.
Ryan C. Gordon <icculus@icculus.org>
parents:
337
diff
changeset
|
705 |
/* both are acceptable outcomes... */ |
24a11f8566f8
Symlink fixes. Still broken, though.
Ryan C. Gordon <icculus@icculus.org>
parents:
337
diff
changeset
|
706 |
rc = ((rc == Z_OK) || (rc == Z_STREAM_END)); |
337 | 707 |
} /* if */ |
708 |
} /* if */ |
|
709 |
free(compressed); |
|
710 |
} /* if */ |
|
711 |
} /* else */ |
|
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
712 |
|
337 | 713 |
if (!rc) |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
714 |
free(path); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
715 |
else |
337 | 716 |
{ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
717 |
path[entry->uncompressed_size] = '\0'; /* null-terminate it. */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
718 |
zip_convert_dos_path(entry, path); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
719 |
entry->symlink = zip_follow_symlink(in, info, path); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
720 |
} /* else */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
721 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
722 |
return(entry->symlink != NULL); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
723 |
} /* zip_resolve_symlink */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
724 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
725 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
726 |
/* |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
727 |
* Parse the local file header of an entry, and update entry->offset. |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
728 |
*/ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
729 |
static int zip_parse_local(void *in, ZIPentry *entry) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
730 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
731 |
PHYSFS_uint32 ui32; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
732 |
PHYSFS_uint16 ui16; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
733 |
PHYSFS_uint16 fnamelen; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
734 |
PHYSFS_uint16 extralen; |
337 | 735 |
|
551
f0fc464fd51b
Fixed seeking in uncompressed zip entries and handle Java-created JAR files.
Ryan C. Gordon <icculus@icculus.org>
parents:
541
diff
changeset
|
736 |
/* |
f0fc464fd51b
Fixed seeking in uncompressed zip entries and handle Java-created JAR files.
Ryan C. Gordon <icculus@icculus.org>
parents:
541
diff
changeset
|
737 |
* crc and (un)compressed_size are always zero if this is a "JAR" |
f0fc464fd51b
Fixed seeking in uncompressed zip entries and handle Java-created JAR files.
Ryan C. Gordon <icculus@icculus.org>
parents:
541
diff
changeset
|
738 |
* archive created with Sun's Java tools, apparently. We only |
f0fc464fd51b
Fixed seeking in uncompressed zip entries and handle Java-created JAR files.
Ryan C. Gordon <icculus@icculus.org>
parents:
541
diff
changeset
|
739 |
* consider this archive corrupted if those entries don't match and |
f0fc464fd51b
Fixed seeking in uncompressed zip entries and handle Java-created JAR files.
Ryan C. Gordon <icculus@icculus.org>
parents:
541
diff
changeset
|
740 |
* aren't zero. That seems to work well. |
f0fc464fd51b
Fixed seeking in uncompressed zip entries and handle Java-created JAR files.
Ryan C. Gordon <icculus@icculus.org>
parents:
541
diff
changeset
|
741 |
*/ |
f0fc464fd51b
Fixed seeking in uncompressed zip entries and handle Java-created JAR files.
Ryan C. Gordon <icculus@icculus.org>
parents:
541
diff
changeset
|
742 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
743 |
BAIL_IF_MACRO(!__PHYSFS_platformSeek(in, entry->offset), NULL, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
744 |
BAIL_IF_MACRO(!readui32(in, &ui32), NULL, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
745 |
BAIL_IF_MACRO(ui32 != ZIP_LOCAL_FILE_SIG, ERR_CORRUPTED, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
746 |
BAIL_IF_MACRO(!readui16(in, &ui16), NULL, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
747 |
BAIL_IF_MACRO(ui16 != entry->version_needed, ERR_CORRUPTED, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
748 |
BAIL_IF_MACRO(!readui16(in, &ui16), NULL, 0); /* general bits. */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
749 |
BAIL_IF_MACRO(!readui16(in, &ui16), NULL, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
750 |
BAIL_IF_MACRO(ui16 != entry->compression_method, ERR_CORRUPTED, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
751 |
BAIL_IF_MACRO(!readui32(in, &ui32), NULL, 0); /* date/time */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
752 |
BAIL_IF_MACRO(!readui32(in, &ui32), NULL, 0); |
551
f0fc464fd51b
Fixed seeking in uncompressed zip entries and handle Java-created JAR files.
Ryan C. Gordon <icculus@icculus.org>
parents:
541
diff
changeset
|
753 |
BAIL_IF_MACRO(ui32 && (ui32 != entry->crc), ERR_CORRUPTED, 0); |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
754 |
BAIL_IF_MACRO(!readui32(in, &ui32), NULL, 0); |
551
f0fc464fd51b
Fixed seeking in uncompressed zip entries and handle Java-created JAR files.
Ryan C. Gordon <icculus@icculus.org>
parents:
541
diff
changeset
|
755 |
BAIL_IF_MACRO(ui32 && (ui32 != entry->compressed_size), ERR_CORRUPTED, 0); |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
756 |
BAIL_IF_MACRO(!readui32(in, &ui32), NULL, 0); |
551
f0fc464fd51b
Fixed seeking in uncompressed zip entries and handle Java-created JAR files.
Ryan C. Gordon <icculus@icculus.org>
parents:
541
diff
changeset
|
757 |
BAIL_IF_MACRO(ui32 && (ui32 != entry->uncompressed_size),ERR_CORRUPTED,0); |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
758 |
BAIL_IF_MACRO(!readui16(in, &fnamelen), NULL, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
759 |
BAIL_IF_MACRO(!readui16(in, &extralen), NULL, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
760 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
761 |
entry->offset += fnamelen + extralen + 30; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
762 |
return(1); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
763 |
} /* zip_parse_local */ |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
764 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
765 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
766 |
static int zip_resolve(void *in, ZIPinfo *info, ZIPentry *entry) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
767 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
768 |
int retval = 1; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
769 |
ZipResolveType resolve_type = entry->resolved; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
770 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
771 |
/* Don't bother if we've failed to resolve this entry before. */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
772 |
BAIL_IF_MACRO(resolve_type == ZIP_BROKEN_FILE, ERR_CORRUPTED, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
773 |
BAIL_IF_MACRO(resolve_type == ZIP_BROKEN_SYMLINK, ERR_CORRUPTED, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
774 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
775 |
/* uhoh...infinite symlink loop! */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
776 |
BAIL_IF_MACRO(resolve_type == ZIP_RESOLVING, ERR_SYMLINK_LOOP, 0); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
777 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
778 |
/* |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
779 |
* We fix up the offset to point to the actual data on the |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
780 |
* first open, since we don't want to seek across the whole file on |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
781 |
* archive open (can be SLOW on large, CD-stored files), but we |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
782 |
* need to check the local file header...not just for corruption, |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
783 |
* but since it stores offset info the central directory does not. |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
784 |
*/ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
785 |
if (resolve_type != ZIP_RESOLVED) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
786 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
787 |
entry->resolved = ZIP_RESOLVING; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
788 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
789 |
retval = zip_parse_local(in, entry); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
790 |
if (retval) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
791 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
792 |
/* |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
793 |
* If it's a symlink, find the original file. This will cause |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
794 |
* resolution of other entries (other symlinks and, eventually, |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
795 |
* the real file) if all goes well. |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
796 |
*/ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
797 |
if (resolve_type == ZIP_UNRESOLVED_SYMLINK) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
798 |
retval = zip_resolve_symlink(in, info, entry); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
799 |
} /* if */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
800 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
801 |
if (resolve_type == ZIP_UNRESOLVED_SYMLINK) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
802 |
entry->resolved = ((retval) ? ZIP_RESOLVED : ZIP_BROKEN_SYMLINK); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
803 |
else if (resolve_type == ZIP_UNRESOLVED_FILE) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
804 |
entry->resolved = ((retval) ? ZIP_RESOLVED : ZIP_BROKEN_FILE); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
805 |
} /* if */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
806 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
807 |
return(retval); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
808 |
} /* zip_resolve */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
809 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
810 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
811 |
static int zip_version_does_symlinks(PHYSFS_uint32 version) |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
812 |
{ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
813 |
int retval = 0; |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
161
diff
changeset
|
814 |
PHYSFS_uint8 hosttype = (PHYSFS_uint8) ((version >> 8) & 0xFF); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
815 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
816 |
switch (hosttype) |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
817 |
{ |
342
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
818 |
/* |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
819 |
* These are the platforms that can NOT build an archive with |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
820 |
* symlinks, according to the Info-ZIP project. |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
821 |
*/ |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
822 |
case 0: /* FS_FAT_ */ |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
823 |
case 1: /* AMIGA_ */ |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
824 |
case 2: /* VMS_ */ |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
825 |
case 4: /* VM_CSM_ */ |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
826 |
case 6: /* FS_HPFS_ */ |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
827 |
case 11: /* FS_NTFS_ */ |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
828 |
case 14: /* FS_VFAT_ */ |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
829 |
case 13: /* ACORN_ */ |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
830 |
case 15: /* MVS_ */ |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
831 |
case 18: /* THEOS_ */ |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
832 |
break; /* do nothing. */ |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
833 |
|
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
834 |
default: /* assume the rest to be unix-like. */ |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
835 |
retval = 1; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
836 |
break; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
837 |
} /* switch */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
838 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
839 |
return(retval); |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
840 |
} /* zip_version_does_symlinks */ |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
841 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
842 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
843 |
static int zip_entry_is_symlink(ZIPentry *entry) |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
844 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
845 |
return((entry->resolved == ZIP_UNRESOLVED_SYMLINK) || |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
846 |
(entry->resolved == ZIP_BROKEN_SYMLINK) || |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
847 |
(entry->symlink)); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
848 |
} /* zip_entry_is_symlink */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
849 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
850 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
851 |
static int zip_has_symlink_attr(ZIPentry *entry, PHYSFS_uint32 extern_attr) |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
852 |
{ |
342
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
853 |
PHYSFS_uint16 xattr = ((extern_attr >> 16) & 0xFFFF); |
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
854 |
|
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
855 |
return ( |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
856 |
(zip_version_does_symlinks(entry->version)) && |
337 | 857 |
(entry->uncompressed_size > 0) && |
342
cef50576cb0b
Fixed symlink detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
858 |
((xattr & UNIX_FILETYPE_MASK) == UNIX_FILETYPE_SYMLINK) |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
859 |
); |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
860 |
} /* zip_has_symlink_attr */ |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
861 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
862 |
|
538
8752e3c0dbf9
Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
863 |
static PHYSFS_sint64 zip_dos_time_to_physfs_time(PHYSFS_uint32 dostime) |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
864 |
{ |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
551
diff
changeset
|
865 |
#ifdef _WIN32_WCE |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
866 |
/* We have no struct tm and no mktime right now. |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
867 |
FIXME: This should probably be fixed at some point. |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
868 |
*/ |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
551
diff
changeset
|
869 |
return -1; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
551
diff
changeset
|
870 |
#else |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
871 |
PHYSFS_uint32 dosdate; |
337 | 872 |
struct tm unixtime; |
873 |
memset(&unixtime, '\0', sizeof (unixtime)); |
|
874 |
||
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
875 |
dosdate = (PHYSFS_uint32) ((dostime >> 16) & 0xFFFF); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
876 |
dostime &= 0xFFFF; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
877 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
878 |
/* dissect date */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
879 |
unixtime.tm_year = ((dosdate >> 9) & 0x7F) + 80; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
880 |
unixtime.tm_mon = ((dosdate >> 5) & 0x0F) - 1; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
881 |
unixtime.tm_mday = ((dosdate ) & 0x1F); |
337 | 882 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
883 |
/* dissect time */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
884 |
unixtime.tm_hour = ((dostime >> 11) & 0x1F); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
885 |
unixtime.tm_min = ((dostime >> 5) & 0x3F); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
886 |
unixtime.tm_sec = ((dostime << 1) & 0x3E); |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
887 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
888 |
/* let mktime calculate daylight savings time. */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
889 |
unixtime.tm_isdst = -1; |
337 | 890 |
|
891 |
return((PHYSFS_sint64) mktime(&unixtime)); |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
551
diff
changeset
|
892 |
#endif |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
893 |
} /* zip_dos_time_to_physfs_time */ |
337 | 894 |
|
895 |
||
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
896 |
static int zip_load_entry(void *in, ZIPentry *entry, PHYSFS_uint32 ofs_fixup) |
337 | 897 |
{ |
898 |
PHYSFS_uint16 fnamelen, extralen, commentlen; |
|
899 |
PHYSFS_uint32 external_attr; |
|
900 |
PHYSFS_uint16 ui16; |
|
901 |
PHYSFS_uint32 ui32; |
|
902 |
PHYSFS_sint64 si64; |
|
903 |
||
904 |
/* sanity check with central directory signature... */ |
|
905 |
BAIL_IF_MACRO(!readui32(in, &ui32), NULL, 0); |
|
906 |
BAIL_IF_MACRO(ui32 != ZIP_CENTRAL_DIR_SIG, ERR_CORRUPTED, 0); |
|
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
907 |
|
337 | 908 |
/* Get the pertinent parts of the record... */ |
909 |
BAIL_IF_MACRO(!readui16(in, &entry->version), NULL, 0); |
|
910 |
BAIL_IF_MACRO(!readui16(in, &entry->version_needed), NULL, 0); |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
911 |
BAIL_IF_MACRO(!readui16(in, &ui16), NULL, 0); /* general bits */ |
337 | 912 |
BAIL_IF_MACRO(!readui16(in, &entry->compression_method), NULL, 0); |
913 |
BAIL_IF_MACRO(!readui32(in, &ui32), NULL, 0); |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
914 |
entry->last_mod_time = zip_dos_time_to_physfs_time(ui32); |
337 | 915 |
BAIL_IF_MACRO(!readui32(in, &entry->crc), NULL, 0); |
916 |
BAIL_IF_MACRO(!readui32(in, &entry->compressed_size), NULL, 0); |
|
917 |
BAIL_IF_MACRO(!readui32(in, &entry->uncompressed_size), NULL, 0); |
|
918 |
BAIL_IF_MACRO(!readui16(in, &fnamelen), NULL, 0); |
|
919 |
BAIL_IF_MACRO(!readui16(in, &extralen), NULL, 0); |
|
920 |
BAIL_IF_MACRO(!readui16(in, &commentlen), NULL, 0); |
|
921 |
BAIL_IF_MACRO(!readui16(in, &ui16), NULL, 0); /* disk number start */ |
|
922 |
BAIL_IF_MACRO(!readui16(in, &ui16), NULL, 0); /* internal file attribs */ |
|
923 |
BAIL_IF_MACRO(!readui32(in, &external_attr), NULL, 0); |
|
924 |
BAIL_IF_MACRO(!readui32(in, &entry->offset), NULL, 0); |
|
925 |
entry->offset += ofs_fixup; |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
926 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
927 |
entry->symlink = NULL; /* will be resolved later, if necessary. */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
928 |
entry->resolved = (zip_has_symlink_attr(entry, external_attr)) ? |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
929 |
ZIP_UNRESOLVED_SYMLINK : ZIP_UNRESOLVED_FILE; |
337 | 930 |
|
931 |
entry->name = (char *) malloc(fnamelen + 1); |
|
932 |
BAIL_IF_MACRO(entry->name == NULL, ERR_OUT_OF_MEMORY, 0); |
|
933 |
if (__PHYSFS_platformRead(in, entry->name, fnamelen, 1) != 1) |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
934 |
goto zip_load_entry_puked; |
337 | 935 |
|
936 |
entry->name[fnamelen] = '\0'; /* null-terminate the filename. */ |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
937 |
zip_convert_dos_path(entry, entry->name); |
337 | 938 |
|
939 |
si64 = __PHYSFS_platformTell(in); |
|
940 |
if (si64 == -1) |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
941 |
goto zip_load_entry_puked; |
337 | 942 |
|
943 |
/* seek to the start of the next entry in the central directory... */ |
|
944 |
if (!__PHYSFS_platformSeek(in, si64 + extralen + commentlen)) |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
945 |
goto zip_load_entry_puked; |
337 | 946 |
|
947 |
return(1); /* success. */ |
|
948 |
||
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
949 |
zip_load_entry_puked: |
337 | 950 |
free(entry->name); |
951 |
return(0); /* failure. */ |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
952 |
} /* zip_load_entry */ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
953 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
954 |
|
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
446
diff
changeset
|
955 |
static int zip_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
956 |
{ |
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
446
diff
changeset
|
957 |
ZIPentry *a = (ZIPentry *) _a; |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
446
diff
changeset
|
958 |
return(strcmp(a[one].name, a[two].name)); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
446
diff
changeset
|
959 |
} /* zip_entry_cmp */ |
337 | 960 |
|
961 |
||
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
446
diff
changeset
|
962 |
static void zip_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
963 |
{ |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
964 |
ZIPentry tmp; |
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
446
diff
changeset
|
965 |
ZIPentry *first = &(((ZIPentry *) _a)[one]); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
446
diff
changeset
|
966 |
ZIPentry *second = &(((ZIPentry *) _a)[two]); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
446
diff
changeset
|
967 |
memcpy(&tmp, first, sizeof (ZIPentry)); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
446
diff
changeset
|
968 |
memcpy(first, second, sizeof (ZIPentry)); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
446
diff
changeset
|
969 |
memcpy(second, &tmp, sizeof (ZIPentry)); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
446
diff
changeset
|
970 |
} /* zip_entry_swap */ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
971 |
|
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
972 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
973 |
static int zip_load_entries(void *in, ZIPinfo *info, |
337 | 974 |
PHYSFS_uint32 data_ofs, PHYSFS_uint32 central_ofs) |
975 |
{ |
|
976 |
PHYSFS_uint32 max = info->entryCount; |
|
977 |
PHYSFS_uint32 i; |
|
978 |
||
979 |
BAIL_IF_MACRO(!__PHYSFS_platformSeek(in, central_ofs), NULL, 0); |
|
980 |
||
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
981 |
info->entries = (ZIPentry *) malloc(sizeof (ZIPentry) * max); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
982 |
BAIL_IF_MACRO(info->entries == NULL, ERR_OUT_OF_MEMORY, 0); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
983 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
984 |
for (i = 0; i < max; i++) |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
985 |
{ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
986 |
if (!zip_load_entry(in, &info->entries[i], data_ofs)) |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
987 |
{ |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
988 |
zip_free_entries(info->entries, i); |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
989 |
return(0); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
990 |
} /* if */ |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
991 |
} /* for */ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
992 |
|
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
446
diff
changeset
|
993 |
__PHYSFS_sort(info->entries, max, zip_entry_cmp, zip_entry_swap); |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
994 |
return(1); |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
995 |
} /* zip_load_entries */ |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
996 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
997 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
998 |
static int zip_parse_end_of_central_dir(void *in, ZIPinfo *info, |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
999 |
PHYSFS_uint32 *data_start, |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
1000 |
PHYSFS_uint32 *central_dir_ofs) |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
1001 |
{ |
337 | 1002 |
PHYSFS_uint32 ui32; |
1003 |
PHYSFS_uint16 ui16; |
|
1004 |
PHYSFS_sint64 len; |
|
1005 |
PHYSFS_sint64 pos; |
|
1006 |
||
1007 |
/* find the end-of-central-dir record, and seek to it. */ |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
1008 |
pos = zip_find_end_of_central_dir(in, &len); |
337 | 1009 |
BAIL_IF_MACRO(pos == -1, NULL, 0); |
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
1010 |
BAIL_IF_MACRO(!__PHYSFS_platformSeek(in, pos), NULL, 0); |
337 | 1011 |
|
1012 |
/* check signature again, just in case. */ |
|
1013 |
BAIL_IF_MACRO(!readui32(in, &ui32), NULL, 0); |
|
1014 |
BAIL_IF_MACRO(ui32 != ZIP_END_OF_CENTRAL_DIR_SIG, ERR_NOT_AN_ARCHIVE, 0); |
|
1015 |
||
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
1016 |
/* number of this disk */ |
337 | 1017 |
BAIL_IF_MACRO(!readui16(in, &ui16), NULL, 0); |
1018 |
BAIL_IF_MACRO(ui16 != 0, ERR_UNSUPPORTED_ARCHIVE, 0); |
|
1019 |
||
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
1020 |
/* number of the disk with the start of the central directory */ |
337 | 1021 |
BAIL_IF_MACRO(!readui16(in, &ui16), NULL, 0); |
1022 |
BAIL_IF_MACRO(ui16 != 0, ERR_UNSUPPORTED_ARCHIVE, 0); |
|
1023 |
||
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
1024 |
/* total number of entries in the central dir on this disk */ |
337 | 1025 |
BAIL_IF_MACRO(!readui16(in, &ui16), NULL, 0); |
1026 |
||
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
1027 |
/* total number of entries in the central dir */ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1028 |
BAIL_IF_MACRO(!readui16(in, &info->entryCount), NULL, 0); |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1029 |
BAIL_IF_MACRO(ui16 != info->entryCount, ERR_UNSUPPORTED_ARCHIVE, 0); |
337 | 1030 |
|
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
1031 |
/* size of the central directory */ |
337 | 1032 |
BAIL_IF_MACRO(!readui32(in, &ui32), NULL, 0); |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
1033 |
|
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
1034 |
/* offset of central directory */ |
337 | 1035 |
BAIL_IF_MACRO(!readui32(in, central_dir_ofs), NULL, 0); |
1036 |
BAIL_IF_MACRO(pos < *central_dir_ofs + ui32, ERR_UNSUPPORTED_ARCHIVE, 0); |
|
1037 |
||
1038 |
/* |
|
1039 |
* For self-extracting archives, etc, there's crapola in the file |
|
1040 |
* before the zipfile records; we calculate how much data there is |
|
1041 |
* prepended by determining how far the central directory offset is |
|
1042 |
* from where it is supposed to be (start of end-of-central-dir minus |
|
1043 |
* sizeof central dir)...the difference in bytes is how much arbitrary |
|
1044 |
* data is at the start of the physical file. |
|
1045 |
*/ |
|
541
2be2fff14b7a
Another attempt at type size correctness.
Ryan C. Gordon <icculus@icculus.org>
parents:
540
diff
changeset
|
1046 |
*data_start = (PHYSFS_uint32) (pos - (*central_dir_ofs + ui32)); |
337 | 1047 |
|
1048 |
/* Now that we know the difference, fix up the central dir offset... */ |
|
1049 |
*central_dir_ofs += *data_start; |
|
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
1050 |
|
491
b8853d8a09cb
Fixed infinite loop bug, cleaned out tab chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
1051 |
/* zipfile comment length */ |
337 | 1052 |
BAIL_IF_MACRO(!readui16(in, &ui16), NULL, 0); |
1053 |
||
1054 |
/* |
|
1055 |
* Make sure that the comment length matches to the end of file... |
|
1056 |
* If it doesn't, we're either in the wrong part of the file, or the |
|
1057 |
* file is corrupted, but we give up either way. |
|
1058 |
*/ |
|
1059 |
BAIL_IF_MACRO((pos + 22 + ui16) != len, ERR_UNSUPPORTED_ARCHIVE, 0); |
|
1060 |
||
1061 |
return(1); /* made it. */ |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
1062 |
} /* zip_parse_end_of_central_dir */ |
337 | 1063 |
|
1064 |
||
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1065 |
static ZIPinfo *zip_create_zipinfo(const char *name) |
337 | 1066 |
{ |
1067 |
char *ptr; |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1068 |
ZIPinfo *info = (ZIPinfo *) malloc(sizeof (ZIPinfo)); |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1069 |
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0); |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
1070 |
memset(info, '\0', sizeof (ZIPinfo)); |
337 | 1071 |
|
1072 |
ptr = (char *) malloc(strlen(name) + 1); |
|
1073 |
if (ptr == NULL) |
|
1074 |
{ |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
1075 |
free(info); |
337 | 1076 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
1077 |
} /* if */ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
1078 |
|
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
1079 |
info->archiveName = ptr; |
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
1080 |
strcpy(info->archiveName, name); |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1081 |
return(info); |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1082 |
} /* zip_create_zipinfo */ |
337 | 1083 |
|
1084 |
||
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1085 |
static void *ZIP_openArchive(const char *name, int forWriting) |
337 | 1086 |
{ |
1087 |
void *in = NULL; |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1088 |
ZIPinfo *info = NULL; |
337 | 1089 |
PHYSFS_uint32 data_start; |
365
3d087cde1252
My rewrite continues. I'm mostly satisfied with this code now, minus debugging.
Ryan C. Gordon <icculus@icculus.org>
parents:
345
diff
changeset
|
1090 |
PHYSFS_uint32 cent_dir_ofs; |
337 | 1091 |
|
1092 |
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL); |
|
1093 |
||
1094 |
if ((in = __PHYSFS_platformOpenRead(name)) == NULL) |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1095 |
goto zip_openarchive_failed; |
337 | 1096 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1097 |
if ((info = zip_create_zipinfo(name)) == NULL) |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1098 |
goto zip_openarchive_failed; |
337 | 1099 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1100 |
if (!zip_parse_end_of_central_dir(in, info, &data_start, ¢_dir_ofs)) |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1101 |
goto zip_openarchive_failed; |
337 | 1102 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1103 |
if (!zip_load_entries(in, info, data_start, cent_dir_ofs)) |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1104 |
goto zip_openarchive_failed; |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1105 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1106 |
__PHYSFS_platformClose(in); |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1107 |
return(info); |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1108 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1109 |
zip_openarchive_failed: |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1110 |
if (info != NULL) |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
1111 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1112 |
if (info->archiveName != NULL) |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1113 |
free(info->archiveName); |
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646
diff
changeset
|
1114 |
free(info); |
53
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
1115 |
} /* if */ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
1116 |
|
337 | 1117 |
if (in != NULL) |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
646 |