2007-03-07 22:02:23 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Common code for gunzip-like applets
|
2007-03-07 22:02:23 +00:00
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2007-03-07 22:02:23 +00:00
|
|
|
*/
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2011-09-22 10:45:14 +00:00
|
|
|
#include "bb_archive.h"
|
2007-03-07 22:02:23 +00:00
|
|
|
|
|
|
|
enum {
|
2010-05-27 00:22:54 +00:00
|
|
|
OPT_STDOUT = 1 << 0,
|
|
|
|
OPT_FORCE = 1 << 1,
|
|
|
|
/* only some decompressors: */
|
|
|
|
OPT_VERBOSE = 1 << 2,
|
|
|
|
OPT_DECOMPRESS = 1 << 3,
|
|
|
|
OPT_TEST = 1 << 4,
|
2007-03-07 22:02:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static
|
|
|
|
int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
|
|
|
|
{
|
2007-04-11 23:20:53 +00:00
|
|
|
int fd = open3_or_warn(filename, flags, mode);
|
2007-03-07 22:02:23 +00:00
|
|
|
if (fd < 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
2007-04-11 23:20:53 +00:00
|
|
|
xmove_fd(fd, to_fd);
|
2007-03-07 22:02:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-31 12:18:57 +00:00
|
|
|
char* FAST_FUNC append_ext(char *filename, const char *expected_ext)
|
|
|
|
{
|
|
|
|
return xasprintf("%s.%s", filename, expected_ext);
|
|
|
|
}
|
|
|
|
|
2008-06-27 02:52:20 +00:00
|
|
|
int FAST_FUNC bbunpack(char **argv,
|
2012-03-06 15:27:48 +00:00
|
|
|
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
|
2010-05-31 12:18:57 +00:00
|
|
|
char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
|
|
|
|
const char *expected_ext
|
2007-03-07 22:02:23 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
struct stat stat_buf;
|
2009-04-21 11:09:40 +00:00
|
|
|
IF_DESKTOP(long long) int status;
|
2007-03-07 23:22:47 +00:00
|
|
|
char *filename, *new_name;
|
2007-03-07 22:02:23 +00:00
|
|
|
smallint exitcode = 0;
|
2012-03-06 15:27:48 +00:00
|
|
|
transformer_aux_data_t aux;
|
2007-03-07 22:02:23 +00:00
|
|
|
|
|
|
|
do {
|
2007-03-07 23:22:47 +00:00
|
|
|
/* NB: new_name is *maybe* malloc'ed! */
|
|
|
|
new_name = NULL;
|
2007-03-07 22:02:23 +00:00
|
|
|
filename = *argv; /* can be NULL - 'streaming' bunzip2 */
|
2007-03-07 23:22:47 +00:00
|
|
|
|
2007-03-07 22:02:23 +00:00
|
|
|
if (filename && LONE_DASH(filename))
|
|
|
|
filename = NULL;
|
|
|
|
|
|
|
|
/* Open src */
|
|
|
|
if (filename) {
|
|
|
|
if (stat(filename, &stat_buf) != 0) {
|
2007-10-01 11:58:38 +00:00
|
|
|
bb_simple_perror_msg(filename);
|
2007-03-07 22:02:23 +00:00
|
|
|
err:
|
|
|
|
exitcode = 1;
|
|
|
|
goto free_name;
|
|
|
|
}
|
|
|
|
if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Special cases: test, stdout */
|
|
|
|
if (option_mask32 & (OPT_STDOUT|OPT_TEST)) {
|
|
|
|
if (option_mask32 & OPT_TEST)
|
|
|
|
if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0))
|
|
|
|
goto err;
|
|
|
|
filename = NULL;
|
|
|
|
}
|
|
|
|
|
2007-03-07 23:22:47 +00:00
|
|
|
/* Open dst if we are going to unpack to file */
|
2007-03-07 22:02:23 +00:00
|
|
|
if (filename) {
|
2010-05-31 12:18:57 +00:00
|
|
|
new_name = make_new_name(filename, expected_ext);
|
2007-03-07 22:02:23 +00:00
|
|
|
if (!new_name) {
|
|
|
|
bb_error_msg("%s: unknown suffix - ignored", filename);
|
|
|
|
goto err;
|
|
|
|
}
|
2008-06-25 20:54:45 +00:00
|
|
|
|
|
|
|
/* -f: overwrite existing output files */
|
|
|
|
if (option_mask32 & OPT_FORCE) {
|
|
|
|
unlink(new_name);
|
|
|
|
}
|
|
|
|
|
2007-03-07 23:22:47 +00:00
|
|
|
/* O_EXCL: "real" bunzip2 doesn't overwrite files */
|
2007-10-05 15:26:08 +00:00
|
|
|
/* GNU gunzip does not bail out, but goes to next file */
|
2007-03-07 22:02:23 +00:00
|
|
|
if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL,
|
|
|
|
stat_buf.st_mode))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2007-03-07 23:22:47 +00:00
|
|
|
/* Check that the input is sane */
|
2007-03-07 22:02:23 +00:00
|
|
|
if (isatty(STDIN_FILENO) && (option_mask32 & OPT_FORCE) == 0) {
|
|
|
|
bb_error_msg_and_die("compressed data not read from terminal, "
|
|
|
|
"use -f to force it");
|
|
|
|
}
|
|
|
|
|
2012-03-06 15:27:48 +00:00
|
|
|
init_transformer_aux_data(&aux);
|
|
|
|
aux.check_signature = 1;
|
|
|
|
status = unpacker(&aux);
|
2007-03-07 22:02:23 +00:00
|
|
|
if (status < 0)
|
|
|
|
exitcode = 1;
|
2011-10-31 00:05:16 +00:00
|
|
|
|
|
|
|
if (!(option_mask32 & OPT_STDOUT))
|
|
|
|
xclose(STDOUT_FILENO); /* with error check! */
|
2007-03-07 22:02:23 +00:00
|
|
|
|
|
|
|
if (filename) {
|
|
|
|
char *del = new_name;
|
|
|
|
if (status >= 0) {
|
2008-11-01 12:54:56 +00:00
|
|
|
/* TODO: restore other things? */
|
2012-03-06 15:27:48 +00:00
|
|
|
if (aux.mtime != 0) {
|
2009-11-29 18:40:36 +00:00
|
|
|
struct timeval times[2];
|
2009-11-15 01:28:56 +00:00
|
|
|
|
2012-03-06 15:27:48 +00:00
|
|
|
times[1].tv_sec = times[0].tv_sec = aux.mtime;
|
2009-11-29 18:40:36 +00:00
|
|
|
times[1].tv_usec = times[0].tv_usec = 0;
|
2009-10-05 01:03:07 +00:00
|
|
|
/* Note: we closed it first.
|
2009-11-15 01:28:56 +00:00
|
|
|
* On some systems calling utimes
|
2009-10-05 01:03:07 +00:00
|
|
|
* then closing resets the mtime
|
|
|
|
* back to current time. */
|
2009-11-29 18:40:36 +00:00
|
|
|
utimes(new_name, times); /* ignoring errors */
|
2008-11-01 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 23:22:47 +00:00
|
|
|
/* Delete _compressed_ file */
|
2007-03-07 22:02:23 +00:00
|
|
|
del = filename;
|
2007-03-07 23:22:47 +00:00
|
|
|
/* restore extension (unless tgz -> tar case) */
|
2007-03-07 22:02:23 +00:00
|
|
|
if (new_name == filename)
|
|
|
|
filename[strlen(filename)] = '.';
|
|
|
|
}
|
2007-04-05 21:25:15 +00:00
|
|
|
xunlink(del);
|
2007-03-07 23:22:47 +00:00
|
|
|
|
2007-03-07 22:02:23 +00:00
|
|
|
#if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */
|
|
|
|
/* Extreme bloat for gunzip compat */
|
|
|
|
if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE) && status >= 0) {
|
|
|
|
fprintf(stderr, "%s: %u%% - replaced with %s\n",
|
|
|
|
filename, (unsigned)(stat_buf.st_size*100 / (status+1)), new_name);
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-07 23:22:47 +00:00
|
|
|
|
2007-03-07 22:02:23 +00:00
|
|
|
free_name:
|
|
|
|
if (new_name != filename)
|
|
|
|
free(new_name);
|
|
|
|
}
|
|
|
|
} while (*argv && *++argv);
|
|
|
|
|
2011-10-31 00:05:16 +00:00
|
|
|
if (option_mask32 & OPT_STDOUT)
|
|
|
|
xclose(STDOUT_FILENO); /* with error check! */
|
|
|
|
|
2007-03-07 22:02:23 +00:00
|
|
|
return exitcode;
|
|
|
|
}
|
|
|
|
|
2010-05-30 01:46:54 +00:00
|
|
|
#if ENABLE_UNCOMPRESS || ENABLE_BUNZIP2 || ENABLE_UNLZMA || ENABLE_UNXZ
|
2007-03-07 22:02:23 +00:00
|
|
|
static
|
2010-05-31 12:18:57 +00:00
|
|
|
char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
|
2007-03-07 22:02:23 +00:00
|
|
|
{
|
|
|
|
char *extension = strrchr(filename, '.');
|
2007-03-09 20:49:55 +00:00
|
|
|
if (!extension || strcmp(extension + 1, expected_ext) != 0) {
|
2007-03-07 23:22:47 +00:00
|
|
|
/* Mimic GNU gunzip - "real" bunzip2 tries to */
|
|
|
|
/* unpack file anyway, to file.out */
|
2007-03-07 22:02:23 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*extension = '\0';
|
|
|
|
return filename;
|
|
|
|
}
|
2007-03-11 10:56:37 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2010-05-30 01:46:54 +00:00
|
|
|
* Uncompress applet for busybox (c) 2002 Glenn McGrath
|
2007-03-11 10:56:37 +00:00
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2007-03-11 10:56:37 +00:00
|
|
|
*/
|
2011-03-27 20:40:30 +00:00
|
|
|
|
|
|
|
//usage:#define uncompress_trivial_usage
|
|
|
|
//usage: "[-cf] [FILE]..."
|
|
|
|
//usage:#define uncompress_full_usage "\n\n"
|
|
|
|
//usage: "Decompress .Z file[s]\n"
|
|
|
|
//usage: "\n -c Write to stdout"
|
|
|
|
//usage: "\n -f Overwrite"
|
|
|
|
|
2010-05-30 01:46:54 +00:00
|
|
|
#if ENABLE_UNCOMPRESS
|
2007-03-09 20:49:55 +00:00
|
|
|
static
|
2012-03-06 15:27:48 +00:00
|
|
|
IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux)
|
2007-03-07 22:02:23 +00:00
|
|
|
{
|
2012-03-06 15:27:48 +00:00
|
|
|
return unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
2010-05-30 01:46:54 +00:00
|
|
|
}
|
|
|
|
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
2007-03-07 22:02:23 +00:00
|
|
|
{
|
2010-05-30 01:46:54 +00:00
|
|
|
getopt32(argv, "cf");
|
2007-03-07 22:02:23 +00:00
|
|
|
argv += optind;
|
|
|
|
|
2010-05-31 12:18:57 +00:00
|
|
|
return bbunpack(argv, unpack_uncompress, make_new_name_generic, "Z");
|
2007-03-07 22:02:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gzip implementation for busybox
|
|
|
|
*
|
|
|
|
* Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly.
|
|
|
|
*
|
|
|
|
* Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
|
|
|
|
* based on gzip sources
|
|
|
|
*
|
|
|
|
* Adjusted further by Erik Andersen <andersen@codepoet.org> to support files as
|
|
|
|
* well as stdin/stdout, and to generally behave itself wrt command line
|
|
|
|
* handling.
|
|
|
|
*
|
|
|
|
* General cleanup to better adhere to the style guide and make use of standard
|
2007-09-21 13:16:32 +00:00
|
|
|
* busybox functions by Glenn McGrath
|
2007-03-07 22:02:23 +00:00
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2007-03-07 22:02:23 +00:00
|
|
|
*
|
|
|
|
* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
|
|
|
* Copyright (C) 1992-1993 Jean-loup Gailly
|
|
|
|
* The unzip code was written and put in the public domain by Mark Adler.
|
|
|
|
* Portions of the lzw code are derived from the public domain 'compress'
|
|
|
|
* written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies,
|
|
|
|
* Ken Turkowski, Dave Mack and Peter Jannesen.
|
|
|
|
*
|
|
|
|
* See the license_msg below and the file COPYING for the software license.
|
|
|
|
* See the file algorithm.doc for the compression algorithms and file formats.
|
|
|
|
*/
|
2011-03-27 20:40:30 +00:00
|
|
|
|
|
|
|
//usage:#define gunzip_trivial_usage
|
|
|
|
//usage: "[-cft] [FILE]..."
|
|
|
|
//usage:#define gunzip_full_usage "\n\n"
|
|
|
|
//usage: "Decompress FILEs (or stdin)\n"
|
|
|
|
//usage: "\n -c Write to stdout"
|
|
|
|
//usage: "\n -f Force"
|
|
|
|
//usage: "\n -t Test file integrity"
|
|
|
|
//usage:
|
|
|
|
//usage:#define gunzip_example_usage
|
|
|
|
//usage: "$ ls -la /tmp/BusyBox*\n"
|
|
|
|
//usage: "-rw-rw-r-- 1 andersen andersen 557009 Apr 11 10:55 /tmp/BusyBox-0.43.tar.gz\n"
|
|
|
|
//usage: "$ gunzip /tmp/BusyBox-0.43.tar.gz\n"
|
|
|
|
//usage: "$ ls -la /tmp/BusyBox*\n"
|
|
|
|
//usage: "-rw-rw-r-- 1 andersen andersen 1761280 Apr 14 17:47 /tmp/BusyBox-0.43.tar\n"
|
|
|
|
//usage:
|
|
|
|
//usage:#define zcat_trivial_usage
|
|
|
|
//usage: "FILE"
|
|
|
|
//usage:#define zcat_full_usage "\n\n"
|
|
|
|
//usage: "Decompress to stdout"
|
|
|
|
|
2007-03-07 22:02:23 +00:00
|
|
|
#if ENABLE_GUNZIP
|
|
|
|
static
|
2010-05-31 12:18:57 +00:00
|
|
|
char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM)
|
2007-03-07 22:02:23 +00:00
|
|
|
{
|
|
|
|
char *extension = strrchr(filename, '.');
|
|
|
|
|
|
|
|
if (!extension)
|
|
|
|
return NULL;
|
|
|
|
|
2007-03-09 20:49:55 +00:00
|
|
|
extension++;
|
|
|
|
if (strcmp(extension, "tgz" + 1) == 0
|
2008-08-05 13:10:34 +00:00
|
|
|
#if ENABLE_FEATURE_SEAMLESS_Z
|
|
|
|
|| (extension[0] == 'Z' && extension[1] == '\0')
|
2007-03-07 22:02:23 +00:00
|
|
|
#endif
|
|
|
|
) {
|
2007-03-09 20:49:55 +00:00
|
|
|
extension[-1] = '\0';
|
2007-04-12 00:32:05 +00:00
|
|
|
} else if (strcmp(extension, "tgz") == 0) {
|
2007-03-07 22:02:23 +00:00
|
|
|
filename = xstrdup(filename);
|
|
|
|
extension = strrchr(filename, '.');
|
|
|
|
extension[2] = 'a';
|
|
|
|
extension[3] = 'r';
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
static
|
2012-03-06 15:27:48 +00:00
|
|
|
IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux)
|
2007-03-07 22:02:23 +00:00
|
|
|
{
|
2009-04-21 11:09:40 +00:00
|
|
|
IF_DESKTOP(long long) int status = -1;
|
2012-03-06 15:27:48 +00:00
|
|
|
uint16_t magic2;
|
2007-03-07 22:02:23 +00:00
|
|
|
|
2012-03-06 15:27:48 +00:00
|
|
|
//TODO: fold below into unpack_gz_stream? Then the whole level of indirection
|
|
|
|
// unpack_FOO() -> unpack_FOO_stream can be collapsed in this module!
|
|
|
|
|
|
|
|
aux->check_signature = 0; /* we will check it here, not in unpack_*_stream */
|
|
|
|
|
|
|
|
if (full_read(STDIN_FILENO, &magic2, 2) != 2)
|
|
|
|
goto bad_magic;
|
|
|
|
if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == COMPRESS_MAGIC) {
|
|
|
|
status = unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
|
|
|
} else if (magic2 == GZIP_MAGIC) {
|
|
|
|
status = unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
2007-03-07 22:02:23 +00:00
|
|
|
} else {
|
|
|
|
bad_magic:
|
|
|
|
bb_error_msg("invalid magic");
|
|
|
|
/* status is still == -1 */
|
|
|
|
}
|
2012-03-06 15:27:48 +00:00
|
|
|
if (status < 0) {
|
|
|
|
bb_error_msg("error inflating");
|
|
|
|
}
|
2007-03-07 22:02:23 +00:00
|
|
|
return status;
|
|
|
|
}
|
2008-03-30 13:11:47 +00:00
|
|
|
/*
|
|
|
|
* Linux kernel build uses gzip -d -n. We accept and ignore it.
|
|
|
|
* Man page says:
|
|
|
|
* -n --no-name
|
|
|
|
* gzip: do not save the original file name and time stamp.
|
|
|
|
* (The original name is always saved if the name had to be truncated.)
|
|
|
|
* gunzip: do not restore the original file name/time even if present
|
|
|
|
* (remove only the gzip suffix from the compressed file name).
|
|
|
|
* This option is the default when decompressing.
|
|
|
|
* -N --name
|
|
|
|
* gzip: always save the original file name and time stamp (this is the default)
|
|
|
|
* gunzip: restore the original file name and time stamp if present.
|
|
|
|
*/
|
2007-10-11 10:05:36 +00:00
|
|
|
int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
2007-03-07 22:02:23 +00:00
|
|
|
{
|
2008-03-30 13:11:47 +00:00
|
|
|
getopt32(argv, "cfvdtn");
|
2007-03-07 22:02:23 +00:00
|
|
|
argv += optind;
|
|
|
|
/* if called as zcat */
|
|
|
|
if (applet_name[1] == 'c')
|
|
|
|
option_mask32 |= OPT_STDOUT;
|
|
|
|
|
2010-05-31 12:18:57 +00:00
|
|
|
return bbunpack(argv, unpack_gunzip, make_new_name_gunzip, /*unused:*/ NULL);
|
2007-03-07 22:02:23 +00:00
|
|
|
}
|
2010-05-30 01:46:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modified for busybox by Glenn McGrath
|
|
|
|
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
|
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2010-05-30 01:46:54 +00:00
|
|
|
*/
|
2010-06-05 23:53:38 +00:00
|
|
|
//usage:#define bunzip2_trivial_usage
|
2010-10-09 19:10:32 +00:00
|
|
|
//usage: "[-cf] [FILE]..."
|
2010-06-05 23:53:38 +00:00
|
|
|
//usage:#define bunzip2_full_usage "\n\n"
|
|
|
|
//usage: "Decompress FILEs (or stdin)\n"
|
|
|
|
//usage: "\n -c Write to stdout"
|
|
|
|
//usage: "\n -f Force"
|
|
|
|
//usage:#define bzcat_trivial_usage
|
|
|
|
//usage: "FILE"
|
|
|
|
//usage:#define bzcat_full_usage "\n\n"
|
|
|
|
//usage: "Decompress to stdout"
|
2011-01-18 12:58:01 +00:00
|
|
|
//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
|
|
|
|
//applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
|
2010-05-30 01:46:54 +00:00
|
|
|
#if ENABLE_BUNZIP2
|
|
|
|
static
|
2012-03-06 15:27:48 +00:00
|
|
|
IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)
|
2010-05-30 01:46:54 +00:00
|
|
|
{
|
2012-03-06 15:27:48 +00:00
|
|
|
return unpack_bz2_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
2010-05-30 01:46:54 +00:00
|
|
|
}
|
|
|
|
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
|
|
|
{
|
|
|
|
getopt32(argv, "cfvdt");
|
|
|
|
argv += optind;
|
|
|
|
if (applet_name[2] == 'c') /* bzcat */
|
|
|
|
option_mask32 |= OPT_STDOUT;
|
2007-03-07 22:02:23 +00:00
|
|
|
|
2010-05-31 12:18:57 +00:00
|
|
|
return bbunpack(argv, unpack_bunzip2, make_new_name_generic, "bz2");
|
2010-05-30 01:46:54 +00:00
|
|
|
}
|
2007-03-07 22:02:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Small lzma deflate implementation.
|
|
|
|
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
|
|
|
|
*
|
|
|
|
* Based on bunzip.c from busybox
|
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2, see file LICENSE in this source tree.
|
2007-03-07 22:02:23 +00:00
|
|
|
*/
|
2011-03-27 20:40:30 +00:00
|
|
|
|
|
|
|
//usage:#define unlzma_trivial_usage
|
|
|
|
//usage: "[-cf] [FILE]..."
|
|
|
|
//usage:#define unlzma_full_usage "\n\n"
|
|
|
|
//usage: "Decompress FILE (or stdin)\n"
|
|
|
|
//usage: "\n -c Write to stdout"
|
|
|
|
//usage: "\n -f Force"
|
|
|
|
//usage:
|
|
|
|
//usage:#define lzma_trivial_usage
|
|
|
|
//usage: "-d [-cf] [FILE]..."
|
|
|
|
//usage:#define lzma_full_usage "\n\n"
|
|
|
|
//usage: "Decompress FILE (or stdin)\n"
|
|
|
|
//usage: "\n -d Decompress"
|
|
|
|
//usage: "\n -c Write to stdout"
|
|
|
|
//usage: "\n -f Force"
|
|
|
|
//usage:
|
|
|
|
//usage:#define lzcat_trivial_usage
|
|
|
|
//usage: "FILE"
|
|
|
|
//usage:#define lzcat_full_usage "\n\n"
|
|
|
|
//usage: "Decompress to stdout"
|
|
|
|
//usage:
|
|
|
|
//usage:#define unxz_trivial_usage
|
|
|
|
//usage: "[-cf] [FILE]..."
|
|
|
|
//usage:#define unxz_full_usage "\n\n"
|
|
|
|
//usage: "Decompress FILE (or stdin)\n"
|
|
|
|
//usage: "\n -c Write to stdout"
|
|
|
|
//usage: "\n -f Force"
|
|
|
|
//usage:
|
|
|
|
//usage:#define xz_trivial_usage
|
|
|
|
//usage: "-d [-cf] [FILE]..."
|
|
|
|
//usage:#define xz_full_usage "\n\n"
|
|
|
|
//usage: "Decompress FILE (or stdin)\n"
|
|
|
|
//usage: "\n -d Decompress"
|
|
|
|
//usage: "\n -c Write to stdout"
|
|
|
|
//usage: "\n -f Force"
|
|
|
|
//usage:
|
|
|
|
//usage:#define xzcat_trivial_usage
|
|
|
|
//usage: "FILE"
|
|
|
|
//usage:#define xzcat_full_usage "\n\n"
|
|
|
|
//usage: "Decompress to stdout"
|
|
|
|
|
2007-03-07 22:02:23 +00:00
|
|
|
#if ENABLE_UNLZMA
|
|
|
|
static
|
2012-03-06 15:27:48 +00:00
|
|
|
IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)
|
2007-03-07 22:02:23 +00:00
|
|
|
{
|
2012-03-06 15:27:48 +00:00
|
|
|
return unpack_lzma_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
2007-03-07 22:02:23 +00:00
|
|
|
}
|
2007-10-11 10:05:36 +00:00
|
|
|
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
2007-03-07 22:02:23 +00:00
|
|
|
{
|
2010-05-30 01:33:50 +00:00
|
|
|
IF_LZMA(int opts =) getopt32(argv, "cfvdt");
|
|
|
|
# if ENABLE_LZMA
|
2010-05-27 00:22:54 +00:00
|
|
|
/* lzma without -d or -t? */
|
|
|
|
if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
|
|
|
|
bb_show_usage();
|
|
|
|
# endif
|
|
|
|
/* lzcat? */
|
|
|
|
if (applet_name[2] == 'c')
|
2007-03-07 22:02:23 +00:00
|
|
|
option_mask32 |= OPT_STDOUT;
|
|
|
|
|
2010-05-27 00:22:54 +00:00
|
|
|
argv += optind;
|
2010-05-31 12:18:57 +00:00
|
|
|
return bbunpack(argv, unpack_unlzma, make_new_name_generic, "lzma");
|
2007-03-07 22:02:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-05-30 01:35:18 +00:00
|
|
|
#if ENABLE_UNXZ
|
|
|
|
static
|
2012-03-06 15:27:48 +00:00
|
|
|
IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)
|
2010-05-30 01:35:18 +00:00
|
|
|
{
|
2012-03-06 15:27:48 +00:00
|
|
|
return unpack_xz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
2010-05-30 01:35:18 +00:00
|
|
|
}
|
|
|
|
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
int unxz_main(int argc UNUSED_PARAM, char **argv)
|
|
|
|
{
|
2010-07-05 19:37:12 +00:00
|
|
|
IF_XZ(int opts =) getopt32(argv, "cfvdt");
|
2010-05-30 01:35:18 +00:00
|
|
|
# if ENABLE_XZ
|
|
|
|
/* xz without -d or -t? */
|
|
|
|
if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
|
|
|
|
bb_show_usage();
|
|
|
|
# endif
|
|
|
|
/* xzcat? */
|
|
|
|
if (applet_name[2] == 'c')
|
|
|
|
option_mask32 |= OPT_STDOUT;
|
|
|
|
|
|
|
|
argv += optind;
|
2010-05-31 12:18:57 +00:00
|
|
|
return bbunpack(argv, unpack_unxz, make_new_name_generic, "xz");
|
2010-05-30 01:35:18 +00:00
|
|
|
}
|
|
|
|
#endif
|