bbunzip.c 19 KB

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