1 | //===-- Unittests for strtoint64 ------------------------------------------===// |
---|---|
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 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include <stdint.h> |
10 | |
11 | #include "src/__support/str_to_integer.h" |
12 | #include "src/errno/libc_errno.h" |
13 | |
14 | #include "StrtolTest.h" |
15 | #include "test/UnitTest/Test.h" |
16 | |
17 | namespace LIBC_NAMESPACE { |
18 | |
19 | int64_t strtoint64(const char *__restrict str, char **__restrict str_end, |
20 | int base) { |
21 | auto result = internal::strtointeger<int64_t>(src: str, base); |
22 | if (result.has_error()) |
23 | LIBC_NAMESPACE::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 | |
31 | uint64_t strtouint64(const char *__restrict str, char **__restrict str_end, |
32 | int base) { |
33 | auto result = internal::strtointeger<uint64_t>(src: str, base); |
34 | if (result.has_error()) |
35 | LIBC_NAMESPACE::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 |
43 | |
44 | STRTOL_TEST(Strtoint64, LIBC_NAMESPACE::strtoint64) |
45 | STRTOL_TEST(Strtouint64, LIBC_NAMESPACE::strtouint64) |
46 |