aboutsummaryrefslogblamecommitdiff
path: root/src/liblzma/common/vli_size.c
blob: 65d11b9ae4a7dce5ef9aaba4b8d463bbbcfc2d5b (plain) (tree)
1
2
3
4
5
6
7
8
9

                                                                               

                                                                        
  
                            
  

                                                                               

                   
 
                         

                           
                               






                           
 


                                        
///////////////////////////////////////////////////////////////////////////////
//
/// \file       vli_size.c
/// \brief      Calculates the encoded size of a variable-length integer
//
//  Author:     Lasse Collin
//
///////////////////////////////////////////////////////////////////////////////

#include "common.h"


extern LZMA_API(uint32_t)
lzma_vli_size(lzma_vli vli)
{
	if (vli > LZMA_VLI_MAX)
		return 0;

	uint32_t i = 0;
	do {
		vli >>= 7;
		++i;
	} while (vli != 0);

	assert(i <= LZMA_VLI_BYTES_MAX);
	return i;
}