]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/block_private.h
Imported to git.
[icculus/xz.git] / src / liblzma / common / block_private.h
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       block_private.h
4 /// \brief      Common stuff for Block encoder and decoder
5 //
6 //  Copyright (C) 2007 Lasse Collin
7 //
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.
12 //
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.
17 //
18 ///////////////////////////////////////////////////////////////////////////////
19
20 #ifndef LZMA_BLOCK_COMMON_H
21 #define LZMA_BLOCK_COMMON_H
22
23 #include "common.h"
24
25 static inline bool
26 update_size(lzma_vli *size, lzma_vli add, lzma_vli limit)
27 {
28         if (limit > LZMA_VLI_VALUE_MAX)
29                 limit = LZMA_VLI_VALUE_MAX;
30
31         if (limit < *size || limit - *size < add)
32                 return true;
33
34         *size += add;
35
36         return false;
37 }
38
39
40 static inline bool
41 is_size_valid(lzma_vli size, lzma_vli reference)
42 {
43         return reference == LZMA_VLI_VALUE_UNKNOWN || reference == size;
44 }
45
46 #endif