about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/liburing/0001-Add-custom-error-function-for-tests.patch
blob: 191f6ae8cd5acec8a97b33789971d7bdfdfb4d14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
From d4714fd7aac9c5f499c406703bc437dc6cf72ef3 Mon Sep 17 00:00:00 2001
From: Steffen <steffen.winter@proton.me>
Date: Mon, 13 Feb 2023 17:32:16 +0100
Subject: [PATCH 1/3] Add custom error function for tests.

On musl systems, liburing cannot build examples and tests due to
it's usage of error.h. t_error calls fprintf(stderr, ...) and
exits.

Closes: #786

Signed-off-by: Steffen Winter <steffen.winter@proton.me>
---
 test/helpers.c | 18 ++++++++++++++++++
 test/helpers.h |  2 ++
 2 files changed, 20 insertions(+)

diff --git a/test/helpers.c b/test/helpers.c
index 8fb32b8..caa887e 100644
--- a/test/helpers.c
+++ b/test/helpers.c
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <stdarg.h>
 #include <sys/types.h>
 
 #include <arpa/inet.h>
@@ -266,3 +267,20 @@ bool t_probe_defer_taskrun(void)
 	io_uring_queue_exit(&ring);
 	return true;
 }
+
+/*
+ * Implementation of error(3), prints an error message and exits.
+ */
+void t_error(int status, int errnum, const char *format, ...)
+{
+	va_list args;
+    	va_start(args, format);
+
+	vfprintf(stderr, format, args);
+    	if (errnum)
+        	fprintf(stderr, ": %s", strerror(errnum));
+
+	fprintf(stderr, "\n");
+	va_end(args);
+    	exit(status);
+}
diff --git a/test/helpers.h b/test/helpers.h
index 4375a9e..33b82cf 100644
--- a/test/helpers.h
+++ b/test/helpers.h
@@ -87,6 +87,8 @@ bool t_probe_defer_taskrun(void);
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
+void t_error(int status, int errnum, const char *format, ...);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.39.1