[libc-commits] [libc] [libc] Support %lc in printf (PR #169983)

Alexey Samsonov via libc-commits libc-commits at lists.llvm.org
Fri Dec 26 09:31:51 PST 2025


================
@@ -20,20 +29,49 @@ namespace printf_core {
 template <WriteMode write_mode>
 LIBC_INLINE int convert_char(Writer<write_mode> *writer,
                              const FormatSection &to_conv) {
-  char c = static_cast<char>(to_conv.conv_val_raw);
 
-  constexpr int STRING_LEN = 1;
+  char buffer[MB_LEN_MAX];
+  cpp::string_view to_write;
+
+  if (to_conv.length_modifier == LengthModifier::l) {
+#ifndef LIBC_COPT_PRINTF_DISABLE_WIDE
+    wint_t wi = static_cast<wint_t>(to_conv.conv_val_raw);
+
+    if (wi == WEOF) {
+      return ILLEGAL_WIDE_CHAR;
+    }
+
+    internal::mbstate mbstate;
+    wchar_t wc = static_cast<wchar_t>(wi);
+    auto ret = wcrtomb(buffer, wc, &mbstate);
----------------
vonosmas wrote:

Could you use `internal::wcrtomb` to clarify you're not using a C function.

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


More information about the libc-commits mailing list