Path: blob/main/system/lib/llvm-libc/src/wchar/mbrtowc.cpp
6174 views
//===-- Implementation of mbrtowc -----------------------------------------===//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/mbrtowc.h"910#include "hdr/types/mbstate_t.h"11#include "hdr/types/size_t.h"12#include "hdr/types/wchar_t.h"13#include "src/__support/common.h"14#include "src/__support/libc_errno.h"15#include "src/__support/macros/config.h"16#include "src/__support/wchar/mbrtowc.h"17#include "src/__support/wchar/mbstate.h"1819namespace LIBC_NAMESPACE_DECL {2021LLVM_LIBC_FUNCTION(size_t, mbrtowc,22(wchar_t *__restrict pwc, const char *__restrict s, size_t n,23mbstate_t *__restrict ps)) {24static internal::mbstate internal_mbstate;25auto ret = internal::mbrtowc(pwc, s, n,26ps == nullptr27? &internal_mbstate28: reinterpret_cast<internal::mbstate *>(ps));29if (!ret.has_value()) {30// Encoding failure31libc_errno = ret.error();32return -1;33}34return ret.value();35}3637} // namespace LIBC_NAMESPACE_DECL383940