[mammoth] Update dbgln to use sprintf

This commit is contained in:
Drew Galbraith 2023-06-07 22:45:24 -07:00
parent 20dd43cdfb
commit 71a601362d
3 changed files with 20 additions and 3 deletions

View File

@ -10,6 +10,7 @@ target_include_directories(mammoth_lib
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(mammoth_lib
c
zion_lib)
set_target_properties(mammoth_lib PROPERTIES

View File

@ -3,7 +3,7 @@
#include <stdint.h>
#include <zerrors.h>
void dbgln(const char*);
void dbgln(const char* fmt, ...);
// Checks that the code is ok.
// if not exits the process.

View File

@ -1,13 +1,29 @@
#include "include/mammoth/debug.h"
#include <stdarg.h>
#include <stdio.h>
#include <zcall.h>
#include <zerrors.h>
void dbgln(const char* str) {
// Safe to ignore the result since right now this doesn't throw.
void dbgln_internal(const char* str) { // Safe to ignore the result since right
// now this doesn't throw.
uint64_t _ = ZDebug(str);
}
void dbgln(const char* fmt, ...) {
char str[1024];
va_list arg;
va_start(arg, fmt);
int ret = vsprintf(str, fmt, arg);
va_end(arg);
if (ret == -1 || ret > 1024) {
crash("Bad vsprintf", 1);
}
dbgln_internal(str);
}
void check(uint64_t code) {
switch (code) {
case Z_OK: