Move {Set,Get}LastError() from fpdsdk/ to core/fx_system.cpp
These are fills for Windows system functions, so they belong at
the fxcrt layer. In turn, this gets rid of an up-level include
of fpdfsdk/cpdfsdk_helpers.h in fpdfxfa.
Also make argument/return types consistent with Win32's DWORD
implementation.
Change-Id: I71db5b71bdd1736bc697f7699402dfdd5d904995
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/58770
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/fx_system.cpp b/core/fxcrt/fx_system.cpp
index eabf8f4..73ae728 100644
--- a/core/fxcrt/fx_system.cpp
+++ b/core/fxcrt/fx_system.cpp
@@ -14,6 +14,10 @@
namespace {
+#if !defined(OS_WIN)
+uint32_t g_last_error = 0;
+#endif
+
template <typename IntType, typename CharType>
IntType FXSYS_StrToInt(const CharType* str) {
if (!str)
@@ -242,5 +246,14 @@
}
return wlen;
}
-
#endif // defined(OS_WIN)
+
+#if !defined(OS_WIN)
+void SetLastError(uint32_t err) {
+ g_last_error = err;
+}
+
+uint32_t GetLastError() {
+ return g_last_error;
+}
+#endif // !defined(OS_WIN)
diff --git a/core/fxcrt/fx_system.h b/core/fxcrt/fx_system.h
index 6b113c0..667de6e 100644
--- a/core/fxcrt/fx_system.h
+++ b/core/fxcrt/fx_system.h
@@ -220,4 +220,10 @@
#endif // _FX_PLATFORM_ != _FX_PLATFORM_WINDOWS_
+// Provide SetLastError() and GetLastError() fills for non-windows platforms.
+#if _FX_PLATFORM_ != _FX_PLATFORM_WINDOWS_
+void SetLastError(uint32_t err);
+uint32_t GetLastError();
+#endif
+
#endif // CORE_FXCRT_FX_SYSTEM_H_
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp
index 2d7cba0..1d7690f 100644
--- a/fpdfsdk/cpdfsdk_helpers.cpp
+++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -32,10 +32,6 @@
UNSUPPORT_INFO* g_unsupport_info = nullptr;
-#if !defined(OS_WIN)
-int g_last_error = 0;
-#endif
-
bool RaiseUnsupportedError(int nError) {
if (!g_unsupport_info)
return false;
@@ -404,16 +400,6 @@
}
}
-#if !defined(OS_WIN)
-void SetLastError(int err) {
- g_last_error = err;
-}
-
-int GetLastError() {
- return g_last_error;
-}
-#endif
-
void ProcessParseError(CPDF_Parser::Error err) {
uint32_t err_code = FPDF_ERR_SUCCESS;
// Translate FPDFAPI error code to FPDFVIEW error code
diff --git a/fpdfsdk/cpdfsdk_helpers.h b/fpdfsdk/cpdfsdk_helpers.h
index a06cc39..fc93d7c 100644
--- a/fpdfsdk/cpdfsdk_helpers.h
+++ b/fpdfsdk/cpdfsdk_helpers.h
@@ -290,12 +290,6 @@
UNSUPPORT_INFO* GetPDFUnssuportInto();
void ReportUnsupportedFeatures(CPDF_Document* pDoc);
void CheckForUnsupportedAnnot(const CPDF_Annot* pAnnot);
-
-#if !defined(OS_WIN)
-void SetLastError(int err);
-int GetLastError();
-#endif
-
void ProcessParseError(CPDF_Parser::Error err);
#endif // FPDFSDK_CPDFSDK_HELPERS_H_
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index ca168ab..9884b1e 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -11,7 +11,6 @@
#include "core/fpdfapi/parser/cpdf_document.h"
#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
-#include "fpdfsdk/cpdfsdk_helpers.h"
#include "fpdfsdk/cpdfsdk_pageview.h"
#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
#include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h"