aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2024-02-08 17:35:23 -0800
committerMark Adler <madler@alumni.caltech.edu>2024-02-08 18:45:49 -0800
commit985a62d11802b44d1d1049ddd692038923da6f0b (patch)
tree172b0f970c0922ee919f4b4a141798abcec25c2e
parent504403f3e468bca2dc85c055d96ad392e9c7aae0 (diff)
downloadzlib-985a62d11802b44d1d1049ddd692038923da6f0b.tar.gz
zlib-985a62d11802b44d1d1049ddd692038923da6f0b.tar.bz2
zlib-985a62d11802b44d1d1049ddd692038923da6f0b.zip
Address Microsoft deprecation warnings.
-rw-r--r--contrib/puff/pufftest.c2
-rw-r--r--examples/gznorm.c2
-rw-r--r--examples/zpipe.c2
-rw-r--r--gzguts.h9
-rw-r--r--gzlib.c17
-rw-r--r--test/minigzip.c6
6 files changed, 25 insertions, 13 deletions
diff --git a/contrib/puff/pufftest.c b/contrib/puff/pufftest.c
index 5f72ecc..328cb9f 100644
--- a/contrib/puff/pufftest.c
+++ b/contrib/puff/pufftest.c
@@ -23,7 +23,7 @@
23#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 23#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
24# include <fcntl.h> 24# include <fcntl.h>
25# include <io.h> 25# include <io.h>
26# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 26# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)
27#else 27#else
28# define SET_BINARY_MODE(file) 28# define SET_BINARY_MODE(file)
29#endif 29#endif
diff --git a/examples/gznorm.c b/examples/gznorm.c
index 68e0a0f..2a1dda8 100644
--- a/examples/gznorm.c
+++ b/examples/gznorm.c
@@ -24,7 +24,7 @@
24#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 24#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
25# include <fcntl.h> 25# include <fcntl.h>
26# include <io.h> 26# include <io.h>
27# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 27# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)
28#else 28#else
29# define SET_BINARY_MODE(file) 29# define SET_BINARY_MODE(file)
30#endif 30#endif
diff --git a/examples/zpipe.c b/examples/zpipe.c
index 83535d1..184fce5 100644
--- a/examples/zpipe.c
+++ b/examples/zpipe.c
@@ -20,7 +20,7 @@
20#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 20#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
21# include <fcntl.h> 21# include <fcntl.h>
22# include <io.h> 22# include <io.h>
23# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 23# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)
24#else 24#else
25# define SET_BINARY_MODE(file) 25# define SET_BINARY_MODE(file)
26#endif 26#endif
diff --git a/gzguts.h b/gzguts.h
index 074ec84..a909e33 100644
--- a/gzguts.h
+++ b/gzguts.h
@@ -17,6 +17,10 @@
17# define ZLIB_INTERNAL 17# define ZLIB_INTERNAL
18#endif 18#endif
19 19
20#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
21# define _CRT_SECURE_NO_WARNINGS
22#endif
23
20#include <stdio.h> 24#include <stdio.h>
21#include "zlib.h" 25#include "zlib.h"
22#ifdef STDC 26#ifdef STDC
@@ -36,13 +40,14 @@
36 40
37#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) 41#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
38# include <io.h> 42# include <io.h>
43# include <sys/stat.h>
39#endif 44#endif
40 45
41#if defined(_WIN32) 46#if defined(_WIN32) && !defined(WIDECHAR)
42# define WIDECHAR 47# define WIDECHAR
43#endif 48#endif
44 49
45#ifdef WINAPI_FAMILY 50#if defined(_WIN32) || defined(WINAPI_FAMILY)
46# define open _open 51# define open _open
47# define read _read 52# define read _read
48# define write _write 53# define write _write
diff --git a/gzlib.c b/gzlib.c
index 983153c..05a9ae5 100644
--- a/gzlib.c
+++ b/gzlib.c
@@ -52,7 +52,8 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
52 msgbuf[chars] = 0; 52 msgbuf[chars] = 0;
53 } 53 }
54 54
55 wcstombs(buf, msgbuf, chars + 1); 55 z_size_t len;
56 wcstombs_s(&len, buf, sizeof(buf), msgbuf, chars + 1);
56 LocalFree(msgbuf); 57 LocalFree(msgbuf);
57 } 58 }
58 else { 59 else {
@@ -180,8 +181,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
180 /* save the path name for error messages */ 181 /* save the path name for error messages */
181#ifdef WIDECHAR 182#ifdef WIDECHAR
182 if (fd == -2) { 183 if (fd == -2) {
183 len = wcstombs(NULL, path, 0); 184 if (wcstombs_s(&len, NULL, 0, path, 0) != 0)
184 if (len == (z_size_t)-1)
185 len = 0; 185 len = 0;
186 } 186 }
187 else 187 else
@@ -195,7 +195,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
195#ifdef WIDECHAR 195#ifdef WIDECHAR
196 if (fd == -2) 196 if (fd == -2)
197 if (len) 197 if (len)
198 wcstombs(state->path, path, len + 1); 198 wcstombs_s(&len, state->path, len + 1, path, len + 1);
199 else 199 else
200 *(state->path) = 0; 200 *(state->path) = 0;
201 else 201 else
@@ -228,11 +228,14 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
228 O_APPEND))); 228 O_APPEND)));
229 229
230 /* open the file with the appropriate flags (or just use fd) */ 230 /* open the file with the appropriate flags (or just use fd) */
231 state->fd = fd > -1 ? fd : ( 231 if (fd == -1)
232 state->fd = open((const char *)path, oflag, 0666);
232#ifdef WIDECHAR 233#ifdef WIDECHAR
233 fd == -2 ? _wopen(path, oflag, 0666) : 234 else if (fd == -2)
235 _wsopen_s(&state->fd, path, oflag, _SH_DENYNO, _S_IREAD | _S_IWRITE);
234#endif 236#endif
235 open((const char *)path, oflag, 0666)); 237 else
238 state->fd = fd;
236 if (state->fd == -1) { 239 if (state->fd == -1) {
237 free(state->path); 240 free(state->path);
238 free(state); 241 free(state);
diff --git a/test/minigzip.c b/test/minigzip.c
index aa787fc..d5173b5 100644
--- a/test/minigzip.c
+++ b/test/minigzip.c
@@ -39,7 +39,7 @@
39# ifdef UNDER_CE 39# ifdef UNDER_CE
40# include <stdlib.h> 40# include <stdlib.h>
41# endif 41# endif
42# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 42# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)
43#else 43#else
44# define SET_BINARY_MODE(file) 44# define SET_BINARY_MODE(file)
45#endif 45#endif
@@ -58,6 +58,10 @@
58#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 58#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
59# include <unix.h> /* for fileno */ 59# include <unix.h> /* for fileno */
60#endif 60#endif
61#ifdef WIN32
62# define fileno _fileno
63# define unlink _unlink
64#endif
61 65
62#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE) 66#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
63#ifndef WIN32 /* unlink already in stdio.h for WIN32 */ 67#ifndef WIN32 /* unlink already in stdio.h for WIN32 */