brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · a344c23 Raw
41 lines · cpp
1//===-- Implementation of wcsnrtombs --------------------------------------===//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/wcsnrtombs.h"10 11#include "hdr/types/char32_t.h"12#include "hdr/types/mbstate_t.h"13#include "hdr/types/size_t.h"14#include "hdr/types/wchar_t.h"15#include "src/__support/common.h"16#include "src/__support/libc_errno.h"17#include "src/__support/macros/config.h"18#include "src/__support/wchar/mbstate.h"19#include "src/__support/wchar/wcsnrtombs.h"20 21namespace LIBC_NAMESPACE_DECL {22 23LLVM_LIBC_FUNCTION(size_t, wcsnrtombs,24                   (char *__restrict s, const wchar_t **__restrict pwcs,25                    size_t nwc, size_t len, mbstate_t *__restrict ps)) {26  LIBC_CRASH_ON_NULLPTR(pwcs);27  static internal::mbstate internal_mbstate;28  auto result = internal::wcsnrtombs(29      s, pwcs, nwc, len,30      ps == nullptr ? &internal_mbstate31                    : reinterpret_cast<internal::mbstate *>(ps));32  if (!result.has_value()) {33    libc_errno = result.error();34    return -1;35  }36 37  return result.value();38}39 40} // namespace LIBC_NAMESPACE_DECL41