2007-12-08 23:42:33 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2008-11-19 22:52:24 +01:00
|
|
|
/// \file xzdec.c
|
2008-11-20 17:05:52 +01:00
|
|
|
/// \brief Simple single-threaded tool to uncompress .xz or .lzma files
|
2007-12-08 23:42:33 +01:00
|
|
|
//
|
|
|
|
// Copyright (C) 2007 Lasse Collin
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "sysdefs.h"
|
|
|
|
|
2008-11-19 19:46:52 +01:00
|
|
|
#include <errno.h>
|
2007-12-08 23:42:33 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2009-01-31 09:13:09 +01:00
|
|
|
#ifdef _WIN32
|
2008-01-18 13:17:37 +01:00
|
|
|
# include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
2007-12-08 23:42:33 +01:00
|
|
|
#include "getopt.h"
|
|
|
|
#include "physmem.h"
|
|
|
|
|
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
#ifdef LZMADEC
|
|
|
|
# define TOOL_FORMAT "lzma"
|
|
|
|
#else
|
|
|
|
# define TOOL_FORMAT "xz"
|
|
|
|
#endif
|
2007-12-08 23:42:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
/// Number of bytes to use memory at maximum
|
2008-11-19 19:46:52 +01:00
|
|
|
static uint64_t memlimit;
|
2007-12-08 23:42:33 +01:00
|
|
|
|
|
|
|
/// Program name to be shown in error messages
|
|
|
|
static const char *argv0;
|
|
|
|
|
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
static void lzma_attribute((noreturn))
|
|
|
|
my_exit(void)
|
|
|
|
{
|
|
|
|
int status = EXIT_SUCCESS;
|
|
|
|
|
|
|
|
// Close stdout. We don't care about stderr, because we write to it
|
|
|
|
// only when an error has already occurred.
|
|
|
|
const int ferror_err = ferror(stdout);
|
|
|
|
const int fclose_err = fclose(stdout);
|
|
|
|
|
|
|
|
if (ferror_err || fclose_err) {
|
|
|
|
// If it was fclose() that failed, we have the reason
|
|
|
|
// in errno. If only ferror() indicated an error,
|
|
|
|
// we have no idea what the reason was.
|
|
|
|
fprintf(stderr, "%s: Cannot write to standard output: %s\n",
|
|
|
|
argv0, fclose_err
|
|
|
|
? strerror(errno) : "Unknown error");
|
|
|
|
status = EXIT_FAILURE;
|
|
|
|
}
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
exit(status);
|
|
|
|
}
|
2007-12-08 23:42:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
static void lzma_attribute((noreturn))
|
|
|
|
help(void)
|
|
|
|
{
|
|
|
|
printf(
|
|
|
|
"Usage: %s [OPTION]... [FILE]...\n"
|
2008-11-20 17:05:52 +01:00
|
|
|
"Uncompress files in the ." TOOL_FORMAT " format to the standard output.\n"
|
2007-12-08 23:42:33 +01:00
|
|
|
"\n"
|
|
|
|
" -c, --stdout (ignored)\n"
|
|
|
|
" -d, --decompress (ignored)\n"
|
|
|
|
" -k, --keep (ignored)\n"
|
2008-11-20 17:05:52 +01:00
|
|
|
" -f, --force (ignored)\n"
|
2008-11-19 19:46:52 +01:00
|
|
|
" -M, --memory=NUM use NUM bytes of memory at maximum (0 means default);\n"
|
|
|
|
" the suffixes k, M, G, Ki, Mi, and Gi are supported.\n"
|
2007-12-08 23:42:33 +01:00
|
|
|
" -h, --help display this help and exit\n"
|
|
|
|
" -V, --version display version and license information and exit\n"
|
|
|
|
"\n"
|
|
|
|
"With no FILE, or when FILE is -, read standard input.\n"
|
|
|
|
"\n"
|
2008-01-06 18:45:27 +01:00
|
|
|
"On this configuration, the tool will use about %" PRIu64
|
|
|
|
" MiB of memory at maximum.\n"
|
2007-12-08 23:42:33 +01:00
|
|
|
"\n"
|
|
|
|
"Report bugs to <" PACKAGE_BUGREPORT "> (in English or Finnish).\n",
|
2008-11-20 17:05:52 +01:00
|
|
|
argv0, (memlimit + 512 * 1024) / (1024 * 1024));
|
|
|
|
my_exit();
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void lzma_attribute((noreturn))
|
|
|
|
version(void)
|
|
|
|
{
|
2008-11-20 17:05:52 +01:00
|
|
|
printf(TOOL_FORMAT "dec " PACKAGE_VERSION "\n"
|
|
|
|
"liblzma %s\n", lzma_version_string());
|
|
|
|
|
|
|
|
my_exit();
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Finds out the amount of physical memory in the system, and sets
|
|
|
|
/// a default memory usage limit.
|
|
|
|
static void
|
2008-08-28 21:53:15 +02:00
|
|
|
set_default_memlimit(void)
|
2007-12-08 23:42:33 +01:00
|
|
|
{
|
2008-11-19 19:46:52 +01:00
|
|
|
const uint64_t mem = physmem();
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-11-19 19:46:52 +01:00
|
|
|
if (mem == 0)
|
2007-12-08 23:42:33 +01:00
|
|
|
// Cannot autodetect, use 10 MiB as the default limit.
|
2008-08-28 21:53:15 +02:00
|
|
|
memlimit = (1U << 23) + (1U << 21);
|
2008-11-19 19:46:52 +01:00
|
|
|
else
|
|
|
|
// Limit is 33 % of RAM.
|
|
|
|
memlimit = mem / 3;
|
2007-12-08 23:42:33 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-20 10:01:29 +01:00
|
|
|
/// \brief Converts a string to uint64_t
|
2007-12-08 23:42:33 +01:00
|
|
|
///
|
2008-11-19 22:52:24 +01:00
|
|
|
/// This is rudely copied from src/xz/util.c and modified a little. :-(
|
2007-12-08 23:42:33 +01:00
|
|
|
///
|
2008-11-20 10:01:29 +01:00
|
|
|
static uint64_t
|
2008-11-19 19:46:52 +01:00
|
|
|
str_to_uint64(const char *value)
|
2007-12-08 23:42:33 +01:00
|
|
|
{
|
2008-11-20 10:01:29 +01:00
|
|
|
uint64_t result = 0;
|
2007-12-08 23:42:33 +01:00
|
|
|
|
|
|
|
if (*value < '0' || *value > '9') {
|
|
|
|
fprintf(stderr, "%s: %s: Not a number", argv0, value);
|
2008-11-20 17:05:52 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
// Don't overflow.
|
2008-11-20 10:01:29 +01:00
|
|
|
if (result > (UINT64_MAX - 9) / 10)
|
|
|
|
return UINT64_MAX;
|
2007-12-08 23:42:33 +01:00
|
|
|
|
|
|
|
result *= 10;
|
|
|
|
result += *value - '0';
|
|
|
|
++value;
|
|
|
|
} while (*value >= '0' && *value <= '9');
|
|
|
|
|
|
|
|
if (*value != '\0') {
|
|
|
|
// Look for suffix.
|
|
|
|
static const struct {
|
2008-06-11 14:08:44 +02:00
|
|
|
const char name[4];
|
2008-11-20 10:01:29 +01:00
|
|
|
uint32_t multiplier;
|
2007-12-08 23:42:33 +01:00
|
|
|
} suffixes[] = {
|
2008-06-11 14:08:44 +02:00
|
|
|
{ "k", 1000 },
|
|
|
|
{ "kB", 1000 },
|
|
|
|
{ "M", 1000000 },
|
|
|
|
{ "MB", 1000000 },
|
|
|
|
{ "G", 1000000000 },
|
|
|
|
{ "GB", 1000000000 },
|
|
|
|
{ "Ki", 1024 },
|
|
|
|
{ "KiB", 1024 },
|
|
|
|
{ "Mi", 1048576 },
|
|
|
|
{ "MiB", 1048576 },
|
|
|
|
{ "Gi", 1073741824 },
|
|
|
|
{ "GiB", 1073741824 }
|
2007-12-08 23:42:33 +01:00
|
|
|
};
|
|
|
|
|
2008-11-20 10:01:29 +01:00
|
|
|
uint32_t multiplier = 0;
|
2008-06-11 14:08:44 +02:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(suffixes); ++i) {
|
2007-12-08 23:42:33 +01:00
|
|
|
if (strcmp(value, suffixes[i].name) == 0) {
|
|
|
|
multiplier = suffixes[i].multiplier;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (multiplier == 0) {
|
|
|
|
fprintf(stderr, "%s: %s: Invalid suffix",
|
|
|
|
argv0, value);
|
2008-11-20 17:05:52 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't overflow here either.
|
2008-11-20 10:01:29 +01:00
|
|
|
if (result > UINT64_MAX / multiplier)
|
|
|
|
result = UINT64_MAX;
|
2008-06-11 14:08:44 +02:00
|
|
|
else
|
|
|
|
result *= multiplier;
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Parses command line options.
|
|
|
|
static void
|
|
|
|
parse_options(int argc, char **argv)
|
|
|
|
{
|
|
|
|
static const char short_opts[] = "cdkfM:hV";
|
|
|
|
static const struct option long_opts[] = {
|
|
|
|
{ "stdout", no_argument, NULL, 'c' },
|
|
|
|
{ "to-stdout", no_argument, NULL, 'c' },
|
|
|
|
{ "decompress", no_argument, NULL, 'd' },
|
|
|
|
{ "uncompress", no_argument, NULL, 'd' },
|
|
|
|
{ "force", no_argument, NULL, 'f' },
|
|
|
|
{ "keep", no_argument, NULL, 'k' },
|
|
|
|
{ "memory", required_argument, NULL, 'M' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL))
|
|
|
|
!= -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
case 'd':
|
|
|
|
case 'f':
|
2008-11-20 17:05:52 +01:00
|
|
|
case 'k':
|
2007-12-08 23:42:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M':
|
2008-11-19 19:46:52 +01:00
|
|
|
memlimit = str_to_uint64(optarg);
|
|
|
|
if (memlimit == 0)
|
|
|
|
set_default_memlimit();
|
|
|
|
|
2007-12-08 23:42:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
help();
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
version();
|
|
|
|
|
|
|
|
default:
|
2008-11-20 17:05:52 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2008-11-20 17:05:52 +01:00
|
|
|
uncompress(lzma_stream *strm, FILE *file, const char *filename)
|
2007-12-08 23:42:33 +01:00
|
|
|
{
|
|
|
|
lzma_ret ret;
|
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
// Initialize the decoder
|
|
|
|
#ifdef LZMADEC
|
|
|
|
ret = lzma_alone_decoder(strm, memlimit);
|
|
|
|
#else
|
|
|
|
ret = lzma_stream_decoder(strm, memlimit, LZMA_CONCATENATED);
|
|
|
|
#endif
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
// The only reasonable error here is LZMA_MEM_ERROR.
|
|
|
|
// FIXME: Maybe also LZMA_MEMLIMIT_ERROR in future?
|
2007-12-08 23:42:33 +01:00
|
|
|
if (ret != LZMA_OK) {
|
|
|
|
fprintf(stderr, "%s: ", argv0);
|
|
|
|
|
|
|
|
if (ret == LZMA_MEM_ERROR)
|
|
|
|
fprintf(stderr, "%s\n", strerror(ENOMEM));
|
|
|
|
else
|
|
|
|
fprintf(stderr, "Internal program error (bug)\n");
|
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
// Input and output buffers
|
|
|
|
uint8_t in_buf[BUFSIZ];
|
|
|
|
uint8_t out_buf[BUFSIZ];
|
2008-08-28 21:53:15 +02:00
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
strm->avail_in = 0;
|
|
|
|
strm->next_out = out_buf;
|
|
|
|
strm->avail_out = BUFSIZ;
|
2008-08-28 21:53:15 +02:00
|
|
|
|
|
|
|
lzma_action action = LZMA_RUN;
|
2007-12-08 23:42:33 +01:00
|
|
|
|
|
|
|
while (true) {
|
2008-11-20 17:05:52 +01:00
|
|
|
if (strm->avail_in == 0) {
|
|
|
|
strm->next_in = in_buf;
|
|
|
|
strm->avail_in = fread(in_buf, 1, BUFSIZ, file);
|
2008-08-28 21:53:15 +02:00
|
|
|
|
|
|
|
if (ferror(file)) {
|
|
|
|
// POSIX says that fread() sets errno if
|
|
|
|
// an error occurred. ferror() doesn't
|
|
|
|
// touch errno.
|
|
|
|
fprintf(stderr, "%s: %s: Error reading "
|
|
|
|
"input file: %s\n",
|
|
|
|
argv0, filename,
|
|
|
|
strerror(errno));
|
2008-11-20 17:05:52 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2008-08-28 21:53:15 +02:00
|
|
|
}
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
#ifndef LZMADEC
|
|
|
|
// When using LZMA_CONCATENATED, we need to tell
|
|
|
|
// liblzma when it has got all the input.
|
2008-08-28 21:53:15 +02:00
|
|
|
if (feof(file))
|
|
|
|
action = LZMA_FINISH;
|
2008-11-20 17:05:52 +01:00
|
|
|
#endif
|
2008-08-28 21:53:15 +02:00
|
|
|
}
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
ret = lzma_code(strm, action);
|
2007-12-08 23:42:33 +01:00
|
|
|
|
|
|
|
// Write and check write error before checking decoder error.
|
|
|
|
// This way as much data as possible gets written to output
|
2008-08-28 21:53:15 +02:00
|
|
|
// even if decoder detected an error.
|
2008-11-20 17:05:52 +01:00
|
|
|
if (strm->avail_out == 0 || ret != LZMA_OK) {
|
|
|
|
const size_t write_size = BUFSIZ - strm->avail_out;
|
2008-08-28 21:53:15 +02:00
|
|
|
|
|
|
|
if (fwrite(out_buf, 1, write_size, stdout)
|
|
|
|
!= write_size) {
|
|
|
|
// Wouldn't be a surprise if writing to stderr
|
|
|
|
// would fail too but at least try to show an
|
|
|
|
// error message.
|
|
|
|
fprintf(stderr, "%s: Cannot write to "
|
|
|
|
"standard output: %s\n", argv0,
|
|
|
|
strerror(errno));
|
2008-11-20 17:05:52 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2008-08-28 21:53:15 +02:00
|
|
|
}
|
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
strm->next_out = out_buf;
|
|
|
|
strm->avail_out = BUFSIZ;
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != LZMA_OK) {
|
2008-11-20 17:05:52 +01:00
|
|
|
if (ret == LZMA_STREAM_END) {
|
|
|
|
#ifdef LZMADEC
|
|
|
|
// Check that there's no trailing garbage.
|
|
|
|
if (strm->avail_in != 0
|
|
|
|
|| fread(in_buf, 1, 1, file)
|
|
|
|
!= 0
|
|
|
|
|| !feof(file))
|
|
|
|
ret = LZMA_DATA_ERROR;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
#else
|
|
|
|
// lzma_stream_decoder() already guarantees
|
|
|
|
// that there's no trailing garbage.
|
|
|
|
assert(strm->avail_in == 0);
|
|
|
|
assert(action == LZMA_FINISH);
|
|
|
|
assert(feof(file));
|
2007-12-08 23:42:33 +01:00
|
|
|
return;
|
2008-11-20 17:05:52 +01:00
|
|
|
#endif
|
|
|
|
}
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
const char *msg;
|
2007-12-08 23:42:33 +01:00
|
|
|
switch (ret) {
|
|
|
|
case LZMA_MEM_ERROR:
|
2008-11-20 17:05:52 +01:00
|
|
|
msg = strerror(ENOMEM);
|
|
|
|
break;
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
case LZMA_MEMLIMIT_ERROR:
|
2008-11-20 17:05:52 +01:00
|
|
|
msg = "Memory usage limit reached";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LZMA_FORMAT_ERROR:
|
|
|
|
msg = "File format not recognized";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LZMA_OPTIONS_ERROR:
|
|
|
|
// FIXME: Better message?
|
|
|
|
msg = "Unsupported compression options";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LZMA_DATA_ERROR:
|
|
|
|
msg = "File is corrupt";
|
|
|
|
break;
|
2008-08-28 21:53:15 +02:00
|
|
|
|
2007-12-08 23:42:33 +01:00
|
|
|
case LZMA_BUF_ERROR:
|
2008-11-20 17:05:52 +01:00
|
|
|
msg = "Unexpected end of input";
|
2007-12-08 23:42:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-11-20 17:05:52 +01:00
|
|
|
msg = "Internal program error (bug)";
|
|
|
|
break;
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|
2008-11-20 17:05:52 +01:00
|
|
|
|
|
|
|
fprintf(stderr, "%s: %s: %s", argv0, filename, msg);
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2008-11-20 17:05:52 +01:00
|
|
|
// Set the argv0 global so that we can print the command name in
|
|
|
|
// error and help messages.
|
2007-12-08 23:42:33 +01:00
|
|
|
argv0 = argv[0];
|
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
// Detect amount of installed RAM and set the memory usage limit.
|
|
|
|
// This is needed before parsing the command line arguments.
|
2008-08-28 21:53:15 +02:00
|
|
|
set_default_memlimit();
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
// Parse the command line options.
|
2007-12-08 23:42:33 +01:00
|
|
|
parse_options(argc, argv);
|
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
// The same lzma_stream is used for all files that we decode. This way
|
|
|
|
// we don't need to reallocate memory for every file if they use same
|
|
|
|
// compression settings.
|
|
|
|
lzma_stream strm = LZMA_STREAM_INIT;
|
|
|
|
|
|
|
|
// Some systems require setting stdin and stdout to binary mode.
|
2009-01-31 09:13:09 +01:00
|
|
|
#ifdef _WIN32
|
2008-01-18 13:17:37 +01:00
|
|
|
setmode(fileno(stdin), O_BINARY);
|
|
|
|
setmode(fileno(stdout), O_BINARY);
|
|
|
|
#endif
|
|
|
|
|
2007-12-08 23:42:33 +01:00
|
|
|
if (optind == argc) {
|
2008-11-20 17:05:52 +01:00
|
|
|
// No filenames given, decode from stdin.
|
|
|
|
uncompress(&strm, stdin, "(stdin)");
|
2007-12-08 23:42:33 +01:00
|
|
|
} else {
|
2008-11-20 17:05:52 +01:00
|
|
|
// Loop through the filenames given on the command line.
|
2007-12-08 23:42:33 +01:00
|
|
|
do {
|
2008-11-20 17:05:52 +01:00
|
|
|
// "-" indicates stdin.
|
2007-12-08 23:42:33 +01:00
|
|
|
if (strcmp(argv[optind], "-") == 0) {
|
2008-11-20 17:05:52 +01:00
|
|
|
uncompress(&strm, stdin, "(stdin)");
|
2007-12-08 23:42:33 +01:00
|
|
|
} else {
|
2008-11-20 17:05:52 +01:00
|
|
|
FILE *file = fopen(argv[optind], "rb");
|
2007-12-08 23:42:33 +01:00
|
|
|
if (file == NULL) {
|
|
|
|
fprintf(stderr, "%s: %s: %s\n",
|
2008-11-20 17:05:52 +01:00
|
|
|
argv0, argv[optind],
|
2007-12-08 23:42:33 +01:00
|
|
|
strerror(errno));
|
2008-11-20 17:05:52 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
uncompress(&strm, file, argv[optind]);
|
2007-12-08 23:42:33 +01:00
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
} while (++optind < argc);
|
|
|
|
}
|
|
|
|
|
2008-01-15 16:46:59 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// Free the memory only when debugging. Freeing wastes some time,
|
|
|
|
// but allows detecting possible memory leaks with Valgrind.
|
|
|
|
lzma_end(&strm);
|
|
|
|
#endif
|
|
|
|
|
2008-11-20 17:05:52 +01:00
|
|
|
my_exit();
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|