Revert "[lldb][test] Remove compiler version check and use regex" (#124101)
[llvm-project.git] / libc / test / src / stdlib / strtoint32_test.cpp
blob17df432fc8e68fdc9c2c73672a025f6c02d60069
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include <stdint.h>
11 #include "src/__support/macros/config.h"
12 #include "src/__support/str_to_integer.h"
13 #include "src/errno/libc_errno.h"
15 #include "StrtolTest.h"
16 #include "test/UnitTest/Test.h"
18 namespace LIBC_NAMESPACE_DECL {
20 int32_t strtoint32(const char *__restrict str, char **__restrict str_end,
21 int base) {
22 auto result = internal::strtointeger<int32_t>(str, base);
23 if (result.has_error())
24 LIBC_NAMESPACE::libc_errno = result.error;
26 if (str_end != nullptr)
27 *str_end = const_cast<char *>(str + result.parsed_len);
29 return result;
32 uint32_t strtouint32(const char *__restrict str, char **__restrict str_end,
33 int base) {
34 auto result = internal::strtointeger<uint32_t>(str, base);
35 if (result.has_error())
36 LIBC_NAMESPACE::libc_errno = result.error;
38 if (str_end != nullptr)
39 *str_end = const_cast<char *>(str + result.parsed_len);
41 return result;
43 } // namespace LIBC_NAMESPACE_DECL
45 STRTOL_TEST(Strtoint32, LIBC_NAMESPACE::strtoint32)
46 STRTOL_TEST(Strtouint32, LIBC_NAMESPACE::strtouint32)