1From d4714fd7aac9c5f499c406703bc437dc6cf72ef3 Mon Sep 17 00:00:00 2001
2From: Steffen <steffen.winter@proton.me>
3Date: Mon, 13 Feb 2023 17:32:16 +0100
4Subject: [PATCH 1/3] Add custom error function for tests.
5
6On musl systems, liburing cannot build examples and tests due to
7it's usage of error.h. t_error calls fprintf(stderr, ...) and
8exits.
9
10Closes: #786
11
12Signed-off-by: Steffen Winter <steffen.winter@proton.me>
13---
14 test/helpers.c | 18 ++++++++++++++++++
15 test/helpers.h | 2 ++
16 2 files changed, 20 insertions(+)
17
18diff --git a/test/helpers.c b/test/helpers.c
19index 8fb32b8..caa887e 100644
20--- a/test/helpers.c
21+++ b/test/helpers.c
22@@ -8,6 +8,7 @@
23 #include <stdio.h>
24 #include <fcntl.h>
25 #include <unistd.h>
26+#include <stdarg.h>
27 #include <sys/types.h>
28
29 #include <arpa/inet.h>
30@@ -266,3 +267,20 @@ bool t_probe_defer_taskrun(void)
31 io_uring_queue_exit(&ring);
32 return true;
33 }
34+
35+/*
36+ * Implementation of error(3), prints an error message and exits.
37+ */
38+void t_error(int status, int errnum, const char *format, ...)
39+{
40+ va_list args;
41+ va_start(args, format);
42+
43+ vfprintf(stderr, format, args);
44+ if (errnum)
45+ fprintf(stderr, ": %s", strerror(errnum));
46+
47+ fprintf(stderr, "\n");
48+ va_end(args);
49+ exit(status);
50+}
51diff --git a/test/helpers.h b/test/helpers.h
52index 4375a9e..33b82cf 100644
53--- a/test/helpers.h
54+++ b/test/helpers.h
55@@ -87,6 +87,8 @@ bool t_probe_defer_taskrun(void);
56
57 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
58
59+void t_error(int status, int errnum, const char *format, ...);
60+
61 #ifdef __cplusplus
62 }
63 #endif
64--
652.39.1
66