[libc-commits] [libc] [libc] Implemented wcrtomb internal function and public libc function (PR #144596)

via libc-commits libc-commits at lists.llvm.org
Wed Jun 18 09:20:36 PDT 2025


================
@@ -0,0 +1,48 @@
+//===-- Implementation of wcrtomb -----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/wchar/wcrtomb.h"
+#include "src/__support/error_or.h"
+#include "src/__support/wchar/character_converter.h"
+#include "src/__support/wchar/mbstate.h"
+
+#include "hdr/types/char32_t.h"
+#include "hdr/types/mbstate_t.h"
+#include "hdr/types/size_t.h"
+#include "hdr/types/wchar_t.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+ErrorOr<size_t> wcrtomb(char *__restrict s, wchar_t wc,
+                        mbstate_t *__restrict ps) {
+  CharacterConverter cr((internal::mbstate *)ps);
+
+  char buf[sizeof(wchar_t) / sizeof(char)];
----------------
sribee8 wrote:

explain why you need to write to an internal buffer maybe

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


More information about the libc-commits mailing list