[libc-commits] [libc] [libc] Add ftw and nftw headers, macros, and types (PR #191425)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Fri Apr 10 07:21:55 PDT 2026
https://github.com/kaladron created https://github.com/llvm/llvm-project/pull/191425
Added headers, macros, and types for POSIX ftw and nftw support:
* libc/include/ftw.h.def
* libc/include/ftw.yaml
* libc/include/llvm-libc-macros/ftw-macros.h
* libc/include/llvm-libc-types/struct_FTW.h
* libc/include/llvm-libc-types/__ftw_func_t.h
* libc/include/llvm-libc-types/__nftw_func_t.h
* libc/hdr/ftw_macros.h
Updated corresponding CMakeLists.txt files to include the new targets.
>From 38263d26348ae711ff7462b659affde5b55fb68a Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Fri, 10 Apr 2026 15:09:09 +0100
Subject: [PATCH] [libc] Add ftw and nftw headers, macros, and types
Added headers, macros, and types for POSIX ftw and nftw support:
* libc/include/ftw.h.def
* libc/include/ftw.yaml
* libc/include/llvm-libc-macros/ftw-macros.h
* libc/include/llvm-libc-types/struct_FTW.h
* libc/include/llvm-libc-types/__ftw_func_t.h
* libc/include/llvm-libc-types/__nftw_func_t.h
* libc/hdr/ftw_macros.h
Updated corresponding CMakeLists.txt files to include the new targets.
Co-authored-by: Raman Tennti <rtenneti at google.com>
---
libc/config/linux/aarch64/headers.txt | 1 +
libc/config/linux/arm/headers.txt | 1 +
libc/config/linux/i386/headers.txt | 1 +
libc/config/linux/riscv/headers.txt | 1 +
libc/config/linux/x86_64/headers.txt | 1 +
libc/hdr/ftw_macros.h | 22 ++++++++++++
libc/include/CMakeLists.txt | 12 +++++++
libc/include/ftw.h.def | 18 ++++++++++
libc/include/ftw.yaml | 28 +++++++++++++++
libc/include/llvm-libc-macros/CMakeLists.txt | 6 ++++
libc/include/llvm-libc-macros/ftw-macros.h | 37 ++++++++++++++++++++
libc/include/llvm-libc-types/CMakeLists.txt | 3 ++
libc/include/llvm-libc-types/__ftw_func_t.h | 16 +++++++++
libc/include/llvm-libc-types/__nftw_func_t.h | 18 ++++++++++
libc/include/llvm-libc-types/struct_FTW.h | 17 +++++++++
15 files changed, 182 insertions(+)
create mode 100644 libc/hdr/ftw_macros.h
create mode 100644 libc/include/ftw.h.def
create mode 100644 libc/include/ftw.yaml
create mode 100644 libc/include/llvm-libc-macros/ftw-macros.h
create mode 100644 libc/include/llvm-libc-types/__ftw_func_t.h
create mode 100644 libc/include/llvm-libc-types/__nftw_func_t.h
create mode 100644 libc/include/llvm-libc-types/struct_FTW.h
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 4784fc5d29ddc..c1f2a86d623ad 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -13,6 +13,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.features
libc.include.fenv
libc.include.float
+ libc.include.ftw
libc.include.inttypes
libc.include.limits
libc.include.link
diff --git a/libc/config/linux/arm/headers.txt b/libc/config/linux/arm/headers.txt
index dad65234363b3..10bc71d27b921 100644
--- a/libc/config/linux/arm/headers.txt
+++ b/libc/config/linux/arm/headers.txt
@@ -5,6 +5,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.errno
libc.include.fenv
libc.include.float
+ libc.include.ftw
libc.include.inttypes
libc.include.malloc
libc.include.math
diff --git a/libc/config/linux/i386/headers.txt b/libc/config/linux/i386/headers.txt
index 6182b1a9c1ef5..0d2c574cd6123 100644
--- a/libc/config/linux/i386/headers.txt
+++ b/libc/config/linux/i386/headers.txt
@@ -1,4 +1,5 @@
set(TARGET_PUBLIC_HEADERS
libc.include.assert
libc.include.cpio
+ libc.include.ftw
)
diff --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt
index 45c42eb65527c..a5a0252378960 100644
--- a/libc/config/linux/riscv/headers.txt
+++ b/libc/config/linux/riscv/headers.txt
@@ -13,6 +13,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.features
libc.include.fenv
libc.include.float
+ libc.include.ftw
libc.include.inttypes
libc.include.limits
libc.include.link
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index 0e5d5c753aed1..6df407c218fa0 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -13,6 +13,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.features
libc.include.fenv
libc.include.float
+ libc.include.ftw
libc.include.inttypes
libc.include.limits
libc.include.link
diff --git a/libc/hdr/ftw_macros.h b/libc/hdr/ftw_macros.h
new file mode 100644
index 0000000000000..edfde3fdb35c7
--- /dev/null
+++ b/libc/hdr/ftw_macros.h
@@ -0,0 +1,22 @@
+//===-- Definition of macros from ftw.h -----------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_FTW_MACROS_H
+#define LLVM_LIBC_HDR_FTW_MACROS_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-macros/ftw-macros.h"
+
+#else // Overlay mode
+
+#include <ftw.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_FTW_MACROS_H
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 41d541f475290..1d885b94cdda6 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -129,6 +129,18 @@ add_header_macro(
.llvm-libc-macros.float_macros
)
+add_header_macro(
+ ftw
+ ../libc/include/ftw.yaml
+ ftw.h
+ DEPENDS
+ .llvm_libc_common_h
+ .llvm-libc-macros.ftw_macros
+ .llvm-libc-types.struct_FTW
+ .llvm-libc-types.__ftw_func_t
+ .llvm-libc-types.__nftw_func_t
+)
+
add_header_macro(
limits
../libc/include/limits.yaml
diff --git a/libc/include/ftw.h.def b/libc/include/ftw.h.def
new file mode 100644
index 0000000000000..990f64e98caee
--- /dev/null
+++ b/libc/include/ftw.h.def
@@ -0,0 +1,18 @@
+//===-- C standard library header ftw.h -----------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_FTW_H
+#define LLVM_LIBC_FTW_H
+
+#include "__llvm-libc-common.h"
+
+#include "llvm-libc-macros/ftw-macros.h"
+
+%%public_api()
+
+#endif // LLVM_LIBC_FTW_H
diff --git a/libc/include/ftw.yaml b/libc/include/ftw.yaml
new file mode 100644
index 0000000000000..eb18a8c1c8160
--- /dev/null
+++ b/libc/include/ftw.yaml
@@ -0,0 +1,28 @@
+header: ftw.h
+header_template: ftw.h.def
+macros: []
+types:
+ - type_name: struct_FTW
+ - type_name: __ftw_func_t
+ - type_name: __nftw_func_t
+enums: []
+objects: []
+functions:
+ - name: ftw
+ standards:
+ - posix
+ return_type: int
+ arguments:
+ - type: const char *
+ - type: __ftw_func_t
+ - type: int
+ - name: nftw
+ standards:
+ - posix
+ - gnu
+ return_type: int
+ arguments:
+ - type: const char *
+ - type: __nftw_func_t
+ - type: int
+ - type: int
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 1f34257c57e01..817b932e87fb9 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -105,6 +105,12 @@ add_macro_header(
fenv-macros.h
)
+add_macro_header(
+ ftw_macros
+ HDR
+ ftw-macros.h
+)
+
add_macro_header(
file_seek_macros
HDR
diff --git a/libc/include/llvm-libc-macros/ftw-macros.h b/libc/include/llvm-libc-macros/ftw-macros.h
new file mode 100644
index 0000000000000..4a9f44356591b
--- /dev/null
+++ b/libc/include/llvm-libc-macros/ftw-macros.h
@@ -0,0 +1,37 @@
+//===-- Definition of macros from ftw.h -----------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_MACROS_FTW_MACROS_H
+#define LLVM_LIBC_MACROS_FTW_MACROS_H
+
+// Values for the typeflag argument to the callback function.
+#define FTW_F 0 // Non-directory file.
+#define FTW_D 1 // Directory.
+#define FTW_DNR 2 // Directory without read permission.
+#define FTW_NS 3 // Unknown type; stat() failed.
+#define FTW_SL 4 // Symbolic link.
+#define FTW_DP 5 // Directory with subdirectories visited.
+#define FTW_SLN 6 // Symbolic link naming non-existing file.
+
+// Flags for the flags argument to nftw().
+#define FTW_PHYS 1 // Physical walk, does not follow symbolic links.
+#define FTW_MOUNT 2 // The walk does not cross a mount point.
+#define FTW_CHDIR 4 // Change to each directory before processing.
+#define FTW_DEPTH 8 // All subdirectories visited before the directory.
+
+#ifdef _GNU_SOURCE
+#define FTW_ACTIONRETVAL 16 // Use FTW_* action return values (GNU extension).
+
+// Return values from callback functions (when FTW_ACTIONRETVAL is set).
+#define FTW_CONTINUE 0 // Continue with next sibling.
+#define FTW_STOP 1 // Return from ftw/nftw with FTW_STOP.
+#define FTW_SKIP_SUBTREE 2 // Don't walk through subtree (FTW_D only).
+#define FTW_SKIP_SIBLINGS 3 // Skip siblings, continue with parent.
+#endif // _GNU_SOURCE
+
+#endif // LLVM_LIBC_MACROS_FTW_MACROS_H
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 0d6bc0982b847..70682225bcf6b 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -98,6 +98,7 @@ add_header(dl_info HDR Dl_info.h)
add_header(struct_f_owner_ex HDR struct_f_owner_ex.h DEPENDS .pid_t)
add_header(struct_flock HDR struct_flock.h DEPENDS .off_t .pid_t)
add_header(struct_flock64 HDR struct_flock64.h DEPENDS .off64_t .pid_t)
+add_header(struct_FTW HDR struct_FTW.h)
add_header(
struct_ipc_perm
HDR struct_ipc_perm.h
@@ -138,6 +139,8 @@ add_header(
.dev_t .ino_t .mode_t .nlink_t .uid_t .gid_t .off_t .struct_timespec
.blksize_t .blkcnt_t
)
+add_header(__ftw_func_t HDR __ftw_func_t.h DEPENDS .struct_stat)
+add_header(__nftw_func_t HDR __nftw_func_t.h DEPENDS .struct_stat .struct_FTW)
add_header(struct_tm HDR struct_tm.h)
add_header(struct_utsname HDR struct_utsname.h)
add_header(thrd_start_t HDR thrd_start_t.h)
diff --git a/libc/include/llvm-libc-types/__ftw_func_t.h b/libc/include/llvm-libc-types/__ftw_func_t.h
new file mode 100644
index 0000000000000..f93b2f82c8ac8
--- /dev/null
+++ b/libc/include/llvm-libc-types/__ftw_func_t.h
@@ -0,0 +1,16 @@
+//===-- Definition of type __ftw_func_t -----------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES___FTW_FUNC_T_H
+#define LLVM_LIBC_TYPES___FTW_FUNC_T_H
+
+struct stat;
+
+typedef int (*__ftw_func_t)(const char *, const struct stat *, int);
+
+#endif // LLVM_LIBC_TYPES___FTW_FUNC_T_H
diff --git a/libc/include/llvm-libc-types/__nftw_func_t.h b/libc/include/llvm-libc-types/__nftw_func_t.h
new file mode 100644
index 0000000000000..c7b74da8571a7
--- /dev/null
+++ b/libc/include/llvm-libc-types/__nftw_func_t.h
@@ -0,0 +1,18 @@
+//===-- Definition of type __nftw_func_t ----------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES___NFTW_FUNC_T_H
+#define LLVM_LIBC_TYPES___NFTW_FUNC_T_H
+
+struct stat;
+struct FTW;
+
+typedef int (*__nftw_func_t)(const char *, const struct stat *, int,
+ struct FTW *);
+
+#endif // LLVM_LIBC_TYPES___NFTW_FUNC_T_H
diff --git a/libc/include/llvm-libc-types/struct_FTW.h b/libc/include/llvm-libc-types/struct_FTW.h
new file mode 100644
index 0000000000000..46825c8f6b781
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_FTW.h
@@ -0,0 +1,17 @@
+//===-- Definition of struct FTW ------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_FTW_H
+#define LLVM_LIBC_TYPES_STRUCT_FTW_H
+
+struct FTW {
+ int base; // Offset of the filename in the pathname.
+ int level; // Depth of the file in the tree.
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_FTW_H
More information about the libc-commits
mailing list