40 lines · cpp
1//===-- Implementation of mbsnrtowcs --------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/wchar/mbsnrtowcs.h"10 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/mbsnrtowcs.h"17#include "src/__support/wchar/mbstate.h"18 19namespace LIBC_NAMESPACE_DECL {20 21LLVM_LIBC_FUNCTION(size_t, mbsnrtowcs,22 (wchar_t *__restrict dst, const char **__restrict src,23 size_t nmc, size_t len, mbstate_t *__restrict ps)) {24 static internal::mbstate internal_mbstate;25 // If destination is null, ignore len26 len = dst == nullptr ? SIZE_MAX : len;27 auto ret = internal::mbsnrtowcs(28 dst, src, nmc, len,29 ps == nullptr ? &internal_mbstate30 : reinterpret_cast<internal::mbstate *>(ps));31 if (!ret.has_value()) {32 // Encoding failure33 libc_errno = ret.error();34 return -1;35 }36 return ret.value();37}38 39} // namespace LIBC_NAMESPACE_DECL40