< prev index next >

src/java.base/share/native/libzip/zlib/inflate.c

Print this page
@@ -113,24 +113,11 @@
  #  ifndef BUILDFIXED
  #    define BUILDFIXED
  #  endif
  #endif
  
- /* function prototypes */
- local int inflateStateCheck OF((z_streamp strm));
- local void fixedtables OF((struct inflate_state FAR *state));
- local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
-                            unsigned copy));
- #ifdef BUILDFIXED
-    void makefixed OF((void));
- #endif
- local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
-                               unsigned len));
- 
- local int inflateStateCheck(strm)
- z_streamp strm;
- {
+ local int inflateStateCheck(z_streamp strm) {
      struct inflate_state FAR *state;
      if (strm == Z_NULL ||
          strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
          return 1;
      state = (struct inflate_state FAR *)strm->state;

@@ -138,13 +125,11 @@
          state->mode < HEAD || state->mode > SYNC)
          return 1;
      return 0;
  }
  
- int ZEXPORT inflateResetKeep(strm)
- z_streamp strm;
- {
+ int ZEXPORT inflateResetKeep(z_streamp strm) {
      struct inflate_state FAR *state;
  
      if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
      state = (struct inflate_state FAR *)strm->state;
      strm->total_in = strm->total_out = state->total = 0;

@@ -164,27 +149,22 @@
      state->back = -1;
      Tracev((stderr, "inflate: reset\n"));
      return Z_OK;
  }
  
- int ZEXPORT inflateReset(strm)
- z_streamp strm;
- {
+ int ZEXPORT inflateReset(z_streamp strm) {
      struct inflate_state FAR *state;
  
      if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
      state = (struct inflate_state FAR *)strm->state;
      state->wsize = 0;
      state->whave = 0;
      state->wnext = 0;
      return inflateResetKeep(strm);
  }
  
- int ZEXPORT inflateReset2(strm, windowBits)
- z_streamp strm;
- int windowBits;
- {
+ int ZEXPORT inflateReset2(z_streamp strm, int windowBits) {
      int wrap;
      struct inflate_state FAR *state;
  
      /* get the state */
      if (inflateStateCheck(strm)) return Z_STREAM_ERROR;

@@ -217,16 +197,12 @@
      state->wrap = wrap;
      state->wbits = (unsigned)windowBits;
      return inflateReset(strm);
  }
  
- int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
- z_streamp strm;
- int windowBits;
- const char *version;
- int stream_size;
- {
+ int ZEXPORT inflateInit2_(z_streamp strm, int windowBits,
+                           const char *version, int stream_size) {
      int ret;
      struct inflate_state FAR *state;
  
      if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
          stream_size != (int)(sizeof(z_stream)))

@@ -261,26 +237,21 @@
          strm->state = Z_NULL;
      }
      return ret;
  }
  
- int ZEXPORT inflateInit_(strm, version, stream_size)
- z_streamp strm;
- const char *version;
- int stream_size;
- {
+ int ZEXPORT inflateInit_(z_streamp strm, const char *version,
+                          int stream_size) {
      return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  }
  
- int ZEXPORT inflatePrime(strm, bits, value)
- z_streamp strm;
- int bits;
- int value;
- {
+ int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) {
      struct inflate_state FAR *state;
  
      if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+     if (bits == 0)
+         return Z_OK;
      state = (struct inflate_state FAR *)strm->state;
      if (bits < 0) {
          state->hold = 0;
          state->bits = 0;
          return Z_OK;

@@ -300,13 +271,11 @@
     thereafter.  This reduces the size of the code by about 2K bytes, in
     exchange for a little execution time.  However, BUILDFIXED should not be
     used for threaded applications, since the rewriting of the tables and virgin
     may not be thread-safe.
   */
- local void fixedtables(state)
- struct inflate_state FAR *state;
- {
+ local void fixedtables(struct inflate_state FAR *state) {
  #ifdef BUILDFIXED
      static int virgin = 1;
      static code *lenfix, *distfix;
      static code fixed[544];
  

@@ -364,11 +333,11 @@
  
     Then that can be linked with zlib built with MAKEFIXED defined and run:
  
      a.out > inffixed.h
   */
- void makefixed()
+ void makefixed(void)
  {
      unsigned low, size;
      struct inflate_state state;
  
      fixedtables(&state);

@@ -418,15 +387,11 @@
     advantage, since only the last 32K of output is copied to the sliding window
     upon return from inflate(), and since all distances after the first 32K of
     output will fall in the output data, making match copies simpler and faster.
     The advantage may be dependent on the size of the processor's data caches.
   */
- local int updatewindow(strm, end, copy)
- z_streamp strm;
- const Bytef *end;
- unsigned copy;
- {
+ local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) {
      struct inflate_state FAR *state;
      unsigned dist;
  
      state = (struct inflate_state FAR *)strm->state;
  

@@ -644,14 +609,11 @@
     stream available.  So the only thing the flush parameter actually does is:
     when flush is set to Z_FINISH, inflate() cannot return Z_OK.  Instead it
     will return Z_BUF_ERROR if it has not reached the end of the stream.
   */
  
- int ZEXPORT inflate(strm, flush)
- z_streamp strm;
- int flush;
- {
+ int ZEXPORT inflate(z_streamp strm, int flush) {
      struct inflate_state FAR *state;
      z_const unsigned char FAR *next;    /* next input */
      unsigned char FAR *put;     /* next output */
      unsigned have, left;        /* available input and output */
      unsigned long hold;         /* bit buffer */

@@ -1323,13 +1285,11 @@
      if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
          ret = Z_BUF_ERROR;
      return ret;
  }
  
- int ZEXPORT inflateEnd(strm)
- z_streamp strm;
- {
+ int ZEXPORT inflateEnd(z_streamp strm) {
      struct inflate_state FAR *state;
      if (inflateStateCheck(strm))
          return Z_STREAM_ERROR;
      state = (struct inflate_state FAR *)strm->state;
      if (state->window != Z_NULL) ZFREE(strm, state->window);

@@ -1337,15 +1297,12 @@
      strm->state = Z_NULL;
      Tracev((stderr, "inflate: end\n"));
      return Z_OK;
  }
  
- int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength)
- z_streamp strm;
- Bytef *dictionary;
- uInt *dictLength;
- {
+ int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary,
+                                  uInt *dictLength) {
      struct inflate_state FAR *state;
  
      /* check state */
      if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
      state = (struct inflate_state FAR *)strm->state;

@@ -1360,15 +1317,12 @@
      if (dictLength != Z_NULL)
          *dictLength = state->whave;
      return Z_OK;
  }
  
- int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
- z_streamp strm;
- const Bytef *dictionary;
- uInt dictLength;
- {
+ int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
+                                  uInt dictLength) {
      struct inflate_state FAR *state;
      unsigned long dictid;
      int ret;
  
      /* check state */

@@ -1395,14 +1349,11 @@
      state->havedict = 1;
      Tracev((stderr, "inflate:   dictionary set\n"));
      return Z_OK;
  }
  
- int ZEXPORT inflateGetHeader(strm, head)
- z_streamp strm;
- gz_headerp head;
- {
+ int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) {
      struct inflate_state FAR *state;
  
      /* check state */
      if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
      state = (struct inflate_state FAR *)strm->state;

@@ -1423,15 +1374,12 @@
     pattern.  If *have is less than four, then the pattern has not been found
     yet and the return value is len.  In the latter case, syncsearch() can be
     called again with more data and the *have state.  *have is initialized to
     zero for the first call.
   */
- local unsigned syncsearch(have, buf, len)
- unsigned FAR *have;
- const unsigned char FAR *buf;
- unsigned len;
- {
+ local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf,
+                           unsigned len) {
      unsigned got;
      unsigned next;
  
      got = *have;
      next = 0;

@@ -1446,13 +1394,11 @@
      }
      *have = got;
      return next;
  }
  
- int ZEXPORT inflateSync(strm)
- z_streamp strm;
- {
+ int ZEXPORT inflateSync(z_streamp strm) {
      unsigned len;               /* number of bytes to look at or looked at */
      int flags;                  /* temporary to save header status */
      unsigned long in, out;      /* temporary to save total_in and total_out */
      unsigned char buf[4];       /* to restore bit buffer to byte string */
      struct inflate_state FAR *state;

@@ -1463,11 +1409,11 @@
      if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  
      /* if first time, start search in bit buffer */
      if (state->mode != SYNC) {
          state->mode = SYNC;
-         state->hold <<= state->bits & 7;
+         state->hold >>= state->bits & 7;
          state->bits -= state->bits & 7;
          len = 0;
          while (state->bits >= 8) {
              buf[len++] = (unsigned char)(state->hold);
              state->hold >>= 8;

@@ -1504,24 +1450,19 @@
     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(strm)
- z_streamp strm;
- {
+ int ZEXPORT inflateSyncPoint(z_streamp strm) {
      struct inflate_state FAR *state;
  
      if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
      state = (struct inflate_state FAR *)strm->state;
      return state->mode == STORED && state->bits == 0;
  }
  
- int ZEXPORT inflateCopy(dest, source)
- z_streamp dest;
- z_streamp source;
- {
+ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
      struct inflate_state FAR *state;
      struct inflate_state FAR *copy;
      unsigned char FAR *window;
      unsigned wsize;
  

@@ -1561,14 +1502,11 @@
      copy->window = window;
      dest->state = (struct internal_state FAR *)copy;
      return Z_OK;
  }
  
- int ZEXPORT inflateUndermine(strm, subvert)
- z_streamp strm;
- int subvert;
- {
+ int ZEXPORT inflateUndermine(z_streamp strm, int subvert) {
      struct inflate_state FAR *state;
  
      if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
      state = (struct inflate_state FAR *)strm->state;
  #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR

@@ -1579,14 +1517,11 @@
      state->sane = 1;
      return Z_DATA_ERROR;
  #endif
  }
  
- int ZEXPORT inflateValidate(strm, check)
- z_streamp strm;
- int check;
- {
+ int ZEXPORT inflateValidate(z_streamp strm, int check) {
      struct inflate_state FAR *state;
  
      if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
      state = (struct inflate_state FAR *)strm->state;
      if (check && state->wrap)

@@ -1594,26 +1529,22 @@
      else
          state->wrap &= ~4;
      return Z_OK;
  }
  
- long ZEXPORT inflateMark(strm)
- z_streamp strm;
- {
+ long ZEXPORT inflateMark(z_streamp strm) {
      struct inflate_state FAR *state;
  
      if (inflateStateCheck(strm))
          return -(1L << 16);
      state = (struct inflate_state FAR *)strm->state;
      return (long)(((unsigned long)((long)state->back)) << 16) +
          (state->mode == COPY ? state->length :
              (state->mode == MATCH ? state->was - state->length : 0));
  }
  
- unsigned long ZEXPORT inflateCodesUsed(strm)
- z_streamp strm;
- {
+ unsigned long ZEXPORT inflateCodesUsed(z_streamp strm) {
      struct inflate_state FAR *state;
      if (inflateStateCheck(strm)) return (unsigned long)-1;
      state = (struct inflate_state FAR *)strm->state;
      return (unsigned long)(state->next - state->codes);
  }
< prev index next >