Changeset - r25282:1405d773e082
[Not reviewed]
master
0 1 0
rubidium42 - 3 years ago 2021-04-27 09:30:56
rubidium@openttd.org
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.
1 file changed with 13 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/safeguards.h
Show inline comments
 
@@ -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 */
0 comments (0 inline, 0 general)