Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/archival/gzip.c


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/gzip.c

    r3232 r3621  
    1616 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1717 */
    18 
    1918/* big objects in bss:
    2019 * 00000020 b bl_count
     
    3231 * 000008f4 b dyn_ltree
    3332 */
    34 
    3533/* TODO: full support for -v for DESKTOP
    3634 * "/usr/bin/gzip -v a bogus aa" should say:
     
    4038*/
    4139
     40//config:config GZIP
     41//config:   bool "gzip"
     42//config:   default y
     43//config:   help
     44//config:     gzip is used to compress files.
     45//config:     It's probably the most widely used UNIX compression program.
     46//config:
     47//config:config FEATURE_GZIP_LONG_OPTIONS
     48//config:   bool "Enable long options"
     49//config:   default y
     50//config:   depends on GZIP && LONG_OPTS
     51//config:   help
     52//config:     Enable use of long options, increases size by about 106 Bytes
     53//config:
     54//config:config GZIP_FAST
     55//config:   int "Trade memory for gzip speed (0:small,slow - 2:fast,big)"
     56//config:   default 0
     57//config:   range 0 2
     58//config:   depends on GZIP
     59//config:   help
     60//config:     Enable big memory options for gzip.
     61//config:     0: small buffers, small hash-tables
     62//config:     1: larger buffers, larger hash-tables
     63//config:     2: larger buffers, largest hash-tables
     64//config:     Larger models may give slightly better compression
     65//config:
     66//config:config FEATURE_GZIP_LEVELS
     67//config:   bool "Enable compression levels"
     68//config:   default n
     69//config:   depends on GZIP
     70//config:   help
     71//config:     Enable support for compression levels 4-9. The default level
     72//config:     is 6. If levels 1-3 are specified, 4 is used.
     73//config:     If this option is not selected, -N options are ignored and -9
     74//config:     is used.
     75
     76//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
     77//kbuild:lib-$(CONFIG_GZIP) += gzip.o
     78
    4279//usage:#define gzip_trivial_usage
    43 //usage:       "[-cfd] [FILE]..."
     80//usage:       "[-cf" IF_GUNZIP("d") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
    4481//usage:#define gzip_full_usage "\n\n"
    4582//usage:       "Compress FILEs (or stdin)\n"
     83//usage:    IF_FEATURE_GZIP_LEVELS(
     84//usage:     "\n    -1..9   Compression level"
     85//usage:    )
     86//usage:    IF_GUNZIP(
    4687//usage:     "\n    -d  Decompress"
     88//usage:    )
    4789//usage:     "\n    -c  Write to stdout"
    4890//usage:     "\n    -f  Force"
     
    226268 */
    227269
     270#ifndef ENABLE_FEATURE_GZIP_LEVELS
     271
    228272    max_chain_length = 4096,
    229273/* To speed up deflation, hash chains are never searched beyond this length.
     
    257301 * meaning.
    258302 */
     303#endif /* ENABLE_FEATURE_GZIP_LEVELS */
    259304};
    260305
    261306
    262307struct globals {
     308
     309#ifdef ENABLE_FEATURE_GZIP_LEVELS
     310    unsigned max_chain_length;
     311    unsigned max_lazy_match;
     312    unsigned good_match;
     313    unsigned nice_match;
     314#define max_chain_length (G1.max_chain_length)
     315#define max_lazy_match   (G1.max_lazy_match)
     316#define good_match   (G1.good_match)
     317#define nice_match   (G1.nice_match)
     318#endif
    263319
    264320    lng block_start;
     
    391447do { \
    392448    G1.outbuf[G1.outcnt++] = (c); \
    393     if (G1.outcnt == OUTBUFSIZ) flush_outbuf(); \
     449    if (G1.outcnt == OUTBUFSIZ) \
     450        flush_outbuf(); \
    394451} while (0)
    395452
     
    397454static void put_16bit(ush w)
    398455{
    399     if (G1.outcnt < OUTBUFSIZ - 2) {
    400         G1.outbuf[G1.outcnt++] = w;
    401         G1.outbuf[G1.outcnt++] = w >> 8;
    402     } else {
    403         put_8bit(w);
    404         put_8bit(w >> 8);
    405     }
     456    /* GCC 4.2.1 won't optimize out redundant loads of G1.outcnt
     457     * (probably because of fear of aliasing with G1.outbuf[]
     458     * stores), do it explicitly:
     459     */
     460    unsigned outcnt = G1.outcnt;
     461    uch *dst = &G1.outbuf[outcnt];
     462
     463#if BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN
     464    if (outcnt < OUTBUFSIZ-2) {
     465        /* Common case */
     466        ush *dst16 = (void*) dst;
     467        *dst16 = w; /* unalinged LSB 16-bit store */
     468        G1.outcnt = outcnt + 2;
     469        return;
     470    }
     471    *dst = (uch)w;
     472    w >>= 8;
     473#else
     474    *dst = (uch)w;
     475    w >>= 8;
     476    if (outcnt < OUTBUFSIZ-2) {
     477        /* Common case */
     478        dst[1] = w;
     479        G1.outcnt = outcnt + 2;
     480        return;
     481    }
     482#endif
     483
     484    /* Slowpath: we will need to do flush_outbuf() */
     485    G1.outcnt = ++outcnt;
     486    if (outcnt == OUTBUFSIZ)
     487        flush_outbuf();
     488    put_8bit(w);
    406489}
    407490
     
    12921375        G2.heap[SMALLEST] = node++;
    12931376        pqdownheap(tree, SMALLEST);
    1294 
    12951377    } while (G2.heap_len >= 2);
    12961378
     
    16401722        copy_block(buf, (unsigned) stored_len, 0);  /* without header */
    16411723        G2.compressed_len = stored_len << 3;
    1642 
    16431724    } else if (stored_len + 4 <= opt_lenb && buf != NULL) {
    16441725        /* 4: two words for the lengths */
     
    16541735
    16551736        copy_block(buf, (unsigned) stored_len, 1);  /* with header */
    1656 
    16571737    } else if (static_lenb == opt_lenb) {
    16581738        send_bits((STATIC_TREES << 1) + eof, 3);
     
    19812061 */
    19822062
    1983 static void zip(ulg time_stamp)
     2063static void zip(void)
    19842064{
    19852065    ush deflate_flags = 0;  /* pkzip -es, -en or -ex equivalent */
     
    19922072    /* general flags: 0 */
    19932073    put_32bit(0x00088b1f);
    1994     put_32bit(time_stamp);
     2074    put_32bit(0);       /* Unix timestamp */
    19952075
    19962076    /* Write deflated file to zip file */
     
    20162096/* ======================================================================== */
    20172097static
    2018 IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_aux_data_t *aux UNUSED_PARAM)
    2019 {
    2020     struct stat s;
    2021 
     2098IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM)
     2099{
    20222100    /* Clear input and output buffers */
    20232101    G1.outcnt = 0;
     
    20512129    //G2.bl_desc.max_code    = 0;
    20522130
     2131#if 0
     2132    /* Saving of timestamp is disabled. Why?
     2133     * - it is not Y2038-safe.
     2134     * - some people want deterministic results
     2135     *   (normally they'd use -n, but our -n is a nop).
     2136     * - it's bloat.
     2137     * Per RFC 1952, gzfile.time=0 is "no timestamp".
     2138     * If users will demand this to be reinstated,
     2139     * implement -n "don't save timestamp".
     2140     */
     2141    struct stat s;
    20532142    s.st_ctime = 0;
    20542143    fstat(STDIN_FILENO, &s);
    20552144    zip(s.st_ctime);
     2145#else
     2146    zip();
     2147#endif
    20562148    return 0;
    20572149}
     
    20712163    "fast\0"                No_argument       "1"
    20722164    "best\0"                No_argument       "9"
     2165    "no-name\0"             No_argument       "n"
    20732166    ;
    20742167#endif
     
    20962189{
    20972190    unsigned opt;
     2191#ifdef ENABLE_FEATURE_GZIP_LEVELS
     2192    static const struct {
     2193        uint8_t good;
     2194        uint8_t chain_shift;
     2195        uint8_t lazy2;
     2196        uint8_t nice2;
     2197    } gzip_level_config[6] = {
     2198        {4,   4,   4/2,  16/2}, /* Level 4 */
     2199        {8,   5,  16/2,  32/2}, /* Level 5 */
     2200        {8,   7,  16/2, 128/2}, /* Level 6 */
     2201        {8,   8,  32/2, 128/2}, /* Level 7 */
     2202        {32, 10, 128/2, 258/2}, /* Level 8 */
     2203        {32, 12, 258/2, 258/2}, /* Level 9 */
     2204    };
     2205#endif
     2206
     2207    SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
     2208            + sizeof(struct globals));
    20982209
    20992210#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
     
    21012212#endif
    21022213    /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
    2103     opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "q123456789n");
     2214    opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "qn123456789");
    21042215#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
    21052216    if (opt & 0x18) // -d and/or -t
    21062217        return gunzip_main(argc, argv);
    21072218#endif
    2108     option_mask32 &= 0x7; /* ignore -q, -0..9 */
    2109     //if (opt & 0x1) // -c
    2110     //if (opt & 0x2) // -f
    2111     //if (opt & 0x4) // -v
    2112     argv += optind;
    2113 
    2114     SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
    2115             + sizeof(struct globals));
     2219#ifdef ENABLE_FEATURE_GZIP_LEVELS
     2220    opt >>= ENABLE_GUNZIP ? 7 : 5; /* drop cfv[dt]qn bits */
     2221    if (opt == 0)
     2222        opt = 1 << 6; /* default: 6 */
     2223    opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */
     2224    max_chain_length = 1 << gzip_level_config[opt].chain_shift;
     2225    good_match   = gzip_level_config[opt].good;
     2226    max_lazy_match   = gzip_level_config[opt].lazy2 * 2;
     2227    nice_match   = gzip_level_config[opt].nice2 * 2;
     2228#endif
     2229    option_mask32 &= 0x7; /* retain only -cfv */
    21162230
    21172231    /* Allocate all global buffers (for DYN_ALLOC option) */
     
    21252239    global_crc32_table = crc32_filltable(NULL, 0);
    21262240
     2241    argv += optind;
    21272242    return bbunpack(argv, pack_gzip, append_ext, "gz");
    21282243}
Note: See TracChangeset for help on using the changeset viewer.