Fix version.sh compatiblity with Solaris
[xz/debian.git] / src / liblzma / common / index.h
blob007e1188f25956f9e23e5eaaf6821018d05c5d25
1 // SPDX-License-Identifier: 0BSD
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 /// \file index.h
6 /// \brief Handling of Index
7 /// \note This header file does not include common.h or lzma.h because
8 /// this file is needed by both liblzma internally and by the
9 /// tests. Including common.h will include and define many things
10 /// the tests do not need and prevents issues with header file
11 /// include order. This way, if lzma.h or common.h are not
12 /// included before this file it will break on every OS instead
13 /// of causing more subtle errors.
15 // Author: Lasse Collin
17 ///////////////////////////////////////////////////////////////////////////////
19 #ifndef LZMA_INDEX_H
20 #define LZMA_INDEX_H
23 /// Minimum Unpadded Size
24 #define UNPADDED_SIZE_MIN LZMA_VLI_C(5)
26 /// Maximum Unpadded Size
27 #define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
29 /// Index Indicator based on xz specification
30 #define INDEX_INDICATOR 0
33 /// Get the size of the Index Padding field. This is needed by Index encoder
34 /// and decoder, but applications should have no use for this.
35 extern uint32_t lzma_index_padding_size(const lzma_index *i);
38 /// Set for how many Records to allocate memory the next time
39 /// lzma_index_append() needs to allocate space for a new Record.
40 /// This is used only by the Index decoder.
41 extern void lzma_index_prealloc(lzma_index *i, lzma_vli records);
44 /// Round the variable-length integer to the next multiple of four.
45 static inline lzma_vli
46 vli_ceil4(lzma_vli vli)
48 assert(vli <= UNPADDED_SIZE_MAX);
49 return (vli + 3) & ~LZMA_VLI_C(3);
53 /// Calculate the size of the Index field excluding Index Padding
54 static inline lzma_vli
55 index_size_unpadded(lzma_vli count, lzma_vli index_list_size)
57 // Index Indicator + Number of Records + List of Records + CRC32
58 return 1 + lzma_vli_size(count) + index_list_size + 4;
62 /// Calculate the size of the Index field including Index Padding
63 static inline lzma_vli
64 index_size(lzma_vli count, lzma_vli index_list_size)
66 return vli_ceil4(index_size_unpadded(count, index_list_size));
70 /// Calculate the total size of the Stream
71 static inline lzma_vli
72 index_stream_size(lzma_vli blocks_size,
73 lzma_vli count, lzma_vli index_list_size)
75 return LZMA_STREAM_HEADER_SIZE + blocks_size
76 + index_size(count, index_list_size)
77 + LZMA_STREAM_HEADER_SIZE;
80 #endif