]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/filter_flags_decoder.c
Some API changes, bug fixes, cleanups etc.
[icculus/xz.git] / src / liblzma / common / filter_flags_decoder.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       filter_flags_decoder.c
4 /// \brief      Decodes a Filter Flags field
5 //
6 //  Copyright (C) 2007 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 "filter_decoder.h"
21
22
23 extern LZMA_API lzma_ret
24 lzma_filter_flags_decode(
25                 lzma_filter *filter, lzma_allocator *allocator,
26                 const uint8_t *in, size_t *in_pos, size_t in_size)
27 {
28         // Set the pointer to NULL so the caller can always safely free it.
29         filter->options = NULL;
30
31         // Filter ID
32         return_if_error(lzma_vli_decode(&filter->id, NULL,
33                         in, in_pos, in_size));
34
35         if (filter->id >= LZMA_FILTER_RESERVED_START)
36                 return LZMA_DATA_ERROR;
37
38         // Size of Properties
39         lzma_vli props_size;
40         return_if_error(lzma_vli_decode(&props_size, NULL,
41                         in, in_pos, in_size));
42
43         // Filter Properties
44         if (in_size - *in_pos < props_size)
45                 return LZMA_DATA_ERROR;
46
47         const lzma_ret ret = lzma_properties_decode(
48                         filter, allocator, in + *in_pos, props_size);
49
50         *in_pos += props_size;
51
52         return ret;
53 }