commit eeb9766
uint
·
2026-07-21 14:35:24 +0000 UTC
parent b21122e
add logging, error codes list
2 files changed,
+52,
-0
+33,
-0
1@@ -0,0 +1,33 @@
2+#include <stdarg.h>
3+#include <stdio.h>
4+#include <stdlib.h>
5+
6+#include "util.h"
7+
8+static void vlog(FILE* fd, const char* fmt, va_list ap);
9+
10+static void vlog(FILE* fd, const char* fmt, va_list ap)
11+{
12+ fprintf(fd, "magnolia: ");
13+ vfprintf(fd, fmt, ap);
14+ fputc('\n', stderr);
15+}
16+
17+void mg_die(int ec, const char* fmt, ...)
18+{
19+ va_list ap;
20+ va_start(ap, fmt);
21+ vlog(stderr, fmt, ap);
22+ va_end(ap);
23+
24+ fprintf(stderr, "Died with ErrorCode [%d]\n", ec);
25+ exit(ec);
26+}
27+
28+void mg_log(FILE* fd, const char* fmt, ...)
29+{
30+ va_list ap;
31+ va_start(ap, fmt);
32+ vlog(fd, fmt, ap);
33+ va_end(ap);
34+}
+19,
-0
1@@ -0,0 +1,19 @@
2+#ifndef LOG_H
3+#define LOG_H
4+
5+#include <stdio.h>
6+
7+typedef enum {
8+ MG_ERR_EXIT_SUCCESS,
9+ MG_ERR_EXIT_FAILURE,
10+
11+ MG_ERR_GL_CTX_CREATE,
12+
13+ MG_ERR_LAST
14+} MGErrorCodes;
15+
16+void mg_die(int ec, const char* fmt, ...);
17+void mg_log(FILE* fd, const char* fmt, ...);
18+
19+#endif /* LOG_H */
20+