diff options
Diffstat (limited to 'libc/src/wchar')
| -rw-r--r-- | libc/src/wchar/CMakeLists.txt | 102 | ||||
| -rw-r--r-- | libc/src/wchar/btowc.cpp | 8 | ||||
| -rw-r--r-- | libc/src/wchar/mbstowcs.cpp | 40 | ||||
| -rw-r--r-- | libc/src/wchar/mbtowc.cpp | 37 | ||||
| -rw-r--r-- | libc/src/wchar/wcstod.cpp | 30 | ||||
| -rw-r--r-- | libc/src/wchar/wcstod.h (renamed from libc/src/wchar/mbtowc.h) | 12 | ||||
| -rw-r--r-- | libc/src/wchar/wcstof.cpp | 30 | ||||
| -rw-r--r-- | libc/src/wchar/wcstof.h (renamed from libc/src/wchar/wctomb.h) | 11 | ||||
| -rw-r--r-- | libc/src/wchar/wcstol.cpp | 4 | ||||
| -rw-r--r-- | libc/src/wchar/wcstold.cpp | 30 | ||||
| -rw-r--r-- | libc/src/wchar/wcstold.h (renamed from libc/src/wchar/mbstowcs.h) | 13 | ||||
| -rw-r--r-- | libc/src/wchar/wcstoll.cpp | 4 | ||||
| -rw-r--r-- | libc/src/wchar/wcstombs.cpp | 38 | ||||
| -rw-r--r-- | libc/src/wchar/wcstombs.h | 22 | ||||
| -rw-r--r-- | libc/src/wchar/wcstoul.cpp | 4 | ||||
| -rw-r--r-- | libc/src/wchar/wcstoull.cpp | 4 | ||||
| -rw-r--r-- | libc/src/wchar/wctob.cpp | 12 | ||||
| -rw-r--r-- | libc/src/wchar/wctomb.cpp | 35 |
18 files changed, 159 insertions, 277 deletions
diff --git a/libc/src/wchar/CMakeLists.txt b/libc/src/wchar/CMakeLists.txt index adde382..ce57199 100644 --- a/libc/src/wchar/CMakeLists.txt +++ b/libc/src/wchar/CMakeLists.txt @@ -40,7 +40,6 @@ add_entrypoint_object( DEPENDS libc.hdr.types.wint_t libc.hdr.stdio_macros - libc.src.__support.wctype_utils ) add_entrypoint_object( @@ -52,7 +51,6 @@ add_entrypoint_object( DEPENDS libc.hdr.types.wint_t libc.hdr.wchar_macros - libc.src.__support.wctype_utils ) add_entrypoint_object( @@ -63,7 +61,7 @@ add_entrypoint_object( wcstol.h DEPENDS libc.src.errno.errno - libc.src.__support.wcs_to_integer + libc.src.__support.str_to_integer ) add_entrypoint_object( @@ -74,7 +72,7 @@ add_entrypoint_object( wcstoll.h DEPENDS libc.src.errno.errno - libc.src.__support.wcs_to_integer + libc.src.__support.str_to_integer ) add_entrypoint_object( @@ -85,7 +83,7 @@ add_entrypoint_object( wcstoul.h DEPENDS libc.src.errno.errno - libc.src.__support.wcs_to_integer + libc.src.__support.str_to_integer ) add_entrypoint_object( @@ -96,109 +94,96 @@ add_entrypoint_object( wcstoull.h DEPENDS libc.src.errno.errno - libc.src.__support.wcs_to_integer + libc.src.__support.str_to_integer ) add_entrypoint_object( - wcstok + wcstof SRCS - wcstok.cpp + wcstof.cpp HDRS - wcstok.h + wcstof.h DEPENDS - libc.hdr.types.wchar_t + libc.src.__support.str_to_float + libc.src.errno.errno ) add_entrypoint_object( - wcrtomb + wcstod SRCS - wcrtomb.cpp + wcstod.cpp HDRS - wcrtomb.h + wcstod.h DEPENDS - libc.hdr.types.wchar_t - libc.hdr.types.mbstate_t - libc.src.__support.libc_errno - libc.src.__support.wchar.wcrtomb - libc.src.__support.wchar.mbstate + libc.src.__support.str_to_float + libc.src.errno.errno ) add_entrypoint_object( - wctomb + wcstold SRCS - wctomb.cpp + wcstold.cpp HDRS - wctomb.h + wcstold.h DEPENDS - libc.hdr.types.wchar_t - libc.src.__support.wchar.wcrtomb - libc.src.__support.wchar.mbstate - libc.src.__support.libc_errno + libc.src.__support.str_to_float + libc.src.errno.errno ) add_entrypoint_object( - mbsinit + wcstok SRCS - mbsinit.cpp + wcstok.cpp HDRS - mbsinit.h + wcstok.h DEPENDS libc.hdr.types.wchar_t - libc.hdr.types.mbstate_t - libc.src.__support.common - libc.src.__support.macros.config - libc.src.__support.wchar.character_converter - libc.src.__support.wchar.mbstate ) add_entrypoint_object( - mbrtowc + wcrtomb SRCS - mbrtowc.cpp + wcrtomb.cpp HDRS - mbrtowc.h + wcrtomb.h DEPENDS - libc.hdr.types.size_t - libc.hdr.types.mbstate_t libc.hdr.types.wchar_t - libc.src.__support.common - libc.src.__support.macros.config - libc.src.__support.wchar.mbrtowc + libc.hdr.types.mbstate_t libc.src.__support.libc_errno + libc.src.__support.wchar.wcrtomb libc.src.__support.wchar.mbstate ) add_entrypoint_object( - mbtowc + mbsinit SRCS - mbtowc.cpp + mbsinit.cpp HDRS - mbtowc.h + mbsinit.h DEPENDS - libc.hdr.types.size_t libc.hdr.types.wchar_t + libc.hdr.types.mbstate_t libc.src.__support.common libc.src.__support.macros.config - libc.src.__support.libc_errno - libc.src.__support.wchar.mbrtowc + libc.src.__support.wchar.character_converter libc.src.__support.wchar.mbstate ) add_entrypoint_object( - mbstowcs + mbrtowc SRCS - mbstowcs.cpp + mbrtowc.cpp HDRS - mbstowcs.h + mbrtowc.h DEPENDS libc.hdr.types.size_t + libc.hdr.types.mbstate_t libc.hdr.types.wchar_t libc.src.__support.common libc.src.__support.macros.config - libc.src.__support.macros.null_check + libc.src.__support.wchar.mbrtowc libc.src.__support.libc_errno libc.src.__support.wchar.mbstate - libc.src.__support.wchar.mbsnrtowcs ) add_entrypoint_object( @@ -234,19 +219,6 @@ add_entrypoint_object( ) add_entrypoint_object( - wcstombs - SRCS - wcstombs.cpp - HDRS - wcstombs.h - DEPENDS - libc.hdr.types.wchar_t - libc.src.__support.wchar.mbstate - libc.src.__support.wchar.wcsnrtombs - libc.src.__support.libc_errno -) - -add_entrypoint_object( wcsrtombs SRCS wcsrtombs.cpp diff --git a/libc/src/wchar/btowc.cpp b/libc/src/wchar/btowc.cpp index c69f77d..6bc7526 100644 --- a/libc/src/wchar/btowc.cpp +++ b/libc/src/wchar/btowc.cpp @@ -9,7 +9,6 @@ #include "src/wchar/btowc.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" -#include "src/__support/wctype_utils.h" #include "hdr/types/wint_t.h" #include "hdr/wchar_macros.h" // for WEOF. @@ -17,12 +16,9 @@ namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(wint_t, btowc, (int c)) { - auto result = internal::btowc(c); - if (result.has_value()) { - return result.value(); - } else { + if (c > 127 || c < 0) return WEOF; - } + return static_cast<wint_t>(c); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/wchar/mbstowcs.cpp b/libc/src/wchar/mbstowcs.cpp deleted file mode 100644 index 43e953c..0000000 --- a/libc/src/wchar/mbstowcs.cpp +++ /dev/null @@ -1,40 +0,0 @@ -//===-- Implementation of mbstowcs ----------------------------------------===// -// -// 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/mbstowcs.h" - -#include "hdr/types/size_t.h" -#include "hdr/types/wchar_t.h" -#include "src/__support/common.h" -#include "src/__support/libc_errno.h" -#include "src/__support/macros/config.h" -#include "src/__support/macros/null_check.h" -#include "src/__support/wchar/mbsnrtowcs.h" -#include "src/__support/wchar/mbstate.h" - -namespace LIBC_NAMESPACE_DECL { - -LLVM_LIBC_FUNCTION(size_t, mbstowcs, - (wchar_t *__restrict pwcs, const char *__restrict s, - size_t n)) { - LIBC_CRASH_ON_NULLPTR(s); - // If destination is null, ignore n - n = pwcs == nullptr ? SIZE_MAX : n; - static internal::mbstate internal_mbstate; - const char *temp = s; - auto ret = internal::mbsnrtowcs(pwcs, &temp, SIZE_MAX, n, &internal_mbstate); - - if (!ret.has_value()) { - // Encoding failure - libc_errno = ret.error(); - return -1; - } - return ret.value(); -} - -} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/wchar/mbtowc.cpp b/libc/src/wchar/mbtowc.cpp deleted file mode 100644 index 6d099d4..0000000 --- a/libc/src/wchar/mbtowc.cpp +++ /dev/null @@ -1,37 +0,0 @@ -//===-- Implementation of mbtowc -----------------------------------------===// -// -// 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/mbtowc.h" - -#include "hdr/types/size_t.h" -#include "hdr/types/wchar_t.h" -#include "src/__support/common.h" -#include "src/__support/libc_errno.h" -#include "src/__support/macros/config.h" -#include "src/__support/wchar/mbrtowc.h" -#include "src/__support/wchar/mbstate.h" - -namespace LIBC_NAMESPACE_DECL { - -LLVM_LIBC_FUNCTION(int, mbtowc, - (wchar_t *__restrict pwc, const char *__restrict s, - size_t n)) { - // returns 0 since UTF-8 encoding is not state-dependent - if (s == nullptr) - return 0; - internal::mbstate internal_mbstate; - auto ret = internal::mbrtowc(pwc, s, n, &internal_mbstate); - if (!ret.has_value() || static_cast<int>(ret.value()) == -2) { - // Encoding failure - libc_errno = EILSEQ; - return -1; - } - return static_cast<int>(ret.value()); -} - -} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/wchar/wcstod.cpp b/libc/src/wchar/wcstod.cpp new file mode 100644 index 0000000..95351c3 --- /dev/null +++ b/libc/src/wchar/wcstod.cpp @@ -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 diff --git a/libc/src/wchar/mbtowc.h b/libc/src/wchar/wcstod.h index f974197f..ff397b9 100644 --- a/libc/src/wchar/mbtowc.h +++ b/libc/src/wchar/wcstod.h @@ -1,4 +1,4 @@ -//===-- Implementation header for mbtowc ---------------------------------===// +//===-- 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. @@ -6,17 +6,15 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SRC_WCHAR_MBTOWC_H -#define LLVM_LIBC_SRC_WCHAR_MBTOWC_H +#ifndef LLVM_LIBC_SRC_WCHAR_WCSTOD_H +#define LLVM_LIBC_SRC_WCHAR_WCSTOD_H -#include "hdr/types/size_t.h" -#include "hdr/types/wchar_t.h" #include "src/__support/macros/config.h" namespace LIBC_NAMESPACE_DECL { -int mbtowc(wchar_t *__restrict pwc, const char *__restrict s, size_t n); +double wcstod(const wchar_t *__restrict str, wchar_t **__restrict str_end); } // namespace LIBC_NAMESPACE_DECL -#endif // LLVM_LIBC_SRC_WCHAR_MBTOWC_H +#endif // LLVM_LIBC_SRC_WCHAR_WCSTOD_H diff --git a/libc/src/wchar/wcstof.cpp b/libc/src/wchar/wcstof.cpp new file mode 100644 index 0000000..162a60a --- /dev/null +++ b/libc/src/wchar/wcstof.cpp @@ -0,0 +1,30 @@ +//===-- Implementation of wcstof ------------------------------------------===// +// +// 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/wcstof.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(float, wcstof, + (const wchar_t *__restrict str, + wchar_t **__restrict str_end)) { + auto result = internal::strtofloatingpoint<float>(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 diff --git a/libc/src/wchar/wctomb.h b/libc/src/wchar/wcstof.h index 02a34e5..1aa7a30 100644 --- a/libc/src/wchar/wctomb.h +++ b/libc/src/wchar/wcstof.h @@ -1,4 +1,4 @@ -//===-- Implementation header for wctomb ------------------------*- C++ -*-===// +//===-- Implementation header for wcstof ------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,17 +6,16 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SRC_WCHAR_WCTOMB_H -#define LLVM_LIBC_SRC_WCHAR_WCTOMB_H +#ifndef LLVM_LIBC_SRC_WCHAR_WCSTOF_H +#define LLVM_LIBC_SRC_WCHAR_WCSTOF_H -#include "hdr/types/mbstate_t.h" #include "hdr/types/wchar_t.h" #include "src/__support/macros/config.h" namespace LIBC_NAMESPACE_DECL { -int wctomb(char *s, wchar_t wc); +float wcstof(const wchar_t *__restrict str, wchar_t **__restrict str_end); } // namespace LIBC_NAMESPACE_DECL -#endif // LLVM_LIBC_SRC_WCHAR_WCTOMB_H +#endif // LLVM_LIBC_SRC_WCHAR_WCSTOF_H diff --git a/libc/src/wchar/wcstol.cpp b/libc/src/wchar/wcstol.cpp index a05718f..a56b5f9 100644 --- a/libc/src/wchar/wcstol.cpp +++ b/libc/src/wchar/wcstol.cpp @@ -10,14 +10,14 @@ #include "src/__support/common.h" #include "src/__support/libc_errno.h" #include "src/__support/macros/config.h" -#include "src/__support/wcs_to_integer.h" +#include "src/__support/str_to_integer.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(long, wcstol, (const wchar_t *__restrict str, wchar_t **__restrict str_end, int base)) { - auto result = internal::wcstointeger<long>(str, base); + auto result = internal::strtointeger<long>(str, base); if (result.has_error()) libc_errno = result.error; diff --git a/libc/src/wchar/wcstold.cpp b/libc/src/wchar/wcstold.cpp new file mode 100644 index 0000000..ffbc3f2 --- /dev/null +++ b/libc/src/wchar/wcstold.cpp @@ -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 diff --git a/libc/src/wchar/mbstowcs.h b/libc/src/wchar/wcstold.h index 7d08a83..1525362 100644 --- a/libc/src/wchar/mbstowcs.h +++ b/libc/src/wchar/wcstold.h @@ -1,4 +1,4 @@ -//===-- Implementation header for mbstowcs --------------------------------===// +//===-- 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. @@ -6,17 +6,16 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SRC_WCHAR_MBSTOWCS_H -#define LLVM_LIBC_SRC_WCHAR_MBSTOWCS_H +#ifndef LLVM_LIBC_SRC_WCHAR_WCSTOLD_H +#define LLVM_LIBC_SRC_WCHAR_WCSTOLD_H -#include "hdr/types/size_t.h" -#include "hdr/types/wchar_t.h" #include "src/__support/macros/config.h" namespace LIBC_NAMESPACE_DECL { -size_t mbstowcs(wchar_t *__restrict pwcs, const char *__restrict s, size_t n); +long double wcstold(const wchar_t *__restrict str, + wchar_t **__restrict str_end); } // namespace LIBC_NAMESPACE_DECL -#endif // LLVM_LIBC_SRC_WCHAR_MBSTOWCS_H +#endif // LLVM_LIBC_SRC_WCHAR_WCSTOLD_H diff --git a/libc/src/wchar/wcstoll.cpp b/libc/src/wchar/wcstoll.cpp index de1299d..6229d24 100644 --- a/libc/src/wchar/wcstoll.cpp +++ b/libc/src/wchar/wcstoll.cpp @@ -10,14 +10,14 @@ #include "src/__support/common.h" #include "src/__support/libc_errno.h" #include "src/__support/macros/config.h" -#include "src/__support/wcs_to_integer.h" +#include "src/__support/str_to_integer.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(long long, wcstoll, (const wchar_t *__restrict str, wchar_t **__restrict str_end, int base)) { - auto result = internal::wcstointeger<long long>(str, base); + auto result = internal::strtointeger<long long>(str, base); if (result.has_error()) libc_errno = result.error; diff --git a/libc/src/wchar/wcstombs.cpp b/libc/src/wchar/wcstombs.cpp deleted file mode 100644 index c3793cb..0000000 --- a/libc/src/wchar/wcstombs.cpp +++ /dev/null @@ -1,38 +0,0 @@ -//===-- Implementation of wcstombs ----------------------------------------===// -// -// 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/wcstombs.h" - -#include "hdr/types/char32_t.h" -#include "hdr/types/size_t.h" -#include "hdr/types/wchar_t.h" -#include "src/__support/common.h" -#include "src/__support/libc_errno.h" -#include "src/__support/macros/config.h" -#include "src/__support/wchar/mbstate.h" -#include "src/__support/wchar/wcsnrtombs.h" - -namespace LIBC_NAMESPACE_DECL { - -LLVM_LIBC_FUNCTION(size_t, wcstombs, - (char *__restrict s, const wchar_t *__restrict wcs, - size_t n)) { - LIBC_CRASH_ON_NULLPTR(wcs); - static internal::mbstate internal_mbstate; - const wchar_t *wcs_ptr_copy = wcs; - auto result = - internal::wcsnrtombs(s, &wcs_ptr_copy, SIZE_MAX, n, &internal_mbstate); - if (!result.has_value()) { - libc_errno = result.error(); - return -1; - } - - return result.value(); -} - -} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/wchar/wcstombs.h b/libc/src/wchar/wcstombs.h deleted file mode 100644 index cd0008a..0000000 --- a/libc/src/wchar/wcstombs.h +++ /dev/null @@ -1,22 +0,0 @@ -//===-- Implementation header for wcstombs --------------------------------===// -// -// 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_WCSTOMBS_H -#define LLVM_LIBC_SRC_WCHAR_WCSTOMBS_H - -#include "hdr/types/size_t.h" -#include "hdr/types/wchar_t.h" -#include "src/__support/macros/config.h" - -namespace LIBC_NAMESPACE_DECL { - -size_t wcstombs(char *__restrict s, const wchar_t *__restrict pwcs, size_t n); - -} // namespace LIBC_NAMESPACE_DECL - -#endif // LLVM_LIBC_SRC_WCHAR_WCSTOMBS_H diff --git a/libc/src/wchar/wcstoul.cpp b/libc/src/wchar/wcstoul.cpp index 79b8c9b..c5639be 100644 --- a/libc/src/wchar/wcstoul.cpp +++ b/libc/src/wchar/wcstoul.cpp @@ -10,14 +10,14 @@ #include "src/__support/common.h" #include "src/__support/libc_errno.h" #include "src/__support/macros/config.h" -#include "src/__support/wcs_to_integer.h" +#include "src/__support/str_to_integer.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(unsigned long, wcstoul, (const wchar_t *__restrict str, wchar_t **__restrict str_end, int base)) { - auto result = internal::wcstointeger<unsigned long>(str, base); + auto result = internal::strtointeger<unsigned long>(str, base); if (result.has_error()) libc_errno = result.error; diff --git a/libc/src/wchar/wcstoull.cpp b/libc/src/wchar/wcstoull.cpp index 768e03c..2ab24e9 100644 --- a/libc/src/wchar/wcstoull.cpp +++ b/libc/src/wchar/wcstoull.cpp @@ -10,14 +10,14 @@ #include "src/__support/common.h" #include "src/__support/libc_errno.h" #include "src/__support/macros/config.h" -#include "src/__support/wcs_to_integer.h" +#include "src/__support/str_to_integer.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(unsigned long long, wcstoull, (const wchar_t *__restrict str, wchar_t **__restrict str_end, int base)) { - auto result = internal::wcstointeger<unsigned long long>(str, base); + auto result = internal::strtointeger<unsigned long long>(str, base); if (result.has_error()) libc_errno = result.error; diff --git a/libc/src/wchar/wctob.cpp b/libc/src/wchar/wctob.cpp index 45240d6..9b6773b 100644 --- a/libc/src/wchar/wctob.cpp +++ b/libc/src/wchar/wctob.cpp @@ -9,7 +9,6 @@ #include "src/wchar/wctob.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" -#include "src/__support/wctype_utils.h" #include "hdr/stdio_macros.h" // for EOF. #include "hdr/types/wint_t.h" @@ -17,12 +16,13 @@ namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(int, wctob, (wint_t c)) { - auto result = internal::wctob(c); - if (result.has_value()) { - return result.value(); - } else { + // The standard states that wint_t may either be an alias of wchar_t or + // an alias of an integer type, different platforms define this type with + // different signedness. This is equivalent to `(c > 127) || (c < 0)` but also + // works without -Wtype-limits warnings when `wint_t` is unsigned. + if ((c & ~127) != 0) return EOF; - } + return static_cast<int>(c); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/wchar/wctomb.cpp b/libc/src/wchar/wctomb.cpp deleted file mode 100644 index 142302e6..0000000 --- a/libc/src/wchar/wctomb.cpp +++ /dev/null @@ -1,35 +0,0 @@ -//===-- Implementation of wctomb ------------------------------------------===// -// -// 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/wctomb.h" - -#include "hdr/types/wchar_t.h" -#include "src/__support/common.h" -#include "src/__support/libc_errno.h" -#include "src/__support/macros/config.h" -#include "src/__support/wchar/mbstate.h" -#include "src/__support/wchar/wcrtomb.h" - -namespace LIBC_NAMESPACE_DECL { - -LLVM_LIBC_FUNCTION(int, wctomb, (char *s, wchar_t wc)) { - static internal::mbstate internal_mbstate; - if (s == nullptr) - return 0; - - auto result = internal::wcrtomb(s, wc, &internal_mbstate); - - if (!result.has_value()) { // invalid wide character - libc_errno = EILSEQ; - return -1; - } - - return static_cast<int>(result.value()); -} - -} // namespace LIBC_NAMESPACE_DECL |
