stream_flags_common.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: 0BSD
  2. ///////////////////////////////////////////////////////////////////////////////
  3. //
  4. /// \file stream_flags_common.c
  5. /// \brief Common stuff for Stream flags coders
  6. //
  7. // Author: Lasse Collin
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #include "stream_flags_common.h"
  11. const uint8_t lzma_header_magic[6] = { 0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00 };
  12. const uint8_t lzma_footer_magic[2] = { 0x59, 0x5A };
  13. extern LZMA_API(lzma_ret)
  14. lzma_stream_flags_compare(
  15. const lzma_stream_flags *a, const lzma_stream_flags *b)
  16. {
  17. // We can compare only version 0 structures.
  18. if (a->version != 0 || b->version != 0)
  19. return LZMA_OPTIONS_ERROR;
  20. // Check type
  21. if ((unsigned int)(a->check) > LZMA_CHECK_ID_MAX
  22. || (unsigned int)(b->check) > LZMA_CHECK_ID_MAX)
  23. return LZMA_PROG_ERROR;
  24. if (a->check != b->check)
  25. return LZMA_DATA_ERROR;
  26. // Backward Sizes are compared only if they are known in both.
  27. if (a->backward_size != LZMA_VLI_UNKNOWN
  28. && b->backward_size != LZMA_VLI_UNKNOWN) {
  29. if (!is_backward_size_valid(a) || !is_backward_size_valid(b))
  30. return LZMA_PROG_ERROR;
  31. if (a->backward_size != b->backward_size)
  32. return LZMA_DATA_ERROR;
  33. }
  34. return LZMA_OK;
  35. }