[libc-commits] [libc] Implement inet_pton (PR #224644)

via libc-commits libc-commits at lists.llvm.org
Fri Sep 18 06:58:23 PDT 2026


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 origin/main HEAD --extensions h,cpp -- libc/src/arpa/inet/inet_pton.cpp libc/src/arpa/inet/inet_pton.h libc/test/src/arpa/inet/inet_pton_test.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

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

``````````diff
diff --git a/libc/src/arpa/inet/inet_pton.cpp b/libc/src/arpa/inet/inet_pton.cpp
index 632386c56..f7794a171 100644
--- a/libc/src/arpa/inet/inet_pton.cpp
+++ b/libc/src/arpa/inet/inet_pton.cpp
@@ -15,6 +15,7 @@
 
 #include "hdr/errno_macros.h"
 #include "hdr/stdint_proxy.h"
+#include "hdr/sys_socket_macros.h"
 #include "hdr/types/struct_in6_addr.h"
 #include "hdr/types/struct_in_addr.h"
 #include "src/__support/CPP/string_view.h"
@@ -23,7 +24,6 @@
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/null_check.h"
 #include "src/__support/str_to_integer.h"
-#include "hdr/sys_socket_macros.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
@@ -33,8 +33,7 @@ LLVM_LIBC_FUNCTION(int, inet_pton,
   LIBC_CRASH_ON_NULLPTR(dst);
   if (af == AF_INET6) {
     return 0;
-  }
-  else if (af != AF_INET) {
+  } else if (af != AF_INET) {
     libc_errno = EAFNOSUPPORT;
     return -1;
   }
@@ -56,9 +55,9 @@ LLVM_LIBC_FUNCTION(int, inet_pton,
       return 0;
     // Ensure all characters are valid ascii
     for (char c : part) {
-        if (c < '0' || c > '9')
-          return 0;
-      }
+      if (c < '0' || c > '9')
+        return 0;
+    }
     auto result = internal::strtointeger<uint32_t>(part.data(), 10);
     if (result.has_error() || result.value > 255 || result.value < 0)
       return 0;
diff --git a/libc/test/src/arpa/inet/inet_pton_test.cpp b/libc/test/src/arpa/inet/inet_pton_test.cpp
index ff49c3745..e8f548386 100644
--- a/libc/test/src/arpa/inet/inet_pton_test.cpp
+++ b/libc/test/src/arpa/inet/inet_pton_test.cpp
@@ -14,8 +14,8 @@
 #include "hdr/errno_macros.h"
 #include "hdr/sys_socket_macros.h"
 #include "hdr/types/struct_in_addr.h"
-#include "src/__support/libc_errno.h"
 #include "src/__support/endian_internal.h"
+#include "src/__support/libc_errno.h"
 #include "src/arpa/inet/inet_pton.h"
 #include "test/UnitTest/ErrnoCheckingTest.h"
 #include "test/UnitTest/Test.h"

``````````

</details>


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


More information about the libc-commits mailing list