diff options
-rw-r--r-- | src/dirvec.c | 16 | ||||
-rw-r--r-- | src/dirvec.h | 3 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/dirvec.c b/src/dirvec.c index fdfbb3434..73375fc70 100644 --- a/src/dirvec.c +++ b/src/dirvec.c @@ -68,3 +68,19 @@ void dirvec_destroy(struct dirvec *dv) } dv->nr = 0; } + +int dirvec_for_each(const struct dirvec *dv, + int (*fn)(struct directory *, void *), void *arg) +{ + size_t i; + + for (i = 0; i < dv->nr; ++i) { + struct directory *dir = dv->base[i]; + + assert(dir); + if (fn(dir, arg) < 0) + return -1; + } + + return 0; +} diff --git a/src/dirvec.h b/src/dirvec.h index 02496cd2b..b820e8739 100644 --- a/src/dirvec.h +++ b/src/dirvec.h @@ -23,4 +23,7 @@ static inline void dirvec_clear(struct dirvec *dv) void dirvec_destroy(struct dirvec *dv); +int dirvec_for_each(const struct dirvec *dv, + int (*fn)(struct directory *, void *), void *arg); + #endif /* DIRVEC_H */ |