Path: blob/main/system/lib/llvm-libc/src/wchar/wcrtomb.cpp
6174 views
//===-- Implementation of wcrtomb -----------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "src/wchar/wcrtomb.h"910#include "hdr/types/mbstate_t.h"11#include "hdr/types/wchar_t.h"12#include "src/__support/common.h"13#include "src/__support/libc_errno.h"14#include "src/__support/macros/config.h"15#include "src/__support/wchar/mbstate.h"16#include "src/__support/wchar/wcrtomb.h"1718namespace LIBC_NAMESPACE_DECL {1920LLVM_LIBC_FUNCTION(size_t, wcrtomb,21(char *__restrict s, wchar_t wc, mbstate_t *__restrict ps)) {22static internal::mbstate internal_mbstate;2324// when s is nullptr, this is equivalent to wcrtomb(buf, L'\0', ps)25char buf[sizeof(wchar_t) / sizeof(char)];26if (s == nullptr) {27s = buf;28wc = L'\0';29}3031auto result = internal::wcrtomb(32s, wc,33ps == nullptr ? &internal_mbstate34: reinterpret_cast<internal::mbstate *>(ps));3536if (!result.has_value()) {37libc_errno = result.error();38return -1;39}4041return result.value();42}4344} // namespace LIBC_NAMESPACE_DECL454647