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//===----------------------------------------------------------------------===//
8
9#include <stdint.h>
10
11#include "src/__support/libc_errno.h"
12#include "src/__support/macros/config.h"
13#include "src/__support/str_to_integer.h"
14
15#include "StrtolTest.h"
16#include "test/UnitTest/Test.h"
17
18namespace LIBC_NAMESPACE_DECL {
19
20int32_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_errno = result.error;
25
26 if (str_end != nullptr)
27 *str_end = const_cast<char *>(str + result.parsed_len);
28
29 return result;
30}
31
32uint32_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_errno = result.error;
37
38 if (str_end != nullptr)
39 *str_end = const_cast<char *>(str + result.parsed_len);
40
41 return result;
42}
43} // namespace LIBC_NAMESPACE_DECL
44
45STRTOL_TEST(Strtoint32, LIBC_NAMESPACE::strtoint32)
46STRTOL_TEST(Strtouint32, LIBC_NAMESPACE::strtouint32)
47

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of libc/test/src/stdlib/strtoint32_test.cpp