1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
// File: crn_assert.cpp
// See Copyright Notice and license at the end of inc/crnlib.h
#include "crn_core.h"
#if CRNLIB_USE_WIN32_API
#include "crn_winhdr.h"
#endif
static bool g_fail_exceptions;
static bool g_exit_on_failure = true;
void crnlib_enable_fail_exceptions(bool enabled) {
g_fail_exceptions = enabled;
}
void crnlib_assert(const char* pExp, const char* pFile, unsigned line) {
char buf[512];
crnlib_snprintf(buf, sizeof(buf), "%s(%u): Assertion failed: \"%s\"\n", pFile, line, pExp);
crnlib_output_debug_string(buf);
fputs(buf, stderr);
if (crnlib_is_debugger_present())
crnlib_debug_break();
}
void crnlib_fail(const char* pExp, const char* pFile, unsigned line) {
char buf[512];
crnlib_snprintf(buf, sizeof(buf), "%s(%u): Failure: \"%s\"\n", pFile, line, pExp);
crnlib_output_debug_string(buf);
fputs(buf, stderr);
if (crnlib_is_debugger_present())
crnlib_debug_break();
#if CRNLIB_USE_WIN32_API
if (g_fail_exceptions)
RaiseException(CRNLIB_FAIL_EXCEPTION_CODE, 0, 0, NULL);
else
#endif
if (g_exit_on_failure)
exit(EXIT_FAILURE);
}
void trace(const char* pFmt, va_list args) {
if (crnlib_is_debugger_present()) {
char buf[512];
crnlib_snprintf(buf, sizeof(buf), pFmt, args);
crnlib_output_debug_string(buf);
}
};
void trace(const char* pFmt, ...) {
va_list args;
va_start(args, pFmt);
trace(pFmt, args);
va_end(args);
};
|