diff --git a/libdftw.h b/libdftw.h index 4aa7a0d..2666b85 100644 --- a/libdftw.h +++ b/libdftw.h @@ -16,6 +16,14 @@ enum { #define FTW_NS FTW_NS }; +#define DFTW_CONTINUE 0 +#define DFTW_SKIP_SUBTREE 1 + +/* + * Callbacks should return DFTW_CONTINUE to continue traversal. Returning + * DFTW_SKIP_SUBTREE from an FTW_D callback skips descending into that + * directory while allowing the walk to continue elsewhere. + */ void dftw(const char *dirpath, int (*fn) (const char *fpath, const struct stat *sb, int typeflag)); diff --git a/libdftw/dftw.c b/libdftw/dftw.c index 2193c07..795e7de 100644 --- a/libdftw/dftw.c +++ b/libdftw/dftw.c @@ -1,8 +1,8 @@ +#include #include #include #include -#include #include #include #include @@ -36,6 +36,7 @@ void DFTW_create(CIRCLE_handle* handle) void DFTW_process(CIRCLE_handle* handle) { struct stat st; + int cb_rc = DFTW_CONTINUE; int status = 0; char temp[CIRCLE_MAX_STRING_LEN]; @@ -51,8 +52,10 @@ void DFTW_process(CIRCLE_handle* handle) } else if(S_ISDIR(st.st_mode) && !(S_ISLNK(st.st_mode))) { - _DFTW_CB(temp, &st, FTW_D); - DFTW_process_dir(temp, handle); + cb_rc = _DFTW_CB(temp, &st, FTW_D); + if(cb_rc == DFTW_CONTINUE) { + DFTW_process_dir(temp, handle); + } } else if(S_ISREG(st.st_mode)) { _DFTW_CB(temp, &st, FTW_F);