"Fossies" - the Fresh Open Source Software Archive

Member "zutils-1.10/zcmpdiff.cc" (5 Jan 2021, 2414 Bytes) of package /linux/privat/zutils-1.10.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 "zcmpdiff.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes reports: 1.10-rc1_vs_1.10 or 1.9_vs_1.10.

    1 /* Common code for zcmp and zdiff
    2    Copyright (C) 2010-2021 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 O_BINARY
   19 #define O_BINARY 0
   20 #endif
   21 
   22 
   23 int open_instream( const std::string & input_filename )
   24   {
   25   const int infd = open( input_filename.c_str(), O_RDONLY | O_BINARY );
   26   if( infd < 0 )
   27     show_file_error( input_filename.c_str(), "Can't open input file", errno );
   28   return infd;
   29   }
   30 
   31 
   32 int open_other_instream( std::string & name )
   33   {
   34   const int eindex = extension_index( name );
   35   if( eindex >= 0 && enabled_format( -1 ) )
   36     {                   // open uncompressed version
   37     name.resize( name.size() - std::strlen( extension_from( eindex ) ) );
   38     name += extension_to( eindex );
   39     return open( name.c_str(), O_RDONLY | O_BINARY );
   40     }
   41   if( eindex < 0 )          // search compressed version
   42     for( int i = 0; i < num_formats; ++i )
   43       if( enabled_format( format_order[i] ) )
   44         {
   45         const std::string s( name + simple_extensions[format_order[i]] );
   46         const int infd = open( s.c_str(), O_RDONLY | O_BINARY );
   47         if( infd >= 0 ) { name = s; return infd; }
   48         }
   49   return -1;
   50   }
   51 
   52 
   53 void parse_format_types2( const std::string & arg, int format_types[2] )
   54   {
   55   const unsigned i = std::min( arg.find( ',' ), arg.size() );
   56   if( i > 0 ) format_types[0] = parse_format_type( arg.substr( 0, i ) );
   57   else format_types[0] = -1;
   58   if( i + 1 < arg.size() ) format_types[1] =
   59     parse_format_type( arg.substr( i + 1 ) );
   60   else format_types[1] = -1;
   61   }
   62 
   63 
   64 bool check_identical( const char * const name1, const char * const name2 )
   65   {
   66   if( std::strcmp( name1, name2 ) == 0 ) return true;
   67   struct stat stat1, stat2;
   68   if( stat( name1, &stat1 ) || stat( name2, &stat2 ) ) return false;
   69   return ( stat1.st_ino == stat2.st_ino && stat1.st_dev == stat2.st_dev );
   70   }