1
0
Fork 0

Merging upstream version 0.9~rc1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-24 05:04:40 +01:00
parent 4f4c7c8781
commit 6503461316
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
19 changed files with 126 additions and 131 deletions

View file

@ -1,3 +1,8 @@
2010-11-20 Antonio Diaz Diaz <ant_diaz@teleline.es>
* Version 0.9-rc1 released.
* configure: Added new options "DIFF" and "GREP".
2010-11-15 Antonio Diaz Diaz <ant_diaz@teleline.es> 2010-11-15 Antonio Diaz Diaz <ant_diaz@teleline.es>
* Version 0.8 released. * Version 0.8 released.

View file

@ -51,6 +51,12 @@ ztest : ztest.in
cat $(VPATH)/ztest.in > ztest cat $(VPATH)/ztest.in > ztest
chmod a+x ztest chmod a+x ztest
main.o : main.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -DGREP=\"$(GREP)\" -c -o $@ $<
zdiff.o : zdiff.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -DDIFF=\"$(DIFF)\" -c -o $@ $<
zutils.o : zutils.cc zutils.o : zutils.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $< $(CXX) $(CPPFLAGS) $(CXXFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $<

16
NEWS
View file

@ -1,15 +1,3 @@
Changes in version 0.8: Changes in version 0.9:
The option "--recursive" has been added to zgrep. Configure now allows the selection of diff and grep programs to use.
All the utilities have been rewritten in C++, making them safer and more
efficient.
Zcat and zcmp implement the functionality of cat and cmp respectively.
Cat and cmp are not needed at runtime.
All mentions to zegrep and zfgrep have been removed from the
documentation because egrep and fgrep are deprecated.
Environment safeguards from configure have been removed. This allows
environment variables to affect configuration.

14
configure vendored
View file

@ -5,12 +5,12 @@
# This configure script is free software: you have unlimited permission # This configure script is free software: you have unlimited permission
# to copy, distribute and modify it. # to copy, distribute and modify it.
# #
# Date of this version: 2010-11-15 # Date of this version: 2010-11-20
args= args=
no_create= no_create=
pkgname=zutils pkgname=zutils
pkgversion=0.8 pkgversion=0.9-rc1
progname=zutils progname=zutils
srctrigger=zutils.h srctrigger=zutils.h
@ -25,6 +25,8 @@ datadir='$(prefix)/share'
infodir='$(datadir)/info' infodir='$(datadir)/info'
mandir='$(datadir)/man' mandir='$(datadir)/man'
sysconfdir='$(prefix)/etc' sysconfdir='$(prefix)/etc'
DIFF=diff
GREP=grep
if [ -n "${CXX}" ] ; then args="${args} CXX=\"${CXX}\"" ; fi if [ -n "${CXX}" ] ; then args="${args} CXX=\"${CXX}\"" ; fi
if [ -n "${CPPFLAGS}" ] ; then args="${args} CPPFLAGS=\"${CPPFLAGS}\"" ; fi if [ -n "${CPPFLAGS}" ] ; then args="${args} CPPFLAGS=\"${CPPFLAGS}\"" ; fi
@ -67,6 +69,8 @@ while [ -n "$1" ] ; do
echo " CPPFLAGS=OPTIONS command line options for the preprocessor [${CPPFLAGS}]" echo " CPPFLAGS=OPTIONS command line options for the preprocessor [${CPPFLAGS}]"
echo " CXXFLAGS=OPTIONS command line options for the C++ compiler [${CXXFLAGS}]" echo " CXXFLAGS=OPTIONS command line options for the C++ compiler [${CXXFLAGS}]"
echo " LDFLAGS=OPTIONS command line options for the linker [${LDFLAGS}]" echo " LDFLAGS=OPTIONS command line options for the linker [${LDFLAGS}]"
echo " DIFF=NAME diff program to use with zdiff [diff]"
echo " GREP=NAME grep program to use with zgrep [grep]"
echo echo
exit 0 ;; exit 0 ;;
--version | --ve* | -V) --version | --ve* | -V)
@ -95,6 +99,8 @@ while [ -n "$1" ] ; do
CPPFLAGS=*) CPPFLAGS=${optarg} ;; CPPFLAGS=*) CPPFLAGS=${optarg} ;;
CXXFLAGS=*) CXXFLAGS=${optarg} ;; CXXFLAGS=*) CXXFLAGS=${optarg} ;;
LDFLAGS=*) LDFLAGS=${optarg} ;; LDFLAGS=*) LDFLAGS=${optarg} ;;
DIFF=*) DIFF=${optarg} ;;
GREP=*) GREP=${optarg} ;;
--* | *=* | *-*-*) ;; --* | *=* | *-*-*) ;;
*) *)
@ -166,6 +172,8 @@ echo "CXX = ${CXX}"
echo "CPPFLAGS = ${CPPFLAGS}" echo "CPPFLAGS = ${CPPFLAGS}"
echo "CXXFLAGS = ${CXXFLAGS}" echo "CXXFLAGS = ${CXXFLAGS}"
echo "LDFLAGS = ${LDFLAGS}" echo "LDFLAGS = ${LDFLAGS}"
echo "DIFF = ${DIFF}"
echo "GREP = ${GREP}"
rm -f Makefile rm -f Makefile
cat > Makefile << EOF cat > Makefile << EOF
# Makefile for Zutils - Utilities dealing with compressed files # Makefile for Zutils - Utilities dealing with compressed files
@ -190,6 +198,8 @@ CXX = ${CXX}
CPPFLAGS = ${CPPFLAGS} CPPFLAGS = ${CPPFLAGS}
CXXFLAGS = ${CXXFLAGS} CXXFLAGS = ${CXXFLAGS}
LDFLAGS = ${LDFLAGS} LDFLAGS = ${LDFLAGS}
DIFF = ${DIFF}
GREP = ${GREP}
EOF EOF
cat ${srcdir}/Makefile.in >> Makefile cat ${srcdir}/Makefile.in >> Makefile

View file

@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
.TH ZCAT "1" "November 2010" "Zcat (zutils) 0.8" "User Commands" .TH ZCAT "1" "November 2010" "Zcat (zutils) 0.9-rc1" "User Commands"
.SH NAME .SH NAME
Zcat \- decompress and concatenate files to standard output Zcat \- decompress and concatenate files to standard output
.SH SYNOPSIS .SH SYNOPSIS

View file

@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
.TH ZCMP "1" "November 2010" "Zcmp (zutils) 0.8" "User Commands" .TH ZCMP "1" "November 2010" "Zcmp (zutils) 0.9-rc1" "User Commands"
.SH NAME .SH NAME
Zcmp \- decompress and compare two files byte by byte Zcmp \- decompress and compare two files byte by byte
.SH SYNOPSIS .SH SYNOPSIS

View file

@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
.TH ZDIFF "1" "November 2010" "Zdiff (zutils) 0.8" "User Commands" .TH ZDIFF "1" "November 2010" "Zdiff (zutils) 0.9-rc1" "User Commands"
.SH NAME .SH NAME
Zdiff \- decompress and compare two files line by line Zdiff \- decompress and compare two files line by line
.SH SYNOPSIS .SH SYNOPSIS

View file

@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
.TH ZGREP "1" "November 2010" "Zgrep (zutils) 0.8" "User Commands" .TH ZGREP "1" "November 2010" "Zgrep (zutils) 0.9-rc1" "User Commands"
.SH NAME .SH NAME
Zgrep \- search compressed files for a regular expression Zgrep \- search compressed files for a regular expression
.SH SYNOPSIS .SH SYNOPSIS

View file

@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
.TH ZTEST "1" "November 2010" "Ztest (zutils) 0.8" "User Commands" .TH ZTEST "1" "November 2010" "Ztest (zutils) 0.9-rc1" "User Commands"
.SH NAME .SH NAME
Ztest \- verify integrity of compressed files Ztest \- verify integrity of compressed files
.SH SYNOPSIS .SH SYNOPSIS

View file

@ -12,7 +12,7 @@ File: zutils.info, Node: Top, Next: Introduction, Up: (dir)
Zutils Manual Zutils Manual
************* *************
This manual is for Zutils (version 0.8, 15 November 2010). This manual is for Zutils (version 0.9-rc1, 20 November 2010).
* Menu: * Menu:
@ -531,13 +531,13 @@ Concept Index
 
Tag Table: Tag Table:
Node: Top224 Node: Top224
Node: Introduction987 Node: Introduction991
Node: Zcat2442 Node: Zcat2446
Node: Zcmp4326 Node: Zcmp4330
Node: Zdiff6383 Node: Zdiff6387
Node: Zgrep8620 Node: Zgrep8624
Node: Ztest11387 Node: Ztest11391
Node: Problems12470 Node: Problems12474
Node: Concept Index12999 Node: Concept Index13003
 
End Tag Table End Tag Table

View file

@ -5,8 +5,8 @@
@finalout @finalout
@c %**end of header @c %**end of header
@set UPDATED 15 November 2010 @set UPDATED 20 November 2010
@set VERSION 0.8 @set VERSION 0.9-rc1
@dircategory Data Compression @dircategory Data Compression
@direntry @direntry

10
main.cc
View file

@ -19,7 +19,6 @@
#include <cerrno> #include <cerrno>
#include <climits> #include <climits>
#include <csignal>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
@ -100,9 +99,8 @@ int open_instream( std::string & input_filename, const Mode program_mode ) throw
if( infd >= 0 ) { input_filename = name; break; } if( infd >= 0 ) { input_filename = name; break; }
} }
} }
if( infd < 0 && verbosity >= 0 ) if( infd < 0 )
std::fprintf( stderr, "%s: Can't open input file `%s': %s.\n", show_error2( "Can't open input file", input_filename.c_str() );
util_name, input_filename.c_str(), std::strerror( errno ) );
} }
return infd; return infd;
} }
@ -371,9 +369,7 @@ int main( const int argc, const char * const argv[] )
DIR * const dirp = opendir( input_filename.c_str() ); DIR * const dirp = opendir( input_filename.c_str() );
if( !dirp ) if( !dirp )
{ {
if( verbosity >= 0 ) show_error2( "Can't open directory", input_filename.c_str() );
std::fprintf( stderr, "%s: Can't open directory `%s': %s.\n",
util_name, input_filename.c_str(), std::strerror( errno ) );
if( retval < 1 ) retval = 1; continue; if( retval < 1 ) retval = 1; continue;
} }
std::list< std::string > tmp_list; std::list< std::string > tmp_list;

View file

@ -45,7 +45,7 @@ public:
str[i] = '0'; str[i] = '0';
} }
if( first_digit_pos > 0 ) str[--first_digit_pos] = '1'; if( first_digit_pos > 0 ) str[--first_digit_pos] = '1';
else str.insert( 0, 1, '1' ); else str.insert( 0U, 1, '1' );
} }
int sprint( uint8_t * const buf ) int sprint( uint8_t * const buf )
@ -116,10 +116,7 @@ int do_cat( const int infd, const int buffer_size,
rd = readblock( infd, inbuf, buffer_size ); rd = readblock( infd, inbuf, buffer_size );
if( rd != buffer_size && errno ) if( rd != buffer_size && errno )
{ {
if( verbosity >= 0 ) show_error2( "Error reading file", input_filename.c_str() );
std::fprintf( stderr, "%s: Error reading file `%s': %s.\n",
util_name, input_filename.c_str(),
std::strerror( errno ) );
return 1; return 1;
} }
if( rd == 0 ) if( rd == 0 )
@ -206,7 +203,7 @@ int cat( int infd, const std::string & input_filename,
input_filename, cat_options ); input_filename, cat_options );
if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 1; if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 1;
if( close( infd ) != 0 ) if( close( infd ) != 0 )
{ show_error( "Can't close output of data feeder", errno ); retval = 1; } { show_close_error( "data feeder" ); retval = 1; }
} }
delete[] inbuf; delete[] outbuf; delete[] inbuf; delete[] outbuf;
return retval; return retval;

20
zcmp.cc
View file

@ -20,7 +20,6 @@
#include <cctype> #include <cctype>
#include <cerrno> #include <cerrno>
#include <climits> #include <climits>
#include <csignal>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
@ -166,9 +165,8 @@ long long getnum( const char * const ptr, const char ** const tailp = 0,
int open_instream( const std::string & input_filename ) throw() int open_instream( const std::string & input_filename ) throw()
{ {
int infd = open( input_filename.c_str(), O_RDONLY | o_binary ); int infd = open( input_filename.c_str(), O_RDONLY | o_binary );
if( infd < 0 && verbosity >= 0 ) if( infd < 0 )
std::fprintf( stderr, "%s: Can't open input file `%s': %s.\n", show_error2( "Can't open input file", input_filename.c_str() );
util_name, input_filename.c_str(), std::strerror( errno ) );
return infd; return infd;
} }
@ -293,9 +291,7 @@ int cmp( const long long max_size, const int infd[2],
rd[i] = readblock( infd[i], buffer[i], size ); rd[i] = readblock( infd[i], buffer[i], size );
if( rd[i] != size && errno ) if( rd[i] != size && errno )
{ {
if( verbosity >= 0 ) show_error2( "Error reading file", filenames[i].c_str() );
std::fprintf( stderr, "%s: Error reading file `%s': %s.\n",
util_name, filenames[i].c_str(), std::strerror( errno ) );
return 2; return 2;
} }
} }
@ -467,9 +463,7 @@ int main( const int argc, const char * const argv[] )
for( int i = 0; i < 2; ++i ) for( int i = 0; i < 2; ++i )
if( !skip_ignore_initial( ignore_initial[i], infd[i] ) ) if( !skip_ignore_initial( ignore_initial[i], infd[i] ) )
{ {
if( verbosity >= 0 ) show_error2( "Can't skip initial bytes from file", filenames[i].c_str() );
std::fprintf( stderr, "%s: Can't skip initial bytes from file `%s': %s.\n",
util_name, filenames[i].c_str(), std::strerror( errno ) );
return 2; return 2;
} }
@ -483,12 +477,10 @@ int main( const int argc, const char * const argv[] )
for( int i = 0; i < 2; ++i ) for( int i = 0; i < 2; ++i )
{ {
if( close( infd[i] ) != 0 ) if( close( infd[i] ) != 0 )
{ show_error( "Can't close output of data feeder", errno ); retval = 2; } { show_close_error( "data feeder" ); retval = 2; }
if( filenames[i] != "-" && close( old_infd[i] ) != 0 ) if( filenames[i] != "-" && close( old_infd[i] ) != 0 )
{ {
if( verbosity >= 0 ) show_error2( "Can't close input file", filenames[i].c_str() );
std::fprintf( stderr, "%s: Can't close input file `%s': %s.\n",
util_name, filenames[i].c_str(), std::strerror( errno ) );
retval = 2; retval = 2;
} }
} }

View file

@ -122,9 +122,8 @@ void show_help() throw()
int open_instream( const std::string & input_filename ) throw() int open_instream( const std::string & input_filename ) throw()
{ {
int infd = open( input_filename.c_str(), O_RDONLY | o_binary ); int infd = open( input_filename.c_str(), O_RDONLY | o_binary );
if( infd < 0 && verbosity >= 0 ) if( infd < 0 )
std::fprintf( stderr, "%s: Can't open input file `%s': %s.\n", show_error2( "Can't open input file", input_filename.c_str() );
util_name, input_filename.c_str(), std::strerror( errno ) );
return infd; 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() ) if( fifonames[0].size() )
{ std::remove( fifonames[0].c_str() ); fifonames[0].clear(); } { 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 ) if( mkfifo( fifonames[i].c_str(), S_IRUSR | S_IWUSR ) == 0 )
continue; continue;
} }
if( verbosity >= 0 ) show_error2( "Can't create FIFO", fifonames[i].c_str() );
std::fprintf( stderr, "%s: Can't create FIFO `%s': %s.\n",
util_name, fifonames[i].c_str(), std::strerror( errno ) );
return false; return false;
} }
return true; 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( fda[0] ) == 0 && close( fda[1] ) == 0 &&
close( outfd ) == 0 ) close( outfd ) == 0 )
execlp( file_type.c_str(), file_type.c_str(), "-cdfq", (char *)0 ); execlp( file_type.c_str(), file_type.c_str(), "-cdfq", (char *)0 );
if( verbosity >= 0 ) show_exec_error( file_type.c_str() );
std::fprintf( stderr, "%s: Can't exec `%s': %s.\n",
util_name, file_type.c_str(), std::strerror( errno ) );
_exit( 2 ); _exit( 2 );
} }
if( pid2 < 0 ) if( pid2 < 0 )
{ { show_fork_error( file_type.c_str() ); _exit( 2 ); }
if( verbosity >= 0 )
std::fprintf( stderr, "%s: Can't fork `%s': %s.\n",
util_name, file_type.c_str(), std::strerror( errno ) );
_exit( 2 );
}
if( close( fda[0] ) != 0 || if( close( fda[0] ) != 0 ||
!feed_data( infd, fda[1], magic_data, magic_size ) ) !feed_data( infd, fda[1], magic_data, magic_size ) )
_exit( 2 ); _exit( 2 );
if( close( fda[1] ) != 0 ) 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() ) ); _exit( wait_for_child( pid2, file_type.c_str() ) );
} }
// parent // parent
close( fda[0] ); close( fda[1] ); close( fda[0] ); close( fda[1] );
if( pid < 0 ) if( pid < 0 )
{ show_error( "Can't fork decompressor feeder", errno ); return false; } { show_fork_error( "decompressor feeder" ); return false; }
*pidp = pid; *pidp = pid;
} }
else // not compressed 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 ) ) if( !feed_data( infd, outfd, magic_data, magic_size ) )
_exit( 2 ); _exit( 2 );
if( close( outfd ) != 0 ) if( close( outfd ) != 0 )
{ show_error( "Can't close output of feeder", errno ); _exit( 2 ); } { show_close_error( "data feeder" ); _exit( 2 ); }
_exit( 0 ); _exit( 0 );
} }
// parent // parent
if( pid < 0 ) if( pid < 0 )
{ show_error( "Can't fork data feeder", errno ); return false; } { show_fork_error( "data feeder" ); return false; }
*pidp = pid; *pidp = pid;
} }
return true; return true;
@ -431,7 +421,7 @@ int main( const int argc, const char * const argv[] )
if( diff_pid == 0 ) // child (diff) if( diff_pid == 0 ) // child (diff)
{ {
const char ** const argv = new const char *[diff_args.size()+5]; 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 ) for( unsigned int i = 0; i < diff_args.size(); ++i )
argv[i+1] = diff_args[i]; argv[i+1] = diff_args[i];
argv[diff_args.size()+1] = "--"; 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()+3] = fifonames[1].c_str();
argv[diff_args.size()+4] = 0; argv[diff_args.size()+4] = 0;
execvp( argv[0], (char **)argv ); execvp( argv[0], (char **)argv );
show_error( "Can't exec `diff'." ); show_exec_error( DIFF );
_exit( 2 ); _exit( 2 );
} }
// parent // parent
if( diff_pid < 0 ) if( diff_pid < 0 )
{ show_error( "Can't fork `diff'", errno ); return 2; } { show_fork_error( DIFF ); return 2; }
pid_t pid[2]; pid_t pid[2];
if( !set_data_feeder( fifonames[0], infd[0], &pid[0] ) || if( !set_data_feeder( fifonames[0], infd[0], &pid[0] ) ||
!set_data_feeder( fifonames[1], infd[1], &pid[1] ) ) !set_data_feeder( fifonames[1], infd[1], &pid[1] ) )
return 2; return 2;
int retval = wait_for_child( diff_pid, "diff" ); int retval = wait_for_child( diff_pid, DIFF );
if( retval != 0 ) if( retval != 0 )
{ {
@ -466,9 +456,7 @@ int main( const int argc, const char * const argv[] )
for( int i = 0; i < 2; ++i ) for( int i = 0; i < 2; ++i )
if( filenames[i] != "-" && close( infd[i] ) != 0 ) if( filenames[i] != "-" && close( infd[i] ) != 0 )
{ {
if( verbosity >= 0 ) show_error2( "Can't close input file", filenames[i].c_str() );
std::fprintf( stderr, "%s: Can't close input file `%s': %s.\n",
util_name, filenames[i].c_str(), std::strerror( errno ) );
retval = 2; retval = 2;
} }

View file

@ -72,23 +72,23 @@ int zgrep_stdin( int infd, const std::vector< const char * > & grep_args )
if( dup2( infd, STDIN_FILENO ) >= 0 && close( infd ) == 0 ) if( dup2( infd, STDIN_FILENO ) >= 0 && close( infd ) == 0 )
{ {
const char ** const argv = new const char *[grep_args.size()+2]; const char ** const argv = new const char *[grep_args.size()+2];
argv[0] = "grep"; argv[0] = GREP;
for( unsigned int i = 0; i < grep_args.size(); ++i ) for( unsigned int i = 0; i < grep_args.size(); ++i )
argv[i+1] = grep_args[i]; argv[i+1] = grep_args[i];
argv[grep_args.size()+1] = 0; argv[grep_args.size()+1] = 0;
execvp( argv[0], (char **)argv ); execvp( argv[0], (char **)argv );
} }
show_error( "Can't exec `grep'." ); show_exec_error( GREP );
_exit( 2 ); _exit( 2 );
} }
// parent // parent
if( grep_pid < 0 ) if( grep_pid < 0 )
{ show_error( "Can't fork `grep'", errno ); return 2; } { show_fork_error( GREP ); return 2; }
int retval = 0; int retval = 0;
if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2; if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
if( wait_for_child( grep_pid, "grep" ) != 0 ) retval = 2; if( wait_for_child( grep_pid, GREP ) != 0 ) retval = 2;
if( close( infd ) != 0 ) if( close( infd ) != 0 )
{ show_error( "Can't close output of data feeder", errno ); return 2; } { show_close_error( "data feeder" ); return 2; }
return retval; return retval;
} }
@ -110,19 +110,19 @@ int zgrep_file( int infd, const std::string & input_filename,
close( infd ) == 0 && close( fda[0] ) == 0 && close( fda[1] ) == 0 ) close( infd ) == 0 && close( fda[0] ) == 0 && close( fda[1] ) == 0 )
{ {
const char ** const argv = new const char *[grep_args.size()+2]; const char ** const argv = new const char *[grep_args.size()+2];
argv[0] = "grep"; argv[0] = GREP;
for( unsigned int i = 0; i < grep_args.size(); ++i ) for( unsigned int i = 0; i < grep_args.size(); ++i )
argv[i+1] = grep_args[i]; argv[i+1] = grep_args[i];
argv[grep_args.size()+1] = 0; argv[grep_args.size()+1] = 0;
execvp( argv[0], (char **)argv ); execvp( argv[0], (char **)argv );
} }
show_error( "Can't exec `grep'." ); show_exec_error( GREP );
_exit( 2 ); _exit( 2 );
} }
// parent // parent
close( fda[1] ); close( fda[1] );
if( grep_pid < 0 ) if( grep_pid < 0 )
{ show_error( "Can't fork `grep'", errno ); return 2; } { show_fork_error( GREP ); return 2; }
enum { buffer_size = 256 }; enum { buffer_size = 256 };
uint8_t buffer[buffer_size]; uint8_t buffer[buffer_size];
bool line_begin = true; bool line_begin = true;
@ -148,12 +148,12 @@ int zgrep_file( int infd, const std::string & input_filename,
} }
int retval = 0; int retval = 0;
if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2; if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
if( wait_for_child( grep_pid, "grep" ) != 0 ) retval = 2; if( wait_for_child( grep_pid, GREP ) != 0 ) retval = 2;
if( grep_list && retval == 0 ) if( grep_list && retval == 0 )
std::printf( "%s\n", input_filename.c_str() ); std::printf( "%s\n", input_filename.c_str() );
if( close( infd ) != 0 ) if( close( infd ) != 0 )
{ show_error( "Can't close output of data feeder", errno ); return 2; } { show_close_error( "data feeder" ); return 2; }
if( close( fda[0] ) != 0 ) if( close( fda[0] ) != 0 )
{ show_error( "Can't close output of grep", errno ); return 2; } { show_close_error( GREP ); return 2; }
return retval; return retval;
} }

View file

@ -60,23 +60,16 @@ int ztest_stdin( const int infd,
argv[ztest_args.size()+2] = 0; argv[ztest_args.size()+2] = 0;
execvp( argv[0], (char **)argv ); execvp( argv[0], (char **)argv );
} }
if( verbosity >= 0 ) show_exec_error( file_type.c_str() );
std::fprintf( stderr, "%s: Can't exec `%s': %s.\n",
util_name, file_type.c_str(), std::strerror( errno ) );
_exit( 1 ); _exit( 1 );
} }
// parent // parent
if( pid < 0 ) if( pid < 0 )
{ { show_fork_error( file_type.c_str() ); return 1; }
if( verbosity >= 0 )
std::fprintf( stderr, "%s: Can't fork `%s': %s.\n",
util_name, file_type.c_str(), std::strerror( errno ) );
return 1;
}
close( fda[0] ); close( fda[0] );
if( !feed_data( infd, fda[1], magic_data, magic_size ) ) return 1; if( !feed_data( infd, fda[1], magic_data, magic_size ) ) return 1;
if( close( fda[1] ) != 0 ) if( close( fda[1] ) != 0 )
{ show_error( "Can't close output of data feeder", errno ); return 1; } { show_close_error( "data feeder" ); return 1; }
return wait_for_child( pid, file_type.c_str() ); return wait_for_child( pid, file_type.c_str() );
} }
@ -102,18 +95,11 @@ int ztest_file( const int infd, const std::string & input_filename,
argv[ztest_args.size()+3] = input_filename.c_str(); argv[ztest_args.size()+3] = input_filename.c_str();
argv[ztest_args.size()+4] = 0; argv[ztest_args.size()+4] = 0;
execvp( argv[0], (char **)argv ); execvp( argv[0], (char **)argv );
if( verbosity >= 0 ) show_exec_error( file_type.c_str() );
std::fprintf( stderr, "%s: Can't exec `%s': %s.\n",
util_name, argv[0], std::strerror( errno ) );
_exit( 1 ); _exit( 1 );
} }
// parent // parent
if( pid < 0 ) if( pid < 0 )
{ { show_fork_error( file_type.c_str() ); return 1; }
if( verbosity >= 0 )
std::fprintf( stderr, "%s: Can't fork `%s': %s.\n",
util_name, file_type.c_str(), std::strerror( errno ) );
return 1;
}
return wait_for_child( pid, file_type.c_str() ); return wait_for_child( pid, file_type.c_str() );
} }

View file

@ -119,32 +119,24 @@ bool set_data_feeder( int * const infdp, pid_t * const pidp )
close( fda[0] ) == 0 && close( fda[1] ) == 0 && close( fda[0] ) == 0 && close( fda[1] ) == 0 &&
close( fda2[0] ) == 0 && close( fda2[1] ) == 0 ) close( fda2[0] ) == 0 && close( fda2[1] ) == 0 )
execlp( file_type.c_str(), file_type.c_str(), "-cdfq", (char *)0 ); execlp( file_type.c_str(), file_type.c_str(), "-cdfq", (char *)0 );
if( verbosity >= 0 ) show_exec_error( file_type.c_str() );
std::fprintf( stderr, "%s: Can't exec `%s': %s.\n",
util_name, file_type.c_str(), std::strerror( errno ) );
_exit( 2 ); _exit( 2 );
} }
if( pid2 < 0 ) if( pid2 < 0 )
{ { show_fork_error( file_type.c_str() ); _exit( 2 ); }
if( verbosity >= 0 )
std::fprintf( stderr, "%s: Can't fork `%s': %s.\n",
util_name, file_type.c_str(), std::strerror( errno ) );
_exit( 2 );
}
if( close( fda[0] ) != 0 || if( close( fda[0] ) != 0 ||
close( fda2[0] ) != 0 || close( fda2[1] ) != 0 || close( fda2[0] ) != 0 || close( fda2[1] ) != 0 ||
!feed_data( old_infd, fda[1], magic_data, magic_size ) ) !feed_data( old_infd, fda[1], magic_data, magic_size ) )
_exit( 2 ); _exit( 2 );
if( close( fda[1] ) != 0 ) if( close( fda[1] ) != 0 )
{ show_error( "Can't close output of decompressor feeder", errno ); { show_close_error( "decompressor feeder" ); _exit( 2 ); }
_exit( 2 ); }
_exit( wait_for_child( pid2, file_type.c_str() ) ); _exit( wait_for_child( pid2, file_type.c_str() ) );
} }
// parent // parent
close( fda[0] ); close( fda[1] ); close( fda2[1] ); close( fda[0] ); close( fda[1] ); close( fda2[1] );
if( pid < 0 ) if( pid < 0 )
{ show_error( "Can't fork decompressor feeder", errno ); return false; } { show_fork_error( "decompressor feeder" ); return false; }
*pidp = pid; *pidp = pid;
} }
else // not compressed 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 ) ) !feed_data( old_infd, fda[1], magic_data, magic_size ) )
_exit( 2 ); _exit( 2 );
if( close( fda[1] ) != 0 ) if( close( fda[1] ) != 0 )
{ show_error( "Can't close output of data feeder", errno ); { show_close_error( "data feeder" ); _exit( 2 ); }
_exit( 2 ); }
_exit( 0 ); _exit( 0 );
} }
// parent // parent
close( fda[1] ); close( fda[1] );
if( pid < 0 ) if( pid < 0 )
{ show_error( "Can't fork data feeder", errno ); return false; } { show_fork_error( "data feeder" ); return false; }
*pidp = pid; *pidp = pid;
} }
return true; 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 ) void internal_error( const char * const msg )
{ {
if( verbosity >= 0 ) if( verbosity >= 0 )

View file

@ -45,6 +45,10 @@ void show_help_addr() throw();
void show_version( const char * const Util_name = 0 ) throw(); void show_version( const char * const Util_name = 0 ) throw();
void show_error( const char * const msg, const int errcode = 0, void show_error( const char * const msg, const int errcode = 0,
const bool help = false ) throw(); const bool help = false ) throw();
void show_error2( const char * const msg, const char * const name ) throw();
void show_close_error( const char * const prog_name ) throw();
void show_exec_error( const char * const prog_name ) throw();
void show_fork_error( const char * const prog_name ) throw();
void internal_error( const char * const msg ); void internal_error( const char * const msg );
bool test_format( const int infd, std::string & file_type, bool test_format( const int infd, std::string & file_type,