libtiff: Use #ifdef _WIN32 to test for Windows, and tiffio.h: remove definition of __WIN32__

From 651b14ffa91722bd1815e367c8e7708925057430 Mon Sep 17 00:00:00 2001
From: Even Rouault <[EMAIL REDACTED]>
Date: Sun, 7 Jan 2024 23:14:24 +0100
Subject: [PATCH] Use #ifdef _WIN32 to test for Windows, and tiffio.h: remove
 definition of __WIN32__

---
 libtiff/tif_dirread.c |  8 ++++----
 libtiff/tif_jpeg.c    |  2 +-
 libtiff/tif_ojpeg.c   |  2 +-
 libtiff/tif_unix.c    |  2 +-
 libtiff/tiffio.h      | 14 +++++---------
 libtiff/tiffiop.h     |  2 +-
 test/raw_decode.c     |  2 +-
 tools/tiffset.c       |  2 +-
 8 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
index 242912f3..cea569d5 100644
--- a/libtiff/tif_dirread.c
+++ b/libtiff/tif_dirread.c
@@ -1016,7 +1016,7 @@ TIFFReadDirEntryFloat(TIFF *tif, TIFFDirEntry *direntry, float *value)
             err = TIFFReadDirEntryCheckedLong8(tif, direntry, &m);
             if (err != TIFFReadDirEntryErrOk)
                 return (err);
-#if defined(__WIN32__) && (_MSC_VER < 1500)
+#if defined(_WIN32) && (_MSC_VER < 1500)
             /*
              * XXX: MSVC 6.0 does not support conversion
              * of 64-bit integers into floating point
@@ -1130,7 +1130,7 @@ TIFFReadDirEntryDouble(TIFF *tif, TIFFDirEntry *direntry, double *value)
             err = TIFFReadDirEntryCheckedLong8(tif, direntry, &m);
             if (err != TIFFReadDirEntryErrOk)
                 return (err);
-#if defined(__WIN32__) && (_MSC_VER < 1500)
+#if defined(_WIN32) && (_MSC_VER < 1500)
             /*
              * XXX: MSVC 6.0 does not support conversion
              * of 64-bit integers into floating point
@@ -2904,7 +2904,7 @@ TIFFReadDirEntryFloatArray(TIFF *tif, TIFFDirEntry *direntry, float **value)
             {
                 if (tif->tif_flags & TIFF_SWAB)
                     TIFFSwabLong8(ma);
-#if defined(__WIN32__) && (_MSC_VER < 1500)
+#if defined(_WIN32) && (_MSC_VER < 1500)
                 /*
                  * XXX: MSVC 6.0 does not support
                  * conversion of 64-bit integers into
@@ -3149,7 +3149,7 @@ TIFFReadDirEntryDoubleArray(TIFF *tif, TIFFDirEntry *direntry, double **value)
             {
                 if (tif->tif_flags & TIFF_SWAB)
                     TIFFSwabLong8(ma);
-#if defined(__WIN32__) && (_MSC_VER < 1500)
+#if defined(_WIN32) && (_MSC_VER < 1500)
                 /*
                  * XXX: MSVC 6.0 does not support
                  * conversion of 64-bit integers into
diff --git a/libtiff/tif_jpeg.c b/libtiff/tif_jpeg.c
index bcab8dd0..da4b53f0 100644
--- a/libtiff/tif_jpeg.c
+++ b/libtiff/tif_jpeg.c
@@ -103,7 +103,7 @@ int TIFFJPEGIsFullStripRequired_12(TIFF *tif);
 */
 
 /* Define "boolean" as unsigned char, not int, per Windows custom. */
-#if defined(__WIN32__) && !defined(__MINGW32__)
+#if defined(_WIN32) && !defined(__MINGW32__)
 #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
 typedef unsigned char boolean;
 #endif
diff --git a/libtiff/tif_ojpeg.c b/libtiff/tif_ojpeg.c
index ec0da992..57adcff8 100644
--- a/libtiff/tif_ojpeg.c
+++ b/libtiff/tif_ojpeg.c
@@ -224,7 +224,7 @@ static const TIFFField ojpegFields[] = {
 #endif
 
 /* Define "boolean" as unsigned char, not int, per Windows custom. */
-#if defined(__WIN32__) && !defined(__MINGW32__)
+#if defined(_WIN32) && !defined(__MINGW32__)
 #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
 typedef unsigned char boolean;
 #endif
diff --git a/libtiff/tif_unix.c b/libtiff/tif_unix.c
index 2cfbbe8d..d9254d45 100644
--- a/libtiff/tif_unix.c
+++ b/libtiff/tif_unix.c
@@ -262,7 +262,7 @@ TIFF *TIFFOpenExt(const char *name, const char *mode, TIFFOpenOptions *opts)
     return tif;
 }
 
-#ifdef __WIN32__
+#ifdef _WIN32
 #include <windows.h>
 /*
  * Open a TIFF file with a Unicode filename, for read/writing.
diff --git a/libtiff/tiffio.h b/libtiff/tiffio.h
index 26e1d089..225f3c1b 100644
--- a/libtiff/tiffio.h
+++ b/libtiff/tiffio.h
@@ -77,10 +77,6 @@ typedef tstrile_t ttile_t;  /* tile number */
 typedef tmsize_t tsize_t;   /* i/o size in bytes */
 typedef void *tdata_t;      /* image data ref */
 
-#if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32))
-#define __WIN32__
-#endif
-
 /*
  * On windows you should define USE_WIN32_FILEIO if you are using tif_win32.c
  * or AVOID_WIN32_FILEIO if you are using something else (like tif_unix.c).
@@ -88,7 +84,7 @@ typedef void *tdata_t;      /* image data ref */
  * By default tif_unix.c is assumed.
  */
 
-#if defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows)
+#if defined(_WIN32)
 #if !defined(__CYGWIN) && !defined(AVOID_WIN32_FILEIO) &&                      \
     !defined(USE_WIN32_FILEIO)
 #define AVOID_WIN32_FILEIO
@@ -98,11 +94,11 @@ typedef void *tdata_t;      /* image data ref */
 #if defined(USE_WIN32_FILEIO)
 #define VC_EXTRALEAN
 #include <windows.h>
-#ifdef __WIN32__
+#ifdef _WIN32
 DECLARE_HANDLE(thandle_t); /* Win32 file handle */
 #else
 typedef HFILE thandle_t; /* client data handle */
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
 #else
 typedef void *thandle_t; /* client data handle */
 #endif /* USE_WIN32_FILEIO */
@@ -522,11 +518,11 @@ extern int TIFFReadRGBAImageOriented(TIFF *, uint32_t, uint32_t, uint32_t *,
 
     extern TIFF *TIFFOpen(const char *, const char *);
     extern TIFF *TIFFOpenExt(const char *, const char *, TIFFOpenOptions *opts);
-#ifdef __WIN32__
+#ifdef _WIN32
     extern TIFF *TIFFOpenW(const wchar_t *, const char *);
     extern TIFF *TIFFOpenWExt(const wchar_t *, const char *,
                               TIFFOpenOptions *opts);
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
     extern TIFF *TIFFFdOpen(int, const char *, const char *);
     extern TIFF *TIFFFdOpenExt(int, const char *, const char *,
                                TIFFOpenOptions *opts);
diff --git a/libtiff/tiffiop.h b/libtiff/tiffiop.h
index da6a0f91..96e67435 100644
--- a/libtiff/tiffiop.h
+++ b/libtiff/tiffiop.h
@@ -334,7 +334,7 @@ struct TIFFOpenOptions
 #define ftell(stream, offset, whence) ftello(stream, offset, whence)
 #endif
 #endif
-#if defined(__WIN32__) && !(defined(_MSC_VER) && _MSC_VER < 1400) &&           \
+#if defined(_WIN32) && !(defined(_MSC_VER) && _MSC_VER < 1400) &&              \
     !(defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < 0x800)
 typedef unsigned int TIFFIOSize_t;
 #define _TIFF_lseek_f(fildes, offset, whence)                                  \
diff --git a/test/raw_decode.c b/test/raw_decode.c
index cf6ef00e..e09f2e17 100644
--- a/test/raw_decode.c
+++ b/test/raw_decode.c
@@ -64,7 +64,7 @@
 */
 
 /* Define "boolean" as unsigned char, not int, per Windows custom. */
-#if defined(__WIN32__) && !defined(__MINGW32__)
+#if defined(_WIN32) && !defined(__MINGW32__)
 #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
 typedef unsigned char boolean;
 #endif
diff --git a/tools/tiffset.c b/tools/tiffset.c
index c7f9c5a2..c768d989 100644
--- a/tools/tiffset.c
+++ b/tools/tiffset.c
@@ -55,7 +55,7 @@
   does not distribute the CRT (it is supplied by Microsoft) so the correct CRT
   must be available on the target computer in order for the program to run.
 */
-#if defined(__WIN32__) && !(defined(_MSC_VER) && _MSC_VER < 1400) &&           \
+#if defined(_WIN32) && !(defined(_MSC_VER) && _MSC_VER < 1400) &&              \
     !(defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < 0x800)
 #define TIFFfseek(stream, offset, whence)                                      \
     _fseeki64(stream, /* __int64 */ offset, whence)