bbunzip.c 19 KB

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