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