// TODO: Replace standard headers when possible. #include #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(); }