diff options
Diffstat (limited to '')
-rw-r--r-- | zutils.cc | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -1,5 +1,5 @@ /* Zutils - Utilities dealing with compressed files - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 Antonio Diaz Diaz. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -112,7 +112,9 @@ int writeblock( const int fd, const uint8_t * const buf, const int size ) } -bool feed_data( const int infd, const int outfd, +// Empty filename means stdin. +// +bool feed_data( const std::string & filename, const int infd, const int outfd, const uint8_t * magic_data, const int magic_size ) { if( magic_size && writeblock( outfd, magic_data, magic_size ) != magic_size ) @@ -123,7 +125,8 @@ bool feed_data( const int infd, const int outfd, { const int size = readblock( infd, buffer, buffer_size ); if( size != buffer_size && errno ) - { show_error( "Read error", errno ); return false; } + { const char * const name = filename.empty() ? "-" : filename.c_str(); + show_file_error( name, "Read error", errno ); return false; } if( size > 0 && writeblock( outfd, buffer, size ) != size ) { show_error( "Write error", errno ); return false; } if( size < buffer_size ) break; @@ -156,7 +159,8 @@ bool good_status( const Children & children, const bool finished ) } -bool set_data_feeder( int * const infdp, Children & children, int format_index ) +bool set_data_feeder( const std::string & filename, int * const infdp, + Children & children, int format_index ) { const uint8_t * magic_data = 0; int magic_size = 0; @@ -177,7 +181,7 @@ bool set_data_feeder( int * const infdp, Children & children, int format_index ) { if( close( fda[0] ) != 0 || close( fda2[0] ) != 0 || close( fda2[1] ) != 0 || - !feed_data( old_infd, fda[1], magic_data, magic_size ) ) + !feed_data( filename, old_infd, fda[1], magic_data, magic_size ) ) _exit( 2 ); if( close( fda[1] ) != 0 ) { show_close_error(); _exit( 2 ); } @@ -226,7 +230,7 @@ bool set_data_feeder( int * const infdp, Children & children, int format_index ) if( pid == 0 ) // child (feeder) { if( close( fda[0] ) != 0 || - !feed_data( old_infd, fda[1], magic_data, magic_size ) ) + !feed_data( filename, old_infd, fda[1], magic_data, magic_size ) ) _exit( 2 ); if( close( fda[1] ) != 0 ) { show_close_error(); _exit( 2 ); } |