< prev index next >

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

Print this page
@@ -27,29 +27,16 @@
   * For conditions of distribution and use, see copyright notice in zlib.h
   */
  
  #include "gzguts.h"
  
- /* Local functions */
- local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
- local int gz_avail OF((gz_statep));
- local int gz_look OF((gz_statep));
- local int gz_decomp OF((gz_statep));
- local int gz_fetch OF((gz_statep));
- local int gz_skip OF((gz_statep, z_off64_t));
- local z_size_t gz_read OF((gz_statep, voidp, z_size_t));
- 
  /* Use read() to load a buffer -- return -1 on error, otherwise 0.  Read from
     state->fd, and update state->eof, state->err, and state->msg as appropriate.
     This function needs to loop on read(), since read() is not guaranteed to
     read the number of bytes requested, depending on the type of descriptor. */
- local int gz_load(state, buf, len, have)
-     gz_statep state;
-     unsigned char *buf;
-     unsigned len;
-     unsigned *have;
- {
+ local int gz_load(gz_statep state, unsigned char *buf, unsigned len,
+                   unsigned *have) {
      int ret;
      unsigned get, max = ((unsigned)-1 >> 2) + 1;
  
      *have = 0;
      do {

@@ -75,13 +62,11 @@
     file is reached, even though there may be unused data in the buffer.  Once
     that data has been used, no more attempts will be made to read the file.
     If strm->avail_in != 0, then the current data is moved to the beginning of
     the input buffer, and then the remainder of the buffer is loaded with the
     available data from the input file. */
- local int gz_avail(state)
-     gz_statep state;
- {
+ local int gz_avail(gz_statep state) {
      unsigned got;
      z_streamp strm = &(state->strm);
  
      if (state->err != Z_OK && state->err != Z_BUF_ERROR)
          return -1;

@@ -110,13 +95,11 @@
     be set to GZIP for decompression.  If direct copying, then leftover input
     data from the input buffer will be copied to the output buffer.  In that
     case, all further file reads will be directly to either the output buffer or
     a user buffer.  If decompressing, the inflate state will be initialized.
     gz_look() will return 0 on success or -1 on failure. */
- local int gz_look(state)
-     gz_statep state;
- {
+ local int gz_look(gz_statep state) {
      z_streamp strm = &(state->strm);
  
      /* allocate read buffers and inflate memory */
      if (state->size == 0) {
          /* allocate buffers */

@@ -192,13 +175,11 @@
  /* Decompress from input to the provided next_out and avail_out in the state.
     On return, state->x.have and state->x.next point to the just decompressed
     data.  If the gzip stream completes, state->how is reset to LOOK to look for
     the next gzip stream or raw data, once state->x.have is depleted.  Returns 0
     on success, -1 on failure. */
- local int gz_decomp(state)
-     gz_statep state;
- {
+ local int gz_decomp(gz_statep state) {
      int ret = Z_OK;
      unsigned had;
      z_streamp strm = &(state->strm);
  
      /* fill output buffer up to end of deflate stream */

@@ -246,13 +227,11 @@
     Data is either copied from the input file or decompressed from the input
     file depending on state->how.  If state->how is LOOK, then a gzip header is
     looked for to determine whether to copy or decompress.  Returns -1 on error,
     otherwise 0.  gz_fetch() will leave state->how as COPY or GZIP unless the
     end of the input file has been reached and all data has been processed.  */
- local int gz_fetch(state)
-     gz_statep state;
- {
+ local int gz_fetch(gz_statep state) {
      z_streamp strm = &(state->strm);
  
      do {
          switch(state->how) {
          case LOOK:      /* -> LOOK, COPY (only if never GZIP), or GZIP */

@@ -276,14 +255,11 @@
      } while (state->x.have == 0 && (!state->eof || strm->avail_in));
      return 0;
  }
  
  /* Skip len uncompressed bytes of output.  Return -1 on error, 0 on success. */
- local int gz_skip(state, len)
-     gz_statep state;
-     z_off64_t len;
- {
+ local int gz_skip(gz_statep state, z_off64_t len) {
      unsigned n;
  
      /* skip over len bytes or reach end-of-file, whichever comes first */
      while (len)
          /* skip over whatever is in output buffer */

@@ -311,15 +287,11 @@
  
  /* Read len bytes into buf from file, or less than len up to the end of the
     input.  Return the number of bytes read.  If zero is returned, either the
     end of file was reached, or there was an error.  state->err must be
     consulted in that case to determine which. */
- local z_size_t gz_read(state, buf, len)
-     gz_statep state;
-     voidp buf;
-     z_size_t len;
- {
+ local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) {
      z_size_t got;
      unsigned n;
  
      /* if len is zero, avoid unnecessary operations */
      if (len == 0)

@@ -392,15 +364,11 @@
      /* return number of bytes read into user buffer */
      return got;
  }
  
  /* -- see zlib.h -- */
- int ZEXPORT gzread(file, buf, len)
-     gzFile file;
-     voidp buf;
-     unsigned len;
- {
+ int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) {
      gz_statep state;
  
      /* get internal structure */
      if (file == NULL)
          return -1;

@@ -428,16 +396,11 @@
      /* return the number of bytes read (this is assured to fit in an int) */
      return (int)len;
  }
  
  /* -- see zlib.h -- */
- z_size_t ZEXPORT gzfread(buf, size, nitems, file)
-     voidp buf;
-     z_size_t size;
-     z_size_t nitems;
-     gzFile file;
- {
+ z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, gzFile file) {
      z_size_t len;
      gz_statep state;
  
      /* get internal structure */
      if (file == NULL)

@@ -464,13 +427,11 @@
  #ifdef Z_PREFIX_SET
  #  undef z_gzgetc
  #else
  #  undef gzgetc
  #endif
- int ZEXPORT gzgetc(file)
-     gzFile file;
- {
+ int ZEXPORT gzgetc(gzFile file) {
      unsigned char buf[1];
      gz_statep state;
  
      /* get internal structure */
      if (file == NULL)

@@ -491,28 +452,27 @@
  
      /* nothing there -- try gz_read() */
      return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
  }
  
- int ZEXPORT gzgetc_(file)
- gzFile file;
- {
+ int ZEXPORT gzgetc_(gzFile file) {
      return gzgetc(file);
  }
  
  /* -- see zlib.h -- */
- int ZEXPORT gzungetc(c, file)
-     int c;
-     gzFile file;
- {
+ int ZEXPORT gzungetc(int c, gzFile file) {
      gz_statep state;
  
      /* get internal structure */
      if (file == NULL)
          return -1;
      state = (gz_statep)file;
  
+     /* in case this was just opened, set up the input buffer */
+     if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
+         (void)gz_look(state);
+ 
      /* check that we're reading and that there's no (serious) error */
      if (state->mode != GZ_READ ||
          (state->err != Z_OK && state->err != Z_BUF_ERROR))
          return -1;
  

@@ -558,15 +518,11 @@
      state->past = 0;
      return c;
  }
  
  /* -- see zlib.h -- */
- char * ZEXPORT gzgets(file, buf, len)
-     gzFile file;
-     char *buf;
-     int len;
- {
+ char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
      unsigned left, n;
      char *str;
      unsigned char *eol;
      gz_statep state;
  

@@ -622,13 +578,11 @@
      buf[0] = 0;
      return str;
  }
  
  /* -- see zlib.h -- */
- int ZEXPORT gzdirect(file)
-     gzFile file;
- {
+ int ZEXPORT gzdirect(gzFile file) {
      gz_statep state;
  
      /* get internal structure */
      if (file == NULL)
          return 0;

@@ -642,13 +596,11 @@
      /* return 1 if transparent, 0 if processing a gzip stream */
      return state->direct;
  }
  
  /* -- see zlib.h -- */
- int ZEXPORT gzclose_r(file)
-     gzFile file;
- {
+ int ZEXPORT gzclose_r(gzFile file) {
      int ret, err;
      gz_statep state;
  
      /* get internal structure */
      if (file == NULL)
< prev index next >