Further address Microsoft deprecation warnings.

This commit is contained in:
Mark Adler 2024-02-09 16:42:36 -08:00
parent ceac32f156
commit fd5fe8b17e
7 changed files with 45 additions and 29 deletions

View File

@ -16,6 +16,10 @@
testing, and causes pufftest to fail with not enough output space (-f does testing, and causes pufftest to fail with not enough output space (-f does
a write like -w, so -w is not required). */ a write like -w, so -w is not required). */
#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
# define _CRT_NONSTDC_NO_DEPRECATE
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "puff.h" #include "puff.h"
@ -23,7 +27,7 @@
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h> # include <fcntl.h>
# include <io.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 #else
# define SET_BINARY_MODE(file) # define SET_BINARY_MODE(file)
#endif #endif

View File

@ -10,6 +10,10 @@
// the data, so it is fast, but no advantage is gained from the history that // the data, so it is fast, but no advantage is gained from the history that
// could be available across member boundaries. // could be available across member boundaries.
#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
# define _CRT_NONSTDC_NO_DEPRECATE
#endif
#include <stdio.h> // fread, fwrite, putc, fflush, ferror, fprintf, #include <stdio.h> // fread, fwrite, putc, fflush, ferror, fprintf,
// vsnprintf, stdout, stderr, NULL, FILE // vsnprintf, stdout, stderr, NULL, FILE
#include <stdlib.h> // malloc, free #include <stdlib.h> // malloc, free
@ -24,7 +28,7 @@
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h> # include <fcntl.h>
# include <io.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 #else
# define SET_BINARY_MODE(file) # define SET_BINARY_MODE(file)
#endif #endif

View File

@ -12,6 +12,10 @@
Avoid some compiler warnings for input and output buffers Avoid some compiler warnings for input and output buffers
*/ */
#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
# define _CRT_NONSTDC_NO_DEPRECATE
#endif
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
@ -20,7 +24,7 @@
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h> # include <fcntl.h>
# include <io.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 #else
# define SET_BINARY_MODE(file) # define SET_BINARY_MODE(file)
#endif #endif

View File

@ -20,6 +20,9 @@
#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS) #if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS # define _CRT_SECURE_NO_WARNINGS
#endif #endif
#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
# define _CRT_NONSTDC_NO_DEPRECATE
#endif
#include <stdio.h> #include <stdio.h>
#include "zlib.h" #include "zlib.h"
@ -40,7 +43,6 @@
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
# include <io.h> # include <io.h>
# include <share.h>
# include <sys/stat.h> # include <sys/stat.h>
#endif #endif
@ -48,13 +50,6 @@
# define WIDECHAR # define WIDECHAR
#endif #endif
#if defined(_WIN32) || defined(WINAPI_FAMILY)
# define open _open
# define read _read
# define write _write
# define close _close
#endif
#ifdef NO_DEFLATE /* for compatibility with old definition */ #ifdef NO_DEFLATE /* for compatibility with old definition */
# define NO_GZCOMPRESS # define NO_GZCOMPRESS
#endif #endif

28
gzlib.c
View File

@ -5,15 +5,17 @@
#include "gzguts.h" #include "gzguts.h"
#if defined(_WIN32) && !defined(__BORLANDC__) #if defined(UNDER_CE)
# define LSEEK _wcelseek
#elif defined(__DJGPP__)
# define LSEEK llseek
#elif defined(_WIN32) && !defined(__BORLANDC__)
# define LSEEK _lseeki64 # define LSEEK _lseeki64
#else #elif defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
# define LSEEK lseek64 # define LSEEK lseek64
#else #else
# define LSEEK lseek # define LSEEK lseek
#endif #endif
#endif
#if defined UNDER_CE #if defined UNDER_CE
@ -52,8 +54,7 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
msgbuf[chars] = 0; msgbuf[chars] = 0;
} }
z_size_t len; wcstombs(buf, msgbuf, chars + 1); // assumes buf is big enough
wcstombs_s(&len, buf, sizeof(buf), msgbuf, chars + 1);
LocalFree(msgbuf); LocalFree(msgbuf);
} }
else { else {
@ -180,10 +181,8 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
/* save the path name for error messages */ /* save the path name for error messages */
#ifdef WIDECHAR #ifdef WIDECHAR
if (fd == -2) { if (fd == -2)
if (wcstombs_s(&len, NULL, 0, path, 0) != 0) len = wcstombs(NULL, path, 0);
len = 0;
}
else else
#endif #endif
len = strlen((const char *)path); len = strlen((const char *)path);
@ -193,18 +192,21 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
return NULL; return NULL;
} }
#ifdef WIDECHAR #ifdef WIDECHAR
if (fd == -2) if (fd == -2) {
if (len) if (len)
wcstombs_s(&len, state->path, len + 1, path, len + 1); wcstombs(state->path, path, len + 1);
else else
*(state->path) = 0; *(state->path) = 0;
}
else else
#endif #endif
{
#if !defined(NO_snprintf) && !defined(NO_vsnprintf) #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
(void)snprintf(state->path, len + 1, "%s", (const char *)path); (void)snprintf(state->path, len + 1, "%s", (const char *)path);
#else #else
strcpy(state->path, path); strcpy(state->path, path);
#endif #endif
}
/* compute the flags for open() */ /* compute the flags for open() */
oflag = oflag =
@ -232,7 +234,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
state->fd = open((const char *)path, oflag, 0666); state->fd = open((const char *)path, oflag, 0666);
#ifdef WIDECHAR #ifdef WIDECHAR
else if (fd == -2) else if (fd == -2)
_wsopen_s(&state->fd, path, oflag, _SH_DENYNO, _S_IREAD | _S_IWRITE); state->fd = _wopen(path, oflag, _S_IREAD | _S_IWRITE);
#endif #endif
else else
state->fd = fd; state->fd = fd;

View File

@ -5,6 +5,10 @@
/* @(#) $Id$ */ /* @(#) $Id$ */
#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS
#endif
#include "zlib.h" #include "zlib.h"
#include <stdio.h> #include <stdio.h>

View File

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