Skip to content

Commit

Permalink
Further address Microsoft deprecation warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
madler committed Feb 10, 2024
1 parent ceac32f commit fd5fe8b
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 29 deletions.
6 changes: 5 additions & 1 deletion contrib/puff/pufftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
testing, and causes pufftest to fail with not enough output space (-f does
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 <stdlib.h>
#include "puff.h"

#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
Expand Down
6 changes: 5 additions & 1 deletion examples/gznorm.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
// the data, so it is fast, but no advantage is gained from the history that
// 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,
// vsnprintf, stdout, stderr, NULL, FILE
#include <stdlib.h> // malloc, free
Expand All @@ -24,7 +28,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
Expand Down
6 changes: 5 additions & 1 deletion examples/zpipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
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 <string.h>
#include <assert.h>
Expand All @@ -20,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
Expand Down
11 changes: 3 additions & 8 deletions gzguts.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#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 <stdio.h>
#include "zlib.h"
Expand All @@ -40,21 +43,13 @@

#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
# include <io.h>
# include <share.h>
# include <sys/stat.h>
#endif

#if defined(_WIN32) && !defined(WIDECHAR)
# define WIDECHAR
#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 */
# define NO_GZCOMPRESS
#endif
Expand Down
28 changes: 15 additions & 13 deletions gzlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@

#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
#else
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
#elif defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
# define LSEEK lseek64
#else
# define LSEEK lseek
#endif
#endif

#if defined UNDER_CE

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

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

/* save the path name for error messages */
#ifdef WIDECHAR
if (fd == -2) {
if (wcstombs_s(&len, NULL, 0, path, 0) != 0)
len = 0;
}
if (fd == -2)
len = wcstombs(NULL, path, 0);
else
#endif
len = strlen((const char *)path);
Expand All @@ -193,18 +192,21 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
return NULL;
}
#ifdef WIDECHAR
if (fd == -2)
if (fd == -2) {
if (len)
wcstombs_s(&len, state->path, len + 1, path, len + 1);
wcstombs(state->path, path, len + 1);
else
*(state->path) = 0;
}
else
#endif
{
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
(void)snprintf(state->path, len + 1, "%s", (const char *)path);
#else
strcpy(state->path, path);
#endif
}

/* compute the flags for open() */
oflag =
Expand Down Expand Up @@ -232,7 +234,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
state->fd = open((const char *)path, oflag, 0666);
#ifdef WIDECHAR
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
else
state->fd = fd;
Expand Down
4 changes: 4 additions & 0 deletions test/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

/* @(#) $Id$ */

#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS
#endif

#include "zlib.h"
#include <stdio.h>

Expand Down
13 changes: 8 additions & 5 deletions test/minigzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
# define _POSIX_C_SOURCE 200112L
#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 <stdio.h>

Expand All @@ -39,7 +46,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
Expand All @@ -58,10 +65,6 @@
#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 */
Expand Down

0 comments on commit fd5fe8b

Please sign in to comment.