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(-)
14 @@ -21,6 +21,14 @@ extern "C" {
19 +#define FTW_ACTIONRETVAL 16
20 +#define FTW_CONTINUE 0
22 +#define FTW_SKIP_SUBTREE 2
23 +#define FTW_SKIP_SIBLINGS 3
36 @@ -72,8 +73,20 @@ static int do_nftw(char *path, int (*fn)
37 if (!fd_limit) close(dfd);
40 - if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev)))
42 + if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) {
43 + if (flags & FTW_ACTIONRETVAL)
45 + case FTW_SKIP_SUBTREE:
49 + case FTW_SKIP_SIBLINGS:
57 for (; h; h = h->chain)
58 if (h->dev == st.st_dev && h->ino == st.st_ino)
59 @@ -101,7 +114,10 @@ static int do_nftw(char *path, int (*fn)
60 strcpy(path+j+1, de->d_name);
61 if ((r=do_nftw(path, fn, fd_limit-1, flags, &new))) {
64 + if ((flags & FTW_ACTIONRETVAL) && r == FTW_SKIP_SIBLINGS)
71 @@ -112,8 +128,16 @@ static int do_nftw(char *path, int (*fn)
75 - if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev)))
77 + if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) {
78 + if (flags & FTW_ACTIONRETVAL)
80 + case FTW_SKIP_SIBLINGS:
90 @@ -139,4 +163,5 @@ int nftw(const char *path, int (*fn)(con
95 weak_alias(nftw, nftw64);