"Fossies" - the Fresh Open Source Software Archive

Member "lzip-1.22-rc2/lzip_index.h" (30 Apr 2020, 3084 Bytes) of package /linux/misc/lzip-1.22-rc2.tar.lz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "lzip_index.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.21_vs_1.22-rc1.

    1 /* Lzip - LZMA lossless data compressor
    2    Copyright (C) 2008-2020 Antonio Diaz Diaz.
    3 
    4    This program is free software: you can redistribute it and/or modify
    5    it under the terms of the GNU General Public License as published by
    6    the Free Software Foundation, either version 2 of the License, or
    7    (at your option) any later version.
    8 
    9    This program is distributed in the hope that it will be useful,
   10    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12    GNU General Public License for more details.
   13 
   14    You should have received a copy of the GNU General Public License
   15    along with this program.  If not, see <http://www.gnu.org/licenses/>.
   16 */
   17 
   18 #ifndef INT64_MAX
   19 #define INT64_MAX  0x7FFFFFFFFFFFFFFFLL
   20 #endif
   21 
   22 
   23 class Block
   24   {
   25   long long pos_, size_;        // pos + size <= INT64_MAX
   26 
   27 public:
   28   Block( const long long p, const long long s ) : pos_( p ), size_( s ) {}
   29 
   30   long long pos() const { return pos_; }
   31   long long size() const { return size_; }
   32   long long end() const { return pos_ + size_; }
   33 
   34   void pos( const long long p ) { pos_ = p; }
   35   void size( const long long s ) { size_ = s; }
   36   };
   37 
   38 
   39 class Lzip_index
   40   {
   41   struct Member
   42     {
   43     Block dblock, mblock;       // data block, member block
   44     unsigned dictionary_size;
   45 
   46     Member( const long long dp, const long long ds,
   47             const long long mp, const long long ms, const unsigned dict_size )
   48       : dblock( dp, ds ), mblock( mp, ms ), dictionary_size( dict_size ) {}
   49     };
   50 
   51   std::vector< Member > member_vector;
   52   std::string error_;
   53   const long long insize;
   54   int retval_;
   55   unsigned dictionary_size_;    // largest dictionary size in the file
   56 
   57   bool check_header_error( const Lzip_header & header );
   58   void set_errno_error( const char * const msg );
   59   void set_num_error( const char * const msg, unsigned long long num );
   60   bool read_header( const int fd, Lzip_header & header, const long long pos );
   61   bool skip_trailing_data( const int fd, unsigned long long & pos,
   62          const bool ignore_trailing, const bool loose_trailing );
   63 
   64 public:
   65   Lzip_index( const int infd, const bool ignore_trailing,
   66               const bool loose_trailing );
   67 
   68   long members() const { return member_vector.size(); }
   69   const std::string & error() const { return error_; }
   70   int retval() const { return retval_; }
   71   unsigned dictionary_size() const { return dictionary_size_; }
   72 
   73   long long udata_size() const
   74     { if( member_vector.empty() ) return 0;
   75       return member_vector.back().dblock.end(); }
   76 
   77   long long cdata_size() const
   78     { if( member_vector.empty() ) return 0;
   79       return member_vector.back().mblock.end(); }
   80 
   81   // total size including trailing data (if any)
   82   long long file_size() const
   83     { if( insize >= 0 ) return insize; else return 0; }
   84 
   85   const Block & dblock( const long i ) const
   86     { return member_vector[i].dblock; }
   87   const Block & mblock( const long i ) const
   88     { return member_vector[i].mblock; }
   89   unsigned dictionary_size( const long i ) const
   90     { return member_vector[i].dictionary_size; }
   91   };