diff --git a/storm/Error.cpp b/storm/Error.cpp deleted file mode 100644 index 712353c..0000000 --- a/storm/Error.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "storm/Error.hpp" -#include "storm/error/Error.hpp" - -#include "storm/Thread.hpp" - -#include -#include -#include - -[[noreturn]] void SErrDisplayAppFatal(const char* format, ...) { - // Format arguments - constexpr size_t size = 1024; - char buffer[size] = {0}; - va_list args; - va_start(args, format); - vsnprintf(buffer, size, format, args); - va_end(args); - - SErrDisplayError(STORM_ERROR_APPLICATION_FATAL, s_appFatInfo.filename, s_appFatInfo.linenumber, buffer, 0, 1, 0); -} - -int32_t SErrDisplayErrorFmt(uint32_t errorcode, const char* filename, int32_t linenumber, int32_t recoverable, uint32_t exitcode, const char* format, ...) { - char buffer[2048]; - - va_list args; - va_start(args, format); - vsnprintf(buffer, sizeof(buffer) - 1, format, args); - buffer[sizeof(buffer) - 1] = '\0'; - va_end(args); - - return SErrDisplayError(errorcode, filename, linenumber, buffer, recoverable, exitcode, 1); -} - -void SErrPrepareAppFatal(const char* filename, int32_t linenumber) { - s_appFatInfo.filename = filename; - s_appFatInfo.linenumber = linenumber; - s_appFatInfo.threadId = SGetCurrentThreadId(); -} - -void SErrSetLastError(uint32_t errorcode) { - s_lasterror = errorcode; -#if defined(WHOA_SYSTEM_WIN) - SetLastError(errorcode); -#endif -} - -uint32_t SErrGetLastError() { - return s_lasterror; -} diff --git a/storm/Error.hpp b/storm/Error.hpp index 542c826..e49598e 100644 --- a/storm/Error.hpp +++ b/storm/Error.hpp @@ -1,21 +1,6 @@ #ifndef STORM_ERROR_HPP #define STORM_ERROR_HPP -#include - -#include "storm/error/Macro.hpp" -#include "storm/error/Codes.hpp" - -[[noreturn]] void SErrDisplayAppFatal(const char* format, ...); - -int32_t SErrDisplayError(uint32_t errorcode, const char* filename, int32_t linenumber, const char* description, int32_t recoverable, uint32_t exitcode, uint32_t a7); - -int32_t SErrDisplayErrorFmt(uint32_t errorcode, const char* filename, int32_t linenumber, int32_t recoverable, uint32_t exitcode, const char* format, ...); - -void SErrPrepareAppFatal(const char* filename, int32_t linenumber); - -void SErrSetLastError(uint32_t errorcode); - -uint32_t SErrGetLastError(); +#include "storm/error/Error.hpp" #endif diff --git a/storm/error/Error.cpp b/storm/error/Error.cpp index 5760617..70be320 100644 --- a/storm/error/Error.cpp +++ b/storm/error/Error.cpp @@ -1,6 +1,52 @@ #include "storm/error/Error.hpp" #include "storm/error/Codes.hpp" +#include "storm/error/Types.hpp" +#include "storm/Thread.hpp" -uint32_t s_lasterror = ERROR_SUCCESS; -APPFATINFO s_appFatInfo = {}; +#include +#include +#include +static uint32_t s_lasterror = ERROR_SUCCESS; +static APPFATINFO s_appFatInfo = {}; + +[[noreturn]] void SErrDisplayAppFatal(const char* format, ...) { + // Format arguments + constexpr size_t size = 1024; + char buffer[size] = {0}; + va_list args; + va_start(args, format); + vsnprintf(buffer, size, format, args); + va_end(args); + + SErrDisplayError(STORM_ERROR_APPLICATION_FATAL, s_appFatInfo.filename, s_appFatInfo.linenumber, buffer, 0, 1, 0); +} + +int32_t SErrDisplayErrorFmt(uint32_t errorcode, const char* filename, int32_t linenumber, int32_t recoverable, uint32_t exitcode, const char* format, ...) { + char buffer[2048]; + + va_list args; + va_start(args, format); + vsnprintf(buffer, sizeof(buffer) - 1, format, args); + buffer[sizeof(buffer) - 1] = '\0'; + va_end(args); + + return SErrDisplayError(errorcode, filename, linenumber, buffer, recoverable, exitcode, 1); +} + +void SErrPrepareAppFatal(const char* filename, int32_t linenumber) { + s_appFatInfo.filename = filename; + s_appFatInfo.linenumber = linenumber; + s_appFatInfo.threadId = SGetCurrentThreadId(); +} + +void SErrSetLastError(uint32_t errorcode) { + s_lasterror = errorcode; +#if defined(WHOA_SYSTEM_WIN) + SetLastError(errorcode); +#endif +} + +uint32_t SErrGetLastError() { + return s_lasterror; +} diff --git a/storm/error/Error.hpp b/storm/error/Error.hpp index e301aba..f5cc848 100644 --- a/storm/error/Error.hpp +++ b/storm/error/Error.hpp @@ -3,13 +3,19 @@ #include -struct APPFATINFO { - const char *filename; - int32_t linenumber; - uintptr_t threadId; -}; +#include "storm/error/Macro.hpp" +#include "storm/error/Codes.hpp" -extern uint32_t s_lasterror; -extern APPFATINFO s_appFatInfo; +[[noreturn]] void SErrDisplayAppFatal(const char* format, ...); + +int32_t SErrDisplayError(uint32_t errorcode, const char* filename, int32_t linenumber, const char* description, int32_t recoverable, uint32_t exitcode, uint32_t a7); + +int32_t SErrDisplayErrorFmt(uint32_t errorcode, const char* filename, int32_t linenumber, int32_t recoverable, uint32_t exitcode, const char* format, ...); + +void SErrPrepareAppFatal(const char* filename, int32_t linenumber); + +void SErrSetLastError(uint32_t errorcode); + +uint32_t SErrGetLastError(); #endif diff --git a/storm/error/Types.hpp b/storm/error/Types.hpp new file mode 100644 index 0000000..5ea908b --- /dev/null +++ b/storm/error/Types.hpp @@ -0,0 +1,12 @@ +#ifndef STORM_ERROR_TYPES_HPP +#define STORM_ERROR_TYPES_HPP + +#include + +struct APPFATINFO { + const char* filename; + int32_t linenumber; + uintptr_t threadId; +}; + +#endif