commit 5e63864

uint  ·  2026-10-13 21:01:55 +0000 UTC
parents e2092e2, 23ef601
Merge pull request #5 from akashsanapala2004/stdarg-todo

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 }