147 sigemptyset(&sa.sa_mask);
149 sa.sa_handler = &progress_signal_handler;
318 static char buf[128];
320 size_t left =
sizeof(
buf);
334 const double ratio = uncompressed_pos > 0
335 ? (double)(compressed_pos) / (double)(uncompressed_pos)
358 static const char unit[][8] = {
364 size_t unit_index = 0;
367 double speed = (double)(uncompressed_pos)
368 / ((double)(elapsed) * (1024.0 / 1000.0));
371 while (speed > 999.0) {
385 speed > 9.9 ? 0 : 1, speed, unit[unit_index]);
396 static char buf[
sizeof(
"9999:59:59")];
402 if (seconds == 0 || seconds > ((9999 * 60) + 59) * 60 + 59)
409 const uint32_t hours = minutes / 60;
413 hours, minutes, seconds);
444 * ((
double)(elapsed) / 1000.0) / (double)(
in_pos));
448 static char buf[
sizeof(
"9 h 55 min")];
451 if (remaining <= 10) {
456 }
else if (remaining <= 50) {
459 remaining = (remaining + 4) / 5 * 5;
462 }
else if (remaining <= 590) {
465 remaining = (remaining + 9) / 10 * 10;
467 remaining / 60, remaining % 60);
469 }
else if (remaining <= 59 * 60) {
472 remaining = (remaining + 59) / 60;
475 }
else if (remaining <= 9 * 3600 + 50 * 60) {
478 remaining = (remaining + 599) / 600 * 10;
480 remaining / 60, remaining % 60);
482 }
else if (remaining <= 23 * 3600) {
485 remaining = (remaining + 3599) / 3600;
488 }
else if (remaining <= 9 * 24 * 3600 + 23 * 3600) {
491 remaining = (remaining + 3599) / 3600;
493 remaining / 24, remaining % 24);
495 }
else if (remaining <= 999 * 24 * 3600) {
498 remaining = (remaining + 24 * 3600 - 1) / (24 * 3600);
527 assert(*in_pos <= progress_strm->total_in);
534 *uncompressed_pos = *
in_pos;
536 *compressed_pos = *
in_pos;
576 const char *cols[5] = {
583 fprintf(stderr,
"\r %*s %*s %*s %10s %10s\r",
645 && (compressed_pos == 0 || uncompressed_pos == 0))
658 const char *cols[5] = {
665 fprintf(stderr,
"\r %*s %*s %*s %10s %10s\n",
686 compressed_pos, uncompressed_pos,
true));
690 if (speed[0] !=
'\0')
691 fprintf(stderr,
", %s", speed);
694 if (elapsed_str[0] !=
'\0')
695 fprintf(stderr,
", %s", elapsed_str);
729 vfprintf(stderr, fmt, ap);
807 return _(
"No integrity check; not verifying file integrity");
810 return _(
"Unsupported type of integrity check; "
811 "not verifying file integrity");
817 return _(
"Memory usage limit reached");
820 return _(
"File format not recognized");
823 return _(
"Unsupported options");
826 return _(
"Compressed data is corrupt");
829 return _(
"Unexpected end of input");
841 return _(
"Internal error (bug)");
862 message(
v,
_(
"%s MiB of memory is required. "
863 "The limiter is disabled."),
871 char memlimitstr[128];
877 snprintf(memlimitstr,
sizeof(memlimitstr),
"%s B",
886 snprintf(memlimitstr,
sizeof(memlimitstr),
"%s MiB",
890 message(
v,
_(
"%s MiB of memory is required. The limit is %s."),
933 const char *mf =
NULL;
996 ",mode=%s,nice=%" PRIu32 ",mf=%s"
998 opt->
lc, opt->
lp, opt->
pb,
1009 static const char bcj_names[][9] = {
1057 fprintf(stderr,
_(
"%s: Filter chain: %s\n"),
progname,
buf);
1083 printf(
"liblzma %s\n", lzma_version_string());
1093 printf(
_(
"Usage: %s [OPTION]... [FILE]...\n"
1094 "Compress or decompress FILEs in the .xz format.\n\n"),
1100 puts(
_(
"Mandatory arguments to long options are mandatory "
1101 "for short options too.\n"));
1104 puts(
_(
" Operation mode:\n"));
1107 " -z, --compress force compression\n"
1108 " -d, --decompress force decompression\n"
1109 " -t, --test test compressed file integrity\n"
1110 " -l, --list list information about .xz files"));
1113 puts(
_(
"\n Operation modifiers:\n"));
1116 " -k, --keep keep (don't delete) input files\n"
1117 " -f, --force force overwrite of output file and (de)compress links\n"
1118 " -c, --stdout write to standard output and don't delete input files"));
1122 " --single-stream decompress only the first stream, and silently\n"
1123 " ignore possible remaining input data"));
1125 " --no-sparse do not create sparse files when decompressing\n"
1126 " -S, --suffix=.SUF use the suffix `.SUF' on compressed files\n"
1127 " --files[=FILE] read filenames to process from FILE; if FILE is\n"
1128 " omitted, filenames are read from the standard input;\n"
1129 " filenames must be terminated with the newline character\n"
1130 " --files0[=FILE] like --files but use the null character as terminator"));
1134 puts(
_(
"\n Basic file format and compression options:\n"));
1136 " -F, --format=FMT file format to encode or decode; possible values are\n"
1137 " `auto' (default), `xz', `lzma', and `raw'\n"
1138 " -C, --check=CHECK integrity check type: `none' (use with caution),\n"
1139 " `crc32', `crc64' (default), or `sha256'"));
1141 " --ignore-check don't verify the integrity check when decompressing"));
1145 " -0 ... -9 compression preset; default is 6; take compressor *and*\n"
1146 " decompressor memory usage into account before using 7-9!"));
1149 " -e, --extreme try to improve compression ratio by using more CPU time;\n"
1150 " does not affect decompressor memory requirements"));
1153 " -T, --threads=NUM use at most NUM threads; the default is 1; set to 0\n"
1154 " to use as many threads as there are processor cores"));
1158 " --block-size=SIZE\n"
1159 " start a new .xz block after every SIZE bytes of input;\n"
1160 " use this to set the block size for threaded compression"));
1162 " --block-list=SIZES\n"
1163 " start a new .xz block after the given comma-separated\n"
1164 " intervals of uncompressed data"));
1166 " --flush-timeout=TIMEOUT\n"
1167 " when compressing, if more than TIMEOUT milliseconds has\n"
1168 " passed since the previous flush and reading more input\n"
1169 " would block, all pending data is flushed out"
1172 " --memlimit-compress=LIMIT\n"
1173 " --memlimit-decompress=LIMIT\n"
1174 " -M, --memlimit=LIMIT\n"
1175 " set memory usage limit for compression, decompression,\n"
1176 " or both; LIMIT is in bytes, % of RAM, or 0 for defaults"));
1179 " --no-adjust if compression settings exceed the memory usage limit,\n"
1180 " give an error instead of adjusting the settings downwards"));
1185 "\n Custom filter chain for compression (alternative for using presets):"));
1187 #if defined(HAVE_ENCODER_LZMA1) || defined(HAVE_DECODER_LZMA1) \
1188 || defined(HAVE_ENCODER_LZMA2) || defined(HAVE_DECODER_LZMA2)
1195 " --lzma1[=OPTS] LZMA1 or LZMA2; OPTS is a comma-separated list of zero or\n"
1196 " --lzma2[=OPTS] more of the following options (valid values; default):\n"
1197 " preset=PRE reset options to a preset (0-9[e])\n"
1198 " dict=NUM dictionary size (4KiB - 1536MiB; 8MiB)\n"
1199 " lc=NUM number of literal context bits (0-4; 3)\n"
1200 " lp=NUM number of literal position bits (0-4; 0)\n"
1201 " pb=NUM number of position bits (0-4; 2)\n"
1202 " mode=MODE compression mode (fast, normal; normal)\n"
1203 " nice=NUM nice length of a match (2-273; 64)\n"
1204 " mf=NAME match finder (hc3, hc4, bt2, bt3, bt4; bt4)\n"
1205 " depth=NUM maximum search depth; 0=automatic (default)"));
1210 " --x86[=OPTS] x86 BCJ filter (32-bit and 64-bit)\n"
1211 " --powerpc[=OPTS] PowerPC BCJ filter (big endian only)\n"
1212 " --ia64[=OPTS] IA-64 (Itanium) BCJ filter\n"
1213 " --arm[=OPTS] ARM BCJ filter (little endian only)\n"
1214 " --armthumb[=OPTS] ARM-Thumb BCJ filter (little endian only)\n"
1215 " --sparc[=OPTS] SPARC BCJ filter\n"
1216 " Valid OPTS for all BCJ filters:\n"
1217 " start=NUM start offset for conversions (default=0)"));
1219 #if defined(HAVE_ENCODER_DELTA) || defined(HAVE_DECODER_DELTA)
1222 " --delta[=OPTS] Delta filter; valid OPTS (valid values; default):\n"
1223 " dist=NUM distance between bytes being subtracted\n"
1224 " from each other (1-256; 1)"));
1229 puts(
_(
"\n Other options:\n"));
1232 " -q, --quiet suppress warnings; specify twice to suppress errors too\n"
1233 " -v, --verbose be verbose; specify twice for even more verbose"));
1237 " -Q, --no-warn make warnings not affect the exit status"));
1239 " --robot use machine-parsable messages (useful for scripts)"));
1242 " --info-memory display the total amount of RAM and the currently active\n"
1243 " memory usage limits, and exit"));
1245 " -h, --help display the short help (lists only the basic options)\n"
1246 " -H, --long-help display this long help and exit"));
1249 " -h, --help display this short help and exit\n"
1250 " -H, --long-help display the long help (lists also the advanced options)"));
1254 " -V, --version display the version number and exit"));
1256 puts(
_(
"\nWith no FILE, or when FILE is -, read standard input.\n"));
1262 printf(
_(
"Report bugs to <%s> (in English or Finnish).\n"),
1266 #if LZMA_VERSION_STABILITY != LZMA_VERSION_STABILITY_STABLE
1268 "THIS IS A DEVELOPMENT VERSION NOT INTENDED FOR PRODUCTION USE."));
const char stdin_filename[]
#define LZMA_FILTER_SPARC
#define LZMA_FILTER_ARMTHUMB
#define LZMA_FILTER_POWERPC
const lzma_allocator const uint8_t size_t uint8_t size_t * out_pos
const lzma_allocator const uint8_t size_t * in_pos
const lzma_allocator const uint8_t size_t in_size
#define PACKAGE_BUGREPORT
enum operation_mode opt_mode
const lzma_filter * filters
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
#define LZMA_FILTER_DELTA
Filter ID.
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type special files
uint64_t hardware_memlimit_get(enum operation_mode mode)
Get the current memory usage limit for compression or decompression.
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t alarm
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
#define LZMA_FILTER_LZMA2
LZMA2 Filter ID.
@ LZMA_MODE_FAST
Fast compression.
@ LZMA_MODE_NORMAL
Normal compression.
#define LZMA_FILTER_LZMA1
LZMA1 Filter ID.
@ LZMA_MF_HC4
Hash Chain with 2-, 3-, and 4-byte hashing.
@ LZMA_MF_BT4
Binary Tree with 2-, 3-, and 4-byte hashing.
@ LZMA_MF_HC3
Hash Chain with 2- and 3-byte hashing.
@ LZMA_MF_BT2
Binary Tree with 2-byte hashing.
@ LZMA_MF_BT3
Binary Tree with 2- and 3-byte hashing.
#define lzma_attribute(attr)
assert(limit<=UINT32_MAX/2)
void message_progress_end(bool success)
Finishes the progress message if we were in verbose mode.
void message_help(bool long_help)
Print the help message.
static const char * progress_percentage(uint64_t in_pos)
Make the string indicating completion percentage.
static void progress_pos(uint64_t *in_pos, uint64_t *compressed_pos, uint64_t *uncompressed_pos)
Get how much uncompressed and compressed data has been processed.
static const char * progress_speed(uint64_t uncompressed_pos, uint64_t elapsed)
Make the string containing the processing speed of uncompressed data.
void message_verbosity_increase(void)
Increase verbosity level by one step unless it was at maximum.
void message_set_files(unsigned int files)
Set the total number of files to be processed.
static bool progress_active
void message_version(void)
Prints the version number to stdout and exits with exit status SUCCESS.
static const char * progress_time(uint64_t mseconds)
static const char * uint32_to_optstr(uint32_t num)
Convert uint32_t to a nice string for –lzma[12]=dict=SIZE.
static bool current_filename_printed
static bool progress_automatic
static bool first_filename_printed
static const char * progress_sizes(uint64_t compressed_pos, uint64_t uncompressed_pos, bool final)
static enum message_verbosity verbosity
Verbosity level.
static uint64_t progress_next_update
Elapsed time when the next progress message update should be done.
void message_filename(const char *src_name)
Set the name of the current file and possibly print it too.
static bool progress_is_from_passthru
void message_mem_needed(enum message_verbosity v, uint64_t memusage)
Display how much memory was needed and how much the limit was.
void message(enum message_verbosity v, const char *fmt,...)
static const char * filename
Filename which we will print with the verbose messages.
static unsigned int files_total
Total number of input files; zero if unknown.
void message_init(void)
Initializes the message functions.
void message_signal_handler(void)
void message_verbosity_decrease(void)
Decrease verbosity level by one step unless it was at minimum.
void message_error(const char *fmt,...)
void message_warning(const char *fmt,...)
static const char * progress_remaining(uint64_t in_pos, uint64_t elapsed)
void message_filters_show(enum message_verbosity v, const lzma_filter *filters)
Print the filter chain.
static unsigned int files_pos
Number of the current file.
static bool progress_needs_updating
void message_progress_start(lzma_stream *strm, bool is_passthru, uint64_t in_size)
Start progress info handling.
void message_filters_to_str(char buf[FILTERS_STR_SIZE], const lzma_filter *filters, bool all_known)
Get the filter chain as a string.
void message_try_help(void)
Print a message that user should try –help.
void message_progress_update(void)
const char * message_strm(lzma_ret code)
Convert lzma_ret to a string.
static bool progress_started
static void print_filename(void)
static void vmessage(enum message_verbosity v, const char *fmt, va_list ap)
void message_fatal(const char *fmt,...)
static lzma_stream * progress_strm
Pointer to lzma_stream used to do the encoding or decoding.
static uint64_t expected_in_size
static void progress_flush(bool finished)
enum message_verbosity message_verbosity_get(void)
Get the current verbosity level.
const int message_progress_sigs[]
Signals used for progress message handling.
message_verbosity
Verbosity levels.
@ V_WARNING
Errors and warnings.
@ V_VERBOSE
Errors, warnings, and verbose statistics.
@ V_ERROR
Only error messages.
#define FILTERS_STR_SIZE
Buffer size for message_filters_to_str()
uint64_t mytime_get_elapsed(void)
Get the number of milliseconds since the operation started.
void signals_unblock(void)
Unblock the signals blocked by signals_block().
void * options
Pointer to filter-specific options structure.
uint32_t start_offset
Start offset for conversions.
Options for the Delta filter.
uint32_t dist
Delta distance.
Options specific to the LZMA1 and LZMA2 filters.
uint32_t nice_len
Nice length of a match.
uint32_t lp
Number of literal position bits.
uint32_t depth
Maximum search depth in the match finder.
uint32_t lc
Number of literal context bits.
uint32_t pb
Number of position bits.
uint32_t dict_size
Dictionary size in bytes.
Passing data to and from liblzma.
void set_exit_status(enum exit_status_type new_status)
Common includes, definitions, and prototypes.
const char * uint64_to_str(uint64_t value, uint32_t slot)
Convert uint64_t to a string.
const char * uint64_to_nicestr(uint64_t value, enum nicestr_unit unit_min, enum nicestr_unit unit_max, bool always_also_bytes, uint32_t slot)
Convert uint64_t to a nice human readable string.
void my_snprintf(char **pos, size_t *left, const char *fmt,...)
uint64_t round_up_to_mib(uint64_t n)
Round an integer up to the next full MiB and convert to MiB.
#define LZMA_VLI_UNKNOWN
VLI value to denote that the value is unknown.
lzma_ret
Return values used by several functions in liblzma.
@ LZMA_PROG_ERROR
Programming error.
@ LZMA_DATA_ERROR
Data is corrupt.
@ LZMA_MEM_ERROR
Cannot allocate memory.
@ LZMA_FORMAT_ERROR
Memory usage limit was reached.
@ LZMA_STREAM_END
End of stream was reached.
@ LZMA_UNSUPPORTED_CHECK
Cannot calculate the integrity check.
@ LZMA_BUF_ERROR
No progress is possible.
@ LZMA_GET_CHECK
Integrity check type is now available.
@ LZMA_NO_CHECK
Input stream has no integrity check.
@ LZMA_OPTIONS_ERROR
Invalid or unsupported options.
@ LZMA_OK
Operation completed successfully.
#define LZMA_VERSION
Compile-time version number.
#define LZMA_VERSION_STRING
Compile-time version as a string.