summaryrefslogtreecommitdiff
path: root/lib/ktl/include/cwchar
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-07-11 22:48:30 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-07-11 22:48:30 +0800
commit3ad39e9878310e5317ee73c9b353c1e2c1c5c4ee (patch)
tree4bd5a49ef60ad1e371c0984cd46838368c5ef83a /lib/ktl/include/cwchar
parent48ef95c24e9ac3d11200b61af617a01b10b507d1 (diff)
downloadlume-3ad39e9878310e5317ee73c9b353c1e2c1c5c4ee.tar.gz
lume-3ad39e9878310e5317ee73c9b353c1e2c1c5c4ee.tar.xz
lib: establish Zircon libc++ and KTL foundation
Diffstat (limited to 'lib/ktl/include/cwchar')
-rw-r--r--lib/ktl/include/cwchar62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/ktl/include/cwchar b/lib/ktl/include/cwchar
new file mode 100644
index 0000000..4f24c73
--- /dev/null
+++ b/lib/ktl/include/cwchar
@@ -0,0 +1,62 @@
+// Copyright 2020 The Fuchsia Authors
+//
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file or at
+// https://opensource.org/licenses/MIT
+
+#ifndef ZIRCON_KERNEL_LIB_KTL_INCLUDE_CWCHAR
+#define ZIRCON_KERNEL_LIB_KTL_INCLUDE_CWCHAR
+
+// The kernel doesn't want this file but some libc++ headers we need
+// wind up including it and they need these declarations.
+
+#include <wchar.h>
+
+#include <__config>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::wmemcpy;
+using ::wmemmove;
+using ::wmemset;
+
+// These are called by libc++ header code. The first two should never actually
+// be called by anything that really gets instantiated in kernel code since
+// wchar_t is never used. However, __constexpr_wmemchr is used by places like
+// std::find not just for wchar_t per se but for any trivial type of the same
+// size, e.g. uint32_t. So its code must be correct. The other two are filled
+// out just in case of an unexpected use.
+
+constexpr size_t __constexpr_wcslen(const wchar_t* str) {
+ size_t len = 0;
+ while (*str++ != L'\0') {
+ ++len;
+ }
+ return len;
+}
+
+constexpr int __constexpr_wmemcmp(const wchar_t* lhs, const wchar_t* rhs, size_t count) {
+ while (count-- > 0) {
+ if (*lhs != *rhs) {
+ return static_cast<int>(*lhs - *rhs);
+ }
+ ++lhs;
+ ++rhs;
+ }
+ return 0;
+}
+
+template <class Tp, class Up>
+constexpr Tp* __constexpr_wmemchr(Tp* str, Up wc, size_t count) {
+ while (count-- > 0) {
+ if (*str == wc) {
+ return str;
+ }
+ ++str;
+ }
+ return nullptr;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // ZIRCON_KERNEL_LIB_KTL_INCLUDE_CWCHAR