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 @@ 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 #include #include "puff.h" @@ -23,7 +27,7 @@ #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) # include # include -# 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 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 @@ // 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 // fread, fwrite, putc, fflush, ferror, fprintf, // vsnprintf, stdout, stderr, NULL, FILE #include // malloc, free @@ -24,7 +28,7 @@ #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) # include # include -# 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 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 @@ Avoid some compiler warnings for input and output buffers */ +#if defined(_WIN32) && !defined(_CRT_NONSTDC_NO_DEPRECATE) +# define _CRT_NONSTDC_NO_DEPRECATE +#endif + #include #include #include @@ -20,7 +24,7 @@ #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) # include # include -# 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 diff --git a/gzguts.h b/gzguts.h index bd0a6fe..a6485ab 100644 --- a/gzguts.h +++ b/gzguts.h @@ -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 #include "zlib.h" @@ -40,7 +43,6 @@ #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) # include -# include # include #endif @@ -48,13 +50,6 @@ # 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 diff --git a/gzlib.c b/gzlib.c index 05a9ae5..e485a27 100644 --- a/gzlib.c +++ b/gzlib.c @@ -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 @@ -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 { @@ -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); @@ -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 = @@ -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; 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 @@ /* @(#) $Id$ */ +#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS) +# define _CRT_SECURE_NO_WARNINGS +#endif + #include "zlib.h" #include 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 @@ # 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 @@ -39,7 +46,7 @@ # ifdef UNDER_CE # include # 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,10 +65,6 @@ #if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os # include /* 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 */