1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file subblock_decoder_helper.c
4 /// \brief Helper filter for the Subblock decoder
6 /// This filter is used to indicate End of Input for subfilters needing it.
8 // Copyright (C) 2007 Lasse Collin
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "subblock_decoder_helper.h"
26 const lzma_options_subblock_helper *options;
31 helper_decode(lzma_coder *coder,
32 lzma_allocator *allocator lzma_attribute((unused)),
33 const uint8_t *restrict in, size_t *restrict in_pos,
34 size_t in_size, uint8_t *restrict out,
35 size_t *restrict out_pos, size_t out_size,
36 lzma_action action lzma_attribute((unused)))
38 // If end_was_reached is true, we cannot have any input.
39 assert(!coder->options->end_was_reached || *in_pos == in_size);
41 // We can safely copy as much as possible, because we are never
42 // given more data than a single Subblock Data field.
43 bufcpy(in, in_pos, in_size, out, out_pos, out_size);
45 // Return LZMA_STREAM_END when instructed so by the Subblock decoder.
46 return coder->options->end_was_reached ? LZMA_STREAM_END : LZMA_OK;
51 helper_end(lzma_coder *coder, lzma_allocator *allocator)
53 lzma_free(coder, allocator);
59 lzma_subblock_decoder_helper_init(lzma_next_coder *next,
60 lzma_allocator *allocator, const lzma_filter_info *filters)
62 // This is always the last filter in the chain.
63 assert(filters[1].init == NULL);
65 if (next->coder == NULL) {
66 next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
67 if (next->coder == NULL)
68 return LZMA_MEM_ERROR;
70 next->code = &helper_decode;
71 next->end = &helper_end;
74 next->coder->options = filters[0].options;