< prev index next >

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

Print this page
*** 21,11 ***
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  
  /* gzlib.c -- zlib functions common to reading and writing gzip files
!  * Copyright (C) 2004-2019 Mark Adler
   * For conditions of distribution and use, see copyright notice in zlib.h
   */
  
  #include "gzguts.h"
  
--- 21,11 ---
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  
  /* gzlib.c -- zlib functions common to reading and writing gzip files
!  * Copyright (C) 2004-2024 Mark Adler
   * For conditions of distribution and use, see copyright notice in zlib.h
   */
  
  #include "gzguts.h"
  

*** 37,14 ***
  #else
  #  define LSEEK lseek
  #endif
  #endif
  
- /* Local functions */
- local void gz_reset OF((gz_statep));
- local gzFile gz_open OF((const void *, int, const char *));
- 
  #if defined UNDER_CE
  
  /* Map the Windows error number in ERROR to a locale-dependent error message
     string and return a pointer to it.  Typically, the values for ERROR come
     from GetLastError.
--- 37,10 ---

*** 52,13 ***
     The string pointed to shall not be modified by the application, but may be
     overwritten by a subsequent call to gz_strwinerror
  
     The gz_strwinerror function does not change the current setting of
     GetLastError. */
! char ZLIB_INTERNAL *gz_strwinerror(error)
-      DWORD error;
- {
      static char buf[1024];
  
      wchar_t *msgbuf;
      DWORD lasterr = GetLastError();
      DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
--- 48,11 ---
     The string pointed to shall not be modified by the application, but may be
     overwritten by a subsequent call to gz_strwinerror
  
     The gz_strwinerror function does not change the current setting of
     GetLastError. */
! char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
      static char buf[1024];
  
      wchar_t *msgbuf;
      DWORD lasterr = GetLastError();
      DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM

*** 94,13 ***
  }
  
  #endif /* UNDER_CE */
  
  /* Reset gzip file state */
! local void gz_reset(state)
-     gz_statep state;
- {
      state->x.have = 0;              /* no output data available */
      if (state->mode == GZ_READ) {   /* for reading ... */
          state->eof = 0;             /* not at end of file */
          state->past = 0;            /* have not read past end yet */
          state->how = LOOK;          /* look for gzip header */
--- 88,11 ---
  }
  
  #endif /* UNDER_CE */
  
  /* Reset gzip file state */
! local void gz_reset(gz_statep state) {
      state->x.have = 0;              /* no output data available */
      if (state->mode == GZ_READ) {   /* for reading ... */
          state->eof = 0;             /* not at end of file */
          state->past = 0;            /* have not read past end yet */
          state->how = LOOK;          /* look for gzip header */

*** 112,15 ***
      state->x.pos = 0;               /* no uncompressed data yet */
      state->strm.avail_in = 0;       /* no input data yet */
  }
  
  /* Open a gzip file either by name or file descriptor. */
! local gzFile gz_open(path, fd, mode)
-     const void *path;
-     int fd;
-     const char *mode;
- {
      gz_statep state;
      z_size_t len;
      int oflag;
  #ifdef O_CLOEXEC
      int cloexec = 0;
--- 104,11 ---
      state->x.pos = 0;               /* no uncompressed data yet */
      state->strm.avail_in = 0;       /* no input data yet */
  }
  
  /* Open a gzip file either by name or file descriptor. */
! local gzFile gz_open(const void *path, int fd, const char *mode) {
      gz_statep state;
      z_size_t len;
      int oflag;
  #ifdef O_CLOEXEC
      int cloexec = 0;

*** 291,30 ***
      /* return stream */
      return (gzFile)state;
  }
  
  /* -- see zlib.h -- */
! gzFile ZEXPORT gzopen(path, mode)
-     const char *path;
-     const char *mode;
- {
      return gz_open(path, -1, mode);
  }
  
  /* -- see zlib.h -- */
! gzFile ZEXPORT gzopen64(path, mode)
-     const char *path;
-     const char *mode;
- {
      return gz_open(path, -1, mode);
  }
  
  /* -- see zlib.h -- */
! gzFile ZEXPORT gzdopen(fd, mode)
-     int fd;
-     const char *mode;
- {
      char *path;         /* identifier for error messages */
      gzFile gz;
  
      if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
          return NULL;
--- 279,21 ---
      /* return stream */
      return (gzFile)state;
  }
  
  /* -- see zlib.h -- */
! gzFile ZEXPORT gzopen(const char *path, const char *mode) {
      return gz_open(path, -1, mode);
  }
  
  /* -- see zlib.h -- */
! gzFile ZEXPORT gzopen64(const char *path, const char *mode) {
      return gz_open(path, -1, mode);
  }
  
  /* -- see zlib.h -- */
! gzFile ZEXPORT gzdopen(int fd, const char *mode) {
      char *path;         /* identifier for error messages */
      gzFile gz;
  
      if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
          return NULL;

*** 328,23 ***
      return gz;
  }
  
  /* -- see zlib.h -- */
  #ifdef WIDECHAR
! gzFile ZEXPORT gzopen_w(path, mode)
-     const wchar_t *path;
-     const char *mode;
- {
      return gz_open(path, -2, mode);
  }
  #endif
  
  /* -- see zlib.h -- */
! int ZEXPORT gzbuffer(file, size)
-     gzFile file;
-     unsigned size;
- {
      gz_statep state;
  
      /* get internal structure and check integrity */
      if (file == NULL)
          return -1;
--- 307,17 ---
      return gz;
  }
  
  /* -- see zlib.h -- */
  #ifdef WIDECHAR
! gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode) {
      return gz_open(path, -2, mode);
  }
  #endif
  
  /* -- see zlib.h -- */
! int ZEXPORT gzbuffer(gzFile file, unsigned size) {
      gz_statep state;
  
      /* get internal structure and check integrity */
      if (file == NULL)
          return -1;

*** 357,20 ***
          return -1;
  
      /* check and set requested size */
      if ((size << 1) < size)
          return -1;              /* need to be able to double it */
!     if (size < 2)
!         size = 2;               /* need two bytes to check magic header */
      state->want = size;
      return 0;
  }
  
  /* -- see zlib.h -- */
! int ZEXPORT gzrewind(file)
-     gzFile file;
- {
      gz_statep state;
  
      /* get internal structure */
      if (file == NULL)
          return -1;
--- 330,18 ---
          return -1;
  
      /* check and set requested size */
      if ((size << 1) < size)
          return -1;              /* need to be able to double it */
!     if (size < 8)
!         size = 8;               /* needed to behave well with flushing */
      state->want = size;
      return 0;
  }
  
  /* -- see zlib.h -- */
! int ZEXPORT gzrewind(gzFile file) {
      gz_statep state;
  
      /* get internal structure */
      if (file == NULL)
          return -1;

*** 387,15 ***
      gz_reset(state);
      return 0;
  }
  
  /* -- see zlib.h -- */
! z_off64_t ZEXPORT gzseek64(file, offset, whence)
-     gzFile file;
-     z_off64_t offset;
-     int whence;
- {
      unsigned n;
      z_off64_t ret;
      gz_statep state;
  
      /* get internal structure and check integrity */
--- 358,11 ---
      gz_reset(state);
      return 0;
  }
  
  /* -- see zlib.h -- */
! z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
      unsigned n;
      z_off64_t ret;
      gz_statep state;
  
      /* get internal structure and check integrity */

*** 464,25 ***
      }
      return state->x.pos + offset;
  }
  
  /* -- see zlib.h -- */
! z_off_t ZEXPORT gzseek(file, offset, whence)
-     gzFile file;
-     z_off_t offset;
-     int whence;
- {
      z_off64_t ret;
  
      ret = gzseek64(file, (z_off64_t)offset, whence);
      return ret == (z_off_t)ret ? (z_off_t)ret : -1;
  }
  
  /* -- see zlib.h -- */
! z_off64_t ZEXPORT gztell64(file)
-     gzFile file;
- {
      gz_statep state;
  
      /* get internal structure and check integrity */
      if (file == NULL)
          return -1;
--- 431,19 ---
      }
      return state->x.pos + offset;
  }
  
  /* -- see zlib.h -- */
! z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) {
      z_off64_t ret;
  
      ret = gzseek64(file, (z_off64_t)offset, whence);
      return ret == (z_off_t)ret ? (z_off_t)ret : -1;
  }
  
  /* -- see zlib.h -- */
! z_off64_t ZEXPORT gztell64(gzFile file) {
      gz_statep state;
  
      /* get internal structure and check integrity */
      if (file == NULL)
          return -1;

*** 493,23 ***
      /* return position */
      return state->x.pos + (state->seek ? state->skip : 0);
  }
  
  /* -- see zlib.h -- */
! z_off_t ZEXPORT gztell(file)
-     gzFile file;
- {
      z_off64_t ret;
  
      ret = gztell64(file);
      return ret == (z_off_t)ret ? (z_off_t)ret : -1;
  }
  
  /* -- see zlib.h -- */
! z_off64_t ZEXPORT gzoffset64(file)
-     gzFile file;
- {
      z_off64_t offset;
      gz_statep state;
  
      /* get internal structure and check integrity */
      if (file == NULL)
--- 454,19 ---
      /* return position */
      return state->x.pos + (state->seek ? state->skip : 0);
  }
  
  /* -- see zlib.h -- */
! z_off_t ZEXPORT gztell(gzFile file) {
      z_off64_t ret;
  
      ret = gztell64(file);
      return ret == (z_off_t)ret ? (z_off_t)ret : -1;
  }
  
  /* -- see zlib.h -- */
! z_off64_t ZEXPORT gzoffset64(gzFile file) {
      z_off64_t offset;
      gz_statep state;
  
      /* get internal structure and check integrity */
      if (file == NULL)

*** 526,23 ***
          offset -= state->strm.avail_in;     /* don't count buffered input */
      return offset;
  }
  
  /* -- see zlib.h -- */
! z_off_t ZEXPORT gzoffset(file)
-     gzFile file;
- {
      z_off64_t ret;
  
      ret = gzoffset64(file);
      return ret == (z_off_t)ret ? (z_off_t)ret : -1;
  }
  
  /* -- see zlib.h -- */
! int ZEXPORT gzeof(file)
-     gzFile file;
- {
      gz_statep state;
  
      /* get internal structure and check integrity */
      if (file == NULL)
          return 0;
--- 483,19 ---
          offset -= state->strm.avail_in;     /* don't count buffered input */
      return offset;
  }
  
  /* -- see zlib.h -- */
! z_off_t ZEXPORT gzoffset(gzFile file) {
      z_off64_t ret;
  
      ret = gzoffset64(file);
      return ret == (z_off_t)ret ? (z_off_t)ret : -1;
  }
  
  /* -- see zlib.h -- */
! int ZEXPORT gzeof(gzFile file) {
      gz_statep state;
  
      /* get internal structure and check integrity */
      if (file == NULL)
          return 0;

*** 553,14 ***
      /* return end-of-file state */
      return state->mode == GZ_READ ? state->past : 0;
  }
  
  /* -- see zlib.h -- */
! const char * ZEXPORT gzerror(file, errnum)
-     gzFile file;
-     int *errnum;
- {
      gz_statep state;
  
      /* get internal structure and check integrity */
      if (file == NULL)
          return NULL;
--- 506,11 ---
      /* return end-of-file state */
      return state->mode == GZ_READ ? state->past : 0;
  }
  
  /* -- see zlib.h -- */
! const char * ZEXPORT gzerror(gzFile file, int *errnum) {
      gz_statep state;
  
      /* get internal structure and check integrity */
      if (file == NULL)
          return NULL;

*** 574,13 ***
      return state->err == Z_MEM_ERROR ? "out of memory" :
                                         (state->msg == NULL ? "" : state->msg);
  }
  
  /* -- see zlib.h -- */
! void ZEXPORT gzclearerr(file)
-     gzFile file;
- {
      gz_statep state;
  
      /* get internal structure and check integrity */
      if (file == NULL)
          return;
--- 524,11 ---
      return state->err == Z_MEM_ERROR ? "out of memory" :
                                         (state->msg == NULL ? "" : state->msg);
  }
  
  /* -- see zlib.h -- */
! void ZEXPORT gzclearerr(gzFile file) {
      gz_statep state;
  
      /* get internal structure and check integrity */
      if (file == NULL)
          return;

*** 600,15 ***
     state->msg accordingly.  Free any previous error message already there.  Do
     not try to free or allocate space if the error is Z_MEM_ERROR (out of
     memory).  Simply save the error message as a static string.  If there is an
     allocation failure constructing the error message, then convert the error to
     out of memory. */
! void ZLIB_INTERNAL gz_error(state, err, msg)
-     gz_statep state;
-     int err;
-     const char *msg;
- {
      /* free previously allocated message and clear */
      if (state->msg != NULL) {
          if (state->err != Z_MEM_ERROR)
              free(state->msg);
          state->msg = NULL;
--- 548,11 ---
     state->msg accordingly.  Free any previous error message already there.  Do
     not try to free or allocate space if the error is Z_MEM_ERROR (out of
     memory).  Simply save the error message as a static string.  If there is an
     allocation failure constructing the error message, then convert the error to
     out of memory. */
! void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
      /* free previously allocated message and clear */
      if (state->msg != NULL) {
          if (state->err != Z_MEM_ERROR)
              free(state->msg);
          state->msg = NULL;

*** 641,23 ***
      strcat(state->msg, ": ");
      strcat(state->msg, msg);
  #endif
  }
  
- #ifndef INT_MAX
  /* portably return maximum value for an int (when limits.h presumed not
     available) -- we need to do this to cover cases where 2's complement not
     used, since C standard permits 1's complement and sign-bit representations,
     otherwise we could just use ((unsigned)-1) >> 1 */
! unsigned ZLIB_INTERNAL gz_intmax()
! {
!     unsigned p, q;
! 
!     p = 1;
      do {
          q = p;
          p <<= 1;
          p++;
      } while (p > q);
      return q >> 1;
- }
  #endif
--- 585,22 ---
      strcat(state->msg, ": ");
      strcat(state->msg, msg);
  #endif
  }
  
  /* portably return maximum value for an int (when limits.h presumed not
     available) -- we need to do this to cover cases where 2's complement not
     used, since C standard permits 1's complement and sign-bit representations,
     otherwise we could just use ((unsigned)-1) >> 1 */
! unsigned ZLIB_INTERNAL gz_intmax(void) {
! #ifdef INT_MAX
!     return INT_MAX;
! #else
!     unsigned p = 1, q;
      do {
          q = p;
          p <<= 1;
          p++;
      } while (p > q);
      return q >> 1;
  #endif
+ }
< prev index next >