simple_decoder.c 913 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // SPDX-License-Identifier: 0BSD
  2. ///////////////////////////////////////////////////////////////////////////////
  3. //
  4. /// \file simple_decoder.c
  5. /// \brief Properties decoder for simple filters
  6. //
  7. // Author: Lasse Collin
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #include "simple_decoder.h"
  11. extern lzma_ret
  12. lzma_simple_props_decode(void **options, const lzma_allocator *allocator,
  13. const uint8_t *props, size_t props_size)
  14. {
  15. if (props_size == 0)
  16. return LZMA_OK;
  17. if (props_size != 4)
  18. return LZMA_OPTIONS_ERROR;
  19. lzma_options_bcj *opt = lzma_alloc(
  20. sizeof(lzma_options_bcj), allocator);
  21. if (opt == NULL)
  22. return LZMA_MEM_ERROR;
  23. opt->start_offset = read32le(props);
  24. // Don't leave an options structure allocated if start_offset is zero.
  25. if (opt->start_offset == 0)
  26. lzma_free(opt, allocator);
  27. else
  28. *options = opt;
  29. return LZMA_OK;
  30. }