Add dlog.c/dlog.h

This commit is contained in:
josh committed 2025-10-07 17:48:15 -04:00
commit 39f645b50a
6 files changed
+563

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
#include "dlog.h"
#include <stdio.h>
#define DLOG_SIZE 1024
char dlog[DLOG_SIZE];
static size_t dlog_index;
void dlog_printf(const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
dlog_vprintf(fmt, args);
va_end(args);
}
void dlog_vprintf(const char * fmt, va_list args)
{
size_t size = DLOG_SIZE - dlog_index;
if (size > 0u)
{
int written = vsnprintf(&dlog[dlog_index], size, fmt, args);
if (written > 0)
{
dlog_index += (size_t)written;
if (dlog_index >= DLOG_SIZE)
{
dlog_index = DLOG_SIZE;
dlog[DLOG_SIZE - 1u] = '\0';
}
}
}
}
+9
View File
@@ -0,0 +1,9 @@
#ifndef DLOG_H
#define DLOG_H
#include <stdarg.h>
void dlog_printf(const char * fmt, ...);
void dlog_vprintf(const char * fmt, va_list args);
#endif