2025-02-17 20:49:14 +01:00
|
|
|
/* Clzip - LZMA lossless data compressor
|
2025-02-17 20:53:44 +01:00
|
|
|
Copyright (C) 2010-2024 Antonio Diaz Diaz.
|
2025-02-17 20:44:01 +01:00
|
|
|
|
2025-02-17 20:49:14 +01:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2025-02-17 20:44:01 +01:00
|
|
|
|
2025-02-17 20:49:14 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2025-02-17 20:44:01 +01:00
|
|
|
|
2025-02-17 20:49:14 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2025-02-17 20:44:01 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INT64_MAX
|
2025-02-17 20:53:19 +01:00
|
|
|
#define INT64_MAX 0x7FFFFFFFFFFFFFFFLL
|
2025-02-17 20:44:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
typedef struct Block
|
2025-02-17 20:44:01 +01:00
|
|
|
{
|
2025-02-17 20:53:19 +01:00
|
|
|
long long pos, size; /* pos >= 0, size >= 0, pos + size <= INT64_MAX */
|
2025-02-17 20:54:18 +01:00
|
|
|
} Block;
|
2025-02-17 20:44:01 +01:00
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
static inline void init_block( Block * const b,
|
2025-02-17 20:44:01 +01:00
|
|
|
const long long p, const long long s )
|
|
|
|
{ b->pos = p; b->size = s; }
|
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
static inline long long block_end( const Block b ) { return b.pos + b.size; }
|
2025-02-17 20:44:01 +01:00
|
|
|
|
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
typedef struct Member
|
2025-02-17 20:44:01 +01:00
|
|
|
{
|
2025-02-17 20:54:18 +01:00
|
|
|
Block dblock, mblock; /* data block, member block */
|
2025-02-17 20:44:01 +01:00
|
|
|
unsigned dictionary_size;
|
2025-02-17 20:54:18 +01:00
|
|
|
} Member;
|
2025-02-17 20:44:01 +01:00
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
static inline void init_member( Member * const m, const long long dpos,
|
|
|
|
const long long dsize, const long long mpos,
|
|
|
|
const long long msize, const unsigned dict_size )
|
|
|
|
{ init_block( &m->dblock, dpos, dsize );
|
|
|
|
init_block( &m->mblock, mpos, msize ); m->dictionary_size = dict_size; }
|
2025-02-17 20:44:01 +01:00
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
typedef struct Lzip_index
|
2025-02-17 20:44:01 +01:00
|
|
|
{
|
2025-02-17 20:54:18 +01:00
|
|
|
Member * member_vector;
|
2025-02-17 20:44:01 +01:00
|
|
|
char * error;
|
2025-02-17 20:46:36 +01:00
|
|
|
long long insize;
|
2025-02-17 20:44:01 +01:00
|
|
|
long members;
|
|
|
|
int error_size;
|
|
|
|
int retval;
|
2025-02-17 20:49:14 +01:00
|
|
|
unsigned dictionary_size; /* largest dictionary size in the file */
|
2025-02-17 20:54:18 +01:00
|
|
|
} Lzip_index;
|
2025-02-17 20:44:01 +01:00
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
bool Li_init( Lzip_index * const li, const int infd,
|
|
|
|
const Cl_options * const cl_opts );
|
2025-02-17 20:44:01 +01:00
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
void Li_free( Lzip_index * const li );
|
2025-02-17 20:44:01 +01:00
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
/* multimember file with empty member(s) */
|
|
|
|
static inline bool Li_multi_empty( Lzip_index * const li )
|
|
|
|
{
|
|
|
|
long i;
|
|
|
|
if( li->members > 1 )
|
|
|
|
for( i = 0; i < li->members; ++i )
|
|
|
|
if( li->member_vector[i].dblock.size == 0 ) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline long long Li_udata_size( const Lzip_index * const li )
|
2025-02-17 20:44:01 +01:00
|
|
|
{
|
2025-02-17 20:46:36 +01:00
|
|
|
if( li->members <= 0 ) return 0;
|
|
|
|
return block_end( li->member_vector[li->members-1].dblock );
|
2025-02-17 20:44:01 +01:00
|
|
|
}
|
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
static inline long long Li_cdata_size( const Lzip_index * const li )
|
2025-02-17 20:44:01 +01:00
|
|
|
{
|
2025-02-17 20:46:36 +01:00
|
|
|
if( li->members <= 0 ) return 0;
|
|
|
|
return block_end( li->member_vector[li->members-1].mblock );
|
2025-02-17 20:44:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* total size including trailing data (if any) */
|
2025-02-17 20:54:18 +01:00
|
|
|
static inline long long Li_file_size( const Lzip_index * const li )
|
2025-02-17 20:46:36 +01:00
|
|
|
{ if( li->insize >= 0 ) return li->insize; else return 0; }
|
2025-02-17 20:44:01 +01:00
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
static inline const Block * Li_dblock( const Lzip_index * const li,
|
|
|
|
const long i )
|
2025-02-17 20:46:36 +01:00
|
|
|
{ return &li->member_vector[i].dblock; }
|
2025-02-17 20:44:01 +01:00
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
static inline const Block * Li_mblock( const Lzip_index * const li,
|
|
|
|
const long i )
|
2025-02-17 20:46:36 +01:00
|
|
|
{ return &li->member_vector[i].mblock; }
|
2025-02-17 20:44:01 +01:00
|
|
|
|
2025-02-17 20:54:18 +01:00
|
|
|
static inline unsigned Li_dictionary_size( const Lzip_index * const li,
|
2025-02-17 20:44:01 +01:00
|
|
|
const long i )
|
2025-02-17 20:46:36 +01:00
|
|
|
{ return li->member_vector[i].dictionary_size; }
|