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

📄 zlib.c

📁 F:worksip2440a board可启动u-boot-like.tar.gz F:worksip2440a board可启动u-boot-like.tar.gz
💻 C
📖 第 1 页 / 共 5 页
字号:
      Trace((stderr, "inflate: zlib header ok\n"));      z->state->mode = BLOCKS;    case BLOCKS:      r = inflate_blocks(z->state->blocks, z, r);      if (f == Z_PACKET_FLUSH && z->avail_in == 0 && z->avail_out != 0)	  r = inflate_packet_flush(z->state->blocks);      if (r == Z_DATA_ERROR)      {	z->state->mode = BAD;	z->state->sub.marker = 0;       /* can try inflateSync */	break;      }      if (r != Z_STREAM_END)	return r;      r = Z_OK;      inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);      if (z->state->nowrap)      {	z->state->mode = DONE;	break;      }      z->state->mode = CHECK4;    case CHECK4:      NEEDBYTE      z->state->sub.check.need = (uLong)NEXTBYTE << 24;      z->state->mode = CHECK3;    case CHECK3:      NEEDBYTE      z->state->sub.check.need += (uLong)NEXTBYTE << 16;      z->state->mode = CHECK2;    case CHECK2:      NEEDBYTE      z->state->sub.check.need += (uLong)NEXTBYTE << 8;      z->state->mode = CHECK1;    case CHECK1:      NEEDBYTE      z->state->sub.check.need += (uLong)NEXTBYTE;      if (z->state->sub.check.was != z->state->sub.check.need)      {	z->state->mode = BAD;	z->msg = "incorrect data check";	z->state->sub.marker = 5;       /* can't try inflateSync */	break;      }      Trace((stderr, "inflate: zlib check ok\n"));      z->state->mode = DONE;    case DONE:      return Z_STREAM_END;    case BAD:      return Z_DATA_ERROR;    default:      return Z_STREAM_ERROR;  } empty:  if (f != Z_PACKET_FLUSH)    return r;  z->state->mode = BAD;  z->state->sub.marker = 0;       /* can try inflateSync */  return Z_DATA_ERROR;}/* * This subroutine adds the data at next_in/avail_in to the output history * without performing any output.  The output buffer must be "caught up"; * i.e. no pending output (hence s->read equals s->write), and the state must * be BLOCKS (i.e. we should be willing to see the start of a series of * BLOCKS).  On exit, the output will also be caught up, and the checksum * will have been updated if need be. */int inflateIncomp(z)z_stream *z;{    if (z->state->mode != BLOCKS)	return Z_DATA_ERROR;    return inflate_addhistory(z->state->blocks, z);}int inflateSync(z)z_stream *z;{  uInt n;       /* number of bytes to look at */  Bytef *p;     /* pointer to bytes */  uInt m;       /* number of marker bytes found in a row */  uLong r, w;   /* temporaries to save total_in and total_out */  /* set up */  if (z == Z_NULL || z->state == Z_NULL)    return Z_STREAM_ERROR;  if (z->state->mode != BAD)  {    z->state->mode = BAD;    z->state->sub.marker = 0;  }  if ((n = z->avail_in) == 0)    return Z_BUF_ERROR;  p = z->next_in;  m = z->state->sub.marker;  /* search */  while (n && m < 4)  {    if (*p == (Byte)(m < 2 ? 0 : 0xff))      m++;    else if (*p)      m = 0;    else      m = 4 - m;    p++, n--;  }  /* restore */  z->total_in += p - z->next_in;  z->next_in = p;  z->avail_in = n;  z->state->sub.marker = m;  /* return no joy or set up to restart on a new block */  if (m != 4)    return Z_DATA_ERROR;  r = z->total_in;  w = z->total_out;  inflateReset(z);  z->total_in = r;  z->total_out = w;  z->state->mode = BLOCKS;  return Z_OK;}#undef NEEDBYTE#undef NEXTBYTE/*+++++*//* infutil.h -- types and macros common to blocks and codes * Copyright (C) 1995 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h *//* WARNING: this file should *not* be used by applications. It is   part of the implementation of the compression library and is   subject to change. Applications should only use zlib.h. *//* inflate blocks semi-private state */struct inflate_blocks_state {  /* mode */  enum {      TYPE,     /* get type bits (3, including end bit) */      LENS,     /* get lengths for stored */      STORED,   /* processing stored block */      TABLE,    /* get table lengths */      BTREE,    /* get bit lengths tree for a dynamic block */      DTREE,    /* get length, distance trees for a dynamic block */      CODES,    /* processing fixed or dynamic block */      DRY,      /* output remaining window bytes */      DONEB,     /* finished last block, done */      BADB}      /* got a data error--stuck here */    mode;               /* current inflate_block mode */  /* mode dependent information */  union {    uInt left;          /* if STORED, bytes left to copy */    struct {      uInt table;               /* table lengths (14 bits) */      uInt index;               /* index into blens (or border) */      uIntf *blens;             /* bit lengths of codes */      uInt bb;                  /* bit length tree depth */      inflate_huft *tb;         /* bit length decoding tree */      int nblens;		/* # elements allocated at blens */    } trees;            /* if DTREE, decoding info for trees */    struct {      inflate_huft *tl, *td;    /* trees to free */      inflate_codes_statef	 *codes;    } decode;           /* if CODES, current state */  } sub;                /* submode */  uInt last;            /* true if this block is the last block */  /* mode independent information */  uInt bitk;            /* bits in bit buffer */  uLong bitb;           /* bit buffer */  Bytef *window;        /* sliding window */  Bytef *end;           /* one byte after sliding window */  Bytef *read;          /* window read pointer */  Bytef *write;         /* window write pointer */  check_func checkfn;   /* check function */  uLong check;          /* check on output */};/* defines for inflate input/output *//*   update pointers and return */#define UPDBITS {s->bitb=b;s->bitk=k;}#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}#define UPDOUT {s->write=q;}#define UPDATE {UPDBITS UPDIN UPDOUT}#define LEAVE {UPDATE return inflate_flush(s,z,r);}/*   get bytes and bits */#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}#define NEXTBYTE (n--,*p++)#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}#define DUMPBITS(j) {b>>=(j);k-=(j);}/*   output bytes */#define WAVAIL (q<s->read?s->read-q-1:s->end-q)#define LOADOUT {q=s->write;m=WAVAIL;}#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=WAVAIL;}}#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}#define OUTBYTE(a) {*q++=(Byte)(a);m--;}/*   load local pointers */#define LOAD {LOADIN LOADOUT}/* * The IBM 150 firmware munges the data right after _etext[].  This * protects it. -- Cort */#if 0local uInt protect_mask[] = {0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0};#endif/* And'ing with mask[n] masks the lower n bits */local uInt inflate_mask[] = {    0x0000,    0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,    0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff};/* copy as much as possible from the sliding window to the output area */local int inflate_flush OF((    inflate_blocks_statef *,    z_stream *,    int));/*+++++*//* inffast.h -- header to use inffast.c * Copyright (C) 1995 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h *//* WARNING: this file should *not* be used by applications. It is   part of the implementation of the compression library and is   subject to change. Applications should only use zlib.h. */local int inflate_fast OF((    uInt,    uInt,    inflate_huft *,    inflate_huft *,    inflate_blocks_statef *,    z_stream *));/*+++++*//* infblock.c -- interpret and process block types to last block * Copyright (C) 1995 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h *//* Table for deflate from PKZIP's appnote.txt. */local uInt border[] = { /* Order of the bit length code lengths */	16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};/*   Notes beyond the 1.93a appnote.txt:   1. Distance pointers never point before the beginning of the output      stream.   2. Distance pointers can point back across blocks, up to 32k away.   3. There is an implied maximum of 7 bits for the bit length table and      15 bits for the actual data.   4. If only one code exists, then it is encoded using one bit.  (Zero      would be more efficient, but perhaps a little confusing.)  If two      codes exist, they are coded using one bit each (0 and 1).   5. There is no way of sending zero distance codes--a dummy must be      sent if there are none.  (History: a pre 2.0 version of PKZIP would      store blocks with no distance codes, but this was discovered to be      too harsh a criterion.)  Valid only for 1.93a.  2.04c does allow      zero distance codes, which is sent as one code of zero bits in      length.   6. There are up to 286 literal/length codes.  Code 256 represents the      end-of-block.  Note however that the static length tree defines      288 codes just to fill out the Huffman codes.  Codes 286 and 287      cannot be used though, since there is no length base or extra bits      defined for them.  Similarily, there are up to 30 distance codes.      However, static trees define 32 codes (all 5 bits) to fill out the      Huffman codes, but the last two had better not show up in the data.   7. Unzip can check dynamic Huffman blocks for complete code sets.      The exception is that a single code would not be complete (see #4).   8. The five bits following the block type is really the number of      literal codes sent minus 257.   9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits      (1+6+6).  Therefore, to output three times the length, you output      three codes (1+1+1), whereas to output four times the same length,      you only need two codes (1+3).  Hmm.  10. In the tree reconstruction algorithm, Code = Code + Increment      only if BitLength(i) is not zero.  (Pretty obvious.)  11. Correction: 4 Bits: # of Bit Length codes - 4     (4 - 19)  12. Note: length code 284 can represent 227-258, but length code 285      really is 258.  The last length deserves its own, short code      since it gets used a lot in very redundant files.  The length      258 is special since 258 - 3 (the min match length) is 255.  13. The literal/length and distance code bit lengths are read as a      single stream of lengths.  It is possible (and advantageous) for      a repeat code (16, 17, or 18) to go across the boundary between      the two sets of lengths. */local void inflate_blocks_reset(s, z, c)inflate_blocks_statef *s;z_stream *z;uLongf *c;{  if (s->checkfn != Z_NULL)    *c = s->check;  if (s->mode == BTREE || s->mode == DTREE)    ZFREE(z, s->sub.trees.blens, s->sub.trees.nblens * sizeof(uInt));  if (s->mode == CODES)  {    inflate_codes_free(s->sub.decode.codes, z);    inflate_trees_free(s->sub.decode.td, z);    inflate_trees_free(s->sub.decode.tl, z);  }  s->mode = TYPE;  s->bitk = 0;  s->bitb = 0;  s->read = s->write = s->window;  if (s->checkfn != Z_NULL)    s->check = (*s->checkfn)(0L, Z_NULL, 0);  if (z->outcb != Z_NULL)    (*z->outcb)(Z_NULL, 0);  Trace((stderr, "inflate:   blocks reset\n"));}local inflate_blocks_statef *inflate_blocks_new(z, c, w)z_stream *z;check_func c;uInt w;{  inflate_blocks_statef *s;  if ((s = (inflate_blocks_statef *)ZALLOC       (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)    return s;  if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)  {    ZFREE(z, s, sizeof(struct inflate_blocks_state));    return Z_NULL;  }  s->end = s->window + w;  s->checkfn = c;  s->mode = TYPE;  Trace((stderr, "inflate:   blocks allocated\n"));  inflate_blocks_reset(s, z, &s->check);  return s;}local int inflate_blocks(s, z, r)inflate_blocks_statef *s;z_stream *z;int r;{  uInt t;               /* temporary storage */  uLong b;              /* bit buffer */  uInt k;               /* bits in bit buffer */  Bytef *p;             /* input data pointer */  uInt n;               /* bytes available there */  Bytef *q;             /* output window write pointer */  uInt m;               /* bytes to end of window or read pointer */  /* copy input/output information to locals (UPDATE macro restores) */  LOAD  /* process input based on current state */  while (1) switch (s->mode)  {    case TYPE:      NEEDBITS(3)      t = (uInt)b & 7;      s->last = t & 1;      switch (t >> 1)      {	case 0:                         /* stored */	  Trace((stderr, "inflate:     stored block%s\n",		 s->last ? " (last)" : ""));	  DUMPBITS(3)	  t = k & 7;                    /* go to byte boundary */	  DUMPBITS(t)	  s->mode = LENS;               /* get length of stored block */	  break;	case 1:                         /* fixed */	  Trace((stderr, "inflate:     fixed codes block%s\n",		 s->last ? " (last)" : ""));	  {	    uInt bl, bd;	    inflate_huft *tl, *td;	    inflate_trees_fixed(&bl, &bd, &tl, &td);	    s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);	    if (s->sub.decode.codes == Z_NULL)	    {	      r = Z_MEM_ERROR;	      LEAVE	    }	    s->sub.decode.tl = Z_NULL;  /* don't try to free these */	    s->sub.decode.td = Z_NULL;	  }	  DUMPBITS(3)	  s->mode = CODES;	  break;	case 2:                         /* dynamic */	  Trace((stderr, "inflate:     dynamic codes block%s\n",		 s->last ? " (last)" : ""));	  DUMPBITS(3)	  s->mode = TABLE;	  break;	case 3:                         /* illegal */	  DUMPBITS(3)	  s->mode = BADB;	  z->msg = "invalid block type";	  r = Z_DATA_ERROR;	  LEAVE      }      break;    case LENS:      NEEDBITS(32)      if (((~b) >> 16) != (b & 0xffff))

⌨️ 快捷键说明

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