lzma.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /*
  2. * LZMA support routines for PhysicsFS.
  3. *
  4. * Please see the file LICENSE in the source's root directory.
  5. *
  6. * This file is written by Dennis Schridde, with some peeking at "7zMain.c"
  7. * by Igor Pavlov.
  8. */
  9. #if HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. #if (defined PHYSFS_SUPPORTS_LZMA)
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include "physfs.h"
  16. #define __PHYSICSFS_INTERNAL__
  17. #include "physfs_internal.h"
  18. #define _LZMA_IN_CB
  19. /* Use callback for input data */
  20. /* #define _LZMA_OUT_READ */
  21. /* Use read function for output data */
  22. #define _LZMA_PROB32
  23. /* It can increase speed on some 32-bit CPUs,
  24. but memory usage will be doubled in that case */
  25. #define _LZMA_SYSTEM_SIZE_T
  26. /* Use system's size_t. You can use it to enable 64-bit sizes supporting */
  27. #include "7zIn.h"
  28. #include "7zCrc.h"
  29. #include "7zExtract.h"
  30. /* 7z internal from 7zIn.c */
  31. int TestSignatureCandidate(Byte *testBytes);
  32. typedef struct _CFileInStream
  33. {
  34. ISzInStream InStream;
  35. void *File;
  36. } CFileInStream;
  37. /*
  38. * In LZMA the archive is splited in blocks, those are called folders
  39. * Set by LZMA_read()
  40. */
  41. typedef struct _LZMAfolder
  42. {
  43. PHYSFS_uint8 *cache; /* Cached folder */
  44. PHYSFS_uint32 size; /* Size of folder */
  45. PHYSFS_uint32 index; /* Index of folder in archive */
  46. PHYSFS_uint32 references; /* Number of files using this block */
  47. } LZMAfolder;
  48. /*
  49. * Set by LZMA_openArchive(), except folder which gets it's values
  50. * in LZMA_read()
  51. */
  52. typedef struct _LZMAarchive
  53. {
  54. struct _LZMAentry *firstEntry; /* Used for cleanup on shutdown */
  55. struct _LZMAentry *lastEntry;
  56. LZMAfolder *folder; /* Array of folders */
  57. CArchiveDatabaseEx db; /* For 7z: Database */
  58. CFileInStream stream; /* For 7z: Input file incl. read and seek callbacks */
  59. } LZMAarchive;
  60. /* Set by LZMA_openRead(), except offset which is set by LZMA_read() */
  61. typedef struct _LZMAentry
  62. {
  63. struct _LZMAentry *next; /* Used for cleanup on shutdown */
  64. struct _LZMAentry *previous;
  65. LZMAarchive *archive; /* Link to corresponding archive */
  66. CFileItem *file; /* For 7z: File info, eg. name, size */
  67. PHYSFS_uint32 fileIndex; /* Index of file in archive */
  68. PHYSFS_uint32 folderIndex; /* Index of folder in archive */
  69. size_t offset; /* Offset in folder */
  70. PHYSFS_uint32 position; /* Current "virtual" position in file */
  71. } LZMAentry;
  72. /* Memory management implementations to be passed to 7z */
  73. static void *SzAllocPhysicsFS(size_t size)
  74. {
  75. return ((size == 0) ? NULL : allocator.Malloc(size));
  76. } /* SzAllocPhysicsFS */
  77. static void SzFreePhysicsFS(void *address)
  78. {
  79. if (address != NULL)
  80. allocator.Free(address);
  81. } /* SzFreePhysicsFS */
  82. /* Filesystem implementations to be passed to 7z */
  83. #ifdef _LZMA_IN_CB
  84. #define kBufferSize (1 << 12)
  85. static Byte g_Buffer[kBufferSize]; /* !!! FIXME: not thread safe! */
  86. SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxReqSize,
  87. size_t *processedSize)
  88. {
  89. CFileInStream *s = (CFileInStream *)object;
  90. size_t processedSizeLoc;
  91. if (maxReqSize > kBufferSize)
  92. maxReqSize = kBufferSize;
  93. processedSizeLoc = __PHYSFS_platformRead(s->File, g_Buffer, 1, maxReqSize);
  94. *buffer = g_Buffer;
  95. if (processedSize != 0)
  96. *processedSize = processedSizeLoc;
  97. return SZ_OK;
  98. } /* SzFileReadImp */
  99. #else
  100. SZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size,
  101. size_t *processedSize)
  102. {
  103. CFileInStream *s = (CFileInStream *)object;
  104. size_t processedSizeLoc = __PHYSFS_platformRead(s->File, buffer, 1, size);
  105. if (processedSize != 0)
  106. *processedSize = processedSizeLoc;
  107. return SZ_OK;
  108. } /* SzFileReadImp */
  109. #endif
  110. SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
  111. {
  112. CFileInStream *s = (CFileInStream *) object;
  113. if (__PHYSFS_platformSeek(s->File, (PHYSFS_uint64) pos))
  114. return SZ_OK;
  115. return SZE_FAIL;
  116. } /* SzFileSeekImp */
  117. /*
  118. * Find entry 'name' in 'archive' and report the 'index' back
  119. */
  120. static int lzma_find_entry(LZMAarchive *archive, const char *name,
  121. PHYSFS_uint32 *index)
  122. {
  123. for (*index = 0; *index < archive->db.Database.NumFiles; (*index)++)
  124. {
  125. if (strcmp(archive->db.Database.Files[*index].Name, name) == 0)
  126. return 1;
  127. } /* for */
  128. BAIL_MACRO(ERR_NO_SUCH_FILE, 0);
  129. } /* lzma_find_entry */
  130. /*
  131. * Report the first file index of a directory
  132. */
  133. static PHYSFS_sint32 lzma_find_start_of_dir(LZMAarchive *archive,
  134. const char *path,
  135. int stop_on_first_find)
  136. {
  137. PHYSFS_sint32 lo = 0;
  138. PHYSFS_sint32 hi = (PHYSFS_sint32) (archive->db.Database.NumFiles - 1);
  139. PHYSFS_sint32 middle;
  140. PHYSFS_uint32 dlen = strlen(path);
  141. PHYSFS_sint32 retval = -1;
  142. const char *name;
  143. int rc;
  144. if (*path == '\0') /* root dir? */
  145. return(0);
  146. if ((dlen > 0) && (path[dlen - 1] == '/')) /* ignore trailing slash. */
  147. dlen--;
  148. while (lo <= hi)
  149. {
  150. middle = lo + ((hi - lo) / 2);
  151. name = archive->db.Database.Files[middle].Name;
  152. rc = strncmp(path, name, dlen);
  153. if (rc == 0)
  154. {
  155. char ch = name[dlen];
  156. if ('/' < ch) /* make sure this isn't just a substr match. */
  157. rc = -1;
  158. else if ('/' > ch)
  159. rc = 1;
  160. else
  161. {
  162. if (stop_on_first_find) /* Just checking dir's existance? */
  163. return(middle);
  164. if (name[dlen + 1] == '\0') /* Skip initial dir entry. */
  165. return(middle + 1);
  166. /* there might be more entries earlier in the list. */
  167. retval = middle;
  168. hi = middle - 1;
  169. } /* else */
  170. } /* if */
  171. if (rc > 0)
  172. lo = middle + 1;
  173. else
  174. hi = middle - 1;
  175. } /* while */
  176. return(retval);
  177. } /* lzma_find_start_of_dir */
  178. /*
  179. * Wrap all 7z calls in this, so the physfs error state is set appropriately.
  180. */
  181. static int lzma_err(SZ_RESULT rc)
  182. {
  183. switch (rc)
  184. {
  185. case SZ_OK: /* Same as LZMA_RESULT_OK */
  186. break;
  187. case SZE_DATA_ERROR: /* Same as LZMA_RESULT_DATA_ERROR */
  188. __PHYSFS_setError(ERR_DATA_ERROR);
  189. break;
  190. case SZE_OUTOFMEMORY:
  191. __PHYSFS_setError(ERR_OUT_OF_MEMORY);
  192. break;
  193. case SZE_CRC_ERROR:
  194. __PHYSFS_setError(ERR_CORRUPTED);
  195. break;
  196. case SZE_NOTIMPL:
  197. __PHYSFS_setError(ERR_NOT_IMPLEMENTED);
  198. break;
  199. case SZE_FAIL:
  200. __PHYSFS_setError(ERR_UNKNOWN_ERROR); /* !!! FIXME: right? */
  201. break;
  202. case SZE_ARCHIVE_ERROR:
  203. __PHYSFS_setError(ERR_CORRUPTED); /* !!! FIXME: right? */
  204. break;
  205. default:
  206. __PHYSFS_setError(ERR_UNKNOWN_ERROR);
  207. } /* switch */
  208. return(rc);
  209. } /* lzma_err */
  210. static PHYSFS_sint64 LZMA_read(fvoid *opaque, void *outBuffer,
  211. PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  212. {
  213. LZMAentry *entry = (LZMAentry *) opaque;
  214. PHYSFS_sint64 wantedSize = objSize*objCount;
  215. PHYSFS_sint64 remainingSize = entry->file->Size - entry->position;
  216. BAIL_IF_MACRO(wantedSize == 0, NULL, 0); /* quick rejection. */
  217. BAIL_IF_MACRO(remainingSize == 0, ERR_PAST_EOF, 0);
  218. if (remainingSize < wantedSize)
  219. {
  220. wantedSize = remainingSize - (remainingSize % objSize);
  221. objCount = (PHYSFS_uint32) (remainingSize / objSize);
  222. BAIL_IF_MACRO(objCount == 0, ERR_PAST_EOF, 0); /* quick rejection. */
  223. __PHYSFS_setError(ERR_PAST_EOF); /* this is always true here. */
  224. } /* if */
  225. size_t fileSize;
  226. ISzAlloc allocImp;
  227. ISzAlloc allocTempImp;
  228. /* Prepare callbacks for 7z */
  229. allocImp.Alloc = SzAllocPhysicsFS;
  230. allocImp.Free = SzFreePhysicsFS;
  231. allocTempImp.Alloc = SzAllocPhysicsFS;
  232. allocTempImp.Free = SzFreePhysicsFS;
  233. /* Only decompress the folder if it is not allready cached */
  234. if (entry->archive->folder[entry->folderIndex].cache == NULL)
  235. if (lzma_err(SzExtract(
  236. &entry->archive->stream.InStream, /* compressed data */
  237. &entry->archive->db,
  238. entry->fileIndex,
  239. /* Index of cached folder, will be changed by SzExtract */
  240. &entry->archive->folder[entry->folderIndex].index,
  241. /* Cache for decompressed folder, allocated/freed by SzExtract */
  242. &entry->archive->folder[entry->folderIndex].cache,
  243. /* Size of cache, will be changed by SzExtract */
  244. &entry->archive->folder[entry->folderIndex].size,
  245. /* Offset of this file inside the cache, set by SzExtract */
  246. &entry->offset,
  247. &fileSize, /* Size of this file */
  248. &allocImp,
  249. &allocTempImp
  250. )) != SZ_OK)
  251. return -1;
  252. /* Copy wanted bytes over from cache to outBuffer */
  253. strncpy(outBuffer,
  254. (void*) (entry->archive->folder[entry->folderIndex].cache +
  255. entry->offset + entry->position),
  256. wantedSize);
  257. entry->position += wantedSize;
  258. return objCount;
  259. } /* LZMA_read */
  260. static PHYSFS_sint64 LZMA_write(fvoid *opaque, const void *buf,
  261. PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  262. {
  263. BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
  264. } /* LZMA_write */
  265. static int LZMA_eof(fvoid *opaque)
  266. {
  267. LZMAentry *entry = (LZMAentry *) opaque;
  268. return (entry->position >= entry->file->Size);
  269. } /* LZMA_eof */
  270. static PHYSFS_sint64 LZMA_tell(fvoid *opaque)
  271. {
  272. LZMAentry *entry = (LZMAentry *) opaque;
  273. return (entry->position);
  274. } /* LZMA_tell */
  275. static int LZMA_seek(fvoid *opaque, PHYSFS_uint64 offset)
  276. {
  277. LZMAentry *entry = (LZMAentry *) opaque;
  278. BAIL_IF_MACRO(offset < 0, ERR_SEEK_OUT_OF_RANGE, 0);
  279. BAIL_IF_MACRO(offset > entry->file->Size, ERR_PAST_EOF, 0);
  280. entry->position = offset;
  281. return 1;
  282. } /* LZMA_seek */
  283. static PHYSFS_sint64 LZMA_fileLength(fvoid *opaque)
  284. {
  285. LZMAentry *entry = (LZMAentry *) opaque;
  286. return (entry->file->Size);
  287. } /* LZMA_fileLength */
  288. static int LZMA_fileClose(fvoid *opaque)
  289. {
  290. LZMAentry *entry = (LZMAentry *) opaque;
  291. /* Fix archive */
  292. if (entry == entry->archive->firstEntry)
  293. entry->archive->firstEntry = entry->next;
  294. if (entry == entry->archive->lastEntry)
  295. entry->archive->lastEntry = entry->previous;
  296. /* Fix neighbours */
  297. if (entry->previous != NULL)
  298. entry->previous->next = entry->next;
  299. if (entry->next != NULL)
  300. entry->next->previous = entry->previous;
  301. entry->archive->folder[entry->folderIndex].references--;
  302. if (entry->archive->folder[entry->folderIndex].references == 0)
  303. {
  304. allocator.Free(entry->archive->folder[entry->folderIndex].cache);
  305. entry->archive->folder[entry->folderIndex].cache = NULL;
  306. }
  307. allocator.Free(entry);
  308. entry = NULL;
  309. return(1);
  310. } /* LZMA_fileClose */
  311. static int LZMA_isArchive(const char *filename, int forWriting)
  312. {
  313. PHYSFS_uint8 sig[k7zSignatureSize];
  314. PHYSFS_uint8 res;
  315. void *in;
  316. BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
  317. in = __PHYSFS_platformOpenRead(filename);
  318. BAIL_IF_MACRO(in == NULL, NULL, 0);
  319. if (__PHYSFS_platformRead(in, sig, k7zSignatureSize, 1) != 1)
  320. BAIL_MACRO(NULL, 0);
  321. /* Test whether sig is the 7z signature */
  322. res = TestSignatureCandidate(sig);
  323. __PHYSFS_platformClose(in);
  324. return res;
  325. } /* LZMA_isArchive */
  326. static void *LZMA_openArchive(const char *name, int forWriting)
  327. {
  328. PHYSFS_uint64 len;
  329. LZMAarchive *archive = NULL;
  330. ISzAlloc allocImp;
  331. ISzAlloc allocTempImp;
  332. BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL);
  333. BAIL_IF_MACRO(!LZMA_isArchive(name,forWriting), ERR_UNSUPPORTED_ARCHIVE, 0);
  334. archive = (LZMAarchive *) allocator.Malloc(sizeof (LZMAarchive));
  335. BAIL_IF_MACRO(archive == NULL, ERR_OUT_OF_MEMORY, NULL);
  336. archive->firstEntry = NULL;
  337. archive->lastEntry = NULL;
  338. if ((archive->stream.File = __PHYSFS_platformOpenRead(name)) == NULL)
  339. {
  340. allocator.Free(archive);
  341. return NULL;
  342. } /* if */
  343. /* Prepare structs for 7z */
  344. archive->stream.InStream.Read = SzFileReadImp;
  345. archive->stream.InStream.Seek = SzFileSeekImp;
  346. allocImp.Alloc = SzAllocPhysicsFS;
  347. allocImp.Free = SzFreePhysicsFS;
  348. allocTempImp.Alloc = SzAllocPhysicsFS;
  349. allocTempImp.Free = SzFreePhysicsFS;
  350. InitCrcTable();
  351. SzArDbExInit(&archive->db);
  352. if (lzma_err(SzArchiveOpen(&archive->stream.InStream, &archive->db,
  353. &allocImp, &allocTempImp)) != SZ_OK)
  354. {
  355. __PHYSFS_platformClose(archive->stream.File);
  356. allocator.Free(archive);
  357. return NULL;
  358. } /* if */
  359. len = archive->db.Database.NumFolders * sizeof (LZMAfolder);
  360. archive->folder = (LZMAfolder *) allocator.Malloc(len);
  361. BAIL_IF_MACRO(archive->folder == NULL, ERR_OUT_OF_MEMORY, NULL);
  362. /*
  363. * Init with 0 so we know when a folder is already cached
  364. * Values will be set by LZMA_read()
  365. */
  366. memset(archive->folder, 0, len);
  367. return(archive);
  368. } /* LZMA_openArchive */
  369. /*
  370. * Moved to seperate function so we can use alloca then immediately throw
  371. * away the allocated stack space...
  372. */
  373. static void doEnumCallback(PHYSFS_EnumFilesCallback cb, void *callbackdata,
  374. const char *odir, const char *str, PHYSFS_sint32 ln)
  375. {
  376. char *newstr = alloca(ln + 1);
  377. if (newstr == NULL)
  378. return;
  379. memcpy(newstr, str, ln);
  380. newstr[ln] = '\0';
  381. cb(callbackdata, odir, newstr);
  382. } /* doEnumCallback */
  383. static void LZMA_enumerateFiles(dvoid *opaque, const char *dname,
  384. int omitSymLinks, PHYSFS_EnumFilesCallback cb,
  385. const char *origdir, void *callbackdata)
  386. {
  387. LZMAarchive *archive = (LZMAarchive *) opaque;
  388. PHYSFS_sint32 dlen;
  389. PHYSFS_sint32 dlen_inc;
  390. PHYSFS_sint32 max;
  391. PHYSFS_sint32 i;
  392. i = lzma_find_start_of_dir(archive, dname, 0);
  393. if (i == -1) /* no such directory. */
  394. return;
  395. dlen = strlen(dname);
  396. if ((dlen > 0) && (dname[dlen - 1] == '/')) /* ignore trailing slash. */
  397. dlen--;
  398. dlen_inc = ((dlen > 0) ? 1 : 0) + dlen;
  399. max = (PHYSFS_sint32) archive->db.Database.NumFiles;
  400. while (i < max)
  401. {
  402. char *add;
  403. char *ptr;
  404. PHYSFS_sint32 ln;
  405. char *e = archive->db.Database.Files[i].Name;
  406. if ((dlen) && ((strncmp(e, dname, dlen)) || (e[dlen] != '/')))
  407. break; /* past end of this dir; we're done. */
  408. add = e + dlen_inc;
  409. ptr = strchr(add, '/');
  410. ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add));
  411. doEnumCallback(cb, callbackdata, origdir, add, ln);
  412. ln += dlen_inc; /* point past entry to children... */
  413. /* increment counter and skip children of subdirs... */
  414. while ((++i < max) && (ptr != NULL))
  415. {
  416. char *e_new = archive->db.Database.Files[i].Name;
  417. if ((strncmp(e, e_new, ln) != 0) || (e_new[ln] != '/'))
  418. break;
  419. } /* while */
  420. } /* while */
  421. } /* LZMA_enumerateFiles */
  422. static int LZMA_exists(dvoid *opaque, const char *name)
  423. {
  424. LZMAarchive *archive = (LZMAarchive *) opaque;
  425. PHYSFS_uint32 index = 0;
  426. return(lzma_find_entry(archive, name, &index));
  427. } /* LZMA_exists */
  428. static PHYSFS_sint64 LZMA_getLastModTime(dvoid *opaque,
  429. const char *name,
  430. int *fileExists)
  431. {
  432. /* !!! FIXME: Lacking support in the LZMA C SDK. */
  433. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  434. } /* LZMA_getLastModTime */
  435. static int LZMA_isDirectory(dvoid *opaque, const char *name, int *fileExists)
  436. {
  437. LZMAarchive *archive = (LZMAarchive *) opaque;
  438. PHYSFS_uint32 index = 0;
  439. *fileExists = lzma_find_entry(archive, name, &index);
  440. return(archive->db.Database.Files[index].IsDirectory);
  441. } /* LZMA_isDirectory */
  442. static int LZMA_isSymLink(dvoid *opaque, const char *name, int *fileExists)
  443. {
  444. BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
  445. } /* LZMA_isSymLink */
  446. static fvoid *LZMA_openRead(dvoid *opaque, const char *name, int *fileExists)
  447. {
  448. LZMAarchive *archive = (LZMAarchive *) opaque;
  449. LZMAentry *entry = NULL;
  450. PHYSFS_uint32 fileIndex = 0;
  451. PHYSFS_uint32 folderIndex = 0;
  452. *fileExists = lzma_find_entry(archive, name, &fileIndex);
  453. BAIL_IF_MACRO(!*fileExists, ERR_NO_SUCH_FILE, NULL);
  454. folderIndex = archive->db.FileIndexToFolderIndexMap[fileIndex];
  455. BAIL_IF_MACRO(folderIndex == (PHYSFS_uint32)-1, ERR_UNKNOWN_ERROR, NULL);
  456. entry = (LZMAentry *) allocator.Malloc(sizeof (LZMAentry));
  457. BAIL_IF_MACRO(entry == NULL, ERR_OUT_OF_MEMORY, NULL);
  458. entry->fileIndex = fileIndex;
  459. entry->folderIndex = folderIndex;
  460. entry->archive = archive;
  461. entry->file = archive->db.Database.Files + entry->fileIndex;
  462. entry->offset = 0; /* Offset will be set by LZMA_read() */
  463. entry->position = 0;
  464. archive->folder[folderIndex].references++;
  465. entry->next = NULL;
  466. entry->previous = entry->archive->lastEntry;
  467. if (entry->previous != NULL)
  468. entry->previous->next = entry;
  469. entry->archive->lastEntry = entry;
  470. if (entry->archive->firstEntry == NULL)
  471. entry->archive->firstEntry = entry;
  472. return(entry);
  473. } /* LZMA_openRead */
  474. static fvoid *LZMA_openWrite(dvoid *opaque, const char *filename)
  475. {
  476. BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
  477. } /* LZMA_openWrite */
  478. static fvoid *LZMA_openAppend(dvoid *opaque, const char *filename)
  479. {
  480. BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
  481. } /* LZMA_openAppend */
  482. static void LZMA_dirClose(dvoid *opaque)
  483. {
  484. LZMAarchive *archive = (LZMAarchive *) opaque;
  485. LZMAentry *entry = archive->firstEntry;
  486. LZMAentry *tmpEntry = entry;
  487. while (entry != NULL)
  488. {
  489. tmpEntry = entry->next;
  490. LZMA_fileClose(entry);
  491. entry = tmpEntry;
  492. } /* while */
  493. SzArDbExFree(&archive->db, SzFreePhysicsFS);
  494. __PHYSFS_platformClose(archive->stream.File);
  495. /* Free the cache which might have been allocated by LZMA_read() */
  496. allocator.Free(archive->folder);
  497. allocator.Free(archive);
  498. } /* LZMA_dirClose */
  499. static int LZMA_remove(dvoid *opaque, const char *name)
  500. {
  501. BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
  502. } /* LZMA_remove */
  503. static int LZMA_mkdir(dvoid *opaque, const char *name)
  504. {
  505. BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
  506. } /* LZMA_mkdir */
  507. const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_LZMA =
  508. {
  509. "7Z",
  510. LZMA_ARCHIVE_DESCRIPTION,
  511. "Dennis Schridde <devurandom@gmx.net>",
  512. "http://icculus.org/physfs/",
  513. };
  514. const PHYSFS_Archiver __PHYSFS_Archiver_LZMA =
  515. {
  516. &__PHYSFS_ArchiveInfo_LZMA,
  517. LZMA_isArchive, /* isArchive() method */
  518. LZMA_openArchive, /* openArchive() method */
  519. LZMA_enumerateFiles, /* enumerateFiles() method */
  520. LZMA_exists, /* exists() method */
  521. LZMA_isDirectory, /* isDirectory() method */
  522. LZMA_isSymLink, /* isSymLink() method */
  523. LZMA_getLastModTime, /* getLastModTime() method */
  524. LZMA_openRead, /* openRead() method */
  525. LZMA_openWrite, /* openWrite() method */
  526. LZMA_openAppend, /* openAppend() method */
  527. LZMA_remove, /* remove() method */
  528. LZMA_mkdir, /* mkdir() method */
  529. LZMA_dirClose, /* dirClose() method */
  530. LZMA_read, /* read() method */
  531. LZMA_write, /* write() method */
  532. LZMA_eof, /* eof() method */
  533. LZMA_tell, /* tell() method */
  534. LZMA_seek, /* seek() method */
  535. LZMA_fileLength, /* fileLength() method */
  536. LZMA_fileClose /* fileClose() method */
  537. };
  538. #endif /* defined PHYSFS_SUPPORTS_LZMA */
  539. /* end of lzma.c ... */