summaryrefslogtreecommitdiff
path: root/src/log.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-09-12 14:51:41 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-09-12 14:51:41 +0200
commitd174d803de2296061731c3698980a6a51e6fc3ef (patch)
tree27cf4a1d2e5c8d7ec98b3c88641d2fc4e231543d /src/log.cpp
parent12f306e2144081e00c36ed9942068462604bef55 (diff)
fix invoice savefile overflow
Diffstat (limited to 'src/log.cpp')
-rw-r--r--src/log.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/log.cpp b/src/log.cpp
new file mode 100644
index 0000000..960ee85
--- /dev/null
+++ b/src/log.cpp
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "log.hpp"
+
+log g_log = {0};
+
+void log_add(double timestamp, const char* fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(g_log.history[g_log.write_cursor], MAX_LEN_LOG_TXT, fmt, args);
+ va_end(args);
+
+ char tmp[MAX_LEN_LOG_TXT];
+ snprintf(tmp, MAX_LEN_LOG_TXT, "[%.3f] %s", timestamp, g_log.history[g_log.write_cursor]);
+ tmp[MAX_LEN_LOG_TXT-1] = 0;
+ memcpy(g_log.history[g_log.write_cursor], tmp, MAX_LEN_LOG_TXT);
+
+ printf(g_log.history[g_log.write_cursor]);
+
+ g_log.write_cursor++;
+ if (g_log.write_cursor >= MAX_LEN_LOG_HISTORY) g_log.write_cursor = 0;
+
+ g_log.history_length++;
+ if (g_log.history_length > MAX_LEN_LOG_HISTORY) g_log.history_length = MAX_LEN_LOG_HISTORY;
+}