42 #if __cplusplus < 201103L
44 #elif __cplusplus == 201103L
46 #elif __cplusplus == 201402L
48 #elif __cplusplus == 201703L
59 #ifdef ZTH_OS_BAREMETAL
61 " newlib" _NEWLIB_VERSION
63 #ifdef ZTH_ARCH_X86_64
71 # ifdef __ARM_ARCH_PROFILE
72 # if __ARM_ARCH_PROFILE == 'A'
74 # elif __ARM_ARCH_PROFILE == 'R'
76 # elif __ARM_ARCH_PROFILE == 'M'
78 # elif __ARM_ARCH_PROFILE == 'S'
86 #ifdef ZTH_ARM_USE_PSP
98 #ifdef ZTH_CONTEXT_UCONTEXT
101 #ifdef ZTH_CONTEXT_SIGALTSTACK
104 #ifdef ZTH_CONTEXT_SJLJ
107 #ifdef ZTH_CONTEXT_WINFIBER
113 #ifdef ZTH_ENABLE_ASAN
116 #ifdef ZTH_ENABLE_LSAN
119 #ifdef ZTH_ENABLE_UBSAN
130 void abort(
char const* fmt, ...) noexcept
142 void abortv(
char const* fmt, va_list args) noexcept
144 static bool recurse =
false;
158 #ifndef ZTH_OS_BAREMETAL
159 static void log_init()
161 # ifdef ZTH_OS_WINDOWS
167 setvbuf(stdout,
nullptr, _IOLBF, 4096);
168 setvbuf(stderr,
nullptr, _IOLBF, 4096);
169 # ifdef ZTH_OS_WINDOWS
181 #ifdef ZTH_OS_WINDOWS
182 static int support = 0;
193 AttachConsole(ATTACH_PARENT_PROCESS);
196 if(!GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &mode))
198 if(!SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), mode | 0x0004))
202 if(GetConsoleMode(GetStdHandle(STD_ERROR_HANDLE), &mode))
203 SetConsoleMode(GetStdHandle(STD_ERROR_HANDLE), mode | 0x0004);
223 static bool do_color =
226 if(do_color && color > 0)
227 log(
"\x1b[%d%sm", (color % 8) + 30, color >= 8 ?
";1" :
"");
231 if(do_color && color > 0)
240 int const maxstack = (int)
sizeof(
void*) * 8;
243 char* hbuf =
nullptr;
244 size_t hbuf_size = 0;
248 va_copy(args2, args);
250 int c = vsnprintf(sbuf, maxstack, fmt, args);
253 hbuf_size = (size_t)c + 1u;
254 hbuf = allocate_noexcept<char>(hbuf_size);
260 int c2 = vsprintf(hbuf, fmt, args2);
269 string res(buf, (
size_t)(c < 0 ? 0 : c));
270 deallocate(hbuf, hbuf_size);
288 #ifdef ZTH_OS_BAREMETAL
289 __attribute__((weak))
int asprintf(
char** strp,
const char* fmt, ...)
293 int res = vasprintf(strp, fmt, args);
298 __attribute__((weak))
int vasprintf(
char** strp,
const char* fmt, va_list ap)
302 int len = vsnprintf(
nullptr, 0, fmt, ap_dup);
305 if(strp && (*strp = (
char*)malloc(len + 1)))
306 vsnprintf(*strp, len + 1, fmt, ap);
void print(int color=-1) const
void zth_abort(char const *fmt,...)
Aborts the process after printing the given printf() formatted message.
#define zth_config(name)
Checks if the given zth::Config field is enabled.
void log_colorv(int color, char const *fmt, va_list args)
Logs a given printf()-like formatted string using an ANSI color code.
void abort(char const *fmt,...) noexcept
Aborts the process after printing the given printf() formatted message.
#define ZTH_VERSION
Zth version as string literal.
char const * banner() noexcept
Prints a banner line with version and configuration information.
void log(char const *fmt,...)
Logs a given printf()-like formatted string.
void logv(char const *fmt, va_list arg)
Logs a given printf()-like formatted string.
void abortv(char const *fmt, va_list args) noexcept
Aborts the process after printing the given printf() formatted message.
bool log_supports_ansi_colors() noexcept
Returns if the system supports ANSI colors.
string formatv(char const *fmt, va_list args)
Format like vsprintf(), but save the result in an zth::string.
static bool const EnableColorLog
Enable colored output.
#define zth_assert(expr)
assert(), but better integrated in Zth.
#define likely(expr)
Marks the given expression to likely be evaluated to true.
#define ZTH_STRINGIFY(x)
Converts the argument to a string literal.
#define unlikely(expr)
Marks the given expression to likely be evaluated to true.