lzma.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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_uint64 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. PHYSFS_sint64 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 != NULL)
  99. *processedSize = (size_t) 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. /* !!! FIXME: strncpy for non-string data? */
  261. strncpy(outBuffer,
  262. (void*) (entry->archive->folder[entry->folderIndex].cache +
  263. entry->offset + entry->position),
  264. (size_t) wantedSize);
  265. entry->position += wantedSize;
  266. return objCount;
  267. } /* LZMA_read */
  268. static PHYSFS_sint64 LZMA_write(fvoid *opaque, const void *buf,
  269. PHYSFS_uint32 objSize, PHYSFS_uint32 objCount)
  270. {
  271. BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
  272. } /* LZMA_write */
  273. static int LZMA_eof(fvoid *opaque)
  274. {
  275. LZMAentry *entry = (LZMAentry *) opaque;
  276. return (entry->position >= entry->file->Size);
  277. } /* LZMA_eof */
  278. static PHYSFS_sint64 LZMA_tell(fvoid *opaque)
  279. {
  280. LZMAentry *entry = (LZMAentry *) opaque;
  281. return (entry->position);
  282. } /* LZMA_tell */
  283. static int LZMA_seek(fvoid *opaque, PHYSFS_uint64 offset)
  284. {
  285. LZMAentry *entry = (LZMAentry *) opaque;
  286. BAIL_IF_MACRO(offset < 0, ERR_SEEK_OUT_OF_RANGE, 0);
  287. BAIL_IF_MACRO(offset > entry->file->Size, ERR_PAST_EOF, 0);
  288. entry->position = offset;
  289. return 1;
  290. } /* LZMA_seek */
  291. static PHYSFS_sint64 LZMA_fileLength(fvoid *opaque)
  292. {
  293. LZMAentry *entry = (LZMAentry *) opaque;
  294. return (entry->file->Size);
  295. } /* LZMA_fileLength */
  296. static int LZMA_fileClose(fvoid *opaque)
  297. {
  298. LZMAentry *entry = (LZMAentry *) opaque;
  299. /* Fix archive */
  300. if (entry == entry->archive->firstEntry)
  301. entry->archive->firstEntry = entry->next;
  302. if (entry == entry->archive->lastEntry)
  303. entry->archive->lastEntry = entry->previous;
  304. /* Fix neighbours */
  305. if (entry->previous != NULL)
  306. entry->previous->next = entry->next;
  307. if (entry->next != NULL)
  308. entry->next->previous = entry->previous;
  309. entry->archive->folder[entry->folderIndex].references--;
  310. if (entry->archive->folder[entry->folderIndex].references == 0)
  311. {
  312. allocator.Free(entry->archive->folder[entry->folderIndex].cache);
  313. entry->archive->folder[entry->folderIndex].cache = NULL;
  314. }
  315. allocator.Free(entry);
  316. entry = NULL;
  317. return(1);
  318. } /* LZMA_fileClose */
  319. static int LZMA_isArchive(const char *filename, int forWriting)
  320. {
  321. PHYSFS_uint8 sig[k7zSignatureSize];
  322. PHYSFS_uint8 res;
  323. void *in;
  324. BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
  325. in = __PHYSFS_platformOpenRead(filename);
  326. BAIL_IF_MACRO(in == NULL, NULL, 0);
  327. if (__PHYSFS_platformRead(in, sig, k7zSignatureSize, 1) != 1)
  328. BAIL_MACRO(NULL, 0);
  329. /* Test whether sig is the 7z signature */
  330. res = TestSignatureCandidate(sig);
  331. __PHYSFS_platformClose(in);
  332. return res;
  333. } /* LZMA_isArchive */
  334. static void *LZMA_openArchive(const char *name, int forWriting)
  335. {
  336. PHYSFS_uint64 len;
  337. LZMAarchive *archive = NULL;
  338. ISzAlloc allocImp;
  339. ISzAlloc allocTempImp;
  340. BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL);
  341. BAIL_IF_MACRO(!LZMA_isArchive(name,forWriting), ERR_UNSUPPORTED_ARCHIVE, 0);
  342. archive = (LZMAarchive *) allocator.Malloc(sizeof (LZMAarchive));
  343. BAIL_IF_MACRO(archive == NULL, ERR_OUT_OF_MEMORY, NULL);
  344. archive->firstEntry = NULL;
  345. archive->lastEntry = NULL;
  346. if ((archive->stream.File = __PHYSFS_platformOpenRead(name)) == NULL)
  347. {
  348. allocator.Free(archive);
  349. return NULL;
  350. } /* if */
  351. /* Prepare structs for 7z */
  352. archive->stream.InStream.Read = SzFileReadImp;
  353. archive->stream.InStream.Seek = SzFileSeekImp;
  354. allocImp.Alloc = SzAllocPhysicsFS;
  355. allocImp.Free = SzFreePhysicsFS;
  356. allocTempImp.Alloc = SzAllocPhysicsFS;
  357. allocTempImp.Free = SzFreePhysicsFS;
  358. InitCrcTable();
  359. SzArDbExInit(&archive->db);
  360. if (lzma_err(SzArchiveOpen(&archive->stream.InStream, &archive->db,
  361. &allocImp, &allocTempImp)) != SZ_OK)
  362. {
  363. __PHYSFS_platformClose(archive->stream.File);
  364. allocator.Free(archive);
  365. return NULL;
  366. } /* if */
  367. len = archive->db.Database.NumFolders * sizeof (LZMAfolder);
  368. archive->folder = (LZMAfolder *) allocator.Malloc(len);
  369. BAIL_IF_MACRO(archive->folder == NULL, ERR_OUT_OF_MEMORY, NULL);
  370. /*
  371. * Init with 0 so we know when a folder is already cached
  372. * Values will be set by LZMA_read()
  373. */
  374. memset(archive->folder, 0, (size_t) len);
  375. return(archive);
  376. } /* LZMA_openArchive */
  377. /*
  378. * Moved to seperate function so we can use alloca then immediately throw
  379. * away the allocated stack space...
  380. */
  381. static void doEnumCallback(PHYSFS_EnumFilesCallback cb, void *callbackdata,
  382. const char *odir, const char *str, PHYSFS_sint32 ln)
  383. {
  384. char *newstr = __PHYSFS_smallAlloc(ln + 1);
  385. if (newstr == NULL)
  386. return;
  387. memcpy(newstr, str, ln);
  388. newstr[ln] = '\0';
  389. cb(callbackdata, odir, newstr);
  390. __PHYSFS_smallFree(newstr);
  391. } /* doEnumCallback */
  392. static void LZMA_enumerateFiles(dvoid *opaque, const char *dname,
  393. int omitSymLinks, PHYSFS_EnumFilesCallback cb,
  394. const char *origdir, void *callbackdata)
  395. {
  396. LZMAarchive *archive = (LZMAarchive *) opaque;
  397. PHYSFS_sint32 dlen;
  398. PHYSFS_sint32 dlen_inc;
  399. PHYSFS_sint32 max;
  400. PHYSFS_sint32 i;
  401. i = lzma_find_start_of_dir(archive, dname, 0);
  402. if (i == -1) /* no such directory. */
  403. return;
  404. dlen = strlen(dname);
  405. if ((dlen > 0) && (dname[dlen - 1] == '/')) /* ignore trailing slash. */
  406. dlen--;
  407. dlen_inc = ((dlen > 0) ? 1 : 0) + dlen;
  408. max = (PHYSFS_sint32) archive->db.Database.NumFiles;
  409. while (i < max)
  410. {
  411. char *add;
  412. char *ptr;
  413. PHYSFS_sint32 ln;
  414. char *e = archive->db.Database.Files[i].Name;
  415. if ((dlen) && ((strncmp(e, dname, dlen)) || (e[dlen] != '/')))
  416. break; /* past end of this dir; we're done. */
  417. add = e + dlen_inc;
  418. ptr = strchr(add, '/');
  419. ln = (PHYSFS_sint32) ((ptr) ? ptr-add : strlen(add));
  420. doEnumCallback(cb, callbackdata, origdir, add, ln);
  421. ln += dlen_inc; /* point past entry to children... */
  422. /* increment counter and skip children of subdirs... */
  423. while ((++i < max) && (ptr != NULL))
  424. {
  425. char *e_new = archive->db.Database.Files[i].Name;
  426. if ((strncmp(e, e_new, ln) != 0) || (e_new[ln] != '/'))
  427. break;
  428. } /* while */
  429. } /* while */
  430. } /* LZMA_enumerateFiles */
  431. static int LZMA_exists(dvoid *opaque, const char *name)
  432. {
  433. LZMAarchive *archive = (LZMAarchive *) opaque;
  434. PHYSFS_uint32 index = 0;
  435. return(lzma_find_entry(archive, name, &index));
  436. } /* LZMA_exists */
  437. static PHYSFS_sint64 LZMA_getLastModTime(dvoid *opaque,
  438. const char *name,
  439. int *fileExists)
  440. {
  441. /* !!! FIXME: Lacking support in the LZMA C SDK. */
  442. BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
  443. } /* LZMA_getLastModTime */
  444. static int LZMA_isDirectory(dvoid *opaque, const char *name, int *fileExists)
  445. {
  446. LZMAarchive *archive = (LZMAarchive *) opaque;
  447. PHYSFS_uint32 index = 0;
  448. *fileExists = lzma_find_entry(archive, name, &index);
  449. return(archive->db.Database.Files[index].IsDirectory);
  450. } /* LZMA_isDirectory */
  451. static int LZMA_isSymLink(dvoid *opaque, const char *name, int *fileExists)
  452. {
  453. BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
  454. } /* LZMA_isSymLink */
  455. static fvoid *LZMA_openRead(dvoid *opaque, const char *name, int *fileExists)
  456. {
  457. LZMAarchive *archive = (LZMAarchive *) opaque;
  458. LZMAentry *entry = NULL;
  459. PHYSFS_uint32 fileIndex = 0;
  460. PHYSFS_uint32 folderIndex = 0;
  461. *fileExists = lzma_find_entry(archive, name, &fileIndex);
  462. BAIL_IF_MACRO(!*fileExists, ERR_NO_SUCH_FILE, NULL);
  463. folderIndex = archive->db.FileIndexToFolderIndexMap[fileIndex];
  464. BAIL_IF_MACRO(folderIndex == (PHYSFS_uint32)-1, ERR_UNKNOWN_ERROR, NULL);
  465. entry = (LZMAentry *) allocator.Malloc(sizeof (LZMAentry));
  466. BAIL_IF_MACRO(entry == NULL, ERR_OUT_OF_MEMORY, NULL);
  467. entry->fileIndex = fileIndex;
  468. entry->folderIndex = folderIndex;
  469. entry->archive = archive;
  470. entry->file = archive->db.Database.Files + entry->fileIndex;
  471. entry->offset = 0; /* Offset will be set by LZMA_read() */
  472. entry->position = 0;
  473. archive->folder[folderIndex].references++;
  474. entry->next = NULL;
  475. entry->previous = entry->archive->lastEntry;
  476. if (entry->previous != NULL)
  477. entry->previous->next = entry;
  478. entry->archive->lastEntry = entry;
  479. if (entry->archive->firstEntry == NULL)
  480. entry->archive->firstEntry = entry;
  481. return(entry);
  482. } /* LZMA_openRead */
  483. static fvoid *LZMA_openWrite(dvoid *opaque, const char *filename)
  484. {
  485. BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
  486. } /* LZMA_openWrite */
  487. static fvoid *LZMA_openAppend(dvoid *opaque, const char *filename)
  488. {
  489. BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
  490. } /* LZMA_openAppend */
  491. static void LZMA_dirClose(dvoid *opaque)
  492. {
  493. LZMAarchive *archive = (LZMAarchive *) opaque;
  494. LZMAentry *entry = archive->firstEntry;
  495. LZMAentry *tmpEntry = entry;
  496. while (entry != NULL)
  497. {
  498. tmpEntry = entry->next;
  499. LZMA_fileClose(entry);
  500. entry = tmpEntry;
  501. } /* while */
  502. SzArDbExFree(&archive->db, SzFreePhysicsFS);
  503. __PHYSFS_platformClose(archive->stream.File);
  504. /* Free the cache which might have been allocated by LZMA_read() */
  505. allocator.Free(archive->folder);
  506. allocator.Free(archive);
  507. } /* LZMA_dirClose */
  508. static int LZMA_remove(dvoid *opaque, const char *name)
  509. {
  510. BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
  511. } /* LZMA_remove */
  512. static int LZMA_mkdir(dvoid *opaque, const char *name)
  513. {
  514. BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
  515. } /* LZMA_mkdir */
  516. const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_LZMA =
  517. {
  518. "7Z",
  519. LZMA_ARCHIVE_DESCRIPTION,
  520. "Dennis Schridde <devurandom@gmx.net>",
  521. "http://icculus.org/physfs/",
  522. };
  523. const PHYSFS_Archiver __PHYSFS_Archiver_LZMA =
  524. {
  525. &__PHYSFS_ArchiveInfo_LZMA,
  526. LZMA_isArchive, /* isArchive() method */
  527. LZMA_openArchive, /* openArchive() method */
  528. LZMA_enumerateFiles, /* enumerateFiles() method */
  529. LZMA_exists, /* exists() method */
  530. LZMA_isDirectory, /* isDirectory() method */
  531. LZMA_isSymLink, /* isSymLink() method */
  532. LZMA_getLastModTime, /* getLastModTime() method */
  533. LZMA_openRead, /* openRead() method */
  534. LZMA_openWrite, /* openWrite() method */
  535. LZMA_openAppend, /* openAppend() method */
  536. LZMA_remove, /* remove() method */
  537. LZMA_mkdir, /* mkdir() method */
  538. LZMA_dirClose, /* dirClose() method */
  539. LZMA_read, /* read() method */
  540. LZMA_write, /* write() method */
  541. LZMA_eof, /* eof() method */
  542. LZMA_tell, /* tell() method */
  543. LZMA_seek, /* seek() method */
  544. LZMA_fileLength, /* fileLength() method */
  545. LZMA_fileClose /* fileClose() method */
  546. };
  547. #endif /* defined PHYSFS_SUPPORTS_7Z */
  548. /* end of lzma.c ... */