Skip to content

Commit fd5fe8b

Browse files
committed
Further address Microsoft deprecation warnings.
1 parent ceac32f commit fd5fe8b

File tree

7 files changed

+45
-29
lines changed

7 files changed

+45
-29
lines changed

Diff for: contrib/puff/pufftest.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616
testing, and causes pufftest to fail with not enough output space (-f does
1717
a write like -w, so -w is not required). */
1818

19+
#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
20+
# define _CRT_NONSTDC_NO_DEPRECATE
21+
#endif
22+
1923
#include <stdio.h>
2024
#include <stdlib.h>
2125
#include "puff.h"
2226

2327
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
2428
# include <fcntl.h>
2529
# 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)
2731
#else
2832
# define SET_BINARY_MODE(file)
2933
#endif

Diff for: examples/gznorm.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
// the data, so it is fast, but no advantage is gained from the history that
1111
// could be available across member boundaries.
1212

13+
#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
14+
# define _CRT_NONSTDC_NO_DEPRECATE
15+
#endif
16+
1317
#include <stdio.h> // fread, fwrite, putc, fflush, ferror, fprintf,
1418
// vsnprintf, stdout, stderr, NULL, FILE
1519
#include <stdlib.h> // malloc, free
@@ -24,7 +28,7 @@
2428
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
2529
# include <fcntl.h>
2630
# 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)
2832
#else
2933
# define SET_BINARY_MODE(file)
3034
#endif

Diff for: examples/zpipe.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
Avoid some compiler warnings for input and output buffers
1313
*/
1414

15+
#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
16+
# define _CRT_NONSTDC_NO_DEPRECATE
17+
#endif
18+
1519
#include <stdio.h>
1620
#include <string.h>
1721
#include <assert.h>
@@ -20,7 +24,7 @@
2024
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
2125
# include <fcntl.h>
2226
# 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)
2428
#else
2529
# define SET_BINARY_MODE(file)
2630
#endif

Diff for: gzguts.h

+3-8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
2121
# define _CRT_SECURE_NO_WARNINGS
2222
#endif
23+
#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
24+
# define _CRT_NONSTDC_NO_DEPRECATE
25+
#endif
2326

2427
#include <stdio.h>
2528
#include "zlib.h"
@@ -40,21 +43,13 @@
4043

4144
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
4245
# include <io.h>
43-
# include <share.h>
4446
# include <sys/stat.h>
4547
#endif
4648

4749
#if defined(_WIN32) && !defined(WIDECHAR)
4850
# define WIDECHAR
4951
#endif
5052

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-
5853
#ifdef NO_DEFLATE /* for compatibility with old definition */
5954
# define NO_GZCOMPRESS
6055
#endif

Diff for: gzlib.c

+15-13
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55

66
#include "gzguts.h"
77

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__)
913
# define LSEEK _lseeki64
10-
#else
11-
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
14+
#elif defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
1215
# define LSEEK lseek64
1316
#else
1417
# define LSEEK lseek
1518
#endif
16-
#endif
1719

1820
#if defined UNDER_CE
1921

@@ -52,8 +54,7 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
5254
msgbuf[chars] = 0;
5355
}
5456

55-
z_size_t len;
56-
wcstombs_s(&len, buf, sizeof(buf), msgbuf, chars + 1);
57+
wcstombs(buf, msgbuf, chars + 1); // assumes buf is big enough
5758
LocalFree(msgbuf);
5859
}
5960
else {
@@ -180,10 +181,8 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
180181

181182
/* save the path name for error messages */
182183
#ifdef WIDECHAR
183-
if (fd == -2) {
184-
if (wcstombs_s(&len, NULL, 0, path, 0) != 0)
185-
len = 0;
186-
}
184+
if (fd == -2)
185+
len = wcstombs(NULL, path, 0);
187186
else
188187
#endif
189188
len = strlen((const char *)path);
@@ -193,18 +192,21 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
193192
return NULL;
194193
}
195194
#ifdef WIDECHAR
196-
if (fd == -2)
195+
if (fd == -2) {
197196
if (len)
198-
wcstombs_s(&len, state->path, len + 1, path, len + 1);
197+
wcstombs(state->path, path, len + 1);
199198
else
200199
*(state->path) = 0;
200+
}
201201
else
202202
#endif
203+
{
203204
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
204205
(void)snprintf(state->path, len + 1, "%s", (const char *)path);
205206
#else
206207
strcpy(state->path, path);
207208
#endif
209+
}
208210

209211
/* compute the flags for open() */
210212
oflag =
@@ -232,7 +234,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
232234
state->fd = open((const char *)path, oflag, 0666);
233235
#ifdef WIDECHAR
234236
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);
236238
#endif
237239
else
238240
state->fd = fd;

Diff for: test/example.c

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
/* @(#) $Id$ */
77

8+
#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
9+
# define _CRT_SECURE_NO_WARNINGS
10+
#endif
11+
812
#include "zlib.h"
913
#include <stdio.h>
1014

Diff for: test/minigzip.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
# define _POSIX_C_SOURCE 200112L
2020
#endif
2121

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+
2229
#include "zlib.h"
2330
#include <stdio.h>
2431

@@ -39,7 +46,7 @@
3946
# ifdef UNDER_CE
4047
# include <stdlib.h>
4148
# endif
42-
# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)
49+
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
4350
#else
4451
# define SET_BINARY_MODE(file)
4552
#endif
@@ -58,10 +65,6 @@
5865
#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
5966
# include <unix.h> /* for fileno */
6067
#endif
61-
#ifdef WIN32
62-
# define fileno _fileno
63-
# define unlink _unlink
64-
#endif
6568

6669
#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
6770
#ifndef WIN32 /* unlink already in stdio.h for WIN32 */

0 commit comments

Comments
 (0)