2 * coreboot interface to memory-saving variant of LZMA decoder
4 * Copyright (C) 2006 Carl-Daniel Hailfinger
5 * Released under the BSD license
7 * Parts of this file are based on C/7zip/Compress/LZMA_C/LzmaTest.c from the LZMA
8 * SDK 4.42, which is written and distributed to public domain by Igor Pavlov.
16 #include "lzmadecode.c"
18 unsigned long ulzman(const unsigned char *src
, unsigned long srcn
,
19 unsigned char *dst
, unsigned long dstn
)
21 unsigned char properties
[LZMA_PROPERTIES_SIZE
];
22 const int data_offset
= LZMA_PROPERTIES_SIZE
+ 8;
27 CLzmaDecoderState state
;
29 unsigned char *scratchpad
;
31 if (srcn
< data_offset
) {
32 printf("lzma: Input too small.\n");
36 memcpy(properties
, src
, LZMA_PROPERTIES_SIZE
);
37 memcpy(&outSize
, src
+ LZMA_PROPERTIES_SIZE
, sizeof(outSize
));
40 if (LzmaDecodeProperties(&state
.Properties
, properties
,
41 LZMA_PROPERTIES_SIZE
) != LZMA_RESULT_OK
) {
42 printf("lzma: Incorrect stream properties.\n");
45 mallocneeds
= (LzmaGetNumProbs(&state
.Properties
) * sizeof(CProb
));
46 scratchpad
= malloc(mallocneeds
);
48 printf("lzma: Cannot allocate %u bytes for scratchpad!\n",
52 state
.Probs
= (CProb
*)scratchpad
;
53 res
= LzmaDecode(&state
, src
+ data_offset
, srcn
- data_offset
,
54 &inProcessed
, dst
, outSize
, &outProcessed
);
57 printf("lzma: Decoding error = %d\n", res
);
63 unsigned long ulzma(const unsigned char *src
, unsigned char *dst
)
65 return ulzman(src
, (unsigned long)(-1), dst
, (unsigned long)(-1));