[libc-commits] [libc] [libc] Add support for writing to wchar_t in printf_core/ converter functions. (PR #230246)

Alex Strelnikov via libc-commits libc-commits at lists.llvm.org
Thu Oct 15 06:54:05 PDT 2026


================
@@ -82,6 +82,65 @@ LIBC_INLINE int convert_char(Writer<mode> *writer,
   return WRITE_OK;
 }
 
+#if !defined(LIBC_COPT_PRINTF_DISABLE_WIDE)
+
+template <OverflowMode mode>
+LIBC_INLINE int
+write_character_as_wchar(Writer<mode, wchar_t> *writer,
+                         const FormatSection<wchar_t> &to_conv) {
+  wchar_t write_char;
+
+  if (to_conv.length_modifier == LengthModifier::l) {
+    wint_t wi = static_cast<wint_t>(to_conv.conv_val_raw);
+    if (wi == WEOF)
+      return ILLEGAL_WIDE_CHAR;
+
+    write_char = static_cast<wchar_t>(wi);
+  } else {
+    int c = static_cast<int>(to_conv.conv_val_raw);
----------------
strel-12 wrote:

Also updated this line to cast to `int` instead of `char` as part of the review fixes.

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


More information about the libc-commits mailing list