[libcxx-commits] [libcxx] [libc++] Add implementations of __get_locale_encoding(...) to Fuschia and LLVM-Libc (PR #205716)

William Tran-Viet via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 24 19:52:22 PDT 2026


https://github.com/smallp-o-p created https://github.com/llvm/llvm-project/pull/205716

- These were missed in #141312 and consequently broke the Fuschia and AMDGPU llvm-libc build bots.
- Fuschia seems to have support for `nl_langinfo_l(...)`, so we can use that.
- However, LLVM-libc does not implement it, so for now we can mark `environment()` and `encoding()` as unsupported on LLVM libc.

>From 9152f88ab6126bc9c7ef8c9f6bb31ddeb4924a1f Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranviet at proton.me>
Date: Wed, 24 Jun 2026 22:47:40 -0400
Subject: [PATCH] Add __get_locale_encoding for fuschia, dummy implementation
 for llvm-libc

---
 libcxx/include/__locale_dir/support/fuchsia.h                | 5 +++++
 libcxx/include/__locale_dir/support/llvm_libc.h              | 2 ++
 libcxx/test/libcxx/text/text_encoding/environment.pass.cpp   | 1 +
 .../text_encoding/text_encoding.members/environment.pass.cpp | 1 +
 4 files changed, 9 insertions(+)

diff --git a/libcxx/include/__locale_dir/support/fuchsia.h b/libcxx/include/__locale_dir/support/fuchsia.h
index 528bfeb0cb6e1..e2e97a77c6c46 100644
--- a/libcxx/include/__locale_dir/support/fuchsia.h
+++ b/libcxx/include/__locale_dir/support/fuchsia.h
@@ -15,6 +15,7 @@
 #include <cstdio>
 #include <cstdlib>
 #include <cwchar>
+#include <langinfo.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -69,6 +70,10 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
   return std::localeconv();
 }
 
+inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding([[maybe_unused]] __locale_t __loc) {
+  return ::nl_langinfo_l(CODESET, __loc);
+}
+
 //
 // Other functions
 //
diff --git a/libcxx/include/__locale_dir/support/llvm_libc.h b/libcxx/include/__locale_dir/support/llvm_libc.h
index 1ce1c443d87ed..d4a88f7e51191 100644
--- a/libcxx/include/__locale_dir/support/llvm_libc.h
+++ b/libcxx/include/__locale_dir/support/llvm_libc.h
@@ -47,6 +47,8 @@ inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __loc
 }
 
 inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t&) { return std::localeconv(); }
+
+inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding([[maybe_unused]] __locale_t) { return nullptr; }
 #endif // _LIBCPP_BUILDING_LIBRARY
 
 } // namespace __locale
diff --git a/libcxx/test/libcxx/text/text_encoding/environment.pass.cpp b/libcxx/test/libcxx/text/text_encoding/environment.pass.cpp
index b5c88c6e6d568..0bcabb235fc8b 100644
--- a/libcxx/test/libcxx/text/text_encoding/environment.pass.cpp
+++ b/libcxx/test/libcxx/text/text_encoding/environment.pass.cpp
@@ -14,6 +14,7 @@
 // UNSUPPORTED: no-localization
 // UNSUPPORTED: windows, android
 // UNSUPPORTED: availability-te-environment-missing
+// UNSUPPORTED: LLVM-LIBC-FIXME
 
 // std::text_encoding::environment()
 
diff --git a/libcxx/test/std/text/text_encoding/text_encoding.members/environment.pass.cpp b/libcxx/test/std/text/text_encoding/text_encoding.members/environment.pass.cpp
index 113b151765c81..8907f72b55140 100644
--- a/libcxx/test/std/text/text_encoding/text_encoding.members/environment.pass.cpp
+++ b/libcxx/test/std/text/text_encoding/text_encoding.members/environment.pass.cpp
@@ -11,6 +11,7 @@
 
 // UNSUPPORTED: no-localization
 // UNSUPPORTED: availability-te-environment-missing
+// UNSUPPORTED: LLVM-LIBC-FIXME
 
 // <text_encoding>
 



More information about the libcxx-commits mailing list