commit 05a293a

uint  ·  2026-06-02 15:51:18 +0000 UTC
parent 3a9fc50
Add maus_die, change maus_log behavior
2 files changed,  +25, -2
+24, -2
 1@@ -1,15 +1,37 @@
 2 #include <stdarg.h>
 3 #include <stdio.h>
 4+#include <stdlib.h>
 5 
 6 #include "mauswin.h"
 7 
 8+static void vlog(FILE* fd, const char* fmt, va_list ap);
 9+
10+/* log message to output `fd` */
11+static void vlog(FILE* fd, const char* fmt, va_list ap)
12+{
13+	fprintf(fd, "maus: ");
14+	vfprintf(fd, fmt, ap);
15+	fflush(fd);
16+}
17+
18+/* log message to output `fd` and die
19+   on finish */
20+void maus_die(const char* fmt, ...)
21+{
22+	va_list ap;
23+	va_start(ap, fmt);
24+	vlog(stderr, fmt, ap);
25+	va_end(ap);
26+
27+	exit(EXIT_FAILURE);
28+}
29+
30 /* log message to output `fd` */
31 void maus_log(FILE* fd, const char* fmt, ...)
32 {
33 	va_list ap;
34 	va_start(ap, fmt);
35-	vfprintf(fd, fmt, ap);
36-	fflush(stderr);
37+	vlog(fd, fmt, ap);
38 	va_end(ap);
39 }
40 
+1, -0
1@@ -35,6 +35,7 @@
2 
3 #endif
4 
5+void maus_die(const char* fmt, ...);
6 MausWindow* maus_init(const char* title, int width, int height);
7 void maus_log(FILE* fd, const char* fmt, ...);
8