Zth (libzth)
Loading...
Searching...
No Matches
assert.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019-2026 Jochem Rutgers
3 *
4 * SPDX-License-Identifier: MPL-2.0
5 */
6
7#include <libzth/util.h>
8
9#include <cassert>
10
11namespace zth {
12
13#ifndef ZTH_OS_WINDOWS
14__attribute__((weak))
15#endif
16void assert_handler(char const* file, int line, char const* expr)
17{
18 if(Config::EnableFullAssert)
19 abort("assertion failed at %s:%d: %s", file ? file : "?", line, expr ? expr : "?");
20 else
21 abort("assertion failed at %s:%d", file ? file : "?", line);
22}
23
24} // namespace zth
25
26#ifdef ZTH_OS_MACOS
27void __assert_rtn(const char* func, const char* file, unsigned int line, const char* exp)
28{
29 (void)func;
30 zth::assert_handler(file, (int)line, exp);
31}
32#elif defined(__NEWLIB__)
33void __assert_func(const char* file, int line, const char* func, const char* failedexpr)
34{
35 (void)func;
36 zth::assert_handler(file, line, failedexpr);
37}
38#else // assume glibc
40 const char* __assertion, const char* __file, unsigned int __line,
41 const char* __function) noexcept
42{
43 (void)__function;
44 zth::assert_handler(__file, (int)__line, __assertion);
45}
46
48 int __errnum, const char* __file, unsigned int __line, const char* __function) noexcept
49
50{
51 (void)__function;
52 zth::assert_handler(__file, (int)__line, zth::err(__errnum).c_str());
53}
54#endif // glibc
void __assert_perror_fail(int __errnum, const char *__file, unsigned int __line, const char *__function) noexcept
Definition assert.cpp:47
void __assert_fail(const char *__assertion, const char *__file, unsigned int __line, const char *__function) noexcept
Definition assert.cpp:39
void abort(char const *fmt,...) noexcept
Aborts the process after printing the given printf() formatted message.
Definition util.cpp:142
string err(int e)
Return a string like strerror() does, but as a zth::string.
Definition util.h:675
void assert_handler(char const *file, int line, char const *expr)
Definition assert.cpp:16