1722832e6SMichael Jones //===-- Unittests for strtoint32 ------------------------------------------===// 2722832e6SMichael Jones // 3722832e6SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4722832e6SMichael Jones // See https://llvm.org/LICENSE.txt for license information. 5722832e6SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6722832e6SMichael Jones // 7722832e6SMichael Jones //===----------------------------------------------------------------------===// 8722832e6SMichael Jones 9722832e6SMichael Jones #include <stdint.h> 10722832e6SMichael Jones 11*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 12722832e6SMichael Jones #include "src/__support/str_to_integer.h" 13722832e6SMichael Jones #include "src/errno/libc_errno.h" 14722832e6SMichael Jones 15722832e6SMichael Jones #include "StrtolTest.h" 16722832e6SMichael Jones #include "test/UnitTest/Test.h" 17722832e6SMichael Jones 18*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 19722832e6SMichael Jones 20722832e6SMichael Jones int32_t strtoint32(const char *__restrict str, char **__restrict str_end, 21722832e6SMichael Jones int base) { 22722832e6SMichael Jones auto result = internal::strtointeger<int32_t>(str, base); 23722832e6SMichael Jones if (result.has_error()) 243eb1e6d8Smichaelrj-google LIBC_NAMESPACE::libc_errno = result.error; 25722832e6SMichael Jones 26722832e6SMichael Jones if (str_end != nullptr) 27722832e6SMichael Jones *str_end = const_cast<char *>(str + result.parsed_len); 28722832e6SMichael Jones 29722832e6SMichael Jones return result; 30722832e6SMichael Jones } 31722832e6SMichael Jones 32722832e6SMichael Jones uint32_t strtouint32(const char *__restrict str, char **__restrict str_end, 33722832e6SMichael Jones int base) { 34722832e6SMichael Jones auto result = internal::strtointeger<uint32_t>(str, base); 35722832e6SMichael Jones if (result.has_error()) 363eb1e6d8Smichaelrj-google LIBC_NAMESPACE::libc_errno = result.error; 37722832e6SMichael Jones 38722832e6SMichael Jones if (str_end != nullptr) 39722832e6SMichael Jones *str_end = const_cast<char *>(str + result.parsed_len); 40722832e6SMichael Jones 41722832e6SMichael Jones return result; 42722832e6SMichael Jones } 43*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 44722832e6SMichael Jones 45b6bc9d72SGuillaume Chatelet STRTOL_TEST(Strtoint32, LIBC_NAMESPACE::strtoint32) 46b6bc9d72SGuillaume Chatelet STRTOL_TEST(Strtouint32, LIBC_NAMESPACE::strtouint32) 47