summaryrefslogtreecommitdiffstats
path: root/compat/zlib/gzlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'compat/zlib/gzlib.c')
-rw-r--r--compat/zlib/gzlib.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/compat/zlib/gzlib.c b/compat/zlib/gzlib.c
index fae202e..a87d3d1 100644
--- a/compat/zlib/gzlib.c
+++ b/compat/zlib/gzlib.c
@@ -1,11 +1,11 @@
/* gzlib.c -- zlib functions common to reading and writing gzip files
- * Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler
+ * Copyright (C) 2004, 2010, 2011, 2012, 2013, 2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "gzguts.h"
-#if defined(_WIN32) && !defined(__BORLANDC__)
+#if defined(_WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__)
# define LSEEK _lseeki64
#else
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
@@ -94,7 +94,7 @@ local gzFile gz_open(path, fd, mode)
const char *mode;
{
gz_statep state;
- size_t len;
+ z_size_t len;
int oflag;
#ifdef O_CLOEXEC
int cloexec = 0;
@@ -188,10 +188,10 @@ local gzFile gz_open(path, fd, mode)
}
/* save the path name for error messages */
-#ifdef _WIN32
+#ifdef WIDECHAR
if (fd == -2) {
len = wcstombs(NULL, path, 0);
- if (len == (size_t)-1)
+ if (len == (z_size_t)-1)
len = 0;
}
else
@@ -202,7 +202,7 @@ local gzFile gz_open(path, fd, mode)
free(state);
return NULL;
}
-#ifdef _WIN32
+#ifdef WIDECHAR
if (fd == -2)
if (len)
wcstombs(state->path, path, len + 1);
@@ -239,7 +239,7 @@ local gzFile gz_open(path, fd, mode)
/* open the file with the appropriate flags (or just use fd) */
state->fd = fd > -1 ? fd : (
-#ifdef _WIN32
+#ifdef WIDECHAR
fd == -2 ? _wopen(path, oflag, 0666) :
#endif
open((const char *)path, oflag, 0666));
@@ -248,8 +248,10 @@ local gzFile gz_open(path, fd, mode)
free(state);
return NULL;
}
- if (state->mode == GZ_APPEND)
+ if (state->mode == GZ_APPEND) {
+ LSEEK(state->fd, 0, SEEK_END); /* so gzoffset() is correct */
state->mode = GZ_WRITE; /* simplify later checks */
+ }
/* save the current position for rewinding (only if reading) */
if (state->mode == GZ_READ) {
@@ -301,7 +303,7 @@ gzFile ZEXPORT gzdopen(fd, mode)
}
/* -- see zlib.h -- */
-#ifdef _WIN32
+#ifdef WIDECHAR
gzFile ZEXPORT gzopen_w(path, mode)
const wchar_t *path;
const char *mode;
@@ -329,6 +331,8 @@ int ZEXPORT gzbuffer(file, size)
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;
@@ -611,7 +615,6 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
strcat(state->msg, ": ");
strcat(state->msg, msg);
#endif
- return;
}
#ifndef INT_MAX