brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 1bf1994 Raw
46 lines · cpp
1//===-- Unittests for strtoint32 ------------------------------------------===//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 "hdr/stdint_proxy.h"10#include "src/__support/libc_errno.h"11#include "src/__support/macros/config.h"12#include "src/__support/str_to_integer.h"13 14#include "StrtolTest.h"15#include "test/UnitTest/Test.h"16 17namespace LIBC_NAMESPACE_DECL {18 19int32_t strtoint32(const char *__restrict str, char **__restrict str_end,20                   int base) {21  auto result = internal::strtointeger<int32_t>(str, base);22  if (result.has_error())23    libc_errno = result.error;24 25  if (str_end != nullptr)26    *str_end = const_cast<char *>(str + result.parsed_len);27 28  return result;29}30 31uint32_t strtouint32(const char *__restrict str, char **__restrict str_end,32                     int base) {33  auto result = internal::strtointeger<uint32_t>(str, base);34  if (result.has_error())35    libc_errno = result.error;36 37  if (str_end != nullptr)38    *str_end = const_cast<char *>(str + result.parsed_len);39 40  return result;41}42} // namespace LIBC_NAMESPACE_DECL43 44STRTOL_TEST(Strtoint32, LIBC_NAMESPACE::strtoint32)45STRTOL_TEST(Strtouint32, LIBC_NAMESPACE::strtouint32)46