[libc-commits] [libc] [libc] Support ls in printf (PR #178841)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Wed Feb 4 14:47:12 PST 2026
================
@@ -50,7 +101,48 @@ LIBC_INLINE int convert_string(Writer<write_mode> *writer,
RET_IF_RESULT_NEGATIVE(writer->write(' ', padding_spaces));
}
- RET_IF_RESULT_NEGATIVE(writer->write({(str_ptr), string_len}));
+ if (to_conv.length_modifier == LengthModifier::l) {
+#ifndef LIBC_COPT_PRINTF_DISABLE_WIDE
+ const wchar_t *wstr_ptr =
+ reinterpret_cast<const wchar_t *>(to_conv.conv_val_ptr);
+
+#ifndef LIBC_COPT_PRINTF_NO_NULLPTR_CHECKS
+ if (wstr_ptr == nullptr) {
+ wstr_ptr = L"(null)";
+ }
+#endif // LIBC_COPT_PRINTF_NO_NULLPTR_CHECKS
+
+ size_t written = 0;
+ char buffer[MB_LEN_MAX];
+ internal::mbstate mbstate;
+ for (size_t i = 0; written < string_len; ++i) {
+ // We don't need to check errors/precision here; Pass 1 guaranteed safety.
+ auto ret = internal::wcrtomb(buffer, wstr_ptr[i], &mbstate);
+ size_t mb_len = ret.value();
+
+ RET_IF_RESULT_NEGATIVE(writer->write({buffer, mb_len}));
+ written += mb_len;
----------------
michaelrj-google wrote:
same as above, this should use the `StringConverter` directly.
https://github.com/llvm/llvm-project/pull/178841
More information about the libc-commits
mailing list