Fix const char

This commit is contained in:
Krzosa Karol
2024-03-16 11:55:44 +01:00
parent da575e8877
commit 18100a87fb
2 changed files with 30 additions and 33 deletions

View File

@@ -36,14 +36,14 @@ IO_THREAD_LOCAL void (*IO_User_OutputMessage)(int kind, const char *file, int li
IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) { IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) {
va_list args1; va_list args1;
va_list args2; va_list args2;
char buff[2048]; char buff[2048];
va_start(args1, msg); va_start(args1, msg);
va_copy(args2, args1); va_copy(args2, args1);
int size = IO_VSNPRINTF(buff, sizeof(buff), msg, args2); int size = IO_VSNPRINTF(buff, sizeof(buff), msg, args2);
va_end(args2); va_end(args2);
char *new_buffer = 0; char *new_buffer = 0;
char *user_message = buff; char *user_message = buff;
if (size >= sizeof(buff)) { if (size >= sizeof(buff)) {
size += 4; size += 4;
@@ -55,14 +55,14 @@ IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) {
IO_ErrorResult ret = IO_ErrorResult_Continue; IO_ErrorResult ret = IO_ErrorResult_Continue;
{ {
char buff2[2048]; char buff2[2048];
char *result = buff2; char *result = buff2;
char *b = 0; char *b = 0;
int size2 = IO_SNPRINTF(buff2, sizeof(buff2), "%s(%d): error: %s \n", file, line, user_message); int size2 = IO_SNPRINTF(buff2, sizeof(buff2), "%s(%d): error: %s \n", file, line, user_message);
if (size2 >= sizeof(buff2)) { if (size2 >= sizeof(buff2)) {
size2 += 4; size2 += 4;
b = (char *)IO_ALLOCATE(size2); b = (char *)IO_ALLOCATE(size2);
size2 = IO_SNPRINTF(b, size2, "%s(%d): error: %s \n", file, line, user_message); size2 = IO_SNPRINTF(b, size2, "%s(%d): error: %s \n", file, line, user_message);
result = b; result = b;
} }
@@ -89,7 +89,7 @@ IO_API void IO__Printf(int kind, const char *file, int line, const char *msg, ..
// case. // case.
va_list args1; va_list args1;
va_list args2; va_list args2;
char buff[2048]; char buff[2048];
va_start(args1, msg); va_start(args1, msg);
va_copy(args2, args1); va_copy(args2, args1);
@@ -97,7 +97,7 @@ IO_API void IO__Printf(int kind, const char *file, int line, const char *msg, ..
va_end(args2); va_end(args2);
char *new_buffer = 0; char *new_buffer = 0;
char *result = buff; char *result = buff;
if (size >= sizeof(buff)) { if (size >= sizeof(buff)) {
size += 4; size += 4;
new_buffer = (char *)IO_ALLOCATE(size); new_buffer = (char *)IO_ALLOCATE(size);
@@ -108,8 +108,7 @@ IO_API void IO__Printf(int kind, const char *file, int line, const char *msg, ..
if (IO_User_OutputMessage) { if (IO_User_OutputMessage) {
IO_User_OutputMessage(kind, file, line, result, size); IO_User_OutputMessage(kind, file, line, result, size);
} } else {
else {
IO_OutputMessage(result, size); IO_OutputMessage(result, size);
} }
@@ -118,9 +117,9 @@ IO_API void IO__Printf(int kind, const char *file, int line, const char *msg, ..
} }
} }
IO_API bool IO__FatalError(char *msg) { IO_API bool IO__FatalError(const char *msg) {
int len = IO_Strlen(msg); int len = IO_Strlen((char *)msg);
IO_ErrorResult result = IO_OutputError(msg, len); IO_ErrorResult result = IO_OutputError((char *)msg, len);
if (result == IO_ErrorResult_Exit) { if (result == IO_ErrorResult_Exit) {
IO_Exit(1); IO_Exit(1);
} }
@@ -130,8 +129,7 @@ IO_API bool IO__FatalError(char *msg) {
IO_API void IO_Print(int kind, const char *file, int line, char *msg, int len) { IO_API void IO_Print(int kind, const char *file, int line, char *msg, int len) {
if (IO_User_OutputMessage) { if (IO_User_OutputMessage) {
IO_User_OutputMessage(kind, file, line, msg, len); IO_User_OutputMessage(kind, file, line, msg, len);
} } else {
else {
IO_OutputMessage(msg, len); IO_OutputMessage(msg, len);
} }
} }
@@ -177,7 +175,7 @@ IO_API IO_ErrorResult IO_OutputError(char *str, int len) {
// Limit size of error output message // Limit size of error output message
char tmp = 0; char tmp = 0;
if (len > 4096) { if (len > 4096) {
tmp = str[4096]; tmp = str[4096];
str[4096] = 0; str[4096] = 0;
} }
@@ -188,8 +186,7 @@ IO_API IO_ErrorResult IO_OutputError(char *str, int len) {
} }
result = IO_ErrorResult_Exit; result = IO_ErrorResult_Exit;
} } else {
else {
result = IO_ErrorResult_Break; result = IO_ErrorResult_Break;
} }

View File

@@ -55,8 +55,8 @@ extern IO_THREAD_LOCAL void (*IO_User_OutputMessage)(int kind, const char *file,
#define IO__TOSTRING(x) IO__STRINGIFY(x) #define IO__TOSTRING(x) IO__STRINGIFY(x)
#define IO_LINE IO__TOSTRING(__LINE__) #define IO_LINE IO__TOSTRING(__LINE__)
#define IO_Assert(x) !(x) && IO__FatalError((char *)(__FILE__ "(" IO_LINE "): " \ #define IO_Assert(x) !(x) && IO__FatalError((__FILE__ "(" IO_LINE "): " \
"error: " #x "\n")) && \ "error: " #x "\n")) && \
IO_DebugBreak() IO_DebugBreak()
#define IO_FatalErrorf(...) \ #define IO_FatalErrorf(...) \
do { \ do { \
@@ -85,22 +85,22 @@ extern IO_THREAD_LOCAL void (*IO_User_OutputMessage)(int kind, const char *file,
IO_InvalidCodepath(); \ IO_InvalidCodepath(); \
} }
#define IO_InvalidCodepath() IO_FatalError("This codepath is invalid") #define IO_InvalidCodepath() IO_FatalError("This codepath is invalid")
#define IO_InvalidDefaultCase() \ #define IO_InvalidDefaultCase() \
default: { \ default: { \
IO_FatalError("Entered invalid switch statement case"); \ IO_FatalError("Entered invalid switch statement case"); \
} }
#define IO_Todo() IO_FatalError("This codepath is not implemented yet") #define IO_Todo() IO_FatalError("This codepath is not implemented yet")
IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) IO__PrintfFormat(3, 4); IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) IO__PrintfFormat(3, 4);
IO_API void IO__Printf(int kind, const char *file, int line, const char *msg, ...) IO__PrintfFormat(4, 5); IO_API void IO__Printf(int kind, const char *file, int line, const char *msg, ...) IO__PrintfFormat(4, 5);
IO_API bool IO__FatalError(char *msg); IO_API bool IO__FatalError(const char *msg);
IO_API void IO_Print(int kind, const char *file, int line, char *msg, int len); IO_API void IO_Print(int kind, const char *file, int line, char *msg, int len);
IO_API void IO_OutputMessage(char *str, int len); IO_API void IO_OutputMessage(char *str, int len);
IO_API IO_ErrorResult IO_OutputError(char *str, int len); IO_API IO_ErrorResult IO_OutputError(char *str, int len);
IO_API void IO_Exit(int error_code); IO_API void IO_Exit(int error_code);
IO_API bool IO_IsDebuggerPresent(void); IO_API bool IO_IsDebuggerPresent(void);
static const int IO_KindPrintf = 1; static const int IO_KindPrintf = 1;
static const int IO_KindWarningf = 2; static const int IO_KindWarningf = 2;
#define IO_Printf(...) IO__Printf(IO_KindPrintf, __FILE__, __LINE__, __VA_ARGS__) #define IO_Printf(...) IO__Printf(IO_KindPrintf, __FILE__, __LINE__, __VA_ARGS__)