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