ciabatta/code/assert.c

45 lines
1.3 KiB
C
Raw Normal View History

2022-06-02 05:18:26 +00:00
#include <assert.h>
#include <stdlib.h>
#include <string.h>
2022-06-02 05:18:26 +00:00
#include <_platform.h>
2022-06-02 23:41:48 +00:00
// TODO: use abort() to break
#if defined(_compiler_msvc)
#include <intrin.h>
#define brk __debugbreak
2022-06-02 23:41:48 +00:00
#else
#define brk __builtin_trap
2022-06-02 23:41:48 +00:00
#endif
2022-06-02 05:18:26 +00:00
#if defined(_os_win)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
2022-06-02 05:18:26 +00:00
// TODO: make it work via printf
static void _assert_win32_prints(HANDLE conout, char const *str) {
DWORD written = 0;
WriteConsole(conout, str, strlen(str), &written, NULL);
}
2022-06-02 05:18:26 +00:00
extern void _assert_error(char *cond, char const *func, char const *file, char const *line) {
HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE);
if(conout != INVALID_HANDLE_VALUE) {
_assert_win32_prints(conout, "Assertion Failed: ");
_assert_win32_prints(conout, cond);
_assert_win32_prints(conout, "\n\tFile: ");
_assert_win32_prints(conout, file);
_assert_win32_prints(conout, "\n\tFunc: ");
_assert_win32_prints(conout, func);
_assert_win32_prints(conout, "\n\tLine: ");
_assert_win32_prints(conout, line);
2022-06-02 05:18:26 +00:00
}
else {
// TODO:
MessageBoxA(NULL,
"Assertion Failed Somewhere, good luck finding it!\n",
"Error",
MB_OK);
2022-06-02 05:18:26 +00:00
}
brk();
}
2022-06-02 05:18:26 +00:00
#endif