1
0
Fork 0

Merging upstream version 1.2~pre3.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-24 05:45:59 +01:00
parent 388270afb8
commit 57a593e0b1
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
32 changed files with 1172 additions and 1035 deletions

112
rc.cc
View file

@ -17,19 +17,28 @@
#define _FILE_OFFSET_BITS 64
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <stdint.h>
#include <unistd.h>
#include <sys/wait.h>
#include "arg_parser.h"
#include "zutils.h"
#include "rc.h"
const char * invocation_name = 0;
const char * program_name = 0;
int verbosity = 0;
namespace {
const char * const config_file_name = "zutilsrc";
const char * const program_year = "2013";
std::string compressor_names[num_formats] =
{ "bzip2", "gzip", "lzip", "xz" }; // default compressor names
@ -227,3 +236,102 @@ const std::vector< std::string > & get_compressor_args( const int format_index )
{
return compressor_args[format_index];
}
void show_help_addr()
{
std::printf( "\nReport bugs to zutils-bug@nongnu.org\n"
"Zutils home page: http://www.nongnu.org/zutils/zutils.html\n" );
}
void show_version( const char * const Program_name )
{
std::printf( "%s (zutils) %s\n", Program_name, PROGVERSION );
std::printf( "Copyright (C) %s Antonio Diaz Diaz.\n", program_year );
std::printf( "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n" );
}
void show_error( const char * const msg, const int errcode, const bool help )
{
if( verbosity >= 0 )
{
if( msg && msg[0] )
{
std::fprintf( stderr, "%s: %s", program_name, msg );
if( errcode > 0 )
std::fprintf( stderr, ": %s", std::strerror( errcode ) );
std::fprintf( stderr, "\n" );
}
if( help )
std::fprintf( stderr, "Try '%s --help' for more information.\n",
invocation_name );
}
}
void show_error2( const char * const msg, const char * const name )
{
if( verbosity >= 0 )
std::fprintf( stderr, "%s: %s '%s': %s.\n",
program_name, msg, name, std::strerror( errno ) );
}
void internal_error( const char * const msg )
{
if( verbosity >= 0 )
std::fprintf( stderr, "%s: internal error: %s.\n", program_name, msg );
std::exit( 3 );
}
void show_close_error( const char * const prog_name )
{
if( verbosity >= 0 )
std::fprintf( stderr, "%s: Can't close output of %s: %s.\n",
program_name, prog_name, std::strerror( errno ) );
}
void show_exec_error( const char * const prog_name )
{
if( verbosity >= 0 )
std::fprintf( stderr, "%s: Can't exec '%s': %s.\n",
program_name, prog_name, std::strerror( errno ) );
}
void show_fork_error( const char * const prog_name )
{
if( verbosity >= 0 )
std::fprintf( stderr, "%s: Can't fork '%s': %s.\n",
program_name, prog_name, std::strerror( errno ) );
}
int wait_for_child( const pid_t pid, const char * const name,
const int eretval, const bool isgzxz )
{
int status;
while( waitpid( pid, &status, 0 ) == -1 )
{
if( errno != EINTR )
{
if( verbosity >= 0 )
std::fprintf( stderr, "%s: Error waiting termination of '%s': %s.\n",
program_name, name, std::strerror( errno ) );
_exit( eretval );
}
}
if( WIFEXITED( status ) )
{
const int tmp = WEXITSTATUS( status );
if( isgzxz && eretval == 1 && tmp == 1 ) return 2; // for ztest
return tmp;
}
return eretval;
}