[libc-commits] [libc] [libc] Add if_nameindex and if_freenameindex as an experimental entrypoint (PR #208438)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Wed Jul 15 05:51:02 PDT 2026


================
@@ -0,0 +1,541 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for if_nameindex and if_freenameindex.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "hdr/net_if_macros.h"
+#include "hdr/types/socklen_t.h"
+#include "hdr/types/ssize_t.h"
+#include "hdr/types/struct_if_nameindex.h"
+#include "src/__support/CPP/span.h"
+#include "src/__support/CPP/string.h"
+#include "src/__support/CPP/string_view.h"
+#include "src/__support/CPP/tuple.h"
+#include "src/__support/CPP/type_traits/type_identity.h"
+#include "src/__support/error_or.h"
+#include "src/__support/fixedvector.h"
+#include "src/net/if_freenameindex.h"
+#include "src/net/if_nameindex.h"
+#include "src/net/linux/if_nameindex.h"
+#include "src/string/memory_utils/inline_memcpy.h"
+#include "src/string/memory_utils/inline_memset.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/Test.h"
+
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
+using LIBC_NAMESPACE::Error;
+using LIBC_NAMESPACE::ErrorOr;
+using LIBC_NAMESPACE::FixedVector;
+using LIBC_NAMESPACE::cpp::get;
+using LIBC_NAMESPACE::cpp::span;
+using LIBC_NAMESPACE::cpp::string;
+using LIBC_NAMESPACE::cpp::string_view;
+using LIBC_NAMESPACE::cpp::tuple;
+
+template <typename T, size_t CAPACITY>
+static T
+pop_front_or(FixedVector<T, CAPACITY> &vec,
+             typename LIBC_NAMESPACE::cpp::type_identity<T>::type default_val) {
----------------
labath wrote:

That would work if we had optional::value_or. Without it, the call sites would get more complicated, and this is just a utility to make the call sites simpler. How about I add another TODO to add value_or ? (I could also do it the other way around, but I chose this because I noticed some reluctance to add library code without an use case.)

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


More information about the libc-commits mailing list