diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-01 09:13:14 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-01 09:13:14 +0100 |
commit | d6f0f03b68fc4cf9ffb8006e192e36f0ebf51ea6 (patch) | |
tree | 24b4adf0a28b91dbcd014cf99527ca07d492003d | |
parent | 99ac1759dd429bd7995feff33dc683589c016c8e (diff) |
libarchive: move bbunpack constants to bb_archive.h
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/bbunzip.c | 57 | ||||
-rw-r--r-- | archival/bzip2.c | 11 | ||||
-rw-r--r-- | archival/gzip.c | 10 | ||||
-rw-r--r-- | include/bb_archive.h | 15 |
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 @@ #include "libbb.h" #include "bb_archive.h" -/* Note: must be kept in sync with archival/lzop.c */ -enum { - OPT_STDOUT = 1 << 0, - OPT_FORCE = 1 << 1, - /* only some decompressors: */ - OPT_KEEP = 1 << 2, - OPT_VERBOSE = 1 << 3, - OPT_QUIET = 1 << 4, - OPT_DECOMPRESS = 1 << 5, - OPT_TEST = 1 << 6, - SEAMLESS_MAGIC = (1 << 31) * ENABLE_ZCAT * SEAMLESS_COMPRESSION, -}; - static int open_to_or_warn(int to_fd, const char *filename, int flags, int mode) { @@ -72,7 +59,7 @@ int FAST_FUNC bbunpack(char **argv, /* Open src */ if (filename) { - if (!(option_mask32 & SEAMLESS_MAGIC)) { + if (!(option_mask32 & BBUNPK_SEAMLESS_MAGIC)) { if (stat(filename, &stat_buf) != 0) { err_name: bb_simple_perror_msg(filename); @@ -91,15 +78,15 @@ int FAST_FUNC bbunpack(char **argv, xmove_fd(fd, STDIN_FILENO); } } else - if (option_mask32 & SEAMLESS_MAGIC) { + if (option_mask32 & BBUNPK_SEAMLESS_MAGIC) { /* "clever zcat" on stdin */ if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1)) goto err; } /* Special cases: test, stdout */ - if (option_mask32 & (OPT_STDOUT|OPT_TEST)) { - if (option_mask32 & OPT_TEST) + if (option_mask32 & (BBUNPK_OPT_STDOUT|BBUNPK_OPT_TEST)) { + if (option_mask32 & BBUNPK_OPT_TEST) if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0)) xfunc_die(); filename = NULL; @@ -114,7 +101,7 @@ int FAST_FUNC bbunpack(char **argv, } /* -f: overwrite existing output files */ - if (option_mask32 & OPT_FORCE) { + if (option_mask32 & BBUNPK_OPT_FORCE) { unlink(new_name); } @@ -126,12 +113,12 @@ int FAST_FUNC bbunpack(char **argv, } /* Check that the input is sane */ - if (!(option_mask32 & OPT_FORCE) && isatty(STDIN_FILENO)) { + if (!(option_mask32 & BBUNPK_OPT_FORCE) && isatty(STDIN_FILENO)) { bb_error_msg_and_die("compressed data not read from terminal, " "use -f to force it"); } - if (!(option_mask32 & SEAMLESS_MAGIC)) { + if (!(option_mask32 & BBUNPK_SEAMLESS_MAGIC)) { init_transformer_state(&xstate); /*xstate.signature_skipped = 0; - already is */ /*xstate.src_fd = STDIN_FILENO; - already is */ @@ -145,7 +132,7 @@ int FAST_FUNC bbunpack(char **argv, xfunc_die(); } - if (!(option_mask32 & OPT_STDOUT)) + if (!(option_mask32 & BBUNPK_OPT_STDOUT)) xclose(STDOUT_FILENO); /* with error check! */ if (filename) { @@ -176,7 +163,7 @@ int FAST_FUNC bbunpack(char **argv, } /* Extreme bloat for gunzip compat */ /* Some users do want this info... */ - if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE)) { + if (ENABLE_DESKTOP && (option_mask32 & BBUNPK_OPT_VERBOSE)) { unsigned percent = status ? ((uoff_t)stat_buf.st_size * 100u / (unsigned long long)status) : 0; @@ -188,7 +175,7 @@ int FAST_FUNC bbunpack(char **argv, } /* Delete _source_ file */ del = filename; - if (option_mask32 & OPT_KEEP) /* ... unless -k */ + if (option_mask32 & BBUNPK_OPT_KEEP) /* ... unless -k */ del = NULL; } if (del) @@ -199,7 +186,7 @@ int FAST_FUNC bbunpack(char **argv, } } while (*argv && *++argv); - if (option_mask32 & OPT_STDOUT) + if (option_mask32 & BBUNPK_OPT_STDOUT) xclose(STDOUT_FILENO); /* with error check! */ return exitcode; @@ -389,9 +376,9 @@ int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int gunzip_main(int argc UNUSED_PARAM, char **argv) { #if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS - getopt32long(argv, "cfkvqdtn", gunzip_longopts); + getopt32long(argv, BBUNPK_OPTSTR "dtn", gunzip_longopts); #else - getopt32(argv, "cfkvqdtn"); + getopt32(argv, BBUNPK_OPTSTR "dtn"); #endif argv += optind; @@ -400,7 +387,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv) * But if seamless magic is enabled, then we are much more clever. */ if (ENABLE_ZCAT && (!ENABLE_GUNZIP || applet_name[1] == 'c')) - option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC; + option_mask32 |= BBUNPK_OPT_STDOUT | BBUNPK_SEAMLESS_MAGIC; return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL); } @@ -453,10 +440,10 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv) int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int bunzip2_main(int argc UNUSED_PARAM, char **argv) { - getopt32(argv, "cfkvqdt"); + getopt32(argv, BBUNPK_OPTSTR "dt"); argv += optind; if (ENABLE_BZCAT && (!ENABLE_BUNZIP2 || applet_name[2] == 'c')) /* bzcat */ - option_mask32 |= OPT_STDOUT; + option_mask32 |= BBUNPK_OPT_STDOUT; return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2"); } @@ -526,15 +513,15 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv) int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int unlzma_main(int argc UNUSED_PARAM, char **argv) { - IF_LZMA(int opts =) getopt32(argv, "cfkvqdt"); + IF_LZMA(int opts =) getopt32(argv, BBUNPK_OPTSTR "dt"); # if ENABLE_LZMA /* lzma without -d or -t? */ - if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST))) + if (applet_name[2] == 'm' && !(opts & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST))) bb_show_usage(); # endif /* lzcat? */ if (ENABLE_LZCAT && applet_name[2] == 'c') - option_mask32 |= OPT_STDOUT; + option_mask32 |= BBUNPK_OPT_STDOUT; argv += optind; return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma"); @@ -594,15 +581,15 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv) int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int unxz_main(int argc UNUSED_PARAM, char **argv) { - IF_XZ(int opts =) getopt32(argv, "cfkvqdt"); + IF_XZ(int opts =) getopt32(argv, BBUNPK_OPTSTR "dt"); # if ENABLE_XZ /* xz without -d or -t? */ - if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST))) + if (applet_name[2] == '\0' && !(opts & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST))) bb_show_usage(); # endif /* xzcat? */ if (ENABLE_XZCAT && applet_name[2] == 'c') - option_mask32 |= OPT_STDOUT; + option_mask32 |= BBUNPK_OPT_STDOUT; argv += optind; 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 iobuf = xmalloc(2 * IOBUF_SIZE); - opt = option_mask32 >> (sizeof("cfkvq" IF_FEATURE_BZIP2_DECOMPRESS("dt") "zs") - 1); + opt = option_mask32 >> (BBUNPK_OPTSTRLEN IF_FEATURE_BZIP2_DECOMPRESS(+ 2) + 2); + /* skipped BBUNPK_OPTSTR, "dt" and "zs" bits */ opt |= 0x100; /* if nothing else, assume -9 */ level = 0; for (;;) { @@ -205,17 +206,17 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv) */ opt = getopt32(argv, "^" - /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ - "cfkvq" IF_FEATURE_BZIP2_DECOMPRESS("dt") "zs123456789" + /* Must match BBUNPK_foo constants! */ + BBUNPK_OPTSTR IF_FEATURE_BZIP2_DECOMPRESS("dt") "zs123456789" "\0" "s2" /* -s means -2 (compatibility) */ ); #if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */ - if (opt & (3 << 5)) /* -d and/or -t */ + if (opt & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)) /* -d and/or -t */ return bunzip2_main(argc, argv); #else /* clear "decompress" and "test" bits (or bbunpack() can get confused) */ /* in !BZIP2_DECOMPRESS config, these bits are -zs and are unused */ - option_mask32 = opt & ~(3 << 5); + option_mask32 = opt & ~(BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST); #endif 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) /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ #if ENABLE_FEATURE_GZIP_LONG_OPTIONS - opt = getopt32long(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789", gzip_longopts); + opt = getopt32long(argv, BBUNPK_OPTSTR IF_FEATURE_GZIP_DECOMPRESS("dt") "n123456789", gzip_longopts); #else - opt = getopt32(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789"); + opt = getopt32(argv, BBUNPK_OPTSTR IF_FEATURE_GZIP_DECOMPRESS("dt") "n123456789"); #endif #if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */ - if (opt & 0x30) // -d and/or -t + if (opt & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)) /* -d and/or -t */ return gunzip_main(argc, argv); #endif #if ENABLE_FEATURE_GZIP_LEVELS - opt >>= ENABLE_FEATURE_GZIP_DECOMPRESS ? 8 : 6; /* drop cfkv[dt]qn bits */ + opt >>= (BBUNPK_OPTSTRLEN IF_FEATURE_GZIP_DECOMPRESS(+ 2) + 1); /* drop cfkvq[dt]n bits */ if (opt == 0) opt = 1 << 6; /* default: 6 */ 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) max_lazy_match = gzip_level_config[opt].lazy2 * 2; nice_match = gzip_level_config[opt].nice2 * 2; #endif - option_mask32 &= 0xf; /* retain only -cfkv */ + option_mask32 &= BBUNPK_OPTSTRMASK; /* retain only -cfkvq */ /* Allocate all global buffers (for DYN_ALLOC option) */ 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, char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext), const char *expected_ext ) FAST_FUNC; +#define BBUNPK_OPTSTR "cfkvq" +#define BBUNPK_OPTSTRLEN 5 +#define BBUNPK_OPTSTRMASK ((1 << BBUNPK_OPTSTRLEN) - 1) +enum { + BBUNPK_OPT_STDOUT = 1 << 0, + BBUNPK_OPT_FORCE = 1 << 1, + /* only some decompressors: */ + BBUNPK_OPT_KEEP = 1 << 2, + BBUNPK_OPT_VERBOSE = 1 << 3, + BBUNPK_OPT_QUIET = 1 << 4, + /* not included in BBUNPK_OPTSTR: */ + BBUNPK_OPT_DECOMPRESS = 1 << 5, + BBUNPK_OPT_TEST = 1 << 6, + BBUNPK_SEAMLESS_MAGIC = (1 << 31) * ENABLE_ZCAT * SEAMLESS_COMPRESSION, +}; void check_errors_in_children(int signo); #if BB_MMU |