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