Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 3 | * Common code for gunzip-like applets |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 4 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 5 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 6 | */ |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 7 | #include "libbb.h" |
Denys Vlasenko | d184a72 | 2011-09-22 12:45:14 +0200 | [diff] [blame] | 8 | #include "bb_archive.h" |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 9 | |
Denys Vlasenko | 66620fa | 2013-11-14 09:53:52 +0100 | [diff] [blame] | 10 | /* lzop_main() uses bbunpack(), need this: */ |
| 11 | //kbuild:lib-$(CONFIG_LZOP) += bbunzip.o |
Denys Vlasenko | 9cc3d3a | 2016-12-23 02:42:26 +0100 | [diff] [blame] | 12 | //kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o |
| 13 | //kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o |
Denys Vlasenko | 548620c | 2016-12-08 12:24:48 +0100 | [diff] [blame] | 14 | /* bzip2_main() too: */ |
Kang-Che Sung | b130f9f | 2017-01-08 14:28:34 +0800 | [diff] [blame] | 15 | //kbuild:lib-$(CONFIG_FEATURE_BZIP2_DECOMPRESS) += bbunzip.o |
Denys Vlasenko | 9cc3d3a | 2016-12-23 02:42:26 +0100 | [diff] [blame] | 16 | /* gzip_main() too: */ |
Kang-Che Sung | b130f9f | 2017-01-08 14:28:34 +0800 | [diff] [blame] | 17 | //kbuild:lib-$(CONFIG_FEATURE_GZIP_DECOMPRESS) += bbunzip.o |
Denys Vlasenko | 66620fa | 2013-11-14 09:53:52 +0100 | [diff] [blame] | 18 | |
Mike Frysinger | 93b5181 | 2013-03-03 00:48:53 -0500 | [diff] [blame] | 19 | /* Note: must be kept in sync with archival/lzop.c */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 20 | enum { |
Denys Vlasenko | ccb88a6 | 2010-05-27 02:22:54 +0200 | [diff] [blame] | 21 | OPT_STDOUT = 1 << 0, |
| 22 | OPT_FORCE = 1 << 1, |
| 23 | /* only some decompressors: */ |
| 24 | OPT_VERBOSE = 1 << 2, |
Mike Frysinger | 920c1ba | 2013-02-28 17:21:50 -0500 | [diff] [blame] | 25 | OPT_QUIET = 1 << 3, |
| 26 | OPT_DECOMPRESS = 1 << 4, |
| 27 | OPT_TEST = 1 << 5, |
Kang-Che Sung | d5e7ff0 | 2017-01-08 14:31:06 +0100 | [diff] [blame] | 28 | SEAMLESS_MAGIC = (1 << 31) * ENABLE_ZCAT * SEAMLESS_COMPRESSION, |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | static |
| 32 | int open_to_or_warn(int to_fd, const char *filename, int flags, int mode) |
| 33 | { |
Denis Vlasenko | 50f7f44 | 2007-04-11 23:20:53 +0000 | [diff] [blame] | 34 | int fd = open3_or_warn(filename, flags, mode); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 35 | if (fd < 0) { |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 36 | return 1; |
| 37 | } |
Denis Vlasenko | 50f7f44 | 2007-04-11 23:20:53 +0000 | [diff] [blame] | 38 | xmove_fd(fd, to_fd); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 39 | return 0; |
| 40 | } |
| 41 | |
Denys Vlasenko | 39a04f7 | 2010-05-31 14:18:57 +0200 | [diff] [blame] | 42 | char* FAST_FUNC append_ext(char *filename, const char *expected_ext) |
| 43 | { |
| 44 | return xasprintf("%s.%s", filename, expected_ext); |
| 45 | } |
| 46 | |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 47 | int FAST_FUNC bbunpack(char **argv, |
Denys Vlasenko | e7800f3 | 2014-12-07 00:42:49 +0100 | [diff] [blame] | 48 | IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_state_t *xstate), |
Denys Vlasenko | 39a04f7 | 2010-05-31 14:18:57 +0200 | [diff] [blame] | 49 | char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext), |
| 50 | const char *expected_ext |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 51 | ) |
| 52 | { |
| 53 | struct stat stat_buf; |
Denys Vlasenko | 8e96efa | 2013-02-28 18:06:09 +0100 | [diff] [blame] | 54 | IF_DESKTOP(long long) int status = 0; |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 55 | char *filename, *new_name; |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 56 | smallint exitcode = 0; |
Denys Vlasenko | e7800f3 | 2014-12-07 00:42:49 +0100 | [diff] [blame] | 57 | transformer_state_t xstate; |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 58 | |
| 59 | do { |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 60 | /* NB: new_name is *maybe* malloc'ed! */ |
| 61 | new_name = NULL; |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 62 | filename = *argv; /* can be NULL - 'streaming' bunzip2 */ |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 63 | |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 64 | if (filename && LONE_DASH(filename)) |
| 65 | filename = NULL; |
| 66 | |
| 67 | /* Open src */ |
| 68 | if (filename) { |
Denys Vlasenko | 8e96efa | 2013-02-28 18:06:09 +0100 | [diff] [blame] | 69 | if (!(option_mask32 & SEAMLESS_MAGIC)) { |
| 70 | if (stat(filename, &stat_buf) != 0) { |
| 71 | err_name: |
| 72 | bb_simple_perror_msg(filename); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 73 | err: |
Denys Vlasenko | 8e96efa | 2013-02-28 18:06:09 +0100 | [diff] [blame] | 74 | exitcode = 1; |
| 75 | goto free_name; |
| 76 | } |
| 77 | if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0)) |
| 78 | goto err; |
| 79 | } else { |
Denys Vlasenko | 4165543 | 2013-02-28 18:37:04 +0100 | [diff] [blame] | 80 | /* "clever zcat" with FILE */ |
Denys Vlasenko | 640ce3d | 2014-02-02 02:06:38 +0100 | [diff] [blame] | 81 | /* fail_if_not_compressed because zcat refuses uncompressed input */ |
| 82 | int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1); |
Denys Vlasenko | 8e96efa | 2013-02-28 18:06:09 +0100 | [diff] [blame] | 83 | if (fd < 0) |
| 84 | goto err_name; |
| 85 | xmove_fd(fd, STDIN_FILENO); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 86 | } |
Denys Vlasenko | 4165543 | 2013-02-28 18:37:04 +0100 | [diff] [blame] | 87 | } else |
| 88 | if (option_mask32 & SEAMLESS_MAGIC) { |
| 89 | /* "clever zcat" on stdin */ |
Denys Vlasenko | 640ce3d | 2014-02-02 02:06:38 +0100 | [diff] [blame] | 90 | if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1)) |
Denys Vlasenko | 4165543 | 2013-02-28 18:37:04 +0100 | [diff] [blame] | 91 | goto err; |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /* Special cases: test, stdout */ |
| 95 | if (option_mask32 & (OPT_STDOUT|OPT_TEST)) { |
| 96 | if (option_mask32 & OPT_TEST) |
| 97 | if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0)) |
Denys Vlasenko | f2d8478 | 2013-02-28 18:04:22 +0100 | [diff] [blame] | 98 | xfunc_die(); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 99 | filename = NULL; |
| 100 | } |
| 101 | |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 102 | /* Open dst if we are going to unpack to file */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 103 | if (filename) { |
Denys Vlasenko | 39a04f7 | 2010-05-31 14:18:57 +0200 | [diff] [blame] | 104 | new_name = make_new_name(filename, expected_ext); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 105 | if (!new_name) { |
| 106 | bb_error_msg("%s: unknown suffix - ignored", filename); |
| 107 | goto err; |
| 108 | } |
Denis Vlasenko | a04cc47 | 2008-06-25 20:54:45 +0000 | [diff] [blame] | 109 | |
| 110 | /* -f: overwrite existing output files */ |
| 111 | if (option_mask32 & OPT_FORCE) { |
| 112 | unlink(new_name); |
| 113 | } |
| 114 | |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 115 | /* O_EXCL: "real" bunzip2 doesn't overwrite files */ |
Denis Vlasenko | 5dd8a03 | 2007-10-05 15:26:08 +0000 | [diff] [blame] | 116 | /* GNU gunzip does not bail out, but goes to next file */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 117 | if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL, |
| 118 | stat_buf.st_mode)) |
| 119 | goto err; |
| 120 | } |
| 121 | |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 122 | /* Check that the input is sane */ |
Denys Vlasenko | f2d8478 | 2013-02-28 18:04:22 +0100 | [diff] [blame] | 123 | if (!(option_mask32 & OPT_FORCE) && isatty(STDIN_FILENO)) { |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 124 | bb_error_msg_and_die("compressed data not read from terminal, " |
| 125 | "use -f to force it"); |
| 126 | } |
| 127 | |
Denys Vlasenko | 8e96efa | 2013-02-28 18:06:09 +0100 | [diff] [blame] | 128 | if (!(option_mask32 & SEAMLESS_MAGIC)) { |
Denys Vlasenko | e7800f3 | 2014-12-07 00:42:49 +0100 | [diff] [blame] | 129 | init_transformer_state(&xstate); |
Denys Vlasenko | 2a0867a | 2017-01-09 10:58:37 +0100 | [diff] [blame^] | 130 | /*xstate.signature_skipped = 0; - already is */ |
Denys Vlasenko | b4c11c1 | 2014-12-07 00:44:00 +0100 | [diff] [blame] | 131 | /*xstate.src_fd = STDIN_FILENO; - already is */ |
| 132 | xstate.dst_fd = STDOUT_FILENO; |
Denys Vlasenko | e7800f3 | 2014-12-07 00:42:49 +0100 | [diff] [blame] | 133 | status = unpacker(&xstate); |
Denys Vlasenko | 8e96efa | 2013-02-28 18:06:09 +0100 | [diff] [blame] | 134 | if (status < 0) |
| 135 | exitcode = 1; |
| 136 | } else { |
Denys Vlasenko | 4165543 | 2013-02-28 18:37:04 +0100 | [diff] [blame] | 137 | if (bb_copyfd_eof(STDIN_FILENO, STDOUT_FILENO) < 0) |
Denys Vlasenko | 8e96efa | 2013-02-28 18:06:09 +0100 | [diff] [blame] | 138 | /* Disk full, tty closed, etc. No point in continuing */ |
| 139 | xfunc_die(); |
Denys Vlasenko | 8e96efa | 2013-02-28 18:06:09 +0100 | [diff] [blame] | 140 | } |
Denys Vlasenko | c531b9a | 2011-10-31 01:05:16 +0100 | [diff] [blame] | 141 | |
| 142 | if (!(option_mask32 & OPT_STDOUT)) |
| 143 | xclose(STDOUT_FILENO); /* with error check! */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 144 | |
| 145 | if (filename) { |
| 146 | char *del = new_name; |
Denys Vlasenko | d0bc708 | 2013-07-30 05:41:11 +0200 | [diff] [blame] | 147 | |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 148 | if (status >= 0) { |
Denys Vlasenko | d0bc708 | 2013-07-30 05:41:11 +0200 | [diff] [blame] | 149 | unsigned new_name_len; |
| 150 | |
Denis Vlasenko | 1a9e9bd | 2008-11-01 12:54:56 +0000 | [diff] [blame] | 151 | /* TODO: restore other things? */ |
Denys Vlasenko | e7800f3 | 2014-12-07 00:42:49 +0100 | [diff] [blame] | 152 | if (xstate.mtime != 0) { |
Denys Vlasenko | dcbfaba | 2009-11-29 19:40:36 +0100 | [diff] [blame] | 153 | struct timeval times[2]; |
Denys Vlasenko | 389cca4 | 2009-11-15 02:28:56 +0100 | [diff] [blame] | 154 | |
Denys Vlasenko | e7800f3 | 2014-12-07 00:42:49 +0100 | [diff] [blame] | 155 | times[1].tv_sec = times[0].tv_sec = xstate.mtime; |
Denys Vlasenko | dcbfaba | 2009-11-29 19:40:36 +0100 | [diff] [blame] | 156 | times[1].tv_usec = times[0].tv_usec = 0; |
Denys Vlasenko | dcd27ab | 2009-10-05 03:03:07 +0200 | [diff] [blame] | 157 | /* Note: we closed it first. |
Denys Vlasenko | 389cca4 | 2009-11-15 02:28:56 +0100 | [diff] [blame] | 158 | * On some systems calling utimes |
Denys Vlasenko | dcd27ab | 2009-10-05 03:03:07 +0200 | [diff] [blame] | 159 | * then closing resets the mtime |
| 160 | * back to current time. */ |
Denys Vlasenko | dcbfaba | 2009-11-29 19:40:36 +0100 | [diff] [blame] | 161 | utimes(new_name, times); /* ignoring errors */ |
Denis Vlasenko | 1a9e9bd | 2008-11-01 12:54:56 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Denys Vlasenko | d0bc708 | 2013-07-30 05:41:11 +0200 | [diff] [blame] | 164 | if (ENABLE_DESKTOP) |
| 165 | new_name_len = strlen(new_name); |
| 166 | /* Restore source filename (unless tgz -> tar case) */ |
| 167 | if (new_name == filename) { |
| 168 | new_name_len = strlen(filename); |
| 169 | filename[new_name_len] = '.'; |
| 170 | } |
| 171 | /* Extreme bloat for gunzip compat */ |
| 172 | /* Some users do want this info... */ |
| 173 | if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE)) { |
| 174 | unsigned percent = status |
| 175 | ? ((uoff_t)stat_buf.st_size * 100u / (unsigned long long)status) |
| 176 | : 0; |
| 177 | fprintf(stderr, "%s: %u%% - replaced with %.*s\n", |
| 178 | filename, |
| 179 | 100u - percent, |
| 180 | new_name_len, new_name |
| 181 | ); |
| 182 | } |
| 183 | /* Delete _source_ file */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 184 | del = filename; |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 185 | } |
Denis Vlasenko | 1bb552b | 2007-04-05 21:25:15 +0000 | [diff] [blame] | 186 | xunlink(del); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 187 | free_name: |
| 188 | if (new_name != filename) |
| 189 | free(new_name); |
| 190 | } |
| 191 | } while (*argv && *++argv); |
| 192 | |
Denys Vlasenko | c531b9a | 2011-10-31 01:05:16 +0100 | [diff] [blame] | 193 | if (option_mask32 & OPT_STDOUT) |
| 194 | xclose(STDOUT_FILENO); /* with error check! */ |
| 195 | |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 196 | return exitcode; |
| 197 | } |
| 198 | |
Denys Vlasenko | 548620c | 2016-12-08 12:24:48 +0100 | [diff] [blame] | 199 | #if ENABLE_UNCOMPRESS \ |
Kang-Che Sung | b130f9f | 2017-01-08 14:28:34 +0800 | [diff] [blame] | 200 | || ENABLE_FEATURE_BZIP2_DECOMPRESS \ |
Denys Vlasenko | 548620c | 2016-12-08 12:24:48 +0100 | [diff] [blame] | 201 | || ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA \ |
| 202 | || ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 203 | static |
Denys Vlasenko | 39a04f7 | 2010-05-31 14:18:57 +0200 | [diff] [blame] | 204 | char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext) |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 205 | { |
| 206 | char *extension = strrchr(filename, '.'); |
Denis Vlasenko | bebbd8c | 2007-03-09 20:49:55 +0000 | [diff] [blame] | 207 | if (!extension || strcmp(extension + 1, expected_ext) != 0) { |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 208 | /* Mimic GNU gunzip - "real" bunzip2 tries to */ |
| 209 | /* unpack file anyway, to file.out */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 210 | return NULL; |
| 211 | } |
| 212 | *extension = '\0'; |
| 213 | return filename; |
| 214 | } |
Denis Vlasenko | a4688bf | 2007-03-11 10:56:37 +0000 | [diff] [blame] | 215 | #endif |
| 216 | |
| 217 | |
Denis Vlasenko | a4688bf | 2007-03-11 10:56:37 +0000 | [diff] [blame] | 218 | /* |
Denys Vlasenko | d93f19e | 2010-05-30 03:46:54 +0200 | [diff] [blame] | 219 | * Uncompress applet for busybox (c) 2002 Glenn McGrath |
Denis Vlasenko | a4688bf | 2007-03-11 10:56:37 +0000 | [diff] [blame] | 220 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 221 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Denis Vlasenko | a4688bf | 2007-03-11 10:56:37 +0000 | [diff] [blame] | 222 | */ |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 223 | //usage:#define uncompress_trivial_usage |
| 224 | //usage: "[-cf] [FILE]..." |
| 225 | //usage:#define uncompress_full_usage "\n\n" |
| 226 | //usage: "Decompress .Z file[s]\n" |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 227 | //usage: "\n -c Write to stdout" |
| 228 | //usage: "\n -f Overwrite" |
| 229 | |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 230 | //config:config UNCOMPRESS |
| 231 | //config: bool "uncompress" |
Denys Vlasenko | db70033 | 2015-10-25 20:36:03 +0100 | [diff] [blame] | 232 | //config: default n # ancient |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 233 | //config: help |
| 234 | //config: uncompress is used to decompress archives created by compress. |
| 235 | //config: Not much used anymore, replaced by gzip/gunzip. |
| 236 | |
Denys Vlasenko | 36184a4 | 2013-11-14 09:54:24 +0100 | [diff] [blame] | 237 | //applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP)) |
Denys Vlasenko | 66620fa | 2013-11-14 09:53:52 +0100 | [diff] [blame] | 238 | //kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o |
Denys Vlasenko | d93f19e | 2010-05-30 03:46:54 +0200 | [diff] [blame] | 239 | #if ENABLE_UNCOMPRESS |
Denys Vlasenko | d93f19e | 2010-05-30 03:46:54 +0200 | [diff] [blame] | 240 | int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 241 | int uncompress_main(int argc UNUSED_PARAM, char **argv) |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 242 | { |
Denys Vlasenko | d93f19e | 2010-05-30 03:46:54 +0200 | [diff] [blame] | 243 | getopt32(argv, "cf"); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 244 | argv += optind; |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 245 | |
Denys Vlasenko | b4c11c1 | 2014-12-07 00:44:00 +0100 | [diff] [blame] | 246 | return bbunpack(argv, unpack_Z_stream, make_new_name_generic, "Z"); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 247 | } |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 248 | #endif |
| 249 | |
| 250 | |
| 251 | /* |
| 252 | * Gzip implementation for busybox |
| 253 | * |
| 254 | * Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly. |
| 255 | * |
| 256 | * Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de> |
| 257 | * based on gzip sources |
| 258 | * |
| 259 | * Adjusted further by Erik Andersen <andersen@codepoet.org> to support files as |
| 260 | * well as stdin/stdout, and to generally behave itself wrt command line |
| 261 | * handling. |
| 262 | * |
| 263 | * General cleanup to better adhere to the style guide and make use of standard |
Denis Vlasenko | 0beaff8 | 2007-09-21 13:16:32 +0000 | [diff] [blame] | 264 | * busybox functions by Glenn McGrath |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 265 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 266 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 267 | * |
| 268 | * gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface |
| 269 | * Copyright (C) 1992-1993 Jean-loup Gailly |
| 270 | * The unzip code was written and put in the public domain by Mark Adler. |
| 271 | * Portions of the lzw code are derived from the public domain 'compress' |
| 272 | * written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies, |
| 273 | * Ken Turkowski, Dave Mack and Peter Jannesen. |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 274 | */ |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 275 | //usage:#define gunzip_trivial_usage |
| 276 | //usage: "[-cft] [FILE]..." |
| 277 | //usage:#define gunzip_full_usage "\n\n" |
| 278 | //usage: "Decompress FILEs (or stdin)\n" |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 279 | //usage: "\n -c Write to stdout" |
| 280 | //usage: "\n -f Force" |
| 281 | //usage: "\n -t Test file integrity" |
| 282 | //usage: |
| 283 | //usage:#define gunzip_example_usage |
| 284 | //usage: "$ ls -la /tmp/BusyBox*\n" |
| 285 | //usage: "-rw-rw-r-- 1 andersen andersen 557009 Apr 11 10:55 /tmp/BusyBox-0.43.tar.gz\n" |
| 286 | //usage: "$ gunzip /tmp/BusyBox-0.43.tar.gz\n" |
| 287 | //usage: "$ ls -la /tmp/BusyBox*\n" |
| 288 | //usage: "-rw-rw-r-- 1 andersen andersen 1761280 Apr 14 17:47 /tmp/BusyBox-0.43.tar\n" |
| 289 | //usage: |
| 290 | //usage:#define zcat_trivial_usage |
Denys Vlasenko | f2d8478 | 2013-02-28 18:04:22 +0100 | [diff] [blame] | 291 | //usage: "[FILE]..." |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 292 | //usage:#define zcat_full_usage "\n\n" |
| 293 | //usage: "Decompress to stdout" |
| 294 | |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 295 | //config:config GUNZIP |
| 296 | //config: bool "gunzip" |
| 297 | //config: default y |
Kang-Che Sung | b130f9f | 2017-01-08 14:28:34 +0800 | [diff] [blame] | 298 | //config: select FEATURE_GZIP_DECOMPRESS |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 299 | //config: help |
| 300 | //config: gunzip is used to decompress archives created by gzip. |
| 301 | //config: You can use the `-t' option to test the integrity of |
| 302 | //config: an archive, without decompressing it. |
Aaro Koskinen | fbe50cf | 2015-10-26 23:42:32 +0200 | [diff] [blame] | 303 | //config: |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 304 | //config:config ZCAT |
| 305 | //config: bool "zcat" |
| 306 | //config: default y |
Kang-Che Sung | b130f9f | 2017-01-08 14:28:34 +0800 | [diff] [blame] | 307 | //config: select FEATURE_GZIP_DECOMPRESS |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 308 | //config: help |
| 309 | //config: Alias to "gunzip -c". |
| 310 | //config: |
Aaro Koskinen | fbe50cf | 2015-10-26 23:42:32 +0200 | [diff] [blame] | 311 | //config:config FEATURE_GUNZIP_LONG_OPTIONS |
| 312 | //config: bool "Enable long options" |
| 313 | //config: default y |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 314 | //config: depends on (GUNZIP || ZCAT) && LONG_OPTS |
Aaro Koskinen | fbe50cf | 2015-10-26 23:42:32 +0200 | [diff] [blame] | 315 | //config: help |
| 316 | //config: Enable use of long options. |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 317 | |
Denys Vlasenko | 36184a4 | 2013-11-14 09:54:24 +0100 | [diff] [blame] | 318 | //applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP)) |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 319 | //applet:IF_ZCAT(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat)) |
Kang-Che Sung | b130f9f | 2017-01-08 14:28:34 +0800 | [diff] [blame] | 320 | #if ENABLE_FEATURE_GZIP_DECOMPRESS |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 321 | static |
Denys Vlasenko | 39a04f7 | 2010-05-31 14:18:57 +0200 | [diff] [blame] | 322 | char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM) |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 323 | { |
| 324 | char *extension = strrchr(filename, '.'); |
| 325 | |
| 326 | if (!extension) |
| 327 | return NULL; |
| 328 | |
Denis Vlasenko | bebbd8c | 2007-03-09 20:49:55 +0000 | [diff] [blame] | 329 | extension++; |
| 330 | if (strcmp(extension, "tgz" + 1) == 0 |
Denis Vlasenko | e9ad84d | 2008-08-05 13:10:34 +0000 | [diff] [blame] | 331 | #if ENABLE_FEATURE_SEAMLESS_Z |
| 332 | || (extension[0] == 'Z' && extension[1] == '\0') |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 333 | #endif |
| 334 | ) { |
Denis Vlasenko | bebbd8c | 2007-03-09 20:49:55 +0000 | [diff] [blame] | 335 | extension[-1] = '\0'; |
Denis Vlasenko | 51742f4 | 2007-04-12 00:32:05 +0000 | [diff] [blame] | 336 | } else if (strcmp(extension, "tgz") == 0) { |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 337 | filename = xstrdup(filename); |
| 338 | extension = strrchr(filename, '.'); |
| 339 | extension[2] = 'a'; |
| 340 | extension[3] = 'r'; |
| 341 | } else { |
| 342 | return NULL; |
| 343 | } |
| 344 | return filename; |
| 345 | } |
Aaro Koskinen | fbe50cf | 2015-10-26 23:42:32 +0200 | [diff] [blame] | 346 | |
| 347 | #if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS |
| 348 | static const char gunzip_longopts[] ALIGN1 = |
| 349 | "stdout\0" No_argument "c" |
| 350 | "to-stdout\0" No_argument "c" |
| 351 | "force\0" No_argument "f" |
| 352 | "test\0" No_argument "t" |
Aaro Koskinen | cddc98e | 2015-10-26 23:42:33 +0200 | [diff] [blame] | 353 | "no-name\0" No_argument "n" |
Aaro Koskinen | fbe50cf | 2015-10-26 23:42:32 +0200 | [diff] [blame] | 354 | ; |
| 355 | #endif |
| 356 | |
Denis Vlasenko | 5297809 | 2008-03-30 13:11:47 +0000 | [diff] [blame] | 357 | /* |
| 358 | * Linux kernel build uses gzip -d -n. We accept and ignore it. |
| 359 | * Man page says: |
| 360 | * -n --no-name |
| 361 | * gzip: do not save the original file name and time stamp. |
| 362 | * (The original name is always saved if the name had to be truncated.) |
| 363 | * gunzip: do not restore the original file name/time even if present |
| 364 | * (remove only the gzip suffix from the compressed file name). |
| 365 | * This option is the default when decompressing. |
| 366 | * -N --name |
| 367 | * gzip: always save the original file name and time stamp (this is the default) |
| 368 | * gunzip: restore the original file name and time stamp if present. |
| 369 | */ |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 370 | int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 371 | int gunzip_main(int argc UNUSED_PARAM, char **argv) |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 372 | { |
Aaro Koskinen | fbe50cf | 2015-10-26 23:42:32 +0200 | [diff] [blame] | 373 | #if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS |
| 374 | applet_long_options = gunzip_longopts; |
| 375 | #endif |
Mike Frysinger | 08e28e8 | 2013-02-28 21:28:21 -0500 | [diff] [blame] | 376 | getopt32(argv, "cfvqdtn"); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 377 | argv += optind; |
Denys Vlasenko | 8e96efa | 2013-02-28 18:06:09 +0100 | [diff] [blame] | 378 | |
| 379 | /* If called as zcat... |
| 380 | * Normally, "zcat" is just "gunzip -c". |
| 381 | * But if seamless magic is enabled, then we are much more clever. |
| 382 | */ |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 383 | if (ENABLE_ZCAT && applet_name[1] == 'c') |
Denys Vlasenko | 8e96efa | 2013-02-28 18:06:09 +0100 | [diff] [blame] | 384 | option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC; |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 385 | |
Denys Vlasenko | b4c11c1 | 2014-12-07 00:44:00 +0100 | [diff] [blame] | 386 | return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 387 | } |
Kang-Che Sung | b130f9f | 2017-01-08 14:28:34 +0800 | [diff] [blame] | 388 | #endif /* FEATURE_GZIP_DECOMPRESS */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 389 | |
Denys Vlasenko | d93f19e | 2010-05-30 03:46:54 +0200 | [diff] [blame] | 390 | |
| 391 | /* |
| 392 | * Modified for busybox by Glenn McGrath |
| 393 | * Added support output to stdout by Thomas Lundquist <thomasez@zelow.no> |
| 394 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 395 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Denys Vlasenko | d93f19e | 2010-05-30 03:46:54 +0200 | [diff] [blame] | 396 | */ |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 397 | //usage:#define bunzip2_trivial_usage |
Denys Vlasenko | 3b2acb7 | 2010-10-09 21:10:32 +0200 | [diff] [blame] | 398 | //usage: "[-cf] [FILE]..." |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 399 | //usage:#define bunzip2_full_usage "\n\n" |
| 400 | //usage: "Decompress FILEs (or stdin)\n" |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 401 | //usage: "\n -c Write to stdout" |
| 402 | //usage: "\n -f Force" |
| 403 | //usage:#define bzcat_trivial_usage |
Denys Vlasenko | f2d8478 | 2013-02-28 18:04:22 +0100 | [diff] [blame] | 404 | //usage: "[FILE]..." |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 405 | //usage:#define bzcat_full_usage "\n\n" |
| 406 | //usage: "Decompress to stdout" |
Denys Vlasenko | 66620fa | 2013-11-14 09:53:52 +0100 | [diff] [blame] | 407 | |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 408 | //config:config BUNZIP2 |
| 409 | //config: bool "bunzip2" |
| 410 | //config: default y |
Kang-Che Sung | b130f9f | 2017-01-08 14:28:34 +0800 | [diff] [blame] | 411 | //config: select FEATURE_BZIP2_DECOMPRESS |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 412 | //config: help |
| 413 | //config: bunzip2 is a compression utility using the Burrows-Wheeler block |
| 414 | //config: sorting text compression algorithm, and Huffman coding. Compression |
| 415 | //config: is generally considerably better than that achieved by more |
| 416 | //config: conventional LZ77/LZ78-based compressors, and approaches the |
| 417 | //config: performance of the PPM family of statistical compressors. |
| 418 | //config: |
| 419 | //config: Unless you have a specific application which requires bunzip2, you |
| 420 | //config: should probably say N here. |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 421 | //config: |
| 422 | //config:config BZCAT |
| 423 | //config: bool "bzcat" |
| 424 | //config: default y |
Kang-Che Sung | b130f9f | 2017-01-08 14:28:34 +0800 | [diff] [blame] | 425 | //config: select FEATURE_BZIP2_DECOMPRESS |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 426 | //config: help |
| 427 | //config: Alias to "bunzip2 -c". |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 428 | |
Denys Vlasenko | b9f2d9f | 2011-01-18 13:58:01 +0100 | [diff] [blame] | 429 | //applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 430 | //applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat)) |
Kang-Che Sung | b130f9f | 2017-01-08 14:28:34 +0800 | [diff] [blame] | 431 | #if ENABLE_FEATURE_BZIP2_DECOMPRESS |
Denys Vlasenko | d93f19e | 2010-05-30 03:46:54 +0200 | [diff] [blame] | 432 | int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 433 | int bunzip2_main(int argc UNUSED_PARAM, char **argv) |
| 434 | { |
Mike Frysinger | 08e28e8 | 2013-02-28 21:28:21 -0500 | [diff] [blame] | 435 | getopt32(argv, "cfvqdt"); |
Denys Vlasenko | d93f19e | 2010-05-30 03:46:54 +0200 | [diff] [blame] | 436 | argv += optind; |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 437 | if (ENABLE_BZCAT && applet_name[2] == 'c') /* bzcat */ |
Denys Vlasenko | d93f19e | 2010-05-30 03:46:54 +0200 | [diff] [blame] | 438 | option_mask32 |= OPT_STDOUT; |
| 439 | |
Denys Vlasenko | b4c11c1 | 2014-12-07 00:44:00 +0100 | [diff] [blame] | 440 | return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2"); |
Denys Vlasenko | d93f19e | 2010-05-30 03:46:54 +0200 | [diff] [blame] | 441 | } |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 442 | #endif |
| 443 | |
| 444 | |
| 445 | /* |
| 446 | * Small lzma deflate implementation. |
| 447 | * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org> |
| 448 | * |
| 449 | * Based on bunzip.c from busybox |
| 450 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 451 | * Licensed under GPLv2, see file LICENSE in this source tree. |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 452 | */ |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 453 | //usage:#define unlzma_trivial_usage |
| 454 | //usage: "[-cf] [FILE]..." |
| 455 | //usage:#define unlzma_full_usage "\n\n" |
| 456 | //usage: "Decompress FILE (or stdin)\n" |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 457 | //usage: "\n -c Write to stdout" |
| 458 | //usage: "\n -f Force" |
| 459 | //usage: |
| 460 | //usage:#define lzma_trivial_usage |
| 461 | //usage: "-d [-cf] [FILE]..." |
| 462 | //usage:#define lzma_full_usage "\n\n" |
| 463 | //usage: "Decompress FILE (or stdin)\n" |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 464 | //usage: "\n -d Decompress" |
| 465 | //usage: "\n -c Write to stdout" |
| 466 | //usage: "\n -f Force" |
| 467 | //usage: |
| 468 | //usage:#define lzcat_trivial_usage |
Denys Vlasenko | f2d8478 | 2013-02-28 18:04:22 +0100 | [diff] [blame] | 469 | //usage: "[FILE]..." |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 470 | //usage:#define lzcat_full_usage "\n\n" |
| 471 | //usage: "Decompress to stdout" |
| 472 | //usage: |
| 473 | //usage:#define unxz_trivial_usage |
| 474 | //usage: "[-cf] [FILE]..." |
| 475 | //usage:#define unxz_full_usage "\n\n" |
| 476 | //usage: "Decompress FILE (or stdin)\n" |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 477 | //usage: "\n -c Write to stdout" |
| 478 | //usage: "\n -f Force" |
| 479 | //usage: |
| 480 | //usage:#define xz_trivial_usage |
| 481 | //usage: "-d [-cf] [FILE]..." |
| 482 | //usage:#define xz_full_usage "\n\n" |
| 483 | //usage: "Decompress FILE (or stdin)\n" |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 484 | //usage: "\n -d Decompress" |
| 485 | //usage: "\n -c Write to stdout" |
| 486 | //usage: "\n -f Force" |
| 487 | //usage: |
| 488 | //usage:#define xzcat_trivial_usage |
Denys Vlasenko | f2d8478 | 2013-02-28 18:04:22 +0100 | [diff] [blame] | 489 | //usage: "[FILE]..." |
Pere Orga | 1f4447b | 2011-03-27 22:40:30 +0200 | [diff] [blame] | 490 | //usage:#define xzcat_full_usage "\n\n" |
| 491 | //usage: "Decompress to stdout" |
| 492 | |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 493 | //config:config UNLZMA |
| 494 | //config: bool "unlzma" |
| 495 | //config: default y |
| 496 | //config: help |
| 497 | //config: unlzma is a compression utility using the Lempel-Ziv-Markov chain |
| 498 | //config: compression algorithm, and range coding. Compression |
| 499 | //config: is generally considerably better than that achieved by the bzip2 |
| 500 | //config: compressors. |
| 501 | //config: |
| 502 | //config: The BusyBox unlzma applet is limited to decompression only. |
| 503 | //config: On an x86 system, this applet adds about 4K. |
| 504 | //config: |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 505 | //config:config LZCAT |
| 506 | //config: bool "lzcat" |
| 507 | //config: default y |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 508 | //config: help |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 509 | //config: unlzma is a compression utility using the Lempel-Ziv-Markov chain |
| 510 | //config: compression algorithm, and range coding. Compression |
| 511 | //config: is generally considerably better than that achieved by the bzip2 |
| 512 | //config: compressors. |
| 513 | //config: |
| 514 | //config: The BusyBox unlzma applet is limited to decompression only. |
| 515 | //config: On an x86 system, this applet adds about 4K. |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 516 | //config: |
| 517 | //config:config LZMA |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 518 | //config: bool "lzma -d" |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 519 | //config: default y |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 520 | //config: help |
| 521 | //config: Enable this option if you want commands like "lzma -d" to work. |
| 522 | //config: IOW: you'll get lzma applet, but it will always require -d option. |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 523 | //config: |
| 524 | //config:config FEATURE_LZMA_FAST |
| 525 | //config: bool "Optimize unlzma for speed" |
| 526 | //config: default n |
| 527 | //config: depends on UNLZMA || LZCAT || LZMA |
| 528 | //config: help |
| 529 | //config: This option reduces decompression time by about 25% at the cost of |
| 530 | //config: a 1K bigger binary. |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 531 | |
Denys Vlasenko | 36184a4 | 2013-11-14 09:54:24 +0100 | [diff] [blame] | 532 | //applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP)) |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 533 | //applet:IF_LZCAT(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat)) |
Denys Vlasenko | ac21687 | 2013-11-14 11:38:18 +0100 | [diff] [blame] | 534 | //applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma)) |
Denys Vlasenko | 66620fa | 2013-11-14 09:53:52 +0100 | [diff] [blame] | 535 | //kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 536 | //kbuild:lib-$(CONFIG_LZCAT) += bbunzip.o |
| 537 | //kbuild:lib-$(CONFIG_LZMA) += bbunzip.o |
| 538 | #if ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 539 | int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 540 | int unlzma_main(int argc UNUSED_PARAM, char **argv) |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 541 | { |
Mike Frysinger | 08e28e8 | 2013-02-28 21:28:21 -0500 | [diff] [blame] | 542 | IF_LZMA(int opts =) getopt32(argv, "cfvqdt"); |
Denys Vlasenko | e04c867 | 2010-05-30 03:33:50 +0200 | [diff] [blame] | 543 | # if ENABLE_LZMA |
Denys Vlasenko | ccb88a6 | 2010-05-27 02:22:54 +0200 | [diff] [blame] | 544 | /* lzma without -d or -t? */ |
| 545 | if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST))) |
| 546 | bb_show_usage(); |
| 547 | # endif |
| 548 | /* lzcat? */ |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 549 | if (ENABLE_LZCAT && applet_name[2] == 'c') |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 550 | option_mask32 |= OPT_STDOUT; |
| 551 | |
Denys Vlasenko | ccb88a6 | 2010-05-27 02:22:54 +0200 | [diff] [blame] | 552 | argv += optind; |
Denys Vlasenko | b4c11c1 | 2014-12-07 00:44:00 +0100 | [diff] [blame] | 553 | return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma"); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 554 | } |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 555 | #endif |
| 556 | |
| 557 | |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 558 | //config:config UNXZ |
| 559 | //config: bool "unxz" |
| 560 | //config: default y |
| 561 | //config: help |
| 562 | //config: unxz is a unlzma successor. |
| 563 | //config: |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 564 | //config:config XZCAT |
| 565 | //config: bool "xzcat" |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 566 | //config: default y |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 567 | //config: help |
| 568 | //config: Alias to "unxz -c". |
| 569 | //config: |
| 570 | //config:config XZ |
| 571 | //config: bool "xz -d" |
| 572 | //config: default y |
Denys Vlasenko | f6beef6 | 2013-11-14 11:39:00 +0100 | [diff] [blame] | 573 | //config: help |
| 574 | //config: Enable this option if you want commands like "xz -d" to work. |
| 575 | //config: IOW: you'll get xz applet, but it will always require -d option. |
| 576 | |
Denys Vlasenko | 36184a4 | 2013-11-14 09:54:24 +0100 | [diff] [blame] | 577 | //applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP)) |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 578 | //applet:IF_XZCAT(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat)) |
Denys Vlasenko | ac21687 | 2013-11-14 11:38:18 +0100 | [diff] [blame] | 579 | //applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz)) |
Denys Vlasenko | 66620fa | 2013-11-14 09:53:52 +0100 | [diff] [blame] | 580 | //kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 581 | //kbuild:lib-$(CONFIG_XZCAT) += bbunzip.o |
| 582 | //kbuild:lib-$(CONFIG_XZ) += bbunzip.o |
| 583 | #if ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ |
Denys Vlasenko | 602ce69 | 2010-05-30 03:35:18 +0200 | [diff] [blame] | 584 | int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 585 | int unxz_main(int argc UNUSED_PARAM, char **argv) |
| 586 | { |
Mike Frysinger | 08e28e8 | 2013-02-28 21:28:21 -0500 | [diff] [blame] | 587 | IF_XZ(int opts =) getopt32(argv, "cfvqdt"); |
Denys Vlasenko | 602ce69 | 2010-05-30 03:35:18 +0200 | [diff] [blame] | 588 | # if ENABLE_XZ |
| 589 | /* xz without -d or -t? */ |
| 590 | if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST))) |
| 591 | bb_show_usage(); |
| 592 | # endif |
| 593 | /* xzcat? */ |
Denys Vlasenko | eb3fdc8 | 2016-11-16 15:45:05 +0100 | [diff] [blame] | 594 | if (ENABLE_XZCAT && applet_name[2] == 'c') |
Denys Vlasenko | 602ce69 | 2010-05-30 03:35:18 +0200 | [diff] [blame] | 595 | option_mask32 |= OPT_STDOUT; |
| 596 | |
| 597 | argv += optind; |
Denys Vlasenko | b4c11c1 | 2014-12-07 00:44:00 +0100 | [diff] [blame] | 598 | return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz"); |
Denys Vlasenko | 602ce69 | 2010-05-30 03:35:18 +0200 | [diff] [blame] | 599 | } |
Denys Vlasenko | 602ce69 | 2010-05-30 03:35:18 +0200 | [diff] [blame] | 600 | #endif |