brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 82ca25a Raw
40 lines · cpp
1//===-- Implementation of mbsrtowcs ---------------------------------------===//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/mbsrtowcs.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, mbsrtowcs,22                   (wchar_t *__restrict dst, const char **__restrict src,23                    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, SIZE_MAX, 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