aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-02-01 09:13:14 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-02-01 09:13:14 +0100
commitd6f0f03b68fc4cf9ffb8006e192e36f0ebf51ea6 (patch)
tree24b4adf0a28b91dbcd014cf99527ca07d492003d
parent99ac1759dd429bd7995feff33dc683589c016c8e (diff)
downloadbusybox-w32-d6f0f03b68fc4cf9ffb8006e192e36f0ebf51ea6.tar.gz
busybox-w32-d6f0f03b68fc4cf9ffb8006e192e36f0ebf51ea6.tar.bz2
busybox-w32-d6f0f03b68fc4cf9ffb8006e192e36f0ebf51ea6.zip
libarchive: move bbunpack constants to bb_archive.h
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/bbunzip.c57
-rw-r--r--archival/bzip2.c11
-rw-r--r--archival/gzip.c10
-rw-r--r--include/bb_archive.h15
4 files changed, 48 insertions, 45 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index 944b397b3..a2ce0a13c 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -21,19 +21,6 @@
21#include "libbb.h" 21#include "libbb.h"
22#include "bb_archive.h" 22#include "bb_archive.h"
23 23
24/* Note: must be kept in sync with archival/lzop.c */
25enum {
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
37static 24static
38int open_to_or_warn(int to_fd, const char *filename, int flags, int mode) 25int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
39{ 26{
@@ -72,7 +59,7 @@ int FAST_FUNC bbunpack(char **argv,
72 59
73 /* Open src */ 60 /* Open src */
74 if (filename) { 61 if (filename) {
75 if (!(option_mask32 & SEAMLESS_MAGIC)) { 62 if (!(option_mask32 & BBUNPK_SEAMLESS_MAGIC)) {
76 if (stat(filename, &stat_buf) != 0) { 63 if (stat(filename, &stat_buf) != 0) {
77 err_name: 64 err_name:
78 bb_simple_perror_msg(filename); 65 bb_simple_perror_msg(filename);
@@ -91,15 +78,15 @@ int FAST_FUNC bbunpack(char **argv,
91 xmove_fd(fd, STDIN_FILENO); 78 xmove_fd(fd, STDIN_FILENO);
92 } 79 }
93 } else 80 } else
94 if (option_mask32 & SEAMLESS_MAGIC) { 81 if (option_mask32 & BBUNPK_SEAMLESS_MAGIC) {
95 /* "clever zcat" on stdin */ 82 /* "clever zcat" on stdin */
96 if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1)) 83 if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
97 goto err; 84 goto err;
98 } 85 }
99 86
100 /* Special cases: test, stdout */ 87 /* Special cases: test, stdout */
101 if (option_mask32 & (OPT_STDOUT|OPT_TEST)) { 88 if (option_mask32 & (BBUNPK_OPT_STDOUT|BBUNPK_OPT_TEST)) {
102 if (option_mask32 & OPT_TEST) 89 if (option_mask32 & BBUNPK_OPT_TEST)
103 if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0)) 90 if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0))
104 xfunc_die(); 91 xfunc_die();
105 filename = NULL; 92 filename = NULL;
@@ -114,7 +101,7 @@ int FAST_FUNC bbunpack(char **argv,
114 } 101 }
115 102
116 /* -f: overwrite existing output files */ 103 /* -f: overwrite existing output files */
117 if (option_mask32 & OPT_FORCE) { 104 if (option_mask32 & BBUNPK_OPT_FORCE) {
118 unlink(new_name); 105 unlink(new_name);
119 } 106 }
120 107
@@ -126,12 +113,12 @@ int FAST_FUNC bbunpack(char **argv,
126 } 113 }
127 114
128 /* Check that the input is sane */ 115 /* Check that the input is sane */
129 if (!(option_mask32 & OPT_FORCE) && isatty(STDIN_FILENO)) { 116 if (!(option_mask32 & BBUNPK_OPT_FORCE) && isatty(STDIN_FILENO)) {
130 bb_error_msg_and_die("compressed data not read from terminal, " 117 bb_error_msg_and_die("compressed data not read from terminal, "
131 "use -f to force it"); 118 "use -f to force it");
132 } 119 }
133 120
134 if (!(option_mask32 & SEAMLESS_MAGIC)) { 121 if (!(option_mask32 & BBUNPK_SEAMLESS_MAGIC)) {
135 init_transformer_state(&xstate); 122 init_transformer_state(&xstate);
136 /*xstate.signature_skipped = 0; - already is */ 123 /*xstate.signature_skipped = 0; - already is */
137 /*xstate.src_fd = STDIN_FILENO; - already is */ 124 /*xstate.src_fd = STDIN_FILENO; - already is */
@@ -145,7 +132,7 @@ int FAST_FUNC bbunpack(char **argv,
145 xfunc_die(); 132 xfunc_die();
146 } 133 }
147 134
148 if (!(option_mask32 & OPT_STDOUT)) 135 if (!(option_mask32 & BBUNPK_OPT_STDOUT))
149 xclose(STDOUT_FILENO); /* with error check! */ 136 xclose(STDOUT_FILENO); /* with error check! */
150 137
151 if (filename) { 138 if (filename) {
@@ -176,7 +163,7 @@ int FAST_FUNC bbunpack(char **argv,
176 } 163 }
177 /* Extreme bloat for gunzip compat */ 164 /* Extreme bloat for gunzip compat */
178 /* Some users do want this info... */ 165 /* Some users do want this info... */
179 if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE)) { 166 if (ENABLE_DESKTOP && (option_mask32 & BBUNPK_OPT_VERBOSE)) {
180 unsigned percent = status 167 unsigned percent = status
181 ? ((uoff_t)stat_buf.st_size * 100u / (unsigned long long)status) 168 ? ((uoff_t)stat_buf.st_size * 100u / (unsigned long long)status)
182 : 0; 169 : 0;
@@ -188,7 +175,7 @@ int FAST_FUNC bbunpack(char **argv,
188 } 175 }
189 /* Delete _source_ file */ 176 /* Delete _source_ file */
190 del = filename; 177 del = filename;
191 if (option_mask32 & OPT_KEEP) /* ... unless -k */ 178 if (option_mask32 & BBUNPK_OPT_KEEP) /* ... unless -k */
192 del = NULL; 179 del = NULL;
193 } 180 }
194 if (del) 181 if (del)
@@ -199,7 +186,7 @@ int FAST_FUNC bbunpack(char **argv,
199 } 186 }
200 } while (*argv && *++argv); 187 } while (*argv && *++argv);
201 188
202 if (option_mask32 & OPT_STDOUT) 189 if (option_mask32 & BBUNPK_OPT_STDOUT)
203 xclose(STDOUT_FILENO); /* with error check! */ 190 xclose(STDOUT_FILENO); /* with error check! */
204 191
205 return exitcode; 192 return exitcode;
@@ -389,9 +376,9 @@ int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
389int gunzip_main(int argc UNUSED_PARAM, char **argv) 376int gunzip_main(int argc UNUSED_PARAM, char **argv)
390{ 377{
391#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS 378#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
392 getopt32long(argv, "cfkvqdtn", gunzip_longopts); 379 getopt32long(argv, BBUNPK_OPTSTR "dtn", gunzip_longopts);
393#else 380#else
394 getopt32(argv, "cfkvqdtn"); 381 getopt32(argv, BBUNPK_OPTSTR "dtn");
395#endif 382#endif
396 argv += optind; 383 argv += optind;
397 384
@@ -400,7 +387,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
400 * But if seamless magic is enabled, then we are much more clever. 387 * But if seamless magic is enabled, then we are much more clever.
401 */ 388 */
402 if (ENABLE_ZCAT && (!ENABLE_GUNZIP || applet_name[1] == 'c')) 389 if (ENABLE_ZCAT && (!ENABLE_GUNZIP || applet_name[1] == 'c'))
403 option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC; 390 option_mask32 |= BBUNPK_OPT_STDOUT | BBUNPK_SEAMLESS_MAGIC;
404 391
405 return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL); 392 return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
406} 393}
@@ -453,10 +440,10 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
453int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 440int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
454int bunzip2_main(int argc UNUSED_PARAM, char **argv) 441int bunzip2_main(int argc UNUSED_PARAM, char **argv)
455{ 442{
456 getopt32(argv, "cfkvqdt"); 443 getopt32(argv, BBUNPK_OPTSTR "dt");
457 argv += optind; 444 argv += optind;
458 if (ENABLE_BZCAT && (!ENABLE_BUNZIP2 || applet_name[2] == 'c')) /* bzcat */ 445 if (ENABLE_BZCAT && (!ENABLE_BUNZIP2 || applet_name[2] == 'c')) /* bzcat */
459 option_mask32 |= OPT_STDOUT; 446 option_mask32 |= BBUNPK_OPT_STDOUT;
460 447
461 return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2"); 448 return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
462} 449}
@@ -526,15 +513,15 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
526int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 513int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
527int unlzma_main(int argc UNUSED_PARAM, char **argv) 514int unlzma_main(int argc UNUSED_PARAM, char **argv)
528{ 515{
529 IF_LZMA(int opts =) getopt32(argv, "cfkvqdt"); 516 IF_LZMA(int opts =) getopt32(argv, BBUNPK_OPTSTR "dt");
530# if ENABLE_LZMA 517# if ENABLE_LZMA
531 /* lzma without -d or -t? */ 518 /* lzma without -d or -t? */
532 if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST))) 519 if (applet_name[2] == 'm' && !(opts & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)))
533 bb_show_usage(); 520 bb_show_usage();
534# endif 521# endif
535 /* lzcat? */ 522 /* lzcat? */
536 if (ENABLE_LZCAT && applet_name[2] == 'c') 523 if (ENABLE_LZCAT && applet_name[2] == 'c')
537 option_mask32 |= OPT_STDOUT; 524 option_mask32 |= BBUNPK_OPT_STDOUT;
538 525
539 argv += optind; 526 argv += optind;
540 return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma"); 527 return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
@@ -594,15 +581,15 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
594int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 581int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
595int unxz_main(int argc UNUSED_PARAM, char **argv) 582int unxz_main(int argc UNUSED_PARAM, char **argv)
596{ 583{
597 IF_XZ(int opts =) getopt32(argv, "cfkvqdt"); 584 IF_XZ(int opts =) getopt32(argv, BBUNPK_OPTSTR "dt");
598# if ENABLE_XZ 585# if ENABLE_XZ
599 /* xz without -d or -t? */ 586 /* xz without -d or -t? */
600 if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST))) 587 if (applet_name[2] == '\0' && !(opts & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)))
601 bb_show_usage(); 588 bb_show_usage();
602# endif 589# endif
603 /* xzcat? */ 590 /* xzcat? */
604 if (ENABLE_XZCAT && applet_name[2] == 'c') 591 if (ENABLE_XZCAT && applet_name[2] == 'c')
605 option_mask32 |= OPT_STDOUT; 592 option_mask32 |= BBUNPK_OPT_STDOUT;
606 593
607 argv += optind; 594 argv += optind;
608 return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz"); 595 return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
diff --git a/archival/bzip2.c b/archival/bzip2.c
index c3969a9e8..fa906150f 100644
--- a/archival/bzip2.c
+++ b/archival/bzip2.c
@@ -151,7 +151,8 @@ IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate U
151 151
152 iobuf = xmalloc(2 * IOBUF_SIZE); 152 iobuf = xmalloc(2 * IOBUF_SIZE);
153 153
154 opt = option_mask32 >> (sizeof("cfkvq" IF_FEATURE_BZIP2_DECOMPRESS("dt") "zs") - 1); 154 opt = option_mask32 >> (BBUNPK_OPTSTRLEN IF_FEATURE_BZIP2_DECOMPRESS(+ 2) + 2);
155 /* skipped BBUNPK_OPTSTR, "dt" and "zs" bits */
155 opt |= 0x100; /* if nothing else, assume -9 */ 156 opt |= 0x100; /* if nothing else, assume -9 */
156 level = 0; 157 level = 0;
157 for (;;) { 158 for (;;) {
@@ -205,17 +206,17 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
205 */ 206 */
206 207
207 opt = getopt32(argv, "^" 208 opt = getopt32(argv, "^"
208 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ 209 /* Must match BBUNPK_foo constants! */
209 "cfkvq" IF_FEATURE_BZIP2_DECOMPRESS("dt") "zs123456789" 210 BBUNPK_OPTSTR IF_FEATURE_BZIP2_DECOMPRESS("dt") "zs123456789"
210 "\0" "s2" /* -s means -2 (compatibility) */ 211 "\0" "s2" /* -s means -2 (compatibility) */
211 ); 212 );
212#if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */ 213#if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */
213 if (opt & (3 << 5)) /* -d and/or -t */ 214 if (opt & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)) /* -d and/or -t */
214 return bunzip2_main(argc, argv); 215 return bunzip2_main(argc, argv);
215#else 216#else
216 /* clear "decompress" and "test" bits (or bbunpack() can get confused) */ 217 /* clear "decompress" and "test" bits (or bbunpack() can get confused) */
217 /* in !BZIP2_DECOMPRESS config, these bits are -zs and are unused */ 218 /* in !BZIP2_DECOMPRESS config, these bits are -zs and are unused */
218 option_mask32 = opt & ~(3 << 5); 219 option_mask32 = opt & ~(BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST);
219#endif 220#endif
220 221
221 argv += optind; 222 argv += optind;
diff --git a/archival/gzip.c b/archival/gzip.c
index d6737b492..e3dd79291 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -2211,16 +2211,16 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
2211 2211
2212 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ 2212 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
2213#if ENABLE_FEATURE_GZIP_LONG_OPTIONS 2213#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
2214 opt = getopt32long(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789", gzip_longopts); 2214 opt = getopt32long(argv, BBUNPK_OPTSTR IF_FEATURE_GZIP_DECOMPRESS("dt") "n123456789", gzip_longopts);
2215#else 2215#else
2216 opt = getopt32(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789"); 2216 opt = getopt32(argv, BBUNPK_OPTSTR IF_FEATURE_GZIP_DECOMPRESS("dt") "n123456789");
2217#endif 2217#endif
2218#if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */ 2218#if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */
2219 if (opt & 0x30) // -d and/or -t 2219 if (opt & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)) /* -d and/or -t */
2220 return gunzip_main(argc, argv); 2220 return gunzip_main(argc, argv);
2221#endif 2221#endif
2222#if ENABLE_FEATURE_GZIP_LEVELS 2222#if ENABLE_FEATURE_GZIP_LEVELS
2223 opt >>= ENABLE_FEATURE_GZIP_DECOMPRESS ? 8 : 6; /* drop cfkv[dt]qn bits */ 2223 opt >>= (BBUNPK_OPTSTRLEN IF_FEATURE_GZIP_DECOMPRESS(+ 2) + 1); /* drop cfkvq[dt]n bits */
2224 if (opt == 0) 2224 if (opt == 0)
2225 opt = 1 << 6; /* default: 6 */ 2225 opt = 1 << 6; /* default: 6 */
2226 opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */ 2226 opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */
@@ -2229,7 +2229,7 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
2229 max_lazy_match = gzip_level_config[opt].lazy2 * 2; 2229 max_lazy_match = gzip_level_config[opt].lazy2 * 2;
2230 nice_match = gzip_level_config[opt].nice2 * 2; 2230 nice_match = gzip_level_config[opt].nice2 * 2;
2231#endif 2231#endif
2232 option_mask32 &= 0xf; /* retain only -cfkv */ 2232 option_mask32 &= BBUNPK_OPTSTRMASK; /* retain only -cfkvq */
2233 2233
2234 /* Allocate all global buffers (for DYN_ALLOC option) */ 2234 /* Allocate all global buffers (for DYN_ALLOC option) */
2235 ALLOC(uch, G1.l_buf, INBUFSIZ); 2235 ALLOC(uch, G1.l_buf, INBUFSIZ);
diff --git a/include/bb_archive.h b/include/bb_archive.h
index d3a02cf18..8ed20d70e 100644
--- a/include/bb_archive.h
+++ b/include/bb_archive.h
@@ -250,6 +250,21 @@ int bbunpack(char **argv,
250 char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext), 250 char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
251 const char *expected_ext 251 const char *expected_ext
252) FAST_FUNC; 252) FAST_FUNC;
253#define BBUNPK_OPTSTR "cfkvq"
254#define BBUNPK_OPTSTRLEN 5
255#define BBUNPK_OPTSTRMASK ((1 << BBUNPK_OPTSTRLEN) - 1)
256enum {
257 BBUNPK_OPT_STDOUT = 1 << 0,
258 BBUNPK_OPT_FORCE = 1 << 1,
259 /* only some decompressors: */
260 BBUNPK_OPT_KEEP = 1 << 2,
261 BBUNPK_OPT_VERBOSE = 1 << 3,
262 BBUNPK_OPT_QUIET = 1 << 4,
263 /* not included in BBUNPK_OPTSTR: */
264 BBUNPK_OPT_DECOMPRESS = 1 << 5,
265 BBUNPK_OPT_TEST = 1 << 6,
266 BBUNPK_SEAMLESS_MAGIC = (1 << 31) * ENABLE_ZCAT * SEAMLESS_COMPRESSION,
267};
253 268
254void check_errors_in_children(int signo); 269void check_errors_in_children(int signo);
255#if BB_MMU 270#if BB_MMU