summaryrefslogtreecommitdiffstats
path: root/depends/lzma/wrapper/lzip_header.c
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-09-26 02:58:09 +0200
committerPetr Mrázek <peterix@gmail.com>2013-09-26 02:59:56 +0200
commit2c8dc0b855c38c5204d398ad306fa9cf43be1ada (patch)
tree59429d658012a3df0e548e1a5f08100fb2930fc0 /depends/lzma/wrapper/lzip_header.c
parentaf234f35029de8c46aefecd8b9345b30ae1c51b0 (diff)
downloadMultiMC-2c8dc0b855c38c5204d398ad306fa9cf43be1ada.tar
MultiMC-2c8dc0b855c38c5204d398ad306fa9cf43be1ada.tar.gz
MultiMC-2c8dc0b855c38c5204d398ad306fa9cf43be1ada.tar.lz
MultiMC-2c8dc0b855c38c5204d398ad306fa9cf43be1ada.tar.xz
MultiMC-2c8dc0b855c38c5204d398ad306fa9cf43be1ada.zip
Compression algo dependencies, still need hackery...
Diffstat (limited to 'depends/lzma/wrapper/lzip_header.c')
-rw-r--r--depends/lzma/wrapper/lzip_header.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/depends/lzma/wrapper/lzip_header.c b/depends/lzma/wrapper/lzip_header.c
new file mode 100644
index 00000000..39872813
--- /dev/null
+++ b/depends/lzma/wrapper/lzip_header.c
@@ -0,0 +1,96 @@
+#include "lzip_header.h"
+
+#include <string.h>
+
+#define ELZMA_LZIP_HEADER_SIZE 6
+#define ELZMA_LZIP_FOOTER_SIZE 12
+
+static void initLzipHeader(struct elzma_file_header *hdr)
+{
+ memset((void *)hdr, 0, sizeof(struct elzma_file_header));
+}
+
+static int parseLzipHeader(const unsigned char *hdrBuf, struct elzma_file_header *hdr)
+{
+ if (0 != strncmp("LZIP", (char *)hdrBuf, 4))
+ return 1;
+ /* XXX: ignore version for now */
+ hdr->pb = 2;
+ hdr->lp = 0;
+ hdr->lc = 3;
+ /* unknown at this point */
+ hdr->isStreamed = 1;
+ hdr->uncompressedSize = 0;
+ hdr->dictSize = 1 << (hdrBuf[5] & 0x1F);
+ return 0;
+}
+
+static int serializeLzipHeader(unsigned char *hdrBuf, const struct elzma_file_header *hdr)
+{
+ hdrBuf[0] = 'L';
+ hdrBuf[1] = 'Z';
+ hdrBuf[2] = 'I';
+ hdrBuf[3] = 'P';
+ hdrBuf[4] = 0;
+ {
+ int r = 0;
+ while ((hdr->dictSize >> r) != 0)
+ r++;
+ hdrBuf[5] = (unsigned char)(r - 1) & 0x1F;
+ }
+ return 0;
+}
+
+static int serializeLzipFooter(struct elzma_file_footer *ftr, unsigned char *ftrBuf)
+{
+ unsigned int i = 0;
+
+ /* first crc32 */
+ for (i = 0; i < 4; i++)
+ {
+ *(ftrBuf++) = (unsigned char)(ftr->crc32 >> (i * 8));
+ }
+
+ /* next data size */
+ for (i = 0; i < 8; i++)
+ {
+ *(ftrBuf++) = (unsigned char)(ftr->uncompressedSize >> (i * 8));
+ }
+
+ /* write version 0 files, omit member length for now*/
+
+ return 0;
+}
+
+static int parseLzipFooter(const unsigned char *ftrBuf, struct elzma_file_footer *ftr)
+{
+ unsigned int i = 0;
+ ftr->crc32 = 0;
+ ftr->uncompressedSize = 0;
+
+ /* first crc32 */
+ for (i = 0; i < 4; i++)
+ {
+ ftr->crc32 += ((unsigned int)*(ftrBuf++) << (i * 8));
+ }
+
+ /* next data size */
+ for (i = 0; i < 8; i++)
+ {
+ ftr->uncompressedSize += (unsigned long long)*(ftrBuf++) << (i * 8);
+ }
+ /* read version 0 files, omit member length for now*/
+
+ return 0;
+}
+
+void initializeLZIPFormatHandler(struct elzma_format_handler *hand)
+{
+ hand->header_size = ELZMA_LZIP_HEADER_SIZE;
+ hand->init_header = initLzipHeader;
+ hand->parse_header = parseLzipHeader;
+ hand->serialize_header = serializeLzipHeader;
+ hand->footer_size = ELZMA_LZIP_FOOTER_SIZE;
+ hand->serialize_footer = serializeLzipFooter;
+ hand->parse_footer = parseLzipFooter;
+}