⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inflate.c

📁 Lib files of linux kernel
💻 C
📖 第 1 页 / 共 3 页
字号:
#else  if (nl > 286 || nd > 30)#endif  {    ret = 1;             /* bad lengths */    goto out;  }DEBG("dyn1 ");  /* read in bit-length-code lengths */  for (j = 0; j < nb; j++)  {    NEEDBITS(3)    ll[border[j]] = (unsigned)b & 7;    DUMPBITS(3)  }  for (; j < 19; j++)    ll[border[j]] = 0;DEBG("dyn2 ");  /* build decoding table for trees--single level, 7 bit lookup */  bl = 7;  if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0)  {    if (i == 1)      huft_free(tl);    ret = i;                   /* incomplete code set */    goto out;  }DEBG("dyn3 ");  /* read in literal and distance code lengths */  n = nl + nd;  m = mask_bits[bl];  i = l = 0;  while ((unsigned)i < n)  {    NEEDBITS((unsigned)bl)    j = (td = tl + ((unsigned)b & m))->b;    DUMPBITS(j)    j = td->v.n;    if (j < 16)                 /* length of code in bits (0..15) */      ll[i++] = l = j;          /* save last length in l */    else if (j == 16)           /* repeat last length 3 to 6 times */    {      NEEDBITS(2)      j = 3 + ((unsigned)b & 3);      DUMPBITS(2)      if ((unsigned)i + j > n) {        ret = 1;	goto out;      }      while (j--)        ll[i++] = l;    }    else if (j == 17)           /* 3 to 10 zero length codes */    {      NEEDBITS(3)      j = 3 + ((unsigned)b & 7);      DUMPBITS(3)      if ((unsigned)i + j > n) {        ret = 1;	goto out;      }      while (j--)        ll[i++] = 0;      l = 0;    }    else                        /* j == 18: 11 to 138 zero length codes */    {      NEEDBITS(7)      j = 11 + ((unsigned)b & 0x7f);      DUMPBITS(7)      if ((unsigned)i + j > n) {        ret = 1;	goto out;      }      while (j--)        ll[i++] = 0;      l = 0;    }  }DEBG("dyn4 ");  /* free decoding table for trees */  huft_free(tl);DEBG("dyn5 ");  /* restore the global bit buffer */  bb = b;  bk = k;DEBG("dyn5a ");  /* build the decoding tables for literal/length and distance codes */  bl = lbits;  if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0)  {DEBG("dyn5b ");    if (i == 1) {      error("incomplete literal tree");      huft_free(tl);    }    ret = i;                   /* incomplete code set */    goto out;  }DEBG("dyn5c ");  bd = dbits;  if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0)  {DEBG("dyn5d ");    if (i == 1) {      error("incomplete distance tree");#ifdef PKZIP_BUG_WORKAROUND      i = 0;    }#else      huft_free(td);    }    huft_free(tl);    ret = i;                   /* incomplete code set */    goto out;#endif  }DEBG("dyn6 ");  /* decompress until an end-of-block code */  if (inflate_codes(tl, td, bl, bd)) {    ret = 1;    goto out;  }DEBG("dyn7 ");  /* free the decoding tables, return */  huft_free(tl);  huft_free(td);  DEBG(">");  ret = 0;out:  free(ll);  return ret;underrun:  ret = 4;			/* Input underrun */  goto out;}STATIC int INIT inflate_block(	int *e                  /* last block flag */	)/* decompress an inflated block */{  unsigned t;           /* block type */  register ulg b;       /* bit buffer */  register unsigned k;  /* number of bits in bit buffer */  DEBG("<blk");  /* make local bit buffer */  b = bb;  k = bk;  /* read in last block bit */  NEEDBITS(1)  *e = (int)b & 1;  DUMPBITS(1)  /* read in block type */  NEEDBITS(2)  t = (unsigned)b & 3;  DUMPBITS(2)  /* restore the global bit buffer */  bb = b;  bk = k;  /* inflate that block type */  if (t == 2)    return inflate_dynamic();  if (t == 0)    return inflate_stored();  if (t == 1)    return inflate_fixed();  DEBG(">");  /* bad block type */  return 2; underrun:  return 4;			/* Input underrun */}STATIC int INIT inflate(void)/* decompress an inflated entry */{  int e;                /* last block flag */  int r;                /* result code */  unsigned h;           /* maximum struct huft's malloc'ed */  /* initialize window, bit buffer */  wp = 0;  bk = 0;  bb = 0;  /* decompress until the last block */  h = 0;  do {    hufts = 0;#ifdef ARCH_HAS_DECOMP_WDOG    arch_decomp_wdog();#endif    r = inflate_block(&e);    if (r)	    return r;    if (hufts > h)      h = hufts;  } while (!e);  /* Undo too much lookahead. The next read will be byte aligned so we   * can discard unused bits in the last meaningful byte.   */  while (bk >= 8) {    bk -= 8;    inptr--;  }  /* flush out slide */  flush_output(wp);  /* return success */#ifdef DEBUG  fprintf(stderr, "<%u> ", h);#endif /* DEBUG */  return 0;}/********************************************************************** * * The following are support routines for inflate.c * **********************************************************************/static ulg crc_32_tab[256];static ulg crc;		/* initialized in makecrc() so it'll reside in bss */#define CRC_VALUE (crc ^ 0xffffffffUL)/* * Code to compute the CRC-32 table. Borrowed from  * gzip-1.0.3/makecrc.c. */static void INITmakecrc(void){/* Not copyrighted 1990 Mark Adler	*/  unsigned long c;      /* crc shift register */  unsigned long e;      /* polynomial exclusive-or pattern */  int i;                /* counter for all possible eight bit values */  int k;                /* byte being shifted into crc apparatus */  /* terms of polynomial defining this crc (except x^32): */  static const int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};  /* Make exclusive-or pattern from polynomial */  e = 0;  for (i = 0; i < sizeof(p)/sizeof(int); i++)    e |= 1L << (31 - p[i]);  crc_32_tab[0] = 0;  for (i = 1; i < 256; i++)  {    c = 0;    for (k = i | 256; k != 1; k >>= 1)    {      c = c & 1 ? (c >> 1) ^ e : c >> 1;      if (k & 1)        c ^= e;    }    crc_32_tab[i] = c;  }  /* this is initialized here so this code could reside in ROM */  crc = (ulg)0xffffffffUL; /* shift register contents */}/* gzip flag byte */#define ASCII_FLAG   0x01 /* bit 0 set: file probably ASCII text */#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */#define ORIG_NAME    0x08 /* bit 3 set: original file name present */#define COMMENT      0x10 /* bit 4 set: file comment present */#define ENCRYPTED    0x20 /* bit 5 set: file is encrypted */#define RESERVED     0xC0 /* bit 6,7:   reserved *//* * Do the uncompression! */static int INIT gunzip(void){    uch flags;    unsigned char magic[2]; /* magic header */    char method;    ulg orig_crc = 0;       /* original crc */    ulg orig_len = 0;       /* original uncompressed length */    int res;    magic[0] = NEXTBYTE();    magic[1] = NEXTBYTE();    method   = NEXTBYTE();    if (magic[0] != 037 ||	((magic[1] != 0213) && (magic[1] != 0236))) {	    error("bad gzip magic numbers");	    return -1;    }    /* We only support method #8, DEFLATED */    if (method != 8)  {	    error("internal error, invalid method");	    return -1;    }    flags  = (uch)get_byte();    if ((flags & ENCRYPTED) != 0) {	    error("Input is encrypted");	    return -1;    }    if ((flags & CONTINUATION) != 0) {	    error("Multi part input");	    return -1;    }    if ((flags & RESERVED) != 0) {	    error("Input has invalid flags");	    return -1;    }    NEXTBYTE();	/* Get timestamp */    NEXTBYTE();    NEXTBYTE();    NEXTBYTE();    (void)NEXTBYTE();  /* Ignore extra flags for the moment */    (void)NEXTBYTE();  /* Ignore OS type for the moment */    if ((flags & EXTRA_FIELD) != 0) {	    unsigned len = (unsigned)NEXTBYTE();	    len |= ((unsigned)NEXTBYTE())<<8;	    while (len--) (void)NEXTBYTE();    }    /* Get original file name if it was truncated */    if ((flags & ORIG_NAME) != 0) {	    /* Discard the old name */	    while (NEXTBYTE() != 0) /* null */ ;    }     /* Discard file comment if any */    if ((flags & COMMENT) != 0) {	    while (NEXTBYTE() != 0) /* null */ ;    }    /* Decompress */    if ((res = inflate())) {	    switch (res) {	    case 0:		    break;	    case 1:		    error("invalid compressed format (err=1)");		    break;	    case 2:		    error("invalid compressed format (err=2)");		    break;	    case 3:		    error("out of memory");		    break;	    case 4:		    error("out of input data");		    break;	    default:		    error("invalid compressed format (other)");	    }	    return -1;    }	        /* Get the crc and original length */    /* crc32  (see algorithm.doc)     * uncompressed input size modulo 2^32     */    orig_crc = (ulg) NEXTBYTE();    orig_crc |= (ulg) NEXTBYTE() << 8;    orig_crc |= (ulg) NEXTBYTE() << 16;    orig_crc |= (ulg) NEXTBYTE() << 24;        orig_len = (ulg) NEXTBYTE();    orig_len |= (ulg) NEXTBYTE() << 8;    orig_len |= (ulg) NEXTBYTE() << 16;    orig_len |= (ulg) NEXTBYTE() << 24;        /* Validate decompression */    if (orig_crc != CRC_VALUE) {	    error("crc error");	    return -1;    }    if (orig_len != bytes_out) {	    error("length error");	    return -1;    }    return 0; underrun:			/* NEXTBYTE() goto's here if needed */    error("out of input data");    return -1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -