author | Ryan C. Gordon <icculus@icculus.org> |
Mon, 14 Mar 2005 11:49:30 +0000 | |
changeset 691 | 71d9affe0d8a |
parent 678 | 73a2641375a0 |
child 754 | e7cd7411eadf |
permissions | -rw-r--r-- |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/* |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
* GRP support routines for PhysicsFS. |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
* |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
* This driver handles BUILD engine archives ("groupfiles"). This format |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* (but not this driver) was put together by Ken Silverman. |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
* |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
* The format is simple enough. In Ken's words: |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
* |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
* What's the .GRP file format? |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
* |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
* The ".grp" file format is just a collection of a lot of files stored |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 |
* into 1 big one. I tried to make the format as simple as possible: The |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 |
* first 12 bytes contains my name, "KenSilverman". The next 4 bytes is |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
* the number of files that were compacted into the group file. Then for |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
* each file, there is a 16 byte structure, where the first 12 bytes are |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
* the filename, and the last 4 bytes are the file's size. The rest of |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
* the group file is just the raw data packed one after the other in the |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
* same order as the list of files. |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
* |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 |
* (That info is from http://www.advsys.net/ken/build.htm ...) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 |
* |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 |
* Please see the file LICENSE in the source's root directory. |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
* |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 |
* This file written by Ryan C. Gordon. |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 |
*/ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
|
214
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
27 |
#if HAVE_CONFIG_H |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
28 |
# include <config.h> |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
29 |
#endif |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
30 |
|
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
31 |
#if (defined PHYSFS_SUPPORTS_GRP) |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
32 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
#include <stdio.h> |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
#include <stdlib.h> |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
#include <string.h> |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
#include "physfs.h" |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
#define __PHYSICSFS_INTERNAL__ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
#include "physfs_internal.h" |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
typedef struct |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
{ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
43 |
char name[13]; |
480
2cf0b6edd200
Cleaned up some stuff, reduced some unnecessary 64-bit ints to 32.
Ryan C. Gordon <icculus@icculus.org>
parents:
467
diff
changeset
|
44 |
PHYSFS_uint32 startPos; |
2cf0b6edd200
Cleaned up some stuff, reduced some unnecessary 64-bit ints to 32.
Ryan C. Gordon <icculus@icculus.org>
parents:
467
diff
changeset
|
45 |
PHYSFS_uint32 size; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
46 |
} GRPentry; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
47 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
48 |
typedef struct |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
49 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
50 |
char *filename; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
51 |
PHYSFS_sint64 last_mod_time; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
52 |
PHYSFS_uint32 entryCount; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
53 |
GRPentry *entries; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
} GRPinfo; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
typedef struct |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
58 |
void *handle; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
59 |
GRPentry *entry; |
480
2cf0b6edd200
Cleaned up some stuff, reduced some unnecessary 64-bit ints to 32.
Ryan C. Gordon <icculus@icculus.org>
parents:
467
diff
changeset
|
60 |
PHYSFS_uint32 curPos; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
} GRPfileinfo; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
64 |
static void GRP_dirClose(dvoid *opaque) |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
65 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
66 |
GRPinfo *info = ((GRPinfo *) opaque); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
67 |
allocator.Free(info->filename); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
68 |
allocator.Free(info->entries); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
69 |
allocator.Free(info); |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
70 |
} /* GRP_dirClose */ |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
73 |
static PHYSFS_sint64 GRP_read(fvoid *opaque, void *buffer, |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
74 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
76 |
GRPfileinfo *finfo = (GRPfileinfo *) opaque; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
77 |
GRPentry *entry = finfo->entry; |
480
2cf0b6edd200
Cleaned up some stuff, reduced some unnecessary 64-bit ints to 32.
Ryan C. Gordon <icculus@icculus.org>
parents:
467
diff
changeset
|
78 |
PHYSFS_uint32 bytesLeft = entry->size - finfo->curPos; |
2cf0b6edd200
Cleaned up some stuff, reduced some unnecessary 64-bit ints to 32.
Ryan C. Gordon <icculus@icculus.org>
parents:
467
diff
changeset
|
79 |
PHYSFS_uint32 objsLeft = (bytesLeft / objSize); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
80 |
PHYSFS_sint64 rc; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 |
if (objsLeft < objCount) |
480
2cf0b6edd200
Cleaned up some stuff, reduced some unnecessary 64-bit ints to 32.
Ryan C. Gordon <icculus@icculus.org>
parents:
467
diff
changeset
|
83 |
objCount = objsLeft; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
85 |
rc = __PHYSFS_platformRead(finfo->handle, buffer, objSize, objCount); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
86 |
if (rc > 0) |
480
2cf0b6edd200
Cleaned up some stuff, reduced some unnecessary 64-bit ints to 32.
Ryan C. Gordon <icculus@icculus.org>
parents:
467
diff
changeset
|
87 |
finfo->curPos += (PHYSFS_uint32) (rc * objSize); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
88 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
89 |
return(rc); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 |
} /* GRP_read */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
93 |
static PHYSFS_sint64 GRP_write(fvoid *opaque, const void *buffer, |
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
94 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
95 |
{ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
96 |
BAIL_MACRO(ERR_NOT_SUPPORTED, -1); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
97 |
} /* GRP_write */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
98 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
99 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
100 |
static int GRP_eof(fvoid *opaque) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
102 |
GRPfileinfo *finfo = (GRPfileinfo *) opaque; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
103 |
GRPentry *entry = finfo->entry; |
480
2cf0b6edd200
Cleaned up some stuff, reduced some unnecessary 64-bit ints to 32.
Ryan C. Gordon <icculus@icculus.org>
parents:
467
diff
changeset
|
104 |
return(finfo->curPos >= entry->size); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 |
} /* GRP_eof */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
108 |
static PHYSFS_sint64 GRP_tell(fvoid *opaque) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
110 |
return(((GRPfileinfo *) opaque)->curPos); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 |
} /* GRP_tell */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
114 |
static int GRP_seek(fvoid *opaque, PHYSFS_uint64 offset) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
116 |
GRPfileinfo *finfo = (GRPfileinfo *) opaque; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
117 |
GRPentry *entry = finfo->entry; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
118 |
int rc; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 |
BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0); |
480
2cf0b6edd200
Cleaned up some stuff, reduced some unnecessary 64-bit ints to 32.
Ryan C. Gordon <icculus@icculus.org>
parents:
467
diff
changeset
|
121 |
BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0); |
2cf0b6edd200
Cleaned up some stuff, reduced some unnecessary 64-bit ints to 32.
Ryan C. Gordon <icculus@icculus.org>
parents:
467
diff
changeset
|
122 |
rc = __PHYSFS_platformSeek(finfo->handle, entry->startPos + offset); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
123 |
if (rc) |
480
2cf0b6edd200
Cleaned up some stuff, reduced some unnecessary 64-bit ints to 32.
Ryan C. Gordon <icculus@icculus.org>
parents:
467
diff
changeset
|
124 |
finfo->curPos = (PHYSFS_uint32) offset; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
125 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
126 |
return(rc); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 |
} /* GRP_seek */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
130 |
static PHYSFS_sint64 GRP_fileLength(fvoid *opaque) |
28
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
131 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
132 |
GRPfileinfo *finfo = (GRPfileinfo *) opaque; |
480
2cf0b6edd200
Cleaned up some stuff, reduced some unnecessary 64-bit ints to 32.
Ryan C. Gordon <icculus@icculus.org>
parents:
467
diff
changeset
|
133 |
return((PHYSFS_sint64) finfo->entry->size); |
28
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
134 |
} /* GRP_fileLength */ |
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
135 |
|
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
136 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
137 |
static int GRP_fileClose(fvoid *opaque) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
139 |
GRPfileinfo *finfo = (GRPfileinfo *) opaque; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
140 |
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
141 |
allocator.Free(finfo); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
return(1); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 |
} /* GRP_fileClose */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
146 |
static int grp_open(const char *filename, int forWriting, |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
147 |
void **fh, PHYSFS_uint32 *count) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
149 |
PHYSFS_uint8 buf[12]; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 |
*fh = NULL; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 |
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
154 |
*fh = __PHYSFS_platformOpenRead(filename); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
155 |
BAIL_IF_MACRO(*fh == NULL, NULL, 0); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
157 |
if (__PHYSFS_platformRead(*fh, buf, 12, 1) != 1) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
158 |
goto openGrp_failed; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
160 |
if (memcmp(buf, "KenSilverman", 12) != 0) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
161 |
{ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
162 |
__PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
163 |
goto openGrp_failed; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
164 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
165 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
166 |
if (__PHYSFS_platformRead(*fh, count, sizeof (PHYSFS_uint32), 1) != 1) |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
167 |
goto openGrp_failed; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
169 |
*count = PHYSFS_swapULE32(*count); |
175
45e423c38ff8
Fixed byte ordering bugs.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
170 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 |
return(1); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
172 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
173 |
openGrp_failed: |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
174 |
if (*fh != NULL) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
175 |
__PHYSFS_platformClose(*fh); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
176 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
177 |
*count = -1; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
178 |
*fh = NULL; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
179 |
return(0); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
180 |
} /* grp_open */ |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 |
static int GRP_isArchive(const char *filename, int forWriting) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
185 |
void *fh; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
186 |
PHYSFS_uint32 fileCount; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
187 |
int retval = grp_open(filename, forWriting, &fh, &fileCount); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 |
if (fh != NULL) |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
190 |
__PHYSFS_platformClose(fh); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 |
return(retval); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 |
} /* GRP_isArchive */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 |
|
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
196 |
static int grp_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
197 |
{ |
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
198 |
GRPentry *a = (GRPentry *) _a; |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
199 |
return(strcmp(a[one].name, a[two].name)); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
200 |
} /* grp_entry_cmp */ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
201 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
202 |
|
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
203 |
static void grp_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
204 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
205 |
GRPentry tmp; |
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
206 |
GRPentry *first = &(((GRPentry *) _a)[one]); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
207 |
GRPentry *second = &(((GRPentry *) _a)[two]); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
208 |
memcpy(&tmp, first, sizeof (GRPentry)); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
209 |
memcpy(first, second, sizeof (GRPentry)); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
210 |
memcpy(second, &tmp, sizeof (GRPentry)); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
211 |
} /* grp_entry_swap */ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
212 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
213 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
214 |
static int grp_load_entries(const char *name, int forWriting, GRPinfo *info) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
215 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
216 |
void *fh = NULL; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
217 |
PHYSFS_uint32 fileCount; |
370 | 218 |
PHYSFS_uint32 location = 16; /* sizeof sig. */ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
219 |
GRPentry *entry; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
220 |
char *ptr; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
221 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
222 |
BAIL_IF_MACRO(!grp_open(name, forWriting, &fh, &fileCount), NULL, 0); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
223 |
info->entryCount = fileCount; |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
224 |
info->entries = (GRPentry *) allocator.Malloc(sizeof(GRPentry)*fileCount); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
225 |
if (info->entries == NULL) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
226 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
227 |
__PHYSFS_platformClose(fh); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
228 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
229 |
} /* if */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
230 |
|
370 | 231 |
location += (16 * fileCount); |
232 |
||
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
233 |
for (entry = info->entries; fileCount > 0; fileCount--, entry++) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
234 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
235 |
if (__PHYSFS_platformRead(fh, &entry->name, 12, 1) != 1) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
236 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
237 |
__PHYSFS_platformClose(fh); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
238 |
return(0); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
239 |
} /* if */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
240 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
241 |
entry->name[12] = '\0'; /* name isn't null-terminated in file. */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
242 |
if ((ptr = strchr(entry->name, ' ')) != NULL) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
243 |
*ptr = '\0'; /* trim extra spaces. */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
244 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
245 |
if (__PHYSFS_platformRead(fh, &entry->size, 4, 1) != 1) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
246 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
247 |
__PHYSFS_platformClose(fh); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
248 |
return(0); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
249 |
} /* if */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
250 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
251 |
entry->size = PHYSFS_swapULE32(entry->size); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
252 |
entry->startPos = location; |
370 | 253 |
location += entry->size; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
254 |
} /* for */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
255 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
256 |
__PHYSFS_platformClose(fh); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
257 |
|
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
258 |
__PHYSFS_sort(info->entries, info->entryCount, |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
427
diff
changeset
|
259 |
grp_entry_cmp, grp_entry_swap); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
260 |
return(1); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
261 |
} /* grp_load_entries */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
262 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
263 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
264 |
static void *GRP_openArchive(const char *name, int forWriting) |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
265 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
266 |
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
267 |
GRPinfo *info = (GRPinfo *) allocator.Malloc(sizeof (GRPinfo)); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 |
|
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
269 |
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
270 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
271 |
memset(info, '\0', sizeof (GRPinfo)); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
272 |
info->filename = (char *) allocator.Malloc(strlen(name) + 1); |
678
73a2641375a0
Cleaned up some minor bloat with my new evil GOTO_*_MACRO macros.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset
|
273 |
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, GRP_openArchive_failed); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
274 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
275 |
if (!grp_load_entries(name, forWriting, info)) |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
276 |
goto GRP_openArchive_failed; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
278 |
strcpy(info->filename, name); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
279 |
info->last_mod_time = modtime; |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
280 |
|
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
281 |
return(info); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
282 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
283 |
GRP_openArchive_failed: |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
284 |
if (info != NULL) |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
285 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
286 |
if (info->filename != NULL) |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
287 |
allocator.Free(info->filename); |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
288 |
if (info->entries != NULL) |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
289 |
allocator.Free(info->entries); |
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
290 |
allocator.Free(info); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
291 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
292 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
293 |
return(NULL); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 |
} /* GRP_openArchive */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
297 |
static void GRP_enumerateFiles(dvoid *opaque, const char *dname, |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
298 |
int omitSymLinks, PHYSFS_StringCallback cb, |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
299 |
void *callbackdata) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 |
{ |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
301 |
/* no directories in GRP files. */ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
302 |
if (*dname != '\0') |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
303 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
304 |
GRPinfo *info = (GRPinfo *) opaque; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
305 |
GRPentry *entry = info->entries; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
306 |
PHYSFS_uint32 max = info->entryCount; |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
307 |
PHYSFS_uint32 i; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
309 |
for (i = 0; i < max; i++, entry++) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
310 |
cb(callbackdata, entry->name); |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
650
diff
changeset
|
311 |
} /* if */ |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 |
} /* GRP_enumerateFiles */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
315 |
static GRPentry *grp_find_entry(GRPinfo *info, const char *name) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 |
{ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
317 |
char *ptr = strchr(name, '.'); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
318 |
GRPentry *a = info->entries; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
319 |
PHYSFS_sint32 lo = 0; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
320 |
PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
321 |
PHYSFS_sint32 middle; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
322 |
int rc; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
324 |
/* |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
325 |
* Rule out filenames to avoid unneeded processing...no dirs, |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
326 |
* big filenames, or extensions > 3 chars. |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
327 |
*/ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
328 |
BAIL_IF_MACRO((ptr) && (strlen(ptr) > 4), ERR_NO_SUCH_FILE, NULL); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
329 |
BAIL_IF_MACRO(strlen(name) > 12, ERR_NO_SUCH_FILE, NULL); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
330 |
BAIL_IF_MACRO(strchr(name, '/') != NULL, ERR_NO_SUCH_FILE, NULL); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
332 |
while (lo <= hi) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
333 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
334 |
middle = lo + ((hi - lo) / 2); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
335 |
rc = strcmp(name, a[middle].name); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
336 |
if (rc == 0) /* found it! */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
337 |
return(&a[middle]); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
338 |
else if (rc > 0) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
339 |
lo = middle + 1; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
340 |
else |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
341 |
hi = middle - 1; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
342 |
} /* while */ |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
343 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
344 |
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
345 |
} /* grp_find_entry */ |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
346 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
347 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
348 |
static int GRP_exists(dvoid *opaque, const char *name) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
349 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
350 |
return(grp_find_entry((GRPinfo *) opaque, name) != NULL); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
351 |
} /* GRP_exists */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
353 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
354 |
static int GRP_isDirectory(dvoid *opaque, const char *name, int *fileExists) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
355 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
356 |
*fileExists = GRP_exists(opaque, name); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
357 |
return(0); /* never directories in a groupfile. */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
358 |
} /* GRP_isDirectory */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
359 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
360 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
361 |
static int GRP_isSymLink(dvoid *opaque, const char *name, int *fileExists) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
362 |
{ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
363 |
*fileExists = GRP_exists(opaque, name); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
364 |
return(0); /* never symlinks in a groupfile. */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
365 |
} /* GRP_isSymLink */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
366 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
368 |
static PHYSFS_sint64 GRP_getLastModTime(dvoid *opaque, |
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
369 |
const char *name, |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
370 |
int *fileExists) |
258
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
371 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
372 |
GRPinfo *info = (GRPinfo *) opaque; |
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
373 |
PHYSFS_sint64 retval = -1; |
393 | 374 |
|
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
375 |
*fileExists = (grp_find_entry(info, name) != NULL); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
376 |
if (*fileExists) /* use time of GRP itself in the physical filesystem. */ |
648
5c993684b8f2
Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
377 |
retval = info->last_mod_time; |
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
378 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
379 |
return(retval); |
258
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
380 |
} /* GRP_getLastModTime */ |
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
381 |
|
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
382 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
383 |
static fvoid *GRP_openRead(dvoid *opaque, const char *fnm, int *fileExists) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
384 |
{ |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
385 |
GRPinfo *info = (GRPinfo *) opaque; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
386 |
GRPfileinfo *finfo; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
387 |
GRPentry *entry; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
388 |
|
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
389 |
entry = grp_find_entry(info, fnm); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
390 |
*fileExists = (entry != NULL); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
391 |
BAIL_IF_MACRO(entry == NULL, NULL, NULL); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
392 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
393 |
finfo = (GRPfileinfo *) allocator.Malloc(sizeof (GRPfileinfo)); |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
394 |
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
395 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
396 |
finfo->handle = __PHYSFS_platformOpenRead(info->filename); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
397 |
if ( (finfo->handle == NULL) || |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
398 |
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) ) |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
399 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
678
diff
changeset
|
400 |
allocator.Free(finfo); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
401 |
return(NULL); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
402 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
403 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
404 |
finfo->curPos = 0; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
405 |
finfo->entry = entry; |
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
406 |
return(finfo); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
407 |
} /* GRP_openRead */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
408 |
|
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
409 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
410 |
static fvoid *GRP_openWrite(dvoid *opaque, const char *name) |
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
411 |
{ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
412 |
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
413 |
} /* GRP_openWrite */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
414 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
415 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
416 |
static fvoid *GRP_openAppend(dvoid *opaque, const char *name) |
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
417 |
{ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
418 |
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
419 |
} /* GRP_openAppend */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
420 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
421 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
422 |
static int GRP_remove(dvoid *opaque, const char *name) |
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
423 |
{ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
424 |
BAIL_MACRO(ERR_NOT_SUPPORTED, 0); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
425 |
} /* GRP_remove */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
426 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
427 |
|
650
298b8bb26775
Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents:
648
diff
changeset
|
428 |
static int GRP_mkdir(dvoid *opaque, const char *name) |
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
429 |
{ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
430 |
BAIL_MACRO(ERR_NOT_SUPPORTED, 0); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
431 |
} /* GRP_mkdir */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
432 |
|
658
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
433 |
|
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
434 |
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP = |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
435 |
{ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
436 |
"GRP", |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
437 |
GRP_ARCHIVE_DESCRIPTION, |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
438 |
"Ryan C. Gordon <icculus@clutteredmind.org>", |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
439 |
"http://icculus.org/physfs/", |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
440 |
}; |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
441 |
|
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
442 |
|
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
443 |
const PHYSFS_Archiver __PHYSFS_Archiver_GRP = |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
444 |
{ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
445 |
&__PHYSFS_ArchiveInfo_GRP, |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
446 |
GRP_isArchive, /* isArchive() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
447 |
GRP_openArchive, /* openArchive() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
448 |
GRP_enumerateFiles, /* enumerateFiles() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
449 |
GRP_exists, /* exists() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
450 |
GRP_isDirectory, /* isDirectory() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
451 |
GRP_isSymLink, /* isSymLink() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
452 |
GRP_getLastModTime, /* getLastModTime() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
453 |
GRP_openRead, /* openRead() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
454 |
GRP_openWrite, /* openWrite() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
455 |
GRP_openAppend, /* openAppend() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
456 |
GRP_remove, /* remove() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
457 |
GRP_mkdir, /* mkdir() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
458 |
GRP_dirClose, /* dirClose() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
459 |
GRP_read, /* read() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
460 |
GRP_write, /* write() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
461 |
GRP_eof, /* eof() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
462 |
GRP_tell, /* tell() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
463 |
GRP_seek, /* seek() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
464 |
GRP_fileLength, /* fileLength() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
465 |
GRP_fileClose /* fileClose() method */ |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
466 |
}; |
1981818c6170
Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
467 |
|
214
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
468 |
#endif /* defined PHYSFS_SUPPORTS_GRP */ |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
469 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
470 |
/* end of grp.c ... */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
471 |