commit 4b64b80
Akash
·
2026-10-13 16:40:15 +0000 UTC
parent e2092e2
Using stdarg in die in file utils.c
2 files changed,
+8,
-2
+1,
-1
1@@ -6,7 +6,7 @@
2
3 /* perror `msg` and exit program with `ec`
4 TODO? stdarg */
5-void die(int ec, const char* msg);
6+void die(int ec, const char* msg,...);
7
8 /* pack r, g, b and a into u32 (AARRGGBB) */
9 uint32_t rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
+7,
-1
1@@ -1,12 +1,18 @@
2 #include <stdio.h>
3 #include <stdlib.h>
4+#include <stdarg.h>
5
6 #include "utils.h"
7
8 /* perror `msg` and exit program with `ec`
9 TODO? stdarg */
10-void die(int ec, const char* msg)
11+void die(int ec, const char* msg,...)
12 {
13+ va_list args;
14+ va_start(args, msg);
15+ vfprintf(stderr, msg, args);
16+ va_end(args);
17+ exit(ec);
18 perror(msg);
19 exit(ec);
20 }