author | Ryan C. Gordon <icculus@icculus.org> |
Thu, 06 Jun 2002 05:47:41 +0000 | |
changeset 258 | 80fe5c9954dd |
parent 240 | 052041af9001 |
child 335 | 1d4720c018c3 |
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 |
* As it was never a concern in the DOS-based Duke Nukem days, I treat these |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
* archives as CASE-INSENSITIVE. Opening "myfile.txt" and "MYFILE.TXT" both |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 |
* work, and get the same file. |
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 |
* 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
|
27 |
* |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 |
* This file written by Ryan C. Gordon. |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
*/ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
|
214
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
31 |
#if HAVE_CONFIG_H |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
32 |
# include <config.h> |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
33 |
#endif |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
34 |
|
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
35 |
#if (defined PHYSFS_SUPPORTS_GRP) |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
36 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 |
#include <stdio.h> |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
#include <stdlib.h> |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
#include <string.h> |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
#include <errno.h> |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
#include <fcntl.h> |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
#include <assert.h> |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
#include "physfs.h" |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
#define __PHYSICSFS_INTERNAL__ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
#include "physfs_internal.h" |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
typedef struct |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
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 |
void *handle; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
51 |
char *filename; |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
52 |
PHYSFS_uint32 totalEntries; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 |
} GRPinfo; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 |
typedef struct |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
57 |
void *handle; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
58 |
PHYSFS_uint64 startPos; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
59 |
PHYSFS_uint64 size; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
} GRPfileinfo; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
|
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
63 |
static void GRP_dirClose(DirHandle *h); |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
64 |
static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer, |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
65 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount); |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
66 |
static int GRP_eof(FileHandle *handle); |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
67 |
static PHYSFS_sint64 GRP_tell(FileHandle *handle); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
68 |
static int GRP_seek(FileHandle *handle, PHYSFS_uint64 offset); |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
69 |
static PHYSFS_sint64 GRP_fileLength(FileHandle *handle); |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
70 |
static int GRP_fileClose(FileHandle *handle); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
71 |
static int GRP_isArchive(const char *filename, int forWriting); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
72 |
static DirHandle *GRP_openArchive(const char *name, int forWriting); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
73 |
static LinkedStringList *GRP_enumerateFiles(DirHandle *h, |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
74 |
const char *dirname, |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
75 |
int omitSymLinks); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
76 |
static int GRP_exists(DirHandle *h, const char *name); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
77 |
static int GRP_isDirectory(DirHandle *h, const char *name); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
78 |
static int GRP_isSymLink(DirHandle *h, const char *name); |
258
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
79 |
static PHYSFS_sint64 GRP_getLastModTime(DirHandle *h, const char *name); |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
80 |
static FileHandle *GRP_openRead(DirHandle *h, const char *name); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
81 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
82 |
static const FileFunctions __PHYSFS_FileFunctions_GRP = |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
83 |
{ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
84 |
GRP_read, /* read() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
85 |
NULL, /* write() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
86 |
GRP_eof, /* eof() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
87 |
GRP_tell, /* tell() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
88 |
GRP_seek, /* seek() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
89 |
GRP_fileLength, /* fileLength() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
90 |
GRP_fileClose /* fileClose() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
91 |
}; |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
92 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
93 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
94 |
const DirFunctions __PHYSFS_DirFunctions_GRP = |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
95 |
{ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
96 |
GRP_isArchive, /* isArchive() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
97 |
GRP_openArchive, /* openArchive() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
98 |
GRP_enumerateFiles, /* enumerateFiles() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
99 |
GRP_exists, /* exists() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
100 |
GRP_isDirectory, /* isDirectory() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
101 |
GRP_isSymLink, /* isSymLink() method */ |
258
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
102 |
GRP_getLastModTime, /* getLastModTime() method */ |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
103 |
GRP_openRead, /* openRead() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
104 |
NULL, /* openWrite() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
105 |
NULL, /* openAppend() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
106 |
NULL, /* remove() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
107 |
NULL, /* mkdir() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
108 |
GRP_dirClose /* dirClose() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
109 |
}; |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
110 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
111 |
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP = |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
112 |
{ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
113 |
"GRP", |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
114 |
"Build engine Groupfile format", |
95
215a06fc87eb
Changed author credits to wrap email addresses in "<>" and not "()" chars.
Ryan C. Gordon <icculus@icculus.org>
parents:
93
diff
changeset
|
115 |
"Ryan C. Gordon <icculus@clutteredmind.org>", |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
116 |
"http://www.icculus.org/physfs/", |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
117 |
}; |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
118 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
119 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
120 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
121 |
static void GRP_dirClose(DirHandle *h) |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
122 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
123 |
__PHYSFS_platformClose( ((GRPinfo *) h->opaque)->handle ); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
124 |
free(((GRPinfo *) h->opaque)->filename); |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
125 |
free(h->opaque); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
126 |
free(h); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
127 |
} /* GRP_dirClose */ |
24
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 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
130 |
static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer, |
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
131 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 |
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
134 |
void *fh = finfo->handle; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
135 |
PHYSFS_sint64 curPos = __PHYSFS_platformTell(fh); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
136 |
PHYSFS_uint64 bytesLeft = (finfo->startPos + finfo->size) - curPos; |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
161
diff
changeset
|
137 |
PHYSFS_uint64 objsLeft = (bytesLeft / objSize); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 |
if (objsLeft < objCount) |
194
09c353d30cd4
Patches for correctness and cleaner win32 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
175
diff
changeset
|
140 |
objCount = (PHYSFS_uint32) objsLeft; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
142 |
return(__PHYSFS_platformRead(fh, buffer, objSize, objCount)); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 |
} /* GRP_read */ |
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 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 |
static int GRP_eof(FileHandle *handle) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 |
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
149 |
void *fh = finfo->handle; |
194
09c353d30cd4
Patches for correctness and cleaner win32 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
175
diff
changeset
|
150 |
PHYSFS_sint64 pos = __PHYSFS_platformTell(fh); |
09c353d30cd4
Patches for correctness and cleaner win32 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
175
diff
changeset
|
151 |
BAIL_IF_MACRO(pos < 0, NULL, 1); /* (*shrug*) */ |
09c353d30cd4
Patches for correctness and cleaner win32 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
175
diff
changeset
|
152 |
return(pos >= (PHYSFS_sint64) (finfo->startPos + finfo->size)); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
} /* GRP_eof */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
156 |
static PHYSFS_sint64 GRP_tell(FileHandle *handle) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 |
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
159 |
return(__PHYSFS_platformTell(finfo->handle) - finfo->startPos); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 |
} /* GRP_tell */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
162 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
163 |
static int GRP_seek(FileHandle *handle, PHYSFS_uint64 offset) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 |
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque); |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
161
diff
changeset
|
166 |
PHYSFS_uint64 newPos = (finfo->startPos + offset); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 |
BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 |
BAIL_IF_MACRO(newPos > finfo->startPos + finfo->size, ERR_PAST_EOF, 0); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
170 |
return(__PHYSFS_platformSeek(finfo->handle, newPos)); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 |
} /* GRP_seek */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
174 |
static PHYSFS_sint64 GRP_fileLength(FileHandle *handle) |
28
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
175 |
{ |
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
176 |
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque); |
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
177 |
return(finfo->size); |
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
178 |
} /* GRP_fileLength */ |
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
179 |
|
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
180 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 |
static int GRP_fileClose(FileHandle *handle) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
183 |
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
184 |
BAIL_IF_MACRO(__PHYSFS_platformClose(finfo->handle), NULL, 0); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
185 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 |
free(handle->opaque); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 |
free(handle); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 |
return(1); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 |
} /* GRP_fileClose */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
192 |
static int openGrp(const char *filename, int forWriting, |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
193 |
void **fh, PHYSFS_sint32 *count) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
195 |
PHYSFS_uint8 buf[12]; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 |
*fh = NULL; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
198 |
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
|
199 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
200 |
*fh = __PHYSFS_platformOpenRead(filename); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
201 |
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
|
202 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
203 |
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
|
204 |
goto openGrp_failed; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
206 |
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
|
207 |
{ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
208 |
__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
|
209 |
goto openGrp_failed; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
210 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
211 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
212 |
if (__PHYSFS_platformRead(*fh, count, sizeof (PHYSFS_sint32), 1) != 1) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
213 |
goto openGrp_failed; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
214 |
|
175
45e423c38ff8
Fixed byte ordering bugs.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
215 |
*count = PHYSFS_swapSLE32(*count); |
45e423c38ff8
Fixed byte ordering bugs.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
216 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 |
return(1); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
218 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
219 |
openGrp_failed: |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
220 |
if (*fh != NULL) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
221 |
__PHYSFS_platformClose(*fh); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
222 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
223 |
*count = -1; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
224 |
*fh = NULL; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
225 |
return(0); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 |
} /* openGrp */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 |
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
|
230 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
231 |
void *fh; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 |
int fileCount; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
233 |
int retval = openGrp(filename, forWriting, &fh, &fileCount); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 |
if (fh != NULL) |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
236 |
__PHYSFS_platformClose(fh); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
238 |
return(retval); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 |
} /* GRP_isArchive */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
240 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 |
static DirHandle *GRP_openArchive(const char *name, int forWriting) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
243 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
244 |
void *fh = NULL; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 |
int fileCount; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 |
DirHandle *retval = malloc(sizeof (DirHandle)); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
248 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
249 |
retval->opaque = malloc(sizeof (GRPinfo)); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
250 |
if (retval->opaque == NULL) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
252 |
__PHYSFS_setError(ERR_OUT_OF_MEMORY); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
253 |
goto GRP_openArchive_failed; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
254 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
255 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
256 |
((GRPinfo *) retval->opaque)->filename = (char *) malloc(strlen(name) + 1); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
257 |
if (((GRPinfo *) retval->opaque)->filename == NULL) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
258 |
{ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
259 |
__PHYSFS_setError(ERR_OUT_OF_MEMORY); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
260 |
goto GRP_openArchive_failed; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 |
} /* if */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 |
if (!openGrp(name, forWriting, &fh, &fileCount)) |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
264 |
goto GRP_openArchive_failed; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
266 |
strcpy(((GRPinfo *) retval->opaque)->filename, name); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 |
((GRPinfo *) retval->opaque)->handle = fh; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 |
((GRPinfo *) retval->opaque)->totalEntries = fileCount; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 |
retval->funcs = &__PHYSFS_DirFunctions_GRP; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 |
return(retval); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
271 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
272 |
GRP_openArchive_failed: |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
273 |
if (retval != NULL) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
274 |
{ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
275 |
if (retval->opaque != NULL) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
276 |
{ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
277 |
if ( ((GRPinfo *) retval->opaque)->filename != NULL ) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
278 |
free( ((GRPinfo *) retval->opaque)->filename ); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
279 |
free(retval->opaque); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
280 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
281 |
free(retval); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
282 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
283 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
284 |
if (fh != NULL) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
285 |
__PHYSFS_platformClose(fh); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
286 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
287 |
return(NULL); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 |
} /* GRP_openArchive */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
290 |
|
41
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
291 |
static LinkedStringList *GRP_enumerateFiles(DirHandle *h, |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
292 |
const char *dirname, |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
293 |
int omitSymLinks) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
295 |
PHYSFS_uint8 buf[16]; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 |
GRPinfo *g = (GRPinfo *) (h->opaque); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
297 |
void *fh = g->handle; |
161
4fcc863fdc5f
-Added type casting that Ryan needs to approve.
Gregory S. Read <zeph@clutteredmind.org>
parents:
150
diff
changeset
|
298 |
PHYSFS_uint32 i; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 |
LinkedStringList *retval = NULL; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 |
LinkedStringList *l = NULL; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 |
LinkedStringList *prev = NULL; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
303 |
/* !!! FIXME: Does this consider "/" ? */ |
31
41c23ac35615
Fixed GRP_enumerateFiles() so that it will only list files in the root of
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
304 |
if (*dirname != '\0') /* no directories in GRP files. */ |
41c23ac35615
Fixed GRP_enumerateFiles() so that it will only list files in the root of
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
305 |
return(NULL); |
41c23ac35615
Fixed GRP_enumerateFiles() so that it will only list files in the root of
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
306 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 |
/* jump to first file entry... */ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
308 |
BAIL_IF_MACRO(!__PHYSFS_platformSeek(fh, 16), NULL, NULL); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
309 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
310 |
for (i = 0; i < g->totalEntries; i++) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
312 |
BAIL_IF_MACRO(__PHYSFS_platformRead(fh, buf, 16, 1) != 1, NULL, retval); |
24
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 |
buf[12] = '\0'; /* FILENAME.EXT is all you get. */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 |
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
|
317 |
if (l == NULL) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 |
break; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 |
|
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
139
diff
changeset
|
320 |
l->str = (char *) malloc(strlen((const char *) buf) + 1); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
321 |
if (l->str == NULL) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 |
free(l); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 |
break; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
325 |
} /* if */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
326 |
|
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
139
diff
changeset
|
327 |
strcpy(l->str, (const char *) buf); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
328 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
329 |
if (retval == NULL) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
330 |
retval = l; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 |
else |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 |
prev->next = l; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
334 |
prev = l; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
335 |
l->next = NULL; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
336 |
} /* for */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
338 |
return(retval); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
339 |
} /* GRP_enumerateFiles */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
340 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
341 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
342 |
static PHYSFS_sint32 getFileEntry(DirHandle *h, const char *name, |
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
139
diff
changeset
|
343 |
PHYSFS_uint32 *size) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
344 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
345 |
PHYSFS_uint8 buf[16]; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
346 |
GRPinfo *g = (GRPinfo *) (h->opaque); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
347 |
void *fh = g->handle; |
161
4fcc863fdc5f
-Added type casting that Ryan needs to approve.
Gregory S. Read <zeph@clutteredmind.org>
parents:
150
diff
changeset
|
348 |
PHYSFS_uint32 i; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
349 |
char *ptr; |
26
575e03541d5e
Logic fixes; seems to work rather well with KenBuild, now.
Ryan C. Gordon <icculus@icculus.org>
parents:
24
diff
changeset
|
350 |
int retval = (g->totalEntries + 1) * 16; /* offset of raw file data */ |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
351 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 |
/* Rule out filenames to avoid unneeded file i/o... */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
353 |
if (strchr(name, '/') != NULL) /* no directories in groupfiles. */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
354 |
return(-1); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
355 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
356 |
ptr = strchr(name, '.'); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
357 |
if ((ptr) && (strlen(ptr) > 4)) /* 3 char extension at most. */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
358 |
return(-1); |
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 |
if (strlen(name) > 12) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
361 |
return(-1); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
362 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
363 |
/* jump to first file entry... */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
364 |
BAIL_IF_MACRO(!__PHYSFS_platformSeek(fh, 16), NULL, -1); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
365 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
366 |
for (i = 0; i < g->totalEntries; i++) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 |
{ |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
368 |
PHYSFS_sint32 l = 0; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
369 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
370 |
BAIL_IF_MACRO(__PHYSFS_platformRead(fh, buf, 12, 1) != 1, NULL, -1); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
371 |
BAIL_IF_MACRO(__PHYSFS_platformRead(fh, &l, sizeof (l), 1) != 1, NULL, -1); |
175
45e423c38ff8
Fixed byte ordering bugs.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
372 |
l = PHYSFS_swapSLE32(l); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
373 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
374 |
buf[12] = '\0'; /* FILENAME.EXT is all you get. */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
375 |
|
150
221f15a7cb08
Patched to compile on MacOS Classic, with CodeWarrior 6.
Ryan C. Gordon <icculus@icculus.org>
parents:
139
diff
changeset
|
376 |
if (__PHYSFS_platformStricmp((const char *) buf, name) == 0) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
377 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
378 |
if (size != NULL) |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
379 |
*size = l; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
380 |
return(retval); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
381 |
} /* if */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
382 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
383 |
retval += l; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
384 |
} /* for */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
385 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
386 |
return(-1); /* not found. */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
387 |
} /* getFileEntry */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
388 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
389 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
390 |
static int GRP_exists(DirHandle *h, const char *name) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
391 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
392 |
return(getFileEntry(h, name, NULL) != -1); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
393 |
} /* GRP_exists */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
394 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
395 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
396 |
static int GRP_isDirectory(DirHandle *h, const char *name) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
397 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
398 |
return(0); /* never directories in a groupfile. */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
399 |
} /* GRP_isDirectory */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
400 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
401 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
402 |
static int GRP_isSymLink(DirHandle *h, const char *name) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
403 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
404 |
return(0); /* never symlinks in a groupfile. */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
405 |
} /* GRP_isSymLink */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
406 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
407 |
|
258
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
408 |
static PHYSFS_sint64 GRP_getLastModTime(DirHandle *h, const char *name) |
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
409 |
{ |
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
410 |
/* Just return the time of the GRP itself in the physical filesystem. */ |
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
411 |
return(__PHYSFS_platformGetLastModTime(((GRPinfo *) h->opaque)->filename)); |
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
412 |
} /* GRP_getLastModTime */ |
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
413 |
|
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
414 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
415 |
static FileHandle *GRP_openRead(DirHandle *h, const char *name) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
416 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
417 |
const char *filename = ((GRPinfo *) h->opaque)->filename; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
418 |
FileHandle *retval; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
419 |
GRPfileinfo *finfo; |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
420 |
PHYSFS_uint32 size; |
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
421 |
PHYSFS_sint32 offset; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
422 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
423 |
offset = getFileEntry(h, name, &size); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
424 |
BAIL_IF_MACRO(offset == -1, ERR_NO_SUCH_FILE, NULL); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
425 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
426 |
retval = (FileHandle *) malloc(sizeof (FileHandle)); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
427 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
428 |
finfo = (GRPfileinfo *) malloc(sizeof (GRPfileinfo)); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
429 |
if (finfo == NULL) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
430 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
431 |
free(retval); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
432 |
BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
433 |
} /* if */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
434 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
435 |
finfo->handle = __PHYSFS_platformOpenRead(filename); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
436 |
if ( (finfo->handle == NULL) || |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
437 |
(!__PHYSFS_platformSeek(finfo->handle, offset)) ) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
438 |
{ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
439 |
free(finfo); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
440 |
free(retval); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
441 |
return(NULL); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
442 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
443 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
444 |
finfo->startPos = offset; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
445 |
finfo->size = size; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
446 |
retval->opaque = (void *) finfo; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
447 |
retval->funcs = &__PHYSFS_FileFunctions_GRP; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
448 |
retval->dirHandle = h; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
449 |
return(retval); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
450 |
} /* GRP_openRead */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
451 |
|
214
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
452 |
#endif /* defined PHYSFS_SUPPORTS_GRP */ |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
453 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
454 |
/* end of grp.c ... */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
455 |