qpak.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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. char *ptr;
  250. BAIL_IF_MACRO(!qpak_open(name, forWriting, &fh, &fileCount), NULL, 0);
  251. info->entryCount = fileCount;
  252. info->entries = (QPAKentry *) malloc(sizeof (QPAKentry) * fileCount);
  253. if (info->entries == NULL)
  254. {
  255. __PHYSFS_platformClose(fh);
  256. BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
  257. } /* if */
  258. for (entry = info->entries; fileCount > 0; fileCount--, entry++)
  259. {
  260. PHYSFS_uint32 loc;
  261. if (__PHYSFS_platformRead(fh,&entry->name,sizeof(entry->name),1) != 1)
  262. {
  263. __PHYSFS_platformClose(fh);
  264. return(0);
  265. } /* if */
  266. if (__PHYSFS_platformRead(fh,&loc,sizeof(loc),1) != 1)
  267. {
  268. __PHYSFS_platformClose(fh);
  269. return(0);
  270. } /* if */
  271. if (__PHYSFS_platformRead(fh,&entry->size,sizeof(entry->size),1) != 1)
  272. {
  273. __PHYSFS_platformClose(fh);
  274. return(0);
  275. } /* if */
  276. entry->size = PHYSFS_swapULE32(entry->size);
  277. entry->startPos = PHYSFS_swapULE32(loc);
  278. } /* for */
  279. __PHYSFS_platformClose(fh);
  280. __PHYSFS_sort(info->entries, info->entryCount,
  281. qpak_entry_cmp, qpak_entry_swap);
  282. return(1);
  283. } /* qpak_load_entries */
  284. static DirHandle *QPAK_openArchive(const char *name, int forWriting)
  285. {
  286. QPAKinfo *info;
  287. DirHandle *retval = malloc(sizeof (DirHandle));
  288. PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
  289. BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
  290. info = retval->opaque = malloc(sizeof (QPAKinfo));
  291. if (info == NULL)
  292. {
  293. __PHYSFS_setError(ERR_OUT_OF_MEMORY);
  294. goto QPAK_openArchive_failed;
  295. } /* if */
  296. memset(info, '\0', sizeof (QPAKinfo));
  297. info->filename = (char *) malloc(strlen(name) + 1);
  298. if (info->filename == NULL)
  299. {
  300. __PHYSFS_setError(ERR_OUT_OF_MEMORY);
  301. goto QPAK_openArchive_failed;
  302. } /* if */
  303. if (!qpak_load_entries(name, forWriting, info))
  304. goto QPAK_openArchive_failed;
  305. strcpy(info->filename, name);
  306. info->last_mod_time = modtime;
  307. retval->funcs = &__PHYSFS_DirFunctions_QPAK;
  308. return(retval);
  309. QPAK_openArchive_failed:
  310. if (retval != NULL)
  311. {
  312. if (retval->opaque != NULL)
  313. {
  314. if (info->filename != NULL)
  315. free(info->filename);
  316. if (info->entries != NULL)
  317. free(info->entries);
  318. free(info);
  319. } /* if */
  320. free(retval);
  321. } /* if */
  322. return(NULL);
  323. } /* QPAK_openArchive */
  324. static PHYSFS_sint32 qpak_find_start_of_dir(QPAKinfo *info, const char *path,
  325. int stop_on_first_find)
  326. {
  327. PHYSFS_sint32 lo = 0;
  328. PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1);
  329. PHYSFS_sint32 middle;
  330. PHYSFS_uint32 dlen = strlen(path);
  331. PHYSFS_sint32 retval = -1;
  332. const char *name;
  333. int rc;
  334. if (*path == '\0') /* root dir? */
  335. return(0);
  336. if ((dlen > 0) && (path[dlen - 1] == '/')) /* ignore trailing slash. */
  337. dlen--;
  338. while (lo <= hi)
  339. {
  340. middle = lo + ((hi - lo) / 2);
  341. name = info->entries[middle].name;
  342. rc = strncmp(path, name, dlen);
  343. if (rc == 0)
  344. {
  345. char ch = name[dlen];
  346. if (ch < '/') /* make sure this isn't just a substr match. */
  347. rc = -1;
  348. else if (ch > '/')
  349. rc = 1;
  350. else
  351. {
  352. if (stop_on_first_find) /* Just checking dir's existance? */
  353. return(middle);
  354. if (name[dlen + 1] == '\0') /* Skip initial dir entry. */
  355. return(middle + 1);
  356. /* there might be more entries earlier in the list. */
  357. retval = middle;
  358. hi = middle - 1;
  359. } /* else */
  360. } /* if */
  361. if (rc > 0)
  362. lo = middle + 1;
  363. else
  364. hi = middle - 1;
  365. } /* while */
  366. return(retval);
  367. } /* qpak_find_start_of_dir */
  368. static LinkedStringList *QPAK_enumerateFiles(DirHandle *h,
  369. const char *dirname,
  370. int omitSymLinks)
  371. {
  372. QPAKinfo *info = ((QPAKinfo *) h->opaque);
  373. LinkedStringList *retval = NULL, *p = NULL;
  374. PHYSFS_sint32 dlen, dlen_inc, max, i;
  375. i = qpak_find_start_of_dir(info, dirname, 0);
  376. BAIL_IF_MACRO(i == -1, ERR_NO_SUCH_FILE, NULL);
  377. dlen = strlen(dirname);
  378. if ((dlen > 0) && (dirname[dlen - 1] == '/')) /* ignore trailing slash. */
  379. dlen--;
  380. dlen_inc = ((dlen > 0) ? 1 : 0) + dlen;
  381. max = (PHYSFS_sint32) info->entryCount;
  382. while (i < max)
  383. {
  384. char *add;
  385. char *ptr;
  386. PHYSFS_sint32 ln;
  387. char *e = info->entries[i].name;
  388. if ((dlen) && ((strncmp(e, dirname, dlen) != 0) || (e[dlen] != '/')))
  389. break; /* past end of this dir; we're done. */
  390. add = e + dlen_inc;
  391. ptr = strchr(add, '/');
  392. ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add));
  393. retval = __PHYSFS_addToLinkedStringList(retval, &p, add, ln);
  394. ln += dlen_inc; /* point past entry to children... */
  395. /* increment counter and skip children of subdirs... */
  396. while ((++i < max) && (ptr != NULL))
  397. {
  398. char *e_new = info->entries[i].name;
  399. if ((strncmp(e, e_new, ln) != 0) || (e_new[ln] != '/'))
  400. break;
  401. } /* while */
  402. } /* while */
  403. return(retval);
  404. } /* QPAK_enumerateFiles */
  405. /*
  406. * This will find the QPAKentry associated with a path in platform-independent
  407. * notation. Directories don't have QPAKentries associated with them, but
  408. * (*isDir) will be set to non-zero if a dir was hit.
  409. */
  410. static QPAKentry *qpak_find_entry(QPAKinfo *info, const char *path, int *isDir)
  411. {
  412. QPAKentry *a = info->entries;
  413. PHYSFS_sint32 pathlen = strlen(path);
  414. PHYSFS_sint32 lo = 0;
  415. PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1);
  416. PHYSFS_sint32 middle;
  417. const char *thispath = NULL;
  418. int rc;
  419. while (lo <= hi)
  420. {
  421. middle = lo + ((hi - lo) / 2);
  422. thispath = a[middle].name;
  423. rc = strncmp(path, thispath, pathlen);
  424. if (rc > 0)
  425. lo = middle + 1;
  426. else if (rc < 0)
  427. hi = middle - 1;
  428. else /* substring match...might be dir or entry or nothing. */
  429. {
  430. if (isDir != NULL)
  431. {
  432. *isDir = (thispath[pathlen] == '/');
  433. if (*isDir)
  434. return(NULL);
  435. } /* if */
  436. if (thispath[pathlen] == '\0') /* found entry? */
  437. return(&a[middle]);
  438. else
  439. hi = middle - 1; /* adjust search params, try again. */
  440. } /* if */
  441. } /* while */
  442. if (isDir != NULL)
  443. *isDir = 0;
  444. BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
  445. } /* qpak_find_entry */
  446. static int QPAK_exists(DirHandle *h, const char *name)
  447. {
  448. int isDir;
  449. QPAKinfo *info = (QPAKinfo *) h->opaque;
  450. QPAKentry *entry = qpak_find_entry(info, name, &isDir);
  451. return((entry != NULL) || (isDir));
  452. } /* QPAK_exists */
  453. static int QPAK_isDirectory(DirHandle *h, const char *name, int *fileExists)
  454. {
  455. QPAKinfo *info = (QPAKinfo *) h->opaque;
  456. int isDir;
  457. QPAKentry *entry = qpak_find_entry(info, name, &isDir);
  458. *fileExists = ((isDir) || (entry != NULL));
  459. if (isDir)
  460. return(1); /* definitely a dir. */
  461. BAIL_MACRO(ERR_NO_SUCH_FILE, 0);
  462. } /* QPAK_isDirectory */
  463. static int QPAK_isSymLink(DirHandle *h, const char *name, int *fileExists)
  464. {
  465. *fileExists = QPAK_exists(h, name);
  466. return(0); /* never symlinks in a quake pak. */
  467. } /* QPAK_isSymLink */
  468. static PHYSFS_sint64 QPAK_getLastModTime(DirHandle *h,
  469. const char *name,
  470. int *fileExists)
  471. {
  472. int isDir;
  473. QPAKinfo *info = ((QPAKinfo *) h->opaque);
  474. PHYSFS_sint64 retval = -1;
  475. QPAKentry *entry = qpak_find_entry(info, name, &isDir);
  476. *fileExists = ((isDir) || (entry != NULL));
  477. if (*fileExists) /* use time of QPAK itself in the physical filesystem. */
  478. retval = info->last_mod_time;
  479. return(retval);
  480. } /* QPAK_getLastModTime */
  481. static FileHandle *QPAK_openRead(DirHandle *h, const char *fnm, int *fileExists)
  482. {
  483. QPAKinfo *info = ((QPAKinfo *) h->opaque);
  484. FileHandle *retval;
  485. QPAKfileinfo *finfo;
  486. QPAKentry *entry;
  487. int isDir;
  488. entry = qpak_find_entry(info, fnm, &isDir);
  489. *fileExists = ((entry != NULL) || (isDir));
  490. BAIL_IF_MACRO(isDir, ERR_NOT_A_FILE, NULL);
  491. BAIL_IF_MACRO(entry == NULL, ERR_NO_SUCH_FILE, NULL);
  492. retval = (FileHandle *) malloc(sizeof (FileHandle));
  493. BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
  494. finfo = (QPAKfileinfo *) malloc(sizeof (QPAKfileinfo));
  495. if (finfo == NULL)
  496. {
  497. free(retval);
  498. BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
  499. } /* if */
  500. finfo->handle = __PHYSFS_platformOpenRead(info->filename);
  501. if ( (finfo->handle == NULL) ||
  502. (!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
  503. {
  504. free(finfo);
  505. free(retval);
  506. return(NULL);
  507. } /* if */
  508. finfo->curPos = 0;
  509. finfo->entry = entry;
  510. retval->opaque = (void *) finfo;
  511. retval->funcs = &__PHYSFS_FileFunctions_QPAK;
  512. retval->dirHandle = h;
  513. return(retval);
  514. } /* QPAK_openRead */
  515. static FileHandle *QPAK_openWrite(DirHandle *h, const char *name)
  516. {
  517. BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
  518. } /* QPAK_openWrite */
  519. static FileHandle *QPAK_openAppend(DirHandle *h, const char *name)
  520. {
  521. BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
  522. } /* QPAK_openAppend */
  523. static int QPAK_remove(DirHandle *h, const char *name)
  524. {
  525. BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
  526. } /* QPAK_remove */
  527. static int QPAK_mkdir(DirHandle *h, const char *name)
  528. {
  529. BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
  530. } /* QPAK_mkdir */
  531. #endif /* defined PHYSFS_SUPPORTS_QPAK */
  532. /* end of qpak.c ... */