From 6dfff29c01a99e1fe9238a405988874736961953 Mon Sep 17 00:00:00 2001 From: Pavel P Date: Mon, 20 Apr 2020 16:19:30 +0600 Subject: [PATCH] Clean up windows defines, use _WIN32 + replaced WIN32 with _WIN32 + removed unused WINDOWS/_WINDOWS defines + no need to test for __MINGW__, as _WIN32 is also defined --- gzguts.h | 9 +++------ gzlib.c | 4 ++-- test/fuzz/minigzip_fuzzer.c | 4 ++-- test/minigzip.c | 4 ++-- zconf-ng.h.in | 29 +++++++++++------------------ zconf.h.in | 29 +++++++++++------------------ zendian.h | 2 +- zlib-ng.h | 2 +- zlib.h | 2 +- zutil.h | 6 +++--- 10 files changed, 37 insertions(+), 54 deletions(-) diff --git a/gzguts.h b/gzguts.h index 83440d52..263bc9a0 100644 --- a/gzguts.h +++ b/gzguts.h @@ -34,7 +34,7 @@ # include "zlib-ng.h" #endif -#ifdef WIN32 +#ifdef _WIN32 # include #endif @@ -42,11 +42,8 @@ # include /* for lseek(), read(), close(), write(), unlink() */ #endif -#if defined(_MSC_VER) || defined(WIN32) +#if defined(_WIN32) # include -#endif - -#if defined(_WIN32) || defined(__MINGW__) # define WIDECHAR #endif @@ -58,7 +55,7 @@ #endif /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ -#if !defined(STDC99) && !defined(__CYGWIN__) && !defined(__MINGW__) && defined(WIN32) +#if !defined(STDC99) && !defined(__CYGWIN__) && !defined(__MINGW__) && defined(_WIN32) # if !defined(vsnprintf) # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) # define vsnprintf _vsnprintf diff --git a/gzlib.c b/gzlib.c index 56326ccc..9da7a113 100644 --- a/gzlib.c +++ b/gzlib.c @@ -6,7 +6,7 @@ #include "zbuild.h" #include "gzguts.h" -#if defined(WIN32) && !defined(__BORLANDC__) +#if defined(_WIN32) && !defined(__BORLANDC__) # define LSEEK _lseeki64 #else #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 @@ -181,7 +181,7 @@ static gzFile gz_open(const void *path, int fd, const char *mode) { /* open the file with the appropriate flags (or just use fd) */ state->fd = fd > -1 ? fd : ( -#if defined(WIN32) || defined(__MINGW__) +#if defined(_WIN32) fd == -2 ? _wopen(path, oflag, 0666) : #elif __CYGWIN__ fd == -2 ? open(state->path, oflag, 0666) : diff --git a/test/fuzz/minigzip_fuzzer.c b/test/fuzz/minigzip_fuzzer.c index c66ad2e0..e2ac6f7b 100644 --- a/test/fuzz/minigzip_fuzzer.c +++ b/test/fuzz/minigzip_fuzzer.c @@ -33,7 +33,7 @@ # include #endif -#if defined(WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) # include # include # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) @@ -46,7 +46,7 @@ #endif #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 */ extern int unlink (const char *); #endif #endif diff --git a/test/minigzip.c b/test/minigzip.c index 611391b0..d75c317f 100644 --- a/test/minigzip.c +++ b/test/minigzip.c @@ -36,7 +36,7 @@ # include #endif -#if defined(WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) # include # include # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) @@ -49,7 +49,7 @@ #endif #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 */ extern int unlink (const char *); #endif #endif diff --git a/zconf-ng.h.in b/zconf-ng.h.in index 49075b7a..c6c81f63 100644 --- a/zconf-ng.h.in +++ b/zconf-ng.h.in @@ -6,13 +6,8 @@ #ifndef ZCONFNG_H #define ZCONFNG_H -#if defined(_WINDOWS) && !defined(WINDOWS) -# define WINDOWS -#endif -#if defined(_WIN32) || defined(__WIN32__) -# ifndef WIN32 -# define WIN32 -# endif +#if !defined(_WIN32) && defined(__WIN32__) +# define _WIN32 #endif #ifdef __STDC_VERSION__ @@ -50,20 +45,18 @@ for small objects. */ - /* Type declarations */ +/* Type declarations */ -#if defined(WINDOWS) || defined(WIN32) +#if defined(_WIN32) /* If building or using zlib as a DLL, define ZLIB_DLL. * This is not mandatory, but it offers a little performance increase. */ -# ifdef ZLIB_DLL -# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) -# ifdef ZLIB_INTERNAL -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif +# if defined(ZLIB_DLL) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) # endif # endif /* ZLIB_DLL */ /* If building or using zlib with the WINAPI/WINAPIV calling convention, @@ -157,12 +150,12 @@ typedef PTRDIFF_TYPE ptrdiff_t; # define z_off_t long #endif -#if !defined(WIN32) && defined(Z_LARGE64) +#if !defined(_WIN32) && defined(Z_LARGE64) # define z_off64_t off64_t #else # if defined(__MSYS__) # define z_off64_t _off64_t -# elif defined(WIN32) && !defined(__GNUC__) +# elif defined(_WIN32) && !defined(__GNUC__) # define z_off64_t __int64 # else # define z_off64_t z_off_t diff --git a/zconf.h.in b/zconf.h.in index f890fcd9..44c1697a 100644 --- a/zconf.h.in +++ b/zconf.h.in @@ -6,13 +6,8 @@ #ifndef ZCONF_H #define ZCONF_H -#if defined(_WINDOWS) && !defined(WINDOWS) -# define WINDOWS -#endif -#if defined(_WIN32) || defined(__WIN32__) -# ifndef WIN32 -# define WIN32 -# endif +#if !defined(_WIN32) && defined(__WIN32__) +# define _WIN32 #endif #ifdef __STDC_VERSION__ @@ -50,24 +45,22 @@ for small objects. */ - /* Type declarations */ +/* Type declarations */ #ifndef OF /* function prototypes */ # define OF(args) args #endif -#if defined(WINDOWS) || defined(WIN32) +#if defined(_WIN32) /* If building or using zlib as a DLL, define ZLIB_DLL. * This is not mandatory, but it offers a little performance increase. */ -# ifdef ZLIB_DLL -# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) -# ifdef ZLIB_INTERNAL -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif +# if defined(ZLIB_DLL) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) # endif # endif /* ZLIB_DLL */ /* If building or using zlib with the WINAPI/WINAPIV calling convention, @@ -161,12 +154,12 @@ typedef PTRDIFF_TYPE ptrdiff_t; # define z_off_t long #endif -#if !defined(WIN32) && defined(Z_LARGE64) +#if !defined(_WIN32) && defined(Z_LARGE64) # define z_off64_t off64_t #else # if defined(__MSYS__) # define z_off64_t _off64_t -# elif defined(WIN32) && !defined(__GNUC__) +# elif defined(_WIN32) && !defined(__GNUC__) # define z_off64_t __int64 # else # define z_off64_t z_off_t diff --git a/zendian.h b/zendian.h index 4236b130..54718ed1 100644 --- a/zendian.h +++ b/zendian.h @@ -24,7 +24,7 @@ # endif #elif defined(__MINGW32__) # include -#elif defined(WIN32) || defined(_WIN32) +#elif defined(_WIN32) # define LITTLE_ENDIAN 1234 # define BIG_ENDIAN 4321 # if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined (_M_ARM) || defined (_M_ARM64) diff --git a/zlib-ng.h b/zlib-ng.h index 33033b44..7d792eee 100644 --- a/zlib-ng.h +++ b/zlib-ng.h @@ -1939,7 +1939,7 @@ ZEXTERN ZEXPORT int zng_inflateResetKeep (zng_stream *); ZEXTERN ZEXPORT int zng_deflateResetKeep (zng_stream *); #ifdef WITH_GZFILEOP -# if (defined(WIN32) || defined(__MINGW__)) +# if defined(_WIN32) ZEXTERN ZEXPORT gzFile zng_gzopen_w(const wchar_t *path, const char *mode); # endif ZEXTERN ZEXPORTVA int zng_gzvprintf(gzFile file, const char *format, va_list va); diff --git a/zlib.h b/zlib.h index cc6632ac..33bfd9cb 100644 --- a/zlib.h +++ b/zlib.h @@ -1836,7 +1836,7 @@ ZEXTERN unsigned long ZEXPORT inflateCodesUsed (z_stream *); ZEXTERN int ZEXPORT inflateResetKeep (z_stream *); ZEXTERN int ZEXPORT deflateResetKeep (z_stream *); -#if (defined(WIN32) || defined(__MINGW__)) +#if defined(_WIN32) ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode); #endif ZEXTERN int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va); diff --git a/zutil.h b/zutil.h index b8bce163..f4d26e3d 100644 --- a/zutil.h +++ b/zutil.h @@ -102,7 +102,7 @@ extern const char * const zng_errmsg[10]; /* indexed by 2-zlib_error */ # define OS_CODE 13 #endif -#if defined(WIN32) && !defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) # define OS_CODE 10 #endif @@ -115,7 +115,7 @@ extern const char * const zng_errmsg[10]; /* indexed by 2-zlib_error */ #endif /* provide prototypes for these when building zlib without LFS */ -#if !defined(WIN32) && !defined(__MSYS__) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) +#if !defined(_WIN32) && !defined(__MSYS__) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) # include "zbuild.h" /* For PREFIX() */ ZEXTERN uint32_t ZEXPORT PREFIX(adler32_combine64)(uint32_t, uint32_t, z_off_t); ZEXTERN uint32_t ZEXPORT PREFIX(crc32_combine64)(uint32_t, uint32_t, z_off_t); @@ -168,7 +168,7 @@ void ZLIB_INTERNAL zng_cfree(void *opaque, void *ptr); /* Reverse the bytes in a value. Use compiler intrinsics when possible to take advantage of hardware implementations. */ -#if defined(WIN32) && (_MSC_VER >= 1300) +#if defined(_MSC_VER) && (_MSC_VER >= 1300) # pragma intrinsic(_byteswap_ulong) # define ZSWAP16(q) _byteswap_ushort(q) # define ZSWAP32(q) _byteswap_ulong(q) -- 2.47.2