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 /zutils.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 'zutils.cc')
-rw-r--r-- | zutils.cc | 53 |
1 files changed, 38 insertions, 15 deletions
@@ -119,32 +119,24 @@ bool set_data_feeder( int * const infdp, pid_t * const pidp ) close( fda[0] ) == 0 && close( fda[1] ) == 0 && close( fda2[0] ) == 0 && close( fda2[1] ) == 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 || close( fda2[0] ) != 0 || close( fda2[1] ) != 0 || !feed_data( old_infd, fda[1], magic_data, magic_size ) ) _exit( 2 ); if( close( fda[1] ) != 0 ) - { show_error( "Can't close output of decompressor feeder", errno ); - _exit( 2 ); } + { show_close_error( "decompressor feeder" ); _exit( 2 ); } _exit( wait_for_child( pid2, file_type.c_str() ) ); } // parent close( fda[0] ); close( fda[1] ); close( fda2[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 @@ -161,14 +153,13 @@ bool set_data_feeder( int * const infdp, pid_t * const pidp ) !feed_data( old_infd, fda[1], magic_data, magic_size ) ) _exit( 2 ); if( close( fda[1] ) != 0 ) - { show_error( "Can't close output of data feeder", errno ); - _exit( 2 ); } + { show_close_error( "data feeder" ); _exit( 2 ); } _exit( 0 ); } // parent close( fda[1] ); if( pid < 0 ) - { show_error( "Can't fork data feeder", errno ); return false; } + { show_fork_error( "data feeder" ); return false; } *pidp = pid; } return true; @@ -214,6 +205,38 @@ void show_error( const char * const msg, const int errcode, } +void show_error2( const char * const msg, const char * const name ) throw() + { + if( verbosity >= 0 ) + std::fprintf( stderr, "%s: %s `%s': %s.\n", + util_name, msg, name, std::strerror( errno ) ); + } + + +void show_close_error( const char * const prog_name ) throw() + { + if( verbosity >= 0 ) + std::fprintf( stderr, "%s: Can't close output of %s: %s.\n", + util_name, prog_name, std::strerror( errno ) ); + } + + +void show_exec_error( const char * const prog_name ) throw() + { + if( verbosity >= 0 ) + std::fprintf( stderr, "%s: Can't exec `%s': %s.\n", + util_name, prog_name, std::strerror( errno ) ); + } + + +void show_fork_error( const char * const prog_name ) throw() + { + if( verbosity >= 0 ) + std::fprintf( stderr, "%s: Can't fork `%s': %s.\n", + util_name, prog_name, std::strerror( errno ) ); + } + + void internal_error( const char * const msg ) { if( verbosity >= 0 ) |