[PATCH 3/3] io: Sync fts with gnulib
Adhemerval Zanella
adhemerval.zanella@linaro.org
Fri Apr 17 13:24:57 GMT 2026
With both f5ee21eacc5be459a7d08b344196f2245a5de801 and
9ab4bbed73172085c57b38a337d3dc279b1043b0 to document better FTS_NOSTAT.
Checked on x86_64-linux-gnu and i686-linux-gnu.
---
io/fts-common.c | 1 +
io/fts.h | 13 +++++++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/io/fts-common.c b/io/fts-common.c
index 3825f0aeb4..8252d716f8 100644
--- a/io/fts-common.c
+++ b/io/fts-common.c
@@ -554,6 +554,7 @@ FTS_OPEN (char * const *argv,
FTS_XDEV) requires that. */
if (defer_stat && root != NULL) {
p->fts_info = FTS_NSOK;
+ p->fts_statp->st_mode = 0;
fts_set_stat_required(p, true);
} else {
p->fts_info = fts_stat(sp, p, false);
diff --git a/io/fts.h b/io/fts.h
index 50636e6c87..23518cba32 100644
--- a/io/fts.h
+++ b/io/fts.h
@@ -90,6 +90,13 @@ typedef struct {
#define FTS_COMFOLLOW 0x0001 /* follow command line symlinks */
#define FTS_LOGICAL 0x0002 /* logical walk */
#define FTS_NOCHDIR 0x0004 /* don't change directories */
+
+ /* For efficiency do not set *fts_statp except for fts_statp->st_mode,
+ which is set to zero if the file type is unknown,
+ and which otherwise has at least its S_IFMT type bits set.
+ When fts_info == FTS_NSOK this supports expressions like
+ (fts_statp->st_mode ? !!S_ISDIR (fts_statp->st_mode): -1), which yields
+ 1 for a directory, 0 for a non-directory, and -1 for unknown. */
#define FTS_NOSTAT 0x0008 /* don't get stat info */
#define FTS_PHYSICAL 0x0010 /* physical walk */
#define FTS_SEEDOT 0x0020 /* return dot and dot-dot */
@@ -139,10 +146,8 @@ typedef struct {
Use this flag to make fts_open and fts_read defer the stat/lstat/fststat
of each entry until it is actually processed. However, note that if you
use this option and also specify a comparison function, that function may
- not examine any data via fts_statp. However, when fts_statp->st_mode is
- nonzero, the S_IFMT type bits are valid, with mapped dirent.d_type data.
- Of course, that happens only on file systems that provide useful
- dirent.d_type data. */
+ not examine any data via fts_statp, other than fts_statp->st_mode
+ which is set similarly to how FTS_NOSTAT behaves. */
#define FTS_DEFER_STAT 0x1000
/* Use this flag to disable stripping of trailing slashes
--
2.43.0
More information about the Libc-alpha
mailing list