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

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Wed Sep 23 00:13:14 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') {
----------------
labath wrote:

Just to be clear: This is not an optional request. I will not approve this patch while it contains char arithmetic. Our current policy is to use the src/__support/ctype_utils.h functions. If you disagree with that, we can take this up with higher powers :).

Also, note I did not say non-ascii *characters*. I said non-ascii *targets*, i.e. targets where the layout of basic characters like '0' and '1' might be different and things like `c - '0'` might not be valid. EBCDIC is the best example of that although in this case '0'..'9' are still next to each other.

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


More information about the libc-commits mailing list