author | Ryan C. Gordon <icculus@icculus.org> |
Tue, 28 Jan 2003 18:29:10 +0000 | |
changeset 534 | 2aeee045f27e |
parent 504 | 3420d82f9b01 |
child 543 | 90607e53b9b2 |
permissions | -rw-r--r-- |
450 | 1 |
/* |
2 |
* Quake PAK support routines for PhysicsFS. |
|
3 |
* |
|
4 |
* This driver handles id Software Quake PAK files. |
|
5 |
* |
|
6 |
* Please see the file LICENSE in the source's root directory. |
|
7 |
* |
|
8 |
* This file written by Ed Sinjiashvili. |
|
9 |
*/ |
|
10 |
||
11 |
#if HAVE_CONFIG_H |
|
12 |
# include <config.h> |
|
13 |
#endif |
|
14 |
||
15 |
#if (defined PHYSFS_SUPPORTS_QPAK) |
|
16 |
#include <stdio.h> |
|
17 |
#include <stdlib.h> |
|
18 |
#include <string.h> |
|
19 |
#include "physfs.h" |
|
20 |
||
21 |
#define __PHYSICSFS_INTERNAL__ |
|
22 |
#include "physfs_internal.h" |
|
23 |
||
24 |
#define QPAK_MAXDIRLEN 60 |
|
25 |
||
26 |
typedef struct |
|
27 |
{ |
|
28 |
char name[56]; |
|
29 |
PHYSFS_uint32 offset; |
|
30 |
PHYSFS_uint32 size; |
|
31 |
} QPAKentry; |
|
32 |
||
33 |
typedef struct tagQPAKdirentry |
|
34 |
{ |
|
35 |
char *name; |
|
36 |
QPAKentry *entry; |
|
37 |
struct tagQPAKdirentry *next; |
|
38 |
} QPAKdirentry; |
|
39 |
||
40 |
typedef struct QPAKDirectory |
|
41 |
{ |
|
42 |
char name[QPAK_MAXDIRLEN]; |
|
43 |
||
44 |
struct QPAKDirectory *dirs, *next; |
|
45 |
||
46 |
QPAKdirentry *files; |
|
47 |
} QPAKdirectory; |
|
48 |
||
49 |
typedef struct |
|
50 |
{ |
|
51 |
void *handle; |
|
52 |
char *filename; |
|
53 |
PHYSFS_uint32 dirOffset; |
|
54 |
PHYSFS_uint32 totalEntries; |
|
55 |
QPAKentry *entries; |
|
56 |
QPAKdirectory *root; |
|
57 |
} QPAKinfo; |
|
58 |
||
59 |
typedef struct |
|
60 |
{ |
|
61 |
void *handle; |
|
62 |
QPAKentry *entry; |
|
63 |
PHYSFS_sint64 curPos; |
|
64 |
} QPAKfileinfo; |
|
65 |
||
66 |
||
67 |
static int QPAK_isArchive(const char *filename, int forWriting); |
|
68 |
static DirHandle *QPAK_openArchive(const char *name, int forWriting); |
|
69 |
static void QPAK_dirClose(DirHandle *h); |
|
70 |
static LinkedStringList *QPAK_enumerateFiles(DirHandle *h, const char *dirname, |
|
71 |
int omitSymLinks); |
|
72 |
static int QPAK_exists(DirHandle *h, const char *name); |
|
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
73 |
static int QPAK_isDirectory(DirHandle *h, const char *name, int *e); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
74 |
static int QPAK_isSymLink(DirHandle *h, const char *name, int *e); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
75 |
static PHYSFS_sint64 QPAK_getLastModTime(DirHandle *h, const char *n, int *e); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
76 |
static FileHandle *QPAK_openRead(DirHandle *h, const char *name, int *e); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
77 |
static FileHandle *QPAK_openWrite(DirHandle *h, const char *name); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
78 |
static FileHandle *QPAK_openAppend(DirHandle *h, const char *name); |
450 | 79 |
|
80 |
||
81 |
static PHYSFS_sint64 QPAK_read(FileHandle *handle, void *buffer, |
|
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
82 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
83 |
static PHYSFS_sint64 QPAK_write(FileHandle *handle, const void *buffer, |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
84 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount); |
450 | 85 |
static int QPAK_eof(FileHandle *handle); |
86 |
static PHYSFS_sint64 QPAK_tell(FileHandle *handle); |
|
87 |
static int QPAK_seek(FileHandle *handle, PHYSFS_uint64 offset); |
|
88 |
static PHYSFS_sint64 QPAK_fileLength(FileHandle *handle); |
|
89 |
static int QPAK_fileClose(FileHandle *handle); |
|
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
90 |
static int QPAK_remove(DirHandle *h, const char *name); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
91 |
static int QPAK_mkdir(DirHandle *h, const char *name); |
450 | 92 |
|
93 |
||
94 |
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_QPAK = |
|
95 |
{ |
|
96 |
"PAK", |
|
97 |
"Quake PAK file format", |
|
98 |
"Ed Sinjiashvili <slimb@swes.saren.ru>", |
|
99 |
"http://icculus.org/physfs/", |
|
100 |
}; |
|
101 |
||
102 |
static const FileFunctions __PHYSFS_FileFunctions_QPAK = |
|
103 |
{ |
|
104 |
QPAK_read, /* read() method */ |
|
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
105 |
QPAK_write, /* write() method */ |
450 | 106 |
QPAK_eof, /* eof() method */ |
107 |
QPAK_tell, /* tell() method */ |
|
108 |
QPAK_seek, /* seek() method */ |
|
109 |
QPAK_fileLength, /* fileLength() method */ |
|
110 |
QPAK_fileClose /* fileClose() method */ |
|
111 |
}; |
|
112 |
||
113 |
const DirFunctions __PHYSFS_DirFunctions_QPAK = |
|
114 |
{ |
|
115 |
&__PHYSFS_ArchiveInfo_QPAK, |
|
116 |
QPAK_isArchive, /* isArchive() method */ |
|
117 |
QPAK_openArchive, /* openArchive() method */ |
|
118 |
QPAK_enumerateFiles, /* enumerateFiles() method */ |
|
119 |
QPAK_exists, /* exists() method */ |
|
120 |
QPAK_isDirectory, /* isDirectory() method */ |
|
121 |
QPAK_isSymLink, /* isSymLink() method */ |
|
122 |
QPAK_getLastModTime, /* getLastModTime() method */ |
|
123 |
QPAK_openRead, /* openRead() method */ |
|
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
124 |
QPAK_openWrite, /* openWrite() method */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
125 |
QPAK_openAppend, /* openAppend() method */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
126 |
QPAK_remove, /* remove() method */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
127 |
QPAK_mkdir, /* mkdir() method */ |
450 | 128 |
QPAK_dirClose /* dirClose() method */ |
129 |
}; |
|
130 |
||
131 |
||
132 |
#define QPAK_MAGIC 0x4B434150 /* look like "PACK" in ascii. */ |
|
133 |
||
134 |
||
135 |
/* |
|
136 |
* Read an unsigned 32-bit int and swap to native byte order. |
|
137 |
*/ |
|
138 |
static int readui32(void *in, PHYSFS_uint32 *val) |
|
139 |
{ |
|
140 |
PHYSFS_uint32 v; |
|
141 |
BAIL_IF_MACRO(__PHYSFS_platformRead(in, &v, sizeof (v), 1) != 1, NULL, 0); |
|
142 |
*val = PHYSFS_swapULE32(v); |
|
143 |
return(1); |
|
144 |
} /* readui32 */ |
|
145 |
||
146 |
||
147 |
static int openQPak(const char *filename, int forWriting, void **fileHandle) |
|
148 |
{ |
|
149 |
PHYSFS_uint32 sig; |
|
150 |
||
151 |
*fileHandle = NULL; |
|
152 |
BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0); |
|
153 |
||
154 |
*fileHandle = __PHYSFS_platformOpenRead(filename); |
|
155 |
BAIL_IF_MACRO(*fileHandle == NULL, NULL, 0); |
|
156 |
||
157 |
if (!readui32(*fileHandle, &sig)) |
|
158 |
goto openPak_failed; |
|
159 |
||
456 | 160 |
if (sig != QPAK_MAGIC) |
450 | 161 |
{ |
162 |
__PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE); |
|
163 |
goto openPak_failed; |
|
164 |
} /* if */ |
|
165 |
||
166 |
return(1); |
|
167 |
||
168 |
openPak_failed: |
|
169 |
if (*fileHandle != NULL) |
|
170 |
__PHYSFS_platformClose(*fileHandle); |
|
171 |
||
172 |
*fileHandle = NULL; |
|
173 |
return(0); |
|
174 |
} /* openQPak */ |
|
175 |
||
176 |
||
177 |
static int QPAK_isArchive(const char *filename, int forWriting) |
|
178 |
{ |
|
179 |
void *fileHandle; |
|
180 |
int retval = openQPak(filename, forWriting, &fileHandle); |
|
181 |
||
182 |
if (fileHandle != NULL) |
|
183 |
__PHYSFS_platformClose(fileHandle); |
|
184 |
||
185 |
return(retval); |
|
186 |
} /* QPAK_isArchive */ |
|
187 |
||
188 |
||
189 |
static int qpak_loadEntries(void *fh, int dirOffset, int numEntries, |
|
190 |
QPAKentry *entries) |
|
191 |
{ |
|
494 | 192 |
PHYSFS_sint32 i; |
450 | 193 |
|
194 |
BAIL_IF_MACRO(__PHYSFS_platformSeek(fh, dirOffset) == 0, NULL, 0); |
|
195 |
||
196 |
for (i = 0; i < numEntries; i++, entries++) |
|
197 |
{ |
|
198 |
PHYSFS_sint64 r = __PHYSFS_platformRead(fh, entries->name, 56, 1); |
|
199 |
BAIL_IF_MACRO(r == 0, NULL, 0); |
|
200 |
BAIL_IF_MACRO(!readui32(fh, &entries->offset), NULL, 0); |
|
201 |
BAIL_IF_MACRO(!readui32(fh, &entries->size), NULL, 0); |
|
202 |
} /* for */ |
|
203 |
||
204 |
return(1); |
|
205 |
} /* qpak_loadEntries */ |
|
206 |
||
207 |
||
208 |
static QPAKdirentry *qpak_newDirentry(char *name, QPAKentry *entry) |
|
209 |
{ |
|
210 |
QPAKdirentry *retval = (QPAKdirentry *) malloc(sizeof (QPAKdirentry)); |
|
211 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, 0); |
|
212 |
||
213 |
retval->name = name; |
|
214 |
retval->entry = entry; |
|
215 |
retval->next = NULL; |
|
216 |
||
217 |
return(retval); |
|
218 |
} /* qpak_newDirentry */ |
|
219 |
||
220 |
||
221 |
static void qpak_deleteDirentry(QPAKdirentry *e) |
|
222 |
{ |
|
223 |
while (e != NULL) |
|
224 |
{ |
|
225 |
QPAKdirentry *next = e->next; |
|
226 |
free(e); |
|
227 |
e = next; |
|
228 |
} /* while */ |
|
229 |
} /* qpak_deleteDirentry */ |
|
230 |
||
231 |
||
232 |
static QPAKdirectory *qpak_newDirectory(char *name) |
|
233 |
{ |
|
234 |
QPAKdirectory *dir = (QPAKdirectory *) malloc(sizeof (QPAKdirectory)); |
|
235 |
BAIL_IF_MACRO(dir == NULL, ERR_OUT_OF_MEMORY, 0); |
|
236 |
||
237 |
strcpy(dir->name, name); |
|
238 |
dir->dirs = NULL; |
|
239 |
dir->next = NULL; |
|
240 |
dir->files = NULL; |
|
241 |
||
242 |
return dir; |
|
243 |
} /* qpak_newDirectory */ |
|
244 |
||
245 |
||
246 |
static void qpak_deleteDirectory(QPAKdirectory *d) |
|
247 |
{ |
|
248 |
while (d != NULL) |
|
249 |
{ |
|
250 |
QPAKdirectory *next = d->next; |
|
251 |
qpak_deleteDirentry(d->files); |
|
252 |
qpak_deleteDirectory(d->dirs); |
|
253 |
free(d); |
|
254 |
d = next; |
|
255 |
} /* while */ |
|
256 |
} /* qpak_deleteDirectory */ |
|
257 |
||
258 |
||
259 |
static int qpak_addFile(QPAKdirectory *dir, char *name, QPAKentry *entry) |
|
260 |
{ |
|
261 |
QPAKdirentry *file = qpak_newDirentry(name, entry); |
|
262 |
if (file == NULL) |
|
263 |
return(0); |
|
264 |
||
265 |
/* !!! FIXME: Traversing a linkedlist gets slower with each added file. */ |
|
266 |
if (dir->files == NULL) |
|
267 |
{ |
|
268 |
dir->files = file; |
|
269 |
} /* if */ |
|
270 |
else |
|
271 |
{ |
|
272 |
QPAKdirentry *tail = dir->files; |
|
273 |
while (tail->next != NULL) |
|
274 |
tail = tail->next; |
|
275 |
||
276 |
tail->next = file; |
|
277 |
} /* else */ |
|
278 |
||
279 |
return(1); |
|
280 |
} /* qpak_addFile */ |
|
281 |
||
282 |
||
283 |
static QPAKdirectory *qpak_findDirectory(QPAKdirectory *root, const char *name) |
|
284 |
{ |
|
285 |
char *p = strchr(name, '/'); |
|
286 |
||
287 |
if (p == NULL) |
|
288 |
{ |
|
289 |
QPAKdirectory *thisDir = root->dirs; |
|
290 |
while (thisDir != NULL) |
|
291 |
{ |
|
292 |
if (strcmp(thisDir->name, name) == 0) |
|
293 |
return(thisDir); |
|
294 |
thisDir = thisDir->next; |
|
295 |
} /* while */ |
|
296 |
} /* if */ |
|
297 |
||
298 |
else |
|
299 |
{ |
|
300 |
char temp[QPAK_MAXDIRLEN]; |
|
301 |
QPAKdirectory *thisDir = root->dirs; |
|
302 |
||
303 |
strncpy (temp, name, p - name); |
|
304 |
temp[p - name] = '\0'; |
|
305 |
||
306 |
while (thisDir != NULL) |
|
307 |
{ |
|
308 |
if (strcmp(thisDir->name, temp) == 0) |
|
309 |
return(qpak_findDirectory(thisDir, p + 1)); |
|
310 |
thisDir = thisDir->next; |
|
311 |
} /* while */ |
|
312 |
} /* else */ |
|
313 |
||
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
314 |
BAIL_MACRO(ERR_NO_SUCH_PATH, 0); |
450 | 315 |
} /* qpak_findDirectory */ |
316 |
||
317 |
||
318 |
static QPAKdirectory *qpak_addDir(QPAKdirectory *dir, char *name) |
|
319 |
{ |
|
320 |
QPAKdirectory *newDir = qpak_findDirectory(dir, name); |
|
321 |
if (newDir != 0) |
|
322 |
return(newDir); |
|
323 |
||
324 |
newDir = qpak_newDirectory(name); |
|
325 |
if (newDir == 0) |
|
326 |
return 0; |
|
327 |
||
328 |
if (dir->dirs == NULL) |
|
329 |
{ |
|
330 |
dir->dirs = newDir; |
|
331 |
} /* if */ |
|
332 |
||
333 |
else |
|
334 |
{ |
|
335 |
QPAKdirectory *tail = dir->dirs; |
|
336 |
while (tail->next != NULL) |
|
337 |
tail = tail->next; |
|
338 |
||
339 |
tail->next = newDir; |
|
340 |
} /* else */ |
|
341 |
||
342 |
return(newDir); |
|
343 |
} /* qpak_addDir */ |
|
344 |
||
345 |
||
346 |
static int qpak_addEntry(QPAKdirectory *dir, char *name, QPAKentry *entry) |
|
347 |
{ |
|
348 |
char tempName[QPAK_MAXDIRLEN]; |
|
349 |
QPAKdirectory *child; |
|
350 |
char *p = strchr(name, '/'); |
|
351 |
if (p == NULL) |
|
352 |
return(qpak_addFile(dir, name, entry)); |
|
353 |
||
354 |
strncpy(tempName, name, p - name); |
|
355 |
tempName[p - name] = '\0'; |
|
356 |
||
357 |
child = qpak_addDir(dir, tempName); |
|
358 |
return(qpak_addEntry(child, p + 1, entry)); |
|
359 |
} /* qpak_addEntry */ |
|
360 |
||
361 |
||
362 |
static QPAKentry *qpak_findEntry(QPAKdirectory *root, const char *name) |
|
363 |
{ |
|
364 |
QPAKdirectory *dir = NULL; |
|
365 |
QPAKdirentry *thisFile = NULL; |
|
366 |
const char *t = strrchr (name, '/'); |
|
367 |
||
368 |
if (t == NULL) |
|
369 |
{ |
|
370 |
dir = root; |
|
371 |
t = name; |
|
372 |
} /* if */ |
|
373 |
||
374 |
else |
|
375 |
{ |
|
376 |
char temp[QPAK_MAXDIRLEN]; |
|
377 |
strncpy(temp, name, t - name); |
|
378 |
temp[t - name] = '\0'; |
|
379 |
dir = qpak_findDirectory(root, temp); |
|
380 |
t++; |
|
381 |
} /* else */ |
|
382 |
||
383 |
if (dir == NULL) |
|
384 |
return(0); |
|
385 |
||
386 |
thisFile = dir->files; |
|
387 |
||
388 |
while (thisFile != NULL) |
|
389 |
{ |
|
390 |
if (strcmp(thisFile->name, t) == 0) |
|
391 |
return(thisFile->entry); |
|
392 |
||
393 |
thisFile = thisFile->next; |
|
394 |
} /* while */ |
|
395 |
||
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
396 |
BAIL_MACRO(ERR_NO_SUCH_FILE, 0); |
450 | 397 |
} /* qpak_findEntry */ |
398 |
||
399 |
||
400 |
static int qpak_populateDirectories(QPAKentry *entries, int numEntries, |
|
401 |
QPAKdirectory *root) |
|
402 |
{ |
|
494 | 403 |
PHYSFS_sint32 i; |
450 | 404 |
QPAKentry *entry = entries; |
405 |
||
406 |
for (i = 0; i < numEntries; i++, entry++) |
|
407 |
{ |
|
408 |
if (qpak_addEntry(root, entry->name, entry) == 0) |
|
409 |
return(0); |
|
410 |
} /* for */ |
|
411 |
||
412 |
return(1); |
|
413 |
} /* qpak_populateDirectories */ |
|
414 |
||
415 |
||
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
416 |
static void qpak_deletePakInfo(QPAKinfo *pakInfo) |
450 | 417 |
{ |
457 | 418 |
if (pakInfo->handle != NULL) |
419 |
__PHYSFS_platformClose(pakInfo->handle); |
|
420 |
||
450 | 421 |
if (pakInfo->filename != NULL) |
422 |
free(pakInfo->filename); |
|
423 |
||
424 |
if (pakInfo->entries != NULL) |
|
425 |
free(pakInfo->entries); |
|
426 |
||
427 |
qpak_deleteDirectory(pakInfo->root); |
|
428 |
||
429 |
free(pakInfo); |
|
430 |
} /* qpak_deletePakInfo */ |
|
431 |
||
432 |
||
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
433 |
static int qpak_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
434 |
{ |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
435 |
QPAKentry *a = (QPAKentry *) _a; |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
436 |
return(strcmp(a[one].name, a[two].name)); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
437 |
} /* qpak_entry_cmp */ |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
438 |
|
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
439 |
|
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
440 |
static void qpak_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
441 |
{ |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
442 |
QPAKentry tmp; |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
443 |
QPAKentry *first = &(((QPAKentry *) _a)[one]); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
444 |
QPAKentry *second = &(((QPAKentry *) _a)[two]); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
445 |
memcpy(&tmp, first, sizeof (QPAKentry)); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
446 |
memcpy(first, second, sizeof (QPAKentry)); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
447 |
memcpy(second, &tmp, sizeof (QPAKentry)); |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
448 |
} /* qpak_entry_swap */ |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
449 |
|
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
450 |
|
450 | 451 |
static DirHandle *QPAK_openArchive(const char *name, int forWriting) |
452 |
{ |
|
453 |
void *fh = NULL; |
|
454 |
PHYSFS_uint32 dirOffset, dirLength; |
|
455 |
QPAKinfo *pi; |
|
456 |
DirHandle *retval; |
|
457 |
||
458 |
retval = (DirHandle *) malloc(sizeof (DirHandle)); |
|
459 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
460 |
||
461 |
pi = (QPAKinfo *) malloc(sizeof (QPAKinfo)); |
|
462 |
if (pi == NULL) |
|
463 |
{ |
|
464 |
free(retval); |
|
465 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
|
466 |
} /* if */ |
|
467 |
||
468 |
retval->opaque = pi; |
|
469 |
||
470 |
pi->filename = (char *) malloc(strlen(name) + 1); |
|
471 |
if (pi->filename == NULL) |
|
472 |
{ |
|
473 |
__PHYSFS_setError(ERR_OUT_OF_MEMORY); |
|
474 |
goto QPAK_openArchive_failed; |
|
475 |
} /* if */ |
|
476 |
||
477 |
if (!openQPak(name, forWriting, &fh)) |
|
478 |
goto QPAK_openArchive_failed; |
|
479 |
||
480 |
if (!readui32(fh, &dirOffset)) |
|
481 |
goto QPAK_openArchive_failed; |
|
482 |
||
483 |
if (!readui32(fh, &dirLength)) |
|
484 |
goto QPAK_openArchive_failed; |
|
485 |
||
486 |
if (__PHYSFS_platformFileLength(fh) < dirOffset + dirLength) |
|
487 |
goto QPAK_openArchive_failed; |
|
488 |
||
489 |
strcpy(pi->filename, name); |
|
490 |
pi->handle = fh; |
|
491 |
pi->dirOffset = dirOffset; |
|
492 |
pi->totalEntries = dirLength / 64; |
|
493 |
||
494 |
pi->entries = (QPAKentry *) malloc(pi->totalEntries * sizeof (QPAKentry)); |
|
495 |
if (pi->entries == NULL) |
|
496 |
{ |
|
497 |
__PHYSFS_setError(ERR_OUT_OF_MEMORY); |
|
498 |
goto QPAK_openArchive_failed; |
|
499 |
} /* if */ |
|
500 |
||
501 |
if (qpak_loadEntries(fh, dirOffset, pi->totalEntries, pi->entries) == 0) |
|
502 |
goto QPAK_openArchive_failed; |
|
503 |
||
464
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
504 |
__PHYSFS_sort(pi->entries, pi->totalEntries, |
21c8e0d1578c
Generalized sorting routines, and removed individual implementations.
Ryan C. Gordon <icculus@icculus.org>
parents:
457
diff
changeset
|
505 |
qpak_entry_cmp, qpak_entry_swap); |
450 | 506 |
|
507 |
pi->root = qpak_newDirectory(""); |
|
508 |
if (pi->root == NULL) |
|
509 |
goto QPAK_openArchive_failed; |
|
510 |
||
511 |
if (qpak_populateDirectories(pi->entries, pi->totalEntries, pi->root) == 0) |
|
512 |
goto QPAK_openArchive_failed; |
|
513 |
||
514 |
retval->funcs = &__PHYSFS_DirFunctions_QPAK; |
|
515 |
return(retval); |
|
516 |
||
517 |
QPAK_openArchive_failed: |
|
518 |
if (retval != NULL) |
|
519 |
{ |
|
520 |
if (retval->opaque != NULL) |
|
521 |
qpak_deletePakInfo((QPAKinfo *) retval->opaque); |
|
522 |
||
523 |
free(retval); |
|
524 |
} /* if */ |
|
525 |
||
526 |
if (fh != NULL) |
|
527 |
__PHYSFS_platformClose(fh); |
|
528 |
||
529 |
return(0); |
|
530 |
} /* QPAK_openArchive */ |
|
531 |
||
532 |
||
533 |
static void QPAK_dirClose(DirHandle *dirHandle) |
|
534 |
{ |
|
457 | 535 |
qpak_deletePakInfo((QPAKinfo *) dirHandle->opaque); |
450 | 536 |
free(dirHandle); |
537 |
} /* QPAK_dirClose */ |
|
538 |
||
539 |
||
540 |
static LinkedStringList *QPAK_enumerateFiles(DirHandle *h, const char *dirname, |
|
541 |
int omitSymLinks) |
|
542 |
{ |
|
543 |
LinkedStringList *retval = NULL, *p = NULL; |
|
544 |
QPAKdirectory *dir; |
|
545 |
QPAKinfo *info = (QPAKinfo *) h->opaque; |
|
546 |
||
547 |
if ((dirname == NULL) || (*dirname == '\0')) |
|
548 |
dir = info->root; |
|
549 |
else |
|
550 |
dir = qpak_findDirectory(info->root, dirname); |
|
551 |
||
552 |
if (dir != NULL) |
|
553 |
{ |
|
554 |
QPAKdirectory *child = dir->dirs; |
|
555 |
QPAKdirentry *file = dir->files; |
|
556 |
||
557 |
while (child != NULL) |
|
558 |
{ |
|
559 |
retval = __PHYSFS_addToLinkedStringList(retval, &p, child->name, -1); |
|
560 |
child = child->next; |
|
561 |
} /* while */ |
|
562 |
||
563 |
while (file != NULL) |
|
564 |
{ |
|
565 |
retval = __PHYSFS_addToLinkedStringList(retval, &p, file->name, -1); |
|
566 |
file = file->next; |
|
567 |
} /* while */ |
|
568 |
} /* if */ |
|
569 |
||
570 |
return(retval); |
|
571 |
} /* QPAK_enumerateFiles */ |
|
572 |
||
573 |
||
574 |
static int QPAK_exists(DirHandle *h, const char *name) |
|
575 |
{ |
|
576 |
QPAKinfo *driver = (QPAKinfo *) h->opaque; |
|
577 |
||
578 |
if ((name == NULL) || (*name == '\0')) |
|
579 |
return(0); |
|
580 |
||
581 |
if (qpak_findDirectory(driver->root, name) != 0) |
|
582 |
return(1); |
|
583 |
||
584 |
if (qpak_findEntry(driver->root, name) != 0) |
|
585 |
return(1); |
|
586 |
||
587 |
return(0); |
|
588 |
} /* QPAK_exists */ |
|
589 |
||
590 |
||
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
591 |
static int QPAK_isDirectory(DirHandle *h, const char *name, int *fileExists) |
450 | 592 |
{ |
593 |
QPAKinfo *info = (QPAKinfo *) h->opaque; |
|
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
594 |
*fileExists = (qpak_findDirectory(info->root, name) != 0); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
595 |
return(*fileExists); |
450 | 596 |
} /* QPAK_isDirectory */ |
597 |
||
598 |
||
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
599 |
static int QPAK_isSymLink(DirHandle *h, const char *name, int *fileExists) |
450 | 600 |
{ |
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
601 |
*fileExists = QPAK_exists(h, name); |
450 | 602 |
return(0); /* we don't support symlinks for now */ |
603 |
} /* QPAK_isSymlink */ |
|
604 |
||
605 |
||
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
606 |
static int QPAK_remove(DirHandle *h, const char *name) |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
607 |
{ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
608 |
BAIL_MACRO(ERR_NOT_SUPPORTED, 0); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
609 |
} /* QPAK_remove */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
610 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
611 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
612 |
static int QPAK_mkdir(DirHandle *h, const char *name) |
450 | 613 |
{ |
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
614 |
BAIL_MACRO(ERR_NOT_SUPPORTED, 0); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
615 |
} /* QPAK_mkdir */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
616 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
617 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
618 |
static PHYSFS_sint64 QPAK_getLastModTime(DirHandle *h, |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
619 |
const char *name, |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
620 |
int *fileExists) |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
621 |
{ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
622 |
QPAKinfo *info = (QPAKinfo *) h->opaque; |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
623 |
PHYSFS_sint64 retval = -1; |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
624 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
625 |
*fileExists = QPAK_exists(h, name); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
626 |
if (*fileExists) |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
627 |
retval = __PHYSFS_platformGetLastModTime(info->filename); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
628 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
629 |
return(retval); |
450 | 630 |
} /* QPAK_getLastModTime */ |
631 |
||
632 |
||
633 |
static void *qpak_getFileHandle(const char *name, QPAKentry *entry) |
|
634 |
{ |
|
635 |
void *retval = __PHYSFS_platformOpenRead(name); |
|
636 |
if (retval == NULL) |
|
637 |
return(NULL); |
|
638 |
||
639 |
if (!__PHYSFS_platformSeek(retval, entry->offset)) |
|
640 |
{ |
|
641 |
__PHYSFS_platformClose(retval); |
|
642 |
return(NULL); |
|
643 |
} /* if */ |
|
644 |
||
645 |
return(retval); |
|
646 |
} /* qpak_getFileHandle */ |
|
647 |
||
648 |
||
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
649 |
static FileHandle *QPAK_openRead(DirHandle *h, const char *fnm, int *fileExists) |
450 | 650 |
{ |
651 |
QPAKinfo *driver = (QPAKinfo *) h->opaque; |
|
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
652 |
QPAKentry *entry = qpak_findEntry(driver->root, fnm); |
450 | 653 |
QPAKfileinfo *fileDriver = 0; |
654 |
FileHandle *result = 0; |
|
655 |
||
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
656 |
*fileExists = (entry != NULL); |
450 | 657 |
if (entry == NULL) |
658 |
return(NULL); |
|
659 |
||
660 |
fileDriver = (QPAKfileinfo *) malloc(sizeof (QPAKfileinfo)); |
|
661 |
BAIL_IF_MACRO(fileDriver == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
662 |
||
663 |
fileDriver->handle = qpak_getFileHandle(driver->filename, entry); |
|
664 |
if (fileDriver->handle == NULL) |
|
665 |
{ |
|
666 |
free(fileDriver); |
|
667 |
return(NULL); |
|
668 |
} /* if */ |
|
669 |
||
670 |
fileDriver->entry = entry; |
|
671 |
fileDriver->curPos = 0; |
|
672 |
||
673 |
result = (FileHandle *)malloc(sizeof (FileHandle)); |
|
674 |
if (result == NULL) |
|
675 |
{ |
|
676 |
__PHYSFS_platformClose(fileDriver->handle); |
|
677 |
free(fileDriver); |
|
678 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
|
679 |
} /* if */ |
|
680 |
||
681 |
result->opaque = fileDriver; |
|
682 |
result->dirHandle = h; |
|
683 |
result->funcs = &__PHYSFS_FileFunctions_QPAK; |
|
684 |
return(result); |
|
685 |
} /* QPAK_openRead */ |
|
686 |
||
687 |
||
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
688 |
static FileHandle *QPAK_openWrite(DirHandle *h, const char *name) |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
689 |
{ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
690 |
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
691 |
} /* QPAK_openWrite */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
692 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
693 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
694 |
static FileHandle *QPAK_openAppend(DirHandle *h, const char *name) |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
695 |
{ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
696 |
BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
697 |
} /* QPAK_openAppend */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
698 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
699 |
|
450 | 700 |
static PHYSFS_sint64 QPAK_read(FileHandle *handle, void *buffer, |
701 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) |
|
702 |
{ |
|
703 |
QPAKfileinfo *finfo = (QPAKfileinfo *) (handle->opaque); |
|
704 |
QPAKentry *entry = finfo->entry; |
|
705 |
PHYSFS_uint64 bytesLeft = entry->size - finfo->curPos; |
|
706 |
PHYSFS_uint64 objsLeft = (bytesLeft / objSize); |
|
707 |
PHYSFS_sint64 rc; |
|
708 |
||
709 |
if (objsLeft < objCount) |
|
710 |
objCount = (PHYSFS_uint32) objsLeft; |
|
711 |
||
712 |
rc = __PHYSFS_platformRead(finfo->handle, buffer, objSize, objCount); |
|
713 |
if (rc > 0) |
|
714 |
finfo->curPos += (rc * objSize); |
|
715 |
||
716 |
return(rc); |
|
717 |
} /* QPAK_read */ |
|
718 |
||
719 |
||
467
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
720 |
static PHYSFS_sint64 QPAK_write(FileHandle *handle, const void *buffer, |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
721 |
PHYSFS_uint32 objSize, PHYSFS_uint32 objCount) |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
722 |
{ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
723 |
BAIL_MACRO(ERR_NOT_SUPPORTED, -1); |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
724 |
} /* QPAK_write */ |
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
725 |
|
99664d9842cb
Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
464
diff
changeset
|
726 |
|
450 | 727 |
static int QPAK_eof(FileHandle *handle) |
728 |
{ |
|
729 |
QPAKfileinfo *finfo = (QPAKfileinfo *) (handle->opaque); |
|
730 |
QPAKentry *entry = finfo->entry; |
|
731 |
||
732 |
return(finfo->curPos >= (PHYSFS_sint64) entry->size); |
|
733 |
} /* QPAK_eof */ |
|
734 |
||
735 |
||
736 |
static PHYSFS_sint64 QPAK_tell(FileHandle *handle) |
|
737 |
{ |
|
738 |
return(((QPAKfileinfo *) handle->opaque)->curPos); |
|
739 |
} /* QPAK_tell */ |
|
740 |
||
741 |
||
742 |
static int QPAK_seek(FileHandle *handle, PHYSFS_uint64 offset) |
|
743 |
{ |
|
744 |
QPAKfileinfo *finfo = (QPAKfileinfo *) handle->opaque; |
|
745 |
QPAKentry *entry = finfo->entry; |
|
746 |
PHYSFS_uint64 newPos = entry->offset + offset; |
|
747 |
int rc; |
|
748 |
||
749 |
BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0); |
|
750 |
BAIL_IF_MACRO(newPos > entry->offset + entry->size, ERR_PAST_EOF, 0); |
|
751 |
rc = __PHYSFS_platformSeek(finfo->handle, newPos); |
|
752 |
if (rc) |
|
753 |
finfo->curPos = offset; |
|
754 |
||
755 |
return(rc); |
|
756 |
} /* QPAK_seek */ |
|
757 |
||
758 |
||
759 |
static PHYSFS_sint64 QPAK_fileLength(FileHandle *handle) |
|
760 |
{ |
|
761 |
return ((QPAKfileinfo *) handle->opaque)->entry->size; |
|
762 |
} /* QPAK_fileLength */ |
|
763 |
||
764 |
||
765 |
static int QPAK_fileClose(FileHandle *handle) |
|
766 |
{ |
|
767 |
QPAKfileinfo *finfo = (QPAKfileinfo *) handle->opaque; |
|
768 |
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0); |
|
769 |
free(finfo); |
|
770 |
free(handle); |
|
771 |
return(1); |
|
772 |
} /* QPAK_fileClose */ |
|
773 |
||
774 |
#endif /* defined PHYSFS_SUPPORTS_QPAK */ |
|
775 |
||
776 |
/* end of qpak.c ... */ |
|
777 |
||
778 |