Skip to content

[libc] Implement wcs to mbs family of functions #149421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

uzairnawaz
Copy link
Contributor

Implemented internal wcs to mbs internal function + tests
Impelemented wcs to mbs public functions

@uzairnawaz uzairnawaz requested a review from sribee8 July 17, 2025 22:57
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- libc/src/__support/wchar/wcsnrtombs.cpp libc/src/__support/wchar/wcsnrtombs.h libc/src/wchar/wcsnrtombs.cpp libc/src/wchar/wcsnrtombs.h libc/src/wchar/wcsrtombs.cpp libc/src/wchar/wcsrtombs.h libc/src/wchar/wcstombs.cpp libc/src/wchar/wcstombs.h libc/test/src/__support/wchar/wcsnrtombs_test.cpp libc/test/src/wchar/wcsnrtombs_test.cpp libc/test/src/wchar/wcsrtombs_test.cpp libc/test/src/wchar/wcstombs_test.cpp
View the diff from clang-format here.
diff --git a/libc/src/wchar/wcsnrtombs.h b/libc/src/wchar/wcsnrtombs.h
index 793d38366..aef87e9e6 100644
--- a/libc/src/wchar/wcsnrtombs.h
+++ b/libc/src/wchar/wcsnrtombs.h
@@ -1,4 +1,5 @@
-//===-- Implementation header for wcsnrtombs -------------------------------===//
+//===-- Implementation header for wcsnrtombs
+//-------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -16,7 +17,8 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-size_t wcsnrtombs(char *__restrict s, const wchar_t **__restrict pwcs, size_t nwc, size_t len, mbstate_t* ps);
+size_t wcsnrtombs(char *__restrict s, const wchar_t **__restrict pwcs,
+                  size_t nwc, size_t len, mbstate_t *ps);
 
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/src/wchar/wcsrtombs.h b/libc/src/wchar/wcsrtombs.h
index af69fccdb..6a426925e 100644
--- a/libc/src/wchar/wcsrtombs.h
+++ b/libc/src/wchar/wcsrtombs.h
@@ -1,4 +1,5 @@
-//===-- Implementation header for wcsrtombs --------------------------------===//
+//===-- Implementation header for wcsrtombs
+//--------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -16,7 +17,8 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-size_t wcsrtombs(char *__restrict s, const wchar_t **__restrict pwcs, size_t n, mbstate_t* ps);
+size_t wcsrtombs(char *__restrict s, const wchar_t **__restrict pwcs, size_t n,
+                 mbstate_t *ps);
 
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/test/src/__support/wchar/wcsnrtombs_test.cpp b/libc/test/src/__support/wchar/wcsnrtombs_test.cpp
index 710fc4b56..d8f523c6d 100644
--- a/libc/test/src/__support/wchar/wcsnrtombs_test.cpp
+++ b/libc/test/src/__support/wchar/wcsnrtombs_test.cpp
@@ -110,7 +110,8 @@ TEST(LlvmLibcWcsnrtombs, SrcLimit) {
   ASSERT_EQ(mbs[6], '\x91');
   ASSERT_EQ(mbs[7], '\x01');
 
-  res = LIBC_NAMESPACE::internal::wcsnrtombs(mbs + res.value(), &cur, 100, 11, &state);
+  res = LIBC_NAMESPACE::internal::wcsnrtombs(mbs + res.value(), &cur, 100, 11,
+                                             &state);
   ASSERT_TRUE(res.has_value());
   ASSERT_EQ(res.value(), static_cast<size_t>(3));
   ASSERT_EQ(cur, nullptr);
diff --git a/libc/test/src/wchar/wcstombs_test.cpp b/libc/test/src/wchar/wcstombs_test.cpp
index 397ce0460..61e0873dc 100644
--- a/libc/test/src/wchar/wcstombs_test.cpp
+++ b/libc/test/src/wchar/wcstombs_test.cpp
@@ -79,7 +79,6 @@ TEST_F(LlvmLibcWcstombs, ErrnoTest) {
   // n parameter ignored when dest is null
   ASSERT_EQ(LIBC_NAMESPACE::wcstombs(mbs, src, 7), static_cast<size_t>(7));
   ASSERT_ERRNO_SUCCESS();
-  ASSERT_EQ(LIBC_NAMESPACE::wcstombs(mbs, src, 100),
-            static_cast<size_t>(-1));
+  ASSERT_EQ(LIBC_NAMESPACE::wcstombs(mbs, src, 100), static_cast<size_t>(-1));
   ASSERT_ERRNO_EQ(EILSEQ);
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant