]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/xz/src/liblzma/common/vli_size.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / xz / 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 //  Author:     Lasse Collin
7 //
8 //  This file has been put into the public domain.
9 //  You can do whatever you want with this file.
10 //
11 ///////////////////////////////////////////////////////////////////////////////
12
13 #include "common.h"
14
15
16 extern LZMA_API(uint32_t)
17 lzma_vli_size(lzma_vli vli)
18 {
19         if (vli > LZMA_VLI_MAX)
20                 return 0;
21
22         uint32_t i = 0;
23         do {
24                 vli >>= 7;
25                 ++i;
26         } while (vli != 0);
27
28         assert(i <= LZMA_VLI_BYTES_MAX);
29         return i;
30 }