Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,11 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.wchar.wmemchr
libc.src.wchar.wcpcpy
libc.src.wchar.wcpncpy
libc.src.wchar.wcstod
libc.src.wchar.wcstof
libc.src.wchar.wcstok
libc.src.wchar.wcstol
libc.src.wchar.wcstold
libc.src.wchar.wcstoll
libc.src.wchar.wcstoul
libc.src.wchar.wcstoull
Expand Down
14 changes: 14 additions & 0 deletions libc/include/wchar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,17 @@ functions:
arguments:
- type: const wchar_t *__restrict
- type: wchar_t **__restrict
- name: wcstod
standards:
- stdc
return_type: double
arguments:
- type: const wchar_t *__restrict
- type: wchar_t **__restrict
- name: wcstold
standards:
- stdc
return_type: long double
arguments:
- type: const wchar_t *__restrict
- type: wchar_t **__restrict
22 changes: 22 additions & 0 deletions libc/src/wchar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ add_entrypoint_object(
libc.src.errno.errno
)

add_entrypoint_object(
wcstod
SRCS
wcstod.cpp
HDRS
wcstod.h
DEPENDS
libc.src.__support.str_to_float
libc.src.errno.errno
)

add_entrypoint_object(
wcstold
SRCS
wcstold.cpp
HDRS
wcstold.h
DEPENDS
libc.src.__support.str_to_float
libc.src.errno.errno
)

add_entrypoint_object(
wcstok
SRCS
Expand Down
30 changes: 30 additions & 0 deletions libc/src/wchar/wcstod.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===-- Implementation of wcstod ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/wchar/wcstod.h"
#include "src/__support/common.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include "src/__support/str_to_float.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(double, wcstod,
(const wchar_t *__restrict str,
wchar_t **__restrict str_end)) {
auto result = internal::strtofloatingpoint<double>(str);
if (result.has_error())
libc_errno = result.error;

if (str_end != nullptr)
*str_end = const_cast<wchar_t *>(str + result.parsed_len);

return result.value;
}

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/wchar/wcstod.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for wcstod ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_WCHAR_WCSTOD_H
#define LLVM_LIBC_SRC_WCHAR_WCSTOD_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

double wcstod(const wchar_t *__restrict str, wchar_t **__restrict str_end);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_WCHAR_WCSTOD_H
30 changes: 30 additions & 0 deletions libc/src/wchar/wcstold.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===-- Implementation of wcstold -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/wchar/wcstold.h"
#include "src/__support/common.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include "src/__support/str_to_float.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(long double, wcstold,
(const wchar_t *__restrict str,
wchar_t **__restrict str_end)) {
auto result = internal::strtofloatingpoint<long double>(str);
if (result.has_error())
libc_errno = result.error;

if (str_end != nullptr)
*str_end = const_cast<wchar_t *>(str + result.parsed_len);

return result.value;
}

} // namespace LIBC_NAMESPACE_DECL
21 changes: 21 additions & 0 deletions libc/src/wchar/wcstold.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header for wcstold -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_WCHAR_WCSTOLD_H
#define LLVM_LIBC_SRC_WCHAR_WCSTOLD_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

long double wcstold(const wchar_t *__restrict str,
wchar_t **__restrict str_end);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_WCHAR_WCSTOLD_H
29 changes: 28 additions & 1 deletion libc/test/src/wchar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -538,5 +538,32 @@ add_libc_test(
DEPENDS
libc.src.wchar.wcstof
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.LibcFPTestHelpers
LINK_LIBRARIES
LibcFPTestHelpers
)

add_libc_test(
wcstod_test
SUITE
libc_wchar_unittests
SRCS
wcstod_test.cpp
DEPENDS
libc.src.wchar.wcstod
libc.test.UnitTest.ErrnoCheckingTest
LINK_LIBRARIES
LibcFPTestHelpers
)

add_libc_test(
wcstold_test
SUITE
libc_wchar_unittests
SRCS
wcstold_test.cpp
DEPENDS
libc.src.__support.FPUtil.fp_bits
libc.src.__support.uint128
libc.src.wchar.wcstold
libc.test.UnitTest.ErrnoCheckingTest
)
Loading
Loading