[libcxx-commits] [libcxx] [libc++] Fix the locale base API on Linux with musl (PR #167980)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Dec 4 10:18:01 PST 2025


ldionne wrote:

That's what I have in mind, and I believe what @philnik777 also had in mind:

```diff
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 85a2f8ac8ec4..2919f16adb91 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -532,6 +532,7 @@ set(files
   __locale_dir/support/freebsd.h
   __locale_dir/support/fuchsia.h
   __locale_dir/support/linux.h
+  __locale_dir/support/musl.h
   __locale_dir/support/netbsd.h
   __locale_dir/support/no_locale/characters.h
   __locale_dir/support/no_locale/strtonum.h
diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h
index d26d529d4e0c..f9d011782543 100644
--- a/libcxx/include/__locale_dir/locale_base_api.h
+++ b/libcxx/include/__locale_dir/locale_base_api.h
@@ -116,6 +116,8 @@
 #    include <__locale_dir/support/windows.h>
 #  elif defined(__Fuchsia__)
 #    include <__locale_dir/support/fuchsia.h>
+#  elif defined(_LIBCPP_HAS_MUSL_LIBC)
+#    include <__locale_dir/support/musl.h>
 #  elif defined(__linux__)
 #    include <__locale_dir/support/linux.h>
 #  else
diff --git a/libcxx/include/__locale_dir/support/musl.h b/libcxx/include/__locale_dir/support/musl.h
new file mode 100644
index 000000000000..e21046b7ca6d
--- /dev/null
+++ b/libcxx/include/__locale_dir/support/musl.h
@@ -0,0 +1,42 @@
+//===-----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_MUSL_H
+#define _LIBCPP___LOCALE_DIR_SUPPORT_MUSL_H
+
+#include <__config>
+#include <__cstddef/size_t.h>
+#include <__std_mbstate_t.h>
+#include <__utility/forward.h>
+#include <clocale> // std::lconv
+#include <cstdio>
+#include <cstdlib>
+#include <ctype.h>
+#include <stdarg.h>
+#include <string.h>
+#include <time.h>
+#if _LIBCPP_HAS_WIDE_CHARACTERS
+#  include <cwchar>
+#  include <wctype.h>
+#endif
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+namespace __locale {
+
+//
+// Take inspiration from libcxx/include/__locale_dir/support/linux.h
+//
+
+} // namespace __locale
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___LOCALE_DIR_SUPPORT_MUSL_H
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 0ac5a1ade817..59249ec41d40 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -1583,6 +1583,7 @@ module std [system] {
       textual header "__locale_dir/support/freebsd.h"
       textual header "__locale_dir/support/fuchsia.h"
       textual header "__locale_dir/support/linux.h"
+      textual header "__locale_dir/support/musl.h"
       textual header "__locale_dir/support/netbsd.h"
       textual header "__locale_dir/support/no_locale/characters.h"
       textual header "__locale_dir/support/no_locale/strtonum.h"

```

https://github.com/llvm/llvm-project/pull/167980


More information about the libcxx-commits mailing list