1#include <linux/init.h>
2#include <linux/kernel.h>
3#include <linux/vmalloc.h>
4
5#include "LzmaDec.h"
6#include "LzmaDec.c"
7#include "sqlzma.h"
8
9static void *SzAlloc(void *p, size_t size) { p = p; return vmalloc(size); }
10static void SzFree(void *p, void *address) { p = p; vfree(address); }
11static ISzAlloc g_Alloc = { SzAlloc, SzFree };
12
13int LzmaUncompress(void *dst, int *dstlen, void *src, int srclen)
14{
15	int res;
16	SizeT inSizePure;
17	ELzmaStatus status;
18
19	if (srclen < LZMA_PROPS_SIZE)
20	{
21		memcpy(dst, src, srclen);
22		return srclen;
23	}
24	inSizePure = srclen - LZMA_PROPS_SIZE;
25	res = LzmaDecode(dst, dstlen, src + LZMA_PROPS_SIZE, &inSizePure,
26	                 src, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);
27	srclen = inSizePure ;
28
29	if ((res == SZ_OK) ||
30		((res == SZ_ERROR_INPUT_EOF) && (srclen == inSizePure)))
31		res = 0;
32	return res;
33}
34