commit af0e51e

uint  ·  2026-05-04 16:33:46 +0000 UTC
parent bc0dd24
add xmalloc
2 files changed,  +16, -0
+8, -0
 1@@ -1,6 +1,7 @@
 2 #ifndef UTIL_H
 3 #define UTIL_H
 4 
 5+#include <stddef.h>
 6 #include <stdint.h>
 7 
 8 /**
 9@@ -23,5 +24,12 @@ void die(int ec, const char* msg);
10  */
11 uint32_t rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
12 
13+/**
14+ * @brief allocate or die
15+ *
16+ * @param len bytes to allocate
17+ */
18+void* xmalloc(size_t len);
19+
20 #endif /* UTIL_H */
21 
+8, -0
 1@@ -18,3 +18,11 @@ uint32_t rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
 2 		((uint32_t)r);
 3 }
 4 
 5+void* xmalloc(size_t len)
 6+{
 7+	void* p = malloc(len);
 8+	if (!p)
 9+		die(EXIT_FAILURE, "malloc failed");
10+	return p;
11+}
12+