Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/archival/gzip.c


Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/archival/gzip.c

    r1765 r2725  
    1414 * command line handling.
    1515 *
    16  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     16 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1717 */
    1818
     
    4141
    4242#include "libbb.h"
     43#include "archive.h"
    4344
    4445
     
    6869#define SMALL_MEM
    6970
    70 #ifndef INBUFSIZ
     71#ifndef INBUFSIZ
    7172#  ifdef SMALL_MEM
    7273#    define INBUFSIZ  0x2000    /* input buffer size */
     
    7677#endif
    7778
    78 #ifndef OUTBUFSIZ
     79#ifndef OUTBUFSIZ
    7980#  ifdef SMALL_MEM
    8081#    define OUTBUFSIZ   8192    /* output buffer size */
     
    267268    type * array
    268269#define ALLOC(type, array, size) \
    269     array = xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type));
     270    array = xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type))
    270271#define FREE(array) \
    271272    do { free(array); array = NULL; } while (0)
     
    340341#endif
    341342
    342     uint32_t *crc_32_tab;
     343    /*uint32_t *crc_32_tab;*/
    343344    uint32_t crc;   /* shift register contents */
    344345};
     
    389390
    390391/* ===========================================================================
    391  * Clear input and output buffers
    392  */
    393 static void clear_bufs(void)
    394 {
    395     G1.outcnt = 0;
    396 #ifdef DEBUG
    397     G1.insize = 0;
    398 #endif
    399     G1.isize = 0;
    400 }
    401 
    402 
    403 /* ===========================================================================
    404392 * Run a set of bytes through the crc shift register.  If s is a NULL
    405393 * pointer, then initialize the crc shift register contents instead.
    406394 * Return the current crc in either case.
    407395 */
    408 static uint32_t updcrc(uch * s, unsigned n)
    409 {
    410     uint32_t c = G1.crc;
    411     while (n) {
    412         c = G1.crc_32_tab[(uch)(c ^ *s++)] ^ (c >> 8);
    413         n--;
    414     }
    415     G1.crc = c;
    416     return c;
     396static void updcrc(uch * s, unsigned n)
     397{
     398    G1.crc = crc32_block_endian0(G1.crc, s, n, global_crc32_table /*G1.crc_32_tab*/);
    417399}
    418400
     
    633615         * or if the match length is less than 2:
    634616         */
    635         if (match[best_len] != scan_end ||
    636             match[best_len - 1] != scan_end1 ||
    637             *match != *scan || *++match != scan[1])
     617        if (match[best_len] != scan_end
     618         || match[best_len - 1] != scan_end1
     619         || *match != *scan || *++match != scan[1]
     620        ) {
    638621            continue;
     622        }
    639623
    640624        /* The check at best_len-1 can be removed because it will be made
     
    687671        bb_error_msg("\\[%d,%d]", start - match, length);
    688672        do {
    689             putc(G1.window[start++], stderr);
     673            bb_putchar_stderr(G1.window[start++]);
    690674        } while (--length != 0);
    691675    }
     
    975959#  define SEND_CODE(c, tree) \
    976960{ \
    977     if (verbose > 1) bb_error_msg("\ncd %3d ",(c)); \
     961    if (verbose > 1) bb_error_msg("\ncd %3d ", (c)); \
    978962    send_bits(tree[c].Code, tree[c].Len); \
    979963}
     
    11861170        Tracec(tree != G2.static_ltree,
    11871171               (stderr, "\nn %3d %c l %2d c %4x (%x) ", n,
    1188                 (isgraph(n) ? n : ' '), len, tree[n].Code,
     1172                (n > ' ' ? n : ' '), len, tree[n].Code,
    11891173                next_code[len] - 1));
    11901174    }
     
    15541538        if ((flag & 1) == 0) {
    15551539            SEND_CODE(lc, ltree);   /* send a literal byte */
    1556             Tracecv(isgraph(lc), (stderr, " '%c' ", lc));
     1540            Tracecv(lc > ' ', (stderr, " '%c' ", lc));
    15571541        } else {
    15581542            /* Here, lc is the match length - MIN_MATCH */
     
    20091993/* ======================================================================== */
    20101994static
    2011 char* make_new_name_gzip(char *filename)
    2012 {
    2013     return xasprintf("%s.gz", filename);
    2014 }
    2015 
    2016 static
    2017 USE_DESKTOP(long long) int pack_gzip(void)
     1995IF_DESKTOP(long long) int FAST_FUNC pack_gzip(unpack_info_t *info UNUSED_PARAM)
    20181996{
    20191997    struct stat s;
    20201998
    2021     clear_bufs();
    2022     s.st_ctime = 0;
    2023     fstat(STDIN_FILENO, &s);
    2024     zip(s.st_ctime);
    2025     return 0;
    2026 }
    2027 
    2028 int gzip_main(int argc, char **argv);
    2029 int gzip_main(int argc, char **argv)
    2030 {
    2031     unsigned opt;
    2032 
    2033     /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
    2034     opt = getopt32(argv, "cfv" USE_GUNZIP("d") "q123456789" );
    2035     option_mask32 &= 0x7; /* Clear -d, ignore -q, -0..9 */
    2036     //if (opt & 0x1) // -c
    2037     //if (opt & 0x2) // -f
    2038     //if (opt & 0x4) // -v
    2039 #if ENABLE_GUNZIP /* gunzip_main may not be visible... */
    2040     if (opt & 0x8) { // -d
    2041         return gunzip_main(argc, argv);
    2042     }
    2043 #endif
    2044     argv += optind;
    2045 
    2046     PTR_TO_GLOBALS = xzalloc(sizeof(struct globals) + sizeof(struct globals2))
    2047             + sizeof(struct globals);
    2048     G2.l_desc.dyn_tree    = G2.dyn_ltree;
    2049     G2.l_desc.static_tree = G2.static_ltree;
    2050     G2.l_desc.extra_bits  = extra_lbits;
    2051     G2.l_desc.extra_base  = LITERALS + 1;
    2052     G2.l_desc.elems       = L_CODES;
    2053     G2.l_desc.max_length  = MAX_BITS;
    2054     //G2.l_desc.max_code    = 0;
    2055 
    2056     G2.d_desc.dyn_tree    = G2.dyn_dtree;
    2057     G2.d_desc.static_tree = G2.static_dtree;
    2058     G2.d_desc.extra_bits  = extra_dbits;
    2059     //G2.d_desc.extra_base  = 0;
    2060     G2.d_desc.elems       = D_CODES;
    2061     G2.d_desc.max_length  = MAX_BITS;
    2062     //G2.d_desc.max_code    = 0;
    2063 
     1999    /* Clear input and output buffers */
     2000    G1.outcnt = 0;
     2001#ifdef DEBUG
     2002    G1.insize = 0;
     2003#endif
     2004    G1.isize = 0;
     2005
     2006    /* Reinit G2.xxx */
     2007    memset(&G2, 0, sizeof(G2));
     2008    G2.l_desc.dyn_tree     = G2.dyn_ltree;
     2009    G2.l_desc.static_tree  = G2.static_ltree;
     2010    G2.l_desc.extra_bits   = extra_lbits;
     2011    G2.l_desc.extra_base   = LITERALS + 1;
     2012    G2.l_desc.elems        = L_CODES;
     2013    G2.l_desc.max_length   = MAX_BITS;
     2014    //G2.l_desc.max_code     = 0;
     2015    G2.d_desc.dyn_tree     = G2.dyn_dtree;
     2016    G2.d_desc.static_tree  = G2.static_dtree;
     2017    G2.d_desc.extra_bits   = extra_dbits;
     2018    //G2.d_desc.extra_base   = 0;
     2019    G2.d_desc.elems        = D_CODES;
     2020    G2.d_desc.max_length   = MAX_BITS;
     2021    //G2.d_desc.max_code     = 0;
    20642022    G2.bl_desc.dyn_tree    = G2.bl_tree;
    20652023    //G2.bl_desc.static_tree = NULL;
     
    20702028    //G2.bl_desc.max_code    = 0;
    20712029
     2030    s.st_ctime = 0;
     2031    fstat(STDIN_FILENO, &s);
     2032    zip(s.st_ctime);
     2033    return 0;
     2034}
     2035
     2036#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
     2037static const char gzip_longopts[] ALIGN1 =
     2038    "stdout\0"              No_argument       "c"
     2039    "to-stdout\0"           No_argument       "c"
     2040    "force\0"               No_argument       "f"
     2041    "verbose\0"             No_argument       "v"
     2042#if ENABLE_GUNZIP
     2043    "decompress\0"          No_argument       "d"
     2044    "uncompress\0"          No_argument       "d"
     2045    "test\0"                No_argument       "t"
     2046#endif
     2047    "quiet\0"               No_argument       "q"
     2048    "fast\0"                No_argument       "1"
     2049    "best\0"                No_argument       "9"
     2050    ;
     2051#endif
     2052
     2053/*
     2054 * Linux kernel build uses gzip -d -n. We accept and ignore -n.
     2055 * Man page says:
     2056 * -n --no-name
     2057 * gzip: do not save the original file name and time stamp.
     2058 * (The original name is always saved if the name had to be truncated.)
     2059 * gunzip: do not restore the original file name/time even if present
     2060 * (remove only the gzip suffix from the compressed file name).
     2061 * This option is the default when decompressing.
     2062 * -N --name
     2063 * gzip: always save the original file name and time stamp (this is the default)
     2064 * gunzip: restore the original file name and time stamp if present.
     2065 */
     2066
     2067int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     2068#if ENABLE_GUNZIP
     2069int gzip_main(int argc, char **argv)
     2070#else
     2071int gzip_main(int argc UNUSED_PARAM, char **argv)
     2072#endif
     2073{
     2074    unsigned opt;
     2075
     2076#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
     2077    applet_long_options = gzip_longopts;
     2078#endif
     2079    /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
     2080    opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "q123456789n");
     2081#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
     2082    if (opt & 0x18) // -d and/or -t
     2083        return gunzip_main(argc, argv);
     2084#endif
     2085    option_mask32 &= 0x7; /* ignore -q, -0..9 */
     2086    //if (opt & 0x1) // -c
     2087    //if (opt & 0x2) // -f
     2088    //if (opt & 0x4) // -v
     2089    argv += optind;
     2090
     2091    SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
     2092            + sizeof(struct globals));
     2093
    20722094    /* Allocate all global buffers (for DYN_ALLOC option) */
    20732095    ALLOC(uch, G1.l_buf, INBUFSIZ);
     
    20772099    ALLOC(ush, G1.prev, 1L << BITS);
    20782100
    2079     /* Initialise the CRC32 table */
    2080     G1.crc_32_tab = crc32_filltable(NULL, 0);
    2081 
    2082     return bbunpack(argv, make_new_name_gzip, pack_gzip);
    2083 }
     2101    /* Initialize the CRC32 table */
     2102    global_crc32_table = crc32_filltable(NULL, 0);
     2103
     2104    return bbunpack(argv, pack_gzip, append_ext, "gz");
     2105}
Note: See TracChangeset for help on using the changeset viewer.