lzma.c 20 KB

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