Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/archival/bbunzip.c

    r3232 r3621  
    88#include "bb_archive.h"
    99
     10/* lzop_main() uses bbunpack(), need this: */
     11//kbuild:lib-$(CONFIG_LZOP) += bbunzip.o
     12
     13/* Note: must be kept in sync with archival/lzop.c */
    1014enum {
    1115    OPT_STDOUT     = 1 << 0,
     
    1317    /* only some decompressors: */
    1418    OPT_VERBOSE    = 1 << 2,
    15     OPT_DECOMPRESS = 1 << 3,
    16     OPT_TEST       = 1 << 4,
     19    OPT_QUIET      = 1 << 3,
     20    OPT_DECOMPRESS = 1 << 4,
     21    OPT_TEST       = 1 << 5,
     22    SEAMLESS_MAGIC = (1 << 31) * SEAMLESS_COMPRESSION,
    1723};
    1824
     
    3440
    3541int FAST_FUNC bbunpack(char **argv,
    36     IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
     42    IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_state_t *xstate),
    3743    char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
    3844    const char *expected_ext
     
    4046{
    4147    struct stat stat_buf;
    42     IF_DESKTOP(long long) int status;
     48    IF_DESKTOP(long long) int status = 0;
    4349    char *filename, *new_name;
    4450    smallint exitcode = 0;
    45     transformer_aux_data_t aux;
     51    transformer_state_t xstate;
    4652
    4753    do {
     
    5561        /* Open src */
    5662        if (filename) {
    57             if (stat(filename, &stat_buf) != 0) {
    58                 bb_simple_perror_msg(filename);
     63            if (!(option_mask32 & SEAMLESS_MAGIC)) {
     64                if (stat(filename, &stat_buf) != 0) {
     65 err_name:
     66                    bb_simple_perror_msg(filename);
    5967 err:
    60                 exitcode = 1;
    61                 goto free_name;
     68                    exitcode = 1;
     69                    goto free_name;
     70                }
     71                if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0))
     72                    goto err;
     73            } else {
     74                /* "clever zcat" with FILE */
     75                /* fail_if_not_compressed because zcat refuses uncompressed input */
     76                int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1);
     77                if (fd < 0)
     78                    goto err_name;
     79                xmove_fd(fd, STDIN_FILENO);
    6280            }
    63             if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0))
     81        } else
     82        if (option_mask32 & SEAMLESS_MAGIC) {
     83            /* "clever zcat" on stdin */
     84            if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
    6485                goto err;
    6586        }
     
    6990            if (option_mask32 & OPT_TEST)
    7091                if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0))
    71                     goto err;
     92                    xfunc_die();
    7293            filename = NULL;
    7394        }
     
    94115
    95116        /* Check that the input is sane */
    96         if (isatty(STDIN_FILENO) && (option_mask32 & OPT_FORCE) == 0) {
     117        if (!(option_mask32 & OPT_FORCE) && isatty(STDIN_FILENO)) {
    97118            bb_error_msg_and_die("compressed data not read from terminal, "
    98119                    "use -f to force it");
    99120        }
    100121
    101         init_transformer_aux_data(&aux);
    102         aux.check_signature = 1;
    103         status = unpacker(&aux);
    104         if (status < 0)
    105             exitcode = 1;
     122        if (!(option_mask32 & SEAMLESS_MAGIC)) {
     123            init_transformer_state(&xstate);
     124            xstate.signature_skipped = 0;
     125            /*xstate.src_fd = STDIN_FILENO; - already is */
     126            xstate.dst_fd = STDOUT_FILENO;
     127            status = unpacker(&xstate);
     128            if (status < 0)
     129                exitcode = 1;
     130        } else {
     131            if (bb_copyfd_eof(STDIN_FILENO, STDOUT_FILENO) < 0)
     132                /* Disk full, tty closed, etc. No point in continuing */
     133                xfunc_die();
     134        }
    106135
    107136        if (!(option_mask32 & OPT_STDOUT))
     
    110139        if (filename) {
    111140            char *del = new_name;
     141
    112142            if (status >= 0) {
     143                unsigned new_name_len;
     144
    113145                /* TODO: restore other things? */
    114                 if (aux.mtime != 0) {
     146                if (xstate.mtime != 0) {
    115147                    struct timeval times[2];
    116148
    117                     times[1].tv_sec = times[0].tv_sec = aux.mtime;
     149                    times[1].tv_sec = times[0].tv_sec = xstate.mtime;
    118150                    times[1].tv_usec = times[0].tv_usec = 0;
    119151                    /* Note: we closed it first.
     
    124156                }
    125157
    126                 /* Delete _compressed_ file */
     158                if (ENABLE_DESKTOP)
     159                    new_name_len = strlen(new_name);
     160                /* Restore source filename (unless tgz -> tar case) */
     161                if (new_name == filename) {
     162                    new_name_len = strlen(filename);
     163                    filename[new_name_len] = '.';
     164                }
     165                /* Extreme bloat for gunzip compat */
     166                /* Some users do want this info... */
     167                if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE)) {
     168                    unsigned percent = status
     169                        ? ((uoff_t)stat_buf.st_size * 100u / (unsigned long long)status)
     170                        : 0;
     171                    fprintf(stderr, "%s: %u%% - replaced with %.*s\n",
     172                        filename,
     173                        100u - percent,
     174                        new_name_len, new_name
     175                    );
     176                }
     177                /* Delete _source_ file */
    127178                del = filename;
    128                 /* restore extension (unless tgz -> tar case) */
    129                 if (new_name == filename)
    130                     filename[strlen(filename)] = '.';
    131179            }
    132180            xunlink(del);
    133 
    134 #if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */
    135             /* Extreme bloat for gunzip compat */
    136             if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE) && status >= 0) {
    137                 fprintf(stderr, "%s: %u%% - replaced with %s\n",
    138                     filename, (unsigned)(stat_buf.st_size*100 / (status+1)), new_name);
    139             }
    140 #endif
    141 
    142181 free_name:
    143182            if (new_name != filename)
     
    173212 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    174213 */
    175 
    176214//usage:#define uncompress_trivial_usage
    177215//usage:       "[-cf] [FILE]..."
     
    181219//usage:     "\n    -f  Overwrite"
    182220
     221//config:config UNCOMPRESS
     222//config:   bool "uncompress"
     223//config:   default n  # ancient
     224//config:   help
     225//config:     uncompress is used to decompress archives created by compress.
     226//config:     Not much used anymore, replaced by gzip/gunzip.
     227
     228//applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP))
     229//kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
    183230#if ENABLE_UNCOMPRESS
    184 static
    185 IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux)
    186 {
    187     return unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);
    188 }
    189231int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    190232int uncompress_main(int argc UNUSED_PARAM, char **argv)
     
    193235    argv += optind;
    194236
    195     return bbunpack(argv, unpack_uncompress, make_new_name_generic, "Z");
     237    return bbunpack(argv, unpack_Z_stream, make_new_name_generic, "Z");
    196238}
    197239#endif
     
    221263 * written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies,
    222264 * Ken Turkowski, Dave Mack and Peter Jannesen.
    223  *
    224  * See the license_msg below and the file COPYING for the software license.
    225  * See the file algorithm.doc for the compression algorithms and file formats.
    226265 */
    227 
    228266//usage:#define gunzip_trivial_usage
    229267//usage:       "[-cft] [FILE]..."
     
    242280//usage:
    243281//usage:#define zcat_trivial_usage
    244 //usage:       "FILE"
     282//usage:       "[FILE]..."
    245283//usage:#define zcat_full_usage "\n\n"
    246284//usage:       "Decompress to stdout"
    247285
     286//config:config GUNZIP
     287//config:   bool "gunzip"
     288//config:   default y
     289//config:   help
     290//config:     gunzip is used to decompress archives created by gzip.
     291//config:     You can use the `-t' option to test the integrity of
     292//config:     an archive, without decompressing it.
     293//config:
     294//config:config FEATURE_GUNZIP_LONG_OPTIONS
     295//config:   bool "Enable long options"
     296//config:   default y
     297//config:   depends on GUNZIP && LONG_OPTS
     298//config:   help
     299//config:     Enable use of long options.
     300
     301//applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
     302//applet:IF_GUNZIP(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat))
     303//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o
     304//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
    248305#if ENABLE_GUNZIP
    249306static
     
    272329    return filename;
    273330}
    274 static
    275 IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux)
    276 {
    277     return unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
    278 }
     331
     332#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
     333static const char gunzip_longopts[] ALIGN1 =
     334    "stdout\0"              No_argument       "c"
     335    "to-stdout\0"           No_argument       "c"
     336    "force\0"               No_argument       "f"
     337    "test\0"                No_argument       "t"
     338    "no-name\0"             No_argument       "n"
     339    ;
     340#endif
     341
    279342/*
    280343 * Linux kernel build uses gzip -d -n. We accept and ignore it.
     
    293356int gunzip_main(int argc UNUSED_PARAM, char **argv)
    294357{
    295     getopt32(argv, "cfvdtn");
     358#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
     359    applet_long_options = gunzip_longopts;
     360#endif
     361    getopt32(argv, "cfvqdtn");
    296362    argv += optind;
    297     /* if called as zcat */
     363
     364    /* If called as zcat...
     365     * Normally, "zcat" is just "gunzip -c".
     366     * But if seamless magic is enabled, then we are much more clever.
     367     */
    298368    if (applet_name[1] == 'c')
    299         option_mask32 |= OPT_STDOUT;
    300 
    301     return bbunpack(argv, unpack_gunzip, make_new_name_gunzip, /*unused:*/ NULL);
     369        option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
     370
     371    return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
    302372}
    303373#endif
     
    317387//usage:     "\n    -f  Force"
    318388//usage:#define bzcat_trivial_usage
    319 //usage:       "FILE"
     389//usage:       "[FILE]..."
    320390//usage:#define bzcat_full_usage "\n\n"
    321391//usage:       "Decompress to stdout"
     392
     393//config:config BUNZIP2
     394//config:   bool "bunzip2"
     395//config:   default y
     396//config:   help
     397//config:     bunzip2 is a compression utility using the Burrows-Wheeler block
     398//config:     sorting text compression algorithm, and Huffman coding. Compression
     399//config:     is generally considerably better than that achieved by more
     400//config:     conventional LZ77/LZ78-based compressors, and approaches the
     401//config:     performance of the PPM family of statistical compressors.
     402//config:
     403//config:     Unless you have a specific application which requires bunzip2, you
     404//config:     should probably say N here.
     405
    322406//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
    323407//applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
     408//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
     409//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
    324410#if ENABLE_BUNZIP2
    325 static
    326 IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)
    327 {
    328     return unpack_bz2_stream(aux, STDIN_FILENO, STDOUT_FILENO);
    329 }
    330411int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    331412int bunzip2_main(int argc UNUSED_PARAM, char **argv)
    332413{
    333     getopt32(argv, "cfvdt");
     414    getopt32(argv, "cfvqdt");
    334415    argv += optind;
    335416    if (applet_name[2] == 'c') /* bzcat */
    336417        option_mask32 |= OPT_STDOUT;
    337418
    338     return bbunpack(argv, unpack_bunzip2, make_new_name_generic, "bz2");
     419    return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
    339420}
    340421#endif
     
    349430 * Licensed under GPLv2, see file LICENSE in this source tree.
    350431 */
    351 
    352432//usage:#define unlzma_trivial_usage
    353433//usage:       "[-cf] [FILE]..."
     
    366446//usage:
    367447//usage:#define lzcat_trivial_usage
    368 //usage:       "FILE"
     448//usage:       "[FILE]..."
    369449//usage:#define lzcat_full_usage "\n\n"
    370450//usage:       "Decompress to stdout"
     
    386466//usage:
    387467//usage:#define xzcat_trivial_usage
    388 //usage:       "FILE"
     468//usage:       "[FILE]..."
    389469//usage:#define xzcat_full_usage "\n\n"
    390470//usage:       "Decompress to stdout"
    391471
     472//config:config UNLZMA
     473//config:   bool "unlzma"
     474//config:   default y
     475//config:   help
     476//config:     unlzma is a compression utility using the Lempel-Ziv-Markov chain
     477//config:     compression algorithm, and range coding. Compression
     478//config:     is generally considerably better than that achieved by the bzip2
     479//config:     compressors.
     480//config:
     481//config:     The BusyBox unlzma applet is limited to decompression only.
     482//config:     On an x86 system, this applet adds about 4K.
     483//config:
     484//config:config FEATURE_LZMA_FAST
     485//config:   bool "Optimize unlzma for speed"
     486//config:   default n
     487//config:   depends on UNLZMA
     488//config:   help
     489//config:     This option reduces decompression time by about 25% at the cost of
     490//config:     a 1K bigger binary.
     491//config:
     492//config:config LZMA
     493//config:   bool "Provide lzma alias which supports only unpacking"
     494//config:   default y
     495//config:   depends on UNLZMA
     496//config:   help
     497//config:     Enable this option if you want commands like "lzma -d" to work.
     498//config:     IOW: you'll get lzma applet, but it will always require -d option.
     499
     500//applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP))
     501//applet:IF_UNLZMA(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat))
     502//applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
     503//kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o
    392504#if ENABLE_UNLZMA
    393 static
    394 IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)
    395 {
    396     return unpack_lzma_stream(aux, STDIN_FILENO, STDOUT_FILENO);
    397 }
    398505int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    399506int unlzma_main(int argc UNUSED_PARAM, char **argv)
    400507{
    401     IF_LZMA(int opts =) getopt32(argv, "cfvdt");
     508    IF_LZMA(int opts =) getopt32(argv, "cfvqdt");
    402509# if ENABLE_LZMA
    403510    /* lzma without -d or -t? */
     
    410517
    411518    argv += optind;
    412     return bbunpack(argv, unpack_unlzma, make_new_name_generic, "lzma");
    413 }
    414 #endif
    415 
    416 
     519    return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
     520}
     521#endif
     522
     523
     524//config:config UNXZ
     525//config:   bool "unxz"
     526//config:   default y
     527//config:   help
     528//config:     unxz is a unlzma successor.
     529//config:
     530//config:config XZ
     531//config:   bool "Provide xz alias which supports only unpacking"
     532//config:   default y
     533//config:   depends on UNXZ
     534//config:   help
     535//config:     Enable this option if you want commands like "xz -d" to work.
     536//config:     IOW: you'll get xz applet, but it will always require -d option.
     537
     538//applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP))
     539//applet:IF_UNXZ(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat))
     540//applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
     541//kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o
    417542#if ENABLE_UNXZ
    418 static
    419 IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)
    420 {
    421     return unpack_xz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
    422 }
    423543int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    424544int unxz_main(int argc UNUSED_PARAM, char **argv)
    425545{
    426     IF_XZ(int opts =) getopt32(argv, "cfvdt");
     546    IF_XZ(int opts =) getopt32(argv, "cfvqdt");
    427547# if ENABLE_XZ
    428548    /* xz without -d or -t? */
     
    435555
    436556    argv += optind;
    437     return bbunpack(argv, unpack_unxz, make_new_name_generic, "xz");
    438 }
    439 #endif
     557    return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
     558}
     559#endif
Note: See TracChangeset for help on using the changeset viewer.