jak-project/common/util/Assert.cpp
ManDude 9449078a9b
assert toggle (#1377)
* assert toggle

* Update Assert.h
2022-05-28 19:27:58 -04:00

39 lines
1.1 KiB
C++

#include "Assert.h"
#ifndef NO_ASSERT
#include <cstdio>
#include <cstdlib>
#include <string_view>
void private_assert_failed(const char* expr,
const char* file,
int line,
const char* function,
const char* msg) {
if (!msg || msg[0] == '\0') {
fprintf(stderr, "Assertion failed: '%s'\n\tSource: %s:%d\n\tFunction: %s\n", expr, file, line,
function);
} else {
fprintf(stderr, "Assertion failed: '%s'\n\tMessage: %s\n\tSource: %s:%d\n\tFunction: %s\n",
expr, msg, file, line, function);
}
fflush(stdout); // ensure any stdout logs are flushed before we terminate
fflush(stderr);
abort();
}
void private_assert_failed(const char* expr,
const char* file,
int line,
const char* function,
const std::string_view& msg) {
if (msg.empty()) {
private_assert_failed(expr, file, line, function);
} else {
private_assert_failed(expr, file, line, function, msg.data());
}
}
#endif