Path: blob/master/Utilities/cmliblzma/liblzma/common/index.h
3153 views
// SPDX-License-Identifier: 0BSD12///////////////////////////////////////////////////////////////////////////////3//4/// \file index.h5/// \brief Handling of Index6/// \note This header file does not include common.h or lzma.h because7/// this file is needed by both liblzma internally and by the8/// tests. Including common.h will include and define many things9/// the tests do not need and prevents issues with header file10/// include order. This way, if lzma.h or common.h are not11/// included before this file it will break on every OS instead12/// of causing more subtle errors.13//14// Author: Lasse Collin15//16///////////////////////////////////////////////////////////////////////////////1718#ifndef LZMA_INDEX_H19#define LZMA_INDEX_H202122/// Minimum Unpadded Size23#define UNPADDED_SIZE_MIN LZMA_VLI_C(5)2425/// Maximum Unpadded Size26#define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))2728/// Index Indicator based on xz specification29#define INDEX_INDICATOR 0303132/// Get the size of the Index Padding field. This is needed by Index encoder33/// and decoder, but applications should have no use for this.34extern uint32_t lzma_index_padding_size(const lzma_index *i);353637/// Set for how many Records to allocate memory the next time38/// lzma_index_append() needs to allocate space for a new Record.39/// This is used only by the Index decoder.40extern void lzma_index_prealloc(lzma_index *i, lzma_vli records);414243/// Round the variable-length integer to the next multiple of four.44static inline lzma_vli45vli_ceil4(lzma_vli vli)46{47assert(vli <= UNPADDED_SIZE_MAX);48return (vli + 3) & ~LZMA_VLI_C(3);49}505152/// Calculate the size of the Index field excluding Index Padding53static inline lzma_vli54index_size_unpadded(lzma_vli count, lzma_vli index_list_size)55{56// Index Indicator + Number of Records + List of Records + CRC3257return 1 + lzma_vli_size(count) + index_list_size + 4;58}596061/// Calculate the size of the Index field including Index Padding62static inline lzma_vli63index_size(lzma_vli count, lzma_vli index_list_size)64{65return vli_ceil4(index_size_unpadded(count, index_list_size));66}676869/// Calculate the total size of the Stream70static inline lzma_vli71index_stream_size(lzma_vli blocks_size,72lzma_vli count, lzma_vli index_list_size)73{74return LZMA_STREAM_HEADER_SIZE + blocks_size75+ index_size(count, index_list_size)76+ LZMA_STREAM_HEADER_SIZE;77}7879#endif808182