Address Microsoft deprecation warnings.

This commit is contained in:
Mark Adler 2024-02-08 17:35:23 -08:00
parent 504403f3e4
commit 985a62d118
6 changed files with 25 additions and 13 deletions

View File

@ -23,7 +23,7 @@
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)
#else
# define SET_BINARY_MODE(file)
#endif

View File

@ -24,7 +24,7 @@
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)
#else
# define SET_BINARY_MODE(file)
#endif

View File

@ -20,7 +20,7 @@
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)
#else
# define SET_BINARY_MODE(file)
#endif

View File

@ -17,6 +17,10 @@
# define ZLIB_INTERNAL
#endif
#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include "zlib.h"
#ifdef STDC
@ -36,13 +40,14 @@
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
# include <io.h>
# include <sys/stat.h>
#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

17
gzlib.c
View File

@ -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);

View File

@ -39,7 +39,7 @@
# ifdef UNDER_CE
# include <stdlib.h>
# endif
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
# define SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)
#else
# define SET_BINARY_MODE(file)
#endif
@ -58,6 +58,10 @@
#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
# include <unix.h> /* for fileno */
#endif
#ifdef WIN32
# define fileno _fileno
# define unlink _unlink
#endif
#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
#ifndef WIN32 /* unlink already in stdio.h for WIN32 */