dirvec: add dirvec_for_each iterator

This will make it easier to introduce locking
This commit is contained in:
Eric Wong 2008-10-21 01:30:30 +02:00 committed by Max Kellermann
parent 1d385190a0
commit f2525e3efb
2 changed files with 19 additions and 0 deletions

View File

@ -78,3 +78,19 @@ void dirvec_destroy(struct dirvec *dv)
} }
dv->nr = 0; 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;
}

View File

@ -24,4 +24,7 @@ dirvec_clear(struct dirvec *dv)
void dirvec_destroy(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 */ #endif /* DIRVEC_H */