author | Ryan C. Gordon <icculus@icculus.org> |
Thu, 06 Jun 2002 05:38:47 +0000 | |
changeset 254 | c66bbbe50f14 |
parent 240 | 052041af9001 |
child 335 | 1d4720c018c3 |
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 |
* |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
* This file written by Ryan C. Gordon. |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
*/ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
|
214
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
9 |
#if HAVE_CONFIG_H |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
10 |
# include <config.h> |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
11 |
#endif |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
12 |
|
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
13 |
#if (defined PHYSFS_SUPPORTS_ZIP) |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
14 |
|
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
15 |
/* |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
16 |
* !!! FIXME: overall design bugs. |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
17 |
* |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
18 |
* Maybe add a seekToStartOfCurrentFile() in unzip.c if complete seek |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
19 |
* semantics are impossible. |
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
20 |
* |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
21 |
* Could be more i/o efficient if we combined unzip.c and this file. |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
22 |
* (and thus lose all the unzGoToNextFile() dummy loops. |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
23 |
*/ |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
24 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 |
#include <stdio.h> |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
#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
|
27 |
#include <string.h> |
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
28 |
#include <assert.h> |
254
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
29 |
#include <time.h> |
22
49f6101707b4
More tweaks; GRP completely implemented. Everything builds clean.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
30 |
#include "physfs.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
|
31 |
#include "unzip.h" |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
32 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
#define __PHYSICSFS_INTERNAL__ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
#include "physfs_internal.h" |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
|
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
37 |
#define MAXZIPENTRYSIZE 256 |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
38 |
|
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
39 |
typedef struct |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
40 |
{ |
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
|
41 |
char *name; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
42 |
unz_file_info info; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
43 |
char *symlink; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
44 |
} 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
|
45 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
46 |
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
|
47 |
{ |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
48 |
char *archiveName; |
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
|
49 |
unz_global_info global; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
50 |
ZIPentry *entries; |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
51 |
} ZIPinfo; |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
52 |
|
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
53 |
typedef struct |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
54 |
{ |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
55 |
unzFile handle; |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
56 |
} ZIPfileinfo; |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
57 |
|
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
58 |
|
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
59 |
/* Number of symlinks to follow before we assume it's a recursive link... */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
60 |
#define SYMLINK_RECURSE_COUNT 20 |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
61 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
62 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
63 |
static PHYSFS_sint64 ZIP_read(FileHandle *handle, void *buffer, |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
64 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount); |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
65 |
static int ZIP_eof(FileHandle *handle); |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
66 |
static PHYSFS_sint64 ZIP_tell(FileHandle *handle); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
67 |
static int ZIP_seek(FileHandle *handle, PHYSFS_uint64 offset); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
68 |
static PHYSFS_sint64 ZIP_fileLength(FileHandle *handle); |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
69 |
static int ZIP_fileClose(FileHandle *handle); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
70 |
static int ZIP_isArchive(const char *filename, int forWriting); |
144 | 71 |
static char *ZIP_realpath(unzFile fh, unz_file_info *info, ZIPentry *entry); |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
72 |
static DirHandle *ZIP_openArchive(const char *name, int forWriting); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
73 |
static LinkedStringList *ZIP_enumerateFiles(DirHandle *h, |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
74 |
const char *dirname, |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
75 |
int omitSymLinks); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
76 |
static int ZIP_exists(DirHandle *h, const char *name); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
77 |
static int ZIP_isDirectory(DirHandle *h, const char *name); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
78 |
static int ZIP_isSymLink(DirHandle *h, const char *name); |
254
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
79 |
static PHYSFS_sint64 ZIP_getLastModTime(DirHandle *h, const char *name); |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
80 |
static FileHandle *ZIP_openRead(DirHandle *h, const char *filename); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
81 |
static void ZIP_dirClose(DirHandle *h); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
82 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
83 |
|
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
84 |
static const FileFunctions __PHYSFS_FileFunctions_ZIP = |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
85 |
{ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
86 |
ZIP_read, /* read() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
87 |
NULL, /* write() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
88 |
ZIP_eof, /* eof() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
89 |
ZIP_tell, /* tell() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
90 |
ZIP_seek, /* seek() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
91 |
ZIP_fileLength, /* fileLength() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
92 |
ZIP_fileClose /* fileClose() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
93 |
}; |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
94 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
95 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
96 |
const DirFunctions __PHYSFS_DirFunctions_ZIP = |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
97 |
{ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
98 |
ZIP_isArchive, /* isArchive() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
99 |
ZIP_openArchive, /* openArchive() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
100 |
ZIP_enumerateFiles, /* enumerateFiles() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
101 |
ZIP_exists, /* exists() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
102 |
ZIP_isDirectory, /* isDirectory() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
103 |
ZIP_isSymLink, /* isSymLink() method */ |
254
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
104 |
ZIP_getLastModTime, /* getLastModTime() method */ |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
105 |
ZIP_openRead, /* openRead() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
106 |
NULL, /* openWrite() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
107 |
NULL, /* openAppend() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
108 |
NULL, /* remove() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
109 |
NULL, /* mkdir() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
110 |
ZIP_dirClose /* dirClose() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
111 |
}; |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
112 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
113 |
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ZIP = |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
114 |
{ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
115 |
"ZIP", |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
116 |
"PkZip/WinZip/Info-Zip compatible", |
95
215a06fc87eb
Changed author credits to wrap email addresses in "<>" and not "()" chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
117 |
"Ryan C. Gordon <icculus@clutteredmind.org>", |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
118 |
"http://www.icculus.org/physfs/", |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
119 |
}; |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
120 |
|
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
|
121 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
122 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
123 |
static PHYSFS_sint64 ZIP_read(FileHandle *handle, void *buffer, |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
124 |
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
|
125 |
{ |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
126 |
unzFile fh = ((ZIPfileinfo *) (handle->opaque))->handle; |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
127 |
int bytes = (int) (objSize * objCount); /* !!! FIXME: overflow? */ |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
128 |
PHYSFS_sint32 rc = unzReadCurrentFile(fh, buffer, bytes); |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
129 |
|
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
130 |
if (rc < bytes) |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
131 |
__PHYSFS_setError(ERR_PAST_EOF); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
132 |
else if (rc == UNZ_ERRNO) |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
133 |
__PHYSFS_setError(ERR_IO_ERROR); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
134 |
else if (rc < 0) |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
135 |
__PHYSFS_setError(ERR_COMPRESSION); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
136 |
|
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
137 |
return(rc / objSize); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
138 |
} /* ZIP_read */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
139 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
140 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
141 |
static int ZIP_eof(FileHandle *handle) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
142 |
{ |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
143 |
return(unzeof(((ZIPfileinfo *) (handle->opaque))->handle)); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
144 |
} /* ZIP_eof */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
145 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
146 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
147 |
static PHYSFS_sint64 ZIP_tell(FileHandle *handle) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
148 |
{ |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
149 |
return(unztell(((ZIPfileinfo *) (handle->opaque))->handle)); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
150 |
} /* ZIP_tell */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
151 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
152 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
153 |
static int ZIP_seek(FileHandle *handle, 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
|
154 |
{ |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
155 |
/* !!! FIXME : this blows. */ |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
156 |
unzFile fh = ((ZIPfileinfo *) (handle->opaque))->handle; |
52
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
157 |
char *buf = NULL; |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
158 |
PHYSFS_uint32 bufsize = 4096 * 2; |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
159 |
|
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
160 |
BAIL_IF_MACRO(unztell(fh) == offset, NULL, 1); |
194
09c353d30cd4
Patches for correctness and cleaner win32 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
161 |
BAIL_IF_MACRO(ZIP_fileLength(handle) <= (PHYSFS_sint64) offset, ERR_PAST_EOF, 0); |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
162 |
|
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
163 |
/* reset to the start of the zipfile. */ |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
164 |
unzCloseCurrentFile(fh); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
165 |
BAIL_IF_MACRO(unzOpenCurrentFile(fh) != UNZ_OK, ERR_IO_ERROR, 0); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
166 |
|
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
167 |
while ((buf == NULL) && (bufsize >= 512)) |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
168 |
{ |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
169 |
bufsize >>= 1; /* divides by two. */ |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
170 |
buf = (char *) malloc(bufsize); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
171 |
} /* while */ |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
172 |
BAIL_IF_MACRO(buf == NULL, ERR_OUT_OF_MEMORY, 0); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
173 |
|
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
174 |
while (offset > 0) |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
175 |
{ |
161
4fcc863fdc5f
-Added type casting that Ryan needs to approve.
Gregory S. Read <zeph@clutteredmind.org>
parents:
149
diff
changeset
|
176 |
PHYSFS_uint32 chunk = (offset > bufsize) ? bufsize : (PHYSFS_uint32)offset; |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
177 |
PHYSFS_sint32 rc = unzReadCurrentFile(fh, buf, chunk); |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
178 |
BAIL_IF_MACRO(rc == 0, ERR_IO_ERROR, 0); /* shouldn't happen. */ |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
179 |
BAIL_IF_MACRO(rc == UNZ_ERRNO, ERR_IO_ERROR, 0); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
180 |
BAIL_IF_MACRO(rc < 0, ERR_COMPRESSION, 0); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
181 |
offset -= rc; |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
182 |
} /* while */ |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
183 |
|
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
184 |
free(buf); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
185 |
return(offset == 0); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
186 |
} /* ZIP_seek */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
187 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
188 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
95
diff
changeset
|
189 |
static PHYSFS_sint64 ZIP_fileLength(FileHandle *handle) |
28
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
190 |
{ |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
191 |
ZIPfileinfo *finfo = (ZIPfileinfo *) (handle->opaque); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
192 |
unz_file_info info; |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
193 |
|
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
194 |
unzGetCurrentFileInfo(finfo->handle, &info, NULL, 0, NULL, 0, NULL, 0); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
195 |
return(info.uncompressed_size); |
28
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
196 |
} /* ZIP_fileLength */ |
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
197 |
|
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
198 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
199 |
static int ZIP_fileClose(FileHandle *handle) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
200 |
{ |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
201 |
ZIPfileinfo *finfo = (ZIPfileinfo *) (handle->opaque); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
202 |
unzClose(finfo->handle); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
203 |
free(finfo); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
204 |
free(handle); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
205 |
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
|
206 |
} /* ZIP_fileClose */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
207 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
208 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
209 |
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
|
210 |
{ |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
211 |
int retval = 0; |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
212 |
unzFile unz = unzOpen(filename); |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
213 |
unz_global_info global; |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
214 |
|
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
215 |
if (unz != NULL) |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
216 |
{ |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
217 |
if (unzGetGlobalInfo(unz, &global) == UNZ_OK) |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
218 |
retval = 1; |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
219 |
unzClose(unz); |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
220 |
} /* if */ |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
221 |
|
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
222 |
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
|
223 |
} /* ZIP_isArchive */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
224 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
225 |
|
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
|
226 |
static void freeEntries(ZIPinfo *info, int count, const char *errmsg) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
227 |
{ |
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
|
228 |
int i; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
229 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
230 |
for (i = 0; i < count; i++) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
231 |
{ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
232 |
free(info->entries[i].name); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
233 |
if (info->entries[i].symlink != NULL) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
234 |
free(info->entries[i].symlink); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
235 |
} /* 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
|
236 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
237 |
free(info->entries); |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
238 |
|
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
|
239 |
if (errmsg != NULL) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
240 |
__PHYSFS_setError(errmsg); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
241 |
} /* freeEntries */ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
242 |
|
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
243 |
|
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
244 |
/* |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
245 |
* !!! FIXME: Really implement this. |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
246 |
* !!! FIXME: symlinks in zipfiles can be relative paths, including |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
247 |
* !!! FIXME: "." and ".." entries. These need to be parsed out. |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
248 |
* !!! FIXME: For now, though, we're just copying the relative path. Oh well. |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
249 |
*/ |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
250 |
static char *expand_symlink_path(const char *path, ZIPentry *entry) |
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
|
251 |
{ |
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
252 |
char *retval = (char *) malloc(strlen(path) + 1); |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
253 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
254 |
strcpy(retval, path); |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
255 |
return(retval); |
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
256 |
} /* expand_symlink_path */ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
257 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
258 |
|
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
259 |
static char *ZIP_realpath(unzFile fh, unz_file_info *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
|
260 |
{ |
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
261 |
char path[MAXZIPENTRYSIZE]; |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
262 |
int size = info->uncompressed_size; |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
263 |
int rc; |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
264 |
|
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
265 |
BAIL_IF_MACRO(size >= sizeof (path), ERR_IO_ERROR, NULL); |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
266 |
BAIL_IF_MACRO(unzOpenCurrentFile(fh) != UNZ_OK, ERR_IO_ERROR, NULL); |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
267 |
rc = unzReadCurrentFile(fh, path, size); |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
268 |
unzCloseCurrentFile(fh); |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
269 |
BAIL_IF_MACRO(rc != size, ERR_IO_ERROR, NULL); |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
270 |
path[size] = '\0'; /* null terminate it. */ |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
271 |
|
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
272 |
return(expand_symlink_path(path, entry)); /* retval is malloc()'d. */ |
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
273 |
} /* ZIP_realpath */ |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
274 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
275 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
276 |
static int version_does_symlinks(uLong version) |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
277 |
{ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
278 |
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
|
279 |
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
|
280 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
281 |
/* |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
282 |
* These are the platforms that can build an archive with symlinks, |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
283 |
* according to the Info-ZIP project. |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
284 |
*/ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
285 |
switch (hosttype) |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
286 |
{ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
287 |
case 3: /* Unix */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
288 |
case 16: /* BeOS */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
289 |
case 5: /* Atari */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
290 |
retval = 1; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
291 |
break; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
292 |
} /* switch */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
293 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
294 |
return(retval); |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
295 |
} /* version_does_symlinks */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
296 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
297 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
298 |
static int entry_is_symlink(unz_file_info *info) |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
299 |
{ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
300 |
return ( |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
301 |
(version_does_symlinks(info->version)) && |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
302 |
(info->uncompressed_size > 0) && |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
303 |
(info->external_fa & 0x0120000) /* symlink flag. */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
304 |
); |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
305 |
} /* entry_is_symlink */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
306 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
307 |
|
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
|
308 |
static int loadZipEntries(ZIPinfo *info, unzFile unz) |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
309 |
{ |
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
|
310 |
int i, 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
|
311 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
312 |
BAIL_IF_MACRO(unzGetGlobalInfo(unz, &(info->global)) != UNZ_OK, |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
313 |
ERR_IO_ERROR, 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
|
314 |
BAIL_IF_MACRO(unzGoToFirstFile(unz) != UNZ_OK, ERR_IO_ERROR, 0); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
315 |
|
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
|
316 |
max = info->global.number_entry; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
317 |
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
|
318 |
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
|
319 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
320 |
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
|
321 |
{ |
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
|
322 |
unz_file_info *d = &((info->entries[i]).info); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
323 |
if (unzGetCurrentFileInfo(unz, d, NULL, 0, NULL, 0, NULL, 0) != UNZ_OK) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
324 |
{ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
325 |
freeEntries(info, i, ERR_IO_ERROR); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
326 |
return(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
|
327 |
} /* 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
|
328 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
329 |
(info->entries[i]).name = (char *) malloc(d->size_filename + 1); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
330 |
if ((info->entries[i]).name == NULL) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
331 |
{ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
332 |
freeEntries(info, i, ERR_OUT_OF_MEMORY); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
333 |
return(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
|
334 |
} /* 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
|
335 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
336 |
info->entries[i].symlink = NULL; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
337 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
338 |
if (unzGetCurrentFileInfo(unz, NULL, (info->entries[i]).name, |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
339 |
d->size_filename + 1, NULL, 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
|
340 |
NULL, 0) != UNZ_OK) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
341 |
{ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
342 |
freeEntries(info, i + 1, ERR_IO_ERROR); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
343 |
return(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
|
344 |
} /* 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
|
345 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
346 |
if (entry_is_symlink(d)) |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
347 |
{ |
143
337505f94c10
Platform abstracted i/o, other bugfixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
348 |
info->entries[i].symlink = ZIP_realpath(unz, d, &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
|
349 |
if (info->entries[i].symlink == NULL) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
350 |
{ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
351 |
freeEntries(info, i + 1, NULL); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
352 |
return(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
|
353 |
} /* 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
|
354 |
} /* 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
|
355 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
356 |
if ((unzGoToNextFile(unz) != UNZ_OK) && (i + 1 < 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
|
357 |
{ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
358 |
freeEntries(info, i + 1, ERR_IO_ERROR); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
359 |
return(0); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
360 |
} /* 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
|
361 |
} /* 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
|
362 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
363 |
return(1); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
364 |
} /* loadZipEntries */ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
365 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
366 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
367 |
static DirHandle *ZIP_openArchive(const char *name, int forWriting) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
368 |
{ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
369 |
unzFile unz = NULL; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
370 |
DirHandle *retval = NULL; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
371 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
372 |
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
373 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
374 |
retval = malloc(sizeof (DirHandle)); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
375 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
376 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
377 |
unz = unzOpen(name); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
378 |
if (unz == NULL) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
379 |
{ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
380 |
free(retval); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
381 |
BAIL_IF_MACRO(1, ERR_UNSUPPORTED_ARCHIVE, NULL); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
382 |
} /* if */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
383 |
|
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
|
384 |
retval->opaque = malloc(sizeof (ZIPinfo)); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
385 |
if (retval->opaque == NULL) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
386 |
{ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
387 |
free(retval); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
388 |
unzClose(unz); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
389 |
BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
390 |
} /* 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
|
391 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
392 |
((ZIPinfo *) (retval->opaque))->archiveName = malloc(strlen(name) + 1); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
393 |
if ( (((ZIPinfo *) (retval->opaque))->archiveName == NULL) || |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
394 |
(!loadZipEntries( (ZIPinfo *) (retval->opaque), unz)) ) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
395 |
{ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
396 |
if (((ZIPinfo *) (retval->opaque))->archiveName != NULL) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
397 |
free(((ZIPinfo *) (retval->opaque))->archiveName); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
398 |
free(retval->opaque); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
399 |
free(retval); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
400 |
unzClose(unz); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
401 |
BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
402 |
} /* 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
|
403 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
404 |
unzClose(unz); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
405 |
strcpy(((ZIPinfo *) (retval->opaque))->archiveName, name); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
406 |
retval->funcs = &__PHYSFS_DirFunctions_ZIP; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
407 |
|
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
408 |
return(retval); |
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
|
409 |
} /* ZIP_openArchive */ |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
410 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
411 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
412 |
/* !!! This is seriously ugly. */ |
41
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
413 |
static LinkedStringList *ZIP_enumerateFiles(DirHandle *h, |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
414 |
const char *dirname, |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
415 |
int omitSymLinks) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
416 |
{ |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
417 |
ZIPinfo *zi = (ZIPinfo *) (h->opaque); |
71 | 418 |
unsigned int i; |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
419 |
int dlen; |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
420 |
LinkedStringList *retval = NULL; |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
421 |
LinkedStringList *l = NULL; |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
422 |
LinkedStringList *prev = 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
|
423 |
char *d; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
424 |
ZIPentry *entry; |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
425 |
char buf[MAXZIPENTRYSIZE]; |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
426 |
|
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
427 |
dlen = strlen(dirname); |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
428 |
d = malloc(dlen + 1); |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
429 |
BAIL_IF_MACRO(d == NULL, ERR_OUT_OF_MEMORY, NULL); |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
430 |
strcpy(d, dirname); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
431 |
if ((dlen > 0) && (d[dlen - 1] == '/')) /* no trailing slash. */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
432 |
{ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
433 |
dlen--; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
434 |
d[dlen] = '\0'; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
435 |
} /* 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
|
436 |
|
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
|
437 |
for (i = 0, entry = zi->entries; i < zi->global.number_entry; i++, 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
|
438 |
{ |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
439 |
char *ptr; |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
440 |
char *add_file; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
441 |
int this_dlen; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
442 |
|
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
|
443 |
if ((omitSymLinks) && (entry->symlink != NULL)) |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
444 |
continue; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
445 |
|
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
|
446 |
this_dlen = strlen(entry->name); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
447 |
if (this_dlen + 1 > MAXZIPENTRYSIZE) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
448 |
continue; /* ugh. */ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
449 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
450 |
strcpy(buf, entry->name); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
451 |
|
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
452 |
if ((this_dlen > 0) && (buf[this_dlen - 1] == '/')) /* no trailing slash. */ |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
453 |
{ |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
454 |
this_dlen--; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
455 |
buf[this_dlen] = '\0'; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
456 |
} /* if */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
457 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
458 |
if (this_dlen <= dlen) /* not in this dir. */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
459 |
continue; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
460 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
461 |
if (*d == '\0') |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
462 |
add_file = buf; |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
463 |
else |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
464 |
{ |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
465 |
if (buf[dlen] != '/') /* can't be in same directory? */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
466 |
continue; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
467 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
468 |
buf[dlen] = '\0'; |
52
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
469 |
if (__PHYSFS_platformStricmp(d, buf) != 0) /* not same directory? */ |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
470 |
continue; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
471 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
472 |
add_file = buf + dlen + 1; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
473 |
} /* else */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
474 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
475 |
/* handle subdirectories... */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
476 |
ptr = strchr(add_file, '/'); |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
477 |
if (ptr != NULL) |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
478 |
{ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
479 |
LinkedStringList *j; |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
480 |
*ptr = '\0'; |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
481 |
for (j = retval; j != NULL; j = j->next) |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
482 |
{ |
52
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
483 |
if (__PHYSFS_platformStricmp(j->str, ptr) == 0) |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
484 |
break; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
485 |
} /* for */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
486 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
487 |
if (j != NULL) |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
488 |
continue; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
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 |
|
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
491 |
l = (LinkedStringList *) malloc(sizeof (LinkedStringList)); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
492 |
if (l == NULL) |
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 |
break; |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
494 |
|
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
495 |
l->str = (char *) malloc(strlen(add_file) + 1); |
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
496 |
if (l->str == NULL) |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
497 |
{ |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
498 |
free(l); |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
499 |
break; |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
500 |
} /* if */ |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
501 |
|
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
502 |
strcpy(l->str, add_file); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
503 |
|
32
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
504 |
if (retval == NULL) |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
505 |
retval = l; |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
506 |
else |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
507 |
prev->next = l; |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
508 |
|
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
509 |
prev = l; |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
510 |
l->next = NULL; |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
511 |
} /* for */ |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
512 |
|
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
513 |
free(d); |
09a8197fad3b
Initial work on ZIPfile support. Not complete. Not very pleased with this
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
514 |
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
|
515 |
} /* ZIP_enumerateFiles */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
516 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
517 |
|
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
518 |
/* !!! This is seriously ugly. */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
519 |
static int ZIP_exists_symcheck(DirHandle *h, const char *name, int follow) |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
520 |
{ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
521 |
char buf[MAXZIPENTRYSIZE]; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
522 |
ZIPinfo *zi = (ZIPinfo *) (h->opaque); |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
523 |
int dlen; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
524 |
char *d; |
71 | 525 |
unsigned int 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
|
526 |
ZIPentry *entry; |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
527 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
528 |
dlen = strlen(name); |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
529 |
d = malloc(dlen + 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
|
530 |
BAIL_IF_MACRO(d == NULL, ERR_OUT_OF_MEMORY, -1); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
531 |
strcpy(d, name); |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
532 |
if ((dlen > 0) && (d[dlen - 1] == '/')) /* no trailing slash. */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
533 |
{ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
534 |
dlen--; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
535 |
d[dlen] = '\0'; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
536 |
} /* if */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
537 |
|
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
|
538 |
for (i = 0, entry = zi->entries; i < zi->global.number_entry; i++, entry++) |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
539 |
{ |
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
|
540 |
int this_dlen = strlen(entry->name); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
541 |
if (this_dlen + 1 > MAXZIPENTRYSIZE) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
542 |
continue; /* ugh. */ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
543 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
544 |
strcpy(buf, entry->name); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
545 |
if ((this_dlen > 0) && (buf[this_dlen - 1] == '/')) /* no trailing slash. */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
546 |
{ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
547 |
this_dlen--; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
548 |
buf[this_dlen] = '\0'; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
549 |
} /* if */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
550 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
551 |
if ( ((buf[dlen] == '/') || (buf[dlen] == '\0')) && |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
552 |
(strncmp(d, buf, dlen) == 0) ) |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
553 |
{ |
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
|
554 |
int retval = i; |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
555 |
free(d); |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
556 |
if (follow) /* follow symlinks? */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
557 |
{ |
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
|
558 |
if (entry->symlink != NULL) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
559 |
retval = ZIP_exists_symcheck(h, entry->symlink, follow-1); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
560 |
} /* if */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
561 |
return(retval); |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
562 |
} /* if */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
563 |
} /* for */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
564 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
565 |
free(d); |
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
|
566 |
return(-1); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
567 |
} /* ZIP_exists_symcheck */ |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
568 |
|
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
569 |
|
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
570 |
static int ZIP_exists(DirHandle *h, const char *name) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
571 |
{ |
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
|
572 |
int retval = ZIP_exists_symcheck(h, name, SYMLINK_RECURSE_COUNT); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
573 |
int is_sym; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
574 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
575 |
if (retval == -1) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
576 |
return(0); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
577 |
|
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
|
578 |
/* if it's a symlink, then we ran into a possible symlink loop. */ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
579 |
is_sym = ( ((ZIPinfo *)(h->opaque))->entries[retval].symlink != NULL ); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
580 |
BAIL_IF_MACRO(is_sym, ERR_TOO_MANY_SYMLINKS, 0); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
581 |
|
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
|
582 |
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
|
583 |
} /* ZIP_exists */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
584 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
585 |
|
254
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
586 |
static PHYSFS_sint64 ZIP_getLastModTime(DirHandle *h, const char *name) |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
587 |
{ |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
588 |
ZIPinfo *zi = (ZIPinfo *) (h->opaque); |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
589 |
int pos = ZIP_exists_symcheck(h, name, SYMLINK_RECURSE_COUNT); |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
590 |
ZIPentry *entry; |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
591 |
struct tm t; |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
592 |
|
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
593 |
if (pos == -1) |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
594 |
return(0); |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
595 |
|
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
596 |
entry = &zi->entries[pos]; |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
597 |
|
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
598 |
/* if it's a symlink, then we ran into a possible symlink loop. */ |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
599 |
BAIL_IF_MACRO(entry->symlink != NULL, ERR_TOO_MANY_SYMLINKS, 0); |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
600 |
|
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
601 |
memset(&t, '\0', sizeof (t)); |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
602 |
t.tm_year = entry->info.tmu_date.tm_year - 1900; |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
603 |
t.tm_mon = entry->info.tmu_date.tm_mon; |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
604 |
t.tm_mday = entry->info.tmu_date.tm_mday; |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
605 |
t.tm_hour = entry->info.tmu_date.tm_hour; |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
606 |
t.tm_min = entry->info.tmu_date.tm_min; |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
607 |
t.tm_sec = entry->info.tmu_date.tm_sec; |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
608 |
return((PHYSFS_sint64) mktime(&t)); |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
609 |
} /* ZIP_getLastModTime */ |
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
610 |
|
c66bbbe50f14
Implemeted getLastModTime method.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
611 |
|
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
612 |
static int ZIP_isDirectory(DirHandle *h, const char *name) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
613 |
{ |
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
|
614 |
int dlen; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
615 |
int is_sym; |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
616 |
int retval = ZIP_exists_symcheck(h, name, SYMLINK_RECURSE_COUNT); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
617 |
|
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
618 |
if (retval == -1) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
619 |
return(0); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
620 |
|
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
|
621 |
/* if it's a symlink, then we ran into a possible symlink loop. */ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
622 |
is_sym = ( ((ZIPinfo *)(h->opaque))->entries[retval].symlink != NULL ); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
623 |
BAIL_IF_MACRO(is_sym, ERR_TOO_MANY_SYMLINKS, 0); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
624 |
|
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
|
625 |
dlen = strlen(name); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
626 |
/* !!! yikes. Better way to check? */ |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
627 |
retval = (((ZIPinfo *)(h->opaque))->entries[retval].name[dlen] == '/'); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
628 |
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
|
629 |
} /* ZIP_isDirectory */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
630 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
631 |
|
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
632 |
static int ZIP_isSymLink(DirHandle *h, const char *name) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
633 |
{ |
55
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
634 |
int retval = ZIP_exists_symcheck(h, name, 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
|
635 |
if (retval == -1) |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
636 |
return(0); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
637 |
|
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
|
638 |
retval = ( ((ZIPinfo *)(h->opaque))->entries[retval].symlink != NULL ); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
639 |
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
|
640 |
} /* ZIP_isSymLink */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
641 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
642 |
|
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
643 |
static FileHandle *ZIP_openRead(DirHandle *h, const char *filename) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
644 |
{ |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
645 |
FileHandle *retval = 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
|
646 |
ZIPinfo *zi = ((ZIPinfo *) (h->opaque)); |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
647 |
ZIPfileinfo *finfo = NULL; |
55
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
648 |
int pos = ZIP_exists_symcheck(h, filename, SYMLINK_RECURSE_COUNT); |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
649 |
unzFile f; |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
650 |
|
55
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
651 |
BAIL_IF_MACRO(pos == -1, ERR_NO_SUCH_FILE, NULL); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
652 |
|
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
|
653 |
f = unzOpen(zi->archiveName); |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
654 |
BAIL_IF_MACRO(f == NULL, ERR_IO_ERROR, NULL); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
655 |
|
55
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
656 |
if (unzGoToFirstFile(f) != UNZ_OK) |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
657 |
{ |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
658 |
unzClose(f); |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
659 |
BAIL_IF_MACRO(1, ERR_IO_ERROR, NULL); |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
660 |
} /* if */ |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
661 |
|
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
662 |
for (; pos > 0; pos--) |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
663 |
{ |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
664 |
if (unzGoToNextFile(f) != UNZ_OK) |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
665 |
{ |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
666 |
unzClose(f); |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
667 |
BAIL_IF_MACRO(1, ERR_IO_ERROR, NULL); |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
668 |
} /* if */ |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
669 |
} /* for */ |
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
670 |
|
986740ba58ab
Avoids unzLocateFile(), since we already did all the searching ourselves.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
671 |
if ( (unzOpenCurrentFile(f) != UNZ_OK) || |
52
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
672 |
( (finfo = (ZIPfileinfo *) malloc(sizeof (ZIPfileinfo))) == NULL ) ) |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
673 |
{ |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
674 |
unzClose(f); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
675 |
BAIL_IF_MACRO(1, ERR_IO_ERROR, NULL); |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
676 |
} /* if */ |
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
677 |
|
52
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
678 |
if ( (!(retval = (FileHandle *) malloc(sizeof (FileHandle)))) || |
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
679 |
(!(retval->opaque = (ZIPfileinfo *) malloc(sizeof (ZIPfileinfo)))) ) |
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
680 |
{ |
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
681 |
if (retval) |
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
682 |
free(retval); |
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
683 |
unzClose(f); |
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
684 |
BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL); |
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
685 |
} /* if */ |
bbb26eacc532
Enough fixes to get the Build engine working with ZIP files instead of
Ryan C. Gordon <icculus@icculus.org>
parents:
50
diff
changeset
|
686 |
|
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
687 |
finfo->handle = f; |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
688 |
retval->opaque = (void *) finfo; |
50
989b413188e5
Added individual file i/o code. Untested.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
689 |
retval->funcs = &__PHYSFS_FileFunctions_ZIP; |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
690 |
retval->dirHandle = h; |
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
691 |
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
|
692 |
} /* ZIP_openRead */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
693 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
694 |
|
21
b1ea58d70a56
Archive implementation (Build Groupfiles), other tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
695 |
static void ZIP_dirClose(DirHandle *h) |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
696 |
{ |
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
|
697 |
ZIPinfo *zi = (ZIPinfo *) (h->opaque); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
698 |
freeEntries(zi, zi->global.number_entry, NULL); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
699 |
free(zi->archiveName); |
6c3c990f006e
ZIP entries are now cached at openArchive time, which cleans up the race
Ryan C. Gordon <icculus@icculus.org>
parents:
52
diff
changeset
|
700 |
free(zi); |
46
66d9a112b0f7
Now with all directory functions implemented (and debugged?). No file
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
701 |
free(h); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
702 |
} /* ZIP_dirClose */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
703 |
|
214
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
704 |
#endif /* defined PHYSFS_SUPPORTS_ZIP */ |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
705 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
706 |
/* end of zip.c ... */ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
707 |