xref: /llvm-project/libc/src/stdlib/strtoll.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
1b062d639SMichael Jones //===-- Implementation of strtoll -----------------------------------------===//
2b062d639SMichael Jones //
3b062d639SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4b062d639SMichael Jones // See https://llvm.org/LICENSE.txt for license information.
5b062d639SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6b062d639SMichael Jones //
7b062d639SMichael Jones //===----------------------------------------------------------------------===//
8b062d639SMichael Jones 
9b062d639SMichael Jones #include "src/stdlib/strtoll.h"
10b062d639SMichael Jones #include "src/__support/common.h"
11*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
1231d797f4SMichael Jones #include "src/__support/str_to_integer.h"
1304a9c625SMichael Jones #include "src/errno/libc_errno.h"
14b062d639SMichael Jones 
15*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
16b062d639SMichael Jones 
17b062d639SMichael Jones LLVM_LIBC_FUNCTION(long long, strtoll,
18b062d639SMichael Jones                    (const char *__restrict str, char **__restrict str_end,
19b062d639SMichael Jones                     int base)) {
2074da5e6cSMichael Jones   auto result = internal::strtointeger<long long>(str, base);
2174da5e6cSMichael Jones   if (result.has_error())
2204a9c625SMichael Jones     libc_errno = result.error;
2374da5e6cSMichael Jones 
2474da5e6cSMichael Jones   if (str_end != nullptr)
2574da5e6cSMichael Jones     *str_end = const_cast<char *>(str + result.parsed_len);
2674da5e6cSMichael Jones 
2774da5e6cSMichael Jones   return result;
28b062d639SMichael Jones }
29b062d639SMichael Jones 
30*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
31