From f2525e3efbd35262ac1fa017482c8a70c11f35c0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 21 Oct 2008 01:30:30 +0200 Subject: [PATCH] dirvec: add dirvec_for_each iterator This will make it easier to introduce locking --- src/dirvec.c | 16 ++++++++++++++++ src/dirvec.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/dirvec.c b/src/dirvec.c index 61e5a859a..7493a4d2c 100644 --- a/src/dirvec.c +++ b/src/dirvec.c @@ -78,3 +78,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 2cdfb3196..746143aee 100644 --- a/src/dirvec.h +++ b/src/dirvec.h @@ -24,4 +24,7 @@ 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 */