[libc-commits] [libc] Implement inet_pton (PR #224644)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Tue Sep 22 02:32:33 PDT 2026
================
@@ -26,8 +27,48 @@
#include "src/string/memory_utils/inline_memcpy.h"
namespace LIBC_NAMESPACE_DECL {
+
namespace net {
+int inet_pton_v4(cpp::string_view src, void *dst) {
+ uint8_t bytes[4];
+ size_t idx = 0;
+ uint32_t current_val = 0;
+ size_t digits_in_octet = 0;
+
+ for (char c : src) {
+ if (c >= '0' && c <= '9') {
+ // Reject octals and leading zeros
+ if (digits_in_octet > 0 && current_val == 0)
+ return 0;
+
+ current_val = current_val * 10 + static_cast<uint32_t>(c - '0');
----------------
labath wrote:
And for this, use `internal::b36_char_to_int`
https://github.com/llvm/llvm-project/pull/224644
More information about the libc-commits
mailing list