Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Denis Vlasenko | a4688bf | 2007-03-11 10:56:37 +0000 | [diff] [blame] | 3 | * Common code for gunzip-like applets |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 4 | * |
| 5 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 6 | */ |
| 7 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 8 | #include "libbb.h" |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 9 | #include "unarchive.h" |
| 10 | |
| 11 | enum { |
Denis Vlasenko | 7560578 | 2007-03-14 00:07:51 +0000 | [diff] [blame] | 12 | OPT_STDOUT = 0x1, |
| 13 | OPT_FORCE = 0x2, |
Denis Vlasenko | 6fa3ab3 | 2007-10-21 18:59:58 +0000 | [diff] [blame] | 14 | /* gunzip and bunzip2 only: */ |
Denis Vlasenko | 7560578 | 2007-03-14 00:07:51 +0000 | [diff] [blame] | 15 | OPT_VERBOSE = 0x4, |
| 16 | OPT_DECOMPRESS = 0x8, |
| 17 | OPT_TEST = 0x10, |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 18 | }; |
| 19 | |
| 20 | static |
| 21 | int open_to_or_warn(int to_fd, const char *filename, int flags, int mode) |
| 22 | { |
Denis Vlasenko | 50f7f44 | 2007-04-11 23:20:53 +0000 | [diff] [blame] | 23 | int fd = open3_or_warn(filename, flags, mode); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 24 | if (fd < 0) { |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 25 | return 1; |
| 26 | } |
Denis Vlasenko | 50f7f44 | 2007-04-11 23:20:53 +0000 | [diff] [blame] | 27 | xmove_fd(fd, to_fd); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 28 | return 0; |
| 29 | } |
| 30 | |
Denis Vlasenko | 7560578 | 2007-03-14 00:07:51 +0000 | [diff] [blame] | 31 | int bbunpack(char **argv, |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 32 | char* (*make_new_name)(char *filename), |
| 33 | USE_DESKTOP(long long) int (*unpacker)(void) |
| 34 | ) |
| 35 | { |
| 36 | struct stat stat_buf; |
| 37 | USE_DESKTOP(long long) int status; |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 38 | char *filename, *new_name; |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 39 | smallint exitcode = 0; |
| 40 | |
| 41 | do { |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 42 | /* NB: new_name is *maybe* malloc'ed! */ |
| 43 | new_name = NULL; |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 44 | filename = *argv; /* can be NULL - 'streaming' bunzip2 */ |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 45 | |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 46 | if (filename && LONE_DASH(filename)) |
| 47 | filename = NULL; |
| 48 | |
| 49 | /* Open src */ |
| 50 | if (filename) { |
| 51 | if (stat(filename, &stat_buf) != 0) { |
Denis Vlasenko | 0c97c9d | 2007-10-01 11:58:38 +0000 | [diff] [blame] | 52 | bb_simple_perror_msg(filename); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 53 | err: |
| 54 | exitcode = 1; |
| 55 | goto free_name; |
| 56 | } |
| 57 | if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0)) |
| 58 | goto err; |
| 59 | } |
| 60 | |
| 61 | /* Special cases: test, stdout */ |
| 62 | if (option_mask32 & (OPT_STDOUT|OPT_TEST)) { |
| 63 | if (option_mask32 & OPT_TEST) |
| 64 | if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0)) |
| 65 | goto err; |
| 66 | filename = NULL; |
| 67 | } |
| 68 | |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 69 | /* Open dst if we are going to unpack to file */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 70 | if (filename) { |
| 71 | new_name = make_new_name(filename); |
| 72 | if (!new_name) { |
| 73 | bb_error_msg("%s: unknown suffix - ignored", filename); |
| 74 | goto err; |
| 75 | } |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 76 | /* O_EXCL: "real" bunzip2 doesn't overwrite files */ |
Denis Vlasenko | 5dd8a03 | 2007-10-05 15:26:08 +0000 | [diff] [blame] | 77 | /* GNU gunzip does not bail out, but goes to next file */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 78 | if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL, |
| 79 | stat_buf.st_mode)) |
| 80 | goto err; |
| 81 | } |
| 82 | |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 83 | /* Check that the input is sane */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 84 | if (isatty(STDIN_FILENO) && (option_mask32 & OPT_FORCE) == 0) { |
| 85 | bb_error_msg_and_die("compressed data not read from terminal, " |
| 86 | "use -f to force it"); |
| 87 | } |
| 88 | |
| 89 | status = unpacker(); |
| 90 | if (status < 0) |
| 91 | exitcode = 1; |
| 92 | |
| 93 | if (filename) { |
| 94 | char *del = new_name; |
| 95 | if (status >= 0) { |
| 96 | /* TODO: restore user/group/times here? */ |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 97 | /* Delete _compressed_ file */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 98 | del = filename; |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 99 | /* restore extension (unless tgz -> tar case) */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 100 | if (new_name == filename) |
| 101 | filename[strlen(filename)] = '.'; |
| 102 | } |
Denis Vlasenko | 1bb552b | 2007-04-05 21:25:15 +0000 | [diff] [blame] | 103 | xunlink(del); |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 104 | |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 105 | #if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */ |
| 106 | /* Extreme bloat for gunzip compat */ |
| 107 | if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE) && status >= 0) { |
| 108 | fprintf(stderr, "%s: %u%% - replaced with %s\n", |
| 109 | filename, (unsigned)(stat_buf.st_size*100 / (status+1)), new_name); |
| 110 | } |
| 111 | #endif |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 112 | |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 113 | free_name: |
| 114 | if (new_name != filename) |
| 115 | free(new_name); |
| 116 | } |
| 117 | } while (*argv && *++argv); |
| 118 | |
| 119 | return exitcode; |
| 120 | } |
| 121 | |
Denis Vlasenko | a4688bf | 2007-03-11 10:56:37 +0000 | [diff] [blame] | 122 | #if ENABLE_BUNZIP2 || ENABLE_UNLZMA || ENABLE_UNCOMPRESS |
| 123 | |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 124 | static |
Denis Vlasenko | bebbd8c | 2007-03-09 20:49:55 +0000 | [diff] [blame] | 125 | char* make_new_name_generic(char *filename, const char *expected_ext) |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 126 | { |
| 127 | char *extension = strrchr(filename, '.'); |
Denis Vlasenko | bebbd8c | 2007-03-09 20:49:55 +0000 | [diff] [blame] | 128 | if (!extension || strcmp(extension + 1, expected_ext) != 0) { |
Denis Vlasenko | 6c939e0 | 2007-03-07 23:22:47 +0000 | [diff] [blame] | 129 | /* Mimic GNU gunzip - "real" bunzip2 tries to */ |
| 130 | /* unpack file anyway, to file.out */ |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 131 | return NULL; |
| 132 | } |
| 133 | *extension = '\0'; |
| 134 | return filename; |
| 135 | } |
| 136 | |
Denis Vlasenko | a4688bf | 2007-03-11 10:56:37 +0000 | [diff] [blame] | 137 | #endif |
| 138 | |
| 139 | |
Denis Vlasenko | a4688bf | 2007-03-11 10:56:37 +0000 | [diff] [blame] | 140 | /* |
Denis Vlasenko | 0beaff8 | 2007-09-21 13:16:32 +0000 | [diff] [blame] | 141 | * Modified for busybox by Glenn McGrath |
Denis Vlasenko | a4688bf | 2007-03-11 10:56:37 +0000 | [diff] [blame] | 142 | * Added support output to stdout by Thomas Lundquist <thomasez@zelow.no> |
| 143 | * |
| 144 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 145 | */ |
| 146 | |
Denis Vlasenko | bebbd8c | 2007-03-09 20:49:55 +0000 | [diff] [blame] | 147 | #if ENABLE_BUNZIP2 |
| 148 | |
| 149 | static |
| 150 | char* make_new_name_bunzip2(char *filename) |
| 151 | { |
| 152 | return make_new_name_generic(filename, "bz2"); |
| 153 | } |
| 154 | |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 155 | static |
| 156 | USE_DESKTOP(long long) int unpack_bunzip2(void) |
| 157 | { |
Denis Vlasenko | c14d39e | 2007-06-08 13:05:39 +0000 | [diff] [blame] | 158 | return unpack_bz2_stream(STDIN_FILENO, STDOUT_FILENO); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 161 | int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame] | 162 | int bunzip2_main(int argc ATTRIBUTE_UNUSED, char **argv) |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 163 | { |
Denis Vlasenko | 6fa3ab3 | 2007-10-21 18:59:58 +0000 | [diff] [blame] | 164 | getopt32(argv, "cfvdt"); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 165 | argv += optind; |
| 166 | if (applet_name[2] == 'c') |
| 167 | option_mask32 |= OPT_STDOUT; |
| 168 | |
Denis Vlasenko | 7560578 | 2007-03-14 00:07:51 +0000 | [diff] [blame] | 169 | return bbunpack(argv, make_new_name_bunzip2, unpack_bunzip2); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | #endif |
| 173 | |
| 174 | |
| 175 | /* |
| 176 | * Gzip implementation for busybox |
| 177 | * |
| 178 | * Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly. |
| 179 | * |
| 180 | * Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de> |
| 181 | * based on gzip sources |
| 182 | * |
| 183 | * Adjusted further by Erik Andersen <andersen@codepoet.org> to support files as |
| 184 | * well as stdin/stdout, and to generally behave itself wrt command line |
| 185 | * handling. |
| 186 | * |
| 187 | * 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] | 188 | * busybox functions by Glenn McGrath |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 189 | * |
| 190 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 191 | * |
| 192 | * gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface |
| 193 | * Copyright (C) 1992-1993 Jean-loup Gailly |
| 194 | * The unzip code was written and put in the public domain by Mark Adler. |
| 195 | * Portions of the lzw code are derived from the public domain 'compress' |
| 196 | * written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies, |
| 197 | * Ken Turkowski, Dave Mack and Peter Jannesen. |
| 198 | * |
| 199 | * See the license_msg below and the file COPYING for the software license. |
| 200 | * See the file algorithm.doc for the compression algorithms and file formats. |
| 201 | */ |
| 202 | |
| 203 | #if ENABLE_GUNZIP |
| 204 | |
| 205 | static |
| 206 | char* make_new_name_gunzip(char *filename) |
| 207 | { |
| 208 | char *extension = strrchr(filename, '.'); |
| 209 | |
| 210 | if (!extension) |
| 211 | return NULL; |
| 212 | |
Denis Vlasenko | bebbd8c | 2007-03-09 20:49:55 +0000 | [diff] [blame] | 213 | extension++; |
| 214 | if (strcmp(extension, "tgz" + 1) == 0 |
Denis Vlasenko | dbe6e66 | 2007-08-14 16:43:01 +0000 | [diff] [blame] | 215 | #if ENABLE_FEATURE_GUNZIP_UNCOMPRESS |
Denis Vlasenko | bebbd8c | 2007-03-09 20:49:55 +0000 | [diff] [blame] | 216 | || strcmp(extension, "Z") == 0 |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 217 | #endif |
| 218 | ) { |
Denis Vlasenko | bebbd8c | 2007-03-09 20:49:55 +0000 | [diff] [blame] | 219 | extension[-1] = '\0'; |
Denis Vlasenko | 51742f4 | 2007-04-12 00:32:05 +0000 | [diff] [blame] | 220 | } else if (strcmp(extension, "tgz") == 0) { |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 221 | filename = xstrdup(filename); |
| 222 | extension = strrchr(filename, '.'); |
| 223 | extension[2] = 'a'; |
| 224 | extension[3] = 'r'; |
| 225 | } else { |
| 226 | return NULL; |
| 227 | } |
| 228 | return filename; |
| 229 | } |
| 230 | |
| 231 | static |
| 232 | USE_DESKTOP(long long) int unpack_gunzip(void) |
| 233 | { |
| 234 | USE_DESKTOP(long long) int status = -1; |
| 235 | |
| 236 | /* do the decompression, and cleanup */ |
| 237 | if (xread_char(STDIN_FILENO) == 0x1f) { |
| 238 | unsigned char magic2; |
| 239 | |
| 240 | magic2 = xread_char(STDIN_FILENO); |
| 241 | if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && magic2 == 0x9d) { |
| 242 | status = uncompress(STDIN_FILENO, STDOUT_FILENO); |
| 243 | } else if (magic2 == 0x8b) { |
Denis Vlasenko | c14d39e | 2007-06-08 13:05:39 +0000 | [diff] [blame] | 244 | status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 245 | } else { |
| 246 | goto bad_magic; |
| 247 | } |
| 248 | if (status < 0) { |
| 249 | bb_error_msg("error inflating"); |
| 250 | } |
| 251 | } else { |
| 252 | bad_magic: |
| 253 | bb_error_msg("invalid magic"); |
| 254 | /* status is still == -1 */ |
| 255 | } |
| 256 | return status; |
| 257 | } |
| 258 | |
Denis Vlasenko | 5297809 | 2008-03-30 13:11:47 +0000 | [diff] [blame] | 259 | /* |
| 260 | * Linux kernel build uses gzip -d -n. We accept and ignore it. |
| 261 | * Man page says: |
| 262 | * -n --no-name |
| 263 | * gzip: do not save the original file name and time stamp. |
| 264 | * (The original name is always saved if the name had to be truncated.) |
| 265 | * gunzip: do not restore the original file name/time even if present |
| 266 | * (remove only the gzip suffix from the compressed file name). |
| 267 | * This option is the default when decompressing. |
| 268 | * -N --name |
| 269 | * gzip: always save the original file name and time stamp (this is the default) |
| 270 | * gunzip: restore the original file name and time stamp if present. |
| 271 | */ |
| 272 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 273 | int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame] | 274 | int gunzip_main(int argc ATTRIBUTE_UNUSED, char **argv) |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 275 | { |
Denis Vlasenko | 5297809 | 2008-03-30 13:11:47 +0000 | [diff] [blame] | 276 | getopt32(argv, "cfvdtn"); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 277 | argv += optind; |
| 278 | /* if called as zcat */ |
| 279 | if (applet_name[1] == 'c') |
| 280 | option_mask32 |= OPT_STDOUT; |
| 281 | |
Denis Vlasenko | 7560578 | 2007-03-14 00:07:51 +0000 | [diff] [blame] | 282 | return bbunpack(argv, make_new_name_gunzip, unpack_gunzip); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | #endif |
| 286 | |
| 287 | |
| 288 | /* |
| 289 | * Small lzma deflate implementation. |
| 290 | * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org> |
| 291 | * |
| 292 | * Based on bunzip.c from busybox |
| 293 | * |
| 294 | * Licensed under GPL v2, see file LICENSE in this tarball for details. |
| 295 | */ |
| 296 | |
| 297 | #if ENABLE_UNLZMA |
| 298 | |
| 299 | static |
| 300 | char* make_new_name_unlzma(char *filename) |
| 301 | { |
Denis Vlasenko | bebbd8c | 2007-03-09 20:49:55 +0000 | [diff] [blame] | 302 | return make_new_name_generic(filename, "lzma"); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | static |
| 306 | USE_DESKTOP(long long) int unpack_unlzma(void) |
| 307 | { |
Denis Vlasenko | c14d39e | 2007-06-08 13:05:39 +0000 | [diff] [blame] | 308 | return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 311 | int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame] | 312 | int unlzma_main(int argc ATTRIBUTE_UNUSED, char **argv) |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 313 | { |
Denis Vlasenko | 211f7f8 | 2007-09-05 11:48:32 +0000 | [diff] [blame] | 314 | getopt32(argv, "cf"); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 315 | argv += optind; |
| 316 | /* lzmacat? */ |
| 317 | if (applet_name[4] == 'c') |
| 318 | option_mask32 |= OPT_STDOUT; |
| 319 | |
Denis Vlasenko | 7560578 | 2007-03-14 00:07:51 +0000 | [diff] [blame] | 320 | return bbunpack(argv, make_new_name_unlzma, unpack_unlzma); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | #endif |
| 324 | |
| 325 | |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 326 | /* |
| 327 | * Uncompress applet for busybox (c) 2002 Glenn McGrath |
| 328 | * |
| 329 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 330 | */ |
| 331 | |
| 332 | #if ENABLE_UNCOMPRESS |
| 333 | |
| 334 | static |
| 335 | char* make_new_name_uncompress(char *filename) |
| 336 | { |
Denis Vlasenko | bebbd8c | 2007-03-09 20:49:55 +0000 | [diff] [blame] | 337 | return make_new_name_generic(filename, "Z"); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static |
| 341 | USE_DESKTOP(long long) int unpack_uncompress(void) |
| 342 | { |
| 343 | USE_DESKTOP(long long) int status = -1; |
| 344 | |
| 345 | if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) { |
| 346 | bb_error_msg("invalid magic"); |
| 347 | } else { |
| 348 | status = uncompress(STDIN_FILENO, STDOUT_FILENO); |
| 349 | } |
| 350 | return status; |
| 351 | } |
| 352 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 353 | int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame] | 354 | int uncompress_main(int argc ATTRIBUTE_UNUSED, char **argv) |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 355 | { |
Denis Vlasenko | fe7cd64 | 2007-08-18 15:32:12 +0000 | [diff] [blame] | 356 | getopt32(argv, "cf"); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 357 | argv += optind; |
| 358 | |
Denis Vlasenko | 7560578 | 2007-03-14 00:07:51 +0000 | [diff] [blame] | 359 | return bbunpack(argv, make_new_name_uncompress, unpack_uncompress); |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | #endif |