From 312b32e050447be1b1dedb861e38c62093e0fe76 Mon Sep 17 00:00:00 2001 From: tb Date: Sat, 10 Feb 2024 06:10:04 +0000 Subject: [PATCH] libz: sync with upstream - fix type of local variable in deflate_stored() - more Windows compat shuffling - wrap overlong line in gzread --- lib/libz/deflate.c | 3 ++- lib/libz/gzguts.h | 11 +++-------- lib/libz/gzlib.c | 28 +++++++++++++++------------- lib/libz/gzread.c | 3 ++- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/libz/deflate.c b/lib/libz/deflate.c index 1f0004a700e..623119b1fb2 100644 --- a/lib/libz/deflate.c +++ b/lib/libz/deflate.c @@ -1631,7 +1631,8 @@ local block_state deflate_stored(deflate_state *s, int flush) { * possible. If flushing, copy the remaining available input to next_out as * stored blocks, if there is enough space. */ - unsigned len, left, have, last = 0; + int last = 0; + unsigned len, left, have; unsigned used = s->strm->avail_in; do { /* Set len to the maximum size block that we can copy directly with the diff --git a/lib/libz/gzguts.h b/lib/libz/gzguts.h index bd0a6fe2105..a6485ab7e9d 100644 --- a/lib/libz/gzguts.h +++ b/lib/libz/gzguts.h @@ -20,6 +20,9 @@ #if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS) # define _CRT_SECURE_NO_WARNINGS #endif +#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE) +# define _CRT_NONSTDC_NO_DEPRECATE +#endif #include #include "zlib.h" @@ -40,7 +43,6 @@ #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) # include -# include # include #endif @@ -48,13 +50,6 @@ # define WIDECHAR #endif -#if defined(_WIN32) || defined(WINAPI_FAMILY) -# define open _open -# define read _read -# define write _write -# define close _close -#endif - #ifdef NO_DEFLATE /* for compatibility with old definition */ # define NO_GZCOMPRESS #endif diff --git a/lib/libz/gzlib.c b/lib/libz/gzlib.c index 05a9ae519b5..e485a27bf6d 100644 --- a/lib/libz/gzlib.c +++ b/lib/libz/gzlib.c @@ -5,15 +5,17 @@ #include "gzguts.h" -#if defined(_WIN32) && !defined(__BORLANDC__) +#if defined(UNDER_CE) +# define LSEEK _wcelseek +#elif defined(__DJGPP__) +# define LSEEK llseek +#elif defined(_WIN32) && !defined(__BORLANDC__) # define LSEEK _lseeki64 -#else -#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 +#elif defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 # define LSEEK lseek64 #else # define LSEEK lseek #endif -#endif #if defined UNDER_CE @@ -52,8 +54,7 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error) { msgbuf[chars] = 0; } - z_size_t len; - wcstombs_s(&len, buf, sizeof(buf), msgbuf, chars + 1); + wcstombs(buf, msgbuf, chars + 1); // assumes buf is big enough LocalFree(msgbuf); } else { @@ -180,10 +181,8 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { /* save the path name for error messages */ #ifdef WIDECHAR - if (fd == -2) { - if (wcstombs_s(&len, NULL, 0, path, 0) != 0) - len = 0; - } + if (fd == -2) + len = wcstombs(NULL, path, 0); else #endif len = strlen((const char *)path); @@ -193,18 +192,21 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { return NULL; } #ifdef WIDECHAR - if (fd == -2) + if (fd == -2) { if (len) - wcstombs_s(&len, state->path, len + 1, path, len + 1); + wcstombs(state->path, path, len + 1); else *(state->path) = 0; + } else #endif + { #if !defined(NO_snprintf) && !defined(NO_vsnprintf) (void)snprintf(state->path, len + 1, "%s", (const char *)path); #else strcpy(state->path, path); #endif + } /* compute the flags for open() */ oflag = @@ -232,7 +234,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { state->fd = open((const char *)path, oflag, 0666); #ifdef WIDECHAR else if (fd == -2) - _wsopen_s(&state->fd, path, oflag, _SH_DENYNO, _S_IREAD | _S_IWRITE); + state->fd = _wopen(path, oflag, _S_IREAD | _S_IWRITE); #endif else state->fd = fd; diff --git a/lib/libz/gzread.c b/lib/libz/gzread.c index 4168cbc8875..2d4ca4290d7 100644 --- a/lib/libz/gzread.c +++ b/lib/libz/gzread.c @@ -374,7 +374,8 @@ int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) { } /* -- see zlib.h -- */ -z_size_t ZEXPORT gzfread(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; -- 2.20.1