summaryrefslogtreecommitdiffstats
path: root/pdlzip.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--pdlzip.h35
1 files changed, 19 insertions, 16 deletions
diff --git a/pdlzip.h b/pdlzip.h
index 604f508..5af155b 100644
--- a/pdlzip.h
+++ b/pdlzip.h
@@ -39,7 +39,7 @@ static inline void CRC32_init()
{
unsigned int c = n;
for( int k = 0; k < 8; ++k )
- { if( c & 1 ) c = 0xEDB88320 ^ ( c >> 1 ); else c >>= 1; }
+ { if( c & 1 ) c = 0xEDB88320U ^ ( c >> 1 ); else c >>= 1; }
crc32[n] = c;
}
}
@@ -57,6 +57,7 @@ static inline void CRC32_update_buf( uint32_t * crc, const uint8_t * const buffe
typedef uint8_t File_header[6]; // 0-3 magic bytes
// 4 version
// 5 coded_dict_size;
+enum { Fh_size = 6 };
static inline void Fh_set_magic( File_header header )
{
@@ -87,23 +88,23 @@ static inline int Fh_real_bits( const int value )
static inline int Fh_get_dictionary_size( const File_header header )
{
- int size = ( 1 << ( header[5] & 0x1F ) );
- if( size > min_dictionary_size && size <= max_dictionary_size )
- size -= ( size / 16 ) * ( ( header[5] >> 5 ) & 0x07 );
- return size;
+ int sz = ( 1 << ( header[5] & 0x1F ) );
+ if( sz > min_dictionary_size && sz <= max_dictionary_size )
+ sz -= ( sz / 16 ) * ( ( header[5] >> 5 ) & 0x07 );
+ return sz;
}
-static inline bool Fh_set_dictionary_size( File_header header, const int size )
+static inline bool Fh_set_dictionary_size( File_header header, const int sz )
{
- if( size >= min_dictionary_size && size <= max_dictionary_size )
+ if( sz >= min_dictionary_size && sz <= max_dictionary_size )
{
- header[5] = Fh_real_bits( size - 1 );
- if( size > min_dictionary_size )
+ header[5] = Fh_real_bits( sz - 1 );
+ if( sz > min_dictionary_size )
{
const int base_size = 1 << header[5];
const int wedge = base_size / 16;
for( int i = 7; i >= 1; --i )
- if( base_size - ( i * wedge ) >= size )
+ if( base_size - ( i * wedge ) >= sz )
{ header[5] |= ( i << 5 ); break; }
}
return true;
@@ -117,8 +118,10 @@ typedef uint8_t File_trailer[20];
// 4-11 size of the uncompressed data
// 12-19 member size including header and trailer
-static inline int Ft_size( const int version )
- { return sizeof (File_trailer) - ( ( version >= 1 ) ? 0 : 8 ); }
+enum { Ft_size = 20 };
+
+static inline int Ft_versioned_size( const int version )
+ { return ( ( version >= 1 ) ? 20 : 12 ); }
static inline uint32_t Ft_get_data_crc( const File_trailer trailer )
{
@@ -137,9 +140,9 @@ static inline long long Ft_get_data_size( const File_trailer trailer )
return tmp;
}
-static inline void Ft_set_data_size( File_trailer trailer, long long size )
+static inline void Ft_set_data_size( File_trailer trailer, long long sz )
{
- for( int i = 4; i <= 11; ++i ) { trailer[i] = (uint8_t)size; size >>= 8; }
+ for( int i = 4; i <= 11; ++i ) { trailer[i] = (uint8_t)sz; sz >>= 8; }
}
static inline long long Ft_get_member_size( const File_trailer trailer )
@@ -149,9 +152,9 @@ static inline long long Ft_get_member_size( const File_trailer trailer )
return tmp;
}
-static inline void Ft_set_member_size( File_trailer trailer, long long size )
+static inline void Ft_set_member_size( File_trailer trailer, long long sz )
{
- for( int i = 12; i <= 19; ++i ) { trailer[i] = (uint8_t)size; size >>= 8; }
+ for( int i = 12; i <= 19; ++i ) { trailer[i] = (uint8_t)sz; sz >>= 8; }
}