1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file block_header.c
4 /// \brief Utility functions to handle lzma_options_block
6 // Copyright (C) 2008 Lasse Collin
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.
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.
18 ///////////////////////////////////////////////////////////////////////////////
23 extern LZMA_API lzma_ret
24 lzma_block_total_size_set(lzma_options_block *options, lzma_vli total_size)
27 if (options->header_size < LZMA_BLOCK_HEADER_SIZE_MIN
28 || options->header_size > LZMA_BLOCK_HEADER_SIZE_MAX
29 || (options->header_size & 3)
30 || (unsigned)(options->check) > LZMA_CHECK_ID_MAX
32 return LZMA_PROG_ERROR;
34 const uint32_t container_size = options->header_size
35 + lzma_check_sizes[options->check];
37 // Validate that Compressed Size will be greater than zero.
38 if (container_size <= total_size)
39 return LZMA_DATA_ERROR;
41 options->compressed_size = total_size - container_size;
47 extern LZMA_API lzma_vli
48 lzma_block_total_size_get(const lzma_options_block *options)
50 // Validate the values that we are interested in.
51 if (options->header_size < LZMA_BLOCK_HEADER_SIZE_MIN
52 || options->header_size > LZMA_BLOCK_HEADER_SIZE_MAX
53 || (options->header_size & 3)
54 || (unsigned)(options->check) > LZMA_CHECK_ID_MAX)
57 // If Compressed Size is unknown, return that we cannot know
59 if (options->compressed_size == LZMA_VLI_VALUE_UNKNOWN)
60 return LZMA_VLI_VALUE_UNKNOWN;
62 const lzma_vli total_size = options->compressed_size
63 + options->header_size
64 + lzma_check_sizes[options->check];
66 // Validate the calculated Total Size.
67 if (options->compressed_size > LZMA_VLI_VALUE_MAX
68 || (options->compressed_size & 3)
69 || total_size > LZMA_VLI_VALUE_MAX)