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

Shubh Pachchigar via libc-commits libc-commits at lists.llvm.org
Fri Dec 26 10:33:38 PST 2025


================
@@ -33,7 +41,27 @@ LIBC_INLINE int convert_char(Writer<write_mode> *writer,
     RET_IF_RESULT_NEGATIVE(writer->write(' ', padding_spaces));
   }
 
-  RET_IF_RESULT_NEGATIVE(writer->write(c));
+#ifndef LIBC_COPT_PRINTF_DISABLE_WIDE
+  if (to_conv.length_modifier == LengthModifier::l) {
+    wint_t wi = static_cast<wint_t>(to_conv.conv_val_raw);
+
+    if (wi == WEOF) {
+      return -1;
+    }
+
+    char mb_str[MB_LEN_MAX];
+    internal::mbstate mbstate;
+    wchar_t wc = static_cast<wchar_t>(wi);
+
+    auto ret = internal::wcrtomb(mb_str, wc, &mbstate);
+    if (!ret.has_value()) {
+      return -1;
----------------
shubhe25p wrote:

Resolving this as I think the later approach of adding two error codes looks good to you in your next round of reviews.

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


More information about the libc-commits mailing list