aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2024-02-09 16:42:36 -0800
committerMark Adler <madler@alumni.caltech.edu>2024-02-09 20:11:54 -0800
commitfd5fe8b17e27ab92dcc70ed4974915b8dbe2a553 (patch)
tree880202f45d75dbdbde30125ef59c320e3b909349
parentceac32f156c4d39bf991e1163223b8d910a258d3 (diff)
downloadzlib-fd5fe8b17e27ab92dcc70ed4974915b8dbe2a553.tar.gz
zlib-fd5fe8b17e27ab92dcc70ed4974915b8dbe2a553.tar.bz2
zlib-fd5fe8b17e27ab92dcc70ed4974915b8dbe2a553.zip
Further address Microsoft deprecation warnings.
-rw-r--r--contrib/puff/pufftest.c6
-rw-r--r--examples/gznorm.c6
-rw-r--r--examples/zpipe.c6
-rw-r--r--gzguts.h11
-rw-r--r--gzlib.c28
-rw-r--r--test/example.c4
-rw-r--r--test/minigzip.c13
7 files changed, 45 insertions, 29 deletions
diff --git a/contrib/puff/pufftest.c b/contrib/puff/pufftest.c
index 328cb9f..19230b9 100644
--- a/contrib/puff/pufftest.c
+++ b/contrib/puff/pufftest.c
@@ -16,6 +16,10 @@
16 testing, and causes pufftest to fail with not enough output space (-f does 16 testing, and causes pufftest to fail with not enough output space (-f does
17 a write like -w, so -w is not required). */ 17 a write like -w, so -w is not required). */
18 18
19#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
20# define _CRT_NONSTDC_NO_DEPRECATE
21#endif
22
19#include <stdio.h> 23#include <stdio.h>
20#include <stdlib.h> 24#include <stdlib.h>
21#include "puff.h" 25#include "puff.h"
@@ -23,7 +27,7 @@
23#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 27#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
24# include <fcntl.h> 28# include <fcntl.h>
25# include <io.h> 29# include <io.h>
26# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY) 30# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
27#else 31#else
28# define SET_BINARY_MODE(file) 32# define SET_BINARY_MODE(file)
29#endif 33#endif
diff --git a/examples/gznorm.c b/examples/gznorm.c
index 2a1dda8..e8d9b48 100644
--- a/examples/gznorm.c
+++ b/examples/gznorm.c
@@ -10,6 +10,10 @@
10// the data, so it is fast, but no advantage is gained from the history that 10// the data, so it is fast, but no advantage is gained from the history that
11// could be available across member boundaries. 11// could be available across member boundaries.
12 12
13#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
14# define _CRT_NONSTDC_NO_DEPRECATE
15#endif
16
13#include <stdio.h> // fread, fwrite, putc, fflush, ferror, fprintf, 17#include <stdio.h> // fread, fwrite, putc, fflush, ferror, fprintf,
14 // vsnprintf, stdout, stderr, NULL, FILE 18 // vsnprintf, stdout, stderr, NULL, FILE
15#include <stdlib.h> // malloc, free 19#include <stdlib.h> // malloc, free
@@ -24,7 +28,7 @@
24#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 28#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
25# include <fcntl.h> 29# include <fcntl.h>
26# include <io.h> 30# include <io.h>
27# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY) 31# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
28#else 32#else
29# define SET_BINARY_MODE(file) 33# define SET_BINARY_MODE(file)
30#endif 34#endif
diff --git a/examples/zpipe.c b/examples/zpipe.c
index 184fce5..51dec47 100644
--- a/examples/zpipe.c
+++ b/examples/zpipe.c
@@ -12,6 +12,10 @@
12 Avoid some compiler warnings for input and output buffers 12 Avoid some compiler warnings for input and output buffers
13 */ 13 */
14 14
15#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
16# define _CRT_NONSTDC_NO_DEPRECATE
17#endif
18
15#include <stdio.h> 19#include <stdio.h>
16#include <string.h> 20#include <string.h>
17#include <assert.h> 21#include <assert.h>
@@ -20,7 +24,7 @@
20#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 24#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
21# include <fcntl.h> 25# include <fcntl.h>
22# include <io.h> 26# include <io.h>
23# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY) 27# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
24#else 28#else
25# define SET_BINARY_MODE(file) 29# define SET_BINARY_MODE(file)
26#endif 30#endif
diff --git a/gzguts.h b/gzguts.h
index bd0a6fe..a6485ab 100644
--- a/gzguts.h
+++ b/gzguts.h
@@ -20,6 +20,9 @@
20#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS) 20#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
21# define _CRT_SECURE_NO_WARNINGS 21# define _CRT_SECURE_NO_WARNINGS
22#endif 22#endif
23#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
24# define _CRT_NONSTDC_NO_DEPRECATE
25#endif
23 26
24#include <stdio.h> 27#include <stdio.h>
25#include "zlib.h" 28#include "zlib.h"
@@ -40,7 +43,6 @@
40 43
41#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) 44#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
42# include <io.h> 45# include <io.h>
43# include <share.h>
44# include <sys/stat.h> 46# include <sys/stat.h>
45#endif 47#endif
46 48
@@ -48,13 +50,6 @@
48# define WIDECHAR 50# define WIDECHAR
49#endif 51#endif
50 52
51#if defined(_WIN32) || defined(WINAPI_FAMILY)
52# define open _open
53# define read _read
54# define write _write
55# define close _close
56#endif
57
58#ifdef NO_DEFLATE /* for compatibility with old definition */ 53#ifdef NO_DEFLATE /* for compatibility with old definition */
59# define NO_GZCOMPRESS 54# define NO_GZCOMPRESS
60#endif 55#endif
diff --git a/gzlib.c b/gzlib.c
index 05a9ae5..e485a27 100644
--- a/gzlib.c
+++ b/gzlib.c
@@ -5,15 +5,17 @@
5 5
6#include "gzguts.h" 6#include "gzguts.h"
7 7
8#if defined(_WIN32) && !defined(__BORLANDC__) 8#if defined(UNDER_CE)
9# define LSEEK _wcelseek
10#elif defined(__DJGPP__)
11# define LSEEK llseek
12#elif defined(_WIN32) && !defined(__BORLANDC__)
9# define LSEEK _lseeki64 13# define LSEEK _lseeki64
10#else 14#elif defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
11#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
12# define LSEEK lseek64 15# define LSEEK lseek64
13#else 16#else
14# define LSEEK lseek 17# define LSEEK lseek
15#endif 18#endif
16#endif
17 19
18#if defined UNDER_CE 20#if defined UNDER_CE
19 21
@@ -52,8 +54,7 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
52 msgbuf[chars] = 0; 54 msgbuf[chars] = 0;
53 } 55 }
54 56
55 z_size_t len; 57 wcstombs(buf, msgbuf, chars + 1); // assumes buf is big enough
56 wcstombs_s(&len, buf, sizeof(buf), msgbuf, chars + 1);
57 LocalFree(msgbuf); 58 LocalFree(msgbuf);
58 } 59 }
59 else { 60 else {
@@ -180,10 +181,8 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
180 181
181 /* save the path name for error messages */ 182 /* save the path name for error messages */
182#ifdef WIDECHAR 183#ifdef WIDECHAR
183 if (fd == -2) { 184 if (fd == -2)
184 if (wcstombs_s(&len, NULL, 0, path, 0) != 0) 185 len = wcstombs(NULL, path, 0);
185 len = 0;
186 }
187 else 186 else
188#endif 187#endif
189 len = strlen((const char *)path); 188 len = strlen((const char *)path);
@@ -193,18 +192,21 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
193 return NULL; 192 return NULL;
194 } 193 }
195#ifdef WIDECHAR 194#ifdef WIDECHAR
196 if (fd == -2) 195 if (fd == -2) {
197 if (len) 196 if (len)
198 wcstombs_s(&len, state->path, len + 1, path, len + 1); 197 wcstombs(state->path, path, len + 1);
199 else 198 else
200 *(state->path) = 0; 199 *(state->path) = 0;
200 }
201 else 201 else
202#endif 202#endif
203 {
203#if !defined(NO_snprintf) && !defined(NO_vsnprintf) 204#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
204 (void)snprintf(state->path, len + 1, "%s", (const char *)path); 205 (void)snprintf(state->path, len + 1, "%s", (const char *)path);
205#else 206#else
206 strcpy(state->path, path); 207 strcpy(state->path, path);
207#endif 208#endif
209 }
208 210
209 /* compute the flags for open() */ 211 /* compute the flags for open() */
210 oflag = 212 oflag =
@@ -232,7 +234,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
232 state->fd = open((const char *)path, oflag, 0666); 234 state->fd = open((const char *)path, oflag, 0666);
233#ifdef WIDECHAR 235#ifdef WIDECHAR
234 else if (fd == -2) 236 else if (fd == -2)
235 _wsopen_s(&state->fd, path, oflag, _SH_DENYNO, _S_IREAD | _S_IWRITE); 237 state->fd = _wopen(path, oflag, _S_IREAD | _S_IWRITE);
236#endif 238#endif
237 else 239 else
238 state->fd = fd; 240 state->fd = fd;
diff --git a/test/example.c b/test/example.c
index e9cb806..d22e5f4 100644
--- a/test/example.c
+++ b/test/example.c
@@ -5,6 +5,10 @@
5 5
6/* @(#) $Id$ */ 6/* @(#) $Id$ */
7 7
8#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
9# define _CRT_SECURE_NO_WARNINGS
10#endif
11
8#include "zlib.h" 12#include "zlib.h"
9#include <stdio.h> 13#include <stdio.h>
10 14
diff --git a/test/minigzip.c b/test/minigzip.c
index ec86e3f..541f371 100644
--- a/test/minigzip.c
+++ b/test/minigzip.c
@@ -19,6 +19,13 @@
19# define _POSIX_C_SOURCE 200112L 19# define _POSIX_C_SOURCE 200112L
20#endif 20#endif
21 21
22#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
23# define _CRT_SECURE_NO_WARNINGS
24#endif
25#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
26# define _CRT_NONSTDC_NO_DEPRECATE
27#endif
28
22#include "zlib.h" 29#include "zlib.h"
23#include <stdio.h> 30#include <stdio.h>
24 31
@@ -39,7 +46,7 @@
39# ifdef UNDER_CE 46# ifdef UNDER_CE
40# include <stdlib.h> 47# include <stdlib.h>
41# endif 48# endif
42# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY) 49# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
43#else 50#else
44# define SET_BINARY_MODE(file) 51# define SET_BINARY_MODE(file)
45#endif 52#endif
@@ -58,10 +65,6 @@
58#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 65#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
59# include <unix.h> /* for fileno */ 66# include <unix.h> /* for fileno */
60#endif 67#endif
61#ifdef WIN32
62# define fileno _fileno
63# define unlink _unlink
64#endif
65 68
66#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE) 69#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
67#ifndef WIN32 /* unlink already in stdio.h for WIN32 */ 70#ifndef WIN32 /* unlink already in stdio.h for WIN32 */