Use more defines from build/build_config.h.

Remove some trivial _WIN32 and __GNUC__ usage.
Also fix some nits along the way.

Change-Id: I23549ef34584f501de6a4851934563e02aea0882
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/53753
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/fx_memory.cpp b/core/fxcrt/fx_memory.cpp
index b573420..4ed0d6b 100644
--- a/core/fxcrt/fx_memory.cpp
+++ b/core/fxcrt/fx_memory.cpp
@@ -8,6 +8,7 @@
 
 #include <stdlib.h>  // For abort().
 
+#include "build/build_config.h"
 #include "core/fxcrt/fx_safe_types.h"
 #include "third_party/base/debug/alias.h"
 
@@ -66,7 +67,7 @@
 
   // Termimate cleanly if we can, else crash at a specific address (0xbd).
   abort();
-#ifndef _WIN32
+#if !defined(OS_WIN)
   reinterpret_cast<void (*)()>(0xbd)();
 #endif
 }
diff --git a/core/fxcrt/fx_memory_unittest.cpp b/core/fxcrt/fx_memory_unittest.cpp
index eab1111..39b249f 100644
--- a/core/fxcrt/fx_memory_unittest.cpp
+++ b/core/fxcrt/fx_memory_unittest.cpp
@@ -6,6 +6,7 @@
 
 #include <limits>
 
+#include "build/build_config.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
@@ -59,7 +60,7 @@
   FX_Free(ptr);
 }
 
-#if !defined(__GNUC__)
+#if !defined(COMPILER_GCC)
 TEST(fxcrt, FX_TryAllocOverflow) {
   // |ptr| needs to be defined and used to avoid Clang optimizes away the
   // calloc() statement overzealously for optimized builds.
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp
index 63ee361..28609e7 100644
--- a/fpdfsdk/cpdfsdk_helpers.cpp
+++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -6,6 +6,7 @@
 
 #include "fpdfsdk/cpdfsdk_helpers.h"
 
+#include "build/build_config.h"
 #include "constants/form_fields.h"
 #include "constants/stream_dict_common.h"
 #include "core/fpdfapi/cpdf_modulemgr.h"
@@ -29,11 +30,11 @@
 constexpr char kQuadPoints[] = "QuadPoints";
 
 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS
-static uint32_t g_sandbox_policy = 0xFFFFFFFF;
+uint32_t g_sandbox_policy = 0xFFFFFFFF;
 
-#ifndef _WIN32
-int g_last_error;
-#endif  // _WIN32
+#if !defined(OS_WIN)
+int g_last_error = 0;
+#endif
 
 bool RaiseUnsupportedError(int nError) {
   auto* pAdapter = CPDF_ModuleMgr::Get()->GetUnsupportInfoAdapter();
@@ -377,7 +378,7 @@
   }
 }
 
-#ifndef _WIN32
+#if !defined(OS_WIN)
 void SetLastError(int err) {
   g_last_error = err;
 }
@@ -385,7 +386,7 @@
 int GetLastError() {
   return g_last_error;
 }
-#endif  // _WIN32
+#endif
 
 void ProcessParseError(CPDF_Parser::Error err) {
   uint32_t err_code = FPDF_ERR_SUCCESS;
diff --git a/fpdfsdk/cpdfsdk_helpers.h b/fpdfsdk/cpdfsdk_helpers.h
index 038ee5d..bac2dff 100644
--- a/fpdfsdk/cpdfsdk_helpers.h
+++ b/fpdfsdk/cpdfsdk_helpers.h
@@ -7,6 +7,7 @@
 #ifndef FPDFSDK_CPDFSDK_HELPERS_H_
 #define FPDFSDK_CPDFSDK_HELPERS_H_
 
+#include "build/build_config.h"
 #include "core/fpdfapi/page/cpdf_page.h"
 #include "core/fpdfapi/parser/cpdf_parser.h"
 #include "core/fxge/dib/cfx_dibitmap.h"
@@ -17,7 +18,7 @@
 #include "core/fxcrt/fx_stream.h"
 #endif  // PDF_ENABLE_XFA
 
-#ifdef _WIN32
+#if defined(OS_WIN)
 #include <math.h>
 #include <tchar.h>
 #endif
@@ -265,10 +266,10 @@
 void ReportUnsupportedFeatures(CPDF_Document* pDoc);
 void CheckForUnsupportedAnnot(const CPDF_Annot* pAnnot);
 
-#ifndef _WIN32
+#if !defined(OS_WIN)
 void SetLastError(int err);
 int GetLastError();
-#endif  // _WIN32
+#endif
 
 void ProcessParseError(CPDF_Parser::Error err);
 
diff --git a/fpdfsdk/fpdf_text.cpp b/fpdfsdk/fpdf_text.cpp
index 09193e7..86f9ccf 100644
--- a/fpdfsdk/fpdf_text.cpp
+++ b/fpdfsdk/fpdf_text.cpp
@@ -10,6 +10,7 @@
 #include <memory>
 #include <vector>
 
+#include "build/build_config.h"
 #include "core/fpdfapi/font/cpdf_font.h"
 #include "core/fpdfapi/page/cpdf_page.h"
 #include "core/fpdfapi/page/cpdf_textobject.h"
@@ -27,7 +28,7 @@
 #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
 #endif  // PDF_ENABLE_XFA
 
-#ifdef _WIN32
+#if defined(OS_WIN)
 #include <tchar.h>
 #endif
 
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 63374d2..3186779 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -195,7 +195,7 @@
   return FSDK_SetSandBoxPolicy(policy, enable);
 }
 
-#if defined(_WIN32)
+#if defined(OS_WIN)
 #if defined(PDFIUM_PRINT_TEXT_WITH_GDI)
 FPDF_EXPORT void FPDF_CALLCONV
 FPDF_SetTypefaceAccessibleFunc(PDFiumEnsureTypefaceCharactersAccessible func) {
@@ -215,7 +215,7 @@
   g_pdfium_print_mode = static_cast<WindowsPrintMode>(mode);
   return TRUE;
 }
-#endif  // defined(_WIN32)
+#endif  // defined(OS_WIN)
 
 FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV
 FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BYTESTRING password) {
@@ -370,7 +370,7 @@
   return true;
 }
 
-#if defined(_WIN32)
+#if defined(OS_WIN)
 namespace {
 
 const double kEpsilonSize = 0.01f;
@@ -607,7 +607,7 @@
 
   pPage->SetRenderContext(nullptr);
 }
-#endif  // defined(_WIN32)
+#endif  // defined(OS_WIN)
 
 FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPageBitmap(FPDF_BITMAP bitmap,
                                                      FPDF_PAGE page,
diff --git a/fxjs/cjs_util.cpp b/fxjs/cjs_util.cpp
index 4f83ea6..18faf61 100644
--- a/fxjs/cjs_util.cpp
+++ b/fxjs/cjs_util.cpp
@@ -50,7 +50,7 @@
     {L"ddd", L"%a"},  {L"dd", L"%d"},  {L"yyyy", L"%Y"}, {L"yy", L"%y"},
     {L"HH", L"%H"},   {L"hh", L"%I"},  {L"MM", L"%M"},   {L"ss", L"%S"},
     {L"TT", L"%p"},
-#if defined(_WIN32)
+#if defined(OS_WIN)
     {L"tt", L"%p"},   {L"h", L"%#I"},
 #else
     {L"tt", L"%P"},   {L"h", L"%l"},