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

                                

                                                                               

                                                                        
  
                            
  

                                                                               

                   
 
                         

                           
                               






                           
 


                                        
// SPDX-License-Identifier: 0BSD

///////////////////////////////////////////////////////////////////////////////
//
/// \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;
}