xz/src/liblzma/common/filter_flags_decoder.c

47 lines
1.2 KiB
C
Raw Normal View History

2007-12-08 22:42:33 +00:00
///////////////////////////////////////////////////////////////////////////////
//
/// \file filter_flags_decoder.c
/// \brief Decodes a Filter Flags field
//
// Author: Lasse Collin
2007-12-08 22:42:33 +00:00
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
2007-12-08 22:42:33 +00:00
//
///////////////////////////////////////////////////////////////////////////////
#include "filter_decoder.h"
2007-12-08 22:42:33 +00:00
extern LZMA_API(lzma_ret)
lzma_filter_flags_decode(
lzma_filter *filter, lzma_allocator *allocator,
const uint8_t *in, size_t *in_pos, size_t in_size)
2007-12-08 22:42:33 +00:00
{
// Set the pointer to NULL so the caller can always safely free it.
filter->options = NULL;
2007-12-08 22:42:33 +00:00
// Filter ID
return_if_error(lzma_vli_decode(&filter->id, NULL,
in, in_pos, in_size));
2007-12-08 22:42:33 +00:00
if (filter->id >= LZMA_FILTER_RESERVED_START)
return LZMA_DATA_ERROR;
// Size of Properties
lzma_vli props_size;
return_if_error(lzma_vli_decode(&props_size, NULL,
in, in_pos, in_size));
2007-12-08 22:42:33 +00:00
// Filter Properties
if (in_size - *in_pos < props_size)
return LZMA_DATA_ERROR;
2007-12-08 22:42:33 +00:00
const lzma_ret ret = lzma_properties_decode(
filter, allocator, in + *in_pos, props_size);
2007-12-08 22:42:33 +00:00
*in_pos += props_size;
2007-12-08 22:42:33 +00:00
return ret;
2007-12-08 22:42:33 +00:00
}