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

📄 zlib.c

📁 F:worksip2440a board可启动u-boot-like.tar.gz F:worksip2440a board可启动u-boot-like.tar.gz
💻 C
📖 第 1 页 / 共 5 页
字号:
      {	c->sub.lit = t->base;	Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?		 "inflate:         literal '%c'\n" :		 "inflate:         literal 0x%02x\n", t->base));	c->mode = LIT;	break;      }      if (e & 16)               /* length */      {	c->sub.copy.get = e & 15;	c->len = t->base;	c->mode = LENEXT;	break;      }      if ((e & 64) == 0)        /* next table */      {	c->sub.code.need = e;	c->sub.code.tree = t->next;	break;      }      if (e & 32)               /* end of block */      {	Tracevv((stderr, "inflate:         end of block\n"));	c->mode = WASH;	break;      }      c->mode = BADCODE;        /* invalid code */      z->msg = "invalid literal/length code";      r = Z_DATA_ERROR;      LEAVE    case LENEXT:        /* i: getting length extra (have base) */      j = c->sub.copy.get;      NEEDBITS(j)      c->len += (uInt)b & inflate_mask[j];      DUMPBITS(j)      c->sub.code.need = c->dbits;      c->sub.code.tree = c->dtree;      Tracevv((stderr, "inflate:         length %u\n", c->len));      c->mode = DIST;    case DIST:          /* i: get distance next */      j = c->sub.code.need;      NEEDBITS(j)      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);      DUMPBITS(t->bits)      e = (uInt)(t->exop);      if (e & 16)               /* distance */      {	c->sub.copy.get = e & 15;	c->sub.copy.dist = t->base;	c->mode = DISTEXT;	break;      }      if ((e & 64) == 0)        /* next table */      {	c->sub.code.need = e;	c->sub.code.tree = t->next;	break;      }      c->mode = BADCODE;        /* invalid code */      z->msg = "invalid distance code";      r = Z_DATA_ERROR;      LEAVE    case DISTEXT:       /* i: getting distance extra */      j = c->sub.copy.get;      NEEDBITS(j)      c->sub.copy.dist += (uInt)b & inflate_mask[j];      DUMPBITS(j)      Tracevv((stderr, "inflate:         distance %u\n", c->sub.copy.dist));      c->mode = COPY;    case COPY:          /* o: copying bytes in window, waiting for space */#ifndef __TURBOC__ /* Turbo C bug for following expression */      f = (uInt)(q - s->window) < c->sub.copy.dist ?	  s->end - (c->sub.copy.dist - (q - s->window)) :	  q - c->sub.copy.dist;#else      f = q - c->sub.copy.dist;      if ((uInt)(q - s->window) < c->sub.copy.dist)	f = s->end - (c->sub.copy.dist - (q - s->window));#endif      while (c->len)      {	NEEDOUT	OUTBYTE(*f++)	if (f == s->end)	  f = s->window;	c->len--;      }      c->mode = START;      break;    case LIT:           /* o: got literal, waiting for output space */      NEEDOUT      OUTBYTE(c->sub.lit)      c->mode = START;      break;    case WASH:          /* o: got eob, possibly more output */      FLUSH      if (s->read != s->write)	LEAVE      c->mode = END;    case END:      r = Z_STREAM_END;      LEAVE    case BADCODE:       /* x: got error */      r = Z_DATA_ERROR;      LEAVE    default:      r = Z_STREAM_ERROR;      LEAVE  }}local void inflate_codes_free(c, z)inflate_codes_statef *c;z_stream *z;{  ZFREE(z, c, sizeof(struct inflate_codes_state));  Tracev((stderr, "inflate:       codes free\n"));}/*+++++*//* inflate_util.c -- data and routines common to blocks and codes * Copyright (C) 1995 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h *//* copy as much as possible from the sliding window to the output area */local int inflate_flush(s, z, r)inflate_blocks_statef *s;z_stream *z;int r;{  uInt n;  Bytef *p, *q;  /* local copies of source and destination pointers */  p = z->next_out;  q = s->read;  /* compute number of bytes to copy as far as end of window */  n = (uInt)((q <= s->write ? s->write : s->end) - q);  if (n > z->avail_out) n = z->avail_out;  if (n && r == Z_BUF_ERROR) r = Z_OK;  /* update counters */  z->avail_out -= n;  z->total_out += n;  /* update check information */  if (s->checkfn != Z_NULL)    s->check = (*s->checkfn)(s->check, q, n);  /* output callback */  if (z->outcb != Z_NULL)    (*z->outcb)(q, n);  /* copy as far as end of window */  zmemcpy(p, q, n);  p += n;  q += n;  /* see if more to copy at beginning of window */  if (q == s->end)  {    /* wrap pointers */    q = s->window;    if (s->write == s->end)      s->write = s->window;    /* compute bytes to copy */    n = (uInt)(s->write - q);    if (n > z->avail_out) n = z->avail_out;    if (n && r == Z_BUF_ERROR) r = Z_OK;    /* update counters */    z->avail_out -= n;    z->total_out += n;    /* update check information */    if (s->checkfn != Z_NULL)      s->check = (*s->checkfn)(s->check, q, n);    /* output callback */    if (z->outcb != Z_NULL)	(*z->outcb)(q, n);    /* copy */    zmemcpy(p, q, n);    p += n;    q += n;  }  /* update pointers */  z->next_out = p;  s->read = q;  /* done */  return r;}/*+++++*//* inffast.c -- process literals and length/distance pairs fast * Copyright (C) 1995 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h *//* simplify the use of the inflate_huft type with some defines */#define base more.Base#define next more.Next#define exop word.what.Exop#define bits word.what.Bits/* macros for bit input with no checking and for returning unused bytes */#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}#define UNGRAB {n+=(c=k>>3);p-=c;k&=7;}/* Called with number of bytes left to write in window at least 258   (the maximum string length) and number of input bytes available   at least ten.  The ten bytes are six bytes for the longest length/   distance pair plus four bytes for overloading the bit buffer. */local int inflate_fast(bl, bd, tl, td, s, z)uInt bl, bd;inflate_huft *tl, *td;inflate_blocks_statef *s;z_stream *z;{  inflate_huft *t;      /* temporary pointer */  uInt e;               /* extra bits or operation */  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 */  uInt ml;              /* mask for literal/length tree */  uInt md;              /* mask for distance tree */  uInt c;               /* bytes to copy */  uInt d;               /* distance back to copy from */  Bytef *r;             /* copy source pointer */  /* load input, output, bit values */  LOAD  /* initialize masks */  ml = inflate_mask[bl];  md = inflate_mask[bd];  /* do until not enough input or output space for fast loop */  do {                          /* assume called with m >= 258 && n >= 10 */    /* get literal/length code */    GRABBITS(20)                /* max bits for literal/length code */    if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)    {      DUMPBITS(t->bits)      Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?		"inflate:         * literal '%c'\n" :		"inflate:         * literal 0x%02x\n", t->base));      *q++ = (Byte)t->base;      m--;      continue;    }    do {      DUMPBITS(t->bits)      if (e & 16)      {	/* get extra bits for length */	e &= 15;	c = t->base + ((uInt)b & inflate_mask[e]);	DUMPBITS(e)	Tracevv((stderr, "inflate:         * length %u\n", c));	/* decode distance base of block to copy */	GRABBITS(15);           /* max bits for distance code */	e = (t = td + ((uInt)b & md))->exop;	do {	  DUMPBITS(t->bits)	  if (e & 16)	  {	    /* get extra bits to add to distance base */	    e &= 15;	    GRABBITS(e)         /* get extra bits (up to 13) */	    d = t->base + ((uInt)b & inflate_mask[e]);	    DUMPBITS(e)	    Tracevv((stderr, "inflate:         * distance %u\n", d));	    /* do the copy */	    m -= c;	    if ((uInt)(q - s->window) >= d)     /* offset before dest */	    {                                   /*  just copy */	      r = q - d;	      *q++ = *r++;  c--;        /* minimum count is three, */	      *q++ = *r++;  c--;        /*  so unroll loop a little */	    }	    else                        /* else offset after destination */	    {	      e = d - (q - s->window);  /* bytes from offset to end */	      r = s->end - e;           /* pointer to offset */	      if (c > e)                /* if source crosses, */	      {		c -= e;                 /* copy to end of window */		do {		  *q++ = *r++;		} while (--e);		r = s->window;          /* copy rest from start of window */	      }	    }	    do {                        /* copy all or what's left */	      *q++ = *r++;	    } while (--c);	    break;	  }	  else if ((e & 64) == 0)	    e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop;	  else	  {	    z->msg = "invalid distance code";	    UNGRAB	    UPDATE	    return Z_DATA_ERROR;	  }	} while (1);	break;      }      if ((e & 64) == 0)      {	if ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) == 0)	{	  DUMPBITS(t->bits)	  Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?		    "inflate:         * literal '%c'\n" :		    "inflate:         * literal 0x%02x\n", t->base));	  *q++ = (Byte)t->base;	  m--;	  break;	}      }      else if (e & 32)      {	Tracevv((stderr, "inflate:         * end of block\n"));	UNGRAB	UPDATE	return Z_STREAM_END;      }      else      {	z->msg = "invalid literal/length code";	UNGRAB	UPDATE	return Z_DATA_ERROR;      }    } while (1);  } while (m >= 258 && n >= 10);  /* not enough input or output--restore pointers and return */  UNGRAB  UPDATE  return Z_OK;}/*+++++*//* zutil.c -- target dependent utility functions for the compression library * Copyright (C) 1995 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h *//* From: zutil.c,v 1.8 1995/05/03 17:27:12 jloup Exp */char *zlib_version = ZLIB_VERSION;char *z_errmsg[] = {"stream end",          /* Z_STREAM_END    1 */"",                    /* Z_OK            0 */"file error",          /* Z_ERRNO        (-1) */"stream error",        /* Z_STREAM_ERROR (-2) */"data error",          /* Z_DATA_ERROR   (-3) */"insufficient memory", /* Z_MEM_ERROR    (-4) */"buffer error",        /* Z_BUF_ERROR    (-5) */""};/*+++++*//* adler32.c -- compute the Adler-32 checksum of a data stream * Copyright (C) 1995 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h *//* From: adler32.c,v 1.6 1995/05/03 17:27:08 jloup Exp */#define BASE 65521L /* largest prime smaller than 65536 */#define NMAX 5552/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */#define DO1(buf)  {s1 += *buf++; s2 += s1;}#define DO2(buf)  DO1(buf); DO1(buf);#define DO4(buf)  DO2(buf); DO2(buf);#define DO8(buf)  DO4(buf); DO4(buf);#define DO16(buf) DO8(buf); DO8(buf);/* ========================================================================= */uLong adler32(adler, buf, len)    uLong adler;    Bytef *buf;    uInt len;{    unsigned long s1 = adler & 0xffff;    unsigned long s2 = (adler >> 16) & 0xffff;    int k;    if (buf == Z_NULL) return 1L;    while (len > 0) {	k = len < NMAX ? len : NMAX;	len -= k;	while (k >= 16) {	    DO16(buf);	    k -= 16;	}	if (k != 0) do {	    DO1(buf);	} while (--k);	s1 %= BASE;	s2 %= BASE;    }    return (s2 << 16) | s1;}

⌨️ 快捷键说明

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