1 From 6f1143425a3afc4eb5086e9c90e7efb3affd7cb7 Mon Sep 17 00:00:00 2001
2 From: Tony Ambardar <Tony.Ambardar@gmail.com>
3 Date: Sat, 11 Jul 2020 06:35:46 -0700
4 Subject: [PATCH 2/2] nftw: support common gnu extension
6 Signed-off-by: Tony Ambardar <Tony.Ambardar@gmail.com>
8 include/ftw.h | 8 ++++++++
9 src/misc/nftw.c | 35 ++++++++++++++++++++++++++++++-----
10 2 files changed, 38 insertions(+), 5 deletions(-)
12 diff --git a/include/ftw.h b/include/ftw.h
13 index b15c062a..ce85deac 100644
16 @@ -21,6 +21,14 @@ extern "C" {
21 +#define FTW_ACTIONRETVAL 16
22 +#define FTW_CONTINUE 0
24 +#define FTW_SKIP_SUBTREE 2
25 +#define FTW_SKIP_SIBLINGS 3
31 diff --git a/src/misc/nftw.c b/src/misc/nftw.c
32 index 8dcff7fe..0bb7b601 100644
40 @@ -72,8 +73,20 @@ static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int,
41 if (!fd_limit) close(dfd);
44 - if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev)))
46 + if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) {
47 + if (flags & FTW_ACTIONRETVAL)
49 + case FTW_SKIP_SUBTREE:
53 + case FTW_SKIP_SIBLINGS:
61 for (; h; h = h->chain)
62 if (h->dev == st.st_dev && h->ino == st.st_ino)
63 @@ -101,7 +114,10 @@ static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int,
64 strcpy(path+j+1, de->d_name);
65 if ((r=do_nftw(path, fn, fd_limit-1, flags, &new))) {
68 + if ((flags & FTW_ACTIONRETVAL) && r == FTW_SKIP_SIBLINGS)
75 @@ -112,8 +128,16 @@ static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int,
79 - if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev)))
81 + if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) {
82 + if (flags & FTW_ACTIONRETVAL)
84 + case FTW_SKIP_SIBLINGS:
94 @@ -139,4 +163,5 @@ int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, str
99 weak_alias(nftw, nftw64);