Only define UTF16ToWChar() on relevant platforms.

Define the function at compile time instead of choosing to use it at
runtime.

Just as importantly, explicitly allow the use of build/build_config.h
everywhere. It is already implicitly allowed through headers in
third_party/base. This will allow PDFium to eventually standarize on
defines from build/build_config.h and remove redundant defines from
core/fxcrt/fx_system.h.

Change-Id: I5781a2322f8633c55945ddb59867b1ee74e96a2d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/52012
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/DEPS b/DEPS
index f449dc4..3bbf396 100644
--- a/DEPS
+++ b/DEPS
@@ -135,6 +135,7 @@
 include_rules = [
   # Basic stuff that everyone can use.
   # Note: public is not here because core cannot depend on public.
+  '+build/build_config.h',
   '+constants',
   '+testing',
   '+third_party/base',
diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp
index d01e1d1..855ce8a 100644
--- a/core/fxcrt/cfx_seekablestreamproxy.cpp
+++ b/core/fxcrt/cfx_seekablestreamproxy.cpp
@@ -16,6 +16,7 @@
 #include <utility>
 #include <vector>
 
+#include "build/build_config.h"
 #include "core/fxcrt/fx_codepage.h"
 #include "core/fxcrt/fx_extension.h"
 #include "third_party/base/stl_util.h"
@@ -76,18 +77,21 @@
   return {iSrcNum, iDstNum};
 }
 
+#if defined(WCHAR_T_IS_UTF32)
+static_assert(sizeof(wchar_t) > 2, "wchar_t is too small");
+
 void UTF16ToWChar(void* pBuffer, size_t iLength) {
   ASSERT(pBuffer);
   ASSERT(iLength > 0);
-  ASSERT(sizeof(wchar_t) > 2);
 
   uint16_t* pSrc = static_cast<uint16_t*>(pBuffer);
   wchar_t* pDst = static_cast<wchar_t*>(pBuffer);
 
-  // Peform self-intersecting copy in reverse order.
+  // Perform self-intersecting copy in reverse order.
   for (size_t i = iLength; i > 0; --i)
     pDst[i - 1] = static_cast<wchar_t>(pSrc[i - 1]);
 }
+#endif  // defined(WCHAR_T_IS_UTF32)
 
 void SwapByteOrder(uint16_t* pStr, size_t iLength) {
   while (iLength-- > 0) {
@@ -204,8 +208,10 @@
     if (m_wCodePage == FX_CODEPAGE_UTF16BE)
       SwapByteOrder(reinterpret_cast<uint16_t*>(pStr), size);
 
-    if (sizeof(wchar_t) > 2 && size > 0)
+#if defined(WCHAR_T_IS_UTF32)
+    if (size > 0)
       UTF16ToWChar(pStr, size);
+#endif
   } else {
     FX_FILESIZE pos = GetPosition();
     size_t iBytes = std::min(size, static_cast<size_t>(GetSize() - pos));
diff --git a/third_party/DEPS b/third_party/DEPS
index 392d012..dfd263b 100644
--- a/third_party/DEPS
+++ b/third_party/DEPS
@@ -4,5 +4,4 @@
   '+core/fxcrt/fx_memory.h',
   '+core/fxcrt/fx_system.h',
   '+core/fxcrt/unowned_ptr.h',
-  '+build',
 ]