summaryrefslogtreecommitdiff
path: root/etc/patches/clang-16/libcxx-musl-support.patch
blob: 242ea2d9b48d5a41c03cdc144ccef77e3d1b53ed (plain)
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
From 3b3afdadd7d32396a833c10a4e987e7648c2108e Mon Sep 17 00:00:00 2001
From: Oliver Reiche <oliver.reiche@huawei.com>
Date: Wed, 2 Aug 2023 17:04:32 +0200
Subject: [PATCH] libcxx: Add musl support for __locale

... which does not provide a known rune table and uses
missing locale-based string to integer conversion functions.
---
 libcxx/include/__locale | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/libcxx/include/__locale b/libcxx/include/__locale
index e0ffa0ca0..17b628696 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -22,6 +22,38 @@
 #include <cstddef>
 #include <cstring>
 
+// Detect musl libc (inspired by musl detection from gcc's config.guess)
+#include <features.h>
+#if !(defined(__UCLIBC__) || defined(__dietlibc__) || defined(__GLIBC__))
+# include <stdarg.h>
+# ifdef __DEFINED_va_list
+#  ifndef __MUSL_LIBC__
+#   define __MUSL_LIBC__
+#  endif
+# endif
+#endif
+
+#ifdef __MUSL_LIBC__
+// Fall back to default rune table for musl libc
+# ifndef _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
+#  define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
+# endif
+// Implement missing strto*_l functions for musl libc
+# define __MUSL_LIBC_CREATE_STRTOX_L(X) \
+  static inline auto \
+  strto ## X ## _l(const char* str, char** end, int base, locale_t l) { \
+    locale_t old = uselocale(l); \
+    auto result = strto ## X(str, end, base); \
+    uselocale(old); \
+    return result; \
+  }
+__MUSL_LIBC_CREATE_STRTOX_L(l)
+__MUSL_LIBC_CREATE_STRTOX_L(ll)
+__MUSL_LIBC_CREATE_STRTOX_L(ul)
+__MUSL_LIBC_CREATE_STRTOX_L(ull)
+# undef __MUSL_LIBC_CREATE_STRTOX_L
+#endif
+
 #if defined(_LIBCPP_MSVCRT_LIKE)
 # include <__support/win32/locale_win32.h>
 #elif defined(_AIX) || defined(__MVS__)
-- 
2.30.2