]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/vli_size.c
Sort of garbage collection commit. :-| Many things are still
[icculus/xz.git] / src / liblzma / common / vli_size.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       vli_size.c
4 /// \brief      Calculates the encoded size of a variable-length integer
5 //
6 //  Copyright (C) 2007-2008 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 #include "common.h"
21
22
23 extern LZMA_API uint32_t
24 lzma_vli_size(lzma_vli vli)
25 {
26         if (vli > LZMA_VLI_VALUE_MAX)
27                 return 0;
28
29         uint32_t i = 0;
30         do {
31                 vli >>= 7;
32                 ++i;
33         } while (vli != 0);
34
35         assert(i <= LZMA_VLI_BYTES_MAX);
36         return i;
37 }