1 //===-- Unittests for strtoint32 ------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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
,
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
);
32 uint32_t strtouint32(const char *__restrict str
, char **__restrict str_end
,
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
);
43 } // namespace LIBC_NAMESPACE_DECL
45 STRTOL_TEST(Strtoint32
, LIBC_NAMESPACE::strtoint32
)
46 STRTOL_TEST(Strtouint32
, LIBC_NAMESPACE::strtouint32
)