style: Allowing stdarg.h in core code.
authorLukas Krickl <lukas@krickl.dev>
Mon, 23 Feb 2026 06:50:37 +0000 (07:50 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 23 Feb 2026 06:50:37 +0000 (07:50 +0100)
This change maks using some functions way easier.

STYLE.md
src/lrts.h
src/p_pc/p_pc.h [deleted file]
src/p_pc/u_log.c [deleted file]
src/p_pc/u_stdio.c
src/u_log.c
src/u_stdio.h

index f9520553366a4d184b5f5f17956bf3ad5f57eeff..cf024841d6b002d3708a5480057681348a2a98e8 100644 (file)
--- a/STYLE.md
+++ b/STYLE.md
@@ -44,3 +44,10 @@ enabled to allow the program to compile.
 
 All test cases are included in the tests directory.
 When test are run p_tests is used as a platform.
+
+## Exceptions
+
+Some C features might be hard to wrap.
+These are allowed even in core code.
+
+- stdarg.h: for va_list va_start and va_end
index b24dc6bb4362f8be6e799ca22ab9fd1b74156938..278276a9d67927265ecbdf0a9242e7a3ce73b2f5 100644 (file)
@@ -26,7 +26,6 @@
 #include "p_pc/u_assert.c"
 #include "p_posix/p_init.c"
 #include "p_posix/p_getopt.c"
-#include "p_pc/u_log.c"
 #else
 #error "No platform is provided"
 #endif
diff --git a/src/p_pc/p_pc.h b/src/p_pc/p_pc.h
deleted file mode 100644 (file)
index a8bda81..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef P_PC_H__
-#define P_PC_H__
-
-int u_vfprintf(U_FILE* stream, const char *fmt, void *args);
-
-#endif
diff --git a/src/p_pc/u_log.c b/src/p_pc/u_log.c
deleted file mode 100644 (file)
index 48ef2b5..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "../u_log.h"
-#include "../u_stdio.h"
-#include "p_pc.h"
-#include <stdarg.h>
-#include <stdio.h>
-
-int u_log(enum u_log_levels level, const char *fmt, ...) {
-       va_list args;
-       int res = 0;
-
-       if (!u_log_should_log(level)) {
-               return 0;
-       }
-       va_start(args, fmt);
-       res = u_fprintf(u_stderr, fmt, args);
-       va_end(args);
-       return res;
-}
index 4b73a30f8497a82e8374a2d2a05e06de174f153d..87bcab88e5fd18e0c07aba2c2fe798a792968c6e 100644 (file)
@@ -7,7 +7,7 @@ void *u_stdout;
 void *u_stderr;
 
 
-int u_vfprintf(U_FILE* stream, const char *fmt, void *args) {
+int u_vfprintf(U_FILE* stream, const char *fmt, va_list args) {
                return vfprintf(stream, fmt, args);
 }
 
index 47d65ce5359c49c9ee810479d99a79c927d47660..0459f5c1a5f56ad098ea697956f169e66cede6c6 100644 (file)
@@ -1,6 +1,20 @@
 #include "u_log.h"
+#include <stdarg.h>
 
 lrts_bool u_log_should_log(enum u_log_levels level) {
        /* TODO: implement log levels */
        return LRTS_TRUE;
 }
+
+int u_log(enum u_log_levels level, const char *fmt, ...) {
+       va_list args;
+       int res = 0;
+
+       if (!u_log_should_log(level)) {
+               return 0;
+       }
+       va_start(args, fmt);
+       res = u_fprintf(u_stderr, fmt, args);
+       va_end(args);
+       return res;
+}
index 88deabd059e426f751f2a4fc6c8fe1ee01c5dc47..39d9c0d63d95cbecc80bc50e4ded86f6874bd130 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef U_STDIO_H__
 #define U_STDIO_H__
 
+#include <stdarg.h>
 
 #define U_FILE void
 
@@ -8,6 +9,7 @@ extern void *u_stdin;
 extern void *u_stdout;
 extern void *u_stderr;
 
+int u_vfprintf(U_FILE* stream, const char *fmt, va_list args);
 int u_fprintf(U_FILE* stream, const char *fmt, ...);
 int u_fputs(const char *s, U_FILE* stream);