lzma.c 20 KB

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