bbunzip.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  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. //kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o
  10. //kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
  11. //kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o
  12. //kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
  13. /* lzop_main() uses bbunpack(), need this: */
  14. //kbuild:lib-$(CONFIG_LZOP) += bbunzip.o
  15. //kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o
  16. //kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o
  17. /* bzip2_main() too: */
  18. //kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
  19. /* gzip_main() too: */
  20. //kbuild:lib-$(CONFIG_GZIP) += bbunzip.o
  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"
  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"
  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"
  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. applet_long_options = gunzip_longopts;
  355. #endif
  356. getopt32(argv, "cfkvqdtn");
  357. argv += optind;
  358. /* If called as zcat...
  359. * Normally, "zcat" is just "gunzip -c".
  360. * But if seamless magic is enabled, then we are much more clever.
  361. */
  362. if (ENABLE_ZCAT && applet_name[1] == 'c')
  363. option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
  364. return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
  365. }
  366. #endif /* FEATURE_GZIP_DECOMPRESS */
  367. /*
  368. * Modified for busybox by Glenn McGrath
  369. * Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
  370. *
  371. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  372. */
  373. //usage:#define bunzip2_trivial_usage
  374. //usage: "[-cfk] [FILE]..."
  375. //usage:#define bunzip2_full_usage "\n\n"
  376. //usage: "Decompress FILEs (or stdin)\n"
  377. //usage: "\n -c Write to stdout"
  378. //usage: "\n -f Force"
  379. //usage: "\n -k Keep input files"
  380. //usage:#define bzcat_trivial_usage
  381. //usage: "[FILE]..."
  382. //usage:#define bzcat_full_usage "\n\n"
  383. //usage: "Decompress to stdout"
  384. //config:config BUNZIP2
  385. //config: bool "bunzip2"
  386. //config: default y
  387. //config: select FEATURE_BZIP2_DECOMPRESS
  388. //config: help
  389. //config: bunzip2 is a compression utility using the Burrows-Wheeler block
  390. //config: sorting text compression algorithm, and Huffman coding. Compression
  391. //config: is generally considerably better than that achieved by more
  392. //config: conventional LZ77/LZ78-based compressors, and approaches the
  393. //config: performance of the PPM family of statistical compressors.
  394. //config:
  395. //config: Unless you have a specific application which requires bunzip2, you
  396. //config: should probably say N here.
  397. //config:
  398. //config:config BZCAT
  399. //config: bool "bzcat"
  400. //config: default y
  401. //config: select FEATURE_BZIP2_DECOMPRESS
  402. //config: help
  403. //config: Alias to "bunzip2 -c".
  404. //applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
  405. // APPLET_ODDNAME:name main location suid_type help
  406. //applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
  407. #if ENABLE_FEATURE_BZIP2_DECOMPRESS || ENABLE_BUNZIP2 || ENABLE_BZCAT
  408. int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  409. int bunzip2_main(int argc UNUSED_PARAM, char **argv)
  410. {
  411. getopt32(argv, "cfkvqdt");
  412. argv += optind;
  413. if (ENABLE_BZCAT && applet_name[2] == 'c') /* bzcat */
  414. option_mask32 |= OPT_STDOUT;
  415. return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
  416. }
  417. #endif
  418. /*
  419. * Small lzma deflate implementation.
  420. * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
  421. *
  422. * Based on bunzip.c from busybox
  423. *
  424. * Licensed under GPLv2, see file LICENSE in this source tree.
  425. */
  426. //usage:#define unlzma_trivial_usage
  427. //usage: "[-cfk] [FILE]..."
  428. //usage:#define unlzma_full_usage "\n\n"
  429. //usage: "Decompress FILE (or stdin)\n"
  430. //usage: "\n -c Write to stdout"
  431. //usage: "\n -f Force"
  432. //usage: "\n -k Keep input files"
  433. //usage:
  434. //usage:#define lzma_trivial_usage
  435. //usage: "-d [-cfk] [FILE]..."
  436. //usage:#define lzma_full_usage "\n\n"
  437. //usage: "Decompress FILE (or stdin)\n"
  438. //usage: "\n -d Decompress"
  439. //usage: "\n -c Write to stdout"
  440. //usage: "\n -f Force"
  441. //usage: "\n -k Keep input files"
  442. //usage:
  443. //usage:#define lzcat_trivial_usage
  444. //usage: "[FILE]..."
  445. //usage:#define lzcat_full_usage "\n\n"
  446. //usage: "Decompress to stdout"
  447. //config:config UNLZMA
  448. //config: bool "unlzma"
  449. //config: default y
  450. //config: help
  451. //config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
  452. //config: compression algorithm, and range coding. Compression
  453. //config: is generally considerably better than that achieved by the bzip2
  454. //config: compressors.
  455. //config:
  456. //config: The BusyBox unlzma applet is limited to decompression only.
  457. //config: On an x86 system, this applet adds about 4K.
  458. //config:
  459. //config:config LZCAT
  460. //config: bool "lzcat"
  461. //config: default y
  462. //config: help
  463. //config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
  464. //config: compression algorithm, and range coding. Compression
  465. //config: is generally considerably better than that achieved by the bzip2
  466. //config: compressors.
  467. //config:
  468. //config: The BusyBox unlzma applet is limited to decompression only.
  469. //config: On an x86 system, this applet adds about 4K.
  470. //config:
  471. //config:config LZMA
  472. //config: bool "lzma -d"
  473. //config: default y
  474. //config: help
  475. //config: Enable this option if you want commands like "lzma -d" to work.
  476. //config: IOW: you'll get lzma applet, but it will always require -d option.
  477. //config:
  478. //config:config FEATURE_LZMA_FAST
  479. //config: bool "Optimize for speed"
  480. //config: default n
  481. //config: depends on UNLZMA || LZCAT || LZMA
  482. //config: help
  483. //config: This option reduces decompression time by about 25% at the cost of
  484. //config: a 1K bigger binary.
  485. //applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP))
  486. // APPLET_ODDNAME:name main location suid_type help
  487. //applet:IF_LZCAT(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat))
  488. //applet:IF_LZMA( APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
  489. //kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o
  490. //kbuild:lib-$(CONFIG_LZCAT) += bbunzip.o
  491. //kbuild:lib-$(CONFIG_LZMA) += bbunzip.o
  492. #if ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA
  493. int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  494. int unlzma_main(int argc UNUSED_PARAM, char **argv)
  495. {
  496. IF_LZMA(int opts =) getopt32(argv, "cfkvqdt");
  497. # if ENABLE_LZMA
  498. /* lzma without -d or -t? */
  499. if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
  500. bb_show_usage();
  501. # endif
  502. /* lzcat? */
  503. if (ENABLE_LZCAT && applet_name[2] == 'c')
  504. option_mask32 |= OPT_STDOUT;
  505. argv += optind;
  506. return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
  507. }
  508. #endif
  509. //usage:#define unxz_trivial_usage
  510. //usage: "[-cfk] [FILE]..."
  511. //usage:#define unxz_full_usage "\n\n"
  512. //usage: "Decompress FILE (or stdin)\n"
  513. //usage: "\n -c Write to stdout"
  514. //usage: "\n -f Force"
  515. //usage: "\n -k Keep input files"
  516. //usage:
  517. //usage:#define xz_trivial_usage
  518. //usage: "-d [-cfk] [FILE]..."
  519. //usage:#define xz_full_usage "\n\n"
  520. //usage: "Decompress FILE (or stdin)\n"
  521. //usage: "\n -d Decompress"
  522. //usage: "\n -c Write to stdout"
  523. //usage: "\n -f Force"
  524. //usage: "\n -k Keep input files"
  525. //usage:
  526. //usage:#define xzcat_trivial_usage
  527. //usage: "[FILE]..."
  528. //usage:#define xzcat_full_usage "\n\n"
  529. //usage: "Decompress to stdout"
  530. //config:config UNXZ
  531. //config: bool "unxz"
  532. //config: default y
  533. //config: help
  534. //config: unxz is a unlzma successor.
  535. //config:
  536. //config:config XZCAT
  537. //config: bool "xzcat"
  538. //config: default y
  539. //config: help
  540. //config: Alias to "unxz -c".
  541. //config:
  542. //config:config XZ
  543. //config: bool "xz -d"
  544. //config: default y
  545. //config: help
  546. //config: Enable this option if you want commands like "xz -d" to work.
  547. //config: IOW: you'll get xz applet, but it will always require -d option.
  548. //applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP))
  549. // APPLET_ODDNAME:name main location suid_type help
  550. //applet:IF_XZCAT(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat))
  551. //applet:IF_XZ( APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
  552. //kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o
  553. //kbuild:lib-$(CONFIG_XZCAT) += bbunzip.o
  554. //kbuild:lib-$(CONFIG_XZ) += bbunzip.o
  555. #if ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ
  556. int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  557. int unxz_main(int argc UNUSED_PARAM, char **argv)
  558. {
  559. IF_XZ(int opts =) getopt32(argv, "cfkvqdt");
  560. # if ENABLE_XZ
  561. /* xz without -d or -t? */
  562. if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
  563. bb_show_usage();
  564. # endif
  565. /* xzcat? */
  566. if (ENABLE_XZCAT && applet_name[2] == 'c')
  567. option_mask32 |= OPT_STDOUT;
  568. argv += optind;
  569. return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
  570. }
  571. #endif