brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 712af95 Raw
39 lines · cpp
1//===-- Implementation of wcstombs ----------------------------------------===//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/stdlib/wcstombs.h"10 11#include "hdr/types/char32_t.h"12#include "hdr/types/size_t.h"13#include "hdr/types/wchar_t.h"14#include "src/__support/common.h"15#include "src/__support/libc_errno.h"16#include "src/__support/macros/config.h"17#include "src/__support/wchar/mbstate.h"18#include "src/__support/wchar/wcsnrtombs.h"19 20namespace LIBC_NAMESPACE_DECL {21 22LLVM_LIBC_FUNCTION(size_t, wcstombs,23                   (char *__restrict s, const wchar_t *__restrict wcs,24                    size_t n)) {25  LIBC_CRASH_ON_NULLPTR(wcs);26  static internal::mbstate internal_mbstate;27  const wchar_t *wcs_ptr_copy = wcs;28  auto result =29      internal::wcsnrtombs(s, &wcs_ptr_copy, SIZE_MAX, n, &internal_mbstate);30  if (!result.has_value()) {31    libc_errno = result.error();32    return -1;33  }34 35  return result.value();36}37 38} // namespace LIBC_NAMESPACE_DECL39