[libc-commits] [libc] [libc] Implemented wcrtomb internal function and public libc function (PR #144596)

via libc-commits libc-commits at lists.llvm.org
Tue Jun 17 13:18:49 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- libc/hdr/types/mbstate_t.h libc/src/__support/wchar/wcrtomb.cpp libc/src/__support/wchar/wcrtomb.h libc/src/wchar/wcrtomb.cpp libc/src/wchar/wcrtomb.h libc/test/src/wchar/wcrtomb_test.cpp libc/include/llvm-libc-types/mbstate_t.h libc/src/__support/wchar/character_converter.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libc/include/llvm-libc-types/mbstate_t.h b/libc/include/llvm-libc-types/mbstate_t.h
index 40e693355..009fe57da 100644
--- a/libc/include/llvm-libc-types/mbstate_t.h
+++ b/libc/include/llvm-libc-types/mbstate_t.h
@@ -12,9 +12,9 @@
 #include "../llvm-libc-macros/stdint-macros.h"
 
 typedef struct {
-    uint32_t __field1;
-    uint8_t __field2;
-    uint8_t __field3;
+  uint32_t __field1;
+  uint8_t __field2;
+  uint8_t __field3;
 } mbstate_t;
 
 #endif // LLVM_LIBC_TYPES_MBSTATE_T_H
diff --git a/libc/src/__support/wchar/character_converter.cpp b/libc/src/__support/wchar/character_converter.cpp
index 4e6687a61..5b21a6345 100644
--- a/libc/src/__support/wchar/character_converter.cpp
+++ b/libc/src/__support/wchar/character_converter.cpp
@@ -11,9 +11,9 @@
 #include "src/__support/CPP/bit.h"
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
+#include "src/__support/libc_errno.h" // for error numbers
 #include "src/__support/math_extras.h"
 #include "src/__support/wchar/mbstate.h"
-#include "src/__support/libc_errno.h" // for error numbers
 
 #include "character_converter.h"
 
diff --git a/libc/src/__support/wchar/wcrtomb.cpp b/libc/src/__support/wchar/wcrtomb.cpp
index abd18aa39..847ffd162 100644
--- a/libc/src/__support/wchar/wcrtomb.cpp
+++ b/libc/src/__support/wchar/wcrtomb.cpp
@@ -21,7 +21,7 @@ namespace LIBC_NAMESPACE_DECL {
 namespace internal {
 
 ErrorOr<size_t> wcrtomb(char *__restrict s, wchar_t wc,
-                        mbstate_t *__restrict ps) {               
+                        mbstate_t *__restrict ps) {
   CharacterConverter cr((internal::mbstate *)ps);
 
   char buf[sizeof(wchar_t) / sizeof(char)];
diff --git a/libc/src/wchar/wcrtomb.h b/libc/src/wchar/wcrtomb.h
index 3cfb1a6f2..06c42f158 100644
--- a/libc/src/wchar/wcrtomb.h
+++ b/libc/src/wchar/wcrtomb.h
@@ -9,9 +9,9 @@
 #ifndef LLVM_LIBC_SRC_WCHAR_WCRTOMB_H
 #define LLVM_LIBC_SRC_WCHAR_WCRTOMB_H
 
-#include "hdr/types/wchar_t.h"
 #include "hdr/types/mbstate_t.h"
 #include "hdr/types/size_t.h"
+#include "hdr/types/wchar_t.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/test/src/wchar/wcrtomb_test.cpp b/libc/test/src/wchar/wcrtomb_test.cpp
index be249f4f6..c06b39ae0 100644
--- a/libc/test/src/wchar/wcrtomb_test.cpp
+++ b/libc/test/src/wchar/wcrtomb_test.cpp
@@ -6,16 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "hdr/types/wchar_t.h"
 #include "hdr/types/mbstate_t.h"
-#include "src/wchar/wcrtomb.h"
+#include "hdr/types/wchar_t.h"
+#include "src/__support/libc_errno.h"
 #include "src/string/memset.h"
+#include "src/wchar/wcrtomb.h"
 #include "test/UnitTest/Test.h"
-#include "src/__support/libc_errno.h"
 
 TEST(LlvmLibcWCRToMBTest, OneByte) {
   mbstate_t state;
-  LIBC_NAMESPACE::memset(&state, 0, sizeof (mbstate_t));
+  LIBC_NAMESPACE::memset(&state, 0, sizeof(mbstate_t));
   wchar_t wc = L'U';
   char mb[4];
   size_t cnt = LIBC_NAMESPACE::wcrtomb(mb, wc, &state);
@@ -25,7 +25,7 @@ TEST(LlvmLibcWCRToMBTest, OneByte) {
 
 TEST(LlvmLibcWCRToMBTest, TwoByte) {
   mbstate_t state;
-  LIBC_NAMESPACE::memset(&state, 0, sizeof (mbstate_t));
+  LIBC_NAMESPACE::memset(&state, 0, sizeof(mbstate_t));
   // testing utf32: 0xff -> utf8: 0xc3 0xbf
   wchar_t wc = 0xff;
   char mb[4];
@@ -37,7 +37,7 @@ TEST(LlvmLibcWCRToMBTest, TwoByte) {
 
 TEST(LlvmLibcWCRToMBTest, ThreeByte) {
   mbstate_t state;
-  LIBC_NAMESPACE::memset(&state, 0, sizeof (mbstate_t));
+  LIBC_NAMESPACE::memset(&state, 0, sizeof(mbstate_t));
   // testing utf32: 0xac15 -> utf8: 0xea 0xb0 0x95
   wchar_t wc = 0xac15;
   char mb[4];
@@ -50,7 +50,7 @@ TEST(LlvmLibcWCRToMBTest, ThreeByte) {
 
 TEST(LlvmLibcWCRToMBTest, FourByte) {
   mbstate_t state;
-  LIBC_NAMESPACE::memset(&state, 0, sizeof (mbstate_t));
+  LIBC_NAMESPACE::memset(&state, 0, sizeof(mbstate_t));
   // testing utf32: 0x1f921 -> utf8: 0xf0 0x9f 0xa4 0xa1
   wchar_t wc = 0x1f921;
   char mb[4];
@@ -64,7 +64,7 @@ TEST(LlvmLibcWCRToMBTest, FourByte) {
 
 TEST(LlvmLibcWCRToMBTest, NullString) {
   mbstate_t state;
-  LIBC_NAMESPACE::memset(&state, 0, sizeof (mbstate_t));
+  LIBC_NAMESPACE::memset(&state, 0, sizeof(mbstate_t));
   wchar_t wc = L'A';
   char mb[4];
 
@@ -84,7 +84,7 @@ TEST(LlvmLibcWCRToMBTest, NullState) {
 
 TEST(LlvmLibcWCRToMBTest, InvalidWchar) {
   mbstate_t state;
-  LIBC_NAMESPACE::memset(&state, 0, sizeof (mbstate_t));
+  LIBC_NAMESPACE::memset(&state, 0, sizeof(mbstate_t));
   wchar_t wc = 0x12ffff;
   char mb[4];
   size_t cnt = LIBC_NAMESPACE::wcrtomb(mb, wc, &state);

``````````

</details>


https://github.com/llvm/llvm-project/pull/144596


More information about the libc-commits mailing list