aboutsummaryrefslogtreecommitdiff
path: root/cftw.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-07-08 02:30:31 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-07-08 02:30:31 +0200
commit74ca76a58fca114140d0d0cc13a1216d6dffbee0 (patch)
tree750209c29021d60451451132526c120c9ed137d0 /cftw.c
parent8bff49d9c8c5842ee1a0cd423035dd53728bf11c (diff)
downloadslcl-74ca76a58fca114140d0d0cc13a1216d6dffbee0.tar.gz
cftw: Allow directories to call the user callback
This provides a few benefits: - This will allow searching for directories by name. - Future commits will allow to remove files and directories, so this change was also required for cftw.
Diffstat (limited to 'cftw.c')
-rw-r--r--cftw.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/cftw.c b/cftw.c
index 2990888..8fb1d67 100644
--- a/cftw.c
+++ b/cftw.c
@@ -57,7 +57,12 @@ int cftw(const char *const dirpath, int (*const fn)(const char *,
fprintf(stderr, "%s: stat(2) %s: %s\n",
__func__, path, strerror(errno));
else if (S_ISDIR(sb.st_mode))
- ret = cftw(d.str, fn, user);
+ {
+ if ((ret = cftw(d.str, fn, user)))
+ ;
+ else if ((ret = fn(d.str, &sb, user)))
+ ;
+ }
else if (S_ISREG(sb.st_mode))
ret = fn(d.str, &sb, user);
else