[libc-commits] [libc] [libc] Add inet_ntop (PR #204143)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Tue Jun 23 06:46:05 PDT 2026


================
@@ -61,5 +68,160 @@ cpp::optional<in_addr_t> inet_addr(const char *cp) {
   return Endian::to_big_endian(result);
 }
 
+namespace {
+
+size_t ipv4_num_bytes(cpp::span<const uint8_t> src) {
+  size_t result = 8; // four digits, three dots and '\0'
+  for (unsigned i = 0; i < 4; ++i)
+    result += (src[i] >= 10) + (src[i] >= 100);
+  return result;
+}
+
+size_t ipv4_to_str_unchecked(cpp::span<const uint8_t> src,
+                             cpp::span<char> dst) {
+  size_t pos = 0;
+  for (unsigned i = 0; i < 4; ++i) {
+    uint8_t val = src[i];
+    if (val >= 100) {
+      uint8_t cent = val / 100;
+      val -= cent * 100;
+      uint8_t dec = val / 10;
+      dst[pos++] = '0' + cent;
+      dst[pos++] = '0' + dec;
+      dst[pos++] = '0' + val % 10;
+    } else if (val >= 10) {
+      uint8_t dec = val / 10;
+      dst[pos++] = '0' + dec;
+      dst[pos++] = '0' + val % 10;
+    } else {
+      dst[pos++] = '0' + val;
----------------
labath wrote:

I don't know about "support", but ctype_utils.h does mention EBCDIC.

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


More information about the libc-commits mailing list