[libc-commits] [libc] [libc] implement `inet_aton` (PR #162651)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Thu Oct 9 10:48:31 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);
----------------
michaelrj-google wrote:
this is a good use of this function, but you should add note that this may allow binary integers (with a leading `0b`) which isn't in the standard in the undefined behavior doc: https://github.com/llvm/llvm-project/blob/main/libc/docs/dev/undefined_behavior.rst
https://github.com/llvm/llvm-project/pull/162651
More information about the libc-commits
mailing list