Files
2026-08-28 11:42:45 -05:00

43 lines
792 B
C

#include <stdio.h>
#include <stdlib.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
assert_test(
malunal_bool_t cond,
malunal_cstr_t expr,
malunal_cstr_t msg,
malunal_cstr_t file,
malunal_int32_t line
) {
if (!cond) assert_failed(expr, msg, file, line);
}
malunal_void_t
assert_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();
}