aboutsummaryrefslogtreecommitdiff
path: root/cftw.c
diff options
context:
space:
mode:
Diffstat (limited to 'cftw.c')
-rw-r--r--cftw.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/cftw.c b/cftw.c
index 8fb1d67..4b8b013 100644
--- a/cftw.c
+++ b/cftw.c
@@ -9,8 +9,8 @@
#include <stdint.h>
#include <string.h>
-int cftw(const char *const dirpath, int (*const fn)(const char *,
- const struct stat *, void *), void *const user)
+static int do_cftw(const char *const dirpath, int (*const fn)(const char *,
+ const struct stat *, bool *, void *), bool *const done, void *const user)
{
int ret = -1;
DIR *const d = opendir(dirpath);
@@ -58,20 +58,20 @@ int cftw(const char *const dirpath, int (*const fn)(const char *,
__func__, path, strerror(errno));
else if (S_ISDIR(sb.st_mode))
{
- if ((ret = cftw(d.str, fn, user)))
+ if ((ret = do_cftw(d.str, fn, done, user)))
;
- else if ((ret = fn(d.str, &sb, user)))
+ else if ((ret = fn(d.str, &sb, done, user)))
;
}
else if (S_ISREG(sb.st_mode))
- ret = fn(d.str, &sb, user);
+ ret = fn(d.str, &sb, done, user);
else
fprintf(stderr, "%s: unexpected st_mode %ju\n",
__func__, (uintmax_t)sb.st_mode);
dynstr_free(&d);
- if (ret)
+ if (ret || *done)
goto end;
}
@@ -87,3 +87,11 @@ end:
return ret;
}
+
+int cftw(const char *const dirpath, int (*const fn)(const char *,
+ const struct stat *, bool *, void *), void *const user)
+{
+ bool done = false;
+
+ return do_cftw(dirpath, fn, &done, user);
+}