Initial Commit

This commit is contained in:
2026-08-25 06:38:37 -05:00
commit b1ce7c090d
5 changed files with 186 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
// TODO: Replace standard headers when possible.
#include <stdio.h>
#include "malunal/assert.h"
static
assertion_handler_pfn_t
g_handler;
malunal_void_t
assertion_handler(
assertion_handler_pfn_t handler
) {
g_handler = handler;
}
malunal_void_t
assertion_test(
malunal_bool_t cond,
malunal_cstr_t expr,
malunal_cstr_t msg,
malunal_cstr_t file,
malunal_int32_t line
) {
if (!cond) assertion_failed(expr, msg, file, line);
}
malunal_void_t
assertion_failed(
malunal_cstr_t expr,
malunal_cstr_t msg,
malunal_cstr_t file,
malunal_int32_t line
) {
if (g_handler != null)
return (*g_handler)(expr, msg, file, line);
malunal_cstr_t format = msg != null
? "%s:%d '%s' Assertion Failed!\n ↳ %s\n"
: "%s:%d '%s' Assertion Failed!\n";
fprintf(stderr, format, file, line, expr, msg);
abort();
}