~xdavidwu/systemd-apkbuilds

ref: 41b96cafd0e6d4a12252bbbb6564230ecc968f30 systemd-apkbuilds/systemd/0021-errno-util-Make-STRERROR-portable-for-musl.patch -rw-r--r-- 1.5 KiB
41b96cafPinghao Wu systemd: 256.2 8 months ago
                                                                                
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
From d2f632dd6a8cca0fbdd6568ce84004335c004f58 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Mon, 23 Jan 2023 23:39:46 -0800
Subject: [PATCH 21/27] errno-util: Make STRERROR portable for musl

Sadly, systemd has decided to use yet another GNU extention in a macro
lets make this such that we can use XSI compliant strerror_r() for
non-glibc hosts

Upstream-Status: Inappropriate [musl specific]

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 src/basic/errno-util.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/basic/errno-util.h b/src/basic/errno-util.h
index 48b76e4bf7..6e7653e2d9 100644
--- a/src/basic/errno-util.h
+++ b/src/basic/errno-util.h
@@ -15,8 +15,16 @@
  * https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks
  *
  * Note that we use the GNU variant of strerror_r() here. */
-#define STRERROR(errnum) strerror_r(abs(errnum), (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN)
-
+static inline const char * STRERROR(int errnum);
+
+static inline const char * STRERROR(int errnum) {
+#ifdef __GLIBC__
+        return strerror_r(abs(errnum), (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN);
+#else
+        static __thread char buf[ERRNO_BUF_LEN];
+        return strerror_r(abs(errnum), buf, ERRNO_BUF_LEN) ? "unknown error" : buf;
+#endif
+}
 /* A helper to print an error message or message for functions that return 0 on EOF.
  * Note that we can't use ({ … }) to define a temporary variable, so errnum is
  * evaluated twice. */
-- 
2.45.1