summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-04-27 11:30:56 +0200
committerCharles Pigott <charlespigott@googlemail.com>2021-04-27 18:17:34 +0100
commit4880ec29e4649655e775c36cd6bd8c0927d13ee1 (patch)
tree776a43a5d654452bab297d9b7bd9ddd350bdc364
parent8c2e3a004ee362b59bc9f918aa4fb6d4d7baedba (diff)
downloadopenttd-4880ec29e4649655e775c36cd6bd8c0927d13ee1.tar.xz
Change: [Network] Safeguard from using errno/strerror for handling network errors
They are likely not working as expected on Windows, so prevent their usage. Winsock does not set errno and strerror does not return anything useful for Winsock error numbers.
-rw-r--r--src/safeguards.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/safeguards.h b/src/safeguards.h
index 5351116ec..e3d6c4a3e 100644
--- a/src/safeguards.h
+++ b/src/safeguards.h
@@ -69,4 +69,17 @@
#undef abs
#endif
+#if defined(NETWORK_CORE_OS_ABSTRACTION_H) && defined(_WIN32)
+/* Use NetworkGetLastError() instead of errno, or do not (indirectly) include network/core/os_abstraction.h.
+ * Winsock does not set errno, but one should rather call WSAGetLastError. NetworkGetLastError abstracts that away. */
+#ifdef errno
+#undef errno
+#endif
+#define errno SAFEGUARD_DO_NOT_USE_THIS_METHOD
+
+/* Use NetworkGetLastErrorString() instead of strerror, or do not (indirectly) include network/core/os_abstraction.h.
+ * Winsock errors are not handled by strerror, but one should rather call FormatMessage. NetworkGetLastErrorString abstracts that away. */
+#define strerror SAFEGUARD_DO_NOT_USE_THIS_METHOD
+#endif /* defined(NETWORK_CORE_OS_ABSTRACTION_H) && defined(_WIN32) */
+
#endif /* SAFEGUARDS_H */