1
0
Fork 0

Merging upstream version 1.14.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-23 19:28:41 +01:00
parent 8e7b6e24fe
commit 3e788f38b7
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
10 changed files with 98 additions and 100 deletions

View file

@ -1,6 +1,6 @@
2024-11-08 Antonio Diaz Diaz <antonio@gnu.org>
2025-01-07 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.14-rc1 released.
* Version 1.14 released.
* main.c (decompress): Return 2 if empty member in multimember file.
(Pp_free): New function.
* check.sh: Use 'cp' instead of 'cat'.
@ -125,7 +125,7 @@
* Using LZMA SDK 9.10 (public domain) from Igor Pavlov.
Copyright (C) 2010-2024 Antonio Diaz Diaz.
Copyright (C) 2010-2025 Antonio Diaz Diaz.
This file is a collection of facts, and thus it is not copyrightable, but just
in case, you have unlimited permission to copy, distribute, and modify it.

View file

@ -3,7 +3,8 @@ Requirements
You will need a C99 compiler. (gcc 3.3.6 or newer is recommended).
I use gcc 6.1.0 and 3.3.6, but the code should compile with any standards
compliant compiler.
Gcc is available at http://gcc.gnu.org.
Gcc is available at http://gcc.gnu.org
Lzip is available at http://www.nongnu.org/lzip/lzip.html
The operating system must allow signal handlers read access to objects with
static storage duration so that the cleanup handler for Control-C can delete
@ -74,7 +75,7 @@ After running 'configure', you can run 'make' and 'make install' as
explained above.
Copyright (C) 2010-2024 Antonio Diaz Diaz.
Copyright (C) 2010-2025 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy,
distribute, and modify it.

16
README
View file

@ -1,3 +1,5 @@
See the file INSTALL for compilation and installation instructions.
Description
Pdlzip is a permissively licensed implementation of the lzip data
@ -20,11 +22,10 @@ compressed format for Unix-like systems.
The lzip file format is designed for data sharing and long-term archiving,
taking into account both data integrity and decoder availability:
* The lzip format provides very safe integrity checking and some data
recovery means. The program lziprecover can repair bit flip errors
(one of the most common forms of data corruption) in lzip files, and
provides data recovery capabilities, including error-checked merging
of damaged copies of a file.
* The program lziprecover can repair bit flip errors (one of the most
common forms of data corruption) in lzip files, and provides data
recovery capabilities, including error-checked merging of damaged
copies of a file.
* The lzip format is as simple as possible (but not simpler). The lzip
manual provides the source code of a simple decompressor along with a
@ -50,8 +51,11 @@ without recompressing.
Pdlzip includes public domain compression/decompression code from the LZMA
SDK (Software Development Kit) written by Igor Pavlov.
Pdlzip uses Arg_parser for command-line argument parsing:
http://www.nongnu.org/arg-parser/arg_parser.html
Copyright (C) 2010-2024 Antonio Diaz Diaz.
Copyright (C) 2010-2025 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy,
distribute, and modify it.

View file

@ -1,5 +1,5 @@
/* Arg_parser - POSIX/GNU command-line argument parser. (C version)
Copyright (C) 2006-2024 Antonio Diaz Diaz.
Copyright (C) 2006-2025 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@ -32,15 +32,15 @@ static void * ap_resize_buffer( void * buf, const int min_size )
}
static char push_back_record( struct Arg_parser * const ap, const int code,
static char push_back_record( Arg_parser * const ap, const int code,
const char * const long_name,
const char * const argument )
{
struct ap_Record * p;
ap_Record * p;
void * tmp = ap_resize_buffer( ap->data,
( ap->data_size + 1 ) * sizeof (struct ap_Record) );
( ap->data_size + 1 ) * sizeof (ap_Record) );
if( !tmp ) return 0;
ap->data = (struct ap_Record *)tmp;
ap->data = (ap_Record *)tmp;
p = &(ap->data[ap->data_size]);
p->code = code;
if( long_name )
@ -71,7 +71,7 @@ static char push_back_record( struct Arg_parser * const ap, const int code,
}
static char add_error( struct Arg_parser * const ap, const char * const msg )
static char add_error( Arg_parser * const ap, const char * const msg )
{
const int len = strlen( msg );
void * tmp = ap_resize_buffer( ap->error, ap->error_size + len + 1 );
@ -83,7 +83,7 @@ static char add_error( struct Arg_parser * const ap, const char * const msg )
}
static void free_data( struct Arg_parser * const ap )
static void free_data( Arg_parser * const ap )
{
int i;
for( i = 0; i < ap->data_size; ++i )
@ -94,10 +94,9 @@ static void free_data( struct Arg_parser * const ap )
/* Return 0 only if out of memory. */
static char parse_long_option( struct Arg_parser * const ap,
static char parse_long_option( Arg_parser * const ap,
const char * const opt, const char * const arg,
const struct ap_Option options[],
int * const argindp )
const ap_Option options[], int * const argindp )
{
unsigned len;
int index = -1, i;
@ -171,10 +170,9 @@ static char parse_long_option( struct Arg_parser * const ap,
/* Return 0 only if out of memory. */
static char parse_short_option( struct Arg_parser * const ap,
static char parse_short_option( Arg_parser * const ap,
const char * const opt, const char * const arg,
const struct ap_Option options[],
int * const argindp )
const ap_Option options[], int * const argindp )
{
int cind = 1; /* character index in opt */
@ -221,9 +219,9 @@ static char parse_short_option( struct Arg_parser * const ap,
}
char ap_init( struct Arg_parser * const ap,
char ap_init( Arg_parser * const ap,
const int argc, const char * const argv[],
const struct ap_Option options[], const char in_order )
const ap_Option options[], const char in_order )
{
const char ** non_options = 0; /* skipped non-options */
int non_options_size = 0; /* number of skipped non-options */
@ -282,7 +280,7 @@ out: if( non_options ) free( non_options );
}
void ap_free( struct Arg_parser * const ap )
void ap_free( Arg_parser * const ap )
{
free_data( ap );
if( ap->error ) { free( ap->error ); ap->error = 0; }
@ -290,29 +288,25 @@ void ap_free( struct Arg_parser * const ap )
}
const char * ap_error( const struct Arg_parser * const ap )
{ return ap->error; }
const char * ap_error( const Arg_parser * const ap ) { return ap->error; }
int ap_arguments( const Arg_parser * const ap ) { return ap->data_size; }
int ap_arguments( const struct Arg_parser * const ap )
{ return ap->data_size; }
int ap_code( const struct Arg_parser * const ap, const int i )
int ap_code( const Arg_parser * const ap, const int i )
{
if( i < 0 || i >= ap_arguments( ap ) ) return 0;
return ap->data[i].code;
}
const char * ap_parsed_name( const struct Arg_parser * const ap, const int i )
const char * ap_parsed_name( const Arg_parser * const ap, const int i )
{
if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].parsed_name ) return "";
return ap->data[i].parsed_name;
}
const char * ap_argument( const struct Arg_parser * const ap, const int i )
const char * ap_argument( const Arg_parser * const ap, const int i )
{
if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].argument ) return "";
return ap->data[i].argument;

View file

@ -1,5 +1,5 @@
/* Arg_parser - POSIX/GNU command-line argument parser. (C version)
Copyright (C) 2006-2024 Antonio Diaz Diaz.
Copyright (C) 2006-2025 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@ -50,52 +50,52 @@ extern "C" {
#endif
/* ap_yme = yes but maybe empty */
enum ap_Has_arg { ap_no, ap_yes, ap_maybe, ap_yme };
typedef enum ap_Has_arg { ap_no, ap_yes, ap_maybe, ap_yme } ap_Has_arg;
struct ap_Option
typedef struct ap_Option
{
int code; /* Short option letter or code ( code != 0 ) */
const char * long_name; /* Long option name (maybe null) */
enum ap_Has_arg has_arg;
};
ap_Has_arg has_arg;
} ap_Option;
struct ap_Record
typedef struct ap_Record
{
int code;
char * parsed_name;
char * argument;
};
} ap_Record;
struct Arg_parser
typedef struct Arg_parser
{
struct ap_Record * data;
ap_Record * data;
char * error;
int data_size;
int error_size;
};
} Arg_parser;
char ap_init( struct Arg_parser * const ap,
char ap_init( Arg_parser * const ap,
const int argc, const char * const argv[],
const struct ap_Option options[], const char in_order );
const ap_Option options[], const char in_order );
void ap_free( struct Arg_parser * const ap );
void ap_free( Arg_parser * const ap );
const char * ap_error( const struct Arg_parser * const ap );
const char * ap_error( const Arg_parser * const ap );
/* The number of arguments parsed. May be different from argc. */
int ap_arguments( const struct Arg_parser * const ap );
int ap_arguments( const Arg_parser * const ap );
/* If ap_code( i ) is 0, ap_argument( i ) is a non-option.
Else ap_argument( i ) is the option's argument (or empty). */
int ap_code( const struct Arg_parser * const ap, const int i );
int ap_code( const Arg_parser * const ap, const int i );
/* Full name of the option parsed (short or long). */
const char * ap_parsed_name( const struct Arg_parser * const ap, const int i );
const char * ap_parsed_name( const Arg_parser * const ap, const int i );
const char * ap_argument( const struct Arg_parser * const ap, const int i );
const char * ap_argument( const Arg_parser * const ap, const int i );
#ifdef __cplusplus
}

6
configure vendored
View file

@ -1,12 +1,12 @@
#! /bin/sh
# configure script for Pdlzip - LZMA lossless data compressor
# Copyright (C) 2010-2024 Antonio Diaz Diaz.
# Copyright (C) 2010-2025 Antonio Diaz Diaz.
#
# This configure script is free software: you have unlimited permission
# to copy, distribute, and modify it.
pkgname=pdlzip
pkgversion=1.14-rc1
pkgversion=1.14
progname=pdlzip
srctrigger=doc/${progname}.1
@ -171,7 +171,7 @@ echo "MAKEINFO = ${MAKEINFO}"
rm -f Makefile
cat > Makefile << EOF
# Makefile for Pdlzip - LZMA lossless data compressor
# Copyright (C) 2010-2024 Antonio Diaz Diaz.
# Copyright (C) 2010-2025 Antonio Diaz Diaz.
# This file was generated automatically by configure. Don't edit.
#
# This Makefile is free software: you have unlimited permission

View file

@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2.
.TH PDLZIP "1" "November 2024" "pdlzip 1.14-rc1" "User Commands"
.TH PDLZIP "1" "January 2025" "pdlzip 1.14" "User Commands"
.SH NAME
pdlzip \- reduces the size of files
.SH SYNOPSIS
@ -112,7 +112,7 @@ Report bugs to lzip\-bug@nongnu.org
.br
Pdlzip home page: http://www.nongnu.org/lzip/pdlzip.html
.SH COPYRIGHT
Copyright \(co 2024 Antonio Diaz Diaz.
Copyright \(co 2025 Antonio Diaz Diaz.
Public Domain 2009 Igor Pavlov.
License 2\-clause BSD.
.br

10
lzip.h
View file

@ -1,5 +1,5 @@
/* Pdlzip - LZMA lossless data compressor
Copyright (C) 2010-2024 Antonio Diaz Diaz.
Copyright (C) 2010-2025 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@ -188,13 +188,13 @@ static inline void Lt_set_member_size( Lzip_trailer data, unsigned long long sz
{ int i; for( i = 12; i <= 19; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; } }
struct Cl_options /* command-line options */
typedef struct Cl_options /* command-line options */
{
bool ignore_trailing;
bool loose_trailing;
};
} Cl_options;
static inline void Cl_options_init( struct Cl_options * cl_opts )
static inline void Cl_options_init( Cl_options * cl_opts )
{ cl_opts->ignore_trailing = true; cl_opts->loose_trailing = false; }
@ -202,8 +202,8 @@ static inline void set_retval( int * retval, const int new_val )
{ if( *retval < new_val ) *retval = new_val; }
static const char * const empty_msg = "Empty member not allowed.";
static const char * const trailing_msg = "Trailing data not allowed.";
static const char * const mem_msg = "Not enough memory.";
static const char * const trailing_msg = "Trailing data not allowed.";
/* defined in main.c */
extern int verbosity;

66
main.c
View file

@ -1,6 +1,6 @@
/* Pdlzip - LZMA lossless data compressor
2009-08-14 : Igor Pavlov : Public domain
Copyright (C) 2010-2024 Antonio Diaz Diaz.
Copyright (C) 2010-2025 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@ -85,7 +85,7 @@ static void show_file_error( const char * const filename,
static void internal_error( const char * const msg );
static const char * const program_name = "pdlzip";
static const char * const program_year = "2024";
static const char * const program_year = "2025";
static const char * invocation_name = "pdlzip"; /* default value */
static const struct { const char * from; const char * to; } known_extensions[] = {
@ -94,13 +94,13 @@ static const struct { const char * from; const char * to; } known_extensions[] =
{ ".lzma", "" },
{ 0, 0 } };
struct Lzma_options
typedef struct Lzma_options
{
int dictionary_size; /* 4 KiB .. 512 MiB */
int match_len_limit; /* 5 .. 273 */
};
} Lzma_options;
enum Mode { m_compress, m_decompress, m_test };
typedef enum Mode { m_compress, m_decompress, m_test } Mode;
/* Variables used in signal handler context.
They are not declared volatile because the handler never returns. */
@ -196,16 +196,16 @@ static void * resize_buffer( void * buf, const unsigned min_size )
}
struct Pretty_print
typedef struct Pretty_print
{
const char * name;
char * padded_name;
const char * stdin_name;
unsigned longest_name;
bool first_post;
};
} Pretty_print;
static void Pp_init( struct Pretty_print * const pp,
static void Pp_init( Pretty_print * const pp,
const char * const filenames[], const int num_filenames )
{
pp->name = 0;
@ -226,11 +226,10 @@ static void Pp_init( struct Pretty_print * const pp,
if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len;
}
void Pp_free( struct Pretty_print * const pp )
void Pp_free( Pretty_print * const pp )
{ if( pp->padded_name ) { free( pp->padded_name ); pp->padded_name = 0; } }
static void Pp_set_name( struct Pretty_print * const pp,
const char * const filename )
static void Pp_set_name( Pretty_print * const pp, const char * const filename )
{
unsigned name_len, padded_name_len, i = 0;
@ -248,10 +247,10 @@ static void Pp_set_name( struct Pretty_print * const pp,
pp->first_post = true;
}
static void Pp_reset( struct Pretty_print * const pp )
static void Pp_reset( Pretty_print * const pp )
{ if( pp->name && pp->name[0] ) pp->first_post = true; }
static void Pp_show_msg( struct Pretty_print * const pp, const char * const msg )
static void Pp_show_msg( Pretty_print * const pp, const char * const msg )
{
if( verbosity < 0 ) return;
if( pp->first_post )
@ -280,7 +279,7 @@ static void show_header( const unsigned dictionary_size )
}
/* separate numbers of 6 or more digits in groups of 3 digits using '_' */
/* separate numbers of 5 or more digits in groups of 3 digits using '_' */
static const char * format_num3( unsigned long long num )
{
enum { buffers = 8, bufsize = 4 * sizeof num, n = 10 };
@ -303,7 +302,7 @@ static const char * format_num3( unsigned long long num )
{ num /= 1000; prefix = si_prefix[i]; }
if( prefix ) *(--p) = prefix;
}
const bool split = num >= 100000;
const bool split = num >= 10000;
for( i = 0; ; )
{
@ -388,7 +387,7 @@ static int get_dict_size( const char * const arg, const char * const option_name
}
static void set_mode( enum Mode * const program_modep, const enum Mode new_mode )
static void set_mode( Mode * const program_modep, const Mode new_mode )
{
if( *program_modep != m_compress && *program_modep != new_mode )
{
@ -455,7 +454,7 @@ static void set_d_outname( const char * const name, const int eindex )
static int open_instream( const char * const name, struct stat * const in_statsp,
const enum Mode program_mode, const int eindex,
const Mode program_mode, const int eindex,
const bool one_to_one, const bool recompress )
{
if( program_mode == m_compress && !recompress && eindex >= 0 )
@ -540,7 +539,7 @@ static void signal_handler( int sig )
static bool check_tty_in( const char * const input_filename, const int infd,
const enum Mode program_mode, int * const retval )
const Mode program_mode, int * const retval )
{
if( ( program_mode == m_decompress || program_mode == m_test ) &&
isatty( infd ) ) /* for example /dev/tty */
@ -552,7 +551,7 @@ static bool check_tty_in( const char * const input_filename, const int infd,
return true;
}
static bool check_tty_out( const enum Mode program_mode )
static bool check_tty_out( const Mode program_mode )
{
if( program_mode == m_compress && isatty( outfd ) )
{ show_file_error( output_filename[0] ?
@ -596,8 +595,9 @@ static void close_and_set_permissions( const struct stat * const in_statsp )
}
static int compress( const int infd, const struct Lzma_options * const
encoder_options, struct Pretty_print * const pp )
static int compress( const int infd,
const Lzma_options * const encoder_options,
Pretty_print * const pp )
{
int retval = 0;
CLzmaEncHandle encoder = 0;
@ -734,8 +734,8 @@ static int lzma_decode( uint64_t unpackSize, CLzmaDec *decoder, const int infd,
}
static int lzip_decode( CLzmaDec *decoder, const int infd,
struct Pretty_print * const pp, uint8_t inBuf[],
static int lzip_decode( CLzmaDec * decoder, const int infd,
Pretty_print * const pp, uint8_t inBuf[],
int * const inPos, int * const inSize,
const unsigned dictionary_size, bool * const data0p )
{
@ -840,8 +840,8 @@ static int lzip_decode( CLzmaDec *decoder, const int infd,
}
static int decompress( const int infd, const struct Cl_options * const cl_opts,
struct Pretty_print * const pp,
static int decompress( const int infd, const Cl_options * const cl_opts,
Pretty_print * const pp,
const bool from_stdin, const bool testing )
{
uint64_t unpackSize = 0;
@ -1031,7 +1031,7 @@ int main( const int argc, const char * const argv[] )
{
/* Mapping from gzip/bzip2 style 0..9 compression levels to the
corresponding LZMA compression parameters. */
const struct Lzma_options option_mapping[] =
const Lzma_options option_mapping[] =
{
{ 1 << 16, 5 }, /* -0 */
{ 1 << 20, 5 }, /* -1 */
@ -1043,11 +1043,10 @@ int main( const int argc, const char * const argv[] )
{ 1 << 24, 68 }, /* -7 */
{ 3 << 23, 132 }, /* -8 */
{ 1 << 25, 273 } }; /* -9 */
struct Lzma_options encoder_options = option_mapping[6]; /* default = "-6" */
Lzma_options encoder_options = option_mapping[6]; /* default = "-6" */
const char * default_output_filename = "";
enum Mode program_mode = m_compress;
int i;
struct Cl_options cl_opts; /* command-line options */
Mode program_mode = m_compress;
Cl_options cl_opts; /* command-line options */
Cl_options_init( &cl_opts );
bool force = false;
bool keep_input_files = false;
@ -1056,7 +1055,7 @@ int main( const int argc, const char * const argv[] )
if( argc > 0 ) invocation_name = argv[0];
enum { opt_lt = 256 };
const struct ap_Option options[] =
const ap_Option options[] =
{
{ '0', "fast", ap_no },
{ '1', 0, ap_no },
@ -1091,7 +1090,7 @@ int main( const int argc, const char * const argv[] )
CRC32_init();
/* static because valgrind complains and memory management in C sucks */
static struct Arg_parser parser;
static Arg_parser parser;
if( !ap_init( &parser, argc, argv, options, 0 ) )
{ show_error( mem_msg, 0, false ); return 1; }
if( ap_error( &parser ) ) /* bad option */
@ -1144,6 +1143,7 @@ int main( const int argc, const char * const argv[] )
filenames = resize_buffer( filenames, num_filenames * sizeof filenames[0] );
filenames[0] = "-";
int i;
bool filenames_given = false;
for( i = 0; argind + i < ap_arguments( &parser ); ++i )
{
@ -1165,7 +1165,7 @@ int main( const int argc, const char * const argv[] )
if( !to_stdout && program_mode != m_test && ( filenames_given || to_file ) )
set_signals( signal_handler );
static struct Pretty_print pp;
static Pretty_print pp;
Pp_init( &pp, filenames, num_filenames );
int failed_tests = 0;

View file

@ -1,6 +1,6 @@
#! /bin/sh
# check script for Pdlzip - LZMA lossless data compressor
# Copyright (C) 2010-2024 Antonio Diaz Diaz.
# Copyright (C) 2010-2025 Antonio Diaz Diaz.
#
# This script is free software: you have unlimited permission
# to copy, distribute, and modify it.
@ -128,7 +128,6 @@ rm -f copy out || framework_failure
printf "to be overwritten" > out || framework_failure
"${LZIP}" -df -o out < "${in_lz}" || test_failed $LINENO
cmp in out || test_failed $LINENO
rm -f out || framework_failure
"${LZIP}" -d -o ./- "${in_lz}" || test_failed $LINENO
cmp in ./- || test_failed $LINENO
rm -f ./- || framework_failure
@ -141,7 +140,7 @@ cp "${in_lz}" anyothername || framework_failure
test_failed $LINENO
cmp in out || test_failed $LINENO
cmp in anyothername.out || test_failed $LINENO
rm -f out anyothername.out || framework_failure
rm -f anyothername.out || framework_failure
"${LZIP}" -tq in "${in_lz}"
[ $? = 2 ] || test_failed $LINENO