[libc-commits] [libc] [libc] Implement wcs to mbs family of functions (PR #149421)
via libc-commits
libc-commits at lists.llvm.org
Fri Jul 18 12:17:20 PDT 2025
================
@@ -0,0 +1,63 @@
+//===-- Implementation header for wcsnrtombs ------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC__SUPPORT_WCHAR_WCSNRTOMBS_H
+#define LLVM_LIBC_SRC__SUPPORT_WCHAR_WCSNRTOMBS_H
+
+#include "hdr/types/char32_t.h"
+#include "hdr/types/size_t.h"
+#include "hdr/types/wchar_t.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/wchar/mbstate.h"
+#include "src/__support/wchar/string_converter.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+ErrorOr<size_t> wcsnrtombs(char *__restrict s, const wchar_t **__restrict pwcs,
+ size_t nwc, size_t len, mbstate *ps) {
+ CharacterConverter cr(ps);
+ if (!cr.isValidState())
+ return Error(EINVAL);
+
+ if (s == nullptr)
+ len = SIZE_MAX;
+
+ StringConverter<char32_t> str_conv(reinterpret_cast<const char32_t *>(*pwcs),
----------------
lntue wrote:
any check for `pwcs == nullptr`?
https://github.com/llvm/llvm-project/pull/149421
More information about the libc-commits
mailing list