summaryrefslogtreecommitdiffstats
path: root/zcmpdiff.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-23 05:54:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-23 05:54:13 +0000
commite50d8921980602c5569b31dd9d12a24b43a196e8 (patch)
treed7240fd2cd209b129f72dac13832b6cfce13dc76 /zcmpdiff.cc
parentReleasing debian version 1.12-3. (diff)
downloadzutils-e50d8921980602c5569b31dd9d12a24b43a196e8.tar.xz
zutils-e50d8921980602c5569b31dd9d12a24b43a196e8.zip
Merging upstream version 1.13~rc1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'zcmpdiff.cc')
-rw-r--r--zcmpdiff.cc33
1 files changed, 19 insertions, 14 deletions
diff --git a/zcmpdiff.cc b/zcmpdiff.cc
index bbbc87e..961a32a 100644
--- a/zcmpdiff.cc
+++ b/zcmpdiff.cc
@@ -31,21 +31,26 @@ int open_instream( const std::string & input_filename )
int open_other_instream( std::string & name )
{
- const int eindex = extension_index( name );
- if( eindex >= 0 && enabled_format( -1 ) )
- { // open uncompressed version
- name.resize( name.size() - std::strlen( extension_from( eindex ) ) );
- name += extension_to( eindex );
- return open( name.c_str(), O_RDONLY | O_BINARY );
+ const int eindex = extension_index( name ); // search extension
+ if( eindex >= 0 && enabled_format( -1 ) ) // open uncompressed version
+ {
+ std::string s( name, 0, name.size() - std::strlen( extension_from( eindex ) ) );
+ s += extension_to( eindex );
+ const int infd = open( s.c_str(), O_RDONLY | O_BINARY );
+ if( infd >= 0 ) { name = s; return infd; }
+ }
+ const int eformat = extension_format( eindex );
+ for( int i = 0; i < num_formats; ++i ) // search compressed version
+ {
+ const int format_index = format_order[i];
+ if( eformat != format_index && enabled_format( format_index ) )
+ {
+ std::string s( name, 0, name.size() - std::strlen( extension_from( eindex ) ) );
+ s += simple_extensions[format_index];
+ const int infd = open( s.c_str(), O_RDONLY | O_BINARY );
+ if( infd >= 0 ) { name = s; return infd; }
+ }
}
- if( eindex < 0 ) // search compressed version
- for( int i = 0; i < num_formats; ++i )
- if( enabled_format( format_order[i] ) )
- {
- const std::string s( name + simple_extensions[format_order[i]] );
- const int infd = open( s.c_str(), O_RDONLY | O_BINARY );
- if( infd >= 0 ) { name = s; return infd; }
- }
return -1;
}