summaryrefslogtreecommitdiffstats
path: root/depends/lzma/wrapper/common_internal.h
blob: 2c46fadf047f448d7df28aed62a91f31f09ae1bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef __ELZMA_COMMON_INTERNAL_H__
#define __ELZMA_COMMON_INTERNAL_H__

#include "common.h"

/** a structure which may be cast and passed into Igor's allocate
 *  routines */
struct elzma_alloc_struct
{
	void *(*Alloc)(void *p, size_t size);
	void (*Free)(void *p, void *address); /* address can be 0 */

	elzma_malloc clientMallocFunc;
	void *clientMallocContext;

	elzma_free clientFreeFunc;
	void *clientFreeContext;
};

/* initialize an allocation structure, may be called safely multiple
 * times */
void init_alloc_struct(struct elzma_alloc_struct *allocStruct, elzma_malloc clientMallocFunc,
					   void *clientMallocContext, elzma_free clientFreeFunc,
					   void *clientFreeContext);

/** superset representation of a compressed file header */
struct elzma_file_header
{
	unsigned char pb;
	unsigned char lp;
	unsigned char lc;
	unsigned char isStreamed;
	long long unsigned int uncompressedSize;
	unsigned int dictSize;
};

/** superset representation of a compressed file footer */
struct elzma_file_footer
{
	unsigned int crc32;
	long long unsigned int uncompressedSize;
};

/** a structure which encapsulates information about the particular
 *  file header and footer in use (lzip vs lzma vs (eventually) xz.
 *  The intention of this structure is to simplify compression and
 *  decompression logic by abstracting the file format details a bit.  */
struct elzma_format_handler
{
	unsigned int header_size;
	void (*init_header)(struct elzma_file_header *hdr);
	int (*parse_header)(const unsigned char *hdrBuf, struct elzma_file_header *hdr);
	int (*serialize_header)(unsigned char *hdrBuf, const struct elzma_file_header *hdr);

	unsigned int footer_size;
	int (*serialize_footer)(struct elzma_file_footer *ftr, unsigned char *ftrBuf);
	int (*parse_footer)(const unsigned char *ftrBuf, struct elzma_file_footer *ftr);
};

#endif