]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/simple/simple_decoder.c
d7c17e2fdf022c924aa37feac833511349110b7b
[icculus/xz.git] / src / liblzma / simple / simple_decoder.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       simple_decoder.c
4 /// \brief      Properties decoder for simple filters
5 //
6 //  Copyright (C) 2007-2008 Lasse Collin
7 //
8 //  This library is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU Lesser General Public
10 //  License as published by the Free Software Foundation; either
11 //  version 2.1 of the License, or (at your option) any later version.
12 //
13 //  This library is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 //  Lesser General Public License for more details.
17 //
18 ///////////////////////////////////////////////////////////////////////////////
19
20 #include "simple_decoder.h"
21
22
23 extern lzma_ret
24 lzma_simple_props_decode(void **options, lzma_allocator *allocator,
25                 const uint8_t *props, size_t props_size)
26 {
27         if (props_size == 0)
28                 return LZMA_OK;
29
30         if (props_size != 4)
31                 return LZMA_OPTIONS_ERROR;
32
33         lzma_options_bcj *opt = lzma_alloc(
34                         sizeof(lzma_options_bcj), allocator);
35         if (opt == NULL)
36                 return LZMA_MEM_ERROR;
37
38         opt->start_offset = integer_read_32(props);
39
40         // Don't leave an options structure allocated if start_offset is zero.
41         if (opt->start_offset == 0)
42                 lzma_free(opt, allocator);
43         else
44                 *options = opt;
45
46         return LZMA_OK;
47 }