[libc-commits] [libc] [libc] Add POSIX.1-2024 <ftw.h> and Linux nftw implementation (PR #234996)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Wed Nov 18 14:47:37 PST 2026


================
@@ -0,0 +1,583 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Linux implementation of the POSIX nftw function.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/ftw/nftw.h"
+
+#include "hdr/errno_macros.h"
+#include "hdr/fcntl_macros.h"
+#include "hdr/ftw_macros.h"
+#include "hdr/sys_stat_macros.h"
+#include "hdr/types/dev_t.h"
+#include "hdr/types/ino_t.h"
+#include "hdr/types/struct_FTW.h"
+#include "hdr/types/struct_dirent.h"
+#include "hdr/types/struct_stat.h"
+#include "src/__support/CPP/limits.h"
+#include "src/__support/CPP/new.h"
+#include "src/__support/CPP/string_view.h"
+#include "src/__support/File/dir.h"
+#include "src/__support/OSUtil/linux/stat/stat_via_statx.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/chdir.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/close.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/fchdir.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/open.h"
+#include "src/__support/alloc-checker.h"
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
+#include "src/__support/macros/optimization.h"
+#include "src/string/memory_utils/inline_memcpy.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace {
+
+using NftwCallback = int (*)(const char *, const struct stat *, int,
+                             struct FTW *);
+
+constexpr size_t INITIAL_PATH_CAPACITY = 256;
+constexpr size_t INITIAL_NAMES_CAPACITY = 256;
+constexpr size_t INITIAL_VISITED_CAPACITY = 32;
+constexpr size_t MAX_PATH_BUF_CAPACITY =
+    static_cast<size_t>(cpp::numeric_limits<int>::max());
----------------
kaladron wrote:

Adjusting it to PATH_MAX or 16k if PATH_MAX isn't specified.  Got rid of the dynamic allocation accordingly.

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


More information about the libc-commits mailing list