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