[libc-commits] [libc] [libc] implement `inet_aton` (PR #162651)
Connector Switch via libc-commits
libc-commits at lists.llvm.org
Thu Oct 9 20:47:18 PDT 2025
================
@@ -0,0 +1,68 @@
+//===-- Implementation of inet_aton function ------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/arpa/inet/inet_aton.h"
+#include "src/__support/common.h"
+#include "src/__support/endian_internal.h"
+#include "src/__support/str_to_integer.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, inet_aton, (const char *cp, in_addr *inp)) {
+ unsigned long parts[4] = {0};
+ int dot_num = 0;
+
+ for (; dot_num < 4; ++dot_num) {
+ auto result = internal::strtointeger<unsigned long>(cp, 0);
----------------
c8ef wrote:
I haven't tested it yet, but a quick look at the code suggests `strtointeger` might not support binary integers. The test file, libc/test/src/__support/str_to_integer_test.cpp, lacks binary integer coverage either.
https://github.com/llvm/llvm-project/blob/88ba06d6fc36c2c817eb208d06f408afa7373be8/libc/src/__support/str_to_integer.h#L57-L71
https://github.com/llvm/llvm-project/pull/162651
More information about the libc-commits
mailing list