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

📄 inflate.c

📁 eCos/RedBoot for勤研ARM AnywhereII(4510) 含全部源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
      z->state->gz_cnt = NEXTBYTE;
      z->state->mode = GZ_EXTRA_HI;
  case GZ_EXTRA_HI:
      NEEDBYTE;
      z->state->gz_cnt += (((uInt)NEXTBYTE)<<8);
      z->state->mode = GZ_EXTRA_ZAP;
  case GZ_EXTRA_ZAP:
      // Discard extra field
      while (z->state->gz_cnt-- > 0) {
          NEEDBYTE;
          b = NEXTBYTE;
      }
      z->state->mode = GZ_NAME;
  case GZ_NAME:
      if (!(z->state->gz_flag & _GZ_ORIG_NAME)) {
          z->state->mode = GZ_COMMENT;
          break;
      }
      // Skip the name
      do {
          NEEDBYTE;
          b = NEXTBYTE;
      } while (0 != b);
      z->state->mode = GZ_COMMENT;
  case GZ_COMMENT:
      if (!(z->state->gz_flag & _GZ_COMMENT)) {
          z->state->mode = GZ_HEAD_CRC_LO;
          break;
      }
      // Skip the comment
      do {
          NEEDBYTE;
          b = NEXTBYTE;
      } while (0 != b);
      z->state->mode = GZ_HEAD_CRC_LO;
  case GZ_HEAD_CRC_LO:
      if (!(z->state->gz_flag & _GZ_HEAD_CRC)) {
          z->state->mode = GZ_DONE;
          break;
      }
      // skip lo byte
      NEEDBYTE;
      b = NEXTBYTE;
      z->state->mode = GZ_HEAD_CRC_HI;
  case GZ_HEAD_CRC_HI:
      // skip hi byte
      NEEDBYTE;
      b = NEXTBYTE;
      z->state->mode = GZ_DONE;
  case GZ_DONE:
      // Remember where output is written to and flag that this is a
      // gz stream by setting the gz_mode.
      z->state->gz_start = z->next_out;
      z->state->gz_mode = BLOCKS;
      z->state->gz_sum = 0;

      // Depending on the flag select correct next step
      // (clone of code in FLAG)
      if (!(z->state->gz_flag & PRESET_DICT))
          z->state->mode = BLOCKS;
      else
          z->state->mode = DICT4;
      break;
#endif // __ECOS__
    case FLAG:
      NEEDBYTE
      b = NEXTBYTE;
      if (((z->state->sub.method << 8) + b) % 31)
      {
        z->state->mode = BAD;
        z->msg = (char*)"incorrect header check";
        z->state->sub.marker = 5;       /* can't try inflateSync */
        break;
      }
      Tracev((stderr, "inflate: zlib header ok\n"));
      if (!(b & PRESET_DICT))
      {
        z->state->mode = BLOCKS;
        break;
      }
      z->state->mode = DICT4;
    case DICT4:
      NEEDBYTE
      z->state->sub.check.need = (uLong)NEXTBYTE << 24;
      z->state->mode = DICT3;
    case DICT3:
      NEEDBYTE
      z->state->sub.check.need += (uLong)NEXTBYTE << 16;
      z->state->mode = DICT2;
    case DICT2:
      NEEDBYTE
      z->state->sub.check.need += (uLong)NEXTBYTE << 8;
      z->state->mode = DICT1;
    case DICT1:
      NEEDBYTE
      z->state->sub.check.need += (uLong)NEXTBYTE;
      z->adler = z->state->sub.check.need;
      z->state->mode = DICT0;
      return Z_NEED_DICT;
    case DICT0:
      z->state->mode = BAD;
      z->msg = (char*)"need dictionary";
      z->state->sub.marker = 0;       /* can try inflateSync */
      return Z_STREAM_ERROR;
    case BLOCKS:
#ifdef __ECOS__
      if (z->state->gz_mode != DONE)
        z->state->gz_start = z->next_out;
#endif
      r = inflate_blocks(z->state->blocks, z, r);
      if (r == Z_DATA_ERROR)
      {
        z->state->mode = BAD;
        z->state->sub.marker = 0;       /* can try inflateSync */
        break;
      }
      if (r == Z_OK)
        r = f;
#ifdef __ECOS__
      if (z->state->gz_mode != DONE)
        z->state->gz_sum = cyg_ether_crc32_accumulate(z->state->gz_sum,
                                                      z->state->gz_start,
                                                      z->next_out - 
                                                      z->state->gz_start);
#endif
      if (r != Z_STREAM_END)
        return r;
      r = f;
      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;

#ifdef __ECOS__
      if (z->state->gz_mode != DONE) {
          // Byte swap CRC since it is read in the opposite order as
          // written by gzip.
          unsigned long c = z->state->gz_sum;
          z->state->sub.check.was = (((c & 0xff000000) >> 24) | ((c & 0x00ff0000) >> 8)
                                     | ((c & 0x0000ff00) << 8) | ((c & 0x000000ff) << 24));
          
      }
#endif

      if (z->state->sub.check.was != z->state->sub.check.need)
      {
        z->state->mode = BAD;
        z->msg = (char*)"incorrect data check";
        z->state->sub.marker = 5;       /* can't try inflateSync */
        break;
      }
      Tracev((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;
  }
#ifdef NEED_DUMMY_RETURN
  return Z_STREAM_ERROR;  /* Some dumb compilers complain without this */
#endif
}


int ZEXPORT inflateSetDictionary(z, dictionary, dictLength)
z_streamp z;
const Bytef *dictionary;
uInt  dictLength;
{
  uInt length = dictLength;

  if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0)
    return Z_STREAM_ERROR;

  if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
  z->adler = 1L;

  if (length >= ((uInt)1<<z->state->wbits))
  {
    length = (1<<z->state->wbits)-1;
    dictionary += dictLength - length;
  }
  inflate_set_dictionary(z->state->blocks, dictionary, length);
  z->state->mode = BLOCKS;
  return Z_OK;
}


int ZEXPORT inflateSync(z)
z_streamp 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)
  {
    static const Byte mark[4] = {0, 0, 0xff, 0xff};
    if (*p == mark[m])
      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;
}


/* Returns true if inflate is currently at the end of a block generated
 * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
 * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
 * but removes the length bytes of the resulting empty stored block. When
 * decompressing, PPP checks that at the end of input packet, inflate is
 * waiting for these length bytes.
 */
int ZEXPORT inflateSyncPoint(z)
z_streamp z;
{
  if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
    return Z_STREAM_ERROR;
  return inflate_blocks_sync_point(z->state->blocks);
}

⌨️ 快捷键说明

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