diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-08 04:19:00 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-08 04:19:00 +0000 |
commit | 67258f475f17f3824c5715eaa4ebdfee86f20142 (patch) | |
tree | 5281744f82f74ad6c3f79007052bb99bbf209b05 /zdiff.cc | |
parent | Adding debian version 0.8-1. (diff) | |
download | zutils-67258f475f17f3824c5715eaa4ebdfee86f20142.tar.xz zutils-67258f475f17f3824c5715eaa4ebdfee86f20142.zip |
Merging upstream version 0.9~rc1.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'zdiff.cc')
-rw-r--r-- | zdiff.cc | 42 |
1 files changed, 15 insertions, 27 deletions
@@ -122,9 +122,8 @@ void show_help() throw() int open_instream( const std::string & input_filename ) throw() { int infd = open( input_filename.c_str(), O_RDONLY | o_binary ); - if( infd < 0 && verbosity >= 0 ) - std::fprintf( stderr, "%s: Can't open input file `%s': %s.\n", - util_name, input_filename.c_str(), std::strerror( errno ) ); + if( infd < 0 ) + show_error2( "Can't open input file", input_filename.c_str() ); return infd; } @@ -169,7 +168,7 @@ const char * my_basename( const char * filename ) throw() } -void remove_fifos() throw() +extern "C" void remove_fifos() throw() { if( fifonames[0].size() ) { std::remove( fifonames[0].c_str() ); fifonames[0].clear(); } @@ -209,9 +208,7 @@ bool set_fifonames( const std::string filenames[2] ) if( mkfifo( fifonames[i].c_str(), S_IRUSR | S_IWUSR ) == 0 ) continue; } - if( verbosity >= 0 ) - std::fprintf( stderr, "%s: Can't create FIFO `%s': %s.\n", - util_name, fifonames[i].c_str(), std::strerror( errno ) ); + show_error2( "Can't create FIFO", fifonames[i].c_str() ); return false; } return true; @@ -251,30 +248,23 @@ bool set_data_feeder( const std::string & fifoname, const int infd, close( fda[0] ) == 0 && close( fda[1] ) == 0 && close( outfd ) == 0 ) execlp( file_type.c_str(), file_type.c_str(), "-cdfq", (char *)0 ); - if( verbosity >= 0 ) - std::fprintf( stderr, "%s: Can't exec `%s': %s.\n", - util_name, file_type.c_str(), std::strerror( errno ) ); + show_exec_error( file_type.c_str() ); _exit( 2 ); } if( pid2 < 0 ) - { - if( verbosity >= 0 ) - std::fprintf( stderr, "%s: Can't fork `%s': %s.\n", - util_name, file_type.c_str(), std::strerror( errno ) ); - _exit( 2 ); - } + { show_fork_error( file_type.c_str() ); _exit( 2 ); } if( close( fda[0] ) != 0 || !feed_data( infd, fda[1], magic_data, magic_size ) ) _exit( 2 ); if( close( fda[1] ) != 0 ) - { show_error( "Can't close output of feeder", errno ); _exit( 2 ); } + { show_close_error( "data feeder" ); _exit( 2 ); } _exit( wait_for_child( pid2, file_type.c_str() ) ); } // parent close( fda[0] ); close( fda[1] ); if( pid < 0 ) - { show_error( "Can't fork decompressor feeder", errno ); return false; } + { show_fork_error( "decompressor feeder" ); return false; } *pidp = pid; } else // not compressed @@ -293,12 +283,12 @@ bool set_data_feeder( const std::string & fifoname, const int infd, if( !feed_data( infd, outfd, magic_data, magic_size ) ) _exit( 2 ); if( close( outfd ) != 0 ) - { show_error( "Can't close output of feeder", errno ); _exit( 2 ); } + { show_close_error( "data feeder" ); _exit( 2 ); } _exit( 0 ); } // parent if( pid < 0 ) - { show_error( "Can't fork data feeder", errno ); return false; } + { show_fork_error( "data feeder" ); return false; } *pidp = pid; } return true; @@ -431,7 +421,7 @@ int main( const int argc, const char * const argv[] ) if( diff_pid == 0 ) // child (diff) { const char ** const argv = new const char *[diff_args.size()+5]; - argv[0] = "diff"; + argv[0] = DIFF; for( unsigned int i = 0; i < diff_args.size(); ++i ) argv[i+1] = diff_args[i]; argv[diff_args.size()+1] = "--"; @@ -439,19 +429,19 @@ int main( const int argc, const char * const argv[] ) argv[diff_args.size()+3] = fifonames[1].c_str(); argv[diff_args.size()+4] = 0; execvp( argv[0], (char **)argv ); - show_error( "Can't exec `diff'." ); + show_exec_error( DIFF ); _exit( 2 ); } // parent if( diff_pid < 0 ) - { show_error( "Can't fork `diff'", errno ); return 2; } + { show_fork_error( DIFF ); return 2; } pid_t pid[2]; if( !set_data_feeder( fifonames[0], infd[0], &pid[0] ) || !set_data_feeder( fifonames[1], infd[1], &pid[1] ) ) return 2; - int retval = wait_for_child( diff_pid, "diff" ); + int retval = wait_for_child( diff_pid, DIFF ); if( retval != 0 ) { @@ -466,9 +456,7 @@ int main( const int argc, const char * const argv[] ) for( int i = 0; i < 2; ++i ) if( filenames[i] != "-" && close( infd[i] ) != 0 ) { - if( verbosity >= 0 ) - std::fprintf( stderr, "%s: Can't close input file `%s': %s.\n", - util_name, filenames[i].c_str(), std::strerror( errno ) ); + show_error2( "Can't close input file", filenames[i].c_str() ); retval = 2; } |