From 81d1370b5ff2bd0cb825e6d7130cdd648b2bb79b Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 16 Apr 2021 03:40:47 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20Fix=20Storm=20error=20code=20on?= =?UTF-8?q?=20Windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `DVL_ERROR_HANDLE_EOF` was defined incorrectly on Windows. These error codes are used and returned by Storm. Moves them from `miniwin.h` to `storm.h`. Also adds `STORM_ERROR_FILE_NOT_FOUND`, to be used in a follow-up PR. --- Source/miniwin/miniwin.h | 2 -- Source/storm/storm.h | 12 ++++++++++++ Source/storm/storm_sdl_rw.cpp | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Source/miniwin/miniwin.h b/Source/miniwin/miniwin.h index ec4805631..e5e09d5f7 100644 --- a/Source/miniwin/miniwin.h +++ b/Source/miniwin/miniwin.h @@ -89,8 +89,6 @@ bool PostMessage(UINT Msg, WPARAM wParam, LPARAM lParam); #define DVL_FILE_CURRENT 1 #define DVL_FILE_END 2 -#define DVL_ERROR_HANDLE_EOF 1002 - #define DVL_WM_QUIT 0x0012 // diff --git a/Source/storm/storm.h b/Source/storm/storm.h index 5e223b488..7b29a7298 100644 --- a/Source/storm/storm.h +++ b/Source/storm/storm.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -288,6 +289,17 @@ void setIniFloat(const char *keyname, const char *valuename, float value); void SVidPlayBegin(const char *filename, int flags, HANDLE *video); void SVidPlayEnd(HANDLE video); +// These error codes are used and returned by StormLib. +// See StormLib/src/StormPort.h +#if defined(_WIN32) +// https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- +#define STORM_ERROR_FILE_NOT_FOUND 2 +#define STORM_ERROR_HANDLE_EOF 38 +#else // !defined(_WIN32) +#define STORM_ERROR_FILE_NOT_FOUND ENOENT +#define STORM_ERROR_HANDLE_EOF 1002 +#endif + /* SErrGetLastError @ 463 * * Retrieves the last error that was specifically diff --git a/Source/storm/storm_sdl_rw.cpp b/Source/storm/storm_sdl_rw.cpp index 3616e6767..c03ac426e 100644 --- a/Source/storm/storm_sdl_rw.cpp +++ b/Source/storm/storm_sdl_rw.cpp @@ -61,7 +61,7 @@ static int SFileRw_read(struct SDL_RWops *context, void *ptr, int size, int maxn DWORD num_read = 0; if (!SFileReadFile(SFileRw_GetHandle(context), ptr, maxnum * size, &num_read, NULL)) { const DWORD err_code = SErrGetLastError(); - if (err_code != DVL_ERROR_HANDLE_EOF) { + if (err_code != STORM_ERROR_HANDLE_EOF) { SDL_Log("SFileRw_read error: %u %u ERROR CODE %u", (unsigned int)size, (unsigned int)maxnum, (unsigned int)err_code); } }