xref: /llvm-project/libc/src/stdlib/strtold_l.cpp (revision a87105121dd300752c19024ebaf93319c2781a8b)
1*a8710512SJoseph Huber //===-- Implementation of strtold_l ---------------------------------------===//
2*a8710512SJoseph Huber //
3*a8710512SJoseph Huber // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*a8710512SJoseph Huber // See https://llvm.org/LICENSE.txt for license information.
5*a8710512SJoseph Huber // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*a8710512SJoseph Huber //
7*a8710512SJoseph Huber //===----------------------------------------------------------------------===//
8*a8710512SJoseph Huber 
9*a8710512SJoseph Huber #include "src/stdlib/strtold_l.h"
10*a8710512SJoseph Huber #include "src/__support/common.h"
11*a8710512SJoseph Huber #include "src/__support/macros/config.h"
12*a8710512SJoseph Huber #include "src/__support/str_to_float.h"
13*a8710512SJoseph Huber #include "src/errno/libc_errno.h"
14*a8710512SJoseph Huber 
15*a8710512SJoseph Huber namespace LIBC_NAMESPACE_DECL {
16*a8710512SJoseph Huber 
17*a8710512SJoseph Huber LLVM_LIBC_FUNCTION(long double, strtold_l,
18*a8710512SJoseph Huber                    (const char *__restrict str, char **__restrict str_end,
19*a8710512SJoseph Huber                     locale_t)) {
20*a8710512SJoseph Huber   auto result = internal::strtofloatingpoint<long double>(str);
21*a8710512SJoseph Huber   if (result.has_error())
22*a8710512SJoseph Huber     libc_errno = result.error;
23*a8710512SJoseph Huber 
24*a8710512SJoseph Huber   if (str_end != nullptr)
25*a8710512SJoseph Huber     *str_end = const_cast<char *>(str + result.parsed_len);
26*a8710512SJoseph Huber 
27*a8710512SJoseph Huber   return result.value;
28*a8710512SJoseph Huber }
29*a8710512SJoseph Huber 
30*a8710512SJoseph Huber } // namespace LIBC_NAMESPACE_DECL
31