brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 8de78e0 Raw
38 lines · cpp
1//===-- Implementation of mbrlen ------------------------------------------===//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/mbrlen.h"10 11#include "hdr/types/mbstate_t.h"12#include "hdr/types/size_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"18 19namespace LIBC_NAMESPACE_DECL {20 21LLVM_LIBC_FUNCTION(size_t, mbrlen,22                   (const char *__restrict s, size_t n,23                    mbstate_t *__restrict ps)) {24  static internal::mbstate internal_mbstate;25  auto ret = internal::mbrtowc(nullptr, s, n,26                               ps == nullptr27                                   ? &internal_mbstate28                                   : reinterpret_cast<internal::mbstate *>(ps));29  if (!ret.has_value()) {30    // Encoding failure31    libc_errno = ret.error();32    return -1;33  }34  return ret.value();35}36 37} // namespace LIBC_NAMESPACE_DECL38