From: Lukas Krickl Date: Mon, 23 Feb 2026 06:50:37 +0000 (+0100) Subject: style: Allowing stdarg.h in core code. X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=4a235ba48c3c0f059d426f5af557fa4e5ee60832;p=lrts%2F.git style: Allowing stdarg.h in core code. This change maks using some functions way easier. --- diff --git a/STYLE.md b/STYLE.md index f952055..cf02484 100644 --- 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 diff --git a/src/lrts.h b/src/lrts.h index b24dc6b..278276a 100644 --- a/src/lrts.h +++ b/src/lrts.h @@ -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 index a8bda81..0000000 --- a/src/p_pc/p_pc.h +++ /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 index 48ef2b5..0000000 --- a/src/p_pc/u_log.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "../u_log.h" -#include "../u_stdio.h" -#include "p_pc.h" -#include -#include - -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; -} diff --git a/src/p_pc/u_stdio.c b/src/p_pc/u_stdio.c index 4b73a30..87bcab8 100644 --- a/src/p_pc/u_stdio.c +++ b/src/p_pc/u_stdio.c @@ -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); } diff --git a/src/u_log.c b/src/u_log.c index 47d65ce..0459f5c 100644 --- a/src/u_log.c +++ b/src/u_log.c @@ -1,6 +1,20 @@ #include "u_log.h" +#include 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; +} diff --git a/src/u_stdio.h b/src/u_stdio.h index 88deabd..39d9c0d 100644 --- a/src/u_stdio.h +++ b/src/u_stdio.h @@ -1,6 +1,7 @@ #ifndef U_STDIO_H__ #define U_STDIO_H__ +#include #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);