author | Ryan C. Gordon <icculus@icculus.org> |
Tue, 23 Jul 2002 07:48:43 +0000 | |
changeset 364 | 51da162c76f7 |
parent 335 | 1d4720c018c3 |
child 370 | da631e118455 |
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 <errno.h> |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 |
#include <fcntl.h> |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
#include <assert.h> |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
#include "physfs.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 |
#define __PHYSICSFS_INTERNAL__ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
#include "physfs_internal.h" |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
44 |
/* |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
45 |
* When sorting the grp entries in an archive, we use a modified QuickSort. |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
46 |
* When there are less then GRP_QUICKSORT_THRESHOLD entries left to sort, |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
47 |
* we switch over to an InsertionSort for the remainder. Tweak to taste. |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
48 |
*/ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
49 |
#define GRP_QUICKSORT_THRESHOLD 4 |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
50 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
typedef struct |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
{ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
53 |
char name[13]; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
54 |
PHYSFS_uint64 startPos; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
55 |
PHYSFS_uint64 size; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
56 |
} GRPentry; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
57 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
58 |
typedef struct |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
59 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
60 |
char *filename; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
61 |
PHYSFS_sint64 last_mod_time; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
62 |
PHYSFS_uint32 entryCount; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
63 |
GRPentry *entries; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
} GRPinfo; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
typedef struct |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
68 |
void *handle; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
69 |
GRPentry *entry; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
70 |
PHYSFS_sint64 curPos; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
} GRPfileinfo; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
|
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
const char *dirname, |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
86 |
int omitSymLinks); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
87 |
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
|
88 |
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
|
89 |
static int GRP_isSymLink(DirHandle *h, const char *name); |
258
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
90 |
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
|
91 |
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
|
92 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
93 |
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
|
94 |
{ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
95 |
GRP_read, /* read() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
96 |
NULL, /* write() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
97 |
GRP_eof, /* eof() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
98 |
GRP_tell, /* tell() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
99 |
GRP_seek, /* seek() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
100 |
GRP_fileLength, /* fileLength() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
101 |
GRP_fileClose /* fileClose() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
102 |
}; |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
103 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
104 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
105 |
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
|
106 |
{ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
107 |
GRP_isArchive, /* isArchive() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
108 |
GRP_openArchive, /* openArchive() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
109 |
GRP_enumerateFiles, /* enumerateFiles() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
110 |
GRP_exists, /* exists() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
111 |
GRP_isDirectory, /* isDirectory() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
112 |
GRP_isSymLink, /* isSymLink() method */ |
258
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
113 |
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
|
114 |
GRP_openRead, /* openRead() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
115 |
NULL, /* openWrite() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
116 |
NULL, /* openAppend() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
117 |
NULL, /* remove() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
118 |
NULL, /* mkdir() method */ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
119 |
GRP_dirClose /* dirClose() method */ |
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 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
122 |
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
|
123 |
{ |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
124 |
"GRP", |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
125 |
"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
|
126 |
"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
|
127 |
"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
|
128 |
}; |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
129 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
130 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
131 |
|
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
132 |
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
|
133 |
{ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
134 |
GRPinfo *info = ((GRPinfo *) h->opaque); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
135 |
free(info->filename); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
136 |
free(info->entries); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
137 |
free(info); |
93
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
138 |
free(h); |
74d1df359be3
Patched to compile with an ancient version of CodeWarrior.
Ryan C. Gordon <icculus@icculus.org>
parents:
69
diff
changeset
|
139 |
} /* GRP_dirClose */ |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
142 |
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
|
143 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) |
24
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 |
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
146 |
GRPentry *entry = finfo->entry; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
147 |
PHYSFS_uint64 bytesLeft = entry->size - finfo->curPos; |
163
fc2b8ee5b420
Approved zeph's comments, fixed a few of my screwups.
Ryan C. Gordon <icculus@icculus.org>
parents:
161
diff
changeset
|
148 |
PHYSFS_uint64 objsLeft = (bytesLeft / objSize); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
149 |
PHYSFS_sint64 rc; |
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 |
if (objsLeft < objCount) |
194
09c353d30cd4
Patches for correctness and cleaner win32 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
175
diff
changeset
|
152 |
objCount = (PHYSFS_uint32) objsLeft; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
154 |
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
|
155 |
if (rc > 0) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
156 |
finfo->curPos += (rc * objSize); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
157 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
158 |
return(rc); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 |
} /* GRP_read */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 |
|
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 |
static int GRP_eof(FileHandle *handle) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 |
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
165 |
GRPentry *entry = finfo->entry; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
166 |
return(finfo->curPos >= (PHYSFS_sint64) entry->size); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 |
} /* GRP_eof */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
170 |
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
|
171 |
{ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
172 |
return(((GRPfileinfo *) (handle->opaque))->curPos); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
} /* GRP_tell */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
176 |
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
|
177 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 |
GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
179 |
GRPentry *entry = finfo->entry; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
180 |
PHYSFS_uint64 newPos = (entry->startPos + offset); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
181 |
int rc; |
24
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 |
BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
184 |
BAIL_IF_MACRO(newPos > entry->startPos + entry->size, ERR_PAST_EOF, 0); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
185 |
rc = __PHYSFS_platformSeek(finfo->handle, newPos); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
186 |
if (rc) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
187 |
finfo->curPos = offset; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
188 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
189 |
return(rc); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 |
} /* GRP_seek */ |
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 |
|
132
b53fa5093749
Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
193 |
static PHYSFS_sint64 GRP_fileLength(FileHandle *handle) |
28
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
194 |
{ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
195 |
return(((GRPfileinfo *) handle->opaque)->entry->size); |
28
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
196 |
} /* GRP_fileLength */ |
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
197 |
|
529214f57d1b
Added PHYSFS_fileLength(). Bleh.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
198 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 |
static int GRP_fileClose(FileHandle *handle) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 |
{ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
201 |
GRPfileinfo *finfo = ((GRPfileinfo *) handle->opaque); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
202 |
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
203 |
free(finfo); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 |
free(handle); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 |
return(1); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 |
} /* GRP_fileClose */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
209 |
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
|
210 |
void **fh, PHYSFS_uint32 *count) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
212 |
PHYSFS_uint8 buf[12]; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
214 |
*fh = NULL; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
215 |
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
|
216 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
217 |
*fh = __PHYSFS_platformOpenRead(filename); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
218 |
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
|
219 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
220 |
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
|
221 |
goto openGrp_failed; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 |
|
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
223 |
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
|
224 |
{ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
225 |
__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
|
226 |
goto openGrp_failed; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
227 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
228 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
229 |
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
|
230 |
goto openGrp_failed; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
232 |
*count = PHYSFS_swapULE32(*count); |
175
45e423c38ff8
Fixed byte ordering bugs.
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
233 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 |
return(1); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
235 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
236 |
openGrp_failed: |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
237 |
if (*fh != NULL) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
238 |
__PHYSFS_platformClose(*fh); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
239 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
240 |
*count = -1; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
241 |
*fh = NULL; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
242 |
return(0); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
243 |
} /* grp_open */ |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 |
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
|
247 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
248 |
void *fh; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
249 |
PHYSFS_uint32 fileCount; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
250 |
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
|
251 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 |
if (fh != NULL) |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
253 |
__PHYSFS_platformClose(fh); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 |
return(retval); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 |
} /* GRP_isArchive */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
259 |
static void grp_entry_swap(GRPentry *a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
260 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
261 |
GRPentry tmp; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
262 |
memcpy(&tmp, &a[one], sizeof (GRPentry)); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
263 |
memcpy(&a[one], &a[two], sizeof (GRPentry)); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
264 |
memcpy(&a[two], &tmp, sizeof (GRPentry)); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
265 |
} /* grp_entry_swap */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
266 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
267 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
268 |
static void grp_quick_sort(GRPentry *a, PHYSFS_uint32 lo, PHYSFS_uint32 hi) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
269 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
270 |
PHYSFS_uint32 i; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
271 |
PHYSFS_uint32 j; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
272 |
GRPentry *v; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
273 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
274 |
if ((hi - lo) > GRP_QUICKSORT_THRESHOLD) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
275 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
276 |
i = (hi + lo) / 2; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
277 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
278 |
if (strcmp(a[lo].name, a[i].name) > 0) grp_entry_swap(a, lo, i); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
279 |
if (strcmp(a[lo].name, a[hi].name) > 0) grp_entry_swap(a, lo, hi); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
280 |
if (strcmp(a[i].name, a[hi].name) > 0) grp_entry_swap(a, i, hi); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
281 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
282 |
j = hi - 1; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
283 |
grp_entry_swap(a, i, j); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
284 |
i = lo; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
285 |
v = &a[j]; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
286 |
while (1) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
287 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
288 |
while(strcmp(a[++i].name, v->name) < 0) {} |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
289 |
while(strcmp(a[--j].name, v->name) > 0) {} |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
290 |
if (j < i) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
291 |
break; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
292 |
grp_entry_swap(a, i, j); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
293 |
} /* while */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
294 |
grp_entry_swap(a, i, hi-1); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
295 |
grp_quick_sort(a, lo, j); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
296 |
grp_quick_sort(a, i+1, hi); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
297 |
} /* if */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
298 |
} /* grp_quick_sort */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
299 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
300 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
301 |
static void grp_insertion_sort(GRPentry *a, PHYSFS_uint32 lo, PHYSFS_uint32 hi) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
302 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
303 |
PHYSFS_uint32 i; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
304 |
PHYSFS_uint32 j; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
305 |
GRPentry tmp; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
306 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
307 |
for (i = lo + 1; i <= hi; i++) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
308 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
309 |
memcpy(&tmp, &a[i], sizeof (GRPentry)); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
310 |
j = i; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
311 |
while ((j > lo) && (strcmp(a[j - 1].name, tmp.name) > 0)) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
312 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
313 |
memcpy(&a[j], &a[j - 1], sizeof (GRPentry)); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
314 |
j--; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
315 |
} /* while */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
316 |
memcpy(&a[j], &tmp, sizeof (GRPentry)); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
317 |
} /* for */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
318 |
} /* grp_insertion_sort */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
319 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
320 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
321 |
static void grp_sort_entries(GRPentry *entries, PHYSFS_uint32 max) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
322 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
323 |
/* |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
324 |
* Fast Quicksort algorithm inspired by code from here: |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
325 |
* http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
326 |
*/ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
327 |
if (max <= GRP_QUICKSORT_THRESHOLD) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
328 |
grp_quick_sort(entries, 0, max - 1); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
329 |
grp_insertion_sort(entries, 0, max - 1); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
330 |
} /* grp_sort_entries */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
331 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
332 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
333 |
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
|
334 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
335 |
void *fh = NULL; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
336 |
PHYSFS_uint32 fileCount; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
337 |
PHYSFS_uint32 location = 32; /* sizeof sig + sizeof 1st file header. */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
338 |
GRPentry *entry; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
339 |
char *ptr; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
340 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
341 |
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
|
342 |
info->entryCount = fileCount; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
343 |
info->entries = (GRPentry *) malloc(sizeof (GRPentry) * fileCount); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
344 |
if (info->entries == NULL) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
345 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
346 |
__PHYSFS_platformClose(fh); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
347 |
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
|
348 |
} /* if */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
349 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
350 |
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
|
351 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
352 |
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
|
353 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
354 |
__PHYSFS_platformClose(fh); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
355 |
return(0); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
356 |
} /* if */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
357 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
358 |
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
|
359 |
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
|
360 |
*ptr = '\0'; /* trim extra spaces. */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
361 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
362 |
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
|
363 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
364 |
__PHYSFS_platformClose(fh); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
365 |
return(0); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
366 |
} /* if */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
367 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
368 |
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
|
369 |
entry->startPos = location; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
370 |
location += entry->size + 16; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
371 |
} /* for */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
372 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
373 |
__PHYSFS_platformClose(fh); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
374 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
375 |
grp_sort_entries(info->entries, info->entryCount); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
376 |
return(1); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
377 |
} /* grp_load_entries */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
378 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
379 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
380 |
static DirHandle *GRP_openArchive(const char *name, int forWriting) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
381 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
382 |
GRPinfo *info; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
383 |
DirHandle *retval = malloc(sizeof (DirHandle)); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
384 |
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name); |
24
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 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
387 |
info = retval->opaque = malloc(sizeof (GRPinfo)); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
388 |
if (info == NULL) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
389 |
{ |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
390 |
__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
|
391 |
goto GRP_openArchive_failed; |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
392 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
393 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
394 |
memset(info, '\0', sizeof (GRPinfo)); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
395 |
|
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
396 |
info->filename = (char *) malloc(strlen(name) + 1); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
397 |
if (info->filename == NULL) |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
398 |
{ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
399 |
__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
|
400 |
goto GRP_openArchive_failed; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
401 |
} /* if */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
402 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
403 |
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
|
404 |
goto GRP_openArchive_failed; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
405 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
406 |
strcpy(info->filename, name); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
407 |
info->last_mod_time = modtime; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
408 |
retval->funcs = &__PHYSFS_DirFunctions_GRP; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
409 |
return(retval); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
410 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
411 |
GRP_openArchive_failed: |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
412 |
if (retval != NULL) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
413 |
{ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
414 |
if (retval->opaque != NULL) |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
415 |
{ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
416 |
if (info->filename != NULL) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
417 |
free(info->filename); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
418 |
if (info->entries != NULL) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
419 |
free(info->entries); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
420 |
free(info); |
139
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
421 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
422 |
free(retval); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
423 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
424 |
|
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
425 |
return(NULL); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
426 |
} /* GRP_openArchive */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
427 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
428 |
|
41
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
429 |
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
|
430 |
const char *dirname, |
ff60d39d0862
Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
431 |
int omitSymLinks) |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
432 |
{ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
433 |
GRPinfo *info = ((GRPinfo *) h->opaque); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
434 |
GRPentry *entry = info->entries; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
435 |
LinkedStringList *retval = NULL, *p = NULL; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
436 |
PHYSFS_uint32 max = info->entryCount; |
161
4fcc863fdc5f
-Added type casting that Ryan needs to approve.
Gregory S. Read <zeph@clutteredmind.org>
parents:
150
diff
changeset
|
437 |
PHYSFS_uint32 i; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
438 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
439 |
/* no directories in GRP files. */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
440 |
BAIL_IF_MACRO(*dirname != '\0', ERR_NOT_A_DIR, NULL); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
441 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
442 |
for (i = 0; i < max; i++, entry++) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
443 |
retval = __PHYSFS_addToLinkedStringList(retval, &p, entry->name, -1); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
444 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
445 |
return(retval); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
446 |
} /* GRP_enumerateFiles */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
447 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
448 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
449 |
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
|
450 |
{ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
451 |
char *ptr = strchr(name, '.'); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
452 |
GRPentry *a = info->entries; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
453 |
PHYSFS_sint32 lo = 0; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
454 |
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
|
455 |
PHYSFS_sint32 middle; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
456 |
int rc; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
457 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
458 |
/* |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
459 |
* 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
|
460 |
* 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
|
461 |
*/ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
462 |
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
|
463 |
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
|
464 |
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
|
465 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
466 |
while (lo <= hi) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
467 |
{ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
468 |
middle = lo + ((hi - lo) / 2); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
469 |
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
|
470 |
if (rc == 0) /* found it! */ |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
471 |
return(&a[middle]); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
472 |
else if (rc > 0) |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
473 |
lo = middle + 1; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
474 |
else |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
475 |
hi = middle - 1; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
476 |
} /* while */ |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
477 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
478 |
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
|
479 |
} /* grp_find_entry */ |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
480 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
481 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
482 |
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
|
483 |
{ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
484 |
return(grp_find_entry(((GRPinfo *) h->opaque), name) != NULL); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
485 |
} /* GRP_exists */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
486 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
487 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
488 |
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
|
489 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
490 |
return(0); /* never directories in a groupfile. */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
491 |
} /* GRP_isDirectory */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
492 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
493 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
494 |
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
|
495 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
496 |
return(0); /* never symlinks in a groupfile. */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
497 |
} /* GRP_isSymLink */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
498 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
499 |
|
258
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
500 |
static PHYSFS_sint64 GRP_getLastModTime(DirHandle *h, const char *name) |
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
501 |
{ |
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
502 |
/* Just return the time of the GRP itself in the physical filesystem. */ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
503 |
return(((GRPinfo *) h->opaque)->last_mod_time); |
258
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
504 |
} /* GRP_getLastModTime */ |
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
505 |
|
80fe5c9954dd
getLastModTime implemented.
Ryan C. Gordon <icculus@icculus.org>
parents:
240
diff
changeset
|
506 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
507 |
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
|
508 |
{ |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
509 |
GRPinfo *info = ((GRPinfo *) h->opaque); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
510 |
FileHandle *retval; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
511 |
GRPfileinfo *finfo; |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
512 |
GRPentry *entry; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
513 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
514 |
entry = grp_find_entry(info, name); |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
515 |
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
|
516 |
|
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
517 |
retval = (FileHandle *) malloc(sizeof (FileHandle)); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
518 |
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
|
519 |
finfo = (GRPfileinfo *) malloc(sizeof (GRPfileinfo)); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
520 |
if (finfo == NULL) |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
521 |
{ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
522 |
free(retval); |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
523 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
524 |
} /* if */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
525 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
526 |
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
|
527 |
if ( (finfo->handle == NULL) || |
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
528 |
(!__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
|
529 |
{ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
530 |
free(finfo); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
531 |
free(retval); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
532 |
return(NULL); |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
533 |
} /* if */ |
616420dc210c
Converted to file i/o abstraction, removed race condition.
Ryan C. Gordon <icculus@icculus.org>
parents:
132
diff
changeset
|
534 |
|
364
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
535 |
finfo->curPos = 0; |
51da162c76f7
Major overhauls. More efficient, robust, and bug-free.
Ryan C. Gordon <icculus@icculus.org>
parents:
335
diff
changeset
|
536 |
finfo->entry = entry; |
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
537 |
retval->opaque = (void *) finfo; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
538 |
retval->funcs = &__PHYSFS_FileFunctions_GRP; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
539 |
retval->dirHandle = h; |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
540 |
return(retval); |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
541 |
} /* GRP_openRead */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
542 |
|
214
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
543 |
#endif /* defined PHYSFS_SUPPORTS_GRP */ |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
194
diff
changeset
|
544 |
|
24
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
545 |
/* end of grp.c ... */ |
b050804123a3
Initial add. Implemented, buggy, but not crashing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
546 |