qpak.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * QPAK support routines for PhysicsFS.
  3. *
  4. * This archiver handles the archive format utilized by Quake 1 and 2.
  5. * Quake3-based games use the PkZip/Info-Zip format (which our zip.c
  6. * archiver handles).
  7. *
  8. * ========================================================================
  9. *
  10. * This format info (in more detail) comes from:
  11. * http://debian.fmi.uni-sofia.bg/~sergei/cgsr/docs/pak.txt
  12. *
  13. * Quake PAK Format
  14. *
  15. * Header
  16. * (4 bytes) signature = 'PACK'
  17. * (4 bytes) directory offset
  18. * (4 bytes) directory length
  19. *
  20. * Directory
  21. * (56 bytes) file name
  22. * (4 bytes) file position
  23. * (4 bytes) file length
  24. *
  25. * ========================================================================
  26. *
  27. * Please see the file LICENSE in the source's root directory.
  28. *
  29. * This file written by Ryan C. Gordon.
  30. */
  31. #if HAVE_CONFIG_H
  32. # include <config.h>
  33. #endif
  34. #if (defined PHYSFS_SUPPORTS_QPAK)
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include "physfs.h"
  39. #define __PHYSICSFS_INTERNAL__
  40. #include "physfs_internal.h"
  41. typedef struct
  42. {
  43. char name[56];
  44. PHYSFS_uint32 startPos;
  45. PHYSFS_uint32 size;
  46. } QPAKentry;
  47. typedef struct
  48. {
  49. char *filename;
  50. PHYSFS_sint64 last_mod_time;
  51. PHYSFS_uint32 entryCount;
  52. QPAKentry *entries;
  53. } QPAKinfo;
  54. typedef struct
  55. {
  56. void *handle;
  57. QPAKentry *entry;
  58. PHYSFS_uint32 curPos;
  59. } QPAKfileinfo;
  60. /* Magic numbers... */
  61. #define QPAK_SIGNATURE 0x4b434150 /* "PACK" in ASCII. */
  62. static void QPAK_dirClose(DirHandle *h);
  63. static PHYSFS_sint64 QPAK_read(FileHandle *handle, void *buffer,
  64. PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
  65. static PHYSFS_sint64 QPAK_write(FileHandle *handle, const void *buffer,
  66. PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
  67. static int QPAK_eof(FileHandle *handle);
  68. static PHYSFS_sint64 QPAK_tell(FileHandle *handle);
  69. static int QPAK_seek(FileHandle *handle, PHYSFS_uint64 offset);
  70. static PHYSFS_sint64 QPAK_fileLength(FileHandle *handle);
  71. static int QPAK_fileClose(FileHandle *handle);
  72. static int QPAK_isArchive(const char *filename, int forWriting);
  73. static DirHandle *QPAK_openArchive(const char *name, int forWriting);
  74. static LinkedStringList *QPAK_enumerateFiles(DirHandle *h,
  75. const char *dirname,
  76. int omitSymLinks);
  77. static int QPAK_exists(DirHandle *h, const char *name);
  78. static int QPAK_isDirectory(DirHandle *h, const char *name, int *fileExists);
  79. static int QPAK_isSymLink(DirHandle *h, const char *name, int *fileExists);
  80. static PHYSFS_sint64 QPAK_getLastModTime(DirHandle *h, const char *n, int *e);
  81. static FileHandle *QPAK_openRead(DirHandle *h, const char *name, int *exist);
  82. static FileHandle *QPAK_openWrite(DirHandle *h, const char *name);
  83. static FileHandle *QPAK_openAppend(DirHandle *h, const char *name);
  84. static int QPAK_remove(DirHandle *h, const char *name);
  85. static int QPAK_mkdir(DirHandle *h, const char *name);
  86. const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_QPAK =
  87. {
  88. "PAK",
  89. QPAK_ARCHIVE_DESCRIPTION,
  90. "Ryan C. Gordon <icculus@clutteredmind.org>",
  91. "http://icculus.org/physfs/",
  92. };
  93. static const FileFunctions __PHYSFS_FileFunctions_QPAK =
  94. {
  95. QPAK_read, /* read() method */
  96. QPAK_write, /* write() method */
  97. QPAK_eof, /* eof() method */
  98. QPAK_tell, /* tell() method */
  99. QPAK_seek, /* seek() method */
  100. QPAK_fileLength, /* fileLength() method */
  101. QPAK_fileClose /* fileClose() method */
  102. };
  103. const DirFunctions __PHYSFS_DirFunctions_QPAK =
  104. {
  105. &__PHYSFS_ArchiveInfo_QPAK,
  106. QPAK_isArchive, /* isArchive() method */
  107. QPAK_openArchive, /* openArchive() method */
  108. QPAK_enumerateFiles, /* enumerateFiles() method */
  109. QPAK_exists, /* exists() method */
  110. QPAK_isDirectory, /* isDirectory() method */
  111. QPAK_isSymLink, /* isSymLink() method */
  112. QPAK_getLastModTime, /* getLastModTime() method */
  113. QPAK_openRead, /* openRead() method */
  114. QPAK_openWrite, /* openWrite() method */
  115. QPAK_openAppend, /* openAppend() method */
  116. QPAK_remove, /* remove() method */
  117. QPAK_mkdir, /* mkdir() method */
  118. QPAK_dirClose /* dirClose() method */
  119. };
  120. static void QPAK_dirClose(DirHandle *h)
  121. {
  122. QPAKinfo *info = ((QPAKinfo *) h->opaque);
  123. free(info->filename);
  124. free(info->entries);
  125. free(info);
  126. free(h);
  127. } /* QPAK_dirClose */
  128. static PHYSFS_sint64 QPAK_read(FileHandle *handle, void *buffer,
  129. PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  130. {
  131. QPAKfileinfo *finfo = (QPAKfileinfo *) (handle->opaque);
  132. QPAKentry *entry = finfo->entry;
  133. PHYSFS_uint32 bytesLeft = entry->size - finfo->curPos;
  134. PHYSFS_uint32 objsLeft = (bytesLeft / objSize);
  135. PHYSFS_sint64 rc;
  136. if (objsLeft < objCount)
  137. objCount = objsLeft;
  138. rc = __PHYSFS_platformRead(finfo->handle, buffer, objSize, objCount);
  139. if (rc > 0)
  140. finfo->curPos += (PHYSFS_uint32) (rc * objSize);
  141. return(rc);
  142. } /* QPAK_read */
  143. static PHYSFS_sint64 QPAK_write(FileHandle *handle, const void *buffer,
  144. PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  145. {
  146. BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
  147. } /* QPAK_write */
  148. static int QPAK_eof(FileHandle *handle)
  149. {
  150. QPAKfileinfo *finfo = (QPAKfileinfo *) (handle->opaque);
  151. QPAKentry *entry = finfo->entry;
  152. return(finfo->curPos >= entry->size);
  153. } /* QPAK_eof */
  154. static PHYSFS_sint64 QPAK_tell(FileHandle *handle)
  155. {
  156. return(((QPAKfileinfo *) (handle->opaque))->curPos);
  157. } /* QPAK_tell */
  158. static int QPAK_seek(FileHandle *handle, PHYSFS_uint64 offset)
  159. {
  160. QPAKfileinfo *finfo = (QPAKfileinfo *) (handle->opaque);
  161. QPAKentry *entry = finfo->entry;
  162. int rc;
  163. BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0);
  164. BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0);
  165. rc = __PHYSFS_platformSeek(finfo->handle, entry->startPos + offset);
  166. if (rc)
  167. finfo->curPos = (PHYSFS_uint32) offset;
  168. return(rc);
  169. } /* QPAK_seek */
  170. static PHYSFS_sint64 QPAK_fileLength(FileHandle *handle)
  171. {
  172. QPAKfileinfo *finfo = ((QPAKfileinfo *) handle->opaque);
  173. return((PHYSFS_sint64) finfo->entry->size);
  174. } /* QPAK_fileLength */
  175. static int QPAK_fileClose(FileHandle *handle)
  176. {
  177. QPAKfileinfo *finfo = ((QPAKfileinfo *) handle->opaque);
  178. BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
  179. free(finfo);
  180. free(handle);
  181. return(1);
  182. } /* QPAK_fileClose */
  183. static int qpak_open(const char *filename, int forWriting,
  184. void **fh, PHYSFS_uint32 *count)
  185. {
  186. PHYSFS_uint32 buf;
  187. *fh = NULL;
  188. BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
  189. *fh = __PHYSFS_platformOpenRead(filename);
  190. BAIL_IF_MACRO(*fh == NULL, NULL, 0);
  191. if (__PHYSFS_platformRead(*fh, &buf, sizeof (PHYSFS_uint32), 1) != 1)
  192. goto openQpak_failed;
  193. buf = PHYSFS_swapULE32(buf);
  194. if (buf != QPAK_SIGNATURE)
  195. {
  196. __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
  197. goto openQpak_failed;
  198. } /* if */
  199. if (__PHYSFS_platformRead(*fh, &buf, sizeof (PHYSFS_uint32), 1) != 1)
  200. goto openQpak_failed;
  201. buf = PHYSFS_swapULE32(buf); /* directory table offset. */
  202. if (__PHYSFS_platformRead(*fh, count, sizeof (PHYSFS_uint32), 1) != 1)
  203. goto openQpak_failed;
  204. *count = PHYSFS_swapULE32(*count);
  205. if ((*count % 64) != 0) /* corrupted archive? */
  206. {
  207. __PHYSFS_setError(ERR_CORRUPTED);
  208. goto openQpak_failed;
  209. } /* if */
  210. if (!__PHYSFS_platformSeek(*fh, buf))
  211. goto openQpak_failed;
  212. *count /= 64;
  213. return(1);
  214. openQpak_failed:
  215. if (*fh != NULL)
  216. __PHYSFS_platformClose(*fh);
  217. *count = -1;
  218. *fh = NULL;
  219. return(0);
  220. } /* qpak_open */
  221. static int QPAK_isArchive(const char *filename, int forWriting)
  222. {
  223. void *fh;
  224. PHYSFS_uint32 fileCount;
  225. int retval = qpak_open(filename, forWriting, &fh, &fileCount);
  226. if (fh != NULL)
  227. __PHYSFS_platformClose(fh);
  228. return(retval);
  229. } /* QPAK_isArchive */
  230. static int qpak_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
  231. {
  232. QPAKentry *a = (QPAKentry *) _a;
  233. return(strcmp(a[one].name, a[two].name));
  234. } /* qpak_entry_cmp */
  235. static void qpak_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
  236. {
  237. QPAKentry tmp;
  238. QPAKentry *first = &(((QPAKentry *) _a)[one]);
  239. QPAKentry *second = &(((QPAKentry *) _a)[two]);
  240. memcpy(&tmp, first, sizeof (QPAKentry));
  241. memcpy(first, second, sizeof (QPAKentry));
  242. memcpy(second, &tmp, sizeof (QPAKentry));
  243. } /* qpak_entry_swap */
  244. static int qpak_load_entries(const char *name, int forWriting, QPAKinfo *info)
  245. {
  246. void *fh = NULL;
  247. PHYSFS_uint32 fileCount;
  248. QPAKentry *entry;
  249. BAIL_IF_MACRO(!qpak_open(name, forWriting, &fh, &fileCount), NULL, 0);
  250. info->entryCount = fileCount;
  251. info->entries = (QPAKentry *) malloc(sizeof (QPAKentry) * fileCount);
  252. if (info->entries == NULL)
  253. {
  254. __PHYSFS_platformClose(fh);
  255. BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
  256. } /* if */
  257. for (entry = info->entries; fileCount > 0; fileCount--, entry++)
  258. {
  259. PHYSFS_uint32 loc;
  260. if (__PHYSFS_platformRead(fh,&entry->name,sizeof(entry->name),1) != 1)
  261. {
  262. __PHYSFS_platformClose(fh);
  263. return(0);
  264. } /* if */
  265. if (__PHYSFS_platformRead(fh,&loc,sizeof(loc),1) != 1)
  266. {
  267. __PHYSFS_platformClose(fh);
  268. return(0);
  269. } /* if */
  270. if (__PHYSFS_platformRead(fh,&entry->size,sizeof(entry->size),1) != 1)
  271. {
  272. __PHYSFS_platformClose(fh);
  273. return(0);
  274. } /* if */
  275. entry->size = PHYSFS_swapULE32(entry->size);
  276. entry->startPos = PHYSFS_swapULE32(loc);
  277. } /* for */
  278. __PHYSFS_platformClose(fh);
  279. __PHYSFS_sort(info->entries, info->entryCount,
  280. qpak_entry_cmp, qpak_entry_swap);
  281. return(1);
  282. } /* qpak_load_entries */
  283. static DirHandle *QPAK_openArchive(const char *name, int forWriting)
  284. {
  285. QPAKinfo *info;
  286. DirHandle *retval = malloc(sizeof (DirHandle));
  287. PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
  288. BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
  289. info = retval->opaque = malloc(sizeof (QPAKinfo));
  290. if (info == NULL)
  291. {
  292. __PHYSFS_setError(ERR_OUT_OF_MEMORY);
  293. goto QPAK_openArchive_failed;
  294. } /* if */
  295. memset(info, '\0', sizeof (QPAKinfo));
  296. info->filename = (char *) malloc(strlen(name) + 1);
  297. if (info->filename == NULL)
  298. {
  299. __PHYSFS_setError(ERR_OUT_OF_MEMORY);
  300. goto QPAK_openArchive_failed;
  301. } /* if */
  302. if (!qpak_load_entries(name, forWriting, info))
  303. goto QPAK_openArchive_failed;
  304. strcpy(info->filename, name);
  305. info->last_mod_time = modtime;
  306. retval->funcs = &__PHYSFS_DirFunctions_QPAK;
  307. return(retval);
  308. QPAK_openArchive_failed:
  309. if (retval != NULL)
  310. {
  311. if (retval->opaque != NULL)
  312. {
  313. if (info->filename != NULL)
  314. free(info->filename);
  315. if (info->entries != NULL)
  316. free(info->entries);
  317. free(info);
  318. } /* if */
  319. free(retval);
  320. } /* if */
  321. return(NULL);
  322. } /* QPAK_openArchive */
  323. static PHYSFS_sint32 qpak_find_start_of_dir(QPAKinfo *info, const char *path,
  324. int stop_on_first_find)
  325. {
  326. PHYSFS_sint32 lo = 0;
  327. PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1);
  328. PHYSFS_sint32 middle;
  329. PHYSFS_uint32 dlen = strlen(path);
  330. PHYSFS_sint32 retval = -1;
  331. const char *name;
  332. int rc;
  333. if (*path == '\0') /* root dir? */
  334. return(0);
  335. if ((dlen > 0) && (path[dlen - 1] == '/')) /* ignore trailing slash. */
  336. dlen--;
  337. while (lo <= hi)
  338. {
  339. middle = lo + ((hi - lo) / 2);
  340. name = info->entries[middle].name;
  341. rc = strncmp(path, name, dlen);
  342. if (rc == 0)
  343. {
  344. char ch = name[dlen];
  345. if (ch < '/') /* make sure this isn't just a substr match. */
  346. rc = -1;
  347. else if (ch > '/')
  348. rc = 1;
  349. else
  350. {
  351. if (stop_on_first_find) /* Just checking dir's existance? */
  352. return(middle);
  353. if (name[dlen + 1] == '\0') /* Skip initial dir entry. */
  354. return(middle + 1);
  355. /* there might be more entries earlier in the list. */
  356. retval = middle;
  357. hi = middle - 1;
  358. } /* else */
  359. } /* if */
  360. if (rc > 0)
  361. lo = middle + 1;
  362. else
  363. hi = middle - 1;
  364. } /* while */
  365. return(retval);
  366. } /* qpak_find_start_of_dir */
  367. static LinkedStringList *QPAK_enumerateFiles(DirHandle *h,
  368. const char *dirname,
  369. int omitSymLinks)
  370. {
  371. QPAKinfo *info = ((QPAKinfo *) h->opaque);
  372. LinkedStringList *retval = NULL, *p = NULL;
  373. PHYSFS_sint32 dlen, dlen_inc, max, i;
  374. i = qpak_find_start_of_dir(info, dirname, 0);
  375. BAIL_IF_MACRO(i == -1, ERR_NO_SUCH_FILE, NULL);
  376. dlen = strlen(dirname);
  377. if ((dlen > 0) && (dirname[dlen - 1] == '/')) /* ignore trailing slash. */
  378. dlen--;
  379. dlen_inc = ((dlen > 0) ? 1 : 0) + dlen;
  380. max = (PHYSFS_sint32) info->entryCount;
  381. while (i < max)
  382. {
  383. char *add;
  384. char *ptr;
  385. PHYSFS_sint32 ln;
  386. char *e = info->entries[i].name;
  387. if ((dlen) && ((strncmp(e, dirname, dlen) != 0) || (e[dlen] != '/')))
  388. break; /* past end of this dir; we're done. */
  389. add = e + dlen_inc;
  390. ptr = strchr(add, '/');
  391. ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add));
  392. retval = __PHYSFS_addToLinkedStringList(retval, &p, add, ln);
  393. ln += dlen_inc; /* point past entry to children... */
  394. /* increment counter and skip children of subdirs... */
  395. while ((++i < max) && (ptr != NULL))
  396. {
  397. char *e_new = info->entries[i].name;
  398. if ((strncmp(e, e_new, ln) != 0) || (e_new[ln] != '/'))
  399. break;
  400. } /* while */
  401. } /* while */
  402. return(retval);
  403. } /* QPAK_enumerateFiles */
  404. /*
  405. * This will find the QPAKentry associated with a path in platform-independent
  406. * notation. Directories don't have QPAKentries associated with them, but
  407. * (*isDir) will be set to non-zero if a dir was hit.
  408. */
  409. static QPAKentry *qpak_find_entry(QPAKinfo *info, const char *path, int *isDir)
  410. {
  411. QPAKentry *a = info->entries;
  412. PHYSFS_sint32 pathlen = strlen(path);
  413. PHYSFS_sint32 lo = 0;
  414. PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1);
  415. PHYSFS_sint32 middle;
  416. const char *thispath = NULL;
  417. int rc;
  418. while (lo <= hi)
  419. {
  420. middle = lo + ((hi - lo) / 2);
  421. thispath = a[middle].name;
  422. rc = strncmp(path, thispath, pathlen);
  423. if (rc > 0)
  424. lo = middle + 1;
  425. else if (rc < 0)
  426. hi = middle - 1;
  427. else /* substring match...might be dir or entry or nothing. */
  428. {
  429. if (isDir != NULL)
  430. {
  431. *isDir = (thispath[pathlen] == '/');
  432. if (*isDir)
  433. return(NULL);
  434. } /* if */
  435. if (thispath[pathlen] == '\0') /* found entry? */
  436. return(&a[middle]);
  437. else
  438. hi = middle - 1; /* adjust search params, try again. */
  439. } /* if */
  440. } /* while */
  441. if (isDir != NULL)
  442. *isDir = 0;
  443. BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
  444. } /* qpak_find_entry */
  445. static int QPAK_exists(DirHandle *h, const char *name)
  446. {
  447. int isDir;
  448. QPAKinfo *info = (QPAKinfo *) h->opaque;
  449. QPAKentry *entry = qpak_find_entry(info, name, &isDir);
  450. return((entry != NULL) || (isDir));
  451. } /* QPAK_exists */
  452. static int QPAK_isDirectory(DirHandle *h, const char *name, int *fileExists)
  453. {
  454. QPAKinfo *info = (QPAKinfo *) h->opaque;
  455. int isDir;
  456. QPAKentry *entry = qpak_find_entry(info, name, &isDir);
  457. *fileExists = ((isDir) || (entry != NULL));
  458. if (isDir)
  459. return(1); /* definitely a dir. */
  460. BAIL_MACRO(ERR_NO_SUCH_FILE, 0);
  461. } /* QPAK_isDirectory */
  462. static int QPAK_isSymLink(DirHandle *h, const char *name, int *fileExists)
  463. {
  464. *fileExists = QPAK_exists(h, name);
  465. return(0); /* never symlinks in a quake pak. */
  466. } /* QPAK_isSymLink */
  467. static PHYSFS_sint64 QPAK_getLastModTime(DirHandle *h,
  468. const char *name,
  469. int *fileExists)
  470. {
  471. int isDir;
  472. QPAKinfo *info = ((QPAKinfo *) h->opaque);
  473. PHYSFS_sint64 retval = -1;
  474. QPAKentry *entry = qpak_find_entry(info, name, &isDir);
  475. *fileExists = ((isDir) || (entry != NULL));
  476. if (*fileExists) /* use time of QPAK itself in the physical filesystem. */
  477. retval = info->last_mod_time;
  478. return(retval);
  479. } /* QPAK_getLastModTime */
  480. static FileHandle *QPAK_openRead(DirHandle *h, const char *fnm, int *fileExists)
  481. {
  482. QPAKinfo *info = ((QPAKinfo *) h->opaque);
  483. FileHandle *retval;
  484. QPAKfileinfo *finfo;
  485. QPAKentry *entry;
  486. int isDir;
  487. entry = qpak_find_entry(info, fnm, &isDir);
  488. *fileExists = ((entry != NULL) || (isDir));
  489. BAIL_IF_MACRO(isDir, ERR_NOT_A_FILE, NULL);
  490. BAIL_IF_MACRO(entry == NULL, ERR_NO_SUCH_FILE, NULL);
  491. retval = (FileHandle *) malloc(sizeof (FileHandle));
  492. BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
  493. finfo = (QPAKfileinfo *) malloc(sizeof (QPAKfileinfo));
  494. if (finfo == NULL)
  495. {
  496. free(retval);
  497. BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
  498. } /* if */
  499. finfo->handle = __PHYSFS_platformOpenRead(info->filename);
  500. if ( (finfo->handle == NULL) ||
  501. (!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
  502. {
  503. free(finfo);
  504. free(retval);
  505. return(NULL);
  506. } /* if */
  507. finfo->curPos = 0;
  508. finfo->entry = entry;
  509. retval->opaque = (void *) finfo;
  510. retval->funcs = &__PHYSFS_FileFunctions_QPAK;
  511. retval->dirHandle = h;
  512. return(retval);
  513. } /* QPAK_openRead */
  514. static FileHandle *QPAK_openWrite(DirHandle *h, const char *name)
  515. {
  516. BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
  517. } /* QPAK_openWrite */
  518. static FileHandle *QPAK_openAppend(DirHandle *h, const char *name)
  519. {
  520. BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
  521. } /* QPAK_openAppend */
  522. static int QPAK_remove(DirHandle *h, const char *name)
  523. {
  524. BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
  525. } /* QPAK_remove */
  526. static int QPAK_mkdir(DirHandle *h, const char *name)
  527. {
  528. BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
  529. } /* QPAK_mkdir */
  530. #endif /* defined PHYSFS_SUPPORTS_QPAK */
  531. /* end of qpak.c ... */