aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2024-02-01 15:14:35 +0100
committerkdx <kikoodx@paranoici.org>2024-02-01 15:15:40 +0100
commitc044ae2b27c63cdea1232aa62b75faca4c35cc6a (patch)
treea84611b663044dbc37750ee78767e409f547148c
parent3b722ade0c82e13e16dc59ea646b7677527e9064 (diff)
downloadcminus-c044ae2b27c63cdea1232aa62b75faca4c35cc6a.tar.gz
variable logstream
-rw-r--r--_.c6
-rw-r--r--_.h7
2 files changed, 12 insertions, 1 deletions
diff --git a/_.c b/_.c
index bdf651b..c7969f3 100644
--- a/_.c
+++ b/_.c
@@ -8,6 +8,7 @@
static void **_alloced = nullptr;
static size_t _alloced_size = 0;
static size_t _alloced_capacity = 0;
+FILE *_cminus_logstream = nullptr;
void wdeinit(void) {
if (_alloced != nullptr) {
@@ -71,6 +72,11 @@ void *_realloc(void *ptr, size_t size) {
__builtin_unreachable();
}
+void plogstream(FILE *fp) {
+ assert(fp != nullptr);
+ _cminus_logstream = fp;
+}
+
// mathematical vectors
vec2 v2(f32 x, f32 y) {
diff --git a/_.h b/_.h
index 014fb36..8804d97 100644
--- a/_.h
+++ b/_.h
@@ -70,7 +70,12 @@ void *_realloc(void *ptr, size_t size);
#define with(I, T) auto I = (T); if (I)
// logging
-#define pgeneric(PREFIX, ...) fprintf(stderr, \
+extern FILE *_cminus_logstream;
+void plogstream(FILE *fp);
+#define pgeneric(PREFIX, ...) ({ if (_cminus_logstream == nullptr) \
+ _cminus_logstream = stderr; \
+ }), \
+ fprintf(stderr, \
"\x1b[" PREFIX " %s:%s:%d\x1b[0m \t", \
__FILE_NAME__, __FUNCTION__, __LINE__), \
fprintf(stderr, __VA_ARGS__), fputc('\n', stderr)