From: tb Date: Fri, 9 Feb 2024 09:53:05 +0000 (+0000) Subject: zlib: sync with upstream X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=84324f4408d1d0e4985134e43b61c121b6e6896e;p=openbsd zlib: sync with upstream --- diff --git a/lib/libz/gzguts.h b/lib/libz/gzguts.h index 074ec84ec49..a909e3378af 100644 --- a/lib/libz/gzguts.h +++ b/lib/libz/gzguts.h @@ -17,6 +17,10 @@ # define ZLIB_INTERNAL #endif +#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS) +# define _CRT_SECURE_NO_WARNINGS +#endif + #include #include "zlib.h" #ifdef STDC @@ -36,13 +40,14 @@ #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) # include +# include #endif -#if defined(_WIN32) +#if defined(_WIN32) && !defined(WIDECHAR) # define WIDECHAR #endif -#ifdef WINAPI_FAMILY +#if defined(_WIN32) || defined(WINAPI_FAMILY) # define open _open # define read _read # define write _write diff --git a/lib/libz/gzlib.c b/lib/libz/gzlib.c index 983153cc8e4..05a9ae519b5 100644 --- a/lib/libz/gzlib.c +++ b/lib/libz/gzlib.c @@ -52,7 +52,8 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error) { msgbuf[chars] = 0; } - wcstombs(buf, msgbuf, chars + 1); + z_size_t len; + wcstombs_s(&len, buf, sizeof(buf), msgbuf, chars + 1); LocalFree(msgbuf); } else { @@ -180,8 +181,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { /* save the path name for error messages */ #ifdef WIDECHAR if (fd == -2) { - len = wcstombs(NULL, path, 0); - if (len == (z_size_t)-1) + if (wcstombs_s(&len, NULL, 0, path, 0) != 0) len = 0; } else @@ -195,7 +195,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { #ifdef WIDECHAR if (fd == -2) if (len) - wcstombs(state->path, path, len + 1); + wcstombs_s(&len, state->path, len + 1, path, len + 1); else *(state->path) = 0; else @@ -228,11 +228,14 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { O_APPEND))); /* open the file with the appropriate flags (or just use fd) */ - state->fd = fd > -1 ? fd : ( + if (fd == -1) + state->fd = open((const char *)path, oflag, 0666); #ifdef WIDECHAR - fd == -2 ? _wopen(path, oflag, 0666) : + else if (fd == -2) + _wsopen_s(&state->fd, path, oflag, _SH_DENYNO, _S_IREAD | _S_IWRITE); #endif - open((const char *)path, oflag, 0666)); + else + state->fd = fd; if (state->fd == -1) { free(state->path); free(state);